@warnyin/sdlc 0.5.2 → 0.7.0
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 +228 -172
- package/LICENSE +21 -21
- package/README.md +1 -1
- package/bin/cli.mjs +668 -596
- package/lib/active.mjs +199 -0
- package/lib/caps.mjs +45 -45
- package/lib/config.mjs +41 -41
- package/lib/delta.mjs +227 -227
- package/lib/frontmatter.mjs +59 -59
- package/lib/glob.mjs +29 -29
- package/lib/journal.mjs +128 -0
- package/lib/manifest.mjs +99 -99
- package/lib/observe.mjs +19 -16
- package/lib/settings-merge.mjs +63 -63
- package/lib/validate.mjs +196 -196
- 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 -36
- package/payload/adapters/claude/skills/sdlc-conventions/SKILL.md +29 -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 +138 -154
- package/payload/hooks/guard-writes.mjs +87 -83
- package/payload/hooks/inject-context.mjs +57 -55
- package/payload/hooks/journal.mjs +66 -58
- package/payload/hooks/session-summary.mjs +52 -50
- package/payload/hooks/validate-artifact.mjs +84 -80
- package/payload/playbook/auto.md +12 -0
- package/payload/playbook/context.md +26 -26
- package/payload/playbook/converge.md +19 -19
- package/payload/playbook/init.md +22 -22
- package/payload/playbook/next.md +24 -14
- 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 +35 -35
- 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,138 @@
|
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
process.stdin.on('
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
cur
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
fs.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
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
|
+
import { liveJournalPath, globalJournalPath, appendEvent } from './lib/journal.mjs';
|
|
11
|
+
import { resolveActive } from './lib/active.mjs';
|
|
12
|
+
|
|
13
|
+
export function resolveRoots(importMetaUrl) {
|
|
14
|
+
const hooksDir = path.dirname(fileURLToPath(importMetaUrl));
|
|
15
|
+
const sdlcRoot = path.dirname(hooksDir);
|
|
16
|
+
const projectRoot = path.dirname(sdlcRoot);
|
|
17
|
+
return { hooksDir, sdlcRoot, projectRoot };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Reads the hook payload from stdin. Must NEVER hang: when a playbook or a
|
|
21
|
+
// user script invokes a hook utility with stdin open-but-idle (no piped JSON),
|
|
22
|
+
// resolve null after a short grace period instead of blocking forever.
|
|
23
|
+
export function readStdinJson({ timeoutMs = 1000 } = {}) {
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
let data = '';
|
|
26
|
+
let done = false;
|
|
27
|
+
const finish = () => {
|
|
28
|
+
if (done) return;
|
|
29
|
+
done = true;
|
|
30
|
+
// Release stdin so an open-idle stream cannot keep the event loop alive.
|
|
31
|
+
process.stdin.pause();
|
|
32
|
+
if (typeof process.stdin.unref === 'function') process.stdin.unref();
|
|
33
|
+
try { resolve(data.trim() ? JSON.parse(data) : null); } catch { resolve(null); }
|
|
34
|
+
};
|
|
35
|
+
const timer = setTimeout(finish, timeoutMs);
|
|
36
|
+
if (typeof timer.unref === 'function') timer.unref();
|
|
37
|
+
process.stdin.on('data', (chunk) => { data += chunk; });
|
|
38
|
+
process.stdin.on('end', finish);
|
|
39
|
+
process.stdin.on('error', finish);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Resolve symlinks on the deepest EXISTING ancestor, then re-attach the tail.
|
|
44
|
+
// Needed because import.meta.url is symlink-resolved while tool file_paths may
|
|
45
|
+
// arrive through a symlink (/tmp → /private/tmp on macOS).
|
|
46
|
+
export function realResolve(p) {
|
|
47
|
+
let cur = path.resolve(p);
|
|
48
|
+
const tail = [];
|
|
49
|
+
while (!fs.existsSync(cur)) {
|
|
50
|
+
const parent = path.dirname(cur);
|
|
51
|
+
if (parent === cur) break;
|
|
52
|
+
tail.unshift(path.basename(cur));
|
|
53
|
+
cur = parent;
|
|
54
|
+
}
|
|
55
|
+
try { cur = fs.realpathSync.native(cur); } catch { /* keep as-is */ }
|
|
56
|
+
return tail.length ? path.join(cur, ...tail) : cur;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function toPosixRel(projectRoot, absPath) {
|
|
60
|
+
const rel = path.relative(realResolve(projectRoot), realResolve(absPath));
|
|
61
|
+
if (rel.startsWith('..')) return null;
|
|
62
|
+
return rel.split(path.sep).join('/');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Lexical (no-symlink-resolution) relative path: what the path CLAIMS to be.
|
|
66
|
+
// Tried against both the raw and the realpathed project root so /tmp-style
|
|
67
|
+
// root symlinks don't break matching. Guards must compare this against
|
|
68
|
+
// toPosixRel — a divergence means a symlink sits inside the project.
|
|
69
|
+
export function lexicalPosixRel(projectRoot, absPath) {
|
|
70
|
+
const abs = path.resolve(absPath);
|
|
71
|
+
const realRoot = realResolve(projectRoot);
|
|
72
|
+
for (const base of [path.resolve(projectRoot), realRoot]) {
|
|
73
|
+
const rel = path.relative(base, abs);
|
|
74
|
+
if (rel && !rel.startsWith('..') && !path.isAbsolute(rel)) {
|
|
75
|
+
return rel.split(path.sep).join('/');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Root-level symlinks (/tmp → /private/tmp): find the SHALLOWEST ancestor of
|
|
79
|
+
// abs whose realpath IS the project root; the remaining tail is the lexical
|
|
80
|
+
// claim. In-project symlinks are deliberately not resolved here.
|
|
81
|
+
const segs = abs.split(path.sep);
|
|
82
|
+
for (let i = 1; i < segs.length; i++) {
|
|
83
|
+
const ancestor = segs.slice(0, i).join(path.sep) || path.sep;
|
|
84
|
+
let real;
|
|
85
|
+
try { real = fs.realpathSync.native(ancestor); } catch { continue; }
|
|
86
|
+
if (real === realRoot) {
|
|
87
|
+
const tail = segs.slice(i).join('/');
|
|
88
|
+
return tail || null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Gate state written by `journal.mjs open-<phase>` — {phase, change?, expires}.
|
|
95
|
+
export function readPhase(sdlcRoot) {
|
|
96
|
+
try {
|
|
97
|
+
const raw = fs.readFileSync(path.join(sdlcRoot, '.state', 'phase.json'), 'utf8');
|
|
98
|
+
const phase = JSON.parse(raw);
|
|
99
|
+
if (phase.expires && Date.parse(phase.expires) < Date.now()) return null;
|
|
100
|
+
return phase;
|
|
101
|
+
} catch {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function writePhase(sdlcRoot, phase, ttlMinutes = 30) {
|
|
107
|
+
const stateDir = path.join(sdlcRoot, '.state');
|
|
108
|
+
fs.mkdirSync(stateDir, { recursive: true });
|
|
109
|
+
const payload = { ...phase, expires: new Date(Date.now() + ttlMinutes * 60_000).toISOString() };
|
|
110
|
+
fs.writeFileSync(path.join(stateDir, 'phase.json'), JSON.stringify(payload));
|
|
111
|
+
return payload;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function clearPhase(sdlcRoot) {
|
|
115
|
+
fs.rmSync(path.join(sdlcRoot, '.state', 'phase.json'), { force: true });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Active change: session pointer, then project pointer, then the most recently
|
|
119
|
+
// modified changes/*/change.md — resolution lives in lib/active.mjs so the CLI's
|
|
120
|
+
// `status` answers the same question the hooks do. Callers still get just the id
|
|
121
|
+
// (the `recent` fallback still attributes hook events, it just isn't reported as
|
|
122
|
+
// confirmed by `status`).
|
|
123
|
+
export function activeChange(sdlcRoot, sessionId = null) {
|
|
124
|
+
return resolveActive(sdlcRoot, { sessionId })?.change ?? null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Journal: per-change ndjson when a change is active, else a global one — both under
|
|
128
|
+
// .state/, which is gitignored, so a session never dirties a version-controlled file
|
|
129
|
+
// just by running. Hook-written only — agents never hand-edit.
|
|
130
|
+
//
|
|
131
|
+
// Attribution does not depend on the change folder existing: a stale active pointer
|
|
132
|
+
// still records the event under that id rather than silently reattributing it.
|
|
133
|
+
export function appendJournal(sdlcRoot, change, event) {
|
|
134
|
+
try {
|
|
135
|
+
const target = (change && liveJournalPath(sdlcRoot, change)) || globalJournalPath(sdlcRoot);
|
|
136
|
+
appendEvent(target, { ts: new Date().toISOString(), ...event });
|
|
137
|
+
} catch { /* fail open */ }
|
|
138
|
+
}
|
|
@@ -1,83 +1,87 @@
|
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
import { pickSessionId } from './lib/active.mjs';
|
|
18
|
+
|
|
19
|
+
const { sdlcRoot, projectRoot } = resolveRoots(import.meta.url);
|
|
20
|
+
|
|
21
|
+
function deny(reason, rel, sessionId) {
|
|
22
|
+
appendJournal(sdlcRoot, activeChange(sdlcRoot, sessionId), { event: 'guard', action: 'deny', path: rel, reason });
|
|
23
|
+
console.log(JSON.stringify({
|
|
24
|
+
hookSpecificOutput: {
|
|
25
|
+
hookEventName: 'PreToolUse',
|
|
26
|
+
permissionDecision: 'deny',
|
|
27
|
+
permissionDecisionReason: reason,
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Evaluate the lock rules against ONE view of the path. Returns true when a
|
|
33
|
+
// deny was emitted. Rules must hold for BOTH the lexical (claimed) and the
|
|
34
|
+
// realpath-resolved view — a symlink must never weaken a lock.
|
|
35
|
+
function guard(rel, phase, sessionId) {
|
|
36
|
+
if (rel.startsWith('sdlc/.state/') || rel.endsWith('journal.ndjson')) {
|
|
37
|
+
deny(`"${rel}" is machine-owned (hooks/CLI write it) — never edit it by hand.`, rel, sessionId);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (rel.startsWith('sdlc/specs/') || rel.startsWith('sdlc/changes/archive/')) {
|
|
41
|
+
if (phase?.phase === 'ship') return false;
|
|
42
|
+
deny(
|
|
43
|
+
`"${rel}" is write-locked outside ship. Living specs change only by merging a change's Delta: `
|
|
44
|
+
+ 'run `warnyin-sdlc archive <id>` (or `node sdlc/.hooks/journal.mjs open-ship <id>` first if you must edit).',
|
|
45
|
+
rel,
|
|
46
|
+
sessionId,
|
|
47
|
+
);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
if (rel === 'sdlc/context/constitution.md' && fs.existsSync(path.join(projectRoot, rel))) {
|
|
51
|
+
if (phase?.phase === 'steer' || phase?.phase === 'ship') return false;
|
|
52
|
+
deny(
|
|
53
|
+
'The constitution is always-loaded context — edits go through /sdlc:steer '
|
|
54
|
+
+ '(`node sdlc/.hooks/journal.mjs open-steer` opens the gate).',
|
|
55
|
+
rel,
|
|
56
|
+
sessionId,
|
|
57
|
+
);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function main() {
|
|
64
|
+
const input = await readStdinJson();
|
|
65
|
+
const filePath = input?.tool_input?.file_path ?? input?.tool_input?.notebook_path;
|
|
66
|
+
if (!filePath || !fs.existsSync(sdlcRoot)) return;
|
|
67
|
+
|
|
68
|
+
const sessionId = pickSessionId(input?.session_id, process.env.CLAUDE_CODE_SESSION_ID);
|
|
69
|
+
const abs = path.resolve(projectRoot, filePath);
|
|
70
|
+
const relLexical = lexicalPosixRel(projectRoot, abs);
|
|
71
|
+
const relReal = toPosixRel(projectRoot, abs);
|
|
72
|
+
|
|
73
|
+
// A path that CLAIMS to live under sdlc/ but resolves elsewhere (or out of
|
|
74
|
+
// the project) went through a symlink — deny conservatively; a symlink must
|
|
75
|
+
// never disable the write-lock.
|
|
76
|
+
if (relLexical?.startsWith('sdlc/') && relReal !== relLexical) {
|
|
77
|
+
deny(`"${relLexical}" resolves through a symlink to "${relReal ?? 'outside the project'}" — refusing to touch it.`, relLexical, sessionId);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const phase = readPhase(sdlcRoot);
|
|
82
|
+
for (const rel of new Set([relLexical, relReal].filter(Boolean))) {
|
|
83
|
+
if (rel.startsWith('sdlc/') && guard(rel, phase, sessionId)) return;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
main().catch(() => process.exit(0)); // fail open
|
|
@@ -1,55 +1,57 @@
|
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
+
import { pickSessionId } from './lib/active.mjs';
|
|
14
|
+
|
|
15
|
+
const { sdlcRoot } = resolveRoots(import.meta.url);
|
|
16
|
+
|
|
17
|
+
async function main() {
|
|
18
|
+
const input = await readStdinJson();
|
|
19
|
+
if (!fs.existsSync(sdlcRoot)) return;
|
|
20
|
+
const sessionId = pickSessionId(input?.session_id, process.env.CLAUDE_CODE_SESSION_ID);
|
|
21
|
+
|
|
22
|
+
const injected = [];
|
|
23
|
+
const out = [];
|
|
24
|
+
|
|
25
|
+
const constitutionPath = path.join(sdlcRoot, 'context', 'constitution.md');
|
|
26
|
+
if (fs.existsSync(constitutionPath)) {
|
|
27
|
+
out.push(fs.readFileSync(constitutionPath, 'utf8').trim());
|
|
28
|
+
injected.push('context/constitution.md');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const steeringDir = path.join(sdlcRoot, 'context', 'steering');
|
|
32
|
+
if (fs.existsSync(steeringDir)) {
|
|
33
|
+
for (const f of fs.readdirSync(steeringDir).filter((n) => n.endsWith('.md')).sort()) {
|
|
34
|
+
const raw = fs.readFileSync(path.join(steeringDir, f), 'utf8');
|
|
35
|
+
const { data, body } = parseFrontmatter(raw);
|
|
36
|
+
if (data.inclusion !== 'always') continue;
|
|
37
|
+
out.push(body.trim());
|
|
38
|
+
injected.push(`context/steering/${f}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const active = activeChange(sdlcRoot, sessionId);
|
|
43
|
+
if (active) out.push(`Active change: sdlc/changes/${active}/change.md — run /sdlc:next for status.`);
|
|
44
|
+
|
|
45
|
+
if (!out.length) return;
|
|
46
|
+
|
|
47
|
+
let lines = out.join('\n\n').split('\n');
|
|
48
|
+
if (lines.length > CAPS.alwaysBudget) {
|
|
49
|
+
lines = lines.slice(0, CAPS.alwaysBudget);
|
|
50
|
+
lines.push(`[sdlc] static context truncated at ${CAPS.alwaysBudget} lines — run /sdlc:steer to distill (validate also flags this).`);
|
|
51
|
+
}
|
|
52
|
+
console.log(lines.join('\n'));
|
|
53
|
+
|
|
54
|
+
appendJournal(sdlcRoot, active, { event: 'inject', files: injected, lines: lines.length });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
main().catch(() => process.exit(0)); // fail open
|