mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
feat(coding-agent): codemode and MCP
This adds codemode and MCP support to pi. Codemode (packages/codemode) runs model-written JavaScript in a QuickJS wasm VM inside a worker. From there the script calls pi's tools as async functions, uses a per-session store, and can read the model catalog and run classifiers. The codemode tool in coding-agent is compatible with Codex's exec tool, and codemode.mode works like Codex's tool modes (on or only). Large results are written to a JSON temp file. MCP (packages/mcp) is a standalone client for stdio and streamable HTTP servers, with OAuth. The core only gets general mechanisms; codemode, tool_search and MCP are built-in extensions that use them. Other extensions can replace these built-ins. Tools declare an exposure: direct, model-only, codemode, deferred or hidden. prepareLoadout() lets an orchestrating tool change which tool declarations the model sees. ctx.executeTool() runs nested calls through validation and the tool_call/tool_result hooks. Those calls emit events with parentToolCallId and are recorded as bounded nestedCalls on the parent result, which compaction and HTML export use. Tools can also return structuredContent with an outputSchema, and can report errors with isError instead of throwing. MCP servers come from mcp.json (global, or per project after the project is trusted) or from pi.registerMcpServer(). They are managed with /mcp and pi mcp list|login|logout, and their runtimes load on first use. Closes #10040
This commit is contained in:
parent
b485fa3128
commit
8562bcf66a
143 changed files with 17620 additions and 225 deletions
|
|
@ -122,15 +122,16 @@ for platform in "${PLATFORMS[@]}"; do
|
|||
fi
|
||||
|
||||
# Bun compiled executables only embed worker scripts when they are passed as
|
||||
# explicit build entrypoints. The runtime can still use new URL(...), but the
|
||||
# worker must be present in the compiled executable.
|
||||
# explicit build entrypoints. Bun places them at their path relative to the
|
||||
# common directory of all entrypoints, so the main entry must stay in dist/
|
||||
# for the worker URLs in src/config.ts to resolve.
|
||||
#
|
||||
# Disable cwd bunfig.toml autoload so project preload scripts cannot crash the
|
||||
# standalone binary before pi starts (see #7684).
|
||||
if [[ "$platform" == windows-* ]]; then
|
||||
bun build --compile --no-compile-autoload-bunfig --target="$bun_target" ./dist/bun/cli.js ./src/utils/image-resize-worker.ts --outfile "$OUTPUT_DIR/$platform/pi.exe"
|
||||
bun build --compile --no-compile-autoload-bunfig --target="$bun_target" ./dist/bun/cli.js ./src/utils/image-resize-worker.ts ./src/extensions/codemode/worker.ts --outfile "$OUTPUT_DIR/$platform/pi.exe"
|
||||
else
|
||||
bun build --compile --no-compile-autoload-bunfig --target="$bun_target" ./dist/bun/cli.js ./src/utils/image-resize-worker.ts --outfile "$OUTPUT_DIR/$platform/pi"
|
||||
bun build --compile --no-compile-autoload-bunfig --target="$bun_target" ./dist/bun/cli.js ./src/utils/image-resize-worker.ts ./src/extensions/codemode/worker.ts --outfile "$OUTPUT_DIR/$platform/pi"
|
||||
fi
|
||||
done
|
||||
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@ for (const entry of [
|
|||
join(codingAgentDistDir, "index.js"),
|
||||
join(codingAgentDistDir, "rpc-entry.js"),
|
||||
join(codingAgentDistDir, "utils", "image-resize-worker.js"),
|
||||
join(codingAgentDistDir, "extensions", "codemode", "worker.js"),
|
||||
join(aiDistDir, "api", "bedrock-converse-stream.js"),
|
||||
join(aiDistDir, "auth", "oauth", "anthropic.js"),
|
||||
]) {
|
||||
|
|
@ -174,6 +175,7 @@ const mainResult = await build({
|
|||
const bedrockLoaderOutput = findContainingOutput(mainResult.metafile, "packages/ai/dist/api/bedrock-converse-stream.lazy.js");
|
||||
const oauthLoaderOutput = findContainingOutput(mainResult.metafile, "packages/ai/dist/auth/oauth/load.js");
|
||||
const imageResizeOutput = findContainingOutput(mainResult.metafile, "packages/coding-agent/dist/utils/image-resize.js");
|
||||
const configOutput = findContainingOutput(mainResult.metafile, "packages/coding-agent/dist/config.js");
|
||||
if (dirname(bedrockLoaderOutput) !== dirname(oauthLoaderOutput)) {
|
||||
throw new Error("Bedrock and OAuth lazy loaders were emitted into different directories");
|
||||
}
|
||||
|
|
@ -187,6 +189,7 @@ const lazyResult = await build({
|
|||
entryPoints: {
|
||||
anthropic: join(aiDistDir, "auth", "oauth", "anthropic.js"),
|
||||
"bedrock-converse-stream": join(aiDistDir, "api", "bedrock-converse-stream.js"),
|
||||
"codemode-worker": join(codingAgentDistDir, "extensions", "codemode", "worker.js"),
|
||||
"github-copilot": join(aiDistDir, "auth", "oauth", "github-copilot.js"),
|
||||
"image-resize-worker": join(codingAgentDistDir, "utils", "image-resize-worker.js"),
|
||||
"kimi-coding": join(aiDistDir, "auth", "oauth", "kimi-coding.js"),
|
||||
|
|
@ -204,6 +207,10 @@ const imageResizeWorkerOutput = resolve(dirname(bedrockLoaderOutput), "image-res
|
|||
if (dirname(imageResizeOutput) !== dirname(imageResizeWorkerOutput)) {
|
||||
throw new Error("Image resize implementation and worker were emitted into different directories");
|
||||
}
|
||||
// getCodemodeWorkerUrl() in config.ts resolves the worker next to its own chunk.
|
||||
if (dirname(configOutput) !== dirname(bedrockLoaderOutput)) {
|
||||
throw new Error("config.ts and the codemode worker were emitted into different directories");
|
||||
}
|
||||
|
||||
validateExternalImports([mainResult.metafile, lazyResult.metafile]);
|
||||
const cliLauncher = `#!/usr/bin/env node
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ const WORKSPACE = {
|
|||
"@earendil-works/pi-ai": "packages/ai/src",
|
||||
"@earendil-works/pi-durable": "packages/durable/src",
|
||||
"@earendil-works/pi-agent-core": "packages/agent/src",
|
||||
"@earendil-works/pi-codemode": "packages/codemode/src",
|
||||
"@earendil-works/pi-telemetry": "packages/telemetry/src",
|
||||
"@earendil-works/pi-mcp": "packages/mcp/src",
|
||||
"@earendil-works/pi-tui": "packages/tui/src",
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue