@celljs/ta 0.0.0-stage → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -2
- package/bin/ta.mjs +10 -0
- package/dist/pi/CHANGELOG.md +26 -0
- package/dist/pi/dist/bundle/chunks/anthropic-messages-BWGCKOF4.js +6 -0
- package/dist/pi/dist/bundle/chunks/anthropic.js +75 -0
- package/dist/pi/dist/bundle/chunks/azure-openai-responses-FSC6BAW3.js +2 -0
- package/dist/pi/dist/bundle/chunks/bedrock-converse-stream.js +89 -0
- package/dist/pi/dist/bundle/chunks/chunk-36QC74V4.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-3TGLJEWK.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-44DLKSKE.js +1232 -0
- package/dist/pi/dist/bundle/chunks/chunk-4EYXVSA5.js +129 -0
- package/dist/pi/dist/bundle/chunks/chunk-5AGIVGSV.js +6 -0
- package/dist/pi/dist/bundle/chunks/chunk-62VOPMLK.js +65 -0
- package/dist/pi/dist/bundle/chunks/chunk-6QGV3IWD.js +6 -0
- package/dist/pi/dist/bundle/chunks/chunk-7CBJINYJ.js +20 -0
- package/dist/pi/dist/bundle/chunks/chunk-7DDKXS2Q.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-7O7QKK6A.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-7ZC4UXSL.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-B46VJEHW.js +44 -0
- package/dist/pi/dist/bundle/chunks/chunk-C2WU32PX.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-CF5GWZHW.js +31 -0
- package/dist/pi/dist/bundle/chunks/chunk-CHWNPHIS.js +82 -0
- package/dist/pi/dist/bundle/chunks/chunk-EBFHJFEE.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-EOO47QGR.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-FFMDRXC4.js +10 -0
- package/dist/pi/dist/bundle/chunks/chunk-GN3QYODH.js +16 -0
- package/dist/pi/dist/bundle/chunks/chunk-JXWJOIH4.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-L2ZPNLYD.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-LPXNMA2W.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-LVVZS2NO.js +12 -0
- package/dist/pi/dist/bundle/chunks/chunk-NL4X6LBY.js +4 -0
- package/dist/pi/dist/bundle/chunks/chunk-NZY7EIPA.js +4 -0
- package/dist/pi/dist/bundle/chunks/chunk-P7FPUEYA.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-PGXDEOVV.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-PJACZCIR.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-PMRZO46Y.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-PRRNXB7S.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-R2EGYMOO.js +7 -0
- package/dist/pi/dist/bundle/chunks/chunk-RDZVAGPR.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-TMTOQ7H7.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-UKVNB6C4.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-USJZMAIR.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-UTB4DTYQ.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-V6KH5QG4.js +9 -0
- package/dist/pi/dist/bundle/chunks/chunk-VOLAXWGI.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-YZKQS34S.js +9 -0
- package/dist/pi/dist/bundle/chunks/cli-MCOUW5WS.js +53 -0
- package/dist/pi/dist/bundle/chunks/cloudflare-workers-ai-system-one-WLAFJSP6.js +2 -0
- package/dist/pi/dist/bundle/chunks/codemode-worker.js +478 -0
- package/dist/pi/dist/bundle/chunks/easter-egg-3d-WMBNSJ4M.js +2 -0
- package/dist/pi/dist/bundle/chunks/execute-4CEBORGZ.js +505 -0
- package/dist/pi/dist/bundle/chunks/github-copilot.js +2 -0
- package/dist/pi/dist/bundle/chunks/google-generative-ai-INGKNW72.js +2 -0
- package/dist/pi/dist/bundle/chunks/google-vertex-IBTX6MBF.js +2 -0
- package/dist/pi/dist/bundle/chunks/https-proxy-agent-LVOO5TPL.js +13 -0
- package/dist/pi/dist/bundle/chunks/image-resize-worker.js +2 -0
- package/dist/pi/dist/bundle/chunks/jiti-loader-GL4HJFAD.js +21 -0
- package/dist/pi/dist/bundle/chunks/jiti-static-loader-2RCDI6B4.js +2 -0
- package/dist/pi/dist/bundle/chunks/kimi-coding.js +2 -0
- package/dist/pi/dist/bundle/chunks/lib-4AVRLBHM.js +9 -0
- package/dist/pi/dist/bundle/chunks/llama-cpp-classify-V5U3QKXI.js +22 -0
- package/dist/pi/dist/bundle/chunks/meta.js +2 -0
- package/dist/pi/dist/bundle/chunks/mistral-conversations-S4OWXIXQ.js +5 -0
- package/dist/pi/dist/bundle/chunks/multipart-parser-FMGQ7342.js +3 -0
- package/dist/pi/dist/bundle/chunks/node-AUOGOBCN.js +2 -0
- package/dist/pi/dist/bundle/chunks/node-KCMANYC2.js +16 -0
- package/dist/pi/dist/bundle/chunks/openai-chatgpt.js +75 -0
- package/dist/pi/dist/bundle/chunks/openai-codex-responses-QAWLOQSN.js +10 -0
- package/dist/pi/dist/bundle/chunks/openai-codex.js +75 -0
- package/dist/pi/dist/bundle/chunks/openai-completions-EJNYB6IX.js +7 -0
- package/dist/pi/dist/bundle/chunks/openai-decisions-IXI34BYG.js +5 -0
- package/dist/pi/dist/bundle/chunks/openai-responses-MD3562FB.js +4 -0
- package/dist/pi/dist/bundle/chunks/openrouter-images-PISKSFMS.js +2 -0
- package/dist/pi/dist/bundle/chunks/openrouter.js +75 -0
- package/dist/pi/dist/bundle/chunks/pi-messages-NORUKF4E.js +8 -0
- package/dist/pi/dist/bundle/chunks/radius.js +75 -0
- package/dist/pi/dist/bundle/chunks/runtime-FQB7RU7U.js +2 -0
- package/dist/pi/dist/bundle/chunks/src-QKGKDFSU.js +4 -0
- package/dist/pi/dist/bundle/chunks/typesafe-system-one-CHVC2UUI.js +2 -0
- package/dist/pi/dist/bundle/chunks/virtual-modules-O76XM3OB.js +2 -0
- package/dist/pi/dist/bundle/chunks/xai.js +2 -0
- package/dist/pi/dist/bundle/cli-runtime.js +3 -0
- package/dist/pi/dist/bundle/cli.js +5 -0
- package/dist/pi/dist/bundle/index.js +2 -0
- package/dist/pi/dist/bundle/rpc-entry.js +3 -0
- package/dist/pi/dist/core/export-html/ansi-to-html.js +249 -0
- package/dist/pi/dist/core/export-html/index.js +228 -0
- package/dist/pi/dist/core/export-html/template.css +1085 -0
- package/dist/pi/dist/core/export-html/template.html +56 -0
- package/dist/pi/dist/core/export-html/template.js +2044 -0
- package/dist/pi/dist/core/export-html/tool-renderer.js +113 -0
- package/dist/pi/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/pi/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
- package/dist/pi/dist/core/export-html/vendor/marked.min.js +79 -0
- package/dist/pi/dist/modes/interactive/assets/clankolas.png +0 -0
- package/dist/pi/dist/modes/interactive/theme/dark.json +78 -0
- package/dist/pi/dist/modes/interactive/theme/light.json +78 -0
- package/dist/pi/docs/cli-integration.md +106 -0
- package/dist/pi/docs/cli.md +343 -0
- package/dist/pi/docs/codemode.md +230 -0
- package/dist/pi/docs/compaction.md +463 -0
- package/dist/pi/docs/configuration.md +47 -0
- package/dist/pi/docs/containerization.md +183 -0
- package/dist/pi/docs/custom-provider.md +227 -0
- package/dist/pi/docs/docs.json +220 -0
- package/dist/pi/docs/environment-variables.md +103 -0
- package/dist/pi/docs/extensions.md +3347 -0
- package/dist/pi/docs/how-pi-works.md +49 -0
- package/dist/pi/docs/images/doom-extension.png +0 -0
- package/dist/pi/docs/images/exy.png +0 -0
- package/dist/pi/docs/images/interactive-mode.png +0 -0
- package/dist/pi/docs/images/tree-view.png +0 -0
- package/dist/pi/docs/index.md +39 -0
- package/dist/pi/docs/json.md +226 -0
- package/dist/pi/docs/keybindings.md +195 -0
- package/dist/pi/docs/llama-cpp.md +132 -0
- package/dist/pi/docs/mcp.md +274 -0
- package/dist/pi/docs/message-types.md +279 -0
- package/dist/pi/docs/models-configuration.md +196 -0
- package/dist/pi/docs/models.md +225 -0
- package/dist/pi/docs/nvidia-rtx-llama-cpp.md +96 -0
- package/dist/pi/docs/packages.md +153 -0
- package/dist/pi/docs/prompt-templates.md +59 -0
- package/dist/pi/docs/providers.md +247 -0
- package/dist/pi/docs/quickstart.md +140 -0
- package/dist/pi/docs/rpc-commands.md +860 -0
- package/dist/pi/docs/rpc-extension-ui.md +200 -0
- package/dist/pi/docs/rpc.md +193 -0
- package/dist/pi/docs/sdk.md +147 -0
- package/dist/pi/docs/security.md +99 -0
- package/dist/pi/docs/session-format.md +293 -0
- package/dist/pi/docs/sessions.md +74 -0
- package/dist/pi/docs/settings.md +173 -0
- package/dist/pi/docs/shell-aliases.md +93 -0
- package/dist/pi/docs/skills.md +93 -0
- package/dist/pi/docs/slash-commands.md +61 -0
- package/dist/pi/docs/terminal-setup.md +235 -0
- package/dist/pi/docs/termux.md +117 -0
- package/dist/pi/docs/themes.md +138 -0
- package/dist/pi/docs/tmux.md +61 -0
- package/dist/pi/docs/tui.md +197 -0
- package/dist/pi/docs/usage.md +94 -0
- package/dist/pi/docs/virtual-models.md +114 -0
- package/dist/pi/docs/windows.md +108 -0
- package/dist/pi/examples/README.md +36 -0
- package/dist/pi/examples/extensions/README.md +215 -0
- package/dist/pi/examples/extensions/auto-commit-on-exit.ts +49 -0
- package/dist/pi/examples/extensions/bash-spawn-hook.ts +30 -0
- package/dist/pi/examples/extensions/bookmark.ts +50 -0
- package/dist/pi/examples/extensions/border-status-editor.ts +150 -0
- package/dist/pi/examples/extensions/built-in-tool-renderer.ts +225 -0
- package/dist/pi/examples/extensions/claude-rules.ts +86 -0
- package/dist/pi/examples/extensions/commands.ts +72 -0
- package/dist/pi/examples/extensions/confirm-destructive.ts +59 -0
- package/dist/pi/examples/extensions/custom-compaction.ts +117 -0
- package/dist/pi/examples/extensions/custom-footer.ts +64 -0
- package/dist/pi/examples/extensions/custom-header.ts +73 -0
- package/dist/pi/examples/extensions/custom-provider-anthropic/index.ts +613 -0
- package/dist/pi/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
- package/dist/pi/examples/extensions/custom-provider-anthropic/package.json +19 -0
- package/dist/pi/examples/extensions/custom-provider-gitlab-duo/index.ts +405 -0
- package/dist/pi/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
- package/dist/pi/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
- package/dist/pi/examples/extensions/debug-provider.ts +90 -0
- package/dist/pi/examples/extensions/dirty-repo-guard.ts +56 -0
- package/dist/pi/examples/extensions/doom-overlay/README.md +46 -0
- package/dist/pi/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
- package/dist/pi/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/dist/pi/examples/extensions/doom-overlay/doom/build.sh +152 -0
- package/dist/pi/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
- package/dist/pi/examples/extensions/doom-overlay/doom-component.ts +132 -0
- package/dist/pi/examples/extensions/doom-overlay/doom-engine.ts +173 -0
- package/dist/pi/examples/extensions/doom-overlay/doom-keys.ts +104 -0
- package/dist/pi/examples/extensions/doom-overlay/index.ts +74 -0
- package/dist/pi/examples/extensions/doom-overlay/wad-finder.ts +55 -0
- package/dist/pi/examples/extensions/dynamic-resources/SKILL.md +8 -0
- package/dist/pi/examples/extensions/dynamic-resources/dynamic.json +81 -0
- package/dist/pi/examples/extensions/dynamic-resources/dynamic.md +5 -0
- package/dist/pi/examples/extensions/dynamic-resources/index.ts +15 -0
- package/dist/pi/examples/extensions/dynamic-tools.ts +74 -0
- package/dist/pi/examples/extensions/entry-renderer.ts +41 -0
- package/dist/pi/examples/extensions/event-bus.ts +43 -0
- package/dist/pi/examples/extensions/file-trigger.ts +41 -0
- package/dist/pi/examples/extensions/git-checkpoint.ts +53 -0
- package/dist/pi/examples/extensions/git-merge-and-resolve.ts +115 -0
- package/dist/pi/examples/extensions/github-issue-autocomplete.ts +185 -0
- package/dist/pi/examples/extensions/gondolin/index.ts +531 -0
- package/dist/pi/examples/extensions/gondolin/package-lock.json +175 -0
- package/dist/pi/examples/extensions/gondolin/package.json +19 -0
- package/dist/pi/examples/extensions/handoff.ts +190 -0
- package/dist/pi/examples/extensions/hello.ts +26 -0
- package/dist/pi/examples/extensions/hidden-thinking-label.ts +53 -0
- package/dist/pi/examples/extensions/inline-bash.ts +94 -0
- package/dist/pi/examples/extensions/input-transform-streaming.ts +39 -0
- package/dist/pi/examples/extensions/input-transform.ts +43 -0
- package/dist/pi/examples/extensions/interactive-shell.ts +196 -0
- package/dist/pi/examples/extensions/jev-router.ts +113 -0
- package/dist/pi/examples/extensions/mac-system-theme.ts +47 -0
- package/dist/pi/examples/extensions/message-renderer.ts +59 -0
- package/dist/pi/examples/extensions/minimal-mode.ts +353 -0
- package/dist/pi/examples/extensions/modal-editor.ts +85 -0
- package/dist/pi/examples/extensions/model-status.ts +31 -0
- package/dist/pi/examples/extensions/notify.ts +57 -0
- package/dist/pi/examples/extensions/overlay-qa-tests.ts +1450 -0
- package/dist/pi/examples/extensions/overlay-test.ts +153 -0
- package/dist/pi/examples/extensions/permission-gate.ts +34 -0
- package/dist/pi/examples/extensions/pirate.ts +47 -0
- package/dist/pi/examples/extensions/plan-mode/README.md +66 -0
- package/dist/pi/examples/extensions/plan-mode/index.ts +394 -0
- package/dist/pi/examples/extensions/plan-mode/utils.ts +168 -0
- package/dist/pi/examples/extensions/preset.ts +438 -0
- package/dist/pi/examples/extensions/project-trust.ts +64 -0
- package/dist/pi/examples/extensions/prompt-customizer.ts +49 -0
- package/dist/pi/examples/extensions/protected-paths.ts +30 -0
- package/dist/pi/examples/extensions/provider-payload.ts +18 -0
- package/dist/pi/examples/extensions/qna.ts +118 -0
- package/dist/pi/examples/extensions/question.ts +286 -0
- package/dist/pi/examples/extensions/questionnaire.ts +448 -0
- package/dist/pi/examples/extensions/rainbow-editor.ts +88 -0
- package/dist/pi/examples/extensions/reload-runtime.ts +49 -0
- package/dist/pi/examples/extensions/rpc-demo.ts +118 -0
- package/dist/pi/examples/extensions/send-user-message.ts +97 -0
- package/dist/pi/examples/extensions/session-name.ts +27 -0
- package/dist/pi/examples/extensions/shutdown-command.ts +63 -0
- package/dist/pi/examples/extensions/snake.ts +343 -0
- package/dist/pi/examples/extensions/space-invaders.ts +560 -0
- package/dist/pi/examples/extensions/ssh.ts +220 -0
- package/dist/pi/examples/extensions/status-line.ts +32 -0
- package/dist/pi/examples/extensions/structured-output.ts +65 -0
- package/dist/pi/examples/extensions/subagent/README.md +177 -0
- package/dist/pi/examples/extensions/subagent/agents/planner.md +37 -0
- package/dist/pi/examples/extensions/subagent/agents/reviewer.md +35 -0
- package/dist/pi/examples/extensions/subagent/agents/scout.md +50 -0
- package/dist/pi/examples/extensions/subagent/agents/worker.md +24 -0
- package/dist/pi/examples/extensions/subagent/agents.ts +157 -0
- package/dist/pi/examples/extensions/subagent/index.ts +1036 -0
- package/dist/pi/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
- package/dist/pi/examples/extensions/subagent/prompts/implement.md +10 -0
- package/dist/pi/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
- package/dist/pi/examples/extensions/summarize.ts +199 -0
- package/dist/pi/examples/extensions/system-prompt-header.ts +17 -0
- package/dist/pi/examples/extensions/tic-tac-toe.ts +1008 -0
- package/dist/pi/examples/extensions/timed-confirm.ts +70 -0
- package/dist/pi/examples/extensions/titlebar-spinner.ts +58 -0
- package/dist/pi/examples/extensions/todo.ts +304 -0
- package/dist/pi/examples/extensions/tool-override.ts +144 -0
- package/dist/pi/examples/extensions/tools.ts +148 -0
- package/dist/pi/examples/extensions/trigger-compact.ts +50 -0
- package/dist/pi/examples/extensions/truncated-tool.ts +195 -0
- package/dist/pi/examples/extensions/widget-placement.ts +9 -0
- package/dist/pi/examples/extensions/with-deps/index.ts +32 -0
- package/dist/pi/examples/extensions/with-deps/package-lock.json +31 -0
- package/dist/pi/examples/extensions/with-deps/package.json +22 -0
- package/dist/pi/examples/extensions/working-indicator.ts +123 -0
- package/dist/pi/examples/extensions/working-message-test.ts +25 -0
- package/dist/pi/examples/rpc-client.ts +35 -0
- package/dist/pi/examples/rpc-extension-ui.ts +661 -0
- package/dist/pi/examples/sdk/01-minimal.ts +26 -0
- package/dist/pi/examples/sdk/02-custom-model.ts +49 -0
- package/dist/pi/examples/sdk/03-custom-prompt.ts +75 -0
- package/dist/pi/examples/sdk/04-skills.ts +55 -0
- package/dist/pi/examples/sdk/05-tools.ts +48 -0
- package/dist/pi/examples/sdk/06-extensions.ts +99 -0
- package/dist/pi/examples/sdk/07-context-files.ts +47 -0
- package/dist/pi/examples/sdk/08-prompt-templates.ts +51 -0
- package/dist/pi/examples/sdk/09-api-keys-and-oauth.ts +34 -0
- package/dist/pi/examples/sdk/10-settings.ts +53 -0
- package/dist/pi/examples/sdk/11-sessions.ts +52 -0
- package/dist/pi/examples/sdk/12-full-control.ts +74 -0
- package/dist/pi/examples/sdk/13-session-runtime.ts +67 -0
- package/dist/pi/examples/sdk/14-codemode-mcp.ts +61 -0
- package/dist/pi/examples/sdk/README.md +141 -0
- package/dist/pi/examples/tsconfig.json +180 -0
- package/dist/pi/package.json +9 -0
- package/dist/serve/index.mjs +16495 -0
- package/package.json +58 -4
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session runtime
|
|
3
|
+
*
|
|
4
|
+
* Use AgentSessionRuntime when you need to replace the active AgentSession,
|
|
5
|
+
* for example for new-session, resume, fork, or import flows.
|
|
6
|
+
*
|
|
7
|
+
* The important pattern is: after the runtime replaces the active session,
|
|
8
|
+
* rebind any session-local subscriptions and extension bindings to `runtime.session`.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
type CreateAgentSessionRuntimeFactory,
|
|
13
|
+
createAgentSessionFromServices,
|
|
14
|
+
createAgentSessionRuntime,
|
|
15
|
+
createAgentSessionServices,
|
|
16
|
+
getAgentDir,
|
|
17
|
+
SessionManager,
|
|
18
|
+
} from "@earendil-works/pi-coding-agent";
|
|
19
|
+
|
|
20
|
+
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
21
|
+
const services = await createAgentSessionServices({ cwd });
|
|
22
|
+
return {
|
|
23
|
+
...(await createAgentSessionFromServices({
|
|
24
|
+
services,
|
|
25
|
+
sessionManager,
|
|
26
|
+
sessionStartEvent,
|
|
27
|
+
})),
|
|
28
|
+
services,
|
|
29
|
+
diagnostics: services.diagnostics,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
33
|
+
cwd: process.cwd(),
|
|
34
|
+
agentDir: getAgentDir(),
|
|
35
|
+
sessionManager: SessionManager.create(process.cwd()),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
let unsubscribe: (() => void) | undefined;
|
|
39
|
+
|
|
40
|
+
async function bindSession() {
|
|
41
|
+
unsubscribe?.();
|
|
42
|
+
const session = runtime.session;
|
|
43
|
+
await session.bindExtensions({});
|
|
44
|
+
unsubscribe = session.subscribe((event) => {
|
|
45
|
+
if (event.type === "queue_update") {
|
|
46
|
+
console.log("Queued:", event.steering.length + event.followUp.length);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return session;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let session = await bindSession();
|
|
53
|
+
const originalSessionFile = session.sessionFile;
|
|
54
|
+
console.log("Initial session:", originalSessionFile);
|
|
55
|
+
|
|
56
|
+
await runtime.newSession();
|
|
57
|
+
session = await bindSession();
|
|
58
|
+
console.log("After newSession():", session.sessionFile);
|
|
59
|
+
|
|
60
|
+
if (originalSessionFile) {
|
|
61
|
+
await runtime.switchSession(originalSessionFile);
|
|
62
|
+
session = await bindSession();
|
|
63
|
+
console.log("After switchSession():", session.sessionFile);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
unsubscribe?.();
|
|
67
|
+
await runtime.dispose();
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codemode, Tool Search, and MCP
|
|
3
|
+
*
|
|
4
|
+
* The CLI loads `codemode`, `tool_search`, and MCP as built-in extensions. SDK sessions add
|
|
5
|
+
* them to the resource loader's extension factories.
|
|
6
|
+
*
|
|
7
|
+
* `codemode` and `tool_search` are registered inactive. Enable them through the `defaultTools` setting
|
|
8
|
+
* (`tools` would also restrict the session to the named tools, which hides MCP tools), or let the
|
|
9
|
+
* MCP extension activate them: `codemode` for servers with `codemode` exposure, `tool_search` for
|
|
10
|
+
* servers with `deferred` exposure.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
createAgentSession,
|
|
15
|
+
createCodemodeExtension,
|
|
16
|
+
createMcpExtension,
|
|
17
|
+
createToolSearchExtension,
|
|
18
|
+
DefaultResourceLoader,
|
|
19
|
+
getAgentDir,
|
|
20
|
+
SessionManager,
|
|
21
|
+
SettingsManager,
|
|
22
|
+
} from "@earendil-works/pi-coding-agent";
|
|
23
|
+
|
|
24
|
+
const cwd = process.cwd();
|
|
25
|
+
|
|
26
|
+
const resourceLoader = new DefaultResourceLoader({
|
|
27
|
+
cwd,
|
|
28
|
+
agentDir: getAgentDir(),
|
|
29
|
+
extensionFactories: [
|
|
30
|
+
createCodemodeExtension({ mode: "on" }),
|
|
31
|
+
createToolSearchExtension(),
|
|
32
|
+
// Reads mcp.json from the agent directory and the trusted project, like the CLI.
|
|
33
|
+
createMcpExtension(),
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
await resourceLoader.reload();
|
|
37
|
+
|
|
38
|
+
const settingsManager = SettingsManager.create(cwd);
|
|
39
|
+
// `+name` adds to the configured default tools instead of replacing them.
|
|
40
|
+
settingsManager.applyOverrides({ defaultTools: ["+codemode", "+tool_search"] });
|
|
41
|
+
|
|
42
|
+
const { session } = await createAgentSession({
|
|
43
|
+
resourceLoader,
|
|
44
|
+
settingsManager,
|
|
45
|
+
sessionManager: SessionManager.inMemory(),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
// Emits session_start, which connects the MCP servers in the background.
|
|
50
|
+
await session.bindExtensions({});
|
|
51
|
+
console.log("Active tools:", session.getActiveToolNames().join(", "));
|
|
52
|
+
session.subscribe((event) => {
|
|
53
|
+
if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
|
|
54
|
+
process.stdout.write(event.assistantMessageEvent.delta);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
await session.prompt("Use codemode to count the TypeScript files in src/ and list the three largest.");
|
|
58
|
+
console.log();
|
|
59
|
+
} finally {
|
|
60
|
+
session.dispose();
|
|
61
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# SDK Examples
|
|
2
|
+
|
|
3
|
+
Programmatic usage of pi-coding-agent via `createAgentSession()` and `createAgentSessionRuntime()`.
|
|
4
|
+
|
|
5
|
+
The runtime example shows how to build a recreate function that closes over process-global fixed inputs and recreates cwd-bound services and sessions as the active session cwd changes.
|
|
6
|
+
|
|
7
|
+
## Examples
|
|
8
|
+
|
|
9
|
+
| File | Description |
|
|
10
|
+
|------|-------------|
|
|
11
|
+
| `01-minimal.ts` | Simplest usage with all defaults |
|
|
12
|
+
| `02-custom-model.ts` | Select model and thinking level |
|
|
13
|
+
| `03-custom-prompt.ts` | Replace or modify system prompt |
|
|
14
|
+
| `04-skills.ts` | Discover, filter, or replace skills |
|
|
15
|
+
| `05-tools.ts` | Built-in tool allowlists |
|
|
16
|
+
| `06-extensions.ts` | Logging, blocking, result modification |
|
|
17
|
+
| `07-context-files.ts` | AGENTS.md context files |
|
|
18
|
+
| `08-prompt-templates.ts` | File-based prompt templates |
|
|
19
|
+
| `09-api-keys-and-oauth.ts` | API key resolution, OAuth config |
|
|
20
|
+
| `10-settings.ts` | Override compaction, retry, terminal settings |
|
|
21
|
+
| `11-sessions.ts` | In-memory, persistent, continue, list sessions |
|
|
22
|
+
| `12-full-control.ts` | Replace everything, no discovery |
|
|
23
|
+
| `13-session-runtime.ts` | Manage runtime-backed session replacement |
|
|
24
|
+
| `14-codemode-mcp.ts` | Add the `codemode`, `tool_search`, and MCP extensions |
|
|
25
|
+
|
|
26
|
+
## Running
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
cd packages/coding-agent
|
|
30
|
+
node examples/sdk/01-minimal.ts
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick Reference
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { getModel } from "@earendil-works/pi-ai";
|
|
37
|
+
import {
|
|
38
|
+
createAgentSession,
|
|
39
|
+
DefaultResourceLoader,
|
|
40
|
+
ModelRuntime,
|
|
41
|
+
SessionManager,
|
|
42
|
+
SettingsManager,
|
|
43
|
+
} from "@earendil-works/pi-coding-agent";
|
|
44
|
+
|
|
45
|
+
const modelRuntime = await ModelRuntime.create();
|
|
46
|
+
|
|
47
|
+
// Minimal
|
|
48
|
+
const { session } = await createAgentSession({ modelRuntime });
|
|
49
|
+
|
|
50
|
+
// Custom model
|
|
51
|
+
const model = getModel("anthropic", "claude-opus-4-5");
|
|
52
|
+
const { session } = await createAgentSession({ model, thinkingLevel: "high", modelRuntime });
|
|
53
|
+
|
|
54
|
+
// Modify prompt
|
|
55
|
+
const loader = new DefaultResourceLoader({
|
|
56
|
+
systemPromptOverride: (base) => `${base}\n\nBe concise.`,
|
|
57
|
+
});
|
|
58
|
+
await loader.reload();
|
|
59
|
+
const { session } = await createAgentSession({ resourceLoader: loader, modelRuntime });
|
|
60
|
+
|
|
61
|
+
// Read-only
|
|
62
|
+
const { session } = await createAgentSession({ tools: ["read", "grep", "find", "ls"], modelRuntime });
|
|
63
|
+
|
|
64
|
+
// In-memory
|
|
65
|
+
const { session } = await createAgentSession({
|
|
66
|
+
sessionManager: SessionManager.inMemory(),
|
|
67
|
+
modelRuntime,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Full control
|
|
71
|
+
const customRuntime = await ModelRuntime.create({
|
|
72
|
+
authPath: "/my/app/auth.json",
|
|
73
|
+
modelsPath: "/my/app/models.json",
|
|
74
|
+
});
|
|
75
|
+
await customRuntime.setRuntimeApiKey("anthropic", process.env.MY_KEY!);
|
|
76
|
+
|
|
77
|
+
const resourceLoader = new DefaultResourceLoader({
|
|
78
|
+
systemPromptOverride: () => "You are helpful.",
|
|
79
|
+
extensionFactories: [myExtension],
|
|
80
|
+
skillsOverride: () => ({ skills: [], diagnostics: [] }),
|
|
81
|
+
agentsFilesOverride: () => ({ agentsFiles: [] }),
|
|
82
|
+
promptsOverride: () => ({ prompts: [], diagnostics: [] }),
|
|
83
|
+
});
|
|
84
|
+
await resourceLoader.reload();
|
|
85
|
+
|
|
86
|
+
const { session } = await createAgentSession({
|
|
87
|
+
model,
|
|
88
|
+
modelRuntime: customRuntime,
|
|
89
|
+
resourceLoader,
|
|
90
|
+
tools: ["read", "bash", "my_tool"],
|
|
91
|
+
customTools: [myTool],
|
|
92
|
+
sessionManager: SessionManager.inMemory(),
|
|
93
|
+
settingsManager: SettingsManager.inMemory(),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Run prompts
|
|
97
|
+
session.subscribe((event) => {
|
|
98
|
+
if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
|
|
99
|
+
process.stdout.write(event.assistantMessageEvent.delta);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
await session.prompt("Hello");
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Options
|
|
106
|
+
|
|
107
|
+
| Option | Default | Description |
|
|
108
|
+
|--------|---------|-------------|
|
|
109
|
+
| `modelRuntime` | Runtime using `agentDir/auth.json` and `models.json` | Canonical model and authentication runtime |
|
|
110
|
+
| `cwd` | `process.cwd()` | Working directory |
|
|
111
|
+
| `agentDir` | `~/.pi/agent` | Config directory |
|
|
112
|
+
| `model` | From settings/first available | Model to use |
|
|
113
|
+
| `thinkingLevel` | From settings/"off" | off, low, medium, high |
|
|
114
|
+
| `tools` | `["read", "bash", "edit", "write"]` built-ins | Allowlist tool names across built-in, extension, and custom tools |
|
|
115
|
+
| `customTools` | `[]` | Additional tool definitions |
|
|
116
|
+
| `resourceLoader` | DefaultResourceLoader | Resource loader for extensions, skills, prompts, themes, and context files |
|
|
117
|
+
| `sessionManager` | `SessionManager.create(cwd)` | Persistence |
|
|
118
|
+
| `settingsManager` | `SettingsManager.create(cwd, agentDir)` | Settings overrides |
|
|
119
|
+
|
|
120
|
+
## Events
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
session.subscribe((event) => {
|
|
124
|
+
switch (event.type) {
|
|
125
|
+
case "message_update":
|
|
126
|
+
if (event.assistantMessageEvent.type === "text_delta") {
|
|
127
|
+
process.stdout.write(event.assistantMessageEvent.delta);
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
case "tool_execution_start":
|
|
131
|
+
console.log(`Tool: ${event.toolName}`);
|
|
132
|
+
break;
|
|
133
|
+
case "tool_execution_end":
|
|
134
|
+
console.log(`Result: ${event.result}`);
|
|
135
|
+
break;
|
|
136
|
+
case "agent_settled":
|
|
137
|
+
console.log("Done");
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
```
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// Type-checks the example extensions against the modules extensions see at run time (core/extensions/virtual-modules.ts):
|
|
2
|
+
// "@earendil-works/pi-ai" is the extension view, which adds TypeBox's Type, Static and TSchema to the compat entry (the
|
|
3
|
+
// view imports "@earendil-works/pi-ai/compat", so that path stays the package's own).
|
|
4
|
+
// The other paths repeat the root tsconfig.json; keep them in sync.
|
|
5
|
+
// Also the test that imports the subagent example: it type-checks only against the extension view.
|
|
6
|
+
{
|
|
7
|
+
"extends": "../../../tsconfig.json",
|
|
8
|
+
"compilerOptions": {
|
|
9
|
+
"paths": {
|
|
10
|
+
"@earendil-works/chord": [
|
|
11
|
+
"../../../packages/chord/src/index.ts"
|
|
12
|
+
],
|
|
13
|
+
"@earendil-works/chord/context": [
|
|
14
|
+
"../../../packages/chord/src/context/index.ts"
|
|
15
|
+
],
|
|
16
|
+
"@earendil-works/chord/delta": [
|
|
17
|
+
"../../../packages/chord/src/delta/index.ts"
|
|
18
|
+
],
|
|
19
|
+
"@earendil-works/chord/next": [
|
|
20
|
+
"../../../packages/chord/src/next/index.ts"
|
|
21
|
+
],
|
|
22
|
+
"@earendil-works/chord/next/plugins": [
|
|
23
|
+
"../../../packages/chord/src/next-node/plugins/index.ts"
|
|
24
|
+
],
|
|
25
|
+
"@earendil-works/chord/next/plugins/runtime": [
|
|
26
|
+
"../../../packages/chord/src/next-node/plugins/runtime.ts"
|
|
27
|
+
],
|
|
28
|
+
"@test/contracts/*": [
|
|
29
|
+
"../../../packages/chord/test/next-node/fixtures/plugins/contracts/*.ts"
|
|
30
|
+
],
|
|
31
|
+
"@example/contracts/*": [
|
|
32
|
+
"../../../packages/chord/test/next/examples/35-plugins/plugins/contracts/*.ts"
|
|
33
|
+
],
|
|
34
|
+
"@example/weather/*": [
|
|
35
|
+
"../../../packages/chord/test/next/examples/36-plugin-failures/plugins/weather/*.ts"
|
|
36
|
+
],
|
|
37
|
+
"@example/prices/*": [
|
|
38
|
+
"../../../packages/chord/test/next/examples/36-plugin-failures/plugins/prices/*.ts"
|
|
39
|
+
],
|
|
40
|
+
"@example/shapes/*": [
|
|
41
|
+
"../../../packages/chord/test/next/examples/37-plugin-imports/plugins/shapes/*.ts"
|
|
42
|
+
],
|
|
43
|
+
"@example/shared/*": [
|
|
44
|
+
"../../../packages/chord/test/next/examples/38-watch-and-rollout/plugins/contracts/*.ts"
|
|
45
|
+
],
|
|
46
|
+
"@earendil-works/chord/next/http": [
|
|
47
|
+
"../../../packages/chord/src/next-node/http/index.ts"
|
|
48
|
+
],
|
|
49
|
+
"@earendil-works/chord/next/workers": [
|
|
50
|
+
"../../../packages/chord/src/next-node/workers/index.ts"
|
|
51
|
+
],
|
|
52
|
+
"@earendil-works/chord/node": [
|
|
53
|
+
"../../../packages/chord/src/node.ts"
|
|
54
|
+
],
|
|
55
|
+
"@earendil-works/chord/output": [
|
|
56
|
+
"../../../packages/chord/src/output.ts"
|
|
57
|
+
],
|
|
58
|
+
"@earendil-works/chord/telemetry-sqlite": [
|
|
59
|
+
"../../../packages/chord/src/telemetry-sqlite/index.ts"
|
|
60
|
+
],
|
|
61
|
+
"@earendil-works/chord/sqlite": [
|
|
62
|
+
"../../../packages/chord/src/sqlite/index.ts"
|
|
63
|
+
],
|
|
64
|
+
"@earendil-works/chord/sqlite/node": [
|
|
65
|
+
"../../../packages/chord/src/sqlite/node.ts"
|
|
66
|
+
],
|
|
67
|
+
"@earendil-works/chord/sqlite/cloudflare": [
|
|
68
|
+
"../../../packages/chord/src/sqlite/cloudflare.ts"
|
|
69
|
+
],
|
|
70
|
+
"@earendil-works/pi-telemetry": [
|
|
71
|
+
"../../../packages/telemetry/src/index.ts"
|
|
72
|
+
],
|
|
73
|
+
"@earendil-works/pi-telemetry/testing": [
|
|
74
|
+
"../../../packages/telemetry/src/testing/index.ts"
|
|
75
|
+
],
|
|
76
|
+
"@earendil-works/pi-telemetry/render": [
|
|
77
|
+
"../../../packages/telemetry/src/render.ts"
|
|
78
|
+
],
|
|
79
|
+
"@earendil-works/pi-codemode": [
|
|
80
|
+
"../../../packages/codemode/src/index.ts"
|
|
81
|
+
],
|
|
82
|
+
"@earendil-works/pi-codemode/cloudflare": [
|
|
83
|
+
"../../../packages/codemode/src/cloudflare.ts"
|
|
84
|
+
],
|
|
85
|
+
"@earendil-works/pi-codemode/declarations": [
|
|
86
|
+
"../../../packages/codemode/src/declarations.ts"
|
|
87
|
+
],
|
|
88
|
+
"@earendil-works/pi-codemode/portable": [
|
|
89
|
+
"../../../packages/codemode/src/portable.ts"
|
|
90
|
+
],
|
|
91
|
+
"@earendil-works/pi-codemode/source": [
|
|
92
|
+
"../../../packages/codemode/src/source.ts"
|
|
93
|
+
],
|
|
94
|
+
"@earendil-works/pi-codemode/worker": [
|
|
95
|
+
"../../../packages/codemode/src/runtime/worker.ts"
|
|
96
|
+
],
|
|
97
|
+
"@earendil-works/pi-schema": [
|
|
98
|
+
"../../../packages/schema/src/index.ts"
|
|
99
|
+
],
|
|
100
|
+
"@earendil-works/pi-schema/formats": [
|
|
101
|
+
"../../../packages/schema/src/formats/index.ts"
|
|
102
|
+
],
|
|
103
|
+
"@earendil-works/pi-mcp": [
|
|
104
|
+
"../../../packages/mcp/src/index.ts"
|
|
105
|
+
],
|
|
106
|
+
"@earendil-works/pi-mcp/oauth": [
|
|
107
|
+
"../../../packages/mcp/src/oauth/index.ts"
|
|
108
|
+
],
|
|
109
|
+
"@earendil-works/pi-mcp/testing": [
|
|
110
|
+
"../../../packages/mcp/src/testing/index.ts"
|
|
111
|
+
],
|
|
112
|
+
"@earendil-works/pi-ai": [
|
|
113
|
+
"../../../packages/coding-agent/src/core/extensions/pi-ai-extension-view.ts"
|
|
114
|
+
],
|
|
115
|
+
"@earendil-works/pi-ai/oauth": [
|
|
116
|
+
"../../../packages/ai/src/oauth.ts"
|
|
117
|
+
],
|
|
118
|
+
"@earendil-works/pi-ai/*": [
|
|
119
|
+
"../../../packages/ai/src/*.ts",
|
|
120
|
+
"../../../packages/ai/src/providers/*.ts"
|
|
121
|
+
],
|
|
122
|
+
"@earendil-works/pi-ai/dist/*": [
|
|
123
|
+
"../../../packages/ai/src/*"
|
|
124
|
+
],
|
|
125
|
+
"@earendil-works/pi-durable": [
|
|
126
|
+
"../../../packages/durable/src/index.ts"
|
|
127
|
+
],
|
|
128
|
+
"@earendil-works/pi-durable/testing": [
|
|
129
|
+
"../../../packages/durable/src/testing/index.ts"
|
|
130
|
+
],
|
|
131
|
+
"@earendil-works/pi-durable/*": [
|
|
132
|
+
"../../../packages/durable/src/*.ts",
|
|
133
|
+
"../../../packages/durable/src/*/index.ts",
|
|
134
|
+
"../../../packages/durable/src/*"
|
|
135
|
+
],
|
|
136
|
+
"@earendil-works/pi-env": [
|
|
137
|
+
"../../../packages/env/src/index.ts"
|
|
138
|
+
],
|
|
139
|
+
"@earendil-works/pi-agent-core": [
|
|
140
|
+
"../../../packages/agent/src/index.ts"
|
|
141
|
+
],
|
|
142
|
+
"@earendil-works/pi-coding-agent": [
|
|
143
|
+
"../../../packages/coding-agent/src/index.ts"
|
|
144
|
+
],
|
|
145
|
+
"@earendil-works/pi-coding-agent/hooks": [
|
|
146
|
+
"../../../packages/coding-agent/src/core/hooks/index.ts"
|
|
147
|
+
],
|
|
148
|
+
"@earendil-works/pi-coding-agent/*": [
|
|
149
|
+
"../../../packages/coding-agent/src/*"
|
|
150
|
+
],
|
|
151
|
+
"typebox": [
|
|
152
|
+
"../../../node_modules/typebox"
|
|
153
|
+
],
|
|
154
|
+
"@earendil-works/pi-tui": [
|
|
155
|
+
"../../../packages/tui/src/index.ts"
|
|
156
|
+
],
|
|
157
|
+
"@earendil-works/pi-tui/*": [
|
|
158
|
+
"../../../packages/tui/src/*"
|
|
159
|
+
],
|
|
160
|
+
"@earendil-works/pi-agent-old": [
|
|
161
|
+
"../../../packages/agent-old/src/index.ts"
|
|
162
|
+
],
|
|
163
|
+
"@earendil-works/pi-agent-old/*": [
|
|
164
|
+
"../../../packages/agent-old/src/*"
|
|
165
|
+
],
|
|
166
|
+
"@mariozechner/pi-ai": [
|
|
167
|
+
"../../../packages/coding-agent/src/core/extensions/pi-ai-extension-view.ts"
|
|
168
|
+
]
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
"include": [
|
|
172
|
+
"./extensions/**/*",
|
|
173
|
+
"../../*/src/**/*.d.ts",
|
|
174
|
+
"../test/suite/regressions/8261-subagent-project-trust.test.ts"
|
|
175
|
+
],
|
|
176
|
+
"exclude": [
|
|
177
|
+
"**/node_modules/**",
|
|
178
|
+
"./extensions/gondolin/**"
|
|
179
|
+
]
|
|
180
|
+
}
|