@lifeaitools/rdc-skills 0.37.4 → 0.37.5
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/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +23 -0
- package/clauth-plugin.json +1 -1
- package/commands/flow.md +12 -3
- package/git-sha.json +1 -1
- package/hooks/gate-watchdog-selfcheck.js +93 -5
- package/hooks/require-work-item-on-commit.js +15 -1
- package/package.json +3 -3
- package/scripts/acceptance.mjs +5 -2
- package/scripts/install-rdc-skills.js +34 -11
- package/scripts/validate-publish-manifests.js +41 -8
- package/skills/build/SKILL.md +4 -0
- package/skills/collab/SKILL.md +2 -0
- package/skills/edit/SKILL.md +8 -0
- package/skills/fixit/SKILL.md +24 -4
- package/skills/plan/SKILL.md +2 -0
- package/skills/release/SKILL.md +12 -3
- package/skills/status/SKILL.md +3 -5
- package/skills/terminal-config/SKILL.md +5 -0
- package/tests/harness-gates.test.mjs +24 -172
- package/tests/install-stale-checkout.test.mjs +42 -0
- package/tests/publish-manifest-staging-gates.test.mjs +30 -0
- package/tests/require-work-item-on-commit.test.mjs +13 -0
- package/hooks/post-tool-batch-gate.js +0 -203
- package/hooks/task-completed-gate.js +0 -274
|
@@ -58,6 +58,11 @@ rdc:terminal-config: <task>
|
|
|
58
58
|
Get-Content "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" | ConvertFrom-Json
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
+
- **A `%VAR%` in `commandline`/`startingDirectory` that does not expand has two causes; check which before editing:**
|
|
62
|
+
- **Stale inherited environment** (most common): the variable was set after `explorer.exe`, Terminal's parent, last started. Confirm it is set (`[Environment]::GetEnvironmentVariable('VAR','User')`), then `Stop-Process -Name explorer -Force` (it relaunches) and restart Windows Terminal fully — a new tab in a running instance keeps the old block.
|
|
63
|
+
- **Hardcoded path**: the config never used a variable. Only this case is fixed by editing the config.
|
|
64
|
+
- Never replace a `%VAR%` with a literal path to fix a stale environment; a restart fixes it and the literal breaks portability.
|
|
65
|
+
|
|
61
66
|
## Startup Scripts
|
|
62
67
|
|
|
63
68
|
If a project uses role/cell startup scripts, keep those scripts under the project root and commit them with the project. Do not bake one user's absolute machine paths into shared RDC skill files.
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Truth Gate 3.0 —
|
|
3
|
+
* Truth Gate 3.0 — Layer 6 harness-gate tests (WP-5).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* post-tool-batch-gate.js — flag OFF no-op; flag ON + stale worktree base FLAG;
|
|
9
|
-
* flag ON + current base PASS.
|
|
5
|
+
* Fully offline (no DB, no brain, no clauth). task-completed-gate.js and
|
|
6
|
+
* post-tool-batch-gate.js were deleted in 0.37.5 (LIFEAI/regen-root#237): both
|
|
7
|
+
* sat behind env flags nothing ever set.
|
|
10
8
|
* gate-watchdog-selfcheck — STOP-banner when a gate file/registration absent;
|
|
11
9
|
* silent when all present; checks the LIVE hookify
|
|
12
10
|
* hooks.json (plugin manifest), not the dead wrappers.
|
|
@@ -17,7 +15,6 @@ import { mkdtempSync, rmSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
|
17
15
|
import { tmpdir } from 'node:os';
|
|
18
16
|
import { join, resolve, dirname } from 'node:path';
|
|
19
17
|
import { fileURLToPath } from 'node:url';
|
|
20
|
-
import { spawnSync } from 'node:child_process';
|
|
21
18
|
import { createRequire } from 'node:module';
|
|
22
19
|
|
|
23
20
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -31,120 +28,6 @@ function assert(name, condition, detail = '') {
|
|
|
31
28
|
else process.stdout.write(` ok ${name}\n`);
|
|
32
29
|
}
|
|
33
30
|
|
|
34
|
-
function runHook(file, payload, extraEnv = {}) {
|
|
35
|
-
return spawnSync(process.execPath, [join(HOOKS, file)], {
|
|
36
|
-
input: JSON.stringify(payload),
|
|
37
|
-
encoding: 'utf8',
|
|
38
|
-
env: { ...process.env, ...extraEnv },
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const WI = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
|
|
43
|
-
|
|
44
|
-
// ===========================================================================
|
|
45
|
-
// 1. task-completed-gate.js
|
|
46
|
-
// ===========================================================================
|
|
47
|
-
{
|
|
48
|
-
const tcg = require(join(HOOKS, 'task-completed-gate.js'));
|
|
49
|
-
|
|
50
|
-
// pure: closureIsSound branches
|
|
51
|
-
assert('TCG closureIsSound: null row → not ok', tcg.closureIsSound(null).ok === false);
|
|
52
|
-
assert('TCG closureIsSound: not-done task → not ok',
|
|
53
|
-
tcg.closureIsSound({ id: WI, item_type: 'task', status: 'review' }).ok === false);
|
|
54
|
-
assert('TCG closureIsSound: done but witness:agent → not ok',
|
|
55
|
-
tcg.closureIsSound({ id: WI, item_type: 'task', status: 'done', implementation_report: { codeflow_post: { witness: 'agent', commit: 'x', files_changed: ['f'], verification: [{ exit_code: 0 }] } } }).ok === false);
|
|
56
|
-
const soundRow = {
|
|
57
|
-
id: WI, item_type: 'task', status: 'done',
|
|
58
|
-
implementation_report: { codeflow_post: { witness: 'validator-rerun', commit: 'c3189c9d58a37d648e9de4a6bcd7d46772053eea', files_changed: ['hooks/x.js'], verification: [{ exit_code: 0 }] } },
|
|
59
|
-
};
|
|
60
|
-
assert('TCG closureIsSound: full sound closure → ok', tcg.closureIsSound(soundRow).ok === true,
|
|
61
|
-
tcg.closureIsSound(soundRow).reason || '');
|
|
62
|
-
assert('TCG closureIsSound: epic done → ok',
|
|
63
|
-
tcg.closureIsSound({ id: WI, item_type: 'epic', status: 'done' }).ok === true);
|
|
64
|
-
|
|
65
|
-
// pure: extractWorkItemId
|
|
66
|
-
assert('TCG extractWorkItemId: from field', tcg.extractWorkItemId({ work_item_id: WI }) === WI);
|
|
67
|
-
assert('TCG extractWorkItemId: from blob', tcg.extractWorkItemId({ task: { note: `closes ${WI}` } }) === WI);
|
|
68
|
-
assert('TCG extractWorkItemId: none → null', tcg.extractWorkItemId({ task: { note: 'no uuid' } }) === null);
|
|
69
|
-
|
|
70
|
-
// pure: flagEnabledEnv default OFF
|
|
71
|
-
{
|
|
72
|
-
const prev = process.env.RDC_TRUTHGATE_TASKCOMPLETED;
|
|
73
|
-
delete process.env.RDC_TRUTHGATE_TASKCOMPLETED;
|
|
74
|
-
assert('TCG flag default OFF', tcg.flagEnabledEnv() === false);
|
|
75
|
-
process.env.RDC_TRUTHGATE_TASKCOMPLETED = 'true';
|
|
76
|
-
assert('TCG flag ON via env', tcg.flagEnabledEnv() === true);
|
|
77
|
-
if (prev === undefined) delete process.env.RDC_TRUTHGATE_TASKCOMPLETED;
|
|
78
|
-
else process.env.RDC_TRUTHGATE_TASKCOMPLETED = prev;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// pure: flagDbOptIn default OFF, ON via env
|
|
82
|
-
{
|
|
83
|
-
const prev = process.env.RDC_TRUTHGATE_TASKCOMPLETED_DB;
|
|
84
|
-
delete process.env.RDC_TRUTHGATE_TASKCOMPLETED_DB;
|
|
85
|
-
assert('TCG DB-opt-in default OFF', tcg.flagDbOptIn() === false);
|
|
86
|
-
process.env.RDC_TRUTHGATE_TASKCOMPLETED_DB = 'on';
|
|
87
|
-
assert('TCG DB-opt-in ON via env', tcg.flagDbOptIn() === true);
|
|
88
|
-
if (prev === undefined) delete process.env.RDC_TRUTHGATE_TASKCOMPLETED_DB;
|
|
89
|
-
else process.env.RDC_TRUTHGATE_TASKCOMPLETED_DB = prev;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// process: flag OFF → no-op (exit 0, no block)
|
|
93
|
-
{
|
|
94
|
-
const r = runHook('task-completed-gate.js', { work_item_id: WI }, { RDC_TRUTHGATE_TASKCOMPLETED: '' });
|
|
95
|
-
assert('TCG flag OFF → exit 0 no-op', r.status === 0, `status=${r.status} ${r.stderr}`);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// process: flag OFF + DB-opt-in unset → ZERO-COST OFF path makes NO DB call.
|
|
99
|
-
// Point Supabase + the clauth daemon at a non-routable, slow-to-fail address.
|
|
100
|
-
// If the OFF path consulted the DB, the call would stall near the hook's
|
|
101
|
-
// Supabase timeout (~3.5s) / clauth timeout (~2s). The run completing far
|
|
102
|
-
// under that floor proves no round-trip was attempted.
|
|
103
|
-
{
|
|
104
|
-
const t0 = Date.now();
|
|
105
|
-
const r = runHook('task-completed-gate.js', { work_item_id: WI }, {
|
|
106
|
-
RDC_TRUTHGATE_TASKCOMPLETED: '',
|
|
107
|
-
RDC_TRUTHGATE_TASKCOMPLETED_DB: '', // DB check NOT opted into
|
|
108
|
-
SUPABASE_URL: 'http://10.255.255.1', // non-routable: any call would hang
|
|
109
|
-
SUPABASE_SERVICE_ROLE_KEY: 'x', // a key IS present, so only the opt-in gate keeps us off the network
|
|
110
|
-
});
|
|
111
|
-
const elapsed = Date.now() - t0;
|
|
112
|
-
assert('TCG OFF path → exit 0', r.status === 0, `status=${r.status} ${r.stderr}`);
|
|
113
|
-
assert('TCG OFF path makes no DB call (returns well under the network-timeout floor)',
|
|
114
|
-
elapsed < 1500, `elapsed=${elapsed}ms (a DB round-trip would approach the ~3.5s timeout)`);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// process: flag ON + no closure ref → BLOCK (exit 2)
|
|
118
|
-
{
|
|
119
|
-
const r = runHook('task-completed-gate.js', { task: { note: 'no uuid here' } },
|
|
120
|
-
{ RDC_TRUTHGATE_TASKCOMPLETED: '1' });
|
|
121
|
-
assert('TCG flag ON + no work-item ref → exit 2 BLOCK', r.status === 2, `status=${r.status}`);
|
|
122
|
-
assert('TCG block mentions no work-item reference', /no work-item reference/.test(r.stdout + r.stderr), r.stdout);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// process: flag ON + unsound closure (status review via sink) → BLOCK
|
|
126
|
-
{
|
|
127
|
-
const dir = mkdtempSync(join(tmpdir(), 'tcg-'));
|
|
128
|
-
const sink = join(dir, 'closure.json');
|
|
129
|
-
writeFileSync(sink, JSON.stringify({ id: WI, item_type: 'task', status: 'review', implementation_report: null }));
|
|
130
|
-
const r = runHook('task-completed-gate.js', { work_item_id: WI },
|
|
131
|
-
{ RDC_TRUTHGATE_TASKCOMPLETED: '1', RDC_TASKCOMPLETED_CLOSURE_SINK: sink });
|
|
132
|
-
assert('TCG flag ON + unsound closure → exit 2 BLOCK', r.status === 2, `status=${r.status} ${r.stdout}`);
|
|
133
|
-
rmSync(dir, { recursive: true, force: true });
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// process: flag ON + sound closure (via sink) → PASS (exit 0)
|
|
137
|
-
{
|
|
138
|
-
const dir = mkdtempSync(join(tmpdir(), 'tcg-'));
|
|
139
|
-
const sink = join(dir, 'closure.json');
|
|
140
|
-
writeFileSync(sink, JSON.stringify(soundRow));
|
|
141
|
-
const r = runHook('task-completed-gate.js', { work_item_id: WI },
|
|
142
|
-
{ RDC_TRUTHGATE_TASKCOMPLETED: '1', RDC_TASKCOMPLETED_CLOSURE_SINK: sink });
|
|
143
|
-
assert('TCG flag ON + sound closure → exit 0 PASS', r.status === 0, `status=${r.status} ${r.stdout}${r.stderr}`);
|
|
144
|
-
rmSync(dir, { recursive: true, force: true });
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
31
|
// ===========================================================================
|
|
149
32
|
// 2. foreground-process-gate.js — moved to its own file, tests/foreground-process-gate.test.mjs
|
|
150
33
|
//
|
|
@@ -157,57 +40,6 @@ const WI = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
|
|
|
157
40
|
// section is not a coverage loss — see that file instead.
|
|
158
41
|
// ===========================================================================
|
|
159
42
|
|
|
160
|
-
// ===========================================================================
|
|
161
|
-
// 3. post-tool-batch-gate.js
|
|
162
|
-
// ===========================================================================
|
|
163
|
-
{
|
|
164
|
-
const ptb = require(join(HOOKS, 'post-tool-batch-gate.js'));
|
|
165
|
-
const DEV = 'c3189c9d58a37d648e9de4a6bcd7d46772053eea';
|
|
166
|
-
const STALE = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef';
|
|
167
|
-
const FRESH = '1234567812345678123456781234567812345678';
|
|
168
|
-
|
|
169
|
-
// pure: evaluateWave — cannotEvaluate when no develop HEAD
|
|
170
|
-
{
|
|
171
|
-
const v = ptb.evaluateWave({ developHead: null, worktrees: [], isAncestor: () => true });
|
|
172
|
-
assert('PTB evaluateWave: no develop HEAD → cannotEvaluate', v.cannotEvaluate === true && v.ok === false);
|
|
173
|
-
}
|
|
174
|
-
// pure: current base (develop is ancestor of worktree HEAD) → ok
|
|
175
|
-
{
|
|
176
|
-
const v = ptb.evaluateWave({
|
|
177
|
-
developHead: DEV,
|
|
178
|
-
worktrees: [{ path: '/wt/a', head: FRESH }],
|
|
179
|
-
isAncestor: (a, b) => a === DEV && b === FRESH, // DEV is ancestor of FRESH
|
|
180
|
-
});
|
|
181
|
-
assert('PTB evaluateWave: current base → ok, no stale', v.ok === true && v.stale.length === 0);
|
|
182
|
-
}
|
|
183
|
-
// pure: worktree HEAD == develop HEAD → ok
|
|
184
|
-
{
|
|
185
|
-
const v = ptb.evaluateWave({
|
|
186
|
-
developHead: DEV,
|
|
187
|
-
worktrees: [{ path: '/wt/a', head: DEV }],
|
|
188
|
-
isAncestor: () => false,
|
|
189
|
-
});
|
|
190
|
-
assert('PTB evaluateWave: head==develop → ok', v.ok === true && v.stale.length === 0);
|
|
191
|
-
}
|
|
192
|
-
// pure: stale base (develop NOT an ancestor) → flagged
|
|
193
|
-
{
|
|
194
|
-
const v = ptb.evaluateWave({
|
|
195
|
-
developHead: DEV,
|
|
196
|
-
worktrees: [{ path: '/wt/stale', head: STALE }],
|
|
197
|
-
isAncestor: () => false, // DEV is NOT an ancestor of STALE
|
|
198
|
-
});
|
|
199
|
-
assert('PTB evaluateWave: stale base → not ok', v.ok === false, JSON.stringify(v));
|
|
200
|
-
assert('PTB evaluateWave: stale worktree listed', v.stale.length === 1 && v.stale[0].head === STALE);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// process: flag OFF → no-op (exit 0)
|
|
204
|
-
{
|
|
205
|
-
const r = runHook('post-tool-batch-gate.js', { hook_event_name: 'PostToolBatch' },
|
|
206
|
-
{ RDC_TRUTHGATE_POSTTOOLBATCH: '' });
|
|
207
|
-
assert('PTB flag OFF → exit 0 no-op', r.status === 0, `status=${r.status} ${r.stderr}`);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
43
|
// ===========================================================================
|
|
212
44
|
// 4. gate-watchdog-selfcheck.js
|
|
213
45
|
// ===========================================================================
|
|
@@ -296,6 +128,26 @@ const WI = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
|
|
|
296
128
|
rmSync(home, { recursive: true, force: true });
|
|
297
129
|
rmSync(repo, { recursive: true, force: true });
|
|
298
130
|
}
|
|
131
|
+
|
|
132
|
+
// truthGateWiredForEvent (LIFEAI/regen-root#212): since the stage merge the
|
|
133
|
+
// event registers ONE dispatcher; truth-gate.mjs is named only inside it.
|
|
134
|
+
{
|
|
135
|
+
const dir = mkdtempSync(join(tmpdir(), 'wd-stage-'));
|
|
136
|
+
const stop = join(dir, 'stop.mjs');
|
|
137
|
+
const other = join(dir, 'other.mjs');
|
|
138
|
+
writeFileSync(stop, "import './truth-gate.mjs';\n");
|
|
139
|
+
writeFileSync(other, "console.log('unrelated');\n");
|
|
140
|
+
const N = 'truth-gate.mjs';
|
|
141
|
+
assert('WD wired: direct registration → true',
|
|
142
|
+
wd.truthGateWiredForEvent('Stop::node .claude/hooks/truth-gate.mjs', 'Stop', N) === true);
|
|
143
|
+
assert('WD wired: via stage dispatcher → true (positive control)',
|
|
144
|
+
wd.truthGateWiredForEvent(`Stop::node "${stop}"`, 'Stop', N) === true);
|
|
145
|
+
assert('WD wired: dispatcher that does not reference it → false (negative control)',
|
|
146
|
+
wd.truthGateWiredForEvent(`Stop::node "${other}"`, 'Stop', N) === false);
|
|
147
|
+
assert('WD wired: registered on a different event only → false',
|
|
148
|
+
wd.truthGateWiredForEvent(`SubagentStop::node "${stop}"`, 'Stop', N) === false);
|
|
149
|
+
rmSync(dir, { recursive: true, force: true });
|
|
150
|
+
}
|
|
299
151
|
}
|
|
300
152
|
|
|
301
153
|
// ===========================================================================
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// The installer warns when it runs from a checkout behind origin/master
|
|
2
|
+
// (LIFEAI/regen-root#230). Builds a throwaway origin + clone; no network.
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { execFileSync } from 'node:child_process';
|
|
5
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
import { tmpdir } from 'node:os';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { test } from 'node:test';
|
|
10
|
+
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
const { checkoutBehindMaster } = require('../scripts/install-rdc-skills.js');
|
|
13
|
+
|
|
14
|
+
const git = (cwd, ...args) => execFileSync('git', args, { cwd, encoding: 'utf8', stdio: 'pipe' }).trim();
|
|
15
|
+
const commit = (cwd, name) => {
|
|
16
|
+
writeFileSync(join(cwd, name), name);
|
|
17
|
+
git(cwd, 'add', name);
|
|
18
|
+
git(cwd, '-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '-q', '-m', name);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
test('checkoutBehindMaster', () => {
|
|
22
|
+
const dir = mkdtempSync(join(tmpdir(), 'rdc-stale-'));
|
|
23
|
+
try {
|
|
24
|
+
const origin = join(dir, 'origin');
|
|
25
|
+
const clone = join(dir, 'clone');
|
|
26
|
+
execFileSync('git', ['init', '-q', '-b', 'master', origin]);
|
|
27
|
+
commit(origin, 'a');
|
|
28
|
+
execFileSync('git', ['clone', '-q', origin, clone]);
|
|
29
|
+
|
|
30
|
+
assert.deepEqual(checkoutBehindMaster(clone), { behind: 0, branch: 'master' });
|
|
31
|
+
|
|
32
|
+
git(clone, 'checkout', '-q', '-b', 'old-feature');
|
|
33
|
+
commit(origin, 'b');
|
|
34
|
+
commit(origin, 'c');
|
|
35
|
+
git(clone, 'fetch', '-q', 'origin');
|
|
36
|
+
assert.deepEqual(checkoutBehindMaster(clone), { behind: 2, branch: 'old-feature' });
|
|
37
|
+
|
|
38
|
+
assert.equal(checkoutBehindMaster(join(dir, 'origin-not-a-clone-dir')), null);
|
|
39
|
+
} finally {
|
|
40
|
+
rmSync(dir, { recursive: true, force: true });
|
|
41
|
+
}
|
|
42
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// staging_gates in a PUBLISH.md DEPLOY block must be a mapping, the shape
|
|
2
|
+
// regen-root scripts/gen-deploy-blocks.mjs emits (LIFEAI/regen-root#210).
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import { test } from 'node:test';
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const { stagingGatesShapeError } = require('../scripts/validate-publish-manifests.js');
|
|
9
|
+
|
|
10
|
+
const block = (gates) => `\nruntime: next\nport: registry\nhealth_path: /\n${gates}\n# slug: x\n`;
|
|
11
|
+
|
|
12
|
+
test('generated mapping passes', () => {
|
|
13
|
+
assert.equal(stagingGatesShapeError(block('staging_gates:\n tsc_clean: true\n health_200: true\n content_probe: true')), null);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('absent key passes', () => {
|
|
17
|
+
assert.equal(stagingGatesShapeError(block('')), null);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('a list fails', () => {
|
|
21
|
+
assert.match(stagingGatesShapeError(block('staging_gates:\n - tsc_clean\n - health_200')), /mapping.*not a list item/);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('an inline value fails', () => {
|
|
25
|
+
assert.match(stagingGatesShapeError(block('staging_gates: [tsc_clean]')), /not inline/);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('a bare key fails', () => {
|
|
29
|
+
assert.match(stagingGatesShapeError(block('staging_gates:\n tsc_clean')), /not 'key: value'/);
|
|
30
|
+
});
|
|
@@ -45,6 +45,19 @@ assert('isGitCommit: false for --help',
|
|
|
45
45
|
hook.isGitCommit('git commit --help') === false);
|
|
46
46
|
assert('isGitCommit: false for unrelated',
|
|
47
47
|
hook.isGitCommit('git status') === false);
|
|
48
|
+
// LIFEAI/regen-root#243: git must be the command word, not a substring anywhere.
|
|
49
|
+
for (const [cmd, want] of [
|
|
50
|
+
['( cd /repo && git add a.js && git commit -q -F - <<\'EOF\'\nfix(x): y\nEOF\n)', true],
|
|
51
|
+
['git -C "C:/Dev/my repo" commit -m "fix: x"', true],
|
|
52
|
+
['GIT_AUTHOR_NAME=x git -c user.email=a@b commit -m "fix: x"', true],
|
|
53
|
+
['cd a; git --no-pager commit --amend --no-edit', true],
|
|
54
|
+
['node rdc-lesson.mjs submit --what "the git hook fired before commit ran"', false],
|
|
55
|
+
['git log --oneline --grep commit', false],
|
|
56
|
+
['gh issue create --body "run git commit after staging"', false],
|
|
57
|
+
['echo git && echo commit', false],
|
|
58
|
+
]) {
|
|
59
|
+
assert(`isGitCommit(${JSON.stringify(cmd).slice(0, 60)}) === ${want}`, hook.isGitCommit(cmd) === want);
|
|
60
|
+
}
|
|
48
61
|
assert('commitSucceeded: false on nothing-to-commit',
|
|
49
62
|
hook.commitSucceeded({ stdout: 'nothing to commit, working tree clean' }) === false);
|
|
50
63
|
assert('commitSucceeded: true on exit 0',
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* post-tool-batch-gate.js — Truth Gate 3.0 Layer 5 (per-wave batch gate).
|
|
4
|
-
*
|
|
5
|
-
* Registered on the `PostToolBatch` event — it fires after a full batch of
|
|
6
|
-
* parallel tool calls resolves, BEFORE the next model call. Per the Claude Code
|
|
7
|
-
* hooks reference, `PostToolBatch` CAN block (exit code 2 stops the agentic
|
|
8
|
-
* loop). After a parallel build wave (multiple Agent dispatches into isolated
|
|
9
|
-
* worktrees), this gate asserts the wave's worktree bases are sane — every agent
|
|
10
|
-
* worktree must be based on the current `develop` HEAD — so a stale-base wave
|
|
11
|
-
* cannot feed fabricated/diverged closures into the next model turn.
|
|
12
|
-
*
|
|
13
|
-
* ⛔ FLAG-GATED, DEFAULT OFF. Until the flag is flipped at deploy this hook is a
|
|
14
|
-
* pure no-op (exit 0) so the in-flight build session is NOT disrupted. When the
|
|
15
|
-
* flag is ON it is FAIL-CLOSED: an inability to confirm worktree-base sanity is
|
|
16
|
-
* a BLOCK, never a silent pass.
|
|
17
|
-
*
|
|
18
|
-
* Flag (default OFF):
|
|
19
|
-
* - env RDC_TRUTHGATE_POSTTOOLBATCH in {1,true,on,yes}.
|
|
20
|
-
*
|
|
21
|
-
* Worktree-base sanity, per worktree:
|
|
22
|
-
* - resolve develop HEAD: `git rev-parse refs/heads/develop` in the main repo.
|
|
23
|
-
* - for each linked worktree (`git worktree list --porcelain`), its base must
|
|
24
|
-
* equal develop HEAD — i.e. develop is an ancestor of the worktree HEAD
|
|
25
|
-
* (`git merge-base --is-ancestor <developHead> <worktreeHead>`), OR the
|
|
26
|
-
* worktree HEAD already IS develop HEAD. A worktree whose base predates the
|
|
27
|
-
* current develop HEAD is STALE and the wave is flagged.
|
|
28
|
-
*
|
|
29
|
-
* Test seam: inject the git surface via the exported pure `evaluateWave({
|
|
30
|
-
* developHead, worktrees, isAncestor })`, where `worktrees` is
|
|
31
|
-
* [{ path, head }] and `isAncestor(a,b)` returns whether a is an ancestor of b.
|
|
32
|
-
* The pure evaluator has no process/network dependency, so the flag-OFF no-op
|
|
33
|
-
* and the stale-base FLAG branches are provable offline.
|
|
34
|
-
*/
|
|
35
|
-
'use strict';
|
|
36
|
-
|
|
37
|
-
const { execFileSync } = require('child_process');
|
|
38
|
-
const hookLog = require('./hook-logger');
|
|
39
|
-
|
|
40
|
-
const FULL_SHA_RE = /^[0-9a-f]{40}$/i;
|
|
41
|
-
const MAIN_REPO = process.env.RDC_TRUTH_GATE_REPO || 'C:/Dev/regen-root';
|
|
42
|
-
|
|
43
|
-
function readStdin() {
|
|
44
|
-
return new Promise((resolve) => {
|
|
45
|
-
let input = '';
|
|
46
|
-
process.stdin.setEncoding('utf8');
|
|
47
|
-
process.stdin.on('data', (chunk) => { input += chunk; });
|
|
48
|
-
process.stdin.on('end', () => resolve(input));
|
|
49
|
-
process.stdin.resume();
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Block the batch with exit code 2 (the blocking semantics for PostToolBatch). */
|
|
54
|
-
function block(reason, details = {}) {
|
|
55
|
-
hookLog('post-tool-batch-gate', 'PostToolBatch', 'block', { reason, ...details });
|
|
56
|
-
process.stdout.write(JSON.stringify({
|
|
57
|
-
decision: 'block',
|
|
58
|
-
reason: `BUILD WAVE FLAGGED — Truth Gate Layer 5 (PostToolBatch).\n\n${reason}`,
|
|
59
|
-
}));
|
|
60
|
-
process.stderr.write(`BUILD WAVE FLAGGED: ${reason}\n`);
|
|
61
|
-
process.exit(2);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function pass(details = {}) {
|
|
65
|
-
hookLog('post-tool-batch-gate', 'PostToolBatch', 'pass', details);
|
|
66
|
-
process.exit(0);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Default OFF. Only the env switch enables it (test-stable, deploy-flippable). */
|
|
70
|
-
function flagEnabledEnv() {
|
|
71
|
-
const v = String(process.env.RDC_TRUTHGATE_POSTTOOLBATCH || '').trim().toLowerCase();
|
|
72
|
-
return v === '1' || v === 'true' || v === 'on' || v === 'yes';
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function git(args, { cwd = MAIN_REPO, allowFail = false } = {}) {
|
|
76
|
-
try {
|
|
77
|
-
return execFileSync('git', args, {
|
|
78
|
-
cwd,
|
|
79
|
-
encoding: 'utf8',
|
|
80
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
81
|
-
maxBuffer: 8 * 1024 * 1024,
|
|
82
|
-
}).trim();
|
|
83
|
-
} catch (e) {
|
|
84
|
-
if (allowFail) return null;
|
|
85
|
-
throw e;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** Resolve develop's HEAD SHA in the main repo, or null. */
|
|
90
|
-
function developHead() {
|
|
91
|
-
const sha = git(['rev-parse', '--verify', '--quiet', 'refs/heads/develop'], { allowFail: true });
|
|
92
|
-
return sha && FULL_SHA_RE.test(sha) ? sha.toLowerCase() : null;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** Parse `git worktree list --porcelain` into [{ path, head }] (linked only). */
|
|
96
|
-
function listWorktrees() {
|
|
97
|
-
const out = git(['worktree', 'list', '--porcelain'], { allowFail: true });
|
|
98
|
-
if (out == null) return null;
|
|
99
|
-
const worktrees = [];
|
|
100
|
-
let cur = null;
|
|
101
|
-
for (const line of out.split('\n')) {
|
|
102
|
-
if (line.startsWith('worktree ')) {
|
|
103
|
-
if (cur) worktrees.push(cur);
|
|
104
|
-
cur = { path: line.slice('worktree '.length).trim(), head: null, bare: false };
|
|
105
|
-
} else if (line.startsWith('HEAD ')) {
|
|
106
|
-
if (cur) cur.head = line.slice('HEAD '.length).trim().toLowerCase();
|
|
107
|
-
} else if (line.trim() === 'bare') {
|
|
108
|
-
if (cur) cur.bare = true;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (cur) worktrees.push(cur);
|
|
112
|
-
// Linked worktrees only: drop the bare entry and the primary checkout (== MAIN_REPO).
|
|
113
|
-
const norm = (p) => String(p || '').replace(/\\/g, '/').replace(/\/+$/, '').toLowerCase();
|
|
114
|
-
const mainNorm = norm(MAIN_REPO);
|
|
115
|
-
return worktrees.filter((w) => !w.bare && w.head && norm(w.path) !== mainNorm);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** True when `git merge-base --is-ancestor a b` (a is an ancestor of b). */
|
|
119
|
-
function isAncestor(a, b) {
|
|
120
|
-
if (!a || !b) return false;
|
|
121
|
-
if (a === b) return true;
|
|
122
|
-
// exit 0 = ancestor, exit 1 = not. allowFail captures the non-zero exit.
|
|
123
|
-
try {
|
|
124
|
-
execFileSync('git', ['merge-base', '--is-ancestor', a, b], {
|
|
125
|
-
cwd: MAIN_REPO,
|
|
126
|
-
stdio: ['ignore', 'ignore', 'ignore'],
|
|
127
|
-
});
|
|
128
|
-
return true;
|
|
129
|
-
} catch (_) {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Pure wave evaluator (unit-testable, no process/network). Returns
|
|
136
|
-
* { stale: [{ path, head }], ok: boolean }. A worktree is STALE when develop
|
|
137
|
-
* HEAD is NOT an ancestor of its HEAD (its base predates current develop), and
|
|
138
|
-
* its HEAD is not develop HEAD itself.
|
|
139
|
-
*
|
|
140
|
-
* @param {object} surface
|
|
141
|
-
* @param {string|null} surface.developHead develop HEAD SHA (null → cannot evaluate)
|
|
142
|
-
* @param {Array<{path,head}>} surface.worktrees linked worktrees
|
|
143
|
-
* @param {(a:string,b:string)=>boolean} surface.isAncestor
|
|
144
|
-
*/
|
|
145
|
-
function evaluateWave({ developHead, worktrees, isAncestor: anc }) {
|
|
146
|
-
if (!developHead) {
|
|
147
|
-
return { ok: false, cannotEvaluate: true, stale: [] };
|
|
148
|
-
}
|
|
149
|
-
const list = Array.isArray(worktrees) ? worktrees : [];
|
|
150
|
-
const stale = [];
|
|
151
|
-
for (const w of list) {
|
|
152
|
-
if (!w || !w.head) continue;
|
|
153
|
-
const based = w.head === developHead || anc(developHead, w.head);
|
|
154
|
-
if (!based) stale.push({ path: w.path, head: w.head });
|
|
155
|
-
}
|
|
156
|
-
return { ok: stale.length === 0, cannotEvaluate: false, stale };
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async function main() {
|
|
160
|
-
// Drain stdin (PostToolBatch payload) — we don't need its body, but the event
|
|
161
|
-
// delivers JSON on stdin and the process should consume it cleanly.
|
|
162
|
-
try { await readStdin(); } catch (_) {}
|
|
163
|
-
|
|
164
|
-
// Default-OFF: a no-op until the flag is flipped at deploy.
|
|
165
|
-
if (!flagEnabledEnv()) return pass({ reason: 'flag-off' });
|
|
166
|
-
|
|
167
|
-
// FAIL-CLOSED from here.
|
|
168
|
-
const head = developHead();
|
|
169
|
-
const worktrees = listWorktrees();
|
|
170
|
-
if (head == null || worktrees == null) {
|
|
171
|
-
block(
|
|
172
|
-
`Could not read git state in ${MAIN_REPO} (develop HEAD or worktree list unavailable). ` +
|
|
173
|
-
`Fail-closed: cannot confirm the build wave's worktree bases are current.`,
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const verdict = evaluateWave({ developHead: head, worktrees, isAncestor });
|
|
178
|
-
if (verdict.cannotEvaluate) {
|
|
179
|
-
block(`develop HEAD could not be resolved; fail-closed — cannot confirm worktree-base sanity for this wave.`);
|
|
180
|
-
}
|
|
181
|
-
if (!verdict.ok) {
|
|
182
|
-
const lines = verdict.stale.map((s) => ` - ${s.path} @ ${s.head.slice(0, 9)} (base predates develop ${head.slice(0, 9)})`).join('\n');
|
|
183
|
-
block(
|
|
184
|
-
`One or more build-wave worktrees are NOT based on the current develop HEAD ${head.slice(0, 9)}:\n${lines}\n\n` +
|
|
185
|
-
`A wave built on a stale base can feed diverged/fabricated closures into the next turn. ` +
|
|
186
|
-
`Rebase each worktree onto develop (git fetch && git rebase origin/develop), re-run its verification, then continue.`,
|
|
187
|
-
{ developHead: head, stale: verdict.stale },
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
pass({ developHead: head, worktreeCount: worktrees.length });
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (require.main === module) {
|
|
195
|
-
main().catch((e) => block(`post-tool-batch-gate crashed: ${e.message}`));
|
|
196
|
-
} else {
|
|
197
|
-
module.exports = {
|
|
198
|
-
flagEnabledEnv,
|
|
199
|
-
evaluateWave,
|
|
200
|
-
listWorktrees,
|
|
201
|
-
developHead,
|
|
202
|
-
};
|
|
203
|
-
}
|