@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.
- package/README.md +50 -203
- package/cli/dist/commands/config-models.js +206 -127
- package/cli/dist/commands/config.js +104 -16
- package/cli/dist/commands/configure.js +166 -134
- package/cli/dist/commands/install.js +161 -217
- package/cli/dist/commands/migrate.js +23 -48
- package/cli/dist/commands/update.js +203 -30
- package/cli/dist/lib/agents-md.js +111 -0
- package/cli/dist/lib/bindings.js +227 -386
- package/cli/dist/lib/detect.js +7 -2
- package/cli/dist/lib/generate.js +56 -75
- package/cli/dist/lib/harness.js +0 -3
- package/cli/dist/lib/migrate-plan.js +3 -3
- package/cli/dist/lib/prompter.js +4 -4
- package/cli/dist/lib/reader.js +20 -0
- package/cli/dist/lib/upstream.js +0 -17
- package/cli/dist/lib/vendor-write.js +9 -56
- package/cli/dist/reins.js +59 -270
- package/docs/README.ko.md +31 -204
- package/harness/CHANGELOG.md +8 -3
- package/harness/VERSION +1 -1
- package/harness/models.yaml +8 -0
- package/harness/policy/common-red-lines.yaml +4 -4
- package/harness/roles/advisor.md +10 -14
- package/harness/roles/auditor.md +17 -0
- package/harness/roles/executor.md +32 -0
- package/harness/roles/implementer.md +23 -21
- package/harness/roles/pl.md +44 -21
- package/harness/roles/planner.md +17 -19
- package/harness/roles/pm.md +16 -21
- package/harness/schemas/bindings.schema.json +55 -0
- package/harness/schemas/install.schema.json +1 -2
- package/harness/schemas/intent.schema.json +1 -13
- package/harness/templates/agents-md-blocks.md +52 -17
- package/harness/templates/audit.md +25 -0
- package/harness/templates/history.md +14 -0
- package/harness/templates/intent.md +5 -0
- package/harness/templates/spec.md +4 -2
- package/package.json +1 -2
- package/skills/audit/SKILL.md +28 -0
- package/skills/implement/SKILL.md +30 -0
- package/skills/intent/SKILL.md +28 -0
- package/skills/merge/SKILL.md +26 -0
- package/skills/onboard/SKILL.md +31 -0
- package/skills/reins-setup/SKILL.md +16 -25
- package/skills/release/SKILL.md +26 -0
- package/skills/retro/SKILL.md +30 -0
- package/skills/review/SKILL.md +27 -0
- package/skills/roadmap/SKILL.md +29 -0
- package/skills/spec/SKILL.md +27 -0
- package/skills/test/SKILL.md +26 -0
- package/cli/dist/commands/check.js +0 -379
- package/cli/dist/commands/gate.js +0 -136
- package/cli/dist/commands/knowledge.js +0 -111
- package/cli/dist/commands/metrics.js +0 -138
- package/cli/dist/commands/new.js +0 -190
- package/cli/dist/commands/retro.js +0 -7
- package/cli/dist/commands/stages.js +0 -562
- package/cli/dist/commands/status.js +0 -281
- package/cli/dist/lib/enforcement.js +0 -125
- package/cli/dist/lib/memory.js +0 -96
- package/cli/dist/lib/metrics.js +0 -223
- package/cli/dist/lib/retro.js +0 -179
- package/cli/dist/lib/verdict.js +0 -15
- package/cli/dist/lib/work.js +0 -106
- package/cli/dist/scripts/enforcement.js +0 -24
- package/harness/policy/budget.yaml +0 -13
- package/harness/policy/enforcement.yaml +0 -98
- package/harness/policy/stops.yaml +0 -29
- package/harness/policy/transitions.yaml +0 -13
- package/harness/roles/code-review.md +0 -27
- package/harness/roles/deploy.md +0 -50
- package/harness/roles/docs.md +0 -19
- package/harness/roles/lookup.md +0 -22
- package/harness/roles/qa-design.md +0 -22
- package/harness/roles/qa-run.md +0 -19
- package/harness/roles/verify-tool.md +0 -21
- package/harness/schemas/bindings-local.schema.json +0 -21
- package/harness/schemas/bus-request.schema.json +0 -17
- package/harness/schemas/bus-response.schema.json +0 -14
- package/harness/schemas/enforcement.schema.json +0 -22
- package/harness/schemas/plan.schema.json +0 -10
- package/harness/schemas/ticket.schema.json +0 -15
- package/harness/templates/bus/request.yaml +0 -20
- package/harness/templates/bus/response.yaml +0 -10
- package/harness/templates/plan.md +0 -23
- package/harness/templates/ticket.md +0 -29
- package/skills/reins-implement/SKILL.md +0 -20
- package/skills/reins-intent/SKILL.md +0 -26
- package/skills/reins-loop/SKILL.md +0 -26
- package/skills/reins-loop/references/vendor-cli.md +0 -41
- package/skills/reins-release/SKILL.md +0 -18
- package/skills/reins-retro/SKILL.md +0 -20
- package/skills/reins-review/SKILL.md +0 -23
- package/skills/reins-roadmap/SKILL.md +0 -17
- package/skills/reins-spec/SKILL.md +0 -22
- package/skills/reins-test/SKILL.md +0 -18
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync, } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { parse } from 'yaml';
|
|
3
|
+
import { parse, stringify } from 'yaml';
|
|
4
4
|
import { defaultsAsker } from '../lib/ask.js';
|
|
5
|
-
import {
|
|
5
|
+
import { convertV1, readTeam, writeBindings } from '../lib/bindings.js';
|
|
6
|
+
import { placeNote, reconcileNote } from '../lib/agents-md.js';
|
|
6
7
|
import { overrides } from '../lib/blocks.js';
|
|
7
8
|
import { repoRoot } from '../lib/git.js';
|
|
8
9
|
import { BACK, EXIT } from '../lib/prompter.js';
|
|
@@ -32,31 +33,156 @@ export function changesBetween(changelog, from, to) {
|
|
|
32
33
|
}
|
|
33
34
|
return out;
|
|
34
35
|
}
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
/** 0.x working files and folders under `.loctx/` that 0.3 no longer makes (design §7). */
|
|
37
|
+
const LEGACY_LOCTX = [
|
|
38
|
+
'bus',
|
|
39
|
+
'ticket',
|
|
40
|
+
'dispatch',
|
|
41
|
+
'hook-state',
|
|
42
|
+
'units',
|
|
43
|
+
'audit',
|
|
44
|
+
'journal.jsonl',
|
|
45
|
+
'knowledge-proposals/dismissed.jsonl',
|
|
46
|
+
'pr',
|
|
47
|
+
'release',
|
|
48
|
+
'test',
|
|
49
|
+
];
|
|
50
|
+
/** A command that runs reins: what 0.x put into hooks and settings. */
|
|
51
|
+
const RUNS_REINS = /@bluenyang\/reins|reins\.js\b|(^|[\s;&|])reins\s+(check|hook|gate|status)\b/;
|
|
52
|
+
/** Hook files 0.x may have written a `reins:begin hooks` block into. */
|
|
53
|
+
const HOOK_FILES = [
|
|
54
|
+
'.husky/pre-commit',
|
|
55
|
+
'.husky/pre-push',
|
|
56
|
+
'.husky/prepare-commit-msg',
|
|
57
|
+
'.husky/commit-msg',
|
|
58
|
+
'.husky/post-commit',
|
|
59
|
+
'.husky/post-rewrite',
|
|
60
|
+
];
|
|
61
|
+
/** What moving a 0.1.x or 0.2.0 install to 0.3 changes (design §7), computed without writing. */
|
|
62
|
+
function planLegacy(root) {
|
|
63
|
+
const out = { writes: [], deletes: [], notes: [] };
|
|
64
|
+
// old skills and their index, old agent files
|
|
65
|
+
for (const dir of ['.agents/skills', '.claude/skills'])
|
|
66
|
+
if (existsSync(join(root, dir)))
|
|
67
|
+
for (const n of readdirSync(join(root, dir)))
|
|
68
|
+
if (n.startsWith('reins-'))
|
|
69
|
+
out.deletes.push(`${dir}/${n}`);
|
|
70
|
+
if (existsSync(join(root, '.agents/SKILLS.md')))
|
|
71
|
+
out.deletes.push('.agents/SKILLS.md');
|
|
72
|
+
if (existsSync(join(root, '.claude/agents')))
|
|
73
|
+
for (const n of readdirSync(join(root, '.claude/agents')))
|
|
74
|
+
if (/^reins-.*\.md$/.test(n))
|
|
75
|
+
out.deletes.push(`.claude/agents/${n}`);
|
|
76
|
+
// hook blocks: the user's own lines stay
|
|
77
|
+
for (const f of HOOK_FILES) {
|
|
78
|
+
const p = join(root, f);
|
|
79
|
+
if (!existsSync(p))
|
|
80
|
+
continue;
|
|
81
|
+
const cur = readFileSync(p, 'utf8');
|
|
82
|
+
if (!cur.includes('# reins:begin hooks'))
|
|
83
|
+
continue;
|
|
84
|
+
// only a block that runs reins is 0.x; a 0.3 block holds the project's own gate commands and stays
|
|
85
|
+
const next = cur.replace(/\n?# reins:begin hooks\n([\s\S]*?)# reins:end hooks\n?/g, (block, body) => (RUNS_REINS.test(body) ? '\n' : block));
|
|
86
|
+
if (next === cur)
|
|
87
|
+
continue;
|
|
88
|
+
out.writes.push({ path: f, content: next.replace(/^\n+/, '').replace(/\n{3,}/g, '\n\n') });
|
|
89
|
+
}
|
|
90
|
+
// runtime hook entries in .claude/settings.json: the user's own entries stay
|
|
91
|
+
const sp = join(root, '.claude/settings.json');
|
|
92
|
+
if (existsSync(sp)) {
|
|
93
|
+
try {
|
|
94
|
+
const s = JSON.parse(readFileSync(sp, 'utf8'));
|
|
95
|
+
const hooks = s['hooks'];
|
|
96
|
+
if (hooks) {
|
|
97
|
+
let touched = false;
|
|
98
|
+
for (const [ev, list] of Object.entries(hooks)) {
|
|
99
|
+
// drop the reins commands only; a matcher keeps the user's commands and goes only when empty
|
|
100
|
+
const kept = list
|
|
101
|
+
.map((h) => {
|
|
102
|
+
const inner = (h.hooks ?? []).filter((x) => !RUNS_REINS.test(x.command ?? ''));
|
|
103
|
+
if (inner.length !== (h.hooks ?? []).length)
|
|
104
|
+
touched = true;
|
|
105
|
+
return { ...h, hooks: inner };
|
|
106
|
+
})
|
|
107
|
+
.filter((h) => h.hooks.length > 0);
|
|
108
|
+
if (kept.length)
|
|
109
|
+
hooks[ev] = kept;
|
|
110
|
+
else
|
|
111
|
+
delete hooks[ev];
|
|
112
|
+
}
|
|
113
|
+
if (touched) {
|
|
114
|
+
if (Object.keys(hooks).length === 0)
|
|
115
|
+
delete s['hooks'];
|
|
116
|
+
out.writes.push({
|
|
117
|
+
path: '.claude/settings.json',
|
|
118
|
+
content: `${JSON.stringify(s, null, 2)}\n`,
|
|
119
|
+
});
|
|
120
|
+
out.notes.push('removed reins runtime hooks from .claude/settings.json');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
out.notes.push('.claude/settings.json is not valid JSON — left alone');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// AGENTS.md written by 0.x (old workflow/skills blocks): reconcile in the next first conversation
|
|
129
|
+
const ap = join(root, 'AGENTS.md');
|
|
130
|
+
if (existsSync(ap)) {
|
|
131
|
+
const cur = readFileSync(ap, 'utf8');
|
|
132
|
+
if (/<!-- reins:begin (workflow|skills|harness) v=/.test(cur) &&
|
|
133
|
+
!cur.includes('<!-- reins:reconcile')) {
|
|
134
|
+
out.agentsPrevious = cur;
|
|
135
|
+
const kept = cur.replace(/<!-- reins:begin ([a-z-]+) v=[^ ]+ -->[\s\S]*?<!-- reins:end \1 -->\n*/g, '');
|
|
136
|
+
out.writes.push({
|
|
137
|
+
path: 'AGENTS.md',
|
|
138
|
+
content: placeNote(kept, reconcileNote('reins moved this repository from 0.x to 0.3, whose flow differs.'), 'reconcile'),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
/** `reins update` (design §6, §7): sources → generated files, hand-edit confirmation, moving 0.x installs. */
|
|
40
145
|
export async function runUpdate(o) {
|
|
41
146
|
if (o.prompter && !o.dryRun) {
|
|
42
147
|
const plan = await runUpdate({ ...o, prompter: undefined, dryRun: true });
|
|
43
148
|
if (plan.refused)
|
|
44
149
|
return plan;
|
|
45
150
|
const a = plan.install?.applied;
|
|
46
|
-
const nothing = !plan.
|
|
151
|
+
const nothing = !plan.converted &&
|
|
152
|
+
plan.removed.length === 0 &&
|
|
153
|
+
plan.cleanup.length === 0 &&
|
|
154
|
+
plan.handEdited.length === 0 &&
|
|
155
|
+
(!a || a.created.length + a.changed.length + a.removed.length === 0);
|
|
47
156
|
if (nothing)
|
|
48
157
|
return plan;
|
|
49
158
|
o.show?.(plan);
|
|
50
159
|
const ok = await o.prompter.confirm({ message: 'Apply this update?', initial: true });
|
|
51
160
|
if (ok === BACK || ok === EXIT || !ok)
|
|
52
161
|
return { ...plan, declined: true };
|
|
53
|
-
|
|
162
|
+
let force = o.force;
|
|
163
|
+
if (plan.handEdited.length && !force) {
|
|
164
|
+
const over = await o.prompter.confirm({
|
|
165
|
+
message: `Overwrite ${plan.handEdited.length} generated file(s) edited by hand (${plan.handEdited.join(', ')})?`,
|
|
166
|
+
initial: false,
|
|
167
|
+
});
|
|
168
|
+
if (over === EXIT)
|
|
169
|
+
return { ...plan, declined: true };
|
|
170
|
+
force = over === true;
|
|
171
|
+
}
|
|
172
|
+
return runUpdate({ ...o, prompter: undefined, yes: true, force });
|
|
54
173
|
}
|
|
55
174
|
return updateNow(o);
|
|
56
175
|
}
|
|
57
176
|
async function updateNow(o) {
|
|
58
177
|
const root = repoRoot(o.cwd ?? process.cwd());
|
|
59
|
-
const res = {
|
|
178
|
+
const res = {
|
|
179
|
+
root,
|
|
180
|
+
changes: [],
|
|
181
|
+
overrides: [],
|
|
182
|
+
removed: [],
|
|
183
|
+
cleanup: [],
|
|
184
|
+
handEdited: [],
|
|
185
|
+
};
|
|
60
186
|
const pinPath = join(root, '.agents/harness/install.yaml');
|
|
61
187
|
if (!existsSync(pinPath))
|
|
62
188
|
return {
|
|
@@ -70,27 +196,68 @@ async function updateNow(o) {
|
|
|
70
196
|
res.cliFrom = pin.cli ? String(pin.cli) : 'none';
|
|
71
197
|
res.cliTo = packageVersion();
|
|
72
198
|
const cl = join(up, 'CHANGELOG.md');
|
|
73
|
-
if (existsSync(cl) && newer(res.to, res.from))
|
|
199
|
+
if (existsSync(cl) && newer(res.to, res.from))
|
|
74
200
|
res.changes = changesBetween(readFileSync(cl, 'utf8'), res.from, res.to);
|
|
75
|
-
res.needsSkill = res.changes.some((c) => c.includes('[skill]'));
|
|
76
|
-
}
|
|
77
201
|
const agents = join(root, 'AGENTS.md');
|
|
78
202
|
if (existsSync(agents))
|
|
79
203
|
res.overrides = [...overrides(readFileSync(agents, 'utf8'))];
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
204
|
+
// bindings version 1 → 2 (design §7): the converted file stays single until the user switches
|
|
205
|
+
const team = readTeam(root);
|
|
206
|
+
const pending = [];
|
|
207
|
+
if (team.v1) {
|
|
208
|
+
const { doc, notes } = convertV1(team.v1);
|
|
209
|
+
res.converted = notes;
|
|
210
|
+
if (!o.dryRun)
|
|
211
|
+
writeBindings(root, doc, 'project');
|
|
212
|
+
else
|
|
213
|
+
pending.push({ path: '.agents/harness/bindings.yaml', content: stringify(doc) });
|
|
214
|
+
}
|
|
215
|
+
// 0.x pieces
|
|
216
|
+
const legacy = planLegacy(root);
|
|
217
|
+
res.removed.push(...legacy.deletes, ...legacy.writes.map((w) => `~ ${w.path}`), ...legacy.notes);
|
|
218
|
+
for (const x of LEGACY_LOCTX)
|
|
219
|
+
if (existsSync(join(root, '.loctx', x)))
|
|
220
|
+
res.cleanup.push(`.loctx/${x}`);
|
|
221
|
+
// 0.x gate logs sat directly in .loctx/reports/; 0.3 keeps them in reports/<version>/
|
|
222
|
+
const reports = join(root, '.loctx/reports');
|
|
223
|
+
if (existsSync(reports))
|
|
224
|
+
for (const n of readdirSync(reports))
|
|
225
|
+
if (statSync(join(reports, n)).isFile())
|
|
226
|
+
res.cleanup.push(`.loctx/reports/${n}`);
|
|
227
|
+
// the 0.x personal layer (detected vendors, role overrides) has no meaning in version 2
|
|
228
|
+
const local = join(root, '.loctx/bindings.local.yaml');
|
|
229
|
+
if (existsSync(local) && /^schema: reins\/bindings-local@1$/m.test(readFileSync(local, 'utf8')))
|
|
230
|
+
res.cleanup.push('.loctx/bindings.local.yaml');
|
|
231
|
+
if (!o.dryRun) {
|
|
232
|
+
if (legacy.agentsPrevious !== undefined) {
|
|
233
|
+
mkdirSync(join(root, '.agents'), { recursive: true });
|
|
234
|
+
writeFileSync(join(root, '.agents/AGENTS.previous.md'), legacy.agentsPrevious);
|
|
235
|
+
}
|
|
236
|
+
for (const w of legacy.writes)
|
|
237
|
+
writeFileSync(join(root, w.path), w.content);
|
|
238
|
+
for (const d of legacy.deletes)
|
|
239
|
+
rmSync(join(root, d), { recursive: true, force: true });
|
|
240
|
+
if (o.yes && res.cleanup.length) {
|
|
241
|
+
for (const d of res.cleanup)
|
|
242
|
+
rmSync(join(root, d), { recursive: true, force: true });
|
|
243
|
+
res.cleaned = true;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
83
246
|
res.install = await runInstall({
|
|
84
|
-
|
|
85
|
-
mode: pin.mode,
|
|
247
|
+
mode: pin.mode ?? 'auto',
|
|
86
248
|
asker: defaultsAsker,
|
|
87
249
|
cwd: root,
|
|
88
250
|
dryRun: o.dryRun,
|
|
89
251
|
now: o.now,
|
|
90
252
|
detectVendors: o.detectVendors,
|
|
91
|
-
recordAs: 'update',
|
|
92
253
|
retire: true,
|
|
254
|
+
force: o.force,
|
|
255
|
+
pending,
|
|
256
|
+
pendingDeletes: o.dryRun ? legacy.deletes : [],
|
|
93
257
|
});
|
|
258
|
+
res.handEdited = (res.install.generated?.refused ?? [])
|
|
259
|
+
.filter((r) => r.why.startsWith('edited by hand'))
|
|
260
|
+
.map((r) => r.path);
|
|
94
261
|
return res;
|
|
95
262
|
}
|
|
96
263
|
/** The report `reins update` prints; with `dry` it is the plan shown before the confirmation. */
|
|
@@ -100,9 +267,19 @@ export function formatUpdate(r, dry) {
|
|
|
100
267
|
out.push(`reins update — cli ${r.cliFrom === 'none' ? 'none' : `v${r.cliFrom}`} → v${r.cliTo}, harness v${r.from} → v${r.to}${dry ? ' (dry run)' : ''}`);
|
|
101
268
|
for (const c of r.changes)
|
|
102
269
|
out.push(` · ${c}`);
|
|
103
|
-
if (r.
|
|
104
|
-
out.push(`bindings: ${dry ? 'would
|
|
105
|
-
|
|
270
|
+
if (r.converted) {
|
|
271
|
+
out.push(`bindings: ${dry ? 'would convert' : 'converted'} version 1 → 2`);
|
|
272
|
+
for (const n of r.converted)
|
|
273
|
+
out.push(` · ${n}`);
|
|
274
|
+
}
|
|
275
|
+
if (r.removed.length) {
|
|
276
|
+
out.push(`0.x: ${dry ? 'would take out' : 'took out'}`);
|
|
277
|
+
for (const p of r.removed)
|
|
278
|
+
out.push(` - ${p}`);
|
|
279
|
+
}
|
|
280
|
+
if (r.cleanup.length)
|
|
281
|
+
out.push(`.loctx 0.x working files (${dry ? 'deleted on confirmation' : r.cleaned ? 'deleted' : 'listed; --yes deletes them'}): ${r.cleanup.join(', ')}`);
|
|
282
|
+
if (a && a.created.length + a.changed.length + a.removed.length === 0 && !r.removed.length)
|
|
106
283
|
out.push('already up to date');
|
|
107
284
|
else if (a) {
|
|
108
285
|
out.push(`${dry ? 'would write' : 'wrote'}: ${a.created.length} new, ${a.changed.length} changed${a.removed.length ? `, ${a.removed.length} removed` : ''}`);
|
|
@@ -111,15 +288,11 @@ export function formatUpdate(r, dry) {
|
|
|
111
288
|
for (const p of a.changed)
|
|
112
289
|
out.push(` ~ ${p}`);
|
|
113
290
|
for (const p of a.removed)
|
|
114
|
-
out.push(` - ${p}
|
|
291
|
+
out.push(` - ${p}`);
|
|
115
292
|
}
|
|
116
293
|
for (const n of r.overrides)
|
|
117
294
|
out.push(`• block "${n}" is overridden by the project — compare it with the new upstream block`);
|
|
118
|
-
for (const
|
|
119
|
-
out.push(`• ${
|
|
120
|
-
if (r.needsSkill)
|
|
121
|
-
out.push('• this update needs project sections changed: run /reins-update in your agent');
|
|
122
|
-
if (r.install?.history)
|
|
123
|
-
out.push(`recorded: ${r.install.history}`);
|
|
295
|
+
for (const p of r.handEdited)
|
|
296
|
+
out.push(`• ${p} was edited by hand — not overwritten; run with --force to overwrite it`);
|
|
124
297
|
return `${out.join('\n')}\n`;
|
|
125
298
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { parseBlocks } from './blocks.js';
|
|
4
|
+
import { auditBinding, pmBinding, resolveRoles, } from './bindings.js';
|
|
5
|
+
/**
|
|
6
|
+
* AGENTS.md managed blocks for 0.3 (design §5): the static blocks from the template plus the delegation
|
|
7
|
+
* table, resolved from the team bindings when `config`, `install` or `update` writes — never at work time.
|
|
8
|
+
*/
|
|
9
|
+
/** The name of the generated Claude agent file of a role (design §6). */
|
|
10
|
+
export const agentName = (group, role) => group === role ? `rs-${group}` : `rs-${group}-${role}`;
|
|
11
|
+
/**
|
|
12
|
+
* The Claude agent files of a resolved role: one per Claude model. Several Claude models on one role
|
|
13
|
+
* (discussion, committee) get numbered names so each keeps its own model.
|
|
14
|
+
*/
|
|
15
|
+
export function claudeAgents(r) {
|
|
16
|
+
const base = agentName(r.group, r.group === 'auditor' ? 'auditor' : r.role);
|
|
17
|
+
const ms = r.models.filter((b) => b.vendor === 'claude');
|
|
18
|
+
return ms.map((b, i) => ({ name: ms.length > 1 ? `${base}-${i + 1}` : base, model: b.model }));
|
|
19
|
+
}
|
|
20
|
+
/** How the PM hands a role its work on a vendor other than Claude (the vendor's own CLI, read-only unless it writes). */
|
|
21
|
+
export function callLine(b, cli, writes) {
|
|
22
|
+
switch (b.vendor) {
|
|
23
|
+
case 'openai':
|
|
24
|
+
return `\`${cli} exec -m ${b.model} -s ${writes ? 'workspace-write' : 'read-only'} -\` (task on stdin)`;
|
|
25
|
+
case 'google':
|
|
26
|
+
return `\`${cli} -p "<task>" --model ${b.model}${writes ? '' : ' --mode plan'}\``;
|
|
27
|
+
case 'cursor':
|
|
28
|
+
return `\`${cli} -p --model ${b.model} "<task>"\``;
|
|
29
|
+
default:
|
|
30
|
+
return `\`${cli}\` with model \`${b.model}\``;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const WRITES = new Set(['implementer', 'planner', 'auditor']);
|
|
34
|
+
/** The `## Delegation` section for this bindings file. */
|
|
35
|
+
export function renderDelegation(doc) {
|
|
36
|
+
const pm = pmBinding(doc);
|
|
37
|
+
const lines = ['## Delegation', ''];
|
|
38
|
+
if (doc.mode !== 'multi') {
|
|
39
|
+
lines.push(`Mode: **single** — you are the PM (${pm.vendor} ${pm.model}) and do every role yourself, stage by stage. You may use subagents of your own model for read-heavy work (research, large log summaries, review, audit) and, when urgent, for parallel work on independent units; keep connected work (plan and implementation of one feature) in one run. Switching to multi is the user's choice.`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
lines.push(`Mode: **multi** — you are the PM (${pm.vendor} ${pm.model}). Hand a role its work with the list of files and decisions it needs; every report comes back to you, and a role never calls another model itself. Roles not listed are yours.`, '', '| role | model | how to call |', '|---|---|---|');
|
|
43
|
+
for (const r of resolveRoles(doc).filter((x) => x.on)) {
|
|
44
|
+
const agents = claudeAgents(r);
|
|
45
|
+
let k = 0;
|
|
46
|
+
for (const b of r.models) {
|
|
47
|
+
const cli = doc.tools?.[b.vendor]?.cli ?? b.vendor;
|
|
48
|
+
const how = b.vendor === 'claude'
|
|
49
|
+
? `subagent \`${agents[k++].name}\``
|
|
50
|
+
: callLine(b, cli, WRITES.has(r.group));
|
|
51
|
+
lines.push(`| ${r.group}/${r.role} | ${b.vendor} ${b.model} | ${how} |`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
lines.push('', 'Routine review takes one reviewer; `pl/discussion` and `advisor/committee` (every listed model, without seeing each other) are for large decisions, audit remedies, incidents and unresolved disagreements.');
|
|
55
|
+
}
|
|
56
|
+
const a = auditBinding(doc);
|
|
57
|
+
lines.push('', `Audit: ${doc.audit?.required === false ? '**switched off by the user**' : '**required every version**'}; run it on ${a.vendor} ${a.model} in a fresh run that gets only the records, never this conversation.`, 'If `.loctx/bindings.local.yaml` exists, it overrides this section for you.');
|
|
58
|
+
return lines.join('\n');
|
|
59
|
+
}
|
|
60
|
+
/** The managed blocks for this project, from the packaged template. */
|
|
61
|
+
export function renderBlocks(harness, doc, language) {
|
|
62
|
+
const text = readFileSync(join(harness, 'templates/agents-md-blocks.md'), 'utf8')
|
|
63
|
+
.replace('{{DELEGATION}}', () => renderDelegation(doc))
|
|
64
|
+
.replace('{{LANGUAGE}}', () => language);
|
|
65
|
+
return parseBlocks(text);
|
|
66
|
+
}
|
|
67
|
+
export const ONBOARDING_PENDING = '<!-- reins:onboarding pending -->';
|
|
68
|
+
export const RECONCILE_PENDING = '<!-- reins:reconcile pending -->';
|
|
69
|
+
/** The onboarding to-do (design §5), placed above the project sections; the PM sets the marker to `done`. */
|
|
70
|
+
export function onboardingNote(needsHookTool) {
|
|
71
|
+
const todo = [
|
|
72
|
+
'goals and scope',
|
|
73
|
+
'stack and commands',
|
|
74
|
+
'existing rules and conventions',
|
|
75
|
+
'red lines (paths not to touch, secret files)',
|
|
76
|
+
'the language of documents the user reads',
|
|
77
|
+
...(needsHookTool ? ['which hook tool runs the gates (none was found)'] : []),
|
|
78
|
+
];
|
|
79
|
+
return [
|
|
80
|
+
ONBOARDING_PENDING,
|
|
81
|
+
`> **Onboarding — do this first in the next conversation.** Run the \`onboard\` skill: read the project, ask the user, and write the project sections of this file: ${todo.join('; ')}. Then change the marker above to \`<!-- reins:onboarding done -->\`.`,
|
|
82
|
+
].join('\n');
|
|
83
|
+
}
|
|
84
|
+
/** The reconcile note (design §5): the previous body moved aside as reference material. */
|
|
85
|
+
export function reconcileNote(why) {
|
|
86
|
+
return [
|
|
87
|
+
RECONCILE_PENDING,
|
|
88
|
+
`> **Reconcile — do this first in the next conversation.** ${why} The previous AGENTS.md is in \`.agents/AGENTS.previous.md\` as reference material, not instructions. Run the \`onboard\` skill to merge what still applies into the project sections, then delete that file and change the marker above to \`<!-- reins:reconcile done -->\`.`,
|
|
89
|
+
].join('\n');
|
|
90
|
+
}
|
|
91
|
+
/** Put a note right after the first H1 (or at the top) unless one of that kind is still pending. */
|
|
92
|
+
/** The light check after a mode switch (design §5, spec ST-5): only the delegation block changed. */
|
|
93
|
+
export function modeChangedNote(from, to) {
|
|
94
|
+
return [
|
|
95
|
+
'<!-- reins:mode-changed pending -->',
|
|
96
|
+
`> **Mode changed from ${from} to ${to}.** reins rewrote the delegation section. In the next conversation (the \`onboard\` skill), check that the project sections below say nothing that contradicts the new mode, then change the marker above to \`<!-- reins:mode-changed done -->\`.`,
|
|
97
|
+
].join('\n');
|
|
98
|
+
}
|
|
99
|
+
export function placeNote(text, note, kind) {
|
|
100
|
+
if (text.includes(`<!-- reins:${kind} pending -->`))
|
|
101
|
+
return text;
|
|
102
|
+
// a finished one gives way to the new one (e.g. a second mode switch)
|
|
103
|
+
// only the note reins wrote goes with its marker; a project quote under it stays
|
|
104
|
+
const lead = { onboarding: 'Onboarding', reconcile: 'Reconcile', 'mode-changed': 'Mode changed' }[kind];
|
|
105
|
+
text = text.replace(new RegExp(`<!-- reins:${kind} done -->\\n(?:> \\*\\*${lead}[^\\n]*\\n)?\\n?`), '');
|
|
106
|
+
const m = /^# .*\n/m.exec(text);
|
|
107
|
+
if (!m)
|
|
108
|
+
return `${note}\n\n${text}`;
|
|
109
|
+
const at = m.index + m[0].length;
|
|
110
|
+
return `${text.slice(0, at)}\n${note}\n${text.slice(at)}`;
|
|
111
|
+
}
|