feat(core): Fully migrate packages/core to AgentLoopContext. (#22115)

This commit is contained in:
joshualitt
2026-03-12 18:56:31 -07:00
committed by GitHub
parent 1d2585dba6
commit de656f01d7
53 changed files with 522 additions and 292 deletions

View File

@@ -8,7 +8,6 @@ import fsPromises from 'node:fs/promises';
import path from 'node:path';
import os from 'node:os';
import crypto from 'node:crypto';
import type { Config } from '../config/config.js';
import { debugLogger } from '../index.js';
import { ToolErrorType } from './tool-error.js';
import {
@@ -45,6 +44,7 @@ import { SHELL_TOOL_NAME } from './tool-names.js';
import type { MessageBus } from '../confirmation-bus/message-bus.js';
import { getShellDefinition } from './definitions/coreTools.js';
import { resolveToolDeclaration } from './definitions/resolver.js';
import type { AgentLoopContext } from '../config/agent-loop-context.js';
export const OUTPUT_UPDATE_INTERVAL_MS = 1000;
@@ -63,7 +63,7 @@ export class ShellToolInvocation extends BaseToolInvocation<
ToolResult
> {
constructor(
private readonly config: Config,
private readonly context: AgentLoopContext,
params: ShellToolParams,
messageBus: MessageBus,
_toolName?: string,
@@ -168,7 +168,7 @@ export class ShellToolInvocation extends BaseToolInvocation<
.toString('hex')}.tmp`;
const tempFilePath = path.join(os.tmpdir(), tempFileName);
const timeoutMs = this.config.getShellToolInactivityTimeout();
const timeoutMs = this.context.config.getShellToolInactivityTimeout();
const timeoutController = new AbortController();
let timeoutTimer: NodeJS.Timeout | undefined;
@@ -189,10 +189,10 @@ export class ShellToolInvocation extends BaseToolInvocation<
})();
const cwd = this.params.dir_path
? path.resolve(this.config.getTargetDir(), this.params.dir_path)
: this.config.getTargetDir();
? path.resolve(this.context.config.getTargetDir(), this.params.dir_path)
: this.context.config.getTargetDir();
const validationError = this.config.validatePathAccess(cwd);
const validationError = this.context.config.validatePathAccess(cwd);
if (validationError) {
return {
llmContent: validationError,
@@ -271,13 +271,13 @@ export class ShellToolInvocation extends BaseToolInvocation<
}
},
combinedController.signal,
this.config.getEnableInteractiveShell(),
this.context.config.getEnableInteractiveShell(),
{
...shellExecutionConfig,
pager: 'cat',
sanitizationConfig:
shellExecutionConfig?.sanitizationConfig ??
this.config.sanitizationConfig,
this.context.config.sanitizationConfig,
},
);
@@ -382,7 +382,7 @@ export class ShellToolInvocation extends BaseToolInvocation<
}
let returnDisplayMessage = '';
if (this.config.getDebugMode()) {
if (this.context.config.getDebugMode()) {
returnDisplayMessage = llmContent;
} else {
if (this.params.is_background || result.backgrounded) {
@@ -411,7 +411,8 @@ export class ShellToolInvocation extends BaseToolInvocation<
}
}
const summarizeConfig = this.config.getSummarizeToolOutputConfig();
const summarizeConfig =
this.context.config.getSummarizeToolOutputConfig();
const executionError = result.error
? {
error: {
@@ -422,10 +423,10 @@ export class ShellToolInvocation extends BaseToolInvocation<
: {};
if (summarizeConfig && summarizeConfig[SHELL_TOOL_NAME]) {
const summary = await summarizeToolOutput(
this.config,
this.context.config,
{ model: 'summarizer-shell' },
llmContent,
this.config.getGeminiClient(),
this.context.geminiClient,
signal,
);
return {
@@ -461,15 +462,15 @@ export class ShellTool extends BaseDeclarativeTool<
static readonly Name = SHELL_TOOL_NAME;
constructor(
private readonly config: Config,
private readonly context: AgentLoopContext,
messageBus: MessageBus,
) {
void initializeShellParsers().catch(() => {
// Errors are surfaced when parsing commands.
});
const definition = getShellDefinition(
config.getEnableInteractiveShell(),
config.getEnableShellOutputEfficiency(),
context.config.getEnableInteractiveShell(),
context.config.getEnableShellOutputEfficiency(),
);
super(
ShellTool.Name,
@@ -492,10 +493,10 @@ export class ShellTool extends BaseDeclarativeTool<
if (params.dir_path) {
const resolvedPath = path.resolve(
this.config.getTargetDir(),
this.context.config.getTargetDir(),
params.dir_path,
);
return this.config.validatePathAccess(resolvedPath);
return this.context.config.validatePathAccess(resolvedPath);
}
return null;
}
@@ -507,7 +508,7 @@ export class ShellTool extends BaseDeclarativeTool<
_toolDisplayName?: string,
): ToolInvocation<ShellToolParams, ToolResult> {
return new ShellToolInvocation(
this.config,
this.context.config,
params,
messageBus,
_toolName,
@@ -517,8 +518,8 @@ export class ShellTool extends BaseDeclarativeTool<
override getSchema(modelId?: string) {
const definition = getShellDefinition(
this.config.getEnableInteractiveShell(),
this.config.getEnableShellOutputEfficiency(),
this.context.config.getEnableInteractiveShell(),
this.context.config.getEnableShellOutputEfficiency(),
);
return resolveToolDeclaration(definition, modelId);
}