@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
package/cli/dist/lib/bindings.js
CHANGED
|
@@ -1,410 +1,251 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync,
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { parse, stringify } from 'yaml';
|
|
4
4
|
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
5
|
-
import { vendorOf, vendors } from './detect.js';
|
|
6
5
|
import { packageHarness } from './upstream.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
const bad = isObj(doc) ? localValid(doc) : 'not a mapping';
|
|
47
|
-
if (bad !== null || !isObj(doc)) {
|
|
48
|
-
process.stderr.write(`warning: ${LOCAL_BINDINGS} is invalid (${bad}) — ignored\n`);
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
if (isObj(doc['vendors']))
|
|
52
|
-
for (const [k, v] of Object.entries(doc['vendors']))
|
|
53
|
-
if (isObj(v) && typeof v['detected'] === 'boolean')
|
|
54
|
-
out.vendors[k] = {
|
|
55
|
-
detected: v['detected'],
|
|
56
|
-
...(typeof v['at'] === 'string' ? { at: v['at'] } : {}),
|
|
57
|
-
};
|
|
58
|
-
if (isObj(doc['roles']))
|
|
59
|
-
for (const [k, v] of Object.entries(doc['roles']))
|
|
60
|
-
if (isObj(v)) {
|
|
61
|
-
const e = {};
|
|
62
|
-
if (typeof v['model'] === 'string' && v['model'])
|
|
63
|
-
e.model = v['model'];
|
|
64
|
-
if (typeof v['enabled'] === 'boolean')
|
|
65
|
-
e.enabled = v['enabled'];
|
|
66
|
-
if (e.model !== undefined || e.enabled !== undefined)
|
|
67
|
-
out.roles[k] = e;
|
|
68
|
-
}
|
|
69
|
-
return out;
|
|
70
|
-
}
|
|
71
|
-
export function writeLocal(root, doc) {
|
|
72
|
-
const path = join(root, LOCAL_BINDINGS);
|
|
73
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
74
|
-
writeFileSync(path, `# per-user, git-ignored — change with \`reins configure bindings --local\`\n${stringify(doc)}`);
|
|
75
|
-
}
|
|
76
|
-
/** Records a detection run in the local file; `roles` and other vendors' entries are kept. */
|
|
77
|
-
export function recordDetection(root, vs, now = new Date()) {
|
|
78
|
-
const doc = readLocal(root);
|
|
79
|
-
for (const v of vs)
|
|
80
|
-
doc.vendors[v.name] = { detected: v.detected, at: now.toISOString() };
|
|
81
|
-
writeLocal(root, doc);
|
|
82
|
-
}
|
|
83
|
-
function roleMeta(root) {
|
|
84
|
-
const dir = join(root, '.agents/harness/roles');
|
|
85
|
-
const meta = new Map();
|
|
86
|
-
if (!existsSync(dir))
|
|
87
|
-
return meta;
|
|
88
|
-
for (const f of readdirSync(dir)
|
|
89
|
-
.filter((x) => x.endsWith('.md'))
|
|
90
|
-
.toSorted()) {
|
|
91
|
-
const { data } = splitFrontmatter(readFileSync(join(dir, f), 'utf8'));
|
|
92
|
-
meta.set(f.slice(0, -3), {
|
|
93
|
-
def: typeof data?.['default_binding'] === 'string' ? data['default_binding'] : undefined,
|
|
94
|
-
fb: typeof data?.['fallback_binding'] === 'string' ? data['fallback_binding'] : undefined,
|
|
95
|
-
covered: typeof data?.['covered_by'] === 'string' && data['covered_by'] !== 'none'
|
|
96
|
-
? data['covered_by']
|
|
97
|
-
: undefined,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
return meta;
|
|
101
|
-
}
|
|
102
|
-
/** `roles.<r>.enabled` of the committed file, where a boolean is written. */
|
|
103
|
-
export function teamEnabled(root) {
|
|
104
|
-
const path = join(root, '.agents/harness/bindings.yaml');
|
|
105
|
-
if (!existsSync(path))
|
|
106
|
-
return {};
|
|
107
|
-
try {
|
|
108
|
-
const doc = parse(readFileSync(path, 'utf8'));
|
|
109
|
-
const out = {};
|
|
110
|
-
for (const [r, b] of Object.entries(doc?.roles ?? {}))
|
|
111
|
-
if (isObj(b) && typeof b['enabled'] === 'boolean')
|
|
112
|
-
out[r] = b['enabled'];
|
|
113
|
-
return out;
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
return {};
|
|
117
|
-
}
|
|
6
|
+
/** The roles of each group (design §2-2). A group whose list is empty is one role of the same name. */
|
|
7
|
+
export const GROUP_ROLES = {
|
|
8
|
+
pl: [
|
|
9
|
+
'control',
|
|
10
|
+
'plan-reviewer',
|
|
11
|
+
'code-reviewer',
|
|
12
|
+
'qa-plan-reviewer',
|
|
13
|
+
'doc-reviewer',
|
|
14
|
+
'retrospector',
|
|
15
|
+
'discussion',
|
|
16
|
+
],
|
|
17
|
+
planner: ['spec-writer', 'qa-designer'],
|
|
18
|
+
implementer: ['code', 'qa', 'doc'],
|
|
19
|
+
executor: ['tool-executor', 'researcher', 'qa-runner', 'deployer'],
|
|
20
|
+
advisor: ['committee'],
|
|
21
|
+
auditor: [],
|
|
22
|
+
};
|
|
23
|
+
export const GROUPS = Object.keys(GROUP_ROLES);
|
|
24
|
+
/** Roles that use every model of their group rather than one (design §2-2). */
|
|
25
|
+
const ALL_MODELS = new Set(['pl/discussion', 'advisor/committee']);
|
|
26
|
+
const PL_REVIEWERS = new Set([
|
|
27
|
+
'plan-reviewer',
|
|
28
|
+
'code-reviewer',
|
|
29
|
+
'qa-plan-reviewer',
|
|
30
|
+
'doc-reviewer',
|
|
31
|
+
'retrospector',
|
|
32
|
+
]);
|
|
33
|
+
/** Used when a file names no default. */
|
|
34
|
+
export const DEFAULT_BINDING = { vendor: 'claude', model: 'claude-opus-5-5' };
|
|
35
|
+
const pair = (b) => ({ vendor: b.vendor, model: b.model });
|
|
36
|
+
/** The group's models in order: `models`, else the single `vendor`/`model`. */
|
|
37
|
+
function groupModels(spec) {
|
|
38
|
+
if (spec.models?.length)
|
|
39
|
+
return spec.models.map(pair);
|
|
40
|
+
if (spec.vendor && spec.model)
|
|
41
|
+
return [{ vendor: spec.vendor, model: spec.model }];
|
|
42
|
+
return [];
|
|
118
43
|
}
|
|
119
44
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* `enabled: false` in either layer (ignored).
|
|
45
|
+
* Every group's roles with the model(s) that do them. Single mode switches every group off, so the PM
|
|
46
|
+
* does all the work; the auditor's model, if any, stays a recommendation (see `auditBinding`).
|
|
123
47
|
*/
|
|
124
|
-
export function
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
[
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
else if (local.roles[role]?.enabled !== undefined) {
|
|
151
|
-
enabled = local.roles[role].enabled;
|
|
152
|
-
enabled_source = 'local';
|
|
153
|
-
}
|
|
154
|
-
else if (team[role] !== undefined) {
|
|
155
|
-
enabled = team[role];
|
|
156
|
-
enabled_source = 'team';
|
|
48
|
+
export function resolveRoles(doc) {
|
|
49
|
+
const multi = doc.mode === 'multi';
|
|
50
|
+
const out = [];
|
|
51
|
+
for (const group of GROUPS) {
|
|
52
|
+
const spec = doc.groups?.[group];
|
|
53
|
+
const roles = GROUP_ROLES[group].length ? GROUP_ROLES[group] : [group];
|
|
54
|
+
const models = spec ? groupModels(spec) : [];
|
|
55
|
+
for (const role of roles) {
|
|
56
|
+
const own = spec?.roles?.[role];
|
|
57
|
+
if (!multi || (!own && models.length === 0)) {
|
|
58
|
+
out.push({ group, role, on: false, models: [], source: 'off' });
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (own) {
|
|
62
|
+
out.push({ group, role, on: true, models: [pair(own)], source: 'role' });
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
let picked;
|
|
66
|
+
if (ALL_MODELS.has(`${group}/${role}`))
|
|
67
|
+
picked = models;
|
|
68
|
+
else if (group === 'pl' && PL_REVIEWERS.has(role))
|
|
69
|
+
picked = [models[1] ?? models[0]];
|
|
70
|
+
else
|
|
71
|
+
picked = [models[0]];
|
|
72
|
+
out.push({ group, role, on: true, models: picked, source: 'group' });
|
|
157
73
|
}
|
|
158
|
-
states.set(role, {
|
|
159
|
-
role,
|
|
160
|
-
enabled,
|
|
161
|
-
enabled_source,
|
|
162
|
-
...(covered ? { covered_by: covered } : {}),
|
|
163
|
-
});
|
|
164
74
|
}
|
|
165
|
-
return
|
|
75
|
+
return out;
|
|
166
76
|
}
|
|
167
|
-
/** The
|
|
168
|
-
export function
|
|
169
|
-
|
|
170
|
-
return `off${b.covered_by ? ` → ${b.covered_by}` : ''}`;
|
|
171
|
-
return b.enabled_source === 'local' ? 'on (local)' : '';
|
|
77
|
+
/** The PM's model. */
|
|
78
|
+
export function pmBinding(doc) {
|
|
79
|
+
return doc.default ? pair(doc.default) : { ...DEFAULT_BINDING };
|
|
172
80
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (isObj(b) && typeof b['model'] === 'string')
|
|
182
|
-
out[r] = {
|
|
183
|
-
vendor: typeof b['vendor'] === 'string' ? b['vendor'] : vendorOf(b['model']),
|
|
184
|
-
model: b['model'],
|
|
185
|
-
};
|
|
186
|
-
return out;
|
|
187
|
-
}
|
|
188
|
-
catch {
|
|
189
|
-
return {};
|
|
190
|
-
}
|
|
81
|
+
/** The model an audit should run on: the auditor group's, else the PM's (design §3-3). */
|
|
82
|
+
export function auditBinding(doc) {
|
|
83
|
+
const a = doc.groups?.auditor;
|
|
84
|
+
const own = a?.roles?.auditor;
|
|
85
|
+
if (own)
|
|
86
|
+
return pair(own);
|
|
87
|
+
const ms = a ? groupModels(a) : [];
|
|
88
|
+
return ms[0] ?? pmBinding(doc);
|
|
191
89
|
}
|
|
192
|
-
/**
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (v === 'claude')
|
|
210
|
-
return true;
|
|
211
|
-
const known = local.vendors[v];
|
|
212
|
-
if (known)
|
|
213
|
-
return known.detected;
|
|
214
|
-
live ??= new Map(detect().map((x) => [x.name, x.detected]));
|
|
215
|
-
return live.get(v) ?? false;
|
|
216
|
-
};
|
|
217
|
-
const roles = [...new Set([...FIXED_ROLES, ...Object.keys(team), ...meta.keys()])].toSorted();
|
|
218
|
-
const withState = (b) => {
|
|
219
|
-
const { enabled, enabled_source, covered_by } = stateOf(b.role);
|
|
220
|
-
return { ...b, enabled, enabled_source, ...(covered_by ? { covered_by } : {}) };
|
|
221
|
-
};
|
|
222
|
-
const one = (role, last) => {
|
|
223
|
-
const l = local.roles[role]?.model;
|
|
224
|
-
if (l)
|
|
225
|
-
return withState({
|
|
226
|
-
role,
|
|
227
|
-
vendor: vendorOf(l),
|
|
228
|
-
model: l,
|
|
229
|
-
source: 'local',
|
|
230
|
-
reason: 'local override',
|
|
231
|
-
});
|
|
232
|
-
const t = team[role];
|
|
233
|
-
if (t && detected(t.vendor))
|
|
234
|
-
return withState({ role, ...t, source: 'team', reason: 'team binding' });
|
|
235
|
-
const fb = meta.get(role)?.fb;
|
|
236
|
-
const why = t ? `${t.vendor} not detected` : 'no team binding';
|
|
237
|
-
if (fb && detected(vendorOf(fb)))
|
|
238
|
-
return withState({
|
|
239
|
-
role,
|
|
240
|
-
vendor: vendorOf(fb),
|
|
241
|
-
model: fb,
|
|
242
|
-
source: 'fallback',
|
|
243
|
-
reason: `${why} — fallback_binding`,
|
|
244
|
-
});
|
|
245
|
-
return withState({
|
|
246
|
-
role,
|
|
247
|
-
vendor: last.vendor,
|
|
248
|
-
model: last.model,
|
|
249
|
-
source: last.source,
|
|
250
|
-
reason: `${why} — ${last.label}`,
|
|
251
|
-
});
|
|
252
|
-
};
|
|
253
|
-
// pm first, through the same order; its last resort is the claude default model
|
|
254
|
-
const pmRes = one('pm', {
|
|
255
|
-
vendor: vendorOf(DEFAULT_MODEL),
|
|
256
|
-
model: DEFAULT_MODEL,
|
|
257
|
-
source: 'default',
|
|
258
|
-
label: 'default model',
|
|
259
|
-
});
|
|
260
|
-
const pm = {
|
|
261
|
-
vendor: pmRes.vendor,
|
|
262
|
-
model: pmRes.model,
|
|
263
|
-
source: 'pm',
|
|
264
|
-
label: "pm's model",
|
|
265
|
-
};
|
|
266
|
-
const out = [];
|
|
267
|
-
for (const role of roles)
|
|
268
|
-
out.push(role === 'pm' ? pmRes : one(role, pm));
|
|
90
|
+
/** Whether the per-version audit is mandatory (design §3-3): true unless the file says false. */
|
|
91
|
+
export const auditRequired = (doc) => doc.audit?.required !== false;
|
|
92
|
+
/** The local override wins per key: mode, audit, default, each tool and each group as a whole. */
|
|
93
|
+
export function mergeLocal(team, local) {
|
|
94
|
+
if (!local)
|
|
95
|
+
return team;
|
|
96
|
+
const out = { ...team, schema: 'reins/bindings@2' };
|
|
97
|
+
if (local.mode)
|
|
98
|
+
out.mode = local.mode;
|
|
99
|
+
if (local.audit)
|
|
100
|
+
out.audit = { ...team.audit, ...local.audit };
|
|
101
|
+
if (local.default)
|
|
102
|
+
out.default = pair(local.default);
|
|
103
|
+
if (local.tools)
|
|
104
|
+
out.tools = { ...team.tools, ...local.tools };
|
|
105
|
+
if (local.groups)
|
|
106
|
+
out.groups = { ...team.groups, ...local.groups };
|
|
269
107
|
return out;
|
|
270
108
|
}
|
|
271
|
-
|
|
109
|
+
let validator;
|
|
110
|
+
/** Problems of a version-2 file against `harness/schemas/bindings.schema.json`; empty when valid. */
|
|
111
|
+
export function validateBindings(doc) {
|
|
112
|
+
validator ??= new Ajv2020({ allErrors: true, strict: false }).compile(JSON.parse(readFileSync(join(packageHarness(), 'schemas/bindings.schema.json'), 'utf8')));
|
|
113
|
+
if (validator(doc))
|
|
114
|
+
return [];
|
|
115
|
+
const errs = validator
|
|
116
|
+
.errors;
|
|
117
|
+
return (errs ?? []).map((e) => `${e.instancePath || '(root)'} ${e.message ?? 'invalid'}`);
|
|
118
|
+
}
|
|
119
|
+
/** Where each version-1 role goes in version 2 (design §7). `pm` becomes `default`. */
|
|
120
|
+
export const V1_ROLE_MAP = {
|
|
121
|
+
planner: { group: 'planner', role: 'spec-writer' },
|
|
122
|
+
pl: { group: 'pl' },
|
|
123
|
+
'code-review': { group: 'pl', role: 'code-reviewer' },
|
|
124
|
+
implementer: { group: 'implementer' },
|
|
125
|
+
'verify-tool': { group: 'executor', role: 'tool-executor' },
|
|
126
|
+
'qa-run': { group: 'executor', role: 'qa-runner' },
|
|
127
|
+
deploy: { group: 'executor', role: 'deployer' },
|
|
128
|
+
lookup: { group: 'executor', role: 'researcher' },
|
|
129
|
+
'qa-design': { group: 'planner', role: 'qa-designer' },
|
|
130
|
+
docs: { group: 'implementer', role: 'doc' },
|
|
131
|
+
advisor: { group: 'advisor' },
|
|
132
|
+
};
|
|
133
|
+
const DROPPED_V1_KEYS = ['escalation', 'limits'];
|
|
272
134
|
/**
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
* Returns the vendors moved; nothing is written when `dryRun`.
|
|
135
|
+
* A version-1 `bindings.yaml` (`roles.<r>: {vendor, model, enabled, fallback, parallel}`, `vendors`)
|
|
136
|
+
* as version 2. The result is single mode; the converted groups take effect once the user switches to
|
|
137
|
+
* multi with `config`. `notes` says what moved and what was dropped, for the user to confirm.
|
|
277
138
|
*/
|
|
278
|
-
export function
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
const name = isScalar(pair.key) ? String(pair.key.value) : undefined;
|
|
292
|
-
if (name === undefined || !isMap(pair.value))
|
|
139
|
+
export function convertV1(v1) {
|
|
140
|
+
const notes = [];
|
|
141
|
+
const doc = { schema: 'reins/bindings@2', mode: 'single', audit: { required: true } };
|
|
142
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
143
|
+
const roles = isObj(v1['roles']) ? v1['roles'] : {};
|
|
144
|
+
const bindingOf = (v) => isObj(v) && typeof v['vendor'] === 'string' && typeof v['model'] === 'string'
|
|
145
|
+
? { vendor: v['vendor'], model: v['model'] }
|
|
146
|
+
: null;
|
|
147
|
+
const pm = bindingOf(roles['pm']);
|
|
148
|
+
if (pm)
|
|
149
|
+
doc.default = pm;
|
|
150
|
+
for (const [name, raw] of Object.entries(roles)) {
|
|
151
|
+
if (name === 'pm')
|
|
293
152
|
continue;
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
153
|
+
const target = V1_ROLE_MAP[name];
|
|
154
|
+
if (!target) {
|
|
155
|
+
notes.push(`role ${name}: no place in version 2, dropped`);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (isObj(raw) && raw['enabled'] === false) {
|
|
159
|
+
notes.push(`role ${name}: was off, left off`);
|
|
297
160
|
continue;
|
|
298
|
-
const val = (k) => {
|
|
299
|
-
const v = m.get(k);
|
|
300
|
-
return v;
|
|
301
|
-
};
|
|
302
|
-
const det = val('detected');
|
|
303
|
-
const at = ['at', 'detected_at', 'detectedAt', 'checked_at', 'checkedAt']
|
|
304
|
-
.map(val)
|
|
305
|
-
.find((x) => typeof x === 'string' || x instanceof Date);
|
|
306
|
-
if (typeof det !== 'boolean')
|
|
307
|
-
continue; // only a well-formed record is migrated
|
|
308
|
-
found[name] = {
|
|
309
|
-
detected: det,
|
|
310
|
-
...(at === undefined ? {} : { at: at instanceof Date ? at.toISOString() : String(at) }),
|
|
311
|
-
};
|
|
312
|
-
touched.push(name);
|
|
313
|
-
}
|
|
314
|
-
if (touched.length === 0)
|
|
315
|
-
return [];
|
|
316
|
-
if (dryRun)
|
|
317
|
-
return touched;
|
|
318
|
-
const local = loadLocal(root);
|
|
319
|
-
if (local === null)
|
|
320
|
-
return []; // never overwrite a local file we cannot read
|
|
321
|
-
let add = false;
|
|
322
|
-
for (const [k, v] of Object.entries(found))
|
|
323
|
-
if (!local.vendors[k]) {
|
|
324
|
-
local.vendors[k] = v;
|
|
325
|
-
add = true;
|
|
326
161
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
for (const name of touched) {
|
|
330
|
-
const m = vs.get(name, true);
|
|
331
|
-
if (!isMap(m))
|
|
162
|
+
const b = bindingOf(raw);
|
|
163
|
+
if (!b)
|
|
332
164
|
continue;
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if (
|
|
336
|
-
|
|
165
|
+
doc.groups ??= {};
|
|
166
|
+
const spec = (doc.groups[target.group] ??= {});
|
|
167
|
+
if (target.role) {
|
|
168
|
+
spec.roles ??= {};
|
|
169
|
+
spec.roles[target.role] = b;
|
|
170
|
+
}
|
|
171
|
+
else if (!spec.vendor) {
|
|
172
|
+
spec.vendor = b.vendor;
|
|
173
|
+
spec.model = b.model;
|
|
174
|
+
}
|
|
175
|
+
const where = target.role ? `${target.group}.${target.role}` : target.group;
|
|
176
|
+
notes.push(`role ${name} → ${where} (${b.vendor} ${b.model})`);
|
|
177
|
+
for (const k of ['fallback', 'parallel'])
|
|
178
|
+
if (isObj(raw) && k in raw)
|
|
179
|
+
notes.push(`role ${name}: ${k} dropped (no run-time keys)`);
|
|
180
|
+
}
|
|
181
|
+
if (isObj(v1['vendors'])) {
|
|
182
|
+
doc.tools = {};
|
|
183
|
+
for (const [v, raw] of Object.entries(v1['vendors'])) {
|
|
184
|
+
if (!isObj(raw))
|
|
185
|
+
continue;
|
|
186
|
+
const t = {};
|
|
187
|
+
if (typeof raw['cli'] === 'string')
|
|
188
|
+
t.cli = raw['cli'];
|
|
189
|
+
if (typeof raw['available'] === 'boolean')
|
|
190
|
+
t.use = raw['available'];
|
|
191
|
+
doc.tools[v] = t;
|
|
192
|
+
}
|
|
337
193
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
194
|
+
for (const k of DROPPED_V1_KEYS)
|
|
195
|
+
if (k in v1)
|
|
196
|
+
notes.push(`${k}: dropped (no run-time keys)`);
|
|
197
|
+
if (doc.groups)
|
|
198
|
+
notes.push('mode: single — the groups above are kept for multi and unused until then; switch with `reins config`, or remove them with `reins config bindings --off <group>…`');
|
|
199
|
+
return { doc, notes };
|
|
342
200
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
201
|
+
/** The committed team file and the git-ignored personal override (design §5). */
|
|
202
|
+
export const TEAM_BINDINGS = '.agents/harness/bindings.yaml';
|
|
203
|
+
export const LOCAL_BINDINGS = '.loctx/bindings.local.yaml';
|
|
204
|
+
/** Agent tools reins knows how to detect and call (design §9 `config`). */
|
|
205
|
+
export const KNOWN_TOOLS = {
|
|
206
|
+
claude: 'claude',
|
|
207
|
+
openai: 'codex',
|
|
208
|
+
google: 'agy',
|
|
209
|
+
gemini: 'gemini',
|
|
210
|
+
copilot: 'copilot',
|
|
211
|
+
cursor: 'cursor-agent',
|
|
212
|
+
};
|
|
213
|
+
/** The team file as version 2, or `null` when absent; `v1` when an old file is there (update converts it). */
|
|
214
|
+
export function readTeam(root) {
|
|
215
|
+
const p = join(root, TEAM_BINDINGS);
|
|
216
|
+
if (!existsSync(p))
|
|
217
|
+
return { doc: null };
|
|
218
|
+
const raw = parse(readFileSync(p, 'utf8'));
|
|
219
|
+
if (!raw || raw['schema'] !== 'reins/bindings@2')
|
|
220
|
+
return { doc: null, v1: raw ?? {} };
|
|
221
|
+
return { doc: raw };
|
|
351
222
|
}
|
|
352
|
-
/**
|
|
353
|
-
export function
|
|
354
|
-
const
|
|
355
|
-
if (!
|
|
356
|
-
return
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
return null;
|
|
223
|
+
/** The personal override, if any (same shape, any key may be missing). */
|
|
224
|
+
export function readLocalBindings(root) {
|
|
225
|
+
const p = join(root, LOCAL_BINDINGS);
|
|
226
|
+
if (!existsSync(p))
|
|
227
|
+
return undefined;
|
|
228
|
+
const raw = parse(readFileSync(p, 'utf8'));
|
|
229
|
+
return raw && raw['schema'] === 'reins/bindings@2' ? raw : undefined;
|
|
360
230
|
}
|
|
361
|
-
/**
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
if (entry.model === undefined && entry.enabled === undefined)
|
|
382
|
-
delete local.roles[role];
|
|
383
|
-
else
|
|
384
|
-
local.roles[role] = entry;
|
|
385
|
-
writeLocal(root, local);
|
|
386
|
-
return { changed: true };
|
|
387
|
-
}
|
|
388
|
-
const path = join(root, '.agents/harness/bindings.yaml');
|
|
389
|
-
if (!existsSync(path))
|
|
390
|
-
return { refused: 'no bindings.yaml — install the graph tier first', changed: false };
|
|
391
|
-
const doc = parseDocument(readFileSync(path, 'utf8'));
|
|
392
|
-
if (doc.errors.length > 0)
|
|
393
|
-
return { refused: 'bindings.yaml cannot be parsed', changed: false };
|
|
394
|
-
const was = doc.getIn(['roles', role, 'enabled']);
|
|
395
|
-
if (on) {
|
|
396
|
-
if (was === undefined)
|
|
397
|
-
return { changed: false };
|
|
398
|
-
doc.deleteIn(['roles', role, 'enabled']);
|
|
399
|
-
const entry = doc.getIn(['roles', role], true);
|
|
400
|
-
if (isMap(entry) && entry.items.length === 0)
|
|
401
|
-
doc.deleteIn(['roles', role]);
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
if (was === false)
|
|
405
|
-
return { changed: false };
|
|
406
|
-
doc.setIn(['roles', role, 'enabled'], false);
|
|
407
|
-
}
|
|
408
|
-
writeFileSync(path, doc.toString());
|
|
409
|
-
return { changed: true };
|
|
231
|
+
/** What applies to this user: the team file with the personal override on top. */
|
|
232
|
+
export function effectiveBindings(root) {
|
|
233
|
+
const team = readTeam(root).doc;
|
|
234
|
+
return team ? mergeLocal(team, readLocalBindings(root)) : null;
|
|
235
|
+
}
|
|
236
|
+
const HEADER = '# reins model assignment (design §5) — the user changes it with `reins config`; nothing reads it while you work\n';
|
|
237
|
+
export function writeBindings(root, doc, scope) {
|
|
238
|
+
const p = join(root, scope === 'project' ? TEAM_BINDINGS : LOCAL_BINDINGS);
|
|
239
|
+
mkdirSync(dirname(p), { recursive: true });
|
|
240
|
+
writeFileSync(p, `${HEADER}${stringify({ ...doc, schema: 'reins/bindings@2' })}`);
|
|
241
|
+
}
|
|
242
|
+
/** A fresh file for install: single mode, the audit required, the PM on Claude, the detected tools. */
|
|
243
|
+
export function defaultBindings(tools) {
|
|
244
|
+
return {
|
|
245
|
+
schema: 'reins/bindings@2',
|
|
246
|
+
mode: 'single',
|
|
247
|
+
audit: { required: true },
|
|
248
|
+
default: { ...DEFAULT_BINDING },
|
|
249
|
+
tools: Object.fromEntries(tools.map((t) => [t.name, { cli: t.cli, use: t.use }])),
|
|
250
|
+
};
|
|
410
251
|
}
|