chore(vendor): import pi 1.3.0

Imported as a linear vendor commit so forge rebases do not replay the upstream root tree.

git-subtree-dir: third_party/pi

git-subtree-split: 71023aec1546d6d677a65669c5665c0927ce0dd0
This commit is contained in:
2026-10-15 17:58:48 -04:00
parent 719370c8f7
commit 6081e3e325
1743 changed files with 205460 additions and 131705 deletions

View File

@@ -0,0 +1,61 @@
/**
* Codemode, Tool Search, and MCP
*
* The CLI loads `codemode`, `tool_search`, and MCP as built-in extensions. SDK sessions add
* them to the resource loader's extension factories.
*
* `codemode` and `tool_search` are registered inactive. Enable them through the `defaultTools` setting
* (`tools` would also restrict the session to the named tools, which hides MCP tools), or let the
* MCP extension activate them: `codemode` for servers with `codemode` exposure, `tool_search` for
* servers with `deferred` exposure.
*/
import {
createAgentSession,
createCodemodeExtension,
createMcpExtension,
createToolSearchExtension,
DefaultResourceLoader,
getAgentDir,
SessionManager,
SettingsManager,
} from "@earendil-works/pi-coding-agent";
const cwd = process.cwd();
const resourceLoader = new DefaultResourceLoader({
cwd,
agentDir: getAgentDir(),
extensionFactories: [
createCodemodeExtension({ mode: "on" }),
createToolSearchExtension(),
// Reads mcp.json from the agent directory and the trusted project, like the CLI.
createMcpExtension(),
],
});
await resourceLoader.reload();
const settingsManager = SettingsManager.create(cwd);
// `+name` adds to the configured default tools instead of replacing them.
settingsManager.applyOverrides({ defaultTools: ["+codemode", "+tool_search"] });
const { session } = await createAgentSession({
resourceLoader,
settingsManager,
sessionManager: SessionManager.inMemory(),
});
try {
// Emits session_start, which connects the MCP servers in the background.
await session.bindExtensions({});
console.log("Active tools:", session.getActiveToolNames().join(", "));
session.subscribe((event) => {
if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
process.stdout.write(event.assistantMessageEvent.delta);
}
});
await session.prompt("Use codemode to count the TypeScript files in src/ and list the three largest.");
console.log();
} finally {
session.dispose();
}

View File

@@ -15,18 +15,19 @@ The runtime example shows how to build a recreate function that closes over proc
| `05-tools.ts` | Built-in tool allowlists |
| `06-extensions.ts` | Logging, blocking, result modification |
| `07-context-files.ts` | AGENTS.md context files |
| `08-slash-commands.ts` | File-based slash commands |
| `08-prompt-templates.ts` | File-based prompt templates |
| `09-api-keys-and-oauth.ts` | API key resolution, OAuth config |
| `10-settings.ts` | Override compaction, retry, terminal settings |
| `11-sessions.ts` | In-memory, persistent, continue, list sessions |
| `12-full-control.ts` | Replace everything, no discovery |
| `13-session-runtime.ts` | Manage runtime-backed session replacement |
| `14-codemode-mcp.ts` | Add the `codemode`, `tool_search`, and MCP extensions |
## Running
```bash
cd packages/coding-agent
npx tsx examples/sdk/01-minimal.ts
node examples/sdk/01-minimal.ts
```
## Quick Reference