@bluenyang/reins 0.2.0 → 0.3.0-rc.2

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 (97) hide show
  1. package/README.md +50 -203
  2. package/cli/dist/commands/config-models.js +206 -127
  3. package/cli/dist/commands/config.js +104 -16
  4. package/cli/dist/commands/configure.js +166 -134
  5. package/cli/dist/commands/install.js +161 -217
  6. package/cli/dist/commands/migrate.js +23 -48
  7. package/cli/dist/commands/update.js +203 -30
  8. package/cli/dist/lib/agents-md.js +111 -0
  9. package/cli/dist/lib/bindings.js +227 -386
  10. package/cli/dist/lib/detect.js +7 -2
  11. package/cli/dist/lib/generate.js +56 -75
  12. package/cli/dist/lib/harness.js +0 -3
  13. package/cli/dist/lib/migrate-plan.js +3 -3
  14. package/cli/dist/lib/prompter.js +4 -4
  15. package/cli/dist/lib/reader.js +20 -0
  16. package/cli/dist/lib/upstream.js +0 -17
  17. package/cli/dist/lib/vendor-write.js +9 -56
  18. package/cli/dist/reins.js +59 -270
  19. package/docs/README.ko.md +31 -204
  20. package/harness/CHANGELOG.md +8 -3
  21. package/harness/VERSION +1 -1
  22. package/harness/models.yaml +8 -0
  23. package/harness/policy/common-red-lines.yaml +4 -4
  24. package/harness/roles/advisor.md +10 -14
  25. package/harness/roles/auditor.md +17 -0
  26. package/harness/roles/executor.md +32 -0
  27. package/harness/roles/implementer.md +23 -21
  28. package/harness/roles/pl.md +44 -21
  29. package/harness/roles/planner.md +17 -19
  30. package/harness/roles/pm.md +16 -21
  31. package/harness/schemas/bindings.schema.json +55 -0
  32. package/harness/schemas/install.schema.json +1 -2
  33. package/harness/schemas/intent.schema.json +1 -13
  34. package/harness/templates/agents-md-blocks.md +52 -17
  35. package/harness/templates/audit.md +25 -0
  36. package/harness/templates/history.md +14 -0
  37. package/harness/templates/intent.md +5 -0
  38. package/harness/templates/spec.md +4 -2
  39. package/package.json +1 -2
  40. package/skills/audit/SKILL.md +28 -0
  41. package/skills/implement/SKILL.md +30 -0
  42. package/skills/intent/SKILL.md +28 -0
  43. package/skills/merge/SKILL.md +26 -0
  44. package/skills/onboard/SKILL.md +31 -0
  45. package/skills/reins-setup/SKILL.md +16 -25
  46. package/skills/release/SKILL.md +26 -0
  47. package/skills/retro/SKILL.md +30 -0
  48. package/skills/review/SKILL.md +27 -0
  49. package/skills/roadmap/SKILL.md +29 -0
  50. package/skills/spec/SKILL.md +27 -0
  51. package/skills/test/SKILL.md +26 -0
  52. package/cli/dist/commands/check.js +0 -379
  53. package/cli/dist/commands/gate.js +0 -136
  54. package/cli/dist/commands/knowledge.js +0 -111
  55. package/cli/dist/commands/metrics.js +0 -138
  56. package/cli/dist/commands/new.js +0 -190
  57. package/cli/dist/commands/retro.js +0 -7
  58. package/cli/dist/commands/stages.js +0 -562
  59. package/cli/dist/commands/status.js +0 -281
  60. package/cli/dist/lib/enforcement.js +0 -125
  61. package/cli/dist/lib/memory.js +0 -96
  62. package/cli/dist/lib/metrics.js +0 -223
  63. package/cli/dist/lib/retro.js +0 -179
  64. package/cli/dist/lib/verdict.js +0 -15
  65. package/cli/dist/lib/work.js +0 -106
  66. package/cli/dist/scripts/enforcement.js +0 -24
  67. package/harness/policy/budget.yaml +0 -13
  68. package/harness/policy/enforcement.yaml +0 -98
  69. package/harness/policy/stops.yaml +0 -29
  70. package/harness/policy/transitions.yaml +0 -13
  71. package/harness/roles/code-review.md +0 -27
  72. package/harness/roles/deploy.md +0 -50
  73. package/harness/roles/docs.md +0 -19
  74. package/harness/roles/lookup.md +0 -22
  75. package/harness/roles/qa-design.md +0 -22
  76. package/harness/roles/qa-run.md +0 -19
  77. package/harness/roles/verify-tool.md +0 -21
  78. package/harness/schemas/bindings-local.schema.json +0 -21
  79. package/harness/schemas/bus-request.schema.json +0 -17
  80. package/harness/schemas/bus-response.schema.json +0 -14
  81. package/harness/schemas/enforcement.schema.json +0 -22
  82. package/harness/schemas/plan.schema.json +0 -10
  83. package/harness/schemas/ticket.schema.json +0 -15
  84. package/harness/templates/bus/request.yaml +0 -20
  85. package/harness/templates/bus/response.yaml +0 -10
  86. package/harness/templates/plan.md +0 -23
  87. package/harness/templates/ticket.md +0 -29
  88. package/skills/reins-implement/SKILL.md +0 -20
  89. package/skills/reins-intent/SKILL.md +0 -26
  90. package/skills/reins-loop/SKILL.md +0 -26
  91. package/skills/reins-loop/references/vendor-cli.md +0 -41
  92. package/skills/reins-release/SKILL.md +0 -18
  93. package/skills/reins-retro/SKILL.md +0 -20
  94. package/skills/reins-review/SKILL.md +0 -23
  95. package/skills/reins-roadmap/SKILL.md +0 -17
  96. package/skills/reins-spec/SKILL.md +0 -22
  97. package/skills/reins-test/SKILL.md +0 -18
