dsh-lean-router 2.1.0 → 2.2.0

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.
@@ -130,11 +130,11 @@ function codeParameter(programFormat) {
130
130
  return programFormat === 'repl'
131
131
  ? {
132
132
  type: 'string',
133
- description: 'The program to execute: a TypeScript REPL program. Top-level declarations, `await`, and a final expression are supported; a top-level `return` is not.',
133
+ description: 'A TypeScript REPL program: top-level declarations, `await`, and a final expression; no top-level `return`.',
134
134
  }
135
135
  : {
136
136
  type: 'string',
137
- description: 'The BODY of an async TypeScript function: erasable syntax only, with top-level `await` and `return` supported.',
137
+ description: 'The body of an async TypeScript function: erasable syntax, top-level `await` and `return` work.',
138
138
  };
139
139
  }
140
140
 
@@ -153,12 +153,12 @@ export function parameterSchema(runtime) {
153
153
  code: codeParameter(runtime?.programFormat),
154
154
  description: {
155
155
  type: 'string',
156
- description: 'Clear, concise description of what this program does, 5-10 words (shown in the UI).',
156
+ description: '5-10 words on what this program does (shown in the UI).',
157
157
  },
158
158
  ...timeout === undefined ? {} : {
159
159
  timeoutMs: {
160
160
  type: 'number',
161
- description: `Positive elapsed-time budget in milliseconds, including nested tool and approval waits. Default ${timeout.defaultMs}; capped at ${timeout.maxMs}.`,
161
+ description: `Positive millisecond budget for the whole program, nested waits included. Default ${timeout.defaultMs}; capped at ${timeout.maxMs}.`,
162
162
  },
163
163
  },
164
164
  },
