refactor: centralize bootstrap file resolution

This commit is contained in:
Peter Steinberger
2026-01-18 05:31:04 +00:00
parent ad3c12a43a
commit e7a4931932
5 changed files with 38 additions and 35 deletions

View File

@@ -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<WorkspaceBootstrapFile[]> {
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,
});
}

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,
});