dsh-lean-router 0.0.0-stage → 0.2.4

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 (91) 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 +279 -0
  15. package/docs/changelog.md +282 -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/desc-slim.js +140 -0
  45. package/lib/toolface/discovery.js +297 -0
  46. package/lib/toolface/executor.js +333 -0
  47. package/lib/toolface/index.js +250 -0
  48. package/lib/toolface/pool.js +160 -0
  49. package/lib/toolface/retention.js +187 -0
  50. package/lib/toolface/rules.js +435 -0
  51. package/lib/toolface/scope.js +188 -0
  52. package/lib/toolface/transport.js +335 -0
  53. package/package.json +65 -4
  54. package/presets/base/frag-lean.patch.yml +459 -0
  55. package/presets/base/frag-preset.patch.yml +274 -0
  56. package/presets/base/frag-router.patch.yml +17 -0
  57. package/presets/base/frag-toolface.patch.yml +73 -0
  58. package/presets/base/lean-router.patch.yml +44 -0
  59. package/scripts/build-bundle.mjs +45 -0
  60. package/scripts/doctor.mjs +35 -0
  61. package/scripts/install-profile.mjs +113 -0
  62. package/scripts/install.mjs +20 -0
  63. package/scripts/integrate-preset.mjs +107 -0
  64. package/scripts/release.mjs +146 -0
  65. package/scripts/verify.mjs +8 -0
  66. package/test/build.test.mjs +7 -0
  67. package/test/history-budget.test.mjs +210 -0
  68. package/test/history-downgrade.test.mjs +379 -0
  69. package/test/integration-preset.test.mjs +59 -0
  70. package/test/lean-compaction.test.mjs +47 -0
  71. package/test/lean-concurrency.test.mjs +117 -0
  72. package/test/lean-delivery-gate.test.mjs +75 -0
  73. package/test/lean-frag.test.mjs +132 -0
  74. package/test/lean-modules.test.mjs +112 -0
  75. package/test/lean-pruner.test.mjs +42 -0
  76. package/test/output-slim.test.mjs +212 -0
  77. package/test/package.test.mjs +20 -0
  78. package/test/patch-yaml.test.mjs +45 -0
  79. package/test/plugin-entry.test.mjs +26 -0
  80. package/test/router-bands.test.mjs +98 -0
  81. package/test/router.test.mjs +215 -0
  82. package/test/token-ledger-live.test.mjs +351 -0
  83. package/test/token-ledger.test.mjs +264 -0
  84. package/test/toolface-desc-slim.test.mjs +255 -0
  85. package/test/toolface-executor.test.mjs +302 -0
  86. package/test/toolface-mask.test.mjs +258 -0
  87. package/test/toolface-rules.test.mjs +177 -0
  88. package/test/toolface-runtime.test.mjs +466 -0
  89. package/test/toolface-wiring.test.mjs +272 -0
  90. package/test/usage-ledger-inject.test.mjs +50 -0
  91. package/test/usage-ledger.test.mjs +399 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ShawnSun-debug
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTICE.md ADDED
@@ -0,0 +1,23 @@
1
+ # NOTICE
2
+
3
+ 本包(dsh-lean-router)站在三个上游的肩膀上,均按 MIT 或其声明的许可条款再分发。本表是**贡献映射表**:上游 → 贡献到本包的层 → 本包中的承载文件。各上游的 LICENSE 全文保留在其原仓库;以下仅摘录 MIT 声明的版权行(非全文)。
4
+
5
+ ## 三上游致谢表
6
+
7
+ | 上游 | 版本 / 基线 | 贡献到本包的层 | 本包承载位置 | 许可(版权行摘录) |
8
+ |---|---|---|---|---|
9
+ | dsh-flash-presets(LarryE135) | 0.3.2 | lean 四机制(轮次压缩/输出裁剪/关插件/行为纪律)、plan-mode v1、delivery-gate、glob/grep 并发标记、preset 双档形态 | lib/lean/*(compaction/pruner/disabled/persona-text/plan-mode/delivery-gate/tool-concurrency)、presets/base/frag-lean.patch.yml | MIT — Copyright (c) 2026 LarryE135 |
10
+ | dsh-codemode(dsh-codemode contributors) | 0.3.0,main @ f9758ec | toolface 掩蔽接缝(ToolExecutor describe/execute)、code_run 传输与并发池、meta 发现 4 工具、三视图 scope 归因、retention 双清理 | lib/toolface/*(8 模块 file-for-file vendored,适配点以注释标注)、presets/base/frag-toolface.patch.yml | MIT — Copyright (c) 2026 dsh-codemode contributors |
11
+ | dsh-routing-suite(yjh051108) | 0.3.3(@dsh-external/dsh-super-injector) | 思考链路由**思想**(行为带分类、近场引导、反稀释勤勉自检的轻量化)——只移植实测结论,未搬运其旧线代码 | lib/router.js、lib/bands.js(实现重写,头部注明思想来源) | MIT — Copyright (c) 2026 yjh051108 |
12
+
13
+ ## 逐文件 vendored 映射(摘要)
14
+
15
+ - **lib/lean/compaction.js / pruner.js**:flash-presets `flash-lean-ptc-v3.patch.yml` 的口径照抄(lean 档 L121-133;balance 同值)+ 宿主判据镜像(dsh-compaction-basic L15/17/63/124-147;dsh-compaction-tool-result-pruner L8-27/91-124)——纯函数端口,执行归宿主。
16
+ - **lib/lean/persona-text.js**:flash lean 13 条规则与 prefix 原文(flash-lean-ptc-v3.patch.yml L15-60)+ balance 3 条(flash-lean-ptc-v3-balance.patch.yml L13-18);本包增补 3 软门与自检钩;规则 7 删去 PTC-only 句(唯一实质差异)。
17
+ - **lib/lean/plan-mode.js**:flash-lean-ptc-v3.patch.yml L93-107 逐行照抄(vendored)。
18
+ - **lib/lean/delivery-gate.js / tool-concurrency.js**:flash-presets 0.3.2 lib/delivery-gate.js / lib/tool-concurrency.js 逐段移植(0.3.2 版),适配点:动态 import、手写校验、插件名改 `lean-delivery-gate` / `lean-concurrency`、Symbol 键空间改本包。
19
+ - **lib/lean/disabled.js**:flash-lean-ptc-v3.patch.yml L155-202 的 6 行 disabled 清单照抄。
20
+ - **lib/toolface/**(8 模块):upstream dsh-codemode 0.3.0 lib/{index,rules,executor,discovery,scope,pool,retention,transport}.js,file-for-file vendored @ f9758ec;适配:插件名/日志前缀改本包、native executor 依赖动态 import + 安装提示 stub、Symbol 键与 TAG 标注。
21
+ - **lib/router.js / lib/bands.js**:routing-suite 思想移植(非代码);关键实测结论(三带 persona 非连续、V4.1 Flash 阈值型最优解)已在 bands.js L1-7 头注注明。
22
+
23
+ 按 MIT 要求,各上游的版权与许可声明随再分发保留;对本包的修改(适配点)均在文件头部注明,未删除上游署名信息。
package/README.en.md ADDED
@@ -0,0 +1,73 @@
1
+ # dsh-lean-router
2
+
3
+ A DeepSeek Harness (DSH) cordis plugin tuned for DeepSeek V4.1 Flash: **one plugin card** fusing three layers — the lean token-saving four mechanisms (flash-presets measured tuning), `code_run` tool masking (the codemode seam), and thinking-chain routing across three bands (routing-suite ideas).
4
+
5
+ Chinese version: [README.md](./README.md).
6
+
7
+ ## The three layers
8
+
9
+ | Layer | Code | Job |
10
+ |---|---|---|
11
+ | lean | lib/lean/ | turn compaction (thresholdRatio 0.25 / retainTokens 20000), tool-output pruning (8192/4096/1024), six redundant plugins turned off, two behaviour-discipline tiers (lean 13 rules / balance 3 rules), plan-mode v1, plus two add-ons: the delivery gate and glob/grep concurrency markers |
12
+ | toolface | lib/toolface/ | hides every tool the preset does not own from the **model-facing request** (`mcp__` prefix plus everything outside the preset) and keeps `code_run` as the only transport; a program can still discover and call the masked tools |
13
+ | router | lib/router.js · lib/bands.js | spec/react/weak bands + the `[router] band=` directive + near-field guides (zero-write) + a diligence reminder every 10 turns + the `/band` command |
14
+
15
+ > Since 2.0.0 the **skills subsystem is gone entirely**: no bundled mattpocock 31 skills, no per-turn scoring gate, no audit channel and no skills panel UI. See the [changelog](./docs/changelog.en.md).
16
+
17
+ ## Target DSH
18
+
19
+ engines: `>=0.2.1-rc.5 <0.2.4-0` (measured baseline 0.2.3-alpha.2, still compatible back to 0.2.1-rc.5). DSH is in developer preview; breaking changes are handled by the engines gate and the doctor self-check, never by silent degradation.
20
+
21
+ ## Install
22
+
23
+ ~~~powershell
24
+ dsh plugin --profile desktop add npm:dsh-lean-router@2.0.0
25
+ ~~~
26
+
27
+ After restarting DSH, pick **Lean router** (the lean tier) or **Lean router (balance)** (the weaker-constraint tier) for new sessions. For local development install from a `link:` path; see [quickstart](docs/quickstart.en.md).
28
+
29
+ ## Usage
30
+
31
+ 1. Presets: **Lean router** (13 rules + 3 soft gates + routing) or **Lean router (balance)** (3 rules, no routing directives yet).
32
+ 2. Explicit routing directive, written in the first real user message:
33
+
34
+ ~~~text
35
+ [router] band=spec
36
+ [router] band=react task=split the home page into components
37
+ [router] band=auto
38
+ ~~~
39
+
40
+ 3. Commands: `/band` to view or switch the band, `/compact` for manual compaction.
41
+ 4. Masking is automatic: the model's tool list only contains the preset's own tools plus `code_run`; MCP and out-of-preset tools are discovered inside a `code_run` program with `tools.code_tools_search(...)`.
42
+
43
+ ## Docs
44
+
45
+ | Topic | English | 中文 |
46
+ |---|---|---|
47
+ | Architecture | [architecture.en.md](docs/architecture.en.md) | [architecture.md](docs/architecture.md) |
48
+ | Configuration | [configuration.en.md](docs/configuration.en.md) | [configuration.md](docs/configuration.md) |
49
+ | Quickstart | [quickstart.en.md](docs/quickstart.en.md) | [quickstart.md](docs/quickstart.md) |
50
+ | Install | [install.en.md](docs/install.en.md) | [install.md](docs/install.md) |
51
+ | Changelog | [changelog.en.md](docs/changelog.en.md) | [changelog.md](docs/changelog.md) |
52
+ | Release checklist | [release-checklist.en.md](docs/release-checklist.en.md) | [release-checklist.md](docs/release-checklist.md) |
53
+
54
+ Internal engineering notes are Chinese only: [routing](docs/路由-设计说明.md) · [tool-masking wiring](docs/工具遮蔽-接线说明.md) · [disabled-plugin review](docs/复核-关插件清单.md).
55
+
56
+ ## Self-check
57
+
58
+ ~~~powershell
59
+ npm test # node --test "test/*.test.mjs"
60
+ npm run build # rebuild cordis.patch.yml (base + 4 fragments, fixed order)
61
+ npm run doctor # 11 structural checks
62
+ npm run verify # build --check (byte-identical) + doctor
63
+ ~~~
64
+
65
+ ## Current state (stated plainly)
66
+
67
+ - The balance preset carries no routing directives yet.
68
+ - The plan-mode policy paragraph keeps the upstream flash text (including the PTC `run_code` sentence).
69
+ - Tool masking depends on `@deepseek-ai/dsh-tool-executor-native`; when it is missing the executor degrades to an install-hint stub and the first `describe` throws instead of failing silently.
70
+
71
+ ## License and credits
72
+
73
+ MIT, see [LICENSE](LICENSE). The upstream contribution map and license statements are in [NOTICE.md](NOTICE.md): dsh-flash-presets (LarryE135) · dsh-codemode (dsh-codemode contributors) · dsh-routing-suite (yjh051108).
package/README.md CHANGED
@@ -1,3 +1,73 @@
1
- # Temporary Holding Version
1
+ # dsh-lean-router
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 为 DeepSeek V4.1 Flash 调校的 DeepSeek Harness(DSH)cordis 插件:**一张插件卡**里融合三层——lean 省 token 四机制(flash-presets 实测口径)、`code_run` 工具遮蔽(codemode 接缝)、思考链路由三带(routing-suite 思想)。
4
+
5
+ 英文版:[README.en.md](./README.en.md)。
6
+
7
+ ## 三层一览
8
+
9
+ | 层 | 代码 | 职责 |
10
+ |---|---|---|
11
+ | lean | lib/lean/ | 轮次压缩(thresholdRatio 0.25 / retainTokens 20000)、工具输出裁剪(8192/4096/1024)、关 6 个冗余插件、行为纪律双档(lean 13 条 / balance 3 条)、plan-mode v1,外加两个加料件:交付门与 glob/grep 并发标记 |
12
+ | toolface | lib/toolface/ | 把预设不拥有的工具从**模型请求面**隐藏(`mcp__` 前缀 + 预设外全部),`code_run` 作为唯一传输;程序内仍可发现并调用被遮蔽的工具 |
13
+ | router | lib/router.js · lib/bands.js | spec/react/weak 三带 + `[router] band=` 显式指令 + 近场引导(零写入)+ 每 10 轮勤勉自检 + `/band` 命令 |
14
+
15
+ > 2.0.0 起**技能子系统已整体移除**:不再内置 mattpocock 31 技能、不再每轮打分门控、不再有审计通道与技能面板 UI。变更见 [changelog](./changelog.md)。
16
+
17
+ ## 目标 DSH
18
+
19
+ engines:`>=0.2.1-rc.5 <0.2.4-0`(实测基线 0.2.3-alpha.2,兼容回 0.2.1-rc.5)。DSH 处于 developer preview,破坏性变更将以 engines 闸 + doctor 自检应对,不做静默降级。
20
+
21
+ ## 安装
22
+
23
+ ~~~powershell
24
+ dsh plugin --profile desktop add npm:dsh-lean-router@2.0.0
25
+ ~~~
26
+
27
+ 重启 DSH 后,新会话在预设列表选择 **Lean router**(lean 档)或 **Lean router (balance)**(弱约束精简档)。本地开发用 `link:` 路径安装,见 [quickstart](docs/quickstart.md)。
28
+
29
+ ## 用法
30
+
31
+ 1. 预设:**Lean router**(13 条纪律 + 3 软门 + 路由)或 **Lean router (balance)**(3 条纪律,暂不含路由指令)。
32
+ 2. 显式路由指令(写在首条真实用户消息里):
33
+
34
+ ~~~text
35
+ [router] band=spec
36
+ [router] band=react task=把首页拆成组件
37
+ [router] band=auto
38
+ ~~~
39
+
40
+ 3. 命令:`/band` 看切带、`/compact` 手动压缩。
41
+ 4. 工具遮蔽是自动的:模型工具列表只出现预设自有工具 + `code_run`;MCP 与预设外插件工具在 `code_run` 程序内用 `tools.code_tools_search(...)` 发现后调用。
42
+
43
+ ## 文档
44
+
45
+ | 主题 | 中文 | English |
46
+ |---|---|---|
47
+ | 架构 | [architecture.md](docs/architecture.md) | [architecture.en.md](docs/architecture.en.md) |
48
+ | 配置 | [configuration.md](docs/configuration.md) | [configuration.en.md](docs/configuration.en.md) |
49
+ | 快速上手 | [quickstart.md](docs/quickstart.md) | [quickstart.en.md](docs/quickstart.en.md) |
50
+ | 安装 | [install.md](docs/install.md) | [install.en.md](docs/install.en.md) |
51
+ | 变更记录 | [changelog.md](docs/changelog.md) | [changelog.en.md](docs/changelog.en.md) |
52
+ | 发布清单 | [release-checklist.md](docs/release-checklist.md) | [release-checklist.en.md](docs/release-checklist.en.md) |
53
+
54
+ 内部工程说明(中文):[路由-设计说明](docs/路由-设计说明.md) · [工具遮蔽-接线说明](docs/工具遮蔽-接线说明.md) · [复核-关插件清单](docs/复核-关插件清单.md)。
55
+
56
+ ## 自检
57
+
58
+ ~~~powershell
59
+ npm test # node --test "test/*.test.mjs"
60
+ npm run build # 重拼 cordis.patch.yml(base + 4 分片固定顺序)
61
+ npm run doctor # 11 项结构自检
62
+ npm run verify # build --check(cordis.patch.yml 反向逐字节一致)+ doctor
63
+ ~~~
64
+
65
+ ## 现状(如实标注)
66
+
67
+ - balance 预设行暂不含路由指令。
68
+ - plan-mode 政策段保留 flash 原文(含 PTC `run_code` 句)。
69
+ - 工具遮蔽依赖 `@deepseek-ai/dsh-tool-executor-native`;缺失时 executor 退化为安装提示 stub,首次 `describe` 抛错而不静默。
70
+
71
+ ## 许可与致谢
72
+
73
+ MIT,见 [LICENSE](LICENSE)。上游贡献映射与许可声明见 [NOTICE.md](NOTICE.md):dsh-flash-presets(LarryE135)· dsh-codemode(dsh-codemode contributors)· dsh-routing-suite(yjh051108)。