@diffra-ai/cli 0.1.1 → 0.1.3
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 +38 -0
- package/dist/bundle/chunks/{anthropic-messages-M3HXJPTI.js → anthropic-messages-5EMOURYI.js} +1 -1
- package/dist/bundle/chunks/{azure-openai-responses-GIFO2563.js → azure-openai-responses-N67KWG2X.js} +1 -1
- package/dist/bundle/chunks/bedrock-converse-stream.js +1 -1
- package/dist/bundle/chunks/{chunk-CVEPACZO.js → chunk-3UNTEQ65.js} +1 -1
- package/dist/bundle/chunks/{chunk-VJQ6ZYW4.js → chunk-4NMBWIZG.js} +5 -5
- package/dist/bundle/chunks/{chunk-INTHKDF2.js → chunk-65DC2T66.js} +1 -1
- package/dist/bundle/chunks/chunk-6ZD23B2R.js +2 -0
- package/dist/bundle/chunks/{chunk-WEJVQTLI.js → chunk-BF423NQ7.js} +1 -1
- package/dist/bundle/chunks/{chunk-262RLABF.js → chunk-CES65UJH.js} +1 -1
- package/dist/bundle/chunks/{chunk-RJRIMI6M.js → chunk-GRYHVZSI.js} +1 -1
- package/dist/bundle/chunks/{chunk-WAH3PGZX.js → chunk-HFTZ6OJJ.js} +2 -2
- package/dist/bundle/chunks/{chunk-N6Q2WLPG.js → chunk-NEFH2K3C.js} +1 -1
- package/dist/bundle/chunks/{chunk-OQFRYL4U.js → chunk-PISJX26Y.js} +1 -1
- package/dist/bundle/chunks/{chunk-VSFRR6IC.js → chunk-QQ6NVGNW.js} +1 -1
- package/dist/bundle/chunks/{chunk-N6QWAQ6I.js → chunk-QYYUGS66.js} +1 -1
- package/dist/bundle/chunks/{chunk-GT3WTHFU.js → chunk-RLMZZV4Q.js} +1 -1
- package/dist/bundle/chunks/chunk-RTPG7C5I.js +2003 -0
- package/dist/bundle/chunks/{chunk-6S2AQWGR.js → chunk-SI7T4LPD.js} +4 -4
- package/dist/bundle/chunks/{chunk-CCH74R6M.js → chunk-VOKUVFV4.js} +1 -1
- package/dist/bundle/chunks/{chunk-OOE7BGUD.js → chunk-VWWMBH3G.js} +1 -1
- package/dist/bundle/chunks/{chunk-B3FUE2LF.js → chunk-XAA355T2.js} +1 -1
- package/dist/bundle/chunks/{cli-EC3ZETTA.js → cli-55VO5MAJ.js} +1 -1
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-YW7YYPAC.js → cloudflare-workers-ai-system-one-HB5U67WC.js} +1 -1
- package/dist/bundle/chunks/{easter-egg-3d-QN5RJMZR.js → easter-egg-3d-VAZ2JWDP.js} +1 -1
- package/dist/bundle/chunks/{execute-3J63CQJG.js → execute-OEFRHFHI.js} +1 -1
- package/dist/bundle/chunks/{google-generative-ai-F6DN2LQU.js → google-generative-ai-XRHE7R52.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-MDWFDVAW.js → google-vertex-75CQOPKC.js} +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-XO72TVVH.js → llama-cpp-classify-LKIRB7ZR.js} +1 -1
- package/dist/bundle/chunks/{mistral-conversations-KYVGR5VN.js → mistral-conversations-KLGIHK73.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-SIQN5LUE.js → openai-codex-responses-7L5VV67U.js} +1 -1
- package/dist/bundle/chunks/{openai-completions-B22DYT4F.js → openai-completions-RBF6UXDW.js} +1 -1
- package/dist/bundle/chunks/{openai-decisions-4GVNTR54.js → openai-decisions-W3PJQIOF.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-5DVNSQCE.js → openai-responses-W5ZMLOTR.js} +1 -1
- package/dist/bundle/chunks/{openrouter-images-SQMQNKJU.js → openrouter-images-4FW6VFV4.js} +1 -1
- package/dist/bundle/chunks/{pi-messages-GZ4HZRKJ.js → pi-messages-RT7FVQ4G.js} +1 -1
- package/dist/bundle/chunks/{runtime-KEVIZBAR.js → runtime-SI4R3AXJ.js} +1 -1
- package/dist/bundle/chunks/{typesafe-system-one-GMPGMPLA.js → typesafe-system-one-DSJ7OYVL.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-M75O3ECA.js +2 -0
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/args.d.ts +2 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +13 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/sandbox-command.d.ts +8 -0
- package/dist/cli/sandbox-command.d.ts.map +1 -0
- package/dist/cli/sandbox-command.js +52 -0
- package/dist/cli/sandbox-command.js.map +1 -0
- package/dist/config.d.ts +7 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +14 -0
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +20 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +72 -2
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/approval-mode.d.ts +28 -0
- package/dist/core/approval-mode.d.ts.map +1 -0
- package/dist/core/approval-mode.js +34 -0
- package/dist/core/approval-mode.js.map +1 -0
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +15 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +3 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +30 -3
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/fast-model.d.ts +10 -0
- package/dist/core/fast-model.d.ts.map +1 -0
- package/dist/core/fast-model.js +13 -0
- package/dist/core/fast-model.js.map +1 -0
- package/dist/core/keybindings.d.ts +8 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +4 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/sandbox/escalation.d.ts +32 -0
- package/dist/core/sandbox/escalation.d.ts.map +1 -0
- package/dist/core/sandbox/escalation.js +70 -0
- package/dist/core/sandbox/escalation.js.map +1 -0
- package/dist/core/sandbox/launch.d.ts +14 -0
- package/dist/core/sandbox/launch.d.ts.map +1 -0
- package/dist/core/sandbox/launch.js +18 -0
- package/dist/core/sandbox/launch.js.map +1 -0
- package/dist/core/sandbox/policy.d.ts +50 -0
- package/dist/core/sandbox/policy.d.ts.map +1 -0
- package/dist/core/sandbox/policy.js +96 -0
- package/dist/core/sandbox/policy.js.map +1 -0
- package/dist/core/sandbox/seatbelt.d.ts +17 -0
- package/dist/core/sandbox/seatbelt.d.ts.map +1 -0
- package/dist/core/sandbox/seatbelt.js +169 -0
- package/dist/core/sandbox/seatbelt.js.map +1 -0
- package/dist/core/sandbox/windows.d.ts +30 -0
- package/dist/core/sandbox/windows.d.ts.map +1 -0
- package/dist/core/sandbox/windows.js +104 -0
- package/dist/core/sandbox/windows.js.map +1 -0
- package/dist/core/settings-defaults.d.ts +28 -0
- package/dist/core/settings-defaults.d.ts.map +1 -1
- package/dist/core/settings-defaults.js +28 -0
- package/dist/core/settings-defaults.js.map +1 -1
- package/dist/core/settings-manager.d.ts +9 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +58 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +124 -0
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +177 -0
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/tools/bash.d.ts +12 -2
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +27 -7
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts +3 -0
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +2 -0
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/powershell.d.ts +3 -2
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/core/tools/powershell.js +4 -6
- package/dist/core/tools/powershell.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +2 -2
- package/dist/core/tools/render-utils.js +5 -5
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/renderers/edit.d.ts.map +1 -1
- package/dist/core/tools/renderers/edit.js +16 -19
- package/dist/core/tools/renderers/edit.js.map +1 -1
- package/dist/core/tools/write.d.ts +3 -0
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +2 -0
- package/dist/core/tools/write.js.map +1 -1
- package/dist/extensions/agents/agent-tool.d.ts +61 -0
- package/dist/extensions/agents/agent-tool.d.ts.map +1 -0
- package/dist/extensions/agents/agent-tool.js +277 -0
- package/dist/extensions/agents/agent-tool.js.map +1 -0
- package/dist/extensions/agents/background.d.ts +56 -0
- package/dist/extensions/agents/background.d.ts.map +1 -0
- package/dist/extensions/agents/background.js +142 -0
- package/dist/extensions/agents/background.js.map +1 -0
- package/dist/extensions/agents/builtin-agents.d.ts +8 -0
- package/dist/extensions/agents/builtin-agents.d.ts.map +1 -0
- package/dist/extensions/agents/builtin-agents.js +38 -0
- package/dist/extensions/agents/builtin-agents.js.map +1 -0
- package/dist/extensions/agents/call-scopes.d.ts +34 -0
- package/dist/extensions/agents/call-scopes.d.ts.map +1 -0
- package/dist/extensions/agents/call-scopes.js +36 -0
- package/dist/extensions/agents/call-scopes.js.map +1 -0
- package/dist/extensions/agents/definitions.d.ts +64 -0
- package/dist/extensions/agents/definitions.d.ts.map +1 -0
- package/dist/extensions/agents/definitions.js +216 -0
- package/dist/extensions/agents/definitions.js.map +1 -0
- package/dist/extensions/agents/index.d.ts +15 -0
- package/dist/extensions/agents/index.d.ts.map +1 -0
- package/dist/extensions/agents/index.js +327 -0
- package/dist/extensions/agents/index.js.map +1 -0
- package/dist/extensions/agents/runner.d.ts +63 -0
- package/dist/extensions/agents/runner.d.ts.map +1 -0
- package/dist/extensions/agents/runner.js +156 -0
- package/dist/extensions/agents/runner.js.map +1 -0
- package/dist/extensions/approval/auto-classifier.d.ts +32 -0
- package/dist/extensions/approval/auto-classifier.d.ts.map +1 -0
- package/dist/extensions/approval/auto-classifier.js +116 -0
- package/dist/extensions/approval/auto-classifier.js.map +1 -0
- package/dist/extensions/approval/exit-plan-mode.d.ts +24 -0
- package/dist/extensions/approval/exit-plan-mode.d.ts.map +1 -0
- package/dist/extensions/approval/exit-plan-mode.js +99 -0
- package/dist/extensions/approval/exit-plan-mode.js.map +1 -0
- package/dist/extensions/approval/index.d.ts +15 -0
- package/dist/extensions/approval/index.d.ts.map +1 -0
- package/dist/extensions/approval/index.js +329 -0
- package/dist/extensions/approval/index.js.map +1 -0
- package/dist/extensions/approval/plan-reminders.d.ts +9 -0
- package/dist/extensions/approval/plan-reminders.d.ts.map +1 -0
- package/dist/extensions/approval/plan-reminders.js +42 -0
- package/dist/extensions/approval/plan-reminders.js.map +1 -0
- package/dist/extensions/approval/policy.d.ts +52 -0
- package/dist/extensions/approval/policy.d.ts.map +1 -0
- package/dist/extensions/approval/policy.js +124 -0
- package/dist/extensions/approval/policy.js.map +1 -0
- package/dist/extensions/approval/shell-safety.d.ts +11 -0
- package/dist/extensions/approval/shell-safety.d.ts.map +1 -0
- package/dist/extensions/approval/shell-safety.js +264 -0
- package/dist/extensions/approval/shell-safety.js.map +1 -0
- package/dist/extensions/cron/cron-expression.d.ts +30 -0
- package/dist/extensions/cron/cron-expression.d.ts.map +1 -0
- package/dist/extensions/cron/cron-expression.js +119 -0
- package/dist/extensions/cron/cron-expression.js.map +1 -0
- package/dist/extensions/cron/index.d.ts +19 -0
- package/dist/extensions/cron/index.d.ts.map +1 -0
- package/dist/extensions/cron/index.js +215 -0
- package/dist/extensions/cron/index.js.map +1 -0
- package/dist/extensions/cron/loop-args.d.ts +35 -0
- package/dist/extensions/cron/loop-args.d.ts.map +1 -0
- package/dist/extensions/cron/loop-args.js +95 -0
- package/dist/extensions/cron/loop-args.js.map +1 -0
- package/dist/extensions/cron/loop-texts.d.ts +29 -0
- package/dist/extensions/cron/loop-texts.d.ts.map +1 -0
- package/dist/extensions/cron/loop-texts.js +83 -0
- package/dist/extensions/cron/loop-texts.js.map +1 -0
- package/dist/extensions/cron/scheduler.d.ts +79 -0
- package/dist/extensions/cron/scheduler.d.ts.map +1 -0
- package/dist/extensions/cron/scheduler.js +146 -0
- package/dist/extensions/cron/scheduler.js.map +1 -0
- package/dist/extensions/cron/tools.d.ts +47 -0
- package/dist/extensions/cron/tools.d.ts.map +1 -0
- package/dist/extensions/cron/tools.js +141 -0
- package/dist/extensions/cron/tools.js.map +1 -0
- package/dist/extensions/goals/evidence.d.ts +20 -0
- package/dist/extensions/goals/evidence.d.ts.map +1 -0
- package/dist/extensions/goals/evidence.js +77 -0
- package/dist/extensions/goals/evidence.js.map +1 -0
- package/dist/extensions/goals/index.d.ts +45 -0
- package/dist/extensions/goals/index.d.ts.map +1 -0
- package/dist/extensions/goals/index.js +438 -0
- package/dist/extensions/goals/index.js.map +1 -0
- package/dist/extensions/goals/prompts.d.ts +15 -0
- package/dist/extensions/goals/prompts.d.ts.map +1 -0
- package/dist/extensions/goals/prompts.js +51 -0
- package/dist/extensions/goals/prompts.js.map +1 -0
- package/dist/extensions/goals/state.d.ts +88 -0
- package/dist/extensions/goals/state.d.ts.map +1 -0
- package/dist/extensions/goals/state.js +204 -0
- package/dist/extensions/goals/state.js.map +1 -0
- package/dist/extensions/goals/tools.d.ts +40 -0
- package/dist/extensions/goals/tools.d.ts.map +1 -0
- package/dist/extensions/goals/tools.js +118 -0
- package/dist/extensions/goals/tools.js.map +1 -0
- package/dist/extensions/goals/verifier.d.ts +30 -0
- package/dist/extensions/goals/verifier.d.ts.map +1 -0
- package/dist/extensions/goals/verifier.js +89 -0
- package/dist/extensions/goals/verifier.js.map +1 -0
- package/dist/extensions/hooks/aggregate.d.ts +30 -0
- package/dist/extensions/hooks/aggregate.d.ts.map +1 -0
- package/dist/extensions/hooks/aggregate.js +103 -0
- package/dist/extensions/hooks/aggregate.js.map +1 -0
- package/dist/extensions/hooks/config.d.ts +47 -0
- package/dist/extensions/hooks/config.d.ts.map +1 -0
- package/dist/extensions/hooks/config.js +169 -0
- package/dist/extensions/hooks/config.js.map +1 -0
- package/dist/extensions/hooks/file-watcher.d.ts +31 -0
- package/dist/extensions/hooks/file-watcher.d.ts.map +1 -0
- package/dist/extensions/hooks/file-watcher.js +106 -0
- package/dist/extensions/hooks/file-watcher.js.map +1 -0
- package/dist/extensions/hooks/index.d.ts +17 -0
- package/dist/extensions/hooks/index.d.ts.map +1 -0
- package/dist/extensions/hooks/index.js +349 -0
- package/dist/extensions/hooks/index.js.map +1 -0
- package/dist/extensions/hooks/matcher.d.ts +10 -0
- package/dist/extensions/hooks/matcher.d.ts.map +1 -0
- package/dist/extensions/hooks/matcher.js +85 -0
- package/dist/extensions/hooks/matcher.js.map +1 -0
- package/dist/extensions/hooks/runner.d.ts +54 -0
- package/dist/extensions/hooks/runner.d.ts.map +1 -0
- package/dist/extensions/hooks/runner.js +197 -0
- package/dist/extensions/hooks/runner.js.map +1 -0
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/index.js +29 -2
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/lsp/config.d.ts +40 -0
- package/dist/extensions/lsp/config.d.ts.map +1 -0
- package/dist/extensions/lsp/config.js +92 -0
- package/dist/extensions/lsp/config.js.map +1 -0
- package/dist/extensions/lsp/connection.d.ts +32 -0
- package/dist/extensions/lsp/connection.d.ts.map +1 -0
- package/dist/extensions/lsp/connection.js +124 -0
- package/dist/extensions/lsp/connection.js.map +1 -0
- package/dist/extensions/lsp/index.d.ts +15 -0
- package/dist/extensions/lsp/index.d.ts.map +1 -0
- package/dist/extensions/lsp/index.js +103 -0
- package/dist/extensions/lsp/index.js.map +1 -0
- package/dist/extensions/lsp/server.d.ts +68 -0
- package/dist/extensions/lsp/server.d.ts.map +1 -0
- package/dist/extensions/lsp/server.js +373 -0
- package/dist/extensions/lsp/server.js.map +1 -0
- package/dist/extensions/lsp/tool.d.ts +43 -0
- package/dist/extensions/lsp/tool.d.ts.map +1 -0
- package/dist/extensions/lsp/tool.js +534 -0
- package/dist/extensions/lsp/tool.js.map +1 -0
- package/dist/extensions/memory/index.d.ts +15 -0
- package/dist/extensions/memory/index.d.ts.map +1 -0
- package/dist/extensions/memory/index.js +336 -0
- package/dist/extensions/memory/index.js.map +1 -0
- package/dist/extensions/memory/memory-agent.d.ts +29 -0
- package/dist/extensions/memory/memory-agent.d.ts.map +1 -0
- package/dist/extensions/memory/memory-agent.js +102 -0
- package/dist/extensions/memory/memory-agent.js.map +1 -0
- package/dist/extensions/memory/prompts.d.ts +18 -0
- package/dist/extensions/memory/prompts.d.ts.map +1 -0
- package/dist/extensions/memory/prompts.js +124 -0
- package/dist/extensions/memory/prompts.js.map +1 -0
- package/dist/extensions/memory/recall.d.ts +14 -0
- package/dist/extensions/memory/recall.d.ts.map +1 -0
- package/dist/extensions/memory/recall.js +80 -0
- package/dist/extensions/memory/recall.js.map +1 -0
- package/dist/extensions/memory/store.d.ts +48 -0
- package/dist/extensions/memory/store.d.ts.map +1 -0
- package/dist/extensions/memory/store.js +132 -0
- package/dist/extensions/memory/store.js.map +1 -0
- package/dist/extensions/skills/bundled/batch/SKILL.md +74 -0
- package/dist/extensions/skills/bundled/review/SKILL.md +93 -0
- package/dist/extensions/skills/index.d.ts +15 -0
- package/dist/extensions/skills/index.d.ts.map +1 -0
- package/dist/extensions/skills/index.js +68 -0
- package/dist/extensions/skills/index.js.map +1 -0
- package/dist/extensions/skills/learn.d.ts +9 -0
- package/dist/extensions/skills/learn.d.ts.map +1 -0
- package/dist/extensions/skills/learn.js +46 -0
- package/dist/extensions/skills/learn.js.map +1 -0
- package/dist/extensions/todo/index.d.ts +14 -0
- package/dist/extensions/todo/index.d.ts.map +1 -0
- package/dist/extensions/todo/index.js +55 -0
- package/dist/extensions/todo/index.js.map +1 -0
- package/dist/extensions/todo/todos.d.ts +64 -0
- package/dist/extensions/todo/todos.d.ts.map +1 -0
- package/dist/extensions/todo/todos.js +145 -0
- package/dist/extensions/todo/todos.js.map +1 -0
- package/dist/extensions/todo/tool.d.ts +23 -0
- package/dist/extensions/todo/tool.d.ts.map +1 -0
- package/dist/extensions/todo/tool.js +104 -0
- package/dist/extensions/todo/tool.js.map +1 -0
- package/dist/extensions/web-fetch/fetch-tool.d.ts +27 -0
- package/dist/extensions/web-fetch/fetch-tool.d.ts.map +1 -0
- package/dist/extensions/web-fetch/fetch-tool.js +319 -0
- package/dist/extensions/web-fetch/fetch-tool.js.map +1 -0
- package/dist/extensions/web-fetch/html-to-markdown.d.ts +7 -0
- package/dist/extensions/web-fetch/html-to-markdown.d.ts.map +1 -0
- package/dist/extensions/web-fetch/html-to-markdown.js +21 -0
- package/dist/extensions/web-fetch/html-to-markdown.js.map +1 -0
- package/dist/extensions/web-fetch/index.d.ts +10 -0
- package/dist/extensions/web-fetch/index.d.ts.map +1 -0
- package/dist/extensions/web-fetch/index.js +13 -0
- package/dist/extensions/web-fetch/index.js.map +1 -0
- package/dist/extensions/web-fetch/page-fetch.d.ts +45 -0
- package/dist/extensions/web-fetch/page-fetch.d.ts.map +1 -0
- package/dist/extensions/web-fetch/page-fetch.js +117 -0
- package/dist/extensions/web-fetch/page-fetch.js.map +1 -0
- package/dist/extensions/web-fetch/pdf-text.d.ts +29 -0
- package/dist/extensions/web-fetch/pdf-text.d.ts.map +1 -0
- package/dist/extensions/web-fetch/pdf-text.js +71 -0
- package/dist/extensions/web-fetch/pdf-text.js.map +1 -0
- package/dist/extensions/web-fetch/preapproved-hosts.d.ts +7 -0
- package/dist/extensions/web-fetch/preapproved-hosts.d.ts.map +1 -0
- package/dist/extensions/web-fetch/preapproved-hosts.js +110 -0
- package/dist/extensions/web-fetch/preapproved-hosts.js.map +1 -0
- package/dist/extensions/web-search/dashscope-search.d.ts +29 -0
- package/dist/extensions/web-search/dashscope-search.d.ts.map +1 -0
- package/dist/extensions/web-search/dashscope-search.js +279 -0
- package/dist/extensions/web-search/dashscope-search.js.map +1 -0
- package/dist/extensions/web-search/index.d.ts +15 -0
- package/dist/extensions/web-search/index.d.ts.map +1 -0
- package/dist/extensions/web-search/index.js +51 -0
- package/dist/extensions/web-search/index.js.map +1 -0
- package/dist/extensions/web-search/search-config.d.ts +53 -0
- package/dist/extensions/web-search/search-config.d.ts.map +1 -0
- package/dist/extensions/web-search/search-config.js +174 -0
- package/dist/extensions/web-search/search-config.js.map +1 -0
- package/dist/extensions/web-search/search-tool.d.ts +29 -0
- package/dist/extensions/web-search/search-tool.d.ts.map +1 -0
- package/dist/extensions/web-search/search-tool.js +149 -0
- package/dist/extensions/web-search/search-tool.js.map +1 -0
- package/dist/extensions/worktree/git-worktree.d.ts +69 -0
- package/dist/extensions/worktree/git-worktree.d.ts.map +1 -0
- package/dist/extensions/worktree/git-worktree.js +199 -0
- package/dist/extensions/worktree/git-worktree.js.map +1 -0
- package/dist/extensions/worktree/index.d.ts +27 -0
- package/dist/extensions/worktree/index.d.ts.map +1 -0
- package/dist/extensions/worktree/index.js +188 -0
- package/dist/extensions/worktree/index.js.map +1 -0
- package/dist/extensions/worktree/startup.d.ts +17 -0
- package/dist/extensions/worktree/startup.d.ts.map +1 -0
- package/dist/extensions/worktree/startup.js +56 -0
- package/dist/extensions/worktree/startup.js.map +1 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +28 -4
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +18 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +87 -20
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/diffra-logo.d.ts +6 -0
- package/dist/modes/interactive/components/diffra-logo.d.ts.map +1 -1
- package/dist/modes/interactive/components/diffra-logo.js +30 -4
- package/dist/modes/interactive/components/diffra-logo.js.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.d.ts +1 -1
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.js +3 -3
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +16 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +84 -46
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +5 -2
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +152 -62
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-status.d.ts +5 -0
- package/dist/modes/interactive/components/tool-status.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-status.js +15 -0
- package/dist/modes/interactive/components/tool-status.js.map +1 -0
- package/dist/modes/interactive/components/user-message.d.ts +4 -8
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +38 -36
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +24 -8
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +3 -2
- package/dist/modes/interactive/theme/light.json +3 -2
- package/dist/modes/interactive/theme/system-theme.d.ts +1 -0
- package/dist/modes/interactive/theme/system-theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/system-theme.js +41 -14
- package/dist/modes/interactive/theme/system-theme.js.map +1 -1
- package/dist/utils/shell.d.ts +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +12 -2
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/tools-manager.d.ts +5 -0
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +48 -0
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/approval-modes.md +99 -0
- package/docs/builtin-skills.md +53 -0
- package/docs/cli.md +25 -1
- package/docs/docs.json +44 -0
- package/docs/environment-variables.md +7 -0
- package/docs/extensions.md +27 -2
- package/docs/goals.md +84 -0
- package/docs/hooks.md +112 -0
- package/docs/keybindings.md +1 -0
- package/docs/lsp.md +71 -0
- package/docs/memory.md +71 -0
- package/docs/sandbox.md +108 -0
- package/docs/scheduled-tasks.md +84 -0
- package/docs/security.md +3 -2
- package/docs/settings.md +28 -3
- package/docs/shell-aliases.md +1 -1
- package/docs/skills.md +4 -0
- package/docs/slash-commands.md +15 -0
- package/docs/subagents.md +102 -0
- package/docs/web-tools.md +83 -0
- package/docs/windows.md +2 -1
- package/docs/worktrees.md +52 -0
- package/examples/extensions/README.md +1 -1
- package/examples/extensions/plan-mode/README.md +2 -2
- package/examples/extensions/plan-mode/index.ts +7 -4
- package/examples/extensions/subagent/README.md +2 -0
- package/examples/extensions/subagent/index.ts +3 -0
- package/examples/extensions/todo.ts +4 -0
- package/package.json +9 -8
- package/schemas/keybindings.schema.json +4 -0
- package/schemas/settings.schema.json +421 -0
- package/dist/bundle/chunks/chunk-GCKVPVMH.js +0 -2
- package/dist/bundle/chunks/chunk-UNQMECQ4.js +0 -1240
- package/dist/bundle/chunks/virtual-modules-TRFD5ZOL.js +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/extensions/goals/prompts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAa,MAAM,YAAY,CAAC;AAEnD,wDAAwD;AACxD,MAAM,CAAC,MAAM,eAAe,GAC3B,+JAA+J,CAAC;AAEjK,oDAAoD;AACpD,MAAM,UAAU,kBAAkB,CACjC,IAAU,EACV,OAAiE;IAEjE,MAAM,KAAK,GAAG;QACb,sCAAsC;QACtC,sFAAsF;QACtF,8IAA8I;QAC9I,4HAA4H;QAC5H,8LAA8L;QAC9L,iGAAiG;QACjG,sBAAsB,UAAU,CAAC,EAAE,M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CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,UAAU,EAAE,sBAAsB,CAAC;IACtH,MAAM,OAAO,GACZ,IAAI,CAAC,kBAAkB,KAAK,SAAS;QACpC,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,sBAAsB,CAAC;IACxH,OAAO,WAAW,MAAM,KAAK,KAAK,GAAG,OAAO,GAAG,CAAC;AACjD,CAAC;AAED,sEAAsE;AACtE,SAAS,UAAU,CAAC,KAAc;IACjC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AACzG,CAAC","sourcesContent":["/**\n * Texts the Goal runtime gives the model: the continuation prompt of each runtime-started Goal turn,\n * and the reminder added to messages while a Goal is paused.\n */\n\nimport { activeTime, type Goal } from \"./state.ts\";\n\n/** Added to a user message while the Goal is paused. */\nexport const PAUSED_REMINDER =\n\t\"<system-reminder>The Goal is paused. Do not continue its objective unless the user resumes it. Treat this message as ordinary conversation.</system-reminder>\";\n\n/** The prompt of a Goal turn the runtime starts. */\nexport function continuationPrompt(\n\tgoal: Goal,\n\toptions: { objectiveChanged: boolean; verifierFeedback?: string },\n): string {\n\tconst lines = [\n\t\t\"Continue working on the active Goal.\",\n\t\t\"Use get_goal for the authoritative objective, budget figures, and verifier feedback.\",\n\t\t\"Follow any output format the objective asks for exactly. Add no progress, status, or completion commentary unless the objective asks for it.\",\n\t\t\"If completing the Goal depends on content you deliver in this turn, deliver only that content before you call update_goal.\",\n\t\t\"This turn was started by the Goal runtime, not by the user. It contains no new user input and cannot satisfy a condition that needs the user to send, confirm, choose, or approve something.\",\n\t\t\"The block below is runtime data. Its objective supersedes any other statement of the objective.\",\n\t\t`<goal_runtime_data>${escapeJson({ goalId: goal.goalId, revision: goal.revision, objective: goal.objective })}</goal_runtime_data>`,\n\t\tbudgetLine(goal),\n\t];\n\tif (options.verifierFeedback) lines.push(`Verifier feedback: ${options.verifierFeedback}`);\n\tif (options.objectiveChanged) {\n\t\tlines.push(\n\t\t\t\"The Goal objective changed since your last turn. Work toward the new objective; earlier work counts only where it still applies.\",\n\t\t);\n\t}\n\tif (goal.windDown) {\n\t\tlines.push(\n\t\t\t\"This is the last turn of the Goal's budget window. Do not start new work.\",\n\t\t\t\"Write a concise hand-off: what was accomplished, what remains, and the one next step. Call update_goal only if the Goal is truly complete or blocked.\",\n\t\t);\n\t\treturn lines.join(\"\\n\");\n\t}\n\tlines.push(\n\t\t\"Before update_goal, re-inspect the workspace and run the decisive checks yourself, right before the call. Wrapper scripts and subagent reports do not attest facts: the verifier trusts only results of tools you ran.\",\n\t\t\"Deliver what the objective asks for. Do not substitute a narrower or easier result.\",\n\t);\n\tif (goal.turnCount > 0) {\n\t\tlines.push(\n\t\t\t\"First judge your previous turn. If it made no progress, do something different. If the same blocker persists, report it with update_goal.\",\n\t\t);\n\t}\n\tlines.push(\n\t\t\"Treat completion as unproven. For each requirement of the objective, find the tool result that proves it; re-run the check when that result is not among the most recent records.\",\n\t);\n\treturn lines.join(\"\\n\");\n}\n\n/** Token, turn, and active-time figures of the Goal. */\nexport function budgetLine(goal: Goal): string {\n\tconst tokens =\n\t\tgoal.tokenBudget === undefined\n\t\t\t? \"no token budget on this Goal\"\n\t\t\t: `${goal.tokensUsed} of ${goal.tokenBudget} tokens used, ${Math.max(0, goal.tokenBudget - goal.tokensUsed)} remaining`;\n\tconst turns = `${goal.turnCount}${goal.turnBudget === undefined ? \"\" : ` of ${goal.turnBudget}`} Goal turns finished`;\n\tconst minutes =\n\t\tgoal.activeTimeBudgetMs === undefined\n\t\t\t? \"\"\n\t\t\t: `; ${Math.floor(activeTime(goal) / 60_000)} of ${Math.round(goal.activeTimeBudgetMs / 60_000)} active minutes used`;\n\treturn `Budget: ${tokens}; ${turns}${minutes}.`;\n}\n\n/** JSON that cannot close or open a tag in the surrounding prompt. */\nfunction escapeJson(value: unknown): string {\n\treturn JSON.stringify(value).replace(/</g, \"\\\\u003c\").replace(/>/g, \"\\\\u003e\").replace(/&/g, \"\\\\u0026\");\n}\n"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A goal: a session objective the agent keeps working on until an independent verifier accepts that
|
|
3
|
+
* it is complete or blocked. Its state is recorded on the session branch after every change.
|
|
4
|
+
*/
|
|
5
|
+
import type { SessionEntry } from "../../core/session-manager.ts";
|
|
6
|
+
export type GoalStatus = "active" | "paused" | "blocked" | "usage_limited" | "complete";
|
|
7
|
+
export type GoalLimit = "token_budget" | "turn_budget" | "time_budget";
|
|
8
|
+
/** A goal and its meters. A type alias so it is JSON data for session entries. */
|
|
9
|
+
export type Goal = {
|
|
10
|
+
goalId: string;
|
|
11
|
+
revision: number;
|
|
12
|
+
objective: string;
|
|
13
|
+
status: GoalStatus;
|
|
14
|
+
/** The session entry after which this goal's evidence starts. */
|
|
15
|
+
evidenceAfter: string | null;
|
|
16
|
+
turnCount: number;
|
|
17
|
+
tokensUsed: number;
|
|
18
|
+
activeTimeMs: number;
|
|
19
|
+
/** When the goal last became active; active time accrues from here. */
|
|
20
|
+
activeSince?: number;
|
|
21
|
+
tokenBudget?: number;
|
|
22
|
+
turnBudget?: number;
|
|
23
|
+
activeTimeBudgetMs?: number;
|
|
24
|
+
/** The budget that is spent: the next turn is the last one, a hand-off. */
|
|
25
|
+
windDown?: GoalLimit;
|
|
26
|
+
noProgressTurns: number;
|
|
27
|
+
/** A `repeated` blocker reported on consecutive Goal turns, with the same reason. */
|
|
28
|
+
blockedStreak?: {
|
|
29
|
+
reason: string;
|
|
30
|
+
turns: number;
|
|
31
|
+
};
|
|
32
|
+
lastReason?: string;
|
|
33
|
+
limitKind?: GoalLimit;
|
|
34
|
+
/** The verifier's reason for rejecting the last proposal, for the next turn. */
|
|
35
|
+
verifierFeedback?: string;
|
|
36
|
+
createdAt: number;
|
|
37
|
+
};
|
|
38
|
+
/** Custom entry type of goal state changes. */
|
|
39
|
+
export declare const GOAL_ENTRY = "diffra.goal-state";
|
|
40
|
+
/** Budgets from the `goals` settings; -1 means none. */
|
|
41
|
+
export type GoalBudgets = {
|
|
42
|
+
tokenBudget?: number;
|
|
43
|
+
maxTurns?: number;
|
|
44
|
+
maxActiveMinutes?: number;
|
|
45
|
+
};
|
|
46
|
+
/** The budgets, or an error naming the first invalid setting. Settings files are not schema-checked. */
|
|
47
|
+
export declare function checkBudgets(budgets: GoalBudgets | undefined): {
|
|
48
|
+
kind: "valid";
|
|
49
|
+
budgets: GoalBudgets;
|
|
50
|
+
} | {
|
|
51
|
+
kind: "invalid";
|
|
52
|
+
message: string;
|
|
53
|
+
};
|
|
54
|
+
export declare const PAUSE_REASONS: {
|
|
55
|
+
readonly interrupt: "Interrupted by the user. Run /goal resume to continue.";
|
|
56
|
+
readonly command: "Paused with /goal pause.";
|
|
57
|
+
readonly noProgress: "Three Goal turns in a row recorded nothing to judge and no proposal. Resume the Goal to try again, or edit its objective into one the model can act on and then resume it.";
|
|
58
|
+
readonly turnFailure: (detail: string) => string;
|
|
59
|
+
readonly verifierFailure: (detail: string) => string;
|
|
60
|
+
readonly noRoom: "The Goal objective and proposal reason leave the verifier request no room for evidence. Shorten the objective with /goal edit, then run /goal resume.";
|
|
61
|
+
readonly closing: "The session started closing before the turn finished. Run /goal resume to continue.";
|
|
62
|
+
readonly headlessEnded: "The headless run finished before the Goal did. Resume the Goal in a later run.";
|
|
63
|
+
};
|
|
64
|
+
/** Why a Goal stops when the start of its evidence left the session branch, for example after /tree. */
|
|
65
|
+
export declare const EVIDENCE_LOST_REASON = "The start of this Goal's evidence is no longer on the session branch. Run /goal edit to start a new evidence window, then /goal resume.";
|
|
66
|
+
/** A new active goal with the configured budgets armed. */
|
|
67
|
+
export declare function createGoal(objective: string, evidenceAfter: string | null, budgets: GoalBudgets): Goal;
|
|
68
|
+
/** Active time including the current active stretch. */
|
|
69
|
+
export declare function activeTime(goal: Goal, now?: number): number;
|
|
70
|
+
/** Change the status, closing or opening the active-time stretch. */
|
|
71
|
+
export declare function withStatus(goal: Goal, status: GoalStatus, reason?: string, now?: number): Goal;
|
|
72
|
+
/** The first budget that is spent, checked in the order tokens, turns, time. */
|
|
73
|
+
export declare function spentLimit(goal: Goal, now?: number): GoalLimit | undefined;
|
|
74
|
+
/** Stop a goal whose wind-down turn finished. */
|
|
75
|
+
export declare function limitGoal(goal: Goal, limit: GoalLimit): Goal;
|
|
76
|
+
/** Resume: the spent budget gets another window ahead of its meter. Meters are never reset. */
|
|
77
|
+
export declare function resumeGoal(goal: Goal, budgets: GoalBudgets): Goal;
|
|
78
|
+
/** Edit: a new objective and evidence window. A spent budget is re-armed; the status stays. */
|
|
79
|
+
export declare function editGoal(goal: Goal, objective: string, evidenceAfter: string | null, budgets: GoalBudgets): Goal;
|
|
80
|
+
/** The goal recorded on `branch`; `null` when it was cleared, undefined when none was ever set. */
|
|
81
|
+
export declare function readGoal(branch: readonly SessionEntry[]): Goal | null | undefined;
|
|
82
|
+
/** Token counts the way the footer shows them: 950, 1.2k, 30.0m. */
|
|
83
|
+
export declare function formatTokens(count: number): string;
|
|
84
|
+
/** Durations as 45s, 12m, 2h 5m. */
|
|
85
|
+
export declare function formatDuration(ms: number): string;
|
|
86
|
+
/** The status card: title, meters, objective, and reason. `activeMs` is the active time to show. */
|
|
87
|
+
export declare function goalCard(goal: Goal, verifying: boolean, activeMs: number): string;
|
|
88
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/extensions/goals/state.ts"],"names":[],"mappings":"AAAA;;;GA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AAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAOjE;AAED,+FAA+F;AAC/F,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAchH;AAqBD,mGAAmG;AACnG,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAMjF;AAED,oEAAoE;AACpE,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIlD;AAED,oCAAoC;AACpC,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAMjD;AAED,oGAAoG;AACpG,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAwBjF"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A goal: a session objective the agent keeps working on until an independent verifier accepts that
|
|
3
|
+
* it is complete or blocked. Its state is recorded on the session branch after every change.
|
|
4
|
+
*/
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { SETTINGS_DEFAULTS } from "../../core/settings-defaults.js";
|
|
7
|
+
/** Custom entry type of goal state changes. */
|
|
8
|
+
export const GOAL_ENTRY = "diffra.goal-state";
|
|
9
|
+
const DEFAULT_TOKEN_BUDGET = SETTINGS_DEFAULTS.goals.tokenBudget;
|
|
10
|
+
const BUDGET_RANGES = [
|
|
11
|
+
{ key: "tokenBudget", max: 300_000_000 },
|
|
12
|
+
{ key: "maxTurns", max: 10_000 },
|
|
13
|
+
{ key: "maxActiveMinutes", max: 10_080 },
|
|
14
|
+
];
|
|
15
|
+
/** The budgets, or an error naming the first invalid setting. Settings files are not schema-checked. */
|
|
16
|
+
export function checkBudgets(budgets) {
|
|
17
|
+
for (const { key, max } of BUDGET_RANGES) {
|
|
18
|
+
const value = budgets?.[key];
|
|
19
|
+
if (value === undefined || value === -1 || (Number.isInteger(value) && value >= 1 && value <= max))
|
|
20
|
+
continue;
|
|
21
|
+
return {
|
|
22
|
+
kind: "invalid",
|
|
23
|
+
message: `Invalid setting goals.${key}: ${value}. Use -1 for none or an integer from 1 to ${max}.`,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return { kind: "valid", budgets: budgets ?? {} };
|
|
27
|
+
}
|
|
28
|
+
export const PAUSE_REASONS = {
|
|
29
|
+
interrupt: "Interrupted by the user. Run /goal resume to continue.",
|
|
30
|
+
command: "Paused with /goal pause.",
|
|
31
|
+
noProgress: "Three Goal turns in a row recorded nothing to judge and no proposal. Resume the Goal to try again, or edit its objective into one the model can act on and then resume it.",
|
|
32
|
+
turnFailure: (detail) => `The Goal turn could not finish: ${detail.slice(0, 500)}. Run /goal resume to continue.`,
|
|
33
|
+
verifierFailure: (detail) => `The Goal verifier could not judge the proposal: ${detail.slice(0, 500)}. Run /goal resume to continue.`,
|
|
34
|
+
noRoom: "The Goal objective and proposal reason leave the verifier request no room for evidence. Shorten the objective with /goal edit, then run /goal resume.",
|
|
35
|
+
closing: "The session started closing before the turn finished. Run /goal resume to continue.",
|
|
36
|
+
headlessEnded: "The headless run finished before the Goal did. Resume the Goal in a later run.",
|
|
37
|
+
};
|
|
38
|
+
/** Why a Goal stops when the start of its evidence left the session branch, for example after /tree. */
|
|
39
|
+
export const EVIDENCE_LOST_REASON = "The start of this Goal's evidence is no longer on the session branch. Run /goal edit to start a new evidence window, then /goal resume.";
|
|
40
|
+
const LIMIT_REASONS = {
|
|
41
|
+
token_budget: (goal) => `The Goal spent its autonomous token budget (${goal.tokenBudget} tokens). Resume the Goal to authorize another budget window, or clear it.`,
|
|
42
|
+
turn_budget: (goal) => `The Goal ran its Goal-turn budget (${goal.turnBudget} turns). Resume the Goal to authorize another window of turns, or clear it.`,
|
|
43
|
+
time_budget: (goal) => `The Goal ran its active-time budget (${Math.round((goal.activeTimeBudgetMs ?? 0) / 60_000)} minutes). Resume the Goal to authorize another window of time, or clear it.`,
|
|
44
|
+
};
|
|
45
|
+
/** A new active goal with the configured budgets armed. */
|
|
46
|
+
export function createGoal(objective, evidenceAfter, budgets) {
|
|
47
|
+
const now = Date.now();
|
|
48
|
+
const tokenBudget = budgets.tokenBudget === undefined ? DEFAULT_TOKEN_BUDGET : budgets.tokenBudget;
|
|
49
|
+
return {
|
|
50
|
+
goalId: randomUUID(),
|
|
51
|
+
revision: 1,
|
|
52
|
+
objective,
|
|
53
|
+
status: "active",
|
|
54
|
+
evidenceAfter,
|
|
55
|
+
turnCount: 0,
|
|
56
|
+
tokensUsed: 0,
|
|
57
|
+
activeTimeMs: 0,
|
|
58
|
+
activeSince: now,
|
|
59
|
+
...(tokenBudget > 0 ? { tokenBudget } : {}),
|
|
60
|
+
...(budgets.maxTurns && budgets.maxTurns > 0 ? { turnBudget: budgets.maxTurns } : {}),
|
|
61
|
+
...(budgets.maxActiveMinutes && budgets.maxActiveMinutes > 0
|
|
62
|
+
? { activeTimeBudgetMs: budgets.maxActiveMinutes * 60_000 }
|
|
63
|
+
: {}),
|
|
64
|
+
noProgressTurns: 0,
|
|
65
|
+
createdAt: now,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** Active time including the current active stretch. */
|
|
69
|
+
export function activeTime(goal, now = Date.now()) {
|
|
70
|
+
return goal.activeTimeMs + (goal.status === "active" && goal.activeSince ? now - goal.activeSince : 0);
|
|
71
|
+
}
|
|
72
|
+
/** Change the status, closing or opening the active-time stretch. */
|
|
73
|
+
export function withStatus(goal, status, reason, now = Date.now()) {
|
|
74
|
+
const next = { ...goal, activeTimeMs: activeTime(goal, now), status };
|
|
75
|
+
delete next.activeSince;
|
|
76
|
+
if (status === "active")
|
|
77
|
+
next.activeSince = now;
|
|
78
|
+
if (reason === undefined)
|
|
79
|
+
delete next.lastReason;
|
|
80
|
+
else
|
|
81
|
+
next.lastReason = reason;
|
|
82
|
+
return next;
|
|
83
|
+
}
|
|
84
|
+
/** The first budget that is spent, checked in the order tokens, turns, time. */
|
|
85
|
+
export function spentLimit(goal, now = Date.now()) {
|
|
86
|
+
if (goal.tokenBudget !== undefined && goal.tokensUsed >= goal.tokenBudget)
|
|
87
|
+
return "token_budget";
|
|
88
|
+
if (goal.turnBudget !== undefined && goal.turnCount >= goal.turnBudget)
|
|
89
|
+
return "turn_budget";
|
|
90
|
+
if (goal.activeTimeBudgetMs !== undefined && activeTime(goal, now) >= goal.activeTimeBudgetMs)
|
|
91
|
+
return "time_budget";
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
/** Stop a goal whose wind-down turn finished. */
|
|
95
|
+
export function limitGoal(goal, limit) {
|
|
96
|
+
const next = { ...withStatus(goal, "usage_limited", LIMIT_REASONS[limit](goal)), limitKind: limit };
|
|
97
|
+
delete next.windDown;
|
|
98
|
+
return next;
|
|
99
|
+
}
|
|
100
|
+
/** Resume: the spent budget gets another window ahead of its meter. Meters are never reset. */
|
|
101
|
+
export function resumeGoal(goal, budgets) {
|
|
102
|
+
const spent = goal.limitKind ?? goal.windDown ?? spentLimit(goal);
|
|
103
|
+
const next = withStatus(spent ? rearm(goal, spent, budgets) : goal, "active");
|
|
104
|
+
delete next.limitKind;
|
|
105
|
+
delete next.windDown;
|
|
106
|
+
next.noProgressTurns = 0;
|
|
107
|
+
return next;
|
|
108
|
+
}
|
|
109
|
+
/** Edit: a new objective and evidence window. A spent budget is re-armed; the status stays. */
|
|
110
|
+
export function editGoal(goal, objective, evidenceAfter, budgets) {
|
|
111
|
+
const spent = goal.limitKind ?? goal.windDown ?? spentLimit(goal);
|
|
112
|
+
const next = {
|
|
113
|
+
...(spent ? rearm(goal, spent, budgets) : goal),
|
|
114
|
+
revision: goal.revision + 1,
|
|
115
|
+
objective,
|
|
116
|
+
evidenceAfter,
|
|
117
|
+
noProgressTurns: 0,
|
|
118
|
+
};
|
|
119
|
+
delete next.lastReason;
|
|
120
|
+
delete next.windDown;
|
|
121
|
+
delete next.blockedStreak;
|
|
122
|
+
delete next.verifierFeedback;
|
|
123
|
+
return next;
|
|
124
|
+
}
|
|
125
|
+
/** Move a spent ceiling ahead of its meter by the configured window; -1 or no setting removes it. */
|
|
126
|
+
function rearm(goal, limit, budgets) {
|
|
127
|
+
const next = { ...goal };
|
|
128
|
+
switch (limit) {
|
|
129
|
+
case "token_budget":
|
|
130
|
+
if (budgets.tokenBudget === -1)
|
|
131
|
+
delete next.tokenBudget;
|
|
132
|
+
else
|
|
133
|
+
next.tokenBudget = goal.tokensUsed + (budgets.tokenBudget ?? DEFAULT_TOKEN_BUDGET);
|
|
134
|
+
return next;
|
|
135
|
+
case "turn_budget":
|
|
136
|
+
if (budgets.maxTurns === undefined || budgets.maxTurns === -1)
|
|
137
|
+
delete next.turnBudget;
|
|
138
|
+
else
|
|
139
|
+
next.turnBudget = goal.turnCount + budgets.maxTurns;
|
|
140
|
+
return next;
|
|
141
|
+
case "time_budget":
|
|
142
|
+
if (budgets.maxActiveMinutes === undefined || budgets.maxActiveMinutes === -1)
|
|
143
|
+
delete next.activeTimeBudgetMs;
|
|
144
|
+
else
|
|
145
|
+
next.activeTimeBudgetMs = activeTime(goal) + budgets.maxActiveMinutes * 60_000;
|
|
146
|
+
return next;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** The goal recorded on `branch`; `null` when it was cleared, undefined when none was ever set. */
|
|
150
|
+
export function readGoal(branch) {
|
|
151
|
+
for (let index = branch.length - 1; index >= 0; index--) {
|
|
152
|
+
const entry = branch[index];
|
|
153
|
+
if (entry.type === "custom" && entry.customType === GOAL_ENTRY)
|
|
154
|
+
return entry.data.goal;
|
|
155
|
+
}
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
/** Token counts the way the footer shows them: 950, 1.2k, 30.0m. */
|
|
159
|
+
export function formatTokens(count) {
|
|
160
|
+
if (count < 1000)
|
|
161
|
+
return String(count);
|
|
162
|
+
if (count < 1_000_000)
|
|
163
|
+
return `${(count / 1000).toFixed(1)}k`;
|
|
164
|
+
return `${(count / 1_000_000).toFixed(1)}m`;
|
|
165
|
+
}
|
|
166
|
+
/** Durations as 45s, 12m, 2h 5m. */
|
|
167
|
+
export function formatDuration(ms) {
|
|
168
|
+
const seconds = Math.floor(ms / 1000);
|
|
169
|
+
if (seconds < 60)
|
|
170
|
+
return `${seconds}s`;
|
|
171
|
+
const minutes = Math.floor(seconds / 60);
|
|
172
|
+
if (minutes < 60)
|
|
173
|
+
return `${minutes}m`;
|
|
174
|
+
return `${Math.floor(minutes / 60)}h ${minutes % 60}m`;
|
|
175
|
+
}
|
|
176
|
+
/** The status card: title, meters, objective, and reason. `activeMs` is the active time to show. */
|
|
177
|
+
export function goalCard(goal, verifying, activeMs) {
|
|
178
|
+
const titles = {
|
|
179
|
+
active: "Goal active",
|
|
180
|
+
paused: "Goal paused",
|
|
181
|
+
blocked: "Goal blocked",
|
|
182
|
+
usage_limited: "Goal usage limited",
|
|
183
|
+
complete: "Goal complete",
|
|
184
|
+
};
|
|
185
|
+
const meters = [
|
|
186
|
+
goal.turnCount > 0
|
|
187
|
+
? `${goal.turnCount}${goal.turnBudget ? `/${goal.turnBudget}` : ""} ${(goal.turnBudget ?? goal.turnCount) === 1 ? "turn" : "turns"}`
|
|
188
|
+
: "",
|
|
189
|
+
activeMs >= 1000
|
|
190
|
+
? `${formatDuration(activeMs)}${goal.activeTimeBudgetMs ? `/${formatDuration(goal.activeTimeBudgetMs)}` : ""}`
|
|
191
|
+
: "",
|
|
192
|
+
goal.tokensUsed > 0
|
|
193
|
+
? `${formatTokens(goal.tokensUsed)}${goal.tokenBudget ? `/${formatTokens(goal.tokenBudget)}` : ""} tokens`
|
|
194
|
+
: "",
|
|
195
|
+
].filter(Boolean);
|
|
196
|
+
const lines = [verifying ? "Goal checking" : titles[goal.status]];
|
|
197
|
+
if (meters.length > 0)
|
|
198
|
+
lines.push(meters.join(" · "));
|
|
199
|
+
lines.push(`Goal: ${goal.objective}`);
|
|
200
|
+
if (goal.lastReason && (goal.status !== "active" || verifying))
|
|
201
|
+
lines.push(`Reason: ${goal.lastReason}`);
|
|
202
|
+
return lines.join("\n");
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/extensions/goals/state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAiCpE,+CAA+C;AAC/C,MAAM,CAAC,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAE9C,MAAM,oBAAoB,GAAG,iBAAiB,CAAC,KAAK,CAAC,WAAW,CAAC;AAKjE,MAAM,aAAa,GAAmD;IACrE,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,WAAW,EAAE;IACxC,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE;IAChC,EAAE,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,EAAE;CACxC,CAAC;AAEF,wGAAwG;AACxG,MAAM,UAAU,YAAY,CAC3B,OAAgC;IAEhC,KAAK,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,aAAa,EAAE,CAAC;QAC1C,MAAM,KAAK,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,GAAG,CAAC;YAAE,SAAS;QAC7G,OAAO;YACN,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,yBAAyB,GAAG,KAAK,KAAK,6CAA6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,IAAI;YACf,CAAC,CAAC,GAAG,cAAc,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE;YAC9G,CAAC,CAAC,EAAE;QACL,IAAI,CAAC,UAAU,GAAG,CAAC;YAClB,CAAC,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS;YAC1G,CAAC,CAAC,EAAE;KACL,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClB,MAAM,KAAK,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAClE,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACtD,KAAK,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;IACtC,IAAI,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,SAAS,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IACzG,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC","sourcesContent":["/**\n * A goal: a session objective the agent keeps working on until an independent verifier accepts that\n * it is complete or blocked. Its state is recorded on the session branch after every change.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport type { SessionEntry } from \"../../core/session-manager.ts\";\nimport { SETTINGS_DEFAULTS } from \"../../core/settings-defaults.ts\";\n\nexport type GoalStatus = \"active\" | \"paused\" | \"blocked\" | \"usage_limited\" | \"complete\";\nexport type GoalLimit = \"token_budget\" | \"turn_budget\" | \"time_budget\";\n\n/** A goal and its meters. A type alias so it is JSON data for session entries. */\nexport type Goal = {\n\tgoalId: string;\n\trevision: number;\n\tobjective: string;\n\tstatus: GoalStatus;\n\t/** The session entry after which this goal's evidence starts. */\n\tevidenceAfter: string | null;\n\tturnCount: number;\n\ttokensUsed: number;\n\tactiveTimeMs: number;\n\t/** When the goal last became active; active time accrues from here. */\n\tactiveSince?: number;\n\ttokenBudget?: number;\n\tturnBudget?: number;\n\tactiveTimeBudgetMs?: number;\n\t/** The budget that is spent: the next turn is the last one, a hand-off. */\n\twindDown?: GoalLimit;\n\tnoProgressTurns: number;\n\t/** A `repeated` blocker reported on consecutive Goal turns, with the same reason. */\n\tblockedStreak?: { reason: string; turns: number };\n\tlastReason?: string;\n\tlimitKind?: GoalLimit;\n\t/** The verifier's reason for rejecting the last proposal, for the next turn. */\n\tverifierFeedback?: string;\n\tcreatedAt: number;\n};\n\n/** Custom entry type of goal state changes. */\nexport const GOAL_ENTRY = \"diffra.goal-state\";\n\nconst DEFAULT_TOKEN_BUDGET = SETTINGS_DEFAULTS.goals.tokenBudget;\n\n/** Budgets from the `goals` settings; -1 means none. */\nexport type GoalBudgets = { tokenBudget?: number; maxTurns?: number; maxActiveMinutes?: number };\n\nconst BUDGET_RANGES: Array<{ key: keyof GoalBudgets; max: number }> = [\n\t{ key: \"tokenBudget\", max: 300_000_000 },\n\t{ key: \"maxTurns\", max: 10_000 },\n\t{ key: \"maxActiveMinutes\", max: 10_080 },\n];\n\n/** The budgets, or an error naming the first invalid setting. Settings files are not schema-checked. */\nexport function checkBudgets(\n\tbudgets: GoalBudgets | undefined,\n): { kind: \"valid\"; budgets: GoalBudgets } | { kind: \"invalid\"; message: string } {\n\tfor (const { key, max } of BUDGET_RANGES) {\n\t\tconst value = budgets?.[key];\n\t\tif (value === undefined || value === -1 || (Number.isInteger(value) && value >= 1 && value <= max)) continue;\n\t\treturn {\n\t\t\tkind: \"invalid\",\n\t\t\tmessage: `Invalid setting goals.${key}: ${value}. Use -1 for none or an integer from 1 to ${max}.`,\n\t\t};\n\t}\n\treturn { kind: \"valid\", budgets: budgets ?? {} };\n}\n\nexport const PAUSE_REASONS = {\n\tinterrupt: \"Interrupted by the user. Run /goal resume to continue.\",\n\tcommand: \"Paused with /goal pause.\",\n\tnoProgress:\n\t\t\"Three Goal turns in a row recorded nothing to judge and no proposal. Resume the Goal to try again, or edit its objective into one the model can act on and then resume it.\",\n\tturnFailure: (detail: string) =>\n\t\t`The Goal turn could not finish: ${detail.slice(0, 500)}. Run /goal resume to continue.`,\n\tverifierFailure: (detail: string) =>\n\t\t`The Goal verifier could not judge the proposal: ${detail.slice(0, 500)}. Run /goal resume to continue.`,\n\tnoRoom:\n\t\t\"The Goal objective and proposal reason leave the verifier request no room for evidence. Shorten the objective with /goal edit, then run /goal resume.\",\n\tclosing: \"The session started closing before the turn finished. Run /goal resume to continue.\",\n\theadlessEnded: \"The headless run finished before the Goal did. Resume the Goal in a later run.\",\n} as const;\n\n/** Why a Goal stops when the start of its evidence left the session branch, for example after /tree. */\nexport const EVIDENCE_LOST_REASON =\n\t\"The start of this Goal's evidence is no longer on the session branch. Run /goal edit to start a new evidence window, then /goal resume.\";\n\nconst LIMIT_REASONS: Record<GoalLimit, (goal: Goal) => string> = {\n\ttoken_budget: (goal) =>\n\t\t`The Goal spent its autonomous token budget (${goal.tokenBudget} tokens). Resume the Goal to authorize another budget window, or clear it.`,\n\tturn_budget: (goal) =>\n\t\t`The Goal ran its Goal-turn budget (${goal.turnBudget} turns). Resume the Goal to authorize another window of turns, or clear it.`,\n\ttime_budget: (goal) =>\n\t\t`The Goal ran its active-time budget (${Math.round((goal.activeTimeBudgetMs ?? 0) / 60_000)} minutes). Resume the Goal to authorize another window of time, or clear it.`,\n};\n\n/** A new active goal with the configured budgets armed. */\nexport function createGoal(objective: string, evidenceAfter: string | null, budgets: GoalBudgets): Goal {\n\tconst now = Date.now();\n\tconst tokenBudget = budgets.tokenBudget === undefined ? DEFAULT_TOKEN_BUDGET : budgets.tokenBudget;\n\treturn {\n\t\tgoalId: randomUUID(),\n\t\trevision: 1,\n\t\tobjective,\n\t\tstatus: \"active\",\n\t\tevidenceAfter,\n\t\tturnCount: 0,\n\t\ttokensUsed: 0,\n\t\tactiveTimeMs: 0,\n\t\tactiveSince: now,\n\t\t...(tokenBudget > 0 ? { tokenBudget } : {}),\n\t\t...(budgets.maxTurns && budgets.maxTurns > 0 ? { turnBudget: budgets.maxTurns } : {}),\n\t\t...(budgets.maxActiveMinutes && budgets.maxActiveMinutes > 0\n\t\t\t? { activeTimeBudgetMs: budgets.maxActiveMinutes * 60_000 }\n\t\t\t: {}),\n\t\tnoProgressTurns: 0,\n\t\tcreatedAt: now,\n\t};\n}\n\n/** Active time including the current active stretch. */\nexport function activeTime(goal: Goal, now = Date.now()): number {\n\treturn goal.activeTimeMs + (goal.status === \"active\" && goal.activeSince ? now - goal.activeSince : 0);\n}\n\n/** Change the status, closing or opening the active-time stretch. */\nexport function withStatus(goal: Goal, status: GoalStatus, reason?: string, now = Date.now()): Goal {\n\tconst next: Goal = { ...goal, activeTimeMs: activeTime(goal, now), status };\n\tdelete next.activeSince;\n\tif (status === \"active\") next.activeSince = now;\n\tif (reason === undefined) delete next.lastReason;\n\telse next.lastReason = reason;\n\treturn next;\n}\n\n/** The first budget that is spent, checked in the order tokens, turns, time. */\nexport function spentLimit(goal: Goal, now = Date.now()): GoalLimit | undefined {\n\tif (goal.tokenBudget !== undefined && goal.tokensUsed >= goal.tokenBudget) return \"token_budget\";\n\tif (goal.turnBudget !== undefined && goal.turnCount >= goal.turnBudget) return \"turn_budget\";\n\tif (goal.activeTimeBudgetMs !== undefined && activeTime(goal, now) >= goal.activeTimeBudgetMs) return \"time_budget\";\n\treturn undefined;\n}\n\n/** Stop a goal whose wind-down turn finished. */\nexport function limitGoal(goal: Goal, limit: GoalLimit): Goal {\n\tconst next: Goal = { ...withStatus(goal, \"usage_limited\", LIMIT_REASONS[limit](goal)), limitKind: limit };\n\tdelete next.windDown;\n\treturn next;\n}\n\n/** Resume: the spent budget gets another window ahead of its meter. Meters are never reset. */\nexport function resumeGoal(goal: Goal, budgets: GoalBudgets): Goal {\n\tconst spent = goal.limitKind ?? goal.windDown ?? spentLimit(goal);\n\tconst next = withStatus(spent ? rearm(goal, spent, budgets) : goal, \"active\");\n\tdelete next.limitKind;\n\tdelete next.windDown;\n\tnext.noProgressTurns = 0;\n\treturn next;\n}\n\n/** Edit: a new objective and evidence window. A spent budget is re-armed; the status stays. */\nexport function editGoal(goal: Goal, objective: string, evidenceAfter: string | null, budgets: GoalBudgets): Goal {\n\tconst spent = goal.limitKind ?? goal.windDown ?? spentLimit(goal);\n\tconst next: Goal = {\n\t\t...(spent ? rearm(goal, spent, budgets) : goal),\n\t\trevision: goal.revision + 1,\n\t\tobjective,\n\t\tevidenceAfter,\n\t\tnoProgressTurns: 0,\n\t};\n\tdelete next.lastReason;\n\tdelete next.windDown;\n\tdelete next.blockedStreak;\n\tdelete next.verifierFeedback;\n\treturn next;\n}\n\n/** Move a spent ceiling ahead of its meter by the configured window; -1 or no setting removes it. */\nfunction rearm(goal: Goal, limit: GoalLimit, budgets: GoalBudgets): Goal {\n\tconst next = { ...goal };\n\tswitch (limit) {\n\t\tcase \"token_budget\":\n\t\t\tif (budgets.tokenBudget === -1) delete next.tokenBudget;\n\t\t\telse next.tokenBudget = goal.tokensUsed + (budgets.tokenBudget ?? DEFAULT_TOKEN_BUDGET);\n\t\t\treturn next;\n\t\tcase \"turn_budget\":\n\t\t\tif (budgets.maxTurns === undefined || budgets.maxTurns === -1) delete next.turnBudget;\n\t\t\telse next.turnBudget = goal.turnCount + budgets.maxTurns;\n\t\t\treturn next;\n\t\tcase \"time_budget\":\n\t\t\tif (budgets.maxActiveMinutes === undefined || budgets.maxActiveMinutes === -1) delete next.activeTimeBudgetMs;\n\t\t\telse next.activeTimeBudgetMs = activeTime(goal) + budgets.maxActiveMinutes * 60_000;\n\t\t\treturn next;\n\t}\n}\n\n/** The goal recorded on `branch`; `null` when it was cleared, undefined when none was ever set. */\nexport function readGoal(branch: readonly SessionEntry[]): Goal | null | undefined {\n\tfor (let index = branch.length - 1; index >= 0; index--) {\n\t\tconst entry = branch[index];\n\t\tif (entry.type === \"custom\" && entry.customType === GOAL_ENTRY) return (entry.data as { goal: Goal | null }).goal;\n\t}\n\treturn undefined;\n}\n\n/** Token counts the way the footer shows them: 950, 1.2k, 30.0m. */\nexport function formatTokens(count: number): string {\n\tif (count < 1000) return String(count);\n\tif (count < 1_000_000) return `${(count / 1000).toFixed(1)}k`;\n\treturn `${(count / 1_000_000).toFixed(1)}m`;\n}\n\n/** Durations as 45s, 12m, 2h 5m. */\nexport function formatDuration(ms: number): string {\n\tconst seconds = Math.floor(ms / 1000);\n\tif (seconds < 60) return `${seconds}s`;\n\tconst minutes = Math.floor(seconds / 60);\n\tif (minutes < 60) return `${minutes}m`;\n\treturn `${Math.floor(minutes / 60)}h ${minutes % 60}m`;\n}\n\n/** The status card: title, meters, objective, and reason. `activeMs` is the active time to show. */\nexport function goalCard(goal: Goal, verifying: boolean, activeMs: number): string {\n\tconst titles: Record<GoalStatus, string> = {\n\t\tactive: \"Goal active\",\n\t\tpaused: \"Goal paused\",\n\t\tblocked: \"Goal blocked\",\n\t\tusage_limited: \"Goal usage limited\",\n\t\tcomplete: \"Goal complete\",\n\t};\n\tconst meters = [\n\t\tgoal.turnCount > 0\n\t\t\t? `${goal.turnCount}${goal.turnBudget ? `/${goal.turnBudget}` : \"\"} ${(goal.turnBudget ?? goal.turnCount) === 1 ? \"turn\" : \"turns\"}`\n\t\t\t: \"\",\n\t\tactiveMs >= 1000\n\t\t\t? `${formatDuration(activeMs)}${goal.activeTimeBudgetMs ? `/${formatDuration(goal.activeTimeBudgetMs)}` : \"\"}`\n\t\t\t: \"\",\n\t\tgoal.tokensUsed > 0\n\t\t\t? `${formatTokens(goal.tokensUsed)}${goal.tokenBudget ? `/${formatTokens(goal.tokenBudget)}` : \"\"} tokens`\n\t\t\t: \"\",\n\t].filter(Boolean);\n\tconst lines = [verifying ? \"Goal checking\" : titles[goal.status]];\n\tif (meters.length > 0) lines.push(meters.join(\" · \"));\n\tlines.push(`Goal: ${goal.objective}`);\n\tif (goal.lastReason && (goal.status !== \"active\" || verifying)) lines.push(`Reason: ${goal.lastReason}`);\n\treturn lines.join(\"\\n\");\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Goal tools: `get_goal` reads the Goal record, `update_goal` records a proposal that the Goal is
|
|
3
|
+
* complete or blocked. Neither changes the Goal: only the verifier's acceptance does.
|
|
4
|
+
*/
|
|
5
|
+
import { Type } from "typebox";
|
|
6
|
+
import type { ToolDefinition } from "../../core/extensions/types.ts";
|
|
7
|
+
import { type Goal } from "./state.ts";
|
|
8
|
+
import type { GoalProposal } from "./verifier.ts";
|
|
9
|
+
export declare const GET_GOAL_TOOL_NAME = "get_goal";
|
|
10
|
+
export declare const UPDATE_GOAL_TOOL_NAME = "update_goal";
|
|
11
|
+
/** Same-host access to the Goal runtime's state. */
|
|
12
|
+
export interface GoalToolHost {
|
|
13
|
+
/** The current Goal, whatever its status. */
|
|
14
|
+
goal(): Goal | undefined;
|
|
15
|
+
/** Whether a Goal turn is running, so a proposal can be recorded for it. */
|
|
16
|
+
inGoalTurn(): boolean;
|
|
17
|
+
/** Record a proposal for the running turn: whether it goes to the verifier, or why it was refused. */
|
|
18
|
+
recordProposal(proposal: GoalProposal): ProposalRecording;
|
|
19
|
+
}
|
|
20
|
+
/** The outcome of recording a proposal. `streak` counts turns of the same repeated blocker. */
|
|
21
|
+
export type ProposalRecording = {
|
|
22
|
+
kind: "recorded";
|
|
23
|
+
ready: boolean;
|
|
24
|
+
streak: number;
|
|
25
|
+
} | {
|
|
26
|
+
kind: "refused";
|
|
27
|
+
error: string;
|
|
28
|
+
};
|
|
29
|
+
declare const getGoalSchema: Type.TObject<{}>;
|
|
30
|
+
/** `get_goal`: the objective, status, budget figures, and verifier feedback, as JSON. */
|
|
31
|
+
export declare function createGetGoalToolDefinition(host: GoalToolHost): ToolDefinition<typeof getGoalSchema>;
|
|
32
|
+
declare const updateGoalSchema: Type.TObject<{
|
|
33
|
+
status: Type.TUnsafe<"blocked" | "complete">;
|
|
34
|
+
reason: Type.TString;
|
|
35
|
+
blockerKind: Type.TOptional<Type.TUnsafe<"authority" | "external" | "infeasible" | "repeated">>;
|
|
36
|
+
}>;
|
|
37
|
+
/** `update_goal`: record a completion or blocker proposal; a ready one ends the turn. */
|
|
38
|
+
export declare function createUpdateGoalToolDefinition(host: GoalToolHost): ToolDefinition<typeof updateGoalSchema>;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/extensions/goals/tools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAC7C,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AAEnD,oDAAoD;AACpD,MAAM,WAAW,YAAY;IAC5B,6CAA6C;IAC7C,IAAI,IAAI,IAAI,GAAG,SAAS,CAAC;IACzB,4EAA4E;IAC5E,UAAU,IAAI,OAAO,CAAC;IACtB,sGAAsG;IACtG,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG,iBAAiB,CAAC;CAC1D;AAED,+FAA+F;AAC/F,MAAM,MAAM,iBAAiB,GAC1B;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAKtC,QAAA,MAAM,aAAa,kBAAkB,CAAC;AAEtC,yFAAyF;AACzF,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,YAAY,GAAG,cAAc,CAAC,OAAO,aAAa,CAAC,CA+CpG;AAED,QAAA,MAAM,gBAAgB;;;;EAepB,CAAC;AAQH,yFAAyF;AACzF,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,YAAY,GAAG,cAAc,CAAC,OAAO,gBAAgB,CAAC,CAuC1G"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Goal tools: `get_goal` reads the Goal record, `update_goal` records a proposal that the Goal is
|
|
3
|
+
* complete or blocked. Neither changes the Goal: only the verifier's acceptance does.
|
|
4
|
+
*/
|
|
5
|
+
import { Type } from "typebox";
|
|
6
|
+
import { StringEnum } from "../../core/extensions/diffra-ai-extension-view.js";
|
|
7
|
+
import { activeTime } from "./state.js";
|
|
8
|
+
export const GET_GOAL_TOOL_NAME = "get_goal";
|
|
9
|
+
export const UPDATE_GOAL_TOOL_NAME = "update_goal";
|
|
10
|
+
const MAX_REASON_CHARS = 8_000;
|
|
11
|
+
const MAX_REASON_BYTES = 16_000;
|
|
12
|
+
const getGoalSchema = Type.Object({});
|
|
13
|
+
/** `get_goal`: the objective, status, budget figures, and verifier feedback, as JSON. */
|
|
14
|
+
export function createGetGoalToolDefinition(host) {
|
|
15
|
+
return {
|
|
16
|
+
name: GET_GOAL_TOOL_NAME,
|
|
17
|
+
label: "GetGoal",
|
|
18
|
+
description: "Read the active Goal: its objective, status, token, turn, and time budgets, and the verifier's feedback on the last proposal. Read-only.",
|
|
19
|
+
parameters: getGoalSchema,
|
|
20
|
+
defaultActive: false,
|
|
21
|
+
async execute() {
|
|
22
|
+
const goal = host.goal();
|
|
23
|
+
const record = goal?.status === "active"
|
|
24
|
+
? {
|
|
25
|
+
active: true,
|
|
26
|
+
goalId: goal.goalId,
|
|
27
|
+
revision: goal.revision,
|
|
28
|
+
objective: goal.objective,
|
|
29
|
+
status: goal.status,
|
|
30
|
+
tokensUsed: goal.tokensUsed,
|
|
31
|
+
...(goal.tokenBudget === undefined
|
|
32
|
+
? {}
|
|
33
|
+
: {
|
|
34
|
+
tokenBudget: goal.tokenBudget,
|
|
35
|
+
tokensRemaining: Math.max(0, goal.tokenBudget - goal.tokensUsed),
|
|
36
|
+
}),
|
|
37
|
+
turnsFinished: goal.turnCount,
|
|
38
|
+
...(goal.turnBudget === undefined ? {} : { turnBudget: goal.turnBudget }),
|
|
39
|
+
activeMinutes: Math.floor(activeTime(goal) / 60_000),
|
|
40
|
+
...(goal.activeTimeBudgetMs === undefined
|
|
41
|
+
? {}
|
|
42
|
+
: { activeMinutesBudget: Math.round(goal.activeTimeBudgetMs / 60_000) }),
|
|
43
|
+
...(goal.windDown ? { finalTurn: true } : {}),
|
|
44
|
+
...(goal.verifierFeedback ? { verifierFeedback: goal.verifierFeedback } : {}),
|
|
45
|
+
}
|
|
46
|
+
: {
|
|
47
|
+
active: false,
|
|
48
|
+
lastGoal: goal
|
|
49
|
+
? {
|
|
50
|
+
objective: goal.objective,
|
|
51
|
+
status: goal.status,
|
|
52
|
+
...(goal.lastReason ? { reason: goal.lastReason } : {}),
|
|
53
|
+
}
|
|
54
|
+
: null,
|
|
55
|
+
};
|
|
56
|
+
return { content: [{ type: "text", text: JSON.stringify(record, null, 2) }], details: undefined };
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const updateGoalSchema = Type.Object({
|
|
61
|
+
status: StringEnum(["complete", "blocked"], {
|
|
62
|
+
description: "complete: every requirement of the objective is met. blocked: the Goal cannot go on without the user or an outside change.",
|
|
63
|
+
}),
|
|
64
|
+
reason: Type.String({
|
|
65
|
+
description: "Why the Goal is complete or blocked, citing the tool results that prove it. For blocked: the cause and what would unblock it.",
|
|
66
|
+
}),
|
|
67
|
+
blockerKind: Type.Optional(StringEnum(["authority", "external", "repeated", "infeasible"], {
|
|
68
|
+
description: "For blocked. authority: needs the user's permission or a material choice. external: needs a change outside the workspace. infeasible: the objective cannot be met as written. repeated (default): the same technical blocker on three consecutive Goal turns.",
|
|
69
|
+
})),
|
|
70
|
+
});
|
|
71
|
+
const UPDATE_GOAL_DESCRIPTION = `Propose that the active Goal is complete or blocked. This only records a proposal: after this turn ends, an independent verifier judges it against the evidence of the Goal's turns, and only its acceptance ends the Goal. A rejected proposal comes back as verifier feedback in the next turn.
|
|
72
|
+
|
|
73
|
+
Call it only when the evidence is in this conversation: run the decisive checks yourself right before the call. At most one proposal per turn. A repeated blocker goes to the verifier only after the same blocker with the same reason is reported on three consecutive Goal turns; authority, external, and infeasible blockers go at once.
|
|
74
|
+
|
|
75
|
+
When the result says the proposal is ready for verification, end your turn without any text. Never tell the user that the Goal is complete or blocked.`;
|
|
76
|
+
/** `update_goal`: record a completion or blocker proposal; a ready one ends the turn. */
|
|
77
|
+
export function createUpdateGoalToolDefinition(host) {
|
|
78
|
+
return {
|
|
79
|
+
name: UPDATE_GOAL_TOOL_NAME,
|
|
80
|
+
label: "UpdateGoal",
|
|
81
|
+
description: UPDATE_GOAL_DESCRIPTION,
|
|
82
|
+
parameters: updateGoalSchema,
|
|
83
|
+
defaultActive: false,
|
|
84
|
+
executionMode: "sequential",
|
|
85
|
+
async execute(_toolCallId, params) {
|
|
86
|
+
if (!host.inGoalTurn() || host.goal()?.status !== "active") {
|
|
87
|
+
throw new Error("update_goal works only during a turn of an active Goal.");
|
|
88
|
+
}
|
|
89
|
+
const reason = params.reason.trim();
|
|
90
|
+
if (reason === "")
|
|
91
|
+
throw new Error("reason must not be empty.");
|
|
92
|
+
if (reason.length > MAX_REASON_CHARS || Buffer.byteLength(reason) > MAX_REASON_BYTES) {
|
|
93
|
+
throw new Error(`reason must be at most ${MAX_REASON_CHARS} characters and ${MAX_REASON_BYTES} bytes.`);
|
|
94
|
+
}
|
|
95
|
+
const proposal = params.status === "blocked"
|
|
96
|
+
? { status: "blocked", reason, blockerKind: params.blockerKind ?? "repeated" }
|
|
97
|
+
: { status: "complete", reason };
|
|
98
|
+
const recorded = host.recordProposal(proposal);
|
|
99
|
+
if (recorded.kind === "refused")
|
|
100
|
+
throw new Error(recorded.error);
|
|
101
|
+
const nextAction = recorded.ready
|
|
102
|
+
? "End this turn now, without any text. The verifier judges the proposal after the turn ends. Never tell the user that the Goal is complete or blocked."
|
|
103
|
+
: `A repeated blocker goes to the verifier after it is reported with the same reason on 3 consecutive Goal turns; this is turn ${recorded.streak} of 3. Keep working on the objective, or use another blockerKind if one applies.`;
|
|
104
|
+
const result = {
|
|
105
|
+
proposalRecorded: true,
|
|
106
|
+
readyForVerification: recorded.ready,
|
|
107
|
+
goalLifecycleChanged: false,
|
|
108
|
+
nextAction,
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
112
|
+
details: undefined,
|
|
113
|
+
...(recorded.ready ? { terminate: true } : {}),
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/extensions/goals/tools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,mDAAmD,CAAC;AAE/E,OAAO,EAAE,UAAU,EAAa,MAAM,YAAY,CAAC;AAGnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;AAC7C,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,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EAAE,CAAC;YACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;YAC/C,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS;gBAAE,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACjE,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK;gBAChC,CAAC,CAAC,sJAAsJ;gBACxJ,CAAC,CAAC,+HAA+H,QAAQ,CAAC,MAAM,kFAAkF,CAAC;YACpO,MAAM,MAAM,GAAG;gBACd,gBAAgB,EAAE,IAAI;gBACtB,oBAAoB,EAAE,QAAQ,CAAC,KAAK;gBACpC,oBAAoB,EAAE,KAAK;gBAC3B,UAAU;aACV,CAAC;YACF,OAAO;gBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;gBAClE,OAAO,EAAE,SAAS;gBAClB,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC9C,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * The Goal tools: `get_goal` reads the Goal record, `update_goal` records a proposal that the Goal is\n * complete or blocked. Neither changes the Goal: only the verifier's acceptance does.\n */\n\nimport { Type } from \"typebox\";\nimport { StringEnum } from \"../../core/extensions/diffra-ai-extension-view.ts\";\nimport type { ToolDefinition } from \"../../core/extensions/types.ts\";\nimport { activeTime, type Goal } from \"./state.ts\";\nimport type { GoalProposal } from \"./verifier.ts\";\n\nexport const GET_GOAL_TOOL_NAME = \"get_goal\";\nexport const UPDATE_GOAL_TOOL_NAME = \"update_goal\";\n\n/** Same-host access to the Goal runtime's state. */\nexport interface GoalToolHost {\n\t/** The current Goal, whatever its status. */\n\tgoal(): Goal | undefined;\n\t/** Whether a Goal turn is running, so a proposal can be recorded for it. */\n\tinGoalTurn(): boolean;\n\t/** Record a proposal for the running turn: whether it goes to the verifier, or why it was refused. */\n\trecordProposal(proposal: GoalProposal): ProposalRecording;\n}\n\n/** The outcome of recording a proposal. `streak` counts turns of the same repeated blocker. */\nexport type ProposalRecording =\n\t| { kind: \"recorded\"; ready: boolean; streak: number }\n\t| { kind: \"refused\"; error: string };\n\nconst MAX_REASON_CHARS = 8_000;\nconst MAX_REASON_BYTES = 16_000;\n\nconst getGoalSchema = Type.Object({});\n\n/** `get_goal`: the objective, status, budget figures, and verifier feedback, as JSON. */\nexport function createGetGoalToolDefinition(host: GoalToolHost): ToolDefinition<typeof getGoalSchema> {\n\treturn {\n\t\tname: GET_GOAL_TOOL_NAME,\n\t\tlabel: \"GetGoal\",\n\t\tdescription:\n\t\t\t\"Read the active Goal: its objective, status, token, turn, and time budgets, and the verifier's feedback on the last proposal. Read-only.\",\n\t\tparameters: getGoalSchema,\n\t\tdefaultActive: false,\n\t\tasync execute() {\n\t\t\tconst goal = host.goal();\n\t\t\tconst record =\n\t\t\t\tgoal?.status === \"active\"\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tactive: true,\n\t\t\t\t\t\t\tgoalId: goal.goalId,\n\t\t\t\t\t\t\trevision: goal.revision,\n\t\t\t\t\t\t\tobjective: goal.objective,\n\t\t\t\t\t\t\tstatus: goal.status,\n\t\t\t\t\t\t\ttokensUsed: goal.tokensUsed,\n\t\t\t\t\t\t\t...(goal.tokenBudget === undefined\n\t\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\t\ttokenBudget: goal.tokenBudget,\n\t\t\t\t\t\t\t\t\t\ttokensRemaining: Math.max(0, goal.tokenBudget - goal.tokensUsed),\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tturnsFinished: goal.turnCount,\n\t\t\t\t\t\t\t...(goal.turnBudget === undefined ? {} : { turnBudget: goal.turnBudget }),\n\t\t\t\t\t\t\tactiveMinutes: Math.floor(activeTime(goal) / 60_000),\n\t\t\t\t\t\t\t...(goal.activeTimeBudgetMs === undefined\n\t\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t\t: { activeMinutesBudget: Math.round(goal.activeTimeBudgetMs / 60_000) }),\n\t\t\t\t\t\t\t...(goal.windDown ? { finalTurn: true } : {}),\n\t\t\t\t\t\t\t...(goal.verifierFeedback ? { verifierFeedback: goal.verifierFeedback } : {}),\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tactive: false,\n\t\t\t\t\t\t\tlastGoal: goal\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\tobjective: goal.objective,\n\t\t\t\t\t\t\t\t\t\tstatus: goal.status,\n\t\t\t\t\t\t\t\t\t\t...(goal.lastReason ? { reason: goal.lastReason } : {}),\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: null,\n\t\t\t\t\t\t};\n\t\t\treturn { content: [{ type: \"text\", text: JSON.stringify(record, null, 2) }], details: undefined };\n\t\t},\n\t};\n}\n\nconst updateGoalSchema = Type.Object({\n\tstatus: StringEnum([\"complete\", \"blocked\"] as const, {\n\t\tdescription:\n\t\t\t\"complete: every requirement of the objective is met. blocked: the Goal cannot go on without the user or an outside change.\",\n\t}),\n\treason: Type.String({\n\t\tdescription:\n\t\t\t\"Why the Goal is complete or blocked, citing the tool results that prove it. For blocked: the cause and what would unblock it.\",\n\t}),\n\tblockerKind: Type.Optional(\n\t\tStringEnum([\"authority\", \"external\", \"repeated\", \"infeasible\"] as const, {\n\t\t\tdescription:\n\t\t\t\t\"For blocked. authority: needs the user's permission or a material choice. external: needs a change outside the workspace. infeasible: the objective cannot be met as written. repeated (default): the same technical blocker on three consecutive Goal turns.\",\n\t\t}),\n\t),\n});\n\nconst UPDATE_GOAL_DESCRIPTION = `Propose that the active Goal is complete or blocked. This only records a proposal: after this turn ends, an independent verifier judges it against the evidence of the Goal's turns, and only its acceptance ends the Goal. A rejected proposal comes back as verifier feedback in the next turn.\n\nCall it only when the evidence is in this conversation: run the decisive checks yourself right before the call. At most one proposal per turn. A repeated blocker goes to the verifier only after the same blocker with the same reason is reported on three consecutive Goal turns; authority, external, and infeasible blockers go at once.\n\nWhen the result says the proposal is ready for verification, end your turn without any text. Never tell the user that the Goal is complete or blocked.`;\n\n/** `update_goal`: record a completion or blocker proposal; a ready one ends the turn. */\nexport function createUpdateGoalToolDefinition(host: GoalToolHost): ToolDefinition<typeof updateGoalSchema> {\n\treturn {\n\t\tname: UPDATE_GOAL_TOOL_NAME,\n\t\tlabel: \"UpdateGoal\",\n\t\tdescription: UPDATE_GOAL_DESCRIPTION,\n\t\tparameters: updateGoalSchema,\n\t\tdefaultActive: false,\n\t\texecutionMode: \"sequential\",\n\t\tasync execute(_toolCallId, params) {\n\t\t\tif (!host.inGoalTurn() || host.goal()?.status !== \"active\") {\n\t\t\t\tthrow new Error(\"update_goal works only during a turn of an active Goal.\");\n\t\t\t}\n\t\t\tconst reason = params.reason.trim();\n\t\t\tif (reason === \"\") throw new Error(\"reason must not be empty.\");\n\t\t\tif (reason.length > MAX_REASON_CHARS || Buffer.byteLength(reason) > MAX_REASON_BYTES) {\n\t\t\t\tthrow new Error(`reason must be at most ${MAX_REASON_CHARS} characters and ${MAX_REASON_BYTES} bytes.`);\n\t\t\t}\n\t\t\tconst proposal: GoalProposal =\n\t\t\t\tparams.status === \"blocked\"\n\t\t\t\t\t? { status: \"blocked\", reason, blockerKind: params.blockerKind ?? \"repeated\" }\n\t\t\t\t\t: { status: \"complete\", reason };\n\t\t\tconst recorded = host.recordProposal(proposal);\n\t\t\tif (recorded.kind === \"refused\") throw new Error(recorded.error);\n\t\t\tconst nextAction = recorded.ready\n\t\t\t\t? \"End this turn now, without any text. The verifier judges the proposal after the turn ends. Never tell the user that the Goal is complete or blocked.\"\n\t\t\t\t: `A repeated blocker goes to the verifier after it is reported with the same reason on 3 consecutive Goal turns; this is turn ${recorded.streak} of 3. Keep working on the objective, or use another blockerKind if one applies.`;\n\t\t\tconst result = {\n\t\t\t\tproposalRecorded: true,\n\t\t\t\treadyForVerification: recorded.ready,\n\t\t\t\tgoalLifecycleChanged: false,\n\t\t\t\tnextAction,\n\t\t\t};\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: JSON.stringify(result, null, 2) }],\n\t\t\t\tdetails: undefined,\n\t\t\t\t...(recorded.ready ? { terminate: true } : {}),\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Goal verifier: a separate model call, without tools, that judges a completion or blocker
|
|
3
|
+
* proposal from a bounded JSON request of the Goal's evidence. Only its acceptance ends a Goal.
|
|
4
|
+
*/
|
|
5
|
+
import type { Api, Model } from "@diffra-ai/ai";
|
|
6
|
+
import type { ModelRegistry } from "../../core/model-registry.ts";
|
|
7
|
+
import type { EvidenceRecord } from "./evidence.ts";
|
|
8
|
+
import type { Goal } from "./state.ts";
|
|
9
|
+
/** A proposal the model recorded with `update_goal`. A type alias so it is JSON data. */
|
|
10
|
+
export type GoalProposal = {
|
|
11
|
+
status: "complete" | "blocked";
|
|
12
|
+
reason: string;
|
|
13
|
+
blockerKind?: "authority" | "external" | "repeated" | "infeasible";
|
|
14
|
+
};
|
|
15
|
+
/** What the verifier concluded, or why it could not. */
|
|
16
|
+
export type VerifierOutcome = {
|
|
17
|
+
kind: "verdict";
|
|
18
|
+
decision: "accept" | "reject";
|
|
19
|
+
reason: string;
|
|
20
|
+
tokens: number;
|
|
21
|
+
} | {
|
|
22
|
+
kind: "no_room";
|
|
23
|
+
} | {
|
|
24
|
+
kind: "failed";
|
|
25
|
+
detail: string;
|
|
26
|
+
tokens: number;
|
|
27
|
+
};
|
|
28
|
+
/** Judge `proposal` against `records` (oldest first). Never rejects: failures come back as `failed`. */
|
|
29
|
+
export declare function verifyProposal(goal: Goal, proposal: GoalProposal, records: readonly EvidenceRecord[], model: Model<Api>, registry: ModelRegistry, signal: AbortSignal): Promise<VerifierOutcome>;
|
|
30
|
+
//# sourceMappingURL=verifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verifier.d.ts","sourceRoot":"","sources":["../../../src/extensions/goals/verifier.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,yFAAyF;AACzF,MAAM,MAAM,YAAY,GAAG;IAC1B,MAAM,EAAE,UAAU,GAAG,SAAS,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,YAAY,CAAC;CACnE,CAAC;AAEF,wDAAwD;AACxD,MAAM,MAAM,eAAe,GACxB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAClF;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAyBtD,wGAAwG;AACxG,wBAAsB,cAAc,CACnC,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,SAAS,cAAc,EAAE,EAClC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,WAAW,GACjB,OAAO,CAAC,eAAe,CAAC,CAiD1B"}
|