@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,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The texts of auto-memory: the policy and catalog in the system prompt, the background extractor's
|
|
3
|
+
* and dreamer's instructions, the recall block, and the `/remember` request.
|
|
4
|
+
*/
|
|
5
|
+
const MEMORY_FORMAT = `---
|
|
6
|
+
name: short title
|
|
7
|
+
description: one specific line that says when this memory is relevant
|
|
8
|
+
type: user | feedback | project | reference
|
|
9
|
+
keywords: ["2-6", "search terms"]
|
|
10
|
+
---
|
|
11
|
+
The rule or fact first. For feedback and project memories, then:
|
|
12
|
+
**Why:** the reason the user gave
|
|
13
|
+
**How to apply:** when and how to use it`;
|
|
14
|
+
const TYPE_GUIDE = `- user: who the user is (role, expertise, preferences). Always in USER memory.
|
|
15
|
+
- feedback: how the user wants you to work, corrections and confirmed approaches. USER memory by default; PROJECT memory only for a convention of this project.
|
|
16
|
+
- project: ongoing work, goals, decisions, and constraints of this project that the code does not show. Always PROJECT memory; turn relative dates into absolute ones.
|
|
17
|
+
- reference: pointers to external resources (URLs, dashboards, tickets). PROJECT memory by default; USER memory for the user's own resources.`;
|
|
18
|
+
const EXCLUSIONS = `Do not save, not even when asked: code patterns, architecture, or file paths the code shows; git history; fix recipes; tool schemas; anything already in AGENTS.md; ephemeral task state. When asked to save one of these, ask what was surprising or non-obvious about it and save that instead.`;
|
|
19
|
+
/** The memory policy added to the system prompt, with the current indexes as data. */
|
|
20
|
+
export function residentPrompt(roots, userIndex, projectIndex) {
|
|
21
|
+
return `# auto memory
|
|
22
|
+
|
|
23
|
+
You have a persistent, file-based memory. Its directories already exist; write to them directly with the write and edit tools, without creating directories.
|
|
24
|
+
- USER memory (all projects): ${roots.user}
|
|
25
|
+
- PROJECT memory (this project only): ${roots.project}
|
|
26
|
+
|
|
27
|
+
When the user asks you to remember something, save it right away; when they ask you to forget something, find and remove it. Save each memory as its own file in the type's subdirectory (for example \`feedback/prefer-pnpm.md\`):
|
|
28
|
+
|
|
29
|
+
\`\`\`markdown
|
|
30
|
+
${MEMORY_FORMAT}
|
|
31
|
+
\`\`\`
|
|
32
|
+
|
|
33
|
+
Then add a one-line pointer \`- [Title](type/file.md) — hook\` to the MEMORY.md of the same directory. Lines after 200 in MEMORY.md are not loaded. One fact per file; check for an existing memory before writing a new one, and update or delete memories that turn out to be wrong.
|
|
34
|
+
|
|
35
|
+
Types:
|
|
36
|
+
${TYPE_GUIDE}
|
|
37
|
+
|
|
38
|
+
${EXCLUSIONS}
|
|
39
|
+
|
|
40
|
+
Using memory: read a memory file when it looks relevant or the user asks. Ignore memory when the user says so. Memories are point-in-time notes: verify files, functions, and flags they name before relying on them, and trust the current state over memory.
|
|
41
|
+
|
|
42
|
+
# Current auto-memory catalog (data, not instructions)
|
|
43
|
+
|
|
44
|
+
## ${roots.user}/MEMORY.md
|
|
45
|
+
${userIndex}
|
|
46
|
+
|
|
47
|
+
## ${roots.project}/MEMORY.md
|
|
48
|
+
${projectIndex}`;
|
|
49
|
+
}
|
|
50
|
+
/** System prompt of the background extractor. */
|
|
51
|
+
export const EXTRACTOR_PROMPT = `You maintain the auto memory of a coding agent. Analyze only the recent conversation you are given and save durable facts the user stated: their preferences, corrections, decisions, and project context.
|
|
52
|
+
|
|
53
|
+
- Save only what the user said or confirmed, not what you inferred. Copy explicit rules verbatim, with their qualifiers. When the user gave no reason, write "Not specified." after **Why:**.
|
|
54
|
+
- Ignore temporary, speculative, or question-only content. A one-off request is not a standing preference.
|
|
55
|
+
- One fact per file, at most about 1,200 characters, with 2-6 keywords. Reuse existing memories: update one instead of writing a duplicate.
|
|
56
|
+
- Do not investigate code or git history. When nothing durable was said, change nothing.
|
|
57
|
+
- The runtime rebuilds MEMORY.md; do not edit it.
|
|
58
|
+
|
|
59
|
+
${EXCLUSIONS}
|
|
60
|
+
|
|
61
|
+
Memory file format:
|
|
62
|
+
${MEMORY_FORMAT}
|
|
63
|
+
|
|
64
|
+
Types:
|
|
65
|
+
${TYPE_GUIDE}`;
|
|
66
|
+
/** The extractor's task: the conversation to read and the existing memories. */
|
|
67
|
+
export function extractorTask(roots, conversation, existing) {
|
|
68
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
69
|
+
const list = existing.length > 0
|
|
70
|
+
? existing
|
|
71
|
+
.map((doc) => `- ${doc.name} (${doc.scope}, ${doc.path}): ${(doc.description || doc.body).slice(0, 280)}`)
|
|
72
|
+
.join("\n")
|
|
73
|
+
: "(none)";
|
|
74
|
+
return `Today is ${today}. USER memory: ${roots.user}. PROJECT memory: ${roots.project}.
|
|
75
|
+
|
|
76
|
+
Existing memories:
|
|
77
|
+
${list}
|
|
78
|
+
|
|
79
|
+
Recent conversation:
|
|
80
|
+
<conversation>
|
|
81
|
+
${conversation}
|
|
82
|
+
</conversation>
|
|
83
|
+
|
|
84
|
+
Read what you need in parallel, then write in parallel. Stop when done.`;
|
|
85
|
+
}
|
|
86
|
+
/** Instructions of a consolidation run ("dream"). */
|
|
87
|
+
export function dreamPrompt(roots) {
|
|
88
|
+
return `Consolidate the auto memory in ${roots.user} and ${roots.project}.
|
|
89
|
+
|
|
90
|
+
1. Orient: list the directories and read MEMORY.md and the memory files.
|
|
91
|
+
2. Consolidate: merge duplicates, fix stale or contradicted facts, turn relative dates into absolute ones, fill in missing descriptions and keywords, shorten memories over about 1,200 characters, and split ones that hold several facts.
|
|
92
|
+
3. Prune: list memory files that are wrong or superseded in \`.dream-operations.json\` in their memory directory, as \`{"version": 1, "delete": ["type/file.md"]}\`; the runtime deletes them.
|
|
93
|
+
|
|
94
|
+
Keep the memory file format:
|
|
95
|
+
${MEMORY_FORMAT}
|
|
96
|
+
|
|
97
|
+
The runtime rebuilds MEMORY.md afterwards; do not edit it. Report briefly what you changed.`;
|
|
98
|
+
}
|
|
99
|
+
/** The request `/remember` sends to the agent. */
|
|
100
|
+
export function rememberRequest(roots, text) {
|
|
101
|
+
return `Please save the following to your memory system. Choose the destination directory by the type's scope: USER memory at ${roots.user} for cross-project facts, PROJECT memory at ${roots.project} for this-project-only facts. Choose the most appropriate memory type (user, feedback, project, or reference) based on the content:
|
|
102
|
+
|
|
103
|
+
${text}`;
|
|
104
|
+
}
|
|
105
|
+
/** The recall block added before a prompt: memories that look relevant to it. */
|
|
106
|
+
export function recallBlock(docs, now = Date.now()) {
|
|
107
|
+
const sections = docs.map((doc) => {
|
|
108
|
+
const days = Math.floor((now - doc.modifiedAt) / 86_400_000);
|
|
109
|
+
const age = days <= 0 ? "today" : days === 1 ? "yesterday" : `${days} days ago`;
|
|
110
|
+
const body = doc.body.length > 1200
|
|
111
|
+
? `${doc.body.slice(0, 1200)}\n> NOTE: Relevant memory truncated for prompt budget.`
|
|
112
|
+
: doc.body;
|
|
113
|
+
const stale = days > 1
|
|
114
|
+
? `\n> This memory is ${days} days old. Memories are point-in-time observations, not live state. Verify against current code before asserting as fact.`
|
|
115
|
+
: "";
|
|
116
|
+
return `### ${doc.name} (${doc.relativePath})\nSaved ${age}.${doc.description ? `\n${doc.description}` : ""}\n\n${body}${stale}`;
|
|
117
|
+
});
|
|
118
|
+
return `## Relevant memory
|
|
119
|
+
|
|
120
|
+
Use the following memories only when they are directly relevant to the current request. Verify file and function claims before relying on them.
|
|
121
|
+
|
|
122
|
+
${sections.join("\n\n")}`;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/extensions/memory/prompts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,aAAa,GAAG;;;;;;;;yCAQmB,CAAC;AAE1C,MAAM,UAAU,GAAG;;;8IAG2H,CAAC;AAE/I,MAAM,UAAU,GAAG,mSAAmS,CAAC;AAEvT,sFAAsF;AACtF,MAAM,UAAU,cAAc,CAAC,KAAkB,EAAE,SAAiB,EAAE,YAAoB;IACzF,OAAO;;;gCAGwB,KAAK,CAAC,IAAI;wCACF,KAAK,CAAC,OAAO;;;;;EAKnD,aAAa;;;;;;EAMb,UAAU;;EAEV,UAAU;;;;;;KAMP,KAAK,CAAC,IAAI;EACb,SAAS;;KAEN,KAAK,CAAC,OAAO;EAChB,YAAY,EAAE,CAAC;AACjB,CAAC;AAED,iDAAiD;AACjD,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;EAQ9B,UAAU;;;EAGV,aAAa;;;EAGb,UAAU,EAAE,CAAC;AAEf,gFAAgF;AAChF,MAAM,UAAU,aAAa,CAAC,KAAkB,EAAE,YAAoB,EAAE,QAA8B;IACrG,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACpD,MAAM,IAAI,GACT,QAAQ,CA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AAG,IAAI,WAAW,CAAC;QAChF,MAAM,IAAI,GACT,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI;YACrB,CAAC,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,wDAAwD;YACpF,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;QACb,MAAM,KAAK,GACV,IAAI,GAAG,CAAC;YACP,CAAC,CAAC,sBAAsB,IAAI,2HAA2H;YACvJ,CAAC,CAAC,EAAE,CAAC;QACP,OAAO,OAAO,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,YAAY,YAAY,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,GAAG,KAAK,EAAE,CAAC;IAClI,CAAC,CAAC,CAAC;IACH,OAAO;;;;EAIN,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;AAC1B,CAAC","sourcesContent":["/**\n * The texts of auto-memory: the policy and catalog in the system prompt, the background extractor's\n * and dreamer's instructions, the recall block, and the `/remember` request.\n */\n\nimport type { MemoryDoc, MemoryRoots } from \"./store.ts\";\n\nconst MEMORY_FORMAT = `---\nname: short title\ndescription: one specific line that says when this memory is relevant\ntype: user | feedback | project | reference\nkeywords: [\"2-6\", \"search terms\"]\n---\nThe rule or fact first. For feedback and project memories, then:\n**Why:** the reason the user gave\n**How to apply:** when and how to use it`;\n\nconst TYPE_GUIDE = `- user: who the user is (role, expertise, preferences). Always in USER memory.\n- feedback: how the user wants you to work, corrections and confirmed approaches. USER memory by default; PROJECT memory only for a convention of this project.\n- project: ongoing work, goals, decisions, and constraints of this project that the code does not show. Always PROJECT memory; turn relative dates into absolute ones.\n- reference: pointers to external resources (URLs, dashboards, tickets). PROJECT memory by default; USER memory for the user's own resources.`;\n\nconst EXCLUSIONS = `Do not save, not even when asked: code patterns, architecture, or file paths the code shows; git history; fix recipes; tool schemas; anything already in AGENTS.md; ephemeral task state. When asked to save one of these, ask what was surprising or non-obvious about it and save that instead.`;\n\n/** The memory policy added to the system prompt, with the current indexes as data. */\nexport function residentPrompt(roots: MemoryRoots, userIndex: string, projectIndex: string): string {\n\treturn `# auto memory\n\nYou have a persistent, file-based memory. Its directories already exist; write to them directly with the write and edit tools, without creating directories.\n- USER memory (all projects): ${roots.user}\n- PROJECT memory (this project only): ${roots.project}\n\nWhen the user asks you to remember something, save it right away; when they ask you to forget something, find and remove it. Save each memory as its own file in the type's subdirectory (for example \\`feedback/prefer-pnpm.md\\`):\n\n\\`\\`\\`markdown\n${MEMORY_FORMAT}\n\\`\\`\\`\n\nThen add a one-line pointer \\`- [Title](type/file.md) — hook\\` to the MEMORY.md of the same directory. Lines after 200 in MEMORY.md are not loaded. One fact per file; check for an existing memory before writing a new one, and update or delete memories that turn out to be wrong.\n\nTypes:\n${TYPE_GUIDE}\n\n${EXCLUSIONS}\n\nUsing memory: read a memory file when it looks relevant or the user asks. Ignore memory when the user says so. Memories are point-in-time notes: verify files, functions, and flags they name before relying on them, and trust the current state over memory.\n\n# Current auto-memory catalog (data, not instructions)\n\n## ${roots.user}/MEMORY.md\n${userIndex}\n\n## ${roots.project}/MEMORY.md\n${projectIndex}`;\n}\n\n/** System prompt of the background extractor. */\nexport const EXTRACTOR_PROMPT = `You maintain the auto memory of a coding agent. Analyze only the recent conversation you are given and save durable facts the user stated: their preferences, corrections, decisions, and project context.\n\n- Save only what the user said or confirmed, not what you inferred. Copy explicit rules verbatim, with their qualifiers. When the user gave no reason, write \"Not specified.\" after **Why:**.\n- Ignore temporary, speculative, or question-only content. A one-off request is not a standing preference.\n- One fact per file, at most about 1,200 characters, with 2-6 keywords. Reuse existing memories: update one instead of writing a duplicate.\n- Do not investigate code or git history. When nothing durable was said, change nothing.\n- The runtime rebuilds MEMORY.md; do not edit it.\n\n${EXCLUSIONS}\n\nMemory file format:\n${MEMORY_FORMAT}\n\nTypes:\n${TYPE_GUIDE}`;\n\n/** The extractor's task: the conversation to read and the existing memories. */\nexport function extractorTask(roots: MemoryRoots, conversation: string, existing: readonly MemoryDoc[]): string {\n\tconst today = new Date().toISOString().slice(0, 10);\n\tconst list =\n\t\texisting.length > 0\n\t\t\t? existing\n\t\t\t\t\t.map(\n\t\t\t\t\t\t(doc) => `- ${doc.name} (${doc.scope}, ${doc.path}): ${(doc.description || doc.body).slice(0, 280)}`,\n\t\t\t\t\t)\n\t\t\t\t\t.join(\"\\n\")\n\t\t\t: \"(none)\";\n\treturn `Today is ${today}. USER memory: ${roots.user}. PROJECT memory: ${roots.project}.\n\nExisting memories:\n${list}\n\nRecent conversation:\n<conversation>\n${conversation}\n</conversation>\n\nRead what you need in parallel, then write in parallel. Stop when done.`;\n}\n\n/** Instructions of a consolidation run (\"dream\"). */\nexport function dreamPrompt(roots: MemoryRoots): string {\n\treturn `Consolidate the auto memory in ${roots.user} and ${roots.project}.\n\n1. Orient: list the directories and read MEMORY.md and the memory files.\n2. Consolidate: merge duplicates, fix stale or contradicted facts, turn relative dates into absolute ones, fill in missing descriptions and keywords, shorten memories over about 1,200 characters, and split ones that hold several facts.\n3. Prune: list memory files that are wrong or superseded in \\`.dream-operations.json\\` in their memory directory, as \\`{\"version\": 1, \"delete\": [\"type/file.md\"]}\\`; the runtime deletes them.\n\nKeep the memory file format:\n${MEMORY_FORMAT}\n\nThe runtime rebuilds MEMORY.md afterwards; do not edit it. Report briefly what you changed.`;\n}\n\n/** The request `/remember` sends to the agent. */\nexport function rememberRequest(roots: MemoryRoots, text: string): string {\n\treturn `Please save the following to your memory system. Choose the destination directory by the type's scope: USER memory at ${roots.user} for cross-project facts, PROJECT memory at ${roots.project} for this-project-only facts. Choose the most appropriate memory type (user, feedback, project, or reference) based on the content:\n\n${text}`;\n}\n\n/** The recall block added before a prompt: memories that look relevant to it. */\nexport function recallBlock(docs: readonly MemoryDoc[], now = Date.now()): string {\n\tconst sections = docs.map((doc) => {\n\t\tconst days = Math.floor((now - doc.modifiedAt) / 86_400_000);\n\t\tconst age = days <= 0 ? \"today\" : days === 1 ? \"yesterday\" : `${days} days ago`;\n\t\tconst body =\n\t\t\tdoc.body.length > 1200\n\t\t\t\t? `${doc.body.slice(0, 1200)}\\n> NOTE: Relevant memory truncated for prompt budget.`\n\t\t\t\t: doc.body;\n\t\tconst stale =\n\t\t\tdays > 1\n\t\t\t\t? `\\n> This memory is ${days} days old. Memories are point-in-time observations, not live state. Verify against current code before asserting as fact.`\n\t\t\t\t: \"\";\n\t\treturn `### ${doc.name} (${doc.relativePath})\\nSaved ${age}.${doc.description ? `\\n${doc.description}` : \"\"}\\n\\n${body}${stale}`;\n\t});\n\treturn `## Relevant memory\n\nUse the following memories only when they are directly relevant to the current request. Verify file and function claims before relying on them.\n\n${sections.join(\"\\n\\n\")}`;\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recall: which memories to put before a prompt. A word match picks up to two at once; a model then
|
|
3
|
+
* picks up to five from the memories' titles, descriptions, and keywords.
|
|
4
|
+
*/
|
|
5
|
+
import type { Api, Model } from "@diffra-ai/ai";
|
|
6
|
+
import type { ModelRegistry } from "../../core/model-registry.ts";
|
|
7
|
+
import type { MemoryDoc } from "./store.ts";
|
|
8
|
+
/** Words of a text: Latin words of 3+ characters and pairs of CJK characters, lower-cased. */
|
|
9
|
+
export declare function tokenize(text: string): Set<string>;
|
|
10
|
+
/** Up to two memories sharing the most words with `query`; title, description, and keywords count double. */
|
|
11
|
+
export declare function fastRecall(query: string, docs: readonly MemoryDoc[], exclude: ReadonlySet<string>): MemoryDoc[];
|
|
12
|
+
/** Ask `model` which memories are clearly useful for `query`, from their metadata only. Never rejects. */
|
|
13
|
+
export declare function modelRecall(query: string, docs: readonly MemoryDoc[], model: Model<Api>, registry: ModelRegistry, signal: AbortSignal): Promise<MemoryDoc[]>;
|
|
14
|
+
//# sourceMappingURL=recall.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recall.d.ts","sourceRoot":"","sources":["../../../src/extensions/memory/recall.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,SAAS,EAAE,MAAM,YAAY,CAAC;AAO5C,8FAA8F;AAC9F,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAQlD;AAED,6GAA6G;AAC7G,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,SAAS,EAAE,EAAE,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,EAAE,CAe/G;AAED,0GAA0G;AAC1G,wBAAsB,WAAW,CAChC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,SAAS,SAAS,EAAE,EAC1B,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,WAAW,GACjB,OAAO,CAAC,SAAS,EAAE,CAAC,CAqCtB"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recall: which memories to put before a prompt. A word match picks up to two at once; a model then
|
|
3
|
+
* picks up to five from the memories' titles, descriptions, and keywords.
|
|
4
|
+
*/
|
|
5
|
+
import { uuidv7 } from "@diffra-ai/ai";
|
|
6
|
+
const MAX_FAST_RECALL = 2;
|
|
7
|
+
const MAX_MODEL_RECALL = 5;
|
|
8
|
+
const MAX_MANIFEST_CHARS = 25_000;
|
|
9
|
+
const MODEL_RECALL_TIMEOUT_MS = 30_000;
|
|
10
|
+
/** Words of a text: Latin words of 3+ characters and pairs of CJK characters, lower-cased. */
|
|
11
|
+
export function tokenize(text) {
|
|
12
|
+
const tokens = new Set();
|
|
13
|
+
for (const word of text.toLowerCase().match(/[a-z0-9_]{3,}/g) ?? [])
|
|
14
|
+
tokens.add(word);
|
|
15
|
+
for (const run of text.match(/[-ヿ㐀-鿿가-]+/g) ?? []) {
|
|
16
|
+
if (run.length === 1)
|
|
17
|
+
tokens.add(run);
|
|
18
|
+
for (let index = 0; index < run.length - 1; index++)
|
|
19
|
+
tokens.add(run.slice(index, index + 2));
|
|
20
|
+
}
|
|
21
|
+
return tokens;
|
|
22
|
+
}
|
|
23
|
+
/** Up to two memories sharing the most words with `query`; title, description, and keywords count double. */
|
|
24
|
+
export function fastRecall(query, docs, exclude) {
|
|
25
|
+
const words = tokenize(query);
|
|
26
|
+
if (words.size === 0)
|
|
27
|
+
return [];
|
|
28
|
+
const scored = docs
|
|
29
|
+
.filter((doc) => !exclude.has(doc.path))
|
|
30
|
+
.map((doc) => {
|
|
31
|
+
const head = tokenize(`${doc.name} ${doc.description} ${doc.keywords.join(" ")}`);
|
|
32
|
+
const body = tokenize(doc.body);
|
|
33
|
+
let score = 0;
|
|
34
|
+
for (const word of words)
|
|
35
|
+
score += head.has(word) ? 2 : body.has(word) ? 1 : 0;
|
|
36
|
+
return { doc, score };
|
|
37
|
+
})
|
|
38
|
+
.filter((entry) => entry.score >= 2)
|
|
39
|
+
.sort((a, b) => b.score - a.score || b.doc.modifiedAt - a.doc.modifiedAt);
|
|
40
|
+
return scored.slice(0, MAX_FAST_RECALL).map((entry) => entry.doc);
|
|
41
|
+
}
|
|
42
|
+
/** Ask `model` which memories are clearly useful for `query`, from their metadata only. Never rejects. */
|
|
43
|
+
export async function modelRecall(query, docs, model, registry, signal) {
|
|
44
|
+
if (docs.length === 0)
|
|
45
|
+
return [];
|
|
46
|
+
let manifest = "";
|
|
47
|
+
for (const doc of docs) {
|
|
48
|
+
const line = `- [${doc.type ?? "memory"}] ${doc.path} (${new Date(doc.modifiedAt).toISOString()}): ${doc.description}; keywords: ${doc.keywords.slice(0, 3).join(", ")}\n`;
|
|
49
|
+
if (manifest.length + line.length > MAX_MANIFEST_CHARS)
|
|
50
|
+
break;
|
|
51
|
+
manifest += line;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const response = await registry.complete(model, {
|
|
55
|
+
systemPrompt: `Select memories that are clearly useful for answering the user's request: up to ${MAX_MODEL_RECALL}, only when you are certain, possibly none. Reply with only {"selected_memories": ["absolute path", ...]}.`,
|
|
56
|
+
messages: [
|
|
57
|
+
{
|
|
58
|
+
role: "user",
|
|
59
|
+
content: [{ type: "text", text: `Request:\n${query}\n\nMemories:\n${manifest}` }],
|
|
60
|
+
timestamp: Date.now(),
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
}, {
|
|
64
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(MODEL_RECALL_TIMEOUT_MS)]),
|
|
65
|
+
cacheRetention: "none",
|
|
66
|
+
sessionId: uuidv7(),
|
|
67
|
+
});
|
|
68
|
+
const text = response.content
|
|
69
|
+
.filter((part) => part.type === "text")
|
|
70
|
+
.map((part) => part.text)
|
|
71
|
+
.join("");
|
|
72
|
+
const parsed = JSON.parse(/\{[\s\S]*\}/.exec(text)?.[0] ?? "{}");
|
|
73
|
+
const paths = Array.isArray(parsed.selected_memories) ? parsed.selected_memories : [];
|
|
74
|
+
return docs.filter((doc) => paths.includes(doc.path)).slice(0, MAX_MODEL_RECALL);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=recall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recall.js","sourceRoot":"","sources":["../../../src/extensions/memory/recall.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAIvC,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,kBAAkB,G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AG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC;QACtF,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;IAClF,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,EAAE,CAAC;IACX,CAAC;AACF,CAAC","sourcesContent":["/**\n * Recall: which memories to put before a prompt. A word match picks up to two at once; a model then\n * picks up to five from the memories' titles, descriptions, and keywords.\n */\n\nimport type { Api, Model } from \"@diffra-ai/ai\";\nimport { uuidv7 } from \"@diffra-ai/ai\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport type { MemoryDoc } from \"./store.ts\";\n\nconst MAX_FAST_RECALL = 2;\nconst MAX_MODEL_RECALL = 5;\nconst MAX_MANIFEST_CHARS = 25_000;\nconst MODEL_RECALL_TIMEOUT_MS = 30_000;\n\n/** Words of a text: Latin words of 3+ characters and pairs of CJK characters, lower-cased. */\nexport function tokenize(text: string): Set<string> {\n\tconst tokens = new Set<string>();\n\tfor (const word of text.toLowerCase().match(/[a-z0-9_]{3,}/g) ?? []) tokens.add(word);\n\tfor (const run of text.match(/[-ヿ㐀-鿿가-]+/g) ?? []) {\n\t\tif (run.length === 1) tokens.add(run);\n\t\tfor (let index = 0; index < run.length - 1; index++) tokens.add(run.slice(index, index + 2));\n\t}\n\treturn tokens;\n}\n\n/** Up to two memories sharing the most words with `query`; title, description, and keywords count double. */\nexport function fastRecall(query: string, docs: readonly MemoryDoc[], exclude: ReadonlySet<string>): MemoryDoc[] {\n\tconst words = tokenize(query);\n\tif (words.size === 0) return [];\n\tconst scored = docs\n\t\t.filter((doc) => !exclude.has(doc.path))\n\t\t.map((doc) => {\n\t\t\tconst head = tokenize(`${doc.name} ${doc.description} ${doc.keywords.join(\" \")}`);\n\t\t\tconst body = tokenize(doc.body);\n\t\t\tlet score = 0;\n\t\t\tfor (const word of words) score += head.has(word) ? 2 : body.has(word) ? 1 : 0;\n\t\t\treturn { doc, score };\n\t\t})\n\t\t.filter((entry) => entry.score >= 2)\n\t\t.sort((a, b) => b.score - a.score || b.doc.modifiedAt - a.doc.modifiedAt);\n\treturn scored.slice(0, MAX_FAST_RECALL).map((entry) => entry.doc);\n}\n\n/** Ask `model` which memories are clearly useful for `query`, from their metadata only. Never rejects. */\nexport async function modelRecall(\n\tquery: string,\n\tdocs: readonly MemoryDoc[],\n\tmodel: Model<Api>,\n\tregistry: ModelRegistry,\n\tsignal: AbortSignal,\n): Promise<MemoryDoc[]> {\n\tif (docs.length === 0) return [];\n\tlet manifest = \"\";\n\tfor (const doc of docs) {\n\t\tconst line = `- [${doc.type ?? \"memory\"}] ${doc.path} (${new Date(doc.modifiedAt).toISOString()}): ${doc.description}; keywords: ${doc.keywords.slice(0, 3).join(\", \")}\\n`;\n\t\tif (manifest.length + line.length > MAX_MANIFEST_CHARS) break;\n\t\tmanifest += line;\n\t}\n\ttry {\n\t\tconst response = await registry.complete(\n\t\t\tmodel,\n\t\t\t{\n\t\t\t\tsystemPrompt: `Select memories that are clearly useful for answering the user's request: up to ${MAX_MODEL_RECALL}, only when you are certain, possibly none. Reply with only {\"selected_memories\": [\"absolute path\", ...]}.`,\n\t\t\t\tmessages: [\n\t\t\t\t\t{\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: `Request:\\n${query}\\n\\nMemories:\\n${manifest}` }],\n\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tsignal: AbortSignal.any([signal, AbortSignal.timeout(MODEL_RECALL_TIMEOUT_MS)]),\n\t\t\t\tcacheRetention: \"none\",\n\t\t\t\tsessionId: uuidv7(),\n\t\t\t},\n\t\t);\n\t\tconst text = response.content\n\t\t\t.filter((part) => part.type === \"text\")\n\t\t\t.map((part) => part.text)\n\t\t\t.join(\"\");\n\t\tconst parsed = JSON.parse(/\\{[\\s\\S]*\\}/.exec(text)?.[0] ?? \"{}\") as { selected_memories?: unknown };\n\t\tconst paths = Array.isArray(parsed.selected_memories) ? parsed.selected_memories : [];\n\t\treturn docs.filter((doc) => paths.includes(doc.path)).slice(0, MAX_MODEL_RECALL);\n\t} catch {\n\t\treturn [];\n\t}\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The auto-memory store: a user memory directory shared by all projects and a project memory directory
|
|
3
|
+
* per git repository, each with one Markdown file per memory under `user/`, `feedback/`, `project/`,
|
|
4
|
+
* or `reference/`, and a `MEMORY.md` index rebuilt from those files.
|
|
5
|
+
*/
|
|
6
|
+
export declare const MEMORY_TYPES: readonly ["user", "feedback", "project", "reference"];
|
|
7
|
+
export type MemoryType = (typeof MEMORY_TYPES)[number];
|
|
8
|
+
export type MemoryScope = "user" | "project";
|
|
9
|
+
/** One memory file. */
|
|
10
|
+
export interface MemoryDoc {
|
|
11
|
+
scope: MemoryScope;
|
|
12
|
+
/** Absolute path. */
|
|
13
|
+
path: string;
|
|
14
|
+
/** Path relative to the scope's directory, as the index links it. */
|
|
15
|
+
relativePath: string;
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
type: MemoryType | undefined;
|
|
19
|
+
keywords: string[];
|
|
20
|
+
body: string;
|
|
21
|
+
modifiedAt: number;
|
|
22
|
+
}
|
|
23
|
+
export interface MemoryRoots {
|
|
24
|
+
user: string;
|
|
25
|
+
project: string;
|
|
26
|
+
}
|
|
27
|
+
export declare const INDEX_FILE = "MEMORY.md";
|
|
28
|
+
/**
|
|
29
|
+
* The memory directories: `<base>/memories/` for the user and `<base>/projects/<repo>/memory/` for the
|
|
30
|
+
* git repository around `cwd` (or `cwd` itself outside a repository). The base is the agent directory,
|
|
31
|
+
* or `DIFFRA_MEMORY_BASE_DIR`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function memoryRoots(cwd: string): MemoryRoots;
|
|
34
|
+
/** A directory name for a path: letters and digits kept, everything else `-`. */
|
|
35
|
+
export declare function sanitizePath(path: string): string;
|
|
36
|
+
/** Create the directories so writes can go straight into them. */
|
|
37
|
+
export declare function ensureRoots(roots: MemoryRoots): void;
|
|
38
|
+
/** Every memory file of `scope`, newest first. */
|
|
39
|
+
export declare function scanMemories(root: string, scope: MemoryScope): MemoryDoc[];
|
|
40
|
+
/**
|
|
41
|
+
* Write `MEMORY.md` of a directory from its memory files: one `- [Title](path) — hook` line each,
|
|
42
|
+
* within 200 lines and 25,000 characters. Entries of up to 150 characters get room first; one that
|
|
43
|
+
* does not fit is left out whole, and a warning names what was left out.
|
|
44
|
+
*/
|
|
45
|
+
export declare function rebuildIndex(root: string, scope: MemoryScope): string;
|
|
46
|
+
/** The index of a directory as the model sees it; empty indexes say so. */
|
|
47
|
+
export declare function readIndex(root: string): string;
|
|
48
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/extensions/memory/store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,eAAO,MAAM,YAAY,YAAI,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,CAAU,CAAC;AAClF,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AACvD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,SAAS,CAAC;AAE7C,uBAAuB;AACvB,MAAM,WAAW,SAAS;IACzB,KAAK,EAAE,WAAW,CAAC;IACnB,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,UAAU,cAAc,CAAC;AAMtC;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAIpD;AAYD,iFAAiF;AACjF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,kEAAkE;AAClE,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAIpD;AAED,kDAAkD;AAClD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,SAAS,EAAE,CAgB1E;AAuBD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CA2BrE;AAMD,2EAA2E;AAC3E,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI9C"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The auto-memory store: a user memory directory shared by all projects and a project memory directory
|
|
3
|
+
* per git repository, each with one Markdown file per memory under `user/`, `feedback/`, `project/`,
|
|
4
|
+
* or `reference/`, and a `MEMORY.md` index rebuilt from those files.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
8
|
+
import { getAgentDir } from "../../config.js";
|
|
9
|
+
import { parseFrontmatter } from "../../utils/frontmatter.js";
|
|
10
|
+
export const MEMORY_TYPES = ["user", "feedback", "project", "reference"];
|
|
11
|
+
export const INDEX_FILE = "MEMORY.md";
|
|
12
|
+
const MAX_INDEX_LINES = 200;
|
|
13
|
+
const MAX_INDEX_CHARS = 25_000;
|
|
14
|
+
const MAX_ENTRY_CHARS = 150;
|
|
15
|
+
const MAX_SCANNED_FILES = 200;
|
|
16
|
+
/**
|
|
17
|
+
* The memory directories: `<base>/memories/` for the user and `<base>/projects/<repo>/memory/` for the
|
|
18
|
+
* git repository around `cwd` (or `cwd` itself outside a repository). The base is the agent directory,
|
|
19
|
+
* or `DIFFRA_MEMORY_BASE_DIR`.
|
|
20
|
+
*/
|
|
21
|
+
export function memoryRoots(cwd) {
|
|
22
|
+
const base = process.env.DIFFRA_MEMORY_BASE_DIR?.trim() || getAgentDir();
|
|
23
|
+
const anchor = findGitRoot(cwd) ?? resolve(cwd);
|
|
24
|
+
return { user: join(base, "memories"), project: join(base, "projects", sanitizePath(anchor), "memory") };
|
|
25
|
+
}
|
|
26
|
+
function findGitRoot(cwd) {
|
|
27
|
+
let current = resolve(cwd);
|
|
28
|
+
while (true) {
|
|
29
|
+
if (existsSync(join(current, ".git")))
|
|
30
|
+
return current;
|
|
31
|
+
const parent = dirname(current);
|
|
32
|
+
if (parent === current)
|
|
33
|
+
return undefined;
|
|
34
|
+
current = parent;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** A directory name for a path: letters and digits kept, everything else `-`. */
|
|
38
|
+
export function sanitizePath(path) {
|
|
39
|
+
return path.replace(/[^A-Za-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "root";
|
|
40
|
+
}
|
|
41
|
+
/** Create the directories so writes can go straight into them. */
|
|
42
|
+
export function ensureRoots(roots) {
|
|
43
|
+
for (const root of [roots.user, roots.project]) {
|
|
44
|
+
for (const type of MEMORY_TYPES)
|
|
45
|
+
mkdirSync(join(root, type), { recursive: true });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Every memory file of `scope`, newest first. */
|
|
49
|
+
export function scanMemories(root, scope) {
|
|
50
|
+
const docs = [];
|
|
51
|
+
for (const type of MEMORY_TYPES) {
|
|
52
|
+
const dir = join(root, type);
|
|
53
|
+
if (!existsSync(dir))
|
|
54
|
+
continue;
|
|
55
|
+
for (const entry of readdirSync(dir)) {
|
|
56
|
+
if (!entry.endsWith(".md"))
|
|
57
|
+
continue;
|
|
58
|
+
const path = join(dir, entry);
|
|
59
|
+
try {
|
|
60
|
+
docs.push(readMemory(path, root, scope));
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// An unreadable or malformed file is left out; the extractor and dream can fix it.
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return docs.sort((a, b) => b.modifiedAt - a.modifiedAt);
|
|
68
|
+
}
|
|
69
|
+
function readMemory(path, root, scope) {
|
|
70
|
+
const { frontmatter, body } = parseFrontmatter(readFileSync(path, "utf-8"));
|
|
71
|
+
const text = (value) => (typeof value === "string" ? value.trim() : "");
|
|
72
|
+
const type = MEMORY_TYPES.find((candidate) => candidate === frontmatter.type);
|
|
73
|
+
const keywords = Array.isArray(frontmatter.keywords)
|
|
74
|
+
? frontmatter.keywords.filter((keyword) => typeof keyword === "string")
|
|
75
|
+
: [];
|
|
76
|
+
const relativePath = relative(root, path).replaceAll("\\", "/");
|
|
77
|
+
return {
|
|
78
|
+
scope,
|
|
79
|
+
path,
|
|
80
|
+
relativePath,
|
|
81
|
+
name: text(frontmatter.name) || relativePath.replace(/\.md$/, ""),
|
|
82
|
+
description: text(frontmatter.description),
|
|
83
|
+
type,
|
|
84
|
+
keywords,
|
|
85
|
+
body: body.trim(),
|
|
86
|
+
modifiedAt: statSync(path).mtimeMs,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Write `MEMORY.md` of a directory from its memory files: one `- [Title](path) — hook` line each,
|
|
91
|
+
* within 200 lines and 25,000 characters. Entries of up to 150 characters get room first; one that
|
|
92
|
+
* does not fit is left out whole, and a warning names what was left out.
|
|
93
|
+
*/
|
|
94
|
+
export function rebuildIndex(root, scope) {
|
|
95
|
+
const all = scanMemories(root, scope);
|
|
96
|
+
const docs = all.slice(0, MAX_SCANNED_FILES);
|
|
97
|
+
const lines = docs.map((doc) => `- [${doc.name}](${doc.relativePath}) — ${doc.description || doc.type || "memory"}`);
|
|
98
|
+
const kept = new Set();
|
|
99
|
+
let chars = 0;
|
|
100
|
+
const order = lines.map((line, index) => ({ line, index })).sort((a, b) => rank(a.line) - rank(b.line));
|
|
101
|
+
for (const { line, index } of order) {
|
|
102
|
+
if (kept.size >= MAX_INDEX_LINES || chars + line.length + 1 > MAX_INDEX_CHARS)
|
|
103
|
+
continue;
|
|
104
|
+
kept.add(index);
|
|
105
|
+
chars += line.length + 1;
|
|
106
|
+
}
|
|
107
|
+
const dropped = docs.filter((_doc, index) => !kept.has(index)).map((doc) => doc.name);
|
|
108
|
+
let content = lines.filter((_line, index) => kept.has(index)).join("\n");
|
|
109
|
+
if (dropped.length > 0) {
|
|
110
|
+
const names = dropped
|
|
111
|
+
.slice(0, 3)
|
|
112
|
+
.map((name) => `"${name.slice(0, 60)}"`)
|
|
113
|
+
.join(", ");
|
|
114
|
+
content += `\n\n> WARNING: MEMORY.md is over its limit. Only part of it was loaded. Dropped ${dropped.length} of ${lines.length} entries: ${names}${dropped.length > 3 ? `, +${dropped.length - 3} more` : ""}.`;
|
|
115
|
+
}
|
|
116
|
+
if (all.length > docs.length) {
|
|
117
|
+
content += `\n\n> NOTE: MEMORY.md does not list every topic file (${docs.length} of ${all.length} listed, newest first).`;
|
|
118
|
+
}
|
|
119
|
+
mkdirSync(root, { recursive: true });
|
|
120
|
+
writeFileSync(join(root, INDEX_FILE), content ? `${content}\n` : "");
|
|
121
|
+
return content;
|
|
122
|
+
}
|
|
123
|
+
function rank(line) {
|
|
124
|
+
return line.length <= MAX_ENTRY_CHARS ? 0 : 1;
|
|
125
|
+
}
|
|
126
|
+
/** The index of a directory as the model sees it; empty indexes say so. */
|
|
127
|
+
export function readIndex(root) {
|
|
128
|
+
const path = join(root, INDEX_FILE);
|
|
129
|
+
const text = existsSync(path) ? readFileSync(path, "utf-8").trim() : "";
|
|
130
|
+
return text || "Your MEMORY.md is currently empty. When you save new memories, they will appear here.";
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/extensions/memory/store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,CAAU,CAAC;AAwBlF,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAC;AACtC,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,eAAe,GAAG,MAAM,CAAC;AAC/B,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW;IACtC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE,IAAI,EAAE,IAAI,WAAW,EAAE,CAAC;IACzE,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;IAChD,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI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AAI,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC9B,OAAO,IAAI,yDAAyD,IAAI,CAAC,MAAM,OAAO,GAAG,CAAC,MAAM,yBAAyB,CAAC;IAC3H,CAAC;IACD,SAAS,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACrC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACrE,OAAO,OAAO,CAAC;AAChB,CAAC;AAED,SAAS,IAAI,CAAC,IAAY;IACzB,OAAO,IAAI,CAAC,MAAM,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,SAAS,CAAC,IAAY;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACxE,OAAO,IAAI,IAAI,uFAAuF,CAAC;AACxG,CAAC","sourcesContent":["/**\n * The auto-memory store: a user memory directory shared by all projects and a project memory directory\n * per git repository, each with one Markdown file per memory under `user/`, `feedback/`, `project/`,\n * or `reference/`, and a `MEMORY.md` index rebuilt from those files.\n */\n\nimport { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative, resolve } from \"node:path\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { parseFrontmatter } from \"../../utils/frontmatter.ts\";\n\nexport const MEMORY_TYPES = [\"user\", \"feedback\", \"project\", \"reference\"] as const;\nexport type MemoryType = (typeof MEMORY_TYPES)[number];\nexport type MemoryScope = \"user\" | \"project\";\n\n/** One memory file. */\nexport interface MemoryDoc {\n\tscope: MemoryScope;\n\t/** Absolute path. */\n\tpath: string;\n\t/** Path relative to the scope's directory, as the index links it. */\n\trelativePath: string;\n\tname: string;\n\tdescription: string;\n\ttype: MemoryType | undefined;\n\tkeywords: string[];\n\tbody: string;\n\tmodifiedAt: number;\n}\n\nexport interface MemoryRoots {\n\tuser: string;\n\tproject: string;\n}\n\nexport const INDEX_FILE = \"MEMORY.md\";\nconst MAX_INDEX_LINES = 200;\nconst MAX_INDEX_CHARS = 25_000;\nconst MAX_ENTRY_CHARS = 150;\nconst MAX_SCANNED_FILES = 200;\n\n/**\n * The memory directories: `<base>/memories/` for the user and `<base>/projects/<repo>/memory/` for the\n * git repository around `cwd` (or `cwd` itself outside a repository). The base is the agent directory,\n * or `DIFFRA_MEMORY_BASE_DIR`.\n */\nexport function memoryRoots(cwd: string): MemoryRoots {\n\tconst base = process.env.DIFFRA_MEMORY_BASE_DIR?.trim() || getAgentDir();\n\tconst anchor = findGitRoot(cwd) ?? resolve(cwd);\n\treturn { user: join(base, \"memories\"), project: join(base, \"projects\", sanitizePath(anchor), \"memory\") };\n}\n\nfunction findGitRoot(cwd: string): string | undefined {\n\tlet current = resolve(cwd);\n\twhile (true) {\n\t\tif (existsSync(join(current, \".git\"))) return current;\n\t\tconst parent = dirname(current);\n\t\tif (parent === current) return undefined;\n\t\tcurrent = parent;\n\t}\n}\n\n/** A directory name for a path: letters and digits kept, everything else `-`. */\nexport function sanitizePath(path: string): string {\n\treturn path.replace(/[^A-Za-z0-9]+/g, \"-\").replace(/^-+|-+$/g, \"\") || \"root\";\n}\n\n/** Create the directories so writes can go straight into them. */\nexport function ensureRoots(roots: MemoryRoots): void {\n\tfor (const root of [roots.user, roots.project]) {\n\t\tfor (const type of MEMORY_TYPES) mkdirSync(join(root, type), { recursive: true });\n\t}\n}\n\n/** Every memory file of `scope`, newest first. */\nexport function scanMemories(root: string, scope: MemoryScope): MemoryDoc[] {\n\tconst docs: MemoryDoc[] = [];\n\tfor (const type of MEMORY_TYPES) {\n\t\tconst dir = join(root, type);\n\t\tif (!existsSync(dir)) continue;\n\t\tfor (const entry of readdirSync(dir)) {\n\t\t\tif (!entry.endsWith(\".md\")) continue;\n\t\t\tconst path = join(dir, entry);\n\t\t\ttry {\n\t\t\t\tdocs.push(readMemory(path, root, scope));\n\t\t\t} catch {\n\t\t\t\t// An unreadable or malformed file is left out; the extractor and dream can fix it.\n\t\t\t}\n\t\t}\n\t}\n\treturn docs.sort((a, b) => b.modifiedAt - a.modifiedAt);\n}\n\nfunction readMemory(path: string, root: string, scope: MemoryScope): MemoryDoc {\n\tconst { frontmatter, body } = parseFrontmatter(readFileSync(path, \"utf-8\"));\n\tconst text = (value: unknown) => (typeof value === \"string\" ? value.trim() : \"\");\n\tconst type = MEMORY_TYPES.find((candidate) => candidate === frontmatter.type);\n\tconst keywords = Array.isArray(frontmatter.keywords)\n\t\t? frontmatter.keywords.filter((keyword): keyword is string => typeof keyword === \"string\")\n\t\t: [];\n\tconst relativePath = relative(root, path).replaceAll(\"\\\\\", \"/\");\n\treturn {\n\t\tscope,\n\t\tpath,\n\t\trelativePath,\n\t\tname: text(frontmatter.name) || relativePath.replace(/\\.md$/, \"\"),\n\t\tdescription: text(frontmatter.description),\n\t\ttype,\n\t\tkeywords,\n\t\tbody: body.trim(),\n\t\tmodifiedAt: statSync(path).mtimeMs,\n\t};\n}\n\n/**\n * Write `MEMORY.md` of a directory from its memory files: one `- [Title](path) — hook` line each,\n * within 200 lines and 25,000 characters. Entries of up to 150 characters get room first; one that\n * does not fit is left out whole, and a warning names what was left out.\n */\nexport function rebuildIndex(root: string, scope: MemoryScope): string {\n\tconst all = scanMemories(root, scope);\n\tconst docs = all.slice(0, MAX_SCANNED_FILES);\n\tconst lines = docs.map((doc) => `- [${doc.name}](${doc.relativePath}) — ${doc.description || doc.type || \"memory\"}`);\n\tconst kept = new Set<number>();\n\tlet chars = 0;\n\tconst order = lines.map((line, index) => ({ line, index })).sort((a, b) => rank(a.line) - rank(b.line));\n\tfor (const { line, index } of order) {\n\t\tif (kept.size >= MAX_INDEX_LINES || chars + line.length + 1 > MAX_INDEX_CHARS) continue;\n\t\tkept.add(index);\n\t\tchars += line.length + 1;\n\t}\n\tconst dropped = docs.filter((_doc, index) => !kept.has(index)).map((doc) => doc.name);\n\tlet content = lines.filter((_line, index) => kept.has(index)).join(\"\\n\");\n\tif (dropped.length > 0) {\n\t\tconst names = dropped\n\t\t\t.slice(0, 3)\n\t\t\t.map((name) => `\"${name.slice(0, 60)}\"`)\n\t\t\t.join(\", \");\n\t\tcontent += `\\n\\n> WARNING: MEMORY.md is over its limit. Only part of it was loaded. Dropped ${dropped.length} of ${lines.length} entries: ${names}${dropped.length > 3 ? `, +${dropped.length - 3} more` : \"\"}.`;\n\t}\n\tif (all.length > docs.length) {\n\t\tcontent += `\\n\\n> NOTE: MEMORY.md does not list every topic file (${docs.length} of ${all.length} listed, newest first).`;\n\t}\n\tmkdirSync(root, { recursive: true });\n\twriteFileSync(join(root, INDEX_FILE), content ? `${content}\\n` : \"\");\n\treturn content;\n}\n\nfunction rank(line: string): number {\n\treturn line.length <= MAX_ENTRY_CHARS ? 0 : 1;\n}\n\n/** The index of a directory as the model sees it; empty indexes say so. */\nexport function readIndex(root: string): string {\n\tconst path = join(root, INDEX_FILE);\n\tconst text = existsSync(path) ? readFileSync(path, \"utf-8\").trim() : \"\";\n\treturn text || \"Your MEMORY.md is currently empty. When you save new memories, they will appear here.\";\n}\n"]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: batch
|
|
3
|
+
description: Apply one change to many files in parallel with subagents - for example "add a license header to src/**/*.ts" or "convert these tests to async/await". Use when the user wants the same edit made across a set of files. Arguments - <operation> <file-pattern>.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Apply an operation to many files
|
|
7
|
+
|
|
8
|
+
Split a set of files into chunks and let parallel subagents apply the same operation to each chunk, then report what happened to every file. All workers edit the same working tree; there is no isolation.
|
|
9
|
+
|
|
10
|
+
## 1. Understand the request
|
|
11
|
+
|
|
12
|
+
Read the operation (what to change) and the file pattern (a glob such as `src/**/*.ts`) from the arguments after `/batch`. If either is missing or unclear, ask the user for it and stop until they answer.
|
|
13
|
+
|
|
14
|
+
If the user asks for a preview or dry run, do steps 2 and 3, show the file list, the chunk plan, and the operation, then ask whether to proceed.
|
|
15
|
+
|
|
16
|
+
## 2. Find the files
|
|
17
|
+
|
|
18
|
+
Find the files matching the pattern. Leave out, without asking:
|
|
19
|
+
|
|
20
|
+
- `node_modules`, `dist`, `build`, `.git`, and other generated or vendored directories
|
|
21
|
+
- tests: `*.test.*`, `*.spec.*`, files under `__tests__` (unless the operation is about tests)
|
|
22
|
+
- lock files, minified files (`*.min.js`), binary files, and files over 500 KB
|
|
23
|
+
|
|
24
|
+
Then:
|
|
25
|
+
|
|
26
|
+
- No files: say so and stop.
|
|
27
|
+
- More than 100 files: say how many matched, suggest a narrower pattern, and stop.
|
|
28
|
+
- More than 50 files: list the count and the files, then go on.
|
|
29
|
+
|
|
30
|
+
## 3. Plan the chunks
|
|
31
|
+
|
|
32
|
+
| Files | Chunks |
|
|
33
|
+
|---|---|
|
|
34
|
+
| 1-5 | 1 |
|
|
35
|
+
| 6-15 | 2 |
|
|
36
|
+
| 16-30 | 3 |
|
|
37
|
+
| 31-50 | 4 |
|
|
38
|
+
| 51-100 | 5 |
|
|
39
|
+
|
|
40
|
+
Keep 3 to 15 files in a chunk, and at most 5 chunks. Keep files of the same directory together.
|
|
41
|
+
|
|
42
|
+
## 4. Run the workers
|
|
43
|
+
|
|
44
|
+
Start one subagent per chunk with the `agent` tool, all in one message: `subagent_type: "general-purpose"`, `run_in_background: false`, and a short `description` such as `batch 2/4`. Give each worker this brief:
|
|
45
|
+
|
|
46
|
+
- The operation, exactly as the user asked for it.
|
|
47
|
+
- Its files, as a list of paths.
|
|
48
|
+
- Make the smallest change that does the operation; keep each file's style; do not touch tests or files outside the list.
|
|
49
|
+
- Keep going when one file fails.
|
|
50
|
+
- Reply with one line per file: `SUCCESS: <path> - <what changed>`, `FAILED: <path> - <why>`, or `SKIPPED: <path> - <why>`.
|
|
51
|
+
|
|
52
|
+
## 5. Report
|
|
53
|
+
|
|
54
|
+
Collect the workers' lines. A failed worker does not stop the others: report its files as failed, with the reason. Then answer with:
|
|
55
|
+
|
|
56
|
+
```markdown
|
|
57
|
+
### Batch Operation Complete
|
|
58
|
+
|
|
59
|
+
**Operation:** <operation>
|
|
60
|
+
**Files discovered:** <n>
|
|
61
|
+
**Chunks:** <n>
|
|
62
|
+
|
|
63
|
+
| Status | Count |
|
|
64
|
+
|---|---|
|
|
65
|
+
| Success | <n> |
|
|
66
|
+
| Failed | <n> |
|
|
67
|
+
| Skipped | <n> |
|
|
68
|
+
|
|
69
|
+
**Succeeded:** <paths>
|
|
70
|
+
**Failed:** <path - reason>
|
|
71
|
+
**Skipped:** <path - reason>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Leave out empty lists.
|