@bluenyang/reins 0.1.0 → 0.1.1

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 (37) hide show
  1. package/README.md +25 -26
  2. package/cli/dist/commands/check.js +180 -90
  3. package/cli/dist/commands/configure.js +79 -0
  4. package/cli/dist/commands/gate.js +54 -0
  5. package/cli/dist/commands/install.js +80 -30
  6. package/cli/dist/commands/metrics.js +138 -0
  7. package/cli/dist/commands/stages.js +435 -0
  8. package/cli/dist/commands/status.js +249 -0
  9. package/cli/dist/commands/update.js +70 -0
  10. package/cli/dist/lib/blocks.js +6 -1
  11. package/cli/dist/lib/detect.js +91 -1
  12. package/cli/dist/lib/fsx.js +8 -3
  13. package/cli/dist/lib/generate.js +143 -0
  14. package/cli/dist/lib/git.js +12 -1
  15. package/cli/dist/lib/harness.js +15 -4
  16. package/cli/dist/lib/metrics.js +223 -0
  17. package/cli/dist/lib/reader.js +47 -0
  18. package/cli/dist/lib/schema.js +23 -2
  19. package/cli/dist/lib/skills.js +13 -2
  20. package/cli/dist/lib/upstream.js +8 -0
  21. package/cli/dist/lib/vendor-write.js +136 -0
  22. package/cli/dist/lib/work.js +106 -0
  23. package/cli/dist/reins.js +161 -7
  24. package/docs/README.ko.md +25 -27
  25. package/harness/CHANGELOG.md +5 -0
  26. package/harness/VERSION +1 -1
  27. package/harness/policy/stops.yaml +2 -2
  28. package/harness/policy/transitions.yaml +1 -1
  29. package/harness/roles/code-review.md +6 -3
  30. package/harness/roles/pl.md +2 -1
  31. package/harness/roles/qa-design.md +1 -1
  32. package/harness/roles/qa-run.md +1 -1
  33. package/harness/templates/bus/request.yaml +8 -2
  34. package/harness/templates/bus/response.yaml +1 -0
  35. package/package.json +9 -2
  36. package/skills/reins-loop/SKILL.md +5 -1
  37. package/skills/reins-loop/references/vendor-cli.md +40 -0
