@bluenyang/reins 0.3.4 → 0.4.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 +164 -39
- package/cli/dist/commands/config-gates.js +64 -6
- package/cli/dist/commands/config-models.js +19 -0
- package/cli/dist/commands/config.js +40 -16
- package/cli/dist/commands/configure.js +207 -47
- package/cli/dist/commands/install.js +91 -31
- package/cli/dist/commands/migrate.js +17 -20
- package/cli/dist/commands/update.js +164 -12
- package/cli/dist/lib/agents-md.js +55 -13
- package/cli/dist/lib/bindings.js +7 -10
- package/cli/dist/lib/blocks.js +82 -18
- package/cli/dist/lib/detect.js +88 -3
- package/cli/dist/lib/gate-refresh.js +35 -5
- package/cli/dist/lib/gate-script.js +303 -25
- package/cli/dist/lib/generate.js +48 -6
- package/cli/dist/lib/git.js +33 -0
- package/cli/dist/lib/migrate-plan.js +1 -1
- package/cli/dist/lib/profile.js +101 -0
- package/cli/dist/lib/prompter.js +2 -1
- package/cli/dist/lib/release.js +1 -1
- package/cli/dist/lib/schema.js +6 -3
- package/cli/dist/lib/upstream.js +1 -1
- package/cli/dist/reins.js +40 -14
- package/docs/README.ko.md +113 -23
- package/harness/CHANGELOG.md +12 -0
- package/harness/VERSION +1 -1
- package/harness/policy/common-red-lines.yaml +7 -5
- package/harness/roles/advisor.md +1 -1
- package/harness/roles/auditor.md +12 -11
- package/harness/roles/executor.md +4 -3
- package/harness/roles/implementer.md +5 -5
- package/harness/roles/pl.md +4 -4
- package/harness/roles/planner.md +7 -8
- package/harness/roles/pm.md +7 -8
- package/harness/schemas/bindings.schema.json +2 -0
- package/harness/schemas/install.schema.json +1 -0
- package/harness/schemas/intent.schema.json +9 -1
- package/harness/schemas/plan.schema.json +18 -0
- package/harness/schemas/spec.schema.json +9 -6
- package/harness/templates/agents-md-blocks.md +19 -54
- package/harness/templates/agents-md-guide.md +11 -10
- package/harness/templates/audit.md +14 -41
- package/harness/templates/history.md +1 -5
- package/harness/templates/intent.md +8 -19
- package/harness/templates/plan.md +23 -0
- package/harness/templates/spec.md +21 -16
- package/package.json +1 -1
- package/skills/audit/SKILL.md +27 -33
- package/skills/gates/SKILL.md +41 -0
- package/skills/implement/SKILL.md +33 -22
- package/skills/implement/references/procedure.md +51 -0
- package/skills/intent/SKILL.md +29 -20
- package/skills/intent/references/procedure.md +60 -0
- package/skills/onboard/SKILL.md +39 -28
- package/skills/plan/SKILL.md +35 -0
- package/skills/plan/references/procedure.md +52 -0
- package/skills/reins-setup/SKILL.md +4 -4
- package/skills/release/SKILL.md +18 -20
- package/skills/retro/SKILL.md +21 -26
- package/skills/review/SKILL.md +33 -17
- package/skills/review/references/procedure.md +50 -0
- package/skills/spec/SKILL.md +25 -19
- package/skills/spec/references/procedure.md +67 -0
- package/skills/merge/SKILL.md +0 -32
- package/skills/roadmap/SKILL.md +0 -29
- package/skills/test/SKILL.md +0 -26
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
-
import { isScalar, isSeq, parse, parseDocument } from 'yaml';
|
|
5
|
-
import { discoverGates,
|
|
6
|
-
import { actionsOf,
|
|
4
|
+
import { isMap, isScalar, isSeq, parse, parseDocument } from 'yaml';
|
|
5
|
+
import { discoverGates, vendorOf, vendors, } from '../lib/detect.js';
|
|
6
|
+
import { actionsOf, gateStatus, reportLines, } from '../lib/gate-refresh.js';
|
|
7
7
|
import { GROUP_ROLES, GROUPS, effectiveBindings, fallbackProblems, readLocalBindings, readTeam, resolveRoles, validateBindings, writeBindings, } from '../lib/bindings.js';
|
|
8
8
|
import { modeChangedNote, placeNote, renderBlocks } from '../lib/agents-md.js';
|
|
9
9
|
import { applyBlocks } from '../lib/blocks.js';
|
|
@@ -12,6 +12,7 @@ import { repoRoot } from '../lib/git.js';
|
|
|
12
12
|
import { writeGenerated } from '../lib/vendor-write.js';
|
|
13
13
|
import { packageHarness } from '../lib/upstream.js';
|
|
14
14
|
import { syncLocalDelegation } from '../lib/local-delegation.js';
|
|
15
|
+
import { applyProfile, profileOf } from '../lib/profile.js';
|
|
15
16
|
/**
|
|
16
17
|
* The generated files of one `config` call as report lines: `+` a path that did not exist before the call,
|
|
17
18
|
* `~` one that was rewritten, `-` one removed, and what was left alone and why.
|
|
@@ -56,6 +57,13 @@ export function refreshAgents(root, doc, modeFrom) {
|
|
|
56
57
|
writeFileSync(ap, text);
|
|
57
58
|
return text !== before;
|
|
58
59
|
}
|
|
60
|
+
const refuseBindings = (why) => ({
|
|
61
|
+
refused: why,
|
|
62
|
+
code: 1,
|
|
63
|
+
changed: [],
|
|
64
|
+
roles: [],
|
|
65
|
+
});
|
|
66
|
+
const groupOf = (name) => GROUPS.includes(name) ? name : null;
|
|
59
67
|
/** `reins config bindings` (design §9): the flag form of the models-and-roles screen. */
|
|
60
68
|
export async function configureBindings(o) {
|
|
61
69
|
const root = repoRoot(o.cwd ?? process.cwd());
|
|
@@ -79,31 +87,24 @@ export async function configureBindings(o) {
|
|
|
79
87
|
: structuredClone(team.doc);
|
|
80
88
|
const next = structuredClone(base);
|
|
81
89
|
const changed = [];
|
|
82
|
-
const refuse = (why) => ({
|
|
83
|
-
refused: why,
|
|
84
|
-
code: 1,
|
|
85
|
-
changed: [],
|
|
86
|
-
roles: [],
|
|
87
|
-
});
|
|
88
|
-
const groupOf = (name) => GROUPS.includes(name) ? name : null;
|
|
89
90
|
for (const pair of o.set ?? []) {
|
|
90
91
|
const eq = pair.indexOf('=');
|
|
91
92
|
const target = pair.slice(0, eq).trim();
|
|
92
93
|
const b = eq > 0 ? parseBinding(pair.slice(eq + 1)) : null;
|
|
93
94
|
if (!target || !b)
|
|
94
|
-
return
|
|
95
|
+
return refuseBindings(`"${pair}" is not target=model`);
|
|
95
96
|
if (target === 'default')
|
|
96
|
-
return
|
|
97
|
+
return refuseBindings('the PM is the model in the conversation — there is nothing to set; assign models to the groups that need another one');
|
|
97
98
|
const [g, role] = target.split('.');
|
|
98
99
|
const group = groupOf(g ?? '');
|
|
99
100
|
if (!group)
|
|
100
|
-
return
|
|
101
|
+
return refuseBindings(`unknown group "${g}" — groups: ${GROUPS.join(', ')}`);
|
|
101
102
|
const roles = GROUP_ROLES[group];
|
|
102
103
|
next.groups = { ...next.groups };
|
|
103
104
|
const spec = { ...next.groups[group] };
|
|
104
105
|
if (role) {
|
|
105
106
|
if (!roles.includes(role))
|
|
106
|
-
return
|
|
107
|
+
return refuseBindings(`unknown role "${role}" in ${group} — roles: ${roles.join(', ') || group}`);
|
|
107
108
|
// a new model keeps the role's fallback; the check below refuses it when they are now the same
|
|
108
109
|
const kept = spec.roles?.[role]?.fallback;
|
|
109
110
|
spec.roles = { ...spec.roles, [role]: kept ? { ...b, fallback: kept } : b };
|
|
@@ -120,14 +121,14 @@ export async function configureBindings(o) {
|
|
|
120
121
|
const eq = pair.indexOf('=');
|
|
121
122
|
const group = groupOf(pair.slice(0, eq).trim());
|
|
122
123
|
if (!group || (group !== 'pl' && group !== 'advisor'))
|
|
123
|
-
return
|
|
124
|
+
return refuseBindings(`"${pair}": several models are for pl and advisor only`);
|
|
124
125
|
const list = pair
|
|
125
126
|
.slice(eq + 1)
|
|
126
127
|
.split(',')
|
|
127
128
|
.map(parseBinding)
|
|
128
129
|
.filter((x) => x !== null);
|
|
129
130
|
if (!list.length)
|
|
130
|
-
return
|
|
131
|
+
return refuseBindings(`"${pair}" names no model`);
|
|
131
132
|
next.groups = { ...next.groups };
|
|
132
133
|
const { vendor: _v, model: _m, ...rest } = next.groups[group] ?? {};
|
|
133
134
|
next.groups[group] = { ...rest, models: list };
|
|
@@ -136,7 +137,7 @@ export async function configureBindings(o) {
|
|
|
136
137
|
for (const name of o.off ?? []) {
|
|
137
138
|
const group = groupOf(name);
|
|
138
139
|
if (!group)
|
|
139
|
-
return
|
|
140
|
+
return refuseBindings(`unknown group "${name}" — groups: ${GROUPS.join(', ')}`);
|
|
140
141
|
next.groups = { ...next.groups };
|
|
141
142
|
if (o.local) {
|
|
142
143
|
// an empty group in the personal file switches the team's off for this person (mergeLocal, 023 S-20)
|
|
@@ -157,34 +158,34 @@ export async function configureBindings(o) {
|
|
|
157
158
|
const value = eq > 0 ? pair.slice(eq + 1).trim() : '';
|
|
158
159
|
const b = value === 'none' ? null : parseBinding(value);
|
|
159
160
|
if (!target || (!b && value !== 'none'))
|
|
160
|
-
return
|
|
161
|
+
return refuseBindings(`"${pair}" is not target=model|none`);
|
|
161
162
|
const [g, role] = target.split('.');
|
|
162
163
|
const group = groupOf(g ?? '');
|
|
163
164
|
if (!group)
|
|
164
|
-
return
|
|
165
|
+
return refuseBindings(`unknown group "${g}" — groups: ${GROUPS.join(', ')}`);
|
|
165
166
|
const where = o.local ? 'your personal file' : 'bindings.yaml';
|
|
166
167
|
next.groups = { ...next.groups };
|
|
167
168
|
const spec = { ...next.groups[group] };
|
|
168
169
|
if (role) {
|
|
169
170
|
if (!GROUP_ROLES[group].includes(role))
|
|
170
|
-
return
|
|
171
|
+
return refuseBindings(`unknown role "${role}" in ${group} — roles: ${GROUP_ROLES[group].join(', ') || group}`);
|
|
171
172
|
const own = spec.roles?.[role];
|
|
172
173
|
if (!own)
|
|
173
174
|
return b
|
|
174
|
-
?
|
|
175
|
-
:
|
|
175
|
+
? refuseBindings(`${group}.${role} has no model of its own in ${where} — set it with --set ${group}.${role}=<model>, or give the group a fallback`)
|
|
176
|
+
: refuseBindings(`${group}.${role} has no fallback to clear in ${where}`);
|
|
176
177
|
if (!b && !own.fallback)
|
|
177
|
-
return
|
|
178
|
+
return refuseBindings(`${group}.${role} has no fallback to clear in ${where}`);
|
|
178
179
|
const { fallback: _old, ...rest } = own;
|
|
179
180
|
spec.roles = { ...spec.roles, [role]: b ? { ...rest, fallback: b } : rest };
|
|
180
181
|
}
|
|
181
182
|
else {
|
|
182
183
|
if (b && !spec.vendor && !spec.models?.length)
|
|
183
|
-
return
|
|
184
|
+
return refuseBindings(`${group} has no model in ${where} — set it with --set ${group}=<model> first (a fallback goes with the model beside it)`);
|
|
184
185
|
// clearing what is not there must not write an empty group: in the personal file `{}` switches
|
|
185
186
|
// the team's group off for that person
|
|
186
187
|
if (!b && !spec.fallback)
|
|
187
|
-
return
|
|
188
|
+
return refuseBindings(`${group} has no fallback to clear in ${where}`);
|
|
188
189
|
if (b)
|
|
189
190
|
spec.fallback = b;
|
|
190
191
|
else
|
|
@@ -195,16 +196,17 @@ export async function configureBindings(o) {
|
|
|
195
196
|
}
|
|
196
197
|
const wrong = fallbackProblems(next);
|
|
197
198
|
if (wrong.length)
|
|
198
|
-
return
|
|
199
|
+
return refuseBindings(wrong.join('; '));
|
|
199
200
|
if (o.mode && next.mode !== o.mode) {
|
|
200
201
|
next.mode = o.mode;
|
|
201
202
|
changed.push('mode');
|
|
202
203
|
}
|
|
203
|
-
if (o.
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
204
|
+
if (o.profile) {
|
|
205
|
+
if (o.local)
|
|
206
|
+
return refuseBindings('the profile is the team’s: it decides which files are committed — set it without --local');
|
|
207
|
+
if (next.profile !== o.profile) {
|
|
208
|
+
next.profile = o.profile;
|
|
209
|
+
changed.push('profile');
|
|
208
210
|
}
|
|
209
211
|
}
|
|
210
212
|
if (o.detect || o.tools?.length) {
|
|
@@ -220,7 +222,7 @@ export async function configureBindings(o) {
|
|
|
220
222
|
for (const pair of o.tools ?? []) {
|
|
221
223
|
const [name, state] = pair.split('=').map((s) => s.trim());
|
|
222
224
|
if (!name || (state !== 'on' && state !== 'off'))
|
|
223
|
-
return
|
|
225
|
+
return refuseBindings(`"${pair}" is not tool=on|off`);
|
|
224
226
|
const cli = vs.find((v) => v.name === name)?.cli ?? next.tools[name]?.cli ?? name;
|
|
225
227
|
next.tools[name] = { ...next.tools[name], cli, use: state === 'on' };
|
|
226
228
|
}
|
|
@@ -228,13 +230,18 @@ export async function configureBindings(o) {
|
|
|
228
230
|
}
|
|
229
231
|
const problems = o.local ? [] : validateBindings({ ...next, schema: 'reins/bindings@2' });
|
|
230
232
|
if (problems.length)
|
|
231
|
-
return
|
|
233
|
+
return refuseBindings(`the result would not be valid: ${problems.join('; ')}`);
|
|
232
234
|
const wrote = JSON.stringify(next) !== JSON.stringify(base);
|
|
233
235
|
// a file from an earlier reins may still name a PM model; it goes when the file is written (design §5)
|
|
234
236
|
if (wrote && next.default) {
|
|
235
237
|
delete next.default;
|
|
236
238
|
changed.push('default removed (the PM is the model in the conversation)');
|
|
237
239
|
}
|
|
240
|
+
// 0.3's audit switch is read but no longer used (design §5): it goes when the file is written
|
|
241
|
+
if (wrote && next.audit) {
|
|
242
|
+
delete next.audit;
|
|
243
|
+
changed.push('audit removed (the audit is optional and started by a person)');
|
|
244
|
+
}
|
|
238
245
|
if (!wrote) {
|
|
239
246
|
const doc = effective();
|
|
240
247
|
return { changed: [], doc, roles: resolveRoles(doc) };
|
|
@@ -247,6 +254,8 @@ export async function configureBindings(o) {
|
|
|
247
254
|
const teamNow = readTeam(root).doc;
|
|
248
255
|
const from = team.doc.mode ?? 'single';
|
|
249
256
|
const modeChanged = from !== (teamNow.mode ?? 'single');
|
|
257
|
+
// a profile change adds or removes the role files and references before the generated copies follow
|
|
258
|
+
const profileFiles = profileOf(teamNow) !== profileOf(team.doc) ? applyProfile(root, profileOf(teamNow)) : undefined;
|
|
250
259
|
const generated = writeGenerated(root, generateVendorFiles(root), false);
|
|
251
260
|
refreshAgents(root, teamNow, modeChanged ? from : undefined);
|
|
252
261
|
return {
|
|
@@ -256,9 +265,12 @@ export async function configureBindings(o) {
|
|
|
256
265
|
generated,
|
|
257
266
|
modeChanged: modeChanged || undefined,
|
|
258
267
|
localDelegation: local,
|
|
268
|
+
...(profileFiles ? { profileFiles } : {}),
|
|
259
269
|
};
|
|
260
270
|
}
|
|
261
271
|
const GATES = '.agents/harness/gates.yaml';
|
|
272
|
+
/** A list key of gates.yaml (`areas`, `on`, an area's globs): one value is a list of one, none is empty. */
|
|
273
|
+
const list = (v) => v === null || v === undefined ? [] : Array.isArray(v) ? v.map(String) : [String(v)];
|
|
262
274
|
/** The gates of a `gates.yaml` document, in its order (gates missing from `order` follow). */
|
|
263
275
|
export function fileGates(text) {
|
|
264
276
|
const g = parse(text);
|
|
@@ -266,19 +278,166 @@ export function fileGates(text) {
|
|
|
266
278
|
const names = [...new Set([...(g?.order ?? []), ...Object.keys(gates)])];
|
|
267
279
|
return names
|
|
268
280
|
.filter((n) => gates[n]?.cmd)
|
|
269
|
-
.map((n) =>
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
281
|
+
.map((n) => {
|
|
282
|
+
const x = gates[n];
|
|
283
|
+
const areas = list(x.areas);
|
|
284
|
+
const on = list(x.on);
|
|
285
|
+
return {
|
|
286
|
+
name: n,
|
|
287
|
+
cmd: x.cmd,
|
|
288
|
+
...(x.from ? { from: x.from } : {}),
|
|
289
|
+
...(x.optional ? { optional: true } : {}),
|
|
290
|
+
...(areas.length ? { areas } : {}),
|
|
291
|
+
...(on.length ? { on } : {}),
|
|
292
|
+
};
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
/** The areas a `gates.yaml` document defines (spec 025 D-2), name → globs. */
|
|
296
|
+
export function fileAreas(text) {
|
|
297
|
+
const a = parse(text)?.areas ?? {};
|
|
298
|
+
return Object.fromEntries(Object.entries(a).map(([k, v]) => [k, list(v)]));
|
|
299
|
+
}
|
|
300
|
+
/** An area name the gate script reads (spec 025 D-2). */
|
|
301
|
+
const AREA_NAME = /^[\w.-]+$/;
|
|
302
|
+
/**
|
|
303
|
+
* Define an area in the document: the top-level `areas:` map is made after `schema` when there is none,
|
|
304
|
+
* and a schema 1 file becomes schema 2, since it now uses its keys (spec 025 D-2).
|
|
305
|
+
*/
|
|
306
|
+
function defineArea(doc, name, globs) {
|
|
307
|
+
const top = doc.contents;
|
|
308
|
+
if (isMap(top) && !top.has('areas')) {
|
|
309
|
+
const at = top.items.findIndex((p) => isScalar(p.key) && p.key.value === 'schema');
|
|
310
|
+
top.items.splice(at + 1, 0, doc.createPair('areas', doc.createNode({})));
|
|
311
|
+
}
|
|
312
|
+
blockStyle(doc, 'areas');
|
|
313
|
+
doc.setIn(['areas', name], doc.createNode(globs));
|
|
314
|
+
if (doc.get('schema') === 'reins/gates@1')
|
|
315
|
+
doc.set('schema', 'reins/gates@2');
|
|
316
|
+
}
|
|
317
|
+
/** Set a list key of a gate (`areas`, `on`); an empty list takes the key away. */
|
|
318
|
+
function setGateList(doc, gate, key, values) {
|
|
319
|
+
if (values.length) {
|
|
320
|
+
doc.setIn(['gates', gate, key], doc.createNode(values));
|
|
321
|
+
if (key === 'areas' && doc.get('schema') === 'reins/gates@1')
|
|
322
|
+
doc.set('schema', 'reins/gates@2');
|
|
323
|
+
}
|
|
324
|
+
else
|
|
325
|
+
doc.deleteIn(['gates', gate, key]);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* A top-level collection that grows is written in block style: the gate script reads no flow style, and
|
|
329
|
+
* install writes the empty ones as `gates: {}` and `order: []` (spec 025 D-2).
|
|
330
|
+
*/
|
|
331
|
+
function blockStyle(doc, key) {
|
|
332
|
+
const node = doc.get(key, true);
|
|
333
|
+
if ((isMap(node) || isSeq(node)) && node.flow)
|
|
334
|
+
node.flow = false;
|
|
335
|
+
}
|
|
336
|
+
/** A gate added with the area of where it was found brings that area's definition when the file has none. */
|
|
337
|
+
function addGate(doc, defs, g) {
|
|
338
|
+
for (const a of g.areas ?? [])
|
|
339
|
+
if (!doc.hasIn(['areas', a]))
|
|
340
|
+
defineArea(doc, a, defs[a] ?? []);
|
|
341
|
+
blockStyle(doc, 'gates');
|
|
342
|
+
doc.setIn(['gates', g.name], doc.createNode({
|
|
343
|
+
cmd: g.cmd,
|
|
344
|
+
...(g.from ? { from: g.from } : {}),
|
|
345
|
+
...(g.optional ? { optional: true } : {}),
|
|
346
|
+
...(g.areas?.length ? { areas: g.areas } : {}),
|
|
274
347
|
}));
|
|
275
348
|
}
|
|
349
|
+
/** `<name>=<a,b,…>` → the name and the list; null when there is no `=` or no name. */
|
|
350
|
+
const assignment = (s) => {
|
|
351
|
+
const i = s.indexOf('=');
|
|
352
|
+
if (i <= 0)
|
|
353
|
+
return null;
|
|
354
|
+
return {
|
|
355
|
+
name: s.slice(0, i).trim(),
|
|
356
|
+
values: s
|
|
357
|
+
.slice(i + 1)
|
|
358
|
+
.split(',')
|
|
359
|
+
.map((x) => x.trim())
|
|
360
|
+
.filter(Boolean),
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
/** A refused `--define-area`, `--area` or `--on`: nothing is written. */
|
|
364
|
+
const refuse = (why) => ({
|
|
365
|
+
refused: why,
|
|
366
|
+
code: 1,
|
|
367
|
+
available: [],
|
|
368
|
+
added: [],
|
|
369
|
+
set: [],
|
|
370
|
+
});
|
|
371
|
+
/** Every `<name>=<a,b,…>` of a flag, or the message for the first one without `=`. */
|
|
372
|
+
function assignments(xs, flag) {
|
|
373
|
+
const out = [];
|
|
374
|
+
for (const x of xs ?? []) {
|
|
375
|
+
const a = assignment(x);
|
|
376
|
+
if (!a)
|
|
377
|
+
return `${flag} ${x}: write <name>=<value,…>`;
|
|
378
|
+
out.push(a);
|
|
379
|
+
}
|
|
380
|
+
return out;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* `config gates --define-area`, `--area`, `--on` (spec 025 R-5): set areas and stages without a screen.
|
|
384
|
+
* Every assignment is checked first; one that cannot be applied refuses the whole call and writes nothing.
|
|
385
|
+
*/
|
|
386
|
+
function setGateKeys(root, o) {
|
|
387
|
+
const path = join(root, GATES);
|
|
388
|
+
const doc = parseDocument(readFileSync(path, 'utf8'));
|
|
389
|
+
const gates = new Set(fileGates(doc.toString()).map((g) => g.name));
|
|
390
|
+
const defs = assignments(o.defineArea, '--define-area');
|
|
391
|
+
const areas = assignments(o.area, '--area');
|
|
392
|
+
const ons = assignments(o.on, '--on');
|
|
393
|
+
for (const x of [defs, areas, ons])
|
|
394
|
+
if (typeof x === 'string')
|
|
395
|
+
return refuse(x);
|
|
396
|
+
const [d, a, n] = [defs, areas, ons];
|
|
397
|
+
const set = [];
|
|
398
|
+
for (const x of d) {
|
|
399
|
+
if (!AREA_NAME.test(x.name))
|
|
400
|
+
return refuse(`${x.name}: an area name is letters, digits, _, . and -`);
|
|
401
|
+
if (x.values.length)
|
|
402
|
+
defineArea(doc, x.name, x.values);
|
|
403
|
+
else
|
|
404
|
+
doc.deleteIn(['areas', x.name]);
|
|
405
|
+
set.push(`area ${x.name}: ${x.values.join(', ') || 'removed'}`);
|
|
406
|
+
}
|
|
407
|
+
const defined = new Set(Object.keys(fileAreas(doc.toString())));
|
|
408
|
+
for (const x of [...a, ...n])
|
|
409
|
+
if (!gates.has(x.name))
|
|
410
|
+
return refuse(`no gate ${x.name} — gates: ${[...gates].join(', ') || 'none'}`);
|
|
411
|
+
for (const x of a) {
|
|
412
|
+
const missing = x.values.filter((v) => !defined.has(v));
|
|
413
|
+
if (missing.length)
|
|
414
|
+
return refuse(`${x.name}: no area ${missing.join(', ')} — define it with --define-area <name>=<glob,…> (areas: ${[...defined].join(', ') || 'none'})`);
|
|
415
|
+
setGateList(doc, x.name, 'areas', x.values);
|
|
416
|
+
set.push(`areas of ${x.name}: ${x.values.join(', ') || 'none — always runs'}`);
|
|
417
|
+
}
|
|
418
|
+
for (const x of n) {
|
|
419
|
+
setGateList(doc, x.name, 'on', x.values);
|
|
420
|
+
set.push(`on of ${x.name}: ${x.values.join(', ') || 'every stage'}`);
|
|
421
|
+
}
|
|
422
|
+
// an area a gate still names cannot go
|
|
423
|
+
const named = new Set(fileGates(doc.toString()).flatMap((g) => g.areas ?? []));
|
|
424
|
+
for (const x of d)
|
|
425
|
+
if (!x.values.length && named.has(x.name))
|
|
426
|
+
return refuse(`the area ${x.name} is named by a gate — take it off the gate first (--area)`);
|
|
427
|
+
const top = doc.get('areas');
|
|
428
|
+
if (isMap(top) && top.items.length === 0)
|
|
429
|
+
doc.delete('areas');
|
|
430
|
+
if (set.length)
|
|
431
|
+
writeFileSync(path, doc.toString({ lineWidth: 0 }));
|
|
432
|
+
return { available: [], added: [], set };
|
|
433
|
+
}
|
|
276
434
|
/**
|
|
277
435
|
* Put a gate that was just added to `gates` at the end of `order`. A file without `order` runs its gates
|
|
278
436
|
* in the order they are written, so the list starts from those — never from the new gate alone.
|
|
279
437
|
*/
|
|
280
438
|
function appendOrder(doc, name) {
|
|
281
439
|
if (isSeq(doc.get('order'))) {
|
|
440
|
+
blockStyle(doc, 'order');
|
|
282
441
|
doc.addIn(['order'], name);
|
|
283
442
|
return;
|
|
284
443
|
}
|
|
@@ -290,7 +449,8 @@ export function gateRows(root) {
|
|
|
290
449
|
const path = join(root, GATES);
|
|
291
450
|
if (!existsSync(path))
|
|
292
451
|
return null;
|
|
293
|
-
|
|
452
|
+
const found = discoverGates(root);
|
|
453
|
+
return gateStatus(root, fileGates(readFileSync(path, 'utf8')), found.candidates, found.areas);
|
|
294
454
|
}
|
|
295
455
|
/** Where a refresh leaves its rows for the agent who applies the user's picks (024 S-12). */
|
|
296
456
|
export const REFRESH_LIST = '.loctx/gates-refresh.md';
|
|
@@ -303,8 +463,9 @@ export function writeRefreshList(root, rows) {
|
|
|
303
463
|
`- made: ${new Date().toISOString()}`,
|
|
304
464
|
`- gates.yaml: sha256 ${createHash('sha256').update(text).digest('hex').slice(0, 16)}`,
|
|
305
465
|
'- The user picks from this list; an agent applies the picks to `.agents/harness/gates.yaml` in a commit of its own. The agent does not run reins.',
|
|
466
|
+
'- Removal candidates come first: look at what to take out before what to add. A gate without areas always runs.',
|
|
306
467
|
'',
|
|
307
|
-
...rows.map((
|
|
468
|
+
...reportLines(rows).map((l) => (l === '' ? '' : l.endsWith(':') ? `## ${l}` : `- ${l}`)),
|
|
308
469
|
'',
|
|
309
470
|
].join('\n');
|
|
310
471
|
mkdirSync(join(root, '.loctx'), { recursive: true });
|
|
@@ -334,9 +495,12 @@ export function configureGates(o = {}) {
|
|
|
334
495
|
const path = join(root, GATES);
|
|
335
496
|
if (!existsSync(path))
|
|
336
497
|
return { refused: 'no gates.yaml — run reins install', code: 2, available: [], added: [] };
|
|
498
|
+
if (o.defineArea?.length || o.area?.length || o.on?.length)
|
|
499
|
+
return setGateKeys(root, o);
|
|
337
500
|
const doc = parseDocument(readFileSync(path, 'utf8'));
|
|
338
501
|
const have = new Set(Object.keys(doc.toJS()?.gates ?? {}));
|
|
339
|
-
const
|
|
502
|
+
const found = discoverGates(root);
|
|
503
|
+
const available = found.proposals.filter((g) => !have.has(g.name));
|
|
340
504
|
if (o.refresh || o.apply) {
|
|
341
505
|
const rows = gateRows(root) ?? [];
|
|
342
506
|
writeRefreshList(root, rows);
|
|
@@ -380,11 +544,7 @@ export function configureGates(o = {}) {
|
|
|
380
544
|
doc.setIn(['gates', row.name, 'from'], row.found.from);
|
|
381
545
|
}
|
|
382
546
|
else {
|
|
383
|
-
doc
|
|
384
|
-
cmd: row.cmd,
|
|
385
|
-
from: row.from,
|
|
386
|
-
...(row.optional ? { optional: true } : {}),
|
|
387
|
-
}));
|
|
547
|
+
addGate(doc, found.areas, row);
|
|
388
548
|
appendOrder(doc, row.name);
|
|
389
549
|
}
|
|
390
550
|
applied.push(`${action} ${row.name}`);
|
|
@@ -406,7 +566,7 @@ export function configureGates(o = {}) {
|
|
|
406
566
|
const added = [];
|
|
407
567
|
for (const n of new Set(names)) {
|
|
408
568
|
const g = available.find((x) => x.name === n);
|
|
409
|
-
doc
|
|
569
|
+
addGate(doc, found.areas, g);
|
|
410
570
|
appendOrder(doc, g.name);
|
|
411
571
|
added.push(g.name);
|
|
412
572
|
}
|