51 lines
2.0 KiB
TypeScript
51 lines
2.0 KiB
TypeScript
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
import { createCommandFormatterRunner } from "./src/formatting/command-runner.ts";
|
|
import { createCommandDiagnosticsBackend } from "./src/diagnostics/command-backend.ts";
|
|
import { createLspClientManager } from "./src/diagnostics/lsp-client.ts";
|
|
import { createSetupSuggestTool } from "./src/tools/setup-suggest.ts";
|
|
import { probeProject } from "./src/project-probe.ts";
|
|
import { createFormattedWriteTool } from "./src/tools/write.ts";
|
|
import { createFormattedEditTool } from "./src/tools/edit.ts";
|
|
import { createDevToolsRuntime } from "./src/runtime.ts";
|
|
|
|
export default function devTools(pi: ExtensionAPI) {
|
|
const cwd = process.cwd();
|
|
const agentDir = process.env.PI_CODING_AGENT_DIR ?? `${process.env.HOME}/.pi/agent`;
|
|
|
|
const runtime = createDevToolsRuntime({
|
|
cwd,
|
|
agentDir,
|
|
formatterRunner: createCommandFormatterRunner({
|
|
execCommand: async (command, args, options) => {
|
|
const result = await pi.exec(command, args, { timeout: options.timeout });
|
|
return { code: result.code ?? 0, stdout: result.stdout ?? "", stderr: result.stderr ?? "" };
|
|
},
|
|
}),
|
|
commandBackend: createCommandDiagnosticsBackend({
|
|
execCommand: async (command, args, options) => {
|
|
const result = await pi.exec(command, args, { timeout: options.timeout });
|
|
return { code: result.code ?? 0, stdout: result.stdout ?? "", stderr: result.stderr ?? "" };
|
|
},
|
|
}),
|
|
lspBackend: createLspClientManager(),
|
|
probeProject,
|
|
});
|
|
|
|
pi.registerTool(createFormattedEditTool(cwd, runtime));
|
|
pi.registerTool(createFormattedWriteTool(cwd, runtime));
|
|
pi.registerTool(createSetupSuggestTool({
|
|
suggestSetup: async () => {
|
|
const probe = await probeProject({ cwd });
|
|
return probe.summary;
|
|
},
|
|
}));
|
|
|
|
pi.on("before_agent_start", async (event) => {
|
|
const block = runtime.getPromptBlock();
|
|
if (!block) return;
|
|
return {
|
|
systemPrompt: `${event.systemPrompt}\n\n${block}`,
|
|
};
|
|
});
|
|
}
|