@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
@@ -1,49 +1,75 @@
1
- import { existsSync, readFileSync, readdirSync } from 'node:fs';
1
+ import { existsSync, readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
+ import { parse } from 'yaml';
4
+ import { packageHarness } from '../lib/upstream.js';
3
5
  import { CONFIRMED_MODELS, listModels, vendorOf, } from '../lib/detect.js';
4
- import { FIXED_ROLES, readLocal, teamEnabled, resolveBindings, } from '../lib/bindings.js';
6
+ import { GROUP_ROLES, GROUPS, effectiveBindings, readLocalBindings, readTeam, } from '../lib/bindings.js';
5
7
  import { BACK, EXIT } from '../lib/prompter.js';
6
- import { splitFrontmatter } from '../lib/skills.js';
7
8
  import { configureBindings } from './configure.js';
8
9
  const LISTER_CLI = { google: 'agy', cursor: 'cursor-agent' };
9
- /** One line per role: `[ON] planner claude claude-opus-5-5 (team)`; `(local)` marks a value of this user's own. */
10
- export function roleLine(b, scope) {
11
- const mark = scope === 'local' && b.enabled_source === 'local' ? ' state (local)' : '';
12
- const fixed = b.enabled_source === 'fixed' ? ' always on' : '';
13
- return `[${b.enabled ? 'ON ' : 'OFF'}] ${b.role.padEnd(12)} ${b.vendor.padEnd(7)} ${b.model} (${b.source})${mark}${fixed}`;
10
+ /** When switching a group on pays for itself (design §9; Anthropic 2026-10-22). */
11
+ export const WHEN_TO_SWITCH_ON = 'switch a group on when the PM context degrades, independent work can run in parallel, or review/audit should run on another model';
12
+ const show = (b) => (b ? `${b.vendor} ${b.model}` : 'off (PM)');
13
+ /** One line per group: `pl claude claude-sonnet-5-5, openai gpt-6.1-terra +1 role`. */
14
+ export function groupLine(group, spec, mode) {
15
+ if (!spec)
16
+ return `${group.padEnd(12)} off — the PM does it`;
17
+ const tag = mode === 'multi'
18
+ ? ''
19
+ : group === 'auditor'
20
+ ? ' (recommended audit model)'
21
+ : ' (used in multi only)';
22
+ const models = spec.models?.length
23
+ ? spec.models.map(show).join(', ')
24
+ : spec.vendor && spec.model
25
+ ? show({ vendor: spec.vendor, model: spec.model })
26
+ : '—';
27
+ const n = Object.keys(spec.roles ?? {}).length;
28
+ return `${group.padEnd(12)} ${models}${n ? ` +${n} role${n > 1 ? 's' : ''}` : ''}${tag}`;
14
29
  }
15
- /** Models of `vendor` already known to this repository: role defaults and fallbacks, confirmed, current. */
16
- export function knownModels(root, vendor, current) {
17
- const out = [];
18
- const dir = join(root, '.agents/harness/roles');
19
- if (existsSync(dir))
20
- for (const f of readdirSync(dir)
21
- .filter((x) => x.endsWith('.md'))
22
- .toSorted()) {
23
- const { data } = splitFrontmatter(readFileSync(join(dir, f), 'utf8'));
24
- for (const k of ['default_binding', 'fallback_binding'])
25
- if (typeof data?.[k] === 'string')
26
- out.push(data[k]);
30
+ /** The packaged list of known models per vendor (`harness/models.yaml`, spec ST-2). */
31
+ export function catalogue() {
32
+ const p = join(packageHarness(), 'models.yaml');
33
+ if (!existsSync(p))
34
+ return {};
35
+ const doc = parse(readFileSync(p, 'utf8'));
36
+ return doc?.vendors ?? {};
37
+ }
38
+ /** Models of `vendor` known here: the packaged list, confirmed ones, and the current files' bindings of that vendor. */
39
+ export function knownModels(vendor, current) {
40
+ const out = [
41
+ ...(catalogue()[vendor] ?? []),
42
+ ...[...CONFIRMED_MODELS].filter((m) => vendorOf(m) === vendor),
43
+ ];
44
+ const take = (b) => {
45
+ if (b && b.vendor === vendor)
46
+ out.push(b.model);
47
+ };
48
+ for (const d of current) {
49
+ take(d.default);
50
+ for (const g of Object.values(d.groups ?? {})) {
51
+ if (!g)
52
+ continue;
53
+ if (g.vendor && g.model)
54
+ take({ vendor: g.vendor, model: g.model });
55
+ for (const m of g.models ?? [])
56
+ take(m);
57
+ for (const r of Object.values(g.roles ?? {}))
58
+ take(r);
27
59
  }
28
- out.push(...CONFIRMED_MODELS, ...current);
29
- return [...new Set(out)].filter((m) => vendorOf(m) === vendor);
60
+ }
61
+ return [...new Set(out)];
30
62
  }
31
63
  /**
32
- * The models and roles screen (spec S-3) and the role screen under it (S-5). Every choice is written at
33
- * once through `configureBindings` (the same writer as `reins configure bindings`); EXIT writes nothing more.
64
+ * The models-and-roles screen (design §9): scope, the PM's model, each group (off, one model, several for
65
+ * pl and advisor, per-role models). Every choice is written at once through `configureBindings`.
34
66
  * Returns `exit` when the user left reins config, `back` for `< Configuration`.
35
67
  */
36
68
  export async function modelsScreen(o) {
37
69
  const { root, prompter } = o;
38
70
  let scope = 'local';
39
71
  const write = async (opts, label) => {
40
- const r = await configureBindings({
41
- cwd: root,
42
- local: scope === 'local',
43
- detectVendors: o.detectVendors,
44
- modelCache: o.modelCache,
45
- ...opts,
46
- });
72
+ const r = await configureBindings({ cwd: root, local: scope === 'local', ...opts });
47
73
  if (r.refused)
48
74
  prompter.note(`not changed: ${r.refused}`);
49
75
  else if (r.changed.length === 0)
@@ -51,34 +77,47 @@ export async function modelsScreen(o) {
51
77
  else if (scope === 'local')
52
78
  prompter.note(`${label}: written to .loctx/bindings.local.yaml (this user only)`);
53
79
  else
54
- prompter.note(`${label}: written to .agents/harness/bindings.yaml, vendor files regenerated — commit bindings.yaml`);
80
+ prompter.note(`${label}: written to .agents/harness/bindings.yaml, generated files and AGENTS.md refreshed — commit them`);
55
81
  };
56
82
  for (;;) {
57
- const rows = resolveBindings(root, o.detectVendors);
83
+ const doc = effectiveBindings(root);
84
+ if (!doc) {
85
+ prompter.note('no version-2 bindings.yaml here — run `reins install` or `reins update`');
86
+ return 'back';
87
+ }
88
+ const single = doc.mode !== 'multi';
89
+ prompter.note(single
90
+ ? 'single: the PM does every role; the assignments below are used only after switching to multi (the auditor model is the recommended audit model either way)'
91
+ : WHEN_TO_SWITCH_ON);
58
92
  const options = [
59
93
  { value: 'back', label: '< Configuration' },
60
94
  { value: 'exit', label: 'exit' },
61
95
  {
62
96
  value: 'scope',
63
- label: `scope: ${scope === 'local' ? 'local | global' : 'global | local'}`,
97
+ label: `scope: ${scope === 'local' ? 'local | project' : 'project | local'}`,
64
98
  },
65
- { value: 'toggle', label: 'switch roles on or off' },
66
- ...rows.map((b) => ({ value: b.role, label: roleLine(b, scope) })),
99
+ { value: 'default', label: `${'PM'.padEnd(12)} ${show(doc.default)}` },
100
+ ...GROUPS.map((g) => ({ value: g, label: groupLine(g, doc.groups?.[g], doc.mode) })),
67
101
  ];
68
- const v = await prompter.select({ message: 'Models and roles', options });
69
- if (v === EXIT)
102
+ const v = await prompter.select({
103
+ message: `Models and roles (mode: ${doc.mode ?? 'single'})`,
104
+ options,
105
+ });
106
+ if (v === EXIT || v === 'exit')
70
107
  return 'exit';
71
108
  if (v === BACK || v === 'back')
72
109
  return 'back';
73
- if (v === 'exit')
74
- return 'exit';
75
110
  if (v === 'scope') {
76
111
  const s = await prompter.select({
77
112
  message: 'Write changes to',
78
113
  initial: scope,
79
114
  options: [
80
115
  { value: 'local', label: 'local', hint: '.loctx/bindings.local.yaml, this user only' },
81
- { value: 'global', label: 'global', hint: 'bindings.yaml, committed, regenerates files' },
116
+ {
117
+ value: 'project',
118
+ label: 'project',
119
+ hint: 'the team: .agents/harness/bindings.yaml, committed, regenerates files',
120
+ },
82
121
  ],
83
122
  });
84
123
  if (s === EXIT)
@@ -87,107 +126,147 @@ export async function modelsScreen(o) {
87
126
  scope = s;
88
127
  continue;
89
128
  }
90
- if (v === 'toggle') {
91
- const names = rows.filter((b) => !FIXED_ROLES.includes(b.role));
92
- prompter.note(`always on: ${FIXED_ROLES.join(', ')}`);
93
- const on = await prompter.multiselect({
94
- message: 'Roles that are on',
95
- initial: names
96
- .filter((b) => (scope === 'global' ? (teamEnabled(root)[b.role] ?? true) : b.enabled))
97
- .map((b) => b.role),
98
- options: names.map((b) => ({ value: b.role, label: b.role })),
99
- });
100
- if (on === EXIT)
129
+ if (v === 'default') {
130
+ const b = await pickModel(o, 'PM', doc.default);
131
+ if (b === EXIT)
101
132
  return 'exit';
102
- if (on === BACK)
103
- continue;
104
- // the list and the diff use the chosen scope's own value: global = the team file, local = effective
105
- const team = teamEnabled(root);
106
- const isOn = (b) => scope === 'global' ? (team[b.role] ?? true) : b.enabled;
107
- const enable = names.filter((b) => !isOn(b) && on.includes(b.role)).map((b) => b.role);
108
- const disable = names.filter((b) => isOn(b) && !on.includes(b.role)).map((b) => b.role);
109
- if (enable.length + disable.length > 0)
110
- await write({ enable, disable }, `roles ${[...enable, ...disable].join(', ')}`);
133
+ if (b)
134
+ await write({ set: [`default=${b.vendor}:${b.model}`] }, `PM → ${show(b)}`);
111
135
  continue;
112
136
  }
113
- const row = rows.find((b) => b.role === v);
114
- if (!row)
115
- continue;
116
- const r = await roleScreen(o, row, scope);
117
- if (r === EXIT)
137
+ const r = await groupScreen(o, v, doc.groups?.[v], write, doc.mode);
138
+ if (r === 'exit')
118
139
  return 'exit';
119
- if (r !== undefined)
120
- await write({ set: [`${row.role}=${r}`] }, `${row.role} → ${r}`);
121
140
  }
122
141
  }
123
- /** S-5: vendor (detected only), then model. Returns the chosen model ID, `undefined` for back, or EXIT. */
124
- async function roleScreen(o, row, scope) {
142
+ async function groupScreen(o, group, spec, write, mode) {
125
143
  const { prompter } = o;
126
- const detected = o.detectVendors().filter((v) => v.detected || v.name === 'claude');
144
+ const many = group === 'pl' || group === 'advisor';
145
+ const roles = GROUP_ROLES[group];
146
+ const pick = await prompter.select({
147
+ message: `${group}: ${groupLine(group, spec, mode).slice(12).trim()}`,
148
+ options: [
149
+ { value: 'back', label: '< back' },
150
+ { value: 'one', label: many ? 'one model' : 'set the model' },
151
+ ...(many ? [{ value: 'many', label: 'several models', hint: 'first = control (pl)' }] : []),
152
+ ...(roles.length ? [{ value: 'role', label: 'a model for one role' }] : []),
153
+ { value: 'off', label: 'switch off', hint: 'the PM does it' },
154
+ ],
155
+ });
156
+ if (pick === EXIT)
157
+ return 'exit';
158
+ if (pick === BACK || pick === 'back')
159
+ return 'back';
160
+ if (pick === 'off') {
161
+ await write({ off: [group] }, `${group} off`);
162
+ return 'back';
163
+ }
164
+ if (pick === 'one') {
165
+ const b = await pickModel(o, group, spec?.vendor && spec.model ? { vendor: spec.vendor, model: spec.model } : spec?.models?.[0]);
166
+ if (b === EXIT)
167
+ return 'exit';
168
+ if (b)
169
+ await write({ set: [`${group}=${b.vendor}:${b.model}`] }, `${group} → ${show(b)}`);
170
+ return 'back';
171
+ }
172
+ if (pick === 'many') {
173
+ const list = [];
174
+ for (;;) {
175
+ const b = await pickModel(o, `${group} #${list.length + 1}`, undefined);
176
+ if (b === EXIT)
177
+ return 'exit';
178
+ if (!b)
179
+ break;
180
+ list.push(b);
181
+ const more = await prompter.confirm({ message: 'Add another model?', initial: false });
182
+ if (more === EXIT)
183
+ return 'exit';
184
+ if (more !== true)
185
+ break;
186
+ }
187
+ if (list.length)
188
+ await write({ models: [`${group}=${list.map((b) => `${b.vendor}:${b.model}`).join(',')}`] }, `${group} → ${list.map(show).join(', ')}`);
189
+ return 'back';
190
+ }
191
+ const role = await prompter.select({
192
+ message: `${group}: which role`,
193
+ options: [
194
+ { value: 'back', label: '< back' },
195
+ ...roles.map((r) => ({ value: r, label: r, hint: show(spec?.roles?.[r]) })),
196
+ ],
197
+ });
198
+ if (role === EXIT)
199
+ return 'exit';
200
+ if (role === BACK || role === 'back')
201
+ return 'back';
202
+ const b = await pickModel(o, `${group}.${role}`, spec?.roles?.[role]);
203
+ if (b === EXIT)
204
+ return 'exit';
205
+ if (b)
206
+ await write({ set: [`${group}.${role}=${b.vendor}:${b.model}`] }, `${group}.${role} → ${show(b)}`);
207
+ return 'back';
208
+ }
209
+ /** Tool (used tools only), then model. Returns the binding, `undefined` for back, or EXIT. */
210
+ async function pickModel(o, label, current) {
211
+ const { prompter, root } = o;
212
+ const team = readTeam(root).doc;
213
+ const local = readLocalBindings(root);
214
+ const docs = [team, local].filter((d) => !!d);
215
+ const used = Object.entries(effectiveBindings(root)?.tools ?? { claude: { use: true } })
216
+ .filter(([, t]) => t?.use !== false)
217
+ .map(([n]) => n);
218
+ if (!used.includes('claude'))
219
+ used.unshift('claude');
127
220
  for (;;) {
128
221
  const vendor = await prompter.select({
129
- message: `${row.role} (${scope}): vendor`,
130
- initial: row.vendor,
131
- options: [
132
- { value: 'back', label: '< back' },
133
- ...detected.map((v) => ({ value: v.name, label: v.name })),
134
- ],
222
+ message: `${label}: tool`,
223
+ initial: current?.vendor,
224
+ options: [{ value: 'back', label: '< back' }, ...used.map((v) => ({ value: v, label: v }))],
135
225
  });
136
226
  if (vendor === EXIT)
137
227
  return EXIT;
138
228
  if (vendor === BACK || vendor === 'back')
139
229
  return undefined;
140
- const model = await modelPicker(o, row, vendor);
141
- if (model === EXIT)
142
- return EXIT;
143
- if (model === undefined)
144
- continue; // back to the vendor list
145
- return model;
146
- }
147
- }
148
- async function modelPicker(o, row, vendor) {
149
- const { prompter, root } = o;
150
- const team = (await configureBindings({ cwd: root, show: true, detectVendors: o.detectVendors })).table.map((t) => t.model);
151
- const local = Object.values(readLocal(root).roles).flatMap((r) => (r.model ? [r.model] : []));
152
- let ids = knownModels(root, vendor, [...team, ...local, row.model]);
153
- if (vendor === 'google' || vendor === 'cursor') {
154
- let res;
155
- try {
156
- res = listModels(vendor, o.modelCache.run);
230
+ let ids = knownModels(vendor, docs);
231
+ if (vendor === 'google' || vendor === 'cursor') {
232
+ let res;
233
+ try {
234
+ res = listModels(vendor, o.modelCache.run);
235
+ }
236
+ catch (e) {
237
+ res = { failed: e.message };
238
+ }
239
+ if ('failed' in res)
240
+ prompter.note(`${LISTER_CLI[vendor]} models failed (${res.failed}) — showing known models`);
241
+ else
242
+ ids = res.ids;
157
243
  }
158
- catch (e) {
159
- res = { failed: e.message };
244
+ for (;;) {
245
+ const pick = await prompter.select({
246
+ message: `${label}: ${vendor} model`,
247
+ initial: current?.model,
248
+ options: [
249
+ { value: 'back', label: '< back' },
250
+ ...ids.map((m) => ({
251
+ value: m,
252
+ label: m,
253
+ ...(m === current?.model ? { hint: 'current' } : {}),
254
+ })),
255
+ { value: 'other', label: 'other (type a model ID)' },
256
+ ],
257
+ });
258
+ if (pick === EXIT)
259
+ return EXIT;
260
+ if (pick === BACK || pick === 'back')
261
+ break;
262
+ if (pick !== 'other')
263
+ return { vendor, model: pick };
264
+ const t = await prompter.text({ message: 'Model ID' });
265
+ if (t === EXIT)
266
+ return EXIT;
267
+ if (t === BACK || !t.trim())
268
+ continue;
269
+ return { vendor, model: t.trim() };
160
270
  }
161
- if ('failed' in res)
162
- prompter.note(`${LISTER_CLI[vendor]} models failed (${res.failed}) — showing known models`);
163
- else
164
- ids = res.ids;
165
- }
166
- for (;;) {
167
- const pick = await prompter.select({
168
- message: `${row.role}: ${vendor} model`,
169
- initial: row.model,
170
- options: [
171
- { value: 'back', label: '< back' },
172
- ...ids.map((m) => ({
173
- value: m,
174
- label: m,
175
- ...(m === row.model ? { hint: 'current' } : {}),
176
- })),
177
- { value: 'other', label: 'other (type a model ID)' },
178
- ],
179
- });
180
- if (pick === EXIT)
181
- return EXIT;
182
- if (pick === BACK || pick === 'back')
183
- return undefined;
184
- if (pick !== 'other')
185
- return pick;
186
- const t = await prompter.text({ message: 'Model ID' });
187
- if (t === EXIT)
188
- return EXIT;
189
- if (t === BACK || !t.trim())
190
- continue;
191
- return t.trim();
192
271
  }
193
272
  }
@@ -1,42 +1,130 @@
1
- import { resolveBindings, stateLabel } from '../lib/bindings.js';
1
+ import { effectiveBindings, resolveRoles } from '../lib/bindings.js';
2
2
  import { newModelCache, vendors } from '../lib/detect.js';
3
3
  import { repoRoot } from '../lib/git.js';
4
- import { modelsScreen } from './config-models.js';
4
+ import { groupLine, modelsScreen } from './config-models.js';
5
+ import { configureBindings } from './configure.js';
5
6
  import { clackPrompter, isInteractive } from '../lib/prompter.js';
6
- export const CONFIG_HINT = 'change with: reins configure bindings --set <role>=<model> [--local] (see: reins configure bindings --help)';
7
- export function formatBindings(rows) {
8
- return rows
9
- .map((t) => ` ${t.role.padEnd(12)} ${t.vendor.padEnd(7)} ${t.model} (${t.source}: ${t.reason})${stateLabel(t) ? ` ${stateLabel(t)}` : ''}`)
10
- .join('\n');
7
+ export const CONFIG_HINT = 'change with: reins config bindings --set <default|group|group.role>=<model> [--local] (see: reins config bindings --help)';
8
+ /** The effective settings as text: mode, audit, the PM, each role that is on. */
9
+ export function formatBindings(doc) {
10
+ const lines = [
11
+ ` mode: ${doc.mode ?? 'single'}`,
12
+ ` audit: ${doc.audit?.required === false ? 'off (switched off by the user)' : 'required every version'}`,
13
+ ` PM: ${doc.default ? `${doc.default.vendor} ${doc.default.model}` : 'claude claude-opus-5-5'}`,
14
+ ];
15
+ const on = resolveRoles(doc).filter((r) => r.on);
16
+ if (on.length === 0)
17
+ lines.push(' every role: the PM');
18
+ if (doc.mode !== 'multi') {
19
+ const kept = Object.entries(doc.groups ?? {}).filter(([, s]) => s && JSON.stringify(s) !== '{}');
20
+ for (const [g, s] of kept)
21
+ lines.push(` ${g.padEnd(26)} ${groupLine(g, s, doc.mode)
22
+ .slice(12)
23
+ .trim()}`);
24
+ }
25
+ for (const r of on)
26
+ lines.push(` ${`${r.group}/${r.role}`.padEnd(26)} ${r.models.map((b) => `${b.vendor} ${b.model}`).join(', ')} (${r.source})`);
27
+ const tools = Object.entries(doc.tools ?? {})
28
+ .map(([n, t]) => `${n}${t?.use === false ? ' (unused)' : ''}`)
29
+ .join(', ');
30
+ if (tools)
31
+ lines.push(` tools: ${tools}`);
32
+ return lines.join('\n');
11
33
  }
12
- /** `reins config` (design §9): the settings screen on a terminal, the resolved table otherwise. Returns the exit code. */
34
+ /** `reins config` (design §9): the settings screen on a terminal, the effective table otherwise. Returns the exit code. */
13
35
  export async function runConfig(o = {}) {
14
36
  const write = o.write ?? ((s) => void process.stdout.write(s));
15
37
  const root = repoRoot(o.cwd ?? process.cwd());
16
38
  const interactive = o.interactive ?? isInteractive();
17
39
  if (!interactive || o.json) {
18
- const bindings = resolveBindings(root, o.detectVendors);
40
+ const doc = effectiveBindings(root);
41
+ if (!doc) {
42
+ write('no version-2 bindings.yaml — run `reins install` or `reins update`\n');
43
+ return 2;
44
+ }
19
45
  if (o.json)
20
- write(`${JSON.stringify({ bindings }, null, 2)}\n`);
46
+ write(`${JSON.stringify({ bindings: doc, roles: resolveRoles(doc) }, null, 2)}\n`);
21
47
  else
22
- write(`${formatBindings(bindings)}\n${CONFIG_HINT}\n`);
48
+ write(`${formatBindings(doc)}\n${CONFIG_HINT}\n`);
23
49
  return 0;
24
50
  }
25
51
  const prompter = o.prompter ?? (await clackPrompter());
26
52
  const modelCache = o.modelCache ?? newModelCache();
27
53
  const detect = o.detectVendors ?? vendors;
28
54
  for (;;) {
55
+ const doc = effectiveBindings(root);
29
56
  const v = await prompter.select({
30
57
  message: 'Configuration',
31
58
  options: [
32
59
  { value: 'models', label: 'models and roles configuration' },
60
+ { value: 'tools', label: 'agent tools', hint: 'detect again, use or not' },
61
+ { value: 'mode', label: `mode: ${doc?.mode ?? 'single'}` },
62
+ {
63
+ value: 'audit',
64
+ label: `audit: ${doc?.audit?.required === false ? 'off' : 'required'}`,
65
+ },
33
66
  { value: 'exit', label: 'exit' },
34
67
  ],
35
68
  });
36
- if (v !== 'models')
37
- return 0; // exit, EXIT (Ctrl-C) or BACK: nothing more is written
38
- const r = await modelsScreen({ root, prompter, detectVendors: detect, modelCache });
39
- if (r === 'exit')
40
- return 0;
69
+ if (typeof v !== 'string' || v === 'exit')
70
+ return 0; // EXIT (Ctrl-C) or BACK: nothing more is written
71
+ if (v === 'models') {
72
+ const r = await modelsScreen({ root, prompter, detectVendors: detect, modelCache });
73
+ if (r === 'exit')
74
+ return 0;
75
+ continue;
76
+ }
77
+ if (v === 'tools') {
78
+ const found = detect();
79
+ const picked = await prompter.multiselect({
80
+ message: 'Agent tools to use (detected tools are marked)',
81
+ options: found.map((t) => ({
82
+ value: t.name,
83
+ label: t.name,
84
+ hint: t.detected ? `detected (${t.cli})` : `not found (${t.cli})`,
85
+ })),
86
+ initial: found.filter((t) => doc?.tools?.[t.name]?.use ?? t.detected).map((t) => t.name),
87
+ });
88
+ if (typeof picked === 'symbol')
89
+ return 0;
90
+ const r = await configureBindings({
91
+ cwd: root,
92
+ detect: true,
93
+ detectVendors: () => found,
94
+ tools: found.map((t) => `${t.name}=${picked.includes(t.name) ? 'on' : 'off'}`),
95
+ });
96
+ prompter.note(r.refused ? `not changed: ${r.refused}` : 'agent tools written — commit bindings.yaml');
97
+ continue;
98
+ }
99
+ if (v === 'mode') {
100
+ const m = await prompter.select({
101
+ message: 'Mode',
102
+ initial: doc?.mode ?? 'single',
103
+ options: [
104
+ { value: 'single', label: 'single', hint: 'the PM does every role (default)' },
105
+ { value: 'multi', label: 'multi', hint: 'role groups with a model do their work' },
106
+ ],
107
+ });
108
+ if (typeof m === 'symbol')
109
+ return 0;
110
+ const r = await configureBindings({ cwd: root, mode: m });
111
+ prompter.note(r.refused
112
+ ? `not changed: ${r.refused}`
113
+ : r.modeChanged
114
+ ? `mode ${m}: AGENTS.md has a mode-changed note — the PM checks the project sections in the next conversation`
115
+ : `mode ${m}: already so`);
116
+ continue;
117
+ }
118
+ const off = doc?.audit?.required !== false;
119
+ if (off) {
120
+ const sure = await prompter.confirm({
121
+ message: 'Switch the per-version audit off? Nothing will check that the flow was followed.',
122
+ initial: false,
123
+ });
124
+ if (sure !== true)
125
+ continue;
126
+ }
127
+ const r = await configureBindings({ cwd: root, audit: off ? 'off' : 'on' });
128
+ prompter.note(r.refused ? `not changed: ${r.refused}` : `audit ${off ? 'off' : 'required'}`);
41
129
  }
42
130
  }