dal-code 1.0.51 → 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.
Files changed (131) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/NOTICE +17 -1
  3. package/dist/bundle/chunks/{anthropic-messages-2P3UGLIO.js → anthropic-messages-NK5NGKAI.js} +1 -1
  4. package/dist/bundle/chunks/{azure-openai-responses-S4GNH2XC.js → azure-openai-responses-VEASENYL.js} +1 -1
  5. package/dist/bundle/chunks/bedrock-converse-stream.js +1 -1
  6. package/dist/bundle/chunks/{chunk-B7NRFMLU.js → chunk-4VJJ6NXH.js} +1 -1
  7. package/dist/bundle/chunks/{chunk-FCKLBLA4.js → chunk-6EEJ4MZH.js} +1 -1
  8. package/dist/bundle/chunks/{chunk-H5FHS6BV.js → chunk-A5CI3CVQ.js} +1 -1
  9. package/dist/bundle/chunks/{chunk-CFPQOC7P.js → chunk-AAQZXQA7.js} +1 -1
  10. package/dist/bundle/chunks/{chunk-GSGE3ULF.js → chunk-ANL2BCIQ.js} +1 -1
  11. package/dist/bundle/chunks/{chunk-VNHNHA4V.js → chunk-CS4T4O5O.js} +1 -1
  12. package/dist/bundle/chunks/{chunk-PWZRJWNP.js → chunk-DLKRCASW.js} +1 -1
  13. package/dist/bundle/chunks/{chunk-AL7NZVPP.js → chunk-HEFI7NO7.js} +1 -1
  14. package/dist/bundle/chunks/{chunk-R44HF4S5.js → chunk-KJW3E2CB.js} +1 -1
  15. package/dist/bundle/chunks/chunk-ON7ZX67F.js +30 -0
  16. package/dist/bundle/chunks/{chunk-BEDAM2M7.js → chunk-OQWPBJCS.js} +1 -1
  17. package/dist/bundle/chunks/{chunk-ATQJO2OE.js → chunk-TK2WJTRC.js} +1 -1
  18. package/dist/bundle/chunks/{chunk-RR3ZP63P.js → chunk-UVKMBM5X.js} +2 -2
  19. package/dist/bundle/chunks/{chunk-RCVVRHMF.js → chunk-WIZGOHKY.js} +1 -1
  20. package/dist/bundle/chunks/{chunk-HXK5EFBE.js → chunk-XAS5HHBW.js} +284 -276
  21. package/dist/bundle/chunks/{chunk-2KOJ4RNS.js → chunk-XDBGA662.js} +1 -1
  22. package/dist/bundle/chunks/chunk-YWNDPXVM.js +25 -0
  23. package/dist/bundle/chunks/{cli-ZEDY5U67.js → cli-GXB5WYKG.js} +1 -1
  24. package/dist/bundle/chunks/{cli-FWMQKBFA.js → cli-YPE3BB5X.js} +1 -1
  25. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-E6TEENDO.js → cloudflare-workers-ai-system-one-B7WOBGWO.js} +1 -1
  26. package/dist/bundle/chunks/{execute-62LDYHXA.js → execute-27QCJECT.js} +1 -1
  27. package/dist/bundle/chunks/{google-generative-ai-V5DLXTF7.js → google-generative-ai-MBMRBHSZ.js} +1 -1
  28. package/dist/bundle/chunks/{google-vertex-K3KYGGLI.js → google-vertex-S2ZFBDPP.js} +1 -1
  29. package/dist/bundle/chunks/{llama-cpp-classify-JCTIEHTL.js → llama-cpp-classify-S4LVGNNY.js} +1 -1
  30. package/dist/bundle/chunks/{mcp-VF7EY5WC.js → mcp-6LJKGKJQ.js} +1 -1
  31. package/dist/bundle/chunks/{mistral-conversations-LVBXTF6R.js → mistral-conversations-C7LUXIEY.js} +1 -1
  32. package/dist/bundle/chunks/{office-PONBADQP.js → office-5OWKTZOA.js} +1 -1
  33. package/dist/bundle/chunks/{openai-codex-responses-WBZKNYLX.js → openai-codex-responses-YQQXJ24E.js} +1 -1
  34. package/dist/bundle/chunks/{openai-completions-HMHQRGX4.js → openai-completions-7CMH2FKD.js} +1 -1
  35. package/dist/bundle/chunks/{openai-decisions-R7OFRKLL.js → openai-decisions-AOGZTREY.js} +1 -1
  36. package/dist/bundle/chunks/{openai-responses-BHXRQFCI.js → openai-responses-ZSOGZ3MK.js} +1 -1
  37. package/dist/bundle/chunks/{openrouter-images-BIMNIXQZ.js → openrouter-images-AHXST2TH.js} +1 -1
  38. package/dist/bundle/chunks/{pi-messages-X5YTLXQJ.js → pi-messages-QERJLMZ6.js} +1 -1
  39. package/dist/bundle/chunks/{review-WCGIBVLM.js → review-5G56KIWY.js} +1 -1
  40. package/dist/bundle/chunks/{router-7E5LU7US.js → router-776Z7G7G.js} +1 -1
  41. package/dist/bundle/chunks/{runtime-5PTUOEM2.js → runtime-NKPT25KD.js} +1 -1
  42. package/dist/bundle/chunks/{sdk-ZUFIGPSS.js → sdk-TVC4GDUX.js} +1 -1
  43. package/dist/bundle/chunks/sync-JBDC3YBK.js +7 -0
  44. package/dist/bundle/chunks/{typesafe-system-one-KOIOG3HP.js → typesafe-system-one-MMNGGQ46.js} +1 -1
  45. package/dist/bundle/chunks/{usage-2EVEFGNI.js → usage-BDCIALHO.js} +1 -1
  46. package/dist/bundle/chunks/{virtual-modules-MYMONT3Y.js → virtual-modules-25RQ6XTV.js} +1 -1
  47. package/dist/bundle/cli-runtime.js +1 -1
  48. package/dist/bundle/index.js +1 -1
  49. package/dist/bundle/rpc-entry.js +1 -1
  50. package/dist/dal/builtins.js +2 -2
  51. package/dist/dal/manifest.d.ts +1 -0
  52. package/dist/dal/manifest.js +1 -1
  53. package/dist/dal/safety-net.js +11 -3
  54. package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
  55. package/dist/node_modules/@dalcode/dal-awake/package.json +2 -2
  56. package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
  57. package/dist/node_modules/@dalcode/dal-capabilities/package.json +4 -4
  58. package/dist/node_modules/@dalcode/dal-codeindex/package.json +2 -2
  59. package/dist/node_modules/@dalcode/dal-compat/package.json +2 -2
  60. package/dist/node_modules/@dalcode/dal-dap/package.json +2 -2
  61. package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
  62. package/dist/node_modules/@dalcode/dal-goal/package.json +3 -3
  63. package/dist/node_modules/@dalcode/dal-guard/package.json +4 -4
  64. package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
  65. package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
  66. package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
  67. package/dist/node_modules/@dalcode/dal-learn/package.json +4 -2
  68. package/dist/node_modules/@dalcode/dal-learn/src/engine.js +4 -4
  69. package/dist/node_modules/@dalcode/dal-learn/src/extract.js +31 -5
  70. package/dist/node_modules/@dalcode/dal-learn/src/index.js +15 -15
  71. package/dist/node_modules/@dalcode/dal-learn/src/learn-mode.js +1 -0
  72. package/dist/node_modules/@dalcode/dal-learn/src/lessons.js +4 -3
  73. package/dist/node_modules/@dalcode/dal-learn/src/project-map.js +2 -2
  74. package/dist/node_modules/@dalcode/dal-learn/src/safety.js +2 -2
  75. package/dist/node_modules/@dalcode/dal-learn/src/signals.js +6 -5
  76. package/dist/node_modules/@dalcode/dal-learn/src/store.js +3 -2
  77. package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
  78. package/dist/node_modules/@dalcode/dal-mcp/package.json +6 -6
  79. package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
  80. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +3 -3
  81. package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
  82. package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +3 -3
  83. package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -4
  84. package/dist/node_modules/@dalcode/dal-recall/package.json +2 -2
  85. package/dist/node_modules/@dalcode/dal-remote/package.json +2 -2
  86. package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
  87. package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
  88. package/dist/node_modules/@dalcode/dal-router/package.json +6 -6
  89. package/dist/node_modules/@dalcode/dal-rtk/package.json +2 -2
  90. package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
  91. package/dist/node_modules/@dalcode/dal-statusline/package.json +2 -2
  92. package/dist/node_modules/@dalcode/dal-structured/package.json +2 -2
  93. package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
  94. package/dist/node_modules/@dalcode/dal-sync/package.json +4 -4
  95. package/dist/node_modules/@dalcode/dal-sync/src/core.js +2 -2
  96. package/dist/node_modules/@dalcode/dal-telemetry/package.json +4 -4
  97. package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
  98. package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
  99. package/dist/node_modules/@dalcode/dal-usage/package.json +2 -2
  100. package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
  101. package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
  102. package/dist/node_modules/@dalcode/dal-workflow/src/todo-snapshot.js +2 -2
  103. package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
  104. package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  105. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  106. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  107. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  108. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
  109. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  110. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  111. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
  112. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  113. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.d.ts +1 -1
  114. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.js +1 -1
  115. package/dist/node_modules/@earendil-works/pi-ai/package.json +3 -3
  116. package/dist/node_modules/@earendil-works/pi-codemode/package.json +1 -1
  117. package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
  118. package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
  119. package/dist/node_modules/@earendil-works/pi-schema/package.json +1 -1
  120. package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  121. package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
  122. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  123. package/examples/extensions/gondolin/package-lock.json +2 -2
  124. package/examples/extensions/gondolin/package.json +1 -1
  125. package/examples/extensions/with-deps/package-lock.json +2 -2
  126. package/examples/extensions/with-deps/package.json +1 -1
  127. package/npm-shrinkwrap.json +2 -2
  128. package/package.json +1 -1
  129. package/dist/bundle/chunks/chunk-JE6UXK35.js +0 -30
  130. package/dist/bundle/chunks/chunk-NUIR7PPD.js +0 -25
  131. package/dist/bundle/chunks/sync-LOX6TIM6.js +0 -4
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-bridge",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
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.51",
21
+ "@dalcode/dal-pi-kit": "1.0.52",
22
22
  "typebox": "1.3.7"
23
23
  },
24
24
  "peerDependencies": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-capabilities",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
4
  "private": true,
5
5
  "description": "Capability center for DAL: switches on the reviewed MCP connectors, skills and engine packages a task needs (installed automatically from the signed DAL market), with /capabilities to list, disable and enable them.",
6
6
  "license": "MIT",
@@ -23,9 +23,9 @@
23
23
  ]
24
24
  },
25
25
  "dependencies": {
26
- "@dalcode/dal-mcp": "1.0.51",
27
- "@dalcode/dal-pi-kit": "1.0.51",
28
- "@dalcode/deepailab": "1.0.51"
26
+ "@dalcode/dal-mcp": "1.0.52",
27
+ "@dalcode/dal-pi-kit": "1.0.52",
28
+ "@dalcode/deepailab": "1.0.52"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@earendil-works/pi-coding-agent": "^1.0.9"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-codeindex",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
4
  "private": true,
5
5
  "description": "Code index: a persistent local symbol and reference index (tree-sitter WebAssembly grammars) the model queries to find definitions, callers, file outlines and related files without repeated grep.",
6
6
  "type": "module",
@@ -18,7 +18,7 @@
18
18
  ]
19
19
  },
20
20
  "dependencies": {
21
- "@dalcode/dal-pi-kit": "1.0.51",
21
+ "@dalcode/dal-pi-kit": "1.0.52",
22
22
  "@vscode/tree-sitter-wasm": "0.3.1",
23
23
  "ignore": "7.0.8",
24
24
  "typebox": "1.3.27"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-compat",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
4
  "private": true,
5
5
  "description": "Claude Code compatibility: the user's and project's .claude/rules/ and .claude/CLAUDE.md apply in DAL. Grown from the claude-rules extension example.",
6
6
  "type": "module",
@@ -18,7 +18,7 @@
18
18
  ]
