@astralyn/pi 0.87.0 → 0.87.2
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/CHANGELOG.md +31 -0
- package/dist/bundle/chunks/{anthropic-messages-R2LYJUDD.js → anthropic-messages-XWFTZP2N.js} +1 -1
- package/dist/bundle/chunks/{chunk-INDBRWNK.js → chunk-NBIUJDV6.js} +1 -1
- package/dist/bundle/chunks/{chunk-RKLIHRPH.js → chunk-RFLBIA5Z.js} +82 -82
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/{openai-completions-JZCEEJ43.js → openai-completions-SHS3CAEL.js} +1 -1
- package/dist/bundle/chunks/{virtual-modules-CG7NJ5WO.js → virtual-modules-GOHLE5JL.js} +1 -1
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +14 -4
- package/dist/cli/args.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +9 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +158 -157
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +30 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +514 -443
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/background/service.d.ts +9 -0
- package/dist/core/background/service.d.ts.map +1 -1
- package/dist/core/background/service.js +13 -1
- package/dist/core/background/service.js.map +1 -1
- package/dist/core/background/session.d.ts +5 -0
- package/dist/core/background/session.d.ts.map +1 -1
- package/dist/core/background/session.js +2 -1
- package/dist/core/background/session.js.map +1 -1
- package/dist/core/background/types.d.ts +2 -0
- package/dist/core/background/types.d.ts.map +1 -1
- package/dist/core/background/types.js.map +1 -1
- package/dist/core/compaction/compaction.js +9 -9
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/extensions/distribution-api.d.ts +41 -0
- package/dist/core/extensions/distribution-api.d.ts.map +1 -0
- package/dist/core/extensions/distribution-api.js +12 -0
- package/dist/core/extensions/distribution-api.js.map +1 -0
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +1 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +0 -2
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +15 -45
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +1 -11
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/virtual-modules.js +2 -1
- package/dist/core/extensions/virtual-modules.js.map +1 -1
- package/dist/core/keybinding-registry.d.ts +11 -0
- package/dist/core/keybinding-registry.d.ts.map +1 -0
- package/dist/core/keybinding-registry.js +24 -0
- package/dist/core/keybinding-registry.js.map +1 -0
- package/dist/core/keybindings.d.ts +4 -64
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +2 -41
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-config.d.ts +70 -2
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +2 -26
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver.js +1 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +5 -11
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +2 -2
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/shell-execution.d.ts +1 -0
- package/dist/core/tools/shell-execution.d.ts.map +1 -1
- package/dist/core/tools/shell-execution.js +21 -0
- package/dist/core/tools/shell-execution.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +11 -48
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/extensions/background/index.d.ts +2 -0
- package/dist/extensions/background/index.d.ts.map +1 -1
- package/dist/extensions/background/index.js +17 -0
- package/dist/extensions/background/index.js.map +1 -1
- package/dist/extensions/background/keybindings.d.ts +10 -0
- package/dist/extensions/background/keybindings.d.ts.map +1 -0
- package/dist/extensions/background/keybindings.js +14 -0
- package/dist/extensions/background/keybindings.js.map +1 -0
- package/dist/extensions/background/manager.d.ts +2 -0
- package/dist/extensions/background/manager.d.ts.map +1 -1
- package/dist/extensions/background/manager.js +1 -0
- package/dist/extensions/background/manager.js.map +1 -1
- package/dist/extensions/btw/controller.d.ts +1 -0
- package/dist/extensions/btw/controller.d.ts.map +1 -1
- package/dist/extensions/btw/controller.js +5 -5
- package/dist/extensions/btw/controller.js.map +1 -1
- package/dist/extensions/btw/index.js +1 -2
- package/dist/extensions/btw/index.js.map +1 -1
- package/dist/extensions/btw/keybindings.d.ts +10 -0
- package/dist/extensions/btw/keybindings.d.ts.map +1 -0
- package/dist/extensions/btw/keybindings.js +8 -0
- package/dist/extensions/btw/keybindings.js.map +1 -0
- package/dist/extensions/btw/panel.d.ts +1 -0
- package/dist/extensions/btw/panel.d.ts.map +1 -1
- package/dist/extensions/btw/panel.js +1 -0
- package/dist/extensions/btw/panel.js.map +1 -1
- package/dist/extensions/list-keybindings.d.ts +8 -0
- package/dist/extensions/list-keybindings.d.ts.map +1 -0
- package/dist/extensions/list-keybindings.js +8 -0
- package/dist/extensions/list-keybindings.js.map +1 -0
- package/dist/extensions/provider/compat-fields.d.ts.map +1 -1
- package/dist/extensions/provider/compat-fields.js +23 -3
- package/dist/extensions/provider/compat-fields.js.map +1 -1
- package/dist/extensions/provider/connection.d.ts.map +1 -1
- package/dist/extensions/provider/connection.js +1 -1
- package/dist/extensions/provider/connection.js.map +1 -1
- package/dist/extensions/provider/constants.d.ts +2 -0
- package/dist/extensions/provider/constants.d.ts.map +1 -1
- package/dist/extensions/provider/constants.js +2 -0
- package/dist/extensions/provider/constants.js.map +1 -1
- package/dist/extensions/provider/keybindings.d.ts +9 -0
- package/dist/extensions/provider/keybindings.d.ts.map +1 -0
- package/dist/extensions/provider/keybindings.js +12 -0
- package/dist/extensions/provider/keybindings.js.map +1 -0
- package/dist/extensions/provider/probe.d.ts +8 -4
- package/dist/extensions/provider/probe.d.ts.map +1 -1
- package/dist/extensions/provider/probe.js +169 -11
- package/dist/extensions/provider/probe.js.map +1 -1
- package/dist/extensions/provider/ui/builtin-data.d.ts +1 -0
- package/dist/extensions/provider/ui/builtin-data.d.ts.map +1 -1
- package/dist/extensions/provider/ui/builtin-data.js +1 -0
- package/dist/extensions/provider/ui/builtin-data.js.map +1 -1
- package/dist/extensions/provider/ui/compat.d.ts +1 -0
- package/dist/extensions/provider/ui/compat.d.ts.map +1 -1
- package/dist/extensions/provider/ui/compat.js +1 -0
- package/dist/extensions/provider/ui/compat.js.map +1 -1
- package/dist/extensions/provider/ui/dictionary.d.ts +1 -0
- package/dist/extensions/provider/ui/dictionary.d.ts.map +1 -1
- package/dist/extensions/provider/ui/dictionary.js +1 -0
- package/dist/extensions/provider/ui/dictionary.js.map +1 -1
- package/dist/extensions/provider/ui/editor.d.ts +1 -0
- package/dist/extensions/provider/ui/editor.d.ts.map +1 -1
- package/dist/extensions/provider/ui/editor.js +1 -0
- package/dist/extensions/provider/ui/editor.js.map +1 -1
- package/dist/extensions/provider/ui/fetch-models.d.ts +5 -3
- package/dist/extensions/provider/ui/fetch-models.d.ts.map +1 -1
- package/dist/extensions/provider/ui/fetch-models.js +28 -3
- package/dist/extensions/provider/ui/fetch-models.js.map +1 -1
- package/dist/extensions/provider/ui/model-fields.d.ts +1 -0
- package/dist/extensions/provider/ui/model-fields.d.ts.map +1 -1
- package/dist/extensions/provider/ui/model-fields.js +1 -0
- package/dist/extensions/provider/ui/model-fields.js.map +1 -1
- package/dist/extensions/provider/ui/model-options.d.ts +1 -0
- package/dist/extensions/provider/ui/model-options.d.ts.map +1 -1
- package/dist/extensions/provider/ui/model-options.js +1 -0
- package/dist/extensions/provider/ui/model-options.js.map +1 -1
- package/dist/extensions/provider/ui/provider-fields.d.ts +1 -0
- package/dist/extensions/provider/ui/provider-fields.d.ts.map +1 -1
- package/dist/extensions/provider/ui/provider-fields.js +1 -0
- package/dist/extensions/provider/ui/provider-fields.js.map +1 -1
- package/dist/extensions/question/dialog.d.ts +1 -0
- package/dist/extensions/question/dialog.d.ts.map +1 -1
- package/dist/extensions/question/dialog.js +1 -0
- package/dist/extensions/question/dialog.js.map +1 -1
- package/dist/extensions/question/keybindings.d.ts +2 -0
- package/dist/extensions/question/keybindings.d.ts.map +1 -0
- package/dist/extensions/question/keybindings.js +3 -0
- package/dist/extensions/question/keybindings.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/editor-host.d.ts +43 -0
- package/dist/modes/interactive/editor-host.d.ts.map +1 -0
- package/dist/modes/interactive/editor-host.js +83 -0
- package/dist/modes/interactive/editor-host.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +1 -11
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +300 -360
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/tool-chat.d.ts +21 -0
- package/dist/modes/interactive/tool-chat.d.ts.map +1 -0
- package/dist/modes/interactive/tool-chat.js +58 -0
- package/dist/modes/interactive/tool-chat.js.map +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +0 -2
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/utils/path-identity.d.ts +12 -0
- package/dist/utils/path-identity.d.ts.map +1 -0
- package/dist/utils/path-identity.js +63 -0
- package/dist/utils/path-identity.js.map +1 -0
- package/dist/utils/shell.d.ts +0 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +0 -21
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts +2 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +2 -0
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/docs/bundled/extensions/background.md +3 -3
- package/docs/bundled/extensions/provider.md +7 -3
- package/docs/bundled/extensions/subagent.md +1 -1
- package/docs/compaction.md +1 -1
- package/docs/extensions.md +15 -5
- package/docs/sdk.md +1 -1
- package/docs/usage.md +3 -0
- package/examples/README.md +11 -1
- package/examples/extensions/README.md +34 -14
- package/examples/extensions/auto-commit-on-exit.ts +1 -1
- package/examples/extensions/bash-spawn-hook.ts +2 -2
- package/examples/extensions/bookmark.ts +1 -1
- package/examples/extensions/border-status-editor.ts +6 -1
- package/examples/extensions/built-in-tool-renderer.ts +2 -2
- package/examples/extensions/claude-rules.ts +1 -1
- package/examples/extensions/commands.ts +1 -1
- package/examples/extensions/confirm-destructive.ts +1 -1
- package/examples/extensions/custom-compaction.ts +2 -2
- package/examples/extensions/custom-footer.ts +1 -1
- package/examples/extensions/custom-header.ts +2 -2
- package/examples/extensions/custom-provider-anthropic/index.ts +6 -6
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +3 -3
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/dirty-repo-guard.ts +1 -1
- package/examples/extensions/doom-overlay/index.ts +1 -1
- package/examples/extensions/dynamic-resources/dynamic.json +3 -1
- package/examples/extensions/dynamic-resources/index.ts +1 -1
- package/examples/extensions/dynamic-tools.ts +1 -1
- package/examples/extensions/entry-renderer.ts +1 -1
- package/examples/extensions/event-bus.ts +1 -1
- package/examples/extensions/file-trigger.ts +1 -1
- package/examples/extensions/git-checkpoint.ts +1 -1
- package/examples/extensions/git-merge-and-resolve.ts +1 -1
- package/examples/extensions/github-issue-autocomplete.ts +1 -1
- package/examples/extensions/gondolin/index.ts +9 -7
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/handoff.ts +2 -2
- package/examples/extensions/hello.ts +1 -1
- package/examples/extensions/hidden-thinking-label.ts +1 -1
- package/examples/extensions/inline-bash.ts +1 -1
- package/examples/extensions/input-transform-streaming.ts +1 -1
- package/examples/extensions/input-transform.ts +1 -1
- package/examples/extensions/interactive-shell.ts +1 -1
- package/examples/extensions/mac-system-theme.ts +1 -1
- package/examples/extensions/message-renderer.ts +1 -1
- package/examples/extensions/minimal-mode.ts +2 -2
- package/examples/extensions/modal-editor.ts +1 -1
- package/examples/extensions/model-status.ts +1 -1
- package/examples/extensions/notify.ts +1 -1
- package/examples/extensions/overlay-qa-tests.ts +3 -3
- package/examples/extensions/overlay-test.ts +1 -1
- package/examples/extensions/permission-gate.ts +1 -1
- package/examples/extensions/pirate.ts +1 -1
- package/examples/extensions/plan-mode/index.ts +1 -1
- package/examples/extensions/preset.ts +2 -2
- package/examples/extensions/project-trust.ts +3 -3
- package/examples/extensions/prompt-customizer.ts +1 -1
- package/examples/extensions/protected-paths.ts +1 -1
- package/examples/extensions/provider-payload.ts +1 -1
- package/examples/extensions/qna.ts +2 -2
- package/examples/extensions/question.ts +1 -1
- package/examples/extensions/questionnaire.ts +1 -1
- package/examples/extensions/rainbow-editor.ts +1 -1
- package/examples/extensions/reload-runtime.ts +1 -1
- package/examples/extensions/rpc-demo.ts +1 -1
- package/examples/extensions/sandbox/index.ts +2 -2
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/send-user-message.ts +1 -1
- package/examples/extensions/session-name.ts +1 -1
- package/examples/extensions/shutdown-command.ts +1 -1
- package/examples/extensions/snake.ts +1 -1
- package/examples/extensions/space-invaders.ts +1 -1
- package/examples/extensions/ssh.ts +2 -2
- package/examples/extensions/status-line.ts +1 -1
- package/examples/extensions/structured-output.ts +1 -1
- package/examples/extensions/summarize.ts +2 -3
- package/examples/extensions/system-prompt-header.ts +1 -1
- package/examples/extensions/tic-tac-toe.ts +1 -1
- package/examples/extensions/timed-confirm.ts +1 -1
- package/examples/extensions/titlebar-spinner.ts +1 -1
- package/examples/extensions/todo.ts +1 -1
- package/examples/extensions/tool-override.ts +1 -1
- package/examples/extensions/tools.ts +2 -2
- package/examples/extensions/trigger-compact.ts +1 -1
- package/examples/extensions/truncated-tool.ts +4 -4
- package/examples/extensions/widget-placement.ts +1 -1
- package/examples/extensions/with-deps/index.ts +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/extensions/working-indicator.ts +1 -1
- package/examples/extensions/working-message-test.ts +1 -1
- package/examples/rpc-client.ts +35 -0
- package/examples/rpc-extension-ui.ts +25 -5
- package/npm-shrinkwrap.json +43 -43
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax-highlight.js","sourceRoot":"","sources":["../../src/utils/syntax-highlight.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,2BAA2B,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAY/C,MAAM,UAAU,GAAG,SAAS,CAAC;AAC7B,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAEvC,SAAS,mBAAmB,CAAC,GAAW;IACvC,MAAM,KAAK,GAAG,uCAAuC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChE,MAAM,UAAU,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,C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ACZ,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,UAA4B,EAAE;IACrE,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ;QAC5B,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE;YACrB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,cAAc,EAAE,OAAO,CAAC,cAAc;SACtC,CAAC,CAAC,KAAK;QACT,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC;IAC1D,OAAO,qBAAqB,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC;AAC7C,CAAC","sourcesContent":["import hljs from \"highlight.js/lib/index.js\";\nimport { decodeHtmlEntityAt } from \"./html.ts\";\n\nexport type HighlightFormatter = (text: string) => string;\nexport type HighlightTheme = Partial<Record<string, HighlightFormatter>>;\n\nexport interface HighlightOptions {\n\tlanguage?: string;\n\tignoreIllegals?: boolean;\n\tlanguageSubset?: string[];\n\ttheme?: HighlightTheme;\n}\n\nconst SPAN_CLOSE = \"</span>\";\nconst HIGHLIGHT_CLASS_PREFIX = \"hljs-\";\n\nfunction getScopeFromSpanTag(tag: string): string | undefined {\n\tconst match = /\\sclass\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)')/.exec(tag);\n\tconst classValue = match?.[1] ?? match?.[2];\n\tif (!classValue) {\n\t\treturn undefined;\n\t}\n\n\tfor (const className of classValue.split(/\\s+/)) {\n\t\tif (className.startsWith(HIGHLIGHT_CLASS_PREFIX)) {\n\t\t\treturn className.slice(HIGHLIGHT_CLASS_PREFIX.length);\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nfunction getScopeFormatter(scope: string, theme: HighlightTheme): HighlightFormatter | undefined {\n\tconst exact = theme[scope];\n\tif (exact) {\n\t\treturn exact;\n\t}\n\n\tconst dotIndex = scope.indexOf(\".\");\n\tif (dotIndex !== -1) {\n\t\tconst prefixFormatter = theme[scope.slice(0, dotIndex)];\n\t\tif (prefixFormatter) {\n\t\t\treturn prefixFormatter;\n\t\t}\n\t}\n\n\tconst dashIndex = scope.indexOf(\"-\");\n\tif (dashIndex !== -1) {\n\t\tconst prefixFormatter = theme[scope.slice(0, dashIndex)];\n\t\tif (prefixFormatter) {\n\t\t\treturn prefixFormatter;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nfunction getActiveFormatter(scopes: Array<string | undefined>, theme: HighlightTheme): HighlightFormatter | undefined {\n\tfor (let i = scopes.length - 1; i >= 0; i--) {\n\t\tconst scope = scopes[i];\n\t\tif (!scope) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst formatter = getScopeFormatter(scope, theme);\n\t\tif (formatter) {\n\t\t\treturn formatter;\n\t\t}\n\t}\n\treturn theme.default;\n}\n\nfunction isSpanOpenTagStart(html: string, index: number): boolean {\n\tif (!html.startsWith(\"<span\", index)) {\n\t\treturn false;\n\t}\n\tconst nextChar = html[index + \"<span\".length];\n\treturn nextChar === \">\" || nextChar === \" \" || nextChar === \"\\t\" || nextChar === \"\\n\" || nextChar === \"\\r\";\n}\n\nexport function renderHighlightedHtml(html: string, theme: HighlightTheme = {}): string {\n\tlet output = \"\";\n\tlet textBuffer = \"\";\n\tconst scopes: Array<string | undefined> = [];\n\n\tconst flushText = () => {\n\t\tif (!textBuffer) {\n\t\t\treturn;\n\t\t}\n\t\tconst formatter = getActiveFormatter(scopes, theme);\n\t\toutput += formatter ? formatter(textBuffer) : textBuffer;\n\t\ttextBuffer = \"\";\n\t};\n\n\tlet index = 0;\n\twhile (index < html.length) {\n\t\tif (isSpanOpenTagStart(html, index)) {\n\t\t\tconst tagEndIndex = html.indexOf(\">\", index + 5);\n\t\t\tif (tagEndIndex !== -1) {\n\t\t\t\tflushText();\n\t\t\t\tconst tag = html.slice(index, tagEndIndex + 1);\n\t\t\t\tconst scope = getScopeFromSpanTag(tag);\n\t\t\t\tscopes.push(scope);\n\t\t\t\tindex = tagEndIndex + 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tif (html.startsWith(SPAN_CLOSE, index)) {\n\t\t\tflushText();\n\t\t\tif (scopes.length > 0) {\n\t\t\t\tscopes.pop();\n\t\t\t}\n\t\t\tindex += SPAN_CLOSE.length;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (html[index] === \"&\") {\n\t\t\tconst decoded = decodeHtmlEntityAt(html, index);\n\t\t\tif (decoded) {\n\t\t\t\ttextBuffer += decoded.text;\n\t\t\t\tindex += decoded.length;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\ttextBuffer += html[index];\n\t\tindex++;\n\t}\n\n\tflushText();\n\treturn output;\n}\n\nexport function highlight(code: string, options: HighlightOptions = {}): string {\n\tconst html = options.language\n\t\t? hljs.highlight(code, {\n\t\t\t\tlanguage: options.language,\n\t\t\t\tignoreIllegals: options.ignoreIllegals,\n\t\t\t}).value\n\t\t: hljs.highlightAuto(code, options.languageSubset).value;\n\treturn renderHighlightedHtml(html, options.theme);\n}\n\nexport function supportsLanguage(name: string): boolean {\n\treturn hljs.getLanguage(name) !== undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"syntax-highlight.js","sourceRoot":"","sources":["../../src/utils/syntax-highlight.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,2BAA2B,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAY/C,MAAM,UAAU,GAAG,SAAS,CAAC;AAC7B,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAEvC,SAAS,mBAAmB,CAAC,GAAW;IACvC,MAAM,KAAK,GAAG,uCAAuC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChE,MAAM,U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CAAC,CAAC;QAC1B,KAAK,EAAE,CAAC;IACT,CAAC;IAED,SAAS,EAAE,CAAC;IACZ,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,UAA4B,EAAE;IACrE,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ;QAC5B,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE;YACrB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,cAAc,EAAE,OAAO,CAAC,cAAc;SACtC,CAAC,CAAC,KAAK;QACT,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC;IAC1D,OAAO,qBAAqB,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC;AAC7C,CAAC;AAED,gGAAgG;AAChG,MAAM,CAAC,KAAK,UAAU,yBAAyB,KAAmB,CAAC","sourcesContent":["import hljs from \"highlight.js/lib/index.js\";\nimport { decodeHtmlEntityAt } from \"./html.ts\";\n\nexport type HighlightFormatter = (text: string) => string;\nexport type HighlightTheme = Partial<Record<string, HighlightFormatter>>;\n\nexport interface HighlightOptions {\n\tlanguage?: string;\n\tignoreIllegals?: boolean;\n\tlanguageSubset?: string[];\n\ttheme?: HighlightTheme;\n}\n\nconst SPAN_CLOSE = \"</span>\";\nconst HIGHLIGHT_CLASS_PREFIX = \"hljs-\";\n\nfunction getScopeFromSpanTag(tag: string): string | undefined {\n\tconst match = /\\sclass\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)')/.exec(tag);\n\tconst classValue = match?.[1] ?? match?.[2];\n\tif (!classValue) {\n\t\treturn undefined;\n\t}\n\n\tfor (const className of classValue.split(/\\s+/)) {\n\t\tif (className.startsWith(HIGHLIGHT_CLASS_PREFIX)) {\n\t\t\treturn className.slice(HIGHLIGHT_CLASS_PREFIX.length);\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nfunction getScopeFormatter(scope: string, theme: HighlightTheme): HighlightFormatter | undefined {\n\tconst exact = theme[scope];\n\tif (exact) {\n\t\treturn exact;\n\t}\n\n\tconst dotIndex = scope.indexOf(\".\");\n\tif (dotIndex !== -1) {\n\t\tconst prefixFormatter = theme[scope.slice(0, dotIndex)];\n\t\tif (prefixFormatter) {\n\t\t\treturn prefixFormatter;\n\t\t}\n\t}\n\n\tconst dashIndex = scope.indexOf(\"-\");\n\tif (dashIndex !== -1) {\n\t\tconst prefixFormatter = theme[scope.slice(0, dashIndex)];\n\t\tif (prefixFormatter) {\n\t\t\treturn prefixFormatter;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nfunction getActiveFormatter(scopes: Array<string | undefined>, theme: HighlightTheme): HighlightFormatter | undefined {\n\tfor (let i = scopes.length - 1; i >= 0; i--) {\n\t\tconst scope = scopes[i];\n\t\tif (!scope) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst formatter = getScopeFormatter(scope, theme);\n\t\tif (formatter) {\n\t\t\treturn formatter;\n\t\t}\n\t}\n\treturn theme.default;\n}\n\nfunction isSpanOpenTagStart(html: string, index: number): boolean {\n\tif (!html.startsWith(\"<span\", index)) {\n\t\treturn false;\n\t}\n\tconst nextChar = html[index + \"<span\".length];\n\treturn nextChar === \">\" || nextChar === \" \" || nextChar === \"\\t\" || nextChar === \"\\n\" || nextChar === \"\\r\";\n}\n\nexport function renderHighlightedHtml(html: string, theme: HighlightTheme = {}): string {\n\tlet output = \"\";\n\tlet textBuffer = \"\";\n\tconst scopes: Array<string | undefined> = [];\n\n\tconst flushText = () => {\n\t\tif (!textBuffer) {\n\t\t\treturn;\n\t\t}\n\t\tconst formatter = getActiveFormatter(scopes, theme);\n\t\toutput += formatter ? formatter(textBuffer) : textBuffer;\n\t\ttextBuffer = \"\";\n\t};\n\n\tlet index = 0;\n\twhile (index < html.length) {\n\t\tif (isSpanOpenTagStart(html, index)) {\n\t\t\tconst tagEndIndex = html.indexOf(\">\", index + 5);\n\t\t\tif (tagEndIndex !== -1) {\n\t\t\t\tflushText();\n\t\t\t\tconst tag = html.slice(index, tagEndIndex + 1);\n\t\t\t\tconst scope = getScopeFromSpanTag(tag);\n\t\t\t\tscopes.push(scope);\n\t\t\t\tindex = tagEndIndex + 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tif (html.startsWith(SPAN_CLOSE, index)) {\n\t\t\tflushText();\n\t\t\tif (scopes.length > 0) {\n\t\t\t\tscopes.pop();\n\t\t\t}\n\t\t\tindex += SPAN_CLOSE.length;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (html[index] === \"&\") {\n\t\t\tconst decoded = decodeHtmlEntityAt(html, index);\n\t\t\tif (decoded) {\n\t\t\t\ttextBuffer += decoded.text;\n\t\t\t\tindex += decoded.length;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\ttextBuffer += html[index];\n\t\tindex++;\n\t}\n\n\tflushText();\n\treturn output;\n}\n\nexport function highlight(code: string, options: HighlightOptions = {}): string {\n\tconst html = options.language\n\t\t? hljs.highlight(code, {\n\t\t\t\tlanguage: options.language,\n\t\t\t\tignoreIllegals: options.ignoreIllegals,\n\t\t\t}).value\n\t\t: hljs.highlightAuto(code, options.languageSubset).value;\n\treturn renderHighlightedHtml(html, options.theme);\n}\n\nexport function supportsLanguage(name: string): boolean {\n\treturn hljs.getLanguage(name) !== undefined;\n}\n\n/** Every grammar loads statically with this module; kept so upstream callers stay unchanged. */\nexport async function loadAllHighlightLanguages(): Promise<void> {}\n"]}
|
|
@@ -107,7 +107,7 @@ Only the current structured completion format is specialized. Older text-only co
|
|
|
107
107
|
|
|
108
108
|
## Lifetime
|
|
109
109
|
|
|
110
|
-
Background execution belongs to the current session runtime, not a daemon. Parent-turn cancellation still cancels foreground-owned work; after detach it does not cancel background work. Shutdown, `/reload`, `/new`, `/resume`, and `/fork` close admission, stop delivery, cancel work and perform bounded cleanup. `/tree` cancels executions whose launch anchor is absent from the destination branch and suppresses their completion delivery there; navigating back to a branch revives its undelivered completions, and ordinary conversation progress along the same branch does not cancel them. Active processes and workers are not reattached across process restart or copied into a fork.
|
|
110
|
+
Background execution belongs to the current session runtime, not a daemon. Parent-turn cancellation still cancels foreground-owned work; after detach it does not cancel background work. Shutdown, `/reload`, `/new`, `/resume`, and `/fork` close admission, stop delivery, cancel work and perform bounded cleanup. `/tree` cancels executions whose launch anchor is absent from the destination branch and suppresses their completion delivery there; navigating back to a branch revives its undelivered completions, and ordinary conversation progress along the same branch does not cancel them. A completion already handed to the prompt queue when its run was aborted is not recalled — the next run delivers it, like any other queued message. Active processes and workers are not reattached across process restart or copied into a fork.
|
|
111
111
|
|
|
112
112
|
The panel is an observer, not a cleanup engine. Admission, bounded history/output retention, completion delivery and headless exit policy are enforced by the core service and hosting mode.
|
|
113
113
|
|
|
@@ -121,9 +121,9 @@ Terminal snapshots persist as version-2 `background-task-result` custom entries,
|
|
|
121
121
|
|
|
122
122
|
Delivered history outside the selected branch can be released and restored on return, so it does not fill the new branch's history budget. Undelivered completions stay protected while their branch is hidden. Pending delivery, pins and active reads use a separate allowance within the total runtime retention cap; restoration respects the same cap.
|
|
123
123
|
|
|
124
|
-
Completion delivery
|
|
124
|
+
Completion delivery follows the same queueing path as interactive input. While the agent is running, a completion is steered into that run, so it lands right after the current tool batch — exactly like a message the user types mid-run, and behind any already queued steering. An idle session starts a completion turn instead. User preflight (input hooks, model and authentication checks, compaction) still holds delivery, so a user message is always the first thing a new run sees. One bounded completion is in flight at a time. A Subagent group produces one summary, not a separate wake-up per worker. A terminal `bg wait` coordinates with automatic delivery only after its tool result is persisted: while a `bg wait`, `bg read` or a watched `/bg` row holds a task pinned, that task is not announced, and aborting during output reading does not lose the pending completion. Direct SDK waits remain observational until explicitly acknowledged. Progress and repeated reads do not inject messages or add usage. `agent_settled` still describes the main agent, not the end of all background executions.
|
|
125
125
|
|
|
126
|
-
Failed completion delivery leaves the terminal result available for inspection rather than silently discarding it, and warns through the extension error channel. The next user prompt retries delivery automatically; SDK hosts can also call `session.retryBackgroundNotifications()` explicitly after resolving the failure. There is no infinite timer retry loop.
|
|
126
|
+
Failed completion delivery leaves the terminal result available for inspection rather than silently discarding it, and warns through the extension error channel. The next user prompt retries delivery automatically; SDK hosts can also call `session.retryBackgroundNotifications()` explicitly after resolving the failure. There is no infinite timer retry loop. A completion that a run emitted but never persisted, and a completion dropped by clearing the queue, fail the same way; one still sitting in the queue when its run ends stays claimed, because the next run delivers that same message.
|
|
127
127
|
|
|
128
128
|
Queued extension `nextTurn` context accompanies completion turns and stays queued until each message is persisted. A failed or partially persisted turn therefore retries only the context that has not been saved.
|
|
129
129
|
|
|
@@ -84,11 +84,15 @@ The active session model and its provider cannot be deleted or renamed; switch m
|
|
|
84
84
|
|
|
85
85
|
For OpenAI-compatible APIs, discovery uses `GET {baseUrl}/models`. Anthropic Messages uses `{baseUrl}/v1/models`, without repeating an existing `/v1` suffix. The pane's idle action row shows the discovery URL; `Enter` starts the request. Without a `baseUrl`, the pane instead explains what to configure and discovery cannot start.
|
|
86
86
|
|
|
87
|
-
Accepted catalog shapes are `data[]`, `models[]`, or a bare array. Entries can provide `id` or `slug`, plus an optional `name`, `display_name`, or `displayName`.
|
|
87
|
+
Accepted catalog shapes are `data[]`, `models[]`, or a bare array. Entries can provide `id` or `slug`, plus an optional `name`, `display_name`, or `displayName`. Alongside the identifier and label, discovery imports the metadata an entry declares under the common field names — `context_window` / `context_length` / `max_model_len`, `max_output_tokens` / `max_tokens`, image input via `input_modalities` or an explicit vision flag, and reasoning via a supported-effort list or a capability flag. Only positive integers count (`0`, `null`, decimals, and non-numeric values are ignored); where fields disagree the smallest value wins, because an overstated limit overflows requests while an understated one only compacts earlier. Native Google catalog shapes are not supported.
|
|
88
88
|
|
|
89
89
|
- **Authentication:** Credentials resolve through Pi's canonical resolution chain. Header-only resolved authentication is supported, and the default scheme follows the API type. Unsaved connection changes block discovery. Raw `$VAR` or `!command` placeholders are never transmitted unresolved; discovery aborts if configured credentials cannot be resolved. Known resolved credentials are redacted from server errors.
|
|
90
|
-
- **
|
|
91
|
-
- **
|
|
90
|
+
- **Anthropic-compatible gateways:** Anthropic Messages catalogs are often served OpenAI-style only, so a `401`, `403`, or `404` on the Anthropic path triggers exactly one retry with `Authorization: Bearer` at the same URL, or at the base URL with a trailing `/anthropic` removed. Both attempts stay on the original origin, an explicitly configured `Authorization` header is never overridden, and other API types are never retried. A failed retry reports both URLs and their status codes.
|
|
91
|
+
- **Pagination:** Anthropic catalogs answer with their `has_more` marker; discovery follows that marker through `after_id` (up to five pages) instead of reporting the first 20-entry page as partial. Every other catalog is fetched once and a response declaring `has_more` is still marked partial.
|
|
92
|
+
- **Limits:** Discovery has a 10-second deadline covering the whole attempt sequence, including preparation, authentication waits, retries, and pagination. Responses are bounded to 4 MiB (error payloads are bounded to 4 KiB and displayed up to 400 characters). Catalogs are capped at 2,000 models.
|
|
93
|
+
- **Checklist import:** Discovered models appear in a searchable checklist. Models already configured in `models.json` are marked `Added` and cannot be checked. Each row shows the metadata it declared, e.g. `deepseek-flash · DeepSeek-V4.1-Flash · 1.0M ctx · 393k out · img · think`. Confirming imports the checked models — or just the highlighted one when nothing is checked — with that metadata, saves immediately, and refreshes the provider runtime. `Esc` discards the results.
|
|
94
|
+
|
|
95
|
+
Imported metadata lands in the same fields the editor already manages, so `contextWindow`, `maxTokens`, `input`, and `reasoning` remain editable afterwards. Cost is never imported: catalog pricing dialects differ in both unit and precision, and a misread rate misreports spend by orders of magnitude.
|
|
92
96
|
|
|
93
97
|
## Use Built-in Data
|
|
94
98
|
|
|
@@ -85,7 +85,7 @@ Only `explorer` and `general` keys are valid. A malformed, unsupported, unreadab
|
|
|
85
85
|
- A retryable failure that produced no turns or tool use may be retried at task level up to two more times. Runs with partial work are never restarted.
|
|
86
86
|
- Retry backoff does not hold a concurrency slot; another queued worker can run while the failed task waits.
|
|
87
87
|
- Cancellation of the owning execution interrupts queued and retrying workers immediately.
|
|
88
|
-
- Background completion is delivered as one bounded group summary, with reports in input order,
|
|
88
|
+
- Background completion is delivered as one bounded group summary, with reports in input order, through the host's normal prompt queueing: steered into a running turn right after its current tool batch, or as its own turn when the session is idle. Its saved card has independent profile/status/report/error fields and explicit report-truncation flags; report text is never reparsed as worker metadata. Every worker gets a bounded report share. `bg wait` can deliver the terminal result instead; repeated `bg read` calls do not trigger notifications or billing.
|
|
89
89
|
- Managed worker usage settles through an independent persisted ledger, not through panel visits or result reads. Accrued usage from retries, failures, cancellations, and provider-supplied worker compaction is retained; missing provider usage is not fabricated. Worker tokens do not count as parent context occupancy.
|
|
90
90
|
|
|
91
91
|
Child sessions share the parent's canonical model/authentication runtime, so extension-registered providers and current credentials do not need to be mirrored into a second runtime.
|
package/docs/compaction.md
CHANGED
|
@@ -17,7 +17,7 @@ Pi has two summarization mechanisms:
|
|
|
17
17
|
| Compaction | Context exceeds threshold, or `/compact` | Summarize old messages to free up context |
|
|
18
18
|
| Branch summarization | `/tree` navigation | Preserve context when switching branches |
|
|
19
19
|
|
|
20
|
-
Both use the same structured summary format and track file operations cumulatively.
|
|
20
|
+
Both use the same structured summary format and track file operations cumulatively. Summarization requests disable prompt-cache writes because these one-off prompts are unlikely to be reused.
|
|
21
21
|
|
|
22
22
|
## Compaction
|
|
23
23
|
|
package/docs/extensions.md
CHANGED
|
@@ -2853,18 +2853,29 @@ pi.on("session_shutdown", () => {
|
|
|
2853
2853
|
|
|
2854
2854
|
Return `{ consume: true }` to stop dispatch immediately. Return `{ data }` to replace the input seen by later listeners and then Pi's focused component; an empty replacement also prevents focused-component handling after listeners finish. In RPC, JSON, and print modes this is a no-op, so guard terminal-specific behavior with `ctx.mode === "tui"`.
|
|
2855
2855
|
|
|
2856
|
-
|
|
2856
|
+
Subscriptions are removed on extension UI teardown and follow TUI mode changes. For input that should reach you only while the user is typing in the main editor, use `ctx.ui.editorHost.onInput()` below.
|
|
2857
2857
|
|
|
2858
|
-
### Editor
|
|
2858
|
+
### Main Editor Host
|
|
2859
2859
|
|
|
2860
|
-
`ctx.ui.
|
|
2860
|
+
`ctx.ui.editorHost` exposes the main editor. It is defined only where Pi renders the interactive editor, so check for it instead of checking the mode:
|
|
2861
|
+
|
|
2862
|
+
```typescript
|
|
2863
|
+
const host = ctx.ui.editorHost;
|
|
2864
|
+
if (!host) return; // RPC, JSON, and print modes have no main editor
|
|
2865
|
+
const unsubscribeInput = host.onInput((data) => handleKey(data));
|
|
2866
|
+
const cursor = host.getCursor(); // { line, col }, zero-based; undefined if the editor does not expose it
|
|
2867
|
+
```
|
|
2868
|
+
|
|
2869
|
+
`host.onInput(handler)` works like `onTerminalInput()` but only receives input when the main editor has focus, no overlay is visible, and the editor is not showing autocomplete. Custom editors can expose `getCursor()` and `isShowingAutocomplete()` for these checks.
|
|
2870
|
+
|
|
2871
|
+
`host.onSubmit(handler)` intercepts normalized, expanded editor text before command dispatch, editor history, streaming queues, and compaction queues. Enter and the configured follow-up shortcut use the same hook. It does not intercept programmatic extension messages.
|
|
2861
2872
|
|
|
2862
2873
|
The event has `text`, `mode` (`"steer"` or `"followUp"`), and `kind` (`"prompt"`, `"command"`, or `"bash"`). Known built-in/extension commands, templates, and skills are classified as commands; unknown slash-prefixed text remains a prompt.
|
|
2863
2874
|
|
|
2864
2875
|
Handlers run synchronously in registration order. Return `{ handled: true }` to claim and clear the input, or `{ handled: true, editorText }` to keep a draft. Return `undefined` to pass through. Start asynchronous work after making the synchronous claim. The first claim wins; a thrown error restores the input and stops dispatch instead of sending it to the main agent.
|
|
2865
2876
|
|
|
2866
2877
|
```typescript
|
|
2867
|
-
const unsubscribe = ctx.ui.
|
|
2878
|
+
const unsubscribe = ctx.ui.editorHost?.onSubmit((event) => {
|
|
2868
2879
|
if (!panelOpen || event.kind !== "prompt") return undefined;
|
|
2869
2880
|
if (busy) return { handled: true, editorText: event.text };
|
|
2870
2881
|
void answerSideQuestion(event.text).catch(showSideError);
|
|
@@ -2936,7 +2947,6 @@ ctx.ui.setTitle("pi - my-project");
|
|
|
2936
2947
|
// Editor text
|
|
2937
2948
|
ctx.ui.setEditorText("Prefill text");
|
|
2938
2949
|
const current = ctx.ui.getEditorText();
|
|
2939
|
-
const cursor = ctx.ui.getEditorCursor(); // { line, col }, zero-based; undefined if unsupported
|
|
2940
2950
|
|
|
2941
2951
|
// Paste into editor (triggers paste handling, including collapse for large content)
|
|
2942
2952
|
ctx.ui.pasteToEditor("pasted content");
|
package/docs/sdk.md
CHANGED
|
@@ -280,7 +280,7 @@ An embedding can opt in with `await session.bindExtensions({ backgroundEnabled:
|
|
|
280
280
|
The host must choose:
|
|
281
281
|
|
|
282
282
|
- **Lifetime and cancellation:** a settled main-agent turn is not the end of background work. `session.abort()` cancels foreground-owned work, not detached work. Use `session.background.kill(id)` for a whole execution, or `await session.background.shutdown(graceMs?)` to close admission, cancel all owned work and drain within a bounded grace period (default 2 seconds, maximum 60 seconds). A non-cooperating executor can outlive that grace period.
|
|
283
|
-
- **Result-driven turns and cost:** automatic completions
|
|
283
|
+
- **Result-driven turns and cost:** automatic completions join the host's prompt queue, so a running turn receives them as steering and an idle session starts a completion turn. Use the nestable `session.pauseBackgroundNotifications()` to defer delivery; its returned release function is idempotent. Pausing does not stop execution or its costs. Budget worker activity and completion-triggered turns explicitly.
|
|
284
284
|
- **Observation and delivery:** `session.background` exposes the [public supervision methods](extensions.md#ctxbackground). `read()` and `wait()` observe; a terminal snapshot alone does not acknowledge model delivery. The bundled `bg wait` result carries `details.backgroundTaskId`, which the host acknowledges only after persisting the tool result. A direct SDK waiter that consumes the result outside model history can explicitly call `session.background.markDelivered(task.id)` after successful consumption. A timeout or cancelled wait does not stop the execution. Failed notification delivery leaves the result available for inspection; after fixing the host failure, call `session.retryBackgroundNotifications()` explicitly. Pi does not retry a failed delivery forever on a timer.
|
|
285
285
|
- **Shutdown:** `await runtime.dispose()` handles background shutdown and extension lifecycle when using the runtime API. For a directly owned session, drain Background, abort the main agent, then dispose; synchronous `session.dispose()` alone is not an awaited drain.
|
|
286
286
|
|
package/docs/usage.md
CHANGED
|
@@ -168,10 +168,13 @@ See [Pi Packages](packages.md) for package sources and security notes.
|
|
|
168
168
|
|------|-------------|
|
|
169
169
|
| default | Interactive mode |
|
|
170
170
|
| `-p`, `--print` | Print response and exit |
|
|
171
|
+
| `--mode text` | Text output; still opens the terminal UI when stdin and stdout are terminals |
|
|
171
172
|
| `--mode json` | Output all events as JSON lines; see [JSON mode](json.md) |
|
|
172
173
|
| `--mode rpc` | RPC mode over stdin/stdout; see [RPC mode](rpc.md) |
|
|
173
174
|
| `--export <in> [out]` | Export a session to HTML |
|
|
174
175
|
|
|
176
|
+
`--mode` accepts only `text`, `json`, or `rpc`. A missing or invalid value is reported as an error and pi exits with a nonzero status instead of falling back to another mode.
|
|
177
|
+
|
|
175
178
|
In print mode, pi also reads piped stdin and merges it into the initial prompt:
|
|
176
179
|
|
|
177
180
|
```bash
|
package/examples/README.md
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
# Examples
|
|
2
2
|
|
|
3
|
-
Example code for the `@astralyn/pi` SDK and extensions.
|
|
3
|
+
Example code for the `@astralyn/pi` SDK, process integration, and extensions.
|
|
4
4
|
|
|
5
5
|
## Standalone
|
|
6
6
|
|
|
7
|
+
### [rpc-client.ts](rpc-client.ts)
|
|
8
|
+
Runs one prompt through a Pi RPC child process with the typed `RpcClient`: it starts Pi, streams events, and waits for the run to settle.
|
|
9
|
+
|
|
10
|
+
Build the package before running it from a repository checkout:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npx tsx examples/rpc-client.ts "Explain this repository"
|
|
14
|
+
```
|
|
15
|
+
|
|
7
16
|
### [rpc-extension-ui.ts](rpc-extension-ui.ts)
|
|
8
17
|
A lightweight RPC chat client that handles extension UI requests; pair it with [the RPC demo extension](extensions/rpc-demo.ts).
|
|
9
18
|
|
|
@@ -26,5 +35,6 @@ Example extensions demonstrating:
|
|
|
26
35
|
## Documentation
|
|
27
36
|
|
|
28
37
|
- [SDK Reference](sdk/README.md)
|
|
38
|
+
- [RPC Protocol](../docs/rpc.md)
|
|
29
39
|
- [Extensions Documentation](../docs/extensions.md)
|
|
30
40
|
- [Skills Documentation](../docs/skills.md)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Extension Examples
|
|
2
2
|
|
|
3
|
-
Example extensions for
|
|
3
|
+
Example extensions for pi-coding-agent.
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
@@ -35,13 +35,13 @@ cp permission-gate.ts ~/.pi/agent/extensions/
|
|
|
35
35
|
| `question.ts` | Demonstrates `ctx.ui.select()` for asking the user questions with custom UI |
|
|
36
36
|
| `questionnaire.ts` | Multi-question input with tab bar navigation between questions |
|
|
37
37
|
| `tool-override.ts` | Override built-in tools (e.g., add logging/access control to `read`) |
|
|
38
|
-
| `bash-spawn-hook.ts` | Wraps bash to adjust the command, cwd, and environment before execution |
|
|
39
38
|
| `dynamic-tools.ts` | Register tools after startup (`session_start`) and at runtime via command, with prompt snippets and tool-specific prompt guidelines |
|
|
40
39
|
| `structured-output.ts` | Final structured-output tool that returns `terminate: true` so the agent can end on the tool call |
|
|
41
40
|
| `built-in-tool-renderer.ts` | Custom compact rendering for built-in tools (read, bash, edit, write) while keeping original behavior |
|
|
42
41
|
| `minimal-mode.ts` | Override built-in tool rendering for minimal display (only tool calls, no output in collapsed mode) |
|
|
43
42
|
| `truncated-tool.ts` | Wraps ripgrep with proper output truncation (50KB/2000 lines) |
|
|
44
43
|
| `ssh.ts` | Delegate all tools to a remote machine via SSH using pluggable operations |
|
|
44
|
+
| `subagent/` | Delegate tasks to specialized subagents with isolated context windows |
|
|
45
45
|
|
|
46
46
|
### Commands & UI
|
|
47
47
|
|
|
@@ -51,18 +51,14 @@ cp permission-gate.ts ~/.pi/agent/extensions/
|
|
|
51
51
|
| `plan-mode/` | Claude Code-style plan mode for read-only exploration with `/plan` command and step tracking |
|
|
52
52
|
| `tools.ts` | Interactive `/tools` command to enable/disable tools with session persistence |
|
|
53
53
|
| `handoff.ts` | Transfer context to a new focused session via `/handoff <goal>` |
|
|
54
|
-
| `commands.ts` | Lists available slash commands, optionally filtered by source |
|
|
55
54
|
| `qna.ts` | Extracts questions from last response into editor via `ctx.ui.setEditorText()` |
|
|
56
55
|
| `status-line.ts` | Shows turn progress in footer via `ctx.ui.setStatus()` with themed colors |
|
|
57
|
-
| `border-status-editor.ts` | Custom editor borders with working state, model, context, cwd, and Git branch |
|
|
58
56
|
| `github-issue-autocomplete.ts` | Adds `#1234` issue completions by stacking a custom autocomplete provider that preloads open issues from `gh issue list` |
|
|
59
57
|
| `widget-placement.ts` | Shows widgets above and below the editor via `ctx.ui.setWidget()` placement |
|
|
60
58
|
| `hidden-thinking-label.ts` | Customizes the collapsed thinking label via `ctx.ui.setHiddenThinkingLabel()` |
|
|
61
59
|
| `working-indicator.ts` | Customizes the streaming working indicator via `ctx.ui.setWorkingIndicator()` |
|
|
62
|
-
| `working-message-test.ts` | Tests custom working-message and indicator persistence across loader recreation |
|
|
63
60
|
| `model-status.ts` | Shows model changes in status bar via `model_select` hook |
|
|
64
61
|
| `snake.ts` | Snake game with custom UI, keyboard handling, and session persistence |
|
|
65
|
-
| `space-invaders.ts` | Space Invaders game with keyboard controls and session persistence |
|
|
66
62
|
| `tic-tac-toe.ts` | Tic-tac-toe vs the agent with `executionMode: "sequential"` tools to prevent race conditions on shared cursor state |
|
|
67
63
|
| `send-user-message.ts` | Demonstrates `pi.sendUserMessage()` for sending user messages from extensions |
|
|
68
64
|
| `timed-confirm.ts` | Demonstrates AbortSignal for auto-dismissing `ctx.ui.confirm()` and `ctx.ui.select()` dialogs |
|
|
@@ -81,7 +77,6 @@ cp permission-gate.ts ~/.pi/agent/extensions/
|
|
|
81
77
|
| `reload-runtime.ts` | Adds `/reload-runtime` and `reload_runtime` tool showing safe reload flow |
|
|
82
78
|
| `interactive-shell.ts` | Run interactive commands (vim, htop) with full terminal via `user_bash` hook |
|
|
83
79
|
| `inline-bash.ts` | Expands `!{command}` patterns in prompts via `input` event transformation |
|
|
84
|
-
| `input-transform.ts` | Transforms or handles typed input through the `input` event |
|
|
85
80
|
| `input-transform-streaming.ts` | Skips expensive input preprocessing for mid-stream steering via `streamingBehavior` |
|
|
86
81
|
|
|
87
82
|
### Git Integration
|
|
@@ -89,7 +84,6 @@ cp permission-gate.ts ~/.pi/agent/extensions/
|
|
|
89
84
|
| Extension | Description |
|
|
90
85
|
|-----------|-------------|
|
|
91
86
|
| `git-checkpoint.ts` | Creates git stash checkpoints at each turn for code restoration on fork |
|
|
92
|
-
| `git-merge-and-resolve.ts` | Fetches and merges the upstream branch after turns, then sends conflicts for resolution |
|
|
93
87
|
| `auto-commit-on-exit.ts` | Auto-commits on exit using last assistant message for commit message |
|
|
94
88
|
|
|
95
89
|
### System Prompt & Compaction
|
|
@@ -97,9 +91,7 @@ cp permission-gate.ts ~/.pi/agent/extensions/
|
|
|
97
91
|
| Extension | Description |
|
|
98
92
|
|-----------|-------------|
|
|
99
93
|
| `pirate.ts` | Demonstrates `systemPromptAppend` to dynamically modify system prompt |
|
|
100
|
-
| `prompt-customizer.ts` | Adds context-aware guidance based on active tools and skills |
|
|
101
94
|
| `claude-rules.ts` | Scans `.claude/rules/` folder and lists rules in system prompt |
|
|
102
|
-
| `system-prompt-header.ts` | Shows the effective system-prompt length in the status area |
|
|
103
95
|
| `custom-compaction.ts` | Custom compaction that summarizes entire conversation |
|
|
104
96
|
| `trigger-compact.ts` | Triggers compaction when context usage exceeds 100k tokens and adds `/trigger-compact` command |
|
|
105
97
|
|
|
@@ -136,7 +128,6 @@ cp permission-gate.ts ~/.pi/agent/extensions/
|
|
|
136
128
|
|-----------|-------------|
|
|
137
129
|
| `custom-provider-anthropic/` | Custom Anthropic provider with OAuth support and custom streaming implementation |
|
|
138
130
|
| `custom-provider-gitlab-duo/` | GitLab Duo provider using pi-ai's built-in Anthropic/OpenAI streaming via proxy |
|
|
139
|
-
| `provider-payload.ts` | Logs provider request payloads and response headers to `.pi/provider-payload.log` |
|
|
140
131
|
|
|
141
132
|
### External Dependencies
|
|
142
133
|
|
|
@@ -150,11 +141,40 @@ cp permission-gate.ts ~/.pi/agent/extensions/
|
|
|
150
141
|
See [docs/extensions.md](../../docs/extensions.md) for full documentation.
|
|
151
142
|
|
|
152
143
|
```typescript
|
|
153
|
-
import type { ExtensionAPI } from "@
|
|
144
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
145
|
+
import { Type } from "typebox";
|
|
154
146
|
|
|
155
147
|
export default function (pi: ExtensionAPI) {
|
|
156
|
-
|
|
157
|
-
|
|
148
|
+
// Subscribe to lifecycle events
|
|
149
|
+
pi.on("tool_call", async (event, ctx) => {
|
|
150
|
+
if (event.toolName === "bash" && event.input.command?.includes("rm -rf")) {
|
|
151
|
+
const ok = await ctx.ui.confirm("Dangerous!", "Allow rm -rf?");
|
|
152
|
+
if (!ok) return { block: true, reason: "Blocked by user" };
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Register custom tools
|
|
157
|
+
pi.registerTool({
|
|
158
|
+
name: "greet",
|
|
159
|
+
label: "Greeting",
|
|
160
|
+
description: "Generate a greeting",
|
|
161
|
+
parameters: Type.Object({
|
|
162
|
+
name: Type.String({ description: "Name to greet" }),
|
|
163
|
+
}),
|
|
164
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
165
|
+
return {
|
|
166
|
+
content: [{ type: "text", text: `Hello, ${params.name}!` }],
|
|
167
|
+
details: {},
|
|
168
|
+
};
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// Register commands
|
|
173
|
+
pi.registerCommand("hello", {
|
|
174
|
+
description: "Say hello",
|
|
175
|
+
handler: async (args, ctx) => {
|
|
176
|
+
ctx.ui.notify("Hello!", "info");
|
|
177
|
+
},
|
|
158
178
|
});
|
|
159
179
|
}
|
|
160
180
|
```
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Uses the last assistant message to generate a commit message.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { ExtensionAPI } from "@
|
|
8
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
9
9
|
|
|
10
10
|
export default function (pi: ExtensionAPI) {
|
|
11
11
|
pi.on("session_shutdown", async (_event, ctx) => {
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* pi -e ./bash-spawn-hook.ts
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type { ExtensionAPI } from "@
|
|
11
|
-
import { createBashTool } from "@
|
|
10
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
11
|
+
import { createBashTool } from "@earendil-works/pi-coding-agent";
|
|
12
12
|
|
|
13
13
|
export default function (pi: ExtensionAPI) {
|
|
14
14
|
const cwd = process.cwd();
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Usage: /bookmark [label] - bookmark the last assistant message
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type { ExtensionAPI } from "@
|
|
10
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
11
11
|
|
|
12
12
|
export default function (pi: ExtensionAPI) {
|
|
13
13
|
pi.registerCommand("bookmark", {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
CustomEditor,
|
|
3
|
+
type ExtensionAPI,
|
|
4
|
+
type ExtensionContext,
|
|
5
|
+
type KeybindingsManager,
|
|
6
|
+
} from "@earendil-works/pi-coding-agent";
|
|
2
7
|
import type { Component, EditorTheme, TUI } from "@earendil-works/pi-tui";
|
|
3
8
|
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
4
9
|
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
* pi -e ./built-in-tool-renderer.ts
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
import type { BashToolDetails, EditToolDetails, ExtensionAPI, ReadToolDetails } from "@
|
|
29
|
-
import { createBashTool, createEditTool, createReadTool, createWriteTool } from "@
|
|
28
|
+
import type { BashToolDetails, EditToolDetails, ExtensionAPI, ReadToolDetails } from "@earendil-works/pi-coding-agent";
|
|
29
|
+
import { createBashTool, createEditTool, createReadTool, createWriteTool } from "@earendil-works/pi-coding-agent";
|
|
30
30
|
import { Text } from "@earendil-works/pi-tui";
|
|
31
31
|
|
|
32
32
|
export default function (pi: ExtensionAPI) {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
import * as fs from "node:fs";
|
|
21
21
|
import * as path from "node:path";
|
|
22
|
-
import type { ExtensionAPI } from "@
|
|
22
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Recursively find all .md files in a directory
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* 3. Use /commands extensions to filter by source
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import type { ExtensionAPI, SlashCommandInfo } from "@
|
|
13
|
+
import type { ExtensionAPI, SlashCommandInfo } from "@earendil-works/pi-coding-agent";
|
|
14
14
|
|
|
15
15
|
export default function commandsExtension(pi: ExtensionAPI) {
|
|
16
16
|
pi.registerCommand("commands", {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Demonstrates how to cancel session events using the before_* events.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { ExtensionAPI, SessionBeforeSwitchEvent, SessionMessageEntry } from "@
|
|
8
|
+
import type { ExtensionAPI, SessionBeforeSwitchEvent, SessionMessageEntry } from "@earendil-works/pi-coding-agent";
|
|
9
9
|
|
|
10
10
|
export default function (pi: ExtensionAPI) {
|
|
11
11
|
pi.on("session_before_switch", async (event: SessionBeforeSwitchEvent, ctx) => {
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
* pi --extension examples/extensions/custom-compaction.ts
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import type { ExtensionAPI } from "@astralyn/pi";
|
|
17
|
-
import { convertToLlm, serializeConversation } from "@astralyn/pi";
|
|
18
16
|
import { uuidv7 } from "@earendil-works/pi-ai";
|
|
17
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
18
|
+
import { convertToLlm, serializeConversation } from "@earendil-works/pi-coding-agent";
|
|
19
19
|
|
|
20
20
|
export default function (pi: ExtensionAPI) {
|
|
21
21
|
pi.on("session_before_compact", async (event, ctx) => {
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* Token stats come from ctx.sessionManager/ctx.model (already accessible).
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import type { ExtensionAPI } from "@astralyn/pi";
|
|
12
11
|
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
|
12
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
13
13
|
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
14
14
|
|
|
15
15
|
export default function (pi: ExtensionAPI) {
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* (logo + keybinding hints) with a custom component showing the pi mascot.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { ExtensionAPI, Theme } from "@
|
|
9
|
-
import { VERSION } from "@
|
|
8
|
+
import type { ExtensionAPI, Theme } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import { VERSION } from "@earendil-works/pi-coding-agent";
|
|
10
10
|
|
|
11
11
|
// --- PI MASCOT ---
|
|
12
12
|
// Based on pi_mascot.ts - the pi agent character
|
|
@@ -8,22 +8,21 @@
|
|
|
8
8
|
* - API key support via environment variable
|
|
9
9
|
* - Two model definitions
|
|
10
10
|
*
|
|
11
|
-
* Usage
|
|
11
|
+
* Usage:
|
|
12
12
|
* # First install dependencies
|
|
13
|
-
*
|
|
13
|
+
* cd packages/coding-agent/examples/extensions/custom-provider && npm install
|
|
14
14
|
*
|
|
15
15
|
* # With OAuth (run /login custom-anthropic first)
|
|
16
|
-
* pi -e examples/extensions/custom-provider
|
|
16
|
+
* pi -e ./packages/coding-agent/examples/extensions/custom-provider
|
|
17
17
|
*
|
|
18
18
|
* # With API key
|
|
19
|
-
* CUSTOM_ANTHROPIC_API_KEY=sk-ant-... pi -e examples/extensions/custom-provider
|
|
19
|
+
* CUSTOM_ANTHROPIC_API_KEY=sk-ant-... pi -e ./packages/coding-agent/examples/extensions/custom-provider
|
|
20
20
|
*
|
|
21
21
|
* Then use /model to select custom-anthropic/claude-sonnet-4-5
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import Anthropic from "@anthropic-ai/sdk";
|
|
25
25
|
import type { ContentBlockParam, MessageCreateParamsStreaming } from "@anthropic-ai/sdk/resources/messages.js";
|
|
26
|
-
import type { ExtensionAPI } from "@astralyn/pi";
|
|
27
26
|
import {
|
|
28
27
|
type Api,
|
|
29
28
|
type AssistantMessage,
|
|
@@ -47,6 +46,7 @@ import {
|
|
|
47
46
|
type ToolResultMessage,
|
|
48
47
|
type TranscriptContext,
|
|
49
48
|
} from "@earendil-works/pi-ai";
|
|
49
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
50
50
|
|
|
51
51
|
// =============================================================================
|
|
52
52
|
// OAuth implementation adapted for the legacy extension compatibility interface.
|
|
@@ -157,7 +157,7 @@ async function refreshAnthropicToken(credentials: OAuthCredentials, signal: Abor
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
// =============================================================================
|
|
160
|
-
// Streaming Implementation
|
|
160
|
+
// Streaming Implementation (simplified from packages/ai/src/api/anthropic-messages.ts)
|
|
161
161
|
// =============================================================================
|
|
162
162
|
|
|
163
163
|
// Claude Code tool names for OAuth stealth mode
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-extension-custom-provider",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.87.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-custom-provider",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.87.1",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.52.0"
|
|
12
12
|
}
|
|
@@ -4,12 +4,11 @@
|
|
|
4
4
|
* Provides access to GitLab Duo AI models (Claude and GPT) through GitLab's AI Gateway.
|
|
5
5
|
* Delegates to pi-ai's built-in Anthropic and OpenAI streaming implementations.
|
|
6
6
|
*
|
|
7
|
-
* Usage
|
|
8
|
-
* pi -e examples/extensions/custom-provider-gitlab-duo
|
|
7
|
+
* Usage:
|
|
8
|
+
* pi -e ./packages/coding-agent/examples/extensions/custom-provider-gitlab-duo
|
|
9
9
|
* # Then /login gitlab-duo, or set GITLAB_TOKEN=glpat-...
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import type { ExtensionAPI } from "@astralyn/pi";
|
|
13
12
|
import {
|
|
14
13
|
type Api,
|
|
15
14
|
type AssistantMessageEventStream,
|
|
@@ -23,6 +22,7 @@ import {
|
|
|
23
22
|
type ThinkingLevelMap,
|
|
24
23
|
type TranscriptContext,
|
|
25
24
|
} from "@earendil-works/pi-ai/compat";
|
|
25
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
26
26
|
|
|
27
27
|
// =============================================================================
|
|
28
28
|
// Constants
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Useful to ensure work is committed before switching context.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { ExtensionAPI, ExtensionContext } from "@
|
|
8
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
9
9
|
|
|
10
10
|
async function checkDirtyRepo(
|
|
11
11
|
pi: ExtensionAPI,
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* This demonstrates that overlays can handle real-time game rendering at 35 FPS.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import type { ExtensionAPI } from "@
|
|
12
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
13
13
|
import { DoomOverlayComponent } from "./doom-component.ts";
|
|
14
14
|
import { DoomEngine } from "./doom-engine.ts";
|
|
15
15
|
import { ensureWadFile } from "./wad-finder.ts";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "https://raw.githubusercontent.com/
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/earendil-works/pi/main/packages/coding-agent/src/modes/interactive/theme/theme-schema.json",
|
|
3
3
|
"name": "dynamic-resources",
|
|
4
4
|
"vars": {
|
|
5
5
|
"cyan": "#00d7ff",
|
|
@@ -30,6 +30,8 @@
|
|
|
30
30
|
"dim": "dimGray",
|
|
31
31
|
"text": "",
|
|
32
32
|
"thinkingText": "gray",
|
|
33
|
+
"scrollbarTrack": "darkGray",
|
|
34
|
+
"scrollbarThumb": "",
|
|
33
35
|
"selectedBg": "selectedBg",
|
|
34
36
|
"userMessageBg": "userMsgBg",
|
|
35
37
|
"userMessageText": "",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { dirname, join } from "node:path";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
|
-
import type { ExtensionAPI } from "@
|
|
3
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
|
|
5
5
|
const baseDir = dirname(fileURLToPath(import.meta.url));
|
|
6
6
|
|