MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / runCompaction

Method runCompaction

src/agent/loop.ts:2487–2521  ·  view source on GitHub ↗

* Summarize the combined history (base messages + this run's new messages), * collapsing all but the most recent turns into one summary system message. * * Returns the NEW combined message list, or null if compaction didn't run * (below threshold, or summarization failed — caller keeps t

(
    combined: Message[],
    ctxWindow: number,
    signal: AbortSignal | undefined,
  )

Source from the content-addressed store, hash-verified

2485 }
2486 }
2487
2488 const timeoutSec = this.config.budget.toolTimeoutSeconds ?? 300;
2489 const timeoutMs = timeoutSec * 1000;
2490 let timeoutHandle: ReturnType<typeof setTimeout> | undefined;
2491 const timeoutPromise = new Promise<never>((_, reject) => {
2492 timeoutHandle = setTimeout(() => {
2493 // CRITICAL: abort the tool's inner signal so spawn'd processes actually die.
2494 toolAbort.abort('TOOL_TIMEOUT');
2495 const err: any = new Error(`Tool '${tc.function.name}' exceeded ${timeoutSec}s timeout`);
2496 err.code = 'TOOL_TIMEOUT';
2497 reject(err);
2498 }, timeoutMs);
2499 });
2500
2501 const ctx: ToolContext = {
2502 cwd: this.effectiveCwd ?? this.cwd,
2503 sessionId,
2504 transaction,
2505 permissions: this.permissions,
2506 askUser: options.askUser,
2507 emit: (ev) => {
2508 uiEvents.push(ev);
2509 if (options.onToolUI) options.onToolUI(ev);
2510 },
2511 signal: toolAbort.signal,
2512 // The snapshot service (if any) is plumbed in from the agent loop's instance.
2513 // bash and other destructive tools use it to git-stash before risky commands.
2514 snapshotService: this.snapshotService,
2515 // Git sandbox handle (only when runSandboxed is active) — lets a tool or the
2516 // model request a checkpoint or an autonomous backtrack.
2517 sandbox: this.activeSandbox ? {
2518 isActive: () => this.activeSandbox?.isActive() ?? false,
2519 checkpoint: (label: string) => this.activeSandbox?.checkpoint(label) ?? Promise.resolve(null),
2520 backtrack: () => this.activeSandbox?.backtrack() ?? Promise.resolve(null),
2521 } : undefined,
2522 currentTurn: this.currentTurn,
2523 };
2524

Callers 1

runMethod · 0.95

Calls 4

estimateTokensMethod · 0.95
compactMessagesFunction · 0.85
routeMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected