diff --git a/packages/core/src/core/client.ts b/packages/core/src/core/client.ts index 13d540c1ff..f3d9116bcd 100644 --- a/packages/core/src/core/client.ts +++ b/packages/core/src/core/client.ts @@ -16,11 +16,7 @@ import { getDirectoryContextString, getEnvironmentContext, } from '../utils/environmentContext.js'; -import { - Turn, - GeminiEventType, - type ServerGeminiStreamEvent, -} from './turn.js'; +import { Turn, GeminiEventType, type ServerGeminiStreamEvent } from './turn.js'; import { CompressionStatus, type ChatCompressionInfo, @@ -562,7 +558,7 @@ export class GeminiClient { if ( 'type' in hookResult && (hookResult.type === GeminiEventType.AgentExecutionStopped || - hookResult.type === GeminiEventType.AgentExecutionBlocked) + hookResult.type === GeminiEventType.AgentExecutionBlocked) ) { if (hookResult.type === GeminiEventType.AgentExecutionStopped) { this.getChat().addHistory(createUserContent(request)); @@ -603,7 +599,7 @@ export class GeminiClient { debugLogger.debug('[PROJECT CLARITY] Re-prompt requested.'); yield* this.sendMessageStream( - [{ text: '[System: State updated. Please continue.]' }], + [], signal, prompt_id, boundedTurns - 1, diff --git a/packages/core/src/tools/compress.ts b/packages/core/src/tools/compress.ts index 216fce165a..049babc49f 100644 --- a/packages/core/src/tools/compress.ts +++ b/packages/core/src/tools/compress.ts @@ -49,9 +49,13 @@ class CompressInvocation extends BaseToolInvocation< callId?: string, ): Promise { if (!callId) { - throw new Error('Critical error: callId is required for context compression elision.'); + throw new Error( + 'Critical error: callId is required for context compression elision.', + ); } - debugLogger.debug(`[PROJECT CLARITY] Executing CompressTool (callId: ${callId})`); + debugLogger.debug( + `[PROJECT CLARITY] Executing CompressTool (callId: ${callId})`, + ); try { const continuityService = this.config.getContinuityCompressionService(); const snapshot = await continuityService.generateSnapshot( @@ -61,14 +65,10 @@ class CompressInvocation extends BaseToolInvocation< ); // Queue the history replacement via SideEffectService - const sideEffects = this.config.getSideEffectService() + const sideEffects = this.config.getSideEffectService(); sideEffects.replaceHistory([]); sideEffects.setContinuityAnchor(snapshot); - - if (callId) { - sideEffects.elideCall(callId); - } - sideEffects.reprompt(); + sideEffects.elideCall(callId); return { llmContent: `Compression successful.`, diff --git a/packages/core/src/tools/distill-result.ts b/packages/core/src/tools/distill-result.ts index 26dbccc736..ed1952f087 100644 --- a/packages/core/src/tools/distill-result.ts +++ b/packages/core/src/tools/distill-result.ts @@ -49,9 +49,14 @@ class DistillResultInvocation extends BaseToolInvocation< _shellExecutionConfig?: any, ownCallId?: string, ): Promise { + if (!ownCallId) { + throw new Error('Critical error: callId is required for distill result.'); + } const revisedText = this.params.revised_text; - debugLogger.debug(`[PROJECT CLARITY] Executing DistillResultTool (ownCallId: ${ownCallId})`); + debugLogger.debug( + `[PROJECT CLARITY] Executing DistillResultTool (ownCallId: ${ownCallId})`, + ); // 1. Find the target: the last function response in history. const history = this.chat.getHistory(); @@ -82,15 +87,15 @@ class DistillResultInvocation extends BaseToolInvocation< throw new Error('Target call ID missing from tool response.'); } - debugLogger.debug(`[PROJECT CLARITY] Distill target identified: ${targetCallId} at index ${lastToolResponseIndex}`); + debugLogger.debug( + `[PROJECT CLARITY] Distill target identified: ${targetCallId} at index ${lastToolResponseIndex}`, + ); const sideEffects = this.config.getSideEffectService(); // 2. Elide all turns between that tool response and the current turn. - if (ownCallId) { - sideEffects.elideBetween(targetCallId, ownCallId); - sideEffects.elideCall(ownCallId); - } + sideEffects.elideBetween(targetCallId, ownCallId); + sideEffects.elideCall(ownCallId); // 3. Save the raw output to a temp file for safety (to avoid "self-gaslighting") const toolName = @@ -117,7 +122,6 @@ class DistillResultInvocation extends BaseToolInvocation< }; sideEffects.distillResult(targetCallId, distilledResponse); - sideEffects.reprompt(); return { llmContent: 'Result distilled successfully.',