refactor: adapt resource loader and tool wiring to pi-coding-agent 0.70

Three API shifts converge here:

- DefaultResourceLoaderOptions.agentDir is required as of 0.68 (the
  old process.cwd() fallback was removed). Pass getFusionAgentDir()
  explicitly in createFnAgent.

- createAgentSession({ tools }) is now a string[] allowlist of tool
  names, not a Tool[] array (0.68). Our boundary-wrapping via
  wrapToolsWithBoundary produces Tool instances, so we can no longer
  pass them through \`tools\`. Move them into \`customTools\` and
  suppress the built-in defaults with \`noTools: "builtin"\`. The
  wrapped tools keep the same names (read, bash, ...) as the built-ins
  they replace, so no call-site or prompt changes are needed.

- SettingsManager.create's first arg (cwd) became required (was
  optional before). Dashboard routes that previously passed
  \`undefined\` for a process-global settings view now pass
  process.cwd() to match the existing DefaultPackageManager call below.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-23 17:13:58 -07:00
parent 4ce0bf57ac
commit 6296c3cb53
2 changed files with 15 additions and 5 deletions

View File

@@ -3455,7 +3455,7 @@ export function createApiRoutes(store: TaskStore, options?: ServerOptions): Rout
try {
const { SettingsManager, getAgentDir } = await import("@mariozechner/pi-coding-agent");
const agentDir = getAgentDir();
const settingsManager = SettingsManager.create(undefined, agentDir);
const settingsManager = SettingsManager.create(process.cwd(), agentDir);
const packages = settingsManager.getPackages();
const extensions = settingsManager.getExtensionPaths();
const skills = settingsManager.getSkillPaths();
@@ -3493,7 +3493,7 @@ export function createApiRoutes(store: TaskStore, options?: ServerOptions): Rout
const { SettingsManager, getAgentDir } = await import("@mariozechner/pi-coding-agent");
const agentDir = getAgentDir();
const settingsManager = SettingsManager.create(undefined, agentDir);
const settingsManager = SettingsManager.create(process.cwd(), agentDir);
if (packages !== undefined) {
if (!Array.isArray(packages)) {
@@ -3551,7 +3551,7 @@ export function createApiRoutes(store: TaskStore, options?: ServerOptions): Rout
const { SettingsManager, DefaultPackageManager, getAgentDir } = await import("@mariozechner/pi-coding-agent");
const agentDir = getAgentDir();
const cwd = process.cwd();
const settingsManager = SettingsManager.create(undefined, agentDir);
const settingsManager = SettingsManager.create(process.cwd(), agentDir);
const packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });
await packageManager.install(source.trim());

View File

@@ -751,6 +751,7 @@ export async function createFnAgent(options: AgentOptions): Promise<AgentResult>
const resourceLoader = new DefaultResourceLoader({
cwd: options.cwd,
agentDir: getFusionAgentDir(),
settingsManager,
systemPromptOverride: () => options.systemPrompt,
appendSystemPromptOverride: () => [],
@@ -761,13 +762,22 @@ export async function createFnAgent(options: AgentOptions): Promise<AgentResult>
const sessionManager = options.sessionManager ?? SessionManager.inMemory();
const createSessionWithModel = async (modelOverride?: typeof selectedModel) => {
// pi-coding-agent 0.68+: `tools` is a string[] allowlist of tool names, not
// Tool instances. We need boundary-wrapped versions of the built-ins, so we
// suppress the defaults with `noTools: "builtin"` and register our wrapped
// tools through `customTools` instead. The wrapped tools preserve the same
// names (`read`, `bash`, ...) as the built-ins they replace.
const customToolList: ToolDefinition[] = [
...(wrappedTools as ToolDefinition[]),
...(options.customTools ?? []),
];
return createAgentSession({
cwd: options.cwd,
authStorage,
modelRegistry,
resourceLoader,
tools: wrappedTools as any,
customTools: options.customTools,
noTools: "builtin",
customTools: customToolList,
sessionManager,
settingsManager,
...(modelOverride ? { model: modelOverride } : {}),