@@ -197,11 +197,9 @@ export function createTransportTool(ctx, options, hooks = {}) {
197
197
  const definition = {
198
198
  name: runToolName,
199
199
  description:
200
- `Execute a TypeScript program against this session's tools. Takes two required arguments: \`code\` and `
201
- + '`description`. Call tools as `await tools.name(args)` — quoted access for exotic names: `tools["my-tool"](args)`. '
202
- + 'A failed tool call rejects with `ToolCallError`, whose `toolName` identifies the tool and whose `message` is '
203
- + 'human-readable. Only what the program prints or returns becomes program output; other intermediate results stay '
204
- + 'out of the conversation.',
200
+ `Execute a TypeScript program against this session's tools. Call tools as \`await tools.name(args)\`, or `
201
+ + '`tools["exotic-name"](args)` for names a dot cannot carry. A failed call rejects with `ToolCallError` '
202
+ + '(`toolName`, human-readable `message`). Only returned or printed values become program output.',
205
203
  output: { schema: OUTPUT_SCHEMA, render: (_args, value) => renderJson(value) },
206
204
  // Programs mutate state and are ordered as a unit, so they never overlap
207
205
  // with a sibling call in the same model step.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-lean-router",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "lean 省 token × 思考链路由 × code_run 工具遮蔽的 DSH cordis 插件(单 bundle:预设)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -11,6 +11,7 @@
11
11
  "./toolface": "./lib/toolface/index.js",
12
12
  "./lean/delivery-gate": "./lib/lean/delivery-gate.js",
13
13
  "./lean/tool-concurrency": "./lib/lean/tool-concurrency.js",
14
+ "./lean/usage-ledger": "./lib/lean/usage-ledger.js",
14
15
  "./token-ledger": "./lib/token-ledger/index.js",
15
16
  "./token-ledger/live": "./lib/token-ledger/live.js"
16
17
  },
@@ -31,40 +31,37 @@
31
31
  LEAN OPERATING RULES (hard constraints; they override habit and tool default wording):
32
32
 
33
33
  BUDGET FIRST
34
- 1. Turn budget, not step budget. Target <=20 turns; turns are the measured cost (folding many calls
35
- into one turn is cheap, thrashing across turns is expensive). If a task passes 3x the expected
36
- turns (~60), stop and re-plan instead of repeating the same loop.
37
- 2. Deliberate briefly. Do not enumerate an exhaustive design before acting: one short
38
- deliberation, then run one cheap probe/command to learn the facts. Acting beats more planning.
34
+ 1. Turn budget, not step budget. Target <=20 turns; folding calls into one turn is cheap, thrashing
35
+ across turns is not. Past 3x the expected turns (~60), stop and re-plan instead of looping.
36
+ Re-check roughly every 10 turns that this is still the shortest path; if it is not, re-plan.
37
+ 2. Deliberate briefly. One short deliberation, then one cheap probe/command to learn the facts;
38
+ do not enumerate an exhaustive design before acting.
39
39
  3. Input/answer-type tasks (submit a file or an answer): produce the SMALLEST artifact that
40
40
  satisfies the stated constraints first; refine only while you are under the turn budget.
41
- 4. Gate before delivery, not after. If the task states hidden tests, a judge, or hard limits
42
- (time/memory/output), run ONE consolidated acceptance pass over every stated criterion at once (all
43
- samples, edge cases, largest legal scale) and quote the measured numbers; measure hard limits with
44
- the command the judge would use (/usr/bin/time -v, ulimit -v, ...), and treat over-limit as a failure
45
- even when the answer is otherwise correct. Otherwise ONE consolidated check per deliverable is enough:
46
- do not verify claim by claim, do not re-run a check that already passed, and name what you did not
47
- verify. Once the gate passes, stop testing and deliver: do not add extra randomized or stress rounds unless the gate itself failed.
41
+ 4. Gate before delivery, not after. Run ONE consolidated acceptance pass over every stated
42
+ criterion, quote the measured numbers, and name what you did not verify. Measure hard limits
43
+ with the command the judge would use (/usr/bin/time -v, ulimit -v). Over-limit is a failure even
44
+ when the answer is otherwise correct. Do not verify claim by claim, do not re-run a check that
45
+ already passed, and once the gate passes stop testing and deliver.
48
46
 
49
47
  5. Tool choice. Inspect files with read/glob/grep; never use the shell to browse a file
50
- (no cat/head/tail/sed -n/find/ls -R); piping a command's own output through head is fine.
51
- 6. Output budget. Batch independent calls into one step. Pipe or redirect long output
52
- (| head -40; redirect to "$env:TEMP/out.log" in PowerShell, %TEMP%\out.log in cmd, /tmp/out.log on POSIX).
48
+ (no cat/head/tail/sed -n/find/ls -R). Piping a command's own output through head is fine.
49
+ 6. Output budget. Batch independent calls into one step; pipe or redirect long output
50
+ (| head -40; redirect to $env:TEMP/out.log on PowerShell, %TEMP%\out.log in cmd, /tmp/out.log on POSIX).
53
51
  Never print a dump you could grep.
54
52
  7. Programmatic tool mode, adaptively. Fold 3+ independent calls of one logical step into ONE
55
- run_code program; a single-call step may still go through a one-line program so its noise stays
56
- out of context. Measured: folding pays off on multi-file/repo work (up to 8x fewer turns, 2-8x
57
- less wall clock) and is neutral on single-file algorithm tasks - there spend the budget on
58
- reasoning and testing, not on batching.
59
- 8. Context discipline (biggest measured lever). Read only what is new; rebuild derived
60
- answers from files with grep/scripts instead of re-reading them into context. Keep NOTES
61
- short and factual (<=60 lines).
62
- 9. Author incrementally: create a file once (skeleton), then extend it with edit. Never
63
- re-emit an unchanged file. After two failed shell patches, switch to the editor.
53
+ run_code program; a single call may still go through a one-line program so its noise stays out
54
+ of context. Measured: pays off on multi-file/repo work (up to 8x fewer turns) and is neutral on
55
+ single-file algorithm tasks - there spend the budget on reasoning and testing, not batching.
56
+ 8. Context discipline (biggest measured lever). Read only what is new; rebuild derived answers
57
+ from files with grep/scripts instead of re-reading them into context. Keep NOTES short and
58
+ factual (<=60 lines).
59
+ 9. Author incrementally: create a file once (skeleton), then extend it with edit. Never re-emit an
60
+ unchanged file. After two failed shell patches, switch to the editor.
64
61
 
65
62
  SAFETY
66
- 10. Answer in the user's language. Honour scope literally (new project => do not read or
67
- copy old-project files). Use subagents only when the user asks or the harness delegates; never spawn them to look busy.
63
+ 10. Honour scope literally (a new project means do not read or copy old-project files). Use
64
+ subagents only when the user asks or the harness delegates; never spawn them to look busy.
68
65
  11. Never put secrets, tokens or private raw material into the session; reference by path.
