@diffra-ai/cli 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -7
- package/dist/bundle/chunks/{anthropic-messages-RDYSW7WM.js → anthropic-messages-HME6WDIM.js} +1 -1
- package/dist/bundle/chunks/{azure-openai-responses-HB77OIU4.js → azure-openai-responses-WKSFBZF5.js} +1 -1
- package/dist/bundle/chunks/bedrock-converse-stream.js +1 -1
- package/dist/bundle/chunks/{chunk-QRII7KJY.js → chunk-3MKQN3ZR.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-762GZFUO.js → chunk-6L2FT6AE.js} +1 -1
- package/dist/bundle/chunks/chunk-6ZD23B2R.js +2 -0
- package/dist/bundle/chunks/{chunk-ZVEA4XD4.js → chunk-E3MJ4MPN.js} +1 -1
- package/dist/bundle/chunks/chunk-GRDBYTYT.js +2003 -0
- package/dist/bundle/chunks/{chunk-RJRIMI6M.js → chunk-GRYHVZSI.js} +1 -1
- package/dist/bundle/chunks/{chunk-Z72M6UD7.js → chunk-MITPYV3F.js} +1 -1
- package/dist/bundle/chunks/{chunk-JJOJ6QJX.js → chunk-MJRIJM22.js} +1 -1
- package/dist/bundle/chunks/{chunk-B4DODQSC.js → chunk-PQGGR7SQ.js} +1 -1
- package/dist/bundle/chunks/{chunk-Z36XYVPO.js → chunk-PXE534VH.js} +2 -2
- package/dist/bundle/chunks/{chunk-OYSUJGUM.js → chunk-QMZGTPRI.js} +1 -1
- package/dist/bundle/chunks/{chunk-VSFRR6IC.js → chunk-QQ6NVGNW.js} +1 -1
- package/dist/bundle/chunks/{chunk-DWKLYVGO.js → chunk-RUI3NOFB.js} +1 -1
- package/dist/bundle/chunks/{chunk-6S2AQWGR.js → chunk-SI7T4LPD.js} +4 -4
- package/dist/bundle/chunks/{chunk-V5GJW5IX.js → chunk-SMYD2SB5.js} +1 -1
- package/dist/bundle/chunks/{chunk-B3FUE2LF.js → chunk-XAA355T2.js} +1 -1
- package/dist/bundle/chunks/{cli-SYWCWCZU.js → cli-GKHAGQO6.js} +1 -1
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-AASXI4DD.js → cloudflare-workers-ai-system-one-PVUECIVD.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-6HC6JYFU.js → google-generative-ai-2YH7DK5J.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-UJFQATKN.js → google-vertex-QNIS4SPE.js} +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-GCDAR6VP.js → llama-cpp-classify-EMBT3ZMY.js} +1 -1
- package/dist/bundle/chunks/{mistral-conversations-CF3OZSLK.js → mistral-conversations-RCHJWX2M.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-L3IPEYDP.js → openai-codex-responses-LBZQ7HUY.js} +1 -1
- package/dist/bundle/chunks/{openai-completions-UXPSYQS7.js → openai-completions-U7NS5GFY.js} +1 -1
- package/dist/bundle/chunks/{openai-decisions-DML6VHFQ.js → openai-decisions-YC4ZEGAR.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-46Z64FIE.js → openai-responses-4YX6XMEO.js} +1 -1
- package/dist/bundle/chunks/{openrouter-images-EI7VO7CT.js → openrouter-images-QPPGKFJY.js} +1 -1
- package/dist/bundle/chunks/{pi-messages-4MV3SCQE.js → pi-messages-5W3GZ7B6.js} +1 -1
- package/dist/bundle/chunks/{runtime-KEVIZBAR.js → runtime-SI4R3AXJ.js} +1 -1
- package/dist/bundle/chunks/{typesafe-system-one-FZU6TH2G.js → typesafe-system-one-GWMQ2NLX.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-ENTYMDSQ.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 +28 -1
- 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 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +81 -47
- 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 +380 -356
- package/docs/docs.json +264 -220
- package/docs/environment-variables.md +110 -103
- package/docs/extensions.md +24 -0
- 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 +100 -99
- package/docs/settings.md +198 -173
- 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-EIL6ZC3J.js +0 -1240
- package/dist/bundle/chunks/chunk-GCKVPVMH.js +0 -2
- package/dist/bundle/chunks/virtual-modules-RGWFZDWP.js +0 -2
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-only scheduled prompts: cron jobs (recurring or one-shot) and the single pending loop
|
|
3
|
+
* wakeup of a self-paced loop. `due()` hands out what should fire now; nothing is written to disk.
|
|
4
|
+
*/
|
|
5
|
+
import { type CronSchedule } from "./cron-expression.ts";
|
|
6
|
+
/** A cron job. Times are epoch ms. */
|
|
7
|
+
export type CronJob = {
|
|
8
|
+
id: string;
|
|
9
|
+
cron: string;
|
|
10
|
+
schedule: CronSchedule;
|
|
11
|
+
prompt: string;
|
|
12
|
+
recurring: boolean;
|
|
13
|
+
createdAt: number;
|
|
14
|
+
/** Recurring jobs fire once more at or after this time, then are deleted. */
|
|
15
|
+
expiresAt: number;
|
|
16
|
+
/** The slot the job fires for next; it fires at `nextFireAt + jitterMs`. */
|
|
17
|
+
nextFireAt: number;
|
|
18
|
+
jitterMs: number;
|
|
19
|
+
};
|
|
20
|
+
/** The pending wakeup of a self-paced loop. */
|
|
21
|
+
export type LoopWakeup = {
|
|
22
|
+
id: string;
|
|
23
|
+
prompt: string;
|
|
24
|
+
reason?: string;
|
|
25
|
+
fireAt: number;
|
|
26
|
+
createdAt: number;
|
|
27
|
+
};
|
|
28
|
+
/** A prompt to deliver now. */
|
|
29
|
+
export type DueFire = {
|
|
30
|
+
kind: "cron";
|
|
31
|
+
id: string;
|
|
32
|
+
prompt: string;
|
|
33
|
+
} | {
|
|
34
|
+
kind: "wakeup";
|
|
35
|
+
id: string;
|
|
36
|
+
prompt: string;
|
|
37
|
+
};
|
|
38
|
+
export declare const MAX_JOBS = 50;
|
|
39
|
+
export declare const WAKEUP_MIN_SECONDS = 60;
|
|
40
|
+
export declare const WAKEUP_MAX_SECONDS = 3600;
|
|
41
|
+
/** Jobs and the pending wakeup of one session. */
|
|
42
|
+
export declare class CronScheduler {
|
|
43
|
+
private readonly jobs;
|
|
44
|
+
private wakeup;
|
|
45
|
+
private wakeupChainStart;
|
|
46
|
+
/** Create a job; `maxAgeMs` 0 means recurring jobs never expire. */
|
|
47
|
+
create(input: {
|
|
48
|
+
cron: string;
|
|
49
|
+
prompt: string;
|
|
50
|
+
recurring: boolean;
|
|
51
|
+
}, now: number, maxAgeMs: number): {
|
|
52
|
+
kind: "created";
|
|
53
|
+
job: CronJob;
|
|
54
|
+
} | {
|
|
55
|
+
kind: "error";
|
|
56
|
+
message: string;
|
|
57
|
+
};
|
|
58
|
+
/** Delete a job or the pending wakeup by id. */
|
|
59
|
+
delete(id: string): boolean;
|
|
60
|
+
/** Delete every job and the pending wakeup; how many there were. */
|
|
61
|
+
clear(): number;
|
|
62
|
+
jobList(): CronJob[];
|
|
63
|
+
pendingWakeup(): LoopWakeup | undefined;
|
|
64
|
+
/** Schedule the loop's next wakeup, replacing a pending one. A chain may run for 24 hours. */
|
|
65
|
+
scheduleWakeup(delaySeconds: number, prompt: string, reason: string | undefined, now: number): {
|
|
66
|
+
kind: "scheduled";
|
|
67
|
+
wakeup: LoopWakeup;
|
|
68
|
+
delaySeconds: number;
|
|
69
|
+
clamped: boolean;
|
|
70
|
+
replaced?: string;
|
|
71
|
+
} | {
|
|
72
|
+
kind: "error";
|
|
73
|
+
message: string;
|
|
74
|
+
};
|
|
75
|
+
cancelWakeup(): void;
|
|
76
|
+
/** What fires at `now`. A slot fires once however late; one-shots and expired jobs are deleted after it. */
|
|
77
|
+
due(now: number): DueFire[];
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=scheduler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../src/extensions/cron/scheduler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,KAAK,YAAY,EAA2B,MAAM,sBAAsB,CAAC;AAElF,sCAAsC;AACtC,MAAM,MAAM,OAAO,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,SAAS,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,+CAA+C;AAC/C,MAAM,MAAM,UAAU,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC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,UAAU,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GACpG;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CA0BpC;IAED,YAAY,IAAI,IAAI,CAEnB;IAED,4GAA4G;IAC5G,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,EAAE,CAc1B;CACD"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-only scheduled prompts: cron jobs (recurring or one-shot) and the single pending loop
|
|
3
|
+
* wakeup of a self-paced loop. `due()` hands out what should fire now; nothing is written to disk.
|
|
4
|
+
*/
|
|
5
|
+
import { randomBytes } from "node:crypto";
|
|
6
|
+
import { nextFireTime, parseCron } from "./cron-expression.js";
|
|
7
|
+
export const MAX_JOBS = 50;
|
|
8
|
+
export const WAKEUP_MIN_SECONDS = 60;
|
|
9
|
+
export const WAKEUP_MAX_SECONDS = 3600;
|
|
10
|
+
const WAKEUP_DEFAULT_SECONDS = 1200;
|
|
11
|
+
const WAKEUP_CHAIN_MAX_MS = 24 * 3_600_000;
|
|
12
|
+
const MAX_RECURRING_JITTER_MS = 15 * 60_000;
|
|
13
|
+
const MAX_ONE_SHOT_EARLY_MS = 90_000;
|
|
14
|
+
/** Jobs and the pending wakeup of one session. */
|
|
15
|
+
export class CronScheduler {
|
|
16
|
+
jobs = new Map();
|
|
17
|
+
wakeup;
|
|
18
|
+
wakeupChainStart;
|
|
19
|
+
/** Create a job; `maxAgeMs` 0 means recurring jobs never expire. */
|
|
20
|
+
create(input, now, maxAgeMs) {
|
|
21
|
+
if (input.prompt.trim() === "")
|
|
22
|
+
return { kind: "error", message: 'Parameter "prompt" must be a non-empty string.' };
|
|
23
|
+
const parsed = parseCron(input.cron);
|
|
24
|
+
if (parsed.kind === "invalid")
|
|
25
|
+
return { kind: "error", message: parsed.message };
|
|
26
|
+
// The next slot after the current minute: a job never fires in the minute it was created.
|
|
27
|
+
const first = nextFireTime(parsed.schedule, now);
|
|
28
|
+
if (first === undefined) {
|
|
29
|
+
return { kind: "error", message: `No matching fire time found within 4 years for: "${input.cron}"` };
|
|
30
|
+
}
|
|
31
|
+
if (this.jobs.size >= MAX_JOBS) {
|
|
32
|
+
return {
|
|
33
|
+
kind: "error",
|
|
34
|
+
message: `Maximum number of cron jobs (${MAX_JOBS}) reached. Delete some jobs first.`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const id = newId();
|
|
38
|
+
const job = {
|
|
39
|
+
id,
|
|
40
|
+
cron: input.cron.trim(),
|
|
41
|
+
schedule: parsed.schedule,
|
|
42
|
+
prompt: input.prompt,
|
|
43
|
+
recurring: input.recurring,
|
|
44
|
+
createdAt: now,
|
|
45
|
+
expiresAt: input.recurring && maxAgeMs > 0 ? now + maxAgeMs : Number.POSITIVE_INFINITY,
|
|
46
|
+
nextFireAt: first,
|
|
47
|
+
jitterMs: jitter(id, parsed.schedule, first, input.recurring),
|
|
48
|
+
};
|
|
49
|
+
this.jobs.set(id, job);
|
|
50
|
+
return { kind: "created", job };
|
|
51
|
+
}
|
|
52
|
+
/** Delete a job or the pending wakeup by id. */
|
|
53
|
+
delete(id) {
|
|
54
|
+
if (this.wakeup?.id === id) {
|
|
55
|
+
this.wakeup = undefined;
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return this.jobs.delete(id);
|
|
59
|
+
}
|
|
60
|
+
/** Delete every job and the pending wakeup; how many there were. */
|
|
61
|
+
clear() {
|
|
62
|
+
const count = this.jobs.size + (this.wakeup ? 1 : 0);
|
|
63
|
+
this.jobs.clear();
|
|
64
|
+
this.wakeup = undefined;
|
|
65
|
+
return count;
|
|
66
|
+
}
|
|
67
|
+
jobList() {
|
|
68
|
+
return [...this.jobs.values()];
|
|
69
|
+
}
|
|
70
|
+
pendingWakeup() {
|
|
71
|
+
return this.wakeup;
|
|
72
|
+
}
|
|
73
|
+
/** Schedule the loop's next wakeup, replacing a pending one. A chain may run for 24 hours. */
|
|
74
|
+
scheduleWakeup(delaySeconds, prompt, reason, now) {
|
|
75
|
+
if (prompt.trim() === "")
|
|
76
|
+
return { kind: "error", message: "Loop wakeup prompt must not be empty." };
|
|
77
|
+
const rounded = Math.round(delaySeconds);
|
|
78
|
+
const seconds = Number.isFinite(delaySeconds)
|
|
79
|
+
? Math.min(WAKEUP_MAX_SECONDS, Math.max(WAKEUP_MIN_SECONDS, rounded))
|
|
80
|
+
: WAKEUP_DEFAULT_SECONDS;
|
|
81
|
+
const replaced = this.wakeup?.id;
|
|
82
|
+
this.wakeupChainStart ??= now;
|
|
83
|
+
// A refused re-arm leaves nothing behind, so a stale wakeup cannot outlive the limit.
|
|
84
|
+
this.wakeup = undefined;
|
|
85
|
+
const fireAt = now + seconds * 1000;
|
|
86
|
+
if (fireAt > this.wakeupChainStart + WAKEUP_CHAIN_MAX_MS) {
|
|
87
|
+
return {
|
|
88
|
+
kind: "error",
|
|
89
|
+
message: "Loop wakeup chain exceeded the 24h session limit. Omit loop_wakeup to end this loop, or start a new session.",
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
this.wakeup = { id: newId(), prompt, ...(reason ? { reason } : {}), fireAt, createdAt: now };
|
|
93
|
+
return {
|
|
94
|
+
kind: "scheduled",
|
|
95
|
+
wakeup: this.wakeup,
|
|
96
|
+
delaySeconds: seconds,
|
|
97
|
+
clamped: seconds !== rounded,
|
|
98
|
+
...(replaced ? { replaced } : {}),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
cancelWakeup() {
|
|
102
|
+
this.wakeup = undefined;
|
|
103
|
+
}
|
|
104
|
+
/** What fires at `now`. A slot fires once however late; one-shots and expired jobs are deleted after it. */
|
|
105
|
+
due(now) {
|
|
106
|
+
const fires = [];
|
|
107
|
+
for (const job of this.jobs.values()) {
|
|
108
|
+
if (now < job.nextFireAt + job.jitterMs)
|
|
109
|
+
continue;
|
|
110
|
+
fires.push({ kind: "cron", id: job.id, prompt: job.prompt });
|
|
111
|
+
const next = job.recurring && now < job.expiresAt ? nextFireTime(job.schedule, now) : undefined;
|
|
112
|
+
if (next === undefined)
|
|
113
|
+
this.jobs.delete(job.id);
|
|
114
|
+
else
|
|
115
|
+
job.nextFireAt = next;
|
|
116
|
+
}
|
|
117
|
+
if (this.wakeup && now >= this.wakeup.fireAt) {
|
|
118
|
+
fires.push({ kind: "wakeup", id: this.wakeup.id, prompt: this.wakeup.prompt });
|
|
119
|
+
this.wakeup = undefined;
|
|
120
|
+
}
|
|
121
|
+
return fires;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** Eight characters of `[a-z0-9]`. */
|
|
125
|
+
function newId() {
|
|
126
|
+
const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
127
|
+
return [...randomBytes(8)].map((byte) => alphabet[byte % alphabet.length]).join("");
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* A fixed offset per job, so jobs with the same schedule do not all fire in the same second:
|
|
131
|
+
* recurring jobs fire up to 10% of their period late (at most 15 minutes); one-shots on :00 or
|
|
132
|
+
* :30 fire up to 90 seconds early.
|
|
133
|
+
*/
|
|
134
|
+
function jitter(id, schedule, first, recurring) {
|
|
135
|
+
let hash = 0;
|
|
136
|
+
for (const char of id)
|
|
137
|
+
hash = (hash * 31 + char.charCodeAt(0)) >>> 0;
|
|
138
|
+
if (!recurring) {
|
|
139
|
+
return new Date(first).getMinutes() % 30 === 0 ? -(hash % MAX_ONE_SHOT_EARLY_MS) : 0;
|
|
140
|
+
}
|
|
141
|
+
const second = nextFireTime(schedule, first);
|
|
142
|
+
const period = second === undefined ? 0 : second - first;
|
|
143
|
+
const span = Math.min(period * 0.1, MAX_RECURRING_JITTER_MS);
|
|
144
|
+
return span >= 1 ? hash % Math.floor(span) : 0;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=scheduler.js.map
|
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AC,CAAC;IAC7C,MAAM,MAAM,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC;IACzD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE,uBAAuB,CAAC,CAAC;IAC7D,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC","sourcesContent":["/**\n * Session-only scheduled prompts: cron jobs (recurring or one-shot) and the single pending loop\n * wakeup of a self-paced loop. `due()` hands out what should fire now; nothing is written to disk.\n */\n\nimport { randomBytes } from \"node:crypto\";\nimport { type CronSchedule, nextFireTime, parseCron } from \"./cron-expression.ts\";\n\n/** A cron job. Times are epoch ms. */\nexport type CronJob = {\n\tid: string;\n\tcron: string;\n\tschedule: CronSchedule;\n\tprompt: string;\n\trecurring: boolean;\n\tcreatedAt: number;\n\t/** Recurring jobs fire once more at or after this time, then are deleted. */\n\texpiresAt: number;\n\t/** The slot the job fires for next; it fires at `nextFireAt + jitterMs`. */\n\tnextFireAt: number;\n\tjitterMs: number;\n};\n\n/** The pending wakeup of a self-paced loop. */\nexport type LoopWakeup = { id: string; prompt: string; reason?: string; fireAt: number; createdAt: number };\n\n/** A prompt to deliver now. */\nexport type DueFire = { kind: \"cron\"; id: string; prompt: string } | { kind: \"wakeup\"; id: string; prompt: string };\n\nexport const MAX_JOBS = 50;\nexport const WAKEUP_MIN_SECONDS = 60;\nexport const WAKEUP_MAX_SECONDS = 3600;\nconst WAKEUP_DEFAULT_SECONDS = 1200;\nconst WAKEUP_CHAIN_MAX_MS = 24 * 3_600_000;\nconst MAX_RECURRING_JITTER_MS = 15 * 60_000;\nconst MAX_ONE_SHOT_EARLY_MS = 90_000;\n\n/** Jobs and the pending wakeup of one session. */\nexport class CronScheduler {\n\tprivate readonly jobs = new Map<string, CronJob>();\n\tprivate wakeup: LoopWakeup | undefined;\n\tprivate wakeupChainStart: number | undefined;\n\n\t/** Create a job; `maxAgeMs` 0 means recurring jobs never expire. */\n\tcreate(\n\t\tinput: { cron: string; prompt: string; recurring: boolean },\n\t\tnow: number,\n\t\tmaxAgeMs: number,\n\t): { kind: \"created\"; job: CronJob } | { kind: \"error\"; message: string } {\n\t\tif (input.prompt.trim() === \"\")\n\t\t\treturn { kind: \"error\", message: 'Parameter \"prompt\" must be a non-empty string.' };\n\t\tconst parsed = parseCron(input.cron);\n\t\tif (parsed.kind === \"invalid\") return { kind: \"error\", message: parsed.message };\n\t\t// The next slot after the current minute: a job never fires in the minute it was created.\n\t\tconst first = nextFireTime(parsed.schedule, now);\n\t\tif (first === undefined) {\n\t\t\treturn { kind: \"error\", message: `No matching fire time found within 4 years for: \"${input.cron}\"` };\n\t\t}\n\t\tif (this.jobs.size >= MAX_JOBS) {\n\t\t\treturn {\n\t\t\t\tkind: \"error\",\n\t\t\t\tmessage: `Maximum number of cron jobs (${MAX_JOBS}) reached. Delete some jobs first.`,\n\t\t\t};\n\t\t}\n\t\tconst id = newId();\n\t\tconst job: CronJob = {\n\t\t\tid,\n\t\t\tcron: input.cron.trim(),\n\t\t\tschedule: parsed.schedule,\n\t\t\tprompt: input.prompt,\n\t\t\trecurring: input.recurring,\n\t\t\tcreatedAt: now,\n\t\t\texpiresAt: input.recurring && maxAgeMs > 0 ? now + maxAgeMs : Number.POSITIVE_INFINITY,\n\t\t\tnextFireAt: first,\n\t\t\tjitterMs: jitter(id, parsed.schedule, first, input.recurring),\n\t\t};\n\t\tthis.jobs.set(id, job);\n\t\treturn { kind: \"created\", job };\n\t}\n\n\t/** Delete a job or the pending wakeup by id. */\n\tdelete(id: string): boolean {\n\t\tif (this.wakeup?.id === id) {\n\t\t\tthis.wakeup = undefined;\n\t\t\treturn true;\n\t\t}\n\t\treturn this.jobs.delete(id);\n\t}\n\n\t/** Delete every job and the pending wakeup; how many there were. */\n\tclear(): number {\n\t\tconst count = this.jobs.size + (this.wakeup ? 1 : 0);\n\t\tthis.jobs.clear();\n\t\tthis.wakeup = undefined;\n\t\treturn count;\n\t}\n\n\tjobList(): CronJob[] {\n\t\treturn [...this.jobs.values()];\n\t}\n\n\tpendingWakeup(): LoopWakeup | undefined {\n\t\treturn this.wakeup;\n\t}\n\n\t/** Schedule the loop's next wakeup, replacing a pending one. A chain may run for 24 hours. */\n\tscheduleWakeup(\n\t\tdelaySeconds: number,\n\t\tprompt: string,\n\t\treason: string | undefined,\n\t\tnow: number,\n\t):\n\t\t| { kind: \"scheduled\"; wakeup: LoopWakeup; delaySeconds: number; clamped: boolean; replaced?: string }\n\t\t| { kind: \"error\"; message: string } {\n\t\tif (prompt.trim() === \"\") return { kind: \"error\", message: \"Loop wakeup prompt must not be empty.\" };\n\t\tconst rounded = Math.round(delaySeconds);\n\t\tconst seconds = Number.isFinite(delaySeconds)\n\t\t\t? Math.min(WAKEUP_MAX_SECONDS, Math.max(WAKEUP_MIN_SECONDS, rounded))\n\t\t\t: WAKEUP_DEFAULT_SECONDS;\n\t\tconst replaced = this.wakeup?.id;\n\t\tthis.wakeupChainStart ??= now;\n\t\t// A refused re-arm leaves nothing behind, so a stale wakeup cannot outlive the limit.\n\t\tthis.wakeup = undefined;\n\t\tconst fireAt = now + seconds * 1000;\n\t\tif (fireAt > this.wakeupChainStart + WAKEUP_CHAIN_MAX_MS) {\n\t\t\treturn {\n\t\t\t\tkind: \"error\",\n\t\t\t\tmessage:\n\t\t\t\t\t\"Loop wakeup chain exceeded the 24h session limit. Omit loop_wakeup to end this loop, or start a new session.\",\n\t\t\t};\n\t\t}\n\t\tthis.wakeup = { id: newId(), prompt, ...(reason ? { reason } : {}), fireAt, createdAt: now };\n\t\treturn {\n\t\t\tkind: \"scheduled\",\n\t\t\twakeup: this.wakeup,\n\t\t\tdelaySeconds: seconds,\n\t\t\tclamped: seconds !== rounded,\n\t\t\t...(replaced ? { replaced } : {}),\n\t\t};\n\t}\n\n\tcancelWakeup(): void {\n\t\tthis.wakeup = undefined;\n\t}\n\n\t/** What fires at `now`. A slot fires once however late; one-shots and expired jobs are deleted after it. */\n\tdue(now: number): DueFire[] {\n\t\tconst fires: DueFire[] = [];\n\t\tfor (const job of this.jobs.values()) {\n\t\t\tif (now < job.nextFireAt + job.jitterMs) continue;\n\t\t\tfires.push({ kind: \"cron\", id: job.id, prompt: job.prompt });\n\t\t\tconst next = job.recurring && now < job.expiresAt ? nextFireTime(job.schedule, now) : undefined;\n\t\t\tif (next === undefined) this.jobs.delete(job.id);\n\t\t\telse job.nextFireAt = next;\n\t\t}\n\t\tif (this.wakeup && now >= this.wakeup.fireAt) {\n\t\t\tfires.push({ kind: \"wakeup\", id: this.wakeup.id, prompt: this.wakeup.prompt });\n\t\t\tthis.wakeup = undefined;\n\t\t}\n\t\treturn fires;\n\t}\n}\n\n/** Eight characters of `[a-z0-9]`. */\nfunction newId(): string {\n\tconst alphabet = \"abcdefghijklmnopqrstuvwxyz0123456789\";\n\treturn [...randomBytes(8)].map((byte) => alphabet[byte % alphabet.length]).join(\"\");\n}\n\n/**\n * A fixed offset per job, so jobs with the same schedule do not all fire in the same second:\n * recurring jobs fire up to 10% of their period late (at most 15 minutes); one-shots on :00 or\n * :30 fire up to 90 seconds early.\n */\nfunction jitter(id: string, schedule: CronSchedule, first: number, recurring: boolean): number {\n\tlet hash = 0;\n\tfor (const char of id) hash = (hash * 31 + char.charCodeAt(0)) >>> 0;\n\tif (!recurring) {\n\t\treturn new Date(first).getMinutes() % 30 === 0 ? -(hash % MAX_ONE_SHOT_EARLY_MS) : 0;\n\t}\n\tconst second = nextFireTime(schedule, first);\n\tconst period = second === undefined ? 0 : second - first;\n\tconst span = Math.min(period * 0.1, MAX_RECURRING_JITTER_MS);\n\treturn span >= 1 ? hash % Math.floor(span) : 0;\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The scheduling tools: `cron_create`, `cron_list`, and `cron_delete` manage session-only cron jobs;
|
|
3
|
+
* `loop_wakeup` sets the next tick of a self-paced loop.
|
|
4
|
+
*/
|
|
5
|
+
import { Type } from "typebox";
|
|
6
|
+
import type { ToolDefinition } from "../../core/extensions/types.ts";
|
|
7
|
+
import { type CronJob, type CronScheduler, type LoopWakeup } from "./scheduler.ts";
|
|
8
|
+
export declare const CRON_CREATE_TOOL_NAME = "cron_create";
|
|
9
|
+
export declare const CRON_LIST_TOOL_NAME = "cron_list";
|
|
10
|
+
export declare const CRON_DELETE_TOOL_NAME = "cron_delete";
|
|
11
|
+
export declare const LOOP_WAKEUP_TOOL_NAME = "loop_wakeup";
|
|
12
|
+
export declare const CRON_TOOL_NAMES: string[];
|
|
13
|
+
/** Same-host access to the scheduler and its settings. */
|
|
14
|
+
export interface CronToolHost {
|
|
15
|
+
scheduler: CronScheduler;
|
|
16
|
+
/** How long recurring jobs live, in ms; 0 for no limit. */
|
|
17
|
+
maxAgeMs(): number;
|
|
18
|
+
}
|
|
19
|
+
declare const cronCreateSchema: Type.TObject<{
|
|
20
|
+
cron: Type.TString;
|
|
21
|
+
prompt: Type.TString;
|
|
22
|
+
recurring: Type.TOptional<Type.TBoolean>;
|
|
23
|
+
durable: Type.TOptional<Type.TBoolean>;
|
|
24
|
+
}>;
|
|
25
|
+
/** `cron_create`: validate and add a job. */
|
|
26
|
+
export declare function createCronCreateToolDefinition(host: CronToolHost): ToolDefinition<typeof cronCreateSchema>;
|
|
27
|
+
/** How long recurring jobs live, in words. */
|
|
28
|
+
export declare function expiryText(maxAgeMs: number): string;
|
|
29
|
+
declare const cronListSchema: Type.TObject<{}>;
|
|
30
|
+
/** `cron_list`: one line per job and the pending wakeup. */
|
|
31
|
+
export declare function createCronListToolDefinition(host: CronToolHost): ToolDefinition<typeof cronListSchema>;
|
|
32
|
+
/** Lines of `id — schedule (type) [session-only]: prompt`. */
|
|
33
|
+
export declare function listText(jobs: readonly CronJob[], wakeup: LoopWakeup | undefined): string;
|
|
34
|
+
declare const cronDeleteSchema: Type.TObject<{
|
|
35
|
+
id: Type.TString;
|
|
36
|
+
}>;
|
|
37
|
+
/** `cron_delete`: cancel a job or the pending wakeup. */
|
|
38
|
+
export declare function createCronDeleteToolDefinition(host: CronToolHost): ToolDefinition<typeof cronDeleteSchema>;
|
|
39
|
+
declare const loopWakeupSchema: Type.TObject<{
|
|
40
|
+
delaySeconds: Type.TNumber;
|
|
41
|
+
prompt: Type.TString;
|
|
42
|
+
reason: Type.TOptional<Type.TString>;
|
|
43
|
+
}>;
|
|
44
|
+
/** `loop_wakeup`: set the next tick of a self-paced loop. */
|
|
45
|
+
export declare function createLoopWakeupToolDefinition(host: CronToolHost): ToolDefinition<typeof loopWakeupSchema>;
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/extensions/cron/tools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,UAAU,EAGf,MAAM,gBAAgB,CAAC;AAExB,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AACnD,eAAO,MAAM,mBAAmB,cAAc,CAAC;AAC/C,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AACnD,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AACnD,eAAO,MAAM,eAAe,UAK3B,CAAC;AAEF,0DAA0D;AAC1D,MAAM,WAAW,YAAY;IAC5B,SAAS,EAAE,aAAa,CAAC;IACzB,2DAA2D;IAC3D,QAAQ,IAAI,MAAM,CAAC;CACnB;AAED,QAAA,MAAM,gBAAgB;;;;;EAiBrB,CAAC;AAUF,6CAA6C;AAC7C,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,YAAY,GAAG,cAAc,CAAC,OAAO,gBAAgB,CAAC,CAuB1G;AAED,8CAA8C;AAC9C,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAInD;AAED,QAAA,MAAM,cAAc,kBAAkB,CAAC;AAEvC,4DAA4D;AAC5D,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,YAAY,GAAG,cAAc,CAAC,OAAO,cAAc,CAAC,CActG;AAED,8DAA8D;AAC9D,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,EAAE,MAAM,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,CAWzF;AAED,QAAA,MAAM,gBAAgB;;EAA+F,CAAC;AAEtH,yDAAyD;AACzD,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,YAAY,GAAG,cAAc,CAAC,OAAO,gBAAgB,CAAC,CAW1G;AAED,QAAA,MAAM,gBAAgB;;;;EAUpB,CAAC;AAKH,6DAA6D;AAC7D,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,YAAY,GAAG,cAAc,CAAC,OAAO,gBAAgB,CAAC,CAuB1G"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The scheduling tools: `cron_create`, `cron_list`, and `cron_delete` manage session-only cron jobs;
|
|
3
|
+
* `loop_wakeup` sets the next tick of a self-paced loop.
|
|
4
|
+
*/
|
|
5
|
+
import { Type } from "typebox";
|
|
6
|
+
import { WAKEUP_MAX_SECONDS, WAKEUP_MIN_SECONDS, } from "./scheduler.js";
|
|
7
|
+
export const CRON_CREATE_TOOL_NAME = "cron_create";
|
|
8
|
+
export const CRON_LIST_TOOL_NAME = "cron_list";
|
|
9
|
+
export const CRON_DELETE_TOOL_NAME = "cron_delete";
|
|
10
|
+
export const LOOP_WAKEUP_TOOL_NAME = "loop_wakeup";
|
|
11
|
+
export const CRON_TOOL_NAMES = [
|
|
12
|
+
CRON_CREATE_TOOL_NAME,
|
|
13
|
+
CRON_LIST_TOOL_NAME,
|
|
14
|
+
CRON_DELETE_TOOL_NAME,
|
|
15
|
+
LOOP_WAKEUP_TOOL_NAME,
|
|
16
|
+
];
|
|
17
|
+
const cronCreateSchema = Type.Object({
|
|
18
|
+
cron: Type.String({
|
|
19
|
+
description: 'Five-field cron expression in local time: "minute hour day-of-month month day-of-week", e.g. "*/5 * * * *" for every 5 minutes or "30 14 25 12 *" for 14:30 on 25 December.',
|
|
20
|
+
}),
|
|
21
|
+
prompt: Type.String({ description: "The prompt to run at each fire. A slash command runs as that command." }),
|
|
22
|
+
recurring: Type.Optional(Type.Boolean({
|
|
23
|
+
description: "true (default): fire at every match until deleted or expired. false: fire once, then delete.",
|
|
24
|
+
})),
|
|
25
|
+
durable: Type.Optional(Type.Boolean({ description: "Persist across restarts. Not supported in standalone sessions." })),
|
|
26
|
+
}, { additionalProperties: false });
|
|
27
|
+
const CRON_CREATE_DESCRIPTION = `Schedule a prompt to run later in this session, once or on a recurring cron schedule. Times are local.
|
|
28
|
+
|
|
29
|
+
- For a one-shot reminder ("in 20 minutes", "at 3pm"), pin minute, hour, day of month, and month to the target time and set recurring to false.
|
|
30
|
+
- For recurring work use a recurring job; it expires after the configured limit (7 days by default) and fires one last time then.
|
|
31
|
+
- Prefer minutes other than :00 and :30 when the exact minute does not matter, so jobs do not all fire at once. Recurring jobs fire up to 10% of their period late (at most 15 minutes); one-shots on :00 or :30 up to 90 seconds early.
|
|
32
|
+
- Jobs fire only while Diffra is idle, each as its own turn, and end with the session. Use durable only when the user explicitly asks for persistence.
|
|
33
|
+
- At most 50 jobs.`;
|
|
34
|
+
/** `cron_create`: validate and add a job. */
|
|
35
|
+
export function createCronCreateToolDefinition(host) {
|
|
36
|
+
return {
|
|
37
|
+
name: CRON_CREATE_TOOL_NAME,
|
|
38
|
+
label: "CronCreate",
|
|
39
|
+
description: CRON_CREATE_DESCRIPTION,
|
|
40
|
+
parameters: cronCreateSchema,
|
|
41
|
+
async execute(_toolCallId, params) {
|
|
42
|
+
if (params.durable)
|
|
43
|
+
throw new Error("Error creating cron job: Durable cron jobs are not supported in standalone sessions.");
|
|
44
|
+
const recurring = params.recurring !== false;
|
|
45
|
+
const created = host.scheduler.create({ cron: params.cron, prompt: params.prompt, recurring }, Date.now(), host.maxAgeMs());
|
|
46
|
+
if (created.kind === "error")
|
|
47
|
+
throw new Error(`Error creating cron job: ${created.message}`);
|
|
48
|
+
const where = "Session-only (not written to disk, ends when the session ends).";
|
|
49
|
+
const text = recurring
|
|
50
|
+
? `Scheduled recurring job ${created.job.id} (${created.job.cron}). ${where} ${expiryText(host.maxAgeMs())}`
|
|
51
|
+
: `Scheduled one-shot task ${created.job.id} (${created.job.cron}). ${where} It will fire once then auto-delete.`;
|
|
52
|
+
return { content: [{ type: "text", text }], details: undefined };
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** How long recurring jobs live, in words. */
|
|
57
|
+
export function expiryText(maxAgeMs) {
|
|
58
|
+
if (maxAgeMs <= 0)
|
|
59
|
+
return "Never auto-expires. Use cron_delete to cancel it.";
|
|
60
|
+
const days = maxAgeMs / 86_400_000;
|
|
61
|
+
return `Auto-expires after ${days} ${days === 1 ? "day" : "days"}. Use cron_delete to cancel sooner.`;
|
|
62
|
+
}
|
|
63
|
+
const cronListSchema = Type.Object({});
|
|
64
|
+
/** `cron_list`: one line per job and the pending wakeup. */
|
|
65
|
+
export function createCronListToolDefinition(host) {
|
|
66
|
+
return {
|
|
67
|
+
name: CRON_LIST_TOOL_NAME,
|
|
68
|
+
label: "CronList",
|
|
69
|
+
description: "List the scheduled cron jobs and the pending loop wakeup of this session.",
|
|
70
|
+
parameters: cronListSchema,
|
|
71
|
+
annotations: { readOnlyHint: true },
|
|
72
|
+
async execute() {
|
|
73
|
+
return {
|
|
74
|
+
content: [{ type: "text", text: listText(host.scheduler.jobList(), host.scheduler.pendingWakeup()) }],
|
|
75
|
+
details: undefined,
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** Lines of `id — schedule (type) [session-only]: prompt`. */
|
|
81
|
+
export function listText(jobs, wakeup) {
|
|
82
|
+
const lines = jobs.map((job) => `${job.id} — ${job.cron} (${job.recurring ? "recurring" : "one-shot"}) [session-only]: ${job.prompt}`);
|
|
83
|
+
if (wakeup) {
|
|
84
|
+
const prompt = wakeup.prompt.length > 60 ? `${wakeup.prompt.slice(0, 57)}...` : wakeup.prompt;
|
|
85
|
+
lines.push(`${wakeup.id} — wakeup at ${new Date(wakeup.fireAt).toLocaleString()} (one-shot) [session-only]: ${prompt}`);
|
|
86
|
+
}
|
|
87
|
+
return lines.length > 0 ? lines.join("\n") : "No active cron jobs or loop wakeups.";
|
|
88
|
+
}
|
|
89
|
+
const cronDeleteSchema = Type.Object({ id: Type.String({ description: "Id of the job or loop wakeup to cancel." }) });
|
|
90
|
+
/** `cron_delete`: cancel a job or the pending wakeup. */
|
|
91
|
+
export function createCronDeleteToolDefinition(host) {
|
|
92
|
+
return {
|
|
93
|
+
name: CRON_DELETE_TOOL_NAME,
|
|
94
|
+
label: "CronDelete",
|
|
95
|
+
description: "Cancel a cron job or the pending loop wakeup by id.",
|
|
96
|
+
parameters: cronDeleteSchema,
|
|
97
|
+
async execute(_toolCallId, params) {
|
|
98
|
+
if (!host.scheduler.delete(params.id))
|
|
99
|
+
throw new Error(`Job ${params.id} not found.`);
|
|
100
|
+
return { content: [{ type: "text", text: `Cancelled job ${params.id}.` }], details: undefined };
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const loopWakeupSchema = Type.Object({
|
|
105
|
+
delaySeconds: Type.Number({
|
|
106
|
+
description: `Seconds from now, clamped to ${WAKEUP_MIN_SECONDS}-${WAKEUP_MAX_SECONDS}. Use 60-270 only when polling something nothing else reports (a CI run, a remote queue). When a background agent will notify you when it finishes, use 1200-1800 as a fallback in case it never does. Without a specific signal, use 1200 or more.`,
|
|
107
|
+
}),
|
|
108
|
+
prompt: Type.String({
|
|
109
|
+
maxLength: 10_000,
|
|
110
|
+
description: "The prompt of the next tick. Start it with /loop to continue the loop, e.g. `/loop check the deploy`.",
|
|
111
|
+
}),
|
|
112
|
+
reason: Type.Optional(Type.String({ description: "Why this delay, in a few words." })),
|
|
113
|
+
});
|
|
114
|
+
const LOOP_WAKEUP_DESCRIPTION = "Schedule the next tick of a self-paced loop (always pass prompt). Call it before ending the turn to keep the loop going; leave it out to end the loop. One-shot and session-only; a new call replaces the pending wakeup, and a chain of wakeups may run for at most 24 hours. When a background agent will notify you when it finishes, keep the wakeup as a long fallback rather than a short poll.";
|
|
115
|
+
/** `loop_wakeup`: set the next tick of a self-paced loop. */
|
|
116
|
+
export function createLoopWakeupToolDefinition(host) {
|
|
117
|
+
return {
|
|
118
|
+
name: LOOP_WAKEUP_TOOL_NAME,
|
|
119
|
+
label: "LoopWakeup",
|
|
120
|
+
description: LOOP_WAKEUP_DESCRIPTION,
|
|
121
|
+
parameters: loopWakeupSchema,
|
|
122
|
+
async execute(_toolCallId, params) {
|
|
123
|
+
const reason = params.reason?.trim();
|
|
124
|
+
const scheduled = host.scheduler.scheduleWakeup(params.delaySeconds, params.prompt, reason, Date.now());
|
|
125
|
+
if (scheduled.kind === "error")
|
|
126
|
+
throw new Error(`Error scheduling loop wakeup: ${scheduled.message}`);
|
|
127
|
+
const at = new Date(scheduled.wakeup.fireAt).toLocaleString();
|
|
128
|
+
const lines = [
|
|
129
|
+
`Scheduled loop wakeup ${scheduled.wakeup.id}.`,
|
|
130
|
+
scheduled.replaced ? `Replaced pending wakeup ${scheduled.replaced}.` : undefined,
|
|
131
|
+
`Scheduled for: ${at} (in ${scheduled.delaySeconds}s).`,
|
|
132
|
+
scheduled.clamped
|
|
133
|
+
? `Requested ${params.delaySeconds}s was clamped to the [${WAKEUP_MIN_SECONDS}, ${WAKEUP_MAX_SECONDS}] s range.`
|
|
134
|
+
: undefined,
|
|
135
|
+
reason ? `Reason: ${reason}.` : undefined,
|
|
136
|
+
];
|
|
137
|
+
return { content: [{ type: "text", text: lines.filter(Boolean).join("\n") }], details: undefined };
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/extensions/cron/tools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAIN,kBAAkB,EAClB,kBAAkB,GAClB,MAAM,gBAAgB,CAAC;AAExB,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC;AACnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,CAAC;AAC/C,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC;AACnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC;AACnD,MAAM,CAAC,MAAM,eAAe,GAAG;IAC9B,qBAAqB;IACrB,mBAAmB;IACnB,qBAAqB;IACrB,qBAAqB;CACrB,CAAC;AASF,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CACnC;IACC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;QACjB,WAAW,EACV,6KAA6K;KAC9K,CAAC;IACF,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,uEAAuE,EAAE,CAAC;IAC7G,SAAS,EAAE,IAAI,CAAC,QAAQ,CACvB,IAAI,CAAC,OAAO,CAAC;QACZ,WAAW,EAAE,8FAA8F;KAC3G,CAAC,CACF;IACD,OAAO,EAAE,IAAI,CAAC,QAAQ,CACrB,IAAI,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,gEAAgE,EAAE,CAAC,CAC/F;CACD,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAC/B,CAAC;AAEF,MA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SAAS;gBACjF,kBAAkB,EAAE,QAAQ,SAAS,CAAC,YAAY,KAAK;gBACvD,SAAS,CAAC,OAAO;oBAChB,CAAC,CAAC,aAAa,MAAM,CAAC,YAAY,yBAAyB,kBAAkB,KAAK,kBAAkB,YAAY;oBAChH,CAAC,CAAC,SAAS;gBACZ,MAAM,CAAC,CAAC,CAAC,WAAW,MAAM,GAAG,CAAC,CAAC,CAAC,SAAS;aACzC,CAAC;YACF,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;QACpG,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * The scheduling tools: `cron_create`, `cron_list`, and `cron_delete` manage session-only cron jobs;\n * `loop_wakeup` sets the next tick of a self-paced loop.\n */\n\nimport { Type } from \"typebox\";\nimport type { ToolDefinition } from \"../../core/extensions/types.ts\";\nimport {\n\ttype CronJob,\n\ttype CronScheduler,\n\ttype LoopWakeup,\n\tWAKEUP_MAX_SECONDS,\n\tWAKEUP_MIN_SECONDS,\n} from \"./scheduler.ts\";\n\nexport const CRON_CREATE_TOOL_NAME = \"cron_create\";\nexport const CRON_LIST_TOOL_NAME = \"cron_list\";\nexport const CRON_DELETE_TOOL_NAME = \"cron_delete\";\nexport const LOOP_WAKEUP_TOOL_NAME = \"loop_wakeup\";\nexport const CRON_TOOL_NAMES = [\n\tCRON_CREATE_TOOL_NAME,\n\tCRON_LIST_TOOL_NAME,\n\tCRON_DELETE_TOOL_NAME,\n\tLOOP_WAKEUP_TOOL_NAME,\n];\n\n/** Same-host access to the scheduler and its settings. */\nexport interface CronToolHost {\n\tscheduler: CronScheduler;\n\t/** How long recurring jobs live, in ms; 0 for no limit. */\n\tmaxAgeMs(): number;\n}\n\nconst cronCreateSchema = Type.Object(\n\t{\n\t\tcron: Type.String({\n\t\t\tdescription:\n\t\t\t\t'Five-field cron expression in local time: \"minute hour day-of-month month day-of-week\", e.g. \"*/5 * * * *\" for every 5 minutes or \"30 14 25 12 *\" for 14:30 on 25 December.',\n\t\t}),\n\t\tprompt: Type.String({ description: \"The prompt to run at each fire. A slash command runs as that command.\" }),\n\t\trecurring: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"true (default): fire at every match until deleted or expired. false: fire once, then delete.\",\n\t\t\t}),\n\t\t),\n\t\tdurable: Type.Optional(\n\t\t\tType.Boolean({ description: \"Persist across restarts. Not supported in standalone sessions.\" }),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nconst CRON_CREATE_DESCRIPTION = `Schedule a prompt to run later in this session, once or on a recurring cron schedule. Times are local.\n\n- For a one-shot reminder (\"in 20 minutes\", \"at 3pm\"), pin minute, hour, day of month, and month to the target time and set recurring to false.\n- For recurring work use a recurring job; it expires after the configured limit (7 days by default) and fires one last time then.\n- Prefer minutes other than :00 and :30 when the exact minute does not matter, so jobs do not all fire at once. Recurring jobs fire up to 10% of their period late (at most 15 minutes); one-shots on :00 or :30 up to 90 seconds early.\n- Jobs fire only while Diffra is idle, each as its own turn, and end with the session. Use durable only when the user explicitly asks for persistence.\n- At most 50 jobs.`;\n\n/** `cron_create`: validate and add a job. */\nexport function createCronCreateToolDefinition(host: CronToolHost): ToolDefinition<typeof cronCreateSchema> {\n\treturn {\n\t\tname: CRON_CREATE_TOOL_NAME,\n\t\tlabel: \"CronCreate\",\n\t\tdescription: CRON_CREATE_DESCRIPTION,\n\t\tparameters: cronCreateSchema,\n\t\tasync execute(_toolCallId, params) {\n\t\t\tif (params.durable)\n\t\t\t\tthrow new Error(\"Error creating cron job: Durable cron jobs are not supported in standalone sessions.\");\n\t\t\tconst recurring = params.recurring !== false;\n\t\t\tconst created = host.scheduler.create(\n\t\t\t\t{ cron: params.cron, prompt: params.prompt, recurring },\n\t\t\t\tDate.now(),\n\t\t\t\thost.maxAgeMs(),\n\t\t\t);\n\t\t\tif (created.kind === \"error\") throw new Error(`Error creating cron job: ${created.message}`);\n\t\t\tconst where = \"Session-only (not written to disk, ends when the session ends).\";\n\t\t\tconst text = recurring\n\t\t\t\t? `Scheduled recurring job ${created.job.id} (${created.job.cron}). ${where} ${expiryText(host.maxAgeMs())}`\n\t\t\t\t: `Scheduled one-shot task ${created.job.id} (${created.job.cron}). ${where} It will fire once then auto-delete.`;\n\t\t\treturn { content: [{ type: \"text\", text }], details: undefined };\n\t\t},\n\t};\n}\n\n/** How long recurring jobs live, in words. */\nexport function expiryText(maxAgeMs: number): string {\n\tif (maxAgeMs <= 0) return \"Never auto-expires. Use cron_delete to cancel it.\";\n\tconst days = maxAgeMs / 86_400_000;\n\treturn `Auto-expires after ${days} ${days === 1 ? \"day\" : \"days\"}. Use cron_delete to cancel sooner.`;\n}\n\nconst cronListSchema = Type.Object({});\n\n/** `cron_list`: one line per job and the pending wakeup. */\nexport function createCronListToolDefinition(host: CronToolHost): ToolDefinition<typeof cronListSchema> {\n\treturn {\n\t\tname: CRON_LIST_TOOL_NAME,\n\t\tlabel: \"CronList\",\n\t\tdescription: \"List the scheduled cron jobs and the pending loop wakeup of this session.\",\n\t\tparameters: cronListSchema,\n\t\tannotations: { readOnlyHint: true },\n\t\tasync execute() {\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: listText(host.scheduler.jobList(), host.scheduler.pendingWakeup()) }],\n\t\t\t\tdetails: undefined,\n\t\t\t};\n\t\t},\n\t};\n}\n\n/** Lines of `id — schedule (type) [session-only]: prompt`. */\nexport function listText(jobs: readonly CronJob[], wakeup: LoopWakeup | undefined): string {\n\tconst lines = jobs.map(\n\t\t(job) => `${job.id} — ${job.cron} (${job.recurring ? \"recurring\" : \"one-shot\"}) [session-only]: ${job.prompt}`,\n\t);\n\tif (wakeup) {\n\t\tconst prompt = wakeup.prompt.length > 60 ? `${wakeup.prompt.slice(0, 57)}...` : wakeup.prompt;\n\t\tlines.push(\n\t\t\t`${wakeup.id} — wakeup at ${new Date(wakeup.fireAt).toLocaleString()} (one-shot) [session-only]: ${prompt}`,\n\t\t);\n\t}\n\treturn lines.length > 0 ? lines.join(\"\\n\") : \"No active cron jobs or loop wakeups.\";\n}\n\nconst cronDeleteSchema = Type.Object({ id: Type.String({ description: \"Id of the job or loop wakeup to cancel.\" }) });\n\n/** `cron_delete`: cancel a job or the pending wakeup. */\nexport function createCronDeleteToolDefinition(host: CronToolHost): ToolDefinition<typeof cronDeleteSchema> {\n\treturn {\n\t\tname: CRON_DELETE_TOOL_NAME,\n\t\tlabel: \"CronDelete\",\n\t\tdescription: \"Cancel a cron job or the pending loop wakeup by id.\",\n\t\tparameters: cronDeleteSchema,\n\t\tasync execute(_toolCallId, params) {\n\t\t\tif (!host.scheduler.delete(params.id)) throw new Error(`Job ${params.id} not found.`);\n\t\t\treturn { content: [{ type: \"text\", text: `Cancelled job ${params.id}.` }], details: undefined };\n\t\t},\n\t};\n}\n\nconst loopWakeupSchema = Type.Object({\n\tdelaySeconds: Type.Number({\n\t\tdescription: `Seconds from now, clamped to ${WAKEUP_MIN_SECONDS}-${WAKEUP_MAX_SECONDS}. Use 60-270 only when polling something nothing else reports (a CI run, a remote queue). When a background agent will notify you when it finishes, use 1200-1800 as a fallback in case it never does. Without a specific signal, use 1200 or more.`,\n\t}),\n\tprompt: Type.String({\n\t\tmaxLength: 10_000,\n\t\tdescription:\n\t\t\t\"The prompt of the next tick. Start it with /loop to continue the loop, e.g. `/loop check the deploy`.\",\n\t}),\n\treason: Type.Optional(Type.String({ description: \"Why this delay, in a few words.\" })),\n});\n\nconst LOOP_WAKEUP_DESCRIPTION =\n\t\"Schedule the next tick of a self-paced loop (always pass prompt). Call it before ending the turn to keep the loop going; leave it out to end the loop. One-shot and session-only; a new call replaces the pending wakeup, and a chain of wakeups may run for at most 24 hours. When a background agent will notify you when it finishes, keep the wakeup as a long fallback rather than a short poll.\";\n\n/** `loop_wakeup`: set the next tick of a self-paced loop. */\nexport function createLoopWakeupToolDefinition(host: CronToolHost): ToolDefinition<typeof loopWakeupSchema> {\n\treturn {\n\t\tname: LOOP_WAKEUP_TOOL_NAME,\n\t\tlabel: \"LoopWakeup\",\n\t\tdescription: LOOP_WAKEUP_DESCRIPTION,\n\t\tparameters: loopWakeupSchema,\n\t\tasync execute(_toolCallId, params) {\n\t\t\tconst reason = params.reason?.trim();\n\t\t\tconst scheduled = host.scheduler.scheduleWakeup(params.delaySeconds, params.prompt, reason, Date.now());\n\t\t\tif (scheduled.kind === \"error\") throw new Error(`Error scheduling loop wakeup: ${scheduled.message}`);\n\t\t\tconst at = new Date(scheduled.wakeup.fireAt).toLocaleString();\n\t\t\tconst lines = [\n\t\t\t\t`Scheduled loop wakeup ${scheduled.wakeup.id}.`,\n\t\t\t\tscheduled.replaced ? `Replaced pending wakeup ${scheduled.replaced}.` : undefined,\n\t\t\t\t`Scheduled for: ${at} (in ${scheduled.delaySeconds}s).`,\n\t\t\t\tscheduled.clamped\n\t\t\t\t\t? `Requested ${params.delaySeconds}s was clamped to the [${WAKEUP_MIN_SECONDS}, ${WAKEUP_MAX_SECONDS}] s range.`\n\t\t\t\t\t: undefined,\n\t\t\t\treason ? `Reason: ${reason}.` : undefined,\n\t\t\t];\n\t\t\treturn { content: [{ type: \"text\", text: lines.filter(Boolean).join(\"\\n\") }], details: undefined };\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Goal evidence: what the verifier may read. The records of the Goal's turns on the session branch,
|
|
3
|
+
* newest first, each capped in size: user messages, the agent's visible replies, and tool results.
|
|
4
|
+
*/
|
|
5
|
+
import type { SessionEntry } from "../../core/session-manager.ts";
|
|
6
|
+
/** How far a record can prove something. */
|
|
7
|
+
export type ProofKind = "user_input" | "delivered_output" | "execution_output" | "external_fact";
|
|
8
|
+
/** One record of evidence. A type alias so it serializes as JSON. */
|
|
9
|
+
export type EvidenceRecord = {
|
|
10
|
+
uuid: string;
|
|
11
|
+
provenance: string;
|
|
12
|
+
turnId: string;
|
|
13
|
+
proofKind: ProofKind;
|
|
14
|
+
content: string;
|
|
15
|
+
};
|
|
16
|
+
/** Custom message type of the runtime's continuation prompts. */
|
|
17
|
+
export declare const GOAL_CONTINUATION_TYPE = "goal-continuation";
|
|
18
|
+
/** The Goal's records, oldest first; undefined when `evidenceAfter` is no longer on the branch. */
|
|
19
|
+
export declare function collectEvidence(branch: readonly SessionEntry[], evidenceAfter: string | null): EvidenceRecord[] | undefined;
|
|
20
|
+
//# sourceMappingURL=evidence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evidence.d.ts","sourceRoot":"","sources":["../../../src/extensions/goals/evidence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE,4CAA4C;AAC5C,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,kBAAkB,GAAG,kBAAkB,GAAG,eAAe,CAAC;AAEjG,qEAAqE;AACrE,MAAM,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,iEAAiE;AACjE,eAAO,MAAM,sBAAsB,sBAAsB,CAAC;AAU1D,mGAAmG;AACnG,wBAAgB,eAAe,CAC9B,MAAM,EAAE,SAAS,YAAY,EAAE,EAC/B,aAAa,EAAE,MAAM,GAAG,IAAI,GAC1B,cAAc,EAAE,GAAG,SAAS,CA8C9B"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Goal evidence: what the verifier may read. The records of the Goal's turns on the session branch,
|
|
3
|
+
* newest first, each capped in size: user messages, the agent's visible replies, and tool results.
|
|
4
|
+
*/
|
|
5
|
+
/** Custom message type of the runtime's continuation prompts. */
|
|
6
|
+
export const GOAL_CONTINUATION_TYPE = "goal-continuation";
|
|
7
|
+
const GOAL_TOOL_NAMES = new Set(["get_goal", "update_goal"]);
|
|
8
|
+
/** Tools that relay other output (subagents, code-mode scripts): they cannot attest facts themselves. */
|
|
9
|
+
const RELAY_TOOL_NAMES = new Set(["agent", "codemode"]);
|
|
10
|
+
const MAX_RECORD_BYTES = 8_000;
|
|
11
|
+
const RECORD_HEAD_BYTES = 3_000;
|
|
12
|
+
const MAX_ARGUMENT_CHARS = 1_000;
|
|
13
|
+
/** The Goal's records, oldest first; undefined when `evidenceAfter` is no longer on the branch. */
|
|
14
|
+
export function collectEvidence(branch, evidenceAfter) {
|
|
15
|
+
const start = evidenceAfter === null ? 0 : branch.findIndex((entry) => entry.id === evidenceAfter) + 1;
|
|
16
|
+
if (start === 0 && evidenceAfter !== null)
|
|
17
|
+
return undefined;
|
|
18
|
+
const records = [];
|
|
19
|
+
const toolArguments = new Map();
|
|
20
|
+
let turn = 0;
|
|
21
|
+
const add = (entry, provenance, proofKind, content) => {
|
|
22
|
+
if (content.trim() === "")
|
|
23
|
+
return;
|
|
24
|
+
records.push({
|
|
25
|
+
uuid: entry.id,
|
|
26
|
+
provenance,
|
|
27
|
+
turnId: `turn-${Math.max(turn, 1)}`,
|
|
28
|
+
proofKind,
|
|
29
|
+
content: capRecord(content),
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
for (const entry of branch.slice(start)) {
|
|
33
|
+
if (entry.type === "custom_message" && entry.customType === GOAL_CONTINUATION_TYPE)
|
|
34
|
+
turn++;
|
|
35
|
+
if (entry.type !== "message")
|
|
36
|
+
continue;
|
|
37
|
+
const message = entry.message;
|
|
38
|
+
switch (message.role) {
|
|
39
|
+
case "user":
|
|
40
|
+
turn++;
|
|
41
|
+
add(entry, "user_message", "user_input", textOf(message.content));
|
|
42
|
+
break;
|
|
43
|
+
case "assistant":
|
|
44
|
+
for (const part of message.content) {
|
|
45
|
+
if (part.type === "toolCall")
|
|
46
|
+
toolArguments.set(part.id, JSON.stringify(part.arguments));
|
|
47
|
+
}
|
|
48
|
+
add(entry, "assistant_output", "delivered_output", textOf(message.content));
|
|
49
|
+
break;
|
|
50
|
+
case "toolResult": {
|
|
51
|
+
if (GOAL_TOOL_NAMES.has(message.toolName))
|
|
52
|
+
break;
|
|
53
|
+
const args = (toolArguments.get(message.toolCallId) ?? "{}").slice(0, MAX_ARGUMENT_CHARS);
|
|
54
|
+
const header = `${message.toolName} ${args}${message.isError ? " (error)" : ""}`;
|
|
55
|
+
add(entry, `tool_result:${message.toolName}`, RELAY_TOOL_NAMES.has(message.toolName) ? "execution_output" : "external_fact", `${header}\n${textOf(message.content)}`);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return records;
|
|
61
|
+
}
|
|
62
|
+
/** Text parts of message content; images and thinking are left out. */
|
|
63
|
+
function textOf(content) {
|
|
64
|
+
if (typeof content === "string")
|
|
65
|
+
return content;
|
|
66
|
+
return content.flatMap((part) => (part.type === "text" && part.text ? [part.text] : [])).join("\n");
|
|
67
|
+
}
|
|
68
|
+
/** Records over 8,000 bytes keep their first 3,000 bytes and their end, with a marker between. */
|
|
69
|
+
function capRecord(text) {
|
|
70
|
+
const bytes = Buffer.from(text, "utf-8");
|
|
71
|
+
if (bytes.length <= MAX_RECORD_BYTES)
|
|
72
|
+
return text;
|
|
73
|
+
const marker = `\n[... ${bytes.length - MAX_RECORD_BYTES} bytes omitted ...]\n`;
|
|
74
|
+
const tail = MAX_RECORD_BYTES - RECORD_HEAD_BYTES - Buffer.byteLength(marker);
|
|
75
|
+
return `${bytes.subarray(0, RECORD_HEAD_BYTES).toString("utf-8")}${marker}${bytes.subarray(bytes.length - tail).toString("utf-8")}`;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=evidence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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iB,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;AACrI,CAAC","sourcesContent":["/**\n * Goal evidence: what the verifier may read. The records of the Goal's turns on the session branch,\n * newest first, each capped in size: user messages, the agent's visible replies, and tool results.\n */\n\nimport type { SessionEntry } from \"../../core/session-manager.ts\";\n\n/** How far a record can prove something. */\nexport type ProofKind = \"user_input\" | \"delivered_output\" | \"execution_output\" | \"external_fact\";\n\n/** One record of evidence. A type alias so it serializes as JSON. */\nexport type EvidenceRecord = {\n\tuuid: string;\n\tprovenance: string;\n\tturnId: string;\n\tproofKind: ProofKind;\n\tcontent: string;\n};\n\n/** Custom message type of the runtime's continuation prompts. */\nexport const GOAL_CONTINUATION_TYPE = \"goal-continuation\";\n\nconst GOAL_TOOL_NAMES = new Set([\"get_goal\", \"update_goal\"]);\n/** Tools that relay other output (subagents, code-mode scripts): they cannot attest facts themselves. */\nconst RELAY_TOOL_NAMES = new Set([\"agent\", \"codemode\"]);\n\nconst MAX_RECORD_BYTES = 8_000;\nconst RECORD_HEAD_BYTES = 3_000;\nconst MAX_ARGUMENT_CHARS = 1_000;\n\n/** The Goal's records, oldest first; undefined when `evidenceAfter` is no longer on the branch. */\nexport function collectEvidence(\n\tbranch: readonly SessionEntry[],\n\tevidenceAfter: string | null,\n): EvidenceRecord[] | undefined {\n\tconst start = evidenceAfter === null ? 0 : branch.findIndex((entry) => entry.id === evidenceAfter) + 1;\n\tif (start === 0 && evidenceAfter !== null) return undefined;\n\tconst records: EvidenceRecord[] = [];\n\tconst toolArguments = new Map<string, string>();\n\tlet turn = 0;\n\tconst add = (entry: SessionEntry, provenance: string, proofKind: ProofKind, content: string) => {\n\t\tif (content.trim() === \"\") return;\n\t\trecords.push({\n\t\t\tuuid: entry.id,\n\t\t\tprovenance,\n\t\t\tturnId: `turn-${Math.max(turn, 1)}`,\n\t\t\tproofKind,\n\t\t\tcontent: capRecord(content),\n\t\t});\n\t};\n\tfor (const entry of branch.slice(start)) {\n\t\tif (entry.type === \"custom_message\" && entry.customType === GOAL_CONTINUATION_TYPE) turn++;\n\t\tif (entry.type !== \"message\") continue;\n\t\tconst message = entry.message;\n\t\tswitch (message.role) {\n\t\t\tcase \"user\":\n\t\t\t\tturn++;\n\t\t\t\tadd(entry, \"user_message\", \"user_input\", textOf(message.content));\n\t\t\t\tbreak;\n\t\t\tcase \"assistant\":\n\t\t\t\tfor (const part of message.content) {\n\t\t\t\t\tif (part.type === \"toolCall\") toolArguments.set(part.id, JSON.stringify(part.arguments));\n\t\t\t\t}\n\t\t\t\tadd(entry, \"assistant_output\", \"delivered_output\", textOf(message.content));\n\t\t\t\tbreak;\n\t\t\tcase \"toolResult\": {\n\t\t\t\tif (GOAL_TOOL_NAMES.has(message.toolName)) break;\n\t\t\t\tconst args = (toolArguments.get(message.toolCallId) ?? \"{}\").slice(0, MAX_ARGUMENT_CHARS);\n\t\t\t\tconst header = `${message.toolName} ${args}${message.isError ? \" (error)\" : \"\"}`;\n\t\t\t\tadd(\n\t\t\t\t\tentry,\n\t\t\t\t\t`tool_result:${message.toolName}`,\n\t\t\t\t\tRELAY_TOOL_NAMES.has(message.toolName) ? \"execution_output\" : \"external_fact\",\n\t\t\t\t\t`${header}\\n${textOf(message.content)}`,\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\treturn records;\n}\n\n/** Text parts of message content; images and thinking are left out. */\nfunction textOf(content: string | ReadonlyArray<{ type: string; text?: string }>): string {\n\tif (typeof content === \"string\") return content;\n\treturn content.flatMap((part) => (part.type === \"text\" && part.text ? [part.text] : [])).join(\"\\n\");\n}\n\n/** Records over 8,000 bytes keep their first 3,000 bytes and their end, with a marker between. */\nfunction capRecord(text: string): string {\n\tconst bytes = Buffer.from(text, \"utf-8\");\n\tif (bytes.length <= MAX_RECORD_BYTES) return text;\n\tconst marker = `\\n[... ${bytes.length - MAX_RECORD_BYTES} bytes omitted ...]\\n`;\n\tconst tail = MAX_RECORD_BYTES - RECORD_HEAD_BYTES - Buffer.byteLength(marker);\n\treturn `${bytes.subarray(0, RECORD_HEAD_BYTES).toString(\"utf-8\")}${marker}${bytes.subarray(bytes.length - tail).toString(\"utf-8\")}`;\n}\n"]}
|