dsh-lean-router 1.1.0 → 2.1.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.
Files changed (155) hide show
  1. package/NOTICE.md +2 -4
  2. package/README.en.md +47 -43
  3. package/README.md +45 -41
  4. package/cordis.patch.yml +4 -26
  5. package/docs/adr/0001-token-ledger-durable-usage.md +11 -0
  6. package/docs/agents/domain.md +1 -1
  7. package/docs/architecture.en.md +51 -86
  8. package/docs/architecture.md +46 -77
  9. package/docs/changelog.en.md +41 -1
  10. package/docs/changelog.md +41 -1
  11. package/docs/configuration.en.md +25 -56
  12. package/docs/configuration.md +14 -45
  13. package/docs/install.en.md +2 -2
  14. package/docs/install.md +2 -2
  15. package/docs/quickstart.en.md +29 -34
  16. package/docs/quickstart.md +11 -16
  17. package/docs/release-checklist.en.md +3 -4
  18. package/docs/release-checklist.md +5 -6
  19. package/docs//350/267/257/347/224/261-/350/256/276/350/256/241/350/257/264/346/230/216.md +2 -2
  20. package/lib/bands.js +4 -2
  21. package/lib/index.js +9 -61
  22. package/lib/router.js +15 -148
  23. package/lib/token-ledger/index.js +147 -0
  24. package/lib/token-ledger/live.js +184 -0
  25. package/package.json +5 -14
  26. package/presets/base/frag-lean.patch.yml +1 -5
  27. package/presets/base/frag-preset.patch.yml +1 -3
  28. package/presets/base/frag-router.patch.yml +1 -12
  29. package/presets/base/frag-toolface.patch.yml +0 -2
  30. package/presets/base/lean-router.patch.yml +1 -4
  31. package/scripts/doctor.mjs +15 -10
  32. package/test/integration-preset.test.mjs +4 -3
  33. package/test/plugin-entry.test.mjs +15 -50
  34. package/test/router-bands.test.mjs +26 -0
  35. package/test/router.test.mjs +7 -47
  36. package/test/token-ledger-live.test.mjs +351 -0
  37. package/test/token-ledger.test.mjs +264 -0
  38. package/assets/gating.weights.json +0 -13
  39. package/assets/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  40. package/assets/skills/ask-matt/SKILL.md +0 -80
  41. package/assets/skills/ask-matt/agents/openai.yaml +0 -5
  42. package/assets/skills/chief-of-staff/SKILL.md +0 -76
  43. package/assets/skills/chief-of-staff/agents/openai.yaml +0 -5
  44. package/assets/skills/code-review/SKILL.md +0 -91
  45. package/assets/skills/code-review/agents/openai.yaml +0 -5
  46. package/assets/skills/codebase-design/DEEPENING.md +0 -37
  47. package/assets/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  48. package/assets/skills/codebase-design/SKILL.md +0 -116
  49. package/assets/skills/codebase-design/agents/openai.yaml +0 -5
  50. package/assets/skills/diagnosing-bugs/SKILL.md +0 -140
  51. package/assets/skills/diagnosing-bugs/agents/openai.yaml +0 -5
  52. package/assets/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  53. package/assets/skills/domain-modeling/ADR-FORMAT.md +0 -47
  54. package/assets/skills/domain-modeling/GLOSSARY-FORMAT.md +0 -60
  55. package/assets/skills/domain-modeling/SKILL.md +0 -76
  56. package/assets/skills/domain-modeling/agents/openai.yaml +0 -5
  57. package/assets/skills/grilling/SKILL.md +0 -52
  58. package/assets/skills/grilling/agents/openai.yaml +0 -5
  59. package/assets/skills/handoff/SKILL.md +0 -17
  60. package/assets/skills/handoff/agents/openai.yaml +0 -5
  61. package/assets/skills/implement/SKILL.md +0 -55
  62. package/assets/skills/implement/agents/openai.yaml +0 -5
  63. package/assets/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  64. package/assets/skills/improve-codebase-architecture/SKILL.md +0 -72
  65. package/assets/skills/improve-codebase-architecture/agents/openai.yaml +0 -5
  66. package/assets/skills/loop-me/SKILL.md +0 -33
  67. package/assets/skills/loop-me/agents/openai.yaml +0 -5
  68. package/assets/skills/pr/CREDITS.md +0 -3
  69. package/assets/skills/pr/SKILL.md +0 -172
  70. package/assets/skills/pr/agents/openai.yaml +0 -5
  71. package/assets/skills/prototype/LOGIC.md +0 -67
  72. package/assets/skills/prototype/SKILL.md +0 -28
  73. package/assets/skills/prototype/UI.md +0 -112
  74. package/assets/skills/prototype/agents/openai.yaml +0 -5
  75. package/assets/skills/research/SKILL.md +0 -14
  76. package/assets/skills/research/agents/openai.yaml +0 -5
  77. package/assets/skills/retro/SKILL.md +0 -45
  78. package/assets/skills/retro/agents/openai.yaml +0 -5
  79. package/assets/skills/setup-matt-pocock-skills/SKILL.md +0 -121
  80. package/assets/skills/setup-matt-pocock-skills/agents/openai.yaml +0 -5
  81. package/assets/skills/setup-matt-pocock-skills/domain.md +0 -51
  82. package/assets/skills/setup-matt-pocock-skills/issue-tracker-github.md +0 -50
  83. package/assets/skills/setup-matt-pocock-skills/issue-tracker-gitlab.md +0 -46
  84. package/assets/skills/setup-matt-pocock-skills/issue-tracker-local.md +0 -30
  85. package/assets/skills/setup-matt-pocock-skills/triage-labels.md +0 -15
  86. package/assets/skills/setup-ts-deep-modules/SKILL.md +0 -103
  87. package/assets/skills/setup-ts-deep-modules/agents/openai.yaml +0 -5
  88. package/assets/skills/setup-ts-deep-modules/dependency-cruiser.config.cjs +0 -95
  89. package/assets/skills/software-factory/EXAMPLE-TASKS.md +0 -80
  90. package/assets/skills/software-factory/GIT-HOSTS.md +0 -84
  91. package/assets/skills/software-factory/OBSERVABILITY-PLATFORMS.md +0 -75
  92. package/assets/skills/software-factory/RUNNERS.md +0 -94
  93. package/assets/skills/software-factory/SKILL.md +0 -99
  94. package/assets/skills/software-factory/TICKET-TRACKERS.md +0 -85
  95. package/assets/skills/tdd/SKILL.md +0 -40
  96. package/assets/skills/tdd/agents/openai.yaml +0 -5
  97. package/assets/skills/tdd/mocking.md +0 -59
  98. package/assets/skills/tdd/tests.md +0 -77
  99. package/assets/skills/teach/GLOSSARY-FORMAT.md +0 -35
  100. package/assets/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  101. package/assets/skills/teach/MISSION-FORMAT.md +0 -31
  102. package/assets/skills/teach/RESOURCES-FORMAT.md +0 -32
  103. package/assets/skills/teach/SKILL.md +0 -141
  104. package/assets/skills/teach/agents/openai.yaml +0 -5
  105. package/assets/skills/to-questionnaire/SKILL.md +0 -55
  106. package/assets/skills/to-questionnaire/agents/openai.yaml +0 -5
  107. package/assets/skills/to-spec/SKILL.md +0 -76
  108. package/assets/skills/to-spec/agents/openai.yaml +0 -5
  109. package/assets/skills/to-tickets/SKILL.md +0 -106
  110. package/assets/skills/to-tickets/agents/openai.yaml +0 -5
  111. package/assets/skills/triage/AGENT-BRIEF.md +0 -207
  112. package/assets/skills/triage/OUT-OF-SCOPE.md +0 -105
  113. package/assets/skills/triage/SKILL.md +0 -113
  114. package/assets/skills/triage/agents/openai.yaml +0 -5
  115. package/assets/skills/wait-what/SKILL.md +0 -8
  116. package/assets/skills/wait-what/agents/openai.yaml +0 -5
  117. package/assets/skills/wayfinder/SKILL.md +0 -129
  118. package/assets/skills/wayfinder/agents/openai.yaml +0 -5
  119. package/assets/skills/wizard/SKILL.md +0 -46
  120. package/assets/skills/wizard/agents/openai.yaml +0 -5
  121. package/assets/skills/wizard/template.sh +0 -223
  122. package/assets/skills/writing-beats/SKILL.md +0 -44
  123. package/assets/skills/writing-beats/agents/openai.yaml +0 -5
  124. package/assets/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  125. package/assets/skills/writing-for-agents/SKILL.md +0 -83
  126. package/assets/skills/writing-for-agents/agents/openai.yaml +0 -5
  127. package/assets/skills/writing-fragments/SKILL.md +0 -80
  128. package/assets/skills/writing-fragments/agents/openai.yaml +0 -5
  129. package/assets/skills/writing-shape/SKILL.md +0 -59
  130. package/assets/skills/writing-shape/agents/openai.yaml +0 -5
  131. package/assets/skills.matrix.json +0 -311
  132. package/docs/HANDOFF-2026-11-22.md +0 -155
  133. package/docs/matrix.en.md +0 -57
  134. package/docs/matrix.md +0 -57
  135. package/docs//346/212/200/350/203/275/351/227/250/346/216/247-/350/256/276/350/256/241/350/257/264/346/230/216.md +0 -134
  136. package/docs//351/235/242/346/235/277-/350/256/276/350/256/241/350/257/264/346/230/216.md +0 -205
  137. package/lib/audit-commands.js +0 -289
  138. package/lib/audit-sink.js +0 -137
  139. package/lib/client.js +0 -203
  140. package/lib/gate-runner.js +0 -179
  141. package/lib/skill-provider.js +0 -167
  142. package/lib/skillgate.js +0 -396
  143. package/lib/skills-panel.js +0 -322
  144. package/scripts/check-drift.mjs +0 -24
  145. package/skills.manifest.json +0 -287
  146. package/test/audit-commands.test.mjs +0 -325
  147. package/test/audit-sink.test.mjs +0 -150
  148. package/test/client-plugin.test.mjs +0 -117
  149. package/test/gate-run.test.mjs +0 -173
  150. package/test/manifest.test.mjs +0 -25
  151. package/test/provider.test.mjs +0 -21
  152. package/test/skillgate-provider.test.mjs +0 -122
  153. package/test/skillgate.test.mjs +0 -217
  154. package/test/skills-panel.test.mjs +0 -114
  155. package/ui/go.json +0 -19
