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,264 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+
4
+ import { captureRequestSnapshot, createMemoryUsageAdapter, createTokenReport } from 'dsh-lean-router/token-ledger';
5
+
6
+ function usage(seq, inputTokens = 10) {
7
+ return {
8
+ sessionId: 'session-a',
9
+ turn: 1,
10
+ step: 2,
11
+ seq,
12
+ provider: 'fixture',
13
+ model: 'fixture-model',
14
+ atMs: 1_700_000_000_000 + seq,
15
+ usage: {
16
+ inputTokens,
17
+ outputTokens: 3,
18
+ cacheReadTokens: 2,
19
+ cacheWriteTokens: 1,
20
+ reasoningTokens: 1,
21
+ },
22
+ };
23
+ }
24
+
25
+ test('UsageAdapter.read deduplicates, sorts and applies after/to bounds', () => {
26
+ const adapter = createMemoryUsageAdapter([
27
+ usage(4, 40),
28
+ usage(2, 20),
29
+ usage(3, 30),
30
+ usage(2, 999),
31
+ { ...usage(1, 10), turn: 2 },
32
+ { ...usage(1, 11), step: 1 },
33
+ ]);
34
+
35
+ assert.deepEqual(adapter.read('session-a', 0).map((entry) => [entry.turn, entry.step, entry.seq]), [
36
+ [1, 1, 1],
37
+ [1, 2, 2],
38
+ [1, 2, 3],
39
+ [1, 2, 4],
40
+ [2, 2, 1],
41
+ ]);
42
+ assert.equal(adapter.read('session-a', 0).find((entry) => entry.turn === 1 && entry.step === 2 && entry.seq === 2).usage.inputTokens, 20);
43
+ assert.deepEqual(adapter.read('session-a', 2, 3).map((entry) => entry.seq), [3]);
44
+ assert.deepEqual(adapter.read('session-b', 0), []);
45
+ });
46
+
47
+ test('UsageAdapter.watch replays afterSeq and streams sorted unique records', () => {
48
+ const adapter = createMemoryUsageAdapter([usage(2, 20), usage(1, 10)]);
49
+ const seen = [];
50
+ const stop = adapter.watch('session-a', 0, (record) => seen.push(record.seq));
51
+
52
+ assert.deepEqual(seen, [1, 2]);
53
+ adapter.append(usage(4, 40), usage(3, 30), usage(3, 999));
54
+ adapter.append({ ...usage(9, 90), sessionId: 'session-b' });
55
+ assert.deepEqual(seen, [1, 2, 3, 4]);
56
+ assert.equal(adapter.read('session-a', 0).find((record) => record.seq === 3).usage.inputTokens, 30);
57
+
58
+ stop();
59
+ adapter.append(usage(5, 50));
60
+ assert.deepEqual(seen, [1, 2, 3, 4]);
61
+ });
62
+
63
+ test('UsageAdapter keeps first writes and never pushes duplicate appends', () => {
64
+ const first = usage(1, 10);
65
+ const adapter = createMemoryUsageAdapter([first, usage(1, 999)]);
66
+ const seen = [];
67
+ const stop = adapter.watch('session-a', 0, (record) => seen.push(record));
68
+
69
+ assert.deepEqual(seen, [first]);
70
+ const next = usage(2, 20);
71
+ adapter.append(next, usage(2, 999), usage(1, 999));
72
+
73
+ assert.deepEqual(seen, [first, next]);
74
+ assert.deepEqual(adapter.read('session-a', 0), [first, next]);
75
+ stop();
76
+ });
77
+
78
+ test('RequestSnapshot captures metadata without request or tool definition content', () => {
79
+ const snapshot = captureRequestSnapshot({
80
+ sessionId: 'session-a',
81
+ turn: 1,
82
+ step: 2,
83
+ seq: 7,
84
+ headerHash: 'sha256:header',
85
+ messages: ['raw prompt'],
86
+ tools: [
87
+ { name: 'read', schemaHash: 'sha256:read', description: 'raw tool description' },
88
+ { name: 'edit', schemaHash: 'sha256:edit', parameters: { type: 'object' } },
89
+ ],
90
+ partitionChars: { system: 100, context: 200, toolOutput: 300 },
91
+ taskResult: {
92
+ terminal: 'success',
93
+ artifacts: ['lib/token-ledger/index.js'],
94
+ errors: [],
95
+ output: 'raw task output',
96
+ },
97
+ });
98
+
99
+ assert.deepEqual(snapshot, {
100
+ sessionId: 'session-a',
101
+ turn: 1,
102
+ step: 2,
103
+ seq: 7,
104
+ headerHash: 'sha256:header',
105
+ tools: [
106
+ { name: 'read', schemaHash: 'sha256:read' },
107
+ { name: 'edit', schemaHash: 'sha256:edit' },
108
+ ],
109
+ partitionChars: { system: 100, context: 200, toolOutput: 300 },
110
+ taskResult: {
111
+ terminal: 'success',
112
+ artifacts: ['lib/token-ledger/index.js'],
113
+ errors: [],
114
+ },
115
+ });
116
+ });
117
+
118
+ test('RequestSnapshot rejects raw prompt, body and toolOutput fields', () => {
119
+ for (const field of ['prompt', 'body', 'toolOutput']) {
120
+ assert.throws(
121
+ () => captureRequestSnapshot({ sessionId: 'session-a', seq: 1, [field]: 'raw secret' }),
122
+ new RegExp('raw field "' + field + '"'),
123
+ );
124
+ }
125
+ });
126
+
127
+ test('TokenReport associates snapshots by session, turn, step and seq', () => {
128
+ const records = [
129
+ { ...usage(7, 10), turn: 2, step: 3 },
130
+ { ...usage(7, 20), turn: 2, step: 4 },
131
+ { ...usage(7, 30), turn: 1, step: 3 },
132
+ ];
133
+ const snapshots = records.map((record) => captureRequestSnapshot({
134
+ sessionId: record.sessionId,
135
+ turn: record.turn,
136
+ step: record.step,
137
+ seq: record.seq,
138
+ headerHash: `sha256:${record.turn}-${record.step}`,
139
+ }));
140
+ const report = createTokenReport({ records, snapshots });
141
+
142
+ assert.deepEqual(report.entries.map((entry) => [
143
+ entry.turn,
144
+ entry.step,
145
+ entry.seq,
146
+ entry.snapshot.headerHash,
147
+ ]), [
148
+ [1, 3, 7, 'sha256:1-3'],
149
+ [2, 3, 7, 'sha256:2-3'],
150
+ [2, 4, 7, 'sha256:2-4'],
151
+ ]);
152
+ });
153
+
154
+ test('TokenReport totals host Usage and keeps requestSnapshots separate', () => {
155
+ const snapshot = captureRequestSnapshot({
156
+ sessionId: 'session-a',
157
+ turn: 1,
158
+ step: 2,
159
+ seq: 1,
160
+ headerHash: 'sha256:header',
161
+ partitionChars: { context: 120 },
162
+ });
163
+ const taskResult = {
164
+ terminal: 'success',
165
+ toolCalls: ['read', { name: 'edit' }],
166
+ artifacts: ['lib/token-ledger/index.js'],
167
+ errors: [],
168
+ };
169
+ const report = createTokenReport({
170
+ records: [usage(2, 20), usage(1, 10)],
171
+ snapshots: [snapshot],
172
+ taskResult,
173
+ assertions: {
174
+ expectedTerminal: 'success',
175
+ requiredTools: ['read'],
176
+ requiredArtifacts: ['lib/token-ledger/index.js'],
177
+ forbiddenErrors: ['TIMEOUT'],
178
+ },
179
+ });
180
+
181
+ assert.equal(report.pass, true);
182
+ assert.deepEqual(report.reasons, []);
183
+ assert.deepEqual(report.usage, {
184
+ inputTokens: 30,
185
+ outputTokens: 6,
186
+ cacheReadTokens: 4,
187
+ cacheWriteTokens: 2,
188
+ reasoningTokens: 2,
189
+ prompt: 36,
190
+ });
191
+ assert.equal(Object.hasOwn(report.usage, 'promptTokens'), false);
192
+ assert.equal(Object.hasOwn(report.usage, 'freshTokens'), false);
193
+ assert.deepEqual(report.entries[0].usage, {
194
+ inputTokens: 10,
195
+ outputTokens: 3,
196
+ cacheReadTokens: 2,
197
+ cacheWriteTokens: 1,
198
+ reasoningTokens: 1,
199
+ prompt: 13,
200
+ });
201
+ assert.deepEqual(report.entries[0].snapshot, snapshot);
202
+ assert.deepEqual(report.entries[1].snapshot, null);
203
+ assert.deepEqual(report.entries.map((entry) => [entry.seq, entry.atMs]), [
204
+ [1, 1_700_000_000_001],
205
+ [2, 1_700_000_000_002],
206
+ ]);
207
+ assert.deepEqual(report.requestSnapshots, [snapshot]);
208
+ assert.equal(Object.hasOwn(report, 'attribution'), false);
209
+ assert.deepEqual(report.taskResult, taskResult);
210
+ });
211
+
212
+ test('TokenReport fails only on explicit assertion mismatches and explains each reason', () => {
213
+ const report = createTokenReport({
214
+ records: [usage(1)],
215
+ snapshots: [],
216
+ taskResult: {
217
+ terminal: 'failed',
218
+ toolCalls: [{ name: 'edit' }],
219
+ artifacts: ['other.js'],
220
+ errors: ['TIMEOUT'],
221
+ },
222
+ assertions: {
223
+ expectedTerminal: 'success',
224
+ requiredTools: ['read'],
225
+ requiredArtifacts: ['lib/token-ledger/index.js'],
226
+ forbiddenErrors: ['TIMEOUT'],
227
+ },
228
+ });
229
+
230
+ assert.equal(report.pass, false);
231
+ assert.deepEqual(report.reasons, [
232
+ 'expected terminal "success", got "failed"',
233
+ 'missing required tool "read"',
234
+ 'missing required artifact "lib/token-ledger/index.js"',
235
+ 'forbidden error "TIMEOUT"',
236
+ ]);
237
+ });
238
+
239
+ test('TokenReport derives successRate from explicit assertions', () => {
240
+ const passing = createTokenReport({
241
+ records: [usage(1)],
242
+ taskResult: { terminal: 'success' },
243
+ assertions: { expectedTerminal: 'success' },
244
+ });
245
+ assert.equal(passing.pass, true);
246
+ assert.deepEqual(passing.reasons, []);
247
+ assert.equal(passing.successRate, 1);
248
+
249
+ const failing = createTokenReport({
250
+ records: [usage(1)],
251
+ taskResult: { terminal: 'failed' },
252
+ assertions: { expectedTerminal: 'success' },
253
+ });
254
+ assert.equal(failing.pass, false);
255
+ assert.deepEqual(failing.reasons, ['expected terminal "success", got "failed"']);
256
+ assert.equal(failing.successRate, 0);
257
+ });
258
+
259
+ test('package exposes the token-ledger subpath', async () => {
260
+ const publicModule = await import('dsh-lean-router/token-ledger');
261
+ assert.equal(typeof publicModule.createMemoryUsageAdapter, 'function');
262
+ assert.equal(typeof publicModule.captureRequestSnapshot, 'function');
263
+ assert.equal(typeof publicModule.createTokenReport, 'function');
264
+ });
@@ -1,13 +0,0 @@
1
- {
2
- "version": 1,
3
- "sceneMap": {
4
- "react": { "engineering": 2, "process": 1 },
5
- "spec": { "engineering": 2, "research": 1 },
6
- "weak": {}
7
- },
8
- "complexBoost": { "engineering": 1 },
9
- "autoScore": 2,
10
- "hintScore": 1,
11
- "tokenBudget": 8000,
12
- "charsPerToken": 4
13
- }
@@ -1,55 +0,0 @@
1
- # Phase boundaries
2
-
3
- A **phase** is a chunk of work inside a session: the grilling, the implementation, the QA. The definition is fuzzy on purpose: a phase ends when you think *"ok, we're done with that"*.
4
-
5
- The **phase boundary** is the gap between two phases, and it is the only place this decision belongs. Mid-phase there is no decision to make: continue, or split the work that's left into subagents. Compacting mid-phase makes the agent lose the thread.
6
-
7
- ## The five options
8
-
9
- | Option | What it does |
10
- | ------------ | --------------------------------------------------------------- |
11
- | **Continue** | Stay in the session. No context switch at all. |
12
- | **`/clear`** | Empty the context window and start from nothing. |
13
- | **`/handoff`** | Write a portable markdown file and seed a session anywhere with it. |
14
- | **Subagent** | Send the task to its own context window and get a report back. |
15
- | **`/compact`** | Compress this context and seed a fresh session with the summary. |
16
-
17
- ## The tree
18
-
19
- Work top to bottom at the boundary. The first **yes** wins.
20
-
21
- **1. Can you continue in this session?** Two things make the answer yes: the next phase needs this phase as a **primary source**, or you have enough [smart zone](https://www.aihero.dev/ai-coding-dictionary/smart-zone) left (~150k tokens) for the next phase to fit. Grilling → implementation is the standard yes: the implementation wants the reasoning verbatim, not a summary of it. Continue costs nothing and loses nothing, so rule it out before anything else.
22
-
23
- **2. Is the context irrelevant to what comes next?** Is everything in this session (the exploration, the decisions, the dead ends) disposable? If so, **`/clear`**. It is the cheapest move on the board: it takes no time and hands back the whole window. `/clear` also isn't terminal: the old session stays resumable.
24
-
25
- The cost of getting this wrong is one-way. Clear a *relevant* context and you lose the **why** behind what you built, and no amount of reading the diff back gets it returned.
26
-
27
- **3. Do you need to hand off?** `/handoff` is narrow. You need it only when you are:
28
-
29
- - swapping to a **new harness** (Claude → Codex),
30
- - moving to a **new directory** or repo,
31
- - sending the work to a **colleague**,
32
- - or forking a side task you found **mid-phase** without derailing what you're doing.
33
-
34
- That list is the whole clause. What `/handoff` buys is **portability**: a file that travels. If nothing is travelling, you don't need it.
35
-
36
- **4. Can the task be done AFK?** Is it scoped tightly enough to run with you away from the keyboard, no steering? Then send it to a **subagent** and leave this session untouched. Automated review is the standard case: the agent reads the diff and reports, and you aren't needed while it does.
37
-
38
- **5. Otherwise, `/compact`.** Relevant context, same harness, same directory, and you need to stay in the loop: this is where the tree lands, and it lands here often. Pass it an instruction (`/compact we're going to QA this area`) so the summary keeps what the next phase needs.
39
-
40
- `/compact` is the **default, not the first reach**. It sits at the bottom because the four questions above it are all cheaper or more precise. The failure mode when people start here is a fresh session that is confidently wrong about a decision the summary flattened.
41
-
42
- ## Primary and secondary sources
43
-
44
- Every move except **Continue** turns a **primary source** into a **secondary source**: the session as it happened, replaced by a summary of it. The trade is always the same shape:
45
-
46
- | Source | Information | Noise | Room to move |
47
- | --------------------------------- | ----------- | ----- | ------------ |
48
- | Primary (Continue) | Full | Lots | Little |
49
- | Secondary (`/compact`, `/handoff`) | Lossy | Less | Lots |
50
-
51
- This is why question 1 comes first. You only pay the lossiness when staying costs more than it saves.
52
-
53
- ## These are judgement calls
54
-
55
- The questions are not objective: each has taste in it, and the same boundary can go two ways on two days. The value is in asking them **in order**, at the boundary rather than in the middle of the work.
@@ -1,80 +0,0 @@
1
- ---
2
- name: ask-matt
3
- description: Ask which /command fits your situation. A router over the installed skills, all of which are invoked by the user, never by the model.
4
- disable-model-invocation: true
5
- user-invocable: true
6
- ---
7
-
8
- # Ask Matt
9
-
10
- You don't remember every skill, so ask. Describe the situation and get back **one next `/command` to type**, and why.
11
-
12
- Every skill in this set is **user-invoked**: none of them appear in the model's catalog and the model cannot load one on its own. Only the user typing `/name` brings a skill in. That shapes how this router works:
13
-
14
- - Recommend **one command per step**, named exactly, so the user can type it.
15
- - When a skill needs another one, its body points at a file (for example `../tdd/SKILL.md`) that you can read directly. Reading such a file is not invoking the skill; it is following the instructions already in front of you.
16
- - Before describing what a skill does or recommending that a step be skipped, read that skill's `SKILL.md`. The summaries here are for orientation only.
17
-
18
- A **flow** is a path through the skills. Most paths run along one **main flow**, and a few **on-ramps** merge onto it.
19
-
20
- ## The main flow: idea → ship
21
-
22
- 1. **`/grilling`** sharpens the idea by interview. With `--docs` it is stateful: decisions land in `GLOSSARY.md` and ADRs as you go. Use `--docs` whenever there is a working directory to leave a paper trail in; use the plain mode for a plan, a design, or a piece of writing with no repo under it.
23
- 2. **Branch: can you settle every question in conversation?** If a question needs a runnable answer (state, business logic, a UI you have to see), detour through a prototype:
24
- - **`/handoff`** out, then open a fresh session against that file,
25
- - **`/prototype`** to answer the question with throwaway code,
26
- - **`/handoff`** back what you learned, and reference it from the original idea thread.
27
- 3. **Branch: is this a multi-session build?**
28
- - **Yes** → **`/to-spec`** (turn the thread into a spec), then **`/to-tickets`** to split it into tracer-bullet tickets, each declaring its **blocking edges**.
29
- - **No** → **`/implement`** right here, in the same context window.
30
- 4. **`/implement`** does the build either way, in one of its two shapes: hand it a spec and it treats the tickets as a **task graph**, running implementer subagents across the ready **frontier** in parallel and landing everything on one **integration branch**; hand it a single ticket and it builds that on the current branch. Both drive `/tdd` (one red-green slice at a time) and close with `/code-review`.
31
- 5. **`/pr`** shapes the body when the work goes up as a pull request: the smallest visual that shows the change, before/after evidence that it works, and a one-way or two-way door call.
32
- 6. **`/retro`** closes the loop. It looks back over the session and suggests changes to the agent's **environment**, not the code: navigation pointers, automated checks, the coding standards `/code-review` enforces, steering files, tooling. Mechanical mistakes become deterministic checks; judgement calls become coding standards.
33
-
34
- Reach for **`/tdd`** on its own when you just want to build one concrete behaviour test-first without a spec, and **`/code-review`** on its own whenever you want a branch or PR reviewed against a fixed point.
35
-
36
- ### Context hygiene
37
-
38
- Keep the grilling, the spec, and the tickets in **one unbroken context window** so they build on the same thinking. Each `/implement` then starts fresh from the ticket. Run `/retro` in the session it looks back on, before you clear.
39
-
40
- The limit is the window in which the model still reasons sharply (roughly 150k tokens for current models). If a session approaches it before `/to-tickets`, do not push on degraded: compact or split at the nearest phase boundary and carry on.
41
-
42
- ## On-ramps
43
-
44
- A starting situation that generates work, then merges onto the main flow.
45
-
46
- - **Bugs and requests piling up** → **`/triage`**. It moves issues through triage roles and produces agent-ready issues, which `/implement` later picks up. Triage is only for issues **you didn't create**: bug reports, incoming requests, anything that arrives raw. Tickets that `/to-tickets` produced are already agent-ready, so don't triage them.
47
- - **Something's broken** → **`/diagnosing-bugs`**. For the hard ones: the bug that resists a first glance, the intermittent flake, the regression that crept in between two known-good states. It refuses to theorise until it has a **tight feedback loop** (one command that already goes red on *this* bug), then fixes with a regression test. After the fix, run `/retro` to ask what would have prevented it; if the real finding is that there is no good seam to lock it down, that is a job for `/improve-codebase-architecture`.
48
- - **A huge, foggy effort, too big for one session** → **`/wayfinder`**, the most cognitively demanding flow here. When the way from here to the destination isn't visible yet, it charts a **shared map** of decision tickets and resolves them one at a time, producing **decisions, not deliverables**, until the fog clears. Where `/grilling --docs` sharpens an idea you can hold in one session, wayfinder is for the idea you can't: slower and denser, so never use it on a well-scoped feature. When the map clears it **hands off, it doesn't build**: merge back into the main flow at `/to-spec`.
49
- - **You have a spare moment to keep the codebase healthy** → **`/improve-codebase-architecture`**. It surveys for **deepening opportunities** and presents them as a visual report; picking one generates an idea you take back to `/grilling --docs`.
50
-
51
- ## Vocabulary underneath
52
-
53
- Two references that run *beneath* the other skills, each the single source of truth for its vocabulary. Reach for them directly when the **words**, not the process, are the problem, or follow them when a skill above points at them.
54
-
55
- - **`/domain-modeling`**: sharpen the project's *domain* language: challenge a fuzzy term, resolve an overloaded word ("account" doing three jobs), record a hard-to-reverse decision as an ADR. This is the discipline `/grilling --docs` drives to keep `GLOSSARY.md` a clean glossary.
56
- - **`/codebase-design`**: the deep-module vocabulary (module, interface, depth, seam, adapter, leverage, locality) for designing a module's *shape*: a lot of behaviour behind a small interface at a clean seam. `/tdd` and `/improve-codebase-architecture` both speak it.
57
-
58
- ## Phase boundaries
59
-
60
- A **phase** is a chunk of work inside a session: the grilling, the implementation, the QA. At the boundary between two of them you have five options, and picking between them is the fuzziest decision in this whole map: **continue**, **clear** the window, **`/handoff`** a portable file, send a **subagent**, or **compact**. Read [PHASE-BOUNDARIES.md](PHASE-BOUNDARIES.md) for the ordered tree, the reasoning behind each branch, and why "Continue" is the one to rule out first. `/handoff` is narrow: a new harness, a new directory, a colleague, or forking a side task mid-phase. What it buys is portability.
61
-
62
- ## Standalone
63
-
64
- Off the main flow entirely.
65
-
66
- - **`/research`**: delegate reading legwork to a background agent. It investigates against **primary sources**, then leaves a cited Markdown file in the repo. Keep working while it reads. Research feeds thinking rather than replacing it, so take its file into `/grilling --docs`.
67
- - **`/prototype`**: a small, throwaway program that answers one design question: does this state model feel right, or what should this UI look like. Throwaway is a constraint on how the code is written, not a promise to destroy it: the answer folds into the real code, and the prototype itself is kept as a **primary source** on a `prototype/<name>` branch, pointed at from the implementation issue.
68
- - **`/wizard`**: for the steps only a **human** can take: provisioning infrastructure, setting up credentials or CI secrets, clicking through an unfamiliar dashboard, running a one-off migration. It generates an interactive bash script that opens each URL, captures each value, and writes it into `.env` and secrets, so the procedure stops being something you re-explain every time. If you could just do it yourself, do it yourself; this is for where a human is genuinely in the loop.
69
- - **`/to-questionnaire`**: when the thing blocking you isn't in your head or the codebase but in **someone else's**. It writes them a questionnaire to fill in, interviewing you about the **send** (who it goes to, what you need back) and aiming the questions at the gap. What comes back is material for `/grilling --docs` or `/to-spec`.
70
- - **`/wait-what`**: the corrective for a message that didn't land. Use it mid-conversation, inside any other skill, and the agent re-pitches what it just said with the context you were missing, in plain English, using the `GLOSSARY.md` vocabulary.
71
- - **`/teach`**: learn a concept over multiple sessions, using the current directory as a stateful workspace.
72
- - **`/writing-for-agents`**: the reference for writing documents agents consume: skills, AGENTS.md, pointed-at docs.
73
- - **`/writing-fragments`** → **`/writing-beats`** or **`/writing-shape`**: writing a long piece. Fragments is explore (mine raw material, no structure). Beats is exploit as a choose-your-own-adventure journey; shape is exploit as a thesis-driven article grown paragraph by paragraph. Both read `../_shared/WRITING-MECHANICS.md` for the grounding accounting they share.
74
- - **`/loop-me`**: `/grilling` aimed at **workflow** specs, with its own vocabulary and definition of done.
75
- - **`/software-factory`**: the shared language for designing a system of agents that turns tickets, PRs, and schedules into merged code. Vocabulary, not a process.
76
- - **`/chief-of-staff`** and **`/setup-ts-deep-modules`**: the two heavier in-progress skills. Chief-of-staff pursues a long-running goal in one session by co-ordinating subagents; setup-ts-deep-modules wires dependency-cruiser into a TypeScript repo so each package is a deep module.
77
-
78
- ## Precondition
79
-
80
- **`/setup-matt-pocock-skills`**: run before your first engineering flow to configure the issue tracker, triage labels, and doc layout the other skills assume. Custom issue trackers also work.
@@ -1,5 +0,0 @@
1
- interface:
2
- display_name: "Ask Matt"
3
- short_description: "Find the right skill or workflow"
4
- policy:
5
- allow_implicit_invocation: false
@@ -1,76 +0,0 @@
1
- ---
2
- name: chief-of-staff
3
- description: Pursue a long-running goal in a single session by co-ordinating subagents.
4
- disable-model-invocation: true
5
- user-invocable: true
6
- ---
7
-
8
- You are a chief of staff, co-ordinating subagents and schedules to pursue a long-running goal. This session will run for a long time, accruing tribal knowledge and helping you make long-term strategic decisions.
9
-
10
- You are the Directly Responsible Individual for this goal. You are empowered to think much longer-term than you're used to. You must think on two tracks simultaneously:
11
-
12
- - Tactical: how do I complete the immediate task?
13
- - Strategic: how do I modify the environment to improve the outcomes of the _next_ task?
14
-
15
- ## Schedules
16
-
17
- Harness-permitting, you will suggest recurring schedules which can help in achieving the goal.
18
-
19
- ## Subagents
20
-
21
- All work should be done in subagents. Protect your context window.
22
-
23
- Use background agents so you can stay in active dialogue with the user. Start every subagent with a fresh context window.
24
-
25
- Communication to and from subagents should be sparse. Communicate primarily through **context pointers**: research notes, previous commits, wiki pages, and others. Don't duplicate information already available via pointers.
26
-
27
- ## Wiki
28
-
29
- Keep your memory in a **wiki**: a folder of interlinked markdown pages that outlives this session. Tribal knowledge that lives only in your context is lost at compaction; the wiki is how it reaches the next session. Look for a shared wiki first, one the user or other agents already keep, and write your pages into it, following its conventions where they differ from the ones below. Only if there is none, agree a location with the user before the first write.
30
-
31
- - `index.md` lists every page with a link and a one-line summary, grouped by category.
32
- - Each other page covers one thing: a decision, a recurring problem, a subsystem, a user preference. Link related pages to each other.
33
- - Sources (issues, PRs, transcripts, subagent reports) are never copied in or edited. Pages cite them.
34
-
35
- Three operations keep it alive:
36
-
37
- - **Ingest.** When you learn something durable (a decision, a user correction, a subagent's finding), update every page it touches and the index, not only a new page.
38
- - **Query.** Before a decision, read `index.md` and the pages it points to. If the answer you build is worth keeping, file it as a page.
39
- - **Lint.** Periodically look for contradictions, orphan pages, missing links and claims newer sources have overtaken. Suggest this as a schedule.
40
-
41
- ### Write history, not the present
42
-
43
- The wiki is a historical record. It never claims to describe how things are now, because it cannot keep up with the code.
44
-
45
- - Date every claim: "On 2026-10-13, Matt decided..."
46
- - When a claim concerns code, cite the commit it was true at, with its repo: "As of `mattpocock/skills@abc1234`, `retro` loads `writing-for-agents` in step 1."
47
- - Never write "currently", "now" or "is" about code without a date or commit beside it.
48
- - When something changes, add a new dated claim and mark the old one superseded. Don't rewrite the old one.
49
-
50
- ## Procedures
51
-
52
- Some procedures you run live in other skills, installed beside this one. To run one, read its `SKILL.md` at the path below, relative to this skill's directory, and follow it.
53
-
54
- - **Retro** (`../retro/SKILL.md`): run a retro on about one in five of your subagents' sessions, including those an `implement` run dispatches. Pick first the ones where something went wrong. In place of retro's last step, decide yourself which candidates are worth pursuing, then pursue them.
55
- - **Large chunks of work**: write a spec with `../to-spec/SKILL.md`, break it into tickets with `../to-tickets/SKILL.md`, publish both to the issue tracker, then implement them with `../implement/SKILL.md`.
56
-
57
- ## Strategic View
58
-
59
- As part of any and all work, FIRST consider how the environment the agents operate in might be improved. Agents thrive in the **pit of success**:
60
-
61
- - API's and functions which are extremely constrained and limited
62
- - Lint rules which force correctness
63
- - CODING_STANDARDS.md files which let code reviewers enforce best practices
64
-
65
- They also need relevant **data sources** to succeed:
66
-
67
- - Logs from critical running processes, like dev servers (or production logs)
68
- - Access to test environment databases
69
- - Access to the browser (when necessary) for clicking around and taking screenshots
70
-
71
- Finally, create environments (and codebases) that obey the **"no workarounds"** rule:
72
-
73
- - No one-off workarounds, or hacks that bypass established processes
74
- - Any deviations from conventions must be fixed proactively, before feature work is done
75
-
76
- Be relentless in improving the environment. Use every user message as an excuse to search for these improvements.
@@ -1,5 +0,0 @@
1
- interface:
2
- display_name: "Chief Of Staff"
3
- short_description: "Pursue a long-running goal in a single session by co-ordinating subagents"
4
- policy:
5
- allow_implicit_invocation: false
@@ -1,91 +0,0 @@
1
- ---
2
- name: code-review
3
- description: "Review the changes since a fixed point (commit, branch, tag, or merge-base) along two axes: Standards (does the code follow this repo's documented coding standards?) and Spec (does the code match what the originating issue/spec asked for?). Runs both reviews in parallel sub-agents and reports them side by side. Use when the user wants to review a branch, a PR, work-in-progress changes, or asks to \"review since X\"."
4
- disable-model-invocation: true
5
- user-invocable: true
6
- ---
7
-
8
- Two-axis review of the diff between `HEAD` and a fixed point the user supplies:
9
-
10
- - **Standards**: does the code conform to this repo's documented coding standards?
11
- - **Spec**: does the code faithfully implement the originating issue / spec?
12
-
13
- Both axes run as **parallel sub-agents** so they don't pollute each other's context, then this skill aggregates their findings. Start every sub-agent with a fresh context window.
14
-
15
- The issue tracker should have been provided to you. If not, tell the user to run `/setup-matt-pocock-skills`.
16
-
17
- ## Process
18
-
19
- ### 1. Pin the fixed point
20
-
21
- Whatever the user said is the fixed point (a commit SHA, branch name, tag, `main`, `HEAD~5`, etc.). If they didn't specify one, ask for it.
22
-
23
- Capture the diff command once: `git diff <fixed-point>...HEAD` (three-dot, so the comparison is against the merge-base). Also note the list of commits via `git log <fixed-point>..HEAD --oneline`.
24
-
25
- Before going further, confirm the fixed point resolves (`git rev-parse <fixed-point>`) and the diff is non-empty. A bad ref or empty diff should fail here, not inside two parallel sub-agents.
26
-
27
- ### 2. Identify the spec source
28
-
29
- Look for the originating spec, in this order:
30
-
31
- 1. Issue references in the commit messages (`#123`, `Closes #45`, GitLab `!67`, etc.), fetched via the workflow in the tracker doc.
32
- 2. A path the user passed as an argument.
33
- 3. A spec file under `docs/`, `specs/`, or `.scratch/` matching the branch name or feature.
34
- 4. If nothing is found, ask the user where the spec is. If they say there isn't one, the **Spec** sub-agent will skip and report "no spec available".
35
-
36
- ### 3. Identify the standards sources
37
-
38
- Search the repo for every file that documents how code should be written. When `CODING_STANDARDS.md` or `CONTRIBUTING.md` exists, it must be on the list.
39
-
40
- On top of whatever the repo documents, the Standards axis always carries the **smell baseline** below: a fixed set of Fowler code smells (_Refactoring_, ch.3) that applies even when a repo documents nothing. Two rules bind it:
41
-
42
- - **The repo overrides.** A documented repo standard always wins; where it endorses something the baseline would flag, suppress the smell.
43
- - **Always a judgement call.** Each smell is a labelled heuristic ("possible Feature Envy"), never a hard violation. Like any standard here, skip anything tooling already enforces.
44
-
45
- Each smell reads *what it is* → *how to fix*; match it against the diff:
46
-
47
- - **Mysterious Name**: a function, variable, or type whose name doesn't reveal what it does or holds. → rename it; if no honest name comes, the design's murky.
48
- - **Duplicated Code**: the same logic shape appears in more than one hunk or file in the change. → extract the shared shape, call it from both.
49
- - **Feature Envy**: a method that reaches into another object's data more than its own. → move the method onto the data it envies.
50
- - **Data Clumps**: the same few fields or params keep travelling together (a type wanting to be born). → bundle them into one type, pass that.
51
- - **Primitive Obsession**: a primitive or string standing in for a domain concept that deserves its own type. → give the concept its own small type.
52
- - **Repeated Switches**: the same `switch`/`if`-cascade on the same type recurs across the change. → replace with polymorphism, or one map both sites share.
53
- - **Shotgun Surgery**: one logical change forces scattered edits across many files in the diff. → gather what changes together into one module.
54
- - **Divergent Change**: one file or module is edited for several unrelated reasons. → split so each module changes for one reason.
55
- - **Speculative Generality**: abstraction, parameters, or hooks added for needs the spec doesn't have. → delete it; inline back until a real need shows.
56
- - **Message Chains**: long `a.b().c().d()` navigation the caller shouldn't depend on. → hide the walk behind one method on the first object.
57
- - **Middle Man**: a class or function that mostly just delegates onward. → cut it, call the real target direct.
58
- - **Refused Bequest**: a subclass or implementer that ignores or overrides most of what it inherits. → drop the inheritance, use composition.
59
-
60
- ### 4. Spawn both sub-agents in parallel
61
-
62
- Issue both sub-agent calls together, in the foreground, and aggregate the reports they return.
63
-
64
- **Standards sub-agent prompt** should include:
65
-
66
- - The full diff command and commit list.
67
- - The list of standards-source files you found in step 3, **plus the smell baseline from step 3** pasted in full (the sub-agent has no other access to it).
68
- - The brief: "Report, per file/hunk where relevant, (a) every place the diff violates a documented standard: cite the standard (file + the rule); and (b) any baseline smell you spot: name it and quote the hunk. Distinguish hard violations from judgement calls: documented-standard breaches can be hard, but baseline smells are always judgement calls, and a documented repo standard overrides the baseline. Skip anything tooling enforces. Under 400 words."
69
-
70
- **Spec sub-agent prompt** should include:
71
-
72
- - The diff command and commit list.
73
- - The path or fetched contents of the spec.
74
- - The brief: "Report: (a) requirements the spec asked for that are missing or partial; (b) behaviour in the diff that wasn't asked for (scope creep); (c) requirements that look implemented but where the implementation looks wrong. Quote the spec line for each finding. Under 400 words."
75
-
76
- If the spec is missing, skip the Spec sub-agent and note this in the final report.
77
-
78
- ### 5. Aggregate
79
-
80
- Present the two reports under `## Standards` and `## Spec` headings, verbatim or lightly cleaned. Do **not** merge or rerank findings, because the two axes are deliberately separate (see _Why two axes_).
81
-
82
- End with a one-line summary: total findings per axis, and the worst issue _within each axis_ (if any). Don't pick a single winner across axes: that's the reranking the separation exists to prevent.
83
-
84
- ## Why two axes
85
-
86
- A change can pass one axis and fail the other:
87
-
88
- - Code that follows every standard but implements the wrong thing → **Standards pass, Spec fail.**
89
- - Code that does exactly what the issue asked but breaks the project's conventions → **Spec pass, Standards fail.**
90
-
91
- Reporting them separately stops one axis from masking the other.
@@ -1,5 +0,0 @@
1
- interface:
2
- display_name: "Code Review"
3
- short_description: "Review a diff on standards and spec"
4
- policy:
5
- allow_implicit_invocation: false
@@ -1,37 +0,0 @@
1
- # Deepening
2
-
3
- How to deepen a cluster of shallow modules safely, given its dependencies. Assumes the vocabulary in [SKILL.md](SKILL.md): **module**, **interface**, **seam**, **adapter**.
4
-
5
- ## Dependency categories
6
-
7
- When assessing a candidate for deepening, classify its dependencies. The category determines how the deepened module is tested across its seam.
8
-
9
- ### 1. In-process
10
-
11
- Pure computation, in-memory state, no I/O. Always deepenable: merge the modules and test through the new interface directly. No adapter needed.
12
-
13
- ### 2. Local-substitutable
14
-
15
- Dependencies that have local test stand-ins (PGLite for Postgres, in-memory filesystem). Deepenable if the stand-in exists. The deepened module is tested with the stand-in running in the test suite. The seam is internal; no port at the module's external interface.
16
-
17
- ### 3. Remote but owned (Ports & Adapters)
18
-
19
- Your own services across a network boundary (microservices, internal APIs). Define a **port** (interface) at the seam. The deep module owns the logic; the transport is injected as an **adapter**. Tests use an in-memory adapter. Production uses an HTTP/gRPC/queue adapter.
20
-
21
- Recommendation shape: *"Define a port at the seam, implement an HTTP adapter for production and an in-memory adapter for testing, so the logic sits in one deep module even though it's deployed across a network."*
22
-
23
- ### 4. True external (Mock)
24
-
25
- Third-party services (Stripe, Twilio, etc.) you don't control. The deepened module takes the external dependency as an injected port; tests provide a mock adapter.
26
-
27
- ## Seam discipline
28
-
29
- - **One adapter means a hypothetical seam. Two adapters means a real one.** Don't introduce a port unless at least two adapters are justified (typically production + test). A single-adapter seam is just indirection.
30
- - **Internal seams vs external seams.** A deep module can have internal seams (private to its implementation, used by its own tests) as well as the external seam at its interface. Don't expose internal seams through the interface just because tests use them.
31
-
32
- ## Testing strategy: replace, don't layer
33
-
34
- - Old unit tests on shallow modules become waste once tests at the deepened module's interface exist; delete them.
35
- - Write new tests at the deepened module's interface. The **interface is the test surface**.
36
- - Tests assert on observable outcomes through the interface, not internal state.
37
- - Tests should survive internal refactors, since they describe behaviour, not implementation. If a test has to change when the implementation changes, it's testing past the interface.