@bluenyang/reins 0.3.3 → 0.3.4-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 +2 -2
- package/cli/dist/commands/config-gates.js +30 -19
- package/cli/dist/commands/config.js +21 -1
- package/cli/dist/commands/configure.js +77 -44
- package/cli/dist/commands/install.js +121 -11
- package/cli/dist/commands/update.js +57 -15
- package/cli/dist/lib/agents-md.js +1 -1
- package/cli/dist/lib/detect-ci.js +74 -0
- package/cli/dist/lib/detect-workspaces.js +266 -0
- package/cli/dist/lib/detect.js +367 -81
- package/cli/dist/lib/gate-refresh.js +124 -69
- package/cli/dist/lib/gate-script.js +119 -9
- package/cli/dist/lib/generate.js +37 -11
- package/cli/dist/lib/local-settings.js +88 -0
- package/cli/dist/reins.js +11 -13
- package/docs/README.ko.md +2 -2
- package/harness/CHANGELOG.md +11 -0
- package/harness/VERSION +1 -1
- package/harness/schemas/bindings.schema.json +4 -0
- package/harness/templates/agents-md-blocks.md +1 -1
- package/package.json +1 -1
- package/skills/audit/SKILL.md +2 -2
- package/skills/implement/SKILL.md +2 -2
- package/skills/intent/SKILL.md +2 -2
- package/skills/merge/SKILL.md +2 -2
- package/skills/onboard/SKILL.md +1 -1
- package/skills/reins-setup/SKILL.md +4 -4
- package/skills/release/SKILL.md +2 -2
- package/skills/retro/SKILL.md +1 -1
- package/skills/review/SKILL.md +2 -2
- package/skills/roadmap/SKILL.md +1 -1
- package/skills/spec/SKILL.md +2 -2
- package/skills/test/SKILL.md +2 -2
|
@@ -1,82 +1,137 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { REASON } from './detect.js';
|
|
4
|
+
import { forwards, workspacePackages } from './detect-workspaces.js';
|
|
5
|
+
/** `<path>#x` and `<path>:x` are one source (the old notation, 024 S-11). */
|
|
6
|
+
const normal = (from) => from.replace(/#(?!scripts\.)/, ':');
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* another script); what is left of the discovery is `new`, and of the file `gone`. A gate without `from`
|
|
9
|
-
* is the user's own: it is listed and never paired, changed or removed.
|
|
8
|
+
* Whether the script or target a `from` points at is really there (024 S-11): a package.json script,
|
|
9
|
+
* a Makefile target, a go.mod, a workflow file. A source of another kind reads as there.
|
|
10
10
|
*/
|
|
11
|
-
export function
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
export function sourceThere(root, from) {
|
|
12
|
+
const f = normal(from);
|
|
13
|
+
const pkg = /^(.*package\.json)#scripts\.(.+)$/.exec(f);
|
|
14
|
+
if (pkg) {
|
|
15
|
+
try {
|
|
16
|
+
const s = JSON.parse(readFileSync(join(root, pkg[1]), 'utf8'))
|
|
17
|
+
.scripts;
|
|
18
|
+
return !!s && pkg[2] in s;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const mk = /^(.*Makefile):(.+)$/.exec(f);
|
|
25
|
+
if (mk) {
|
|
26
|
+
try {
|
|
27
|
+
return new RegExp(`^${mk[2].replace(/[.+?^${}()|[\]\\]/g, '\\$&')}\\s*:(?!=)`, 'm').test(readFileSync(join(root, mk[1]), 'utf8'));
|
|
25
28
|
}
|
|
26
|
-
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (/(^|\/)go\.mod$/.test(f) || f.startsWith('.github/workflows/'))
|
|
34
|
+
return existsSync(join(root, f));
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
const pieceWords = (cmd) => cmd.trim().split(/\s+/);
|
|
38
|
+
/**
|
|
39
|
+
* Pair the gates of the file with the candidates (024 S-11): the same command is the same gate whatever
|
|
40
|
+
* the source; then the same source. A gate's own command may run candidates through the workspace
|
|
41
|
+
* (`pnpm -r test`): those read `not applied, already runs`. Excluded candidates are not listed.
|
|
42
|
+
*/
|
|
43
|
+
export function gateStatus(root, file, candidates) {
|
|
44
|
+
let left = candidates.filter((c) => c.status !== 'excluded');
|
|
45
|
+
const take = (match) => {
|
|
46
|
+
const c = left.find(match);
|
|
47
|
+
if (c)
|
|
48
|
+
left = left.filter((x) => x !== c);
|
|
49
|
+
return c;
|
|
50
|
+
};
|
|
51
|
+
const rows = [];
|
|
52
|
+
// pairing in passes over every gate, so a looser match never takes a candidate a later gate has by
|
|
53
|
+
// command (review 1): the same command; then the same source and name, the same source and script
|
|
54
|
+
// (two go gates share one go.mod), the same source; then, with a source, the same name (the root
|
|
55
|
+
// `check` that now points at another script; 021, 024 A-7)
|
|
56
|
+
const pair = new Map();
|
|
57
|
+
const pass = (match, withSource = false) => {
|
|
58
|
+
for (const g of file)
|
|
59
|
+
if (!pair.has(g) && (!withSource || g.from)) {
|
|
60
|
+
const c = take((x) => match(g, x));
|
|
61
|
+
if (c)
|
|
62
|
+
pair.set(g, c);
|
|
63
|
+
}
|
|
27
64
|
};
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
65
|
+
const same = (g, c) => normal(c.from) === normal(g.from);
|
|
66
|
+
const scriptOf = (cmd) => cmd.split(' ').find((w) => ['test', 'vet', 'build', 'check', 'lint'].includes(w));
|
|
67
|
+
pass((g, c) => c.cmd === g.cmd);
|
|
68
|
+
pass((g, c) => same(g, c) && c.name === g.name, true);
|
|
69
|
+
pass((g, c) => same(g, c) && c.script === scriptOf(g.cmd), true);
|
|
70
|
+
pass(same, true);
|
|
71
|
+
pass((g, c) => c.name === g.name, true);
|
|
72
|
+
for (const g of file) {
|
|
73
|
+
const c = pair.get(g);
|
|
74
|
+
const base = {
|
|
75
|
+
name: g.name,
|
|
76
|
+
cmd: g.cmd,
|
|
77
|
+
...(g.from ? { from: g.from } : {}),
|
|
78
|
+
...(g.optional ? { optional: true } : {}),
|
|
79
|
+
reasons: c ? c.reasons.filter((r) => !r.startsWith('unclear')) : [],
|
|
80
|
+
};
|
|
81
|
+
if (!g.from)
|
|
82
|
+
rows.push({ ...base, state: 'applied, written by hand' });
|
|
83
|
+
else if (c && c.cmd !== g.cmd)
|
|
84
|
+
rows.push({
|
|
85
|
+
...base,
|
|
86
|
+
state: 'applied, another command',
|
|
87
|
+
found: { cmd: c.cmd, from: c.from },
|
|
88
|
+
});
|
|
89
|
+
else if (!c && !sourceThere(root, g.from))
|
|
90
|
+
rows.push({ ...base, state: 'applied, source not found' });
|
|
91
|
+
else
|
|
92
|
+
rows.push({ ...base, state: 'applied' });
|
|
93
|
+
}
|
|
94
|
+
// a gate that runs workspace packages already runs their candidates
|
|
95
|
+
const pkgs = workspacePackages(root);
|
|
96
|
+
const by = new Map();
|
|
97
|
+
if (pkgs.length)
|
|
98
|
+
for (const g of file) {
|
|
99
|
+
const f = forwards(pieceWords(g.cmd), pkgs);
|
|
100
|
+
if (!f || 'unclear' in f)
|
|
101
|
+
continue;
|
|
102
|
+
for (const c of left)
|
|
103
|
+
if (c.source === 'npm' &&
|
|
104
|
+
f.pkgs.some((p) => p.dir === c.dir) &&
|
|
105
|
+
f.scripts.includes(c.script))
|
|
106
|
+
by.set(c, [...(by.get(c) ?? []), REASON.runs(g.name, g.cmd)]);
|
|
107
|
+
}
|
|
38
108
|
const taken = new Set(file.map((g) => g.name));
|
|
39
|
-
for (const
|
|
40
|
-
let name =
|
|
109
|
+
for (const c of left) {
|
|
110
|
+
let name = c.name;
|
|
41
111
|
for (let i = 2; taken.has(name); i++)
|
|
42
|
-
name = `${
|
|
112
|
+
name = `${c.name}-${i}`;
|
|
43
113
|
taken.add(name);
|
|
44
|
-
|
|
45
|
-
|
|
114
|
+
const extra = by.get(c) ?? [];
|
|
115
|
+
rows.push({
|
|
116
|
+
state: c.status === 'covered' || extra.length ? 'not applied, already runs' : 'not applied',
|
|
46
117
|
name,
|
|
47
|
-
cmd:
|
|
48
|
-
from:
|
|
49
|
-
...(
|
|
118
|
+
cmd: c.cmd,
|
|
119
|
+
from: c.from,
|
|
120
|
+
...(c.optional ? { optional: true } : {}),
|
|
121
|
+
reasons: [...c.reasons, ...extra.filter((r) => !c.reasons.includes(r))],
|
|
50
122
|
});
|
|
51
123
|
}
|
|
52
|
-
|
|
53
|
-
out.push({
|
|
54
|
-
kind: 'gone',
|
|
55
|
-
name: f.name,
|
|
56
|
-
cmd: f.cmd,
|
|
57
|
-
from: f.from,
|
|
58
|
-
why: existsSync(join(root, sourceFile(f.from)))
|
|
59
|
-
? 'no longer proposed: its script or target is gone, or another gate now covers it'
|
|
60
|
-
: `its source is gone (${sourceFile(f.from)})`,
|
|
61
|
-
});
|
|
62
|
-
for (const g of file.filter((x) => !x.from))
|
|
63
|
-
out.push({ kind: 'yours', name: g.name, cmd: g.cmd });
|
|
64
|
-
const order = { changed: 0, gone: 1, new: 2, yours: 3 };
|
|
65
|
-
return out.toSorted((a, b) => order[a.kind] - order[b.kind]);
|
|
124
|
+
return rows;
|
|
66
125
|
}
|
|
67
|
-
/** The
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return `${tag}${d.name} ${d.cmd} (${d.from}) — ${d.why}`;
|
|
79
|
-
default:
|
|
80
|
-
return `${tag}${d.name} ${d.cmd} (written by hand — left alone)`;
|
|
81
|
-
}
|
|
126
|
+
/** The actions a row offers (024 S-13): add for a candidate, remove for a gate, replace for another command. */
|
|
127
|
+
export function actionsOf(row) {
|
|
128
|
+
if (row.state.startsWith('not applied'))
|
|
129
|
+
return ['add'];
|
|
130
|
+
return row.state === 'applied, another command' ? ['replace', 'remove'] : ['remove'];
|
|
131
|
+
}
|
|
132
|
+
/** One line per row, for the report, the screen and `.loctx/gates-refresh.md`. */
|
|
133
|
+
export function formatGateRow(r) {
|
|
134
|
+
const cmd = r.found ? `${r.cmd} → ${r.found.cmd}` : r.cmd;
|
|
135
|
+
const why = r.reasons.length ? ` — ${r.reasons.join('; ')}` : '';
|
|
136
|
+
return `${r.state.padEnd(27)} ${r.name} ${cmd}${r.from ? ` (${r.from})` : ''}${r.optional ? ' optional' : ''}${why}`;
|
|
82
137
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { parse } from 'yaml';
|
|
2
2
|
/**
|
|
3
|
-
* The project's gate script (design §6): one POSIX shell file that
|
|
4
|
-
*
|
|
5
|
-
* whether a commit passed. reins writes it; nothing in it calls reins or the network.
|
|
3
|
+
* The project's gate script (design §6): one POSIX shell file that reads `gates.yaml` when it runs, runs
|
|
4
|
+
* its required commands in order and keeps their output, so a hook tool needs one line and the audit can
|
|
5
|
+
* tell whether a commit passed. reins writes it; nothing in it calls reins or the network (024 S-15).
|
|
6
6
|
*/
|
|
7
7
|
export const GATE_SCRIPT = '.agents/harness/run-gates.sh';
|
|
8
8
|
/** Where the script keeps its logs: one file per tree hash of what was checked. */
|
|
@@ -20,14 +20,110 @@ export function requiredGates(text) {
|
|
|
20
20
|
.filter((x) => !!x?.cmd && !x.optional)
|
|
21
21
|
.map((x) => x.cmd);
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Reads the shape of `gates.yaml` that reins writes (024 S-16) with POSIX awk and prints the required
|
|
25
|
+
* commands, one per line, in order: `order` when it is there (names not in `gates` are skipped, gates
|
|
26
|
+
* not in `order` do not run), else the order of `gates`; `optional: true` is skipped. On any other shape
|
|
27
|
+
* inside `gates:` or `order:` it prints `line <n>: <reason>` and exits 3.
|
|
28
|
+
*/
|
|
29
|
+
const AWK = String.raw `
|
|
30
|
+
function fail(why) { print "line " NR ": " why; bad = 1; exit 3 }
|
|
31
|
+
function rest(r) {
|
|
32
|
+
sub(/^ +/, "", r)
|
|
33
|
+
if (r != "" && substr(r, 1, 1) != "#") fail("text after a quoted value")
|
|
34
|
+
}
|
|
35
|
+
function value(v, out, c, i, n) {
|
|
36
|
+
sub(/^ +/, "", v)
|
|
37
|
+
if (v == "") return ""
|
|
38
|
+
c = substr(v, 1, 1)
|
|
39
|
+
if (c == "|" || c == ">") fail("a multi-line value")
|
|
40
|
+
if (c == "&" || c == "*") fail("an anchor or alias")
|
|
41
|
+
if (c == "{" || c == "[") fail("flow style")
|
|
42
|
+
if (c == "'") {
|
|
43
|
+
out = ""; n = length(v)
|
|
44
|
+
for (i = 2; i <= n; i++) {
|
|
45
|
+
c = substr(v, i, 1)
|
|
46
|
+
if (c == "'") {
|
|
47
|
+
if (substr(v, i + 1, 1) == "'") { out = out "'"; i++; continue }
|
|
48
|
+
rest(substr(v, i + 1)); return out
|
|
49
|
+
}
|
|
50
|
+
out = out c
|
|
51
|
+
}
|
|
52
|
+
fail("an unclosed quote")
|
|
53
|
+
}
|
|
54
|
+
if (c == "\"") {
|
|
55
|
+
out = ""; n = length(v)
|
|
56
|
+
for (i = 2; i <= n; i++) {
|
|
57
|
+
c = substr(v, i, 1)
|
|
58
|
+
if (c == "\\") {
|
|
59
|
+
c = substr(v, i + 1, 1)
|
|
60
|
+
if (c != "\"" && c != "\\") fail("an escape other than a quote or a backslash")
|
|
61
|
+
out = out c; i++; continue
|
|
62
|
+
}
|
|
63
|
+
if (c == "\"") { rest(substr(v, i + 1)); return out }
|
|
64
|
+
out = out c
|
|
65
|
+
}
|
|
66
|
+
fail("an unclosed quote")
|
|
67
|
+
}
|
|
68
|
+
if (match(v, / #/)) v = substr(v, 1, RSTART - 1)
|
|
69
|
+
sub(/ +$/, "", v)
|
|
70
|
+
return v
|
|
71
|
+
}
|
|
72
|
+
function word(v) { sub(/^ +/, "", v); sub(/ +#.*$/, "", v); sub(/ +$/, "", v); return v }
|
|
73
|
+
{ sub(/\r$/, "") }
|
|
74
|
+
/^[ \t]*$/ || /^[ \t]*#/ { next }
|
|
75
|
+
/^\t/ || /^ +\t/ { if (sec == "gates" || sec == "order") fail("a tab in the indentation"); next }
|
|
76
|
+
/^[^ ]/ {
|
|
77
|
+
sec = $0; sub(/:.*/, "", sec)
|
|
78
|
+
if (sec == "gates") hasGates = 1
|
|
79
|
+
if (sec == "order") hasOrder = 1
|
|
80
|
+
if (sec == "gates" || sec == "order") {
|
|
81
|
+
t = $0; sub(/^[^:]*:/, "", t); t = word(t)
|
|
82
|
+
# the empty collections written for no gate (gates: {}, order: []) are read; other flow style is not
|
|
83
|
+
if ((t == "{}" && sec == "gates") || (t == "[]" && sec == "order")) { sec = ""; next }
|
|
84
|
+
if (t != "") fail("flow style")
|
|
85
|
+
}
|
|
86
|
+
next
|
|
87
|
+
}
|
|
88
|
+
sec == "gates" && /^ [^ ]/ {
|
|
89
|
+
if (!match($0, /^ [^ :]+:/)) fail("a gate that is not a name")
|
|
90
|
+
name = substr($0, 3, RLENGTH - 3)
|
|
91
|
+
if (word(substr($0, RLENGTH + 1)) != "") fail("flow style")
|
|
92
|
+
if (name in seen) fail("the gate " name " twice")
|
|
93
|
+
seen[name] = 1; names[++count] = name
|
|
94
|
+
next
|
|
95
|
+
}
|
|
96
|
+
sec == "gates" && /^ [^ ]/ {
|
|
97
|
+
if (name == "") fail("a key outside a gate")
|
|
98
|
+
key = $0; sub(/^ +/, "", key); sub(/:.*/, "", key)
|
|
99
|
+
t = $0; sub(/^ *[^:]*:/, "", t)
|
|
100
|
+
if (key == "cmd") { cmd[name] = value(t); if (cmd[name] == "") fail("an empty cmd") }
|
|
101
|
+
else if (key == "optional") { if (word(t) == "true") opt[name] = 1 }
|
|
102
|
+
else value(t)
|
|
103
|
+
next
|
|
104
|
+
}
|
|
105
|
+
sec == "gates" { fail("a multi-line value") }
|
|
106
|
+
sec == "order" && /^ - / { o = $0; sub(/^ - +/, "", o); order[++ocount] = word(o); next }
|
|
107
|
+
sec == "order" { fail("an order entry that is not a list item") }
|
|
108
|
+
END {
|
|
109
|
+
if (bad) exit 3
|
|
110
|
+
# an empty or unrelated file is no gates.yaml: it must not pass without checks
|
|
111
|
+
if (!hasGates) { print "line " NR ": no gates section"; exit 3 }
|
|
112
|
+
for (k = 1; k <= count; k++) if (!(names[k] in cmd)) { print "the gate " names[k] " has no cmd"; exit 3 }
|
|
113
|
+
# order present, even empty, decides: order: [] runs nothing
|
|
114
|
+
if (hasOrder) { for (k = 1; k <= ocount; k++) if ((order[k] in seen) && !(order[k] in opt)) print cmd[order[k]] }
|
|
115
|
+
else for (k = 1; k <= count; k++) if (!(names[k] in opt)) print cmd[names[k]]
|
|
116
|
+
}
|
|
117
|
+
`;
|
|
23
118
|
const quote = (s) => `'${s.replaceAll("'", `'\\''`)}'`;
|
|
24
|
-
/** The script
|
|
25
|
-
export function renderGateScript(
|
|
119
|
+
/** The script. It holds no command: it reads gates.yaml every time it runs (024 S-15–S-17). */
|
|
120
|
+
export function renderGateScript() {
|
|
26
121
|
return `#!/bin/sh
|
|
27
|
-
# generated by reins
|
|
122
|
+
# generated by reins — do not edit; \`reins update\` rewrites it. The gates are in .agents/harness/gates.yaml.
|
|
28
123
|
#
|
|
29
|
-
#
|
|
30
|
-
# where <tree> is the tree hash of what is checked: \`git rev-parse <commit>^{tree}\`
|
|
124
|
+
# Reads .agents/harness/gates.yaml, runs its required checks in order and keeps their output in
|
|
125
|
+
# ${GATE_LOGS}/<tree>.log, where <tree> is the tree hash of what is checked: \`git rev-parse <commit>^{tree}\`
|
|
126
|
+
# names a commit's log. gates.yaml is read in the shape reins writes; another shape stops the run (exit 2).
|
|
31
127
|
# Usage: sh ${GATE_SCRIPT} <stage> (pre-commit, pre-push, audit, or any name of your own)
|
|
32
128
|
stage="\${1:-manual}"
|
|
33
129
|
root=$(git rev-parse --show-toplevel 2>/dev/null) || {
|
|
@@ -57,6 +153,14 @@ mkdir -p "$dir" || exit 2
|
|
|
57
153
|
log="$dir/$tree.log"
|
|
58
154
|
status="$dir/.status.$$"
|
|
59
155
|
printf '== %s stage: %s worktree: %s\\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$stage" "$worktree" >>"$log"
|
|
156
|
+
stop() {
|
|
157
|
+
echo "run-gates: $1" >&2
|
|
158
|
+
printf 'run-gates: %s\\nexit: 2\\n' "$1" >>"$log"
|
|
159
|
+
exit 2
|
|
160
|
+
}
|
|
161
|
+
gates=.agents/harness/gates.yaml
|
|
162
|
+
[ -f "$gates" ] || stop "no $gates: nothing is checked without it"
|
|
163
|
+
cmds=$(awk ${quote(AWK)} "$gates") || stop "$gates $cmds"
|
|
60
164
|
code=0
|
|
61
165
|
run() {
|
|
62
166
|
[ "$code" -eq 0 ] || return 0
|
|
@@ -70,7 +174,13 @@ run() {
|
|
|
70
174
|
# output that did not end its last line must not run into the next record
|
|
71
175
|
if [ -n "$(tail -c 1 "$log")" ]; then echo >>"$log"; fi
|
|
72
176
|
}
|
|
73
|
-
$
|
|
177
|
+
if [ -z "$cmds" ]; then echo "no required gate" >>"$log"; fi
|
|
178
|
+
# the commands come on fd 3, so a gate still reads the hook's own stdin
|
|
179
|
+
while IFS= read -r c <&3; do
|
|
180
|
+
if [ -n "$c" ]; then run "$c"; fi
|
|
181
|
+
done 3<<GATES
|
|
182
|
+
$cmds
|
|
183
|
+
GATES
|
|
74
184
|
printf 'exit: %s\\n' "$code" >>"$log"
|
|
75
185
|
exit "$code"
|
|
76
186
|
`;
|
package/cli/dist/lib/generate.js
CHANGED
|
@@ -4,7 +4,7 @@ import { workTreeReader } from './reader.js';
|
|
|
4
4
|
import { resolveRoles } from './bindings.js';
|
|
5
5
|
import { agentName, claudeAgents } from './agents-md.js';
|
|
6
6
|
import { splitFrontmatter } from './skills.js';
|
|
7
|
-
import { GATE_SCRIPT, renderGateScript
|
|
7
|
+
import { GATE_SCRIPT, renderGateScript } from './gate-script.js';
|
|
8
8
|
/**
|
|
9
9
|
* Files generated from `.agents/harness/` (design §6): `.claude/agents/rs-<group>-<role>.md` for roles
|
|
10
10
|
* switched on in multi mode on a Claude model, the `.claude/skills/` copy, `.claude/settings.json` deny
|
|
@@ -63,6 +63,34 @@ export function claudeAgent(g, role, model, version, name = agentName(g.group, r
|
|
|
63
63
|
'',
|
|
64
64
|
].join('\n');
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* The force-push rules of the team settings (024 revision 1): `--force`, `-f`, a `+` refspec and hook bypass
|
|
68
|
+
* (also after other arguments). `--force-with-lease` is not here: each person decides it in the personal
|
|
69
|
+
* `.claude/settings.local.json` (local-settings.ts), since a team deny could not be lifted per person.
|
|
70
|
+
* A command-string glob: `git -C`, variables and aliases get past it (design §6).
|
|
71
|
+
*/
|
|
72
|
+
export function forcePushRules() {
|
|
73
|
+
return [
|
|
74
|
+
'Bash(git push --force *)',
|
|
75
|
+
'Bash(git push -f *)',
|
|
76
|
+
// the flag after other arguments too (review 6)
|
|
77
|
+
'Bash(git push * --force)',
|
|
78
|
+
'Bash(git push * --force *)',
|
|
79
|
+
'Bash(git push * -f)',
|
|
80
|
+
'Bash(git push * -f *)',
|
|
81
|
+
'Bash(git push * +*)',
|
|
82
|
+
'Bash(git push *:+*)',
|
|
83
|
+
'Bash(git commit --no-verify *)',
|
|
84
|
+
'Bash(git commit -n *)',
|
|
85
|
+
'Bash(git push --no-verify *)',
|
|
86
|
+
'Bash(git push * --no-verify)',
|
|
87
|
+
'Bash(git push * --no-verify *)',
|
|
88
|
+
'Bash(git commit * --no-verify)',
|
|
89
|
+
'Bash(git commit * --no-verify *)',
|
|
90
|
+
'Bash(git commit * -n)',
|
|
91
|
+
'Bash(git commit * -n *)',
|
|
92
|
+
];
|
|
93
|
+
}
|
|
66
94
|
/** C4 patterns → Claude Code deny rules. A pattern that would also hide an allowed template (`.env.*` vs `.env.example`) is narrowed. */
|
|
67
95
|
export function denyRules(lines) {
|
|
68
96
|
const c4 = lines.find((r) => r.id === 'C4');
|
|
@@ -85,8 +113,8 @@ export function denyRules(lines) {
|
|
|
85
113
|
for (const g of globs)
|
|
86
114
|
for (const t of ['Read', 'Edit'])
|
|
87
115
|
rules.push(`${t}(${g.startsWith('**/') ? g : `**/${g}`})`);
|
|
88
|
-
// force push and hook bypass: the user runs these
|
|
89
|
-
rules.push(
|
|
116
|
+
// force push and hook bypass: the user runs these, never an agent (force-with-lease: per person)
|
|
117
|
+
rules.push(...forcePushRules());
|
|
90
118
|
return rules;
|
|
91
119
|
}
|
|
92
120
|
/** Everything the generator owns, computed from the installed harness. Pure. */
|
|
@@ -138,14 +166,12 @@ export function generateVendorFiles(root, rd = workTreeReader(root)) {
|
|
|
138
166
|
why: `skill ${name}`,
|
|
139
167
|
});
|
|
140
168
|
}
|
|
141
|
-
// the gate script
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
why: 'the project gates, with their output kept',
|
|
148
|
-
});
|
|
169
|
+
// the gate script reads gates.yaml when it runs: one text, written with or without a required gate (024 S-17)
|
|
170
|
+
out.writes.push({
|
|
171
|
+
path: GATE_SCRIPT,
|
|
172
|
+
content: renderGateScript(),
|
|
173
|
+
why: 'the project gates, with their output kept',
|
|
174
|
+
});
|
|
149
175
|
const redText = rd.read(`${harness}/policy/common-red-lines.yaml`);
|
|
150
176
|
if (redText !== undefined) {
|
|
151
177
|
const deny = denyRules(parse(redText).rules);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { parse, stringify } from 'yaml';
|
|
4
|
+
import { LOCAL_BINDINGS, readLocalBindings, writeBindings } from './bindings.js';
|
|
5
|
+
import { mergeSettings } from './vendor-write.js';
|
|
6
|
+
/**
|
|
7
|
+
* Force push with lease, per person (024 revision 1, S-26a). The team's `.claude/settings.json` does not
|
|
8
|
+
* deny it; each person decides at install, update or `config --local`, and reins writes the answer into
|
|
9
|
+
* the personal, git-ignored `.claude/settings.local.json`. Claude Code lets a deny anywhere win over an
|
|
10
|
+
* allow anywhere, so a team deny could not be lifted per person.
|
|
11
|
+
*/
|
|
12
|
+
export const LOCAL_SETTINGS = '.claude/settings.local.json';
|
|
13
|
+
/** The rules reins puts into the personal file when the answer is deny. */
|
|
14
|
+
export const FORCE_WITH_LEASE_RULES = [
|
|
15
|
+
'Bash(git push --force-with-lease)',
|
|
16
|
+
'Bash(git push --force-with-lease *)',
|
|
17
|
+
];
|
|
18
|
+
/** Which rules of the personal file reins wrote (never the team's `generated.yaml`: the file is personal). */
|
|
19
|
+
export const LOCAL_SETTINGS_OWNED = '.loctx/settings.local.owned.yaml';
|
|
20
|
+
/** The answer recorded in `.loctx/bindings.local.yaml` (`local.force_with_lease`), if any. */
|
|
21
|
+
export function recordedForceWithLease(root) {
|
|
22
|
+
const v = readLocalBindings(root)?.local?.force_with_lease;
|
|
23
|
+
return v === 'deny' || v === 'allow' ? v : undefined;
|
|
24
|
+
}
|
|
25
|
+
/** The question install, update and `config --local` ask. */
|
|
26
|
+
export const FORCE_WITH_LEASE_QUESTION = 'Deny `git push --force-with-lease` to the agents on this machine? (written to .claude/settings.local.json; the team settings do not deny it)';
|
|
27
|
+
/** The string deny rules of a settings text; empty when it has none or cannot be read. */
|
|
28
|
+
function denyOf(text) {
|
|
29
|
+
try {
|
|
30
|
+
const d = JSON.parse(text)?.permissions?.deny;
|
|
31
|
+
return Array.isArray(d) ? d.filter((r) => typeof r === 'string') : [];
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function readOwned(root) {
|
|
38
|
+
const p = join(root, LOCAL_SETTINGS_OWNED);
|
|
39
|
+
if (!existsSync(p))
|
|
40
|
+
return [];
|
|
41
|
+
const doc = parse(readFileSync(p, 'utf8'));
|
|
42
|
+
return Array.isArray(doc?.owned)
|
|
43
|
+
? doc.owned.filter((r) => typeof r === 'string')
|
|
44
|
+
: [];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Record the answer and bring `.claude/settings.local.json` in line with it (S-26a): on deny the two rules
|
|
48
|
+
* are added where missing; on allow only the rules reins wrote are taken out. Every other key and entry of
|
|
49
|
+
* the file stays as the person has it. A file that is not a settings object is left alone and named.
|
|
50
|
+
*/
|
|
51
|
+
export function applyLocalForcePush(root, choice, dryRun = false,
|
|
52
|
+
/** an answer the person gave; the non-interactive default is applied but not recorded, so a terminal run still asks */
|
|
53
|
+
answered = true) {
|
|
54
|
+
const path = join(root, LOCAL_SETTINGS);
|
|
55
|
+
const was = readOwned(root);
|
|
56
|
+
const now = choice === 'deny' ? FORCE_WITH_LEASE_RULES : [];
|
|
57
|
+
const before = existsSync(path) ? readFileSync(path, 'utf8') : null;
|
|
58
|
+
const how = choice === 'deny'
|
|
59
|
+
? `force push with lease: denied to the agents on this machine (${LOCAL_SETTINGS}; \`reins config --local\` changes it)`
|
|
60
|
+
: `force push with lease: not denied on this machine (\`reins config --local\` changes it)`;
|
|
61
|
+
// allow and nothing of ours there: no file to make
|
|
62
|
+
// reins owns only what it wrote: a rule the person had already is left theirs (review 6)
|
|
63
|
+
const present = before === null ? [] : denyOf(before);
|
|
64
|
+
const owned = now.filter((r) => was.includes(r) || !present.includes(r));
|
|
65
|
+
const next = before === null && now.length === 0 ? null : mergeSettings(before ?? '{}', now, was);
|
|
66
|
+
if (before !== null && next === null)
|
|
67
|
+
return {
|
|
68
|
+
choice,
|
|
69
|
+
file: 'refused',
|
|
70
|
+
note: `${LOCAL_SETTINGS} is not a settings object — not changed; force push with lease is ${choice === 'deny' ? 'not denied there yet' : 'left as the file has it'}`,
|
|
71
|
+
};
|
|
72
|
+
if (dryRun)
|
|
73
|
+
return { choice, file: next !== null && next !== before ? 'written' : 'unchanged', note: how };
|
|
74
|
+
if (answered && recordedForceWithLease(root) !== choice) {
|
|
75
|
+
const doc = readLocalBindings(root) ?? {};
|
|
76
|
+
writeBindings(root, { ...doc, local: { ...doc.local, force_with_lease: choice } }, 'local');
|
|
77
|
+
}
|
|
78
|
+
const p = join(root, LOCAL_SETTINGS_OWNED);
|
|
79
|
+
mkdirSync(dirname(p), { recursive: true });
|
|
80
|
+
writeFileSync(p, `# the deny rules reins wrote into ${LOCAL_SETTINGS} — this machine only\n${stringify({ owned })}`);
|
|
81
|
+
if (next === null || next === before)
|
|
82
|
+
return { choice, file: 'unchanged', note: how };
|
|
83
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
84
|
+
writeFileSync(path, next);
|
|
85
|
+
return { choice, file: 'written', note: how };
|
|
86
|
+
}
|
|
87
|
+
/** Where the answer is kept, for the report. */
|
|
88
|
+
export const FORCE_WITH_LEASE_RECORD = LOCAL_BINDINGS;
|
package/cli/dist/reins.js
CHANGED
|
@@ -4,9 +4,9 @@ import { Command } from 'commander';
|
|
|
4
4
|
import { runInstall } from './commands/install.js';
|
|
5
5
|
import { runMigrate } from './commands/migrate.js';
|
|
6
6
|
import { formatUpdate, runUpdate } from './commands/update.js';
|
|
7
|
-
import { configureBindings, configureGates, formatGenerated } from './commands/configure.js';
|
|
7
|
+
import { configureBindings, configureGates, formatGenerated, REFRESH_LIST, } from './commands/configure.js';
|
|
8
8
|
import { refreshGates } from './commands/config-gates.js';
|
|
9
|
-
import {
|
|
9
|
+
import { formatGateRow } from './lib/gate-refresh.js';
|
|
10
10
|
import { NotARepository, repoRoot } from './lib/git.js';
|
|
11
11
|
import { LOCAL_DELEGATION_NOTE } from './lib/local-delegation.js';
|
|
12
12
|
import { formatBindings, runConfig } from './commands/config.js';
|
|
@@ -207,10 +207,10 @@ config
|
|
|
207
207
|
});
|
|
208
208
|
config
|
|
209
209
|
.command('gates')
|
|
210
|
-
.description('the project gates: --add <name>… appends
|
|
210
|
+
.description('the project gates: --add <name>… appends offered candidates; --refresh finds the gates again and shows each gate and candidate with its state')
|
|
211
211
|
.option('--add <names...>', 'proposal names to append after the existing gates')
|
|
212
|
-
.option('--refresh', 'run the discovery
|
|
213
|
-
.option('--apply <names...>', 'with --refresh:
|
|
212
|
+
.option('--refresh', 'run the discovery again and show every gate and candidate with its state (also in .loctx/gates-refresh.md)')
|
|
213
|
+
.option('--apply <names...>', 'with --refresh: rows to act on by name (a candidate is added, a gate with another command gets it, a gate is removed), remove:<name>, or `all` (adds every candidate not applied)')
|
|
214
214
|
.option('--json')
|
|
215
215
|
.action(async (o) => {
|
|
216
216
|
const refresh = !!o.refresh || !!o.apply;
|
|
@@ -229,15 +229,13 @@ config
|
|
|
229
229
|
process.exit(r.code ?? 2);
|
|
230
230
|
}
|
|
231
231
|
if (refresh) {
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (
|
|
236
|
-
process.stdout.write('
|
|
237
|
-
else if (r.applied?.length)
|
|
238
|
-
process.stdout.write(`applied: ${r.applied.join(', ')} — gates.yaml and the gate script were written\n`);
|
|
232
|
+
for (const row of r.rows ?? [])
|
|
233
|
+
process.stdout.write(`${formatGateRow(row)}\n`);
|
|
234
|
+
process.stdout.write(`(the same list: ${REFRESH_LIST})\n`);
|
|
235
|
+
if (r.applied?.length)
|
|
236
|
+
process.stdout.write(`applied: ${r.applied.join(', ')} — gates.yaml was written\n`);
|
|
239
237
|
else
|
|
240
|
-
process.stdout.write('nothing written — apply with: reins config gates --refresh --apply <name…|all>\n');
|
|
238
|
+
process.stdout.write('nothing written — apply with: reins config gates --refresh --apply <name…|all|remove:name>\n');
|
|
241
239
|
return;
|
|
242
240
|
}
|
|
243
241
|
for (const n of r.added)
|
package/docs/README.ko.md
CHANGED
|
@@ -8,7 +8,7 @@ BlueNyang과 Team Croffle의 저장소 열두 곳이 같은 하네스 계통을
|
|
|
8
8
|
|
|
9
9
|
## 상태
|
|
10
10
|
|
|
11
|
-
**0.3.
|
|
11
|
+
**0.3.4-rc.2가 릴리스 후보입니다**(intent 024): `npx @bluenyang/reins@0.3.4-rc.2`. **0.3.3이 최신 릴리스입니다**(intent 019~023): `npx @bluenyang/reins install`. 0.2.0까지는 스킬과 훅이 작업 중에 `npx @bluenyang/reins`를 불렀습니다. 0.3은 그것을 없애고, `reins update`가 0.1.x·0.2.0 설치를 옮깁니다. 버전마다 바뀐 것은 [CHANGELOG.md](../CHANGELOG.md)에, 앞으로의 계획은 [로드맵](ROADMAP.ko.md)에 있습니다.
|
|
12
12
|
|
|
13
13
|
## 동작 방식
|
|
14
14
|
|
|
@@ -48,7 +48,7 @@ reins 자체를 개발하려면 `git clone https://github.com/bluenyang/reins.gi
|
|
|
48
48
|
| `install` | 하네스를 배치하고, 에이전트 도구를 감지하고, 게이트를 확인하고, 검사 스크립트 `.agents/harness/run-gates.sh`(프로젝트 게이트 명령을 돌리고 출력을 감사용으로 남김)를 쓰고 그것을 부르는 훅 한 줄을 제안하고(`--hooks`면 husky에 넣음), 온보딩 표시를 남깁니다. `--mode manual\|auto`, `--dry-run`, `--json` |
|
|
49
49
|
| `migrate` | 이전 하네스나 `.ai/` 작업 공간을 이 배치로 옮기고, 이전 `AGENTS.md`는 PM이 합치도록 따로 둡니다. `--legacy local\|committed`, `--dry-run` |
|
|
50
50
|
| `update` | 패키지의 하네스를 다시 적용합니다. 손으로 고친 생성 파일은 덮어쓰기 전에 묻고(`--force`), 0.1.x·0.2.0 설치를 0.3으로 옮기며 옛 작업 파일을 보여 줍니다(`--yes`면 지움) |
|
|
51
|
-
| `config` | 터미널에서 화면: 모델과 역할, 에이전트 도구, 모드(single·multi), 감사. `config bindings`·`config gates`는 플래그로(`configure`는 별칭). `config gates --refresh`는 프로젝트 검사를 다시 찾아
|
|
51
|
+
| `config` | 터미널에서 화면: 모델과 역할, 에이전트 도구, 모드(single·multi), 감사. `config bindings`·`config gates`는 플래그로(`configure`는 별칭). `config gates --refresh`는 프로젝트 검사를 다시 찾아(이름과 본문, 워크스페이스, CI) 모든 게이트와 후보를 상태와 근거와 함께 보여 줍니다 — 적용됨, 적용 안 됨, 다른 것이 이미 돌림. 같은 목록을 `.loctx/gates-refresh.md`에 남기고, `gates.yaml`은 고른 대로만 바꿉니다(터미널이 아니면 `--apply <이름…|all|remove:이름>`). 게이트가 없어졌다고 판정하지 않습니다. 화면의 `gates` 항목에서도 같은 일을 합니다. 군이나 역할에 대체 모델을 적을 수 있습니다(`config bindings --fallback <군>[.<역할>]=<model>`). 첫 모델을 부를 수 없을 때 쓰도록 대체 실행 줄이 위임 표에 들어갑니다 |
|
|
52
52
|
|
|
53
53
|
## 스킬
|
|
54
54
|
|
package/harness/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Read by `reins update`: it lists the entries newer than a project's pinned version.
|
|
4
4
|
|
|
5
|
+
## 0.3.4
|
|
6
|
+
- Gate discovery finds candidates by name and body: a script with `check`, `lint`, `test`, `typecheck`, `build`, `e2e`, `verify` or `ci` as a word of its name, or `type-check` (`lint:check`, `format:check`, `check:migrations`, `test:unit`, `build:web`), Makefile targets and go.mod below the root, workspace packages (pnpm, npm, yarn 1 and berry, bun, turbo, nx, lerna) and the one-line `run:` commands of pull-request workflows. Each candidate has a state and its reasons: picked, offered, already run by another script or gate, or excluded (rewrites files, never ends, install step, platform packaging). `lint:check` is no bundle any more but a gate of its own; a gate name has `-` where the script has `:`.
|
|
7
|
+
- `reins config gates --refresh` no longer reports new, changed or gone. It shows every gate and candidate with its state — applied, applied (written by hand / source not found / another command), not applied, not applied (already runs) — and leaves the same list in `.loctx/gates-refresh.md`, so the user picks and an agent edits `gates.yaml` in a commit of its own. reins never calls a gate gone and never removes one by itself; `--apply all` only adds, removing and replacing take a name.
|
|
8
|
+
- `.agents/harness/run-gates.sh` reads `gates.yaml` when it runs (POSIX `awk`, the shape reins writes) instead of holding the commands, so editing `gates.yaml` is enough. Another shape, or a missing `gates.yaml`, stops the run with exit 2 before anything runs. The script is written even without a required gate; `config gates` no longer rewrites it. `gates.yaml` is the project's file, not a generated one.
|
|
9
|
+
- Already installed repositories: run `reins config gates --refresh` once after `reins update` to see the candidates the new discovery finds; `update` does not change `gates.yaml`.
|
|
10
|
+
- husky: a hook file that already runs the gate script outside a reins block is neither proposed nor given a block again. lefthook and pre-commit (rc.2): a stage whose configuration already runs the gate script is not proposed again.
|
|
11
|
+
- Force push (revision 1): the team `.claude/settings.json` no longer denies `--force-with-lease` (a team deny cannot be lifted for one person, and a glob cannot tell a work branch from the default branch). `install` and `update` ask on a terminal whether to deny it to the agents on this machine; the answer is kept in `.loctx/bindings.local.yaml` and written to the personal `.claude/settings.local.json` (`Bash(git push --force-with-lease)`, `Bash(git push --force-with-lease *)`); `reins config` changes it. Without a terminal it is denied and the next terminal run asks. `--force`, `-f`, a `+` refspec and hook bypass, each also after other arguments, stay denied for everyone. The `merge` skill says to push a work branch naming it, never the default branch or a tag; the stop block names force push to the default branch or a tag.
|
|
12
|
+
- Skills (0.3.3 retro): open `.loctx/delegation.local.md` before anything else when work starts (`intent`, `implement`, the delegation block); `git diff --stat` at the head of a review request, checked against the diff received (`review`); keep the request to another model and its final answer in `.loctx/reports/<version>/` as they came (every skill that calls one); compare the two language editions again after the last change (`review`, `test`); read both roadmaps and the review records when revising a spec (`spec`); rate each violation's severity and put independent opinions beside a high one's remedy (`audit`).
|
|
13
|
+
- `update` lists these entries under a heading per version.
|
|
14
|
+
|
|
5
15
|
## 0.3.3
|
|
16
|
+
- Stable 2026-11-17 (same harness as rc.1).
|
|
6
17
|
- Gate discovery: the root `typecheck` and `lint` scripts become gate candidates in `reins install` and `reins config gates --refresh`, unless the chosen bundle check already calls them (by name, or an identical command). Only a command that runs the script counts; recursive, filtered, other-directory and task-runner calls (`pnpm -r`, `--filter`, `--dir`, `turbo`, `nx`, `lerna`), a command with any option and a mere mention (`echo lint`) do not; a script that rewrites files is left out. Order: check, lint, typecheck, test, build, e2e.
|
|
7
18
|
- Already installed repositories: `reins update` does not change `gates.yaml`. Run `reins config gates --refresh` once to see the new candidates and apply the ones you want.
|
|
8
19
|
- Personal settings: a group in `.loctx/bindings.local.yaml` wins only where it speaks (a role alone keeps the team's group and its other roles; a group model replaces the team's; a fallback alone is added to the team's model instead of switching the group off; `{}` switches it off), and the `config` models screen shows the file of the chosen scope. `reins config` or `reins update` rewrites `.loctx/delegation.local.md` accordingly.
|
package/harness/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.3.
|
|
1
|
+
0.3.4
|