19
19
  },
20
20
  "dependencies": {
21
- "@dalcode/dal-pi-kit": "1.0.51",
21
+ "@dalcode/dal-pi-kit": "1.0.52",
22
22
  "minimatch": "11.0.3"
23
23
  },
24
24
  "peerDependencies": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-dap",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
4
  "private": true,
5
5
  "description": "Debugger for DAL: breakpoints, stepping, call stacks and variables in Node.js and Python programs over the Debug Adapter Protocol, installing the adapter on first use. The DAP client is adapted from oh-my-pi's src/dap (MIT).",
6
6
  "license": "MIT",
@@ -24,7 +24,7 @@
24
24
  ]
25
25
  },
26
26
  "dependencies": {
27
- "@dalcode/dal-pi-kit": "1.0.51",
27
+ "@dalcode/dal-pi-kit": "1.0.52",
28
28
  "typebox": "1.3.27"
29
29
  },
30
30
  "peerDependencies": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-gateway",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -17,7 +17,7 @@
17
17
  ]
18
18
  },
19
19
  "dependencies": {
20
- "@dalcode/deepailab": "1.0.51"
20
+ "@dalcode/deepailab": "1.0.52"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@earendil-works/pi-coding-agent": "^1.0.9"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-goal",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
4
  "private": true,
5
5
  "description": "Goal mode for DAL: /goal keeps the agent working on one objective until it is verified complete, with token and continuation limits. Adapted from @narumitw/pi-goal 0.54.11 (MIT, narumiruna); the independent completion check adapts pi-goal-x 0.32.3 (MIT, Lucas).",
6
6
  "license": "MIT",
@@ -21,8 +21,8 @@
21
21
  ]