package/cli/dist/reins.js CHANGED
@@ -1,23 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFileSync } from 'node:fs';
3
3
  import { Command } from 'commander';
4
- import { runCheck, STAGES } from './commands/check.js';
5
4
  import { runInstall } from './commands/install.js';
6
5
  import { runMigrate } from './commands/migrate.js';
7
- import { acceptKnowledge, dismissKnowledge, proposeKnowledge } from './commands/knowledge.js';
8
- import { formatRetro, runRetro } from './commands/retro.js';
9
- import { runStatus } from './commands/status.js';
10
6
  import { formatUpdate, runUpdate } from './commands/update.js';
11
7
  import { configureBindings, configureGates } from './commands/configure.js';
12
- import { runConfig } from './commands/config.js';
13
- import { stateLabel } from './lib/bindings.js';
14
- import { respondRefusal, runGates, writeResponse } from './commands/gate.js';
15
- import { newIntent, newRequest, newTicket } from './commands/new.js';
16
- import { collectMetrics, formatMetrics, logCheck, logGates, recordUsage, } from './commands/metrics.js';
17
- import { repoRoot } from './lib/git.js';
8
+ import { formatBindings, runConfig } from './commands/config.js';
18
9
  import { defaultsAsker, stdinAsker } from './lib/ask.js';
19
10
  import { clackPrompter, isInteractive } from './lib/prompter.js';
20
- import { EXIT } from './lib/verdict.js';
21
11
  // the version npm installed — cli/dist/reins.js sits two levels below package.json
22
12
  const VERSION = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')).version;
23
13
  // every command: a reader that went away (`| head`) ends the run quietly with the exit code already set
@@ -28,36 +18,27 @@ process.stdout.on('error', (e) => {
28
18
  });
29
19
  const program = new Command()
30
20
  .name('reins')
31
- .description('agent harness — install, migrate, update; check keeps agents inside their roles')
21
+ .description('manages an agent harness — install, migrate, update, config; never called while a project works')
32
22
  .version(VERSION)
