dal-code 1.0.50 → 1.0.52
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 +1050 -5
- package/NOTICE +17 -1
- package/dist/bundle/chunks/anthropic-messages-NK5NGKAI.js +5 -0
- package/dist/bundle/chunks/anthropic.js +74 -0
- package/dist/bundle/chunks/azure-openai-responses-VEASENYL.js +1 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +88 -0
- package/dist/bundle/chunks/chunk-3YGHTGYM.js +7 -0
- package/dist/bundle/chunks/chunk-4LDEEFCY.js +1 -0
- package/dist/bundle/chunks/chunk-4UTLMBZZ.js +13 -0
- package/dist/bundle/chunks/chunk-4VJJ6NXH.js +8 -0
- package/dist/bundle/chunks/chunk-567OJLS7.js +1 -0
- package/dist/bundle/chunks/chunk-5AGIVGSV.js +5 -0
- package/dist/bundle/chunks/chunk-6EEJ4MZH.js +1 -0
- package/dist/bundle/chunks/chunk-6QGV3IWD.js +5 -0
- package/dist/bundle/chunks/chunk-723ZGEZ2.js +1 -0
- package/dist/bundle/chunks/chunk-7DDKXS2Q.js +1 -0
- package/dist/bundle/chunks/chunk-7ZC4UXSL.js +1 -0
- package/dist/bundle/chunks/chunk-A5CI3CVQ.js +1 -0
- package/dist/bundle/chunks/chunk-AAQZXQA7.js +1 -0
- package/dist/bundle/chunks/chunk-ANL2BCIQ.js +15 -0
- package/dist/bundle/chunks/chunk-CF5GWZHW.js +30 -0
- package/dist/bundle/chunks/chunk-CS4T4O5O.js +1 -0
- package/dist/bundle/chunks/chunk-D2WTLI2T.js +19 -0
- package/dist/bundle/chunks/chunk-DLKRCASW.js +17 -0
- package/dist/bundle/chunks/chunk-EH7SFF47.js +129 -0
- package/dist/bundle/chunks/chunk-FFMDRXC4.js +9 -0
- package/dist/bundle/chunks/chunk-HEFI7NO7.js +1 -0
- package/dist/bundle/chunks/chunk-IEBK4HQA.js +1 -0
- package/dist/bundle/chunks/chunk-JXWJOIH4.js +1 -0
- package/dist/bundle/chunks/chunk-K7VBBYTT.js +1 -0
- package/dist/bundle/chunks/chunk-KJW3E2CB.js +9 -0
- package/dist/bundle/chunks/chunk-L2ZPNLYD.js +1 -0
- package/dist/bundle/chunks/chunk-LVVZS2NO.js +11 -0
- package/dist/bundle/chunks/chunk-ML5DIOWR.js +1 -0
- package/dist/bundle/chunks/chunk-ON7ZX67F.js +30 -0
- package/dist/bundle/chunks/chunk-OQWPBJCS.js +81 -0
- package/dist/bundle/chunks/chunk-P7FPUEYA.js +1 -0
- package/dist/bundle/chunks/chunk-PGXDEOVV.js +1 -0
- package/dist/bundle/chunks/chunk-PJACZCIR.js +1 -0
- package/dist/bundle/chunks/chunk-PRRNXB7S.js +1 -0
- package/dist/bundle/chunks/chunk-R47JBGS3.js +1 -0
- package/dist/bundle/chunks/chunk-RDZVAGPR.js +1 -0
- package/dist/bundle/chunks/chunk-SE42OS3U.js +21 -0
- package/dist/bundle/chunks/chunk-TK2WJTRC.js +3 -0
- package/dist/bundle/chunks/chunk-TMTOQ7H7.js +1 -0
- package/dist/bundle/chunks/chunk-UTB4DTYQ.js +1 -0
- package/dist/bundle/chunks/chunk-UVKMBM5X.js +56 -0
- package/dist/bundle/chunks/chunk-WIZGOHKY.js +9 -0
- package/dist/bundle/chunks/chunk-XAS5HHBW.js +1180 -0
- package/dist/bundle/chunks/chunk-XDBGA662.js +43 -0
- package/dist/bundle/chunks/chunk-XJFQKN3N.js +2 -0
- package/dist/bundle/chunks/chunk-YWNDPXVM.js +25 -0
- package/dist/bundle/chunks/chunk-ZG74NES2.js +1 -0
- package/dist/bundle/chunks/cli-GXB5WYKG.js +52 -0
- package/dist/bundle/chunks/cli-YPE3BB5X.js +30 -0
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-B7WOBGWO.js +1 -0
- package/dist/bundle/chunks/codemode-worker.js +480 -0
- package/dist/bundle/chunks/dist-D3WIBXB5.js +10 -0
- package/dist/bundle/chunks/easter-egg-3d-5TFBCTIS.js +1 -0
- package/dist/bundle/chunks/execute-27QCJECT.js +506 -0
- package/dist/bundle/chunks/github-copilot.js +1 -0
- package/dist/bundle/chunks/google-generative-ai-MBMRBHSZ.js +1 -0
- package/dist/bundle/chunks/google-vertex-S2ZFBDPP.js +1 -0
- package/dist/bundle/chunks/http-proxy-KF35JLJN.js +1 -0
- package/dist/bundle/chunks/https-proxy-agent-LVOO5TPL.js +12 -0
- package/dist/bundle/chunks/image-resize-worker.js +1 -0
- package/dist/bundle/chunks/jiti-loader-GL4HJFAD.js +20 -0
- package/dist/bundle/chunks/jiti-static-loader-2RCDI6B4.js +1 -0
- package/dist/bundle/chunks/kimi-coding.js +1 -0
- package/dist/bundle/chunks/lib-4AVRLBHM.js +8 -0
- package/dist/bundle/chunks/llama-cpp-classify-S4LVGNNY.js +21 -0
- package/dist/bundle/chunks/mcp-6LJKGKJQ.js +10 -0
- package/dist/bundle/chunks/meta.js +1 -0
- package/dist/bundle/chunks/mistral-conversations-C7LUXIEY.js +4 -0
- package/dist/bundle/chunks/multipart-parser-FMGQ7342.js +2 -0
- package/dist/bundle/chunks/node-AUOGOBCN.js +1 -0
- package/dist/bundle/chunks/node-ZTHARAQV.js +15 -0
- package/dist/bundle/chunks/office-5OWKTZOA.js +419 -0
- package/dist/bundle/chunks/openai-chatgpt.js +74 -0
- package/dist/bundle/chunks/openai-codex-responses-YQQXJ24E.js +9 -0
- package/dist/bundle/chunks/openai-codex.js +74 -0
- package/dist/bundle/chunks/openai-completions-7CMH2FKD.js +6 -0
- package/dist/bundle/chunks/openai-decisions-AOGZTREY.js +4 -0
- package/dist/bundle/chunks/openai-responses-ZSOGZ3MK.js +3 -0
- package/dist/bundle/chunks/openrouter-images-AHXST2TH.js +1 -0
- package/dist/bundle/chunks/openrouter.js +74 -0
- package/dist/bundle/chunks/pi-messages-QERJLMZ6.js +7 -0
- package/dist/bundle/chunks/radius.js +74 -0
- package/dist/bundle/chunks/review-5G56KIWY.js +80 -0
- package/dist/bundle/chunks/rewind-2OYLDDHH.js +8 -0
- package/dist/bundle/chunks/router-776Z7G7G.js +3 -0
- package/dist/bundle/chunks/runtime-NKPT25KD.js +1 -0
- package/dist/bundle/chunks/sdk-TVC4GDUX.js +1 -0
- package/dist/bundle/chunks/src-QKGKDFSU.js +3 -0
- package/dist/bundle/chunks/sync-JBDC3YBK.js +7 -0
- package/dist/bundle/chunks/typesafe-system-one-MMNGGQ46.js +1 -0
- package/dist/bundle/chunks/usage-BDCIALHO.js +1 -0
- package/dist/bundle/chunks/virtual-modules-25RQ6XTV.js +1 -0
- package/dist/bundle/chunks/xai.js +1 -0
- package/dist/bundle/cli-runtime.js +2 -0
- package/dist/bundle/cli.js +2 -0
- package/dist/bundle/index.js +1 -0
- package/dist/bundle/rpc-entry.js +2 -0
- package/dist/cli/args.js +1 -1
- package/dist/cli/auth-command.js +9 -6
- package/dist/cli/auth-login.js +2 -0
- package/dist/cli/auth-logout.js +1 -0
- package/dist/cli/auth-terminal.js +5 -0
- package/dist/cli/config-selector.js +1 -1
- package/dist/config.d.ts +5 -0
- package/dist/config.js +1 -1
- package/dist/core/agent-session-runtime.js +1 -1
- package/dist/core/agent-session-services.js +1 -1
- package/dist/core/agent-session.d.ts +8 -1
- package/dist/core/agent-session.js +12 -9
- package/dist/core/auth-storage.js +1 -1
- package/dist/core/bash-executor.js +1 -1
- package/dist/core/bug-report.js +3 -3
- package/dist/core/cache-warmer.d.ts +3 -15
- package/dist/core/cache-warmer.js +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +3 -2
- package/dist/core/compaction/branch-summarization.js +5 -5
- package/dist/core/compaction/compaction.d.ts +1 -0
- package/dist/core/compaction/compaction.js +14 -14
- package/dist/core/compaction/tool-output-pruning.js +1 -1
- package/dist/core/compaction/utils.d.ts +0 -1
- package/dist/core/compaction/utils.js +8 -8
- package/dist/core/exec.d.ts +2 -0
- package/dist/core/exec.js +1 -1
- package/dist/core/export-html/template.css +9 -0
- package/dist/core/export-html/template.js +46 -39
- package/dist/core/export-html/tool-renderer.js +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/loader.js +1 -1
- package/dist/core/extensions/pi-ai-extension-view.js +1 -0
- package/dist/core/extensions/runner.js +1 -1
- package/dist/core/extensions/types.d.ts +25 -7
- package/dist/core/extensions/virtual-modules.js +1 -1
- package/dist/core/keybindings.d.ts +1 -1
- package/dist/core/keybindings.js +1 -1
- package/dist/core/mcp-servers.d.ts +6 -17
- package/dist/core/mcp-servers.js +1 -1
- package/dist/core/model-config.d.ts +1912 -2211
- package/dist/core/model-config.js +4 -4
- package/dist/core/model-resolver.js +1 -1
- package/dist/core/model-runtime.d.ts +1 -0
- package/dist/core/model-runtime.js +1 -1
- package/dist/core/package-manager.d.ts +10 -1
- package/dist/core/package-manager.js +2 -2
- package/dist/core/pi-ai-schemas.js +1 -0
- package/dist/core/pi-manifest.js +1 -1
- package/dist/core/preferred-providers.js +1 -0
- package/dist/core/project-trust.js +2 -2
- package/dist/core/prompt-templates.js +2 -2
- package/dist/core/provider-composer.js +1 -1
- package/dist/core/provider-matching.js +1 -0
- package/dist/core/radius-mcp.js +1 -0
- package/dist/core/remote-catalog-provider.js +1 -1
- package/dist/core/resource-loader.d.ts +3 -1
- package/dist/core/resource-loader.js +1 -1
- package/dist/core/runtime-credentials.js +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/session-cwd.js +3 -7
- package/dist/core/session-manager.d.ts +1 -0
- package/dist/core/session-manager.js +12 -12
- package/dist/core/settings-defaults.js +1 -1
- package/dist/core/settings-manager.d.ts +4 -0
- package/dist/core/settings-manager.js +1 -1
- package/dist/core/settings-schema.d.ts +4 -2
- package/dist/core/settings-schema.js +1 -1
- package/dist/core/skills.js +3 -3
- package/dist/core/slash-commands.js +1 -1
- package/dist/core/source-info.d.ts +8 -0
- package/dist/core/source-info.js +1 -1
- package/dist/core/system-prompt.js +3 -3
- package/dist/core/tools/bash.d.ts +2 -2
- package/dist/core/tools/bash.js +15 -15
- package/dist/core/tools/edit-diff.d.ts +9 -4
- package/dist/core/tools/edit-diff.js +22 -15
- package/dist/core/tools/edit.d.ts +3 -3
- package/dist/core/tools/edit.js +3 -3
- package/dist/core/tools/find.d.ts +2 -2
- package/dist/core/tools/find.js +10 -11
- package/dist/core/tools/grep.d.ts +3 -3
- package/dist/core/tools/grep.js +8 -12
- package/dist/core/tools/ls.d.ts +2 -2
- package/dist/core/tools/ls.js +4 -4
- package/dist/core/tools/powershell.js +6 -2
- package/dist/core/tools/read.d.ts +5 -2
- package/dist/core/tools/read.js +20 -19
- package/dist/core/tools/render-utils.js +5 -5
- package/dist/core/tools/renderers/write.js +10 -10
- package/dist/core/tools/tool-definition-wrapper.d.ts +11 -0
- package/dist/core/tools/truncate.d.ts +2 -8
- package/dist/core/tools/truncate.js +10 -10
- package/dist/core/tools/write.d.ts +2 -2
- package/dist/core/trust-manager.js +2 -2
- package/dist/core/usage-totals.js +1 -1
- package/dist/dal/builtins.js +2 -2
- package/dist/dal/manifest.d.ts +1 -0
- package/dist/dal/manifest.js +1 -1
- package/dist/dal/safety-net.js +11 -3
- package/dist/extensions/codemode/execute.js +12 -12
- package/dist/extensions/codemode/renderer.js +6 -6
- package/dist/extensions/codemode/tool.d.ts +2 -1
- package/dist/extensions/codemode/tool.js +11 -10
- package/dist/extensions/llama/client.js +5 -5
- package/dist/extensions/llama/ui.js +2 -2
- package/dist/extensions/mcp/cli.js +21 -19
- package/dist/extensions/mcp/config.js +2 -2
- package/dist/extensions/mcp/index.js +7 -7
- package/dist/extensions/mcp/oauth.d.ts +3 -22
- package/dist/extensions/mcp/oauth.js +2 -2
- package/dist/extensions/mcp/resources.d.ts +1 -1
- package/dist/extensions/mcp/resources.js +1 -1
- package/dist/extensions/mcp/runtime.d.ts +2 -2
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/extensions/mcp/tools.d.ts +1 -8
- package/dist/extensions/mcp/tools.js +4 -9
- package/dist/extensions/mcp/ui.js +1 -1
- package/dist/extensions/tool-search/tool.js +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/main.js +4 -4
- package/dist/modes/interactive/components/assistant-message.d.ts +4 -1
- package/dist/modes/interactive/components/assistant-message.js +2 -2
- package/dist/modes/interactive/components/branch-summary-message.d.ts +5 -1
- package/dist/modes/interactive/components/branch-summary-message.js +2 -2
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +5 -1
- package/dist/modes/interactive/components/compaction-summary-message.js +2 -2
- package/dist/modes/interactive/components/config-selector.js +1 -1
- package/dist/modes/interactive/components/custom-editor.js +1 -1
- package/dist/modes/interactive/components/custom-entry.js +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts +5 -2
- package/dist/modes/interactive/components/custom-message.js +3 -3
- package/dist/modes/interactive/components/diff.js +3 -3
- package/dist/modes/interactive/components/extension-editor.d.ts +1 -0
- package/dist/modes/interactive/components/extension-editor.js +1 -1
- package/dist/modes/interactive/components/extension-selector.js +2 -2
- package/dist/modes/interactive/components/login-dialog.d.ts +5 -0
- package/dist/modes/interactive/components/login-dialog.js +1 -1
- package/dist/modes/interactive/components/markdown-transform.js +1 -1
- package/dist/modes/interactive/components/mermaid.js +4 -4
- package/dist/modes/interactive/components/model-selector.d.ts +1 -0
- package/dist/modes/interactive/components/model-selector.js +2 -2
- package/dist/modes/interactive/components/oauth-selector.d.ts +2 -1
- package/dist/modes/interactive/components/oauth-selector.js +1 -1
- package/dist/modes/interactive/components/provider-brand.js +1 -0
- package/dist/modes/interactive/components/radius-login-selector.js +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.js +1 -1
- package/dist/modes/interactive/components/session-selector-search.js +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +2 -1
- package/dist/modes/interactive/components/session-selector.js +2 -2
- package/dist/modes/interactive/components/settings-submenu.js +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +5 -1
- package/dist/modes/interactive/components/skill-invocation-message.js +2 -2
- package/dist/modes/interactive/components/tool-execution.d.ts +1 -0
- package/dist/modes/interactive/components/tool-execution.js +3 -3
- package/dist/modes/interactive/components/tree-selector.d.ts +2 -0
- package/dist/modes/interactive/components/tree-selector.js +1 -1
- package/dist/modes/interactive/components/user-message-selector.d.ts +1 -0
- package/dist/modes/interactive/components/user-message-selector.js +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +2 -1
- package/dist/modes/interactive/components/user-message.js +1 -1
- package/dist/modes/interactive/external-editor.js +3 -3
- package/dist/modes/interactive/interactive-mode.d.ts +10 -1
- package/dist/modes/interactive/interactive-mode.js +45 -40
- package/dist/modes/interactive/model-search.js +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +4 -0
- package/dist/modes/interactive/theme/theme.js +3 -6
- package/dist/modes/print-mode.js +7 -7
- package/dist/modes/rpc/rpc-mode.js +1 -1
- package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-awake/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-capabilities/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-codeindex/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-compat/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-dap/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-goal/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-guard/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-learn/package.json +5 -2
- package/dist/node_modules/@dalcode/dal-learn/src/engine.js +4 -4
- package/dist/node_modules/@dalcode/dal-learn/src/extract.js +31 -5
- package/dist/node_modules/@dalcode/dal-learn/src/index.js +16 -16
- package/dist/node_modules/@dalcode/dal-learn/src/learn-mode.js +1 -0
- package/dist/node_modules/@dalcode/dal-learn/src/lesson-events.js +1 -0
- package/dist/node_modules/@dalcode/dal-learn/src/lessons.js +4 -3
- package/dist/node_modules/@dalcode/dal-learn/src/project-map.js +2 -2
- package/dist/node_modules/@dalcode/dal-learn/src/safety.js +2 -2
- package/dist/node_modules/@dalcode/dal-learn/src/signals.js +6 -5
- package/dist/node_modules/@dalcode/dal-learn/src/store.js +3 -2
- package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-mcp/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +4 -3
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +4 -3
- package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-recall/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-remote/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-router/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-rtk/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-statusline/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-structured/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-sync/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-sync/src/core.js +2 -2
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-usage/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-workflow/src/todo-snapshot.js +2 -2
- package/dist/node_modules/@dalcode/dal-workflow/src/todo.js +3 -3
- package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-agent-core/README.md +8 -6
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/proxy.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/proxy.js +2 -2
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts +8 -5
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/README.md +58 -39
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +5 -5
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.lazy.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.lazy.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/constrained-sampling.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js +2 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/lazy.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/lazy.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +4 -4
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts +2 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +5 -5
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +9 -9
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openrouter-images.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/strict-tool-limits.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/oauth/meta.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/oauth/radius.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/oauth/trusted-url.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/cache-warming.d.ts +21 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/cache-warming.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/cli.js +5 -5
- package/dist/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/index.d.ts +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/lazy-bedrock-provider.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/lazy-oauth.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/models.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +4 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/models.generated.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/models.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/all.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/compat-schema.d.ts +485 -498
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/compat-schema.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/azure.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/google-vertex.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/meta.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-individual-cn.json +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-individual.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/faux.js +5 -5
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/model-schema.d.ts +65 -65
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/model-schema.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-individual-cn.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-individual-cn.models.d.ts +5 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-individual-cn.models.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/radius-config.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/schema-builders.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/telemetry.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/types.d.ts +4 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/error-body.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/openrouter-cost.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/streaming-json.d.ts +26 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/streaming-json.js +4 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/{typebox-helpers.d.ts → string-enum.d.ts} +2 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/string-enum.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/text.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/text.js +2 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/validation.js +4 -4
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/package.json +12 -5
- package/dist/node_modules/@earendil-works/pi-codemode/README.md +2 -2
- package/dist/node_modules/@earendil-works/pi-codemode/dist/declarations.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-codemode/dist/declarations.js +4 -4
- package/dist/node_modules/@earendil-works/pi-codemode/dist/index.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-codemode/dist/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/prelude-source.js +2 -0
- package/dist/node_modules/@earendil-works/pi-codemode/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/CHANGELOG.md +32 -0
- package/dist/node_modules/@earendil-works/pi-mcp/README.md +60 -5
- package/dist/node_modules/@earendil-works/pi-mcp/dist/config.d.ts +45 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/config.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/index.d.ts +5 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/input-schema.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/input-schema.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/naming.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/naming.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/auth-provider.d.ts +18 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/auth-provider.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/callback.js +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/client-settings.d.ts +42 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/client-settings.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/errors.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/errors.js +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/flow.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/flow.js +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/index.d.ts +5 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/loopback.d.ts +22 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/loopback.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/sign-in.d.ts +28 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/sign-in.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/types.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/types.js +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/output-limit.d.ts +8 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/output-limit.js +11 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/lines.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/pipe.d.ts +34 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/pipe.js +2 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/stdio.d.ts +1 -4
- package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/stdio.js +2 -2
- package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/streamable-http.js +6 -4
- package/dist/node_modules/@earendil-works/pi-mcp/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-schema/CHANGELOG.md +37 -0
- package/dist/node_modules/@earendil-works/pi-schema/LICENSE +21 -0
- package/dist/node_modules/@earendil-works/pi-schema/README.md +319 -0
- package/dist/node_modules/@earendil-works/pi-schema/THIRD_PARTY_NOTICES/typebox-LICENSE +23 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/annotations.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/builders.d.ts +89 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/builders.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/checks.d.ts +51 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/checks.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/coerce.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/compiler.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/explain.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/index.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/date.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/date_time.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/duration.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/email.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/hostname.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idn_email.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idn_hostname.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/format/bidi.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/format/puny.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/hostname.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/idn-hostname.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/index.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/label/ascii.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/label/puny.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/label/unicode.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/pattern/pattern.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/ipv4.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/ipv6.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/iri.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/iri_reference.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/json_pointer.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/json_pointer_uri_fragment.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/regex.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/relative_json_pointer.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/time.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/uri.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/uri_reference.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/uri_template.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/url.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/uuid.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/index.d.ts +4 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/index.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/resolver.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/shared.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/typebox-static.d.ts +54 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/typebox-static.js +0 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/types.d.ts +25 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/types.js +0 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/validator.d.ts +20 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/validator.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/package.json +43 -0
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/index.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/memory.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/memory.js +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/render.js +2 -2
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +3 -1
- package/dist/node_modules/@earendil-works/pi-tui/README.md +2 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/editor.js +3 -3
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts +4 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/markdown.js +11 -10
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/select-list.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/select-list.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/settings-list.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/text.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/index.d.ts +2 -2
- package/dist/node_modules/@earendil-works/pi-tui/dist/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/keybindings.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/keys.js +5 -5
- package/dist/node_modules/@earendil-works/pi-tui/dist/layout.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/program-status.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/terminal-image.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/terminal-image.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/terminal.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js +4 -4
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-main-screen.js +13 -13
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui.js +2 -2
- package/dist/node_modules/@earendil-works/pi-tui/dist/utils.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/utils.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/dist/package-manager-cli.js +17 -16
- package/dist/utils/ansi.js +1 -1
- package/dist/utils/changelog.js +3 -3
- package/dist/utils/clipboard-command.js +1 -1
- package/dist/utils/image-resize-core.js +1 -1
- package/dist/utils/image-resize.js +1 -1
- package/dist/utils/open-browser.js +1 -1
- package/dist/utils/paths.js +1 -1
- package/dist/utils/shell.js +3 -3
- package/dist/utils/syntax-highlight.js +4 -4
- package/dist/utils/terminal-question.js +1 -0
- package/dist/utils/tools-manager.js +1 -1
- package/dist/utils/web-url.js +1 -0
- package/examples/extensions/README.md +2 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +14 -14
- package/examples/extensions/debug-provider.ts +2 -2
- package/examples/extensions/gondolin/package-lock.json +19 -29
- package/examples/extensions/gondolin/package.json +2 -2
- package/examples/extensions/plan-mode/index.ts +20 -9
- package/examples/extensions/plan-mode/utils.ts +42 -16
- package/examples/extensions/preset.ts +2 -0
- package/examples/extensions/reload-runtime.ts +17 -5
- package/examples/extensions/subagent/README.md +14 -11
- package/examples/extensions/subagent/index.ts +392 -171
- package/examples/extensions/todo.ts +7 -0
- package/examples/extensions/tools.ts +2 -0
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +20 -20
- package/examples/tsconfig.json +208 -0
- package/npm-shrinkwrap.json +407 -383
- package/package.json +6 -7
- package/examples/extensions/sandbox/index.ts +0 -327
- package/examples/extensions/sandbox/package-lock.json +0 -92
- package/examples/extensions/sandbox/package.json +0 -19
- /package/dist/node_modules/@earendil-works/pi-mcp/{LICENSES → THIRD_PARTY_NOTICES}/modelcontextprotocol-typescript-sdk.txt +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),evidence:
|
|
1
|
+
var oe=Object.defineProperty;var k=(f,e)=>oe(f,"name",{value:e,configurable:!0});var re=Object.defineProperty,j=k((f,e)=>re(f,"name",{value:e,configurable:!0}),"y");import{existsSync as ie,readdirSync as ne,readFileSync as ae,realpathSync as ce}from"node:fs";import{join as x}from"node:path";import{t as y}from"@dalcode/dal-pi-kit";import{buildExtractPrompt as de,buildInducePrompt as ue,buildReflectPrompt as le,draftFromFix as pe,EXTRACT_SYSTEM_PROMPT as fe,INDUCE_SYSTEM_PROMPT as he,normalizeCommand as R,parseExtractAnswer as me,parseInduceAnswer as ke,parseReflectAnswer as ye,REFLECT_SYSTEM_PROMPT as ge,taskNoteSignature as U}from"./extract.js";import{applyFeedback as je,proposeLesson as Fe,readLessons as m,recordInjection as we,renderLessonsSection as xe,retireLessons as De,updateLessons as D}from"./lessons.js";import{desktopProjectsRoot as Ce,importDesktopRules as be}from"./migrate.js";import{procedureOf as Ee,proceduresPath as Ie,recordProcedure as Ae,updateProcedures as $}from"./procedures.js";import{identifyProject as Se}from"./project.js";import{learnFromRun as ve,readMap as Pe,renderMapSection as Re,updateMap as $e,viewMap as Me}from"./project-map.js";import{rejectLesson as Y,riskOf as M}from"./safety.js";import{analyzeRun as T,buildExcerpt as L,longSuccess as Te,needsModel as Le,needsReflection as _e,protectedChanges as q,runsChecks as X,verifiedOutcome as Be}from"./signals.js";import{applyPatches as z,decideScope as Ke,improvementFor as Oe,isEditable as We,lineDiff as b,MAX_SKILL_CHARS as Ne,matchSkill as Ue,restoreBefore as H,runOutcome as Ye,skillKey as E,skillsLoaded as qe,trackUse as Xe}from"./skill-evolution.js";import{claimExtraction as ze,claimPending as He,learnedRoot as Ge,listPending as Je,MAX_PENDING_ATTEMPTS as Qe,pendingDir as Ve,projectDir as I,recordExtractionTokens as Ze,removePending as et,updateDoc as G,userDir as tt,writePending as _}from"./store.js";const J=6,Q=4;function B(f,e){return e?.length?f.map(t=>t.tag==="helpful"?{...t,tag:"neutral",why:`${t.why} [not credited: the run changed ${e.join(", ")}]`.slice(0,200)}:t):f}k(B,"Ge"),j(B,"capProtectedCredit");function A(f){return{signals:f,notices:[],proposed:[],taskNotes:[],feedback:0,modelCall:"none",reflection:"none",induction:"none"}}k(A,"$"),j(A,"emptyReport");function V(f,e){const t=[...f.list()],o=[...new Set((e.evidence??[]).flatMap(r=>r.skills))],s=[e.steps.join(" "),...o];for(const r of s)for(const i of f.search?.(r)??[])t.some(n=>n.name===i.name)||t.push(i);return t}k(V,"Je"),j(V,"candidateSkills");class st{static{k(this,"ht")}static{j(this,"Learner")}root;desktopRoot;dailyCap;reflectCap;clock;inFlight=new Set;constructor(e={}){this.root=Ge(e.root),this.desktopRoot=e.desktopRoot??Ce(),this.dailyCap=e.dailyCap??J,this.reflectCap=e.reflectCap??Math.min(Q,this.dailyCap),this.clock=e.now??Date.now}now(){return this.clock()}project(e){return Se(e)}projectDir(e){return I(this.root,e.key)}userDir(){return tt(this.root)}recordProjectIdentity(e){const t=x(this.projectDir(e),"project.json");G(t,o=>({root:typeof o?.root=="string"?o.root:"",remote:o?.remote,roots:o?.roots}),o=>{const s=Array.isArray(o.roots)?o.roots:[];if(!(o.root===e.root&&s.includes(e.root)))return{root:e.root,remote:e.remote,roots:[...new Set([...s,e.root])].slice(-20)}})}startSession(e,t={}){const o=this.now(),s=this.project(e),r=this.projectDir(s);let i=0;const n=[];try{this.recordProjectIdentity(s)}catch{}try{D(r,l=>{const u=be(l,[s.root,e],this.desktopRoot,o);if(u)return i=u.added.length,u.doc})}catch{i=0}for(const l of[r,this.userDir()])try{D(l,u=>{const c=De(u,o);return n.push(...c.transitions),c.transitions.length>0?c.doc:void 0})}catch{}const a=this.render(s,o,t);for(const l of[r,this.userDir()])try{D(l,u=>{const c=we(u,a.lessonIds,a.eligible,o);return n.push(...c.transitions),c.doc===u?void 0:c.doc})}catch{}const{eligible:d,...p}=a;return{...p,imported:i,retired:n}}preview(e,t={}){const{eligible:o,...s}=this.render(this.project(e),this.now(),t);return{...s,imported:0,retired:[]}}render(e,t,o){const s=this.projectDir(e),r=m(s).lessons.filter(c=>!(o.hostHasLearnedSection&&c.origin?.kind==="desktop")),i=m(this.userDir()).lessons,n=Pe(s),a=xe([{label:"Your habits (every project)",lessons:i},{label:"This project",lessons:r}],{...o.request?{request:o.request}:{},paths:[...n.hotFiles.map(c=>c.path),...n.locations.map(c=>c.path)]}),d=new Set(a.ids),p=[...i,...r].filter(c=>d.has(c.id)&&c.fix),l=Me(n,e.root,t);l.pitfalls=l.pitfalls.filter(c=>!p.some(h=>h.fix?.bad.endsWith(c.bad)&&h.fix.good.endsWith(c.good)));const u=Re(l);return{project:e,...a.text?{lessons:a.text}:{},lessonIds:a.ids,eligible:a.eligible,lessonTokens:a.tokens,...u.text?{map:u.text}:{},mapTokens:u.tokens}}async onRunEnd(e,t){const o=this.now(),s=T(e,t.previousAssistant),r=A(s);let i;try{i=this.project(t.cwd)}catch{return r}const n=this.projectDir(i);let a=[];try{a=this.commandFeedback(s,t,n),a.length>0&&(r.feedback+=this.applyFeedback(n,a,t.sessionId,o))}catch{}try{$e(n,l=>ve(l,{root:i.root,cwd:te(t.cwd),sessionId:t.sessionId,steps:s.steps,fixes:s.fixes.filter(u=>u.proven),now:o}))}catch{}for(const l of s.fixes){let u=pe(l);Y({content:u.content})&&(u={...u,content:u.content.replace(/([^)]*)|\s\([^)]*\)/u,""),rootCause:""},Y({content:u.content}))||this.propose(n,u,t.sessionId,o,r)}const d=[...new Set([...qe(s),...t.loadedSkills??[]])],p=Ye(s);try{const l=p==="correction"?[...new Set([...d,...t.earlierSkills??[]])]:d;this.trackSkills(n,l,p,t,o,r)}catch{}try{const l=Ee(s.steps);if(l){let u;const c=s.fixes.map(h=>({bad:R(h.bad),good:R(h.good),reason:h.reason}));if($(n,h=>{const g=Ae(h,l,t.sessionId,o,{skills:d,fixes:c,outcome:p});return g.draft&&(u={draft:g.draft,procedure:g.procedure}),g.doc}),u){const h=await this.shapeProposal(n,i,u.procedure,u.draft,t,o);h&&r.notices.push({kind:"skill_proposed",draft:h})}}}catch{}if(Le(s))await this.draftWithModel(s,t,i,o,r);else if(_e(s,t.injected)){const l=new Set(a.map(c=>c.id));for(const c of[...m(n).lessons,...m(this.userDir()).lessons])c.feedback.some(h=>h.sessionId===t.sessionId)&&l.add(c.id);const u=t.injected.filter(c=>!l.has(c));u.length>0&&await this.reflectWithModel(s,u,t,i,o,r)}return Te(s)&&await this.induceWithModel(s,t,i,o,r),r}skillFeedback(e,t,o,s){const r=A(T([]));if(o.length===0)return[];try{const i=this.projectDir(this.project(e));this.trackSkills(i,o,"correction",{cwd:e,sessionId:t,injected:[],skills:s},this.now(),r)}catch{}return r.notices}trackSkills(e,t,o,s,r,i){if(t.length===0)return;const n=s.skills?.list()??[],a=t.flatMap(d=>{const p=n.filter(l=>l.name===d);return p.length>0?p.map(E):[E({origin:"cloud",name:d})]});for(const d of Xe(this.root,a,s.sessionId,o,r)){if(H(this.root,d.key,d.proposalId,"revert",r).kind!=="restored")continue;let p;$(e,u=>{const c=u.drafts.findIndex(g=>g.id===d.proposalId);if(c<0)return;p={...u.drafts[c],status:"undone"};const h=[...u.drafts];return h[c]=p,{...u,drafts:h}});const l=p?.target;p?.kind==="split"&&l&&l.key!==d.key&&H(this.root,l.key,d.proposalId,"revert",r),i.notices.push({kind:"skill_reverted",skill:d.name,proposalId:d.proposalId,...p?{draft:p}:{},uses:{total:d.uses.length,bad:d.uses.filter(u=>u.outcome!=="success").length}})}}otherProjectsWith(e,t){let o=0,s=[];try{s=ne(x(this.root,"projects"))}catch{return 0}for(const r of s){const i=x(this.root,"projects",r);if(i!==t)try{ae(Ie(i),"utf8").includes(e)&&o++}catch{}}return o}async shapeProposal(e,t,o,s,r,i){const n=(o.evidence??[]).map(u=>({sessionId:u.sessionId,at:u.at,note:Z(u)})),a=Ke(o,t.root,this.otherProjectsWith(o.fingerprint,e));let d={...s,kind:"new",scope:a.scope,scopeReason:a.reason,diff:b("",s.content,`${s.name}/SKILL.md`),evidence:n,risk:M(s.content)};const p=r.skills?Ue(o,V(r.skills,o)):void 0,l=p?await r.skills?.text(p.ref).catch(()=>{}):void 0;if(p&&l!==void 0){const u=Oe(l,o,i,s.id),c=p.ref,h=E(c);if(!u)d=void 0;else{const g=c.origin==="learned-project"&&c.projectKey===t.key,C=a.scope==="project"&&!g,v=We(c)&&!C,K=C?{...u,projectKey:t.key}:u,O={key:h,name:c.name,origin:c.origin,editable:v,...c.filePath?{filePath:c.filePath}:{}},se=g||C||c.origin==="project"?"project":"user",W=p.why==="loaded"?F(y("\u8FD9\u4E9B\u4F1A\u8BDD\u91CC\u6709 {n} \u4E2A\u52A0\u8F7D\u8FC7\u6280\u80FD\u300C{name}\u300D"),{n:p.count,name:c.name}):F(y("\u6280\u80FD\u300C{name}\u300D\u7684\u540D\u79F0\u548C\u8BF4\u660E\u4E0E\u8FD9\u5957\u6B65\u9AA4\u76F8\u7B26"),{name:c.name});if(l.length+u.text.length>Ne){const w=`${c.name}-${s.name}`.slice(0,64).replace(/-+$/g,""),P=ee(w,c.name,o,u.text),N={id:`${s.id}p`,mode:"append",text:F(y("\u53E6\u89C1\u6280\u80FD\u300C{name}\u300D\uFF1A\u672C\u673A\u8865\u5145\u7684\u505A\u6CD5\u3002"),{name:w}),proposalId:s.id,created:u.created,...C?{projectKey:t.key}:{}};d={...s,name:w,content:P,kind:"split",scope:a.scope,scopeReason:`${W}\uFF1B${F(y("\u5B83\u5DF2\u7ECF\u5F88\u957F\uFF08{n} \u5B57\u7B26\uFF09\uFF0C\u8865\u5145\u53E6\u6210\u4E00\u4E2A\u6280\u80FD"),{n:l.length})}\uFF1B${a.reason}`,target:O,patch:N,diff:[b("",P,`${w}/SKILL.md`),b(l,z(l,[N],{marker:!v,projectKey:t.key}).text,`${c.name}`)].join(`
|
|
2
|
+
`),evidence:n,risk:M(P)}}else{const w=z(l,[K],{marker:!v,projectKey:t.key}).text;d={...s,name:c.name,content:"",kind:"improve",scope:se,scopeReason:`${W}\uFF1B${a.reason}`,target:O,patch:K,diff:b(l,w,c.name),evidence:n,risk:M(u.text)}}}}return $(e,u=>({...u,procedures:u.procedures.map(c=>c.fingerprint===o.fingerprint&&!d&&p?{...c,coveredBy:E(p.ref)}:c),drafts:d?u.drafts.map(c=>c.id===s.id?d:c):u.drafts.filter(c=>c.id!==s.id)})),d}seenInAnotherTask(e,t,o){const s=U(t.content);let r=!1;try{G(x(e,"task-notes.json"),i=>({signatures:i?.signatures&&typeof i.signatures=="object"&&!Array.isArray(i.signatures)?i.signatures:{}}),i=>{const n=Array.isArray(i.signatures[s])?i.signatures[s]:[];if(r=n.some(d=>d!==o),n.includes(o))return;const a=Object.entries({...i.signatures,[s]:[...n,o].slice(-4)});return{signatures:Object.fromEntries(a.slice(-200))}})}catch{return!1}return r}propose(e,t,o,s,r){const i=t.scope==="user"?this.userDir():e;try{D(i,n=>{const a=Fe(n,t,o,s);if(a.outcome.kind!=="suppressed"){if(a.outcome.kind==="created"&&r.proposed.push(a.outcome.lesson),a.transition){const d=a.transition.to;d==="active"&&r.notices.push({kind:"activated",lesson:a.transition.lesson}),d==="awaiting_user"&&r.notices.push({kind:"awaiting_user",lesson:a.transition.lesson})}return a.doc}})}catch{}}applyFeedback(e,t,o,s){let r=0;for(const i of[e,this.userDir()])D(i,n=>{const a=je(n,t,o,s);return r+=a.changed,a.changed>0?a.doc:void 0});return r}commandFeedback(e,t,o){if(t.injected.length===0)return[];const s=new Set(t.injected),r=[...m(o).lessons,...m(this.userDir()).lessons].filter(n=>s.has(n.id)&&n.fix),i=[];for(const n of r){const a=n.fix?.good;if(a)for(const d of e.steps){if(!d.command)continue;const p=R(d.cdDir?`cd ${d.cdDir} && ${d.command}`:d.command);if(!d.isError&&!d.unverifiedPass&&X(p,a)){i.push({id:n.id,tag:"helpful",why:`\`${a}\` passed`});break}if(d.isError&&X(p,a,!0)){i.push({id:n.id,tag:"harmful",why:`\`${a}\` failed`});break}}}return i}async draftWithModel(e,t,o,s,r){if(!t.complete){r.modelCall="unavailable";return}if(!this.claimCall(s,"draft")){r.modelCall="capped";return}const i={id:S(s),kind:"draft",createdAt:s,attempts:1,projectKey:o.key,projectRoot:o.root,sessionId:t.sessionId,excerpt:L(e,e.corrected?t.previousAssistant:void 0),reason:{corrected:e.corrected,detour:e.detour,denials:e.denials.length,fixes:e.fixes.length}};await this.draftFromExcerpt(i,t.complete,s,r)}async reflectWithModel(e,t,o,s,r,i){if(!o.complete){i.reflection="unavailable";return}if(!this.claimCall(r,"reflect")){i.reflection="capped";return}const n={id:S(r),kind:"reflect",injected:[...t],outcome:Be(e.steps)??"passed",...q(e.steps).length?{touched:q(e.steps)}:{},createdAt:r,attempts:1,projectKey:s.key,projectRoot:s.root,sessionId:o.sessionId,excerpt:L(e),reason:{corrected:!1,detour:!1,denials:0,fixes:e.fixes.length}};await this.draftFromExcerpt(n,o.complete,r,i)}async induceWithModel(e,t,o,s,r){if(!t.complete){r.induction="unavailable";return}if(!this.claimCall(s,"draft")){r.induction="capped";return}const i={id:S(s),kind:"induce",...t.injected.length>0?{injected:[...t.injected]}:{},createdAt:s,attempts:1,projectKey:o.key,projectRoot:o.root,sessionId:t.sessionId,excerpt:L(e),reason:{corrected:!1,detour:!1,denials:0,fixes:e.fixes.length}};await this.draftFromExcerpt(i,t.complete,s,r)}claimCall(e,t){try{return ze(this.root,t==="reflect"?this.reflectCap:this.dailyCap,e,t)}catch{return!1}}async ask(e,t,o,s,r){const i={job:e,kept:!1,abort:new AbortController};this.inFlight.add(i);let n;try{n=await s(t,o,i.abort.signal)}catch{return{status:"failed"}}finally{this.inFlight.delete(i)}if(!n)return{status:"unavailable"};if(i.kept&&!et(this.root,e.id))return{status:"none"};try{Ze(this.root,n.inputTokens??0,n.outputTokens??0,r)}catch{}return{status:"done",answer:n}}async draftFromExcerpt(e,t,o,s){if(e.kind==="reflect")return s.reflection=await this.reflectFromExcerpt(e,t,o,s),s.reflection;if(e.kind==="induce")return s.induction=await this.induceFromExcerpt(e,t,o,s),s.induction;const r=I(this.root,e.projectKey),i={corrected:e.reason.corrected,detour:e.reason.detour,denials:{length:e.reason.denials},fixes:{length:e.reason.fixes}},n=[...m(r).lessons,...m(this.userDir()).lessons],{status:a,answer:d}=await this.ask(e,fe,de(e.excerpt,i,n),t,o);if(s.modelCall=a,!d)return a;const p=me(d.text,i);for(const l of p.drafts)this.propose(r,l,e.sessionId,o,s);for(const l of p.taskNotes)s.taskNotes.push(l),this.seenInAnotherTask(r,l,e.sessionId)&&this.propose(r,{scope:"project",section:l.section,content:l.content,rootCause:l.rootCause,signal:l.signal,note:l.note,signature:`task:${U(l.content)}`},e.sessionId,o,s);return a}async induceFromExcerpt(e,t,o,s){const r=I(this.root,e.projectKey),i=[...m(r).lessons,...m(this.userDir()).lessons],{status:n,answer:a}=await this.ask(e,he,ue(e.excerpt,i,e.injected??[]),t,o);if(!a)return n;const d=/^\[user\] (.*)$/m.exec(e.excerpt)?.[1]??"";for(const p of ke(a.text,d).drafts)this.propose(r,p,e.sessionId,o,s);return n}async reflectFromExcerpt(e,t,o,s){const r=I(this.root,e.projectKey),i=new Set(e.injected??[]),n=[...m(r).lessons,...m(this.userDir()).lessons].filter(l=>i.has(l.id)&&l.status==="active");if(n.length===0)return"none";const{status:a,answer:d}=await this.ask(e,ge,le(e.excerpt,e.outcome??"passed",n),t,o);if(!d)return a;const p=B(ye(d.text,n.map(l=>l.id)),e.touched);if(p.length>0)try{s.feedback+=this.applyFeedback(r,p,e.sessionId,o)}catch{}return a}keepUnfinished(){let e=0;for(const t of this.inFlight)if(!t.kept){try{_(this.root,t.job),t.kept=!0,e++}catch{continue}t.abort.abort()}return e}async finishPending(e,t=2){const o=[];let s;try{s=Je(this.root,this.now())}catch{return o}for(const r of s.slice(0,t)){const i=this.now(),n=He(this.root,r.id);if(!n)continue;if(!this.claimCall(i,n.kind==="reflect"?"reflect":"draft")){try{_(this.root,n)}catch{}continue}const a=A(T([])),d={...n,attempts:n.attempts+1},p=await this.draftFromExcerpt(d,e,i,a);if(p==="failed"||p==="unavailable")try{d.attempts<Qe&&!ie(x(Ve(this.root),`${n.id}.json`))&&_(this.root,d)}catch{}o.push({project:{key:n.projectKey,root:n.projectRoot},report:a})}return o}}function S(f){return`${f.toString(36)}-${Math.random().toString(36).slice(2,10)}`}k(S,"M"),j(S,"pendingId");function F(f,e){return f.replace(/\{(\w+)\}/g,(t,o)=>o in e?String(e[o]):t)}k(F,"S"),j(F,"fill");function Z(f){const e=[];f.outcome==="correction"&&e.push(y("\u4F60\u7EA0\u6B63\u4E86\u52A9\u624B")),f.outcome==="failure"&&e.push(y("\u68C0\u67E5\u5931\u8D25\u672A\u4FEE\u597D"));for(const t of f.fixes.slice(0,2))e.push(F(y("`{bad}` \u5931\u8D25\u540E\u6539\u7528 `{good}`"),t));return f.skills.length>0&&e.push(F(y("\u52A0\u8F7D\u4E86\u6280\u80FD {names}"),{names:f.skills.join("\u3001")})),e.length>0?e.join(y("\uFF1B")):y("\u987A\u5229\u5B8C\u6210")}k(Z,"Qe"),j(Z,"evidenceNote");function ee(f,e,t,o){const s=t.steps.join(" \u2192 "),r=F(y("\u300C{original}\u300D\u5728\u672C\u673A\u7684\u8865\u5145\u505A\u6CD5\uFF08{flow}\uFF09\u3002\u548C\u300C{original}\u300D\u4E00\u8D77\u4F7F\u7528\u3002"),{original:e,flow:s});return`---
|
|
3
3
|
name: ${f}
|
|
4
|
-
description: ${JSON.stringify(
|
|
4
|
+
description: ${JSON.stringify(r)}
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
${o}
|
|
8
|
-
`}k(
|
|
8
|
+
`}k(ee,"Ve"),j(ee,"companionSkill");function te(f){try{return ce(f)}catch{return f}}k(te,"Ze"),j(te,"realCwd");export{J as DEFAULT_DAILY_CAP,Q as DEFAULT_REFLECT_CAP,st as Learner,B as capProtectedCredit};
|
|
@@ -1,14 +1,40 @@
|
|
|
1
|
-
var
|
|
1
|
+
var O=Object.defineProperty;var c=(e,t)=>O(e,"name",{value:t,configurable:!0});var P=Object.defineProperty,d=c((e,t)=>P(e,"name",{value:t,configurable:!0}),"d");import{createHash as F}from"node:crypto";import{getLanguage as I}from"@dalcode/dal-pi-kit";import{isContested as M,isTrusted as T}from"./lessons.js";import{redact as m,rejectLesson as $}from"./safety.js";import{bareCommand as J}from"./signals.js";const b=3;function y(e){return m(J(e)).replace(/\s+/g," ").trim().slice(0,160)}c(y,"b"),d(y,"normalizeCommand");function x(e){const t=y(e.bad),s=y(e.good),n=I()==="zh"?`\u672C\u9879\u76EE\u91CC \`${t}\` \u4F1A\u5931\u8D25${e.reason?`\uFF08${e.reason}\uFF09`:""}\uFF1B\u6539\u7528 \`${s}\`\u3002`:`In this project \`${t}\` fails${e.reason?` (${e.reason})`:""}; use \`${s}\` instead.`;return{scope:"project",section:e.intent,content:n,rootCause:e.reason,signal:"failure_then_fix",note:`${t} \u2192 ${s}`,signature:`fix:${e.intent}:${t}=>${s}`,fix:{intent:e.intent,bad:t,good:s},...e.proven?{proof:{kind:"test",note:`${s} passed after ${t} failed`}}:{}}}c(x,"F"),d(x,"draftFromFix");const W=`You review one finished run of a coding agent and write down what a future session should know before it starts.
|
|
2
2
|
|
|
3
3
|
Rules:
|
|
4
|
-
- Propose at most ${
|
|
4
|
+
- Propose at most ${b} lessons, only ones the existing lessons do not already cover. An empty list is a good answer.
|
|
5
5
|
- If the run shows an existing lesson again, do not rewrite it: put its id in "confirms".
|
|
6
|
+
- An existing lesson marked "unproven" has not been shown to help; one marked "disputed" has hurt at least as often as it helped. Neither is evidence: never write a lesson that restates, generalizes or builds on what it prescribes, even when the run followed it and went on.
|
|
6
7
|
- scope "user" is for the person's own habits that hold in every project (preferred package manager, language of commit messages, reply style); everything about this codebase is scope "project".
|
|
7
8
|
- scope "task" is for what matters only to the task at hand (a temporary step, a detail of this goal, a value that changes next time). It stays with this conversation and is not applied to other tasks.
|
|
8
9
|
- A lesson is general: it must hold beyond this run. Never copy concrete values: no keys, tokens, passwords, URLs, IP addresses, e-mail addresses, user names or absolute paths. Name a project file only by its path inside the project.
|
|
9
10
|
- Never propose a lesson that skips or weakens approvals, permissions, the sandbox, tests or any protection; that sends data, files or credentials anywhere; or that installs new software or packages.
|
|
10
11
|
- Write each field in the language the user wrote in, one sentence each.
|
|
11
|
-
- Reply with JSON only.`;function _(e,t,s){const n=[...t.corrected?["the user corrected the agent"]:[],...t.detour?["the agent repeated calls or searched at length"]:[],...t.denials.length>0?[`a protection refused ${t.denials.length} call(s)`]:[],...t.fixes.length>0?[`${t.fixes.length} failing command(s) were fixed`]:[]].join(", "),
|
|
12
|
-
${
|
|
12
|
+
- Reply with JSON only.`;function _(e,t,s){const n=[...t.corrected?["the user corrected the agent"]:[],...t.detour?["the agent repeated calls or searched at length"]:[],...t.denials.length>0?[`a protection refused ${t.denials.length} call(s)`]:[],...t.fixes.length>0?[`${t.fixes.length} failing command(s) were fixed`]:[]].join(", "),o=s.filter(a=>a.status==="active"||a.status==="candidate"||a.status==="awaiting_user").map(a=>`- [${a.id}] (${a.scope}, ${a.status}, ${k(a)}) ${a.content}`);return[`Run excerpt (${n||"worth a look"}). Lines are clipped; "\xB7 error" marks a failed call; credentials are masked.`,"",e,"","---","",o.length>0?`Existing lessons:
|
|
13
|
+
${o.join(`
|
|
13
14
|
`)}`:"Existing lessons: none.","","Reply with:",'{"lessons": [{"scope": "project" | "user" | "task", "section": "<snake_case topic>", "what_happened": "<what went wrong or what the user corrected>", "root_cause": "<why>", "lesson": "<what to do next time>", "confirms": "<existing id, only when this run shows that lesson again>"}],',' "feedback": [{"id": "<active lesson id>", "tag": "helpful" | "harmful", "why": "<short>"}]}',"feedback lists only active lessons this run shows to have helped or hurt."].join(`
|
|
14
|
-
`)}
|
|
15
|
+
`)}c(_,"W"),d(_,"buildExtractPrompt");function p(e,t,s){const n=e[t];return typeof n=="string"?n.replace(/\s+/g," ").trim().slice(0,s):""}c(p,"p"),d(p,"field");function j(e){const t=e.toLowerCase().replace(/[\d]+/g,"").replace(/[^\p{L}]+/gu,"");return F("sha256").update(t).digest("hex").slice(0,16)}c(j,"z"),d(j,"taskNoteSignature");function N(e,t){const s={drafts:[],taskNotes:[],feedback:[],rejected:[]},n=/\{[\s\S]*\}/.exec(e);if(!n)return s;let o;try{o=JSON.parse(n[0])}catch{return s}if(!o||typeof o!="object")return s;const a=o,g=t.denials.length>0?"guard_denial":t.corrected?"user_correction":"repeated_detour";for(const i of Array.isArray(a.lessons)?a.lessons:[]){if(!i||typeof i!="object")continue;const r=i,l=p(r,"lesson",320);if(!l)continue;const h=p(r,"root_cause",300),f=p(r,"what_happened",300),w=$({content:l,rootCause:h,note:f});if(w){s.rejected.push({content:l,reason:w});continue}const u=p(r,"confirms",16);if(r.scope==="task"&&!u){s.taskNotes.push({content:l,section:p(r,"section",40).toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"general",rootCause:h,signal:g,note:m(f)});continue}const L=u.startsWith("u-")?"user":u.startsWith("l-")?"project":r.scope==="user"?"user":"project";if(s.drafts.push({scope:L,section:p(r,"section",40).toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"general",content:l,rootCause:h,signal:g,note:m(f),.../^[lu]-\d{4,6}$/.test(u)?{confirms:u}:{}}),s.drafts.length>=b)break}for(const i of Array.isArray(a.feedback)?a.feedback:[]){if(!i||typeof i!="object")continue;const r=i;typeof r.id=="string"&&(r.tag==="helpful"||r.tag==="harmful")&&s.feedback.push({id:r.id,tag:r.tag,why:p(r,"why",200)})}return s}c(N,"J"),d(N,"parseExtractAnswer");const z=`You judge whether lessons given to a coding agent made a difference in one finished run.
|
|
16
|
+
|
|
17
|
+
Rules:
|
|
18
|
+
- Tag only the lessons listed under "Lessons the run was given", by their id. Never tag another id.
|
|
19
|
+
- "helpful": the run visibly followed the lesson (a step it names, a command it recommends, a pitfall it warns about avoided) and that step worked or moved the task forward.
|
|
20
|
+
- "harmful": the run followed the lesson and that step failed, misled the agent or had to be undone.
|
|
21
|
+
- "neutral": everything else. Being given a lesson is not using it, and using it is not being helped by it. If the run does not show the lesson applied, or you cannot tell, the tag is "neutral".
|
|
22
|
+
- Judge from what the tool calls and their results show, not from what the agent said it did.
|
|
23
|
+
- "why" is one short sentence naming the step that shows it, in the language the user wrote in.
|
|
24
|
+
- Reply with JSON only.`;function R(e,t,s){return[`Run excerpt. Its last check ${t==="passed"?"passed":"failed"}. Lines are clipped; "\xB7 error" marks a failed call; credentials are masked.`,"",e,"","---","","Lessons the run was given:",...s.map(n=>`- [${n.id}] ${n.content}`),"","Reply with:",'{"bullet_tags": [{"id": "<lesson id>", "tag": "helpful" | "harmful" | "neutral", "why": "<short>"}]}'].join(`
|
|
25
|
+
`)}c(R,"Y"),d(R,"buildReflectPrompt");function A(e,t){const s=/\{[\s\S]*\}/.exec(e);if(!s)return[];let n;try{n=JSON.parse(s[0])}catch{return[]}const o=n?.bullet_tags,a=[];for(const g of Array.isArray(o)?o:[]){if(!g||typeof g!="object")continue;const i=g,r=typeof i.id=="string"?i.id.trim():"",l=i.tag;!t.includes(r)||a.some(h=>h.id===r)||l!=="helpful"&&l!=="harmful"&&l!=="neutral"||a.push({id:r,tag:l,why:m(p(i,"why",200))})}return a}c(A,"X"),d(A,"parseReflectAnswer");const v=2,Y=`You read one finished run of a coding agent that succeeded (its last check passed) and write down the reusable procedure it followed, so that a future session in the same project can follow it.
|
|
26
|
+
|
|
27
|
+
Rules:
|
|
28
|
+
- Describe only steps the run shows succeeding: a call whose result shows it worked. Never an assumption, a step that failed, a step the agent only talked about, or the answer itself.
|
|
29
|
+
- Make it reusable: replace every instance value (file names, function and variable names, ids, numbers, dates, messages) with a {parameter} such as {file}, {name}, {id} or {n}. Keep project paths only as fixed parts every instance shares (a folder, a script name).
|
|
30
|
+
- Never copy the user's request or describe the task itself: describe how this kind of change is done.
|
|
31
|
+
- At most ${v} workflows, each with a short "when" and 2 to 6 short steps. Fewer is better.
|
|
32
|
+
- If an existing lesson already covers the procedure, or the run shows nothing worth reusing, reply with NONE.
|
|
33
|
+
- If a candidate workflow listed below describes the same procedure, write it again with the same wording.
|
|
34
|
+
- A lesson marked "unproven" or "disputed" is not evidence that its step is right. When the run took a step because such a lesson "given to this run" prescribes it, leave that step out; if fewer than two steps remain, reply NONE. Never build a workflow on a disputed lesson.
|
|
35
|
+
- Never include keys, tokens, passwords, URLs, IP addresses, e-mail addresses, user names or absolute paths. Never propose a step that skips or weakens approvals, permissions, the sandbox, tests or any protection, sends data anywhere, or installs software.
|
|
36
|
+
- Write in the language the user wrote in.
|
|
37
|
+
- Reply with JSON only, or NONE.`;function k(e){return T(e)?"proven":M(e)?"disputed":"unproven"}c(k,"x"),d(k,"trustOf");function E(e,t,s=[]){const n=t.filter(o=>o.status==="active"||o.status==="candidate"&&o.section==="workflow").map(o=>{const a=[o.status==="active"?"lesson":"candidate workflow",k(o),...s.includes(o.id)?["given to this run"]:[]];return`- [${o.id}] (${a.join(", ")}) ${o.content}`});return['Run excerpt (it succeeded). Lines are clipped; "\xB7 error" marks a failed call; credentials are masked.',"",e,"","---","",n.length>0?`Existing lessons:
|
|
38
|
+
${n.join(`
|
|
39
|
+
`)}`:"Existing lessons: none.","","Reply with NONE, or:",'{"workflows": [{"when": "<the kind of task it applies to>", "steps": ["<step>", "<step>"]}]}'].join(`
|
|
40
|
+
`)}c(E,"q"),d(E,"buildInducePrompt");const B=24,U=10;function S(e,t){const s={drafts:[],rejected:[]},n=/\{[\s\S]*\}/.exec(e);if(!n)return s;let o;try{o=JSON.parse(n[0])}catch{return s}const a=o?.workflows,g=t.replace(/\s+/g,"").toLowerCase();for(const i of Array.isArray(a)?a:[]){if(s.drafts.length>=v)break;if(!i||typeof i!="object")continue;const r=i,l=p(r,"when",200),h=Array.isArray(r.steps)?r.steps.map(u=>typeof u=="string"?u.replace(/\s+/g," ").trim():""):[],f=`${l}${/[㐀-鿿]/u.test(l)?"\uFF1A":": "}${h.join(" \u2192 ")}`,w=!l||l.length>120||h.length<2||h.length>6||h.some(u=>!u||u.length>120)?"malformed":$({content:f})??(/\d{3,}|\b(?=[0-9a-f]*\d)[0-9a-f]{7,}\b/i.test(f)?"concrete_value":void 0)??(C(f.replace(/\s+/g,"").toLowerCase(),g)?"copies_task":void 0);if(w){s.rejected.push({content:f,reason:w});continue}s.drafts.push({scope:"project",section:"workflow",content:f,rootCause:"",signal:"success_workflow",note:"a long run that ended on a passing check"})}return s}c(S,"B"),d(S,"parseInduceAnswer");function C(e,t){if(t.length<U)return!1;const s=Math.min(B,t.length);for(let n=0;n+s<=t.length;n++)if(e.includes(t.slice(n,n+s)))return!0;return!1}c(C,"E"),d(C,"copies");export{W as EXTRACT_SYSTEM_PROMPT,Y as INDUCE_SYSTEM_PROMPT,b as MAX_LESSONS_PER_RUN,v as MAX_WORKFLOWS_PER_RUN,z as REFLECT_SYSTEM_PROMPT,_ as buildExtractPrompt,E as buildInducePrompt,R as buildReflectPrompt,x as draftFromFix,y as normalizeCommand,N as parseExtractAnswer,S as parseInduceAnswer,A as parseReflectAnswer,j as taskNoteSignature,k as trustOf};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),inputTokens:
|
|
3
|
-
`):""}
|
|
4
|
-
`)}
|
|
5
|
-
${t.content}`}
|
|
6
|
-
References are relative to ${
|
|
1
|
+
var zu=Object.defineProperty;var k=(t,n)=>zu(t,"name",{value:n,configurable:!0});var qu=Object.defineProperty,E=k((t,n)=>qu(t,"name",{value:n,configurable:!0}),"m");import{existsSync as Ju,readFileSync as z,realpathSync as Yu}from"node:fs";import{dirname as Gu,isAbsolute as Qu,join as q,resolve as Bu,sep as nu}from"node:path";import{t as e}from"@dalcode/dal-pi-kit";import{CONFIG_DIR_NAME as Xu,getAgentDir as J,readSignedSection as Zu,stripFrontmatter as ue}from"@earendil-works/pi-coding-agent";import{DEFAULT_DAILY_CAP as ee,Learner as te}from"./engine.js";import{learnMode as ne,reflectCapOverride as se}from"./learn-mode.js";import{LESSON_PROPOSED_EVENT as oe,LESSON_RESOLVED_EVENT as re,LESSON_RETIRED_EVENT as ie,lessonEventForNotice as ae,lessonSnapshot as Y}from"./lesson-events.js";import{approveLesson as Fe,isContested as hu,readLessons as G,undoLesson as le,updateLessons as ce}from"./lessons.js";import{registerEvolvePatches as de}from"./patches.js";import{readProcedures as ku,updateProcedures as pe}from"./procedures.js";import{readMap as gu,renderMapSection as vu,viewMap as yu}from"./project-map.js";import{adoptRevision as Ee,latestInForce as De,marketRevisions as fe,revertRevision as Ae}from"./revisions.js";import{acceptProposal as me,exportProjectSkill as Ce,keepSupplement as Be,learnedProjectSkillsDir as he,undoProposal as ke}from"./skill-actions.js";import{applyPatches as ge,isEditable as wu,listRecords as xu,noteConflicts as ve,readRecord as _u,restoreBefore as ye,skillKey as Su,skillsLoaded as we}from"./skill-evolution.js";import{readUsage as xe}from"./store.js";const $u="learned_lessons",bu="learn_skill_proposal",Q="learn_skill_resolved",ju="learn_skill_reverted",Iu="dal:skill-feedback",Lu="learn_skill_conflict",Ru="dal-learn-task-note",_e=Symbol.for("dalcode.skills.search"),Se=Symbol.for("dalcode.skills.textTransform");function X(){return globalThis[_e]}k(X,"ne"),E(X,"skillSearch");function O(t){try{return Yu(t)}catch{return Bu(t)}}k(O,"V"),E(O,"real");function su(t,n){const i=O(n);return t===i||t.startsWith(i.endsWith(nu)?i:`${i}${nu}`)}k(su,"ve"),E(su,"under");function ou(t,n,i){const s=O(t),g=q(i,"projects");if(su(s,g)){const w=s.slice(O(g).length+1).split(nu);if(w.length>=3&&w[1]==="skills")return{origin:"learned-project",projectKey:w[0]}}return su(s,q(J(),"skills"))?{origin:"user"}:/[\\/]dal-skills[\\/]src[\\/]bundled[\\/]/.test(s)?{origin:"bundled"}:n.origin==="package"?{origin:"package"}:n.scope==="project"?{origin:"project"}:{origin:"other"}}k(ou,"wn"),E(ou,"classifySkill");const Pu="learned_project_map",$e="learned_experience";function Tu(){const t=ne(),n={enabled:t!=="off",frozen:t==="frozen",dailyCap:ee};try{const s=JSON.parse(z(q(J(),"settings.json"),"utf8")).dalLearn;s?.enabled===!1&&(n.enabled=!1),typeof s?.dailyCap=="number"&&s.dailyCap>=0&&(n.dailyCap=Math.floor(s.dailyCap)),typeof s?.reflectCap=="number"&&s.reflectCap>=0&&(n.reflectCap=Math.floor(s.reflectCap)),typeof s?.model=="string"&&s.model.includes("/")&&(n.model=s.model)}catch{}const i=se();return i!==void 0&&(n.reflectCap=i),n}k(Tu,"En"),E(Tu,"readSettings");function F(t,n){return t.replace(/\{(\w+)\}/g,(i,s)=>s in n?String(n[s]):i)}k(F,"c"),E(F,"fill");function Z(t){const n=t.cost;return(n?.input??0)+(n?.output??0)}k(Z,"te"),E(Z,"cost");function ru(t,n){const i=t.modelRegistry,s=E(w=>!i.hasConfiguredAuth||i.hasConfiguredAuth(w),"usable");if(n){const w=n.indexOf("/"),x=i.find(n.slice(0,w),n.slice(w+1));if(x&&s(x))return x}let g=[];try{g=i.getAvailable().filter(s)}catch{g=[]}return g.filter(w=>Z(w)>0).sort((w,x)=>Z(w)-Z(x))[0]??t.model}k(ru,"Ln"),E(ru,"pickDraftingModel");function Ou(){return globalThis[Symbol.for("dalcode.budget.gate")]?.remaining()}k(Ou,"_n"),E(Ou,"budgetRemaining");function iu(t,n,i){return async(s,g,w)=>{if(Ou()===0)return;const x=ru(n,i);if(!x)return;const L=await n.modelRegistry.complete(x,{systemPrompt:s,messages:[{role:"user",content:[{type:"text",text:g}],timestamp:Date.now()}]},{cacheRetention:"none",maxTokens:1200,signal:w});if(L.usage)try{t.appendUsage(L.usage,{kind:"learn",provider:x.provider,model:x.id})}catch{}return L.stopReason==="error"||L.stopReason==="aborted"?void 0:{text:L.content.filter(j=>j.type==="text").map(j=>j.text).join(`
|
|
2
|
+
`),inputTokens:L.usage?.input,outputTokens:L.usage?.output}}}k(iu,"be"),E(iu,"completeWith");function Nu(t){try{const n=t.sessionManager.getBranch();for(let i=n.length-1;i>=0;i--){const s=n[i];if(s.type!=="message"||s.message.role!=="assistant")continue;const g=au(s.message);if(g)return g}}catch{}}k(Nu,"Cn"),E(Nu,"lastAnswerIn");function au(t){const n=t?.content;return typeof n=="string"?n:Array.isArray(n)?n.filter(i=>i&&typeof i=="object"&&i.type==="text").map(i=>i.text).join(`
|
|
3
|
+
`):""}k(au,"Ee"),E(au,"textOf");const Fu={deletion:"\u5220\u9664",permissions:"\u6743\u9650",credentials:"\u51ED\u636E",network:"\u7F51\u7EDC",publishing:"\u53D1\u5E03",dependencies:"\u4F9D\u8D56\u4E0E\u914D\u7F6E"};function lu(t){return t.retiredReason==="harmful"?e("\u5E2E\u5012\u5FD9\u591A\u4E8E\u5E2E\u5FD9"):t.retiredReason==="ineffective"?e("\u591A\u6B21\u7528\u5230\u90FD\u770B\u4E0D\u51FA\u6548\u679C"):t.retiredReason==="malformed"?e("\u65E7\u7248\u8BB0\u4E0B\u7684\u7ECF\u9A8C\u683C\u5F0F\u6709\u8BEF"):e("\u957F\u671F\u6CA1\u6709\u7528\u4E0A")}k(lu,"Le"),E(lu,"retiredWhy");function cu(t){return t.risk.map(n=>e(Fu[n]??n)).join(e("\u3001"))}k(cu,"_e"),E(cu,"riskText");function Vu(t){switch(t.status){case"active":return e("\u5DF2\u542F\u7528");case"candidate":return e("\u89C2\u5BDF\u4E2D");case"awaiting_user":return e("\u5F85\u4F60\u786E\u8BA4");case"retired":return e("\u5DF2\u9000\u5F79");case"undone":return e("\u5DF2\u64A4\u9500");case"expired":return e("\u5DF2\u8FC7\u671F")}}k(Vu,"Rn"),E(Vu,"statusLabel");function uu(t){switch(t.activatedBy){case"sessions":return F(e("{n} \u4E2A\u4F1A\u8BDD\u5370\u8BC1"),{n:t.sessions.length});case"proof":return e("\u68C0\u67E5\u901A\u8FC7\u5370\u8BC1");case"user":return e("\u4F60\u786E\u8BA4");case"import":return e("\u4ECE DAL Code \u5BFC\u5165");default:return""}}k(uu,"oe"),E(uu,"activatedText");function K(t){const n=t.lesson;switch(t.kind){case"activated":return n?F(e("\u5B66\u5230\u4E00\u6761\u7ECF\u9A8C\u5E76\u5DF2\u542F\u7528 [{id}]\uFF1A{content}\uFF08{why}\uFF1B\u64A4\u9500\uFF1A/lessons undo {id}\uFF09"),{id:n.id,content:n.content,why:uu(n)}):void 0;case"awaiting_user":return n?F(e("\u6709\u4E00\u6761\u6D89\u53CA{risk}\u7684\u7ECF\u9A8C\u9700\u8981\u4F60\u786E\u8BA4\u540E\u624D\u4F1A\u542F\u7528 [{id}]\uFF1A{content}\uFF08\u542F\u7528\uFF1A/lessons approve {id}\uFF1B\u4E0D\u8981\uFF1A/lessons undo {id}\uFF09"),{id:n.id,content:n.content,risk:cu(n)}):void 0;case"retired":return n?F(e("\u7ECF\u9A8C [{id}] \u5DF2\u9000\u5F79\uFF1A{why}"),{id:n.id,why:lu(n)}):void 0;case"skill_proposed":return t.draft?Ku(t.draft):void 0;case"skill_reverted":return F(e("\u6280\u80FD\u300C{name}\u300D\u91C7\u7EB3\u6539\u52A8\u540E\u7684 {total} \u6B21\u4F7F\u7528\u91CC\u6709 {bad} \u6B21\u88AB\u7EA0\u6B63\u6216\u5931\u8D25\uFF0C\u6BD4\u6539\u52A8\u524D\u5DEE\uFF0C\u5DF2\u81EA\u52A8\u9000\u56DE\u4E0A\u4E00\u7248\uFF08{id}\uFF09\u3002"),{name:t.skill??"",total:t.uses?.total??0,bad:t.uses?.bad??0,id:t.draft?.id??t.proposalId??""});case"imported":return F(e("\u5DF2\u5BFC\u5165 DAL Code \u4E2D\u4FDD\u7559\u7684 {n} \u6761\u7ECF\u9A8C"),{n:t.count??0})}}k(K,"G"),E(K,"noticeText");function du(t){return t.scope==="project"?e("\u9879\u76EE\u6280\u80FD"):e("\u4E2A\u4EBA\u6280\u80FD")}k(du,"Ce"),E(du,"scopeLabel");function Ku(t){const n={name:t.name,id:t.id,scope:du(t),reason:t.scopeReason??""};switch(t.kind){case"improve":return F(e("\u540C\u4E00\u5957\u6B65\u9AA4\u5DF2\u5728 3 \u4E2A\u4F1A\u8BDD\u91CC\u91CD\u590D\u51FA\u73B0\uFF0C\u5BF9\u5DF2\u6709\u6280\u80FD\u300C{name}\u300D\u63D0\u4E86\u4E00\u5904\u8865\u5145\uFF08{scope}\uFF1A{reason}\uFF09\u3002\u67E5\u770B\u6539\u52A8\uFF1A/lessons skills\uFF1B\u91C7\u7528\uFF1A/lessons skill accept {id}"),n);case"split":return F(e("\u540C\u4E00\u5957\u6B65\u9AA4\u5DF2\u5728 3 \u4E2A\u4F1A\u8BDD\u91CC\u91CD\u590D\u51FA\u73B0\uFF1B\u76F8\u5173\u6280\u80FD\u5DF2\u7ECF\u5F88\u957F\uFF0C\u5EFA\u8BAE\u628A\u8865\u5145\u62C6\u6210\u65B0\u6280\u80FD\u300C{name}\u300D\uFF08{scope}\uFF1A{reason}\uFF09\u3002\u67E5\u770B\uFF1A/lessons skills\uFF1B\u91C7\u7528\uFF1A/lessons skill accept {id}"),n);default:return F(e("\u540C\u4E00\u5957\u6B65\u9AA4\u5DF2\u5728 3 \u4E2A\u4F1A\u8BDD\u91CC\u91CD\u590D\u51FA\u73B0\uFF0C\u8D77\u8349\u4E86\u6280\u80FD\u300C{name}\u300D\uFF08{scope}\uFF1A{reason}\uFF09\u3002\u67E5\u770B\uFF1A/lessons skills\uFF1B\u91C7\u7528\uFF1A/lessons skill accept {id}"),n)}}k(Ku,"$n"),E(Ku,"proposalNotice");const be={new:"\u65B0\u6280\u80FD",improve:"\u6539\u8FDB\u5DF2\u6709\u6280\u80FD",split:"\u62C6\u5206"};function Mu(t){const n=t.kind??"new",i=[`[${t.id}] ${e(be[n]??n)} \xB7 ${t.name} \xB7 ${du(t)}${t.scopeReason?`\uFF08${t.scopeReason}\uFF09`:""}`];return t.risk&&t.risk.length>0&&i.push(F(e(" \u6D89\u53CA{risk}\uFF0C\u91C7\u7528\u65F6\u9700\u8981\u786E\u8BA4"),{risk:t.risk.map(s=>e(Fu[s]??s)).join(e("\u3001"))})),t.evidence&&t.evidence.length>0&&i.push(e(" \u4F9D\u636E\uFF1A"),...t.evidence.map(s=>` ${s.at.slice(0,16).replace("T"," ")} ${s.sessionId.slice(-8)} ${s.note}`)),i.push(t.diff?t.diff:t.content),i.join(`
|
|
4
|
+
`)}k(Mu,"jn"),E(Mu,"proposalBlock");const je=new Set(["active","awaiting_user","candidate"]);function pu(t){const n=t.filter(i=>je.has(i.status));return{inUse:n,count:E(i=>t.filter(s=>s.status===i).length,"count"),helpful:n.reduce((i,s)=>i+s.helpful,0),harmful:n.reduce((i,s)=>i+s.harmful,0)}}k(pu,"Re"),E(pu,"tallyLessons");function Hu(t){const n=t.helpful+t.harmful>0?` \xB7 +${t.helpful}/-${t.harmful}`:"",i=t.scope==="user"?e("\u4E2A\u4EBA"):e("\u9879\u76EE");let s="";return t.status==="active"?s=uu(t)?` \xB7 ${uu(t)}`:"":t.status==="candidate"?s=` \xB7 ${F(e("{n}/2 \u4E2A\u4F1A\u8BDD"),{n:t.sessions.length})}`:t.status==="awaiting_user"&&(s=` \xB7 ${F(e("\u6D89\u53CA{risk}"),{risk:cu(t)})}`),`[${t.id}] ${i} \xB7 ${Vu(t)}${s}${n}
|
|
5
|
+
${t.content}`}k(Hu,"xn"),E(Hu,"lessonLine");function Eu(t={}){return E(function(n){de(n,t.evolveAgentDir??J());const i=Tu(),s=new te({...t,dailyCap:t.dailyCap??i.dailyCap,reflectCap:t.reflectCap??i.reflectCap});let g,w,x=Promise.resolve();const L={flush:E(()=>x,"flush"),learner:s,sections:E(()=>g?.sections,"sections")};t.onReady?.(L);const j=E((o,u,r="info")=>{o.hasUI&&o.ui.notify(u,r)},"say"),T=E(()=>n.getCommands().filter(o=>o.source==="skill"&&o.name.startsWith("skill:")).map(o=>({name:o.name.slice(6),description:o.description??"",filePath:o.sourceInfo.path,...ou(o.sourceInfo.path,o.sourceInfo,s.root)})),"hostSkills"),eu=E(o=>({list:T,search:E(u=>(X()?.search(u,o,6)??[]).filter(r=>r.source!=="local").map(r=>({name:r.name,description:r.description,origin:"cloud"})),"search"),text:E(async u=>{if(u.filePath)try{return z(u.filePath,"utf8")}catch{return}return X()?.load(u.name)},"text")}),"catalog"),Du=E(o=>{const u=O(o);return T().find(r=>r.filePath&&O(r.filePath)===u)},"refByPath"),Wu=E(o=>{if(process.env.DAL_SKILL_REVISIONS==="off")return;let u;try{u=Zu("skills")}catch{return}if(!u.ok)return;const r=new Set(u.value.revoked.map(p=>p.id)),d=T();for(const p of fe(u.value.rows)){const l=d.find(D=>D.name===p.skill&&!wu(D));if(!l?.filePath)continue;const B=s.now();if(r.has(`${p.skill}--${p.id}`)){Ae(s.root,l,p.id,B).kind==="restored"&&j(o,F(e("\u6280\u80FD\u300C{name}\u300D\u7684\u66F4\u65B0 {id} \u5DF2\u88AB\u64A4\u56DE\uFF0C\u5DF2\u9000\u56DE\u4E0A\u4E00\u7248\u3002"),{name:l.name,id:p.id}),"warning");continue}let v;try{v=z(l.filePath,"utf8")}catch{continue}Ee(s.root,l,v,p,"market",B).kind==="adopted"&&j(o,F(e("\u6280\u80FD\u300C{name}\u300D\u5DF2\u66F4\u65B0\u4E3A\u7ECF\u8FC7\u8BC4\u6D4B\u7684\u65B0\u7248\uFF08{id}\uFF09\u3002\u4E0D\u6EE1\u610F\u53EF\u4EE5\u9000\u56DE\uFF1A/lessons skill revert {name}"),{name:l.name,id:p.id}))}},"adoptMarketRevisions"),fu=E((o,u)=>{const r=u.length>0?u:[...new Set([...M,...V])];if(r.length===0)return e("\u8FD9\u6B21\u4F1A\u8BDD\u8FD8\u6CA1\u6709\u7528\u5230\u6280\u80FD\uFF0C\u6CA1\u6709\u53EF\u4EE5\u8BB0\u7684\u3002");const d=o.sessionManager.getSessionId(),p=s.skillFeedback(o.cwd,d,r,eu(o.cwd));for(const l of p){const B=K(l);B&&j(o,B,"warning"),mu(l)}return F(e("\u5DF2\u8BB0\u4E0B\u5BF9\u6280\u80FD {names} \u8FD9\u6B21\u4EA7\u51FA\u7684\u8D1F\u53CD\u9988\uFF1B\u6539\u52A8\u540E\u7684\u7248\u672C\u6301\u7EED\u53D8\u5DEE\u4F1A\u81EA\u52A8\u9000\u56DE\u4E0A\u4E00\u7248\u3002"),{names:r.join(e("\u3001"))})},"rateBad");n.events.on(Iu,o=>{const u=o;if(!i.enabled||i.frozen||!N||u?.rating!=="bad")return;const r=Array.isArray(u.skills)?u.skills.filter(d=>typeof d=="string"):[];fu(N,r)});const tu=E((o,u,r)=>{if(wu(o))return;const d=Su(o),p=_u(s.root,d);if(!p||p.kind!=="overlay"||p.patches.length===0)return;const l=s.project(r.cwd),B=l.key,v=ge(u,p.patches,{marker:!0,projectKey:B}),D=i.frozen?[]:ve(s.root,d,v.conflicts,s.now());for(const c of D){const C=p.patches.find(y=>y.id===c.patchId)?.proposalId??c.patchId;j(r,F(e("\u6280\u80FD\u300C{name}\u300D\u5DF2\u66F4\u65B0\uFF0C\u672C\u673A\u8865\u5145\u9488\u5BF9\u7684\u300C{section}\u300D\u4E00\u6BB5\u53D8\u4E86\uFF0C\u8FD9\u6761\u8865\u5145\u6682\u4E0D\u751F\u6548\uFF08{id}\uFF09\u3002\u4FDD\u7559\u5E76\u8DDF\u968F\u65B0\u7248\uFF1A/lessons skill keep {id}\uFF1B\u4E0D\u8981\u4E86\uFF1A/lessons undo {id}"),{name:o.name,section:c.section,id:C}),"warning"),n.emitHostEvent(Lu,{schemaVersion:1,projectKey:l.key,projectRoot:l.root,id:C,skill:o.name,section:c.section,reason:c.reason})}return v.applied.length>0?v.text:void 0},"mergeSupplements");n.on("resources_discover",o=>{if(i.enabled)try{const u=he(s.projectDir(s.project(o.cwd)));return Ju(u)?{skillPaths:[u]}:void 0}catch{return}});let N;const V=new Set,M=new Set;globalThis[Se]=((o,u)=>{if(!i.enabled||!N)return u;V.add(o.name);const r=o.source==="local"&&o.path?Du(o.path):{name:o.name,description:"",origin:"cloud"};return(r&&tu(r,u,N))??u}),n.on("tool_result",(o,u)=>{if(!i.enabled||o.isError)return;const r=o.content.length===1&&o.content[0].type==="text"?o.content[0].text:void 0;if(r===void 0)return;let d;if(o.toolName==="read"){const l=o.input;if(typeof l.path!="string"||l.offset!==void 0||l.limit!==void 0||/\n\n\[(?:Showing lines|\d+ more lines)/.test(r))return;d=Du(Qu(l.path)?l.path:Bu(u.cwd,l.path))}if(!d)return;const p=tu(d,r,u);return p?{content:[{type:"text",text:p}]}:void 0}),n.on("input",(o,u)=>{if(!i.enabled||!o.text.startsWith("/skill:"))return{action:"continue"};const r=o.text.indexOf(" "),d=r===-1?o.text.slice(7):o.text.slice(7,r),p=r===-1?"":o.text.slice(r+1).trim(),l=T().find(c=>c.name===d);if(!l?.filePath)return{action:"continue"};let B;try{B=ue(z(l.filePath,"utf8")).trim()}catch{return{action:"continue"}}const v=tu(l,B,u);if(!v)return{action:"continue"};const D=`<skill name="${l.name}" location="${l.filePath}">
|
|
6
|
+
References are relative to ${Gu(l.filePath)}.
|
|
7
7
|
|
|
8
|
-
${
|
|
9
|
-
</skill>`;return{action:"transform",text:
|
|
8
|
+
${v.trim()}
|
|
9
|
+
</skill>`;return{action:"transform",text:p?`${D}
|
|
10
10
|
|
|
11
|
-
${
|
|
12
|
-
`)},"print");n.registerCommand("lessons",{description:e("\u5B66\u5230\u7684\u7ECF\u9A8C\uFF1A\u5217\u8868\u3001\u7EDF\u8BA1\u3001\u64A4\u9500\u3001\u786E\u8BA4\u3001\u9879\u76EE\u5730\u56FE\u3001\u6280\u80FD\u8349\u7A3F\uFF08/lessons stats|map|skills|undo|approve\uFF09"),getArgumentCompletions:
|
|
13
|
-
`));return}
|
|
14
|
-
`));return}if(
|
|
15
|
-
`));return}if(
|
|
16
|
-
`));return}if(
|
|
17
|
-
`));return}if(
|
|
18
|
-
`));return}const
|
|
11
|
+
${p}`:D}}),n.on("session_start",(o,u)=>{if(g=void 0,w=Nu(u),N=u,V.clear(),M.clear(),!i.enabled||i.frozen)return;Wu(u);const r=iu(n,u,i.model),d=E(async()=>{for(const{project:p,report:l}of await s.finishPending(r))Au(u,l,p)},"resume");x=x.then(d,d).catch(()=>{})}),n.on("before_agent_start",(o,u)=>{if(!i.enabled)return;const r=u.sessionManager.getSessionId();if(!g||g.sessionId!==r)try{const l=!!o.systemPromptOptions.sections[$e],B=o.messageType==="user"?o.prompt:void 0,v=i.frozen?s.preview(u.cwd,{hostHasLearnedSection:l,request:B}):s.startSession(u.cwd,{hostHasLearnedSection:l,request:B});if(g={sessionId:r,sections:v},v.imported>0){const c=K({kind:"imported",count:v.imported});c&&j(u,c)}const D=s.project(u.cwd);for(const c of v.retired){if(c.to!=="retired")continue;const C=K({kind:"retired",lesson:c.lesson});C&&j(u,C),n.emitHostEvent(ie,{schemaVersion:1,lesson:Y(c.lesson,D)})}}catch{g={sessionId:r,sections:{project:s.project(u.cwd),lessonIds:[],lessonTokens:0,mapTokens:0,imported:0,retired:[]}}}const{lessons:d,map:p}=g.sections;d&&(o.systemPromptOptions.sections[$u]=d),p&&(o.systemPromptOptions.sections[Pu]=p)});const Au=E((o,u,r)=>{for(const d of u.notices){const p=K(d);if(p&&j(o,p,d.kind==="awaiting_user"||d.kind==="skill_reverted"?"warning":"info"),mu(d,r),d.lesson&&(d.kind==="activated"||d.kind==="awaiting_user"||d.kind==="retired")){const l=ae(d.kind);l&&n.emitHostEvent(l,{schemaVersion:1,lesson:Y(d.lesson,r)})}}for(const d of u.proposed)d.status==="candidate"&&n.emitHostEvent(oe,{schemaVersion:1,lesson:Y(d,r)})},"deliver");n.on("agent_end",(o,u)=>{if(!i.enabled||i.frozen)return;const r=u.sessionManager.getSessionId(),d=g?.sessionId===r?g.sections.lessonIds:[],p=w,l=o.messages,B=l.filter(A=>A.role==="assistant").map(au).filter(Boolean).at(-1);B&&(w=B);const v=u.cwd,D=iu(n,u,i.model),c=eu(v),C=[...V];V.clear();const y=[...M],f=E(async()=>{const A=s.project(v),S=await s.onRunEnd(l,{cwd:v,sessionId:r,injected:d,previousAssistant:p,complete:D,skills:c,loadedSkills:C,earlierSkills:y});for(const $ of[...C,...we(S.signals)])M.add($);Au(u,S,A);for(const $ of S.taskNotes)n.appendEntry(Ru,{content:$.content,section:$.section,at:new Date().toISOString()})},"work");x=x.then(f,f).catch(()=>{})}),n.on("session_shutdown",async()=>{let o=!1;const u=x.then(()=>{o=!0});await Promise.race([u,new Promise(r=>setTimeout(r,t.shutdownWaitMs??5e3).unref?.())]),o||s.keepUnfinished()});const mu=E((o,u)=>{const r=o.draft,d=u?{projectKey:u.key,projectRoot:u.root}:{};o.kind==="skill_proposed"&&r?n.emitHostEvent(bu,{schemaVersion:1,...d,id:r.id,kind:r.kind??"new",skill:r.name,scope:r.scope??"user",scopeReason:r.scopeReason??"",diff:r.diff??r.content,evidenceCount:r.evidence?.length??0,risk:r.risk??[]}):o.kind==="skill_reverted"&&n.emitHostEvent(ju,{schemaVersion:1,...d,id:r?.id??o.proposalId??"",skill:o.skill??"",uses:o.uses??{total:0,bad:0}})},"emitSkillEvent"),Cu=E(async o=>{try{await o.reload()}catch{}},"reloadSkills"),m=E((o,u)=>{o.hasUI?o.ui.notify(u,"info"):process.stdout.write(`${u}
|
|
12
|
+
`)},"print");n.registerCommand("lessons",{description:e("\u5B66\u5230\u7684\u7ECF\u9A8C\uFF1A\u5217\u8868\u3001\u7EDF\u8BA1\u3001\u64A4\u9500\u3001\u786E\u8BA4\u3001\u9879\u76EE\u5730\u56FE\u3001\u6280\u80FD\u8349\u7A3F\uFF08/lessons stats|map|skills|undo|approve\uFF09"),getArgumentCompletions:E(o=>{const u=["stats","map","skills","undo ","approve ","skill accept ","skill discard ","skill keep ","skill export ","skill bad ","skill revert ","skill history "].filter(r=>r.startsWith(o.trimStart()));return u.length>0?u.map(r=>({value:r,label:r.trim()})):null},"getArgumentCompletions"),handler:E(async(o,u)=>{await x;const[r="",...d]=o.trim().split(/\s+/).filter(Boolean),p=s.project(u.cwd),l=s.projectDir(p),B=s.now(),v=E(D=>D.startsWith("u-")?s.userDir():l,"findTarget");if(r===""||r==="list"){const D=[...G(s.userDir()).lessons,...G(l).lessons],c=pu(D),C=c.inUse,y={retired:c.count("retired"),undone:c.count("undone"),expired:c.count("expired")},f=y.retired+y.undone+y.expired>0?[F(e("\u53E6\u6709\u5DF2\u9000\u5F79 {retired} \xB7 \u5DF2\u64A4\u9500 {undone} \xB7 \u5DF2\u8FC7\u671F {expired}\uFF0C\u4E0D\u518D\u4F7F\u7528\uFF08/lessons stats \u67E5\u770B\uFF09"),y)]:[];if(C.length===0){if(f.length>0){m(u,[e("\u6CA1\u6709\u5728\u7528\u7684\u7ECF\u9A8C\u3002"),...f].join(`
|
|
13
|
+
`));return}m(u,e("\u8FD8\u6CA1\u6709\u5B66\u5230\u7ECF\u9A8C\u3002\u51FA\u73B0\u5931\u8D25\u540E\u4FEE\u597D\u3001\u4F60\u7EA0\u6B63\u52A9\u624B\u3001\u6216\u53CD\u590D\u7ED5\u8DEF\u65F6\uFF0C\u4F1A\u81EA\u52A8\u8BB0\u4E0B\u3002"));return}const A={awaiting_user:0,active:1,candidate:2};C.sort((S,$)=>(A[S.status]??3)-(A[$.status]??3)||S.id.localeCompare($.id)),m(u,[e("\u5B66\u5230\u7684\u7ECF\u9A8C\uFF08\u5DF2\u542F\u7528\u7684\u4F1A\u5728\u6BCF\u4E2A\u65B0\u4F1A\u8BDD\u5F00\u5934\u4EA4\u7ED9\u52A9\u624B\uFF09\uFF1A"),...C.map(Hu),...f,e("\u64A4\u9500\uFF1A/lessons undo <id> \xB7 \u786E\u8BA4\uFF1A/lessons approve <id> \xB7 \u7EDF\u8BA1\uFF1A/lessons stats")].join(`
|
|
14
|
+
`));return}if(r==="undo"&&/^s-\d{4,6}$/.test(d[0]??"")){const D=d[0],c=ke(s.root,l,D,B);if(c.kind==="not_latest"){m(u,F(e("\u8FD9\u4E2A\u6280\u80FD\u4E4B\u540E\u8FD8\u6709\u6539\u52A8 {newer}\uFF0C\u5148\u64A4\u9500\u5B83\uFF1A/lessons undo {newer}"),{newer:c.newer}));return}if(c.kind==="changed_outside"){m(u,F(e("\u6280\u80FD\u300C{name}\u300D\u5728\u91C7\u7528\u4E4B\u540E\u88AB\u624B\u52A8\u6539\u8FC7\uFF0C\u4E3A\u4E86\u4E0D\u8986\u76D6\u4F60\u7684\u4FEE\u6539\uFF0C\u6CA1\u6709\u64A4\u9500\u3002"),{name:c.skill}));return}if(c.kind==="not_found"){m(u,F(e("\u6CA1\u6709\u5DF2\u91C7\u7528\u7684\u6280\u80FD\u6539\u52A8 {id}"),{id:D}));return}n.emitHostEvent(Q,{schemaVersion:1,projectKey:p.key,projectRoot:p.root,id:D,status:"undone",skill:c.draft.name}),m(u,F(e("\u5DF2\u64A4\u9500\u6280\u80FD\u6539\u52A8 [{id}]\uFF0C\u6280\u80FD\u56DE\u5230\u91C7\u7528\u4E4B\u524D\u7684\u7248\u672C\u3002"),{id:D})),c.draft.kind!=="improve"&&await Cu(u);return}if(r==="undo"||r==="approve"){const D=d[0]??"";if(!/^[lu]-\d{4,6}$/.test(D)){m(u,F(e("\u7528\u6CD5\uFF1A/lessons {sub} <id>\uFF08\u4F8B\u5982 l-0001\uFF09"),{sub:r}));return}const c=v(D);let C;if(ce(c,y=>{const f=r==="undo"?le(y,D,B):Fe(y,D,B);return C=f.lesson,f.lesson?f.doc:void 0}),!C){m(u,F(e("\u6CA1\u6709\u627E\u5230\u7ECF\u9A8C {id}"),{id:D}));return}m(u,r==="undo"?F(e("\u5DF2\u64A4\u9500\u7ECF\u9A8C [{id}]\uFF0C\u4ECE\u4E0B\u4E00\u4E2A\u4F1A\u8BDD\u8D77\u4E0D\u518D\u4F7F\u7528\uFF0C\u4E5F\u4E0D\u4F1A\u518D\u6B21\u63D0\u8BAE\u3002"),{id:D}):F(e("\u5DF2\u542F\u7528\u7ECF\u9A8C [{id}]\uFF0C\u4ECE\u4E0B\u4E00\u4E2A\u4F1A\u8BDD\u8D77\u4EA4\u7ED9\u52A9\u624B\u3002"),{id:D})),n.emitHostEvent(re,{schemaVersion:1,action:r,status:C.status,changed:!0,lesson:Y(C,D.startsWith("l-")?p:void 0)});return}if(r==="stats"){const D=[...G(s.userDir()).lessons,...G(l).lessons],{count:c,helpful:C,harmful:y}=pu(D),f=xe(s.root,B),A=yu(gu(l),p.root,B),S=vu(A),$=g?.sections??s.preview(u.cwd),R=D.filter(a=>a.status==="active"&&a.helpful>0).sort((a,b)=>b.helpful-a.helpful).slice(0,3),_=D.filter(a=>a.status==="active"&&a.harmful>0&&!hu(a)),I=D.filter(a=>a.status==="active"&&hu(a)),H=[F(e("\u7ECF\u9A8C\uFF1A\u5DF2\u542F\u7528 {active} \xB7 \u5F85\u786E\u8BA4 {awaiting} \xB7 \u89C2\u5BDF\u4E2D {candidate} \xB7 \u5DF2\u9000\u5F79 {retired} \xB7 \u5DF2\u64A4\u9500 {undone} \xB7 \u5DF2\u8FC7\u671F {expired}"),{expired:c("expired"),active:c("active"),awaiting:c("awaiting_user"),candidate:c("candidate"),retired:c("retired"),undone:c("undone")}),F(e("\u6548\u679C\uFF08\u5728\u7528\u7684\u7ECF\u9A8C\uFF09\uFF1A\u5E2E\u4E0A\u5FD9 {helpful} \u6B21 \xB7 \u5E2E\u5012\u5FD9 {harmful} \u6B21"),{helpful:C,harmful:y}),F(e("\u9879\u76EE\u5730\u56FE\uFF1A{facts} \u6761\u4E8B\u5B9E\u53EF\u7528 \xB7 {stale} \u6761\u5DF2\u8FC7\u65F6\u5F85\u5237\u65B0"),{facts:S.facts,stale:A.stale.length}),F(e("\u672C\u4F1A\u8BDD\u6CE8\u5165\uFF1A\u7ECF\u9A8C\u7EA6 {lt} tokens \xB7 \u9879\u76EE\u5730\u56FE\u7EA6 {mt} tokens"),{lt:$?.lessonTokens??0,mt:$?.mapTokens??0}),F(e("\u4ECA\u5929\u7684\u63D0\u70BC\u8C03\u7528\uFF1A{runs}/{cap}\uFF08\u8F93\u5165 {input} \xB7 \u8F93\u51FA {output} tokens\uFF09"),{runs:f.runs,cap:s.dailyCap,input:f.inputTokens,output:f.outputTokens}),F(e("\u4ECA\u5929\u7684\u6548\u679C\u5224\u5B9A\u8C03\u7528\uFF1A{runs}/{cap}"),{runs:f.reflectRuns,cap:s.reflectCap}),...R.length>0?[e("\u6700\u6709\u7528\uFF1A"),...R.map(a=>` [${a.id}] +${a.helpful} ${a.content}`)]:[],..._.length>0?[e("\u7559\u610F\uFF08\u5E2E\u5012\u5FD9\u8FC7\uFF09\uFF1A"),..._.map(a=>` [${a.id}] -${a.harmful} ${a.content}`)]:[],...I.length>0?[e("\u6682\u505C\u6CE8\u5165\uFF08\u5E2E\u5012\u5FD9\u4E0D\u5C11\u4E8E\u5E2E\u5FD9\uFF0C\u5E2E\u4E0A\u5FD9\u591A\u4E8E\u5E2E\u5012\u5FD9\u540E\u6062\u590D\uFF09\uFF1A"),...I.map(a=>` [${a.id}] +${a.helpful}/-${a.harmful} ${a.content}`)]:[]],h=D.filter(a=>a.status==="retired");h.length>0&&H.push(e("\u5DF2\u9000\u5F79\uFF1A"),...h.map(a=>` [${a.id}] ${lu(a)} \xB7 +${a.helpful}/-${a.harmful} \xB7 ${a.content}`)),m(u,H.join(`
|
|
15
|
+
`));return}if(r==="map"){const D=yu(gu(l),p.root,B),c=[vu(D).text??e("\u9879\u76EE\u5730\u56FE\u8FD8\u662F\u7A7A\u7684\uFF1A\u6210\u529F\u8FD0\u884C\u6D4B\u8BD5/\u6784\u5EFA\u547D\u4EE4\u3001\u67E5\u627E\u5E76\u6253\u5F00\u6587\u4EF6\u540E\u4F1A\u81EA\u52A8\u8BB0\u4E0B\u3002")];D.stale.length>0&&c.push(e("\u5DF2\u8FC7\u65F6\uFF08\u4E0B\u6B21\u6210\u529F\u540E\u5237\u65B0\uFF09\uFF1A"),...D.stale.map(C=>` ${C.fact}`)),m(u,c.join(`
|
|
16
|
+
`));return}if(r==="skills"){const D=ku(l).drafts.filter(f=>f.status==="proposed"),c=xu(s.root).flatMap(f=>f.conflicts.map(A=>({record:f,conflict:A}))),C=xu(s.root).filter(f=>f.tracking&&!f.tracking.settled);if(D.length===0&&c.length===0&&C.length===0){m(u,e("\u6CA1\u6709\u5F85\u91C7\u7528\u7684\u6280\u80FD\u63D0\u8BAE\u3002\u540C\u4E00\u5957\u6B65\u9AA4\u5728 3 \u4E2A\u4F1A\u8BDD\u91CC\u91CD\u590D\u540E\uFF0C\u4F1A\u6539\u8FDB\u76F8\u5173\u6280\u80FD\u6216\u8D77\u8349\u65B0\u6280\u80FD\u3002"));return}const y=D.map(Mu);c.length>0&&y.push(e("\u672C\u673A\u8865\u5145\u4E0E\u539F\u6280\u80FD\u7684\u65B0\u7248\u51B2\u7A81\uFF08\u6682\u4E0D\u751F\u6548\uFF09\uFF1A"),...c.map(({record:f,conflict:A})=>` [${f.patches.find(S=>S.id===A.patchId)?.proposalId??A.patchId}] ${f.name} \xB7 ${A.section}`),e("\u4FDD\u7559\u5E76\u8DDF\u968F\u65B0\u7248\uFF1A/lessons skill keep <id> \xB7 \u4E0D\u8981\u4E86\uFF1A/lessons undo <id>")),C.length>0&&y.push(e("\u89C2\u5BDF\u6548\u679C\u4E2D\uFF08\u53D8\u5DEE\u4F1A\u81EA\u52A8\u9000\u56DE\u4E0A\u4E00\u7248\uFF09\uFF1A"),...C.map(f=>{const A=f.tracking?.uses??[],S=A.filter($=>$.outcome!=="success").length;return` [${f.tracking?.proposalId}] ${f.name} \xB7 ${F(e("\u5DF2\u7528 {n} \u6B21\uFF0C{bad} \u6B21\u4E0D\u987A"),{n:A.length,bad:S})} \xB7 ${F(e("{n} \u4E2A\u7248\u672C"),{n:f.versions.length})}`})),y.push(e("\u91C7\u7528\uFF1A/lessons skill accept <id> [\u540D\u5B57] [--scope project|user] \xB7 \u4E22\u5F03\uFF1A/lessons skill discard <id> \xB7 \u64A4\u9500\u5DF2\u91C7\u7528\u7684\uFF1A/lessons undo <id>")),m(u,y.join(`
|
|
17
|
+
`));return}if(r==="skill"){const D=d.filter(h=>h.startsWith("--")),c=d.indexOf("--scope"),C=c>=0?d[c+1]:void 0,y=d.filter((h,a)=>!h.startsWith("--")&&!(c>=0&&a===c+1)),[f="",A="",S]=y,$=q(J(),"skills");if(f==="keep"){const h=await Be(s.root,A,async a=>{const b=T().find(W=>W.name===a.name);return b?eu(u.cwd).text(b):X()?.load(a.name)},B);m(u,h.kind==="kept"?F(e("\u5DF2\u4FDD\u7559 {id} \u7684\u8865\u5145\uFF0C\u8DDF\u968F\u6280\u80FD\u300C{name}\u300D\u7684\u65B0\u7248\u751F\u6548\u3002"),{id:A,name:h.skill}):h.kind==="unreadable"?F(e("\u8BFB\u4E0D\u5230\u6280\u80FD\u300C{name}\u300D\u7684\u5F53\u524D\u5185\u5BB9\uFF0C\u7A0D\u540E\u518D\u8BD5\u3002"),{name:h.skill}):F(e("\u6CA1\u6709\u51B2\u7A81\u4E2D\u7684\u8865\u5145 {id}"),{id:A}));return}if(f==="bad"){m(u,fu(u,A?[A]:[]));return}if(f==="revert"||f==="history"){const h=T().find(P=>P.name===A)??{name:A,description:"",origin:"cloud"},a=A?_u(s.root,Su(h)):void 0;if(!a){m(u,F(e("\u6280\u80FD\u300C{name}\u300D\u6CA1\u6709\u672C\u673A\u91C7\u7528\u8FC7\u7684\u6539\u52A8\u3002"),{name:A}));return}if(f==="history"){m(u,[F(e("\u6280\u80FD\u300C{name}\u300D\u7684\u7248\u672C\uFF1A"),{name:a.name}),...a.versions.map(P=>{const U=P.meta,Uu=U?` \xB7 ${String(U.source)}${U.delta!==void 0?` \u0394${String(U.delta)}`:""}`:"";return` v${P.v} ${P.at.slice(0,16)} ${P.reason}${P.proposalId?` [${P.proposalId}]`:""}${Uu}`})].join(`
|
|
18
|
+
`));return}const b=De(a);if(!b?.proposalId){m(u,F(e("\u6280\u80FD\u300C{name}\u300D\u5DF2\u7ECF\u662F\u539F\u59CB\u7248\u672C\u3002"),{name:a.name}));return}const W=ye(s.root,a.key,b.proposalId,"undo",B);m(u,W.kind==="restored"?F(e("\u5DF2\u628A\u6280\u80FD\u300C{name}\u300D\u9000\u56DE\u4E0A\u4E00\u7248\uFF08\u64A4\u9500 {id}\uFF09\u3002"),{name:a.name,id:b.proposalId}):F(e("\u6CA1\u80FD\u9000\u56DE\u6280\u80FD\u300C{name}\u300D\uFF1A{why}"),{name:a.name,why:W.kind}));return}if(f==="export"){const h=(A||"").toLowerCase(),a=Ce(l,p.root,Xu,h,u.isProjectTrusted()),b={exported:F(e("\u5DF2\u628A\u9879\u76EE\u6280\u80FD {name} \u5BFC\u51FA\u5230\u9879\u76EE\u91CC\uFF1A{path}\uFF08\u53EF\u4EE5\u63D0\u4EA4\u8FDB\u4ED3\u5E93\u7ED9\u56E2\u961F\u7528\uFF09"),{name:h,path:a.kind==="exported"?a.path:""}),exists:F(e("\u9879\u76EE\u91CC\u5DF2\u6709\u540C\u540D\u6280\u80FD\uFF1A{path}"),{path:a.kind==="exists"?a.path:""}),untrusted:e("\u8FD9\u4E2A\u9879\u76EE\u8FD8\u6CA1\u6709\u88AB\u4FE1\u4EFB\uFF0C\u9879\u76EE\u91CC\u7684\u6280\u80FD\u4E0D\u4F1A\u52A0\u8F7D\uFF1B\u5148\u4FE1\u4EFB\u9879\u76EE\u518D\u5BFC\u51FA\u3002"),not_found:F(e("\u6CA1\u6709 DAL \u4E3A\u672C\u9879\u76EE\u4FDD\u5B58\u7684\u6280\u80FD {name}"),{name:h})};m(u,b[a.kind]);return}const R=ku(l).drafts.find(h=>h.id===A&&h.status==="proposed");if(!R||f!=="accept"&&f!=="discard"){m(u,e("\u7528\u6CD5\uFF1A/lessons skill accept|discard <id> [\u540D\u5B57] [--scope project|user] \xB7 keep <id> \xB7 export <\u540D\u5B57> \xB7 bad [\u6280\u80FD]\uFF08\u8FD9\u6B21\u4EA7\u51FA\u4E0D\u597D\uFF09\xB7 revert <\u6280\u80FD>\uFF08\u9000\u56DE\u4E0A\u4E00\u7248\uFF09\xB7 history <\u6280\u80FD>\uFF08id \u89C1 /lessons skills\uFF09"));return}if(f==="discard"){pe(l,h=>({...h,drafts:h.drafts.map(a=>a.id===A?{...a,status:"discarded"}:a)})),n.emitHostEvent(Q,{schemaVersion:1,projectKey:p.key,projectRoot:p.root,id:A,status:"discarded",skill:R.name}),m(u,F(e("\u5DF2\u4E22\u5F03\u6280\u80FD\u8349\u7A3F {id}"),{id:A}));return}if(C!==void 0&&C!=="project"&&C!=="user"){m(u,e("\u8303\u56F4\u53EA\u80FD\u662F project \u6216 user"));return}if(R.risk&&R.risk.length>0&&!D.includes("--confirm")){const h=R.risk.map(b=>e(Fu[b]??b)).join(e("\u3001")),a=F(e("\u8FD9\u4E2A\u6280\u80FD\u6539\u52A8\u6D89\u53CA{risk}\uFF0C\u786E\u5B9A\u91C7\u7528\u5417\uFF1F"),{risk:h});if(!(u.hasUI&&await u.ui.confirm(e("\u786E\u8BA4\u91C7\u7528"),a))){m(u,F(e("\u6D89\u53CA{risk}\uFF0C\u9700\u8981\u786E\u8BA4\uFF1A/lessons skill accept {id} --confirm"),{risk:h,id:A}));return}}const _=me({root:s.root,projectDir:l,projectKey:p.key,userSkillsDir:$,id:A,...S?{name:S}:{},...C?{scope:C}:{},now:B});if(_.kind==="bad_name"){m(u,e("\u6280\u80FD\u540D\u79F0\u65E0\u6548\uFF08\u4EC5\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u3001-\uFF0C\u226464 \u5B57\u7B26\uFF09\uFF1A"));return}if(_.kind==="name_taken"){m(u,F(e("\u6280\u80FD {name} \u5DF2\u5B58\u5728\uFF0C\u6362\u4E2A\u540D\u5B57\uFF1A/lessons skill accept {id} <\u540D\u5B57>"),{name:_.name,id:A}));return}if(_.kind==="stale"){m(u,F(e("\u6280\u80FD\u300C{name}\u300D\u5728\u63D0\u8BAE\u4E4B\u540E\u88AB\u6539\u8FC7\uFF0C\u8FD9\u6761\u6539\u52A8\u5BF9\u4E0D\u4E0A\u4E86\uFF1B\u4E22\u5F03\u5B83\uFF0C\u4E0B\u6B21\u4F1A\u6309\u65B0\u5185\u5BB9\u91CD\u65B0\u63D0\u8BAE\u3002"),{name:_.skill}));return}if(_.kind==="invalid"){m(u,F(e("\u6539\u52A8\u540E\u7684\u6280\u80FD\u300C{name}\u300D\u65E0\u6CD5\u6B63\u5E38\u52A0\u8F7D\uFF08{reason}\uFF09\uFF0C\u6CA1\u6709\u5199\u5165\u3002"),{name:_.skill,reason:_.reason}));return}if(_.kind==="not_found"){m(u,F(e("\u6CA1\u6709\u627E\u5230\u6280\u80FD\u63D0\u8BAE {id}"),{id:A}));return}n.emitHostEvent(Q,{schemaVersion:1,projectKey:p.key,projectRoot:p.root,id:A,status:"accepted",skill:_.draft.name,paths:_.paths});const I=_.draft,H=I.kind==="improve"&&!I.target?.editable?e("\u4F5C\u4E3A\u672C\u673A\u8865\u5145\uFF0C\u539F\u6280\u80FD\u6587\u4EF6\u4E0D\u53D8"):_.paths.join("\u3001");m(u,I.kind==="improve"?F(e("\u5DF2\u91C7\u7528\u5BF9\u6280\u80FD\u300C{name}\u300D\u7684\u6539\u8FDB\uFF08{where}\uFF09\u3002\u4E4B\u540E\u4F1A\u89C2\u5BDF\u6548\u679C\uFF0C\u53D8\u5DEE\u4F1A\u81EA\u52A8\u9000\u56DE\uFF1B\u64A4\u9500\uFF1A/lessons undo {id}"),{name:I.target?.name??I.name,where:H,id:A}):F(e("\u5DF2\u91C7\u7528\u6280\u80FD {name}\uFF1A{path}"),{name:(S??I.name).toLowerCase(),path:_.paths.at(-1)??""})),(I.kind!=="improve"||I.target?.editable)&&await Cu(u);return}m(u,e("\u7528\u6CD5\uFF1A/lessons [stats|map|skills|undo <id>|approve <id>|skill accept|discard <id>]"))},"handler")})},"dalLearn")}k(Eu,"An"),E(Eu,"createDalLearn");var Ie=Eu();export{$u as LESSONS_SECTION,Pu as MAP_SECTION,Lu as SKILL_CONFLICT_EVENT,Iu as SKILL_FEEDBACK_CHANNEL,bu as SKILL_PROPOSAL_EVENT,Q as SKILL_RESOLVED_EVENT,ju as SKILL_REVERTED_EVENT,Ru as TASK_NOTE_ENTRY,ou as classifySkill,Eu as createDalLearn,Ie as default,ru as pickDraftingModel};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var i=Object.defineProperty;var n=(r,e)=>i(r,"name",{value:e,configurable:!0});var f=Object.defineProperty,o=n((r,e)=>f(r,"name",{value:e,configurable:!0}),"n");function t(r=process.env){const e=r.DAL_LEARN?.trim().toLowerCase();return e==="0"?"off":e==="frozen"?"frozen":"on"}n(t,"t"),o(t,"learnMode");function s(r=process.env){return t(r)==="frozen"}n(s,"s"),o(s,"isLearningFrozen");function a(r=process.env){const e=r.DAL_LEARN_REFLECT_CAP?.trim();if(!(!e||!/^\d+$/.test(e)))return Number(e)}n(a,"u"),o(a,"reflectCapOverride");export{s as isLearningFrozen,t as learnMode,a as reflectCapOverride};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var l=Object.defineProperty;var a=(e,s)=>l(e,"name",{value:s,configurable:!0});var u=Object.defineProperty,r=a((e,s)=>u(e,"name",{value:s,configurable:!0}),"r");const E="learn_lesson_proposed",t="learn_lesson_activated",n="learn_lesson_awaiting_user",o="learn_lesson_retired",_="learn_lesson_resolved";function i(e,s){const d=e.scope==="project"&&s?{projectKey:s.key,projectRoot:s.root}:{};return{schemaVersion:1,id:e.id,scope:e.scope,...d,section:e.section,content:e.content,rootCause:e.rootCause,status:e.status,risk:[...e.risk],helpful:e.helpful,harmful:e.harmful,sessionsCount:e.sessions.length,evidenceCount:e.evidence.length,created:e.created,updated:e.updated,...e.activatedAt?{activatedAt:e.activatedAt}:{},...e.activatedBy?{activatedBy:e.activatedBy}:{},...e.retiredAt?{retiredAt:e.retiredAt}:{},...e.retiredReason?{retiredReason:e.retiredReason}:{},...e.fix?{fix:{...e.fix}}:{}}}a(i,"p"),r(i,"lessonSnapshot");function c(e){switch(e){case"activated":return t;case"awaiting_user":return n;case"retired":return o;default:return}}a(c,"_"),r(c,"lessonEventForNotice");export{t as LESSON_ACTIVATED_EVENT,n as LESSON_AWAITING_USER_EVENT,E as LESSON_PROPOSED_EVENT,_ as LESSON_RESOLVED_EVENT,o as LESSON_RETIRED_EVENT,c as lessonEventForNotice,i as lessonSnapshot};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
${
|
|
3
|
-
|
|
1
|
+
var vs=Object.defineProperty;var d=(s,e)=>vs(s,"name",{value:e,configurable:!0});var Es=Object.defineProperty,u=d((s,e)=>Es(s,"name",{value:e,configurable:!0}),"a");import{join as bs}from"node:path";import{rejectLesson as ks,riskOf as U}from"./safety.js";import{codeFailed as As,commandIntent as ys,failureReason as Is,fixCommands as ws,isUntellingReason as xs}from"./signals.js";import{estimateTokens as S,num as b,readDoc as js,records as L,str as c,strList as _,updateDoc as Cs}from"./store.js";const Ss=["harmful","ineffective","unused","user","malformed"],P=2,K=60,Y=5,q=30,G=700,V=6,W=12,R=20,X=864e5,Ls=["candidate","active","awaiting_user","retired","undone","expired"],_s=["failure_then_fix","user_correction","repeated_detour","guard_denial","success_workflow","imported"],Rs=["helpful","harmful","neutral"],Fs=["deletion","permissions","credentials","network","publishing","dependencies"];function A(s){return bs(s,"lessons.json")}d(A,"N"),u(A,"lessonsPath");function Z(s){const e=c(s.id,16),o=c(s.content,400);if(!/^[lu]-\d{4,6}$/.test(e)||!o)return;const n=Ls.includes(s.status)?s.status:"candidate",t=s.fix,i=s.proof,r=s.origin;return{...s,id:e,scope:s.scope==="user"?"user":"project",section:c(s.section,40)||"general",content:o,rootCause:c(s.rootCause,400),...c(s.signature,300)?{signature:c(s.signature,300)}:{},...t&&typeof t.good=="string"?{fix:{intent:c(t.intent,20),bad:c(t.bad,200),good:c(t.good,200)}}:{},status:n,risk:_(s.risk,5,20).filter(a=>Fs.includes(a)),sessions:_(s.sessions,W,80),evidence:L(s.evidence).map(a=>({sessionId:c(a.sessionId,80),at:c(a.at,32),signal:_s.includes(a.signal)?a.signal:"user_correction",note:c(a.note,300)})).slice(-V),...i&&typeof i.at=="string"?{proof:{kind:i.kind==="outcome"?"outcome":"test",at:c(i.at,32),sessionId:c(i.sessionId,80),note:c(i.note,300)}}:{},helpful:b(s.helpful),harmful:b(s.harmful),...b(s.neutral)>0?{neutral:b(s.neutral)}:{},...b(s.injections)>0?{injections:b(s.injections)}:{},...c(s.lastInjectedAt,32)?{lastInjectedAt:c(s.lastInjectedAt,32)}:{},feedback:L(s.feedback).filter(a=>Rs.includes(a.tag)).map(a=>({sessionId:c(a.sessionId,80),tag:a.tag,at:c(a.at,32),why:c(a.why,200)})).slice(-R),created:c(s.created,32),updated:c(s.updated,32),...c(s.activatedAt,32)?{activatedAt:c(s.activatedAt,32)}:{},...["sessions","proof","user","import"].includes(s.activatedBy)?{activatedBy:s.activatedBy}:{},...c(s.lastHelpfulAt,32)?{lastHelpfulAt:c(s.lastHelpfulAt,32)}:{},...c(s.retiredAt,32)?{retiredAt:c(s.retiredAt,32)}:{},...Ss.includes(s.retiredReason)?{retiredReason:s.retiredReason}:{},...r&&r.kind==="desktop"?{origin:{kind:"desktop",projectId:c(r.projectId,32),ruleId:c(r.ruleId,16)}}:{}}}d(Z,"oe"),u(Z,"parseLesson");const y=u(s=>s.replace(/\s+/g," ").trim(),"fold");function F(s){if(!s.fix||!s.signature?.startsWith("fix:")||s.activatedBy==="user"||s.activatedBy==="import")return!1;const e=ws(s.fix.bad,s.fix.good);return!e||y(e.bad)!==y(s.fix.bad)||y(e.good)!==y(s.fix.good)||xs(s.rootCause)||s.rootCause.trim()&&!Is(s.rootCause)||As(s.rootCause)?!0:ks({content:s.content})!==void 0}d(F,"re"),u(F,"isMalformed");const Bs=["candidate","active","awaiting_user"];function J(s){return!Bs.includes(s.status)||!F(s)?s:{...s,status:"retired",retiredAt:s.updated||s.created,retiredReason:"malformed"}}d(J,"ce"),u(J,"retireMalformed");function Q(s){if(s.activatedBy==="user"||s.activatedBy==="import")return s;const e=U(s.fix?`${s.fix.good}
|
|
2
|
+
${s.rootCause??""}`:s.content).filter(n=>!s.risk.includes(n));if(e.length===0)return s;const o=[...s.risk,...e];return s.status==="active"?{...s,risk:o,status:"awaiting_user"}:{...s,risk:o}}d(Q,"de"),u(Q,"recheckRisk");function I(s){const e=L(s?.lessons).map(Z).filter(i=>i!==void 0).map(J).map(Q),o=e.reduce((i,r)=>Math.max(i,Number(r.id.slice(2))),0),n={},t=s?.imported;if(t&&typeof t=="object"&&!Array.isArray(t))for(const[i,r]of Object.entries(t))n[i]=_(r,1e3,16);return{nextId:Math.max(b(s?.nextId),o+1,1),lessons:e,imported:n}}d(I,"F"),u(I,"parseLessonsDoc");function ss(s){return js(A(s),I).value}d(ss,"Ce"),u(ss,"readLessons");function es(s,e){return Cs(A(s),I,e)}d(es,"Te"),u(es,"updateLessons");function w(s){return s.toLowerCase().replace(/[\s\p{P}\p{S}]+/gu,"")}d(w,"v"),u(w,"normalizeText");function B(s){const e=w(s),o=new Set;for(let n=0;n<e.length-1;n++)o.add(e.slice(n,n+2));return o}d(B,"O"),u(B,"bigrams");function D(s,e){const o=B(s),n=B(e);if(o.size===0||n.size===0)return w(s)===w(e)?1:0;let t=0;for(const i of o)n.has(i)&&t++;return 2*t/(o.size+n.size)}d(D,"ue"),u(D,"similarity");const ts=.72;function N(s,e){const o=s.lessons.filter(i=>i.retiredReason!=="malformed");if(e.signature){const i=o.find(r=>r.signature===e.signature);if(i)return i}let n,t=0;for(const i of o){const r=D(i.content,e.content);r>t&&(n=i,t=r)}return t>=ts?n:void 0}d(N,"le"),u(N,"findMatch");function l(s){return new Date(s).toISOString()}d(l,"f"),u(l,"iso");function T(s,e){if(s.status!=="candidate")return s;const o=s.sessions.length>=P,n=s.proof!==void 0;return!o&&!n?s:s.risk.length>0?{...s,status:"awaiting_user",updated:l(e)}:{...s,status:"active",activatedAt:l(e),activatedBy:n&&!o?"proof":"sessions",updated:l(e)}}d(T,"B"),u(T,"promote");function ns(s,e,o,n){const t=(e.confirms?s.lessons.find(a=>a.id===e.confirms):void 0)??N(s,e),i={sessionId:o,at:l(n),signal:e.signal,note:e.note.slice(0,300)};if(t){if(t.status==="undone"||t.status==="retired")return{doc:s,outcome:{kind:"suppressed",lesson:t}};const a=!t.sessions.includes(o),f=t.status==="active"&&x(t)&&a&&e.proof!==void 0&&!t.feedback.some(v=>v.sessionId===o&&v.tag==="helpful");let p={...t,status:t.status==="expired"?"candidate":t.status,sessions:a?[...t.sessions,o].slice(-W):t.sessions,evidence:[...t.evidence,i].slice(-V),...e.proof&&!t.proof?{proof:{...e.proof,at:l(n),sessionId:o}}:{},...f?{helpful:t.helpful+1,lastHelpfulAt:l(n),feedback:[...t.feedback,{sessionId:o,tag:"helpful",at:l(n),why:`proven again: ${e.note}`.slice(0,200)}].slice(-R)}:{},updated:l(n)};p=T(p,n);const E=s.lessons.map(v=>v.id===t.id?p:v);return{doc:{...s,lessons:E},outcome:{kind:a?"confirmed":"repeated",lesson:p},...t.status!==p.status?{transition:{lesson:p,from:t.status,to:p.status}}:{}}}let r={id:`${e.scope==="user"?"u":"l"}-${String(s.nextId).padStart(4,"0")}`,scope:e.scope,section:e.section||"general",content:e.content,rootCause:e.rootCause,...e.signature?{signature:e.signature}:{},...e.fix?{fix:e.fix}:{},status:"candidate",risk:U(e.fix?`${e.fix.good}
|
|
3
|
+
${e.rootCause??""}`:e.content),sessions:[o],evidence:[i],...e.proof?{proof:{...e.proof,at:l(n),sessionId:o}}:{},helpful:0,harmful:0,feedback:[],created:l(n),updated:l(n)};return r=T(r,n),{doc:{...s,nextId:s.nextId+1,lessons:[...s.lessons,r]},outcome:{kind:"created",lesson:r},...r.status!=="candidate"?{transition:{lesson:r,from:"candidate",to:r.status}}:{}}}d(ns,"je"),u(ns,"proposeLesson");function os(s,e,o){const n=s.lessons.find(i=>i.id===e);if(!n||n.status==="active")return{doc:s,lesson:n};const t={...n,status:"active",activatedAt:l(o),activatedBy:"user",updated:l(o)};return delete t.retiredAt,delete t.retiredReason,{doc:{...s,lessons:s.lessons.map(i=>i.id===e?t:i)},lesson:t}}d(os,"Ne"),u(os,"approveLesson");function is(s,e,o){const n=s.lessons.find(i=>i.id===e);if(!n||n.status==="undone")return{doc:s,lesson:n};const t={...n,status:"undone",retiredAt:l(o),retiredReason:"user",updated:l(o)};return{doc:{...s,lessons:s.lessons.map(i=>i.id===e?t:i)},lesson:t}}d(is,"Fe"),u(is,"undoLesson");function as(s,e,o,n){let t=0;const i=s.lessons.map(r=>{let a=r;for(const f of e.filter(p=>p.id===r.id))a.feedback.some(p=>p.sessionId===o&&p.tag===f.tag)||(t++,a={...a,helpful:a.helpful+(f.tag==="helpful"?1:0),harmful:a.harmful+(f.tag==="harmful"?1:0),...f.tag==="neutral"?{neutral:(a.neutral??0)+1}:{},feedback:[...a.feedback,{sessionId:o,tag:f.tag,at:l(n),why:f.why.slice(0,200)}].slice(-R),...f.tag==="helpful"?{lastHelpfulAt:l(n)}:{},updated:l(n)});return a});return{doc:t>0?{...s,lessons:i}:s,changed:t}}d(as,"Oe"),u(as,"applyFeedback");function $(s){return s.harmful>=2&&s.harmful>s.helpful}d($,"pe"),u($,"isHarmful");function x(s){return s.harmful>=1&&s.harmful===s.helpful}d(x,"$"),u(x,"isContested");function rs(s){return s.status==="active"&&s.helpful>=1&&s.harmful===0}d(rs,"Be"),u(rs,"isTrusted");function O(s){return s.helpful===0&&(s.neutral??0)>=Y}d(O,"ge"),u(O,"isIneffective");function j(s,e,o){return{...s,status:"retired",retiredAt:l(o),retiredReason:e,updated:l(o)}}d(j,"I"),u(j,"retired");function us(s,e){const o=[],n=s.lessons.map(t=>{let i;if(t.status==="active"&&$(t))i=j(t,"harmful",e);else if(t.status==="active"&&O(t))i=j(t,"ineffective",e);else if(t.status==="candidate"){const r=Date.parse(t.updated||t.created);Number.isFinite(r)&&e-r>q*X&&(i={...t,status:"expired",updated:l(e)})}return i?(o.push({lesson:i,from:t.status,to:i.status}),i):t});return{doc:o.length>0?{...s,lessons:n}:s,transitions:o}}d(us,"$e"),u(us,"retireLessons");function ds(s,e,o,n){const t=[];let i=!1;const r=s.lessons.map(a=>{if(a.status!=="active")return a;if(e.includes(a.id))return i=!0,{...a,injections:(a.injections??0)+1,lastInjectedAt:l(n)};if(!o.includes(a.id))return a;const f=Math.max(...[a.lastInjectedAt,a.lastHelpfulAt,a.activatedAt??a.created].map(E=>E?Date.parse(E):Number.NaN).filter(Number.isFinite));if(!Number.isFinite(f)||n-f<=K*X)return a;i=!0;const p=j(a,"unused",n);return t.push({lesson:p,from:a.status,to:p.status}),p});return{doc:i?{...s,lessons:r}:s,transitions:t}}d(ds,"Ke"),u(ds,"recordInjection");const cs="Lessons learned from earlier sessions, applied automatically on evidence (two sessions or a passing check) or confirmed by the user. Apply one when the situation matches; the user's instructions and every protection come first. If a lesson is wrong here, say so and name its id. When a lesson contradicts what the repository or the user shows now, trust the repository and the user: the lesson is outdated.",ls=6,fs=2;function M(s){return(s.activatedBy==="proof"||s.activatedBy==="sessions")&&s.helpful===0&&(s.neutral??0)>=fs}d(M,"Le"),u(M,"lacksEvidence");const Ds=new Set("the and for with this that these those from into when then than before after instead only each every use used using run runs running ran make makes made keep edit edits editing file files project projects here there what which while where your you our are was were has have had not but all any its one two fails fail failed failing passes pass passed should must can will just also more most first last same src lib test tests js mjs cjs ts tsx jsx json md py go rs txt yaml yml".split(" ")),Ns=new Set("\u672C\u9879 \u9879\u76EE \u76EE\u91CC \u6539\u7528 \u4F1A\u5931 \u5931\u8D25 \u4F7F\u7528 \u65F6\u5019 \u4E4B\u524D \u4E4B\u540E \u6587\u4EF6 \u8FD0\u884C \u4E00\u4E0B \u8FD9\u4E2A \u90A3\u4E2A \u53EF\u4EE5 \u9700\u8981 \u4E0D\u8981 \u5982\u679C \u7136\u540E \u73B0\u5728 \u5DF2\u7ECF \u6211\u4EEC \u4F60\u7684 \u4E00\u4E2A \u4EC0\u4E48 \u600E\u4E48 \u4E3A\u4EC0\u4E48 \u5E2E\u6211 \u770B\u770B \u95EE\u9898 \u4EE3\u7801".split(" "));function C(s){const e=new Set,o=s.replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase();for(const n of o.match(/[a-z][a-z0-9_-]{2,}/g)??[])for(const t of[n,...n.split(/[-_]/)])t.length>=3&&!Ds.has(t)&&e.add(t);for(const n of s.match(new RegExp("\\p{Script=Han}{2,}","gu"))??[])for(let t=0;t<n.length-1;t++){const i=n.slice(t,t+2);Ns.has(i)||e.add(i)}return e}d(C,"_"),u(C,"termsOf");function ps(s){const e=new Set,o=u(n=>n.test(s),"has");if(o(/\b(?:fix|bug|broken|implement|add|change|update|refactor|rename|remove|support|migrate|make|failing|regression)\w*\b/i)||o(/修|改|实现|加上|增加|添加|支持|重构|迁移|报错|错误|不对|坏了/))for(const n of["test","build","typecheck"])e.add(n);return(o(/\b(?:tests?|specs?|ci)\b/i)||o(/测试|用例|单测/))&&e.add("test"),(o(/\b(?:build|compile|bundle|dist)\w*\b/i)||o(/构建|编译|打包/))&&e.add("build"),(o(/\b(?:lint|format)\w*\b/i)||o(/格式|规范/))&&e.add("lint"),(o(/\b(?:types?|typecheck|tsc)\b/i)||o(/类型/))&&e.add("typecheck"),(o(/\b(?:install|dependenc\w*|packages?|upgrade)\b/i)||o(/依赖|安装|升级/))&&e.add("install"),e}d(ps,"ke"),u(ps,"impliedKinds");const Ts=new Set(["test","build","lint","typecheck","install"]);function ms(s){const e=new Set;s.fix?.intent&&e.add(s.fix.intent),Ts.has(s.section)&&e.add(s.section);for(const[,o]of s.content.matchAll(/`([^`]+)`/g)){const n=ys(o);n&&e.add(n)}return e}d(ms,"Se"),u(ms,"kindsOf");function z(s,e){const o=e.request?.trim()??"";if(!o)return 0;const n=C(o);for(const r of e.paths??[]){const a=C(r);if([...a].some(f=>n.has(f)))for(const f of a)n.add(f)}let t=0;for(const r of C(`${s.content} ${s.fix?.bad??""} ${s.fix?.good??""}`))n.has(r)&&(t+=1);const i=ps(o);return[...ms(s)].some(r=>i.has(r))&&(t+=1),t}d(z,"Ae"),u(z,"relevance");function hs(s){return s.helpful-s.harmful+(s.activatedBy==="user"?1:0)}d(hs,"Re"),u(hs,"effect");function gs(s,e={},o=G){const n=!!e.request?.trim(),t=[],i=[];s.forEach((m,g)=>{for(const h of m.lessons){if(h.status!=="active")continue;const k=h.scope==="user",H=n&&!k?z(h,e):0;n&&!k&&H<1||(t.push(h.id),!(M(h)||x(h))&&i.push({group:g,lesson:h,score:H+hs(h)}))}}),i.sort((m,g)=>m.group-g.group||g.score-m.score||m.lesson.id.localeCompare(g.lesson.id));const r=u(m=>`- [${m.id}] ${m.content.replace(/\s+/g," ")}`,"lineOf");let a=S(cs);const f=new Set,p=u(m=>[...f].some(g=>i.find(h=>h.lesson.id===g)?.group===m)?0:S(`${s[m].label}:`),"headerCost");for(const m of i){if(f.size>=ls)break;const g=S(r(m.lesson))+1+p(m.group);a+g>o||(a+=g,f.add(m.lesson.id))}if(f.size===0)return{ids:[],eligible:t,tokens:0};const E=[cs],v=[];return s.forEach(m=>{const g=m.lessons.filter(h=>f.has(h.id)&&h.status==="active").sort((h,k)=>h.id.localeCompare(k.id));g.length!==0&&(E.push(`${m.label}:`,...g.map(r)),v.push(...g.map(h=>h.id)))}),{text:E.join(`
|
|
4
|
+
`),ids:v,eligible:t,tokens:a}}d(gs,"Me"),u(gs,"renderLessonsSection");export{q as CANDIDATE_EXPIRE_DAYS,P as CONFIRMATIONS_TO_ACTIVATE,G as LESSONS_TOKEN_BUDGET,ls as MAX_LESSONS_GIVEN,fs as NEUTRAL_HOLD_AFTER,Y as NEUTRAL_RETIRE_AFTER,ts as SAME_LESSON_SIMILARITY,K as UNUSED_RETIRE_DAYS,as as applyFeedback,os as approveLesson,N as findMatch,x as isContested,$ as isHarmful,O as isIneffective,F as isMalformed,rs as isTrusted,M as lacksEvidence,A as lessonsPath,I as parseLessonsDoc,ns as proposeLesson,ss as readLessons,ds as recordInjection,z as relevance,gs as renderLessonsSection,us as retireLessons,D as similarity,is as undoLesson,es as updateLessons};
|