22
22
  },
23
23
  "dependencies": {
24
- "@dalcode/dal-pi-kit": "1.0.51",
25
- "@dalcode/dal-subagent": "1.0.51",
24
+ "@dalcode/dal-pi-kit": "1.0.52",
25
+ "@dalcode/dal-subagent": "1.0.52",
26
26
  "typebox": "1.3.27"
27
27
  },
28
28
  "peerDependencies": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-guard",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -21,9 +21,9 @@
21
21
  ]
22
22
  },
23
23
  "dependencies": {
24
- "@dalcode/dal-pi-kit": "1.0.51",
25
- "@dalcode/dal-bridge": "1.0.51",
26
- "@dalcode/dal-halo": "1.0.51"
24
+ "@dalcode/dal-pi-kit": "1.0.52",
25
+ "@dalcode/dal-bridge": "1.0.52",
26
+ "@dalcode/dal-halo": "1.0.52"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@earendil-works/pi-coding-agent": "^1.0.9"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-halo",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-interactive",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
4
  "private": true,
5
5
  "description": "Terminal-UI conveniences adopted from pi's example extensions: the questionnaire tool (the model asks you questions), /handoff (carry context into a new session) and interactive ! commands (vim, git rebase -i, htop). Active only in the TUI; stands down under DAL Code.",
6
6
  "license": "MIT",
@@ -20,7 +20,7 @@
20
20
  ]
21
21
  },
22
22
  "dependencies": {
23
- "@dalcode/dal-pi-kit": "1.0.51",
23
+ "@dalcode/dal-pi-kit": "1.0.52",
24
24
  "typebox": "1.3.7"
25
25
  },
26
26
  "peerDependencies": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-lang",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -17,8 +17,8 @@
17
17
  ]
18
18
  },
19
19
  "dependencies": {
20
- "@dalcode/dal-pi-kit": "1.0.51",
21
- "@dalcode/dal-bridge": "1.0.51"
20
+ "@dalcode/dal-pi-kit": "1.0.52",
21
+ "@dalcode/dal-bridge": "1.0.52"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@earendil-works/pi-coding-agent": "^1.0.9"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-learn",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
4
  "private": true,
5
5
  "description": "Self-evolution for DAL: lessons learned from earlier sessions (project and personal), a project map of verified commands and locations, effect tracking, and skill proposals for recurring procedures (/lessons).",
6
6
  "license": "MIT",
@@ -9,6 +9,8 @@
9
9
  "exports": {
10
10
  ".": "./src/index.js",
11
11
  "./store": "./src/store.js",
12
+ "./learn-mode": "./src/learn-mode.js",
13
+ "./project": "./src/project.js",
12
14
  "./lessons": "./src/lessons.js",
13
15
  "./lesson-events": "./src/lesson-events.js",
14
16
  "./project-map": "./src/project-map.js",
@@ -28,7 +30,7 @@
28
30
  ]
29
31
  },
30
32
  "dependencies": {
31
- "@dalcode/dal-pi-kit": "1.0.51"
33
+ "@dalcode/dal-pi-kit": "1.0.52"
32
34
  },
