@astralyn/pi 1.4.11 → 1.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/CHANGELOG.md +73 -0
- package/dist/bundle/chunks/anthropic-messages-G5ZGBHOH.js +6 -0
- package/dist/bundle/chunks/azure-openai-responses-EMPTMYNF.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +22 -15
- package/dist/bundle/chunks/chunk-AXX7FFFD.js +2 -0
- package/dist/bundle/chunks/chunk-FNGB3ASD.js +2 -0
- package/dist/bundle/chunks/chunk-FPALVF3F.js +4 -0
- package/dist/bundle/chunks/chunk-H3UF54OB.js +9 -0
- package/dist/bundle/chunks/chunk-IC6JXX2J.js +10 -0
- package/dist/bundle/chunks/{chunk-TH3QDDPD.js → chunk-IRUUTK4W.js} +1 -1
- package/dist/bundle/chunks/{chunk-MZJC45TM.js → chunk-J7L6O5XA.js} +3 -3
- package/dist/bundle/chunks/{chunk-DLVLAQEG.js → chunk-KBFO53OG.js} +3 -3
- package/dist/bundle/chunks/{chunk-TPVFPFJP.js → chunk-P7VXFB2M.js} +1 -1
- package/dist/bundle/chunks/chunk-PSYLMRL6.js +9 -0
- package/dist/bundle/chunks/chunk-QNZARXLE.js +82 -0
- package/dist/bundle/chunks/chunk-R3YHAMWH.js +1503 -0
- package/dist/bundle/chunks/chunk-RAIYJ5FC.js +4 -0
- package/dist/bundle/chunks/{chunk-OV2VMHBX.js → chunk-SR6EWNPW.js} +1 -1
- package/dist/bundle/chunks/chunk-TA3YH2ZI.js +16 -0
- package/dist/bundle/chunks/{chunk-NUQMVNKQ.js → chunk-THAJ4BZF.js} +58 -62
- package/dist/bundle/chunks/{chunk-24FY4C5S.js → chunk-TRSJS3FM.js} +1 -1
- package/dist/bundle/chunks/chunk-ZRI3ICDE.js +2 -0
- package/dist/bundle/chunks/{cli-MBFCFGI2.js → cli-LAZQG54B.js} +11 -9
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-7BKATOEJ.js → cloudflare-workers-ai-system-one-4L2ABUJE.js} +1 -1
- package/dist/bundle/chunks/{execute-VLAIP26K.js → execute-ACWDKC3C.js} +1 -1
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/{google-generative-ai-HTUSU45F.js → google-generative-ai-OOVDGS5W.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-AVQV4P76.js → google-vertex-IK5RNG7J.js} +1 -1
- package/dist/bundle/chunks/image-resize-worker.js +1 -1
- package/dist/bundle/chunks/kimi-coding.js +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-27QYLJZY.js → llama-cpp-classify-XHAVT37C.js} +1 -1
- package/dist/bundle/chunks/meta.js +1 -1
- package/dist/bundle/chunks/mistral-conversations-Z56KY4OJ.js +5 -0
- package/dist/bundle/chunks/{openai-codex-responses-Q25MHDFX.js → openai-codex-responses-5NAH3SK6.js} +1 -1
- package/dist/bundle/chunks/openai-completions-S7S6PO3J.js +7 -0
- package/dist/bundle/chunks/{openai-decisions-3WYFPGSK.js → openai-decisions-7A36EAHE.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-E4BNZIQK.js → openai-responses-ZQRZJKH4.js} +1 -1
- package/dist/bundle/chunks/{openrouter-images-CBP3OPOD.js → openrouter-images-X7PX72ON.js} +1 -1
- package/dist/bundle/chunks/pi-messages-TXNWPLI4.js +8 -0
- package/dist/bundle/chunks/radius.js +1 -1
- package/dist/bundle/chunks/{runtime-3RPOJS5T.js → runtime-X3XOMNXQ.js} +1 -1
- package/dist/bundle/chunks/{typesafe-system-one-BNICP2LS.js → typesafe-system-one-XJGMSHWL.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-T2KLVAFL.js +2 -0
- 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 +8 -7
- package/dist/cli/args.js.map +1 -1
- package/dist/config.d.ts +10 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +24 -5
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +0 -5
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +12 -28
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +21 -14
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +67 -93
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +4 -2
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +16 -4
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/exec.d.ts +9 -1
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js +104 -60
- package/dist/core/exec.js.map +1 -1
- package/dist/core/export-html/template.css +9 -0
- package/dist/core/export-html/template.js +165 -45
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +5 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- 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 +7 -6
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/pi-ai-extension-view.d.ts +19 -0
- package/dist/core/extensions/pi-ai-extension-view.d.ts.map +1 -0
- package/dist/core/extensions/pi-ai-extension-view.js +22 -0
- package/dist/core/extensions/pi-ai-extension-view.js.map +1 -0
- package/dist/core/extensions/runner.d.ts +0 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +7 -12
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +41 -23
- package/dist/core/extensions/types.d.ts.map +1 -1
- 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 +8 -7
- package/dist/core/extensions/virtual-modules.js.map +1 -1
- package/dist/core/mcp-servers.d.ts +11 -4
- package/dist/core/mcp-servers.d.ts.map +1 -1
- package/dist/core/mcp-servers.js +15 -5
- package/dist/core/mcp-servers.js.map +1 -1
- package/dist/core/model-config.d.ts +1678 -2029
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +2 -3
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +16 -10
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/package-manager.d.ts +14 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +160 -46
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-ai-schemas.d.ts +163 -0
- package/dist/core/pi-ai-schemas.d.ts.map +1 -0
- package/dist/core/pi-ai-schemas.js +21 -0
- package/dist/core/pi-ai-schemas.js.map +1 -0
- package/dist/core/pi-manifest.d.ts +1 -0
- package/dist/core/pi-manifest.d.ts.map +1 -1
- package/dist/core/pi-manifest.js +4 -0
- package/dist/core/pi-manifest.js.map +1 -1
- package/dist/core/project-trust.js +1 -1
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/quiescence.d.ts +24 -0
- package/dist/core/quiescence.d.ts.map +1 -0
- package/dist/core/quiescence.js +81 -0
- package/dist/core/quiescence.js.map +1 -0
- package/dist/core/resource-loader.d.ts +4 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +41 -28
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +3 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +7 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +32 -13
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +2 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +11 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +4 -2
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +8 -1
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +6 -14
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-command-name.d.ts +6 -0
- package/dist/core/slash-command-name.d.ts.map +1 -0
- package/dist/core/slash-command-name.js +11 -0
- package/dist/core/slash-command-name.js.map +1 -0
- package/dist/core/slash-commands.js +2 -2
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/source-info.d.ts +9 -0
- package/dist/core/source-info.d.ts.map +1 -1
- package/dist/core/source-info.js +13 -0
- package/dist/core/source-info.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +5 -6
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/codec.d.ts +14 -0
- package/dist/core/tasks/codec.d.ts.map +1 -1
- package/dist/core/tasks/codec.js +57 -4
- package/dist/core/tasks/codec.js.map +1 -1
- package/dist/core/tasks/record.d.ts +1 -7
- package/dist/core/tasks/record.d.ts.map +1 -1
- package/dist/core/tasks/record.js +0 -18
- package/dist/core/tasks/record.js.map +1 -1
- package/dist/core/tasks/reminder.d.ts +3 -2
- package/dist/core/tasks/reminder.d.ts.map +1 -1
- package/dist/core/tasks/reminder.js +4 -3
- package/dist/core/tasks/reminder.js.map +1 -1
- package/dist/core/tasks/runtime.d.ts +0 -2
- package/dist/core/tasks/runtime.d.ts.map +1 -1
- package/dist/core/tasks/runtime.js +2 -15
- package/dist/core/tasks/runtime.js.map +1 -1
- package/dist/core/tasks/session.d.ts +9 -2
- package/dist/core/tasks/session.d.ts.map +1 -1
- package/dist/core/tasks/session.js +23 -9
- package/dist/core/tasks/session.js.map +1 -1
- package/dist/core/tasks/types.d.ts +1 -18
- package/dist/core/tasks/types.d.ts.map +1 -1
- package/dist/core/tasks/types.js +1 -1
- package/dist/core/tasks/types.js.map +1 -1
- package/dist/core/tools/bash.d.ts +8 -7
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +6 -5
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts +3 -3
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +2 -4
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +2 -2
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +2 -2
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +1 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts +2 -2
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/powershell.d.ts +1 -5
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/core/tools/read.d.ts +2 -2
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +4 -6
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +19 -41
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/renderers/bash.d.ts.map +1 -1
- package/dist/core/tools/renderers/bash.js +3 -25
- package/dist/core/tools/renderers/bash.js.map +1 -1
- package/dist/core/tools/renderers/write.d.ts.map +1 -1
- package/dist/core/tools/renderers/write.js +18 -19
- package/dist/core/tools/renderers/write.js.map +1 -1
- package/dist/core/tools/shell-execution.d.ts +20 -13
- package/dist/core/tools/shell-execution.d.ts.map +1 -1
- package/dist/core/tools/shell-execution.js +165 -183
- package/dist/core/tools/shell-execution.js.map +1 -1
- package/dist/core/tools/shell-tool.d.ts +9 -14
- package/dist/core/tools/shell-tool.d.ts.map +1 -1
- package/dist/core/tools/shell-tool.js +38 -66
- package/dist/core/tools/shell-tool.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts +14 -4
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +2 -3
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/write.d.ts +2 -2
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +30 -13
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/core/usage-totals.d.ts +0 -9
- package/dist/core/usage-totals.d.ts.map +1 -1
- package/dist/core/usage-totals.js +24 -91
- package/dist/core/usage-totals.js.map +1 -1
- package/dist/extensions/agent/activity-lines.d.ts +2 -3
- package/dist/extensions/agent/activity-lines.d.ts.map +1 -1
- package/dist/extensions/agent/activity-lines.js +5 -9
- package/dist/extensions/agent/activity-lines.js.map +1 -1
- package/dist/extensions/agent/activity.d.ts +0 -2
- package/dist/extensions/agent/activity.d.ts.map +1 -1
- package/dist/extensions/agent/activity.js +1 -1
- package/dist/extensions/agent/activity.js.map +1 -1
- package/dist/extensions/agent/progress.d.ts +0 -3
- package/dist/extensions/agent/progress.d.ts.map +1 -1
- package/dist/extensions/agent/progress.js +2 -8
- package/dist/extensions/agent/progress.js.map +1 -1
- package/dist/extensions/agent/render.js +1 -1
- package/dist/extensions/agent/render.js.map +1 -1
- package/dist/extensions/agent/tool.d.ts.map +1 -1
- package/dist/extensions/agent/tool.js +0 -6
- package/dist/extensions/agent/tool.js.map +1 -1
- package/dist/{core/isolated-session.d.ts → extensions/agent/worker-session.d.ts} +6 -6
- package/dist/extensions/agent/worker-session.d.ts.map +1 -0
- package/dist/{core/isolated-session.js → extensions/agent/worker-session.js} +9 -9
- package/dist/extensions/agent/worker-session.js.map +1 -0
- package/dist/extensions/agent/worker.d.ts +0 -3
- package/dist/extensions/agent/worker.d.ts.map +1 -1
- package/dist/extensions/agent/worker.js +2 -3
- package/dist/extensions/agent/worker.js.map +1 -1
- package/dist/extensions/btw/agent.d.ts.map +1 -1
- package/dist/extensions/btw/agent.js +2 -1
- package/dist/extensions/btw/agent.js.map +1 -1
- package/dist/extensions/cached-compaction/render.d.ts.map +1 -1
- package/dist/extensions/cached-compaction/render.js +3 -3
- package/dist/extensions/cached-compaction/render.js.map +1 -1
- package/dist/extensions/codemode/renderer.d.ts.map +1 -1
- package/dist/extensions/codemode/renderer.js +6 -2
- package/dist/extensions/codemode/renderer.js.map +1 -1
- package/dist/extensions/codemode/tool.d.ts +2 -1
- package/dist/extensions/codemode/tool.d.ts.map +1 -1
- package/dist/extensions/codemode/tool.js +33 -8
- package/dist/extensions/codemode/tool.js.map +1 -1
- package/dist/extensions/deepwiki/schema.d.ts.map +1 -1
- package/dist/extensions/deepwiki/schema.js +1 -1
- package/dist/extensions/deepwiki/schema.js.map +1 -1
- package/dist/extensions/llama/ui.d.ts.map +1 -1
- package/dist/extensions/llama/ui.js +16 -4
- package/dist/extensions/llama/ui.js.map +1 -1
- package/dist/extensions/mcp/cli.d.ts.map +1 -1
- package/dist/extensions/mcp/cli.js +34 -8
- package/dist/extensions/mcp/cli.js.map +1 -1
- package/dist/extensions/mcp/oauth.d.ts +1 -1
- package/dist/extensions/mcp/oauth.d.ts.map +1 -1
- package/dist/extensions/mcp/oauth.js +36 -13
- package/dist/extensions/mcp/oauth.js.map +1 -1
- package/dist/extensions/mcp/ui.d.ts +1 -0
- package/dist/extensions/mcp/ui.d.ts.map +1 -1
- package/dist/extensions/mcp/ui.js +33 -24
- package/dist/extensions/mcp/ui.js.map +1 -1
- package/dist/extensions/run-summary/index.d.ts +1 -1
- package/dist/extensions/run-summary/index.d.ts.map +1 -1
- package/dist/extensions/run-summary/index.js +11 -23
- package/dist/extensions/run-summary/index.js.map +1 -1
- package/dist/extensions/statusline/usage.d.ts.map +1 -1
- package/dist/extensions/statusline/usage.js +2 -1
- package/dist/extensions/statusline/usage.js.map +1 -1
- package/dist/extensions/tasks/tool/schema.d.ts.map +1 -1
- package/dist/extensions/tasks/tool/schema.js +1 -1
- package/dist/extensions/tasks/tool/schema.js.map +1 -1
- package/dist/extensions/tasks/ui/completion-render.d.ts +5 -1
- package/dist/extensions/tasks/ui/completion-render.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/completion-render.js +25 -70
- package/dist/extensions/tasks/ui/completion-render.js.map +1 -1
- package/dist/extensions/tasks/ui/inspector.d.ts +1 -1
- package/dist/extensions/tasks/ui/inspector.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/inspector.js +0 -6
- package/dist/extensions/tasks/ui/inspector.js.map +1 -1
- package/dist/extensions/tasks/ui/manager.d.ts +1 -1
- package/dist/extensions/tasks/ui/manager.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/manager.js.map +1 -1
- package/dist/extensions/tasks/ui/views.d.ts +2 -4
- package/dist/extensions/tasks/ui/views.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/views.js +3 -7
- package/dist/extensions/tasks/ui/views.js.map +1 -1
- package/dist/extensions/tool-presentation/fallback.d.ts.map +1 -0
- package/dist/{modes/interactive/tool-view → extensions/tool-presentation}/fallback.js +5 -5
- package/dist/extensions/tool-presentation/fallback.js.map +1 -0
- package/dist/extensions/tool-presentation/index.js +1 -1
- package/dist/extensions/tool-presentation/index.js.map +1 -1
- package/dist/{modes/interactive/tool-view → extensions/tool-presentation}/shell.d.ts +1 -1
- package/dist/extensions/tool-presentation/shell.d.ts.map +1 -0
- package/dist/{modes/interactive/tool-view → extensions/tool-presentation}/shell.js +3 -3
- package/dist/extensions/tool-presentation/shell.js.map +1 -0
- package/dist/extensions/tool-search/tool.d.ts +21 -6
- package/dist/extensions/tool-search/tool.d.ts.map +1 -1
- package/dist/extensions/tool-search/tool.js +104 -36
- package/dist/extensions/tool-search/tool.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +15 -8
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +5 -3
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +61 -45
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector-skills.d.ts +54 -0
- package/dist/modes/interactive/components/config-selector-skills.d.ts.map +1 -0
- package/dist/modes/interactive/components/config-selector-skills.js +178 -0
- package/dist/modes/interactive/components/config-selector-skills.js.map +1 -0
- package/dist/modes/interactive/components/config-selector.d.ts +2 -11
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +31 -181
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +7 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-entry.js +2 -1
- package/dist/modes/interactive/components/custom-entry.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +2 -1
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/extension-editor.d.ts +2 -0
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +4 -0
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +5 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +103 -10
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/markdown-transform.d.ts +2 -1
- package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -1
- package/dist/modes/interactive/components/markdown-transform.js +3 -2
- package/dist/modes/interactive/components/markdown-transform.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +17 -6
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +1 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +13 -4
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +14 -3
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.d.ts +4 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.js +86 -22
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +2 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +15 -23
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.js +2 -0
- package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +7 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +48 -9
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +5 -6
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.d.ts +1 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.js +9 -1
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +3 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +4 -2
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/editor-host.d.ts.map +1 -1
- package/dist/modes/interactive/editor-host.js +3 -2
- package/dist/modes/interactive/editor-host.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts +1 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +17 -5
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +8 -12
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +169 -112
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/model-search.d.ts +10 -0
- package/dist/modes/interactive/model-search.d.ts.map +1 -1
- package/dist/modes/interactive/model-search.js +21 -0
- package/dist/modes/interactive/model-search.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +10 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +30 -23
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/interactive/tool-view/chat.d.ts +2 -2
- package/dist/modes/interactive/tool-view/chat.d.ts.map +1 -1
- package/dist/modes/interactive/tool-view/chat.js +22 -19
- package/dist/modes/interactive/tool-view/chat.js.map +1 -1
- package/dist/modes/interactive/transcript-layout.d.ts +2 -0
- package/dist/modes/interactive/transcript-layout.d.ts.map +1 -1
- package/dist/modes/interactive/transcript-layout.js +5 -2
- package/dist/modes/interactive/transcript-layout.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +9 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +23 -23
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +0 -3
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +55 -4
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/ansi.d.ts.map +1 -1
- package/dist/utils/ansi.js +5 -2
- package/dist/utils/ansi.js.map +1 -1
- package/dist/utils/clipboard-command.d.ts.map +1 -1
- package/dist/utils/clipboard-command.js +4 -0
- package/dist/utils/clipboard-command.js.map +1 -1
- package/dist/utils/git.d.ts +1 -1
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/git.js.map +1 -1
- package/dist/utils/image-resize-core.d.ts.map +1 -1
- package/dist/utils/image-resize-core.js +5 -3
- package/dist/utils/image-resize-core.js.map +1 -1
- package/dist/utils/open-browser.d.ts.map +1 -1
- package/dist/utils/open-browser.js +4 -1
- package/dist/utils/open-browser.js.map +1 -1
- package/dist/utils/paths.d.ts +17 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +42 -1
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +14 -0
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts +5 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +7 -0
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +30 -35
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/usage.d.ts +5 -0
- package/dist/utils/usage.d.ts.map +1 -0
- package/dist/utils/usage.js +16 -0
- package/dist/utils/usage.js.map +1 -0
- package/docs/bundled/README.md +1 -1
- package/docs/bundled/extensions/agent.md +5 -5
- package/docs/bundled/extensions/run-summary.md +4 -4
- package/docs/bundled/tasks.md +2 -4
- package/docs/bundled/tool-presentation.md +2 -2
- package/docs/custom-provider.md +1 -1
- package/docs/environment-variables.md +2 -0
- package/docs/extensions.md +36 -21
- package/docs/keybindings.md +1 -1
- package/docs/llama-cpp.md +17 -12
- package/docs/mcp.md +6 -4
- package/docs/packages.md +26 -1
- package/docs/rpc.md +1 -1
- package/docs/sdk.md +7 -5
- package/docs/session-format.md +2 -2
- package/docs/sessions.md +10 -0
- package/docs/settings.md +5 -4
- package/docs/terminal-setup.md +2 -2
- package/docs/tmux.md +6 -0
- package/docs/tui.md +12 -7
- package/docs/usage.md +19 -9
- package/docs/windows.md +29 -0
- package/examples/extensions/README.md +2 -1
- package/examples/extensions/custom-provider-anthropic/index.ts +27 -31
- 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/package.json +1 -1
- package/examples/extensions/debug-provider.ts +2 -2
- package/examples/extensions/gondolin/package-lock.json +19 -29
- package/examples/extensions/gondolin/package.json +2 -2
- package/examples/extensions/preset.ts +2 -0
- package/examples/extensions/reload-runtime.ts +17 -5
- package/examples/extensions/tools.ts +2 -0
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +9 -9
- package/schemas/models.schema.json +36 -36
- package/schemas/settings.schema.json +17 -0
- package/dist/bundle/chunks/anthropic-messages-HWL6AS7T.js +0 -6
- package/dist/bundle/chunks/azure-openai-responses-4YYPDYV5.js +0 -2
- package/dist/bundle/chunks/chunk-6JS2SOFO.js +0 -11
- package/dist/bundle/chunks/chunk-ANCZPKX7.js +0 -2
- package/dist/bundle/chunks/chunk-FEZ5RM2B.js +0 -2
- package/dist/bundle/chunks/chunk-LPF7HQ3S.js +0 -4
- package/dist/bundle/chunks/chunk-MMNIHCU7.js +0 -2
- package/dist/bundle/chunks/chunk-PUU43PDV.js +0 -1484
- package/dist/bundle/chunks/chunk-R267VV5T.js +0 -82
- package/dist/bundle/chunks/chunk-RVKT7OUB.js +0 -9
- package/dist/bundle/chunks/chunk-SA2AQYEI.js +0 -7
- package/dist/bundle/chunks/chunk-ZAIGBRV5.js +0 -16
- package/dist/bundle/chunks/mistral-conversations-V2JJTMJ5.js +0 -5
- package/dist/bundle/chunks/openai-completions-TXZXILJR.js +0 -7
- package/dist/bundle/chunks/pi-messages-LBJQ4NGP.js +0 -8
- package/dist/bundle/chunks/virtual-modules-63XNTSVN.js +0 -2
- package/dist/core/isolated-session.d.ts.map +0 -1
- package/dist/core/isolated-session.js.map +0 -1
- package/dist/modes/interactive/tool-view/fallback.d.ts.map +0 -1
- package/dist/modes/interactive/tool-view/fallback.js.map +0 -1
- package/dist/modes/interactive/tool-view/shell.d.ts.map +0 -1
- package/dist/modes/interactive/tool-view/shell.js.map +0 -1
- package/dist/utils/path-identity.d.ts +0 -12
- package/dist/utils/path-identity.d.ts.map +0 -1
- package/dist/utils/path-identity.js +0 -63
- package/dist/utils/path-identity.js.map +0 -1
- package/examples/extensions/sandbox/index.ts +0 -321
- package/examples/extensions/sandbox/package-lock.json +0 -92
- package/examples/extensions/sandbox/package.json +0 -19
- /package/dist/{modes/interactive/tool-view → extensions/tool-presentation}/fallback.d.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAEhE,MAAM,WAAW,wBAAwB;IACxC,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,iBAAiB,CAAC,EAAE,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AM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG,SAAS,CAS3C"}
|
|
@@ -80,19 +80,18 @@ export function buildSystemPromptSections(input) {
|
|
|
80
80
|
}
|
|
81
81
|
else {
|
|
82
82
|
promptSections.preamble =
|
|
83
|
-
"You are
|
|
83
|
+
"You are a coding assistant running inside pi, a coding agent harness. Help users inspect files, run commands, and modify code.";
|
|
84
84
|
const visibleTools = declaredTools.filter((name) => !!toolSnippets[name]);
|
|
85
85
|
const tools = visibleTools.length > 0 ? visibleTools.map((name) => `- ${name}: ${toolSnippets[name]}`).join("\n") : "(none)";
|
|
86
|
-
promptSections.tools = `${tools}\n\
|
|
86
|
+
promptSections.tools = `${tools}\n\nAdditional tools may be available.`;
|
|
87
87
|
promptSections.rules = buildRules(declaredTools, toolGuidelines, promptGuidelines);
|
|
88
|
-
promptSections.docs = `Pi documentation (read only when the user asks about
|
|
88
|
+
promptSections.docs = `Pi documentation (read only when the user asks about the harness itself, its SDK, extensions, themes, skills, or TUI):
|
|
89
89
|
- Main documentation: ${getReadmePath()}
|
|
90
90
|
- Additional docs: ${getDocsPath()}
|
|
91
91
|
- Examples: ${getExamplesPath()} (extensions, custom tools, SDK)
|
|
92
92
|
- When reading pi docs or examples, resolve docs/... under Additional docs and examples/... under Examples, not the current working directory
|
|
93
|
-
- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md),
|
|
94
|
-
-
|
|
95
|
-
- Always read pi .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;
|
|
93
|
+
- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), packages (docs/packages.md), environment variables (docs/environment-variables.md), MCP servers (docs/mcp.md), codemode scripts and non-LLM models such as classifiers and image models (docs/codemode.md)
|
|
94
|
+
- Before implementing harness changes, read the relevant docs and examples in full, following related cross-references.`;
|
|
96
95
|
}
|
|
97
96
|
if (appendSystemPrompt)
|
|
98
97
|
promptSections.addendum = appendSystemPrompt;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAmDhE,MAAM,0BAA0B,GAAG,oBAAoB,CAAC;AACxD,gGAAgG;AAChG,MAAM,UAAU,iCAAiC,CAAC,KAA+B;IAChF,OAAO;QACN,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;QAC1C,aAAa,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,aAAa,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QAC9E,WAAW,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;QAC3C,YAAY,EAAE,EAAE,GAAG,CAAC,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,EAAE;QAC/C,cAAc,EAAE,MAAM,CAAC,WAAW,CACjC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CA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I,OAAO,CAAC,IAAI,CAAC,KAAK,SAAS;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACrD,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getSystemMessageText } from \"@earendil-works/pi-ai\";\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.ts\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.ts\";\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces the default prefix). */\n\tcustomPrompt?: string;\n\t/** Exact full prompt replacement set by a before_agent_start handler. */\n\tforceSystemPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write]. */\n\tselectedTools?: string[];\n\t/**\n\t * Selected tools whose declarations requests leave out (`prepareLoadout` hidden declarations).\n\t * They are reachable only through another tool, so the tool list and rules leave them out too.\n\t */\n\thiddenTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Guideline bullets contributed by each tool, keyed by tool name. */\n\ttoolGuidelines?: Record<string, string[]>;\n\t/** Additional guideline bullets appended to the default system prompt rules. */\n\tpromptGuidelines?: string[];\n\t/** Text appended from user configuration before project context, skills, and cwd. */\n\tappendSystemPrompt?: string;\n\t/** Additional XML-wrapped prompt sections keyed by tag name. */\n\tsections?: Record<string, string>;\n\t/** Working directory. */\n\tcwd: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\nexport type NormalizedBuildSystemPromptOptions = BuildSystemPromptOptions & {\n\tselectedTools: string[];\n\thiddenTools: string[];\n\ttoolSnippets: Record<string, string>;\n\ttoolGuidelines: Record<string, string[]>;\n\tpromptGuidelines: string[];\n\tappendSystemPrompt: string;\n\tsections: Record<string, string>;\n\tcontextFiles: Array<{ path: string; content: string }>;\n\tskills: Skill[];\n};\n\n/**\n * Ordered system prompt sections, keyed by name. `preamble` is untagged text; every other\n * section is wrapped in a tag of the same name so the model can match later updates to it.\n * These become `SystemMessage.sections` in the transcript.\n */\nexport type SystemPromptSections = Record<string, string>;\n\nconst SYSTEM_PROMPT_SECTION_NAME = /^[a-z][a-z0-9_-]*$/;\n/** Normalize prompt input into the mutable, collection-complete shape exposed to extensions. */\nexport function normalizeBuildSystemPromptOptions(input: BuildSystemPromptOptions): NormalizedBuildSystemPromptOptions {\n\treturn {\n\t\tcustomPrompt: input.customPrompt,\n\t\tforceSystemPrompt: input.forceSystemPrompt,\n\t\tselectedTools: [...(input.selectedTools ?? [\"read\", \"bash\", \"edit\", \"write\"])],\n\t\thiddenTools: [...(input.hiddenTools ?? [])],\n\t\ttoolSnippets: { ...(input.toolSnippets ?? {}) },\n\t\ttoolGuidelines: Object.fromEntries(\n\t\t\tObject.entries(input.toolGuidelines ?? {}).map(([name, guidelines]) => [name, [...guidelines]]),\n\t\t),\n\t\tpromptGuidelines: [...(input.promptGuidelines ?? [])],\n\t\tappendSystemPrompt: input.appendSystemPrompt ?? \"\",\n\t\tsections: { ...(input.sections ?? {}) },\n\t\tcwd: input.cwd,\n\t\tcontextFiles: (input.contextFiles ?? []).map((file) => ({ ...file })),\n\t\tskills: (input.skills ?? []).map((skill) => ({ ...skill })),\n\t};\n}\n\nfunction renderProjectContext(contextFiles: Array<{ path: string; content: string }>): string {\n\treturn [\n\t\t\"Project-specific instructions and guidelines:\",\n\t\t...contextFiles.map(\n\t\t\t({ path, content }) => `<project_instructions path=\"${path}\">\\n${content}\\n</project_instructions>`,\n\t\t),\n\t].join(\"\\n\\n\");\n}\n\nfunction buildRules(\n\tselectedTools: string[],\n\ttoolGuidelines: Record<string, string[]>,\n\tpromptGuidelines: string[],\n): string {\n\tconst rules: string[] = [];\n\tconst seen = new Set<string>();\n\tconst addRule = (rule: string): void => {\n\t\tconst normalized = rule.trim();\n\t\tif (!normalized || seen.has(normalized)) return;\n\t\tseen.add(normalized);\n\t\trules.push(normalized);\n\t};\n\n\tconst hasBash = selectedTools.includes(\"bash\");\n\tconst hasPowerShell = selectedTools.includes(\"powershell\");\n\tconst hasGrep = selectedTools.includes(\"grep\");\n\tconst hasFind = selectedTools.includes(\"find\");\n\tconst hasLs = selectedTools.includes(\"ls\");\n\n\tif ((hasBash || hasPowerShell) && !hasGrep && !hasFind && !hasLs) {\n\t\tif (hasBash && hasPowerShell) {\n\t\t\taddRule(\"Use bash or PowerShell for file operations like listing, searching, and finding files\");\n\t\t} else if (hasPowerShell) {\n\t\t\taddRule(\"Use PowerShell for file operations like listing, searching, and finding files\");\n\t\t} else {\n\t\t\taddRule(\"Use bash for file operations like ls, rg, find\");\n\t\t}\n\t}\n\n\tfor (const name of selectedTools) {\n\t\tfor (const rule of toolGuidelines[name] ?? []) addRule(rule);\n\t}\n\tfor (const rule of promptGuidelines) addRule(rule);\n\taddRule(\"Be concise in your responses\");\n\taddRule(\"Show file paths clearly when working with files\");\n\treturn rules.map((rule) => `- ${rule}`).join(\"\\n\");\n}\n\n/** Build the ordered, independently replaceable sections of the structured system prompt. */\nexport function buildSystemPromptSections(input: BuildSystemPromptOptions): SystemPromptSections {\n\tconst options = normalizeBuildSystemPromptOptions(input);\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\thiddenTools,\n\t\ttoolSnippets,\n\t\ttoolGuidelines,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tsections: customSections,\n\t\tcwd,\n\t\tcontextFiles,\n\t\tskills,\n\t} = options;\n\n\tfor (const name of Object.keys(customSections)) {\n\t\tif (!SYSTEM_PROMPT_SECTION_NAME.test(name) || name === \"preamble\") {\n\t\t\tthrow new Error(`Invalid system prompt section name: ${name}`);\n\t\t}\n\t}\n\n\tconst declaredTools = selectedTools.filter((name) => !hiddenTools.includes(name));\n\tconst promptSections: Record<string, string> = {};\n\tif (customPrompt) {\n\t\tpromptSections.preamble = customPrompt;\n\t} else {\n\t\tpromptSections.preamble =\n\t\t\t\"You are an expert coding assistant operating inside pi, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\";\n\t\tconst visibleTools = declaredTools.filter((name) => !!toolSnippets[name]);\n\t\tconst tools =\n\t\t\tvisibleTools.length > 0 ? visibleTools.map((name) => `- ${name}: ${toolSnippets[name]}`).join(\"\\n\") : \"(none)\";\n\t\tpromptSections.tools = `${tools}\\n\\nIn addition to the tools above, you may have access to other custom tools depending on the project.`;\n\t\tpromptSections.rules = buildRules(declaredTools, toolGuidelines, promptGuidelines);\n\t\tpromptSections.docs = `Pi documentation (read only when the user asks about pi itself, its SDK, extensions, themes, skills, or TUI):\n- Main documentation: ${getReadmePath()}\n- Additional docs: ${getDocsPath()}\n- Examples: ${getExamplesPath()} (extensions, custom tools, SDK)\n- When reading pi docs or examples, resolve docs/... under Additional docs and examples/... under Examples, not the current working directory\n- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), pi packages (docs/packages.md), environment variables (docs/environment-variables.md), MCP servers (docs/mcp.md), codemode scripts and non-LLM models such as classifiers and image models (docs/codemode.md)\n- When working on pi topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read pi .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\t}\n\n\tif (appendSystemPrompt) promptSections.addendum = appendSystemPrompt;\n\tif (contextFiles.length > 0) promptSections.project_context = renderProjectContext(contextFiles);\n\t// A hidden reader is still reachable through another tool, so skills stay but the hint names no tool.\n\tconst readers = [\"read\", \"bash\"] as const;\n\tconst skillFileReadTool =\n\t\treaders.find((tool) => declaredTools.includes(tool)) ??\n\t\t(readers.some((tool) => selectedTools.includes(tool)) ? \"indirect\" : undefined);\n\tif (skillFileReadTool && skills.length > 0) {\n\t\tconst skillsPrompt = formatSkillsForPrompt(skills, skillFileReadTool).trim();\n\t\tif (skillsPrompt) promptSections.skills = skillsPrompt;\n\t}\n\tpromptSections.cwd = cwd.replace(/\\\\/g, \"/\");\n\tfor (const [name, content] of Object.entries(customSections)) {\n\t\tif (content) promptSections[name] = content;\n\t}\n\n\tconst sections: SystemPromptSections = { preamble: promptSections.preamble };\n\tfor (const [name, content] of Object.entries(promptSections)) {\n\t\tif (name !== \"preamble\") sections[name] = `<${name}>\\n${content}\\n</${name}>`;\n\t}\n\treturn sections;\n}\n\n/**\n * The complete prompt state for `input`. A forced prompt is opaque and lives in `content`\n * with no sections; otherwise `content` is empty and the structured sections carry the prompt.\n */\nexport function buildSystemPromptState(input: BuildSystemPromptOptions): {\n\tcontent: string;\n\tsections?: SystemPromptSections;\n} {\n\tif (input.forceSystemPrompt !== undefined) return { content: input.forceSystemPrompt };\n\treturn { content: \"\", sections: buildSystemPromptSections(input) };\n}\n\n/** Build the system prompt text, rendered exactly as the transcript's system message replays it. */\nexport function buildSystemPrompt(input: BuildSystemPromptOptions): string {\n\treturn getSystemMessageText({ role: \"system\", ...buildSystemPromptState(input), timestamp: 0 });\n}\n\n/**\n * Diff the sections the model currently has (replayed from the transcript, so never null)\n * against the desired ones. Returns a `SystemMessage.sections` patch, or undefined when\n * nothing changed.\n */\nexport function diffSystemPromptSections(\n\tprevious: Record<string, string | null>,\n\tcurrent: SystemPromptSections,\n): Record<string, string | null> | undefined {\n\tconst patch: Record<string, string | null> = {};\n\tfor (const [name, text] of Object.entries(current)) {\n\t\tif (previous[name] !== text) patch[name] = text;\n\t}\n\tfor (const name of Object.keys(previous)) {\n\t\tif (current[name] === undefined) patch[name] = null;\n\t}\n\treturn Object.keys(patch).length > 0 ? patch : undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.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AC;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAA+B;IAIrE,IAAI,KAAK,CAAC,iBAAiB,KAAK,SAAS;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,iBAAiB,EAAE,CAAC;IACvF,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,yBAAyB,CAAC,KAAK,CAAC,EAAE,CAAC;AACpE,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,iBAAiB,CAAC,KAA+B;IAChE,OAAO,oBAAoB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,sBAAsB,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;AACjG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CACvC,QAAuC,EACvC,OAA6B;IAE7B,MAAM,KAAK,GAAkC,EAAE,CAAC;IAChD,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACjD,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1C,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,SAAS;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACrD,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getSystemMessageText } from \"@earendil-works/pi-ai\";\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.ts\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.ts\";\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces the default prefix). */\n\tcustomPrompt?: string;\n\t/** Exact full prompt replacement set by a before_agent_start handler. */\n\tforceSystemPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write]. */\n\tselectedTools?: string[];\n\t/**\n\t * Selected tools whose declarations requests leave out (`prepareLoadout` hidden declarations).\n\t * They are reachable only through another tool, so the tool list and rules leave them out too.\n\t */\n\thiddenTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Guideline bullets contributed by each tool, keyed by tool name. */\n\ttoolGuidelines?: Record<string, string[]>;\n\t/** Additional guideline bullets appended to the default system prompt rules. */\n\tpromptGuidelines?: string[];\n\t/** Text appended from user configuration before project context, skills, and cwd. */\n\tappendSystemPrompt?: string;\n\t/** Additional XML-wrapped prompt sections keyed by tag name. */\n\tsections?: Record<string, string>;\n\t/** Working directory. */\n\tcwd: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\nexport type NormalizedBuildSystemPromptOptions = BuildSystemPromptOptions & {\n\tselectedTools: string[];\n\thiddenTools: string[];\n\ttoolSnippets: Record<string, string>;\n\ttoolGuidelines: Record<string, string[]>;\n\tpromptGuidelines: string[];\n\tappendSystemPrompt: string;\n\tsections: Record<string, string>;\n\tcontextFiles: Array<{ path: string; content: string }>;\n\tskills: Skill[];\n};\n\n/**\n * Ordered system prompt sections, keyed by name. `preamble` is untagged text; every other\n * section is wrapped in a tag of the same name so the model can match later updates to it.\n * These become `SystemMessage.sections` in the transcript.\n */\nexport type SystemPromptSections = Record<string, string>;\n\nconst SYSTEM_PROMPT_SECTION_NAME = /^[a-z][a-z0-9_-]*$/;\n/** Normalize prompt input into the mutable, collection-complete shape exposed to extensions. */\nexport function normalizeBuildSystemPromptOptions(input: BuildSystemPromptOptions): NormalizedBuildSystemPromptOptions {\n\treturn {\n\t\tcustomPrompt: input.customPrompt,\n\t\tforceSystemPrompt: input.forceSystemPrompt,\n\t\tselectedTools: [...(input.selectedTools ?? [\"read\", \"bash\", \"edit\", \"write\"])],\n\t\thiddenTools: [...(input.hiddenTools ?? [])],\n\t\ttoolSnippets: { ...(input.toolSnippets ?? {}) },\n\t\ttoolGuidelines: Object.fromEntries(\n\t\t\tObject.entries(input.toolGuidelines ?? {}).map(([name, guidelines]) => [name, [...guidelines]]),\n\t\t),\n\t\tpromptGuidelines: [...(input.promptGuidelines ?? [])],\n\t\tappendSystemPrompt: input.appendSystemPrompt ?? \"\",\n\t\tsections: { ...(input.sections ?? {}) },\n\t\tcwd: input.cwd,\n\t\tcontextFiles: (input.contextFiles ?? []).map((file) => ({ ...file })),\n\t\tskills: (input.skills ?? []).map((skill) => ({ ...skill })),\n\t};\n}\n\nfunction renderProjectContext(contextFiles: Array<{ path: string; content: string }>): string {\n\treturn [\n\t\t\"Project-specific instructions and guidelines:\",\n\t\t...contextFiles.map(\n\t\t\t({ path, content }) => `<project_instructions path=\"${path}\">\\n${content}\\n</project_instructions>`,\n\t\t),\n\t].join(\"\\n\\n\");\n}\n\nfunction buildRules(\n\tselectedTools: string[],\n\ttoolGuidelines: Record<string, string[]>,\n\tpromptGuidelines: string[],\n): string {\n\tconst rules: string[] = [];\n\tconst seen = new Set<string>();\n\tconst addRule = (rule: string): void => {\n\t\tconst normalized = rule.trim();\n\t\tif (!normalized || seen.has(normalized)) return;\n\t\tseen.add(normalized);\n\t\trules.push(normalized);\n\t};\n\n\tconst hasBash = selectedTools.includes(\"bash\");\n\tconst hasPowerShell = selectedTools.includes(\"powershell\");\n\tconst hasGrep = selectedTools.includes(\"grep\");\n\tconst hasFind = selectedTools.includes(\"find\");\n\tconst hasLs = selectedTools.includes(\"ls\");\n\n\tif ((hasBash || hasPowerShell) && !hasGrep && !hasFind && !hasLs) {\n\t\tif (hasBash && hasPowerShell) {\n\t\t\taddRule(\"Use bash or PowerShell for file operations like listing, searching, and finding files\");\n\t\t} else if (hasPowerShell) {\n\t\t\taddRule(\"Use PowerShell for file operations like listing, searching, and finding files\");\n\t\t} else {\n\t\t\taddRule(\"Use bash for file operations like ls, rg, find\");\n\t\t}\n\t}\n\n\tfor (const name of selectedTools) {\n\t\tfor (const rule of toolGuidelines[name] ?? []) addRule(rule);\n\t}\n\tfor (const rule of promptGuidelines) addRule(rule);\n\taddRule(\"Be concise in your responses\");\n\taddRule(\"Show file paths clearly when working with files\");\n\treturn rules.map((rule) => `- ${rule}`).join(\"\\n\");\n}\n\n/** Build the ordered, independently replaceable sections of the structured system prompt. */\nexport function buildSystemPromptSections(input: BuildSystemPromptOptions): SystemPromptSections {\n\tconst options = normalizeBuildSystemPromptOptions(input);\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\thiddenTools,\n\t\ttoolSnippets,\n\t\ttoolGuidelines,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tsections: customSections,\n\t\tcwd,\n\t\tcontextFiles,\n\t\tskills,\n\t} = options;\n\n\tfor (const name of Object.keys(customSections)) {\n\t\tif (!SYSTEM_PROMPT_SECTION_NAME.test(name) || name === \"preamble\") {\n\t\t\tthrow new Error(`Invalid system prompt section name: ${name}`);\n\t\t}\n\t}\n\n\tconst declaredTools = selectedTools.filter((name) => !hiddenTools.includes(name));\n\tconst promptSections: Record<string, string> = {};\n\tif (customPrompt) {\n\t\tpromptSections.preamble = customPrompt;\n\t} else {\n\t\tpromptSections.preamble =\n\t\t\t\"You are a coding assistant running inside pi, a coding agent harness. Help users inspect files, run commands, and modify code.\";\n\t\tconst visibleTools = declaredTools.filter((name) => !!toolSnippets[name]);\n\t\tconst tools =\n\t\t\tvisibleTools.length > 0 ? visibleTools.map((name) => `- ${name}: ${toolSnippets[name]}`).join(\"\\n\") : \"(none)\";\n\t\tpromptSections.tools = `${tools}\\n\\nAdditional tools may be available.`;\n\t\tpromptSections.rules = buildRules(declaredTools, toolGuidelines, promptGuidelines);\n\t\tpromptSections.docs = `Pi documentation (read only when the user asks about the harness itself, its SDK, extensions, themes, skills, or TUI):\n- Main documentation: ${getReadmePath()}\n- Additional docs: ${getDocsPath()}\n- Examples: ${getExamplesPath()} (extensions, custom tools, SDK)\n- When reading pi docs or examples, resolve docs/... under Additional docs and examples/... under Examples, not the current working directory\n- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), packages (docs/packages.md), environment variables (docs/environment-variables.md), MCP servers (docs/mcp.md), codemode scripts and non-LLM models such as classifiers and image models (docs/codemode.md)\n- Before implementing harness changes, read the relevant docs and examples in full, following related cross-references.`;\n\t}\n\n\tif (appendSystemPrompt) promptSections.addendum = appendSystemPrompt;\n\tif (contextFiles.length > 0) promptSections.project_context = renderProjectContext(contextFiles);\n\t// A hidden reader is still reachable through another tool, so skills stay but the hint names no tool.\n\tconst readers = [\"read\", \"bash\"] as const;\n\tconst skillFileReadTool =\n\t\treaders.find((tool) => declaredTools.includes(tool)) ??\n\t\t(readers.some((tool) => selectedTools.includes(tool)) ? \"indirect\" : undefined);\n\tif (skillFileReadTool && skills.length > 0) {\n\t\tconst skillsPrompt = formatSkillsForPrompt(skills, skillFileReadTool).trim();\n\t\tif (skillsPrompt) promptSections.skills = skillsPrompt;\n\t}\n\tpromptSections.cwd = cwd.replace(/\\\\/g, \"/\");\n\tfor (const [name, content] of Object.entries(customSections)) {\n\t\tif (content) promptSections[name] = content;\n\t}\n\n\tconst sections: SystemPromptSections = { preamble: promptSections.preamble };\n\tfor (const [name, content] of Object.entries(promptSections)) {\n\t\tif (name !== \"preamble\") sections[name] = `<${name}>\\n${content}\\n</${name}>`;\n\t}\n\treturn sections;\n}\n\n/**\n * The complete prompt state for `input`. A forced prompt is opaque and lives in `content`\n * with no sections; otherwise `content` is empty and the structured sections carry the prompt.\n */\nexport function buildSystemPromptState(input: BuildSystemPromptOptions): {\n\tcontent: string;\n\tsections?: SystemPromptSections;\n} {\n\tif (input.forceSystemPrompt !== undefined) return { content: input.forceSystemPrompt };\n\treturn { content: \"\", sections: buildSystemPromptSections(input) };\n}\n\n/** Build the system prompt text, rendered exactly as the transcript's system message replays it. */\nexport function buildSystemPrompt(input: BuildSystemPromptOptions): string {\n\treturn getSystemMessageText({ role: \"system\", ...buildSystemPromptState(input), timestamp: 0 });\n}\n\n/**\n * Diff the sections the model currently has (replayed from the transcript, so never null)\n * against the desired ones. Returns a `SystemMessage.sections` patch, or undefined when\n * nothing changed.\n */\nexport function diffSystemPromptSections(\n\tprevious: Record<string, string | null>,\n\tcurrent: SystemPromptSections,\n): Record<string, string | null> | undefined {\n\tconst patch: Record<string, string | null> = {};\n\tfor (const [name, text] of Object.entries(current)) {\n\t\tif (previous[name] !== text) patch[name] = text;\n\t}\n\tfor (const name of Object.keys(previous)) {\n\t\tif (current[name] === undefined) patch[name] = null;\n\t}\n\treturn Object.keys(patch).length > 0 ? patch : undefined;\n}\n"]}
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one reader for persisted task snapshots: session `task-record` entries and
|
|
3
|
+
* `task-completion` message details share this format and these bounds. It also reads the
|
|
4
|
+
* usage settlement those entries carry for session totals.
|
|
5
|
+
*/
|
|
6
|
+
import type { Usage } from "@earendil-works/pi-ai/compat";
|
|
7
|
+
import type { SessionEntry } from "../session-manager.ts";
|
|
1
8
|
import { type TaskSnapshot } from "./types.ts";
|
|
2
9
|
export declare const TASK_RECORD_TYPE = "task-record";
|
|
3
10
|
/** Shared by `task-record` entries and `task-completion` details. */
|
|
4
11
|
export declare const TASK_SNAPSHOT_VERSION = 3;
|
|
12
|
+
/** One task's usage settlement, as session totals account for it. */
|
|
13
|
+
export interface TaskUsageRecord {
|
|
14
|
+
taskId: string;
|
|
15
|
+
usage: Usage;
|
|
16
|
+
}
|
|
5
17
|
/** Read persisted data properties only; never invoke getters or custom serialization. */
|
|
6
18
|
export declare function plainObject(value: unknown): Record<string, unknown>;
|
|
7
19
|
export declare function field(object: object, key: string): unknown;
|
|
@@ -9,4 +21,6 @@ export declare function field(object: object, key: string): unknown;
|
|
|
9
21
|
export declare function readPersistedTask(value: unknown): TaskSnapshot | undefined;
|
|
10
22
|
/** The task saved by a `task-record` entry or `task-completion` details. */
|
|
11
23
|
export declare function readVersionedTask(value: unknown): TaskSnapshot | undefined;
|
|
24
|
+
/** The usage a `task-record` entry, or a released `task-usage` entry, settles for its task. */
|
|
25
|
+
export declare function readTaskUsage(entry: SessionEntry): TaskUsageRecord | undefined;
|
|
12
26
|
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/codec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/codec.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAY1D,OAAO,EAKN,KAAK,YAAY,EAGjB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAC9C,qEAAqE;AACrE,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAIvC,qEAAqE;AACrE,MAAM,WAAW,eAAe;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;CACb;AAED,yFAAyF;AACzF,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAKnE;AAED,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAI1D;AAmDD,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,GAAG,SAAS,CAgD1E;AAED,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,GAAG,SAAS,CAO1E;AA+BD,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,eAAe,GAAG,SAAS,CAkB9E"}
|
package/dist/core/tasks/codec.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The one reader for persisted task snapshots: session `task-record` entries and
|
|
3
|
-
* `task-completion` message details share this format and these bounds.
|
|
4
|
-
*/
|
|
5
1
|
import { boundText, TASK_ERROR_BYTES, TASK_FACT_BYTES, TASK_FACTS, TASK_INPUT_BYTES, TASK_LABEL_BYTES, TASK_PATH_BYTES, TASK_RESULT_BYTES, TASK_TITLE_BYTES, } from "./output.js";
|
|
6
2
|
import { isTaskTerminal, TASK_KIND_PATTERN, } from "./types.js";
|
|
7
3
|
export const TASK_RECORD_TYPE = "task-record";
|
|
8
4
|
/** Shared by `task-record` entries and `task-completion` details. */
|
|
9
5
|
export const TASK_SNAPSHOT_VERSION = 3;
|
|
6
|
+
/** Released sessions settled usage in separate entries; their billing still counts. */
|
|
7
|
+
const LEGACY_TASK_USAGE_TYPE = "task-usage";
|
|
10
8
|
/** Read persisted data properties only; never invoke getters or custom serialization. */
|
|
11
9
|
export function plainObject(value) {
|
|
12
10
|
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
@@ -136,4 +134,59 @@ export function readVersionedTask(value) {
|
|
|
136
134
|
return undefined;
|
|
137
135
|
}
|
|
138
136
|
}
|
|
137
|
+
function usageValue(value) {
|
|
138
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
|
|
139
|
+
throw new Error("Expected usage value");
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
/** Only the serializable accounting fields, so a settlement never carries provider extras into totals. */
|
|
143
|
+
function taskUsage(value) {
|
|
144
|
+
const source = plainObject(value);
|
|
145
|
+
const cost = plainObject(field(source, "cost"));
|
|
146
|
+
const reasoning = optional(source, "reasoning", usageValue);
|
|
147
|
+
const cacheWrite1h = optional(source, "cacheWrite1h", usageValue);
|
|
148
|
+
return {
|
|
149
|
+
input: usageValue(field(source, "input")),
|
|
150
|
+
output: usageValue(field(source, "output")),
|
|
151
|
+
cacheRead: usageValue(field(source, "cacheRead")),
|
|
152
|
+
cacheWrite: usageValue(field(source, "cacheWrite")),
|
|
153
|
+
totalTokens: usageValue(field(source, "totalTokens")),
|
|
154
|
+
...(reasoning === undefined ? {} : { reasoning }),
|
|
155
|
+
...(cacheWrite1h === undefined ? {} : { cacheWrite1h }),
|
|
156
|
+
cost: {
|
|
157
|
+
input: usageValue(field(cost, "input")),
|
|
158
|
+
output: usageValue(field(cost, "output")),
|
|
159
|
+
cacheRead: usageValue(field(cost, "cacheRead")),
|
|
160
|
+
cacheWrite: usageValue(field(cost, "cacheWrite")),
|
|
161
|
+
total: usageValue(field(cost, "total")),
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** The usage a `task-record` entry, or a released `task-usage` entry, settles for its task. */
|
|
166
|
+
export function readTaskUsage(entry) {
|
|
167
|
+
if (entry.type !== "custom")
|
|
168
|
+
return undefined;
|
|
169
|
+
if (entry.customType !== TASK_RECORD_TYPE && entry.customType !== LEGACY_TASK_USAGE_TYPE)
|
|
170
|
+
return undefined;
|
|
171
|
+
try {
|
|
172
|
+
const data = plainObject(entry.data);
|
|
173
|
+
let taskId;
|
|
174
|
+
if (entry.customType === TASK_RECORD_TYPE) {
|
|
175
|
+
if (field(data, "version") !== TASK_SNAPSHOT_VERSION)
|
|
176
|
+
return undefined;
|
|
177
|
+
taskId = field(plainObject(field(data, "task")), "id");
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
if (field(data, "version") !== 1)
|
|
181
|
+
return undefined;
|
|
182
|
+
taskId = field(data, "taskId");
|
|
183
|
+
}
|
|
184
|
+
if (typeof taskId !== "string" || !taskId.trim())
|
|
185
|
+
return undefined;
|
|
186
|
+
return { taskId, usage: taskUsage(field(data, "usage")) };
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
139
192
|
//# sourceMappingURL=codec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../../src/core/tasks/codec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACN,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,cAAc,EACd,iBAAiB,GAMjB,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAC9C,qEAAqE;AACrE,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEvC,yFAAyF;AACzF,MAAM,UAAU,WAAW,CAAC,KAAc;IACzC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAC5G,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACnG,OAAO,KAAgC,CAAC;AACzC,CAAC;AAED,MA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,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAClH,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC","sourcesContent":["/**\n * The one reader for persisted task snapshots: session `task-record` entries and\n * `task-completion` message details share this format and these bounds.\n */\nimport {\n\tboundText,\n\tTASK_ERROR_BYTES,\n\tTASK_FACT_BYTES,\n\tTASK_FACTS,\n\tTASK_INPUT_BYTES,\n\tTASK_LABEL_BYTES,\n\tTASK_PATH_BYTES,\n\tTASK_RESULT_BYTES,\n\tTASK_TITLE_BYTES,\n} from \"./output.ts\";\nimport {\n\tisTaskTerminal,\n\tTASK_KIND_PATTERN,\n\ttype TaskFact,\n\ttype TaskInput,\n\ttype TaskSnapshot,\n\ttype TaskStatus,\n\ttype TaskText,\n} from \"./types.ts\";\n\nexport const TASK_RECORD_TYPE = \"task-record\";\n/** Shared by `task-record` entries and `task-completion` details. */\nexport const TASK_SNAPSHOT_VERSION = 3;\n\n/** Read persisted data properties only; never invoke getters or custom serialization. */\nexport function plainObject(value: unknown): Record<string, unknown> {\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) throw new Error(\"Expected object\");\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) throw new Error(\"Expected plain object\");\n\treturn value as Record<string, unknown>;\n}\n\nexport function field(object: object, key: string): unknown {\n\tconst descriptor = Object.getOwnPropertyDescriptor(object, key);\n\tif (descriptor && !(\"value\" in descriptor)) throw new Error(\"Unexpected accessor\");\n\treturn descriptor?.value;\n}\n\nfunction text(value: unknown, bytes: number): string {\n\tif (typeof value !== \"string\") throw new Error(\"Expected string\");\n\treturn boundText(value, bytes);\n}\n\n/** Identities and paths are never clipped: a shortened value would name something else. */\nfunction exact(value: unknown, bytes: number): string {\n\tif (typeof value !== \"string\" || !value || Buffer.byteLength(value) > bytes || value.includes(\"\\0\"))\n\t\tthrow new Error(\"Invalid identity or path\");\n\treturn value;\n}\n\nfunction optional<T>(source: object, key: string, read: (value: unknown) => T): T | undefined {\n\tconst value = field(source, key);\n\treturn value === undefined ? undefined : read(value);\n}\n\nfunction taskText(value: unknown, bytes: number): TaskText {\n\tconst source = plainObject(value);\n\tconst original = field(source, \"text\");\n\tconst truncated = field(source, \"truncated\");\n\tif (typeof truncated !== \"boolean\") throw new Error(\"Expected truncation flag\");\n\tconst bounded = text(original, bytes);\n\treturn { text: bounded, truncated: truncated || bounded !== original };\n}\n\nfunction taskInput(value: unknown): TaskInput {\n\tconst source = plainObject(value);\n\tconst language = optional(source, \"language\", (item) => text(item, 64));\n\treturn {\n\t\tlabel: text(field(source, \"label\"), TASK_LABEL_BYTES),\n\t\t...taskText(source, TASK_INPUT_BYTES),\n\t\t...(language ? { language } : {}),\n\t};\n}\n\nfunction taskFacts(value: unknown): TaskFact[] {\n\tif (!Array.isArray(value)) throw new Error(\"Expected facts\");\n\treturn value.slice(0, TASK_FACTS).map((row): TaskFact => {\n\t\tif (!Array.isArray(row) || row.length !== 2) throw new Error(\"Expected fact\");\n\t\treturn [text(row[0], TASK_LABEL_BYTES), text(row[1], TASK_FACT_BYTES)];\n\t});\n}\n\nfunction timestamp(value: unknown): number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0) throw new Error(\"Expected time\");\n\treturn value;\n}\n\n/** A bounded terminal snapshot, or undefined for any other shape or version. */\nexport function readPersistedTask(value: unknown): TaskSnapshot | undefined {\n\ttry {\n\t\tconst source = plainObject(value);\n\t\tconst kind = field(source, \"kind\");\n\t\tconst mode = field(source, \"mode\");\n\t\tconst status = field(source, \"status\") as TaskStatus;\n\t\tconst output = field(source, \"output\");\n\t\tif (typeof kind !== \"string\" || !TASK_KIND_PATTERN.test(kind)) return undefined;\n\t\tif (mode !== \"foreground\" && mode !== \"background\") return undefined;\n\t\tif (output !== \"log\" && output !== \"report\") return undefined;\n\t\tif (typeof status !== \"string\" || !isTaskTerminal(status)) return undefined;\n\t\tconst startedAt = timestamp(field(source, \"startedAt\"));\n\t\tconst endedAt = timestamp(field(source, \"endedAt\"));\n\t\tif (endedAt < startedAt) return undefined;\n\t\tconst id = exact(field(source, \"id\"), 512);\n\t\tif (!id.startsWith(`${kind}-`) || id.length <= kind.length + 1) return undefined;\n\t\tconst anchor = field(source, \"anchorId\");\n\t\tconst task: TaskSnapshot = {\n\t\t\tid,\n\t\t\tkind,\n\t\t\tlabel: text(field(source, \"label\"), TASK_LABEL_BYTES),\n\t\t\ttitle: text(field(source, \"title\"), TASK_TITLE_BYTES),\n\t\t\toutput,\n\t\t\ttoolCallId: exact(field(source, \"toolCallId\"), 512),\n\t\t\tanchorId: anchor === null ? null : exact(anchor, 8192),\n\t\t\tmode,\n\t\t\tstatus,\n\t\t\tstartedAt,\n\t\t\tendedAt,\n\t\t};\n\t\tconst input = optional(source, \"input\", taskInput);\n\t\tconst facts = optional(source, \"facts\", taskFacts);\n\t\tconst outputPath = optional(source, \"outputPath\", (item) => exact(item, TASK_PATH_BYTES));\n\t\tconst result = optional(source, \"result\", (item) => taskText(item, TASK_RESULT_BYTES));\n\t\tconst display = optional(source, \"display\", (item) => taskText(item, TASK_RESULT_BYTES));\n\t\tconst error = optional(source, \"error\", (item) => text(item, TASK_ERROR_BYTES));\n\t\treturn {\n\t\t\t...task,\n\t\t\t...(input ? { input } : {}),\n\t\t\t...(facts ? { facts } : {}),\n\t\t\t...(outputPath ? { outputPath } : {}),\n\t\t\t...(result ? { result } : {}),\n\t\t\t...(display ? { display } : {}),\n\t\t\t...(error !== undefined ? { error } : {}),\n\t\t};\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** The task saved by a `task-record` entry or `task-completion` details. */\nexport function readVersionedTask(value: unknown): TaskSnapshot | undefined {\n\ttry {\n\t\tconst source = plainObject(value);\n\t\treturn field(source, \"version\") === TASK_SNAPSHOT_VERSION ? readPersistedTask(field(source, \"task\")) : undef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AS,CAAC;IAClB,CAAC;AACF,CAAC","sourcesContent":["/**\n * The one reader for persisted task snapshots: session `task-record` entries and\n * `task-completion` message details share this format and these bounds. It also reads the\n * usage settlement those entries carry for session totals.\n */\nimport type { Usage } from \"@earendil-works/pi-ai/compat\";\nimport type { SessionEntry } from \"../session-manager.ts\";\nimport {\n\tboundText,\n\tTASK_ERROR_BYTES,\n\tTASK_FACT_BYTES,\n\tTASK_FACTS,\n\tTASK_INPUT_BYTES,\n\tTASK_LABEL_BYTES,\n\tTASK_PATH_BYTES,\n\tTASK_RESULT_BYTES,\n\tTASK_TITLE_BYTES,\n} from \"./output.ts\";\nimport {\n\tisTaskTerminal,\n\tTASK_KIND_PATTERN,\n\ttype TaskFact,\n\ttype TaskInput,\n\ttype TaskSnapshot,\n\ttype TaskStatus,\n\ttype TaskText,\n} from \"./types.ts\";\n\nexport const TASK_RECORD_TYPE = \"task-record\";\n/** Shared by `task-record` entries and `task-completion` details. */\nexport const TASK_SNAPSHOT_VERSION = 3;\n/** Released sessions settled usage in separate entries; their billing still counts. */\nconst LEGACY_TASK_USAGE_TYPE = \"task-usage\";\n\n/** One task's usage settlement, as session totals account for it. */\nexport interface TaskUsageRecord {\n\ttaskId: string;\n\tusage: Usage;\n}\n\n/** Read persisted data properties only; never invoke getters or custom serialization. */\nexport function plainObject(value: unknown): Record<string, unknown> {\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) throw new Error(\"Expected object\");\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) throw new Error(\"Expected plain object\");\n\treturn value as Record<string, unknown>;\n}\n\nexport function field(object: object, key: string): unknown {\n\tconst descriptor = Object.getOwnPropertyDescriptor(object, key);\n\tif (descriptor && !(\"value\" in descriptor)) throw new Error(\"Unexpected accessor\");\n\treturn descriptor?.value;\n}\n\nfunction text(value: unknown, bytes: number): string {\n\tif (typeof value !== \"string\") throw new Error(\"Expected string\");\n\treturn boundText(value, bytes);\n}\n\n/** Identities and paths are never clipped: a shortened value would name something else. */\nfunction exact(value: unknown, bytes: number): string {\n\tif (typeof value !== \"string\" || !value || Buffer.byteLength(value) > bytes || value.includes(\"\\0\"))\n\t\tthrow new Error(\"Invalid identity or path\");\n\treturn value;\n}\n\nfunction optional<T>(source: object, key: string, read: (value: unknown) => T): T | undefined {\n\tconst value = field(source, key);\n\treturn value === undefined ? undefined : read(value);\n}\n\nfunction taskText(value: unknown, bytes: number): TaskText {\n\tconst source = plainObject(value);\n\tconst original = field(source, \"text\");\n\tconst truncated = field(source, \"truncated\");\n\tif (typeof truncated !== \"boolean\") throw new Error(\"Expected truncation flag\");\n\tconst bounded = text(original, bytes);\n\treturn { text: bounded, truncated: truncated || bounded !== original };\n}\n\nfunction taskInput(value: unknown): TaskInput {\n\tconst source = plainObject(value);\n\tconst language = optional(source, \"language\", (item) => text(item, 64));\n\treturn {\n\t\tlabel: text(field(source, \"label\"), TASK_LABEL_BYTES),\n\t\t...taskText(source, TASK_INPUT_BYTES),\n\t\t...(language ? { language } : {}),\n\t};\n}\n\nfunction taskFacts(value: unknown): TaskFact[] {\n\tif (!Array.isArray(value)) throw new Error(\"Expected facts\");\n\treturn value.slice(0, TASK_FACTS).map((row): TaskFact => {\n\t\tif (!Array.isArray(row) || row.length !== 2) throw new Error(\"Expected fact\");\n\t\treturn [text(row[0], TASK_LABEL_BYTES), text(row[1], TASK_FACT_BYTES)];\n\t});\n}\n\nfunction timestamp(value: unknown): number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0) throw new Error(\"Expected time\");\n\treturn value;\n}\n\n/** A bounded terminal snapshot, or undefined for any other shape or version. */\nexport function readPersistedTask(value: unknown): TaskSnapshot | undefined {\n\ttry {\n\t\tconst source = plainObject(value);\n\t\tconst kind = field(source, \"kind\");\n\t\tconst mode = field(source, \"mode\");\n\t\tconst status = field(source, \"status\") as TaskStatus;\n\t\tconst output = field(source, \"output\");\n\t\tif (typeof kind !== \"string\" || !TASK_KIND_PATTERN.test(kind)) return undefined;\n\t\tif (mode !== \"foreground\" && mode !== \"background\") return undefined;\n\t\tif (output !== \"log\" && output !== \"report\") return undefined;\n\t\tif (typeof status !== \"string\" || !isTaskTerminal(status)) return undefined;\n\t\tconst startedAt = timestamp(field(source, \"startedAt\"));\n\t\tconst endedAt = timestamp(field(source, \"endedAt\"));\n\t\tif (endedAt < startedAt) return undefined;\n\t\tconst id = exact(field(source, \"id\"), 512);\n\t\tif (!id.startsWith(`${kind}-`) || id.length <= kind.length + 1) return undefined;\n\t\tconst anchor = field(source, \"anchorId\");\n\t\tconst task: TaskSnapshot = {\n\t\t\tid,\n\t\t\tkind,\n\t\t\tlabel: text(field(source, \"label\"), TASK_LABEL_BYTES),\n\t\t\ttitle: text(field(source, \"title\"), TASK_TITLE_BYTES),\n\t\t\toutput,\n\t\t\ttoolCallId: exact(field(source, \"toolCallId\"), 512),\n\t\t\tanchorId: anchor === null ? null : exact(anchor, 8192),\n\t\t\tmode,\n\t\t\tstatus,\n\t\t\tstartedAt,\n\t\t\tendedAt,\n\t\t};\n\t\tconst input = optional(source, \"input\", taskInput);\n\t\tconst facts = optional(source, \"facts\", taskFacts);\n\t\tconst outputPath = optional(source, \"outputPath\", (item) => exact(item, TASK_PATH_BYTES));\n\t\tconst result = optional(source, \"result\", (item) => taskText(item, TASK_RESULT_BYTES));\n\t\tconst display = optional(source, \"display\", (item) => taskText(item, TASK_RESULT_BYTES));\n\t\tconst error = optional(source, \"error\", (item) => text(item, TASK_ERROR_BYTES));\n\t\treturn {\n\t\t\t...task,\n\t\t\t...(input ? { input } : {}),\n\t\t\t...(facts ? { facts } : {}),\n\t\t\t...(outputPath ? { outputPath } : {}),\n\t\t\t...(result ? { result } : {}),\n\t\t\t...(display ? { display } : {}),\n\t\t\t...(error !== undefined ? { error } : {}),\n\t\t};\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** The task saved by a `task-record` entry or `task-completion` details. */\nexport function readVersionedTask(value: unknown): TaskSnapshot | undefined {\n\ttry {\n\t\tconst source = plainObject(value);\n\t\treturn field(source, \"version\") === TASK_SNAPSHOT_VERSION ? readPersistedTask(field(source, \"task\")) : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction usageValue(value: unknown): number {\n\tif (typeof value !== \"number\" || !Number.isFinite(value) || value < 0) throw new Error(\"Expected usage value\");\n\treturn value;\n}\n\n/** Only the serializable accounting fields, so a settlement never carries provider extras into totals. */\nfunction taskUsage(value: unknown): Usage {\n\tconst source = plainObject(value);\n\tconst cost = plainObject(field(source, \"cost\"));\n\tconst reasoning = optional(source, \"reasoning\", usageValue);\n\tconst cacheWrite1h = optional(source, \"cacheWrite1h\", usageValue);\n\treturn {\n\t\tinput: usageValue(field(source, \"input\")),\n\t\toutput: usageValue(field(source, \"output\")),\n\t\tcacheRead: usageValue(field(source, \"cacheRead\")),\n\t\tcacheWrite: usageValue(field(source, \"cacheWrite\")),\n\t\ttotalTokens: usageValue(field(source, \"totalTokens\")),\n\t\t...(reasoning === undefined ? {} : { reasoning }),\n\t\t...(cacheWrite1h === undefined ? {} : { cacheWrite1h }),\n\t\tcost: {\n\t\t\tinput: usageValue(field(cost, \"input\")),\n\t\t\toutput: usageValue(field(cost, \"output\")),\n\t\t\tcacheRead: usageValue(field(cost, \"cacheRead\")),\n\t\t\tcacheWrite: usageValue(field(cost, \"cacheWrite\")),\n\t\t\ttotal: usageValue(field(cost, \"total\")),\n\t\t},\n\t};\n}\n\n/** The usage a `task-record` entry, or a released `task-usage` entry, settles for its task. */\nexport function readTaskUsage(entry: SessionEntry): TaskUsageRecord | undefined {\n\tif (entry.type !== \"custom\") return undefined;\n\tif (entry.customType !== TASK_RECORD_TYPE && entry.customType !== LEGACY_TASK_USAGE_TYPE) return undefined;\n\ttry {\n\t\tconst data = plainObject(entry.data);\n\t\tlet taskId: unknown;\n\t\tif (entry.customType === TASK_RECORD_TYPE) {\n\t\t\tif (field(data, \"version\") !== TASK_SNAPSHOT_VERSION) return undefined;\n\t\t\ttaskId = field(plainObject(field(data, \"task\")), \"id\");\n\t\t} else {\n\t\t\tif (field(data, \"version\") !== 1) return undefined;\n\t\t\ttaskId = field(data, \"taskId\");\n\t\t}\n\t\tif (typeof taskId !== \"string\" || !taskId.trim()) return undefined;\n\t\treturn { taskId, usage: taskUsage(field(data, \"usage\")) };\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type TaskPresenter, type TaskSnapshot } from "./types.ts";
|
|
1
|
+
import { type TaskSnapshot } from "./types.ts";
|
|
3
2
|
export declare const EXPIRED_OUTPUT = "Output has expired: the managed log was released; showing the stored result.";
|
|
4
3
|
type OutputCleanup = () => void | Promise<void>;
|
|
5
4
|
/**
|
|
@@ -21,16 +20,11 @@ export declare class TaskRecord {
|
|
|
21
20
|
private pins;
|
|
22
21
|
private cleanup?;
|
|
23
22
|
private expiredReason?;
|
|
24
|
-
private presenter?;
|
|
25
23
|
constructor(task: TaskSnapshot);
|
|
26
24
|
/** A terminal record rebuilt from persisted history: nothing is left to run or deliver. */
|
|
27
25
|
static restored(task: TaskSnapshot, readError: string | undefined): TaskRecord;
|
|
28
26
|
/** Terminal: nothing is left to run. Derived from the status so it can never disagree with it. */
|
|
29
27
|
get settled(): boolean;
|
|
30
|
-
/** The executor's live Output renderer; held in memory for a running task only. */
|
|
31
|
-
setPresenter(presenter: TaskPresenter | undefined): void;
|
|
32
|
-
/** Live Output while running; `undefined` once settled, without a presenter, or if the presenter throws. */
|
|
33
|
-
present(width: number, theme: Theme): string[] | undefined;
|
|
34
28
|
/** Called once, after the terminal snapshot is final. */
|
|
35
29
|
settle(): void;
|
|
36
30
|
update(mutate: (task: TaskSnapshot) => void): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/record.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,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IAClF,IAAI,SAAS,IAAI,MAAM,GAAG,SAAS,CAElC;IAED,gGAAgG;IAChG,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,IAAI;IAQzD;;;OAGG;IACH,YAAY,IAAI,aAAa,GAAG,SAAS;CAUzC"}
|
|
@@ -36,26 +36,8 @@ export class TaskRecord {
|
|
|
36
36
|
get settled() {
|
|
37
37
|
return isTaskTerminal(this.working.status);
|
|
38
38
|
}
|
|
39
|
-
/** The executor's live Output renderer; held in memory for a running task only. */
|
|
40
|
-
setPresenter(presenter) {
|
|
41
|
-
this.presenter = presenter;
|
|
42
|
-
}
|
|
43
|
-
/** Live Output while running; `undefined` once settled, without a presenter, or if the presenter throws. */
|
|
44
|
-
present(width, theme) {
|
|
45
|
-
if (this.settled || !this.presenter)
|
|
46
|
-
return undefined;
|
|
47
|
-
try {
|
|
48
|
-
const lines = this.presenter(width, theme);
|
|
49
|
-
return Array.isArray(lines) ? lines : undefined;
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
// An executor bug must not break the panel; it falls back to the default view.
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
39
|
/** Called once, after the terminal snapshot is final. */
|
|
57
40
|
settle() {
|
|
58
|
-
this.presenter = undefined;
|
|
59
41
|
this.resolveSettlement();
|
|
60
42
|
}
|
|
61
43
|
update(mutate) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../../src/core/tasks/record.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../../src/core/tasks/record.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAqB,MAAM,YAAY,CAAC;AAE/D,MAAM,CAAC,MAAM,cAAc,GAAG,8EAA8E,CAAC;AAE7G,SAAS,MAAM,CAAI,KAAQ;IAC1B,IAAI,KAAK,KAAK,IAAI,IAAI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SAAS,CAAC;QACtE,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YACpB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC7B,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,aAAa,GAAG,cAAc,CAAC;QACpC,OAAO,OAAO,CAAC;IAChB,CAAC;CACD","sourcesContent":["import { isTaskTerminal, type TaskSnapshot } from \"./types.ts\";\n\nexport const EXPIRED_OUTPUT = \"Output has expired: the managed log was released; showing the stored result.\";\n\nfunction freeze<T>(value: T): T {\n\tif (value !== null && typeof value === \"object\" && !Object.isFrozen(value)) {\n\t\tfor (const child of Object.values(value)) freeze(child);\n\t\tObject.freeze(value);\n\t}\n\treturn value;\n}\n\ntype OutputCleanup = () => void | Promise<void>;\n\n/**\n * The runtime's state for one task: its working snapshot, whether it is on the selected branch,\n * the pins that keep it retained, and the managed output it owns. Whether a completion reached\n * the model is a session concern held outside the runtime as a pin. Every lifecycle fact changes\n * through a named method here; the working snapshot changes only through `update()`, which also\n * drops the frozen copy that readers share, so a mutation can never leave a stale snapshot behind.\n */\nexport class TaskRecord {\n\t/** Read-only view of the working copy; change it with update(). */\n\treadonly task: Readonly<TaskSnapshot>;\n\t/** Settles once the task is terminal and its final snapshot is stored. Never rejects. */\n\treadonly settlement: Promise<void>;\n\tprivate readonly working: TaskSnapshot;\n\tprivate frozen?: TaskSnapshot;\n\tprivate resolveSettlement!: () => void;\n\tprivate onBranch = true;\n\tprivate pins = 0;\n\tprivate cleanup?: OutputCleanup;\n\tprivate expiredReason?: string;\n\n\tconstructor(task: TaskSnapshot) {\n\t\tthis.working = task;\n\t\tthis.task = task;\n\t\tthis.settlement = new Promise<void>((resolve) => {\n\t\t\tthis.resolveSettlement = resolve;\n\t\t});\n\t}\n\n\t/** A terminal record rebuilt from persisted history: nothing is left to run or deliver. */\n\tstatic restored(task: TaskSnapshot, readError: string | undefined): TaskRecord {\n\t\tconst record = new TaskRecord(task);\n\t\trecord.expiredReason = readError;\n\t\trecord.settle();\n\t\treturn record;\n\t}\n\n\t/** Terminal: nothing is left to run. Derived from the status so it can never disagree with it. */\n\tget settled(): boolean {\n\t\treturn isTaskTerminal(this.working.status);\n\t}\n\n\t/** Called once, after the terminal snapshot is final. */\n\tsettle(): void {\n\t\tthis.resolveSettlement();\n\t}\n\n\tupdate(mutate: (task: TaskSnapshot) => void): void {\n\t\ttry {\n\t\t\tmutate(this.working);\n\t\t} finally {\n\t\t\tthis.frozen = undefined;\n\t\t}\n\t}\n\n\t/** Readers share one frozen copy, so polling and status rendering never clone unchanged output. */\n\tsnapshot(): TaskSnapshot {\n\t\tthis.frozen ??= freeze(structuredClone(this.working));\n\t\treturn this.frozen;\n\t}\n\n\t/** Whether the launch anchor is on the selected branch. */\n\tget visible(): boolean {\n\t\treturn this.onBranch;\n\t}\n\n\tsetVisible(visible: boolean): void {\n\t\tthis.onBranch = visible;\n\t}\n\n\t/** Keep the record, and its output, retained until the returned release runs. Idempotent. */\n\tpin(): () => void {\n\t\tthis.pins++;\n\t\tlet released = false;\n\t\treturn () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\tthis.pins--;\n\t\t};\n\t}\n\n\t/** Settled and unpinned: bounded history that retention may evict. */\n\tget inHistory(): boolean {\n\t\treturn this.settled && this.pins === 0;\n\t}\n\n\t/** Why the output could not be read from a log: it expired, or was never kept. */\n\tget readError(): string | undefined {\n\t\treturn this.expiredReason;\n\t}\n\n\t/** Register the one output file this task owns; `cleanup` deletes it when retention lets go. */\n\tattachOutput(path: string, cleanup?: OutputCleanup): void {\n\t\tif (this.cleanup) throw new Error(\"Managed output is already registered\");\n\t\tthis.cleanup = cleanup;\n\t\tthis.update((task) => {\n\t\t\ttask.outputPath = path;\n\t\t});\n\t}\n\n\t/**\n\t * Release the managed output once nothing retains it. Returns the owner's cleanup to run, if\n\t * any; the snapshot keeps its final bounded text, so an expired file is never needed again.\n\t */\n\texpireOutput(): OutputCleanup | undefined {\n\t\tif (!this.settled || this.pins > 0 || !this.cleanup) return undefined;\n\t\tconst cleanup = this.cleanup;\n\t\tthis.cleanup = undefined;\n\t\tthis.update((task) => {\n\t\t\ttask.outputPath = undefined;\n\t\t});\n\t\tthis.expiredReason = EXPIRED_OUTPUT;\n\t\treturn cleanup;\n\t}\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import type
|
|
2
|
+
import { type TaskSnapshot } from "./types.ts";
|
|
3
3
|
/**
|
|
4
4
|
* A one-shot, request-local reminder after compaction. It is never persisted and
|
|
5
5
|
* creates no turn. Failed requests keep it eligible; an assistant response consumes it.
|
|
@@ -8,7 +8,8 @@ export declare class TaskContextReminder {
|
|
|
8
8
|
private pending;
|
|
9
9
|
private projected;
|
|
10
10
|
compacted(): void;
|
|
11
|
-
|
|
11
|
+
/** `runningBackground` is read only while a reminder is pending. */
|
|
12
|
+
project(messages: AgentMessage[], runningBackground: () => TaskSnapshot[]): AgentMessage[];
|
|
12
13
|
assistantCompleted(): void;
|
|
13
14
|
reset(): void;
|
|
14
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reminder.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/reminder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"reminder.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/reminder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAOhE;;;GAGG;AACH,qBAAa,mBAAmB;IAC/B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,SAAS,CAAS;IAE1B,SAAS,IAAI,IAAI;IAKjB,oEAAoE;IACpE,OAAO,CAAC,QAAQ,EAAE,YAAY,EAAE,EAAE,iBAAiB,EAAE,MAAM,YAAY,EAAE,GAAG,YAAY,EAAE;IAyB1F,kBAAkB,IAAI,IAAI;IAI1B,KAAK,IAAI,IAAI;CAIb"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { boundText } from "./output.js";
|
|
2
|
-
import {
|
|
2
|
+
import { TASKS_TOOL_NAME } from "./types.js";
|
|
3
3
|
function taskLine(task) {
|
|
4
4
|
const title = boundText(task.title.replace(/\s+/gu, " ").trim(), 240);
|
|
5
5
|
return boundText(`${task.id} ${task.kind} ${task.status} ${title}`, 1024);
|
|
@@ -17,10 +17,11 @@ export class TaskContextReminder {
|
|
|
17
17
|
this.pending = true;
|
|
18
18
|
this.projected = false;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
/** `runningBackground` is read only while a reminder is pending. */
|
|
21
|
+
project(messages, runningBackground) {
|
|
21
22
|
if (!this.pending)
|
|
22
23
|
return messages;
|
|
23
|
-
const tasks =
|
|
24
|
+
const tasks = runningBackground();
|
|
24
25
|
if (tasks.length === 0) {
|
|
25
26
|
this.reset();
|
|
26
27
|
return messages;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reminder.js","sourceRoot":"","sources":["../../../src/core/tasks/reminder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"reminder.js","sourceRoot":"","sources":["../../../src/core/tasks/reminder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,eAAe,EAAqB,MAAM,YAAY,CAAC;AAEhE,SAAS,QAAQ,CAAC,IAAkB;IACnC,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK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AC,KAAK,EAAE,CAAC;IAClC,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACxB,CAAC;CACD","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport { boundText } from \"./output.ts\";\nimport { TASKS_TOOL_NAME, type TaskSnapshot } from \"./types.ts\";\n\nfunction taskLine(task: TaskSnapshot): string {\n\tconst title = boundText(task.title.replace(/\\s+/gu, \" \").trim(), 240);\n\treturn boundText(`${task.id} ${task.kind} ${task.status} ${title}`, 1024);\n}\n\n/**\n * A one-shot, request-local reminder after compaction. It is never persisted and\n * creates no turn. Failed requests keep it eligible; an assistant response consumes it.\n */\nexport class TaskContextReminder {\n\tprivate pending = false;\n\tprivate projected = false;\n\n\tcompacted(): void {\n\t\tthis.pending = true;\n\t\tthis.projected = false;\n\t}\n\n\t/** `runningBackground` is read only while a reminder is pending. */\n\tproject(messages: AgentMessage[], runningBackground: () => TaskSnapshot[]): AgentMessage[] {\n\t\tif (!this.pending) return messages;\n\t\tconst tasks = runningBackground();\n\t\tif (tasks.length === 0) {\n\t\t\tthis.reset();\n\t\t\treturn messages;\n\t\t}\n\t\tconst reminder: AgentMessage = {\n\t\t\trole: \"user\",\n\t\t\tcontent: [\n\t\t\t\t{\n\t\t\t\t\ttype: \"text\",\n\t\t\t\t\ttext: [\n\t\t\t\t\t\t\"Context was compacted. These background tasks are still active; do not start duplicates.\",\n\t\t\t\t\t\t`Use ${TASKS_TOOL_NAME} list/read/kill to inspect or stop them. Each completion wakes you automatically; do not wait for it.`,\n\t\t\t\t\t\t...tasks.map(taskLine),\n\t\t\t\t\t].join(\"\\n\"),\n\t\t\t\t},\n\t\t\t],\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\t\tthis.projected = true;\n\t\treturn [...messages, reminder];\n\t}\n\n\tassistantCompleted(): void {\n\t\tif (this.projected) this.reset();\n\t}\n\n\treset(): void {\n\t\tthis.pending = false;\n\t\tthis.projected = false;\n\t}\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import type { Theme } from "../../modes/interactive/theme/theme.ts";
|
|
3
2
|
import { type TaskExecution, type TaskRead, type TaskReadOptions, type TaskRuntimeOptions, type TaskSnapshot, type TasksContext, type TaskToolOutcome } from "./types.ts";
|
|
4
3
|
/** Session-local supervision. Executors own their processes, items and output files. */
|
|
5
4
|
export declare class TaskRuntime implements TasksContext {
|
|
@@ -48,7 +47,6 @@ export declare class TaskRuntime implements TasksContext {
|
|
|
48
47
|
private lookup;
|
|
49
48
|
get(id: string): TaskSnapshot;
|
|
50
49
|
read(id: string, options?: TaskReadOptions): Promise<TaskRead>;
|
|
51
|
-
presentOutput(id: string, width: number, theme: Theme): string[] | undefined;
|
|
52
50
|
private resultText;
|
|
53
51
|
kill(id: string): boolean;
|
|
54
52
|
private cancel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAiBrE,OAAO,EAIN,KAAK,aAAa,EAElB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,MAAM,YAAY,CAAC;AAEpB,wFAAwF;AACxF,qBAAa,WAAY,YAAW,YAAY;IAC/C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAY;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyC;IACpE,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,EAAE;IAItB,OAAO,CAAC,MAAM;IAad,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY;IAIvB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAuBxE,OAAO,CAAC,UAAU;IAIlB,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIzB,OAAO,CAAC,MAAM;IAId,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAQ3C,yFAAyF;IACzF,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,IAAI;IAI9B,OAAO,CAAC,GAAG;IAQX,KAAK,IAAI,IAAI;IAYP,QAAQ,CAAC,OAAO,SAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAK7C,mFAAmF;IACnF,mBAAmB,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,YAAY,EAAE;IAOnE;;;OAGG;IACG,mBAAmB,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;YAW1D,KAAK;IAgBnB,OAAO,CAAC,IAAI;CAWZ"}
|
|
@@ -53,7 +53,7 @@ export class TaskRuntime {
|
|
|
53
53
|
this.store.restoreHistory(records, toolResults);
|
|
54
54
|
}
|
|
55
55
|
get enabled() {
|
|
56
|
-
return this.configuredEnabled && !this.closed
|
|
56
|
+
return this.configuredEnabled && !this.closed;
|
|
57
57
|
}
|
|
58
58
|
setEnabled(enabled) {
|
|
59
59
|
this.configuredEnabled = enabled;
|
|
@@ -79,13 +79,11 @@ export class TaskRuntime {
|
|
|
79
79
|
}
|
|
80
80
|
async execute(execution) {
|
|
81
81
|
// Admission and registration happen synchronously, before invoking user code or awaiting anything.
|
|
82
|
-
if (execution.background && this.options.backgroundAllowed === false)
|
|
83
|
-
throw new Error(TASK_BACKGROUND_REJECTION);
|
|
84
82
|
if (this.closed)
|
|
85
83
|
throw new Error("Task service is closed");
|
|
86
84
|
if (execution.background) {
|
|
87
85
|
if (!this.enabled)
|
|
88
|
-
throw new Error(
|
|
86
|
+
throw new Error(TASK_BACKGROUND_REJECTION);
|
|
89
87
|
if (!this.admitsBackground)
|
|
90
88
|
throw new Error(TASK_MANAGEMENT_REJECTION);
|
|
91
89
|
if (this.backgroundActive() >= this.maxBackground)
|
|
@@ -119,7 +117,6 @@ export class TaskRuntime {
|
|
|
119
117
|
startedAt: Date.now(),
|
|
120
118
|
};
|
|
121
119
|
const record = new TaskRecord(task);
|
|
122
|
-
record.setPresenter(execution.present);
|
|
123
120
|
const active = new Execution(this.host, record, execution);
|
|
124
121
|
this.store.add(record);
|
|
125
122
|
this.executions.set(task.id, active);
|
|
@@ -206,16 +203,6 @@ export class TaskRuntime {
|
|
|
206
203
|
release();
|
|
207
204
|
}
|
|
208
205
|
}
|
|
209
|
-
presentOutput(id, width, theme) {
|
|
210
|
-
let record;
|
|
211
|
-
try {
|
|
212
|
-
record = this.lookup(id);
|
|
213
|
-
}
|
|
214
|
-
catch {
|
|
215
|
-
return undefined;
|
|
216
|
-
}
|
|
217
|
-
return record.present(width, theme);
|
|
218
|
-
}
|
|
219
206
|
resultText(task) {
|
|
220
207
|
return task.result?.text || task.error || "No output yet.";
|
|
221
208
|
}
|