@@ -0,0 +1,147 @@
1
+ function definedFields(source, keys) {
2
+ const result = {};
3
+ for (const key of keys) {
4
+ if (source[key] !== undefined) result[key] = source[key];
5
+ }
6
+ return result;
7
+ }
8
+
9
+ export function captureRequestSnapshot(input) {
10
+ for (const field of ['prompt', 'body', 'toolOutput']) {
11
+ if (Object.hasOwn(input, field)) {
12
+ throw new Error('RequestSnapshot: raw field "' + field + '" is not allowed');
13
+ }
14
+ }
15
+ const snapshot = definedFields(input, ['sessionId', 'turn', 'step', 'seq', 'headerHash']);
16
+ if (input.tools !== undefined) {
17
+ snapshot.tools = input.tools.map((tool) => definedFields(tool, ['name', 'schemaHash']));
18
+ }
19
+ if (input.partitionChars !== undefined) {
20
+ snapshot.partitionChars = { ...input.partitionChars };
21
+ }
22
+ if (input.taskResult !== undefined) {
23
+ snapshot.taskResult = definedFields(input.taskResult, ['terminal', 'artifacts', 'errors']);
24
+ }
25
+ return snapshot;
26
+ }
27
+
28
+ function compareUsageRecords(left, right) {
29
+ return left.turn - right.turn
30
+ || left.step - right.step
31
+ || left.seq - right.seq;
32
+ }
33
+
34
+ const USAGE_FIELDS = ['inputTokens', 'outputTokens', 'cacheReadTokens', 'cacheWriteTokens', 'reasoningTokens'];
35
+
36
+ function normalizeUsage(usage) {
37
+ const normalized = {};
38
+ for (const field of USAGE_FIELDS) normalized[field] = usage[field] ?? 0;
39
+ normalized.prompt = normalized.inputTokens + normalized.cacheReadTokens + normalized.cacheWriteTokens;
40
+ return normalized;
41
+ }
42
+
43
+ function snapshotKey(snapshot) {
44
+ return JSON.stringify([snapshot.sessionId, snapshot.turn, snapshot.step, snapshot.seq]);
45
+ }
46
+
47
+ export function createTokenReport({
48
+ records = [],
49
+ snapshots = [],
50
+ taskResult = {},
51
+ assertions = {},
52
+ } = {}) {
53
+ const attributionByKey = new Map(snapshots.map((snapshot) => [snapshotKey(snapshot), snapshot]));
54
+ const entries = [...records].sort(compareUsageRecords).map((record) => ({
55
+ ...definedFields(record, ['sessionId', 'turn', 'step', 'seq', 'provider', 'model', 'atMs']),
56
+ usage: normalizeUsage(record.usage),
57
+ snapshot: attributionByKey.get(snapshotKey(record)) ?? null,
58
+ }));
59
+ const usage = normalizeUsage({});
60
+ for (const entry of entries) {
61
+ for (const field of USAGE_FIELDS) usage[field] += entry.usage[field];
62
+ }
63
+ usage.prompt = usage.inputTokens + usage.cacheReadTokens + usage.cacheWriteTokens;
64
+
65
+ const toolNames = new Set((taskResult.toolCalls ?? []).map((call) => typeof call === 'string' ? call : call.name));
66
+ const artifacts = new Set(taskResult.artifacts ?? []);
67
+ const errors = new Set(taskResult.errors ?? []);
68
+ const reasons = [];
69
+ if (assertions.expectedTerminal !== undefined && taskResult.terminal !== assertions.expectedTerminal) {
70
+ reasons.push('expected terminal "' + assertions.expectedTerminal + '", got "' + taskResult.terminal + '"');
71
+ }
72
+ for (const tool of assertions.requiredTools ?? []) {
73
+ if (!toolNames.has(tool)) reasons.push('missing required tool "' + tool + '"');
74
+ }
75
+ for (const artifact of assertions.requiredArtifacts ?? []) {
76
+ if (!artifacts.has(artifact)) reasons.push('missing required artifact "' + artifact + '"');
77
+ }
78
+ for (const error of assertions.forbiddenErrors ?? []) {
79
+ if (errors.has(error)) reasons.push('forbidden error "' + error + '"');
80
+ }
81
+
82
+ const pass = reasons.length === 0;
83
+ return {
84
+ entries,
85
+ requestSnapshots: snapshots,
86
+ usage,
87
+ taskResult,
88
+ assertions,
89
+ pass,
90
+ successRate: pass ? 1 : 0,
91
+ reasons,
92
+ };
93
+ }
94
+
95
+ function usageKey(record) {
96
+ return JSON.stringify([record.sessionId, record.turn, record.step, record.seq]);
97
+ }
98
+
99
+ export function createMemoryUsageAdapter(initialRecords = []) {
100
+ const records = new Map();
101
+ const watchers = new Set();
102
+ for (const record of initialRecords) {
103
+ const key = usageKey(record);
104
+ if (!records.has(key)) records.set(key, record);
105
+ }
106
+
107
+ function selectRecords(candidates, sessionId, afterSeq, toSeq) {
108
+ return [...candidates]
109
+ .filter((record) => record.sessionId === sessionId
110
+ && record.seq > afterSeq
111
+ && (toSeq === undefined || record.seq <= toSeq))
112
+ .sort(compareUsageRecords);
113
+ }
114
+
115
+ function read(sessionId, afterSeq = 0, toSeq) {
116
+ return selectRecords(records.values(), sessionId, afterSeq, toSeq);
117
+ }
118
+
119
+ return {
120
+ read,
121
+
122
+ append(...newRecords) {
123
+ const addedKeys = new Set();
124
+ for (const record of newRecords) {
125
+ const key = usageKey(record);
126
+ if (records.has(key)) continue;
127
+ records.set(key, record);
128
+ addedKeys.add(key);
129
+ }
130
+ for (const watcher of watchers) {
131
+ const pending = selectRecords(
132
+ [...addedKeys].map((key) => records.get(key)),
133
+ watcher.sessionId,
134
+ watcher.afterSeq,
135
+ );
136
+ for (const record of pending) watcher.callback(record);
137
+ }
138
+ },
139
+
140
+ watch(sessionId, afterSeq, callback) {
141
+ const watcher = { sessionId, afterSeq, callback };
142
+ watchers.add(watcher);
143
+ for (const record of read(sessionId, afterSeq)) callback(record);
144
+ return () => watchers.delete(watcher);
145
+ },
146
+ };
147
+ }
@@ -0,0 +1,184 @@
1
+ import { createMemoryUsageAdapter } from './index.js';
2
+
3
+ function usageKey(record) {
4
+ return JSON.stringify([record.sessionId, record.turn, record.step, record.seq]);
5
+ }
6
+
7
+ function describeError(error) {
8
+ if (error && typeof error.message === 'string') return error.message;
9
+ return String(error);
10
+ }
11
+
12
+ /**
13
+ * Map one `session/event` payload onto a Usage Record, or explain why it is not
14
+ * part of the durable Usage ledger. Only `assistant/message` events that carry
15
+ * `data.usage` participate; every other event is skipped without inventing
16
+ * provider, model, or token values.
17
+ */
18
+ function recordFromEvent(session, event) {
19
+ if (!event || typeof event !== 'object') {
20
+ return { skip: true, reason: 'event is not an object' };
21
+ }
22
+ if (event.type !== 'assistant/message') return { skip: true };
23
+ if (!Number.isFinite(event.seq)) {
24
+ return { skip: true, reason: 'assistant/message has no numeric seq' };
25
+ }
26
+ if (!Number.isFinite(event.time)) {
27
+ return { skip: true, reason: 'assistant/message has no numeric time' };
28
+ }
29
+ const data = event.data;
30
+ if (!data || typeof data !== 'object') {
31
+ return { skip: true, reason: 'assistant/message has no data' };
32
+ }
33
+ const usage = data.usage;
34
+ if (!usage || typeof usage !== 'object' || Array.isArray(usage)) return { skip: true };
35
+ if (!Number.isFinite(data.turn) || !Number.isFinite(data.step)) {
36
+ return { skip: true, reason: 'assistant/message has no numeric turn/step' };
37
+ }
38
+ const sessionId = session && session.id;
39
+ if (typeof sessionId !== 'string' || sessionId.length === 0) {
40
+ return { skip: true, reason: 'event has no session id' };
41
+ }
42
+
43
+ const record = {
44
+ sessionId,
45
+ turn: data.turn,
46
+ step: data.step,
47
+ seq: event.seq,
48
+ atMs: event.time,
49
+ usage,
50
+ };
51
+ const source = data.message && typeof data.message === 'object' ? data.message.source : undefined;
52
+ if (source && typeof source === 'object') {
53
+ if (typeof source.provider === 'string') record.provider = source.provider;
54
+ if (typeof source.model === 'string') record.model = source.model;
55
+ }
56
+ return { skip: false, record };
57
+ }
58
+
59
+ /**
60
+ * Live Usage adapter over the durable `session/event` feed.
61
+ *
62
+ * Subscribes once to the context's `session/event` emit hook and appends the
63
+ * Usage Record of every `assistant/message` event that carries `usage`.
64
+ * `read`/`watch` keep the semantics of {@link createMemoryUsageAdapter}, and
65
+ * `hydrate` backfills events the subscription missed through
66
+ * `session.snapshotEvents`. Every failure path degrades to "skip and warn":
67
+ * usage capture must never break the host's append publication.
68
+ *
69
+ * @param ctx - plugin context; only `on` and `logger` are used.
70
+ * @param options - optional logger override (`options.logger ?? ctx.logger`).
71
+ * @returns `{ read, watch, hydrate, dispose }`.
72
+ */
73
+ export function createLiveUsageAdapter(ctx = {}, options = {}) {
74
+ const context = ctx && typeof ctx === 'object' ? ctx : {};
75
+ const settings = options && typeof options === 'object' ? options : {};
76
+ const logger = settings.logger ?? context.logger;
77
+ const adapter = createMemoryUsageAdapter();
78
+ const committed = new Set();
79
+ let disposed = false;
80
+ let unsubscribe = null;
81
+
82
+ function warn(message) {
83
+ if (!logger || typeof logger.warn !== 'function') return;
84
+ try {
85
+ logger.warn('[token-ledger] ' + message);
86
+ } catch {
87
+ // A logger must never break usage capture.
88
+ }
89
+ }
90
+
91
+ function commit(record) {
92
+ const key = usageKey(record);
93
+ if (committed.has(key)) return false;
94
+ try {
95
+ adapter.append(record);
96
+ } catch (error) {
97
+ warn('usage watcher failed: ' + describeError(error));
98
+ }
99
+ committed.add(key);
100
+ return true;
101
+ }
102
+
103
+ function handleEvent(session, event) {
104
+ if (disposed) return;
105
+ const mapped = recordFromEvent(session, event);
106
+ if (mapped.skip) {
107
+ if (mapped.reason) warn('skipped session/event: ' + mapped.reason);
108
+ return;
109
+ }
110
+ commit(mapped.record);
111
+ }
112
+
113
+ if (typeof context.on === 'function') {
114
+ try {
115
+ const disposer = context.on('session/event', handleEvent);
116
+ if (typeof disposer === 'function') unsubscribe = disposer;
117
+ } catch (error) {
118
+ warn('could not subscribe to session/event: ' + describeError(error));
119
+ }
120
+ } else {
121
+ warn('ctx.on is unavailable; live usage capture disabled');
122
+ }
123
+
124
+ /**
125
+ * Backfill Usage Records from a session's event log.
126
+ *
127
+ * @param session - the session whose log is read; skipped when it cannot
128
+ * enumerate events.
129
+ * @param afterSeq - last sequence number already known; only later events are
130
+ * read. Omitted or non-numeric means "from the start of the log".
131
+ * @returns the number of newly recorded Usage Records.
132
+ */
133
+ function hydrate(session, afterSeq) {
134
+ if (disposed) return 0;
135
+ if (!session || typeof session.snapshotEvents !== 'function') {
136
+ warn('hydrate skipped: session.snapshotEvents is unavailable');
137
+ return 0;
138
+ }
139
+ const from = typeof afterSeq === 'number' && Number.isFinite(afterSeq) && afterSeq >= 0
140
+ ? afterSeq + 1
141
+ : undefined;
142
+ let events;
143
+ try {
144
+ events = from === undefined ? session.snapshotEvents() : session.snapshotEvents(from);
145
+ } catch (error) {
146
+ warn('hydrate failed: ' + describeError(error));
147
+ return 0;
148
+ }
149
+ if (!Array.isArray(events)) {
150
+ warn('hydrate skipped: snapshotEvents returned no event list');
151
+ return 0;
152
+ }
153
+ let added = 0;
154
+ for (const event of events) {
155
+ const mapped = recordFromEvent(session, event);
156
+ if (mapped.skip) {
157
+ if (mapped.reason) warn('hydrate skipped session/event: ' + mapped.reason);
158
+ continue;
159
+ }
160
+ if (commit(mapped.record)) added += 1;
161
+ }
162
+ return added;
163
+ }
164
+
165
+ function dispose() {
166
+ if (disposed) return;
167
+ disposed = true;
168
+ const stop = unsubscribe;
169
+ unsubscribe = null;
170
+ if (typeof stop !== 'function') return;
171
+ try {
172
+ stop();
173
+ } catch (error) {
174
+ warn('dispose failed: ' + describeError(error));
175
+ }
176
+ }
177
+
178
+ return {
179
+ read: adapter.read,
180
+ watch: adapter.watch,
181
+ hydrate,
182
+ dispose,
183
+ };
184
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-lean-router",
3
- "version": "1.1.0",
4
- "description": "lean 省 token × 思考链路由 × code_run 工具遮蔽 × mattpocock 技能自动调用的 DSH cordis 插件(单 bundle:预设+配套技能)",
3
+ "version": "2.1.0",
4
+ "description": "lean 省 token × 思考链路由 × code_run 工具遮蔽的 DSH cordis 插件(单 bundle:预设)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -11,17 +11,13 @@
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
- "./client": {
15
- "default": "./lib/client.js"
16
- }
14
+ "./token-ledger": "./lib/token-ledger/index.js",
15
+ "./token-ledger/live": "./lib/token-ledger/live.js"
17
16
  },