33
35
  "peerDependencies": {
34
36
  "@earendil-works/pi-coding-agent": "^1.0.9"
@@ -1,8 +1,8 @@
1
- var q=Object.defineProperty;var k=(f,e)=>q(f,"name",{value:e,configurable:!0});var G=Object.defineProperty,g=k((f,e)=>G(f,"name",{value:e,configurable:!0}),"k");import{readdirSync as Q,readFileSync as V,realpathSync as Z}from"node:fs";import{join as w}from"node:path";import{t as h}from"@dalcode/dal-pi-kit";import{buildExtractPrompt as ee,draftFromFix as te,EXTRACT_SYSTEM_PROMPT as se,normalizeCommand as E,parseExtractAnswer as oe,taskNoteSignature as M}from"./extract.js";import{applyFeedback as re,proposeLesson as ne,readLessons as j,renderLessonsSection as ie,retireLessons as ae,updateLessons as x}from"./lessons.js";import{desktopProjectsRoot as ce,importDesktopRules as de}from"./migrate.js";import{procedureOf as ue,proceduresPath as le,recordProcedure as pe,updateProcedures as I}from"./procedures.js";import{identifyProject as fe}from"./project.js";import{learnFromRun as he,readMap as me,renderMapSection as ke,updateMap as ye,viewMap as ge}from"./project-map.js";import{rejectLesson as _,riskOf as $}from"./safety.js";import{analyzeRun as K,buildExcerpt as Fe,needsModel as je}from"./signals.js";import{applyPatches as O,decideScope as De,improvementFor as Ce,isEditable as we,lineDiff as S,MAX_SKILL_CHARS as xe,matchSkill as Se,restoreBefore as N,runOutcome as be,skillKey as b,skillsLoaded as ve,trackUse as Ae}from"./skill-evolution.js";import{claimExtraction as Ee,learnedRoot as Ie,projectDir as $e,recordExtractionTokens as Pe,updateDoc as W,userDir as Le}from"./store.js";const z=6;function Y(f,e){const s=[...f.list()],o=[...new Set((e.evidence??[]).flatMap(n=>n.skills))],t=[e.steps.join(" "),...o];for(const n of t)for(const a of f.search?.(n)??[])s.some(c=>c.name===a.name)||s.push(a);return s}k(Y,"Ce"),g(Y,"candidateSkills");class Be{static{k(this,"ze")}static{g(this,"Learner")}root;desktopRoot;dailyCap;clock;constructor(e={}){this.root=Ie(e.root),this.desktopRoot=e.desktopRoot??ce(),this.dailyCap=e.dailyCap??z,this.clock=e.now??Date.now}now(){return this.clock()}project(e){return fe(e)}projectDir(e){return $e(this.root,e.key)}userDir(){return Le(this.root)}recordProjectIdentity(e){const s=w(this.projectDir(e),"project.json");W(s,o=>({root:typeof o?.root=="string"?o.root:"",remote:o?.remote,roots:o?.roots}),o=>{const t=Array.isArray(o.roots)?o.roots:[];if(!(o.root===e.root&&t.includes(e.root)))return{root:e.root,remote:e.remote,roots:[...new Set([...t,e.root])].slice(-20)}})}startSession(e,s={}){const o=this.now(),t=this.project(e),n=this.projectDir(t);let a=0;const c=[];try{this.recordProjectIdentity(t)}catch{}try{x(n,u=>{const i=de(u,[t.root,e],this.desktopRoot,o);if(i)return a=i.added.length,i.doc})}catch{a=0}for(const u of[n,this.userDir()])try{x(u,i=>{const d=ae(i,o);return c.push(...d.transitions),d.transitions.length>0?d.doc:void 0})}catch{}return{...this.render(t,o,s),imported:a,retired:c}}preview(e,s={}){return{...this.render(this.project(e),this.now(),s),imported:0,retired:[]}}render(e,s,o){const t=this.projectDir(e),n=j(t).lessons.filter(l=>!(o.hostHasLearnedSection&&l.origin?.kind==="desktop")),a=j(this.userDir()).lessons,c=ie([{label:"Your habits (every project)",lessons:a},{label:"This project",lessons:n}]),u=new Set(c.ids),i=[...a,...n].filter(l=>u.has(l.id)&&l.fix),d=ge(me(t),e.root,s);d.pitfalls=d.pitfalls.filter(l=>!i.some(r=>r.fix?.bad.endsWith(l.bad)&&r.fix.good.endsWith(l.good)));const p=ke(d);return{project:e,...c.text?{lessons:c.text}:{},lessonIds:c.ids,lessonTokens:c.tokens,...p.text?{map:p.text}:{},mapTokens:p.tokens}}async onRunEnd(e,s){const o=this.now(),t=K(e),n={signals:t,notices:[],proposed:[],taskNotes:[],feedback:0,modelCall:"none"};let a;try{a=this.project(s.cwd)}catch{return n}const c=this.projectDir(a);try{const d=this.commandFeedback(t,s,c);d.length>0&&(n.feedback+=this.applyFeedback(c,d,s.sessionId,o))}catch{}try{ye(c,d=>he(d,{root:a.root,cwd:X(s.cwd),sessionId:s.sessionId,steps:t.steps,fixes:t.fixes.filter(p=>p.proven),now:o}))}catch{}for(const d of t.fixes){let p=te(d);_({content:p.content})&&(p={...p,content:p.content.replace(/([^)]*)|\s\([^)]*\)/u,""),rootCause:""},_({content:p.content}))||this.propose(c,p,s.sessionId,o,n)}je(t)&&await this.draftWithModel(t,s,c,o,n);const u=[...new Set([...ve(t),...s.loadedSkills??[]])],i=be(t);try{const d=i==="correction"?[...new Set([...u,...s.earlierSkills??[]])]:u;this.trackSkills(c,d,i,s,o,n)}catch{}try{const d=ue(t.steps);if(d){let p;const l=t.fixes.map(r=>({bad:E(P(r.failed.command??"",r.failed.cdDir)),good:E(P(r.fixed.command??"",r.fixed.cdDir)),reason:r.reason}));if(I(c,r=>{const m=pe(r,d,s.sessionId,o,{skills:u,fixes:l,outcome:i});return m.draft&&(p={draft:m.draft,procedure:m.procedure}),m.doc}),p){const r=await this.shapeProposal(c,a,p.procedure,p.draft,s,o);r&&n.notices.push({kind:"skill_proposed",draft:r})}}}catch{}return n}skillFeedback(e,s,o,t){const n={signals:K([]),notices:[],proposed:[],taskNotes:[],feedback:0,modelCall:"none"};if(o.length===0)return[];try{const a=this.projectDir(this.project(e));this.trackSkills(a,o,"correction",{cwd:e,sessionId:s,injected:[],skills:t},this.now(),n)}catch{}return n.notices}trackSkills(e,s,o,t,n,a){if(s.length===0)return;const c=t.skills?.list()??[],u=s.flatMap(i=>{const d=c.filter(p=>p.name===i);return d.length>0?d.map(b):[b({origin:"cloud",name:i})]});for(const i of Ae(this.root,u,t.sessionId,o,n)){if(N(this.root,i.key,i.proposalId,"revert",n).kind!=="restored")continue;let d;I(e,l=>{const r=l.drafts.findIndex(D=>D.id===i.proposalId);if(r<0)return;d={...l.drafts[r],status:"undone"};const m=[...l.drafts];return m[r]=d,{...l,drafts:m}});const p=d?.target;d?.kind==="split"&&p&&p.key!==i.key&&N(this.root,p.key,i.proposalId,"revert",n),a.notices.push({kind:"skill_reverted",skill:i.name,proposalId:i.proposalId,...d?{draft:d}:{},uses:{total:i.uses.length,bad:i.uses.filter(l=>l.outcome!=="success").length}})}}otherProjectsWith(e,s){let o=0,t=[];try{t=Q(w(this.root,"projects"))}catch{return 0}for(const n of t){const a=w(this.root,"projects",n);if(a!==s)try{V(le(a),"utf8").includes(e)&&o++}catch{}}return o}async shapeProposal(e,s,o,t,n,a){const c=(o.evidence??[]).map(l=>({sessionId:l.sessionId,at:l.at,note:H(l)})),u=De(o,s.root,this.otherProjectsWith(o.fingerprint,e));let i={...t,kind:"new",scope:u.scope,scopeReason:u.reason,diff:S("",t.content,`${t.name}/SKILL.md`),evidence:c,risk:$(t.content)};const d=n.skills?Se(o,Y(n.skills,o)):void 0,p=d?await n.skills?.text(d.ref).catch(()=>{}):void 0;if(d&&p!==void 0){const l=Ce(p,o,a,t.id),r=d.ref,m=b(r);if(!l)i=void 0;else{const D=r.origin==="learned-project"&&r.projectKey===s.key,C=u.scope==="project"&&!D,v=we(r)&&!C,L=C?{...l,projectKey:s.key}:l,B={key:m,name:r.name,origin:r.origin,editable:v,...r.filePath?{filePath:r.filePath}:{}},J=D||C||r.origin==="project"?"project":"user",R=d.why==="loaded"?y(h("\u8FD9\u4E9B\u4F1A\u8BDD\u91CC\u6709 {n} \u4E2A\u52A0\u8F7D\u8FC7\u6280\u80FD\u300C{name}\u300D"),{n:d.count,name:r.name}):y(h("\u6280\u80FD\u300C{name}\u300D\u7684\u540D\u79F0\u548C\u8BF4\u660E\u4E0E\u8FD9\u5957\u6B65\u9AA4\u76F8\u7B26"),{name:r.name});if(p.length+l.text.length>xe){const F=`${r.name}-${t.name}`.slice(0,64).replace(/-+$/g,""),A=U(F,r.name,o,l.text),T={id:`${t.id}p`,mode:"append",text:y(h("\u53E6\u89C1\u6280\u80FD\u300C{name}\u300D\uFF1A\u672C\u673A\u8865\u5145\u7684\u505A\u6CD5\u3002"),{name:F}),proposalId:t.id,created:l.created,...C?{projectKey:s.key}:{}};i={...t,name:F,content:A,kind:"split",scope:u.scope,scopeReason:`${R}\uFF1B${y(h("\u5B83\u5DF2\u7ECF\u5F88\u957F\uFF08{n} \u5B57\u7B26\uFF09\uFF0C\u8865\u5145\u53E6\u6210\u4E00\u4E2A\u6280\u80FD"),{n:p.length})}\uFF1B${u.reason}`,target:B,patch:T,diff:[S("",A,`${F}/SKILL.md`),S(p,O(p,[T],{marker:!v,projectKey:s.key}).text,`${r.name}`)].join(`
2
- `),evidence:c,risk:$(A)}}else{const F=O(p,[L],{marker:!v,projectKey:s.key}).text;i={...t,name:r.name,content:"",kind:"improve",scope:J,scopeReason:`${R}\uFF1B${u.reason}`,target:B,patch:L,diff:S(p,F,r.name),evidence:c,risk:$(l.text)}}}}return I(e,l=>({...l,procedures:l.procedures.map(r=>r.fingerprint===o.fingerprint&&!i&&d?{...r,coveredBy:b(d.ref)}:r),drafts:i?l.drafts.map(r=>r.id===t.id?i:r):l.drafts.filter(r=>r.id!==t.id)})),i}seenInAnotherTask(e,s,o){const t=M(s.content);let n=!1;try{W(w(e,"task-notes.json"),a=>({signatures:a?.signatures&&typeof a.signatures=="object"&&!Array.isArray(a.signatures)?a.signatures:{}}),a=>{const c=Array.isArray(a.signatures[t])?a.signatures[t]:[];if(n=c.some(i=>i!==o),c.includes(o))return;const u=Object.entries({...a.signatures,[t]:[...c,o].slice(-4)});return{signatures:Object.fromEntries(u.slice(-200))}})}catch{return!1}return n}propose(e,s,o,t,n){const a=s.scope==="user"?this.userDir():e;try{x(a,c=>{const u=ne(c,s,o,t);if(u.outcome.kind!=="suppressed"){if(u.outcome.kind==="created"&&n.proposed.push(u.outcome.lesson),u.transition){const i=u.transition.to;i==="active"&&n.notices.push({kind:"activated",lesson:u.transition.lesson}),i==="awaiting_user"&&n.notices.push({kind:"awaiting_user",lesson:u.transition.lesson})}return u.doc}})}catch{}}applyFeedback(e,s,o,t){let n=0;for(const a of[e,this.userDir()])x(a,c=>{const u=re(c,s,o,t);return n+=u.changed,u.changed>0?u.doc:void 0});return n}commandFeedback(e,s,o){if(s.injected.length===0)return[];const t=new Set(s.injected),n=[...j(o).lessons,...j(this.userDir()).lessons].filter(c=>t.has(c.id)&&c.fix),a=[];for(const c of n){const u=c.fix?.good;if(u){for(const i of e.steps)if(!(!i.command||E(i.cdDir?`cd ${i.cdDir} && ${i.command}`:i.command)!==u)){a.push(i.isError?{id:c.id,tag:"harmful",why:`\`${u}\` failed`}:{id:c.id,tag:"helpful",why:`\`${u}\` passed`});break}}}return a}async draftWithModel(e,s,o,t,n){if(!s.complete){n.modelCall="unavailable";return}let a=!1;try{a=Ee(this.root,this.dailyCap,t)}catch{a=!1}if(!a){n.modelCall="capped";return}const c=[...j(o).lessons,...j(this.userDir()).lessons],u=Fe(e,e.corrected?s.previousAssistant:void 0);let i;try{i=await s.complete(se,ee(u,e,c))}catch{n.modelCall="failed";return}if(!i){n.modelCall="unavailable";return}n.modelCall="done";try{Pe(this.root,i.inputTokens??0,i.outputTokens??0,t)}catch{}const d=oe(i.text,e);for(const r of d.drafts)this.propose(o,r,s.sessionId,t,n);for(const r of d.taskNotes)n.taskNotes.push(r),this.seenInAnotherTask(o,r,s.sessionId)&&this.propose(o,{scope:"project",section:r.section,content:r.content,rootCause:r.rootCause,signal:r.signal,note:r.note,signature:`task:${M(r.content)}`},s.sessionId,t,n);const p=new Set(c.filter(r=>r.status==="active").map(r=>r.id)),l=d.feedback.filter(r=>p.has(r.id));if(l.length>0)try{n.feedback+=this.applyFeedback(o,l,s.sessionId,t)}catch{}}}function P(f,e){return e?`cd ${e} && ${f}`:f}k(P,"W"),g(P,"located");function y(f,e){return f.replace(/\{(\w+)\}/g,(s,o)=>o in e?String(e[o]):s)}k(y,"g"),g(y,"fill");function H(f){const e=[];f.outcome==="correction"&&e.push(h("\u4F60\u7EA0\u6B63\u4E86\u52A9\u624B")),f.outcome==="failure"&&e.push(h("\u68C0\u67E5\u5931\u8D25\u672A\u4FEE\u597D"));for(const s of f.fixes.slice(0,2))e.push(y(h("`{bad}` \u5931\u8D25\u540E\u6539\u7528 `{good}`"),s));return f.skills.length>0&&e.push(y(h("\u52A0\u8F7D\u4E86\u6280\u80FD {names}"),{names:f.skills.join("\u3001")})),e.length>0?e.join(h("\uFF1B")):h("\u987A\u5229\u5B8C\u6210")}k(H,"Le"),g(H,"evidenceNote");function U(f,e,s,o){const t=s.steps.join(" \u2192 "),n=y(h("\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:t});return`---
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(n)}
4
+ description: ${JSON.stringify(r)}
5
5
  ---
6
6
 
7
7
  ${o}
8
- `}k(U,"we"),g(U,"companionSkill");function X(f){try{return Z(f)}catch{return f}}k(X,"Te"),g(X,"realCwd");export{z as DEFAULT_DAILY_CAP,Be as Learner};
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 C=Object.defineProperty;var r=(e,t)=>C(e,"name",{value:t,configurable:!0});var E=Object.defineProperty,d=r((e,t)=>E(e,"name",{value:t,configurable:!0}),"i");import{createHash as A}from"node:crypto";import{getLanguage as N}from"@dalcode/dal-pi-kit";import{redact as m,rejectLesson as F}from"./safety.js";const w=3;function h(e){return m(e).replace(/\s+/g," ").trim().slice(0,160)}r(h,"y"),d(h,"normalizeCommand");function y(e,t){return t?`cd ${t} && ${e}`:e}r(y,"k"),d(y,"located");function x(e){const t=h(y(e.failed.command??"",e.failed.cdDir)),s=h(y(e.fixed.command??"",e.fixed.cdDir)),n=N()==="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`}}:{}}}r(x,"A"),d(x,"draftFromFix");const S=`You review one finished run of a coding agent and write down what a future session should know before it starts.
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 ${w} lessons, only ones the existing lessons do not already cover. An empty list is a good answer.
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(", "),c=s.filter(o=>o.status==="active"||o.status==="candidate"||o.status==="awaiting_user").map(o=>`- [${o.id}] (${o.scope}, ${o.status}) ${o.content}`);return[`Run excerpt (${n||"worth a look"}). Lines are clipped; "\xB7 error" marks a failed call; credentials are masked.`,"",e,"","---","",c.length>0?`Existing lessons:
12
- ${c.join(`
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
- `)}r(_,"P"),d(_,"buildExtractPrompt");function i(e,t,s){const n=e[t];return typeof n=="string"?n.replace(/\s+/g," ").trim().slice(0,s):""}r(i,"d"),d(i,"field");function b(e){const t=e.toLowerCase().replace(/[\d]+/g,"").replace(/[^\p{L}]+/gu,"");return A("sha256").update(t).digest("hex").slice(0,16)}r(b,"C"),d(b,"taskNoteSignature");function j(e,t){const s={drafts:[],taskNotes:[],feedback:[],rejected:[]},n=/\{[\s\S]*\}/.exec(e);if(!n)return s;let c;try{c=JSON.parse(n[0])}catch{return s}if(!c||typeof c!="object")return s;const o=c,$=t.denials.length>0?"guard_denial":t.corrected?"user_correction":"repeated_detour";for(const l of Array.isArray(o.lessons)?o.lessons:[]){if(!l||typeof l!="object")continue;const a=l,u=i(a,"lesson",320);if(!u)continue;const f=i(a,"root_cause",300),g=i(a,"what_happened",300),k=F({content:u,rootCause:f,note:g});if(k){s.rejected.push({content:u,reason:k});continue}const p=i(a,"confirms",16);if(a.scope==="task"&&!p){s.taskNotes.push({content:u,section:i(a,"section",40).toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"general",rootCause:f,signal:$,note:m(g)});continue}const v=p.startsWith("u-")?"user":p.startsWith("l-")?"project":a.scope==="user"?"user":"project";if(s.drafts.push({scope:v,section:i(a,"section",40).toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"general",content:u,rootCause:f,signal:$,note:m(g),.../^[lu]-\d{4,6}$/.test(p)?{confirms:p}:{}}),s.drafts.length>=w)break}for(const l of Array.isArray(o.feedback)?o.feedback:[]){if(!l||typeof l!="object")continue;const a=l;typeof a.id=="string"&&(a.tag==="helpful"||a.tag==="harmful")&&s.feedback.push({id:a.id,tag:a.tag,why:i(a,"why",200)})}return s}r(j,"E"),d(j,"parseExtractAnswer");export{S as EXTRACT_SYSTEM_PROMPT,w as MAX_LESSONS_PER_RUN,_ as buildExtractPrompt,x as draftFromFix,h as normalizeCommand,j as parseExtractAnswer,b as taskNoteSignature};
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};