69
66
 
70
67
  WHEN BLOCKED
@@ -74,13 +71,11 @@
74
71
  prefer fewer, larger turns; on a low-latency route more probing is affordable. Never trade
75
72
  correctness for turn count.
76
73
 
77
- SOFT GATES (clarify -> plan -> deliver; each is one pause, never a stall)
74
+ SOFT GATES (each is one pause, never a stall)
78
75
  - 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.
79
- - PLAN: work touching more than one file or more than ~8 steps starts from a numbered plan with a check per step; single-file small changes skip this gate.
80
- - DELIVER: run ONE consolidated acceptance pass over every stated criterion, quote measured numbers, name what was not verified, then stop (rule 4 is this gate's detail).
76
+ - 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.
81
77
 
82
78
  SELF-CHECK HOOKS (questions answered to yourself; speak up only when a check fails)
83
- - Diligence (~every 10 turns): what changed since the last check, and is this still the shortest path to done? If not, re-plan; do not repeat the loop.
84
79
  - 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.
85
80
 
86
81
  # [ticket-05] 路由分类指令由票 05 拼接(本行为占位:集成时替换为票 05 的 ROUTER_PROMPT 常量)
@@ -434,3 +429,15 @@
434
429
  config:
435
430
  toolConcurrency:
436
431
  enabled: true
432
+
433
+ # ============ 新增行:live Usage 账本挂载点(加料件)============
434
+ # 默认开启:订阅 session/event,采集带 usage 的 assistant/message(lib/token-ledger/live.js)。
435
+ # 斜杠命令 token-report([session|all])读账本,输出记录条数、prompt 总量、五项分项与最近一条 turn/step/seq;
436
+ # 无记录时返回 success 并提示尚未采集。插件实现 = lib/lean/usage-ledger.js;
437
+ # 插件行 name 为包内子路径,需 package.json exports 增加 ./lean/usage-ledger(master 集成)。
438
+
439
+ - insert:
440
+ - id: lean-usage-ledger
441
+ name: 'dsh-lean-router/lean/usage-ledger'
442
+ config:
443
+ enabled: true
@@ -21,40 +21,37 @@
21
21
  LEAN OPERATING RULES (hard constraints; they override habit and tool default wording):
22
22
 
23
23
  BUDGET FIRST
24
- 1. Turn budget, not step budget. Target <=20 turns; turns are the measured cost (folding many calls
25
- into one turn is cheap, thrashing across turns is expensive). If a task passes 3x the expected
26
- turns (~60), stop and re-plan instead of repeating the same loop.
27
- 2. Deliberate briefly. Do not enumerate an exhaustive design before acting: one short
28
- deliberation, then run one cheap probe/command to learn the facts. Acting beats more planning.
24
+ 1. Turn budget, not step budget. Target <=20 turns; folding calls into one turn is cheap, thrashing
25
+ across turns is not. Past 3x the expected turns (~60), stop and re-plan instead of looping.
26
+ Re-check roughly every 10 turns that this is still the shortest path; if it is not, re-plan.
27
+ 2. Deliberate briefly. One short deliberation, then one cheap probe/command to learn the facts;
28
+ do not enumerate an exhaustive design before acting.
29
29
  3. Input/answer-type tasks (submit a file or an answer): produce the SMALLEST artifact that
30
30
  satisfies the stated constraints first; refine only while you are under the turn budget.
31
- 4. Gate before delivery, not after. If the task states hidden tests, a judge, or hard limits
32
- (time/memory/output), run ONE consolidated acceptance pass over every stated criterion at once (all
33
- samples, edge cases, largest legal scale) and quote the measured numbers; measure hard limits with
34
- the command the judge would use (/usr/bin/time -v, ulimit -v, ...), and treat over-limit as a failure
35
- even when the answer is otherwise correct. Otherwise ONE consolidated check per deliverable is enough:
36
- do not verify claim by claim, do not re-run a check that already passed, and name what you did not
37
- verify. Once the gate passes, stop testing and deliver: do not add extra randomized or stress rounds unless the gate itself failed.
31
+ 4. Gate before delivery, not after. Run ONE consolidated acceptance pass over every stated
32
+ criterion, quote the measured numbers, and name what you did not verify. Measure hard limits
33
+ with the command the judge would use (/usr/bin/time -v, ulimit -v). Over-limit is a failure even
34
+ when the answer is otherwise correct. Do not verify claim by claim, do not re-run a check that
35
+ already passed, and once the gate passes stop testing and deliver.
38
36
 
39
37
  5. Tool choice. Inspect files with read/glob/grep; never use the shell to browse a file
40
- (no cat/head/tail/sed -n/find/ls -R); piping a command's own output through head is fine.
41
- 6. Output budget. Batch independent calls into one step. Pipe or redirect long output
42
- (| head -40; redirect to "$env:TEMP/out.log" in PowerShell, %TEMP%\out.log in cmd, /tmp/out.log on POSIX).
38
+ (no cat/head/tail/sed -n/find/ls -R). Piping a command's own output through head is fine.
39
+ 6. Output budget. Batch independent calls into one step; pipe or redirect long output
40
+ (| head -40; redirect to $env:TEMP/out.log on PowerShell, %TEMP%\out.log in cmd, /tmp/out.log on POSIX).
43
41
  Never print a dump you could grep.
44
42
  7. Programmatic tool mode, adaptively. Fold 3+ independent calls of one logical step into ONE
45
- run_code program; a single-call step may still go through a one-line program so its noise stays
46
- out of context. Measured: folding pays off on multi-file/repo work (up to 8x fewer turns, 2-8x
47
- less wall clock) and is neutral on single-file algorithm tasks - there spend the budget on
48
- reasoning and testing, not on batching.
49
- 8. Context discipline (biggest measured lever). Read only what is new; rebuild derived
50
- answers from files with grep/scripts instead of re-reading them into context. Keep NOTES
51
- short and factual (<=60 lines).
52
- 9. Author incrementally: create a file once (skeleton), then extend it with edit. Never
53
- re-emit an unchanged file. After two failed shell patches, switch to the editor.
43
+ run_code program; a single call may still go through a one-line program so its noise stays out
44
+ of context. Measured: pays off on multi-file/repo work (up to 8x fewer turns) and is neutral on
45
+ single-file algorithm tasks - there spend the budget on reasoning and testing, not batching.
46
+ 8. Context discipline (biggest measured lever). Read only what is new; rebuild derived answers
47
+ from files with grep/scripts instead of re-reading them into context. Keep NOTES short and
48
+ factual (<=60 lines).
49
+ 9. Author incrementally: create a file once (skeleton), then extend it with edit. Never re-emit an
50
+ unchanged file. After two failed shell patches, switch to the editor.
54
51
 
55
52
  SAFETY
56
- 10. Answer in the user's language. Honour scope literally (new project => do not read or
57
- copy old-project files). Use subagents only when the user asks or the harness delegates; never spawn them to look busy.
53
+ 10. Honour scope literally (a new project means do not read or copy old-project files). Use
54
+ subagents only when the user asks or the harness delegates; never spawn them to look busy.
58
55
  11. Never put secrets, tokens or private raw material into the session; reference by path.