33
23
  .enablePositionalOptions();
34
- const notYet = (name) => () => {
35
- process.stderr.write(`reins ${name}: not implemented yet (see docs/design.md §11)\n`);
36
- process.exit(2);
37
- };
38
24
  program
39
25
  .command('install')
40
- .description('install the harness at a tier: harness | loop | graph')
41
- .argument('<tier>', 'harness | loop | graph')
26
+ .description('install the harness: settings, roles, stage skills, AGENTS.md blocks, hook proposals')
42
27
  .option('--mode <mode>', 'manual (ask) | auto (detect and apply defaults)', 'manual')
43
- .option('--hooks', 'add the reins check line to existing husky hooks (otherwise only proposed)')
28
+ .option('--hooks', 'add the project gate commands to existing husky hooks (otherwise only proposed)')
44
29
  .option('--dry-run', 'show what would be written')
45
30
  .option('--json')
46
- .action(async (tier, o) => {
47
- if (!['harness', 'loop', 'graph'].includes(tier)) {
48
- process.stderr.write(`reins install: tier must be harness, loop or graph (got "${tier}")\n`);
49
- process.exit(2);
50
- }
31
+ .action(async (o) => {
51
32
  // screens only on a terminal, in manual mode, without --json; otherwise the line-based questions
52
33
  const screens = o.mode === 'manual' && !o.json && isInteractive();
53
34
  const asker = o.mode === 'auto' || screens ? defaultsAsker : await stdinAsker();
54
35
  const r = await runInstall({
55
- tier: tier,
56
36
  mode: o.mode,
57
37
  hooks: o.hooks,
58
38
  dryRun: o.dryRun,
59
39
  asker,
60
40
  prompter: screens ? await clackPrompter() : undefined,
41
+ confirmHooks: !o.json && !o.dryRun && isInteractive() ? await clackPrompter() : undefined,
61
42
  });
62
43
  asker.close();
63
44
  if (o.json) {
@@ -74,7 +55,7 @@ program
74
55
  }
75
56
  const a = r.applied;
76
57
  const verb = o.dryRun ? 'would write' : 'wrote';
77
- process.stdout.write(`reins install ${tier} — generation before: ${r.generation}\n`);
58
+ process.stdout.write(`reins install — generation before: ${r.generation}\n`);
78
59
  process.stdout.write(`${verb}: ${a.created.length} new, ${a.changed.length} changed; ${a.unchanged.length} already up to date\n`);
79
60
  for (const p of a.created)
80
61
  process.stdout.write(` + ${p}\n`);
@@ -82,29 +63,21 @@ program
82
63
  process.stdout.write(` ~ ${p}\n`);
83
64
  for (const n of r.notes)
84
65
  process.stdout.write(`• ${n}\n`);
85
- if (r.history)
86
- process.stdout.write(`recorded: ${r.history}\n`);
87
66
  });
88
67
  program
89
68
  .command('migrate')
90
69
  .description('move an existing harness or .ai/ workspace onto the reins layout')
91
- .argument('<tier>', 'harness | loop | graph')
92
70
  .option('--mode <mode>', 'manual | auto', 'manual')
93
71
  .option('--legacy <where>', 'local (.loctx/_legacy/) | committed (.agents/legacy/)', 'local')
94
72
  .option('--dry-run', 'show the moves without touching anything')
95
73
  .option('--json')
96
- .action(async (tier, o) => {
74
+ .action(async (o) => {
97
75
  if (!['local', 'committed'].includes(o.legacy)) {
98
76
  process.stderr.write(`reins migrate: --legacy must be local or committed (got "${o.legacy}")\n`);
99
77
  process.exit(2);
100
78
  }
101
- if (!['harness', 'loop', 'graph'].includes(tier)) {
102
- process.stderr.write(`reins migrate: tier must be harness, loop or graph (got "${tier}")\n`);
103
- process.exit(2);
104
- }
105
79
  const asker = o.mode === 'auto' || o.dryRun ? defaultsAsker : await stdinAsker();
106
80
  const r = await runMigrate({
107
- tier: tier,
108
81
  mode: o.mode,
109
82
  dryRun: o.dryRun,
110
83
  legacy: o.legacy,
@@ -120,36 +93,36 @@ program
120
93
  process.exit(2);
121
94
  }
122
95
  const by = (k) => r.moves.filter((m) => m.result === k).length;
123
- process.stdout.write(`reins migrate ${tier} — from ${r.generation}${o.dryRun ? ' (dry run)' : ''}\n`);
96
+ process.stdout.write(`reins migrate — from ${r.generation}${o.dryRun ? ' (dry run)' : ''}\n`);
124
97
  process.stdout.write(o.dryRun
125
98
  ? `would move ${r.moves.length} files\n`
126
- : `moved ${by('moved')} · tickets ${by('converted')} · identical ${by('same')} · kept both ${by('kept-both')}\n`);
99
+ : `moved ${by('moved')} · converted ${by('converted')} · identical ${by('same')} · kept both ${by('kept-both')}\n`);
127
100
  if (o.dryRun)
128
101
  for (const m of r.moves)
129
102
  process.stdout.write(` ${m.action === 'move' ? ' ' : m.action[0]} ${m.from} → ${m.to}\n`);
130
- process.stdout.write(`AGENTS.md: swapped ${r.agents.swapped.join(', ') || 'none'}; inserted ${r.agents.inserted.join(', ') || 'none'}\n`);
131
103
  for (const n of r.report)
132
104
  process.stdout.write(`• ${n}\n`);
133
- if (r.history)
134
- process.stdout.write(`recorded: ${r.history}\n`);
135
105
  });
136
106
  program
137
107
  .command('update')
138
- .description('re-apply the packaged harness: upstream files, managed blocks, vendor files, version pin')
108
+ .description('re-apply the packaged harness; ask before overwriting hand-edited files; move 0.x installs to 0.3')
139
109
  .option('--dry-run', 'show what would change')
140
- .option('--yes', 'do not ask for confirmation')
110
+ .option('--yes', 'do not ask for confirmation (also deletes the listed 0.x working files)')
111
+ .option('--force', 'overwrite generated files edited by hand')
141
112
  .option('--json')
142
113
  .action(async (o) => {
143
114
  // on a terminal, show the plan and ask first (design §9); otherwise run as before
144
115
  const confirm = !o.yes && !o.dryRun && !o.json && isInteractive();
145
116
  const r = await runUpdate({
146
117
  dryRun: o.dryRun,
118
+ force: o.force,
119
+ yes: o.yes,
147
120
  prompter: confirm ? await clackPrompter() : undefined,
148
121
  show: (plan) => process.stdout.write(formatUpdate(plan, true)),
149
122
  });
150
123
  if (o.json) {
151
124
  process.stdout.write(`${JSON.stringify(r, null, 2)}\n`);
152
- process.exit(r.refused ? 2 : 0);
125
+ process.exit(r.refused ? 2 : r.handEdited.length && !o.dryRun ? 1 : 0);
153
126
  }
154
127
  if (r.refused) {
155
128
  process.stderr.write(`reins update: ${r.refused}\n`);
@@ -160,55 +133,66 @@ program
160
133
  process.exit(0);
161
134
  }
162
135
  process.stdout.write(formatUpdate(r, !!o.dryRun));
136
+ if (r.handEdited.length && !o.dryRun)
137
+ process.exit(1);
163
138
  });
164
- program
139
+ const config = program
165
140
  .command('config')
166
- .description('settings screen on a terminal; the resolved bindings table otherwise')
167
- .option('--json', 'print the resolved bindings as JSON (no screen)')
141
+ .alias('configure')
142
+ .description('settings: models and roles, agent tools, mode, audit; a screen on a terminal');
143
+ config
144
+ .command('screen', { isDefault: true, hidden: true })
145
+ .option('--json', 'print the effective settings as JSON (no screen)')
168
146
  .action(async (o) => {
169
147
  process.exit(await runConfig({ json: o.json }));
170
148
  });
171
- const configure = program.command('configure').description('change project-owned settings');
172
- configure
149
+ config
173
150
  .command('bindings')
174
- .description('bind roles to models: --set role=model … or --vendors claude,openai,…; no options asks')
175
- .option('--set <pairs...>', 'role=model pairs')
176
- .option('--vendors <list>', 'rebuild every role from its defaults for these vendors (comma-separated)')
177
- .option('--local', 'with --set: write your own override to .loctx/bindings.local.yaml')
178
- .option('--disable <roles...>', 'switch roles off (pm, implementer and verify-tool cannot be)')
179
- .option('--enable <roles...>', 'switch roles on again')
180
- .option('--show', 'print what each role actually runs on')
151
+ .description('change the model assignment without a screen')
152
+ .option('--set <pairs...>', 'default|<group>|<group>.<role>=<model> or =<vendor>:<model>')
153
+ .option('--models <pairs...>', '<pl|advisor>=<model>,<model>,… (several models)')
154
+ .option('--off <groups...>', 'switch groups off (the PM does their work)')
155
+ .option('--mode <mode>', 'single | multi')
156
+ .option('--audit <state>', 'on | off — the per-version audit')
157
+ .option('--tools <pairs...>', '<tool>=on|off')
158
+ .option('--detect', 'detect the agent tools again')
159
+ .option('--local', 'write your own override to .loctx/bindings.local.yaml')
160
+ .option('--show', 'print the effective settings')
181
161
  .option('--json')
182
162
  .action(async (o) => {
183
- const asker = !o.set && !o.vendors && !o.local && !o.show && !o.disable && !o.enable
184
- ? await stdinAsker()
185
- : undefined;
163
+ if (o.mode && o.mode !== 'single' && o.mode !== 'multi') {
164
+ process.stderr.write(`reins config bindings: --mode must be single or multi\n`);
165
+ process.exit(1);
166
+ }
167
+ if (o.audit && o.audit !== 'on' && o.audit !== 'off') {
168
+ process.stderr.write(`reins config bindings: --audit must be on or off\n`);
169
+ process.exit(1);
170
+ }
186
171
  const r = await configureBindings({
172
+ set: o.set,
173
+ models: o.models,
174
+ off: o.off,
175
+ mode: o.mode,
176
+ audit: o.audit,
177
+ tools: o.tools,
178
+ detect: o.detect,
187
179
  local: o.local,
188
180
  show: o.show,
189
- set: o.set,
190
- disable: o.disable,
191
- enable: o.enable,
192
- vendors: o.vendors?.split(',').map((s) => s.trim()),
193
- asker,
194
181
  });
195
- asker?.close();
196
182
  if (o.json) {
197
183
  process.stdout.write(`${JSON.stringify(r, null, 2)}\n`);
198
184
  process.exit(r.refused ? (r.code ?? 2) : 0);
199
185
  }
200
186
  if (r.refused) {
201
- process.stderr.write(`reins configure bindings: ${r.refused}\n`);
187
+ process.stderr.write(`reins config bindings: ${r.refused}\n`);
202
188
  process.exit(r.code ?? 2);
203
189
  }
204
- if (o.show || o.local) {
205
- for (const t of r.resolved ?? [])
206
- process.stdout.write(` ${r.changed.includes(t.role) ? '*' : ' '} ${t.role.padEnd(12)} ${t.vendor.padEnd(7)} ${t.model} (${t.source}: ${t.reason})${stateLabel(t) ? ` ${stateLabel(t)}` : ''}\n`);
207
- }
208
- else
209
- for (const t of r.table)
210
- process.stdout.write(` ${r.changed.includes(t.role) ? '*' : ' '} ${t.role.padEnd(12)} ${t.vendor.padEnd(7)} ${t.model}\n`);
211
- process.stdout.write(r.changed.length ? `changed: ${r.changed.join(', ')}\n` : 'no change\n');
190
+ if (r.doc)
191
+ process.stdout.write(`${formatBindings(r.doc)}\n`);
192
+ if (!o.show)
193
+ process.stdout.write(r.changed.length ? `changed: ${r.changed.join(', ')}\n` : 'no change\n');
194
+ if (r.modeChanged)
195
+ process.stdout.write('• AGENTS.md has a mode-changed note — the PM checks the project sections in the next conversation\n');
212
196
  const g = r.generated;
213
197
  if (g) {
214
198
  for (const p of g.written)
@@ -219,7 +203,7 @@ configure
219
203
  process.stdout.write(`• left alone ${x.path}: ${x.why}\n`);
220
204
  }
221
205
  });
222
- configure
206
+ config
223
207
  .command('gates')
224
208
  .description('subdirectory gate proposals not in gates.yaml; --add <name>… appends them')
225
209
  .option('--add <names...>', 'proposal names to append after the existing gates')
@@ -231,7 +215,7 @@ configure
231
215
  process.exit(r.code ?? 0);
232
216
  }
233
217
  if (r.refused) {
234
- process.stderr.write(`reins configure gates: ${r.refused}\n`);
218
+ process.stderr.write(`reins config gates: ${r.refused}\n`);
235
219
  process.exit(r.code ?? 2);
236
220
  }
237
221
  for (const n of r.added)
@@ -241,199 +225,4 @@ configure
241
225
  for (const g of r.available)
242
226
  process.stdout.write(` ${g.name} ${g.cmd} (${g.from})\n`);
243
227
  });
244
- program
245
- .command('gate')
246
- .description('run gates.yaml gates as declared; raw output goes to .loctx/reports/ as T3 evidence')
247
- .argument('[names...]', 'gates to run (default: the declared order)')
248
- .option('--ticket <id>', 'name the reports after this ticket')
249
- .option('--all', 'keep going after a failure')
250
- .option('--respond', 'with --ticket: write the bus response for the open verify request (one line per gate on stdout)')
251
- .option('--json')
252
- .action((names, o) => {
253
- const refusal = o.respond ? respondRefusal(names) : null;
254
- if (refusal) {
255
- process.stderr.write(`reins gate: ${refusal}\n`);
256
- process.exit(2);
257
- }
258
- if (o.respond && !o.ticket) {
259
- process.stderr.write('reins gate: --respond needs --ticket <id>\n');
260
- process.exit(2);
261
- }
262
- const r = runGates({ names, ticket: o.ticket, all: o.all });
263
- logGates(r.runs, { ticket: o.ticket });
264
- const resp = o.respond && o.ticket && !r.refused
265
- ? writeResponse(repoRoot(process.cwd()), o.ticket, r.runs)
266
- : null;
267
- if (o.json)
268
- process.stdout.write(`${JSON.stringify(resp ? { ...r, respond: resp } : r, null, 2)}\n`);
269
- else if (r.refused)
270
- process.stderr.write(`reins gate: ${r.refused}\n`);
271
- else
272
- for (const g of r.runs)
273
- process.stdout.write(` ${g.skipped ? '-' : g.exit === 0 ? 'ok' : 'FAIL'} ${g.gate.padEnd(10)} ${g.skipped ?? `exit ${g.exit} → ${g.report}`}\n`);
274
- if (resp && !o.json) {
275
- for (const [gate, s] of Object.entries(resp.summaries))
276
- process.stdout.write(` ! ${gate}: ${s}\n`);
277
- if (resp.response)
278
- process.stdout.write(`response: ${resp.response} (${resp.verdict})\n`);
279
- else
280
- process.stderr.write(`reins gate: no response written — ${resp.refused}\n`);
281
- }
282
- process.exit(r.refused ? 2 : resp?.refused ? 1 : r.runs.every((g) => g.exit === 0) ? 0 : 1);
283
- });
284
- const done = (r) => {
285
- process.stdout.write(r.stdout);
286
- process.stderr.write(r.stderr);
287
- process.exit(r.code);
288
- };
289
- const nw = program
290
- .command('new')
291
- .description('create an intent, ticket or bus request from the templates (no prompts, never overwrites)');
292
- nw.command('intent')
293
- .argument('<slug>')
294
- .option('--version <v>', 'target version')
295
- .option('--origin <o>', 'user | agent | incident')
296
- .action((slug, o) => done(newIntent(process.cwd(), slug, o)));
297
- nw.command('ticket')
298
- .argument('<intent>')
299
- .argument('<step>', "the plan's order-of-work step")
300
- .argument('<slug>')
301
- .option('--title <t>')
302
- .option('--depends <ids>', 'comma separated ticket ids')
303
- .option('--role <r>')
304
- .option('--release <r>', 'planned | stabilization')
305
- .action((intent, step, slug, o) => done(newTicket(process.cwd(), intent, step, slug, o)));
306
- nw.command('request')
307
- .argument('<ticket>')
308
- .argument('<kind>', 'implement | verify | review | question | stop-report')
309
- .option('--from <r>')
310
- .option('--to <r>')
311
- .action((ticket, kind, o) => done(newRequest(process.cwd(), ticket, kind, o)));
312
- program
313
- .command('status')
314
- .description('where the project stands: harness, intents, tickets, bus, last history (read-only)')
315
- .option('--json')
316
- .action((o) => {
317
- const r = runStatus({ json: o.json });
318
- process.stdout.write(r.stdout);
319
- process.stderr.write(r.stderr);
320
- process.exit(r.code);
321
- });
322
- const metrics = program
323
- .command('metrics')
324
- .enablePositionalOptions()
325
- .description('what the loop cost and where it stopped: counts, tokens by role and vendor, per ticket and intent')
326
- .option('--intent <NNN>', 'only this intent')
327
- .option('--json')
328
- .action((o) => {
329
- const m = collectMetrics({ intent: o.intent });
330
- process.stdout.write(o.json ? `${JSON.stringify(m, null, 2)}\n` : formatMetrics(m));
331
- });
332
- metrics
333
- .command('record')
334
- .description('append a usage line: tokens a role run used (the caller reports; reins calls no model)')
335
- .requiredOption('--role <role>', 'a role in bindings.yaml')
336
- .requiredOption('--tokens <n>', 'whole number ≥ 0')
337
- .option('--ticket <id>', 'the ticket the run served (fills the intent)')
338
- .option('--intent <NNN>', 'the intent, when there is no ticket')
339
- .option('--vendor <v>', 'default: the binding of --role')
340
- .option('--model <m>', 'default: the binding of --role')
341
- .option('--note <text>')
342
- .option('--json')
343
- .action((o) => {
344
- const r = recordUsage(o);
345
- if (r.refused) {
346
- process.stderr.write(`reins metrics record: ${r.refused}\n`);
347
- process.exit(2);
348
- }
349
- const u = r.record;
350
- process.stdout.write(o.json
351
- ? `${JSON.stringify(u, null, 2)}\n`
352
- : `recorded: ${u.role} (${u.vendor}/${u.model}) ${u.tokens} tokens${u.ticket ? ` · ticket ${u.ticket}` : ''}${u.intent ? ` · intent ${u.intent}` : ''}\n`);
353
- });
354
- program
355
- .command('retro')
356
- .description('what repeated: stop ids, review reasons, decisions, failed rounds, tokens; knowledge candidates')
357
- .option('--release <v>', 'only the intents whose version is v')
358
- .option('--json')
359
- .action((o) => {
360
- const r = runRetro({ release: o.release });
361
- process.stdout.write(o.json ? `${JSON.stringify(r, null, 2)}\n` : formatRetro(r));
362
- });
363
- const knowledge = program
364
- .command('knowledge')
365
- .description('promote a repeated key to a knowledge entry');
366
- const knowledgeDone = (verb, r) => {
367
- if (r.refused) {
368
- process.stderr.write(`reins knowledge ${verb}: ${r.refused}\n`);
369
- process.exit(1);
370
- }
371
- process.stdout.write(`${r.path}\n`);
372
- };
373
- knowledge
374
- .command('propose')
375
- .description('write a draft to .loctx/knowledge-proposals/ (records no approval)')
376
- .argument('<key>', 'a retro key (decision:<slug>) or a slug')
377
- .option('--from <history...>', 'history pages that back it')
378
- .action((key, o) => knowledgeDone('propose', proposeKnowledge(key, o)));
379
- knowledge
380
- .command('accept')
381
- .description('after the user approves: write .agents/knowledge/<date>_<slug>.md with approved')
382
- .argument('<draft>', 'the draft slug')
383
- .action((draft) => knowledgeDone('accept', acceptKnowledge(draft)));
384
- knowledge
385
- .command('dismiss')
386
- .description('record that a candidate is not a lesson; it returns when it repeats further')
387
- .argument('<key>', 'a candidate key as reins retro prints it')
388
- .requiredOption('--reason <text>', 'why it is not a lesson')
389
- .action((key, o) => knowledgeDone('dismiss', dismissKnowledge(key, o)));
390
- for (const n of ['recall', 'doctor'])
391
- program.command(n).allowUnknownOption().allowExcessArguments().action(notYet(n));
392
- program
393
- .command('check')
394
- .description(`harness verifier: --stage ${STAGES.join('|')}, or --drift`)
395
- .option('--stage <stage>', 'T1 ticket-start · T2 pre-commit · T3 verdict · T4 pre-push · T5 rc-close')
396
- .option('--ticket <id>', 'ticket-start, verdict: the ticket id')
397
- .option('--release <version>', 'rc-close: the version the rc closes')
398
- .option('--stable', "rc-close: print the stable dispatch lines (the user's instruction only)")
399
- .option('--drift')
400
- .option('--json')
401
- .action(async (o) => {
402
- if (o.stage && !STAGES.includes(o.stage)) {
403
- process.stderr.write(`reins check: unknown stage "${o.stage}" (${STAGES.join(', ')})\n`);
404
- process.exit(2);
405
- }
406
- const stage = o.stage;
407
- let pushRefs = [];
408
- if (stage === 'pre-push' && !process.stdin.isTTY) {
409
- const chunks = [];
410
- for await (const c of process.stdin)
411
- chunks.push(c);
412
- pushRefs = Buffer.concat(chunks).toString('utf8').split('\n').filter(Boolean);
413
- }
414
- const r = runCheck({
415
- stage,
416
- drift: o.drift,
417
- pushRefs,
418
- ticket: o.ticket,
419
- release: o.release,
420
- stable: o.stable,
421
- });
422
- // S-8: the verdict code is set before anything is printed, so a closed pipe cannot change it
423
- process.exitCode = EXIT[r.verdict];
424
- process.stdout.on('error', (e) => {
425
- if (e.code === 'EPIPE')
426
- process.exit(process.exitCode ?? 0);
427
- throw e;
428
- });
429
- logCheck(r, { ticket: o.ticket });
430
- if (o.json)
431
- process.stdout.write(`${JSON.stringify(r, null, 2)}\n`);
432
- else {
433
- process.stdout.write(`${r.summary}\n`);
434
- for (const f of r.findings)
435
- process.stdout.write(` [${f.reason} ${f.verdict}] ${f.path ? `${f.path}: ` : ''}${f.message}${f.resume ? `\n → ${f.resume}` : ''}\n`);
436
- }
437
- process.exit(EXIT[r.verdict]);
438
- });
439
228
  program.parseAsync(process.argv);