dsh-lean-router 0.0.0-stage → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +23 -0
  3. package/README.en.md +73 -0
  4. package/README.md +72 -2
  5. package/cordis.patch.yml +870 -0
  6. package/docs/adr/0001-token-ledger-durable-usage.md +11 -0
  7. package/docs/agents/domain.md +38 -0
  8. package/docs/agents/issue-tracker.md +44 -0
  9. package/docs/agents/release.md +24 -0
  10. package/docs/agents/triage-labels.md +13 -0
  11. package/docs/agents/verification.md +32 -0
  12. package/docs/architecture.en.md +67 -0
  13. package/docs/architecture.md +66 -0
  14. package/docs/changelog.en.md +266 -0
  15. package/docs/changelog.md +269 -0
  16. package/docs/configuration.en.md +57 -0
  17. package/docs/configuration.md +57 -0
  18. package/docs/install.en.md +60 -0
  19. package/docs/install.md +60 -0
  20. package/docs/quickstart.en.md +75 -0
  21. package/docs/quickstart.md +75 -0
  22. package/docs/release-checklist.en.md +82 -0
  23. package/docs/release-checklist.md +131 -0
  24. package/docs//345/244/215/346/240/270-/345/205/263/346/217/222/344/273/266/346/270/205/345/215/225.md +108 -0
  25. package/docs//345/267/245/345/205/267/351/201/256/350/224/275-/346/216/245/347/272/277/350/257/264/346/230/216.md +140 -0
  26. package/docs//350/267/257/347/224/261-/350/256/276/350/256/241/350/257/264/346/230/216.md +104 -0
  27. package/lib/bands.js +149 -0
  28. package/lib/index.js +12 -0
  29. package/lib/lean/compaction.js +119 -0
  30. package/lib/lean/delivery-gate.js +312 -0
  31. package/lib/lean/disabled.js +61 -0
  32. package/lib/lean/history-budget.js +301 -0
  33. package/lib/lean/history-downgrade.js +345 -0
  34. package/lib/lean/index.js +19 -0
  35. package/lib/lean/output-slim.js +271 -0
  36. package/lib/lean/persona-text.js +111 -0
  37. package/lib/lean/plan-mode.js +31 -0
  38. package/lib/lean/pruner.js +75 -0
  39. package/lib/lean/tool-concurrency.js +319 -0
  40. package/lib/lean/usage-ledger.js +442 -0
  41. package/lib/router.js +287 -0
  42. package/lib/token-ledger/index.js +147 -0
  43. package/lib/token-ledger/live.js +193 -0
  44. package/lib/toolface/discovery.js +297 -0
  45. package/lib/toolface/executor.js +323 -0
  46. package/lib/toolface/index.js +242 -0
  47. package/lib/toolface/pool.js +160 -0
  48. package/lib/toolface/retention.js +187 -0
  49. package/lib/toolface/rules.js +395 -0
  50. package/lib/toolface/scope.js +188 -0
  51. package/lib/toolface/transport.js +335 -0
  52. package/package.json +65 -4
  53. package/presets/base/frag-lean.patch.yml +459 -0
  54. package/presets/base/frag-preset.patch.yml +274 -0
  55. package/presets/base/frag-router.patch.yml +17 -0
  56. package/presets/base/frag-toolface.patch.yml +73 -0
  57. package/presets/base/lean-router.patch.yml +44 -0
  58. package/scripts/build-bundle.mjs +45 -0
  59. package/scripts/doctor.mjs +35 -0
  60. package/scripts/install-profile.mjs +113 -0
  61. package/scripts/install.mjs +20 -0
  62. package/scripts/integrate-preset.mjs +107 -0
  63. package/scripts/release.mjs +145 -0
  64. package/scripts/verify.mjs +8 -0
  65. package/test/build.test.mjs +7 -0
  66. package/test/history-budget.test.mjs +210 -0
  67. package/test/history-downgrade.test.mjs +379 -0
  68. package/test/integration-preset.test.mjs +59 -0
  69. package/test/lean-compaction.test.mjs +47 -0
  70. package/test/lean-concurrency.test.mjs +117 -0
  71. package/test/lean-delivery-gate.test.mjs +75 -0
  72. package/test/lean-frag.test.mjs +132 -0
  73. package/test/lean-modules.test.mjs +112 -0
  74. package/test/lean-pruner.test.mjs +42 -0
  75. package/test/output-slim.test.mjs +212 -0
  76. package/test/package.test.mjs +20 -0
  77. package/test/patch-yaml.test.mjs +45 -0
  78. package/test/plugin-entry.test.mjs +26 -0
  79. package/test/router-bands.test.mjs +98 -0
  80. package/test/router.test.mjs +215 -0
  81. package/test/token-ledger-live.test.mjs +351 -0
  82. package/test/token-ledger.test.mjs +264 -0
  83. package/test/toolface-executor.test.mjs +302 -0
  84. package/test/toolface-mask.test.mjs +258 -0
  85. package/test/toolface-rules.test.mjs +177 -0
  86. package/test/toolface-runtime.test.mjs +466 -0
  87. package/test/toolface-wiring.test.mjs +272 -0
  88. package/test/usage-ledger-inject.test.mjs +50 -0
  89. package/test/usage-ledger.test.mjs +399 -0
