dal-code 1.0.40 → 1.0.42
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 +35 -0
- package/NOTICE +76 -1
- package/PRIVACY.md +68 -2
- package/dist/cli/startup-ui.js +1 -1
- package/dist/core/agent-session.d.ts +3 -0
- package/dist/core/agent-session.js +6 -6
- package/dist/core/bug-report.js +5 -5
- package/dist/core/settings-manager.d.ts +0 -5
- package/dist/core/settings-manager.js +1 -1
- package/dist/dal/manifest.js +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +1 -1
- package/dist/modes/interactive/components/status-indicator.js +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.js +2 -2
- package/dist/modes/print-mode.d.ts +1 -1
- package/dist/modes/print-mode.js +7 -6
- package/dist/modes/rpc/rpc-client.d.ts +5 -1
- package/dist/modes/rpc/rpc-client.js +3 -3
- package/dist/modes/rpc/rpc-mode.js +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +25 -0
- package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-advisor/src/index.js +9 -8
- package/dist/node_modules/@dalcode/dal-awake/LICENSE +21 -0
- package/dist/node_modules/@dalcode/dal-awake/package.json +31 -0
- package/dist/node_modules/@dalcode/dal-awake/src/index.js +3 -0
- package/dist/node_modules/@dalcode/dal-awake/src/inhibitor.js +1 -0
- 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-compat/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-compat/src/at-imports.js +3 -0
- package/dist/node_modules/@dalcode/dal-compat/src/index.js +7 -5
- package/dist/node_modules/@dalcode/dal-dap/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-dap/src/install.js +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-guard/src/edit-anchor-core.js +22 -21
- package/dist/node_modules/@dalcode/dal-guard/src/edit-anchor.js +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/index.js +10 -10
- package/dist/node_modules/@dalcode/dal-learn/src/lessons.js +3 -3
- package/dist/node_modules/@dalcode/dal-learn/src/patches.js +10 -0
- package/dist/node_modules/@dalcode/dal-lsp/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-mcp/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-office/src/index.d.ts +1 -0
- package/dist/node_modules/@dalcode/dal-office/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/render/deck-source.d.ts +10 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/deck-source.js +2 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/pptx.js +3 -3
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +3 -3
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +3 -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-review/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-review/src/core.d.ts +1 -0
- package/dist/node_modules/@dalcode/dal-review/src/core.js +1 -1
- package/dist/node_modules/@dalcode/dal-review/src/findings.js +2 -2
- package/dist/node_modules/@dalcode/dal-review/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-review/src/prompt.d.ts +1 -1
- package/dist/node_modules/@dalcode/dal-review/src/prompt.js +3 -2
- package/dist/node_modules/@dalcode/dal-review/src/runner.d.ts +2 -1
- package/dist/node_modules/@dalcode/dal-review/src/runner.js +2 -2
- package/dist/node_modules/@dalcode/dal-review/src/simplify.d.ts +5 -0
- package/dist/node_modules/@dalcode/dal-review/src/simplify.js +30 -0
- package/dist/node_modules/@dalcode/dal-review/src/types.d.ts +5 -0
- package/dist/node_modules/@dalcode/dal-review/src/types.js +1 -1
- package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-router/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-rtk/LICENSE +21 -0
- package/dist/node_modules/@dalcode/dal-rtk/package.json +31 -0
- package/dist/node_modules/@dalcode/dal-rtk/src/index.js +2 -0
- package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/bounded-code-repair/SKILL.md +45 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/evidence-first-retrieval/SKILL.md +43 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/validated-structured-output/SKILL.md +36 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled.js +1 -1
- 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-subagent/src/index.js +21 -21
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +8 -2
- package/dist/node_modules/@dalcode/dal-telemetry/src/config.js +3 -2
- package/dist/node_modules/@dalcode/dal-telemetry/src/consent.js +1 -0
- package/dist/node_modules/@dalcode/dal-telemetry/src/failure-queue.js +4 -0
- package/dist/node_modules/@dalcode/dal-telemetry/src/failure-reporting.js +5 -0
- package/dist/node_modules/@dalcode/dal-telemetry/src/failures.js +2 -0
- package/dist/node_modules/@dalcode/dal-telemetry/src/index.js +4 -3
- package/dist/node_modules/@dalcode/dal-telemetry/src/reporter.js +1 -1
- package/dist/node_modules/@dalcode/dal-telemetry/src/repro.js +1 -0
- 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-tool-catalog/src/index.js +4 -4
- package/dist/node_modules/@dalcode/dal-tool-catalog/src/path-hint.js +1 -0
- package/dist/node_modules/@dalcode/dal-tool-catalog/src/repair-hook.js +2 -1
- package/dist/node_modules/@dalcode/dal-tool-catalog/src/repair.js +1 -1
- package/dist/node_modules/@dalcode/dal-tool-catalog/src/tool-name.js +1 -0
- package/dist/node_modules/@dalcode/dal-usage/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-usage/src/index.d.ts +1 -0
- package/dist/node_modules/@dalcode/dal-usage/src/index.js +2 -2
- package/dist/node_modules/@dalcode/dal-usage/src/time-limit.d.ts +4 -0
- package/dist/node_modules/@dalcode/dal-usage/src/time-limit.js +2 -0
- 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/index.js +4 -4
- package/dist/node_modules/@dalcode/dal-workflow/src/lean-code.js +1 -1
- package/dist/node_modules/@dalcode/dal-workflow/src/working-contract.js +1 -0
- package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
- package/dist/node_modules/@dalcode/deepailab/src/index.js +3 -3
- package/dist/node_modules/@earendil-works/chord/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/cli.js +0 -0
- 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/baseten.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/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/zai-coding-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-client/package.json +3 -3
- 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/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-protocol/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-server/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/dist/sdk/index.d.ts +1 -1
- package/dist/sdk/office.d.ts +1 -1
- package/dist/sdk/office.js +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-structured",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.42",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "dal -p --output-schema: the final answer as JSON that matches a JSON Schema, with a non-zero exit when it does not. Grown from the structured-output extension example.",
|
|
6
6
|
"type": "module",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
21
|
+
"@dalcode/dal-pi-kit": "1.0.42",
|
|
22
22
|
"typebox": "1.3.27"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-subagent",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.42",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
22
|
-
"@dalcode/dal-guard": "1.0.
|
|
23
|
-
"@earendil-works/pi-agent-core": "^1.0.
|
|
24
|
-
"@earendil-works/pi-ai": "^1.0.
|
|
21
|
+
"@dalcode/dal-pi-kit": "1.0.42",
|
|
22
|
+
"@dalcode/dal-guard": "1.0.42",
|
|
23
|
+
"@earendil-works/pi-agent-core": "^1.0.42",
|
|
24
|
+
"@earendil-works/pi-ai": "^1.0.42",
|
|
25
25
|
"typebox": "1.3.7"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
var yu=Object.defineProperty;var
|
|
2
|
-
`).trim();if(o)return o;if(r.errorMessage)return`${e("\u5B50 agent \u8FD0\u884C\u51FA\u9519\uFF1A")}${r.errorMessage}`}return e("\u5B50 agent \u6CA1\u6709\u4EA7\u751F\u4EFB\u4F55\u8F93\u51FA\u3002")}
|
|
1
|
+
var yu=Object.defineProperty;var d=(u,t)=>yu(u,"name",{value:t,configurable:!0});var ku=Object.defineProperty,i=d((u,t)=>ku(u,"name",{value:t,configurable:!0}),"s");import{execFileSync as bu}from"node:child_process";import{randomUUID as tu}from"node:crypto";import{mkdirSync as eu,readFileSync as Su,writeFileSync as nu}from"node:fs";import{join as xu}from"node:path";import{t as e}from"@dalcode/dal-pi-kit";import{routeSubagentModel as vu,subagentModelPreference as Iu}from"@dalcode/dal-router/subagent";import{isAccountLimitAssistantError as Pu}from"@earendil-works/pi-ai";import{Type as m}from"typebox";import{formatAgentList as ru,loadAgents as ou,projectAgentsDir as Ou,READ_ONLY_TOOL_NAMES as su,userAgentsDir as Tu}from"./agents.js";import{BackgroundSubagents as iu}from"./background.js";import{proxiedToolNames as ju,runInProcessSubagent as Ru}from"./inproc-runner.js";import{SubagentPool as Mu}from"./pool.js";import{addUsage as Lu,assistantUsage as _u,currentSubagentDepth as Nu,emptyUsage as Uu,endedOnAccountLimit as Ju,findSubagentSessionFile as au,finishedNormally as qu,MAX_SUBAGENT_DEPTH as Gu,pruneSubagentSessions as Fu,runResumableSubagent as Wu,subagentSessionDir as cu}from"./process-runner.js";import{pickRoleWithJev as Eu}from"./role-pick.js";import{readTmuxSetting as du,registerTmuxChild as zu,runTmuxSubagent as Xu,saveTmuxSetting as Hu,tmuxLocation as Ku,tmuxPlacement as Qu}from"./tmux-runner.js";import{createWorktree as Yu,finishWorktree as Zu}from"./worktree.js";export*from"./agents.js";export*from"./background.js";export*from"./inproc-runner.js";export*from"./pool.js";export*from"./process-runner.js";export*from"./role-pick.js";export*from"./tmux-runner.js";export*from"./worktree.js";const U=50,J=new Map;function q(u){if(J.has(u))return J.get(u);let t;try{t=bu("git",["ls-files","-z","--cached","--others","--exclude-standard"],{cwd:u,encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5e3,maxBuffer:67108864}).split("\0").filter(Boolean).length}catch{t=void 0}return J.set(u,t),t}d(q,"Ce"),i(q,"gitProjectFileCount");function lu(u){const t=u.sessionManager?.getBranch?.()??[];for(let r=t.length-1;r>=0;r--){const o=t[r];if(o.type!=="message"||o.message.role!=="user")continue;const c=o.message.content,s=typeof c=="string"?c:c.map(n=>n.type==="text"?n.text:"").join(" ");return/sub-?agents?|subtasks?|in parallel|parallel(ly)?|子助手|子代理|子 ?agent|子任务|并行|派发/i.test(s)}return!1}d(lu,"_e"),i(lu,"userAskedForSubagents");function G(u){const t=q(u.cwd);if(!(t===void 0||t>=U||lu(u)))return`Not started: this project has ${t} files. Briefing a sub-agent costs more than reading them yourself; do the work directly (parallel reads in one response). Start sub-agents here only when the user asks for them.`}d(G,"Fe"),i(G,"smallProjectRefusal");const pu=['Several separate items (modules, packages, repositories, documents, questions) that each need real work: dispatch one sub-agent per item with task, in your first response, all at once, without reading the items yourself first; there is no limit on how many ("review A, B and C" is three calls). Quick lookups you do yourself',"Sub-agents cannot see this conversation: each prompt states the goal, exact paths or inputs, constraints, how the result will be checked, and what to report. Running together they share the working tree: give each different files, and let only one run installs, builds or git","Build on their reports; verify only what your answer depends on. Follow up with task resume=<the id in its result> and a prompt holding only the new instruction (resume alone continues one that failed)",`In a project of under ${U} files, do the work yourself unless the user asks for sub-agents`,"background=true for long work you can continue without: the call returns an id at once and the report arrives later as a message (never poll or sleep for it); task steer=<id> prompt=<instruction> redirects it while it runs. worktree=true gives a sub-agent that edits files its own git checkout; its changes come back on a branch for you to review and merge"],Vu=m.Object({agent:m.Optional(m.String({description:e("\u8FD9\u4E00\u6B65\u7684\u89D2\u8272\u540D")})),prompt:m.String({description:e("\u8FD9\u4E00\u6B65\u7684\u4EFB\u52A1\uFF1B{previous} \u4E3A\u4E0A\u4E00\u6B65\u7684\u8F93\u51FA")})}),ut=m.Object({description:m.String({description:e("\u5B50\u4EFB\u52A1\u7684\u7B80\u77ED\u6807\u9898\uFF083-5 \u4E2A\u5B57\uFF0C\u7528\u4E8E\u5C55\u793A\u8FDB\u5EA6\uFF09")}),prompt:m.Optional(m.String({description:e("\u5B8C\u6574\u3001\u81EA\u5305\u542B\u7684\u4EFB\u52A1\u8BF4\u660E")})),resume:m.Optional(m.String({description:e("\u7EE7\u7EED\u67D0\u4E2A\u5B50 agent\uFF1A\u586B\u7ED3\u679C\u91CC\u7684\u5B50 agent ID\uFF1Bprompt \u53EA\u5199\u65B0\u6307\u793A\uFF0C\u4E0D\u586B\u5219\u4ECE\u4E2D\u65AD\u5904\u7EE7\u7EED")})),agent:m.Optional(m.String({description:e("\u89D2\u8272\u540D\uFF08\u89C1\u5DE5\u5177\u8BF4\u660E\uFF09\uFF1B\u4E0D\u586B\u4E3A\u901A\u7528\u5B50 agent")})),readOnly:m.Optional(m.Boolean({description:e("\u53EA\u7ED9\u53EA\u8BFB\u5DE5\u5177\uFF08read/grep/find/ls\uFF09")})),chain:m.Optional(m.Array(Vu,{description:e("\u6309\u987A\u5E8F\u8FD0\u884C\u7684\u6B65\u9AA4\uFF1B\u4E0E prompt \u4E8C\u9009\u4E00")})),background:m.Optional(m.Boolean({description:e("\u5728\u540E\u53F0\u8FD0\u884C\uFF1A\u7ACB\u5373\u8FD4\u56DE ID\uFF0C\u5B8C\u6210\u540E\u7ED3\u679C\u4EE5\u6D88\u606F\u9001\u56DE\uFF1B\u4E0D\u7528\u7B49\u5F85\u6216\u8F6E\u8BE2")})),steer:m.Optional(m.String({description:e("\u8C03\u6574\u6B63\u5728\u540E\u53F0\u8FD0\u884C\u7684\u5B50 agent\uFF1A\u586B\u5B83\u7684 ID\uFF0Cprompt \u5199\u65B0\u7684\u6307\u793A")})),worktree:m.Optional(m.Boolean({description:e("\u5728\u72EC\u7ACB\u7684 git \u5DE5\u4F5C\u533A\u91CC\u8FD0\u884C\uFF0C\u6539\u52A8\u63D0\u4EA4\u5230\u4E00\u4E2A\u65B0\u5206\u652F\uFF0C\u4E0D\u5F71\u54CD\u5F53\u524D\u5DE5\u4F5C\u533A")}))});function x(u){return`${e("[\u5B50 agent ID\uFF1A")}${u}${e("\uFF0C\u53EF\u7528 resume \u53C2\u6570\u7EE7\u7EED]")}`}d(x,"D"),i(x,"subagentIdLine");function T(){return e("\u4E0A\u4E00\u6B21\u8FD0\u884C\u4E2D\u65AD\u4E86\u3002\u8BF7\u4ECE\u4E2D\u65AD\u5904\u7EE7\u7EED\u5B8C\u6210\u539F\u6765\u7684\u4EFB\u52A1\uFF0C\u4E0D\u8981\u91CD\u590D\u5DF2\u7ECF\u5B8C\u6210\u7684\u6B65\u9AA4\uFF0C\u5B8C\u6210\u540E\u7ED9\u51FA\u6700\u7EC8\u7ED3\u679C\u3002")}d(T,"V"),i(T,"continuePrompt");const W=i((u,t)=>xu(u,`${t}.meta.json`),"metaPath");function gu(u,t){const r=i(()=>new Error(`${e("\u627E\u4E0D\u5230\u5B50 agent\uFF1A")}${t}${e("\uFF08ID \u4E0D\u5B58\u5728\uFF0C\u6216\u4F1A\u8BDD\u5DF2\u8FC7\u671F\u88AB\u6E05\u7406\uFF09")}`),"missing");if(!/^[A-Za-z0-9-]+$/.test(t)||!au(u,t))throw r();try{return JSON.parse(Su(W(u,t),"utf8"))}catch{throw r()}}d(gu,"We"),i(gu,"loadSubagentMeta");function j(u){return`${e("[\u672A\u6307\u5B9A\u89D2\u8272\uFF0C\u5DF2\u81EA\u52A8\u9009\u62E9\uFF1A")}${u.agent.name}${e("\uFF0C\u7F6E\u4FE1\u5EA6 ")}${Math.round(u.confidence*100)}%]`}d(j,"ee"),i(j,"autoRoleNote");function z(u){for(let t=u.length-1;t>=0;t--){const r=u[t];if(r.role!=="assistant")continue;const o=r.content.filter(c=>c.type==="text").map(c=>c.text).join(`
|
|
2
|
+
`).trim();if(o)return o;if(r.errorMessage)return`${e("\u5B50 agent \u8FD0\u884C\u51FA\u9519\uFF1A")}${r.errorMessage}`}return e("\u5B50 agent \u6CA1\u6709\u4EA7\u751F\u4EFB\u4F55\u8F93\u51FA\u3002")}d(z,"Je"),i(z,"lastAssistantText");const tt=new Set(["write","edit","multi_edit","notebook_edit"]);function X(u){for(const t of["file_path","path","filePath"]){const r=u[t];if(typeof r=="string"&&r.length>0)return r}}d(X,"te"),i(X,"filePathFromInput");function mu(u,t){const r=X(t);if(r)return`${u} ${r.split("/").slice(-2).join("/")}`;const o=t??{};for(const c of["command","pattern","query"]){const s=o[c];if(typeof s=="string"&&s.trim()){const n=s.replace(/\s+/g," ").trim();return`${u} ${n.length>40?`${n.slice(0,39)}\u2026`:n}`}}return u}d(mu,"Ge"),i(mu,"describeSubagentStep");function H(u){const t=e("\u4F60\u662F\u4E00\u4E2A\u4E13\u6CE8\u7684\u5B50 agent\uFF0C\u8D1F\u8D23\u5B8C\u6210\u7236\u4EFB\u52A1\u6D3E\u53D1\u7ED9\u4F60\u7684\u4E00\u4E2A\u72EC\u7ACB\u5B50\u4EFB\u52A1\u3002")+e("\u5B8C\u6210\u540E\u7528\u7B80\u6D01\u7684\u4E2D\u6587\u6587\u5B57\u7ED9\u51FA\u6700\u7EC8\u7ED3\u679C\uFF0C\u4E0D\u8981\u53CD\u95EE\uFF0C\u4E0D\u8981\u5F81\u6C42\u786E\u8BA4\u3002")+e("\u4EFB\u52A1\u8FD8\u6CA1\u505A\u5B8C\u65F6\u5C31\u63A5\u7740\u8C03\u7528\u4E0B\u4E00\u4E2A\u5DE5\u5177\uFF0C\u4E0D\u8981\u4EE5\u8BA1\u5212\u3001\u627F\u8BFA\uFF08\u201C\u63A5\u4E0B\u6765\u6211\u4F1A\u2026\u201D\uFF09\u6216\u63D0\u95EE\u7ED3\u675F\uFF1B\u505A\u4E0D\u4E0B\u53BB\u65F6\u8BF4\u660E\u5361\u5728\u54EA\u91CC\u3001\u8BD5\u8FC7\u4EC0\u4E48\u3002");return u?.systemPrompt?`${u.systemPrompt}
|
|
3
3
|
|
|
4
|
-
${t}`:t}
|
|
5
|
-
${e("\u8D26\u6237\u6216\u6A21\u578B\u901A\u9053\u4F59\u989D\u4E0D\u8DB3\uFF0C\u5DF2\u505C\u6B62\u672C\u8F6E\u5168\u90E8\u5B50 agent\u3002\u4F59\u989D\u6062\u590D\u524D\u4E0D\u8981\u518D\u6D3E\u53D1\u5B50\u4EFB\u52A1\u6216\u91CD\u8BD5\u3002")}`}
|
|
6
|
-
`));let
|
|
4
|
+
${t}`:t}d(H,"ze"),i(H,"buildSubagentSystemPrompt");function Au(u,t,r){const o=r?` \xB7 ${r}`:"";return`${u} \u2014 ${t} ${e("\u6B65")}${o}`}d(Au,"Xe"),i(Au,"progressLine");function R(u){return u.keptPath?`${e("[\u6CA1\u80FD\u63D0\u4EA4\u72EC\u7ACB\u5DE5\u4F5C\u533A\u91CC\u7684\u6539\u52A8\uFF0C\u5DE5\u4F5C\u533A\u4FDD\u7559\u5728\uFF1A")}${u.keptPath}]`:u.branch?`${e("[\u6539\u52A8\u5DF2\u63D0\u4EA4\u5230\u5206\u652F ")}${u.branch}${e("\uFF1A")}${u.files.join(", ")}${e("\u3002\u5BA1\u9605\u540E\u7528 git merge \u6216 cherry-pick \u5408\u5E76]")}`:e("[\u72EC\u7ACB\u5DE5\u4F5C\u533A\u91CC\u6CA1\u6709\u6539\u52A8]")}d(R,"ne"),i(R,"worktreeLine");function M(u,t,r){const o=u.indexOf("/");if(o>0){const n=t.find(u.slice(0,o),u.slice(o+1));if(n)return n}const c=t.find(r.provider,u);if(c)return c;const s=t.getAll().filter(n=>n.id===u);if(s.length===1)return s[0];throw new Error(`${e("\u627E\u4E0D\u5230\u89D2\u8272\u6307\u5B9A\u7684\u6A21\u578B\uFF1A")}${u}`)}d(M,"re"),i(M,"resolveAgentModel");async function K(u,t){const r=t.model;if(!r)throw new Error(e("\u6CA1\u6709\u53EF\u7528\u7684\u5F53\u524D\u6A21\u578B\uFF0C\u65E0\u6CD5\u6D3E\u53D1\u5B50 agent\u3002"));let o=r;const c=Iu();if(u.agent?.model)o=M(u.agent.model,t.modelRegistry,r);else if(c.kind==="model")o=M(c.spec,t.modelRegistry,r);else if(c.kind==="route")try{const E=await vu({taskText:u.prompt,credentials:t.modelRegistry});if(E?.modelId&&E.provider){const a=t.modelRegistry?.find(E.provider,E.modelId);a&&(o=a)}}catch{}const s=u.agent?.tools,n=u.readOnly?(s??su).filter(E=>su.includes(E)):s;return{cwd:t.cwd,model:`${o.provider}/${o.id}`,thinking:u.agent?.thinking??"off",...n?{tools:n}:{},appendSystemPrompt:H(u.agent),...u.agent?{agent:u.agent.name}:{}}}d(K,"oe"),i(K,"newSubagentMeta");class Du{static{d(this,"He")}static{i(this,"AccountLimitStop")}controller=new AbortController;tripped;get signal(){return this.controller.signal}get reason(){return this.tripped}trip(t){this.tripped===void 0&&(this.tripped=t,this.controller.abort())}reset(){this.tripped=void 0,this.controller=new AbortController}}function O(u){return`${e("\u5B50 agent \u8FD0\u884C\u51FA\u9519\uFF1A")}${u}
|
|
5
|
+
${e("\u8D26\u6237\u6216\u6A21\u578B\u901A\u9053\u4F59\u989D\u4E0D\u8DB3\uFF0C\u5DF2\u505C\u6B62\u672C\u8F6E\u5168\u90E8\u5B50 agent\u3002\u4F59\u989D\u6062\u590D\u524D\u4E0D\u8981\u518D\u6D3E\u53D1\u5B50\u4EFB\u52A1\u6216\u91CD\u8BD5\u3002")}`}d(O,"C"),i(O,"accountLimitMessage");async function Q(u,t,r,o,c,s,n){if(s?.reason!==void 0)throw new Error(O(s.reason));if(u.worktree&&u.resume)throw new Error(e("worktree \u4E0D\u80FD\u548C resume \u4E00\u8D77\u4F7F\u7528\u3002"));const E=cu();let a,F;u.resume?(a=u.resume.trim(),F=gu(E,a)):(F=await K(u,t),a=tu(),eu(E,{recursive:!0}),Fu(E),nu(W(E,a),`${JSON.stringify(F)}
|
|
6
|
+
`));let h;if(u.worktree&&(h=n?await Yu(n,t.cwd,a):void 0,!h))throw new Error(e("worktree \u9700\u8981\u4E00\u4E2A\u81F3\u5C11\u6709\u4E00\u6B21\u63D0\u4EA4\u7684 git \u4ED3\u5E93\u3002"));let D;const B=i(async()=>(h&&n&&!D&&(D=await Zu(n,t.cwd,h,u.description)),D),"finishTree");try{const g=await l(),w=await B();return w?{...g,text:`${g.text}
|
|
7
7
|
|
|
8
|
-
${R(
|
|
9
|
-
${R(
|
|
10
|
-
${
|
|
8
|
+
${R(w)}`,changedFiles:w.files,worktree:w}:g}catch(g){const w=await B();throw!w||!(g instanceof Error)?g:new Error(`${g.message}
|
|
9
|
+
${R(w)}`)}async function l(){const g=[];let w=0;const k=i(A=>new Error(au(E,a)?`${A}
|
|
10
|
+
${x(a)}`:A),"failed"),$=await Wu({cwd:h?.workPath??F.cwd,prompt:u.prompt||T(),session:{dir:E,id:a},resumePrompt:T(),model:F.model,thinking:F.thinking,tools:F.tools,...c?{excludeTools:c}:{},appendSystemPrompt:F.appendSystemPrompt,projectTrusted:t.isProjectTrusted(),signal:s?t.signal?AbortSignal.any([t.signal,s.signal]):s.signal:t.signal,attribution:{sessionId:t.sessionManager.getSessionId(),subagentId:a,label:u.description},onResume:i(()=>o?.(`${u.description} \u2014 ${e("\u4E2D\u65AD\uFF0C\u6B63\u5728\u81EA\u52A8\u7EED\u8DD1")}`),"onResume"),onEvent:i(A=>{const p=_u(A);if(p&&Lu(r,p),A.type!=="tool_execution_start")return;const C=String(A.toolName),f=A.args??{};if(w+=1,o?.(Au(u.description,w,mu(C,f))),tt.has(C)){const S=X(f);S&&g.push(S)}},"onEvent")}).catch(A=>{throw t.signal?.aborted?A:s?.reason!==void 0?k(O(s.reason)):k(`${e("\u5B50 agent \u8FD0\u884C\u51FA\u9519\uFF1A")}${A instanceof Error?A.message:String(A)}`)});if($.idleTimedOut)throw k(e("\u5B50 agent \u8D85\u8FC7 10 \u5206\u949F\u6CA1\u6709\u4EFB\u4F55\u8FDB\u5C55\uFF0C\u5DF2\u505C\u6B62\u3002"));if(Ju($)){const A=$.messages.at(-1),p=A?.role==="assistant"&&A.errorMessage||"account limit";throw s?.trip(p),k(O(p))}const y=$.messages.at(-1),v=y?.role==="assistant"&&y.stopReason==="length";if(!v&&!qu($)){const A=y?.role==="assistant"&&y.errorMessage||$.stderr.trim().split(`
|
|
11
11
|
`).slice(-3).join(`
|
|
12
|
-
`)||`exit ${
|
|
12
|
+
`)||`exit ${$.exitCode}`;throw k(`${e("\u5B50 agent \u8FD0\u884C\u51FA\u9519\uFF1A")}${A}`)}const I=z($.messages);return{text:v?`${I}
|
|
13
13
|
|
|
14
|
-
${e("\uFF08\u5B50 agent \u7684\u56DE\u7B54\u8FBE\u5230\u4E86\u6A21\u578B\u8F93\u51FA\u957F\u5EA6\u4E0A\u9650\uFF0C\u5185\u5BB9\u4E0D\u5B8C\u6574\u3002\uFF09")}`:I,changedFiles:[...new Set(g)],subagentId:a,...
|
|
14
|
+
${e("\uFF08\u5B50 agent \u7684\u56DE\u7B54\u8FBE\u5230\u4E86\u6A21\u578B\u8F93\u51FA\u957F\u5EA6\u4E0A\u9650\uFF0C\u5185\u5BB9\u4E0D\u5B8C\u6574\u3002\uFF09")}`:I,changedFiles:[...new Set(g)],subagentId:a,...F.agent?{agent:F.agent}:{},autoResumed:$.autoResumed}}d(l,"l"),i(l,"runAndCheck")}d(Q,"ie"),i(Q,"runSubagent");function L(u){return ou({cwd:u.cwd,projectTrusted:u.isProjectTrusted()})}d(L,"_"),i(L,"agentsFor");function _(u,t){if(t===void 0||t.trim()==="")return;const r=u.find(o=>o.name===t.trim());if(!r)throw new Error(`${e("\u672A\u77E5\u7684\u5B50 agent \u89D2\u8272\uFF1A")}${t}${e("\u3002\u53EF\u7528\u89D2\u8272\uFF1A")}${u.map(o=>o.name).join(", ")}`);return r}d(_,"F"),i(_,"findAgent");function Y(u,t){return u.split("{previous}").join(t)}d(Y,"Ke"),i(Y,"fillPrevious");function Bu(u){return e("\u6D3E\u53D1\u4E00\u4E2A\u5B50 agent \u5B8C\u6210\u81EA\u5305\u542B\u7684\u5B50\u4EFB\u52A1\uFF1B\u540C\u4E00\u8F6E\u591A\u6B21\u8C03\u7528\u5373\u5E76\u884C\u8FD0\u884C\u3002\u5B50 agent \u7528\u5F53\u524D\u6A21\u578B\u548C\u5B8C\u6574\u5DE5\u5177\uFF08\u540C\u6837\u7ECF\u8FC7\u5B89\u5168\u5BA1\u6279\uFF09\uFF0C\u770B\u4E0D\u5230\u672C\u5BF9\u8BDD\u3002")+`
|
|
15
15
|
`+e("\u89D2\u8272\uFF08agent \u53C2\u6570\uFF09\uFF1A")+`
|
|
16
|
-
`+
|
|
17
|
-
`+e("chain\uFF1A\u6309\u987A\u5E8F\u8FD0\u884C\u591A\u6B65\uFF08\u5982 scout \u2192 worker \u2192 reviewer\uFF09\u3002")}
|
|
18
|
-
${
|
|
16
|
+
`+ru(u)+`
|
|
17
|
+
`+e("chain\uFF1A\u6309\u987A\u5E8F\u8FD0\u884C\u591A\u6B65\uFF08\u5982 scout \u2192 worker \u2192 reviewer\uFF09\u3002")}d(Bu,"Qe"),i(Bu,"taskToolDescription");const Z=new Map,N=i(u=>u.totalTokens>0||u.cost.total>0,"hasUsage");function V(u,t,r){u.registerTool({name:"task",label:e("\u6D3E\u53D1\u5B50\u4EFB\u52A1"),description:Bu(t),promptSnippet:e("task - \u6D3E\u53D1\u5B50 agent \u5E76\u884C\u5904\u7406\u72EC\u7ACB\u5B50\u4EFB\u52A1"),promptGuidelines:pu,parameters:ut,executionMode:"parallel",execute:i(async(o,c,s,n,E)=>{const a=Uu();try{return await fu(c,E,a,F=>{n?.({content:[{type:"text",text:F}],details:{description:c.description}})},u.getToolDenylist?.(),r.accountStop,{pi:u,deps:r})}catch(F){const h=r.accountStop.reason;if(h!==void 0)return{content:[{type:"text",text:F instanceof Error?F.message:String(F)}],details:{description:c.description,accountLimit:{reason:h},...N(a)?{usage:a}:{}},...N(a)?{usage:a}:{},isError:!0,terminate:!0};throw N(a)&&Z.set(o,a),F}},"execute")})}d(V,"se"),i(V,"registerTaskTool");async function fu(u,t,r,o,c,s,n){const E=u.steer?.trim();if(E){if(!n)throw new Error(e("\u8FD9\u4E2A\u4F1A\u8BDD\u4E0D\u652F\u6301\u540E\u53F0\u5B50\u52A9\u624B\u3002"));const p=u.prompt?.trim();if(!p)throw new Error(e("steer \u9700\u8981\u5728 prompt \u91CC\u5199\u65B0\u7684\u6307\u793A\u3002"));const C=await n.deps.background().steer(E,p);if(C)throw new Error(C);return{content:[{type:"text",text:e("\u5DF2\u628A\u65B0\u6307\u793A\u9001\u8FBE\u540E\u53F0\u5B50\u52A9\u624B\uFF1B\u5B83\u7684\u62A5\u544A\u5B8C\u6210\u540E\u4F1A\u4EE5\u6D88\u606F\u9001\u56DE\u3002")}],details:{description:u.description,subagentId:E,background:!0}}}const{agents:a}=L(t),F=Array.isArray(u.chain)&&u.chain.length>0,h=typeof u.prompt=="string"&&u.prompt.trim()!=="",D=u.resume?.trim();if(D&&F)throw new Error(e("resume \u4E0D\u80FD\u548C chain \u4E00\u8D77\u4F7F\u7528\u3002"));if(!D&&F===h)throw new Error(e("task \u9700\u8981\u4E14\u53EA\u80FD\u63D0\u4F9B prompt \u6216 chain \u5176\u4E2D\u4E4B\u4E00\u3002"));const B=i(()=>N(r)?{usage:r}:{},"usage"),l=D?void 0:G(t);if(l)throw new Error(l);if(u.background&&(F||D||u.worktree))throw new Error(e("background \u4E0D\u80FD\u548C chain\u3001resume \u6216 worktree \u4E00\u8D77\u4F7F\u7528\u3002"));if(u.worktree&&F)throw new Error(e("worktree \u4E0D\u80FD\u548C chain \u4E00\u8D77\u4F7F\u7528\u3002"));if(!D){const p=n?.deps.pool.admit();if(p)throw new Error(p)}if(u.background){if(!n)throw new Error(e("\u8FD9\u4E2A\u4F1A\u8BDD\u4E0D\u652F\u6301\u540E\u53F0\u5B50\u52A9\u624B\u3002"));if(t.mode==="print"||t.mode==="json")throw new Error(e("\u5355\u6B21\u8FD0\u884C\uFF08-p\uFF09\u7ED3\u675F\u540E\u6536\u4E0D\u5230\u540E\u53F0\u7ED3\u679C\uFF1A\u4E0D\u8981\u7528 background\uFF0C\u76F4\u63A5\u8FD0\u884C\u3002"));return Cu(u,t,a,n,c,s)}if(!F){let p=D?void 0:_(a,u.agent);const C=!D&&p===void 0?await Eu(u.prompt??"",a,{credentials:t.modelRegistry}):void 0;C&&(p=C.agent);const f=await Q({description:u.description,prompt:h?u.prompt??"":"",readOnly:u.readOnly===!0,agent:p,resume:D,worktree:u.worktree===!0},t,r,o,c,s,u.worktree&&n?(S,b,P)=>n.pi.exec(S,b,P):void 0);return{content:[{type:"text",text:`${C?`${j(C)}
|
|
18
|
+
${f.text}`:f.text}
|
|
19
19
|
|
|
20
|
-
${
|
|
20
|
+
${x(f.subagentId)}`}],details:{description:u.description,...f.agent?{agent:f.agent}:{},subagentId:f.subagentId,...f.autoResumed?{autoResumed:!0}:{},...B(),...C?{autoAgent:{name:C.agent.name,confidence:C.confidence}}:{},...f.changedFiles.length>0?{changedFiles:f.changedFiles}:{},...f.worktree?{worktree:f.worktree}:{}},...B()}}const g=u.chain??[],w=g.map(p=>_(a,p.agent??u.agent));let k="";const $=[],y=[];let v=!1;for(const[p,C]of g.entries()){const f=w[p],S=`${u.description} [${p+1}/${g.length}${f?` ${f.name}`:""}]`;try{const{text:b,changedFiles:P,subagentId:wu,autoResumed:$u}=await Q({description:S,prompt:Y(C.prompt,k),readOnly:u.readOnly===!0,agent:f},t,r,o,c,s);k=b,$.push(...P),y.push(wu),v||=$u}catch(b){const P=b instanceof Error?b.message:String(b);throw new Error(`${e("\u4E32\u884C\u94FE\u5728\u7B2C")} ${p+1} ${e("\u6B65\u4E2D\u65AD\uFF1A")}${P}`)}}const I=[...new Set($)],A=y[y.length-1]??"";return{content:[{type:"text",text:`${k}
|
|
21
21
|
|
|
22
|
-
${
|
|
23
|
-
`);const g=await
|
|
24
|
-
`:""}${e("\u5DF2\u5728\u540E\u53F0\u542F\u52A8\uFF1B\u5B8C\u6210\u540E\u62A5\u544A\u4F1A\u4EE5\u6D88\u606F\u9001\u56DE\uFF0C\u4E0D\u7528\u7B49\u5F85\u6216\u8F6E\u8BE2\u3002")} (${e("\u8FD0\u884C\u4E2D")} ${k}, ${e("\u6392\u961F")} ${
|
|
25
|
-
${g?`${
|
|
26
|
-
`:""}${
|
|
27
|
-
${e("\u5F53\u524D\uFF1A")}${du()}`,"info");return}try{
|
|
28
|
-
`),
|
|
22
|
+
${x(A)}`}],details:{description:u.description,subagentId:A,...v?{autoResumed:!0}:{},...B(),chain:w.map((p,C)=>({...p?{agent:p.name}:{},subagentId:y[C]})),...I.length>0?{changedFiles:I}:{}},...B()}}d(fu,"Ye"),i(fu,"executeTask");async function Cu(u,t,r,o,c,s){let n=_(r,u.agent);const E=n===void 0?await Eu(u.prompt??"",r,{credentials:t.modelRegistry}):void 0;E&&(n=E.agent);const a={description:u.description,prompt:u.prompt??"",readOnly:u.readOnly===!0,agent:n},F=await K(a,t),h=F.model.indexOf("/"),D=t.modelRegistry.find(F.model.slice(0,h),F.model.slice(h+1));if(!D)throw new Error(`${e("\u627E\u4E0D\u5230\u89D2\u8272\u6307\u5B9A\u7684\u6A21\u578B\uFF1A")}${F.model}`);const B=tu(),l=cu();eu(l,{recursive:!0}),Fu(l),nu(W(l,B),`${JSON.stringify(F)}
|
|
23
|
+
`);const g=await Qu(B,{mode:t.mode}),w=ju(t.tools.map(y=>y.name),{...F.tools?{allow:F.tools}:{},...c?{exclude:c}:{}});o.deps.background().start({id:B,description:u.description,...n?{agent:n.name}:{},run:{parent:t,toolNames:w,toolInfos:o.pi.getAllTools(),model:D,thinking:F.thinking,appendSystemPrompt:F.appendSystemPrompt,prompt:a.prompt,session:{dir:l,id:B},...g?{tmux:g}:{}},...s?{signal:s.signal}:{},parentIdle:i(()=>t.isIdle(),"parentIdle"),onAccountLimit:i(y=>s?.trip(y),"onAccountLimit")});const{running:k,queued:$}=o.deps.pool.stats;return{content:[{type:"text",text:`${E?`${j(E)}
|
|
24
|
+
`:""}${e("\u5DF2\u5728\u540E\u53F0\u542F\u52A8\uFF1B\u5B8C\u6210\u540E\u62A5\u544A\u4F1A\u4EE5\u6D88\u606F\u9001\u56DE\uFF0C\u4E0D\u7528\u7B49\u5F85\u6216\u8F6E\u8BE2\u3002")} (${e("\u8FD0\u884C\u4E2D")} ${k}, ${e("\u6392\u961F")} ${$})
|
|
25
|
+
${g?`${Ku(g)}
|
|
26
|
+
`:""}${x(B)}`}],details:{description:u.description,subagentId:B,background:!0,...n?{agent:n.name}:{},...E?{autoAgent:{name:E.agent.name,confidence:E.confidence}}:{}}}}d(Cu,"Ze"),i(Cu,"startBackground");function uu(u){const{tmux:t}=u;return t?Xu({...u,tmux:t}):Ru(u)}d(uu,"ae"),i(uu,"runBackground");function hu(u){if(zu(u),Nu()>=Gu)return;const t=new Du,r=new Mu;let o=new iu(u,r,uu);const c={accountStop:t,pool:r,background:i(()=>o,"background")};V(u,ou({cwd:process.cwd(),projectTrusted:!1}).agents,c),u.on("session_start",async(s,n)=>{o=new iu(u,r,uu),V(u,L(n).agents,c)}),u.on("session_shutdown",()=>{o.close()}),u.on("message_end",s=>{const n=s.message;n.role==="assistant"&&Pu(n)&&t.trip(n.errorMessage??"account limit")}),u.on("agent_start",()=>{t.reset(),r.resetRun()}),u.on("tool_result",s=>{const n=s.toolName==="task"&&s.isError?Z.get(s.toolCallId):void 0;if(Z.delete(s.toolCallId),!n)return;const E=s.input.description??"";return{usage:n,details:{description:E,usage:n}}}),u.registerCommand("agents",{description:e("\u5217\u51FA\u5B50 agent \u89D2\u8272\u548C\u6B63\u5728\u540E\u53F0\u8FD0\u884C\u7684\u5B50\u52A9\u624B\uFF1B/agents steer <ID> <\u6307\u793A> \u8C03\u6574\u65B9\u5411\uFF0C/agents stop <ID> \u505C\u6B62\u4E00\u4E2A\uFF0C/agents tmux on|off \u5207\u6362 tmux \u7A97\u53E3"),handler:i(async(s,n)=>{const[E,a]=s.trim().split(/\s+/);if(E==="tmux"){if(a!=="on"&&a!=="off"){n.ui.notify(`${e("\u7528\u6CD5\uFF1A/agents tmux on|off\uFF08\u540E\u53F0\u5B50\u52A9\u624B\u662F\u5426\u5728\u72EC\u7ACB\u7684 tmux \u7A97\u53E3\u8FD0\u884C\uFF09")}
|
|
27
|
+
${e("\u5F53\u524D\uFF1A")}${du()}`,"info");return}try{Hu(a)}catch(l){n.ui.notify(`${e("\u4FDD\u5B58\u5931\u8D25\uFF1A")}${l instanceof Error?l.message:String(l)}`,"error");return}n.ui.notify(a==="on"?e("\u5DF2\u5F00\u542F\uFF1A\u4E4B\u540E\u7684\u540E\u53F0\u5B50\u52A9\u624B\u5728\u72EC\u7ACB\u7684 tmux \u7A97\u53E3\u8FD0\u884C\uFF0C\u7B49\u4F60\u786E\u8BA4\u65F6\u4F1A\u5728\u8FD9\u91CC\u63D0\u793A\u7A97\u53E3\u53F7"):e("\u5DF2\u5173\u95ED\uFF1A\u540E\u53F0\u5B50\u52A9\u624B\u56DE\u5230\u5F53\u524D\u8FDB\u7A0B\u91CC\u8FD0\u884C"),"info");return}if(E==="steer"){const l=s.trim().replace(/^steer\s+\S+\s*/,"").trim();if(!a||!l){n.ui.notify(e("\u7528\u6CD5\uFF1A/agents steer <ID> <\u65B0\u7684\u6307\u793A>\uFF08ID \u89C1 /agents \u5217\u8868\uFF09"),"warning");return}const g=await o.steer(a,l);n.ui.notify(g??e("\u5DF2\u628A\u65B0\u6307\u793A\u9001\u8FBE\u540E\u53F0\u5B50\u52A9\u624B\u3002"),g?"warning":"info");return}if(E==="stop"){const l=a?o.stop(a):!1;n.ui.notify(l?e("\u5DF2\u505C\u6B62\u8BE5\u540E\u53F0\u5B50\u52A9\u624B\u3002"):e("\u7528\u6CD5\uFF1A/agents stop <ID>\uFF08ID \u89C1 /agents \u5217\u8868\uFF09"),l?"info":"warning");return}const F=o.active(),{agents:h,diagnostics:D}=L(n),B=[e("\u53EF\u7528\u7684\u5B50 agent \u89D2\u8272\uFF1A"),ru(h,!0),"",`${e("\u7528\u6237\u89D2\u8272\u76EE\u5F55\uFF1A")}${Tu()}`,`${e("\u9879\u76EE\u89D2\u8272\u76EE\u5F55\uFF1A")}${Ou(n.cwd)}${n.isProjectTrusted()?"":e("\uFF08\u9879\u76EE\u672A\u4FE1\u4EFB\uFF0C\u672A\u8BFB\u53D6\uFF09")}`];F.length>0&&B.unshift(e("\u540E\u53F0\u5B50\u52A9\u624B\uFF1A"),...F.map(l=>`- ${l.id.slice(0,8)} ${l.description} \xB7 ${l.status==="queued"?e("\u6392\u961F"):e("\u8FD0\u884C\u4E2D")} ${Math.round((Date.now()-l.startedAt)/1e3)}s`),""),D.length>0&&B.push("",e("\u4EE5\u4E0B\u89D2\u8272\u6587\u4EF6\u6709\u95EE\u9898\uFF1A"),...D.map(l=>`- ${l}`)),process.env.TMUX&&du()==="off"&&B.push("",e("\u4F60\u5728 tmux \u91CC\uFF1A/agents tmux on \u53EF\u8BA9\u540E\u53F0\u5B50\u52A9\u624B\u5728\u72EC\u7ACB\u7A97\u53E3\u8FD0\u884C\uFF0C\u4FBF\u4E8E\u67E5\u770B\u548C\u63A5\u7BA1\u3002")),n.ui.notify(B.join(`
|
|
28
|
+
`),D.length>0?"warning":"info")},"handler")})}d(hu,"Ve"),i(hu,"default");export{Du as AccountLimitStop,U as SMALL_PROJECT_FILES,pu as TASK_TOOL_GUIDELINES,O as accountLimitMessage,j as autoRoleNote,H as buildSubagentSystemPrompt,T as continuePrompt,hu as default,Y as fillPrevious,q as gitProjectFileCount,z as lastAssistantText,M as resolveAgentModel,G as smallProjectRefusal,x as subagentIdLine,R as worktreeLine};
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-telemetry",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.42",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
|
9
9
|
"./config": "./src/config.js",
|
|
10
|
+
"./consent": "./src/consent.js",
|
|
10
11
|
"./redact": "./src/redact.js",
|
|
11
12
|
"./reporter": "./src/reporter.js",
|
|
13
|
+
"./failures": "./src/failures.js",
|
|
14
|
+
"./failure-queue": "./src/failure-queue.js",
|
|
15
|
+
"./failure-reporting": "./src/failure-reporting.js",
|
|
16
|
+
"./repro": "./src/repro.js",
|
|
12
17
|
"./package.json": "./package.json"
|
|
13
18
|
},
|
|
14
19
|
"files": [
|
|
@@ -20,7 +25,8 @@
|
|
|
20
25
|
]
|
|
21
26
|
},
|
|
22
27
|
"dependencies": {
|
|
23
|
-
"@dalcode/dal-
|
|
28
|
+
"@dalcode/dal-learn": "1.0.42",
|
|
29
|
+
"@dalcode/dal-pi-kit": "1.0.42"
|
|
24
30
|
},
|
|
25
31
|
"peerDependencies": {
|
|
26
32
|
"@earendil-works/pi-coding-agent": "^1.0.9"
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
`,{mode:384}),
|
|
1
|
+
var Y=Object.defineProperty;var a=(t,e)=>Y(t,"name",{value:e,configurable:!0});var x=Object.defineProperty,s=a((t,e)=>x(t,"name",{value:e,configurable:!0}),"s");import{randomUUID as v}from"node:crypto";import{existsSync as b,mkdirSync as R,readFileSync as B,renameSync as D,writeFileSync as N}from"node:fs";import{join as G}from"node:path";import{newReporterId as O}from"./failures.js";import{DEFAULT_ENDPOINT as H}from"./reporter.js";const h=720*60*60*1e3;function y(t=process.env){const e=t.DAL_TELEMETRY_ENDPOINT??H;return e.length>0?e:void 0}a(y,"_"),s(y,"resolveEndpoint");function S(t){return!!(t.CI||t.GITHUB_ACTIONS||t.GITLAB_CI||t.BUILDKITE||t.JENKINS_URL)}a(S,"T"),s(S,"isCi");function c(t){return G(t,"telemetry.json")}a(c,"a"),s(c,"telemetryPath");function u(t){try{const e=JSON.parse(B(t,"utf8"));return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0}catch{return}}a(u,"c"),s(u,"readRaw");function I(t){return l(c(t))}a(I,"j"),s(I,"readTelemetryState");function l(t){const e=u(t);if(!e||typeof e.anonymousId!="string"||typeof e.enabled!="boolean")return;const n=s(r=>typeof r=="string"?r:void 0,"text");return{enabled:e.enabled,anonymousId:e.anonymousId,consentedAt:n(e.consentedAt),decidedAt:n(e.decidedAt),askedAt:n(e.askedAt),notifiedAt:n(e.notifiedAt)}}a(l,"l"),s(l,"readState");function k(t){return!!(t?.enabled&&t.consentedAt)}a(k,"F"),s(k,"hasConsented");function A(t){return!!(t&&!t.enabled&&(t.decidedAt||t.notifiedAt))}a(A,"k"),s(A,"hasOptedOut");function p(t,e){try{R(t,{recursive:!0});const n=c(t),r=`${n}.${process.pid}.tmp`,o={...u(n),...e};for(const i of["consentedAt","decidedAt","askedAt","notifiedAt"])e[i]===void 0&&delete o[i];return N(r,`${JSON.stringify(o,null," ")}
|
|
2
|
+
`,{mode:384}),D(r,n),!0}catch{return!1}}a(p,"E"),s(p,"writeState");function _(t,e=process.env,n=Date.now()){const r=c(t),o=l(r),i=o??{enabled:!1,anonymousId:v()},d=s(J=>({state:i,active:!1,shouldAsk:!1,reason:J}),"off");if(!o&&b(r))return d("unreadable");if(A(o))return d("opted-out");if(e.DO_NOT_TRACK==="1"||e.DO_NOT_TRACK==="true")return d("do-not-track");if(e.DAL_TELEMETRY==="0"||e.DAL_TELEMETRY==="off")return d("env");if(S(e))return d("ci");if(!y(e))return d("unconfigured");if(k(o))return{state:i,active:!0,shouldAsk:!1};const f=i.askedAt?Date.parse(i.askedAt):Number.NaN,$=!Number.isFinite(f)||n-f>=h;return{state:{...i,enabled:!1},active:!1,shouldAsk:$,reason:"not-decided"}}a(_,"Y"),s(_,"resolveTelemetry");function g(t,e,n=Date.now()){const r={...l(c(t))??e,enabled:!1,consentedAt:void 0,askedAt:new Date(n).toISOString()};return p(t,r),r}a(g,"G"),s(g,"markAsked");function F(t,e,n=Date.now()){const r=new Date(n).toISOString(),o={...l(c(t))??{enabled:e,anonymousId:v()},enabled:e,consentedAt:e?r:void 0,decidedAt:r,askedAt:void 0};return p(t,o),o}a(F,"H"),s(F,"setTelemetryEnabled");const L="",w=720*60*60*1e3,C=720*60*60*1e3;function E(t=process.env){const e=(t.DAL_FAILURE_ENDPOINT??L).trim();if(e)try{const n=new URL(e),r=n.hostname==="127.0.0.1"||n.hostname==="localhost"||n.hostname==="[::1]";if(n.protocol==="https:"||n.protocol==="http:"&&r)return e.replace(/\/+$/,"")}catch{}}a(E,"v"),s(E,"resolveFailureEndpoint");function T(t){const e=u(c(t))?.failureReports;return!e||typeof e!="object"||typeof e.enabled!="boolean"?e&&typeof e=="object"&&typeof e.askedAt=="string"?{enabled:!1,askedAt:e.askedAt,decidedAt:void 0}:void 0:{enabled:e.enabled,decidedAt:typeof e.decidedAt=="string"?e.decidedAt:void 0,askedAt:typeof e.askedAt=="string"?e.askedAt:void 0,reporter:typeof e.reporter=="string"?e.reporter:void 0,reporterSince:typeof e.reporterSince=="string"?e.reporterSince:void 0}}a(T,"P"),s(T,"readFailureConsent");function m(t,e){try{R(t,{recursive:!0});const n=c(t),r=`${n}.${process.pid}.tmp`,o=u(n)??{},i={...typeof o.anonymousId=="string"&&typeof o.enabled=="boolean"?o:{enabled:!1,anonymousId:v(),...o},failureReports:JSON.parse(JSON.stringify(e))};return N(r,`${JSON.stringify(i,null," ")}
|
|
3
|
+
`,{mode:384}),D(r,n),!0}catch{return!1}}a(m,"p"),s(m,"writeFailureConsent");const U=s(t=>t==="0"||t==="off"||t==="false","isOff");function P(t,e=process.env,n=Date.now()){const r=c(t);if(b(r)&&!u(r))return{active:!1,shouldAsk:!1,reason:"unreadable"};const o=l(r);if(A(o))return{active:!1,shouldAsk:!1,reason:"opted-out"};if(e.DO_NOT_TRACK==="1"||e.DO_NOT_TRACK==="true")return{active:!1,shouldAsk:!1,reason:"do-not-track"};if(U(e.DAL_TELEMETRY)||U(e.DAL_FAILURE_REPORTS))return{active:!1,shouldAsk:!1,reason:"env"};if(S(e))return{active:!1,shouldAsk:!1,reason:"ci"};const i=E(e);if(!i)return{active:!1,shouldAsk:!1,reason:"unconfigured"};const d=T(t);if(!d||d.decidedAt===void 0){const f=d?.askedAt?Date.parse(d.askedAt):Number.NaN;return{active:!1,shouldAsk:!Number.isFinite(f)||n-f>=C,reason:"not-decided",endpoint:i,consent:d}}return d.enabled?{active:!0,shouldAsk:!1,endpoint:i,consent:d}:{active:!1,shouldAsk:!1,reason:"declined",endpoint:i,consent:d}}a(P,"q"),s(P,"resolveFailureReporting");function K(t,e,n=Date.now()){const r=new Date(n).toISOString(),o=e?{enabled:!0,decidedAt:r,reporter:O(),reporterSince:r}:{enabled:!1,decidedAt:r};return m(t,o),o}a(K,"z"),s(K,"setFailureReporting");function M(t,e=Date.now()){m(t,{askedAt:new Date(e).toISOString()})}a(M,"Q"),s(M,"markFailureAsked");function j(t,e,n=Date.now()){const r=e.reporterSince?Date.parse(e.reporterSince):Number.NaN;if(e.reporter&&Number.isFinite(r)&&n-r<w)return e.reporter;const o={...e,reporter:O(),reporterSince:new Date(n).toISOString()};return m(t,o),o.reporter}a(j,"V"),s(j,"currentReporter");export{L as DEFAULT_FAILURE_ENDPOINT,C as REASK_AFTER_MS,w as REPORTER_ROTATE_MS,h as TELEMETRY_REASK_MS,j as currentReporter,k as hasConsented,A as hasOptedOut,g as markAsked,M as markFailureAsked,T as readFailureConsent,I as readTelemetryState,y as resolveEndpoint,E as resolveFailureEndpoint,P as resolveFailureReporting,_ as resolveTelemetry,K as setFailureReporting,F as setTelemetryEnabled,c as telemetryPath,p as writeState};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var R=Object.defineProperty;var r=(e,t)=>R(e,"name",{value:t,configurable:!0});var D=Object.defineProperty,o=r((e,t)=>D(e,"name",{value:t,configurable:!0}),"t");import{hasConsented as c,hasOptedOut as u,readFailureConsent as p,readTelemetryState as f,resolveFailureEndpoint as L,resolveFailureReporting as _,resolveTelemetry as T,setFailureReporting as C,setTelemetryEnabled as g}from"./config.js";import{FailureQueue as N}from"./failure-queue.js";function m(e,t=process.env,a=Date.now()){const n=T(e,t,a),s=_(e,t,a),i=p(e),l=f(e);return{usage:{decided:c(l)||u(l),enabled:c(l),active:n.active,...n.active?{}:{reason:n.reason}},failures:{decided:i?.decidedAt!==void 0,enabled:i?.decidedAt!==void 0&&i.enabled,active:s.active,...s.active?{}:{reason:s.reason}}}}r(m,"A"),o(m,"getTelemetryConsent");function b(e,t){new N({agentDir:e,endpoint:L(t)??"http://127.0.0.1"}).clear()}r(b,"R"),o(b,"clearFailureQueue");function y(e,t,a=process.env,n=Date.now()){return g(e,t.usage,n),t.failures!==void 0&&C(e,t.failures,n),(!t.usage||t.failures===!1)&&b(e,a),v(),m(e,a,n)}r(y,"h"),o(y,"setTelemetryConsent");const A=o(e=>e==="granted"?!0:e==="denied"?!1:void 0,"parseConsent");function h(e,t=process.env,a=Date.now()){const n=A(t.DAL_TELEMETRY_CONSENT),s=A(t.DAL_FAILURE_REPORTS_CONSENT);if(n===void 0&&s===void 0)return{};if(T(e,t,a).reason==="unreadable")return{};const i={},l=f(e);return n!==void 0&&!c(l)&&!u(l)&&(g(e,n,a),i.usage=n),s!==void 0&&p(e)?.decidedAt===void 0&&(s&&u(f(e))||(C(e,s,a),i.failures=s)),i}r(h,"O"),o(h,"applyConsentFromEnv");const E=Symbol.for("dalcode.telemetry.startupAnswer");function S(){const e=globalThis,t=e[E];return delete e[E],typeof t=="boolean"?t:void 0}r(S,"P"),o(S,"takeStartupTelemetryAnswer");const k=Symbol.for("dalcode.telemetry.consentApi");function F(e){globalThis[k]={set:o(t=>y(e,t),"set")}}r(F,"w"),o(F,"registerTelemetryConsentApi");const w=Symbol.for("dalcode.telemetry.consentListeners");function d(){const e=globalThis;return e[w]??=new Set,e[w]}r(d,"c"),o(d,"listeners");function O(e){return d().add(e),()=>d().delete(e)}r(O,"k"),o(O,"onTelemetryConsentChanged");function v(){for(const e of[...d()])try{e()}catch{}}r(v,"F"),o(v,"notifyTelemetryConsentChanged");export{h as applyConsentFromEnv,m as getTelemetryConsent,v as notifyTelemetryConsentChanged,O as onTelemetryConsentChanged,F as registerTelemetryConsentApi,y as setTelemetryConsent,S as takeStartupTelemetryAnswer};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var R=Object.defineProperty;var p=(r,t)=>R(r,"name",{value:t,configurable:!0});var Z=Object.defineProperty,h=p((r,t)=>Z(r,"name",{value:t,configurable:!0}),"a");import{chmodSync as F,existsSync as q,mkdirSync as z,readFileSync as C,renameSync as D,rmSync as v,writeFileSync as H}from"node:fs";import{dirname as N,join as Q}from"node:path";import{validateSymptom as Y}from"./failures.js";const _="dal.failure-repro/v1",j="dal.failure-batch/v1",$=12e3,k=200,M=336*60*60*1e3,x=10,O=50,B=3e3,J=360*60*1e3;function l(r){return Q(r,"telemetry-failures.jsonl")}p(l,"S"),h(l,"queuePath");const X=[["user path",/(?:\/Users\/|\/home\/|[A-Za-z]:\\Users\\)[^\s/\\<]+/],["api key",/\b(?:sk|pk|rk)-[A-Za-z0-9_-]{8,}/],["github token",/\b(?:ghp|gho|ghu|ghs|ghr|github_pat)_[A-Za-z0-9_]{8,}/],["jwt",/\beyJ[A-Za-z0-9._-]{16,}/],["aws key",/\bAKIA[0-9A-Z]{12,}/],["private key",/-----BEGIN [A-Z ]*PRIVATE KEY-----/],["bearer",/\bBearer\s+(?!<)[A-Za-z0-9._~+/=-]{8,}/i]];function w(r){const t=[];if(typeof r!="object"||r===null||Array.isArray(r))return["not an object"];const s=r,i=["schema","symptomId","day","consentedOn","excerpt"];for(const e of Object.keys(s))i.includes(e)||t.push(`${e}: unknown field`);s.schema!==_&&t.push("schema: wrong"),(typeof s.symptomId!="string"||!/^fs-[0-9a-f]{20}$/.test(s.symptomId))&&t.push("symptomId: wrong shape");for(const e of["day","consentedOn"])(typeof s[e]!="string"||!/^\d{4}-\d{2}-\d{2}$/.test(s[e]))&&t.push(`${e}: not YYYY-MM-DD`);if(typeof s.excerpt!="string"||s.excerpt.length>$)t.push("excerpt: not a short string");else for(const[e,o]of X)o.test(s.excerpt)&&t.push(`excerpt: ${e}`);return t}p(w,"N"),h(w,"validateRepro");function d(r){return r.kind==="symptom"?Y(r.payload):w(r.payload)}p(d,"w"),h(d,"validateItem");class G{static{p(this,"K")}static{h(this,"FailureQueue")}path;fetchImpl;now;endpoint;flushing;stopped=!1;constructor(t){this.path=l(t.agentDir),this.endpoint=t.endpoint.replace(/\/+$/,""),this.fetchImpl=t.fetchImpl??globalThis.fetch,this.now=t.now??Date.now}list(){let t;try{t=C(this.path,"utf8")}catch{return[]}const s=[];for(const i of t.split(`
|
|
2
|
+
`))if(i.trim())try{const e=JSON.parse(i);e&&(e.kind==="symptom"||e.kind==="repro")&&typeof e.payload=="object"&&s.push(e)}catch{}return s}write(t){try{if(t.length===0){v(this.path,{force:!0});return}z(N(this.path),{recursive:!0});const s=`${this.path}.${process.pid}.tmp`;H(s,`${t.map(i=>JSON.stringify(i)).join(`
|
|
3
|
+
`)}
|
|
4
|
+
`,{mode:384}),D(s,this.path),F(this.path,384)}catch{}}enqueue(t,s){if(this.stopped)return!1;const i={kind:t,payload:s,queuedAt:this.now(),attempts:0,nextAttemptAt:0};if(d(i).length>0)return!1;const e=this.prune(this.list());return e.push(i),this.write(e.slice(-k)),!0}prune(t){const s=this.now();return t.filter(i=>s-i.queuedAt<M&&i.attempts<x&&d(i).length===0).slice(-k)}clear(){this.stopped=!0;try{v(this.path,{force:!0})}catch{}}get pending(){return this.list().length}flush(t=B){return this.stopped?Promise.resolve({sent:0,kept:0,dropped:0}):(this.flushing??=this.doFlush(t).finally(()=>{this.flushing=void 0}),this.flushing)}async post(t,s,i){const e=i-this.now();if(e<=0)return"retry";try{const o=await this.fetchImpl(`${this.endpoint}${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s),signal:AbortSignal.timeout(e)});return o.ok?"ok":o.status>=400&&o.status<500&&o.status!==408&&o.status!==429?"rejected":"retry"}catch{return"retry"}}async doFlush(t){const s=this.list(),i=this.prune(s);let e=s.length-i.length;const o=this.now(),f=i.filter(n=>n.nextAttemptAt<=o);if(f.length===0)return e&&this.write(i),{sent:0,kept:i.length,dropped:e};const S=o+t,m=new Set,y=new Set;let g=0;const b=f.filter(n=>n.kind==="symptom");for(let n=0;n<b.length;n+=O){const a=b.slice(n,n+O),u=await this.post("/failures",{schema:j,symptoms:a.map(A=>A.payload)},S);for(const A of a)(u==="retry"?y:m).add(A);if(u==="ok"&&(g+=a.length),u==="rejected"&&(e+=a.length),u==="retry")break}for(const n of f.filter(a=>a.kind==="repro")){if(this.stopped)break;const a=await this.post("/failure-repro",n.payload,S);(a==="retry"?y:m).add(n),a==="ok"&&g++,a==="rejected"&&e++}if(this.stopped)return{sent:0,kept:0,dropped:0};const P=new Set([...m].map(n=>c(n))),T=new Set([...y].map(n=>c(n))),I=this.prune(this.list()).filter(n=>!P.has(c(n))).map(n=>{if(!T.has(c(n)))return n;const a=n.attempts+1;return{...n,attempts:a,nextAttemptAt:o+Math.min(J,6e4*2**a)}});return this.write(I),{sent:g,kept:I.length,dropped:e}}}function c(r){return r.kind==="symptom"?`s:${String(r.payload.id)}`:`r:${r.payload.symptomId}`}p(c,"c"),h(c,"idOf");function E(r){return q(l(r))}p(E,"G"),h(E,"hasQueue");export{j as BATCH_SCHEMA,G as FailureQueue,M as MAX_AGE_MS,x as MAX_ATTEMPTS,k as MAX_ITEMS,$ as MAX_REPRO_CHARS,_ as REPRO_SCHEMA,E as hasQueue,l as queuePath,d as validateItem,w as validateRepro};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var L=Object.defineProperty;var w=(i,F)=>L(i,"name",{value:F,configurable:!0});var S=Object.defineProperty,D=w((i,F)=>S(i,"name",{value:F,configurable:!0}),"f");import{platform as j}from"node:os";import{t as e}from"@dalcode/dal-pi-kit";import{currentReporter as J,markFailureAsked as M,resolveFailureReporting as I,setFailureReporting as v}from"./config.js";import{FailureQueue as b}from"./failure-queue.js";import{buildSymptom as P,classifyRun as Q,isCorrection as U}from"./failures.js";import{buildRepro as z}from"./repro.js";const H=5e3,K=1e3,O=1500,_=D((i,F)=>i.replace(/\{(\w+)\}/g,(a,m)=>m in F?String(F[m]):a),"fill");function T(i,F){const{agentDir:a,version:m}=F,x=F.env??process.env,r=F.now??Date.now;let o=I(a,x,r()),p,l,C=!1;const d=D(()=>{if(!(!o.active||!o.endpoint))return p??=new b({agentDir:a,endpoint:o.endpoint,fetchImpl:F.fetchImpl,now:r}),p},"queueFor"),E=D(()=>{o=I(a,x,r()),o.active||(l&&clearTimeout(l),l=void 0,p=void 0)},"refresh"),k=D(()=>{l||!d()||(l=setTimeout(()=>{l=void 0,d()?.flush()},H),l.unref?.())},"scheduleFlush"),$=D(()=>{v(a,!1,r()),new b({agentDir:a,endpoint:o.endpoint??"http://127.0.0.1",now:r}).clear(),p?.clear(),E()},"turnOff");let f,B,A;const y=D((t,u)=>{const n=B;if(B=void 0,!n)return;const c=d();if(!(!c||!o.consent))try{const s=P({...n,correctedNext:t},{version:m,platform:j(),model:u?.model?{id:u.model.id,provider:u.model.provider}:void 0,reporter:J(a,o.consent,r()),now:new Date(r())});if(!s)return;c.enqueue("symptom",s)&&(A={symptomId:s.id,messages:n.messages,attached:!1},k())}catch{}},"finalize");i.on("session_start",async()=>{E(),C=!1,o.active&&d()?.flush()}),i.on("agent_start",async()=>{f={startedAt:r(),compactions:0,compactionFailed:!1}}),i.on("session_compact",async()=>{f&&f.compactions++}),i.on("session_compact_failed",async t=>{f&&!t.aborted&&(f.compactionFailed=!0)}),i.on("agent_end",async(t,u)=>{B&&y(!1,u),B={messages:t.messages,aborted:!1,durationMs:f?r()-f.startedAt:0,compactions:f?.compactions??0,compactionFailed:f?.compactionFailed??!1},f=void 0}),i.on("agent_settled",async(t,u)=>{if(!B||(B.aborted=t.aborted,!o.shouldAsk||C||!u.hasUI))return;let n=!1;try{n=Q({...B,correctedNext:!1}).length>0}catch{n=!1}if(!n)return;C=!0;const c=e("\u5141\u8BB8\uFF08\u53EA\u53D1\u5931\u8D25\u7C7B\u522B\u3001\u5DE5\u5177\u540D\u4E0E\u6B21\u6570\u3001\u6A21\u578B\u548C\u7248\u672C\uFF0C\u4E0D\u542B\u63D0\u793A\u8BCD\u3001\u4EE3\u7801\u3001\u6587\u4EF6\u8DEF\u5F84\u548C\u5BC6\u94A5\uFF09"),s=e("\u4E0D\u5141\u8BB8"),h=e("\u4EE5\u540E\u518D\u95EE"),R=await u.ui.select(e("\u8FD9\u6B21\u4EFB\u52A1\u597D\u50CF\u6CA1\u987A\u5229\u5B8C\u6210\u3002\u5141\u8BB8 DAL \u4E0A\u62A5\u533F\u540D\u7684\u5931\u8D25\u75C7\u72B6\uFF0C\u5E2E\u52A9\u6539\u8FDB\u4EA7\u54C1\u5417\uFF1F"),[c,s,h]);R===c?(v(a,!0,r()),E(),u.ui.notify(e("\u5DF2\u5F00\u542F\u5931\u8D25\u75C7\u72B6\u4E0A\u62A5\u3002/telemetry failures show \u67E5\u770B\u5F85\u53D1\u9001\u5185\u5BB9\uFF0C/telemetry failures off \u968F\u65F6\u5173\u95ED\u3002"),"info")):R===s?($(),u.ui.notify(e("\u4E0D\u4F1A\u4E0A\u62A5\u3002\u6539\u4E3B\u610F\u53EF\u4EE5\u7528 /telemetry failures on\u3002"),"info")):(M(a,r()),E())}),i.on("input",async(t,u)=>(B&&t.source!=="extension"&&y(U(t.text),u),{action:"continue"})),i.on("session_shutdown",async(t,u)=>{y(!1,u),l&&clearTimeout(l),l=void 0;const n=d();n&&n.pending>0&&await n.flush(K)});const g=D(()=>{if(o.active){const u=d()?.pending??0;return _(e("\u5931\u8D25\u75C7\u72B6\u4E0A\u62A5\uFF1A\u5F00\u542F\uFF08\u5F85\u53D1\u9001 {n} \u6761\uFF09"),{n:u})}const t={"not-decided":e("\u5C1A\u672A\u9009\u62E9"),declined:e("\u4F60\u5DF2\u62D2\u7EDD"),"opted-out":e("\u533F\u540D\u9065\u6D4B\u5DF2\u5173\u95ED"),"do-not-track":e("DO_NOT_TRACK \u5DF2\u8BBE\u7F6E"),env:e("\u73AF\u5883\u53D8\u91CF\u5DF2\u5173\u95ED"),ci:e("\u68C0\u6D4B\u5230 CI \u73AF\u5883"),unconfigured:e("\u5C1A\u672A\u914D\u7F6E\u63A5\u6536\u7AEF"),unreadable:e("\u914D\u7F6E\u65E0\u6CD5\u8BFB\u53D6")};return`${e("\u5931\u8D25\u75C7\u72B6\u4E0A\u62A5\uFF1A\u5173\u95ED")}\uFF08${t[o.reason??"declined"]??""}\uFF09`},"statusLine"),q=D(async(t,u)=>{const n=t.trim().split(/\s+/);if(n[0]==="attach")return await N(u),!0;if(n[0]!=="failures")return!1;const c=n[1]??"";if(c==="on"){if(E(),o.reason==="unconfigured"||o.reason==="opted-out"||o.reason==="env")return u.ui.notify(g(),"warning"),!0;v(a,!0,r()),E(),u.ui.notify(e("\u5DF2\u5F00\u542F\u5931\u8D25\u75C7\u72B6\u4E0A\u62A5\u3002/telemetry failures show \u67E5\u770B\u5F85\u53D1\u9001\u5185\u5BB9\u3002"),"info")}else if(c==="off")$(),u.ui.notify(e("\u5DF2\u5173\u95ED\u5931\u8D25\u75C7\u72B6\u4E0A\u62A5\uFF0C\u5F85\u53D1\u9001\u7684\u5185\u5BB9\u5DF2\u6E05\u7A7A\u3002"),"info");else if(c==="show"){const s=d()?.list()??[];u.ui.notify(s.length===0?e("\u6CA1\u6709\u5F85\u53D1\u9001\u7684\u5931\u8D25\u75C7\u72B6\u3002"):`${_(e("\u5F85\u53D1\u9001 {n} \u6761\uFF08\u53D1\u9001\u5185\u5BB9\u539F\u6837\u5982\u4E0B\uFF09\uFF1A"),{n:s.length})}
|
|
2
|
+
${s.map(h=>JSON.stringify(h.payload)).join(`
|
|
3
|
+
`)}`,"info")}else u.ui.notify(`${g()}${e("\u3000\u7528 /telemetry failures on|off|show \u5207\u6362\u6216\u67E5\u770B")}`,"info");return!0},"handleCommand"),N=D(async t=>{const u=d();if(!u){t.ui.notify(e("\u8BF7\u5148\u7528 /telemetry failures on \u5F00\u542F\u5931\u8D25\u75C7\u72B6\u4E0A\u62A5\u3002"),"warning");return}if(!A||A.attached){t.ui.notify(e("\u672C\u6B21\u4F1A\u8BDD\u8FD8\u6CA1\u6709\u8BB0\u5F55\u5230\u5931\u8D25\uFF0C\u6CA1\u6709\u53EF\u9644\u5E26\u7684\u6750\u6599\u3002"),"info");return}const{payload:n,problems:c}=z(A.messages,A.symptomId,new Date(r()));if(c.length){t.ui.notify(e("\u8FD9\u6BB5\u6750\u6599\u91CC\u4ECD\u6709\u7591\u4F3C\u5BC6\u94A5\u6216\u4E2A\u4EBA\u8DEF\u5F84\uFF0C\u4E3A\u5B89\u5168\u8D77\u89C1\u4E0D\u53D1\u9001\u3002"),"warning");return}const s=n.excerpt.length>O?`${n.excerpt.slice(0,O)}\u2026`:n.excerpt;await t.ui.confirm(e("\u9644\u5E26\u8FD9\u6B21\u5931\u8D25\u7684\u590D\u73B0\u6750\u6599\uFF1F"),`${_(e("\u4F1A\u53D1\u9001\u8FD9\u6B21\u4EFB\u52A1\u7684\u8BF7\u6C42\u3001\u5DE5\u5177\u8C03\u7528\u548C\u622A\u65AD\u540E\u7684\u5DE5\u5177\u8F93\u51FA\uFF08\u5171 {n} \u5B57\uFF09\uFF0C\u5BC6\u94A5\u5DF2\u906E\u76D6\uFF0C\u654F\u611F\u6587\u4EF6\u4E0D\u542B\u5185\u5BB9\u3002\u53EA\u53D1\u8FD9\u4E00\u6B21\uFF0C\u4E0B\u6B21\u4ECD\u4F1A\u518D\u95EE\u3002"),{n:n.excerpt.length})}
|
|
4
|
+
|
|
5
|
+
${s}`)&&u.enqueue("repro",n)&&(A.attached=!0,u.flush(),t.ui.notify(e("\u5DF2\u52A0\u5165\u53D1\u9001\u961F\u5217\u3002"),"info"))},"attach");return{handleCommand:q,statusLine:g,refresh:E,stopAll:D(()=>{new b({agentDir:a,endpoint:o.endpoint??"http://127.0.0.1",now:r}).clear(),p?.clear(),E()},"stopAll"),get state(){return{decision:o,queue:p}}}}w(T,"X"),D(T,"setupFailureReporting");export{T as setupFailureReporting};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var L=Object.defineProperty;var l=(t,e)=>L(t,"name",{value:e,configurable:!0});var P=Object.defineProperty,c=l((t,e)=>P(t,"name",{value:e,configurable:!0}),"c");import{randomBytes as O}from"node:crypto";import{isCorrection as J,isDenial as B,toolSteps as T}from"@dalcode/dal-learn/signals";import{redactToolName as G}from"./redact.js";const S="dal.failure-symptom/v1",_=["tool_repeated_failure","edit_anchor_miss","loop","over_budget","context_overflow","ended_with_error","interrupted_then_corrected","user_correction","claimed_done_tests_failing","guard_denied"],x=["edit-anchor","validation","permission-denied","guard-blocked","sandbox-refused","timeout","non-zero-exit","not-found","network","rate-limit","context-overflow","provider-error","other"],H=["test","build","lint","typecheck","install"],E=["darwin","linux","win32","other"],V=new Set(["deepailab","anthropic","openai","openai-codex","google","google-vertex","google-gemini-cli","deepseek","openrouter","xai","groq","mistral","cerebras","zai","zai-coding-cn","moonshot","moonshotai","minimax","amazon-bedrock","azure-openai-responses","github-copilot","vercel-ai-gateway","huggingface","opencode"]),R=/^[a-z0-9][a-z0-9_.:@+-]{0,63}$/,Q=/^\d{1,4}\.\d{1,4}\.\d{1,6}(?:-[0-9a-z.-]{1,32})?$/,W=/^\d{4}-\d{2}-\d{2}$/,X=/^fs-[0-9a-f]{20}$/,tt=/^r-[0-9a-f]{16}$/,j=/^(?:[a-z][a-z0-9_]{0,31})(?::(?:test|build|lint|typecheck|install))?$/,u={categories:_.length,tools:16,sequence:32,count:1e4,durationSec:86400,costUsd:1e3,runCostUsd:2,runTurns:80},I=/could not find (?:the exact text|edits\[\d+\])|oldText must match|old text must match|anchor (?:is )?stale|锚点已过期|edit not applied|编辑未执行/i,U=/context[_ ]length|context window|maximum context|too many tokens|prompt is too long|input is too long|上下文(?:过长|超出)/i,et=new Set(["bash","powershell","shell"]);function $(t,e=""){return I.test(t)?"edit-anchor":/dal-guard|safety.?net|blocked by|was blocked|已拦截|拦截了|保护拒绝|用户已拒绝|needs approval|需要交互式审批/i.test(t)?"guard-blocked":/sandbox|沙箱|bwrap|seatbelt/i.test(t)?"sandbox-refused":et.has(e)?/command (?:timed out|was killed after)|timed out after|超时/i.test(t)?"timeout":/command not found|not recognized as an internal or external command|No such file or directory/i.test(t)?"not-found":/EACCES|permission denied|operation not permitted/i.test(t)?"permission-denied":"non-zero-exit":U.test(t)?"context-overflow":/\b429\b|rate.?limit|too many requests|限流/i.test(t)?"rate-limit":/timed? ?out|timeout|超时/i.test(t)?"timeout":/EACCES|EPERM|permission denied|operation not permitted|权限不足/i.test(t)?"permission-denied":/ENOTFOUND|ECONNREFUSED|ECONNRESET|EAI_AGAIN|network|socket hang up|fetch failed/i.test(t)?"network":/ENOENT|no such file|not found|cannot find|不存在|找不到/i.test(t)?"not-found":/validation|invalid (?:argument|input|parameter)|must be|schema/i.test(t)?"validation":/exited with code|exit code|non-zero|returned \d+/i.test(t)?"non-zero-exit":/\b5\d\d\b|provider|upstream|overloaded/i.test(t)?"provider-error":"other"}l($,"P"),c($,"classifyError");function k(t){const e=G(t.name);return t.intent?`${e}:${t.intent}`:e}l(k,"$"),c(k,"label");const ot=new Set(["edit","write","multi_edit","apply_patch"]);function C(t){return`${t.name}\0${JSON.stringify(t.args)}`}l(C,"w"),c(C,"callKey");function D(t){return typeof t=="string"?t:Array.isArray(t)?t.map(e=>e&&typeof e=="object"&&e.type==="text"?String(e.text??""):"").join(`
|
|
2
|
+
`):""}l(D,"G"),c(D,"textOf");const st=/\b(?:all (?:the )?tests? (?:now )?pass|tests? (?:now )?pass(?:es|ing)?|(?:is|are|has been|have been|now) (?:fixed|done|complete|implemented)|done\b|fixed\b)|完成了|已完成|已修复|已修好|修好了|测试(?:全部)?通过|全部通过|已通过/i,rt=/\bfail(?:s|ed|ing)?\b|\bstill\b|\bnot (?:yet )?pass|失败|未通过|没通过|还没|仍然/i;function A(t){const e=T(t.messages),i=t.messages.filter(s=>s?.role==="assistant"),o=new Set,a=new Map;let n=0;for(const s of e)s.isError?(a.set(s.name,(a.get(s.name)??0)+1),n++,n>=3&&o.add("tool_repeated_failure")):n=0;[...a.values()].some(s=>s>=3)&&o.add("tool_repeated_failure"),e.filter(s=>s.isError&&(s.name==="edit"||s.name==="write")&&I.test(s.output)).length>=2&&o.add("edit_anchor_miss");const f=new Map;for(const s of e){if(!s.isError&&ot.has(s.name)){f.clear();continue}const b=(f.get(C(s))??0)+1;f.set(C(s),b),b>=3&&o.add("loop")}const y=i.reduce((s,b)=>s+(b.usage?.cost?.total??0),0);(i.some(s=>s.stopReason==="length")||y>=u.runCostUsd||i.length>=u.runTurns)&&o.add("over_budget");const v=i.at(-1);if((t.compactionFailed||i.some(s=>s.stopReason==="error"&&U.test(s.errorMessage??"")))&&o.add("context_overflow"),v?.stopReason==="error"&&o.add("ended_with_error"),t.correctedNext&&o.add(t.aborted?"interrupted_then_corrected":"user_correction"),e.filter(s=>s.intent==="test").at(-1)?.isError&&!t.aborted){const s=D(v?.content);st.test(s)&&!rt.test(s)&&o.add("claimed_done_tests_failing")}return e.filter(B).length>=2&&o.add("guard_denied"),_.filter(s=>o.has(s))}l(A,"H"),c(A,"classifyRun");const h=c(t=>Math.max(0,Math.min(u.count,Math.round(t))),"clampCount");function Y(t){return E.includes(t)?t:"other"}l(Y,"V"),c(Y,"osOf");function M(t){const e=typeof t?.provider=="string"?t.provider.toLowerCase():"",i=typeof t?.id=="string"?t.id.toLowerCase():"";if(!e)return{provider:"unknown",id:"unknown"};if(!V.has(e))return{provider:"custom",id:"custom"};const o=i.split("/").at(-1)??"";return{provider:e,id:R.test(o)?o:"other"}}l(M,"J"),c(M,"redactModel");function z(){return`fs-${O(10).toString("hex")}`}l(z,"W"),c(z,"newSymptomId");function Z(){return`r-${O(8).toString("hex")}`}l(Z,"re"),c(Z,"newReporterId");function F(t,e){const i=A(t);if(i.length===0)return;const o=T(t.messages),a=t.messages.filter(r=>r?.role==="assistant"),n=new Map;for(const r of o){const d=k(r),p=n.get(d)??{tool:d,calls:0,errors:0,errorClasses:[]};if(p.calls++,r.isError){p.errors++;const N=$(r.output,r.name);p.errorClasses.includes(N)||p.errorClasses.push(N)}n.set(d,p)}const f=[...n.values()].sort((r,d)=>d.errors-r.errors||d.calls-r.calls||r.tool.localeCompare(d.tool)).slice(0,u.tools).map(r=>({...r,calls:h(r.calls),errors:h(r.errors),errorClasses:x.filter(d=>r.errorClasses.includes(d))})),y=[];for(const r of o){const d=k(r),p=y.at(-1);p&&p.tool===d&&p.ok===!r.isError?p.n++:y.push({tool:d,ok:!r.isError,n:1})}const v=Math.max(0,y.length-u.sequence),s=a.reduce((r,d)=>r+(d.usage?.cost?.total??0),0),b=e.now??new Date;return{schema:S,id:z(),day:b.toISOString().slice(0,10),reporter:e.reporter,client:{app:"dal-cli",version:e.version,os:Y(e.platform)},model:M(e.model),categories:i,tools:f,sequence:y.slice(v).map(r=>({...r,n:h(r.n)})),sequenceTruncated:h(v),stats:{turns:h(a.length),toolCalls:h(o.length),durationSec:Math.max(0,Math.min(u.durationSec,Math.round(t.durationMs/1e3))),costUsd:Math.max(0,Math.min(u.costUsd,Math.round(s*1e4)/1e4)),compactions:h(t.compactions)}}}l(F,"ie"),c(F,"buildSymptom");const nt=[["user path",/(?:\/Users\/|\/home\/|\/root\/|[A-Za-z]:\\\\?Users|~\/)/],["temp path",/\/tmp\/|\/private\/var\/|\/var\/folders\//],["any path",/[\\/][\w.-]+[\\/]/],["api key",/\b(?:sk|pk|rk)-[A-Za-z0-9_-]{8,}/],["github token",/\b(?:ghp|gho|ghu|ghs|ghr|github_pat)_[A-Za-z0-9_]{8,}/],["jwt",/\beyJ[A-Za-z0-9._-]{16,}/],["aws key",/\bAKIA[0-9A-Z]{12,}/],["private key",/PRIVATE KEY/],["bearer",/\bBearer\s/i],["long opaque",/[A-Za-z0-9+/_-]{41,}/],["whitespace",/\s/]];function q(t){return nt.filter(([,e])=>e.test(t)).map(([e])=>e)}l(q,"Q"),c(q,"findSensitive");const w=c(t=>typeof t=="object"&&t!==null&&!Array.isArray(t),"isObject");function g(t,e,i,o){for(const a of Object.keys(t))e.includes(a)||o.push(`${i}.${a}: unknown field`);for(const a of e)a in t||o.push(`${i}.${a}: missing`)}l(g,"g"),c(g,"exactKeys");function m(t,e,i,o=u.count){(typeof t!="number"||!Number.isFinite(t)||t<0||t>o)&&i.push(`${e}: not a count in 0..${o}`)}l(m,"u"),c(m,"count");function K(t){const e=[];if(!w(t))return["not an object"];if(g(t,["schema","id","day","reporter","client","model","categories","tools","sequence","sequenceTruncated","stats"],"symptom",e),t.schema!==S&&e.push("schema: wrong"),(typeof t.id!="string"||!X.test(t.id))&&e.push("id: wrong shape"),(typeof t.day!="string"||!W.test(t.day))&&e.push("day: not YYYY-MM-DD"),(typeof t.reporter!="string"||!tt.test(t.reporter))&&e.push("reporter: wrong shape"),w(t.client)?(g(t.client,["app","version","os"],"client",e),t.client.app!=="dal-cli"&&e.push("client.app: wrong"),(typeof t.client.version!="string"||!Q.test(t.client.version))&&e.push("client.version: not semver"),E.includes(t.client.os)||e.push("client.os: not in enum")):e.push("client: not an object"),w(t.model)){g(t.model,["provider","id"],"model",e);for(const o of["provider","id"]){const a=t.model[o];(typeof a!="string"||!R.test(a))&&e.push(`model.${o}: not an identifier`)}}else e.push("model: not an object");if(!Array.isArray(t.categories)||t.categories.length===0||t.categories.length>u.categories)e.push("categories: not a non-empty list");else for(const o of t.categories)_.includes(o)||e.push(`categories: ${String(o).slice(0,40)} not in enum`);!Array.isArray(t.tools)||t.tools.length>u.tools?e.push("tools: not a short list"):t.tools.forEach((o,a)=>{const n=`tools[${a}]`;if(!w(o)){e.push(`${n}: not an object`);return}if(g(o,["tool","calls","errors","errorClasses"],n,e),(typeof o.tool!="string"||!j.test(o.tool))&&e.push(`${n}.tool: not a tool name`),m(o.calls,`${n}.calls`,e),m(o.errors,`${n}.errors`,e),!Array.isArray(o.errorClasses))e.push(`${n}.errorClasses: not a list`);else for(const f of o.errorClasses)x.includes(f)||e.push(`${n}.errorClasses: not in enum`)}),!Array.isArray(t.sequence)||t.sequence.length>u.sequence?e.push("sequence: not a short list"):t.sequence.forEach((o,a)=>{const n=`sequence[${a}]`;if(!w(o)){e.push(`${n}: not an object`);return}g(o,["tool","ok","n"],n,e),(typeof o.tool!="string"||!j.test(o.tool))&&e.push(`${n}.tool: not a tool name`),typeof o.ok!="boolean"&&e.push(`${n}.ok: not a boolean`),m(o.n,`${n}.n`,e)}),m(t.sequenceTruncated,"sequenceTruncated",e),w(t.stats)?(g(t.stats,["turns","toolCalls","durationSec","costUsd","compactions"],"stats",e),m(t.stats.turns,"stats.turns",e),m(t.stats.toolCalls,"stats.toolCalls",e),m(t.stats.durationSec,"stats.durationSec",e,u.durationSec),m(t.stats.costUsd,"stats.costUsd",e,u.costUsd),m(t.stats.compactions,"stats.compactions",e)):e.push("stats: not an object");const i=q(JSON.stringify(t));return i.length&&e.push(`looks sensitive: ${i.join(", ")}`),e}l(K,"ae"),c(K,"validateSymptom");export{_ as CATEGORIES,x as ERROR_CLASSES,H as INTENTS,u as LIMITS,E as OSES,S as SYMPTOM_SCHEMA,F as buildSymptom,$ as classifyError,A as classifyRun,q as findSensitive,J as isCorrection,Z as newReporterId,z as newSymptomId,M as redactModel,K as validateSymptom};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
`),
|
|
1
|
+
var _=Object.defineProperty;var E=(a,e)=>_(a,"name",{value:e,configurable:!0});var w=Object.defineProperty,d=E((a,e)=>w(a,"name",{value:e,configurable:!0}),"d");import{t as u}from"@dalcode/dal-pi-kit";import{getAgentDir as T,VERSION as B}from"@earendil-works/pi-coding-agent";import{markAsked as R,resolveEndpoint as j,resolveTelemetry as F,setTelemetryEnabled as f}from"./config.js";import{applyConsentFromEnv as L,onTelemetryConsentChanged as S,registerTelemetryConsentApi as $,setTelemetryConsent as I,takeStartupTelemetryAnswer as N}from"./consent.js";import{setupFailureReporting as b}from"./failure-reporting.js";import{redactMessage as x,redactStack as O,redactToolName as M}from"./redact.js";import{TelemetryReporter as U}from"./reporter.js";function h(a){const e=T(),A=N();A!==void 0&&I(e,{usage:A}),L(e),$(e);let t=F(e),s;const i=b(a,{agentDir:e,version:B});a.registerCommand("telemetry",{description:u("\u67E5\u770B\u6216\u5207\u6362\u533F\u540D\u9065\u6D4B\uFF08on | off | failures on|off|show | attach\uFF09"),handler:d(async(o,r)=>{const n=o.trim();if(await i.handleCommand(n,r))return;if(n==="on"||n==="off"){f(e,n==="on"),n==="off"&&i.stopAll(),t=F(e),n==="off"&&(s?.discard(),s=void 0),r.ui.notify(n==="on"?u("\u533F\u540D\u9065\u6D4B\u5DF2\u5F00\u542F\uFF0C\u91CD\u542F\u540E\u751F\u6548\u3002"):u("\u533F\u540D\u9065\u6D4B\u5DF2\u5173\u95ED\uFF0C\u91CD\u542F\u540E\u751F\u6548\u3002"),"info");return}t=F(e);const c={"not-decided":u("\u5C1A\u672A\u9009\u62E9"),unconfigured:u("\u5C1A\u672A\u914D\u7F6E\u63A5\u6536\u7AEF"),"opted-out":u("\u4F60\u5DF2\u5173\u95ED"),"do-not-track":u("DO_NOT_TRACK \u5DF2\u8BBE\u7F6E"),env:u("DAL_TELEMETRY \u5DF2\u8BBE\u7F6E\u4E3A\u5173\u95ED"),ci:u("\u68C0\u6D4B\u5230 CI \u73AF\u5883"),unreadable:u("\u914D\u7F6E\u65E0\u6CD5\u5199\u5165")},p=t.active?u("\u533F\u540D\u9065\u6D4B\uFF1A\u5F00\u542F"):`${u("\u533F\u540D\u9065\u6D4B\uFF1A\u5173\u95ED")}\uFF08${c[t.reason??"opted-out"]??""}\uFF09`;r.ui.notify(`${p}${u("\u3000\u7528 /telemetry on|off \u5207\u6362")}
|
|
2
|
+
${i.statusLine()}`,"info")},"handler")});const l=d(()=>{s??=new U({endpoint:j(),anonymousId:t.state.anonymousId,appVersion:B})},"startReporting");t.active&&l();const v=S(()=>{t=F(e),t.shouldAsk=!1,i.refresh(),t.active?(l(),m()):(s?.discard(),s=void 0)}),k=Date.now();let D=0;a.on("session_start",async(o,r)=>{if(t.shouldAsk&&r.hasUI){t.shouldAsk=!1;const n=u("\u5141\u8BB8\uFF08\u53EA\u53D1\u529F\u80FD\u4F7F\u7528\u6B21\u6570\u3001\u662F\u5426\u51FA\u9519\u3001\u5E73\u53F0\u548C\u8131\u654F\u540E\u7684\u5D29\u6E83\u4FE1\u606F\uFF0C\u4E0D\u542B\u4EE3\u7801\u3001\u63D0\u793A\u8BCD\u548C\u6587\u4EF6\u8DEF\u5F84\uFF09"),c=u("\u4E0D\u5141\u8BB8"),p=u("\u4EE5\u540E\u518D\u95EE"),y=await r.ui.select(u("\u662F\u5426\u5141\u8BB8 DAL \u53D1\u9001\u533F\u540D\u4F7F\u7528\u7EDF\u8BA1\u548C\u5D29\u6E83\u4FE1\u606F\uFF0C\u5E2E\u52A9\u6539\u8FDB\u4EA7\u54C1\uFF1F"),[n,c,p]);y===n?(f(e,!0),t=F(e),t.active&&l(),r.ui.notify(u("\u5DF2\u5F00\u542F\u533F\u540D\u4F7F\u7528\u7EDF\u8BA1\u3002/telemetry off \u53EF\u968F\u65F6\u5173\u95ED\u3002"),"info")):y===c?(f(e,!1),i.stopAll(),t=F(e),r.ui.notify(u("\u4E0D\u4F1A\u53D1\u9001\u3002\u6539\u4E3B\u610F\u53EF\u4EE5\u7528 /telemetry on\u3002"),"info")):R(e,t.state)}s?.record({name:"session_start",props:{reason:o.reason}})}),a.on("turn_end",async()=>{D+=1}),a.on("model_select",async o=>{s?.record({name:"model_select",props:{model:String(o.model?.id??"unknown"),source:o.source}})}),a.on("tool_execution_end",async o=>{s?.record({name:"tool_end",props:{tool:M(o.toolName),error:o.isError}})}),a.on("session_shutdown",async()=>{s?.record({name:"session_end",props:{turns:D,durationMs:Date.now()-k}}),await s?.close(),v()});const C=d((o,r)=>{const n=r instanceof Error?r:new Error(String(r));s?.record({name:"crash",props:{kind:o,errorName:n.name,message:x(n.message),stack:O(n.stack).join(`
|
|
3
|
+
`),turns:D}}),s?.close()},"reportCrash");(t.active||t.shouldAsk)&&m();function m(){g||(g=!0,process.prependListener("uncaughtException",o=>{C("uncaught",o)}),process.prependListener("unhandledRejection",o=>{C("unhandled_rejection",o),process.listenerCount("unhandledRejection")<=1&&(process.stderr.write(`Unhandled rejection: ${o instanceof Error?o.stack:String(o)}
|
|
4
|
+
`),process.exitCode=1)}))}E(m,"E"),d(m,"installCrashHandlers")}E(h,"F"),d(h,"default");let g=!1;export{h as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var o=Object.defineProperty;var s=(e,t)=>o(e,"name",{value:t,configurable:!0});var r=Object.defineProperty,n=s((e,t)=>r(e,"name",{value:t,configurable:!0}),"r");import{arch as a,platform as l,release as
|
|
1
|
+
var o=Object.defineProperty;var s=(e,t)=>o(e,"name",{value:t,configurable:!0});var r=Object.defineProperty,n=s((e,t)=>r(e,"name",{value:t,configurable:!0}),"r");import{arch as a,platform as l,release as c}from"node:os";const u=200,m=3e3,p=1500,f="";class d{static{s(this,"f")}static{n(this,"TelemetryReporter")}queue=[];timer;closed=!1;fetchImpl;batchSize;flushIntervalMs;now;options;constructor(t){this.options=t,this.fetchImpl=t.fetchImpl??globalThis.fetch,this.batchSize=t.batchSize??20,this.flushIntervalMs=t.flushIntervalMs??1e4,this.now=t.now??Date.now}record(t){if(!this.closed){if(this.queue.length>=u&&this.queue.shift(),this.queue.push({...t,ts:this.now()}),this.queue.length>=this.batchSize){this.flush();return}this.timer===void 0&&(this.timer=setTimeout(()=>{this.flush()},this.flushIntervalMs),this.timer.unref?.())}}clearTimer(){this.timer!==void 0&&(clearTimeout(this.timer),this.timer=void 0)}async flush(t=m){this.clearTimer();const i=this.queue;if(i.length===0)return;this.queue=[];const h=JSON.stringify({schema:1,anonymousId:this.options.anonymousId,app:{version:this.options.appVersion,platform:l(),arch:a(),osRelease:c(),node:process.versions.node},events:i});try{await this.fetchImpl(this.options.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:h,signal:AbortSignal.timeout(t)})}catch{}}async close(){this.closed||(this.closed=!0,this.clearTimer(),await this.flush(p))}discard(){this.closed=!0,this.clearTimer(),this.queue=[]}get pending(){return this.queue.length}}export{f as DEFAULT_ENDPOINT,d as TelemetryReporter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var p=Object.defineProperty;var r=(e,a)=>p(e,"name",{value:a,configurable:!0});var c=Object.defineProperty,l=r((e,a)=>c(e,"name",{value:a,configurable:!0}),"a");import{analyzeRun as m,buildExcerpt as d}from"@dalcode/dal-learn/signals";import{MAX_REPRO_CHARS as R,REPRO_SCHEMA as u,validateRepro as f}from"./failure-queue.js";import{redactText as b}from"./redact.js";function s(e,a,i=new Date){const n=b(d(m(e))).slice(0,R),t=i.toISOString().slice(0,10),o={schema:u,symptomId:a,day:t,consentedOn:t,excerpt:n};return{payload:o,problems:f(o)}}r(s,"f"),l(s,"buildRepro");export{s as buildRepro};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-terminal",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.42",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Host terminal context: a terminal_read tool and @terminal mentions, registered only when the embedding host advertises the terminal capability.",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
]
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
22
|
+
"@dalcode/dal-pi-kit": "1.0.42",
|
|
23
23
|
"typebox": "1.3.7"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-tool-catalog",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.42",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
21
|
+
"@dalcode/dal-pi-kit": "1.0.42",
|
|
22
22
|
"typebox": "1.3.7"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)}i(B,"$"),n(B,"renderCatalogue");function v(u){
|
|
3
|
-
${s("\u53EF\u7528\u5206\u7EC4\uFF1A")}${[...F,...l()].map(
|
|
4
|
-
`)}i(g,"x"),n(g,"describeCatalog");export{
|
|
1
|
+
var O=Object.defineProperty;var i=(u,o)=>O(u,"name",{value:o,configurable:!0});var w=Object.defineProperty,n=i((u,o)=>w(u,"name",{value:o,configurable:!0}),"i");import{existsSync as j,readFileSync as x}from"node:fs";import{join as E}from"node:path";import{t as s}from"@dalcode/dal-pi-kit";import{CONFIG_DIR_NAME as S,getAgentDir as $}from"@earendil-works/pi-coding-agent";import{Type as f}from"typebox";import{deferredToolNames as G,externalToolGroups as l,findGroup as T,isBuiltinGroup as L,setExternalGroups as R,TOOL_GROUPS as F}from"./groups.js";import{registerToolRepair as P}from"./repair-hook.js";import{similarPaths as N}from"./path-hint.js";import{repairArgumentsText as k,repairToolCall as I}from"./repair.js";import{missingPathHint as M,repairNote as H,TOOL_REPAIR_ENTRY as Y,toolRepairEnabled as J}from"./repair-hook.js";import{fallbackToolName as Q}from"./tool-name.js";const U=f.Object({activate:f.Optional(f.String({description:s("\u8981\u6FC0\u6D3B\u7684\u5DE5\u5177\u5206\u7EC4 id\uFF08\u89C1\u5DE5\u5177\u8BF4\u660E\u91CC\u7684\u5206\u7EC4\uFF09\u3002\u7559\u7A7A\u5219\u5217\u51FA\u6240\u6709\u5206\u7EC4\u53CA\u5176\u72B6\u6001\u3002")}))});function d(u,o){try{const t=JSON.parse(x(u,"utf8"));if(t&&typeof t=="object"&&o in t){const e=t[o];if(typeof e=="boolean")return e}}catch{}}i(d,"T"),n(d,"readBoolSetting");function C(u){const o=process.env.DAL_TOOL_CATALOG?.trim().toLowerCase();if(o==="off"||o==="0"||o==="false")return"off";if(o==="mcp")return"mcp";if(o==="on"||o==="1"||o==="true")return"all";const t=d(E(u,S,"settings.json"),"deferTools");if(t!==void 0)return t?"all":"off";const e=d(E($(),"settings.json"),"deferTools");return e!==void 0?e?"all":"off":"all"}i(C,"v"),n(C,"deferralMode");let c=!0;function B(u){const o=new Set(u.getActiveTools()),t=new Set(u.getAllTools().map(a=>a.name)),e=[s("\u53EF\u7528\u7684\u5DE5\u5177\u5206\u7EC4\uFF08\u7528 tool_catalog \u7684 activate \u6FC0\u6D3B\u540E\u5373\u53EF\u8C03\u7528\u5176\u4E2D\u7684\u5DE5\u5177\uFF09\uFF1A")];for(const a of[...F,...l()]){const r=a.tools.filter(m=>t.has(m));if(r.length===0)continue;const p=r.every(m=>o.has(m))?s("\uFF08\u5DF2\u6FC0\u6D3B\uFF09"):s("\uFF08\u672A\u6FC0\u6D3B\uFF09");e.push(`- ${a.id}${p}: ${b(a)}`)}return e.join(`
|
|
2
|
+
`)}i(B,"$"),n(B,"renderCatalogue");function v(u){P(u),u.registerTool({name:"tool_catalog",label:s("\u5DE5\u5177\u76EE\u5F55"),description:g(),prepareLoadout:n(()=>c||l().length>0?{descriptions:{tool_catalog:g()}}:{hiddenDeclarations:["tool_catalog"]},"prepareLoadout"),promptSnippet:s("tool_catalog - \u67E5\u770B\u5E76\u6309\u9700\u6FC0\u6D3B\u5DE5\u5177\u5206\u7EC4\uFF08office/web/lsp \u9ED8\u8BA4\u4E0D\u6FC0\u6D3B\uFF09"),promptGuidelines:[s("\u9700\u8981\u751F\u6210/\u8BFB\u53D6\u529E\u516C\u6587\u6863\u3001\u8054\u7F51\u6216\u7528\u8BED\u8A00\u670D\u52A1\u5668\u65F6\uFF0C\u5148\u8C03\u7528 tool_catalog \u6FC0\u6D3B\u5BF9\u5E94\u5206\u7EC4\uFF08office/web/lsp\uFF09\uFF0C\u518D\u4F7F\u7528\u5176\u4E2D\u7684\u5DE5\u5177\u3002")],parameters:U,execute:n(async(o,t)=>{const e=t.activate?.trim();if(!e||e.toLowerCase()==="list")return{content:[{type:"text",text:B(u)}],details:{listed:!0}};const a=T(e);if(!a)return{content:[{type:"text",text:`${s("\u6CA1\u6709\u8FD9\u4E2A\u5DE5\u5177\u5206\u7EC4\uFF1A")}${e}
|
|
3
|
+
${s("\u53EF\u7528\u5206\u7EC4\uFF1A")}${[...F,...l()].map(p=>p.id).join(", ")}`}],details:{ok:!1}};const r=A(u,a);return r.length===0?{content:[{type:"text",text:`${s("\u8BE5\u5206\u7EC4\u5F53\u524D\u6CA1\u6709\u53EF\u7528\u7684\u5DE5\u5177\uFF1A")}${a.id}`}],details:{ok:!1,group:a.id}}:{content:[{type:"text",text:`${s("\u5DF2\u6FC0\u6D3B\u5206\u7EC4 ")}${a.id}${s("\uFF0C\u73B0\u5728\u53EF\u4EE5\u4F7F\u7528\uFF1A")}${r.join(", ")}`}],details:{activated:a.id,tools:r}}},"execute")}),_(u),u.on("session_start",(o,t)=>{c=C(t.cwd)==="all"&&u.isToolAllowed("tool_catalog");const e=o.reason==="reload"||y(t),a=c&&!e?G():new Set;D(t.cwd)&&a.delete("lsp"),u.setActiveTools(u.getActiveTools().filter(r=>!a.has(r)))})}i(v,"j"),n(v,"toolCatalogExtension");const W=["tsconfig.json","jsconfig.json","package.json","pyproject.toml","go.mod","Cargo.toml"];function D(u){return W.some(o=>j(E(u,o)))}i(D,"P"),n(D,"isCodeProject");function y(u){return u.sessionManager.getBranch().some(o=>o.type==="message"&&o.message.role==="system"&&((o.message.toolsAdded?.length??0)>0||(o.message.toolsRemoved?.length??0)>0))}i(y,"I"),n(y,"recordsToolLoadout");function A(u,o){const t=new Set(u.getAllTools().map(r=>r.name)),e=o.tools.filter(r=>t.has(r)&&u.isToolAllowed(r));if(e.length===0)return[];const a=new Set([...u.getActiveTools(),...e]);return u.setActiveTools([...a]),e}i(A,"A"),n(A,"activateGroup");const h=Symbol.for("dalcode.tool-catalog.api");function _(u){const o={inactiveGroups:n(()=>{const t=new Set(u.getActiveTools()),e=new Set(u.getAllTools().map(a=>a.name));return[...F,...l()].filter(a=>a.tools.some(r=>e.has(r)&&u.isToolAllowed(r)&&!t.has(r))).map(a=>({id:a.id,summary:a.summary}))},"inactiveGroups"),activate:n(t=>{const e=T(t);return e?A(u,e):[]},"activate"),deferralEnabled:n(t=>C(t)!=="off"&&u.isToolAllowed("tool_catalog"),"deferralEnabled"),setGroups:n((t,e)=>R(t,e),"setGroups")};globalThis[h]=o}i(_,"k"),n(_,"publishCatalogApi");function b(u){return L(u)?s(u.summary):u.summary}i(b,"M"),n(b,"groupSummary");function g(){const u=l();return[...c?[s("\u6309\u9700\u52A0\u8F7D\u5DE5\u5177\u5206\u7EC4\u3002office / web / lsp \u9ED8\u8BA4\u4E0D\u6FC0\u6D3B\uFF0C\u7528\u672C\u5DE5\u5177\u67E5\u770B\u5E76\u6FC0\u6D3B\u9700\u8981\u7684\u5206\u7EC4\u3002"),s("\u5F53\u4EFB\u52A1\u6D89\u53CA\u529E\u516C\u6587\u6863\u3001\u8054\u7F51\u6216\u8BED\u8A00\u670D\u52A1\u5668\u65F6\uFF0C\u5148\u7528 activate \u6FC0\u6D3B\u5BF9\u5E94\u5206\u7EC4\uFF0C\u518D\u8C03\u7528\u5176\u4E2D\u7684\u5DE5\u5177\u3002"),s("\u5206\u7EC4\uFF1A"),...F.map(o=>`- ${o.id}: ${s(o.summary)}`)]:[],...u.length>0?[s("MCP \u8FDE\u63A5\u5668\uFF08\u5DE5\u5177\u672A\u52A0\u8F7D\uFF1B\u8981\u7528\u5176\u4E2D\u7684\u5DE5\u5177\u65F6\u5148 activate \u8BE5\u8FDE\u63A5\u5668\u540D\uFF0C\u6FC0\u6D3B\u540E\u672C\u4F1A\u8BDD\u4E00\u76F4\u53EF\u7528\uFF09\uFF1A"),...u.map(o=>`- ${o.id}: ${o.summary}`)]:[]].join(`
|
|
4
|
+
`)}i(g,"x"),n(g,"describeCatalog");export{h as TOOL_CATALOG_SLOT,Y as TOOL_REPAIR_ENTRY,v as default,Q as fallbackToolName,D as isCodeProject,M as missingPathHint,k as repairArgumentsText,H as repairNote,I as repairToolCall,N as similarPaths,J as toolRepairEnabled};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var x=Object.defineProperty;var c=(t,i)=>x(t,"name",{value:i,configurable:!0});var P=Object.defineProperty,f=c((t,i)=>P(t,"name",{value:i,configurable:!0}),"l");import{execFileSync as _}from"node:child_process";import{readdirSync as w}from"node:fs";import{basename as m,isAbsolute as E,join as F,relative as S,sep as j}from"node:path";const p=2e4,N=8,A=5,B=new Set(["node_modules",".git","dist","build","target",".venv","__pycache__",".next"]);function d(t){return/\bENOENT\b|no such file or directory/i.test(t)}c(d,"w"),f(d,"isMissingPathError");function y(t){try{return _("git",["ls-files","--cached","--others","--exclude-standard","-z"],{cwd:t,encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:3e3,maxBuffer:33554432}).split("\0").filter(Boolean).slice(0,p)}catch{return}}c(y,"P"),f(y,"gitFiles");function b(t){const i=[],h=f((r,l)=>{if(l>N||i.length>=p)return;let u;try{u=w(F(t,r),{withFileTypes:!0})}catch{return}for(const s of u){if(i.length>=p)return;const n=r?`${r}/${s.name}`:s.name;s.isDirectory()?B.has(s.name)||h(n,l+1):s.isFile()&&i.push(n)}},"visit");return h("",0),i}c(b,"v"),f(b,"walk");function v(t,i,h){let r=i.trim().replace(/\\/g,"/");if(E(r)){const e=S(t,r);if(e.startsWith(".."))return[];r=e.split(j).join("/")}r=r.replace(/^(\.\/)+/,"").replace(/^[ab]\//,"");const l=m(r);if(!l)return[];const u=h??y(t)??b(t),s=r.split("/"),n=[];for(const e of u){if(m(e)!==l)continue;const o=e.split("/");let a=0;for(;a<s.length&&a<o.length&&s[s.length-1-a]===o[o.length-1-a];)a++;n.push({path:e,score:a})}n.sort((e,o)=>o.score-e.score||e.path.length-o.path.length);const g=n[0]?.score??0;return n.filter(e=>e.score===g||g<=1).slice(0,A).map(e=>e.path)}c(v,"N"),f(v,"similarPaths");export{d as isMissingPathError,v as similarPaths};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var T=Object.defineProperty;var m=(u,o)=>T(u,"name",{value:o,configurable:!0});var j=Object.defineProperty,d=m((u,o)=>j(u,"name",{value:o,configurable:!0}),"u");import{existsSync as S,readFileSync as x}from"node:fs";import{join as y}from"node:path";import{tm as E}from"@dalcode/dal-pi-kit";import{CONFIG_DIR_NAME as b,getAgentDir as w}from"@earendil-works/pi-coding-agent";import{isMissingPathError as P,similarPaths as I}from"./path-hint.js";import{repairToolCall as J,validates as L}from"./repair.js";import{fallbackToolName as M}from"./tool-name.js";const R="dal-tool-repair";function h(u){if(S(u))try{const o=JSON.parse(x(u,"utf8")).toolArgRepair;return typeof o=="boolean"?o:void 0}catch{return}}m(h,"x"),d(h,"readSetting");function D(u,o=process.env){const t=o.DAL_TOOL_REPAIR?.trim().toLowerCase();return t==="off"||t==="0"||t==="false"?!1:t==="on"||t==="1"||t==="true"?!0:h(y(u,b,"settings.json"))??h(y(w(),"settings.json"))??!0}m(D,"D"),d(D,"toolRepairEnabled");const N={"code-fence":"\u53BB\u6389\u4E86\u5305\u88F9\u7684\u4EE3\u7801\u5757\u6807\u8BB0","json-string":"\u628A\u5B57\u7B26\u4E32\u91CC\u7684 JSON \u89E3\u5F00","trailing-comma":"\u5220\u6389\u591A\u4F59\u7684\u9017\u53F7","single-quotes":"\u628A\u5355\u5F15\u53F7\u6539\u6210\u53CC\u5F15\u53F7","python-literals":"\u628A True/False/None \u6539\u6210 JSON \u5199\u6CD5","unclosed-brackets":"\u8865\u4E0A\u7F3A\u5C11\u7684\u53F3\u62EC\u53F7\uFF08\u53C2\u6570 JSON \u4E0D\u5B8C\u6574\uFF09","param-name":"\u53C2\u6570\u540D","string-to-json":"\u628A\u5B57\u7B26\u4E32\u5F62\u5F0F\u7684\u5217\u8868/\u5BF9\u8C61\u89E3\u5F00","wrap-array":"\u628A\u5355\u4E2A\u503C\u653E\u8FDB\u5217\u8868","tool-name":"\u5DE5\u5177\u540D"};function C(u){const o=[];for(const t of u){const r=(t.kind==="param-name"||t.kind==="tool-name")&&t.detail?`${E(N[t.kind])} ${t.detail}`:E(N[t.kind]);o.includes(r)||o.push(r)}return E("[\u53C2\u6570\u5DF2\u81EA\u52A8\u4FEE\u6B63\uFF1A{fixes}\u3002\u4E0B\u6B21\u8BF7\u76F4\u63A5\u6309\u5DE5\u5177\u7684\u53C2\u6570\u683C\u5F0F\u8C03\u7528\u3002]").replace("{fixes}",o.join(E("\uFF1B")))}m(C,"E"),d(C,"repairNote");function _(u){let o=!0;const t=new Map;let r=[];u.on("session_start",(n,a)=>{o=D(a.cwd),t.clear(),r=[]}),u.on("message_end",n=>{if(!o||n.message.role!=="assistant")return;const a=n.message;if(a.stopReason==="error"||a.stopReason==="aborted"||a.content.filter(e=>e.type==="toolCall").length===0)return;const s=new Map(u.getAllTools().map(e=>[e.name,e])),l=u.getActiveTools();let c=!1;const A=a.content.map(e=>{if(e.type!=="toolCall")return e;let g=s.get(e.name),f;if(!g){const p=M(e.name,l),F=p?s.get(p):void 0;if(!F)return e;g=F,f=F.name}const i=J(g,e);if(f){const p={...e,name:f,...i?{arguments:i.arguments,argumentsError:void 0}:{}};if(!L(g,p))return e;c=!0;const F=["tool-name",...i?.repairs.map(O=>O.kind)??[]];t.set(e.id,C([{kind:"tool-name",detail:`${e.name} \u2192 ${f}`},...i?.repairs??[]])),r.push({tool:f,kinds:[...new Set(F)]});const{argumentsError:q,...v}=p;return v}if(!i)return e;c=!0,t.set(e.id,C(i.repairs)),r.push({tool:e.name,kinds:[...new Set(i.repairs.map(p=>p.kind))]});const{argumentsError:$,...k}=e;return{...k,arguments:i.arguments}});return c?{message:{...a,content:A}}:void 0}),u.on("tool_result",(n,a)=>{const s=[],l=t.get(n.toolCallId);l&&(t.delete(n.toolCallId),s.push(l));const c=o?B(n,a.cwd):void 0;if(c&&s.push(c),s.length!==0)return{content:[...n.content,...s.map(A=>({type:"text",text:A}))]}}),u.on("turn_end",()=>{r.length!==0&&(u.appendEntry(R,{repairs:r}),r=[])})}m(_,"V"),d(_,"registerToolRepair");function B(u,o,t){if(!u.isError||u.toolName!=="read"&&u.toolName!=="edit")return;const r=u.input,n=typeof r.path=="string"?r.path:typeof r.file_path=="string"?r.file_path:"",a=u.content.map(l=>l.type==="text"?l.text??"":"").join(`
|
|
2
|
+
`);if(!n||!P(a))return;const s=I(o,n,t);if(s.length!==0)return E("[{path} \u4E0D\u5B58\u5728\u3002\u9879\u76EE\u91CC\u540C\u540D\u7684\u6587\u4EF6\uFF1A{files}\u3002\u662F\u5176\u4E2D\u4E4B\u4E00\u5C31\u7528\u5B83\u7684\u8DEF\u5F84\u91CD\u8BD5\uFF0C\u4E0D\u8981\u518D\u641C\u7D22\u3002]").replace("{path}",n).replace("{files}",s.join(", "))}m(B,"$"),d(B,"missingPathHint");export{R as TOOL_REPAIR_ENTRY,B as missingPathHint,_ as registerToolRepair,C as repairNote,D as toolRepairEnabled};
|