Files
oh-my-openagent/src/hooks/anthropic-context-window-limit-recovery/executor.ts
YeonGyu-Kim ac3a9fd272 fix(hooks/anthropic-context-window-limit-recovery): remove @ts-ignore comments and fix parameter types
Remove @ts-ignore and eslint-disable comments from executor.ts and recovery-hook.ts

- Change client: any to client: Client with proper import

- Rename experimental to _experimental for unused parameter

- Remove @ts-ignore for ctx.client casts

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-02-23 02:42:24 +09:00

84 lines
2.3 KiB
TypeScript

import type { AutoCompactState } from "./types";
import type { OhMyOpenCodeConfig } from "../../config";
import type { ExperimentalConfig } from "../../config";
import { TRUNCATE_CONFIG } from "./types";
import type { Client } from "./client";
import { getOrCreateTruncateState } from "./state";
import {
runAggressiveTruncationStrategy,
runSummarizeRetryStrategy,
} from "./recovery-strategy";
export { getLastAssistant } from "./message-builder";
export async function executeCompact(
sessionID: string,
msg: Record<string, unknown>,
autoCompactState: AutoCompactState,
client: Client,
directory: string,
pluginConfig: OhMyOpenCodeConfig,
_experimental?: ExperimentalConfig
): Promise<void> {
void _experimental
if (autoCompactState.compactionInProgress.has(sessionID)) {
await client.tui
.showToast({
body: {
title: "Compact In Progress",
message:
"Recovery already running. Please wait or start new session if stuck.",
variant: "warning",
duration: 5000,
},
})
.catch(() => {});
return;
}
autoCompactState.compactionInProgress.add(sessionID);
try {
const errorData = autoCompactState.errorDataBySession.get(sessionID);
const truncateState = getOrCreateTruncateState(autoCompactState, sessionID);
const isOverLimit =
errorData?.currentTokens &&
errorData?.maxTokens &&
errorData.currentTokens > errorData.maxTokens;
// Aggressive Truncation - always try when over limit
if (
isOverLimit &&
truncateState.truncateAttempt < TRUNCATE_CONFIG.maxTruncateAttempts
) {
const result = await runAggressiveTruncationStrategy({
sessionID,
autoCompactState,
client: client,
directory,
truncateAttempt: truncateState.truncateAttempt,
currentTokens: errorData.currentTokens,
maxTokens: errorData.maxTokens,
});
truncateState.truncateAttempt = result.nextTruncateAttempt;
if (result.handled) return;
}
await runSummarizeRetryStrategy({
sessionID,
msg,
autoCompactState,
client: client,
directory,
pluginConfig,
errorType: errorData?.errorType,
messageIndex: errorData?.messageIndex,
})
} finally {
autoCompactState.compactionInProgress.delete(sessionID);
}
}