From e7a49319324c9ae9d7cbda2a05feee56f9850047 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 18 Jan 2026 05:31:04 +0000 Subject: [PATCH] refactor: centralize bootstrap file resolution --- src/agents/bootstrap-files.ts | 29 +++++++++++++++++++ src/agents/cli-runner.ts | 10 ++----- src/agents/pi-embedded-runner/compact.ts | 10 ++----- src/agents/pi-embedded-runner/run/attempt.ts | 10 ++----- .../reply/commands-context-report.ts | 14 ++------- 5 files changed, 38 insertions(+), 35 deletions(-) create mode 100644 src/agents/bootstrap-files.ts diff --git a/src/agents/bootstrap-files.ts b/src/agents/bootstrap-files.ts new file mode 100644 index 000000000..59371853c --- /dev/null +++ b/src/agents/bootstrap-files.ts @@ -0,0 +1,29 @@ +import type { ClawdbotConfig } from "../config/config.js"; +import { applyBootstrapHookOverrides } from "./bootstrap-hooks.js"; +import { + filterBootstrapFilesForSession, + loadWorkspaceBootstrapFiles, + type WorkspaceBootstrapFile, +} from "./workspace.js"; + +export async function resolveBootstrapFilesForRun(params: { + workspaceDir: string; + config?: ClawdbotConfig; + sessionKey?: string; + sessionId?: string; + agentId?: string; +}): Promise { + const sessionKey = params.sessionKey ?? params.sessionId; + const bootstrapFiles = filterBootstrapFilesForSession( + await loadWorkspaceBootstrapFiles(params.workspaceDir), + sessionKey, + ); + return applyBootstrapHookOverrides({ + files: bootstrapFiles, + workspaceDir: params.workspaceDir, + config: params.config, + sessionKey: params.sessionKey, + sessionId: params.sessionId, + agentId: params.agentId, + }); +} diff --git a/src/agents/cli-runner.ts b/src/agents/cli-runner.ts index 92d1ee24e..b128bbecd 100644 --- a/src/agents/cli-runner.ts +++ b/src/agents/cli-runner.ts @@ -7,7 +7,7 @@ import { createSubsystemLogger } from "../logging.js"; import { runCommandWithTimeout } from "../process/exec.js"; import { resolveUserPath } from "../utils.js"; import { resolveSessionAgentIds } from "./agent-scope.js"; -import { applyBootstrapHookOverrides } from "./bootstrap-hooks.js"; +import { resolveBootstrapFilesForRun } from "./bootstrap-files.js"; import { resolveCliBackendConfig } from "./cli-backends.js"; import { appendImagePathsToPrompt, @@ -32,7 +32,6 @@ import { resolveBootstrapMaxChars, } from "./pi-embedded-helpers.js"; import type { EmbeddedPiRunResult } from "./pi-embedded-runner.js"; -import { filterBootstrapFilesForSession, loadWorkspaceBootstrapFiles } from "./workspace.js"; const log = createSubsystemLogger("agent/claude-cli"); @@ -73,12 +72,7 @@ export async function runCliAgent(params: { .filter(Boolean) .join("\n"); - const bootstrapFiles = filterBootstrapFilesForSession( - await loadWorkspaceBootstrapFiles(workspaceDir), - params.sessionKey ?? params.sessionId, - ); - const hookAdjustedBootstrapFiles = await applyBootstrapHookOverrides({ - files: bootstrapFiles, + const hookAdjustedBootstrapFiles = await resolveBootstrapFilesForRun({ workspaceDir, config: params.config, sessionKey: params.sessionKey, diff --git a/src/agents/pi-embedded-runner/compact.ts b/src/agents/pi-embedded-runner/compact.ts index a6f0beeb2..f5d9ef25f 100644 --- a/src/agents/pi-embedded-runner/compact.ts +++ b/src/agents/pi-embedded-runner/compact.ts @@ -16,7 +16,7 @@ import { isReasoningTagProvider } from "../../utils/provider-utils.js"; import { resolveUserPath } from "../../utils.js"; import { resolveClawdbotAgentDir } from "../agent-paths.js"; import { resolveSessionAgentIds } from "../agent-scope.js"; -import { applyBootstrapHookOverrides } from "../bootstrap-hooks.js"; +import { resolveBootstrapFilesForRun } from "../bootstrap-files.js"; import type { ExecElevatedDefaults } from "../bash-tools.js"; import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "../defaults.js"; import { getApiKeyForModel, resolveModelAuthMode } from "../model-auth.js"; @@ -44,7 +44,6 @@ import { resolveSkillsPromptForRun, type SkillSnapshot, } from "../skills.js"; -import { filterBootstrapFilesForSession, loadWorkspaceBootstrapFiles } from "../workspace.js"; import { buildEmbeddedExtensionPaths } from "./extensions.js"; import { logToolSchemasForGoogle, @@ -179,12 +178,7 @@ export async function compactEmbeddedPiSession(params: { workspaceDir: effectiveWorkspace, }); - const bootstrapFiles = filterBootstrapFilesForSession( - await loadWorkspaceBootstrapFiles(effectiveWorkspace), - params.sessionKey ?? params.sessionId, - ); - const hookAdjustedBootstrapFiles = await applyBootstrapHookOverrides({ - files: bootstrapFiles, + const hookAdjustedBootstrapFiles = await resolveBootstrapFilesForRun({ workspaceDir: effectiveWorkspace, config: params.config, sessionKey: params.sessionKey, diff --git a/src/agents/pi-embedded-runner/run/attempt.ts b/src/agents/pi-embedded-runner/run/attempt.ts index 23deead2d..83c0edcef 100644 --- a/src/agents/pi-embedded-runner/run/attempt.ts +++ b/src/agents/pi-embedded-runner/run/attempt.ts @@ -17,7 +17,7 @@ import { isSubagentSessionKey } from "../../../routing/session-key.js"; import { resolveUserPath } from "../../../utils.js"; import { resolveClawdbotAgentDir } from "../../agent-paths.js"; import { resolveSessionAgentIds } from "../../agent-scope.js"; -import { applyBootstrapHookOverrides } from "../../bootstrap-hooks.js"; +import { resolveBootstrapFilesForRun } from "../../bootstrap-files.js"; import { resolveModelAuthMode } from "../../model-auth.js"; import { buildBootstrapContextFiles, @@ -42,7 +42,6 @@ import { resolveSkillsPromptForRun, } from "../../skills.js"; import { buildSystemPromptReport } from "../../system-prompt-report.js"; -import { filterBootstrapFilesForSession, loadWorkspaceBootstrapFiles } from "../../workspace.js"; import { isAbortError } from "../abort.js"; import { buildEmbeddedExtensionPaths } from "../extensions.js"; @@ -121,12 +120,7 @@ export async function runEmbeddedAttempt( workspaceDir: effectiveWorkspace, }); - const bootstrapFiles = filterBootstrapFilesForSession( - await loadWorkspaceBootstrapFiles(effectiveWorkspace), - params.sessionKey ?? params.sessionId, - ); - const hookAdjustedBootstrapFiles = await applyBootstrapHookOverrides({ - files: bootstrapFiles, + const hookAdjustedBootstrapFiles = await resolveBootstrapFilesForRun({ workspaceDir: effectiveWorkspace, config: params.config, sessionKey: params.sessionKey, diff --git a/src/auto-reply/reply/commands-context-report.ts b/src/auto-reply/reply/commands-context-report.ts index 7f218756d..0d9382451 100644 --- a/src/auto-reply/reply/commands-context-report.ts +++ b/src/auto-reply/reply/commands-context-report.ts @@ -9,11 +9,7 @@ import { getSkillsSnapshotVersion } from "../../agents/skills/refresh.js"; import { buildAgentSystemPrompt } from "../../agents/system-prompt.js"; import { buildSystemPromptReport } from "../../agents/system-prompt-report.js"; import { buildToolSummaryMap } from "../../agents/tool-summaries.js"; -import { applyBootstrapHookOverrides } from "../../agents/bootstrap-hooks.js"; -import { - filterBootstrapFilesForSession, - loadWorkspaceBootstrapFiles, -} from "../../agents/workspace.js"; +import { resolveBootstrapFilesForRun } from "../../agents/bootstrap-files.js"; import type { SessionSystemPromptReport } from "../../config/sessions/types.js"; import { getRemoteSkillEligibility } from "../../infra/skills-remote.js"; import type { ReplyPayload } from "../types.js"; @@ -56,17 +52,13 @@ async function resolveContextReport( const workspaceDir = params.workspaceDir; const bootstrapMaxChars = resolveBootstrapMaxChars(params.cfg); - const bootstrapFiles = filterBootstrapFilesForSession( - await loadWorkspaceBootstrapFiles(workspaceDir), - params.sessionKey, - ); - const hookAdjustedBootstrapFiles = await applyBootstrapHookOverrides({ - files: bootstrapFiles, + const hookAdjustedBootstrapFiles = await resolveBootstrapFilesForRun({ workspaceDir, config: params.cfg, sessionKey: params.sessionKey, sessionId: params.sessionEntry?.sessionId, }); + const bootstrapFiles: WorkspaceBootstrapFile[] = hookAdjustedBootstrapFiles; const injectedFiles = buildBootstrapContextFiles(hookAdjustedBootstrapFiles, { maxChars: bootstrapMaxChars, });