feat(FN-1000): add token cap detection for agent task execution

- Add tokenCap to ProjectSettings with tokenCapEnabled flag, default 500K tokens
- Create TokenCapDetector class with usage tracking and cap enforcement
- Wire TokenCapDetector into executor agentWork() to auto-fail tasks exceeding cap
- Add token cap input fields to Settings Modal dashboard UI
- Add comprehensive unit tests for TokenCapDetector (174 lines)
This commit is contained in:
gsxdsm
2026-04-05 22:50:03 -07:00
parent 931093a4e2
commit 904e4c8e00
6 changed files with 306 additions and 0 deletions

View File

@@ -924,6 +924,11 @@ export interface ProjectSettings {
* in their prompts and will not read or write to .fusion/memory.md.
* Default: true (enabled for backward compatibility). */
memoryEnabled?: boolean;
/** Maximum token count before auto-compact triggers. When undefined, compact
* only on overflow errors. When set, the engine monitors token usage after
* each prompt and proactively compacts context when the token count reaches
* this threshold. */
tokenCap?: number;
}
/**
@@ -1013,6 +1018,7 @@ export const DEFAULT_PROJECT_SETTINGS: ProjectSettings = {
insightExtractionSchedule: "0 2 * * *",
insightExtractionMinIntervalMs: 86_400_000,
memoryEnabled: true,
tokenCap: undefined,
};
/**
@@ -1087,6 +1093,7 @@ export const PROJECT_SETTINGS_KEYS: ReadonlyArray<keyof ProjectSettings> = [
"titleSummarizerModelId",
"titleSummarizerFallbackProvider",
"titleSummarizerFallbackModelId",
"tokenCap",
"insightExtractionEnabled",
"insightExtractionSchedule",
"insightExtractionMinIntervalMs",