slicekit 0.0.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +252 -3
  3. package/bin/slicekit.js +4 -0
  4. package/package.json +21 -4
  5. package/src/adapters/githost/errors.js +17 -0
  6. package/src/adapters/githost/fixture.js +136 -0
  7. package/src/adapters/githost/gh-json.js +99 -0
  8. package/src/adapters/githost/github.js +127 -0
  9. package/src/adapters/githost/index.js +12 -0
  10. package/src/adapters/tracker/errors.js +53 -0
  11. package/src/adapters/tracker/fixture.js +71 -0
  12. package/src/adapters/tracker/github-issues.js +65 -0
  13. package/src/adapters/tracker/index.js +14 -0
  14. package/src/baseline.js +109 -0
  15. package/src/build/commit.js +201 -0
  16. package/src/build/decline.js +81 -0
  17. package/src/build/finish.js +155 -0
  18. package/src/build/order.js +158 -0
  19. package/src/build/overlap.js +173 -0
  20. package/src/build/parallel.js +50 -0
  21. package/src/build/pr.js +263 -0
  22. package/src/build/record.js +28 -0
  23. package/src/build/red.js +207 -0
  24. package/src/build/review.js +123 -0
  25. package/src/build/sync.js +47 -0
  26. package/src/build/verdict.js +410 -0
  27. package/src/build/worktree.js +169 -0
  28. package/src/check/ci-event.js +52 -0
  29. package/src/check/context.js +129 -0
  30. package/src/check/index.js +140 -0
  31. package/src/check/rules/.gitkeep +0 -0
  32. package/src/check/rules/ci-body.js +22 -0
  33. package/src/check/rules/ci-title.js +43 -0
  34. package/src/check/rules/citations.js +224 -0
  35. package/src/check/rules/commands.js +146 -0
  36. package/src/check/rules/coverage.js +248 -0
  37. package/src/check/rules/hooks.js +58 -0
  38. package/src/check/rules/journal.js +17 -0
  39. package/src/check/rules/layout.js +56 -0
  40. package/src/check/rules/managed.js +31 -0
  41. package/src/check/rules/queue.js +106 -0
  42. package/src/check/rules/references.js +249 -0
  43. package/src/check/rules/style.js +177 -0
  44. package/src/check/rules/trailer.js +67 -0
  45. package/src/cli/baseline.js +66 -0
  46. package/src/cli/branch.js +86 -0
  47. package/src/cli/build.js +239 -0
  48. package/src/cli/check.js +40 -0
  49. package/src/cli/decide.js +59 -0
  50. package/src/cli/gaps.js +73 -0
  51. package/src/cli/hook.js +28 -0
  52. package/src/cli/index.js +83 -0
  53. package/src/cli/init.js +96 -0
  54. package/src/cli/instructions.js +63 -0
  55. package/src/cli/intake.js +107 -0
  56. package/src/cli/journal.js +82 -0
  57. package/src/cli/plan.js +29 -0
  58. package/src/cli/pr.js +83 -0
  59. package/src/cli/process.js +59 -0
  60. package/src/cli/ready-label.js +119 -0
  61. package/src/cli/review.js +64 -0
  62. package/src/cli/spec.js +31 -0
  63. package/src/cli/stage.js +37 -0
  64. package/src/cli/state.js +106 -0
  65. package/src/cli/status.js +108 -0
  66. package/src/cli/update.js +62 -0
  67. package/src/cli/workflow.js +48 -0
  68. package/src/config.js +203 -0
  69. package/src/decisions.js +289 -0
  70. package/src/evidence.js +27 -0
  71. package/src/fs.js +38 -0
  72. package/src/gaps.js +271 -0
  73. package/src/git.js +209 -0
  74. package/src/githooks.js +37 -0
  75. package/src/hook-cli.js +63 -0
  76. package/src/hooks/io.js +205 -0
  77. package/src/hooks/paths.js +82 -0
  78. package/src/hooks/pre-bash.js +715 -0
  79. package/src/hooks/pre-compact.js +139 -0
  80. package/src/hooks/pre-edit.js +170 -0
  81. package/src/hooks/session-end.js +118 -0
  82. package/src/hooks/session-start.js +209 -0
  83. package/src/hooks/shapes.js +103 -0
  84. package/src/hooks/stop.js +37 -0
  85. package/src/hooks/subagent-marker.js +88 -0
  86. package/src/hooks/subagent-start.js +100 -0
  87. package/src/hooks/subagent-stop.js +106 -0
  88. package/src/ids.js +43 -0
  89. package/src/init.js +281 -0
  90. package/src/instructions.js +235 -0
  91. package/src/intake.js +409 -0
  92. package/src/journal.js +326 -0
  93. package/src/lock.js +35 -0
  94. package/src/markdown.js +155 -0
  95. package/src/paths.js +33 -0
  96. package/src/plan.js +25 -0
  97. package/src/pr.js +73 -0
  98. package/src/prbody.js +266 -0
  99. package/src/ready-label.js +107 -0
  100. package/src/redact.js +33 -0
  101. package/src/render/compare.js +23 -0
  102. package/src/render/entry.js +101 -0
  103. package/src/render/index.js +27 -0
  104. package/src/render/managed.js +128 -0
  105. package/src/render/manifest.js +24 -0
  106. package/src/render/settings.js +76 -0
  107. package/src/render/update.js +151 -0
  108. package/src/slicefile.js +173 -0
  109. package/src/spec-verify.js +58 -0
  110. package/src/stage.js +325 -0
  111. package/src/state/build.js +156 -0
  112. package/src/state/covers.js +58 -0
  113. package/src/state/index.js +191 -0
  114. package/src/state/sync.js +64 -0
  115. package/src/state/transitions.js +282 -0
  116. package/src/verdict.js +203 -0
  117. package/src/which.js +37 -0
  118. package/src/workflow.js +177 -0
  119. package/src/worktrees.js +68 -0
  120. package/templates/claude-code/agents/auditor.md +7 -0
  121. package/templates/claude-code/agents/designer.md +7 -0
  122. package/templates/claude-code/agents/developer.md +7 -0
  123. package/templates/claude-code/agents/fixer.md +7 -0
  124. package/templates/claude-code/agents/ops.md +7 -0
  125. package/templates/claude-code/agents/reviewer.md +7 -0
  126. package/templates/claude-code/commands/slicekit-audit.md +7 -0
  127. package/templates/claude-code/commands/slicekit-build.md +7 -0
  128. package/templates/claude-code/commands/slicekit-gaps.md +6 -0
  129. package/templates/claude-code/commands/slicekit-intake.md +7 -0
  130. package/templates/claude-code/commands/slicekit-ops.md +7 -0
  131. package/templates/claude-code/commands/slicekit-plan.md +6 -0
  132. package/templates/claude-code/commands/slicekit-release.md +7 -0
  133. package/templates/claude-code/commands/slicekit-review.md +7 -0
  134. package/templates/claude-code/commands/slicekit-specify.md +6 -0
  135. package/templates/claude-code/commands/slicekit.md +7 -0
  136. package/templates/claude-code/hooks.json +90 -0
  137. package/templates/claude-code/manifest.json +171 -0
  138. package/templates/claude-code/skills/slicekit-ids/SKILL.md +16 -0
  139. package/templates/claude-code/skills/slicekit-loop/SKILL.md +23 -0
  140. package/templates/claude-code/skills/slicekit-writing/SKILL.md +24 -0
  141. package/templates/docs/BUILD.md +5 -0
  142. package/templates/docs/decisions.md +15 -0
  143. package/templates/docs/intake/.keep +0 -0
  144. package/templates/docs/observability.md +25 -0
  145. package/templates/docs/phases/.keep +0 -0
  146. package/templates/docs/platform.md +25 -0
  147. package/templates/docs/releases/.keep +0 -0
  148. package/templates/docs/runbook.md +21 -0
  149. package/templates/docs/spec/00-overview.md +8 -0
  150. package/templates/docs/spec/contracts/.keep +0 -0
  151. package/templates/docs/spec/gaps.md +6 -0
  152. package/templates/docs/spec/stack.md +3 -0
  153. package/templates/githooks/pre-commit +79 -0
  154. package/templates/githooks/pre-merge-commit +79 -0
  155. package/templates/githooks/prepare-commit-msg +110 -0
  156. package/templates/instructions/agents/auditor.md +33 -0
  157. package/templates/instructions/agents/designer.md +21 -0
  158. package/templates/instructions/agents/developer.md +49 -0
  159. package/templates/instructions/agents/fixer.md +41 -0
  160. package/templates/instructions/agents/ops.md +21 -0
  161. package/templates/instructions/agents/reviewer.md +63 -0
  162. package/templates/instructions/commands/build.md +234 -0
  163. package/templates/instructions/commands/gaps.md +65 -0
  164. package/templates/instructions/commands/intake.md +90 -0
  165. package/templates/instructions/commands/plan.md +60 -0
  166. package/templates/instructions/commands/review.md +117 -0
  167. package/templates/instructions/commands/specify.md +49 -0
  168. package/templates/style.json +11 -0
  169. package/templates/workflow/pins.json +6 -0
  170. package/templates/workflow/slicekit.yml +110 -0