18
17
  "files": [
19
18
  "lib",
20
19
  "presets",
21
- "assets",
22
- "ui",
23
20
  "docs",
24
- "skills.manifest.json",
25
21
  "cordis.patch.yml",
26
22
  "scripts",
27
23
  "test",
@@ -42,16 +38,12 @@
42
38
  "scripts": {
43
39
  "test": "node --test \"test/*.test.mjs\"",
44
40
  "build": "node scripts/build-bundle.mjs",
45
- "drift": "node scripts/check-drift.mjs",
46
41
  "doctor": "node scripts/doctor.mjs",
47
42
  "verify": "node scripts/verify.mjs"
48
43
  },
49
44
  "dsh": {
50
45
  "bundle": {
51
46
  "patch": "./cordis.patch.yml"
52
- },
53
- "client": {
54
- "platform": "web"
55
47
  }
56
48
  },
57
49
  "keywords": [
@@ -59,8 +51,7 @@
59
51
  "agent-preset",
60
52
  "lean",
61
53
  "router",
62
- "codemode",
63
- "skills"
54
+ "codemode"
64
55
  ],
65
56
  "dependencies": {
66
57
  "@deepseek-ai/dsh-tool-executor-native": ">=0.2.2-alpha.3 <0.2.4-0"
@@ -17,7 +17,7 @@
17
17
  config:
18
18
  id: lean-router
19
19
  name: Lean router
20
- description: "lean 省 token × 思考链路由 × code_run 遮蔽 × mattpocock 技能自动调用(lean 档:13 条纪律 + 3 软门 + 自检题钩子)。"
20
+ description: "lean 省 token × 思考链路由 × code_run 遮蔽(lean 档:13 条纪律 + 3 软门 + 自检题钩子)。"
21
21
  order: 30
22
22
  plugins:
23
23
  # 机制 4 · 行为纪律(persona 双档;lean 档 13 条硬规则 + 3 软门 + 自检题钩子)
@@ -106,8 +106,6 @@
106
106
  name: '@deepseek-ai/dsh-tool-jobs'
107
107
  - id: skill-filesystem
108
108
  name: '@deepseek-ai/dsh-skill-filesystem'
109
- - id: skill-lean-router
110
- name: dsh-lean-router
111
109
  - id: tool-skill
112
110
  name: '@deepseek-ai/dsh-tool-skill'
113
111
  - id: command-goal
@@ -284,8 +282,6 @@
284
282
  name: '@deepseek-ai/dsh-tool-jobs'
285
283
  - id: skill-filesystem
286
284
  name: '@deepseek-ai/dsh-skill-filesystem'
287
- - id: skill-lean-router
288
- name: dsh-lean-router
289
285
  - id: tool-skill
290
286
  name: '@deepseek-ai/dsh-tool-skill'
291
287
  - id: command-goal
@@ -9,7 +9,7 @@
9
9
  config:
10
10
  id: lean-router
11
11
  name: Lean router
12
- description: "lean 省 token × 思考链路由 × code_run 遮蔽 × mattpocock 技能自动调用(lean 档:13 条纪律 + 3 软门 + 自检题钩子)。"
12
+ description: "lean 省 token × 思考链路由 × code_run 遮蔽(lean 档:13 条纪律 + 3 软门 + 自检题钩子)。"
13
13
  order: 30
14
14
  plugins:
15
15
  - id: persona
@@ -100,8 +100,6 @@
100
100
  name: '@deepseek-ai/dsh-tool-jobs'
101
101
  - id: skill-filesystem
102
102
  name: '@deepseek-ai/dsh-skill-filesystem'
103
- - id: skill-lean-router
104
- name: dsh-lean-router
105
103
  - id: tool-skill
106
104
  name: '@deepseek-ai/dsh-tool-skill'
107
105
  - id: command-goal
@@ -1,28 +1,17 @@
1
1
  # dsh-lean-router 票 05 路由层分片(顶层列表续项;由 scripts/build-bundle.mjs 续接进 cordis.patch.yml)
2
2
  # 钩子行:agent/inbox/claimed 首轮捕获 + 近场引导 dynamic context + 勤勉自检
3
- # 命令行:/band 显式改档、/skill 技能与 invocation 列表(宿主 ctx.commands 缝)
3
+ # 命令行:/band 显式改档(宿主 ctx.commands 缝)
4
4
  # 入口子路径 dsh-lean-router/router 需要 package.json exports 增补 "./router": "./lib/router.js"
5
5
  # (package.json 为共享文件,由 master 统一集成;见 lib/router.js ROUTER_INJECTION_NOTES.patchEntry)
6
6
  - insert:
7
- # 1.0.5 修:宿主层裸包名行(对照 dsh-cost-meter 的 "one host row")。
8
- # 没有这一行,客户端模块扫描看不到 dsh.client -> 客户端 bundle 不加载 -> 无顶栏按钮。
9
- # config.provider=false:不重复注册 skill provider(预设层已注册)。
10
- - id: lean-router-client-host
11
- name: dsh-lean-router
12
7
  - id: lean-router-router
13
8
  name: dsh-lean-router/router
14
9
  config:
15
10
  hooks: true
16
11
  commands: false
17
12
  diligenceEvery: 10
18
- # 1.0.5 修:每轮门控必须开,否则 skillgate 不跑 -> 审计零条目、审计文件从不生成。
19
- # 依据 lib/router.js:345(cfg.hooks && cfg.gate 才建 runner)与 lib/router.js:194。
20
- gate: true
21
13
  - id: lean-router-commands
22
14
  name: dsh-lean-router/router
23
15
  config:
24
16
  hooks: false
25
17
  commands: true
26
- # master 集成(票 07 §9.1):审计落盘开;auditPath/weightsPath 省略 = 默认值
27
- # (注意不能传空串:lib/router.js:145-149 对空串抛错,缺省语义见 §9.1 修正版)
28
- audit: true
@@ -37,8 +37,6 @@
37
37
  name: '@deepseek-ai/dsh-tool-jobs'
38
38
  - id: skill-filesystem
39
39
  name: '@deepseek-ai/dsh-skill-filesystem'
40
- - id: skill-lean-router
41
- name: dsh-lean-router
42
40
  - id: tool-skill
43
41
  name: '@deepseek-ai/dsh-tool-skill'
44
42
  - id: command-goal
@@ -2,14 +2,13 @@
2
2
  # TODO(ticket-03 lean 层):compaction 0.25/20000、tool-result pruner 4096/1024、关 6 插件、lean13/balance3 persona、plan-mode v1、delivery-gate、glob/grep 并发标记
3
3
  # TODO(ticket-04 工具遮蔽层):codemode executor 遮蔽行 + code_run 传输 + meta 4 工具 + 常驻 ptc-runtime
4
4
  # TODO(ticket-05 路由层):首轮 inbox.claim 捕获 + [router] band/task 分类指令 + pre-step 近场引导 + 3 软门 + /band
5
- # TODO(ticket-06 技能门控层):skill provider rank 配置 + 每轮评分放行 + 8k 软降级 + 审计
6
5
  - insert:
7
6
  - id: preset-lean-router
8
7
  name: '@deepseek-ai/dsh-agent-preset'
9
8
  config:
10
9
  id: lean-router
11
10
  name: Lean router
12
- description: "lean 省 token × 思考链路由 × code_run 遮蔽 × mattpocock 技能自动调用(v1.0.0 骨架)"
11
+ description: "lean 省 token × 思考链路由 × code_run 遮蔽(2.0.0)"
13
12
  order: 30
14
13
  plugins:
15
14
  - id: persona
@@ -37,8 +36,6 @@
37
36
  name: '@deepseek-ai/dsh-tool-jobs'
38
37
  - id: skill-filesystem
39
38
  name: '@deepseek-ai/dsh-skill-filesystem'
40
- - id: skill-lean-router
41
- name: dsh-lean-router
42
39
  - id: tool-skill
43
40
  name: '@deepseek-ai/dsh-tool-skill'
44
41
  - id: command-goal
@@ -1,5 +1,5 @@
1
- // dsh-lean-router - 体检(票 02 骨架版;票 04/06 将加四层接缝自检)
2
- import { readFile, readdir } from "node:fs/promises";
1
+ // dsh-lean-router - 体检(2.0.0:技能子系统下线后只剩结构自检)
2
+ import { readFile, access } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
 
@@ -8,20 +8,25 @@ const ROOT = fileURLToPath(new URL("..", import.meta.url));
8
8
  export async function doctor() {
9
9
  const lines = []; let fail = 0;
10
10
  const ok = (name, cond, extra) => { lines.push((cond ? "[PASS] " : "[FAIL] ") + name + (extra ? " | " + extra : "")); if (!cond) fail++; };
11
+ const exists = async (rel) => { try { await access(join(ROOT, rel)); return true; } catch { return false; } };
12
+
11
13
  const pkg = JSON.parse(await readFile(join(ROOT, "package.json"), "utf8"));
12
14
  ok("package.name", pkg.name === "dsh-lean-router", pkg.name);
13
15
  ok("package.engines.dsh", typeof (pkg.engines ?? {}).dsh === "string" && pkg.engines.dsh.includes("0.2.1-rc.5"), pkg.engines?.dsh);
16
+
14
17
  const patch = await readFile(join(ROOT, "cordis.patch.yml"), "utf8").catch(() => null);
15
18
  ok("cordis.patch.yml 存在", !!patch);
16
19
  ok("patch 含预设行", !!patch && patch.includes("preset-lean-router"));
17
- const manifest = JSON.parse(await readFile(join(ROOT, "skills.manifest.json"), "utf8"));
18
- ok("manifest 31 技能", manifest.skills.length === 31, String(manifest.skills.length));
19
- const dirs = (await readdir(join(ROOT, "assets", "skills"), { withFileTypes: true })).filter(d => d.isDirectory());
20
- ok("assets/skills 目录数", dirs.length === 31, String(dirs.length));
21
- const matrix = JSON.parse(await readFile(join(ROOT, "assets", "skills.matrix.json"), "utf8"));
22
- const c = { both: 0, modelOnly: 0, userOnly: 0 };
23
- for (const s of matrix.skills) { if (s.model && s.user) c.both++; else if (s.model) c.modelOnly++; else c.userOnly++; }
24
- ok("矩阵计数 13/10/8", c.both === 13 && c.modelOnly === 10 && c.userOnly === 8, JSON.stringify(c));
20
+ ok("patch 含路由行", !!patch && patch.includes("lean-router-router"));
21
+ // 2.0.0 移除的子系统不得回流:技能 provider 行与客户端宿主行都已下线。
22
+ ok("patch 无技能 provider 行", !!patch && !patch.includes("skill-lean-router"));
23
+ ok("patch 无客户端宿主行", !!patch && !patch.includes("lean-router-client-host"));
24
+
25
+ ok("lib/router.js 存在", await exists("lib/router.js"));
26
+ ok("lib/lean/index.js 存在", await exists("lib/lean/index.js"));
27
+ ok("lib/toolface/index.js 存在", await exists("lib/toolface/index.js"));
28
+ ok("客户端 bundle 已移除", !(await exists("lib/client.js")));
29
+
25
30
  console.log(lines.join("\n"));
26
31
  return fail === 0;
27
32
  }
@@ -26,15 +26,16 @@ function suffixBlock(text) {
26
26
  return out.join('\n');
27
27
  }
28
28
 
29
- test('frag-preset 是 preset 行唯一生效 owner:21 行并集、无重复、toolface 收尾', () => {
29
+ test('frag-preset 是 preset 行唯一生效 owner:20 行并集、无重复、toolface 收尾', () => {
30
30
  const ids = frag.split(/\r?\n/).filter(l => /^ - id: /.test(l)).map(l => /^ - id: (.+)$/.exec(l)[1].trim());
31
- assert.equal(ids.length, 21, '并集行数 = 覆写块 20 + toolface(ptc-runtime 属宿主层,不进 preset)');
31
+ assert.equal(ids.length, 20, '并集行数 = 覆写块 19 + toolface(2.0.0 移除 skill-lean-router;ptc-runtime 属宿主层,不进 preset)');
32
32
  assert.equal(new Set(ids).size, ids.length, '无重复 id');
33
33
  assert.equal(ids[ids.length - 1], 'toolface', 'toolface 最后(遮蔽面与 preset 同行生效)');
34
34
  assert.ok(!ids.includes('ptc-runtime'), 'ptc-runtime 由宿主 dsh-base 挂载,放进 preset 会让整条 preset 激活失败(1.0.3 事故回归)');
35
- for (const id of ['persona', 'agent-instructions', 'skill-filesystem', 'skill-lean-router', 'planning', 'compaction', 'delegation', 'tool-todo', 'tool-web', 'present', 'toolface']) {
35
+ for (const id of ['persona', 'agent-instructions', 'skill-filesystem', 'planning', 'compaction', 'delegation', 'tool-todo', 'tool-web', 'present', 'toolface']) {
36
36
  assert.ok(ids.includes(id), '缺行: ' + id);
37
37
  }
38
+ assert.ok(!ids.includes('skill-lean-router'), '2.0.0 起不再挂 lean-router 技能 provider 行');
38
39
  assert.ok(!ids.includes('preset-lean-router-balance'), 'balance 是独立行,不在并集行 id 内');
39
40
  assert.ok(!ids.includes('lean-delivery-gate') && !ids.includes('lean-concurrency'), '交付门/并发标记是独立行,不在并集行 id 内');
40
41
  });
@@ -1,61 +1,26 @@
1
- // dsh-lean-router 1.0.6 —— 包入口(lib/index.js)的 cordis 契约回归。
2
- // 背景(0.2.3 真机):inject 写成 { required: [], optional: ["skills"] } 会被 cordis 当成
3
- // 两个叫 required / optional 的服务,宿主层那行永远 PENDING,apply 不跑,客户端 bundle
4
- // 不被扫描,顶栏按钮不出现。cordis 的 inject 只有两种形状:
5
- // Inject<M> = (keyof M)[] | { [K in keyof M]?: M[K] } (registry.ts L19)
1
+ // dsh-lean-router 2.0.0 —— 包入口(lib/index.js)的 cordis 契约回归。
2
+ // 2.0.0 起技能子系统下线,入口只剩一个合法插件形状;保留本测试是因为历史上两次真机事故都出在这里:
3
+ // 1.0.6: inject 写成 { required: [], optional: [...] } → 被当成两个服务名,宿主行永远 PENDING。
4
+ // 1.0.2: apply 返回普通对象 → cordis 抛 Invalid effect,整条 preset 不注册。
6
5
  import test from "node:test";
7
6
  import assert from "node:assert/strict";
8
- import { tmpdir } from "node:os";
9
- import { join } from "node:path";
10
7
 
11
8
  import * as entry from "../lib/index.js";
12
9
 
13
- /** 把 homedir() 指向临时目录,避免自检日志写进真实用户目录。 */
14
- function withTempHome(fn) {
15
- const saved = process.env.USERPROFILE;
16
- process.env.USERPROFILE = join(tmpdir(), "dsh-lean-router-test-home");
17
- try {
18
- return fn();
19
- } finally {
20
- if (saved === undefined) delete process.env.USERPROFILE;
21
- else process.env.USERPROFILE = saved;
22
- }
23
- }
24
-
25
- test("inject 是 cordis 认的形状,不能出现 required/optional 键", () => {
26
- if (Array.isArray(entry.inject)) return;
27
- assert.equal(typeof entry.inject, "object", "inject 必须是数组或服务名映射");
28
- const keys = Object.keys(entry.inject);
29
- assert.ok(
30
- !keys.includes("required") && !keys.includes("optional"),
31
- "inject 被当成服务名映射后出现了 required/optional 键:" + keys.join(","),
32
- );
10
+ test("包可被导入,且有 name / inject / apply", () => {
11
+ assert.equal(typeof entry.name, "string");
12
+ assert.ok(Array.isArray(entry.inject), "inject 必须是服务名数组或服务名映射,不能是 { required, optional }");
13
+ assert.equal(typeof entry.apply, "function");
33
14
  });
34
15
 
35
- test("宿主作用域:provider:false 时不碰 skills,apply 返回 undefined", () => {
36
- withTempHome(() => {
37
- const ctx = { inject() { throw new Error("provider:false 不该调用 ctx.inject"); } };
38
- assert.equal(entry.apply(ctx, { provider: false }), undefined);
39
- });
40
- });
41
-
42
- test("预设作用域:用 ctx.inject 等 skills 就绪,而不是把它写进必需依赖", () => {
43
- withTempHome(() => {
44
- const calls = [];
45
- const ctx = { inject(deps, cb) { calls.push({ deps, cb }); } };
46
- assert.equal(entry.apply(ctx, {}), undefined, "apply 不能把 ctx.inject 的 fiber 当 effect 交回去");
47
- assert.equal(calls.length, 1);
48
- assert.deepEqual(calls[0].deps, ["skills"]);
49
- let registered = null;
50
- calls[0].cb({ skills: { registerProvider(factory) { registered = factory; } } });
51
- assert.equal(typeof registered, "function", "skills 就绪后必须注册 provider");
52
- });
16
+ test("inject 里不出现 required / optional 这类伪服务名", () => {
17
+ const keys = Array.isArray(entry.inject) ? entry.inject : Object.keys(entry.inject);
18
+ assert.ok(!keys.includes("required") && !keys.includes("optional"), "inject 键:" + keys.join(","));
53
19
  });
54
20
 
55
- test("没有 ctx.inject 时退化为直接注册(老宿主兼容)", () => {
56
- withTempHome(() => {
57
- let registered = null;
58
- entry.apply({ skills: { registerProvider(factory) { registered = factory; } } }, {});
59
- assert.equal(typeof registered, "function");
21
+ test("apply 返回 undefined,且不读任何服务属性(cordis 会因未 inject 直接抛)", () => {
22
+ const ctx = new Proxy({}, {
23
+ get(_t, key) { throw new Error("apply 不该读 ctx." + String(key)); },
60
24
  });
25
+ assert.equal(entry.apply(ctx, {}), undefined);
61
26
  });