@warnyin/sdlc 0.5.0 → 0.5.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/CHANGELOG.md +25 -0
- package/LICENSE +21 -21
- package/bin/cli.mjs +12 -1
- package/lib/caps.mjs +45 -45
- package/lib/config.mjs +41 -41
- package/lib/delta.mjs +227 -160
- package/lib/frontmatter.mjs +59 -59
- package/lib/glob.mjs +29 -29
- package/lib/manifest.mjs +99 -99
- package/lib/settings-merge.mjs +63 -63
- package/lib/usage.mjs +49 -46
- package/lib/validate.mjs +196 -186
- package/package.json +42 -42
- package/payload/adapters/agents-md.md +8 -8
- package/payload/adapters/claude/agents/sdlc-architect.md +12 -12
- package/payload/adapters/claude/agents/sdlc-builder.md +14 -14
- package/payload/adapters/claude/agents/sdlc-contractor.md +13 -13
- package/payload/adapters/claude/agents/sdlc-evaluator.md +13 -13
- package/payload/adapters/claude/agents/sdlc-learner.md +16 -16
- package/payload/adapters/claude/agents/sdlc-ops.md +11 -11
- package/payload/adapters/claude/agents/sdlc-quality.md +13 -13
- package/payload/adapters/claude/agents/sdlc-security.md +12 -12
- package/payload/adapters/claude/commands/sdlc/converge.md +5 -5
- package/payload/adapters/claude/commands/sdlc/init.md +4 -4
- package/payload/adapters/claude/commands/sdlc/next.md +4 -4
- package/payload/adapters/claude/commands/sdlc/observe.md +4 -4
- package/payload/adapters/claude/commands/sdlc/steer.md +4 -4
- package/payload/adapters/claude/skills/contract-writing/SKILL.md +26 -26
- package/payload/adapters/claude/skills/delta-spec-format/SKILL.md +36 -33
- package/payload/adapters/claude/skills/sdlc-conventions/SKILL.md +26 -26
- package/payload/adapters/cline.md +8 -8
- package/payload/adapters/copilot.md +8 -8
- package/payload/adapters/cursor.mdc +7 -7
- package/payload/adapters/gemini.md +8 -8
- package/payload/adapters/windsurf.md +4 -4
- package/payload/hooks/_shared.mjs +154 -154
- package/payload/hooks/guard-writes.mjs +83 -83
- package/payload/hooks/inject-context.mjs +55 -55
- package/payload/hooks/journal.mjs +58 -58
- package/payload/hooks/session-summary.mjs +50 -50
- package/payload/hooks/validate-artifact.mjs +80 -80
- package/payload/playbook/context.md +26 -26
- package/payload/playbook/converge.md +19 -19
- package/payload/playbook/init.md +22 -22
- package/payload/playbook/observe.md +20 -20
- package/payload/playbook/principles.md +28 -28
- package/payload/playbook/routing.md +19 -19
- package/payload/playbook/rules-card.md +16 -16
- package/payload/playbook/ship.md +2 -0
- package/payload/playbook/steer.md +21 -21
- package/payload/templates/change-deep.md +29 -29
- package/payload/templates/change-standard.md +28 -28
- package/payload/templates/change-vibe.md +19 -19
- package/payload/templates/config.yaml +8 -8
- package/payload/templates/constitution.md +14 -14
- package/payload/templates/contract-evals.md +9 -9
- package/payload/templates/contract-tests.md +9 -9
- package/payload/templates/harness.md +33 -33
- package/payload/templates/spec.md +14 -14
- package/payload/templates/steering.md +9 -9
- package/scripts/validate.mjs +47 -47
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
// Shared plumbing for installed hooks. This file lives at
|
|
2
|
-
// <project>/sdlc/.hooks/_shared.mjs with lib/ as a sibling directory.
|
|
3
|
-
// Every hook must be fail-open: on any unexpected condition, exit 0 silently
|
|
4
|
-
// so the harness is never blocked by our tooling.
|
|
5
|
-
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
import path from 'node:path';
|
|
8
|
-
import process from 'node:process';
|
|
9
|
-
import { fileURLToPath } from 'node:url';
|
|
10
|
-
|
|
11
|
-
export function resolveRoots(importMetaUrl) {
|
|
12
|
-
const hooksDir = path.dirname(fileURLToPath(importMetaUrl));
|
|
13
|
-
const sdlcRoot = path.dirname(hooksDir);
|
|
14
|
-
const projectRoot = path.dirname(sdlcRoot);
|
|
15
|
-
return { hooksDir, sdlcRoot, projectRoot };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Reads the hook payload from stdin. Must NEVER hang: when a playbook or a
|
|
19
|
-
// user script invokes a hook utility with stdin open-but-idle (no piped JSON),
|
|
20
|
-
// resolve null after a short grace period instead of blocking forever.
|
|
21
|
-
export function readStdinJson({ timeoutMs = 1000 } = {}) {
|
|
22
|
-
return new Promise((resolve) => {
|
|
23
|
-
let data = '';
|
|
24
|
-
let done = false;
|
|
25
|
-
const finish = () => {
|
|
26
|
-
if (done) return;
|
|
27
|
-
done = true;
|
|
28
|
-
// Release stdin so an open-idle stream cannot keep the event loop alive.
|
|
29
|
-
process.stdin.pause();
|
|
30
|
-
if (typeof process.stdin.unref === 'function') process.stdin.unref();
|
|
31
|
-
try { resolve(data.trim() ? JSON.parse(data) : null); } catch { resolve(null); }
|
|
32
|
-
};
|
|
33
|
-
const timer = setTimeout(finish, timeoutMs);
|
|
34
|
-
if (typeof timer.unref === 'function') timer.unref();
|
|
35
|
-
process.stdin.on('data', (chunk) => { data += chunk; });
|
|
36
|
-
process.stdin.on('end', finish);
|
|
37
|
-
process.stdin.on('error', finish);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Resolve symlinks on the deepest EXISTING ancestor, then re-attach the tail.
|
|
42
|
-
// Needed because import.meta.url is symlink-resolved while tool file_paths may
|
|
43
|
-
// arrive through a symlink (/tmp → /private/tmp on macOS).
|
|
44
|
-
export function realResolve(p) {
|
|
45
|
-
let cur = path.resolve(p);
|
|
46
|
-
const tail = [];
|
|
47
|
-
while (!fs.existsSync(cur)) {
|
|
48
|
-
const parent = path.dirname(cur);
|
|
49
|
-
if (parent === cur) break;
|
|
50
|
-
tail.unshift(path.basename(cur));
|
|
51
|
-
cur = parent;
|
|
52
|
-
}
|
|
53
|
-
try { cur = fs.realpathSync.native(cur); } catch { /* keep as-is */ }
|
|
54
|
-
return tail.length ? path.join(cur, ...tail) : cur;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function toPosixRel(projectRoot, absPath) {
|
|
58
|
-
const rel = path.relative(realResolve(projectRoot), realResolve(absPath));
|
|
59
|
-
if (rel.startsWith('..')) return null;
|
|
60
|
-
return rel.split(path.sep).join('/');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Lexical (no-symlink-resolution) relative path: what the path CLAIMS to be.
|
|
64
|
-
// Tried against both the raw and the realpathed project root so /tmp-style
|
|
65
|
-
// root symlinks don't break matching. Guards must compare this against
|
|
66
|
-
// toPosixRel — a divergence means a symlink sits inside the project.
|
|
67
|
-
export function lexicalPosixRel(projectRoot, absPath) {
|
|
68
|
-
const abs = path.resolve(absPath);
|
|
69
|
-
const realRoot = realResolve(projectRoot);
|
|
70
|
-
for (const base of [path.resolve(projectRoot), realRoot]) {
|
|
71
|
-
const rel = path.relative(base, abs);
|
|
72
|
-
if (rel && !rel.startsWith('..') && !path.isAbsolute(rel)) {
|
|
73
|
-
return rel.split(path.sep).join('/');
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
// Root-level symlinks (/tmp → /private/tmp): find the SHALLOWEST ancestor of
|
|
77
|
-
// abs whose realpath IS the project root; the remaining tail is the lexical
|
|
78
|
-
// claim. In-project symlinks are deliberately not resolved here.
|
|
79
|
-
const segs = abs.split(path.sep);
|
|
80
|
-
for (let i = 1; i < segs.length; i++) {
|
|
81
|
-
const ancestor = segs.slice(0, i).join(path.sep) || path.sep;
|
|
82
|
-
let real;
|
|
83
|
-
try { real = fs.realpathSync.native(ancestor); } catch { continue; }
|
|
84
|
-
if (real === realRoot) {
|
|
85
|
-
const tail = segs.slice(i).join('/');
|
|
86
|
-
return tail || null;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Gate state written by `journal.mjs open-<phase>` — {phase, change?, expires}.
|
|
93
|
-
export function readPhase(sdlcRoot) {
|
|
94
|
-
try {
|
|
95
|
-
const raw = fs.readFileSync(path.join(sdlcRoot, '.state', 'phase.json'), 'utf8');
|
|
96
|
-
const phase = JSON.parse(raw);
|
|
97
|
-
if (phase.expires && Date.parse(phase.expires) < Date.now()) return null;
|
|
98
|
-
return phase;
|
|
99
|
-
} catch {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function writePhase(sdlcRoot, phase, ttlMinutes = 30) {
|
|
105
|
-
const stateDir = path.join(sdlcRoot, '.state');
|
|
106
|
-
fs.mkdirSync(stateDir, { recursive: true });
|
|
107
|
-
const payload = { ...phase, expires: new Date(Date.now() + ttlMinutes * 60_000).toISOString() };
|
|
108
|
-
fs.writeFileSync(path.join(stateDir, 'phase.json'), JSON.stringify(payload));
|
|
109
|
-
return payload;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function clearPhase(sdlcRoot) {
|
|
113
|
-
fs.rmSync(path.join(sdlcRoot, '.state', 'phase.json'), { force: true });
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Active change: explicit .state/active.json first, else the most recently
|
|
117
|
-
// modified changes/*/change.md.
|
|
118
|
-
export function activeChange(sdlcRoot) {
|
|
119
|
-
try {
|
|
120
|
-
const explicit = JSON.parse(fs.readFileSync(path.join(sdlcRoot, '.state', 'active.json'), 'utf8'));
|
|
121
|
-
if (explicit?.change && fs.existsSync(path.join(sdlcRoot, 'changes', explicit.change))) {
|
|
122
|
-
return explicit.change;
|
|
123
|
-
}
|
|
124
|
-
} catch { /* fall through */ }
|
|
125
|
-
const changesDir = path.join(sdlcRoot, 'changes');
|
|
126
|
-
if (!fs.existsSync(changesDir)) return null;
|
|
127
|
-
let best = null;
|
|
128
|
-
for (const d of fs.readdirSync(changesDir, { withFileTypes: true })) {
|
|
129
|
-
if (!d.isDirectory() || d.name === 'archive') continue;
|
|
130
|
-
const p = path.join(changesDir, d.name, 'change.md');
|
|
131
|
-
if (!fs.existsSync(p)) continue;
|
|
132
|
-
const mtime = fs.statSync(p).mtimeMs;
|
|
133
|
-
if (!best || mtime > best.mtime) best = { change: d.name, mtime };
|
|
134
|
-
}
|
|
135
|
-
return best?.change ?? null;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Journal: per-change ndjson when a change is active, else a global one under
|
|
139
|
-
// .state/ so no signal is lost. Hook-written only — agents never hand-edit.
|
|
140
|
-
export function appendJournal(sdlcRoot, change, event) {
|
|
141
|
-
try {
|
|
142
|
-
const line = JSON.stringify({ ts: new Date().toISOString(), ...event }) + '\n';
|
|
143
|
-
if (change) {
|
|
144
|
-
const dir = path.join(sdlcRoot, 'changes', change);
|
|
145
|
-
if (fs.existsSync(dir)) {
|
|
146
|
-
fs.appendFileSync(path.join(dir, 'journal.ndjson'), line);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const stateDir = path.join(sdlcRoot, '.state');
|
|
151
|
-
fs.mkdirSync(stateDir, { recursive: true });
|
|
152
|
-
fs.appendFileSync(path.join(stateDir, 'journal.ndjson'), line);
|
|
153
|
-
} catch { /* fail open */ }
|
|
154
|
-
}
|
|
1
|
+
// Shared plumbing for installed hooks. This file lives at
|
|
2
|
+
// <project>/sdlc/.hooks/_shared.mjs with lib/ as a sibling directory.
|
|
3
|
+
// Every hook must be fail-open: on any unexpected condition, exit 0 silently
|
|
4
|
+
// so the harness is never blocked by our tooling.
|
|
5
|
+
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import process from 'node:process';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
|
|
11
|
+
export function resolveRoots(importMetaUrl) {
|
|
12
|
+
const hooksDir = path.dirname(fileURLToPath(importMetaUrl));
|
|
13
|
+
const sdlcRoot = path.dirname(hooksDir);
|
|
14
|
+
const projectRoot = path.dirname(sdlcRoot);
|
|
15
|
+
return { hooksDir, sdlcRoot, projectRoot };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Reads the hook payload from stdin. Must NEVER hang: when a playbook or a
|
|
19
|
+
// user script invokes a hook utility with stdin open-but-idle (no piped JSON),
|
|
20
|
+
// resolve null after a short grace period instead of blocking forever.
|
|
21
|
+
export function readStdinJson({ timeoutMs = 1000 } = {}) {
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
let data = '';
|
|
24
|
+
let done = false;
|
|
25
|
+
const finish = () => {
|
|
26
|
+
if (done) return;
|
|
27
|
+
done = true;
|
|
28
|
+
// Release stdin so an open-idle stream cannot keep the event loop alive.
|
|
29
|
+
process.stdin.pause();
|
|
30
|
+
if (typeof process.stdin.unref === 'function') process.stdin.unref();
|
|
31
|
+
try { resolve(data.trim() ? JSON.parse(data) : null); } catch { resolve(null); }
|
|
32
|
+
};
|
|
33
|
+
const timer = setTimeout(finish, timeoutMs);
|
|
34
|
+
if (typeof timer.unref === 'function') timer.unref();
|
|
35
|
+
process.stdin.on('data', (chunk) => { data += chunk; });
|
|
36
|
+
process.stdin.on('end', finish);
|
|
37
|
+
process.stdin.on('error', finish);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Resolve symlinks on the deepest EXISTING ancestor, then re-attach the tail.
|
|
42
|
+
// Needed because import.meta.url is symlink-resolved while tool file_paths may
|
|
43
|
+
// arrive through a symlink (/tmp → /private/tmp on macOS).
|
|
44
|
+
export function realResolve(p) {
|
|
45
|
+
let cur = path.resolve(p);
|
|
46
|
+
const tail = [];
|
|
47
|
+
while (!fs.existsSync(cur)) {
|
|
48
|
+
const parent = path.dirname(cur);
|
|
49
|
+
if (parent === cur) break;
|
|
50
|
+
tail.unshift(path.basename(cur));
|
|
51
|
+
cur = parent;
|
|
52
|
+
}
|
|
53
|
+
try { cur = fs.realpathSync.native(cur); } catch { /* keep as-is */ }
|
|
54
|
+
return tail.length ? path.join(cur, ...tail) : cur;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function toPosixRel(projectRoot, absPath) {
|
|
58
|
+
const rel = path.relative(realResolve(projectRoot), realResolve(absPath));
|
|
59
|
+
if (rel.startsWith('..')) return null;
|
|
60
|
+
return rel.split(path.sep).join('/');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Lexical (no-symlink-resolution) relative path: what the path CLAIMS to be.
|
|
64
|
+
// Tried against both the raw and the realpathed project root so /tmp-style
|
|
65
|
+
// root symlinks don't break matching. Guards must compare this against
|
|
66
|
+
// toPosixRel — a divergence means a symlink sits inside the project.
|
|
67
|
+
export function lexicalPosixRel(projectRoot, absPath) {
|
|
68
|
+
const abs = path.resolve(absPath);
|
|
69
|
+
const realRoot = realResolve(projectRoot);
|
|
70
|
+
for (const base of [path.resolve(projectRoot), realRoot]) {
|
|
71
|
+
const rel = path.relative(base, abs);
|
|
72
|
+
if (rel && !rel.startsWith('..') && !path.isAbsolute(rel)) {
|
|
73
|
+
return rel.split(path.sep).join('/');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Root-level symlinks (/tmp → /private/tmp): find the SHALLOWEST ancestor of
|
|
77
|
+
// abs whose realpath IS the project root; the remaining tail is the lexical
|
|
78
|
+
// claim. In-project symlinks are deliberately not resolved here.
|
|
79
|
+
const segs = abs.split(path.sep);
|
|
80
|
+
for (let i = 1; i < segs.length; i++) {
|
|
81
|
+
const ancestor = segs.slice(0, i).join(path.sep) || path.sep;
|
|
82
|
+
let real;
|
|
83
|
+
try { real = fs.realpathSync.native(ancestor); } catch { continue; }
|
|
84
|
+
if (real === realRoot) {
|
|
85
|
+
const tail = segs.slice(i).join('/');
|
|
86
|
+
return tail || null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Gate state written by `journal.mjs open-<phase>` — {phase, change?, expires}.
|
|
93
|
+
export function readPhase(sdlcRoot) {
|
|
94
|
+
try {
|
|
95
|
+
const raw = fs.readFileSync(path.join(sdlcRoot, '.state', 'phase.json'), 'utf8');
|
|
96
|
+
const phase = JSON.parse(raw);
|
|
97
|
+
if (phase.expires && Date.parse(phase.expires) < Date.now()) return null;
|
|
98
|
+
return phase;
|
|
99
|
+
} catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function writePhase(sdlcRoot, phase, ttlMinutes = 30) {
|
|
105
|
+
const stateDir = path.join(sdlcRoot, '.state');
|
|
106
|
+
fs.mkdirSync(stateDir, { recursive: true });
|
|
107
|
+
const payload = { ...phase, expires: new Date(Date.now() + ttlMinutes * 60_000).toISOString() };
|
|
108
|
+
fs.writeFileSync(path.join(stateDir, 'phase.json'), JSON.stringify(payload));
|
|
109
|
+
return payload;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function clearPhase(sdlcRoot) {
|
|
113
|
+
fs.rmSync(path.join(sdlcRoot, '.state', 'phase.json'), { force: true });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Active change: explicit .state/active.json first, else the most recently
|
|
117
|
+
// modified changes/*/change.md.
|
|
118
|
+
export function activeChange(sdlcRoot) {
|
|
119
|
+
try {
|
|
120
|
+
const explicit = JSON.parse(fs.readFileSync(path.join(sdlcRoot, '.state', 'active.json'), 'utf8'));
|
|
121
|
+
if (explicit?.change && fs.existsSync(path.join(sdlcRoot, 'changes', explicit.change))) {
|
|
122
|
+
return explicit.change;
|
|
123
|
+
}
|
|
124
|
+
} catch { /* fall through */ }
|
|
125
|
+
const changesDir = path.join(sdlcRoot, 'changes');
|
|
126
|
+
if (!fs.existsSync(changesDir)) return null;
|
|
127
|
+
let best = null;
|
|
128
|
+
for (const d of fs.readdirSync(changesDir, { withFileTypes: true })) {
|
|
129
|
+
if (!d.isDirectory() || d.name === 'archive') continue;
|
|
130
|
+
const p = path.join(changesDir, d.name, 'change.md');
|
|
131
|
+
if (!fs.existsSync(p)) continue;
|
|
132
|
+
const mtime = fs.statSync(p).mtimeMs;
|
|
133
|
+
if (!best || mtime > best.mtime) best = { change: d.name, mtime };
|
|
134
|
+
}
|
|
135
|
+
return best?.change ?? null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Journal: per-change ndjson when a change is active, else a global one under
|
|
139
|
+
// .state/ so no signal is lost. Hook-written only — agents never hand-edit.
|
|
140
|
+
export function appendJournal(sdlcRoot, change, event) {
|
|
141
|
+
try {
|
|
142
|
+
const line = JSON.stringify({ ts: new Date().toISOString(), ...event }) + '\n';
|
|
143
|
+
if (change) {
|
|
144
|
+
const dir = path.join(sdlcRoot, 'changes', change);
|
|
145
|
+
if (fs.existsSync(dir)) {
|
|
146
|
+
fs.appendFileSync(path.join(dir, 'journal.ndjson'), line);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const stateDir = path.join(sdlcRoot, '.state');
|
|
151
|
+
fs.mkdirSync(stateDir, { recursive: true });
|
|
152
|
+
fs.appendFileSync(path.join(stateDir, 'journal.ndjson'), line);
|
|
153
|
+
} catch { /* fail open */ }
|
|
154
|
+
}
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// PreToolUse hook — the deterministic guardrail ("things the agent should
|
|
3
|
-
// never forget but often does"). Denies direct edits to:
|
|
4
|
-
// sdlc/specs/** outside an open ship gate
|
|
5
|
-
// sdlc/changes/archive/** outside an open ship gate
|
|
6
|
-
// sdlc/context/constitution.md (existing) outside an open steer gate
|
|
7
|
-
// sdlc/.state/** and any journal.ndjson always (machine-owned)
|
|
8
|
-
// The sanctioned paths are the CLI (`warnyin-sdlc archive`) and the gates
|
|
9
|
-
// opened by `journal.mjs open-ship|open-steer`.
|
|
10
|
-
|
|
11
|
-
import fs from 'node:fs';
|
|
12
|
-
import process from 'node:process';
|
|
13
|
-
import path from 'node:path';
|
|
14
|
-
import {
|
|
15
|
-
resolveRoots, readStdinJson, readPhase, activeChange, appendJournal, toPosixRel, lexicalPosixRel,
|
|
16
|
-
} from './_shared.mjs';
|
|
17
|
-
|
|
18
|
-
const { sdlcRoot, projectRoot } = resolveRoots(import.meta.url);
|
|
19
|
-
|
|
20
|
-
function deny(reason, rel) {
|
|
21
|
-
appendJournal(sdlcRoot, activeChange(sdlcRoot), { event: 'guard', action: 'deny', path: rel, reason });
|
|
22
|
-
console.log(JSON.stringify({
|
|
23
|
-
hookSpecificOutput: {
|
|
24
|
-
hookEventName: 'PreToolUse',
|
|
25
|
-
permissionDecision: 'deny',
|
|
26
|
-
permissionDecisionReason: reason,
|
|
27
|
-
},
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Evaluate the lock rules against ONE view of the path. Returns true when a
|
|
32
|
-
// deny was emitted. Rules must hold for BOTH the lexical (claimed) and the
|
|
33
|
-
// realpath-resolved view — a symlink must never weaken a lock.
|
|
34
|
-
function guard(rel, phase) {
|
|
35
|
-
if (rel.startsWith('sdlc/.state/') || rel.endsWith('journal.ndjson')) {
|
|
36
|
-
deny(`"${rel}" is machine-owned (hooks/CLI write it) — never edit it by hand.`, rel);
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
if (rel.startsWith('sdlc/specs/') || rel.startsWith('sdlc/changes/archive/')) {
|
|
40
|
-
if (phase?.phase === 'ship') return false;
|
|
41
|
-
deny(
|
|
42
|
-
`"${rel}" is write-locked outside ship. Living specs change only by merging a change's Delta: `
|
|
43
|
-
+ 'run `warnyin-sdlc archive <id>` (or `node sdlc/.hooks/journal.mjs open-ship <id>` first if you must edit).',
|
|
44
|
-
rel,
|
|
45
|
-
);
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
if (rel === 'sdlc/context/constitution.md' && fs.existsSync(path.join(projectRoot, rel))) {
|
|
49
|
-
if (phase?.phase === 'steer' || phase?.phase === 'ship') return false;
|
|
50
|
-
deny(
|
|
51
|
-
'The constitution is always-loaded context — edits go through /sdlc:steer '
|
|
52
|
-
+ '(`node sdlc/.hooks/journal.mjs open-steer` opens the gate).',
|
|
53
|
-
rel,
|
|
54
|
-
);
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async function main() {
|
|
61
|
-
const input = await readStdinJson();
|
|
62
|
-
const filePath = input?.tool_input?.file_path ?? input?.tool_input?.notebook_path;
|
|
63
|
-
if (!filePath || !fs.existsSync(sdlcRoot)) return;
|
|
64
|
-
|
|
65
|
-
const abs = path.resolve(projectRoot, filePath);
|
|
66
|
-
const relLexical = lexicalPosixRel(projectRoot, abs);
|
|
67
|
-
const relReal = toPosixRel(projectRoot, abs);
|
|
68
|
-
|
|
69
|
-
// A path that CLAIMS to live under sdlc/ but resolves elsewhere (or out of
|
|
70
|
-
// the project) went through a symlink — deny conservatively; a symlink must
|
|
71
|
-
// never disable the write-lock.
|
|
72
|
-
if (relLexical?.startsWith('sdlc/') && relReal !== relLexical) {
|
|
73
|
-
deny(`"${relLexical}" resolves through a symlink to "${relReal ?? 'outside the project'}" — refusing to touch it.`, relLexical);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const phase = readPhase(sdlcRoot);
|
|
78
|
-
for (const rel of new Set([relLexical, relReal].filter(Boolean))) {
|
|
79
|
-
if (rel.startsWith('sdlc/') && guard(rel, phase)) return;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
main().catch(() => process.exit(0)); // fail open
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// PreToolUse hook — the deterministic guardrail ("things the agent should
|
|
3
|
+
// never forget but often does"). Denies direct edits to:
|
|
4
|
+
// sdlc/specs/** outside an open ship gate
|
|
5
|
+
// sdlc/changes/archive/** outside an open ship gate
|
|
6
|
+
// sdlc/context/constitution.md (existing) outside an open steer gate
|
|
7
|
+
// sdlc/.state/** and any journal.ndjson always (machine-owned)
|
|
8
|
+
// The sanctioned paths are the CLI (`warnyin-sdlc archive`) and the gates
|
|
9
|
+
// opened by `journal.mjs open-ship|open-steer`.
|
|
10
|
+
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import process from 'node:process';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import {
|
|
15
|
+
resolveRoots, readStdinJson, readPhase, activeChange, appendJournal, toPosixRel, lexicalPosixRel,
|
|
16
|
+
} from './_shared.mjs';
|
|
17
|
+
|
|
18
|
+
const { sdlcRoot, projectRoot } = resolveRoots(import.meta.url);
|
|
19
|
+
|
|
20
|
+
function deny(reason, rel) {
|
|
21
|
+
appendJournal(sdlcRoot, activeChange(sdlcRoot), { event: 'guard', action: 'deny', path: rel, reason });
|
|
22
|
+
console.log(JSON.stringify({
|
|
23
|
+
hookSpecificOutput: {
|
|
24
|
+
hookEventName: 'PreToolUse',
|
|
25
|
+
permissionDecision: 'deny',
|
|
26
|
+
permissionDecisionReason: reason,
|
|
27
|
+
},
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Evaluate the lock rules against ONE view of the path. Returns true when a
|
|
32
|
+
// deny was emitted. Rules must hold for BOTH the lexical (claimed) and the
|
|
33
|
+
// realpath-resolved view — a symlink must never weaken a lock.
|
|
34
|
+
function guard(rel, phase) {
|
|
35
|
+
if (rel.startsWith('sdlc/.state/') || rel.endsWith('journal.ndjson')) {
|
|
36
|
+
deny(`"${rel}" is machine-owned (hooks/CLI write it) — never edit it by hand.`, rel);
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
if (rel.startsWith('sdlc/specs/') || rel.startsWith('sdlc/changes/archive/')) {
|
|
40
|
+
if (phase?.phase === 'ship') return false;
|
|
41
|
+
deny(
|
|
42
|
+
`"${rel}" is write-locked outside ship. Living specs change only by merging a change's Delta: `
|
|
43
|
+
+ 'run `warnyin-sdlc archive <id>` (or `node sdlc/.hooks/journal.mjs open-ship <id>` first if you must edit).',
|
|
44
|
+
rel,
|
|
45
|
+
);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if (rel === 'sdlc/context/constitution.md' && fs.existsSync(path.join(projectRoot, rel))) {
|
|
49
|
+
if (phase?.phase === 'steer' || phase?.phase === 'ship') return false;
|
|
50
|
+
deny(
|
|
51
|
+
'The constitution is always-loaded context — edits go through /sdlc:steer '
|
|
52
|
+
+ '(`node sdlc/.hooks/journal.mjs open-steer` opens the gate).',
|
|
53
|
+
rel,
|
|
54
|
+
);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function main() {
|
|
61
|
+
const input = await readStdinJson();
|
|
62
|
+
const filePath = input?.tool_input?.file_path ?? input?.tool_input?.notebook_path;
|
|
63
|
+
if (!filePath || !fs.existsSync(sdlcRoot)) return;
|
|
64
|
+
|
|
65
|
+
const abs = path.resolve(projectRoot, filePath);
|
|
66
|
+
const relLexical = lexicalPosixRel(projectRoot, abs);
|
|
67
|
+
const relReal = toPosixRel(projectRoot, abs);
|
|
68
|
+
|
|
69
|
+
// A path that CLAIMS to live under sdlc/ but resolves elsewhere (or out of
|
|
70
|
+
// the project) went through a symlink — deny conservatively; a symlink must
|
|
71
|
+
// never disable the write-lock.
|
|
72
|
+
if (relLexical?.startsWith('sdlc/') && relReal !== relLexical) {
|
|
73
|
+
deny(`"${relLexical}" resolves through a symlink to "${relReal ?? 'outside the project'}" — refusing to touch it.`, relLexical);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const phase = readPhase(sdlcRoot);
|
|
78
|
+
for (const rel of new Set([relLexical, relReal].filter(Boolean))) {
|
|
79
|
+
if (rel.startsWith('sdlc/') && guard(rel, phase)) return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
main().catch(() => process.exit(0)); // fail open
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// SessionStart hook — THE static-context loader. Emits (hard cap 60 lines):
|
|
3
|
-
// constitution + every `inclusion: always` steering file + a one-line
|
|
4
|
-
// pointer to the active change. Everything else stays dynamic.
|
|
5
|
-
// Journals what was injected so /sdlc:observe can price residency honestly.
|
|
6
|
-
|
|
7
|
-
import fs from 'node:fs';
|
|
8
|
-
import path from 'node:path';
|
|
9
|
-
import process from 'node:process';
|
|
10
|
-
import { resolveRoots, readStdinJson, activeChange, appendJournal } from './_shared.mjs';
|
|
11
|
-
import { parseFrontmatter } from './lib/frontmatter.mjs';
|
|
12
|
-
import { CAPS } from './lib/caps.mjs';
|
|
13
|
-
|
|
14
|
-
const { sdlcRoot } = resolveRoots(import.meta.url);
|
|
15
|
-
|
|
16
|
-
async function main() {
|
|
17
|
-
await readStdinJson(); // drain; content not needed
|
|
18
|
-
if (!fs.existsSync(sdlcRoot)) return;
|
|
19
|
-
|
|
20
|
-
const injected = [];
|
|
21
|
-
const out = [];
|
|
22
|
-
|
|
23
|
-
const constitutionPath = path.join(sdlcRoot, 'context', 'constitution.md');
|
|
24
|
-
if (fs.existsSync(constitutionPath)) {
|
|
25
|
-
out.push(fs.readFileSync(constitutionPath, 'utf8').trim());
|
|
26
|
-
injected.push('context/constitution.md');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const steeringDir = path.join(sdlcRoot, 'context', 'steering');
|
|
30
|
-
if (fs.existsSync(steeringDir)) {
|
|
31
|
-
for (const f of fs.readdirSync(steeringDir).filter((n) => n.endsWith('.md')).sort()) {
|
|
32
|
-
const raw = fs.readFileSync(path.join(steeringDir, f), 'utf8');
|
|
33
|
-
const { data, body } = parseFrontmatter(raw);
|
|
34
|
-
if (data.inclusion !== 'always') continue;
|
|
35
|
-
out.push(body.trim());
|
|
36
|
-
injected.push(`context/steering/${f}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const active = activeChange(sdlcRoot);
|
|
41
|
-
if (active) out.push(`Active change: sdlc/changes/${active}/change.md — run /sdlc:next for status.`);
|
|
42
|
-
|
|
43
|
-
if (!out.length) return;
|
|
44
|
-
|
|
45
|
-
let lines = out.join('\n\n').split('\n');
|
|
46
|
-
if (lines.length > CAPS.alwaysBudget) {
|
|
47
|
-
lines = lines.slice(0, CAPS.alwaysBudget);
|
|
48
|
-
lines.push(`[sdlc] static context truncated at ${CAPS.alwaysBudget} lines — run /sdlc:steer to distill (validate also flags this).`);
|
|
49
|
-
}
|
|
50
|
-
console.log(lines.join('\n'));
|
|
51
|
-
|
|
52
|
-
appendJournal(sdlcRoot, active, { event: 'inject', files: injected, lines: lines.length });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
main().catch(() => process.exit(0)); // fail open
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SessionStart hook — THE static-context loader. Emits (hard cap 60 lines):
|
|
3
|
+
// constitution + every `inclusion: always` steering file + a one-line
|
|
4
|
+
// pointer to the active change. Everything else stays dynamic.
|
|
5
|
+
// Journals what was injected so /sdlc:observe can price residency honestly.
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import process from 'node:process';
|
|
10
|
+
import { resolveRoots, readStdinJson, activeChange, appendJournal } from './_shared.mjs';
|
|
11
|
+
import { parseFrontmatter } from './lib/frontmatter.mjs';
|
|
12
|
+
import { CAPS } from './lib/caps.mjs';
|
|
13
|
+
|
|
14
|
+
const { sdlcRoot } = resolveRoots(import.meta.url);
|
|
15
|
+
|
|
16
|
+
async function main() {
|
|
17
|
+
await readStdinJson(); // drain; content not needed
|
|
18
|
+
if (!fs.existsSync(sdlcRoot)) return;
|
|
19
|
+
|
|
20
|
+
const injected = [];
|
|
21
|
+
const out = [];
|
|
22
|
+
|
|
23
|
+
const constitutionPath = path.join(sdlcRoot, 'context', 'constitution.md');
|
|
24
|
+
if (fs.existsSync(constitutionPath)) {
|
|
25
|
+
out.push(fs.readFileSync(constitutionPath, 'utf8').trim());
|
|
26
|
+
injected.push('context/constitution.md');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const steeringDir = path.join(sdlcRoot, 'context', 'steering');
|
|
30
|
+
if (fs.existsSync(steeringDir)) {
|
|
31
|
+
for (const f of fs.readdirSync(steeringDir).filter((n) => n.endsWith('.md')).sort()) {
|
|
32
|
+
const raw = fs.readFileSync(path.join(steeringDir, f), 'utf8');
|
|
33
|
+
const { data, body } = parseFrontmatter(raw);
|
|
34
|
+
if (data.inclusion !== 'always') continue;
|
|
35
|
+
out.push(body.trim());
|
|
36
|
+
injected.push(`context/steering/${f}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const active = activeChange(sdlcRoot);
|
|
41
|
+
if (active) out.push(`Active change: sdlc/changes/${active}/change.md — run /sdlc:next for status.`);
|
|
42
|
+
|
|
43
|
+
if (!out.length) return;
|
|
44
|
+
|
|
45
|
+
let lines = out.join('\n\n').split('\n');
|
|
46
|
+
if (lines.length > CAPS.alwaysBudget) {
|
|
47
|
+
lines = lines.slice(0, CAPS.alwaysBudget);
|
|
48
|
+
lines.push(`[sdlc] static context truncated at ${CAPS.alwaysBudget} lines — run /sdlc:steer to distill (validate also flags this).`);
|
|
49
|
+
}
|
|
50
|
+
console.log(lines.join('\n'));
|
|
51
|
+
|
|
52
|
+
appendJournal(sdlcRoot, active, { event: 'inject', files: injected, lines: lines.length });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
main().catch(() => process.exit(0)); // fail open
|