@@ -0,0 +1,146 @@
1
+ // commands (03 REQ-3.7): every command the team declared in config must be findable. Nothing is
2
+ // ever run. An empty string means "not declared", not missing.
3
+ //
4
+ // What is judged: the command is split on `&&`, `||`, `;` and `|` outside quotes. Each segment
5
+ // loses a leading `(` and a trailing `)`, then its leading `NAME=value` words. A segment whose next
6
+ // word is a shell builtin (`cd`, `set`, `export`, `.`, `source`, `exit`, `true`, `false`, `echo`,
7
+ // `test`, `[`) is not judged. In every other segment the first word is looked up. So
8
+ // `cd x && nosuchtool` is a finding on `nosuchtool`.
9
+ //
10
+ // Not expanded: a `$VAR` or `%VAR%` token is looked up as written and reported as written.
11
+ // A token with a path separator must be a regular file, relative to the root or absolute. On win32
12
+ // it is tried with the PATHEXT suffixes and bare, as `which()` does; on POSIX bare only. So a
13
+ // Windows-only `.cmd` passes on Windows and fails on POSIX.
14
+ import fs from 'node:fs';
15
+ import path from 'node:path';
16
+ import { which, extensions } from '../../which.js';
17
+
18
+ export const id = 'commands';
19
+ export const blocking = true;
20
+ export const ratchet = false;
21
+
22
+ const NAMES = ['test', 'lint', 'build', 'e2e'];
23
+ const CONFIG = '.slicekit/config.json';
24
+ const ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
25
+
26
+ const BUILTINS = new Set(['cd', 'set', 'export', '.', 'source', 'exit', 'true', 'false', 'echo', 'test', '[']);
27
+
28
+ // Split on &&, ||, ; and | outside single or double quotes.
29
+ function segments(command) {
30
+ const out = [];
31
+ let cur = '';
32
+ let quote = null;
33
+ for (let i = 0; i < command.length; i++) {
34
+ const c = command[i];
35
+ if (quote) {
36
+ if (c === quote) quote = null;
37
+ cur += c;
38
+ } else if (c === '"' || c === "'") {
39
+ quote = c;
40
+ cur += c;
41
+ } else if ((c === '&' && command[i + 1] === '&') || (c === '|' && command[i + 1] === '|')) {
42
+ out.push(cur);
43
+ cur = '';
44
+ i++;
45
+ } else if (c === ';' || c === '|') {
46
+ out.push(cur);
47
+ cur = '';
48
+ } else cur += c;
49
+ }
50
+ out.push(cur);
51
+ return out;
52
+ }
53
+
54
+ // The words to look up: one per segment that is not empty and not led by a builtin.
55
+ function commandWords(command) {
56
+ const words = [];
57
+ for (const seg of segments(command)) {
58
+ const s = seg.trim().replace(/^\(+/, '').replace(/\)+$/, '').trim();
59
+ if (s === '') continue;
60
+ const word = firstToken(s);
61
+ if (word === '' || BUILTINS.has(word)) continue;
62
+ words.push(word);
63
+ }
64
+ return words;
65
+ }
66
+
67
+ // The command word: skip leading NAME=value words, then take the first token. A leading double
68
+ // quote runs to its closing quote, or to the end of the string when it is never closed.
69
+ function firstToken(command) {
70
+ let s = command.trim();
71
+ for (;;) {
72
+ if (s.startsWith('"')) {
73
+ const end = s.indexOf('"', 1);
74
+ return end === -1 ? s.slice(1) : s.slice(1, end);
75
+ }
76
+ const word = s.split(/\s+/)[0];
77
+ if (!ASSIGNMENT.test(word) || word === s) return word;
78
+ s = s.slice(word.length).trimStart();
79
+ }
80
+ }
81
+
82
+ const isFile = (file) => {
83
+ try {
84
+ return fs.statSync(file).isFile();
85
+ } catch {
86
+ return false;
87
+ }
88
+ };
89
+
90
+ function resolves(token, ctx) {
91
+ const env = ctx.env ?? process.env;
92
+ if (token.includes('/') || token.includes('\\')) {
93
+ const file = path.resolve(ctx.root, token);
94
+ return extensions(env).some((ext) => isFile(file + ext));
95
+ }
96
+ return which(token, env, [path.join(ctx.root, 'node_modules', '.bin')]) !== null;
97
+ }
98
+
99
+ // The line of the `"<name>"` key inside the "commands" object: scan from its opening brace to the
100
+ // brace that closes it, skipping string contents. Falls back to the "commands" line, else 1.
101
+ function keyLine(root, name) {
102
+ let text;
103
+ try {
104
+ text = fs.readFileSync(path.join(root, CONFIG), 'utf8');
105
+ } catch {
106
+ return 1;
107
+ }
108
+ const open = /"commands"\s*:\s*\{/.exec(text);
109
+ if (!open) return 1;
110
+ const lineAt = (i) => text.slice(0, i).split('\n').length;
111
+ let depth = 0;
112
+ for (let i = open.index + open[0].length - 1; i < text.length; i++) {
113
+ const c = text[i];
114
+ if (c === '{') depth++;
115
+ else if (c === '}') {
116
+ depth--;
117
+ if (depth === 0) break;
118
+ } else if (c === '"') {
119
+ let j = i + 1;
120
+ while (j < text.length && text[j] !== '"') j += text[j] === '\\' ? 2 : 1;
121
+ const isKey = depth === 1 && /^\s*:/.test(text.slice(j + 1, j + 64));
122
+ if (isKey && text.slice(i + 1, j) === name) return lineAt(i);
123
+ i = j;
124
+ }
125
+ }
126
+ return lineAt(open.index);
127
+ }
128
+
129
+ export function run(ctx) {
130
+ const out = [];
131
+ for (const name of NAMES) {
132
+ const value = ctx.cfg?.commands?.[name];
133
+ if (typeof value !== 'string' || value.trim() === '') continue;
134
+ for (const token of commandWords(value)) {
135
+ if (resolves(token, ctx)) continue;
136
+ out.push({
137
+ file: CONFIG,
138
+ line: keyLine(ctx.root, name),
139
+ message: `commands.${name}: "${token}" not found on PATH or under node_modules/.bin`,
140
+ });
141
+ }
142
+ }
143
+ return out;
144
+ }
145
+
146
+ export default { id, blocking, ratchet, run };
@@ -0,0 +1,248 @@
1
+ // coverage (03 REQ-3.7, 02 REQ-2.5): once a program is at the plan stage, every REQ is named by at
2
+ // least one slice, every slice lists its expected changes and has a happy and a negative test, a
3
+ // phase's Order line names each of its groups once (D-38), and no two slices that run at the same
4
+ // time (one Order step, or one parallel group without an Order line) expect to change the same path.
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ import { readText } from '../../fs.js';
8
+ import { re, stateFileName } from '../../ids.js';
9
+ import { headings, prose } from '../../markdown.js';
10
+ import { findSliceFiles, parseOrder, parseSliceFile, phaseOfDir } from '../../slicefile.js';
11
+ import { programStage } from '../../stage.js';
12
+
13
+ export const id = 'coverage';
14
+ export const blocking = true;
15
+ export const ratchet = false;
16
+
17
+ const toPosix = (p) => p.split(path.sep).join('/');
18
+
19
+ // Every slice file, parsed or with the error that stopped it, in phase and slice order.
20
+ function readSlices(ctx) {
21
+ return findSliceFiles(ctx.root, ctx.cfg).map((f) => {
22
+ const rel = toPosix(path.relative(ctx.root, f.path));
23
+ const doc = ctx.docs.find((d) => d.rel === rel);
24
+ try {
25
+ return { rel, phaseId: f.phaseId, slice: parseSliceFile(doc ? doc.text : readText(f.path), f.path) };
26
+ } catch (e) {
27
+ return { rel, phaseId: f.phaseId, error: e.message };
28
+ }
29
+ });
30
+ }
31
+
32
+ // One pass over the parsed slices' state files: whether any is past `todo`, and the state files
33
+ // that do not parse. A missing state file is `todo`. A corrupt one is a finding and counts as past
34
+ // `todo`: an unreadable state must never close the gate. (`listSlices` would throw on the first
35
+ // corrupt file or unparseable slice file, so this reads the files itself.)
36
+ function sliceStates(ctx, parsed) {
37
+ const corrupt = [];
38
+ let beyondTodo = false;
39
+ for (const p of parsed) {
40
+ if (!p.slice) continue;
41
+ const file = path.join(ctx.paths.state, stateFileName(p.slice.id));
42
+ if (!fs.existsSync(file)) continue;
43
+ let stored;
44
+ try {
45
+ stored = JSON.parse(readText(file));
46
+ } catch {
47
+ corrupt.push(toPosix(path.relative(ctx.root, file)));
48
+ beyondTodo = true;
49
+ continue;
50
+ }
51
+ if ((stored?.state ?? 'todo') !== 'todo') beyondTodo = true;
52
+ }
53
+ return { beyondTodo, corrupt };
54
+ }
55
+
56
+ // Planned means the first stage that is not complete is `plan` or later, so the plan branch is
57
+ // checked before it merges. Stopping the stage reader at `plan` gives exactly that: it reports
58
+ // `plan` both when plan is the first incomplete stage and when it is complete. A slice past `todo`
59
+ // also counts: a program that is building is past planning even when its earlier stages cannot be
60
+ // proven (the kit itself has no intake sidecar, so its stage reader stops at intake).
61
+ function planned(ctx, beyondTodo) {
62
+ return beyondTodo || programStage(ctx.root, ctx.cfg, { upTo: 'plan' }).stage === 'plan';
63
+ }
64
+
65
+ // The REQ headings of the spec's own files (not contracts), first definition only.
66
+ function reqHeadings(ctx) {
67
+ const dir = toPosix(path.relative(ctx.root, ctx.paths.spec)) || '.';
68
+ const reqHead = new RegExp(`^(${re('req').source})\\b`);
69
+ const out = new Map();
70
+ for (const doc of ctx.docs) {
71
+ if (path.posix.dirname(doc.rel) !== dir) continue;
72
+ for (const h of headings(doc.text)) {
73
+ const m = (h.level === 2 || h.level === 3) && reqHead.exec(h.text);
74
+ if (m && !out.has(m[1])) out.set(m[1], { file: doc.rel, line: h.line });
75
+ }
76
+ }
77
+ return out;
78
+ }
79
+
80
+ // Every `{a,b}` group is expanded, outermost first, until none is left: `src/cli/{state,status}.js`
81
+ // is two paths, `src/{a,b/{c,d}}.js` three and `src/{a,b}/{c,d}.js` four. A group is split on its
82
+ // own commas only, not on those of a group inside it. An unclosed `{` stays as written.
83
+ export function expand(p) {
84
+ const open = p.indexOf('{');
85
+ if (open === -1) return [p];
86
+ const alts = [];
87
+ let depth = 0;
88
+ let from = open + 1;
89
+ for (let i = open; i < p.length; i++) {
90
+ if (p[i] === '{') depth++;
91
+ else if (p[i] === '}' && --depth === 0) {
92
+ alts.push(p.slice(from, i));
93
+ return alts.flatMap((alt) => expand(`${p.slice(0, open)}${alt.trim()}${p.slice(i + 1)}`));
94
+ } else if (p[i] === ',' && depth === 1) {
95
+ alts.push(p.slice(from, i));
96
+ from = i + 1;
97
+ }
98
+ }
99
+ return [p];
100
+ }
101
+
102
+ // Four shared roots are never an overlap: `.` (the repository itself), anything under `test/` (a
103
+ // slice may always add tests), `src/cli/index.js` (the command registration table every slice
104
+ // touches) and the runbook (every operational slice appends a section to it). The runbook is
105
+ // passed in as resolved from the config, because the docs root is the team's to choose.
106
+ const ALWAYS_SHARED = (n, runbook) => n === '' || n === '.' || n === 'test' || n.startsWith('test/') || n === 'src/cli/index.js' || n === runbook;
107
+ // The same test for one normalised repository-relative path (POSIX separators, no leading `./`), as
108
+ // `build pr`'s overlap stop asks it of a path two branches change.
109
+ export const isSharedRoot = (p, runbookRel) => ALWAYS_SHARED(p, runbookRel);
110
+
111
+ function normalise(p, runbook) {
112
+ return expand(p)
113
+ .map((one) =>
114
+ one
115
+ .replace(/\\/g, '/')
116
+ .replace(/\/{2,}/g, '/')
117
+ .replace(/^(\.\/)+/, '')
118
+ .replace(/\/+$/, ''),
119
+ )
120
+ .filter((n) => !ALWAYS_SHARED(n, runbook));
121
+ }
122
+
123
+ // The path both slices would change, when one prefix contains the other by whole segments.
124
+ function overlap(a, b) {
125
+ if (a === b || b.startsWith(`${a}/`)) return b;
126
+ if (a.startsWith(`${b}/`)) return a;
127
+ return null;
128
+ }
129
+
130
+ // Each slice's normalised prefixes, each with the file line of the first entry that gave it.
131
+ function prefixes(slice, runbook) {
132
+ const out = new Map();
133
+ slice.expectedChanges.forEach((c, k) => {
134
+ for (const n of normalise(c, runbook)) if (!out.has(n)) out.set(n, slice.expectedChangeLines[k] ?? 1);
135
+ });
136
+ return out;
137
+ }
138
+
139
+ // Each phase directory's Order line (D-38), parsed, with its file and line, and the lines of any
140
+ // further Order line (`parseOrder` follows the first); phases without one are left out. The lines
141
+ // are found with the same pattern `parseOrder` uses, so the two cannot disagree.
142
+ function orderLines(ctx) {
143
+ const out = new Map();
144
+ if (!fs.existsSync(ctx.paths.phases)) return out;
145
+ for (const dir of fs.readdirSync(ctx.paths.phases, { withFileTypes: true })) {
146
+ const phase = phaseOfDir(dir.name);
147
+ if (!dir.isDirectory() || !phase) continue;
148
+ const file = path.join(ctx.paths.phases, dir.name, `${phase.id}.md`);
149
+ const rel = toPosix(path.relative(ctx.root, file));
150
+ const doc = ctx.docs.find((d) => d.rel === rel);
151
+ if (!doc && !fs.existsSync(file)) continue;
152
+ const text = doc ? doc.text : readText(file);
153
+ const steps = parseOrder(text);
154
+ if (!steps) continue;
155
+ const at = [...prose(text)].filter(([l]) => /^\*\*Order:\*\*\s*(.+)$/.test(l)).map(([, n]) => n);
156
+ out.set(phase.id, { rel, line: at[0] ?? 1, more: at.slice(1), steps: steps.map((s) => s.filter((g) => g !== '')).filter((s) => s.length > 0) });
157
+ }
158
+ return out;
159
+ }
160
+
161
+ // REQ-2.5 / D-38: an Order line names every group of its phase, each once, and no group no slice has.
162
+ function orderFindings(parsed, orders, out) {
163
+ for (const [phaseId, order] of orders) {
164
+ const groups = new Set(parsed.filter((p) => p.slice && p.phaseId === phaseId).map((p) => p.slice.group));
165
+ const seen = new Set();
166
+ const twice = new Set();
167
+ for (const g of order.steps.flat()) (seen.has(g) ? twice : seen).add(g);
168
+ const at = (message) => out.push({ file: order.rel, line: order.line, message: `phase ${phaseId} Order line ${message}` });
169
+ for (const g of [...groups].sort()) if (!seen.has(g)) at(`does not name group ${g}`);
170
+ for (const g of twice) at(`names group ${g} twice`);
171
+ for (const g of seen) if (!groups.has(g)) at(`names group ${g}, which no slice has`);
172
+ for (const line of order.more) out.push({ file: order.rel, line, message: `phase ${phaseId} has more than one Order line` });
173
+ }
174
+ }
175
+
176
+ // The slices that run at the same time: with an Order line, those of one step (a group named in
177
+ // several steps is in each, so all its overlaps show; a group the line does not name is its own
178
+ // step, so its overlaps are still found); without one, those of one group.
179
+ function overlaps(parsed, orders, out, runbook) {
180
+ const sets = new Map();
181
+ for (const p of parsed) {
182
+ if (!p.slice) continue;
183
+ const order = orders.get(p.phaseId);
184
+ const steps = order ? order.steps.filter((s) => s.includes(p.slice.group)) : [];
185
+ // A Set, so a step written twice (`A; A`) does not put a slice beside itself.
186
+ const labels = new Set(steps.length > 0 ? steps.map((s) => `step ${s.join(', ')}`) : [`group ${p.slice.group}`]);
187
+ const member = { ...p, prefixes: prefixes(p.slice, runbook) };
188
+ for (const label of labels) {
189
+ const key = `${p.phaseId}\u0000${label}`;
190
+ if (!sets.has(key)) sets.set(key, { label, members: [] });
191
+ sets.get(key).members.push(member);
192
+ }
193
+ }
194
+ for (const { label, members } of sets.values()) {
195
+ for (let j = 1; j < members.length; j++) {
196
+ for (let i = 0; i < j; i++) {
197
+ const [a, b] = [members[i], members[j]];
198
+ const shared = new Map();
199
+ for (const x of a.prefixes.keys()) {
200
+ for (const [y, line] of b.prefixes) {
201
+ const hit = overlap(x, y);
202
+ if (hit !== null && !shared.has(hit)) shared.set(hit, line);
203
+ }
204
+ }
205
+ for (const [where, line] of shared) {
206
+ out.push({ file: b.rel, line, message: `slices ${a.slice.id} and ${b.slice.id} in ${label} both expect ${where}` });
207
+ }
208
+ }
209
+ }
210
+ }
211
+ }
212
+
213
+ export function run(ctx) {
214
+ const parsed = readSlices(ctx);
215
+ const states = sliceStates(ctx, parsed);
216
+ if (!planned(ctx, states.beyondTodo)) return [];
217
+ const out = [];
218
+ for (const rel of states.corrupt) out.push({ file: rel, line: 1, message: `state file ${rel} is not valid JSON` });
219
+ for (const p of parsed) {
220
+ if (p.error) out.push({ file: p.rel, line: 1, message: `slice file cannot be read: ${p.error}` });
221
+ }
222
+ const named = new Set(parsed.flatMap((p) => (p.slice ? p.slice.requirements : [])));
223
+ const heads = reqHeadings(ctx);
224
+ for (const reqId of ctx.ids.req) {
225
+ if (named.has(reqId)) continue;
226
+ const at = heads.get(reqId) ?? { file: toPosix(path.relative(ctx.root, ctx.paths.spec)), line: 1 };
227
+ out.push({ file: at.file, line: at.line, message: `${reqId} is named by no slice` });
228
+ }
229
+ // REQ-1.5: a slice file lists its expected changes; an empty list would pass every overlap check.
230
+ for (const p of parsed) {
231
+ if (p.slice && p.slice.expectedChanges.length === 0) {
232
+ out.push({ file: p.rel, line: p.slice.expectedChangesLine ?? 1, message: `slice ${p.slice.id} lists no expected changes` });
233
+ }
234
+ }
235
+ // REQ-2.5: each slice's evaluation set has at least one happy and one negative test.
236
+ for (const p of parsed) {
237
+ if (!p.slice) continue;
238
+ for (const kind of ['happy', 'negative']) {
239
+ if (!p.slice.evaluation.some((e) => e.kind === kind)) out.push({ file: p.rel, line: 1, message: `slice ${p.slice.id} has no ${kind} test` });
240
+ }
241
+ }
242
+ const orders = orderLines(ctx);
243
+ orderFindings(parsed, orders, out);
244
+ overlaps(parsed, orders, out, toPosix(path.relative(ctx.root, ctx.paths.runbook)));
245
+ return out;
246
+ }
247
+
248
+ export default { id, blocking, ratchet, run };
@@ -0,0 +1,58 @@
1
+ // hooks (03 REQ-3.9, REQ-3.7): git hooks do not survive a clone, so check fails until
2
+ // `core.hooksPath` names `.githooks` and the three slicekit hooks are there and executable. Silent
3
+ // outside a git repository. A hooks-path finding is reported on `.githooks` (line 0); a finding about
4
+ // one hook, on that hook's file. On win32 there is no mode bit: a tracked hook's index mode is read
5
+ // instead, and an untracked one is not judged for it.
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+ import { git } from '../../git.js';
9
+ import { GITHOOKS, HOOKS_PATH, hooksPathValue, isInstalledHooksPath } from '../../githooks.js';
10
+
11
+ export const id = 'hooks';
12
+ export const blocking = true;
13
+ export const ratchet = false;
14
+
15
+ // true or false, or null when the platform cannot tell.
16
+ function executable(root, rel) {
17
+ if (process.platform !== 'win32') {
18
+ try {
19
+ fs.accessSync(path.join(root, rel), fs.constants.X_OK);
20
+ return true;
21
+ } catch {
22
+ return false;
23
+ }
24
+ }
25
+ const staged = git(root, ['ls-files', '-s', '--', rel]);
26
+ if (staged === '') return null;
27
+ return staged.split(/\s/)[0] === '100755';
28
+ }
29
+
30
+ const isFile = (abs) => {
31
+ try {
32
+ return fs.statSync(abs).isFile();
33
+ } catch {
34
+ return false;
35
+ }
36
+ };
37
+
38
+ export function run(ctx) {
39
+ if (!ctx.git?.isRepo) return [];
40
+ const out = [];
41
+ const value = hooksPathValue(ctx.root);
42
+ if (value === null) {
43
+ out.push({ file: HOOKS_PATH, line: 0, message: `core.hooksPath is not set (must be ${HOOKS_PATH}); run slicekit init` });
44
+ } else if (!isInstalledHooksPath(ctx.root, value)) {
45
+ out.push({ file: HOOKS_PATH, line: 0, message: `core.hooksPath is ${value}, not ${HOOKS_PATH}; set it to ${HOOKS_PATH} or run slicekit init` });
46
+ }
47
+ for (const name of GITHOOKS) {
48
+ const rel = `${HOOKS_PATH}/${name}`;
49
+ if (!isFile(path.join(ctx.root, rel))) {
50
+ out.push({ file: rel, line: 1, message: `${rel} is missing; run slicekit init` });
51
+ } else if (executable(ctx.root, rel) === false) {
52
+ out.push({ file: rel, line: 1, message: `${rel} is not executable; run git update-index --chmod=+x ${rel}` });
53
+ }
54
+ }
55
+ return out;
56
+ }
57
+
58
+ export default { id, blocking, ratchet, run };
@@ -0,0 +1,17 @@
1
+ // journal (03 REQ-3.7, REQ-3.8, D-34, D-36): every file under .slicekit/journal/ must verify as an unbroken
2
+ // hash chain from genesis (one finding per broken file, at its first broken line); nothing else may sit
3
+ // in that directory but `*.log` files and their `*.lock`; and every journal file committed at the merge
4
+ // base with the default branch must still be there and only have grown. Silent when there is no journal
5
+ // and, for the git part, outside a repository; without a base, silent locally and one finding under
6
+ // --ci. Never repairs.
7
+ import { appendOnlyProblems, verifyJournal } from '../../journal.js';
8
+
9
+ export const id = 'journal';
10
+ export const blocking = true;
11
+ export const ratchet = false;
12
+
13
+ export function run(ctx) {
14
+ return [...verifyJournal(ctx.root, ctx.cfg).problems, ...appendOnlyProblems(ctx.root, ctx.cfg, { ci: Boolean(ctx.ci) })];
15
+ }
16
+
17
+ export default { id, blocking, ratchet, run };
@@ -0,0 +1,56 @@
1
+ // layout (03 REQ-3.7, 01 REQ-1.1, REQ-1.10): every path slicekit init lays down must exist, as the
2
+ // kind it was laid down as; and no file under .claude/ may be one the manifest ships only for
3
+ // another shape. A file under .claude/ that no manifest entry names is the team's and never a
4
+ // finding. With no .slicekit/config.json the rule is silent: there is no install to judge.
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ import { listFiles } from '../../fs.js';
8
+ import { loadManifest } from '../../render/manifest.js';
9
+
10
+ export const id = 'layout';
11
+ export const blocking = true;
12
+ export const ratchet = false;
13
+
14
+ const CONFIG = '.slicekit/config.json';
15
+ const FILES = ['decisions', 'gaps', 'stack', 'platform', 'observability', 'runbook', 'build', 'workflow'];
16
+ const DIRS = ['kit', 'state', 'baselines', 'docs', 'intake', 'spec', 'contracts', 'phases', 'releases', 'githooks', 'claude'];
17
+
18
+ const toPosix = (p) => p.split(path.sep).join('/');
19
+
20
+ const kindOf = (abs) => {
21
+ try {
22
+ const st = fs.statSync(abs);
23
+ return st.isDirectory() ? 'dir' : st.isFile() ? 'file' : 'other';
24
+ } catch {
25
+ return null;
26
+ }
27
+ };
28
+
29
+ export function run(ctx) {
30
+ const { root, cfg, paths } = ctx;
31
+ if (kindOf(paths.config) !== 'file') return [];
32
+ const out = [];
33
+ const rel = (abs) => toPosix(path.relative(root, abs)) || '.';
34
+
35
+ const required = [...FILES.map((k) => [k, 'file']), ...DIRS.map((k) => [k, 'dir'])];
36
+ for (const [key, kind] of required) {
37
+ if (kindOf(paths[key]) !== kind) {
38
+ out.push({ file: CONFIG, line: 1, message: `${rel(paths[key])} is missing; run slicekit init` });
39
+ }
40
+ }
41
+
42
+ if (kindOf(paths.claude) === 'dir') {
43
+ const ours = new Set();
44
+ const foreign = new Set();
45
+ for (const e of loadManifest()) (e.shapes.includes(cfg.shape) ? ours : foreign).add(e.dest);
46
+ for (const file of listFiles(paths.claude)) {
47
+ const dest = `${rel(paths.claude)}/${file}`;
48
+ if (foreign.has(dest) && !ours.has(dest)) {
49
+ out.push({ file: dest, line: 1, message: `${dest} is not part of shape ${cfg.shape}; run slicekit update` });
50
+ }
51
+ }
52
+ }
53
+ return out;
54
+ }
55
+
56
+ export default { id, blocking, ratchet, run };
@@ -0,0 +1,31 @@
1
+ // managed (03 REQ-3.12): every file slicekit renders must still hold the block slicekit wrote.
2
+ // The plan is the one `slicekit update` makes at the kit's own version. `drifted`, `missing` and
3
+ // `unmanaged` are findings; `same` and `changed` are not: `changed` means the kit ships a newer
4
+ // template, which is update's business, not drift. A plan that cannot be made is one finding.
5
+ import { kitVersion } from '../../render/index.js';
6
+ import { planUpdate, reportKind } from '../../render/update.js';
7
+
8
+ export const id = 'managed';
9
+ export const blocking = true;
10
+ export const ratchet = false;
11
+
12
+ const MESSAGE = {
13
+ drifted: (dest) => `${dest}: managed block edited since slicekit wrote it; run slicekit update --force or revert`,
14
+ missing: (dest) => `${dest}: managed file missing; run slicekit update`,
15
+ unmanaged: (dest) => `${dest}: exists but is not managed by slicekit; move it or run slicekit update --force`,
16
+ // With no reference copy the verdict was taken against the kit's current templates, so the
17
+ // difference may be the team's edit or a kit change; the message must not claim either.
18
+ noReference: (dest) => `${dest}: no reference copy; cannot tell a kit change from an edit; slicekit update --force overwrites`,
19
+ };
20
+
21
+ export function run(ctx) {
22
+ let items;
23
+ try {
24
+ items = planUpdate(ctx.root, ctx.cfg, { version: kitVersion() });
25
+ } catch (e) {
26
+ return [{ file: '-', line: 0, message: `managed: cannot plan an update: ${e?.message ?? e}` }];
27
+ }
28
+ return items.filter((i) => MESSAGE[i.status]).map((i) => ({ file: i.dest, line: 1, message: MESSAGE[reportKind(i)](i.dest) }));
29
+ }
30
+
31
+ export default { id, blocking, ratchet, run };
@@ -0,0 +1,106 @@
1
+ // queue (01 REQ-1.6, 03 REQ-3.7): BUILD.md is a view of the slice files and their state, so its
2
+ // generated region must read exactly as `slicekit status --write` would write it. The text below
3
+ // the marker is the team's and is never compared.
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+ import { readText } from '../../fs.js';
7
+ import { lines } from '../../markdown.js';
8
+ import { findSliceFiles } from '../../slicefile.js';
9
+ import { generatedRegion, renderBuild, MARKER } from '../../state/build.js';
10
+
11
+ export const id = 'queue';
12
+ export const blocking = true;
13
+ export const ratchet = false;
14
+
15
+ const toPosix = (p) => p.split(path.sep).join('/');
16
+ const PHASE = /^##\s+Phase\s+(\d+)\b/;
17
+ const ROW = /^\|\s*(S-\d+)\s*\|/;
18
+
19
+ // The cells of a table row, split on unescaped pipes.
20
+ const cells = (line) =>
21
+ line
22
+ .split(/(?<!\\)\|/)
23
+ .slice(1, -1)
24
+ .map((c) => c.trim());
25
+
26
+ // The generated region split into slice rows keyed `P<n>/S-<m>` and every other line. Each keyed
27
+ // row leaves a placeholder in `other`, so the order and position of rows are compared with the
28
+ // rest of the region. A row outside a phase section, or a second row for one slice, stays an
29
+ // other line, so it is a difference outside the rows.
30
+ const HOLDER = '\u0000';
31
+ function parse(generated) {
32
+ const out = { rows: new Map(), phases: new Map(), other: [] };
33
+ let phase = null;
34
+ lines(generated).forEach((raw, i) => {
35
+ const line = raw.trimEnd();
36
+ const p = PHASE.exec(line);
37
+ if (p) {
38
+ phase = Number(p[1]);
39
+ if (!out.phases.has(phase)) out.phases.set(phase, i + 1);
40
+ }
41
+ const r = ROW.exec(line);
42
+ const key = r && phase !== null ? `P${phase}/${r[1]}` : null;
43
+ if (key && !out.rows.has(key)) {
44
+ out.rows.set(key, { line: i + 1, cells: cells(line) });
45
+ out.other.push(`${HOLDER}${key}`);
46
+ } else out.other.push(line);
47
+ });
48
+ while (out.other.length > 0 && out.other[out.other.length - 1] === '') out.other.pop();
49
+ return out;
50
+ }
51
+
52
+ // Nothing to check before the first plan: no state written and no slice file yet.
53
+ function unplanned(ctx) {
54
+ const dir = ctx.paths.state;
55
+ const states = fs.existsSync(dir) ? fs.readdirSync(dir).filter((n) => n.endsWith('.json')) : [];
56
+ return states.length === 0 && findSliceFiles(ctx.root, ctx.cfg).length === 0;
57
+ }
58
+
59
+ export function run(ctx) {
60
+ if (unplanned(ctx)) return [];
61
+ const file = toPosix(path.relative(ctx.root, ctx.paths.build));
62
+ const at = (line, message) => ({ file, line, message });
63
+ if (!fs.existsSync(ctx.paths.build)) return [at(0, `${file} is missing; run slicekit status --write`)];
64
+ const doc = ctx.docs.find((d) => d.rel === file);
65
+ const text = doc ? doc.text : readText(ctx.paths.build);
66
+ if (!lines(text).some((l) => l.trim() === MARKER)) {
67
+ return [at(1, `${file} has no generated region marker; run slicekit status --write`)];
68
+ }
69
+ let rendered;
70
+ try {
71
+ // Warnings (a phase without a phase file) are printed by `status`, not reported here.
72
+ rendered = renderBuild(ctx.root, ctx.cfg, '');
73
+ } catch (e) {
74
+ return [at(1, `${file} cannot be rendered from the slice files and state: ${e.message}`)];
75
+ }
76
+ const have = parse(generatedRegion(text).generated);
77
+ const want = parse(generatedRegion(rendered).generated);
78
+
79
+ const out = [];
80
+ // A row on one side only is reported by its own finding below, so its placeholder is dropped
81
+ // here; what remains differs only through order, position or a line outside the rows.
82
+ const shared = (key) => have.rows.has(key) && want.rows.has(key);
83
+ const both = (o) => o.filter((l) => !l.startsWith(HOLDER) || shared(l.slice(HOLDER.length)));
84
+ if (both(have.other).join('\n') !== both(want.other).join('\n')) out.push(at(1, `${file} is stale; run slicekit status --write`));
85
+ for (const [key, row] of have.rows) {
86
+ const expected = want.rows.get(key);
87
+ if (!expected) {
88
+ out.push(at(row.line, `${file} row for ${key} has no slice file`));
89
+ continue;
90
+ }
91
+ const [hs, ws] = [row.cells.at(-1), expected.cells.at(-1)];
92
+ if (row.cells.length !== expected.cells.length) out.push(at(row.line, `${file} row for ${key} is stale; run slicekit status --write`));
93
+ else if (hs !== ws) out.push(at(row.line, `${file} row for ${key} says "${hs}", state says "${ws}"`));
94
+ else if (row.cells.join('\u0000') !== expected.cells.join('\u0000')) {
95
+ out.push(at(row.line, `${file} row for ${key} is stale; run slicekit status --write`));
96
+ }
97
+ }
98
+ for (const key of want.rows.keys()) {
99
+ if (have.rows.has(key)) continue;
100
+ const phase = Number(/^P(\d+)\//.exec(key)[1]);
101
+ out.push(at(have.phases.get(phase) ?? 1, `${file} lacks a row for ${key}; run slicekit status --write`));
102
+ }
103
+ return out.sort((a, b) => a.line - b.line);
104
+ }
105
+
106
+ export default { id, blocking, ratchet, run };