@bluenyang/reins 0.1.4 → 0.1.5-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 +84 -6
- package/cli/dist/commands/check.js +1 -1
- package/cli/dist/commands/configure.js +32 -5
- package/cli/dist/commands/gate.js +1 -1
- package/cli/dist/commands/install.js +7 -5
- package/cli/dist/commands/knowledge.js +1 -1
- package/cli/dist/commands/migrate.js +3 -2
- package/cli/dist/commands/new.js +3 -6
- package/cli/dist/commands/stages.js +70 -10
- package/cli/dist/commands/status.js +8 -0
- package/cli/dist/commands/update.js +5 -1
- package/cli/dist/lib/bindings.js +243 -0
- package/cli/dist/lib/enforcement.js +125 -0
- package/cli/dist/lib/fsx.js +16 -2
- package/cli/dist/lib/generate.js +24 -5
- package/cli/dist/lib/git.js +2 -2
- package/cli/dist/lib/metrics.js +1 -1
- package/cli/dist/lib/release.js +48 -0
- package/cli/dist/lib/retro.js +1 -1
- package/cli/dist/reins.js +29 -4
- package/cli/dist/scripts/enforcement.js +24 -0
- package/cli/dist/scripts/sync-version.js +2 -2
- package/docs/README.ko.md +83 -6
- package/harness/policy/enforcement.yaml +98 -0
- package/harness/roles/deploy.md +5 -1
- package/harness/schemas/bindings-local.schema.json +20 -0
- package/harness/schemas/enforcement.schema.json +22 -0
- package/harness/schemas/install.schema.json +11 -1
- package/package.json +7 -3
- package/skills/reins-loop/SKILL.md +2 -0
- package/skills/reins-loop/references/vendor-cli.md +1 -0
- package/skills/reins-release/SKILL.md +2 -1
- package/skills/reins-setup/SKILL.md +1 -1
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { isMap, isScalar, parse, parseDocument, stringify } from 'yaml';
|
|
4
|
+
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
5
|
+
import { vendorOf, vendors } from './detect.js';
|
|
6
|
+
import { packageHarness } from './upstream.js';
|
|
7
|
+
import { splitFrontmatter } from './skills.js';
|
|
8
|
+
/** The git-ignored per-user layer (design §5): detection results and role overrides. */
|
|
9
|
+
export const LOCAL_BINDINGS = '.loctx/bindings.local.yaml';
|
|
10
|
+
/** Used only when pm itself has no usable binding. */
|
|
11
|
+
export const DEFAULT_MODEL = 'claude-opus-5-5';
|
|
12
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
13
|
+
let validateLocal;
|
|
14
|
+
function localValid(doc) {
|
|
15
|
+
validateLocal ??= (() => {
|
|
16
|
+
const schema = JSON.parse(readFileSync(join(packageHarness(), 'schemas/bindings-local.schema.json'), 'utf8'));
|
|
17
|
+
return new Ajv2020({ allErrors: true, strict: false }).compile(schema);
|
|
18
|
+
})();
|
|
19
|
+
if (validateLocal(doc))
|
|
20
|
+
return null;
|
|
21
|
+
const errs = validateLocal.errors;
|
|
22
|
+
return (errs ?? [])
|
|
23
|
+
.map((e) => `${e.instancePath || '(root)'} ${e.message ?? 'invalid'}`)
|
|
24
|
+
.join('; ');
|
|
25
|
+
}
|
|
26
|
+
/** Tolerant: a missing file reads as empty; an invalid one is ignored with a warning, never a crash. */
|
|
27
|
+
export function readLocal(root) {
|
|
28
|
+
return loadLocal(root) ?? { schema: 'reins/bindings-local@1', vendors: {}, roles: {} };
|
|
29
|
+
}
|
|
30
|
+
/** The local file, empty when absent; `null` (after a warning) when it exists but cannot be used. */
|
|
31
|
+
function loadLocal(root) {
|
|
32
|
+
const out = { schema: 'reins/bindings-local@1', vendors: {}, roles: {} };
|
|
33
|
+
const path = join(root, LOCAL_BINDINGS);
|
|
34
|
+
if (!existsSync(path))
|
|
35
|
+
return out;
|
|
36
|
+
let doc;
|
|
37
|
+
try {
|
|
38
|
+
doc = parse(readFileSync(path, 'utf8'));
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
process.stderr.write(`warning: ${LOCAL_BINDINGS} cannot be read (${e.message}) — ignored\n`);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const bad = isObj(doc) ? localValid(doc) : 'not a mapping';
|
|
45
|
+
if (bad !== null || !isObj(doc)) {
|
|
46
|
+
process.stderr.write(`warning: ${LOCAL_BINDINGS} is invalid (${bad}) — ignored\n`);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
if (isObj(doc['vendors']))
|
|
50
|
+
for (const [k, v] of Object.entries(doc['vendors']))
|
|
51
|
+
if (isObj(v) && typeof v['detected'] === 'boolean')
|
|
52
|
+
out.vendors[k] = {
|
|
53
|
+
detected: v['detected'],
|
|
54
|
+
...(typeof v['at'] === 'string' ? { at: v['at'] } : {}),
|
|
55
|
+
};
|
|
56
|
+
if (isObj(doc['roles']))
|
|
57
|
+
for (const [k, v] of Object.entries(doc['roles']))
|
|
58
|
+
if (isObj(v) && typeof v['model'] === 'string' && v['model'])
|
|
59
|
+
out.roles[k] = { model: v['model'] };
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
export function writeLocal(root, doc) {
|
|
63
|
+
const path = join(root, LOCAL_BINDINGS);
|
|
64
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
65
|
+
writeFileSync(path, `# per-user, git-ignored — change with \`reins configure bindings --local\`\n${stringify(doc)}`);
|
|
66
|
+
}
|
|
67
|
+
/** Records a detection run in the local file; `roles` and other vendors' entries are kept. */
|
|
68
|
+
export function recordDetection(root, vs, now = new Date()) {
|
|
69
|
+
const doc = readLocal(root);
|
|
70
|
+
for (const v of vs)
|
|
71
|
+
doc.vendors[v.name] = { detected: v.detected, at: now.toISOString() };
|
|
72
|
+
writeLocal(root, doc);
|
|
73
|
+
}
|
|
74
|
+
function roleMeta(root) {
|
|
75
|
+
const dir = join(root, '.agents/harness/roles');
|
|
76
|
+
const meta = new Map();
|
|
77
|
+
if (!existsSync(dir))
|
|
78
|
+
return meta;
|
|
79
|
+
for (const f of readdirSync(dir)
|
|
80
|
+
.filter((x) => x.endsWith('.md'))
|
|
81
|
+
.toSorted()) {
|
|
82
|
+
const { data } = splitFrontmatter(readFileSync(join(dir, f), 'utf8'));
|
|
83
|
+
meta.set(f.slice(0, -3), {
|
|
84
|
+
def: typeof data?.['default_binding'] === 'string' ? data['default_binding'] : undefined,
|
|
85
|
+
fb: typeof data?.['fallback_binding'] === 'string' ? data['fallback_binding'] : undefined,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return meta;
|
|
89
|
+
}
|
|
90
|
+
function teamRoles(root) {
|
|
91
|
+
const path = join(root, '.agents/harness/bindings.yaml');
|
|
92
|
+
if (!existsSync(path))
|
|
93
|
+
return {};
|
|
94
|
+
try {
|
|
95
|
+
const doc = parse(readFileSync(path, 'utf8'));
|
|
96
|
+
const out = {};
|
|
97
|
+
for (const [r, b] of Object.entries(doc?.roles ?? {}))
|
|
98
|
+
if (isObj(b) && typeof b['model'] === 'string')
|
|
99
|
+
out[r] = {
|
|
100
|
+
vendor: typeof b['vendor'] === 'string' ? b['vendor'] : vendorOf(b['model']),
|
|
101
|
+
model: b['model'],
|
|
102
|
+
};
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return {};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The model each role actually runs on (design §5). Per role: local override → team binding when its
|
|
111
|
+
* vendor is detected → the role file's `fallback_binding` when its vendor is detected → the pm model.
|
|
112
|
+
* A vendor missing from the local file is detected live (`detect`) and not written back. claude is the floor.
|
|
113
|
+
*/
|
|
114
|
+
export function resolveBindings(root, detect = vendors) {
|
|
115
|
+
const local = readLocal(root);
|
|
116
|
+
const team = teamRoles(root);
|
|
117
|
+
const meta = roleMeta(root);
|
|
118
|
+
let live;
|
|
119
|
+
const detected = (v) => {
|
|
120
|
+
if (v === 'claude')
|
|
121
|
+
return true;
|
|
122
|
+
const known = local.vendors[v];
|
|
123
|
+
if (known)
|
|
124
|
+
return known.detected;
|
|
125
|
+
live ??= new Map(detect().map((x) => [x.name, x.detected]));
|
|
126
|
+
return live.get(v) ?? false;
|
|
127
|
+
};
|
|
128
|
+
const roles = [...new Set([...Object.keys(team), ...meta.keys()])].toSorted();
|
|
129
|
+
const one = (role, last) => {
|
|
130
|
+
const l = local.roles[role]?.model;
|
|
131
|
+
if (l)
|
|
132
|
+
return { role, vendor: vendorOf(l), model: l, source: 'local', reason: 'local override' };
|
|
133
|
+
const t = team[role];
|
|
134
|
+
if (t && detected(t.vendor))
|
|
135
|
+
return { role, ...t, source: 'team', reason: 'team binding' };
|
|
136
|
+
const fb = meta.get(role)?.fb;
|
|
137
|
+
const why = t ? `${t.vendor} not detected` : 'no team binding';
|
|
138
|
+
if (fb && detected(vendorOf(fb)))
|
|
139
|
+
return {
|
|
140
|
+
role,
|
|
141
|
+
vendor: vendorOf(fb),
|
|
142
|
+
model: fb,
|
|
143
|
+
source: 'fallback',
|
|
144
|
+
reason: `${why} — fallback_binding`,
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
role,
|
|
148
|
+
vendor: last.vendor,
|
|
149
|
+
model: last.model,
|
|
150
|
+
source: last.source,
|
|
151
|
+
reason: `${why} — ${last.label}`,
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
// pm first, through the same order; its last resort is the claude default model
|
|
155
|
+
const pmRes = one('pm', {
|
|
156
|
+
vendor: vendorOf(DEFAULT_MODEL),
|
|
157
|
+
model: DEFAULT_MODEL,
|
|
158
|
+
source: 'default',
|
|
159
|
+
label: 'default model',
|
|
160
|
+
});
|
|
161
|
+
const pm = {
|
|
162
|
+
vendor: pmRes.vendor,
|
|
163
|
+
model: pmRes.model,
|
|
164
|
+
source: 'pm',
|
|
165
|
+
label: "pm's model",
|
|
166
|
+
};
|
|
167
|
+
const out = [];
|
|
168
|
+
for (const role of roles)
|
|
169
|
+
out.push(role === 'pm' ? pmRes : one(role, pm));
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
const DETECT_KEYS = ['detected', 'at', 'detected_at', 'detectedAt', 'checked_at', 'checkedAt'];
|
|
173
|
+
/**
|
|
174
|
+
* 0.1.4 kept `vendors.<v>.detected` (and a timestamp) in the committed bindings.yaml. Moves them to the
|
|
175
|
+
* local file (a vendor the local file already has is kept as is) and removes just those keys from the
|
|
176
|
+
* committed one through the Document API, so comments, order and every other key stay as written.
|
|
177
|
+
* Returns the vendors moved; nothing is written when `dryRun`.
|
|
178
|
+
*/
|
|
179
|
+
export function migrateDetected(root, dryRun = false) {
|
|
180
|
+
const path = join(root, '.agents/harness/bindings.yaml');
|
|
181
|
+
if (!existsSync(path))
|
|
182
|
+
return [];
|
|
183
|
+
const doc = parseDocument(readFileSync(path, 'utf8'));
|
|
184
|
+
if (doc.errors.length > 0)
|
|
185
|
+
return [];
|
|
186
|
+
const vs = doc.get('vendors', true);
|
|
187
|
+
if (!isMap(vs))
|
|
188
|
+
return [];
|
|
189
|
+
const found = {};
|
|
190
|
+
const touched = [];
|
|
191
|
+
for (const pair of vs.items) {
|
|
192
|
+
const name = isScalar(pair.key) ? String(pair.key.value) : undefined;
|
|
193
|
+
if (name === undefined || !isMap(pair.value))
|
|
194
|
+
continue;
|
|
195
|
+
const m = pair.value;
|
|
196
|
+
const keys = m.items.filter((i) => isScalar(i.key) && DETECT_KEYS.includes(String(i.key.value)));
|
|
197
|
+
if (keys.length === 0)
|
|
198
|
+
continue;
|
|
199
|
+
const val = (k) => {
|
|
200
|
+
const v = m.get(k);
|
|
201
|
+
return v;
|
|
202
|
+
};
|
|
203
|
+
const det = val('detected');
|
|
204
|
+
const at = ['at', 'detected_at', 'detectedAt', 'checked_at', 'checkedAt']
|
|
205
|
+
.map(val)
|
|
206
|
+
.find((x) => typeof x === 'string' || x instanceof Date);
|
|
207
|
+
if (typeof det !== 'boolean')
|
|
208
|
+
continue; // only a well-formed record is migrated
|
|
209
|
+
found[name] = {
|
|
210
|
+
detected: det,
|
|
211
|
+
...(at === undefined ? {} : { at: at instanceof Date ? at.toISOString() : String(at) }),
|
|
212
|
+
};
|
|
213
|
+
touched.push(name);
|
|
214
|
+
}
|
|
215
|
+
if (touched.length === 0)
|
|
216
|
+
return [];
|
|
217
|
+
if (dryRun)
|
|
218
|
+
return touched;
|
|
219
|
+
const local = loadLocal(root);
|
|
220
|
+
if (local === null)
|
|
221
|
+
return []; // never overwrite a local file we cannot read
|
|
222
|
+
let add = false;
|
|
223
|
+
for (const [k, v] of Object.entries(found))
|
|
224
|
+
if (!local.vendors[k]) {
|
|
225
|
+
local.vendors[k] = v;
|
|
226
|
+
add = true;
|
|
227
|
+
}
|
|
228
|
+
if (add)
|
|
229
|
+
writeLocal(root, local);
|
|
230
|
+
for (const name of touched) {
|
|
231
|
+
const m = vs.get(name, true);
|
|
232
|
+
if (!isMap(m))
|
|
233
|
+
continue;
|
|
234
|
+
for (const k of DETECT_KEYS)
|
|
235
|
+
m.delete(k);
|
|
236
|
+
if (m.items.length === 0)
|
|
237
|
+
vs.delete(name);
|
|
238
|
+
}
|
|
239
|
+
if (vs.items.length === 0)
|
|
240
|
+
doc.delete('vendors');
|
|
241
|
+
writeFileSync(path, doc.toString());
|
|
242
|
+
return touched;
|
|
243
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { readFileSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { parse } from 'yaml';
|
|
4
|
+
import { splitFrontmatter } from './skills.js';
|
|
5
|
+
const HELD = ['blocked', 'checked', 'advised'];
|
|
6
|
+
const WORDS = {
|
|
7
|
+
en: { blocked: 'blocked', checked: 'checked', advised: 'advised' },
|
|
8
|
+
ko: { blocked: '차단', checked: '검사', advised: '권고' },
|
|
9
|
+
};
|
|
10
|
+
const HEAD = {
|
|
11
|
+
en: {
|
|
12
|
+
main: ['id', 'held', 'by', 'gap'],
|
|
13
|
+
role: ['role', 'blocked', 'checked', 'advised', 'blocked items'],
|
|
14
|
+
budget: 'budget scopes',
|
|
15
|
+
},
|
|
16
|
+
ko: {
|
|
17
|
+
main: ['id', '지킴', '수단', '빈틈'],
|
|
18
|
+
role: ['역할', '차단', '검사', '권고', '차단되는 항목'],
|
|
19
|
+
budget: '예산 범위',
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export function readRules(text) {
|
|
23
|
+
const d = parse(text);
|
|
24
|
+
return d?.rules ?? [];
|
|
25
|
+
}
|
|
26
|
+
/** `must_not` items of every role file in `<harness>/roles`, by role name. */
|
|
27
|
+
export function roleMustNot(harness) {
|
|
28
|
+
const out = new Map();
|
|
29
|
+
const dir = join(harness, 'roles');
|
|
30
|
+
for (const f of readdirSync(dir)
|
|
31
|
+
.filter((x) => x.endsWith('.md'))
|
|
32
|
+
.toSorted()) {
|
|
33
|
+
const m = splitFrontmatter(readFileSync(join(dir, f), 'utf8')).data?.['must_not'];
|
|
34
|
+
out.set(f.replace(/\.md$/, ''), Array.isArray(m) ? m.map(String) : []);
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
/** Every id the table must cover: policy files, role `must_not` items, budget scopes. */
|
|
39
|
+
export function expectedIds(harness) {
|
|
40
|
+
const y = (f) => parse(readFileSync(join(harness, 'policy', f), 'utf8'));
|
|
41
|
+
const ids = [];
|
|
42
|
+
for (const r of y('common-red-lines.yaml')['rules'] ?? [])
|
|
43
|
+
ids.push(r.id);
|
|
44
|
+
for (const s of y('stops.yaml')['stops'] ?? [])
|
|
45
|
+
ids.push(s.id);
|
|
46
|
+
for (const p of y('transitions.yaml')['points'] ?? [])
|
|
47
|
+
ids.push(p.id);
|
|
48
|
+
for (const [role, items] of roleMustNot(harness))
|
|
49
|
+
items.forEach((_, i) => ids.push(`${role}#${i + 1}`));
|
|
50
|
+
for (const s of y('budget.yaml')['scopes'] ?? [])
|
|
51
|
+
ids.push(`budget:${s.name}`);
|
|
52
|
+
return ids;
|
|
53
|
+
}
|
|
54
|
+
/** The rules of `enforcement.yaml`, each with its `must_not` text where it has one. */
|
|
55
|
+
export function enforcementRows(harness) {
|
|
56
|
+
const mustNot = roleMustNot(harness);
|
|
57
|
+
return readRules(readFileSync(join(harness, 'policy', 'enforcement.yaml'), 'utf8')).map((r) => {
|
|
58
|
+
const m = /^(.+)#(\d+)$/.exec(r.id);
|
|
59
|
+
const text = m ? mustNot.get(m[1] ?? '')?.[Number(m[2]) - 1] : undefined;
|
|
60
|
+
return text === undefined ? r : { ...r, text };
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const esc = (s) => s.replaceAll('|', '\\|');
|
|
64
|
+
const table = (head, rows) => [
|
|
65
|
+
`| ${head.join(' | ')} |`,
|
|
66
|
+
`|${head.map(() => '---').join('|')}|`,
|
|
67
|
+
...rows.map((r) => `| ${r.map(esc).join(' | ')} |`),
|
|
68
|
+
];
|
|
69
|
+
const isRole = (id) => id.includes('#');
|
|
70
|
+
const isBudget = (id) => id.startsWith('budget:');
|
|
71
|
+
function mainRows(rows, lang, pick) {
|
|
72
|
+
return table(HEAD[lang].main, rows
|
|
73
|
+
.filter((r) => pick(r.id))
|
|
74
|
+
.map((r) => [
|
|
75
|
+
r.id,
|
|
76
|
+
WORDS[lang][r.held],
|
|
77
|
+
r.by.map((b) => `\`${b}\``).join(', '),
|
|
78
|
+
r.gap ?? '—',
|
|
79
|
+
]));
|
|
80
|
+
}
|
|
81
|
+
function roleRows(rows, lang) {
|
|
82
|
+
const roles = new Map();
|
|
83
|
+
for (const r of rows.filter((x) => isRole(x.id))) {
|
|
84
|
+
const role = r.id.slice(0, r.id.indexOf('#'));
|
|
85
|
+
roles.set(role, [...(roles.get(role) ?? []), r]);
|
|
86
|
+
}
|
|
87
|
+
const count = (rs, h) => String(rs.filter((r) => r.held === h).length);
|
|
88
|
+
const body = [...roles].map(([role, rs]) => [
|
|
89
|
+
role,
|
|
90
|
+
...HELD.map((h) => count(rs, h)),
|
|
91
|
+
rs
|
|
92
|
+
.filter((r) => r.held === 'blocked')
|
|
93
|
+
.map((r) => r.text ?? r.id)
|
|
94
|
+
.join('; ') || '—',
|
|
95
|
+
]);
|
|
96
|
+
const budget = rows.filter((r) => isBudget(r.id));
|
|
97
|
+
body.push([HEAD[lang].budget, ...HELD.map((h) => count(budget, h)), '—']);
|
|
98
|
+
return table(HEAD[lang].role, body);
|
|
99
|
+
}
|
|
100
|
+
/** The Markdown tables between the `enforcement` markers; no trailing newline. */
|
|
101
|
+
export function renderTable(rows, lang, view = 'all') {
|
|
102
|
+
if (view === 'redlines')
|
|
103
|
+
return mainRows(rows, lang, (id) => /^C\d+$/.test(id)).join('\n');
|
|
104
|
+
if (view === 'stops')
|
|
105
|
+
return mainRows(rows, lang, (id) => /^[ABDEFGPT]\d+$/.test(id)).join('\n');
|
|
106
|
+
const main = mainRows(rows, lang, (id) => !isRole(id) && !isBudget(id));
|
|
107
|
+
return [...main, '', ...roleRows(rows, lang)].join('\n');
|
|
108
|
+
}
|
|
109
|
+
const MARK = /(<!-- enforcement:begin(?: (\w+))? -->\n)([\s\S]*?)(\n<!-- enforcement:end -->)/g;
|
|
110
|
+
/** Replaces the content of every `enforcement` marker pair with the rendered table; returns the text and how many pairs it found. */
|
|
111
|
+
export function applyMarkers(text, lang, rows) {
|
|
112
|
+
let pairs = 0;
|
|
113
|
+
const out = text.replace(MARK, (_m, open, view, _body, close) => {
|
|
114
|
+
pairs += 1;
|
|
115
|
+
return `${open}${renderTable(rows, lang, view ?? 'all')}${close}`;
|
|
116
|
+
});
|
|
117
|
+
return { text: out, pairs };
|
|
118
|
+
}
|
|
119
|
+
/** Documents that carry markers, with their language and how many pairs each must hold. */
|
|
120
|
+
export const MARKED_DOCS = [
|
|
121
|
+
{ file: 'README.md', lang: 'en', pairs: 1 },
|
|
122
|
+
{ file: 'docs/README.ko.md', lang: 'ko', pairs: 1 },
|
|
123
|
+
{ file: 'docs/design.md', lang: 'en', pairs: 2 },
|
|
124
|
+
{ file: 'docs/design.ko.md', lang: 'ko', pairs: 2 },
|
|
125
|
+
];
|
package/cli/dist/lib/fsx.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { dirname, join, relative, sep } from 'node:path';
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync, } from 'node:fs';
|
|
2
|
+
import path, { dirname, join, relative, sep } from 'node:path';
|
|
3
3
|
export function apply(root, writes, dryRun) {
|
|
4
4
|
const out = { created: [], changed: [], unchanged: [], removed: [] };
|
|
5
5
|
for (const w of writes) {
|
|
@@ -22,6 +22,20 @@ export function relPath(from, to) {
|
|
|
22
22
|
const rel = relative(from, to);
|
|
23
23
|
return sep === '/' ? rel : rel.split(sep).join('/');
|
|
24
24
|
}
|
|
25
|
+
/** Whether `to` is `from` or lies under it; `p` selects the path flavour (tests pass `path.win32`). */
|
|
26
|
+
export function isWithin(from, to, p = path) {
|
|
27
|
+
const rel = p.relative(from, to);
|
|
28
|
+
return rel !== '..' && !rel.startsWith(`..${p.sep}`) && !p.isAbsolute(rel);
|
|
29
|
+
}
|
|
30
|
+
/** The real path with symlinks and Windows 8.3 short names (RUNNER~1) resolved; the input when it does not exist. */
|
|
31
|
+
export function realPath(p) {
|
|
32
|
+
try {
|
|
33
|
+
return realpathSync.native(p);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return p;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
25
39
|
/** Every file under `dir`, as `/`-separated paths relative to `dir`. */
|
|
26
40
|
export function listFiles(dir) {
|
|
27
41
|
const out = [];
|
package/cli/dist/lib/generate.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { parse, stringify } from 'yaml';
|
|
3
3
|
import { workTreeReader } from './reader.js';
|
|
4
|
+
import { vendorOf } from './detect.js';
|
|
4
5
|
import { splitFrontmatter } from './skills.js';
|
|
5
6
|
/**
|
|
6
7
|
* Vendor files generated from `.agents/harness/` (design §6). Round one generates Claude Code only:
|
|
@@ -17,6 +18,7 @@ function readRole(text) {
|
|
|
17
18
|
may: d['may'] ?? [],
|
|
18
19
|
mustNot: d['must_not'] ?? [],
|
|
19
20
|
capabilities: d['capabilities'] ?? {},
|
|
21
|
+
fallback: typeof d['fallback_binding'] === 'string' ? d['fallback_binding'] : undefined,
|
|
20
22
|
body: body.trim(),
|
|
21
23
|
};
|
|
22
24
|
}
|
|
@@ -29,7 +31,7 @@ function disallowed(c) {
|
|
|
29
31
|
out.push('Bash');
|
|
30
32
|
return out;
|
|
31
33
|
}
|
|
32
|
-
export function claudeAgent(r, b, version) {
|
|
34
|
+
export function claudeAgent(r, b, version, fallbackFor) {
|
|
33
35
|
const fm = {
|
|
34
36
|
name: `reins-${r.role}`,
|
|
35
37
|
description: `reins ${r.role} role. ${r.summary}`,
|
|
@@ -43,6 +45,9 @@ export function claudeAgent(r, b, version) {
|
|
|
43
45
|
stringify(fm).trimEnd(),
|
|
44
46
|
'---',
|
|
45
47
|
`<!-- generated by reins ${version} from .agents/harness/roles/${r.role}.md and bindings.yaml — do not edit; run \`reins update\` -->`,
|
|
48
|
+
...(fallbackFor
|
|
49
|
+
? [`<!-- fallback for ${fallbackFor} — the team binds this role to another vendor -->`]
|
|
50
|
+
: []),
|
|
46
51
|
'',
|
|
47
52
|
`You are the **${r.role}** role of the reins harness in this repository. ${r.summary}`,
|
|
48
53
|
'',
|
|
@@ -107,14 +112,28 @@ export function generateVendorFiles(root, rd = workTreeReader(root)) {
|
|
|
107
112
|
const b = bindings[r.role];
|
|
108
113
|
if (!b)
|
|
109
114
|
continue;
|
|
115
|
+
// Committed team defaults only (never the local file), so no user's override makes drift.
|
|
116
|
+
// A role bound to another vendor still gets a Claude file on its fallback model, else pm's.
|
|
117
|
+
let model = b.model;
|
|
118
|
+
let fallbackFor;
|
|
110
119
|
if (b.vendor !== 'claude') {
|
|
111
|
-
|
|
112
|
-
|
|
120
|
+
const pm = bindings['pm'];
|
|
121
|
+
const fb = r.fallback && vendorOf(r.fallback) === 'claude'
|
|
122
|
+
? r.fallback
|
|
123
|
+
: pm && pm.vendor === 'claude'
|
|
124
|
+
? pm.model
|
|
125
|
+
: undefined;
|
|
126
|
+
if (!fb) {
|
|
127
|
+
out.skipped.push(`${r.role} → ${b.vendor} ${b.model}`);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
model = fb;
|
|
131
|
+
fallbackFor = b.vendor;
|
|
113
132
|
}
|
|
114
133
|
out.writes.push({
|
|
115
134
|
path: `.claude/agents/reins-${r.role}.md`,
|
|
116
|
-
content: claudeAgent(r,
|
|
117
|
-
why: `role ${r.role}`,
|
|
135
|
+
content: claudeAgent(r, { vendor: 'claude', model }, version, fallbackFor),
|
|
136
|
+
why: fallbackFor ? `role ${r.role} (fallback for ${fallbackFor})` : `role ${r.role}`,
|
|
118
137
|
});
|
|
119
138
|
}
|
|
120
139
|
// skills: Codex, Gemini and Cursor read .agents/skills/ directly; Claude Code reads a byte-identical copy
|
package/cli/dist/lib/git.js
CHANGED
|
@@ -8,7 +8,7 @@ function git(args, cwd) {
|
|
|
8
8
|
}
|
|
9
9
|
export function stagedFiles(cwd) {
|
|
10
10
|
const out = git(['diff', '--cached', '--name-only', '--diff-filter=ACMR'], cwd);
|
|
11
|
-
return out ? out.split(
|
|
11
|
+
return out ? out.split(/\r?\n/) : [];
|
|
12
12
|
}
|
|
13
13
|
/** The checked-out branch; on a repository without commits `rev-parse` fails, so ask for the symbolic ref instead. */
|
|
14
14
|
export function currentBranch(cwd) {
|
|
@@ -43,7 +43,7 @@ export function repoRoot(cwd) {
|
|
|
43
43
|
export function pushedSubjects(remoteSha, localSha, cwd) {
|
|
44
44
|
try {
|
|
45
45
|
const out = git(['log', '--format=%s', `${remoteSha}..${localSha}`], cwd);
|
|
46
|
-
return out ? out.split(
|
|
46
|
+
return out ? out.split(/\r?\n/) : [];
|
|
47
47
|
}
|
|
48
48
|
catch {
|
|
49
49
|
return [];
|
package/cli/dist/lib/metrics.js
CHANGED
package/cli/dist/lib/release.js
CHANGED
|
@@ -122,3 +122,51 @@ export function releaseDraftNotes(drafts) {
|
|
|
122
122
|
.map(([k, v]) => `${k}: ${JSON.stringify(v)}`)
|
|
123
123
|
.join(', ')}}, approval: ${d.approval}}`);
|
|
124
124
|
}
|
|
125
|
+
/** The checks `release.docs` may name (design §4). */
|
|
126
|
+
export const DOC_CHECKS = ['roadmap-row', 'changelog-section', 'mentions-version'];
|
|
127
|
+
/** Reads `release.docs`; [] when the file, the key or an entry is missing or malformed. */
|
|
128
|
+
export function readReleaseDocs(root) {
|
|
129
|
+
const p = join(root, '.agents/harness/install.yaml');
|
|
130
|
+
if (!existsSync(p))
|
|
131
|
+
return [];
|
|
132
|
+
let doc;
|
|
133
|
+
try {
|
|
134
|
+
doc = parse(readFileSync(p, 'utf8'));
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
const list = doc?.release?.docs;
|
|
140
|
+
if (!Array.isArray(list))
|
|
141
|
+
return [];
|
|
142
|
+
const out = [];
|
|
143
|
+
for (const d of list) {
|
|
144
|
+
const check = d?.['check'];
|
|
145
|
+
if (typeof d?.['file'] === 'string' && DOC_CHECKS.includes(check))
|
|
146
|
+
out.push({ file: d['file'], check: check });
|
|
147
|
+
}
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, (c) => `\\${c}`);
|
|
151
|
+
/**
|
|
152
|
+
* Whether `text` is up to date for version `v` (pure). `roadmap-row`: a table row whose first
|
|
153
|
+
* cell is `v` and whose state cell is not planned/계획. `changelog-section`: rc `## [Unreleased] — v`
|
|
154
|
+
* or `## [v]`; stable only `## [v]`. `mentions-version`: `v` as a token of its own.
|
|
155
|
+
*/
|
|
156
|
+
export function checkDoc(text, check, v, stage) {
|
|
157
|
+
const e = escapeRe(v);
|
|
158
|
+
if (check === 'roadmap-row')
|
|
159
|
+
return text.split(/\r?\n/).some((line) => {
|
|
160
|
+
const cells = line.split('|').map((c) => c.trim());
|
|
161
|
+
return (line.trimStart().startsWith('|') &&
|
|
162
|
+
cells[1] === v &&
|
|
163
|
+
cells[2] !== undefined &&
|
|
164
|
+
cells[2] !== '' &&
|
|
165
|
+
!/^(planned|계획)$/i.test(cells[2]));
|
|
166
|
+
});
|
|
167
|
+
if (check === 'changelog-section')
|
|
168
|
+
return stage === 'stable'
|
|
169
|
+
? new RegExp(`^## \\[${e}\\]`, 'm').test(text)
|
|
170
|
+
: new RegExp(`^## (\\[Unreleased\\] — ${e}(?![\\w.])|\\[${e}\\])`, 'm').test(text);
|
|
171
|
+
return new RegExp(`(?<![\\w.])${e}(?![\\w]|\\.\\d)`).test(text);
|
|
172
|
+
}
|
package/cli/dist/lib/retro.js
CHANGED
|
@@ -11,7 +11,7 @@ export function readDismissals(root) {
|
|
|
11
11
|
const f = join(root, DISMISSED);
|
|
12
12
|
if (!existsSync(f))
|
|
13
13
|
return out;
|
|
14
|
-
for (const line of readFileSync(f, 'utf8').split(
|
|
14
|
+
for (const line of readFileSync(f, 'utf8').split(/\r?\n/)) {
|
|
15
15
|
try {
|
|
16
16
|
const d = JSON.parse(line);
|
|
17
17
|
if (typeof d.key === 'string' && typeof d.units === 'number')
|
package/cli/dist/reins.js
CHANGED
|
@@ -17,6 +17,12 @@ import { defaultsAsker, stdinAsker } from './lib/ask.js';
|
|
|
17
17
|
import { EXIT } from './lib/verdict.js';
|
|
18
18
|
// the version npm installed — cli/dist/reins.js sits two levels below package.json
|
|
19
19
|
const VERSION = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')).version;
|
|
20
|
+
// every command: a reader that went away (`| head`) ends the run quietly with the exit code already set
|
|
21
|
+
process.stdout.on('error', (e) => {
|
|
22
|
+
if (e.code === 'EPIPE')
|
|
23
|
+
process.exit(process.exitCode ?? 0);
|
|
24
|
+
throw e;
|
|
25
|
+
});
|
|
20
26
|
const program = new Command()
|
|
21
27
|
.name('reins')
|
|
22
28
|
.description('agent harness — install, migrate, update; check keeps agents inside their roles')
|
|
@@ -136,6 +142,8 @@ program
|
|
|
136
142
|
process.stdout.write(`reins update — cli ${r.cliFrom === 'none' ? 'none' : `v${r.cliFrom}`} → v${r.cliTo}, harness v${r.from} → v${r.to}${o.dryRun ? ' (dry run)' : ''}\n`);
|
|
137
143
|
for (const c of r.changes)
|
|
138
144
|
process.stdout.write(` · ${c}\n`);
|
|
145
|
+
if (r.bindingsMoved)
|
|
146
|
+
process.stdout.write(`bindings: ${o.dryRun ? 'would move' : 'moved'} detected vendors (${r.bindingsMoved.join(', ')}) to .loctx/bindings.local.yaml\n`);
|
|
139
147
|
if (a && a.created.length + a.changed.length + a.removed.length === 0)
|
|
140
148
|
process.stdout.write('already up to date\n');
|
|
141
149
|
else if (a) {
|
|
@@ -160,10 +168,14 @@ configure
|
|
|
160
168
|
.description('bind roles to models: --set role=model … or --vendors claude,openai,…; no options asks')
|
|
161
169
|
.option('--set <pairs...>', 'role=model pairs')
|
|
162
170
|
.option('--vendors <list>', 'rebuild every role from its defaults for these vendors (comma-separated)')
|
|
171
|
+
.option('--local', 'with --set: write your own override to .loctx/bindings.local.yaml')
|
|
172
|
+
.option('--show', 'print what each role actually runs on')
|
|
163
173
|
.option('--json')
|
|
164
174
|
.action(async (o) => {
|
|
165
|
-
const asker = !o.set && !o.vendors ? await stdinAsker() : undefined;
|
|
175
|
+
const asker = !o.set && !o.vendors && !o.local && !o.show ? await stdinAsker() : undefined;
|
|
166
176
|
const r = await configureBindings({
|
|
177
|
+
local: o.local,
|
|
178
|
+
show: o.show,
|
|
167
179
|
set: o.set,
|
|
168
180
|
vendors: o.vendors?.split(',').map((s) => s.trim()),
|
|
169
181
|
asker,
|
|
@@ -177,8 +189,13 @@ configure
|
|
|
177
189
|
process.stderr.write(`reins configure bindings: ${r.refused}\n`);
|
|
178
190
|
process.exit(2);
|
|
179
191
|
}
|
|
180
|
-
|
|
181
|
-
|
|
192
|
+
if (o.show || o.local) {
|
|
193
|
+
for (const t of r.resolved ?? [])
|
|
194
|
+
process.stdout.write(` ${r.changed.includes(t.role) ? '*' : ' '} ${t.role.padEnd(12)} ${t.vendor.padEnd(7)} ${t.model} (${t.source}: ${t.reason})\n`);
|
|
195
|
+
}
|
|
196
|
+
else
|
|
197
|
+
for (const t of r.table)
|
|
198
|
+
process.stdout.write(` ${r.changed.includes(t.role) ? '*' : ' '} ${t.role.padEnd(12)} ${t.vendor.padEnd(7)} ${t.model}\n`);
|
|
182
199
|
process.stdout.write(r.changed.length ? `changed: ${r.changed.join(', ')}\n` : 'no change\n');
|
|
183
200
|
const g = r.generated;
|
|
184
201
|
if (g) {
|
|
@@ -366,6 +383,7 @@ program
|
|
|
366
383
|
.option('--stage <stage>', 'T1 ticket-start · T2 pre-commit · T3 verdict · T4 pre-push · T5 rc-close')
|
|
367
384
|
.option('--ticket <id>', 'ticket-start, verdict: the ticket id')
|
|
368
385
|
.option('--release <version>', 'rc-close: the version the rc closes')
|
|
386
|
+
.option('--stable', "rc-close: print the stable dispatch lines (the user's instruction only)")
|
|
369
387
|
.option('--drift')
|
|
370
388
|
.option('--json')
|
|
371
389
|
.action(async (o) => {
|
|
@@ -381,7 +399,14 @@ program
|
|
|
381
399
|
chunks.push(c);
|
|
382
400
|
pushRefs = Buffer.concat(chunks).toString('utf8').split('\n').filter(Boolean);
|
|
383
401
|
}
|
|
384
|
-
const r = runCheck({
|
|
402
|
+
const r = runCheck({
|
|
403
|
+
stage,
|
|
404
|
+
drift: o.drift,
|
|
405
|
+
pushRefs,
|
|
406
|
+
ticket: o.ticket,
|
|
407
|
+
release: o.release,
|
|
408
|
+
stable: o.stable,
|
|
409
|
+
});
|
|
385
410
|
// S-8: the verdict code is set before anything is printed, so a closed pipe cannot change it
|
|
386
411
|
process.exitCode = EXIT[r.verdict];
|
|
387
412
|
process.stdout.on('error', (e) => {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Re-renders the enforcement tables between the `enforcement` markers of the README and design editions.
|
|
2
|
+
// Run by `pnpm docs:enforcement`; the test in cli/test/enforcement.test.ts fails when they drift.
|
|
3
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
|
+
import { MARKED_DOCS, applyMarkers, enforcementRows } from '../lib/enforcement.js';
|
|
7
|
+
// compiled to cli/dist/scripts/: the repository root is three levels up (or the first argument)
|
|
8
|
+
const root = resolve(process.argv[2] ?? fileURLToPath(new URL('../../../', import.meta.url)));
|
|
9
|
+
export function renderDocs() {
|
|
10
|
+
const rows = enforcementRows(resolve(root, 'harness'));
|
|
11
|
+
for (const d of MARKED_DOCS) {
|
|
12
|
+
const path = resolve(root, d.file);
|
|
13
|
+
const { text, pairs } = applyMarkers(readFileSync(path, 'utf8'), d.lang, rows);
|
|
14
|
+
if (pairs !== d.pairs) {
|
|
15
|
+
console.error(`enforcement: ${d.file} has ${pairs} marker pair(s), expected ${d.pairs}`);
|
|
16
|
+
return 1;
|
|
17
|
+
}
|
|
18
|
+
writeFileSync(path, text);
|
|
19
|
+
}
|
|
20
|
+
console.log('enforcement tables rendered');
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href)
|
|
24
|
+
process.exitCode = renderDocs();
|