@bluenyang/reins 0.1.0 → 0.1.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 +31 -24
- package/cli/dist/commands/check.js +180 -90
- package/cli/dist/commands/configure.js +79 -0
- package/cli/dist/commands/gate.js +54 -0
- package/cli/dist/commands/install.js +80 -30
- package/cli/dist/commands/metrics.js +138 -0
- package/cli/dist/commands/stages.js +435 -0
- package/cli/dist/commands/status.js +249 -0
- package/cli/dist/commands/update.js +70 -0
- package/cli/dist/lib/blocks.js +6 -1
- package/cli/dist/lib/detect.js +91 -1
- package/cli/dist/lib/fsx.js +8 -3
- package/cli/dist/lib/generate.js +143 -0
- package/cli/dist/lib/git.js +12 -1
- package/cli/dist/lib/harness.js +15 -4
- package/cli/dist/lib/metrics.js +223 -0
- package/cli/dist/lib/reader.js +47 -0
- package/cli/dist/lib/schema.js +23 -2
- package/cli/dist/lib/skills.js +13 -2
- package/cli/dist/lib/upstream.js +8 -0
- package/cli/dist/lib/vendor-write.js +136 -0
- package/cli/dist/lib/work.js +106 -0
- package/cli/dist/reins.js +161 -7
- package/cli/dist/scripts/sync-version.js +16 -0
- package/docs/README.ko.md +31 -25
- package/harness/CHANGELOG.md +5 -0
- package/harness/VERSION +1 -1
- package/harness/policy/stops.yaml +2 -2
- package/harness/policy/transitions.yaml +1 -1
- package/harness/roles/code-review.md +6 -3
- package/harness/roles/pl.md +2 -1
- package/harness/roles/qa-design.md +1 -1
- package/harness/roles/qa-run.md +1 -1
- package/harness/templates/bus/request.yaml +8 -2
- package/harness/templates/bus/response.yaml +1 -0
- package/package.json +10 -2
- package/skills/reins-loop/SKILL.md +5 -1
- package/skills/reins-loop/references/vendor-cli.md +40 -0
- package/skills/reins-setup/SKILL.md +7 -2
package/README.md
CHANGED
|
@@ -14,14 +14,16 @@ loop that works only with Claude. The full list (P1–P6) is in [docs/proposal.m
|
|
|
14
14
|
|
|
15
15
|
## Status
|
|
16
16
|
|
|
17
|
-
Version 0.1.0
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
Version 0.1.0 is on npm: `npx @bluenyang/reins <command>`. It is round one of the plan — the graph
|
|
18
|
+
tier, with generated vendor files verified for Claude Code only; the loop and harness tiers are
|
|
19
|
+
carved out of it in 0.2. Known issues are listed in [CHANGELOG.md](CHANGELOG.md); their fixes ship
|
|
20
|
+
as 0.1.1, and 0.1.2 adds a Claude Code plugin.
|
|
20
21
|
|
|
21
|
-
reins develops itself through its own loop
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
the `reins-loop` skill. The CLI does
|
|
22
|
+
reins develops itself through its own loop: intents 001 (`reins status`), 002 (`reins metrics`) and
|
|
23
|
+
003 (violation scenarios) each went intent → spec → plan → tickets, with the checks at T1 to T5
|
|
24
|
+
passing and Codex doing the code review. Roles bound to other vendors ran through their CLIs
|
|
25
|
+
(`codex exec`, `agy -p`): the lead agent called them following the `reins-loop` skill. The CLI does
|
|
26
|
+
not dispatch to vendors by itself yet.
|
|
25
27
|
|
|
26
28
|
## The ladder
|
|
27
29
|
|
|
@@ -76,30 +78,35 @@ reviewed by roles. Verification output is pasted as produced; a bare "passed" is
|
|
|
76
78
|
| `.claude/` | yes | generated from `.agents/`; do not edit |
|
|
77
79
|
| `.loctx/` | no (gitignored) | tickets, reports, handoff `bus/`, `history/`, local roadmap |
|
|
78
80
|
|
|
79
|
-
## Quick start
|
|
81
|
+
## Quick start
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
In Claude Code, install the plugin and let it set the repository up:
|
|
82
84
|
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
pnpm build
|
|
85
|
+
```
|
|
86
|
+
/plugin marketplace add bluenyang/reins
|
|
87
|
+
/plugin install reins@bluenyang
|
|
88
|
+
/reins:reins-setup
|
|
88
89
|
```
|
|
89
90
|
|
|
90
|
-
|
|
91
|
-
commit (`check` fails on an empty history in 0.1.0):
|
|
91
|
+
For Codex, Antigravity, Cursor or a plain terminal, use the CLI. It requires Node 20 or later. Run it from the root of the repository you want to set up; the repository
|
|
92
|
+
needs at least one commit (`check` fails on an empty history in 0.1.0):
|
|
92
93
|
|
|
93
94
|
```sh
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
npx @bluenyang/reins install graph --dry-run # show what would be written
|
|
96
|
+
npx @bluenyang/reins install graph --mode auto # place files, detect CLIs, take defaults
|
|
97
|
+
npx @bluenyang/reins check --drift # prints "drift: ok" when sources and output match
|
|
98
|
+
npx @bluenyang/reins status # intents, tickets, bus, last history entry
|
|
98
99
|
```
|
|
99
100
|
|
|
100
101
|
`install` refuses over a 3rd or 4th generation harness and points to `migrate`. Hooks are proposed
|
|
101
|
-
in the install notes and added only with `--hooks`.
|
|
102
|
-
|
|
102
|
+
in the install notes and added only with `--hooks`.
|
|
103
|
+
|
|
104
|
+
After the install, work goes through the agent: in Claude Code run `/reins-setup` once, then
|
|
105
|
+
`/reins-intent` for each new request; Codex, Antigravity and Cursor read the same skills from
|
|
106
|
+
`.agents/skills/`. The skills call the CLI themselves.
|
|
107
|
+
|
|
108
|
+
To work on reins itself: `git clone https://github.com/bluenyang/reins.git`, then `pnpm install`,
|
|
109
|
+
`pnpm build`, and run `node cli/dist/reins.js <command>` (see [CONTRIBUTING.md](CONTRIBUTING.md)).
|
|
103
110
|
|
|
104
111
|
## Commands
|
|
105
112
|
|
|
@@ -134,9 +141,9 @@ Three skills are the entry points for an agent; they follow the `SKILL.md` stand
|
|
|
134
141
|
|
|
135
142
|
| Version | Content |
|
|
136
143
|
|---|---|
|
|
137
|
-
| 0.1 | graph design, self-install and self-migrate of this repository, the verifier, three skills,
|
|
144
|
+
| 0.1 | graph design, self-install and self-migrate of this repository, the verifier, three skills, metrics, violation scenarios. 0.1.0 published; 0.1.1 stabilisation (fixes the loop found); 0.1.2 Claude Code plugin (marketplace install) |
|
|
138
145
|
| 0.2 | carve the loop and harness tiers out of the graph; generated files for Codex, Gemini and Cursor; `recall`, `doctor`, budget stops; trial migration of older harnesses |
|
|
139
|
-
| 0.3 |
|
|
146
|
+
| 0.3 | application to Team Croffle repositories |
|
|
140
147
|
| 1.0 | not scheduled: reins stays on 0.x and gains features until the maintainer considers the system settled; stabilising alone does not make it 1.0 |
|
|
141
148
|
|
|
142
149
|
## Documents
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import { existsSync, readFileSync
|
|
2
|
-
import { basename, join
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { basename, join } from 'node:path';
|
|
3
|
+
import { hasOwnSection, overrides, parseBlocks } from '../lib/blocks.js';
|
|
3
4
|
import { currentBranch, isAncestor, repoRoot, stagedFiles } from '../lib/git.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { harnessRel, secretPolicy } from '../lib/harness.js';
|
|
6
|
+
import { loadSchemasFrom, schemaFor, validateFile } from '../lib/schema.js';
|
|
6
7
|
import { DEFAULT_ALLOWED, DEFAULT_SECRET_PATTERNS, isSecretPath } from '../lib/secrets.js';
|
|
7
|
-
import {
|
|
8
|
-
import { harnessVersion, packageHarness } from '../lib/upstream.js';
|
|
8
|
+
import { splitFrontmatter, validateSkillFile } from '../lib/skills.js';
|
|
9
|
+
import { harnessVersion, packageHarness, packageSkills, tierSkills } from '../lib/upstream.js';
|
|
10
|
+
import { listFiles, relPath } from '../lib/fsx.js';
|
|
11
|
+
import { driftGenerated } from '../lib/vendor-write.js';
|
|
12
|
+
import { indexReader, workTreeReader } from '../lib/reader.js';
|
|
13
|
+
import { rcClose, ticketStart, verdictCheck } from './stages.js';
|
|
9
14
|
import { parse } from 'yaml';
|
|
10
15
|
import { report } from '../lib/verdict.js';
|
|
16
|
+
export const STAGES = ['ticket-start', 'pre-commit', 'verdict', 'pre-push', 'rc-close'];
|
|
11
17
|
const SKILL_ROOTS = ['skills', '.agents/skills', '.claude/skills'];
|
|
12
18
|
const LOCAL_DIRS = ['.loctx/', '.ai/'];
|
|
13
19
|
function gitignoreHas(root, entry) {
|
|
@@ -23,7 +29,8 @@ function gitignoreHas(root, entry) {
|
|
|
23
29
|
/** T2 — before a commit. */
|
|
24
30
|
export function preCommit(root) {
|
|
25
31
|
const findings = [];
|
|
26
|
-
const
|
|
32
|
+
const rd = indexReader(root);
|
|
33
|
+
const policy = secretPolicy(root, rd);
|
|
27
34
|
const patterns = policy?.patterns ?? DEFAULT_SECRET_PATTERNS;
|
|
28
35
|
const allowed = policy?.allowed ?? DEFAULT_ALLOWED;
|
|
29
36
|
const staged = stagedFiles(root);
|
|
@@ -55,9 +62,15 @@ export function preCommit(root) {
|
|
|
55
62
|
message: 'local workspace exists but is not in .gitignore',
|
|
56
63
|
resume: 'add ".loctx/" (or ".ai/") to .gitignore',
|
|
57
64
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
// S-1: the checks read the content the commit would contain (the index), not the working tree
|
|
66
|
+
findings.push(...driftFormat(root, staged, rd), ...driftConvention(root, staged, rd));
|
|
67
|
+
const under = (...dirs) => staged.some((f) => dirs.some((d) => f.startsWith(d)));
|
|
68
|
+
if (under('harness/', '.agents/harness/', 'skills/', '.agents/skills/'))
|
|
69
|
+
findings.push(...driftMatch(root, rd));
|
|
70
|
+
if (staged.includes('AGENTS.md'))
|
|
71
|
+
findings.push(...driftBlocks(root, rd));
|
|
72
|
+
if (under('.claude/', '.agents/harness/', '.agents/skills/'))
|
|
73
|
+
findings.push(...driftGenerated(root, rd));
|
|
61
74
|
return findings;
|
|
62
75
|
}
|
|
63
76
|
/** T4 — before leaving the machine. */
|
|
@@ -68,8 +81,18 @@ export function prePush(root, refs) {
|
|
|
68
81
|
const [localRef, localSha, remoteRef, remoteSha] = line.trim().split(/\s+/);
|
|
69
82
|
if (!localSha || !remoteSha || !remoteRef)
|
|
70
83
|
continue;
|
|
84
|
+
if (ZERO.test(localSha) && remoteRef.startsWith('refs/tags/')) {
|
|
85
|
+
findings.push({
|
|
86
|
+
reason: 'A1',
|
|
87
|
+
verdict: 'HOLD',
|
|
88
|
+
path: remoteRef,
|
|
89
|
+
message: `push deletes tag ${remoteRef.slice('refs/tags/'.length)}`,
|
|
90
|
+
resume: 'deleting a published tag is irreversible — the user must run it explicitly',
|
|
91
|
+
});
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
71
94
|
if (ZERO.test(remoteSha) || ZERO.test(localSha))
|
|
72
|
-
continue; // new
|
|
95
|
+
continue; // new ref or branch deletion
|
|
73
96
|
if (!isAncestor(remoteSha, localSha, root))
|
|
74
97
|
findings.push({
|
|
75
98
|
reason: 'A1',
|
|
@@ -82,56 +105,45 @@ export function prePush(root, refs) {
|
|
|
82
105
|
return findings;
|
|
83
106
|
}
|
|
84
107
|
/** Drift, format layer — Agent Skills spec on SKILL.md files. */
|
|
85
|
-
export function driftFormat(root, only) {
|
|
86
|
-
const files =
|
|
87
|
-
const chosen = only ? files.filter((f) => only.includes(
|
|
88
|
-
return chosen.flatMap((f) => validateSkillFile(f).map((i) => ({
|
|
108
|
+
export function driftFormat(root, only, rd = workTreeReader(root)) {
|
|
109
|
+
const files = SKILL_ROOTS.flatMap((r) => rd.list(r).filter((p) => /^[^/]+\/SKILL\.md$/.test(p.slice(r.length + 1))));
|
|
110
|
+
const chosen = only ? files.filter((f) => only.includes(f)) : files;
|
|
111
|
+
return chosen.flatMap((f) => validateSkillFile(join(root, f), rd.read(f)).map((i) => ({
|
|
89
112
|
reason: 'F2',
|
|
90
113
|
verdict: 'STOP',
|
|
91
|
-
path:
|
|
114
|
+
path: relPath(root, i.path),
|
|
92
115
|
message: i.message,
|
|
93
116
|
resume: 'fix the SKILL.md frontmatter; see agentskills.io/specification',
|
|
94
117
|
})));
|
|
95
118
|
}
|
|
96
|
-
/** Files the convention layer looks at: harness sources plus the installed project's agent files. */
|
|
97
|
-
function walk(dir, out = []) {
|
|
98
|
-
if (!existsSync(dir))
|
|
99
|
-
return out;
|
|
100
|
-
for (const e of readdirSync(dir)) {
|
|
101
|
-
const p = join(dir, e);
|
|
102
|
-
if (statSync(p).isDirectory())
|
|
103
|
-
walk(p, out);
|
|
104
|
-
else
|
|
105
|
-
out.push(p);
|
|
106
|
-
}
|
|
107
|
-
return out;
|
|
108
|
-
}
|
|
109
119
|
/** Drift, convention layer — frontmatter schemas and role files (design §6). */
|
|
110
|
-
export function driftConvention(root, only) {
|
|
111
|
-
const
|
|
112
|
-
if (!
|
|
120
|
+
export function driftConvention(root, only, rd = workTreeReader(root)) {
|
|
121
|
+
const hrel = harnessRel(rd);
|
|
122
|
+
if (!hrel)
|
|
113
123
|
return [];
|
|
114
|
-
const schemas =
|
|
124
|
+
const schemas = loadSchemasFrom(rd, hrel);
|
|
115
125
|
const findings = [];
|
|
116
126
|
const candidates = [
|
|
117
|
-
...
|
|
118
|
-
...
|
|
119
|
-
...
|
|
120
|
-
...
|
|
121
|
-
...
|
|
122
|
-
...
|
|
127
|
+
...rd.list(`${hrel}/templates`),
|
|
128
|
+
...rd.list(`${hrel}/knowledge-seeds`),
|
|
129
|
+
...rd.list('.agents/intent'),
|
|
130
|
+
...rd.list('.agents/knowledge'),
|
|
131
|
+
...rd.list('.loctx/ticket'),
|
|
132
|
+
...rd.list('.loctx/bus'),
|
|
123
133
|
];
|
|
124
|
-
for (const
|
|
125
|
-
const rel = relative(root, abs);
|
|
134
|
+
for (const rel of candidates) {
|
|
126
135
|
if (only && !only.includes(rel))
|
|
127
136
|
continue;
|
|
137
|
+
const text = rd.read(rel);
|
|
138
|
+
if (text === undefined)
|
|
139
|
+
continue;
|
|
128
140
|
const m = schemaFor(rel);
|
|
129
141
|
if (!m)
|
|
130
142
|
continue;
|
|
131
143
|
const v = schemas.get(m.schema);
|
|
132
144
|
if (!v)
|
|
133
145
|
continue;
|
|
134
|
-
for (const i of validateFile(v,
|
|
146
|
+
for (const i of validateFile(v, join(root, rel), m.whole, text))
|
|
135
147
|
findings.push({
|
|
136
148
|
reason: 'F2',
|
|
137
149
|
verdict: 'STOP',
|
|
@@ -141,45 +153,43 @@ export function driftConvention(root, only) {
|
|
|
141
153
|
});
|
|
142
154
|
}
|
|
143
155
|
// role files: role == file name, must_not present
|
|
144
|
-
const roles =
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
});
|
|
173
|
-
}
|
|
156
|
+
const roles = `${hrel}/roles`;
|
|
157
|
+
for (const rel of rd.list(roles).filter((x) => /^[^/]+\.md$/.test(x.slice(roles.length + 1)))) {
|
|
158
|
+
if (only && !only.includes(rel))
|
|
159
|
+
continue;
|
|
160
|
+
const { data, error } = splitFrontmatter(rd.read(rel) ?? '');
|
|
161
|
+
const name = basename(rel, '.md');
|
|
162
|
+
if (error)
|
|
163
|
+
findings.push({
|
|
164
|
+
reason: 'F2',
|
|
165
|
+
verdict: 'STOP',
|
|
166
|
+
path: rel,
|
|
167
|
+
message: `frontmatter is not valid YAML: ${error}`,
|
|
168
|
+
});
|
|
169
|
+
else if (!data || data['role'] !== name)
|
|
170
|
+
findings.push({
|
|
171
|
+
reason: 'F2',
|
|
172
|
+
verdict: 'STOP',
|
|
173
|
+
path: rel,
|
|
174
|
+
message: `role file must declare role: ${name}`,
|
|
175
|
+
});
|
|
176
|
+
else if (!Array.isArray(data['must_not']) || data['must_not'].length === 0)
|
|
177
|
+
findings.push({
|
|
178
|
+
reason: 'F2',
|
|
179
|
+
verdict: 'STOP',
|
|
180
|
+
path: rel,
|
|
181
|
+
message: 'must_not is the enforced source and cannot be empty',
|
|
182
|
+
});
|
|
183
|
+
}
|
|
174
184
|
return findings;
|
|
175
185
|
}
|
|
176
186
|
/** Files in an installed harness that belong to the project, not upstream. */
|
|
177
|
-
const PROJECT_OWNED = new Set(['bindings.yaml', 'gates.yaml', 'install.yaml']);
|
|
187
|
+
const PROJECT_OWNED = new Set(['bindings.yaml', 'gates.yaml', 'install.yaml', 'generated.yaml']);
|
|
178
188
|
/** Drift, match layer — the installed `.agents/harness/` against the packaged upstream at the pinned version (design §6). */
|
|
179
|
-
export function driftMatch(root) {
|
|
180
|
-
const installed =
|
|
181
|
-
const
|
|
182
|
-
if (
|
|
189
|
+
export function driftMatch(root, rd = workTreeReader(root)) {
|
|
190
|
+
const installed = '.agents/harness';
|
|
191
|
+
const pinText = rd.read(`${installed}/install.yaml`);
|
|
192
|
+
if (pinText === undefined)
|
|
183
193
|
return [];
|
|
184
194
|
let up;
|
|
185
195
|
try {
|
|
@@ -188,7 +198,8 @@ export function driftMatch(root) {
|
|
|
188
198
|
catch {
|
|
189
199
|
return [];
|
|
190
200
|
}
|
|
191
|
-
const
|
|
201
|
+
const pinned = parse(pinText);
|
|
202
|
+
const pin = pinned.version;
|
|
192
203
|
const upVersion = harnessVersion(up);
|
|
193
204
|
if (pin !== upVersion)
|
|
194
205
|
return [
|
|
@@ -201,14 +212,14 @@ export function driftMatch(root) {
|
|
|
201
212
|
},
|
|
202
213
|
];
|
|
203
214
|
const findings = [];
|
|
204
|
-
for (const
|
|
205
|
-
const rel =
|
|
215
|
+
for (const entry of rd.list(installed)) {
|
|
216
|
+
const rel = entry.slice(installed.length + 1);
|
|
206
217
|
if (PROJECT_OWNED.has(rel))
|
|
207
218
|
continue;
|
|
208
219
|
const src = join(up, rel);
|
|
209
220
|
if (!existsSync(src))
|
|
210
221
|
continue;
|
|
211
|
-
if (readFileSync(src, 'utf8') !==
|
|
222
|
+
if (readFileSync(src, 'utf8') !== rd.read(entry))
|
|
212
223
|
findings.push({
|
|
213
224
|
reason: 'F2',
|
|
214
225
|
verdict: 'STOP',
|
|
@@ -217,6 +228,80 @@ export function driftMatch(root) {
|
|
|
217
228
|
resume: 'run `reins update` to restore it; change behaviour upstream or with an override',
|
|
218
229
|
});
|
|
219
230
|
}
|
|
231
|
+
// installed skill entry points = the packaged ones
|
|
232
|
+
const skillsUp = packageSkills();
|
|
233
|
+
for (const name of tierSkills(pinned.tier ?? 'graph')) {
|
|
234
|
+
const dir = `.agents/skills/${name}`;
|
|
235
|
+
if (rd.list(dir).length === 0)
|
|
236
|
+
continue;
|
|
237
|
+
for (const f of listFiles(join(skillsUp, name))) {
|
|
238
|
+
if (rd.read(`${dir}/${f}`) !== readFileSync(join(skillsUp, name, f), 'utf8'))
|
|
239
|
+
findings.push({
|
|
240
|
+
reason: 'F2',
|
|
241
|
+
verdict: 'STOP',
|
|
242
|
+
path: `.agents/skills/${name}/${f}`,
|
|
243
|
+
message: `differs from the packaged skill (v${upVersion})`,
|
|
244
|
+
resume: 'run `reins update`; a project-specific procedure belongs in its own skill',
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return findings;
|
|
249
|
+
}
|
|
250
|
+
/** Compare a block for drift: CRLF to LF, trailing whitespace per line, blank lines around the content. */
|
|
251
|
+
function normBlock(s) {
|
|
252
|
+
return s
|
|
253
|
+
.replace(/\r\n/g, '\n')
|
|
254
|
+
.split('\n')
|
|
255
|
+
.map((l) => l.replace(/\s+$/, ''))
|
|
256
|
+
.join('\n')
|
|
257
|
+
.replace(/^\n+|\n+$/g, '');
|
|
258
|
+
}
|
|
259
|
+
/** Drift, managed blocks — AGENTS.md blocks against the packaged ones at the pinned version (design §5). */
|
|
260
|
+
export function driftBlocks(root, rd = workTreeReader(root)) {
|
|
261
|
+
const text = rd.read('AGENTS.md');
|
|
262
|
+
if (text === undefined)
|
|
263
|
+
return [];
|
|
264
|
+
const pinText = rd.read('.agents/harness/install.yaml');
|
|
265
|
+
if (pinText === undefined)
|
|
266
|
+
return [];
|
|
267
|
+
let upBlocks;
|
|
268
|
+
try {
|
|
269
|
+
const up = packageHarness();
|
|
270
|
+
if (parse(pinText).version !== harnessVersion(up))
|
|
271
|
+
return []; // driftMatch warns
|
|
272
|
+
upBlocks = new Map(parseBlocks(readFileSync(join(up, 'templates/agents-md-blocks.md'), 'utf8')).map((b) => [
|
|
273
|
+
b.name,
|
|
274
|
+
b,
|
|
275
|
+
]));
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
return [];
|
|
279
|
+
}
|
|
280
|
+
const over = overrides(text);
|
|
281
|
+
const findings = [];
|
|
282
|
+
const have = parseBlocks(text);
|
|
283
|
+
for (const [name, up] of upBlocks)
|
|
284
|
+
if (!over.has(name) && !have.some((b) => b.name === name) && !hasOwnSection(text, up))
|
|
285
|
+
findings.push({
|
|
286
|
+
reason: 'F2',
|
|
287
|
+
verdict: 'STOP',
|
|
288
|
+
path: 'AGENTS.md',
|
|
289
|
+
message: `managed block "${name}" is missing`,
|
|
290
|
+
resume: `run \`reins update\`, or add <!-- reins:override ${name} -->`,
|
|
291
|
+
});
|
|
292
|
+
for (const b of have) {
|
|
293
|
+
const want = upBlocks.get(b.name);
|
|
294
|
+
if (!want || over.has(b.name))
|
|
295
|
+
continue;
|
|
296
|
+
if (normBlock(b.body) !== normBlock(want.body))
|
|
297
|
+
findings.push({
|
|
298
|
+
reason: 'F2',
|
|
299
|
+
verdict: 'STOP',
|
|
300
|
+
path: 'AGENTS.md',
|
|
301
|
+
message: `managed block "${b.name}" was edited by hand`,
|
|
302
|
+
resume: `run \`reins update\`, or add <!-- reins:override ${b.name} -->`,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
220
305
|
return findings;
|
|
221
306
|
}
|
|
222
307
|
export function runCheck(opts) {
|
|
@@ -227,17 +312,22 @@ export function runCheck(opts) {
|
|
|
227
312
|
findings.push(...preCommit(root));
|
|
228
313
|
else if (opts.stage === 'pre-push')
|
|
229
314
|
findings.push(...prePush(root, opts.pushRefs ?? []));
|
|
230
|
-
else if (opts.stage) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
315
|
+
else if (opts.stage === 'ticket-start' || opts.stage === 'verdict') {
|
|
316
|
+
if (!opts.ticket)
|
|
317
|
+
findings.push({
|
|
318
|
+
reason: 'F2',
|
|
319
|
+
verdict: 'STOP',
|
|
320
|
+
message: `stage needs --ticket <id>`,
|
|
321
|
+
});
|
|
322
|
+
else
|
|
323
|
+
findings.push(...(opts.stage === 'ticket-start'
|
|
324
|
+
? ticketStart(root, opts.ticket)
|
|
325
|
+
: verdictCheck(root, opts.ticket)));
|
|
238
326
|
}
|
|
327
|
+
else if (opts.stage === 'rc-close')
|
|
328
|
+
findings.push(...rcClose(root, opts.release));
|
|
239
329
|
if (opts.drift || !opts.stage)
|
|
240
|
-
findings.push(...driftFormat(root), ...driftConvention(root), ...driftMatch(root));
|
|
330
|
+
findings.push(...driftFormat(root), ...driftConvention(root), ...driftMatch(root), ...driftBlocks(root), ...driftGenerated(root));
|
|
241
331
|
if (!currentBranch(root))
|
|
242
332
|
findings.push({ reason: 'F2', verdict: 'STOP', message: 'not a git repository' });
|
|
243
333
|
return report(stage, findings);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { parse, stringify } from 'yaml';
|
|
4
|
+
import { CONFIRMED_MODELS, checkBinding, newModelCache, vendorOf, vendors, } from '../lib/detect.js';
|
|
5
|
+
import { generateVendorFiles } from '../lib/generate.js';
|
|
6
|
+
import { repoRoot } from '../lib/git.js';
|
|
7
|
+
import { writeGenerated } from '../lib/vendor-write.js';
|
|
8
|
+
import { packageHarness } from '../lib/upstream.js';
|
|
9
|
+
import { buildBindings } from './install.js';
|
|
10
|
+
/** `reins configure bindings` (R57–R59): any role, any model, any vendor; then the vendor files follow. */
|
|
11
|
+
export async function configureBindings(o) {
|
|
12
|
+
const root = repoRoot(o.cwd ?? process.cwd());
|
|
13
|
+
const path = join(root, '.agents/harness/bindings.yaml');
|
|
14
|
+
if (!existsSync(path))
|
|
15
|
+
return { refused: 'no bindings.yaml — install the graph tier first', changed: [], table: [] };
|
|
16
|
+
const roles = new Set(readdirSync(join(root, '.agents/harness/roles'))
|
|
17
|
+
.filter((f) => f.endsWith('.md'))
|
|
18
|
+
.map((f) => f.slice(0, -3)));
|
|
19
|
+
let doc = parse(readFileSync(path, 'utf8'));
|
|
20
|
+
const changed = [];
|
|
21
|
+
const cache = o.modelCache ?? newModelCache();
|
|
22
|
+
if (o.vendors?.length) {
|
|
23
|
+
const vs = (o.detectVendors ?? vendors)();
|
|
24
|
+
const avail = new Set([
|
|
25
|
+
'claude',
|
|
26
|
+
...o.vendors.filter((v) => ['openai', 'google', 'cursor'].includes(v)),
|
|
27
|
+
]);
|
|
28
|
+
const rebuilt = parse(buildBindings(packageHarness(), avail, vs, doc.mode ?? 'manual', cache));
|
|
29
|
+
for (const r of Object.keys(rebuilt.roles))
|
|
30
|
+
if (JSON.stringify(rebuilt.roles[r]) !== JSON.stringify(doc.roles[r]))
|
|
31
|
+
changed.push(r);
|
|
32
|
+
doc = rebuilt;
|
|
33
|
+
}
|
|
34
|
+
let pairs = o.set ?? [];
|
|
35
|
+
if (!pairs.length && !o.vendors?.length && o.asker) {
|
|
36
|
+
const ans = await o.asker.ask('change bindings as role=model, comma-separated (empty: keep)', '');
|
|
37
|
+
pairs = ans
|
|
38
|
+
.split(',')
|
|
39
|
+
.map((s) => s.trim())
|
|
40
|
+
.filter(Boolean);
|
|
41
|
+
}
|
|
42
|
+
for (const pair of pairs) {
|
|
43
|
+
const [role, model] = pair.split('=').map((s) => s.trim());
|
|
44
|
+
if (!role || !model)
|
|
45
|
+
return { refused: `"${pair}" is not role=model`, changed: [], table: [] };
|
|
46
|
+
if (!roles.has(role))
|
|
47
|
+
return {
|
|
48
|
+
refused: `unknown role "${role}" — roles: ${[...roles].toSorted().join(', ')}`,
|
|
49
|
+
changed: [],
|
|
50
|
+
table: [],
|
|
51
|
+
};
|
|
52
|
+
const entry = { vendor: vendorOf(model), model };
|
|
53
|
+
if (role === 'implementer')
|
|
54
|
+
entry['parallel'] = doc.roles[role]?.['parallel'] ?? 4;
|
|
55
|
+
const chk = checkBinding(model, entry.vendor, cache);
|
|
56
|
+
if (chk) {
|
|
57
|
+
if (chk.unverified)
|
|
58
|
+
entry['unverified'] = true;
|
|
59
|
+
if (chk.note)
|
|
60
|
+
entry['note'] = chk.note;
|
|
61
|
+
}
|
|
62
|
+
else if (!CONFIRMED_MODELS.has(model))
|
|
63
|
+
entry['unverified'] = true;
|
|
64
|
+
if (JSON.stringify(doc.roles[role]) !== JSON.stringify(entry)) {
|
|
65
|
+
doc.roles[role] = entry;
|
|
66
|
+
if (!changed.includes(role))
|
|
67
|
+
changed.push(role);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (changed.length)
|
|
71
|
+
writeFileSync(path, `# generated by reins — change with \`reins configure bindings\`\n${stringify(doc)}`);
|
|
72
|
+
const generated = changed.length
|
|
73
|
+
? writeGenerated(root, generateVendorFiles(root), false)
|
|
74
|
+
: undefined;
|
|
75
|
+
const table = Object.entries(doc.roles)
|
|
76
|
+
.map(([role, b]) => ({ role, vendor: b.vendor, model: b.model }))
|
|
77
|
+
.toSorted((a, b) => a.role.localeCompare(b.role));
|
|
78
|
+
return { changed, table, generated };
|
|
79
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { repoRoot } from '../lib/git.js';
|
|
5
|
+
import { harnessDir, readYaml } from '../lib/harness.js';
|
|
6
|
+
/** One command per gate (design §5): no pipes, chains or redirects — anything else is massaged output (C5). */
|
|
7
|
+
export function compound(cmd) {
|
|
8
|
+
return /[|;&<>`]|\$\(/.test(cmd.replace(/'[^']*'|"[^"]*"/g, ''));
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Runs gates exactly as gates.yaml declares them and keeps the raw output as evidence:
|
|
12
|
+
* `$ <cmd>`, the output untouched, `exit <code>` — the format `check --stage verdict` (T3) reads.
|
|
13
|
+
*/
|
|
14
|
+
export function runGates(o) {
|
|
15
|
+
const root = repoRoot(o.cwd ?? process.cwd());
|
|
16
|
+
const dir = harnessDir(root);
|
|
17
|
+
const path = dir && join(dir, 'gates.yaml');
|
|
18
|
+
if (!path || !existsSync(path))
|
|
19
|
+
return { runs: [], refused: 'no gates.yaml — run reins install' };
|
|
20
|
+
const g = readYaml(path);
|
|
21
|
+
const gates = g.gates ?? {};
|
|
22
|
+
const names = o.names?.length ? o.names : (g.order ?? Object.keys(gates));
|
|
23
|
+
const unknown = names.filter((n) => !gates[n]?.cmd);
|
|
24
|
+
if (unknown.length)
|
|
25
|
+
return {
|
|
26
|
+
runs: [],
|
|
27
|
+
refused: `unknown gate${unknown.length > 1 ? 's' : ''}: ${unknown.join(', ')} (gates: ${Object.keys(gates).join(', ')})`,
|
|
28
|
+
};
|
|
29
|
+
const reports = join(root, '.loctx', 'reports');
|
|
30
|
+
mkdirSync(reports, { recursive: true });
|
|
31
|
+
const runs = [];
|
|
32
|
+
let failed = false;
|
|
33
|
+
for (const name of names) {
|
|
34
|
+
const cmd = gates[name].cmd;
|
|
35
|
+
const report = `.loctx/reports/${o.ticket ?? 'adhoc'}_${name}.log`;
|
|
36
|
+
if (failed && !o.all) {
|
|
37
|
+
runs.push({ gate: name, cmd, exit: null, report, skipped: 'an earlier gate failed' });
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (compound(cmd)) {
|
|
41
|
+
runs.push({ gate: name, cmd, exit: null, report, skipped: 'not a single command (C5)' });
|
|
42
|
+
failed = true;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const r = spawnSync(`${cmd} 2>&1`, { cwd: root, shell: true, encoding: 'utf8' });
|
|
46
|
+
const exit = r.status ?? 1;
|
|
47
|
+
const out = (r.stdout ?? '').replace(/\n?$/, '\n');
|
|
48
|
+
writeFileSync(join(root, report), `$ ${cmd}\n${out}exit ${exit}\n`);
|
|
49
|
+
runs.push({ gate: name, cmd, exit, report });
|
|
50
|
+
if (exit !== 0)
|
|
51
|
+
failed = true;
|
|
52
|
+
}
|
|
53
|
+
return { runs };
|
|
54
|
+
}
|