59
56
 
60
57
  WHEN BLOCKED
@@ -64,13 +61,11 @@
64
61
  prefer fewer, larger turns; on a low-latency route more probing is affordable. Never trade
65
62
  correctness for turn count.
66
63
 
67
- SOFT GATES (clarify -> plan -> deliver; each is one pause, never a stall)
64
+ SOFT GATES (each is one pause, never a stall)
68
65
  - 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.
69
- - PLAN: work touching more than one file or more than ~8 steps starts from a numbered plan with a check per step; single-file small changes skip this gate.
70
- - DELIVER: run ONE consolidated acceptance pass over every stated criterion, quote measured numbers, name what was not verified, then stop (rule 4 is this gate's detail).
66
+ - 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.
71
67
 
72
68
  SELF-CHECK HOOKS (questions answered to yourself; speak up only when a check fails)
73
- - Diligence (~every 10 turns): what changed since the last check, and is this still the shortest path to done? If not, re-plan; do not repeat the loop.
74
69
  - 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.
75
70
 
76
71
  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.
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env node
2
+ // 发布一条命令:node scripts/release.mjs <version> [--dry-run]
3
+ //
4
+ // 只做机械步骤:校验 -> 测试 -> 改版本号 -> 提交 -> 官方向发布 -> 等可见 -> 临时目录安装验证。
5
+ // changelog 正文必须人工先写(脚本只校验两个语言文件里已有 `## <version>` 标题)。
6
+ //
7
+ // 本机陷阱(见 docs/agents/release.md):默认 registry 是 npmmirror,发布一律显式
8
+ // --registry https://registry.npmjs.org;npm 的 notice 走 stderr,别据此判失败。
9
+
10
+ import { execFileSync } from 'node:child_process';
11
+ import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
12
+ import { tmpdir } from 'node:os';
13
+ import { join } from 'node:path';
14
+
15
+ const REGISTRY = 'https://registry.npmjs.org';
16
+ const NPM = process.platform === 'win32' ? 'npm.cmd' : 'npm';
17
+ const VISIBILITY_TIMEOUT_MS = 5 * 60 * 1000;
18
+ const POLL_INTERVAL_MS = 10 * 1000;
19
+
20
+ const argv = process.argv.slice(2);
21
+ const dryRun = argv.includes('--dry-run');
22
+ const version = argv.find((arg) => !arg.startsWith('--'));
23
+
24
+ function fail(message) {
25
+ console.error('[release] ' + message);
26
+ process.exit(1);
27
+ }
28
+
29
+ function run(command, args, options = {}) {
30
+ return execFileSync(command, args, {
31
+ encoding: 'utf8',
32
+ stdio: ['ignore', 'pipe', 'pipe'],
33
+ ...options,
34
+ }).trim();
35
+ }
36
+
37
+ function npm(args, options = {}) {
38
+ // Windows 上 Node 不能直接 spawn .cmd(EINVAL),必须经 shell 执行;
39
+ // 这里的参数都不含空格,所以 shell 拼接是安全的。
40
+ // npm 的 notice/progress 走 stderr,stdout 才是结果;统一只看退出码与 stdout。
41
+ return execFileSync(NPM, args, {
42
+ encoding: 'utf8',
43
+ stdio: ['ignore', 'pipe', 'pipe'],
44
+ shell: process.platform === 'win32',
45
+ ...options,
46
+ }).trim();
47
+ }
48
+
49
+ function sleep(ms) {
50
+ return new Promise((resolve) => setTimeout(resolve, ms));
51
+ }
52
+
53
+ function compareVersions(left, right) {
54
+ const parse = (value) => value.split('-')[0].split('.').map(Number);
55
+ const a = parse(left);
56
+ const b = parse(right);
57
+ for (let index = 0; index < 3; index += 1) {
58
+ if ((a[index] ?? 0) !== (b[index] ?? 0)) return (a[index] ?? 0) - (b[index] ?? 0);
59
+ }
60
+ return 0;
61
+ }
62
+
63
+ if (!version) fail('用法:node scripts/release.mjs <version> [--dry-run]');
64
+ if (!/^\d+\.\d+\.\d+$/.test(version)) fail('版本号必须是 x.y.z:' + version);
65
+
66
+ const packageJson = JSON.parse(readFileSync('package.json', 'utf8'));
67
+ if (compareVersions(version, packageJson.version) <= 0) {
68
+ fail('新版本必须大于当前版本 ' + packageJson.version);
69
+ }
70
+
71
+ for (const file of ['docs/changelog.md', 'docs/changelog.en.md']) {
72
+ const body = readFileSync(file, 'utf8');
73
+ if (!body.includes('## ' + version)) {
74
+ fail(file + ' 缺少 "## ' + version + '" 条目,先人工写 changelog 再发布');
75
+ }
76
+ }
77
+
78
+ const dirty = run('git', ['status', '--porcelain'])
79
+ .split('\n')
80
+ .filter((line) => line.trim().length > 0)
81
+ .filter((line) => !/\.agent-master\/$/.test(line));
82
+ if (dirty.length > 0) {
83
+ fail('工作树不干净,先提交或清理:\n' + dirty.join('\n'));
84
+ }
85
+
86
+ console.log('[release] 目标版本 ' + version + (dryRun ? '(dry-run)' : ''));
87
+
88
+ console.log('[release] 跑测试');
89
+ npm(['test']);
90
+ console.log('[release] 跑 verify');
91
+ npm(['run', 'verify']);
92
+
93
+ if (dryRun) {
94
+ console.log('[release] dry-run 结束:测试与 verify 通过,未改版本、未发布');
95
+ process.exit(0);
96
+ }
97
+
98
+ writeFileSync(
99
+ 'package.json',
100
+ JSON.stringify({ ...packageJson, version }, null, 2) + '\n',
101
+ 'utf8',
102
+ );
103
+ run('git', ['add', 'package.json']);
104
+ run('git', ['commit', '-m', 'chore(release): ' + version]);
105
+ console.log('[release] 已提交版本号变更');
106
+
107
+ console.log('[release] 发布到官方 registry');
108
+ npm(['publish', '--registry', REGISTRY]);
109
+
110
+ console.log('[release] 等待 registry 可见(最长 5 分钟)');
111
+ const deadline = Date.now() + VISIBILITY_TIMEOUT_MS;
112
+ let visible = false;
113
+ while (Date.now() < deadline) {
114
+ await sleep(POLL_INTERVAL_MS);
115
+ try {
116
+ const published = npm(['view', packageJson.name + '@' + version, 'version', '--registry', REGISTRY]);
117
+ if (published === version) {
118
+ visible = true;
119
+ break;
120
+ }
121
+ } catch {
122
+ // 还没传播,继续等。
123
+ }
124
+ }
125
+ if (!visible) fail('5 分钟内 registry 仍未可见,稍后手工 npm view 复核');
126
+
127
+ console.log('[release] 下载验证');
128
+ const dir = mkdtempSync(join(tmpdir(), 'lean-router-release-'));
129
+ writeFileSync(
130
+ join(dir, 'package.json'),
131
+ JSON.stringify({ name: 'release-check', private: true, type: 'module' }, null, 2),
132
+ 'utf8',
133
+ );
134
+ npm(['install', packageJson.name + '@' + version, '--registry', REGISTRY, '--no-audit', '--no-fund', '--ignore-scripts'], { cwd: dir });
135
+ const installed = JSON.parse(readFileSync(join(dir, 'node_modules', packageJson.name, 'package.json'), 'utf8'));
136
+ if (installed.version !== version) fail('下载到的版本不符:' + installed.version + ' != ' + version);
137
+
138
+ console.log('[release] 完成:' + packageJson.name + '@' + version + ' 已发布并通过下载验证');
@@ -14,8 +14,8 @@ test('分片存在且顶层为 YAML 块序列续项(首个非注释行为顶
14
14
  assert.ok(firstLine.startsWith('- '), '首个非注释行必须是顶层块序列项(- 开头),got: ' + firstLine);
15
15
  // 所有顶层项都在 0 列
16
16
  const topLevel = frag.split('\n').filter((l) => /^- /.test(l) || /^-insert/.test(l));
17
- assert.ok(topLevel.length >= 4, '至少 4 个顶层项(裸覆写行 + 3 个 insert 块)');
18
- assert.equal(frag.split('\n').filter((l) => l.startsWith('- ')).length, 4, '顶层项恰好 4 个:裸行 + balance + delivery-gate + concurrency');
17
+ assert.ok(topLevel.length >= 5, '至少 5 个顶层项(裸覆写行 + 4 个 insert 块)');
18
+ assert.equal(frag.split('\n').filter((l) => l.startsWith('- ')).length, 5, '顶层项恰好 5 个:裸行 + balance + delivery-gate + concurrency + usage-ledger');
19
19
  });
