cdf063a0a3
- Rename all PascalCase types: OhMyOpenCodePlugin → OhMyOpenAgentPlugin, etc. - 231 OhMyOpenAgent references across ~60 files - Centralize 4 PACKAGE_NAME constants to import from plugin-identity.ts - Update src/plugin-config.ts to use CONFIG_BASENAME from plugin-identity Wave 3 Tasks 5 & 6 complete.
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import type { AutoCompactState } from "./types";
|
|
import type { OhMyOpenAgentConfig } 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: OhMyOpenAgentConfig,
|
|
_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);
|
|
}
|
|
}
|