@@ -1,17 +1,21 @@
1
1
  import { existsSync, readFileSync, readdirSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
- import { stringify } from 'yaml';
3
+ import { parse, stringify } from 'yaml';
4
4
  import { applyBlocks, parseBlocks } from '../lib/blocks.js';
5
- import { discoverGates, generation, stacks, vendors, } from '../lib/detect.js';
5
+ import { CONFIRMED_MODELS, checkBinding, discoverGates, newModelCache, vendorOf, generation, stacks, vendors, } from '../lib/detect.js';
6
6
  import { apply, listFiles } from '../lib/fsx.js';
7
7
  import { repoRoot } from '../lib/git.js';
8
- import { splitFrontmatter } from '../lib/skills.js';
9
- import { harnessVersion, packageHarness } from '../lib/upstream.js';
8
+ import { SKILLS_INDEX_HEADER, skillsIndex, splitFrontmatter } from '../lib/skills.js';
9
+ import { harnessVersion, packageHarness, packageSkills, tierSkills } from '../lib/upstream.js';
10
+ import { generateVendorFiles } from '../lib/generate.js';
11
+ import { writeGenerated } from '../lib/vendor-write.js';
10
12
  /** Which upstream harness files a tier installs (design §1, tier table). */
11
13
  function tierFiles(all, tier) {
12
14
  return all.filter((f) => {
13
15
  if (f.startsWith('knowledge-seeds/'))
14
16
  return false; // copied into knowledge/, not harness/
17
+ if (f === 'CHANGELOG.md')
18
+ return false; // read by update from the package, not installed
15
19
  if (f === 'VERSION' || f.startsWith('policy/'))
16
20
  return true;
17
21
  if (f === 'templates/agents-md-blocks.md')
@@ -25,10 +29,8 @@ function tierFiles(all, tier) {
25
29
  return tier === 'graph'; // roles/, schemas/
26
30
  });
27
31
  }
28
- const VENDOR_OF = (model) => model.startsWith('gpt') ? 'openai' : model.startsWith('gemini') ? 'google' : 'claude';
29
- const CONFIRMED_MODELS = new Set(['claude-opus-5-5', 'claude-fable-5-1']); // seen working in this environment
30
32
  /** bindings.yaml (design §5): defaults from role files; an unavailable vendor falls back, else to pm's model. */
31
- export function buildBindings(harness, available, vs, mode) {
33
+ export function buildBindings(harness, available, vs, mode, cache) {
32
34
  const roles = {};
33
35
  const files = readdirSync(join(harness, 'roles'))
34
36
  .filter((f) => f.endsWith('.md'))
@@ -45,14 +47,21 @@ export function buildBindings(harness, available, vs, mode) {
45
47
  for (const [role, m] of meta) {
46
48
  let model = m.def;
47
49
  let note;
48
- if (!available.has(VENDOR_OF(model))) {
49
- note = `${VENDOR_OF(model)} not available — default was ${model}`;
50
- model = m.fb && available.has(VENDOR_OF(m.fb)) ? m.fb : pm;
50
+ if (!available.has(vendorOf(model))) {
51
+ note = `${vendorOf(model)} not available — default was ${model}`;
52
+ model = m.fb && available.has(vendorOf(m.fb)) ? m.fb : pm;
51
53
  }
52
- const entry = { vendor: VENDOR_OF(model), model };
54
+ const entry = { vendor: vendorOf(model), model };
53
55
  if (role === 'implementer')
54
56
  entry['parallel'] = 4;
55
- if (!CONFIRMED_MODELS.has(model))
57
+ const chk = cache ? checkBinding(model, entry['vendor'], cache) : null;
58
+ if (chk) {
59
+ if (chk.unverified)
60
+ entry['unverified'] = true;
61
+ if (chk.note)
62
+ note = note ? `${note}; ${chk.note}` : chk.note;
63
+ }
64
+ else if (!CONFIRMED_MODELS.has(model))
56
65
  entry['unverified'] = true;
57
66
  if (note)
58
67
  entry['note'] = note;
@@ -124,28 +133,38 @@ export async function runInstall(o) {
124
133
  // 1. upstream harness files for the tier
125
134
  for (const f of tierFiles(listFiles(up), o.tier))
126
135
  add(`.agents/harness/${f}`, readFileSync(join(up, f), 'utf8'), 'upstream harness');
127
- // 2. questions (manual) / detection (auto)
136
+ // 2. questions (manual) / detection (auto) — only for what does not exist yet.
137
+ // bindings.yaml and gates.yaml belong to the project once written; `reins configure` changes them.
138
+ const hasBindings = existsSync(join(root, '.agents/harness/bindings.yaml'));
139
+ const hasGates = existsSync(join(root, '.agents/harness/gates.yaml'));
140
+ const pinPath = join(root, '.agents/harness/install.yaml');
141
+ const pinned = existsSync(pinPath)
142
+ ? parse(readFileSync(pinPath, 'utf8'))
143
+ : null;
128
144
  const vs = (o.detectVendors ?? vendors)();
129
145
  const detected = vs.filter((v) => v.detected).map((v) => v.name);
130
146
  const avail = new Set(['claude']); // claude is the floor (R22)
131
- if (o.tier === 'graph') {
147
+ if (o.tier === 'graph' && !hasBindings) {
132
148
  const ans = await o.asker.ask(`vendors you can use (claude,openai,google,cursor) — detected: ${detected.join(',') || 'none'}`, ['claude', ...detected.filter((d) => d !== 'claude')].join(','));
133
149
  for (const v of ans.split(',').map((s) => s.trim()))
134
150
  if (['claude', 'openai', 'google', 'cursor'].includes(v))
135
151
  avail.add(v);
136
152
  }
137
- const language = await o.asker.ask('language of documents the user reads (ko, en, …)', 'ko');
138
- const proposal = discoverGates(root);
139
- const gateList = proposal.gates.map((g) => `${g.name}=${g.cmd}`).join(', ') || 'none found';
140
- const okGates = await o.asker.ask(`gates found: ${gateList} — use them? (y/n)`, 'y');
141
- if (!/^y/i.test(okGates))
142
- notes.push('gates not confirmed — edit .agents/harness/gates.yaml, then `reins check --dry-run`');
143
- for (const x of proposal.excluded)
144
- notes.push(`excluded from gates: ${x.name} (${x.why})`);
153
+ const language = pinned?.language ??
154
+ (await o.asker.ask('language of documents the user reads (ko, en, …)', 'ko'));
155
+ if (!hasGates) {
156
+ const proposal = discoverGates(root);
157
+ const gateList = proposal.gates.map((g) => `${g.name}=${g.cmd}`).join(', ') || 'none found';
158
+ const okGates = await o.asker.ask(`gates found: ${gateList} — use them? (y/n)`, 'y');
159
+ if (!/^y/i.test(okGates))
160
+ notes.push('gates not confirmed — edit .agents/harness/gates.yaml, then `reins check --dry-run`');
161
+ for (const x of proposal.excluded)
162
+ notes.push(`excluded from gates: ${x.name} (${x.why})`);
163
+ add('.agents/harness/gates.yaml', buildGates(root, /^y/i.test(okGates) ? proposal.gates : []), 'declared gates');
164
+ }
145
165
  // 3. generated configuration
146
- if (o.tier === 'graph')
147
- add('.agents/harness/bindings.yaml', buildBindings(up, avail, vs, o.mode), 'role ↔ model bindings');
148
- add('.agents/harness/gates.yaml', buildGates(root, /^y/i.test(okGates) ? proposal.gates : []), 'declared gates');
166
+ if (o.tier === 'graph' && !hasBindings)
167
+ add('.agents/harness/bindings.yaml', buildBindings(up, avail, vs, o.mode, o.modelCache ?? newModelCache()), 'role ↔ model bindings');
149
168
  add('.agents/harness/install.yaml', `# version pin and install settings (R25) — read by reins update\n${stringify({ schema: 'reins/install@1', tier: o.tier, version, mode: o.mode, language })}`, 'version pin');
150
169
  // 4. layout skeleton (design §1); never overwrite project files
151
170
  if (o.tier !== 'harness') {
@@ -161,8 +180,31 @@ export async function runInstall(o) {
161
180
  add('.loctx/README.md', LOCTX_README, 'local workspace layout');
162
181
  addIfMissing('.loctx/ROADMAP.local.md', ROADMAP_STUB, 'raw roadmap');
163
182
  }
164
- addIfMissing('.agents/skills/.gitkeep', '', 'skills (Agent Skills standard path)');
165
- addIfMissing('.agents/SKILLS.md', '# Skills\n\n| skill | does |\n|---|---|\n', 'skill index');
183
+ // skill entry points: upstream-owned copies under the Agent Skills path, plus the index
184
+ const skillsUp = packageSkills();
185
+ const installed = [];
186
+ for (const name of tierSkills(o.tier)) {
187
+ for (const f of listFiles(join(skillsUp, name)))
188
+ add(`.agents/skills/${name}/${f}`, readFileSync(join(skillsUp, name, f), 'utf8'), 'upstream skill');
189
+ }
190
+ const skillsDir = join(root, '.agents', 'skills');
191
+ const names = new Set([
192
+ ...tierSkills(o.tier),
193
+ ...(existsSync(skillsDir) ? readdirSync(skillsDir) : []).filter((n) => existsSync(join(skillsDir, n, 'SKILL.md'))),
194
+ ]);
195
+ for (const n of names) {
196
+ const src = tierSkills(o.tier).includes(n) ? join(skillsUp, n) : join(skillsDir, n);
197
+ const { data } = splitFrontmatter(readFileSync(join(src, 'SKILL.md'), 'utf8'));
198
+ installed.push({ name: n, description: String(data?.['description'] ?? '') });
199
+ }
200
+ const indexPath = join(root, '.agents', 'SKILLS.md');
201
+ const index = existsSync(indexPath) ? readFileSync(indexPath, 'utf8') : null;
202
+ if (index === null ||
203
+ index.startsWith(SKILLS_INDEX_HEADER) ||
204
+ /^# Skills\n\n\| skill \| does \|\n\|---\|---\|\n$/.test(index))
205
+ add('.agents/SKILLS.md', skillsIndex(installed), 'skill index');
206
+ else
207
+ notes.push('.agents/SKILLS.md is written by the project — add the reins skills to it by hand');
166
208
  const gi = existsSync(join(root, '.gitignore'))
167
209
  ? readFileSync(join(root, '.gitignore'), 'utf8')
168
210
  : '';
@@ -199,17 +241,25 @@ export async function runInstall(o) {
199
241
  notes.push('legacy workspace .ai/ found — left untouched; run `reins migrate ' +
200
242
  o.tier +
201
243
  '` to move it into .agents/ and .loctx/');
202
- notes.push('vendor files (.claude/agents, settings.json) are generated in a later step — `reins update` once the generator ships');
203
244
  notes.push('next: in your agent, run the setup skill (/reins-setup) — the PM reads the project and proposes AGENTS.md project sections');
204
245
  // 8. apply, then record (only when something changed)
205
246
  const applied = apply(root, writes, !!o.dryRun);
247
+ // 9. vendor files from the installed harness (design §6) — never over a file reins did not write
248
+ const generated = o.dryRun ? undefined : writeGenerated(root, generateVendorFiles(root), false);
249
+ if (generated) {
250
+ applied.created.push(...generated.written.filter((p) => !applied.created.includes(p)));
251
+ for (const s of generated.skipped)
252
+ notes.push(`not generated this round (vendor CLI files arrive in round two): ${s}`);
253
+ for (const r of generated.refused)
254
+ notes.push(`left alone ${r.path}: ${r.why}`);
255
+ }
206
256
  let history;
207
257
  const changedAny = applied.created.length + applied.changed.length > 0;
208
258
  if (changedAny && !o.dryRun && o.tier !== 'harness') {
209
259
  const now = o.now ?? new Date();
210
260
  // local time, like every other history file name (<YYYY-MM-DD-HHmm>)
211
261
  const stamp = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}`;
212
- history = `.loctx/history/${stamp}_install-${o.tier}.md`;
262
+ history = `.loctx/history/${stamp}_${o.recordAs ?? 'install'}-${o.tier}.md`;
213
263
  const body = [
214
264
  `decisions: install-${o.tier}`,
215
265
  '',
@@ -226,5 +276,5 @@ export async function runInstall(o) {
226
276
  ].join('\n');
227
277
  apply(root, [{ path: history, content: body, why: 'install record' }], false);
228
278
  }
229
- return { root, generation: gen, applied, notes, history };
279
+ return { root, generation: gen, applied, generated, notes, history };
230
280
  }
@@ -0,0 +1,138 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { repoRoot } from '../lib/git.js';
4
+ import { harnessDir, readYaml } from '../lib/harness.js';
5
+ import { appendMetric, classify, METRICS_FILE, readMetrics, summarize, } from '../lib/metrics.js';
6
+ const TICKET = /^\d{3}-\d+$/;
7
+ const INTENT = /^\d{3}$/;
8
+ /**
9
+ * `reins metrics record` (S-3): one `usage` line for a role run. Anything doubtful is refused
10
+ * and nothing is written — a wrong number in the file is worse than a missing one.
11
+ */
12
+ export function recordUsage(o) {
13
+ const root = repoRoot(o.cwd ?? process.cwd());
14
+ if (!o.role)
15
+ return { refused: '--role <role> is required' };
16
+ if (o.tokens === undefined)
17
+ return { refused: '--tokens <n> is required' };
18
+ if (!/^\d+$/.test(o.tokens.trim()))
19
+ return { refused: `--tokens must be a whole number ≥ 0 (got "${o.tokens}")` };
20
+ const tokens = Number(o.tokens.trim());
21
+ if (!Number.isSafeInteger(tokens))
22
+ return { refused: `--tokens is too large (got "${o.tokens}")` };
23
+ if (o.ticket !== undefined && !TICKET.test(o.ticket))
24
+ return { refused: `--ticket must look like 002-1 (got "${o.ticket}")` };
25
+ if (o.intent !== undefined && !INTENT.test(o.intent))
26
+ return { refused: `--intent must be three digits like 002 (got "${o.intent}")` };
27
+ if (o.ticket && o.intent && o.ticket.slice(0, 3) !== o.intent)
28
+ return {
29
+ refused: `--ticket ${o.ticket} belongs to intent ${o.ticket.slice(0, 3)}, not ${o.intent}`,
30
+ };
31
+ const dir = harnessDir(root);
32
+ const file = dir && join(dir, 'bindings.yaml');
33
+ if (!file || !existsSync(file))
34
+ return { refused: 'no bindings.yaml — run reins install' };
35
+ const roles = readYaml(file).roles ?? {};
36
+ const bound = Object.hasOwn(roles, o.role) ? roles[o.role] : undefined;
37
+ if (!bound)
38
+ return { refused: `unknown role "${o.role}" (roles: ${Object.keys(roles).join(', ')})` };
39
+ const vendor = o.vendor ?? bound.vendor;
40
+ const model = o.model ?? bound.model;
41
+ if (!vendor || !model)
42
+ return {
43
+ refused: `bindings.yaml has no vendor/model for ${o.role}; pass --vendor and --model`,
44
+ };
45
+ if (!existsSync(join(root, '.loctx')))
46
+ return { refused: 'no .loctx/ here — nothing recorded' };
47
+ const record = {
48
+ kind: 'usage',
49
+ role: o.role,
50
+ vendor,
51
+ model,
52
+ tokens,
53
+ ...(o.ticket ? { ticket: o.ticket } : {}),
54
+ ...(!o.ticket && o.intent ? { intent: o.intent } : {}),
55
+ ...(o.note ? { note: o.note } : {}),
56
+ };
57
+ if (!appendMetric(root, record))
58
+ return { refused: `could not write ${METRICS_FILE}` };
59
+ return { record };
60
+ }
61
+ /** `reins metrics` (S-4): read-only. */
62
+ export function collectMetrics(o = {}) {
63
+ const root = repoRoot(o.cwd ?? process.cwd());
64
+ const present = existsSync(join(root, METRICS_FILE));
65
+ const { records, broken } = readMetrics(root);
66
+ return { present, intent: o.intent ?? null, ...summarize(records, { intent: o.intent, broken }) };
67
+ }
68
+ const n = (x) => x.toLocaleString('en-US');
69
+ export function formatMetrics(m) {
70
+ if (!m.present)
71
+ return 'no metrics yet\n';
72
+ const out = [];
73
+ out.push(`reins metrics${m.intent ? ` — intent ${m.intent}` : ''}`);
74
+ out.push(`records: check ${m.counts.check} · gate ${m.counts.gate} · usage ${m.counts.usage} · broken ${m.broken}`);
75
+ out.push(`tokens: ${n(m.tokens.total)}`);
76
+ const group = (title, g) => {
77
+ out.push(` ${title}`);
78
+ const rows = Object.entries(g);
79
+ if (!rows.length)
80
+ out.push(' —');
81
+ for (const [k, v] of rows)
82
+ out.push(` ${k.padEnd(14)} ${n(v).padStart(12)}`);
83
+ };
84
+ group('by role', m.tokens.byRole);
85
+ group('by vendor', m.tokens.byVendor);
86
+ out.push('tickets');
87
+ if (!m.tickets.length)
88
+ out.push(' —');
89
+ for (const t of m.tickets)
90
+ out.push(` ${t.ticket.padEnd(8)} tokens ${n(t.tokens).padStart(10)} · checks ${String(t.checks).padStart(3)} · knowledge stops ${t.knowledgeStops}`);
91
+ out.push('intents');
92
+ if (!m.intents.length)
93
+ out.push(' —');
94
+ for (const i of m.intents)
95
+ out.push(` ${i.intent.padEnd(8)} tokens ${n(i.tokens).padStart(10)} · checks ${String(i.checks).padStart(3)} · stops intent ${i.stops.intent} / knowledge ${i.stops.knowledge} / redline ${i.stops.redline} · tickets ${i.tickets} · knowledge stops per ticket ${i.knowledgeStopsPerTicket ?? '—'}`);
96
+ return `${out.join('\n')}\n`;
97
+ }
98
+ const uniq = (xs) => [...new Set(xs)];
99
+ /** The `check` line for a finished run; never throws, never changes the run's result. */
100
+ export function logCheck(r, o) {
101
+ try {
102
+ const root = repoRoot(o.cwd ?? process.cwd());
103
+ const reasons = uniq(r.findings.filter((f) => f.verdict !== 'WARN').map((f) => f.reason));
104
+ const warns = uniq(r.findings.filter((f) => f.verdict === 'WARN').map((f) => f.reason));
105
+ appendMetric(root, {
106
+ kind: 'check',
107
+ stage: r.stage,
108
+ ...(o.ticket ? { ticket: o.ticket } : {}),
109
+ verdict: r.verdict,
110
+ reasons,
111
+ warns,
112
+ stops: classify(reasons, harnessDir(root)),
113
+ });
114
+ }
115
+ catch {
116
+ // metrics never change what check reports
117
+ }
118
+ }
119
+ /** One `gate` line per gate that actually ran (skipped and refused runs write nothing). */
120
+ export function logGates(runs, o) {
121
+ try {
122
+ const root = repoRoot(o.cwd ?? process.cwd());
123
+ for (const g of runs) {
124
+ if (g.exit === null)
125
+ continue;
126
+ appendMetric(root, {
127
+ kind: 'gate',
128
+ ...(o.ticket ? { ticket: o.ticket } : {}),
129
+ gate: g.gate,
130
+ exit: g.exit,
131
+ report: g.report,
132
+ });
133
+ }
134
+ }
135
+ catch {
136
+ // metrics never change what gate reports
137
+ }
138
+ }