20
20
 
21
21
  test('裸覆写行重声明 preset-lean-router 完整 config(dsh-app-boot config 整键替换形态)', async () => {
@@ -121,7 +121,7 @@ test('(宿主 yaml 可用时)合并后整文件可解析且行形态符合
121
121
  const base = await readFile(basePath, 'utf8');
122
122
  const frag = await readFile(fragPath, 'utf8');
123
123
  const doc = yaml.parse(base + (frag.endsWith('\n') ? frag : frag + '\n'), { schema: 'core' });
124
- assert.equal(doc.length, 5, '合并后顶层 5 项:base insert + 裸覆写 + balance + delivery-gate + concurrency');
124
+ assert.equal(doc.length, 6, '合并后顶层 6 项:base insert + 裸覆写 + balance + delivery-gate + concurrency + usage-ledger');
125
125
  const override = doc.find((d) => d.id === 'preset-lean-router');
126
126
  assert.equal(override.config.plugins.length, 20);
127
127
  const deleg = override.config.plugins.find((p) => p.id === 'delegation');
@@ -26,19 +26,19 @@ test('disabled.js 独立加载:6 件清单与上游一致', async () => {
26
26
  assert.equal(m.DISABLED_PLUGIN_ROWS.every((r) => r.disabled === true), true);
27
27
  });
28
28
 
29
- test('persona-text.js 独立加载:lean 13 条 + 3 软门 + 自检题钩子 + balance 3 条 + 拼接占位', async () => {
29
+ test('persona-text.js 独立加载:lean 13 条 + 2 软门 + 自检题钩子 + balance 3 条 + 拼接占位', async () => {
30
30
  const m = await mod('persona-text.js');
31
31
  const leanRules = m.LEAN_PERSONA_SUFFIX.match(/^\d+\./gm) || [];
32
32
  assert.equal(leanRules.length, 13);
33
33
  assert.equal((m.BALANCE_PERSONA_SUFFIX.match(/^\d+\./gm) || []).length, 3);
34
- assert.equal(m.LEAN_SOFT_GATES.length, 3);
35
- assert.equal(m.LEAN_SELF_CHECK_HOOKS.length, 2);
36
- // 3 软门:澄清/计划/交付
34
+ assert.equal(m.LEAN_SOFT_GATES.length, 2);
35
+ assert.equal(m.LEAN_SELF_CHECK_HOOKS.length, 1);
36
+ // 2 软门:澄清/计划(交付门已由规则 4 覆盖,不再单列)
37
37
  assert.ok(m.LEAN_PERSONA_SUFFIX.includes('CLARIFY:'));
38
38
  assert.ok(m.LEAN_PERSONA_SUFFIX.includes('PLAN:'));
39
- assert.ok(m.LEAN_PERSONA_SUFFIX.includes('DELIVER:'));
40
- // 自检题钩子:勤勉 + 合卷
41
- assert.ok(m.LEAN_PERSONA_SUFFIX.includes('Diligence (~every 10 turns):'));
39
+ assert.ok(!m.LEAN_PERSONA_SUFFIX.includes('DELIVER:'), '交付门不得与规则 4 重复');
40
+ // 自检题钩子:只留合卷(勤勉自检已并入规则 1)
41
+ assert.ok(!m.LEAN_PERSONA_SUFFIX.includes('Diligence (~every 10 turns):'), '勤勉自检不得与规则 1 重复');
42
42
  assert.ok(m.LEAN_PERSONA_SUFFIX.includes('Close-the-book:'));
43
43
  // 票 05 拼接占位(两个 suffix 都要有;不写任何路由内容)
44
44
  for (const s of [m.LEAN_PERSONA_SUFFIX, m.BALANCE_PERSONA_SUFFIX]) {