@bluenyang/reins 0.3.0 → 0.3.1-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.
- package/README.md +4 -3
- package/cli/dist/commands/config-gates.js +95 -0
- package/cli/dist/commands/config-models.js +72 -1
- package/cli/dist/commands/config.js +9 -2
- package/cli/dist/commands/configure.js +158 -14
- package/cli/dist/commands/install.js +52 -43
- package/cli/dist/commands/update.js +21 -4
- package/cli/dist/lib/agents-md.js +27 -5
- package/cli/dist/lib/bindings.js +79 -7
- package/cli/dist/lib/detect.js +6 -1
- package/cli/dist/lib/gate-refresh.js +82 -0
- package/cli/dist/lib/gate-script.js +77 -0
- package/cli/dist/lib/generate.js +17 -4
- package/cli/dist/lib/vendor-write.js +111 -6
- package/cli/dist/reins.js +28 -4
- package/docs/README.ko.md +4 -3
- package/harness/CHANGELOG.md +12 -0
- package/harness/VERSION +1 -1
- package/harness/models.yaml +2 -2
- package/harness/roles/auditor.md +7 -4
- package/harness/roles/pl.md +1 -1
- package/harness/schemas/bindings.schema.json +12 -3
- package/package.json +1 -1
- package/skills/audit/SKILL.md +7 -6
- package/skills/onboard/SKILL.md +1 -1
- package/skills/reins-setup/SKILL.md +4 -4
- package/skills/retro/SKILL.md +5 -3
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ knowledge lost in gitignored space, copies that drift apart. The full list is in
|
|
|
15
15
|
|
|
16
16
|
## Status
|
|
17
17
|
|
|
18
|
-
**0.3.
|
|
18
|
+
**0.3.1-rc.2 is the release candidate** (intent 021): `npx @bluenyang/reins@0.3.1-rc.2`. **0.3.0 is the latest release** (intents 019, 020): `npx @bluenyang/reins install`. Up to 0.2.0, skills and hooks called `npx @bluenyang/reins` during work; 0.3 removes that, and `reins update` moves a 0.1.x or 0.2.0 install over. What changed in each version is in [CHANGELOG.md](CHANGELOG.md); what comes next is in the [roadmap](docs/ROADMAP.md).
|
|
19
19
|
|
|
20
20
|
## How it works
|
|
21
21
|
|
|
@@ -64,10 +64,10 @@ To work on reins itself: `git clone https://github.com/bluenyang/reins.git`, the
|
|
|
64
64
|
|
|
65
65
|
| Command | Does |
|
|
66
66
|
|---|---|
|
|
67
|
-
| `install` | places the harness, detects agent tools, confirms gates,
|
|
67
|
+
| `install` | places the harness, detects agent tools, confirms gates, writes the gate script `.agents/harness/run-gates.sh` (it runs the project's gate commands and keeps their output for the audit) and proposes the one hook line that calls it (`--hooks` adds it to husky), adds the onboarding note; `--mode manual\|auto`, `--dry-run`, `--json` |
|
|
68
68
|
| `migrate` | moves an older harness or an `.ai/` workspace onto this layout and keeps the previous `AGENTS.md` aside for the PM to reconcile; `--legacy local\|committed`, `--dry-run` |
|
|
69
69
|
| `update` | re-applies the packaged harness; asks before overwriting a generated file edited by hand (`--force`); moves a 0.1.x or 0.2.0 install to 0.3 and lists its old working files (`--yes` deletes them) |
|
|
70
|
-
| `config` | a screen on a terminal: models and roles, agent tools, mode (single or multi), audit; `config bindings` and `config gates` take flags (`configure` is an alias) |
|
|
70
|
+
| `config` | a screen on a terminal: models and roles, agent tools, mode (single or multi), audit; `config bindings` and `config gates` take flags (`configure` is an alias). `config gates --refresh` finds the project's checks again, shows what differs from `gates.yaml` (new, changed, gone) and applies only what you pick (`--apply <name…|all>` without a terminal); the screen has a `gates` item for the same. A group or a role may name a fallback model (`config bindings --fallback <group>[.<role>]=<model>`): its call line goes into the delegation table, for when the first model cannot be called |
|
|
71
71
|
|
|
72
72
|
## Skills
|
|
73
73
|
|
|
@@ -80,6 +80,7 @@ are deleted, and the next skill.
|
|
|
80
80
|
- [docs/proposal.md](docs/proposal.md): problems, goal, requirements
|
|
81
81
|
- [docs/design.md](docs/design.md): layout, roles, flow, audit, file formats, CLI
|
|
82
82
|
- [docs/ROADMAP.md](docs/ROADMAP.md): versions
|
|
83
|
+
- [docs/conversation/](docs/conversation/): the maintainer's design conversations — what was weighed and why, not rules (in Korean only)
|
|
83
84
|
- Korean editions: [proposal.ko.md](docs/proposal.ko.md), [design.ko.md](docs/design.ko.md), [ROADMAP.ko.md](docs/ROADMAP.ko.md). Where an English and a Korean edition disagree, the Korean file wins.
|
|
84
85
|
|
|
85
86
|
## License
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { applicable, formatGateDiff } from '../lib/gate-refresh.js';
|
|
4
|
+
import { GATE_SCRIPT } from '../lib/gate-script.js';
|
|
5
|
+
import { BACK, EXIT } from '../lib/prompter.js';
|
|
6
|
+
import { configureGates, fileGates, gateDiff } from './configure.js';
|
|
7
|
+
import { hookTool } from './install.js';
|
|
8
|
+
const GATES = '.agents/harness/gates.yaml';
|
|
9
|
+
/** The gates as the project has them now: name, command, source, in order; and what runs them. */
|
|
10
|
+
export function formatGates(root) {
|
|
11
|
+
const path = join(root, GATES);
|
|
12
|
+
if (!existsSync(path))
|
|
13
|
+
return ' no gates.yaml — run `reins install`';
|
|
14
|
+
const gates = fileGates(readFileSync(path, 'utf8'));
|
|
15
|
+
const lines = gates.length
|
|
16
|
+
? gates.map((g, i) => ` ${String(i + 1).padStart(2)}. ${g.name.padEnd(18)} ${g.cmd} (${g.from ?? 'written by hand'})${g.optional ? ' optional — not in the hooks' : ''}`)
|
|
17
|
+
: [' no gates'];
|
|
18
|
+
const tool = hookTool(root);
|
|
19
|
+
lines.push(` hook tool: ${tool ?? 'none found'}`, ` gate script: ${existsSync(join(root, GATE_SCRIPT)) ? GATE_SCRIPT : 'none (no required gate)'}`);
|
|
20
|
+
return lines.join('\n');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Run the discovery again and let the user pick which differences to apply (design §9). Nothing is
|
|
24
|
+
* written unless something is picked. Returns `exit` when the user left with Ctrl-C.
|
|
25
|
+
*/
|
|
26
|
+
export async function refreshGates(root, prompter) {
|
|
27
|
+
const diff = gateDiff(root);
|
|
28
|
+
if (!diff) {
|
|
29
|
+
prompter.note('no gates.yaml — run `reins install`');
|
|
30
|
+
return 'done';
|
|
31
|
+
}
|
|
32
|
+
const can = applicable(diff);
|
|
33
|
+
const yours = diff.filter((d) => d.kind === 'yours');
|
|
34
|
+
if (yours.length)
|
|
35
|
+
prompter.note(yours.map(formatGateDiff).join('\n'));
|
|
36
|
+
if (can.length === 0) {
|
|
37
|
+
prompter.note('gates: up to date — the discovery finds what gates.yaml holds');
|
|
38
|
+
return 'done';
|
|
39
|
+
}
|
|
40
|
+
const picked = await prompter.multiselect({
|
|
41
|
+
message: 'Differences to apply to gates.yaml (nothing is changed unless picked)',
|
|
42
|
+
options: can.map((d) => ({ value: d.name, label: formatGateDiff(d) })),
|
|
43
|
+
initial: [],
|
|
44
|
+
});
|
|
45
|
+
if (picked === EXIT)
|
|
46
|
+
return 'exit';
|
|
47
|
+
if (picked === BACK || picked.length === 0) {
|
|
48
|
+
prompter.note('gates: nothing changed');
|
|
49
|
+
return 'done';
|
|
50
|
+
}
|
|
51
|
+
const r = configureGates({ cwd: root, refresh: true, apply: picked });
|
|
52
|
+
prompter.note(r.refused
|
|
53
|
+
? `not changed: ${r.refused}`
|
|
54
|
+
: `gates: applied ${r.applied?.join(', ')} — gates.yaml and ${GATE_SCRIPT} written; commit them (the hook line stays as it is)`);
|
|
55
|
+
return 'done';
|
|
56
|
+
}
|
|
57
|
+
/** The gates item of the config screen: see the gates, find them again, add subdirectory proposals. */
|
|
58
|
+
export async function gatesScreen(root, prompter) {
|
|
59
|
+
for (;;) {
|
|
60
|
+
prompter.note(formatGates(root));
|
|
61
|
+
const v = await prompter.select({
|
|
62
|
+
message: 'Gates',
|
|
63
|
+
options: [
|
|
64
|
+
{ value: 'back', label: '< Configuration' },
|
|
65
|
+
{ value: 'refresh', label: 'refresh', hint: 'find the gates again and pick what to apply' },
|
|
66
|
+
{ value: 'add', label: 'add subdirectory proposals' },
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
if (v === EXIT)
|
|
70
|
+
return 'exit';
|
|
71
|
+
if (v === BACK || v === 'back')
|
|
72
|
+
return 'back';
|
|
73
|
+
if (v === 'refresh') {
|
|
74
|
+
if ((await refreshGates(root, prompter)) === 'exit')
|
|
75
|
+
return 'exit';
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const { available } = configureGates({ cwd: root });
|
|
79
|
+
if (available.length === 0) {
|
|
80
|
+
prompter.note('no subdirectory proposals left');
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const picked = await prompter.multiselect({
|
|
84
|
+
message: 'Subdirectory gates to add',
|
|
85
|
+
options: available.map((g) => ({ value: g.name, label: g.name, hint: g.cmd })),
|
|
86
|
+
initial: [],
|
|
87
|
+
});
|
|
88
|
+
if (picked === EXIT)
|
|
89
|
+
return 'exit';
|
|
90
|
+
if (picked === BACK || picked.length === 0)
|
|
91
|
+
continue;
|
|
92
|
+
const r = configureGates({ cwd: root, add: picked });
|
|
93
|
+
prompter.note(r.refused ? `not changed: ${r.refused}` : `gates: added ${r.added.join(', ')}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -26,7 +26,8 @@ export function groupLine(group, spec, mode) {
|
|
|
26
26
|
? show({ vendor: spec.vendor, model: spec.model })
|
|
27
27
|
: '—';
|
|
28
28
|
const n = Object.keys(spec.roles ?? {}).length;
|
|
29
|
-
|
|
29
|
+
const fb = spec.fallback ? ` (fallback: ${show(spec.fallback)})` : '';
|
|
30
|
+
return `${group.padEnd(12)} ${models}${fb}${n ? ` +${n} role${n > 1 ? 's' : ''}` : ''}${tag}`;
|
|
30
31
|
}
|
|
31
32
|
/** The packaged list of known models per vendor (`harness/models.yaml`, spec ST-2). */
|
|
32
33
|
export function catalogue() {
|
|
@@ -153,6 +154,11 @@ async function groupScreen(o, group, spec, write, mode) {
|
|
|
153
154
|
{ value: 'one', label: many ? 'one model' : 'set the model' },
|
|
154
155
|
...(many ? [{ value: 'many', label: 'several models', hint: 'first = control (pl)' }] : []),
|
|
155
156
|
...(roles.length ? [{ value: 'role', label: 'a model for one role' }] : []),
|
|
157
|
+
{
|
|
158
|
+
value: 'fallback',
|
|
159
|
+
label: 'fallback (optional)',
|
|
160
|
+
hint: 'what to call when the model cannot be called',
|
|
161
|
+
},
|
|
156
162
|
{ value: 'off', label: 'switch off', hint: 'the PM does it' },
|
|
157
163
|
],
|
|
158
164
|
});
|
|
@@ -160,6 +166,8 @@ async function groupScreen(o, group, spec, write, mode) {
|
|
|
160
166
|
return 'exit';
|
|
161
167
|
if (pick === BACK || pick === 'back')
|
|
162
168
|
return 'back';
|
|
169
|
+
if (pick === 'fallback')
|
|
170
|
+
return fallbackScreen(o, group, spec, write);
|
|
163
171
|
if (pick === 'off') {
|
|
164
172
|
await write({ off: [group] }, `${group} off`);
|
|
165
173
|
return 'back';
|
|
@@ -209,6 +217,69 @@ async function groupScreen(o, group, spec, write, mode) {
|
|
|
209
217
|
await write({ set: [`${group}.${role}=${b.vendor}:${b.model}`] }, `${group}.${role} → ${show(b)}`);
|
|
210
218
|
return 'back';
|
|
211
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* The fallback of a group's model or of a role's own model (design §5): pick a model, or clear it. Only a
|
|
222
|
+
* place that has a model in the file being written can take one; `configureBindings` says so otherwise.
|
|
223
|
+
*/
|
|
224
|
+
async function fallbackScreen(o, group, spec, write) {
|
|
225
|
+
const { prompter } = o;
|
|
226
|
+
const targets = [];
|
|
227
|
+
if (spec?.models?.length || (spec?.vendor && spec.model))
|
|
228
|
+
targets.push({
|
|
229
|
+
value: group,
|
|
230
|
+
label: `${group} (the group's model)`,
|
|
231
|
+
hint: show(spec.fallback).replace('off (PM)', 'none'),
|
|
232
|
+
current: spec.fallback,
|
|
233
|
+
});
|
|
234
|
+
for (const [r, b] of Object.entries(spec?.roles ?? {}))
|
|
235
|
+
targets.push({
|
|
236
|
+
value: `${group}.${r}`,
|
|
237
|
+
label: `${group}.${r} (${show(b)})`,
|
|
238
|
+
hint: show(b.fallback).replace('off (PM)', 'none'),
|
|
239
|
+
current: b.fallback,
|
|
240
|
+
});
|
|
241
|
+
if (targets.length === 0) {
|
|
242
|
+
prompter.note(`${group} has no model yet — set one first; a fallback goes with a model`);
|
|
243
|
+
return 'back';
|
|
244
|
+
}
|
|
245
|
+
let target = targets[0];
|
|
246
|
+
if (targets.length > 1) {
|
|
247
|
+
const t = await prompter.select({
|
|
248
|
+
message: `${group}: fallback of`,
|
|
249
|
+
options: [
|
|
250
|
+
{ value: 'back', label: '< back' },
|
|
251
|
+
...targets.map(({ value, label, hint }) => ({ value, label, hint })),
|
|
252
|
+
],
|
|
253
|
+
});
|
|
254
|
+
if (t === EXIT)
|
|
255
|
+
return 'exit';
|
|
256
|
+
if (t === BACK || t === 'back')
|
|
257
|
+
return 'back';
|
|
258
|
+
target = targets.find((x) => x.value === t);
|
|
259
|
+
}
|
|
260
|
+
const what = await prompter.select({
|
|
261
|
+
message: `${target.value}: fallback (now: ${target.hint})`,
|
|
262
|
+
options: [
|
|
263
|
+
{ value: 'back', label: '< back' },
|
|
264
|
+
{ value: 'pick', label: 'choose a model' },
|
|
265
|
+
...(target.current ? [{ value: 'none', label: 'none', hint: 'remove the fallback' }] : []),
|
|
266
|
+
],
|
|
267
|
+
});
|
|
268
|
+
if (what === EXIT)
|
|
269
|
+
return 'exit';
|
|
270
|
+
if (what === BACK || what === 'back')
|
|
271
|
+
return 'back';
|
|
272
|
+
if (what === 'none') {
|
|
273
|
+
await write({ fallback: [`${target.value}=none`] }, `${target.value} fallback removed`);
|
|
274
|
+
return 'back';
|
|
275
|
+
}
|
|
276
|
+
const b = await pickModel(o, `${target.value} fallback`, target.current);
|
|
277
|
+
if (b === EXIT)
|
|
278
|
+
return 'exit';
|
|
279
|
+
if (b)
|
|
280
|
+
await write({ fallback: [`${target.value}=${b.vendor}:${b.model}`] }, `${target.value} fallback → ${show(b)}`);
|
|
281
|
+
return 'back';
|
|
282
|
+
}
|
|
212
283
|
/** Tool (used tools only), then model. Returns the binding, `undefined` for back, or EXIT. */
|
|
213
284
|
async function pickModel(o, label, current) {
|
|
214
285
|
const { prompter, root } = o;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { gatesScreen } from './config-gates.js';
|
|
1
2
|
import { effectiveBindings, resolveRoles } from '../lib/bindings.js';
|
|
2
3
|
import { newModelCache, vendors } from '../lib/detect.js';
|
|
3
4
|
import { repoRoot } from '../lib/git.js';
|
|
@@ -5,7 +6,7 @@ import { groupLine, modelsScreen } from './config-models.js';
|
|
|
5
6
|
import { configureBindings } from './configure.js';
|
|
6
7
|
import { LOCAL_DELEGATION_NOTE } from '../lib/local-delegation.js';
|
|
7
8
|
import { clackPrompter, isInteractive } from '../lib/prompter.js';
|
|
8
|
-
export const CONFIG_HINT = 'change with: reins config bindings --set <default|group|group.role>=<model> [--local] (see: reins config bindings --help)';
|
|
9
|
+
export const CONFIG_HINT = 'change with: reins config bindings --set <default|group|group.role>=<model> [--fallback <group|group.role>=<model|none>] [--local] (see: reins config bindings --help)';
|
|
9
10
|
/** The effective settings as text: mode, audit, the PM, each role that is on. */
|
|
10
11
|
export function formatBindings(doc) {
|
|
11
12
|
const lines = [
|
|
@@ -24,7 +25,7 @@ export function formatBindings(doc) {
|
|
|
24
25
|
.trim()}`);
|
|
25
26
|
}
|
|
26
27
|
for (const r of on)
|
|
27
|
-
lines.push(` ${`${r.group}/${r.role}`.padEnd(26)} ${r.models.map((b) => `${b.vendor} ${b.model}`).join(', ')} (${r.source})`);
|
|
28
|
+
lines.push(` ${`${r.group}/${r.role}`.padEnd(26)} ${r.models.map((b) => `${b.vendor} ${b.model}`).join(', ')} (${r.source})${r.fallback ? ` — fallback: ${r.fallback.vendor} ${r.fallback.model}` : ''}`);
|
|
28
29
|
const tools = Object.entries(doc.tools ?? {})
|
|
29
30
|
.map(([n, t]) => `${n}${t?.use === false ? ' (unused)' : ''}`)
|
|
30
31
|
.join(', ');
|
|
@@ -64,6 +65,7 @@ export async function runConfig(o = {}) {
|
|
|
64
65
|
value: 'audit',
|
|
65
66
|
label: `audit: ${doc?.audit?.required === false ? 'off' : 'required'}`,
|
|
66
67
|
},
|
|
68
|
+
{ value: 'gates', label: 'gates', hint: 'the project checks: see them, find them again' },
|
|
67
69
|
{ value: 'exit', label: 'exit' },
|
|
68
70
|
],
|
|
69
71
|
});
|
|
@@ -75,6 +77,11 @@ export async function runConfig(o = {}) {
|
|
|
75
77
|
return 0;
|
|
76
78
|
continue;
|
|
77
79
|
}
|
|
80
|
+
if (v === 'gates') {
|
|
81
|
+
if ((await gatesScreen(root, prompter)) === 'exit')
|
|
82
|
+
return 0;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
78
85
|
if (v === 'tools') {
|
|
79
86
|
const found = detect();
|
|
80
87
|
const picked = await prompter.multiselect({
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { parse, parseDocument } from 'yaml';
|
|
4
|
-
import { subdirProposals, vendorOf, vendors } from '../lib/detect.js';
|
|
5
|
-
import {
|
|
3
|
+
import { isScalar, isSeq, parse, parseDocument } from 'yaml';
|
|
4
|
+
import { discoverGates, subdirProposals, vendorOf, vendors, } from '../lib/detect.js';
|
|
5
|
+
import { applicable, diffGates } from '../lib/gate-refresh.js';
|
|
6
|
+
import { GROUP_ROLES, GROUPS, effectiveBindings, fallbackProblems, readLocalBindings, readTeam, resolveRoles, validateBindings, writeBindings, } from '../lib/bindings.js';
|
|
6
7
|
import { modeChangedNote, placeNote, renderBlocks } from '../lib/agents-md.js';
|
|
7
8
|
import { applyBlocks } from '../lib/blocks.js';
|
|
8
9
|
import { generateVendorFiles } from '../lib/generate.js';
|
|
@@ -16,9 +17,12 @@ export function parseBinding(v) {
|
|
|
16
17
|
if (!s)
|
|
17
18
|
return null;
|
|
18
19
|
const i = s.indexOf(':');
|
|
19
|
-
if (i
|
|
20
|
-
return { vendor: s
|
|
21
|
-
|
|
20
|
+
if (i < 0)
|
|
21
|
+
return { vendor: vendorOf(s), model: s };
|
|
22
|
+
// `vendor:` or `:model` names no model: the personal file is not schema-checked, so refuse it here
|
|
23
|
+
const vendor = s.slice(0, i).trim();
|
|
24
|
+
const model = s.slice(i + 1).trim();
|
|
25
|
+
return vendor && model ? { vendor, model } : null;
|
|
22
26
|
}
|
|
23
27
|
/** Rewrite AGENTS.md's managed blocks for these settings (design §5); a mode change adds the light mode-changed note (ST-5). */
|
|
24
28
|
export function refreshAgents(root, doc, modeFrom) {
|
|
@@ -90,7 +94,9 @@ export async function configureBindings(o) {
|
|
|
90
94
|
if (role) {
|
|
91
95
|
if (!roles.includes(role))
|
|
92
96
|
return refuse(`unknown role "${role}" in ${group} — roles: ${roles.join(', ') || group}`);
|
|
93
|
-
|
|
97
|
+
// a new model keeps the role's fallback; the check below refuses it when they are now the same
|
|
98
|
+
const kept = spec.roles?.[role]?.fallback;
|
|
99
|
+
spec.roles = { ...spec.roles, [role]: kept ? { ...b, fallback: kept } : b };
|
|
94
100
|
}
|
|
95
101
|
else {
|
|
96
102
|
delete spec.models;
|
|
@@ -135,6 +141,52 @@ export async function configureBindings(o) {
|
|
|
135
141
|
changed.push(group);
|
|
136
142
|
}
|
|
137
143
|
}
|
|
144
|
+
// fallbacks last, so they are checked against the models this same call set
|
|
145
|
+
for (const pair of o.fallback ?? []) {
|
|
146
|
+
const eq = pair.indexOf('=');
|
|
147
|
+
const target = pair.slice(0, eq).trim();
|
|
148
|
+
const value = eq > 0 ? pair.slice(eq + 1).trim() : '';
|
|
149
|
+
const b = value === 'none' ? null : parseBinding(value);
|
|
150
|
+
if (!target || (!b && value !== 'none'))
|
|
151
|
+
return refuse(`"${pair}" is not target=model|none`);
|
|
152
|
+
const [g, role] = target.split('.');
|
|
153
|
+
const group = groupOf(g ?? '');
|
|
154
|
+
if (!group)
|
|
155
|
+
return refuse(`unknown group "${g}" — groups: ${GROUPS.join(', ')}`);
|
|
156
|
+
const where = o.local ? 'your personal file' : 'bindings.yaml';
|
|
157
|
+
next.groups = { ...next.groups };
|
|
158
|
+
const spec = { ...next.groups[group] };
|
|
159
|
+
if (role) {
|
|
160
|
+
if (!GROUP_ROLES[group].includes(role))
|
|
161
|
+
return refuse(`unknown role "${role}" in ${group} — roles: ${GROUP_ROLES[group].join(', ') || group}`);
|
|
162
|
+
const own = spec.roles?.[role];
|
|
163
|
+
if (!own)
|
|
164
|
+
return b
|
|
165
|
+
? refuse(`${group}.${role} has no model of its own in ${where} — set it with --set ${group}.${role}=<model>, or give the group a fallback`)
|
|
166
|
+
: refuse(`${group}.${role} has no fallback to clear in ${where}`);
|
|
167
|
+
if (!b && !own.fallback)
|
|
168
|
+
return refuse(`${group}.${role} has no fallback to clear in ${where}`);
|
|
169
|
+
const { fallback: _old, ...rest } = own;
|
|
170
|
+
spec.roles = { ...spec.roles, [role]: b ? { ...rest, fallback: b } : rest };
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
if (b && !spec.vendor && !spec.models?.length)
|
|
174
|
+
return refuse(`${group} has no model in ${where} — set it with --set ${group}=<model> first (a fallback goes with the model beside it)`);
|
|
175
|
+
// clearing what is not there must not write an empty group: in the personal file `{}` switches
|
|
176
|
+
// the team's group off for that person
|
|
177
|
+
if (!b && !spec.fallback)
|
|
178
|
+
return refuse(`${group} has no fallback to clear in ${where}`);
|
|
179
|
+
if (b)
|
|
180
|
+
spec.fallback = b;
|
|
181
|
+
else
|
|
182
|
+
delete spec.fallback;
|
|
183
|
+
}
|
|
184
|
+
next.groups[group] = spec;
|
|
185
|
+
changed.push(`${target} fallback`);
|
|
186
|
+
}
|
|
187
|
+
const wrong = fallbackProblems(next);
|
|
188
|
+
if (wrong.length)
|
|
189
|
+
return refuse(wrong.join('; '));
|
|
138
190
|
if (o.mode && next.mode !== o.mode) {
|
|
139
191
|
next.mode = o.mode;
|
|
140
192
|
changed.push('mode');
|
|
@@ -192,15 +244,107 @@ export async function configureBindings(o) {
|
|
|
192
244
|
localDelegation: local,
|
|
193
245
|
};
|
|
194
246
|
}
|
|
195
|
-
|
|
247
|
+
const GATES = '.agents/harness/gates.yaml';
|
|
248
|
+
/** The gates of a `gates.yaml` document, in its order (gates missing from `order` follow). */
|
|
249
|
+
export function fileGates(text) {
|
|
250
|
+
const g = parse(text);
|
|
251
|
+
const gates = g?.gates ?? {};
|
|
252
|
+
const names = [...new Set([...(g?.order ?? []), ...Object.keys(gates)])];
|
|
253
|
+
return names
|
|
254
|
+
.filter((n) => gates[n]?.cmd)
|
|
255
|
+
.map((n) => ({
|
|
256
|
+
name: n,
|
|
257
|
+
cmd: gates[n].cmd,
|
|
258
|
+
...(gates[n].from ? { from: gates[n].from } : {}),
|
|
259
|
+
...(gates[n].optional ? { optional: true } : {}),
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Put a gate that was just added to `gates` at the end of `order`. A file without `order` runs its gates
|
|
264
|
+
* in the order they are written, so the list starts from those — never from the new gate alone.
|
|
265
|
+
*/
|
|
266
|
+
function appendOrder(doc, name) {
|
|
267
|
+
if (isSeq(doc.get('order'))) {
|
|
268
|
+
doc.addIn(['order'], name);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const gates = doc.toJS()?.gates ?? {};
|
|
272
|
+
doc.set('order', doc.createNode([...Object.keys(gates).filter((n) => n !== name), name]));
|
|
273
|
+
}
|
|
274
|
+
/** How gates.yaml differs from what the discovery of installation finds now (design §9). */
|
|
275
|
+
export function gateDiff(root) {
|
|
276
|
+
const path = join(root, GATES);
|
|
277
|
+
if (!existsSync(path))
|
|
278
|
+
return null;
|
|
279
|
+
const found = discoverGates(root);
|
|
280
|
+
return diffGates(root, fileGates(readFileSync(path, 'utf8')), [
|
|
281
|
+
...found.gates,
|
|
282
|
+
...found.proposals,
|
|
283
|
+
]);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* `reins config gates` (design §9). `--add <name>…` appends subdirectory proposals. `--refresh` runs the
|
|
287
|
+
* discovery again and reports the differences; `--apply <name…|all>` applies the chosen ones: a new gate is
|
|
288
|
+
* appended, a changed one gets its command and source, a gone one is removed. Comments and other keys stay,
|
|
289
|
+
* a gate written by hand is never touched, and the gate script is rewritten when the file changes.
|
|
290
|
+
*/
|
|
196
291
|
export function configureGates(o = {}) {
|
|
197
292
|
const root = repoRoot(o.cwd ?? process.cwd());
|
|
198
|
-
const path = join(root,
|
|
293
|
+
const path = join(root, GATES);
|
|
199
294
|
if (!existsSync(path))
|
|
200
295
|
return { refused: 'no gates.yaml — run reins install', code: 2, available: [], added: [] };
|
|
201
296
|
const doc = parseDocument(readFileSync(path, 'utf8'));
|
|
202
297
|
const have = new Set(Object.keys(doc.toJS()?.gates ?? {}));
|
|
203
298
|
const available = subdirProposals(root).filter((g) => !have.has(g.name));
|
|
299
|
+
if (o.refresh || o.apply) {
|
|
300
|
+
const diff = gateDiff(root) ?? [];
|
|
301
|
+
const can = applicable(diff);
|
|
302
|
+
// every name is checked, `all` beside others too: one unknown name refuses the whole call
|
|
303
|
+
const asked = [...new Set(o.apply ?? [])];
|
|
304
|
+
const unknown = asked.filter((n) => n !== 'all' && !can.some((d) => d.name === n));
|
|
305
|
+
const names = asked.includes('all') ? can.map((d) => d.name) : asked;
|
|
306
|
+
if (unknown.length)
|
|
307
|
+
return {
|
|
308
|
+
refused: `nothing to apply under: ${unknown.join(', ')} — names: ${can.map((d) => d.name).join(', ') || 'none'}`,
|
|
309
|
+
code: 1,
|
|
310
|
+
available,
|
|
311
|
+
added: [],
|
|
312
|
+
diff,
|
|
313
|
+
applied: [],
|
|
314
|
+
};
|
|
315
|
+
for (const n of names) {
|
|
316
|
+
const d = can.find((x) => x.name === n);
|
|
317
|
+
if (d.kind === 'gone') {
|
|
318
|
+
doc.deleteIn(['gates', d.name]);
|
|
319
|
+
// every occurrence: a name left in `order` without its gate would dangle
|
|
320
|
+
const order = doc.get('order');
|
|
321
|
+
if (isSeq(order))
|
|
322
|
+
for (let i = order.items.length - 1; i >= 0; i--) {
|
|
323
|
+
const x = order.items[i];
|
|
324
|
+
if ((isScalar(x) ? x.value : x) === d.name)
|
|
325
|
+
order.delete(i);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
else if (d.kind === 'changed') {
|
|
329
|
+
doc.setIn(['gates', d.name, 'cmd'], d.cmd);
|
|
330
|
+
doc.setIn(['gates', d.name, 'from'], d.from);
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
doc.setIn(['gates', d.name], doc.createNode({ cmd: d.cmd, from: d.from, ...(d.optional ? { optional: true } : {}) }));
|
|
334
|
+
appendOrder(doc, d.name);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (names.length) {
|
|
338
|
+
writeFileSync(path, doc.toString());
|
|
339
|
+
writeGenerated(root, generateVendorFiles(root), false);
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
available: available.filter((g) => !names.includes(g.name)),
|
|
343
|
+
added: [],
|
|
344
|
+
diff,
|
|
345
|
+
applied: names,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
204
348
|
const names = o.add ?? [];
|
|
205
349
|
const unknown = names.filter((n) => !available.some((g) => g.name === n));
|
|
206
350
|
if (unknown.length)
|
|
@@ -214,13 +358,13 @@ export function configureGates(o = {}) {
|
|
|
214
358
|
for (const n of new Set(names)) {
|
|
215
359
|
const g = available.find((x) => x.name === n);
|
|
216
360
|
doc.setIn(['gates', g.name], doc.createNode({ cmd: g.cmd, from: g.from }));
|
|
217
|
-
|
|
218
|
-
doc.addIn(['order'], g.name);
|
|
219
|
-
else
|
|
220
|
-
doc.set('order', doc.createNode([g.name]));
|
|
361
|
+
appendOrder(doc, g.name);
|
|
221
362
|
added.push(g.name);
|
|
222
363
|
}
|
|
223
|
-
if (added.length)
|
|
364
|
+
if (added.length) {
|
|
224
365
|
writeFileSync(path, doc.toString());
|
|
366
|
+
// the gate script holds the commands of gates.yaml (design §6): it follows the file
|
|
367
|
+
writeGenerated(root, generateVendorFiles(root), false);
|
|
368
|
+
}
|
|
225
369
|
return { available: available.filter((g) => !added.includes(g.name)), added };
|
|
226
370
|
}
|
|
@@ -9,6 +9,7 @@ import { apply, listFiles } from '../lib/fsx.js';
|
|
|
9
9
|
import { repoRoot } from '../lib/git.js';
|
|
10
10
|
import { harnessVersion, packageHarness, packageSkills, packageVersion } from '../lib/upstream.js';
|
|
11
11
|
import { generateVendorFiles } from '../lib/generate.js';
|
|
12
|
+
import { hookLine, requiredGates } from '../lib/gate-script.js';
|
|
12
13
|
import { defaultBindings, readTeam } from '../lib/bindings.js';
|
|
13
14
|
import { overlayReader, workTreeReader } from '../lib/reader.js';
|
|
14
15
|
import { LOCAL_DELEGATION, onboardingNote, placeNote, renderBlocks } from '../lib/agents-md.js';
|
|
@@ -69,22 +70,18 @@ const LOCTX_README = `# .loctx — 이 머신·이 개발자만 (gitignore)
|
|
|
69
70
|
| ROADMAP.local.md | 날 것의 아이디어. 사용자와 정리되면 docs/ROADMAP.md | 사용자 |
|
|
70
71
|
| history/<version>.md | 버전마다 한 장: 결정, 판정, 건너뛴 단계, 감사·회고 요약 | 지우지 않음 |
|
|
71
72
|
| reports/<version>/ | 게이트·테스트 원본 로그, 하위 보고 | 회고 뒤 (history·감사에 요약한 다음) |
|
|
73
|
+
| reports/gates/<tree>.log | 훅이 돌린 검사의 출력 (.agents/harness/run-gates.sh; 커밋의 트리 해시가 파일 이름) | 회고 뒤 (그 버전의 stable 전에 쓰인 것) |
|
|
72
74
|
| context/ | 개인 컨텍스트 — 대화·메모 | 사용자 |
|
|
73
75
|
| bindings.local.yaml | 나만 쓰는 모델 할당 (있으면 팀 설정보다 우선) | 사용자 |
|
|
74
76
|
`;
|
|
75
77
|
const TOOL_NAMES = ['claude', 'openai', 'google', 'gemini', 'copilot', 'cursor'];
|
|
76
78
|
/** The gate commands, in order, as hook lines (design §6). */
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return (g?.order ?? Object.keys(gates))
|
|
84
|
-
.map((n) => gates[n])
|
|
85
|
-
.filter((x) => !!x?.cmd && !x.optional)
|
|
86
|
-
.map((x) => x.cmd);
|
|
87
|
-
}
|
|
79
|
+
/** The git hooks reins proposes the gates for. */
|
|
80
|
+
const HOOK_STAGES = ['pre-commit', 'pre-push'];
|
|
81
|
+
/** A `reins:begin hooks` block in a hook file, with its body. */
|
|
82
|
+
const HOOK_BLOCK = /# reins:begin hooks\n([\s\S]*?)# reins:end hooks/g;
|
|
83
|
+
/** A command that runs reins: what 0.x put into hooks and settings. */
|
|
84
|
+
export const RUNS_REINS = /@bluenyang\/reins|reins\.js\b|(^|[\s;&|])reins\s+(check|hook|gate|status)\b/;
|
|
88
85
|
/** `reins install` (design §9): place the harness, ask, propose hooks, mark onboarding. Never writes history. */
|
|
89
86
|
export async function runInstall(o) {
|
|
90
87
|
const root = repoRoot(o.cwd ?? process.cwd());
|
|
@@ -271,44 +268,56 @@ export async function runInstall(o) {
|
|
|
271
268
|
notes.push('.claude/memory found — left as it is; the PM can propose knowledge entries from it in a retro');
|
|
272
269
|
// 4c. a release: draft from dispatchable workflows — proposal only, never written
|
|
273
270
|
notes.push(...releaseDraftNotes(draftRelease(root)));
|
|
274
|
-
// 5. hooks:
|
|
271
|
+
// 5. hooks: one line per stage that calls the project's gate script (design §6)
|
|
275
272
|
const tool = hookTool(root);
|
|
276
|
-
const
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
.filter((x) => x && !x.optional)
|
|
284
|
-
.map((x) => x.cmd);
|
|
285
|
-
})()
|
|
286
|
-
: cmds;
|
|
287
|
-
let addHooks = !!o.hooks;
|
|
288
|
-
if (lines.length && tool === 'husky' && !addHooks && o.confirmHooks && !o.dryRun) {
|
|
289
|
-
const yes = await o.confirmHooks.confirm({
|
|
290
|
-
message: `Add the project gates to husky pre-commit and pre-push? (${lines.join(' && ')})`,
|
|
291
|
-
initial: true,
|
|
273
|
+
const gatesPath = join(root, '.agents/harness/gates.yaml');
|
|
274
|
+
const gated = requiredGates(writes.find((w) => w.path === '.agents/harness/gates.yaml')?.content ??
|
|
275
|
+
(existsSync(gatesPath) ? readFileSync(gatesPath, 'utf8') : undefined)).length > 0;
|
|
276
|
+
if (gated && tool === 'husky') {
|
|
277
|
+
const files = HOOK_STAGES.map((stage) => {
|
|
278
|
+
const p = join(root, '.husky', stage);
|
|
279
|
+
return { stage, cur: existsSync(p) ? readFileSync(p, 'utf8') : '' };
|
|
292
280
|
});
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
addHooks
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
281
|
+
const missing = files.filter((f) => !f.cur.includes('# reins:begin hooks'));
|
|
282
|
+
let addHooks = !!o.hooks;
|
|
283
|
+
if (missing.length && !addHooks && o.confirmHooks && !o.dryRun) {
|
|
284
|
+
const yes = await o.confirmHooks.confirm({
|
|
285
|
+
message: `Add the project gates to husky pre-commit and pre-push? (${hookLine('<stage>')})`,
|
|
286
|
+
initial: true,
|
|
287
|
+
});
|
|
288
|
+
if (yes === EXIT)
|
|
289
|
+
return cancelled();
|
|
290
|
+
addHooks = yes === true;
|
|
291
|
+
}
|
|
292
|
+
for (const { stage, cur } of files) {
|
|
293
|
+
const line = hookLine(stage);
|
|
294
|
+
if (cur.includes('# reins:begin hooks')) {
|
|
295
|
+
// a block an earlier reins wrote: its body becomes the one line. A block that runs reins is 0.x
|
|
296
|
+
// and `update` removes it as a whole; one that already is the line stays.
|
|
297
|
+
const held = [];
|
|
298
|
+
const next = cur.replace(HOOK_BLOCK, (block, body) => {
|
|
299
|
+
if (RUNS_REINS.test(body) || body.trim() === line)
|
|
300
|
+
return block;
|
|
301
|
+
held.push(...body.split('\n').filter((l) => l.trim()));
|
|
302
|
+
return `# reins:begin hooks\n${line}\n# reins:end hooks`;
|
|
303
|
+
});
|
|
304
|
+
if (next === cur)
|
|
303
305
|
continue;
|
|
304
|
-
add(`.husky/${stage}`,
|
|
306
|
+
add(`.husky/${stage}`, next, 'hook: the gate script');
|
|
307
|
+
notes.push(`.husky/${stage}: the reins hooks block now calls the gate script — it held: ${held.join(' && ')} (move a line of your own outside the block)`);
|
|
305
308
|
}
|
|
309
|
+
else if (addHooks)
|
|
310
|
+
add(`.husky/${stage}`, `${cur.replace(/\s*$/, '')}\n# reins:begin hooks\n${line}\n# reins:end hooks\n`.replace(/^\n/, ''), 'hook: the gate script');
|
|
306
311
|
}
|
|
307
|
-
|
|
308
|
-
notes.push(`hook proposal (
|
|
309
|
-
else
|
|
310
|
-
notes.push('no hook tool found — the PM asks which one to use during onboarding');
|
|
312
|
+
if (missing.length && !addHooks)
|
|
313
|
+
notes.push(`hook proposal (husky): add \`${hookLine('pre-commit')}\` to .husky/pre-commit and \`${hookLine('pre-push')}\` to .husky/pre-push; re-run with --hooks to add them`);
|
|
311
314
|
}
|
|
315
|
+
else if (gated && tool === 'lefthook')
|
|
316
|
+
notes.push(`hook proposal (lefthook): under \`pre-commit: commands:\` add \`gates: { run: ${hookLine('pre-commit')} }\`, and the same under \`pre-push:\` with \`${hookLine('pre-push')}\` (reins proposes lefthook lines only; add them to its config yourself)`);
|
|
317
|
+
else if (gated && tool === 'pre-commit')
|
|
318
|
+
notes.push(`hook proposal (pre-commit): under \`repos:\` add \`- repo: local\` with a hook \`{ id: gates, name: project gates, entry: ${hookLine('pre-commit')}, language: system, pass_filenames: false }\`, and one with \`stages: [pre-push]\` and \`${hookLine('pre-push')}\` (reins proposes pre-commit lines only; add them to its config yourself)`);
|
|
319
|
+
else if (gated)
|
|
320
|
+
notes.push(`no hook tool found — the PM asks which one to use during onboarding; whichever it is runs \`${hookLine('pre-commit')}\` and \`${hookLine('pre-push')}\``);
|
|
312
321
|
// 6. AGENTS.md: managed blocks, the onboarding note; CLAUDE.md pointer
|
|
313
322
|
const agentsPath = join(root, 'AGENTS.md');
|
|
314
323
|
const before = existsSync(agentsPath) ? readFileSync(agentsPath, 'utf8') : '# AGENTS.md\n';
|