@@ -0,0 +1,870 @@
1
+ # dsh-lean-router cordis.patch.yml
2
+ # Generated by scripts/build-bundle.mjs - do not edit by hand.
3
+ # base: presets/base/lean-router.patch.yml + fragments: frag-lean.patch.yml, frag-toolface.patch.yml, frag-router.patch.yml, frag-preset.patch.yml
4
+ # dsh-lean-router 预设行模板(票 02 骨架;由 scripts/build-bundle.mjs 组装成 cordis.patch.yml)
5
+ # TODO(ticket-03 lean 层):compaction 0.25/20000、tool-result pruner 4096/1024、关 6 插件、lean13/balance3 persona、plan-mode v1、delivery-gate、glob/grep 并发标记
6
+ # TODO(ticket-04 工具遮蔽层):codemode executor 遮蔽行 + code_run 传输 + meta 4 工具 + 常驻 ptc-runtime
7
+ # TODO(ticket-05 路由层):首轮 inbox.claim 捕获 + [router] band/task 分类指令 + pre-step 近场引导 + 3 软门 + /band
8
+ - insert:
9
+ - id: preset-lean-router
10
+ name: '@deepseek-ai/dsh-agent-preset'
11
+ config:
12
+ id: lean-router
13
+ name: Lean router
14
+ description: "lean 省 token × 思考链路由 × code_run 遮蔽(2.0.0)"
15
+ order: 30
16
+ plugins:
17
+ - id: persona
18
+ name: '@deepseek-ai/dsh-persona'
19
+ config:
20
+ prefix: You are a coding agent powered by the {{model}} model.
21
+ # TODO(ticket-03/05): suffix 填充 lean 纪律双档 + 3 软门 + 首轮 [router] 分类指令
22
+ suffix: |-
23
+ - (骨架占位:lean 纪律与路由分类指令由票 03/05 填充,安装前请勿使用本预设)
24
+ - id: agent-instructions
25
+ name: '@deepseek-ai/dsh-agent-instructions'
26
+ config:
27
+ maxBytes: 65536
28
+ - id: tool-bash
29
+ name: '@deepseek-ai/dsh-tool-bash'
30
+ disabled: !!js process.platform === 'win32'
31
+ - id: tool-pwsh
32
+ name: '@deepseek-ai/dsh-tool-pwsh'
33
+ disabled: !!js process.platform !== 'win32'
34
+ - id: tool-fs
35
+ name: '@deepseek-ai/dsh-tool-fs'
36
+ - id: tool-fs-search
37
+ name: '@deepseek-ai/dsh-tool-fs-search'
38
+ - id: tool-jobs
39
+ name: '@deepseek-ai/dsh-tool-jobs'
40
+ - id: skill-filesystem
41
+ name: '@deepseek-ai/dsh-skill-filesystem'
42
+ - id: tool-skill
43
+ name: '@deepseek-ai/dsh-tool-skill'
44
+ - id: command-goal
45
+ name: '@deepseek-ai/dsh-command-goal'
46
+ - id: tool-goal
47
+ name: '@deepseek-ai/dsh-tool-goal'
48
+ # dsh-lean-router · frag-lean.patch.yml —— 票 03 lean 层(机制 1-4 + plan-mode v1 + 交付门 + 并发标记)
49
+ # 本分片由 build 脚本按固定顺序续接到顶层 YAML 块序列(scripts/build-bundle.mjs:base 后按
50
+ # frag-lean → frag-toolface → frag-router 合并);顶层为块序列续项,多操作形态参照上游
51
+ # flash-presets/cordis.patch.yml(多个 - insert: 块 + 裸 - id: 调优行)。
52
+ # 合并语义依据(宿主 dsh-app-boot/lib/index.js applyPatches L506-556):
53
+ # - 无 id 的 - insert: = 顶层追加新行;
54
+ # - 裸 - id: 行 = 按 id 寻址已有行,supplied 字段整体替换(config 整键替换,plugins 数组
55
+ # 因此整表重声明)→ 本分片第一行用裸覆写行给主模板的 preset-lean-router 重声明完整 config;
56
+ # - 合并复验由 master 用宿主 --dump-config 做(本票只保证分片形态与模块同源)。
57
+ # 数据同源:persona 双档文本 = lib/lean/persona-text.js;plan-mode v1 = lib/lean/plan-mode.js;
58
+ # 关 6 插件清单 = lib/lean/disabled.js;压缩/裁剪口径 = lib/lean/compaction.js 与 pruner.js。
59
+
60
+ # ============ 裸覆写行:preset-lean-router(lean 档 13 条)============
61
+
62
+ - id: preset-lean-router
63
+ name: '@deepseek-ai/dsh-agent-preset'
64
+ config:
65
+ id: lean-router
66
+ name: Lean router
67
+ description: "lean 省 token × 思考链路由 × code_run 遮蔽(lean 档:13 条纪律 + 3 软门 + 自检题钩子)。"
68
+ order: 30
69
+ plugins:
70
+ # 机制 4 · 行为纪律(persona 双档;lean 档 13 条硬规则 + 3 软门 + 自检题钩子)
71
+ # 上游:flash-lean-ptc-v3.patch.yml L15-60;suffix 末行留票 05 路由拼接占位。
72
+ - id: persona
73
+ name: '@deepseek-ai/dsh-persona'
74
+ config:
75
+ prefix: "You are a coding agent powered by the {{model}} model."
76
+ # 纪律双档(lean 13 / balance 3)由 lib/lean/persona-text.js 生成,与模块保持同源。
77
+ suffix: |-
78
+ LEAN OPERATING RULES (hard constraints; they override habit and tool default wording):
79
+
80
+ BUDGET FIRST
81
+ 1. Turn budget, not step budget. Target <=20 turns; folding calls into one turn is cheap, thrashing
82
+ across turns is not. Past 3x the expected turns (~60), stop and re-plan instead of looping.
83
+ Re-check roughly every 10 turns that this is still the shortest path; if it is not, re-plan.
84
+ 2. Deliberate briefly. One short deliberation, then one cheap probe/command to learn the facts;
85
+ do not enumerate an exhaustive design before acting.
86
+ 3. Input/answer-type tasks (submit a file or an answer): produce the SMALLEST artifact that
87
+ satisfies the stated constraints first; refine only while you are under the turn budget.
88
+ 4. Gate before delivery, not after. Run ONE consolidated acceptance pass over every stated
89
+ criterion, quote the measured numbers, and name what you did not verify. Measure hard limits
90
+ with the command the judge would use (/usr/bin/time -v, ulimit -v). Over-limit is a failure even
91
+ when the answer is otherwise correct. Do not verify claim by claim, do not re-run a check that
92
+ already passed, and once the gate passes stop testing and deliver.
93
+
94
+ 5. Tool choice. Inspect files with read/glob/grep; never use the shell to browse a file
95
+ (no cat/head/tail/sed -n/find/ls -R). Piping a command's own output through head is fine.
96
+ 6. Output budget. Pipe or redirect long output
97
+ (| head -40; redirect to $env:TEMP/out.log on PowerShell, %TEMP%\out.log in cmd, /tmp/out.log on POSIX).
98
+ Never print a dump you could grep.
99
+ PARALLEL CALLS (tool calls sent together run concurrently)
100
+ read-only read/grep/glob/read_image: independent calls in ONE message overlap truly.
101
+ pwsh/edit/write run serially, yet batched they still cost one round trip.
102
+ Never batch a masked tool name: it rejects the whole batch, siblings never run.
103
+ 7. Programmatic tool mode, adaptively. Fold 3+ independent calls of one logical step into ONE
104
+ run_code program; a single call may still go through a one-line program so its noise stays out
105
+ of context. Measured: pays off on multi-file/repo work (up to 8x fewer turns) and is neutral on
106
+ single-file algorithm tasks - there spend the budget on reasoning and testing, not batching.
107
+ 8. Context discipline (biggest measured lever). Read only what is new; rebuild derived answers
108
+ from files with grep/scripts instead of re-reading them into context. Keep NOTES short and
109
+ factual (<=60 lines).
110
+ 9. Author incrementally: create a file once (skeleton), then extend it with edit. Never re-emit an
111
+ unchanged file. After two failed shell patches, switch to the editor.
112
+
113
+ SAFETY
114
+ 10. Honour scope literally (a new project means do not read or copy old-project files). Use
115
+ subagents only when the user asks or the harness delegates; never spawn them to look busy.
116
+ 11. Never put secrets, tokens or private raw material into the session; reference by path.
117
+
118
+ WHEN BLOCKED
119
+ 12. If two attempts at the same approach fail, change approach once; if that also fails, report the
120
+ blocker with the exact command and observed output instead of continuing.
121
+ 13. Route awareness: running on provider "{{provider}}" with model "{{model}}". On a high-latency route
122
+ prefer fewer, larger turns; on a low-latency route more probing is affordable. Never trade
123
+ correctness for turn count.
124
+
125
+ SOFT GATES (each is one pause, never a stall)
126
+ - CLARIFY: if goal, scope, or acceptance is ambiguous in a way that changes the result, ask one consolidated question round before acting; when a cheap read/probe settles it, probe instead of asking.
127
+ - PLAN: work touching more than one file or more than ~8 steps starts with a numbered plan with a check per step; single-file small changes skip this gate.
128
+
129
+ SELF-CHECK HOOKS (questions answered to yourself; speak up only when a check fails)
130
+ - Close-the-book: could I redo the last step with the AI closed - do I actually know this fact, command, or path, or would I have to look it up again? If look-up, fetch it from the source of truth now instead of trusting recall.
131
+
132
+ # [ticket-05] 路由分类指令由票 05 拼接(本行为占位:集成时替换为票 05 的 ROUTER_PROMPT 常量)
133
+ - id: agent-instructions
134
+ name: '@deepseek-ai/dsh-agent-instructions'
135
+ config:
136
+ maxBytes: 65536
137
+ # 平台互斥(!!js 表达式,上游 lean/balance 两档同形)
138
+ - id: tool-bash
139
+ name: '@deepseek-ai/dsh-tool-bash'
140
+ disabled: !!js process.platform === 'win32'
141
+ - id: tool-pwsh
142
+ name: '@deepseek-ai/dsh-tool-pwsh'
143
+ disabled: !!js process.platform !== 'win32'
144
+ - id: tool-fs
145
+ name: '@deepseek-ai/dsh-tool-fs'
146
+ # 上游 lean 口径:超上限不抽样、直接报告(flash-lean-ptc-v3.patch.yml L73-76;codemode/cordis.patch.yml L50-53 同值)
147
+ - id: tool-fs-search
148
+ name: '@deepseek-ai/dsh-tool-fs-search'
149
+ config:
150
+ sampleOverCapGlobResults: false
151
+ - id: tool-jobs
152
+ name: '@deepseek-ai/dsh-tool-jobs'
153
+ - id: skill-filesystem
154
+ name: '@deepseek-ai/dsh-skill-filesystem'
155
+ - id: tool-skill
156
+ name: '@deepseek-ai/dsh-tool-skill'
157
+ - id: command-goal
158
+ name: '@deepseek-ai/dsh-command-goal'
159
+ - id: tool-goal
160
+ name: '@deepseek-ai/dsh-tool-goal'
161
+ # plan-mode v1 并入(上游 flash-lean-ptc-v3.patch.yml L87-107;section 文本 = lib/lean/plan-mode.js)
162
+ - id: planning
163
+ name: cordis:group
164
+ group: true
165
+ isolate:
166
+ planMode: true
167
+ config:
168
+ - id: plan-mode
169
+ name: '@deepseek-ai/dsh-plan-mode'
170
+ config:
171
+ section: |-
172
+ You are in plan mode. Stay in plan mode until exit_plan_mode succeeds or the user switches the session mode. Imperative language to implement changes means plan the implementation, not execute it. A user's conversational agreement — including an answer confirming something you asked — approves nothing and does not end plan mode; fold the confirmed decision into the plan and submit it through exit_plan_mode.
173
+
174
+ Explore first. Use non-mutating reads, searches, static analysis, and checks to ground the plan in the actual repository. Do not edit or write files, change configuration, run formatters or code generation that rewrites tracked files, commit, or otherwise carry out the plan. Prefer existing functions and patterns over new machinery.
175
+
176
+ The tool catalog stays the same across modes for request-cache stability. These plan-mode rules override any later tool description or guidance that suggests using mutation tools; those tools remain listed to keep the tool catalog unchanged. Do not use todo_write to track this planning phase: it tracks implementation after an approved plan, while the plan itself belongs in exit_plan_mode.
177
+
178
+ Resolve discoverable facts by inspection. Use ask_user_question only for user-owned choices or material ambiguity that inspection cannot answer. Do not ask the user where code lives or how current behavior works when you can find out.
179
+
180
+ Make the plan decision-complete: state the goal and success criteria; group implementation changes by subsystem; identify public API, schema, and data-flow changes; cover edge cases, failure modes, tests, acceptance criteria, and explicit assumptions. Keep it concise enough to review but detailed enough that another engineer can implement it without making design decisions.
181
+
182
+ When ready, call exit_plan_mode with the complete plan markdown, starting with a # title. Make exit_plan_mode the only and final tool call in that assistant response: it presents the plan for approval, and implementation begins only in a later step after approval. Do not paste the final plan as a plain reply or ask "should I proceed?" through prose or ask_user_question. If review rejects it, incorporate the feedback and present again. If the review channel is unavailable, stay in plan mode and ask the user to switch modes manually; do not proceed with implementation. If a review (or an ask_user_question) is aborted or times out, that is not a rejection either: do not resubmit on your own and do not switch modes yourself - tell the user it timed out and wait. Under programmatic tool mode exit_plan_mode (and ask_user_question) is reached through run_code: make it the program's only call and pass timeoutMs: 600000, because the run_code deadline includes the time the user spends reading the plan.
183
+ # 机制 1 + 机制 2(compaction 组;isolate 与上游一致;先裁剪再压缩的顺序由宿主保证)
184
+ - id: compaction
185
+ name: cordis:group
186
+ group: true
187
+ isolate:
188
+ compaction: true
189
+ toolResultPruner: true
190
+ config:
191
+ # FLASH TUNING(上游注释原文):该路由声明 1,000,000 窗口,dsh 默认 0.8 要到 800k 才压缩。
192
+ # 本预设取 0.25(250k 触发)/ 保留 20000 近期轮次。2026-11-09 实测:109 个运行
193
+ # 的上下文峰值中位 20k、p90 34k、最大 126k —— 250k 从未触发,这颗旋钮目前是
194
+ # 安全网而不是降本手段;真正压上下文的是 tool-result-pruner。
195
+ - id: compaction-basic
196
+ name: '@deepseek-ai/dsh-compaction-basic'
197
+ config:
198
+ thresholdRatio: 0.25
199
+ retainTokens: 20000
200
+ compactionRetries: 1
201
+ auto: true
202
+ - id: command-compact
203
+ name: '@deepseek-ai/dsh-command-compact'
204
+ # 裁剪口径 8192/4096/1024(上游 L129-133;不变量 head+marker+tail<=threshold 已由 lib/lean/pruner.js 复核)
205
+ - id: tool-result-pruner
206
+ name: '@deepseek-ai/dsh-compaction-tool-result-pruner'
207
+ config:
208
+ thresholdChars: 8192
209
+ headChars: 4096
210
+ tailChars: 1024
211
+ # 委派组(isolate workflowEngine;活跃三件 + 机制 3 关 6 插件清单,逐行照抄上游 L134-182)
212
+ - id: delegation
213
+ name: cordis:group
214
+ group: true
215
+ isolate:
216
+ workflowEngine: true
217
+ config:
218
+ - id: tool-subagent-control
219
+ name: '@deepseek-ai/dsh-tool-subagent-control'
220
+ - id: tool-subagent
221
+ name: '@deepseek-ai/dsh-tool-subagent'
222
+ config:
223
+ provider: spawn
224
+ toolName: subagent
225
+ modelSelectionSettings: true # DSH <=0.2.1 的旧名(上游注释)
226
+ modelSelection: true # DSH >=0.2.2:能不能选模型
227
+ modelDiscovery: true # DSH >=0.2.2:能不能列可选模型
228
+ - id: tool-subagent-fork
229
+ name: '@deepseek-ai/dsh-tool-subagent'
230
+ config:
231
+ provider: fork
232
+ toolName: subagent_fork
233
+ # 机制 3 · 关插件(上游 flash-lean-ptc-v3.patch.yml 对应行;复核见 docs/复核-关插件清单.md)
234
+ - id: tool-subagent-codex
235
+ name: "@deepseek-ai/dsh-tool-subagent"
236
+ disabled: true
237
+ config:
238
+ provider: "codex"
239
+ toolName: "subagent_codex"
240
+ maxDepth: "provider-managed"
241
+ # 机制 3 · 关插件(上游 flash-lean-ptc-v3.patch.yml 对应行;复核见 docs/复核-关插件清单.md)
242
+ - id: tool-subagent-claude-code
243
+ name: "@deepseek-ai/dsh-tool-subagent"
244
+ disabled: true
245
+ config:
246
+ provider: "claude-code"
247
+ toolName: "subagent_claude_code"
248
+ maxDepth: "provider-managed"
249
+ # 机制 3 · 关插件(上游 flash-lean-ptc-v3.patch.yml 对应行;复核见 docs/复核-关插件清单.md)
250
+ - id: workflow-ptc
251
+ name: "@deepseek-ai/dsh-workflow-ptc"
252
+ disabled: true
253
+ config:
254
+ provider: "spawn"
255
+ # 机制 3 · 关插件(上游 flash-lean-ptc-v3.patch.yml 对应行;复核见 docs/复核-关插件清单.md)
256
+ - id: tool-workflow
257
+ name: "@deepseek-ai/dsh-tool-workflow"
258
+ disabled: true
259
+ # 机制 3 · 关插件(上游 flash-lean-ptc-v3.patch.yml 对应行;复核见 docs/复核-关插件清单.md)
260
+ - id: tool-ralph
261
+ name: "@deepseek-ai/dsh-tool-ralph"
262
+ disabled: true
263
+ config:
264
+ subagentProvider: "spawn"
265
+ maxRounds: 64
266
+ - id: tool-ask-user
267
+ name: '@deepseek-ai/dsh-tool-ask-user'
268
+ - id: tool-todo
269
+ name: '@deepseek-ai/dsh-tool-todo'
270
+ config:
271
+ allowParallelInProgress: true
272
+ - id: tool-web
273
+ name: '@deepseek-ai/dsh-tool-web'
274
+ config:
275
+ fetch: true
276
+ searchTimeoutMs: 60000
277
+ - id: present
278
+ name: '@deepseek-ai/dsh-tool-present'
279
+ # 机制 3 · 第六件:插件管理工具(预设顶层,上游 L200-202)
280
+ - id: tool-plugin-manager
281
+ name: '@deepseek-ai/dsh-plugin-manager/tools'
282
+ disabled: true
283
+ # live Usage 账本:订阅 session/event 采集带 usage 的 assistant/message,注册 /token-report 命令。
284
+ # 必须留在 preset 的 plugins 内(与 command-goal 同层)才拿得到 ctx.commands;实现 = lib/lean/usage-ledger.js。
285
+ - id: lean-usage-ledger
286
+ name: 'dsh-lean-router/lean/usage-ledger'
287
+ config:
288
+ enabled: true
289
+ # 旧工具结果降级:agent/pre-step(waterfall,历史定稿前)把未降级 tool/result 攒到 >32 条时
290
+ # 批量换成一行占位符,最近 6 条永远保留原样;DSH_LEAN_ROUTER_DOWNGRADE=0 可关。
291
+ # 失败安全:钩子体全包 try/catch,异常只 warn 一次、绝不阻断 step;实现 = lib/lean/history-downgrade.js。
292
+ - id: lean-history-downgrade
293
+ name: 'dsh-lean-router/lean/history-downgrade'
294
+ config:
295
+ enabled: true
296
+
297
+ # ============ 新增行:preset-lean-router-balance(balance 档 3 条;上游双预设形态,flash-lean-ptc-v3-balance 同构)============
298
+
299
+ - insert:
300
+ - id: preset-lean-router-balance
301
+ name: '@deepseek-ai/dsh-agent-preset'
302
+ config:
303
+ id: lean-router-balance
304
+ name: "Lean router (balance)"
305
+ description: "约束较弱的精简档(balance 3 条纪律),适用于需要模型发挥的场景。"
306
+ order: 29
307
+ plugins:
308
+ # 机制 4 · 行为纪律(persona 双档;lean 档 13 条硬规则 + 3 软门 + 自检题钩子)
309
+ # 上游:flash-lean-ptc-v3.patch.yml L15-60;suffix 末行留票 05 路由拼接占位。
310
+ - id: persona
311
+ name: '@deepseek-ai/dsh-persona'
312
+ config:
313
+ prefix: "You are a coding agent powered by the {{model}} model."
314
+ # 纪律双档(lean 13 / balance 3)由 lib/lean/persona-text.js 生成,与模块保持同源。
315
+ suffix: |-
316
+ CORE RULES (only what the harness cannot enforce for you):
317
+ 1. Answer in the user scope. Honour the requested language and the stated scope literally; do not read or copy files outside it.
318
+ 2. Never put secrets, tokens or private raw material into the session; reference them by path.
319
+ 3. If two attempts at the same approach fail, change approach once; if that also fails, report the blocker with the exact command and the observed output instead of continuing.
320
+
321
+ # [ticket-05] 路由分类指令由票 05 拼接(本行为占位:集成时替换为票 05 的 ROUTER_PROMPT 常量)
322
+ - id: agent-instructions
323
+ name: '@deepseek-ai/dsh-agent-instructions'
324
+ config:
325
+ maxBytes: 65536
326
+ # 平台互斥(!!js 表达式,上游 lean/balance 两档同形)
327
+ - id: tool-bash
328
+ name: '@deepseek-ai/dsh-tool-bash'
329
+ disabled: !!js process.platform === 'win32'
330
+ - id: tool-pwsh
331
+ name: '@deepseek-ai/dsh-tool-pwsh'
332
+ disabled: !!js process.platform !== 'win32'
333
+ - id: tool-fs
334
+ name: '@deepseek-ai/dsh-tool-fs'
335
+ # 上游 lean 口径:超上限不抽样、直接报告(flash-lean-ptc-v3.patch.yml L73-76;codemode/cordis.patch.yml L50-53 同值)
336
+ - id: tool-fs-search
337
+ name: '@deepseek-ai/dsh-tool-fs-search'
338
+ config:
339
+ sampleOverCapGlobResults: false
340
+ - id: tool-jobs
341
+ name: '@deepseek-ai/dsh-tool-jobs'
342
+ - id: skill-filesystem
343
+ name: '@deepseek-ai/dsh-skill-filesystem'
344
+ - id: tool-skill
345
+ name: '@deepseek-ai/dsh-tool-skill'
346
+ - id: command-goal
347
+ name: '@deepseek-ai/dsh-command-goal'
348
+ - id: tool-goal
349
+ name: '@deepseek-ai/dsh-tool-goal'
350
+ # plan-mode v1 并入(上游 flash-lean-ptc-v3.patch.yml L87-107;section 文本 = lib/lean/plan-mode.js)
351
+ - id: planning
352
+ name: cordis:group
353
+ group: true
354
+ isolate:
355
+ planMode: true
356
+ config:
357
+ - id: plan-mode
358
+ name: '@deepseek-ai/dsh-plan-mode'
359
+ config:
360
+ section: |-
361
+ You are in plan mode. Stay in plan mode until exit_plan_mode succeeds or the user switches the session mode. Imperative language to implement changes means plan the implementation, not execute it. A user's conversational agreement — including an answer confirming something you asked — approves nothing and does not end plan mode; fold the confirmed decision into the plan and submit it through exit_plan_mode.
362
+
363
+ Explore first. Use non-mutating reads, searches, static analysis, and checks to ground the plan in the actual repository. Do not edit or write files, change configuration, run formatters or code generation that rewrites tracked files, commit, or otherwise carry out the plan. Prefer existing functions and patterns over new machinery.
364
+
365
+ The tool catalog stays the same across modes for request-cache stability. These plan-mode rules override any later tool description or guidance that suggests using mutation tools; those tools remain listed to keep the tool catalog unchanged. Do not use todo_write to track this planning phase: it tracks implementation after an approved plan, while the plan itself belongs in exit_plan_mode.
366
+
367
+ Resolve discoverable facts by inspection. Use ask_user_question only for user-owned choices or material ambiguity that inspection cannot answer. Do not ask the user where code lives or how current behavior works when you can find out.
368
+
369
+ Make the plan decision-complete: state the goal and success criteria; group implementation changes by subsystem; identify public API, schema, and data-flow changes; cover edge cases, failure modes, tests, acceptance criteria, and explicit assumptions. Keep it concise enough to review but detailed enough that another engineer can implement it without making design decisions.
370
+
371
+ When ready, call exit_plan_mode with the complete plan markdown, starting with a # title. Make exit_plan_mode the only and final tool call in that assistant response: it presents the plan for approval, and implementation begins only in a later step after approval. Do not paste the final plan as a plain reply or ask "should I proceed?" through prose or ask_user_question. If review rejects it, incorporate the feedback and present again. If the review channel is unavailable, stay in plan mode and ask the user to switch modes manually; do not proceed with implementation. If a review (or an ask_user_question) is aborted or times out, that is not a rejection either: do not resubmit on your own and do not switch modes yourself - tell the user it timed out and wait. Under programmatic tool mode exit_plan_mode (and ask_user_question) is reached through run_code: make it the program's only call and pass timeoutMs: 600000, because the run_code deadline includes the time the user spends reading the plan.
372
+ # 机制 1 + 机制 2(compaction 组;isolate 与上游一致;先裁剪再压缩的顺序由宿主保证)
373
+ - id: compaction
374
+ name: cordis:group
375
+ group: true
376
+ isolate:
377
+ compaction: true
378
+ toolResultPruner: true
379
+ config:
380
+ # FLASH TUNING(上游注释原文):该路由声明 1,000,000 窗口,dsh 默认 0.8 要到 800k 才压缩。
381
+ # 本预设取 0.25(250k 触发)/ 保留 20000 近期轮次。2026-11-09 实测:109 个运行
382
+ # 的上下文峰值中位 20k、p90 34k、最大 126k —— 250k 从未触发,这颗旋钮目前是
383
+ # 安全网而不是降本手段;真正压上下文的是 tool-result-pruner。
384
+ - id: compaction-basic
385
+ name: '@deepseek-ai/dsh-compaction-basic'
386
+ config:
387
+ thresholdRatio: 0.25
388
+ retainTokens: 20000
389
+ compactionRetries: 1
390
+ auto: true
391
+ - id: command-compact
392
+ name: '@deepseek-ai/dsh-command-compact'
393
+ # 裁剪口径 8192/4096/1024(上游 L129-133;不变量 head+marker+tail<=threshold 已由 lib/lean/pruner.js 复核)
394
+ - id: tool-result-pruner
395
+ name: '@deepseek-ai/dsh-compaction-tool-result-pruner'
396
+ config:
397
+ thresholdChars: 8192
398
+ headChars: 4096
399
+ tailChars: 1024
400
+ # 委派组(isolate workflowEngine;活跃三件 + 机制 3 关 6 插件清单,逐行照抄上游 L134-182)
401
+ - id: delegation
402
+ name: cordis:group
403
+ group: true
404
+ isolate:
405
+ workflowEngine: true
406
+ config:
407
+ - id: tool-subagent-control
408
+ name: '@deepseek-ai/dsh-tool-subagent-control'
409
+ - id: tool-subagent
410
+ name: '@deepseek-ai/dsh-tool-subagent'
411
+ config:
412
+ provider: spawn
413
+ toolName: subagent
414
+ modelSelectionSettings: true # DSH <=0.2.1 的旧名(上游注释)
415
+ modelSelection: true # DSH >=0.2.2:能不能选模型
416
+ modelDiscovery: true # DSH >=0.2.2:能不能列可选模型
417
+ - id: tool-subagent-fork
418
+ name: '@deepseek-ai/dsh-tool-subagent'
419
+ config:
420
+ provider: fork
421
+ toolName: subagent_fork
422
+ # 机制 3 · 关插件(上游 flash-lean-ptc-v3.patch.yml 对应行;复核见 docs/复核-关插件清单.md)
423
+ - id: tool-subagent-codex
424
+ name: "@deepseek-ai/dsh-tool-subagent"
425
+ disabled: true
426
+ config:
427
+ provider: "codex"
428
+ toolName: "subagent_codex"
429
+ maxDepth: "provider-managed"
430
+ # 机制 3 · 关插件(上游 flash-lean-ptc-v3.patch.yml 对应行;复核见 docs/复核-关插件清单.md)
431
+ - id: tool-subagent-claude-code
432
+ name: "@deepseek-ai/dsh-tool-subagent"
433
+ disabled: true
434
+ config:
435
+ provider: "claude-code"
436
+ toolName: "subagent_claude_code"
437
+ maxDepth: "provider-managed"
438
+ # 机制 3 · 关插件(上游 flash-lean-ptc-v3.patch.yml 对应行;复核见 docs/复核-关插件清单.md)
439
+ - id: workflow-ptc
440
+ name: "@deepseek-ai/dsh-workflow-ptc"
441
+ disabled: true
442
+ config:
443
+ provider: "spawn"
444
+ # 机制 3 · 关插件(上游 flash-lean-ptc-v3.patch.yml 对应行;复核见 docs/复核-关插件清单.md)
445
+ - id: tool-workflow
446
+ name: "@deepseek-ai/dsh-tool-workflow"
447
+ disabled: true
448
+ # 机制 3 · 关插件(上游 flash-lean-ptc-v3.patch.yml 对应行;复核见 docs/复核-关插件清单.md)
449
+ - id: tool-ralph
450
+ name: "@deepseek-ai/dsh-tool-ralph"
451
+ disabled: true
452
+ config:
453
+ subagentProvider: "spawn"
454
+ maxRounds: 64
455
+ - id: tool-ask-user
456
+ name: '@deepseek-ai/dsh-tool-ask-user'
457
+ - id: tool-todo
458
+ name: '@deepseek-ai/dsh-tool-todo'
459
+ config:
460
+ allowParallelInProgress: true
461
+ - id: tool-web
462
+ name: '@deepseek-ai/dsh-tool-web'
463
+ config:
464
+ fetch: true
465
+ searchTimeoutMs: 60000
466
+ - id: present
467
+ name: '@deepseek-ai/dsh-tool-present'
468
+ # 机制 3 · 第六件:插件管理工具(预设顶层,上游 L200-202)
469
+ - id: tool-plugin-manager
470
+ name: '@deepseek-ai/dsh-plugin-manager/tools'
471
+ disabled: true
472
+ # live Usage 账本(balance 档同挂):见 lean 档同名行说明。
473
+ - id: lean-usage-ledger
474
+ name: 'dsh-lean-router/lean/usage-ledger'
475
+ config:
476
+ enabled: true
477
+ # 旧工具结果降级(balance 档同挂):见 lean 档同名行说明。
478
+ - id: lean-history-downgrade
479
+ name: 'dsh-lean-router/lean/history-downgrade'
480
+ config:
481
+ enabled: true
482
+
483
+ # ============ 新增行:交付门(加料件)============
484
+ # 默认关闭(enabled: false):它会执行工作区里的验收脚本,要用户显式打开
485
+ # (上游 cordis.patch.yml L392-400 同口径)。插件实现 = lib/lean/delivery-gate.js;
486
+ # 插件行 name 为包内子路径,需 package.json exports 增加 ./lean/delivery-gate(master 集成)。
487
+
488
+ - insert:
489
+ - id: lean-delivery-gate
490
+ name: 'dsh-lean-router/lean/delivery-gate'
491
+ config:
492
+ enabled: false
493
+ maxRounds: 2
494
+
495
+ # ============ 新增行:glob/grep 只读并发标记(加料件)============
496
+ # 默认开启;关闭优先级从高到低:DSH_LEAN_ROUTER_CONCURRENCY=0(兼容 DSH_FLASH_PRESETS_CONCURRENCY=0)
497
+ # > 本行 config.toolConcurrency.enabled=false > 默认开启。插件实现 = lib/lean/tool-concurrency.js;
498
+ # 插件行 name 为包内子路径,需 package.json exports 增加 ./lean/tool-concurrency(master 集成)。
499
+
500
+ - insert:
501
+ - id: lean-concurrency
502
+ name: 'dsh-lean-router/lean/tool-concurrency'
503
+ config:
504
+ toolConcurrency:
505
+ enabled: true
506
+
507
+ # dsh-lean-router frag-toolface.patch.yml — 票 04 工具遮蔽层
508
+ # 由 scripts/build-bundle.mjs 拼在 presets/base/lean-router.patch.yml 之后(顶层列表续项)。
509
+ # 形态与上游 dsh-codemode 0.3.x 样本一致(cordis patch 顶层 "- <op>:" 列表;本分片为
510
+ # 键级 override 操作,参照上游 fixtures/verify-host-codemode.patch.yml 的 "- id: tools" 形态)。
511
+ #
512
+ # cordis patch override 是「键级整体替换」(target[key] = value),预设行不是 group、
513
+ # 无法向 plugins 数组增量插入,因此本分片把 preset-lean-router 的 config.plugins
514
+ # 整快照重声明:base 全部行原样保留 + 追加 toolface 行。
515
+ # 防漂移:test/toolface-wiring.test.mjs 校验本分片行集合 = base 模板行集合 + toolface。
516
+ # 集成注意:票 03/05 若也需改 preset 行(persona suffix、加行),与本分片是同一接缝,
517
+ # 由 master 统一裁决(最终可把 toolface 行并入 base 模板、本分片只留校验)。
518
+ - id: preset-lean-router
519
+ config:
520
+ plugins:
521
+ - id: persona
522
+ name: '@deepseek-ai/dsh-persona'
523
+ config:
524
+ prefix: You are a coding agent powered by the {{model}} model.
525
+ # 骨架占位原样保留:lean 纪律与路由分类指令由票 03/05 填充
526
+ suffix: |-
527
+ - (骨架占位:lean 纪律与路由分类指令由票 03/05 填充,安装前请勿使用本预设)
528
+ - id: agent-instructions
529
+ name: '@deepseek-ai/dsh-agent-instructions'
530
+ config:
531
+ maxBytes: 65536
532
+ - id: tool-bash
533
+ name: '@deepseek-ai/dsh-tool-bash'
534
+ disabled: !!js process.platform === 'win32'
535
+ - id: tool-pwsh
536
+ name: '@deepseek-ai/dsh-tool-pwsh'
537
+ disabled: !!js process.platform !== 'win32'
538
+ - id: tool-fs
539
+ name: '@deepseek-ai/dsh-tool-fs'
540
+ - id: tool-fs-search
541
+ name: '@deepseek-ai/dsh-tool-fs-search'
542
+ - id: tool-jobs
543
+ name: '@deepseek-ai/dsh-tool-jobs'
544
+ - id: skill-filesystem
545
+ name: '@deepseek-ai/dsh-skill-filesystem'
546
+ - id: tool-skill
547
+ name: '@deepseek-ai/dsh-tool-skill'
548
+ - id: command-goal
549
+ name: '@deepseek-ai/dsh-command-goal'
550
+ - id: tool-goal
551
+ name: '@deepseek-ai/dsh-tool-goal'
552
+ - id: toolface
553
+ name: 'dsh-lean-router/toolface'
554
+ config:
555
+ # 与上游 dsh-codemode 0.3.x 的 codemode 行同形(默认值显式写出)
556
+ # 遮蔽名前缀:MCP 工具名 mcp__server__tool
557
+ hiddenPrefixes:
558
+ - 'mcp__'
559
+ # 预设自身清单之外的工具(全局层 MCP/bundle、agent 层工具集)一律遮蔽
560
+ nativeScope: true
561
+ nativeTools: []
562
+ hiddenTools: []
563
+ # 传输工具名:run_code 为 DSH 保留名,注册表拒绝注册,故用 code_run
564
+ runToolName: code_run
565
+ # 发现工具(仅可从程序内部调用)
566
+ metaTools:
567
+ - code_tools_list
568
+ - code_tools_search
569
+ - code_tools_describe
570
+ - code_debug
571
+ searchLimit: 8
572
+ maxDescriptionChars: 240
573
+ # 一个程序的最大并发子调用
574
+ maxParallelSubCalls: 10
575
+ # 拒绝模型直呼被遮蔽名(派发前),并以 Code Mode 段替换 tools:sdk
576
+ guard: true
577
+ sdkSection: true
578
+ # code_debug 保留最近的装配决策
579
+ debug: true
580
+ # dsh-lean-router 票 05 路由层分片(顶层列表续项;由 scripts/build-bundle.mjs 续接进 cordis.patch.yml)
581
+ # 钩子行:agent/inbox/claimed 首轮捕获 + 近场引导 dynamic context + 勤勉自检
582
+ # 命令行:/band 显式改档(宿主 ctx.commands 缝)
583
+ # 入口子路径 dsh-lean-router/router 需要 package.json exports 增补 "./router": "./lib/router.js"
584
+ # (package.json 为共享文件,由 master 统一集成;见 lib/router.js ROUTER_INJECTION_NOTES.patchEntry)
585
+ - insert:
586
+ - id: lean-router-router
587
+ name: dsh-lean-router/router
588
+ config:
589
+ hooks: true
590
+ commands: false
591
+ diligenceEvery: 10
592
+ - id: lean-router-commands
593
+ name: dsh-lean-router/router
594
+ config:
595
+ hooks: false
596
+ commands: true
597
+ # dsh-lean-router frag-preset.patch.yml - master 集成产物(票 03/04/05/06 preset 行收敛)
598
+ # 唯一生效 owner:cordis patch 键级整体替换 + 本片在 FRAGMENTS 最后 → apply 时以本片为准。
599
+ # frag-lean / frag-toolface 的同 id 覆写保留原文件(其自测不动),apply 时被本片覆盖。
600
+ # persona suffix = LEAN_PERSONA_SUFFIX(lean 13 纪律 + 3 软门 + 自检钩)拼接 ROUTER_PROMPT(首轮 [router] 分类指令),
601
+ # 由 lib/lean/persona-text.js 与 lib/router.js 同源生成;改动模块后重跑本脚本 + npm run build 即同步。
602
+ # v1 裁定(master):三带 persona 不常驻 suffix,走 pre-step 近场引导分流;balance 预设行 v1 不拼路由指令(见票 08)。
603
+ - id: preset-lean-router
604
+ name: '@deepseek-ai/dsh-agent-preset'
605
+ config:
606
+ id: lean-router
607
+ name: Lean router
608
+ description: "lean 省 token × 思考链路由 × code_run 遮蔽(lean 档:13 条纪律 + 3 软门 + 自检题钩子)。"
609
+ order: 30
610
+ plugins:
611
+ - id: persona
612
+ name: '@deepseek-ai/dsh-persona'
613
+ config:
614
+ prefix: "You are a coding agent powered by the {{model}} model."
615
+ # 纪律双档(lean 13 / balance 3)由 lib/lean/persona-text.js 生成,与模块保持同源。
616
+ suffix: |-
617
+ LEAN OPERATING RULES (hard constraints; they override habit and tool default wording):
618
+
619
+ BUDGET FIRST
620
+ 1. Turn budget, not step budget. Target <=20 turns; folding calls into one turn is cheap, thrashing
621
+ across turns is not. Past 3x the expected turns (~60), stop and re-plan instead of looping.
622
+ Re-check roughly every 10 turns that this is still the shortest path; if it is not, re-plan.
623
+ 2. Deliberate briefly. One short deliberation, then one cheap probe/command to learn the facts;
624
+ do not enumerate an exhaustive design before acting.
625
+ 3. Input/answer-type tasks (submit a file or an answer): produce the SMALLEST artifact that
626
+ satisfies the stated constraints first; refine only while you are under the turn budget.
627
+ 4. Gate before delivery, not after. Run ONE consolidated acceptance pass over every stated
628
+ criterion, quote the measured numbers, and name what you did not verify. Measure hard limits
629
+ with the command the judge would use (/usr/bin/time -v, ulimit -v). Over-limit is a failure even
630
+ when the answer is otherwise correct. Do not verify claim by claim, do not re-run a check that
631
+ already passed, and once the gate passes stop testing and deliver.
632
+
633
+ 5. Tool choice. Inspect files with read/glob/grep; never use the shell to browse a file
634
+ (no cat/head/tail/sed -n/find/ls -R). Piping a command's own output through head is fine.
635
+ 6. Output budget. Pipe or redirect long output
636
+ (| head -40; redirect to $env:TEMP/out.log on PowerShell, %TEMP%\out.log in cmd, /tmp/out.log on POSIX).
637
+ Never print a dump you could grep.
638
+ PARALLEL CALLS (tool calls sent together run concurrently)
639
+ read-only read/grep/glob/read_image: independent calls in ONE message overlap truly.
640
+ pwsh/edit/write run serially, yet batched they still cost one round trip.
641
+ Never batch a masked tool name: it rejects the whole batch, siblings never run.
642
+ 7. Programmatic tool mode, adaptively. Fold 3+ independent calls of one logical step into ONE
643
+ run_code program; a single call may still go through a one-line program so its noise stays out
644
+ of context. Measured: pays off on multi-file/repo work (up to 8x fewer turns) and is neutral on
645
+ single-file algorithm tasks - there spend the budget on reasoning and testing, not batching.
646
+ 8. Context discipline (biggest measured lever). Read only what is new; rebuild derived answers
647
+ from files with grep/scripts instead of re-reading them into context. Keep NOTES short and
648
+ factual (<=60 lines).
649
+ 9. Author incrementally: create a file once (skeleton), then extend it with edit. Never re-emit an
650
+ unchanged file. After two failed shell patches, switch to the editor.
651
+
652
+ SAFETY
653
+ 10. Honour scope literally (a new project means do not read or copy old-project files). Use
654
+ subagents only when the user asks or the harness delegates; never spawn them to look busy.
655
+ 11. Never put secrets, tokens or private raw material into the session; reference by path.
656
+
657
+ WHEN BLOCKED
658
+ 12. If two attempts at the same approach fail, change approach once; if that also fails, report the
659
+ blocker with the exact command and observed output instead of continuing.
660
+ 13. Route awareness: running on provider "{{provider}}" with model "{{model}}". On a high-latency route
661
+ prefer fewer, larger turns; on a low-latency route more probing is affordable. Never trade
662
+ correctness for turn count.
663
+
664
+ SOFT GATES (each is one pause, never a stall)
665
+ - CLARIFY: if goal, scope, or acceptance is ambiguous in a way that changes the result, ask one consolidated question round before acting; when a cheap read/probe settles it, probe instead of asking.
666
+ - PLAN: work touching more than one file or more than ~8 steps starts with a numbered plan with a check per step; single-file small changes skip this gate.
667
+
668
+ SELF-CHECK HOOKS (questions answered to yourself; speak up only when a check fails)
669
+ - Close-the-book: could I redo the last step with the AI closed - do I actually know this fact, command, or path, or would I have to look it up again? If look-up, fetch it from the source of truth now instead of trusting recall.
670
+
671
+ Routing: before acting on any new task, classify it - (build) create something new end-to-end, or (fix) diagnose and repair something broken - then adopt the matching style: build -> hands-on production; fix -> inspect-and-plan.
672
+ The first real user message of the session may carry an explicit directive like [router] band=spec|react|weak|auto task=<one line>; treat it as the routing decision for the session.
673
+ Recall what you have already done in this session and continue from there; do not repeat completed steps.
674
+ Converge on the deliverable; do not expand scope.
675
+ Return to the task at hand whenever you notice drift.
676
+ - id: agent-instructions
677
+ name: '@deepseek-ai/dsh-agent-instructions'
678
+ config:
679
+ maxBytes: 65536
680
+ # 平台互斥(!!js 表达式,上游 lean/balance 两档同形)
681
+ - id: tool-bash
682
+ name: '@deepseek-ai/dsh-tool-bash'
683
+ disabled: !!js process.platform === 'win32'
684
+ - id: tool-pwsh
685
+ name: '@deepseek-ai/dsh-tool-pwsh'
686
+ disabled: !!js process.platform !== 'win32'
687
+ - id: tool-fs
688
+ name: '@deepseek-ai/dsh-tool-fs'
689
+ # 上游 lean 口径:超上限不抽样、直接报告(flash-lean-ptc-v3.patch.yml L73-76;codemode/cordis.patch.yml L50-53 同值)
690
+ - id: tool-fs-search
691
+ name: '@deepseek-ai/dsh-tool-fs-search'
692
+ config:
693
+ sampleOverCapGlobResults: false
694
+ - id: tool-jobs
695
+ name: '@deepseek-ai/dsh-tool-jobs'
696
+ - id: skill-filesystem
697
+ name: '@deepseek-ai/dsh-skill-filesystem'
698
+ - id: tool-skill
699
+ name: '@deepseek-ai/dsh-tool-skill'
700
+ - id: command-goal
701
+ name: '@deepseek-ai/dsh-command-goal'
702
+ - id: tool-goal
703
+ name: '@deepseek-ai/dsh-tool-goal'
704
+ # plan-mode v1 并入(上游 flash-lean-ptc-v3.patch.yml L87-107;section 文本 = lib/lean/plan-mode.js)
705
+ - id: planning
706
+ name: cordis:group
707
+ group: true
708
+ isolate:
709
+ planMode: true
710
+ config:
711
+ - id: plan-mode
712
+ name: '@deepseek-ai/dsh-plan-mode'
713
+ config:
714
+ section: |-
715
+ You are in plan mode. Stay in plan mode until exit_plan_mode succeeds or the user switches the session mode. Imperative language to implement changes means plan the implementation, not execute it. A user's conversational agreement — including an answer confirming something you asked — approves nothing and does not end plan mode; fold the confirmed decision into the plan and submit it through exit_plan_mode.
716
+
717
+ Explore first. Use non-mutating reads, searches, static analysis, and checks to ground the plan in the actual repository. Do not edit or write files, change configuration, run formatters or code generation that rewrites tracked files, commit, or otherwise carry out the plan. Prefer existing functions and patterns over new machinery.
718
+
719
+ The tool catalog stays the same across modes for request-cache stability. These plan-mode rules override any later tool description or guidance that suggests using mutation tools; those tools remain listed to keep the tool catalog unchanged. Do not use todo_write to track this planning phase: it tracks implementation after an approved plan, while the plan itself belongs in exit_plan_mode.
720
+
721
+ Resolve discoverable facts by inspection. Use ask_user_question only for user-owned choices or material ambiguity that inspection cannot answer. Do not ask the user where code lives or how current behavior works when you can find out.
722
+
723
+ Make the plan decision-complete: state the goal and success criteria; group implementation changes by subsystem; identify public API, schema, and data-flow changes; cover edge cases, failure modes, tests, acceptance criteria, and explicit assumptions. Keep it concise enough to review but detailed enough that another engineer can implement it without making design decisions.
724
+
725
+ When ready, call exit_plan_mode with the complete plan markdown, starting with a # title. Make exit_plan_mode the only and final tool call in that assistant response: it presents the plan for approval, and implementation begins only in a later step after approval. Do not paste the final plan as a plain reply or ask "should I proceed?" through prose or ask_user_question. If review rejects it, incorporate the feedback and present again. If the review channel is unavailable, stay in plan mode and ask the user to switch modes manually; do not proceed with implementation. If a review (or an ask_user_question) is aborted or times out, that is not a rejection either: do not resubmit on your own and do not switch modes yourself - tell the user it timed out and wait. Under programmatic tool mode exit_plan_mode (and ask_user_question) is reached through run_code: make it the program's only call and pass timeoutMs: 600000, because the run_code deadline includes the time the user spends reading the plan.
726
+ # 机制 1 + 机制 2(compaction 组;isolate 与上游一致;先裁剪再压缩的顺序由宿主保证)
727
+ - id: compaction
728
+ name: cordis:group
729
+ group: true
730
+ isolate:
731
+ compaction: true
732
+ toolResultPruner: true
733
+ config:
734
+ # FLASH TUNING(上游注释原文):该路由声明 1,000,000 窗口,dsh 默认 0.8 要到 800k 才压缩。
735
+ # 本预设取 0.25(250k 触发)/ 保留 20000 近期轮次。2026-11-09 实测:109 个运行
736
+ # 的上下文峰值中位 20k、p90 34k、最大 126k —— 250k 从未触发,这颗旋钮目前是
737
+ # 安全网而不是降本手段;真正压上下文的是 tool-result-pruner。
738
+ - id: compaction-basic
739
+ name: '@deepseek-ai/dsh-compaction-basic'
740
+ config:
741
+ thresholdRatio: 0.25
742
+ retainTokens: 20000
743
+ compactionRetries: 1
744
+ auto: true
745
+ - id: command-compact
746
+ name: '@deepseek-ai/dsh-command-compact'
747
+ # 裁剪口径 8192/4096/1024(上游 L129-133;不变量 head+marker+tail<=threshold 已由 lib/lean/pruner.js 复核)
748
+ - id: tool-result-pruner
749
+ name: '@deepseek-ai/dsh-compaction-tool-result-pruner'
750
+ config:
751
+ thresholdChars: 8192
752
+ headChars: 4096
753
+ tailChars: 1024
754
+ # 委派组(isolate workflowEngine;活跃三件 + 机制 3 关 6 插件清单,逐行照抄上游 L134-182)
755
+ - id: delegation
756
+ name: cordis:group
757
+ group: true
758
+ isolate:
759
+ workflowEngine: true
760
+ config:
761
+ - id: tool-subagent-control
762
+ name: '@deepseek-ai/dsh-tool-subagent-control'
763
+ - id: tool-subagent
764
+ name: '@deepseek-ai/dsh-tool-subagent'
765
+ config:
766
+ provider: spawn
767
+ toolName: subagent
768
+ modelSelectionSettings: true # DSH <=0.2.1 的旧名(上游注释)
769
+ modelSelection: true # DSH >=0.2.2:能不能选模型
770
+ modelDiscovery: true # DSH >=0.2.2:能不能列可选模型
771
+ - id: tool-subagent-fork
772
+ name: '@deepseek-ai/dsh-tool-subagent'
773
+ config:
774
+ provider: fork
775
+ toolName: subagent_fork
776
+ # 机制 3 · 关插件(上游 flash-lean-ptc-v3.patch.yml 对应行;复核见 docs/复核-关插件清单.md)
777
+ - id: tool-subagent-codex
778
+ name: "@deepseek-ai/dsh-tool-subagent"
779
+ disabled: true
780
+ config:
781
+ provider: "codex"
782
+ toolName: "subagent_codex"
783
+ maxDepth: "provider-managed"
784
+ # 机制 3 · 关插件(上游 flash-lean-ptc-v3.patch.yml 对应行;复核见 docs/复核-关插件清单.md)
785
+ - id: tool-subagent-claude-code
786
+ name: "@deepseek-ai/dsh-tool-subagent"
787
+ disabled: true
788
+ config:
789
+ provider: "claude-code"
790
+ toolName: "subagent_claude_code"
791
+ maxDepth: "provider-managed"
792
+ # 机制 3 · 关插件(上游 flash-lean-ptc-v3.patch.yml 对应行;复核见 docs/复核-关插件清单.md)
793
+ - id: workflow-ptc
794
+ name: "@deepseek-ai/dsh-workflow-ptc"
795
+ disabled: true
796
+ config:
797
+ provider: "spawn"
798
+ # 机制 3 · 关插件(上游 flash-lean-ptc-v3.patch.yml 对应行;复核见 docs/复核-关插件清单.md)
799
+ - id: tool-workflow
800
+ name: "@deepseek-ai/dsh-tool-workflow"
801
+ disabled: true
802
+ # 机制 3 · 关插件(上游 flash-lean-ptc-v3.patch.yml 对应行;复核见 docs/复核-关插件清单.md)
803
+ - id: tool-ralph
804
+ name: "@deepseek-ai/dsh-tool-ralph"
805
+ disabled: true
806
+ config:
807
+ subagentProvider: "spawn"
808
+ maxRounds: 64
809
+ - id: tool-ask-user
810
+ name: '@deepseek-ai/dsh-tool-ask-user'
811
+ - id: tool-todo
812
+ name: '@deepseek-ai/dsh-tool-todo'
813
+ config:
814
+ allowParallelInProgress: true
815
+ - id: tool-web
816
+ name: '@deepseek-ai/dsh-tool-web'
817
+ config:
818
+ fetch: true
819
+ searchTimeoutMs: 60000
820
+ - id: present
821
+ name: '@deepseek-ai/dsh-tool-present'
822
+ # 机制 3 · 第六件:插件管理工具(预设顶层,上游 L200-202)
823
+ - id: tool-plugin-manager
824
+ name: '@deepseek-ai/dsh-plugin-manager/tools'
825
+ disabled: true
826
+ # live Usage 账本:订阅 session/event 采集带 usage 的 assistant/message,注册 /token-report 命令。
827
+ # 必须留在 preset 的 plugins 内(与 command-goal 同层)才拿得到 ctx.commands;实现 = lib/lean/usage-ledger.js。
828
+ - id: lean-usage-ledger
829
+ name: 'dsh-lean-router/lean/usage-ledger'
830
+ config:
831
+ enabled: true
832
+ # 旧工具结果降级:agent/pre-step(waterfall,历史定稿前)把未降级 tool/result 攒到 >32 条时
833
+ # 批量换成一行占位符,最近 6 条永远保留原样;DSH_LEAN_ROUTER_DOWNGRADE=0 可关。
834
+ # 失败安全:钩子体全包 try/catch,异常只 warn 一次、绝不阻断 step;实现 = lib/lean/history-downgrade.js。
835
+ - id: lean-history-downgrade
836
+ name: 'dsh-lean-router/lean/history-downgrade'
837
+ config:
838
+ enabled: true
839
+
840
+ # ============ 新增行:preset-lean-router-balance(balance 档 3 条;上游双预设形态,flash-lean-ptc-v3-balance 同构)============
841
+
842
+ - id: toolface
843
+ name: 'dsh-lean-router/toolface'
844
+ config:
845
+ # 与上游 dsh-codemode 0.3.x 的 codemode 行同形(默认值显式写出)
846
+ # 遮蔽名前缀:MCP 工具名 mcp__server__tool
847
+ hiddenPrefixes:
848
+ - 'mcp__'
849
+ # 预设自身清单之外的工具(全局层 MCP/bundle、agent 层工具集)一律遮蔽
850
+ nativeScope: true
851
+ nativeTools: []
852
+ hiddenTools: []
853
+ # 传输工具名:run_code 为 DSH 保留名,注册表拒绝注册,故用 code_run
854
+ runToolName: code_run
855
+ # 发现工具(仅可从程序内部调用)
856
+ metaTools:
857
+ - code_tools_list
858
+ - code_tools_search
859
+ - code_tools_describe
860
+ - code_debug
861
+ searchLimit: 8
862
+ maxDescriptionChars: 240
863
+ # 一个程序的最大并发子调用
864
+ maxParallelSubCalls: 10
865
+ # 拒绝模型直呼被遮蔽名(派发前),并以 Code Mode 段替换 tools:sdk
866
+ guard: true
867
+ sdkSection: true
868
+ # code_debug 保留最近的装配决策
869
+ debug: true
870
+