slicekit 0.1.1 → 0.2.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.
Files changed (68) hide show
  1. package/README.md +15 -13
  2. package/package.json +3 -2
  3. package/src/adapters/githost/fixture.js +24 -1
  4. package/src/adapters/githost/gh-json.js +69 -2
  5. package/src/adapters/githost/github.js +16 -1
  6. package/src/build/commit.js +152 -26
  7. package/src/build/config.js +50 -0
  8. package/src/build/pr.js +30 -15
  9. package/src/build/record.js +8 -2
  10. package/src/build/red.js +4 -3
  11. package/src/build/render.js +155 -0
  12. package/src/build/verdict.js +29 -0
  13. package/src/build/worktree.js +26 -5
  14. package/src/check/ci-event.js +17 -0
  15. package/src/check/rules/citations.js +53 -2
  16. package/src/check/rules/commands.js +32 -4
  17. package/src/check/rules/trailer.js +5 -16
  18. package/src/check/rules/workspace.js +86 -0
  19. package/src/cli/build.js +34 -8
  20. package/src/cli/ci.js +150 -0
  21. package/src/cli/decide.js +4 -3
  22. package/src/cli/gaps.js +6 -5
  23. package/src/cli/graph.js +79 -0
  24. package/src/cli/history.js +17 -0
  25. package/src/cli/hook.js +1 -1
  26. package/src/cli/impact.js +17 -0
  27. package/src/cli/index.js +28 -3
  28. package/src/cli/instructions.js +1 -1
  29. package/src/cli/intake.js +3 -3
  30. package/src/cli/query.js +39 -0
  31. package/src/cli/shipped.js +32 -0
  32. package/src/cli/state.js +42 -2
  33. package/src/cli/trace.js +21 -0
  34. package/src/cli/uncovered.js +32 -0
  35. package/src/cli/visualize.js +88 -0
  36. package/src/cli/workflow.js +6 -2
  37. package/src/config.js +85 -0
  38. package/src/graph/build.js +312 -0
  39. package/src/graph/docs.js +241 -0
  40. package/src/graph/git-walk.js +91 -0
  41. package/src/graph/history.js +60 -0
  42. package/src/graph/impact.js +143 -0
  43. package/src/graph/kitfiles.js +60 -0
  44. package/src/graph/load.js +93 -0
  45. package/src/graph/prs.js +136 -0
  46. package/src/graph/render.js +28 -0
  47. package/src/graph/schema.js +108 -0
  48. package/src/graph/shipped.js +32 -0
  49. package/src/graph/tests.js +45 -0
  50. package/src/graph/trace.js +83 -0
  51. package/src/graph/uncovered.js +16 -0
  52. package/src/graph/workspace.js +188 -0
  53. package/src/hook-cli.js +1 -1
  54. package/src/init.js +8 -1
  55. package/src/instructions.js +26 -8
  56. package/src/state/index.js +35 -4
  57. package/src/verdict.js +14 -2
  58. package/src/visualize/client.js +489 -0
  59. package/src/visualize/page.js +100 -0
  60. package/src/visualize/server.js +46 -0
  61. package/src/workflow.js +87 -9
  62. package/templates/githooks/pre-commit +24 -4
  63. package/templates/githooks/pre-merge-commit +24 -4
  64. package/templates/githooks/prepare-commit-msg +41 -5
  65. package/templates/instructions/agents/reviewer.md +7 -7
  66. package/templates/instructions/commands/build.md +34 -4
  67. package/templates/workflow/pins.json +2 -1
  68. package/templates/workflow/slicekit.yml +32 -1
package/src/workflow.js CHANGED
@@ -5,7 +5,7 @@
5
5
  import fs from 'node:fs';
6
6
  import path from 'node:path';
7
7
  import { fileURLToPath } from 'node:url';
8
- import { DEFAULT_TIMEOUT_MINUTES, GITHUB_EXPRESSION, LINE_SEPARATOR } from './config.js';
8
+ import { DEFAULT_TIMEOUT_MINUTES, GITHUB_EXPRESSION, LINE_SEPARATOR, shardErrors } from './config.js';
9
9
  import { readText } from './fs.js';
10
10
  import { kitPaths } from './paths.js';
11
11
  import { substitute } from './render/entry.js';
@@ -16,7 +16,7 @@ export const PINS_PATH = fileURLToPath(new URL('../templates/workflow/pins.json'
16
16
  export const WORKFLOW_PATH = '.github/workflows/slicekit.yml';
17
17
  export const WORKFLOW_DRIFT = `${WORKFLOW_PATH} differs from the generator; run slicekit workflow --write to regenerate it`;
18
18
 
19
- const ACTIONS = { checkout: 'actions/checkout', setupNode: 'actions/setup-node', uploadArtifact: 'actions/upload-artifact' };
19
+ const ACTIONS = { checkout: 'actions/checkout', setupNode: 'actions/setup-node', uploadArtifact: 'actions/upload-artifact', cache: 'actions/cache' };
20
20
  const COMMAND_ORDER = ['test', 'lint', 'build', 'e2e'];
21
21
  const MATRIX_OS = ['ubuntu-latest', 'windows-latest', 'macos-latest'];
22
22
  const SHA = /^[0-9a-f]{40}$/;
@@ -24,7 +24,7 @@ const TAG = /^v\d+\.\d+\.\d+$/;
24
24
  const BLOCK_KEYS = ['gateExtraSteps', 'commandJobs', 'observabilityJobs'];
25
25
  // Filled as written: values the kit computes or validates to a safe shape.
26
26
  const VALUE_KEYS = [
27
- 'defaultBranchItem', 'readyNeeds', 'syncPaths', 'timeoutMinutes',
27
+ 'checksOk', 'defaultBranchItem', 'readyNeeds', 'syncPaths', 'timeoutMinutes',
28
28
  ...Object.keys(ACTIONS).flatMap((k) => [`${k}Sha`, `${k}Tag`]),
29
29
  ];
30
30
  // The team's own text: a mapping value holding one is filled, then quoted as a whole.
@@ -107,11 +107,46 @@ function runStep(name, run, env) {
107
107
  return lines;
108
108
  }
109
109
 
110
- function commandJob(name, command, v, matrix, timeout) {
111
- const head = matrix
112
- ? [' strategy:', ' fail-fast: false', ' matrix:', ` os: [${MATRIX_OS.join(', ')}]`, ' runs-on: ${{ matrix.os }}']
113
- : [' runs-on: ubuntu-latest'];
114
- return ['', ` cmd-${name}:`, ...head, ` timeout-minutes: ${timeout}`, ' steps:', ...setupSteps(v), ...runStep(name, command)];
110
+ // The gate's decision (D-49): a push of only bookkeeping skips the team command jobs. A gate that
111
+ // failed before deciding leaves the output empty, which reads as code, so the tests still run.
112
+ const BOOKKEEPING = "needs.gate.outputs.kind == 'bookkeeping'";
113
+ const COMMAND_IF = ' if: ${{ !cancelled() && !(' + BOOKKEEPING + ') }}';
114
+
115
+ // One job per declared team command, run on `systems`. `shards` (the test command only, D-49) maps a
116
+ // system to its shard count; each shard sets SLICEKIT_SHARD to <k>/<n>, 1/1 on a system not split.
117
+ function commandJob(name, command, v, systems, timeout, shards) {
118
+ const strategy = [' strategy:', ' fail-fast: false', ' matrix:'];
119
+ let head;
120
+ let env = [];
121
+ if (shards) {
122
+ const include = systems.flatMap((os) => {
123
+ const n = shards[os] ?? 1;
124
+ return Array.from({ length: n }, (_x, i) => [` - os: ${os}`, ` shard: ${yamlScalar(`${i + 1}/${n}`)}`]).flat();
125
+ });
126
+ head = [...strategy, ' include:', ...include, ' runs-on: ${{ matrix.os }}'];
127
+ env = [' env:', ' SLICEKIT_SHARD: ${{ matrix.shard }}'];
128
+ } else if (systems.length > 1) {
129
+ head = [...strategy, ` os: [${systems.join(', ')}]`, ' runs-on: ${{ matrix.os }}'];
130
+ } else {
131
+ head = [` runs-on: ${systems[0]}`];
132
+ }
133
+ const [stepName, ...rest] = runStep(name, command);
134
+ return ['', ` cmd-${name}:`, ' needs: [gate]', COMMAND_IF, ...head, ` timeout-minutes: ${timeout}`, ' steps:', ...setupSteps(v), stepName, ...env, ...rest];
135
+ }
136
+
137
+ // SLICEKIT_CHECKS_OK for ready-label: the gate and every observability job succeeded, and each team
138
+ // command job succeeded or was skipped because the gate said bookkeeping. A job that failed, was
139
+ // cancelled or was skipped for any other reason is not passed.
140
+ function checksOk(commands, steps) {
141
+ const passed = (id) => `needs.${id}.result == 'success'`;
142
+ const parts = [
143
+ "!contains(needs.*.result, 'failure')",
144
+ "!contains(needs.*.result, 'cancelled')",
145
+ passed('gate'),
146
+ ...commands.map((c) => `(${passed(`cmd-${c}`)} || (needs.cmd-${c}.result == 'skipped' && ${BOOKKEEPING}))`),
147
+ ...steps.map((_s, i) => passed(`obs-${i + 1}`)),
148
+ ];
149
+ return '${{ ' + parts.join(' && ') + ' }}';
115
150
  }
116
151
 
117
152
  function observabilityJob(n, step, v, timeout) {
@@ -139,17 +174,29 @@ export function renderWorkflow(cfg, pins = loadPins(), { template = fs.readFileS
139
174
  const matrix = cfg.ci?.matrix === true;
140
175
  const timeout = cfg.ci?.timeoutMinutes ?? DEFAULT_TIMEOUT_MINUTES;
141
176
  if (!Number.isInteger(timeout) || timeout < 1 || timeout > 360) throw new Error('ci.timeoutMinutes: must be an integer from 1 to 360');
177
+ const shardProblems = shardErrors(cfg.ci?.shards);
178
+ if (shardProblems.length > 0) throw new Error(shardProblems.join('; '));
179
+ const testSystems = matrix ? MATRIX_OS : ['ubuntu-latest'];
180
+ const shards = cfg.ci?.shards && Object.keys(cfg.ci.shards).length > 0 ? cfg.ci.shards : null;
181
+ for (const os of Object.keys(shards ?? {})) {
182
+ if (!testSystems.includes(os)) throw new Error(`ci.shards.${os}: the test job runs only on ${testSystems.join(', ')}`);
183
+ }
142
184
  const commands = COMMAND_ORDER.filter((name) => typeof cfg.commands[name] === 'string' && cfg.commands[name].trim() !== '');
143
185
  const steps = cfg.ci?.observabilitySteps ?? [];
144
186
  const texts = [cfg.cli, ...commands.map((c) => cfg.commands[c]), ...steps.map((s) => s.run)];
145
187
  if (texts.some((t) => GITHUB_EXPRESSION.test(t))) throw new Error('workflow: a command contains a GitHub expression; pass values through env:');
146
188
  const blocks = {
147
189
  gateExtraSteps: matrix ? NO_DEPENDENCIES : [],
148
- commandJobs: commands.flatMap((name) => commandJob(name, cfg.commands[name], v, matrix && name === 'test', timeout)),
190
+ commandJobs: commands.flatMap((name) =>
191
+ name === 'test'
192
+ ? commandJob(name, cfg.commands[name], v, testSystems, timeout, shards)
193
+ : commandJob(name, cfg.commands[name], v, ['ubuntu-latest'], timeout, null),
194
+ ),
149
195
  observabilityJobs: steps.flatMap((step, i) => observabilityJob(i + 1, step, v, timeout)),
150
196
  };
151
197
  const vars = {
152
198
  ...v,
199
+ checksOk: checksOk(commands, steps),
153
200
  defaultBranchItem: yamlScalar(cfg.defaultBranch),
154
201
  readyNeeds: ['gate', ...commands.map((c) => `cmd-${c}`), ...steps.map((_s, i) => `obs-${i + 1}`)].join(', '),
155
202
  syncPaths: syncPaths(cfg),
@@ -175,3 +222,34 @@ export function workflowState(root, cfg, pins = loadPins()) {
175
222
  const current = fs.existsSync(file) ? readText(file) : null;
176
223
  return { file, expected, current };
177
224
  }
225
+
226
+ // D-49: a team whose test command never reads SLICEKIT_SHARD runs the whole command in every shard.
227
+ // The command reads it when its text names it; `npm test` and `npm run <script>` are read through to
228
+ // that package.json script, and a command or script `node <file>.js` through to that file.
229
+ export function shardWarnings(root, cfg) {
230
+ const shards = cfg.ci?.shards;
231
+ const command = cfg.commands?.test;
232
+ if (!shards || Object.keys(shards).length === 0 || typeof command !== 'string' || command.trim() === '') return [];
233
+ let text = command;
234
+ const npm = /^\s*npm\s+(?:run(?:-script)?\s+(\S+)|test\b|t\b)/.exec(command);
235
+ if (npm) {
236
+ try {
237
+ const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
238
+ text += ` ${pkg.scripts?.[npm[1] ?? 'test'] ?? ''}`;
239
+ } catch {
240
+ // No readable package.json: only the command's own text counts.
241
+ }
242
+ }
243
+ // The command itself, or the npm script it named when there was one.
244
+ const runs = text === command ? command : text.slice(command.length).trim();
245
+ const script = /^\s*node\s+([\w./-]+\.[cm]?js)\b/.exec(runs);
246
+ if (script && !script[1].split('/').includes('..')) {
247
+ try {
248
+ text += ` ${fs.readFileSync(path.join(root, ...script[1].split('/')), 'utf8')}`;
249
+ } catch {
250
+ // No such file: only the text so far counts.
251
+ }
252
+ }
253
+ if (text.includes('SLICEKIT_SHARD')) return [];
254
+ return ['ci.shards is set but commands.test does not read SLICEKIT_SHARD; every shard runs the whole test command'];
255
+ }
@@ -2,17 +2,19 @@
2
2
  # slicekit: refuses a commit on a protected branch (REQ-3.9). Installed as pre-commit and as
3
3
  # pre-merge-commit, byte for byte; prepare-commit-msg carries the same check between the markers.
4
4
  # >>> slicekit protected-branch check (identical in every slicekit hook)
5
- # The branch a commit lands on: HEAD's branch, or during a rebase the branch being rebased.
5
+ # Sets slicekit_b to the branch a commit lands on: HEAD's branch, or during a rebase the branch being
6
+ # rebased; empty on a detached HEAD. A variable, not output, so no extra shell starts to read it.
6
7
  slicekit_branch() {
8
+ slicekit_b=
7
9
  # The full ref, stripped here: --short says heads/main when a tag main exists.
8
10
  if slicekit_r=$(git symbolic-ref -q HEAD); then
9
- case $slicekit_r in refs/heads/*) printf '%s\n' "${slicekit_r#refs/heads/}" ;; esac
11
+ case $slicekit_r in refs/heads/*) slicekit_b=${slicekit_r#refs/heads/} ;; esac
10
12
  return 0
11
13
  fi
12
14
  for slicekit_d in rebase-merge rebase-apply; do
13
15
  slicekit_f=$(git rev-parse --git-path "$slicekit_d/head-name")
14
16
  if [ -f "$slicekit_f" ]; then
15
- sed -e 's#^refs/heads/##' "$slicekit_f"
17
+ slicekit_b=$(sed -e 's#^refs/heads/##' "$slicekit_f")
16
18
  return 0
17
19
  fi
18
20
  done
@@ -31,10 +33,28 @@ slicekit_op() {
31
33
  # Refuses when that branch is in protectedBranches of .slicekit/config.json, or is main when node or
32
34
  # the file is absent or unreadable. ALLOW_PROTECTED_COMMIT=1 overrides. Entries are names, never
33
35
  # globs: globbing is off while they are compared.
36
+ # False only when the config's text proves branch $1 cannot be protected, so node need not start; true
37
+ # whenever only node can say (D-42). Proof is kept to the hot path: a slice branch spelled in ASCII
38
+ # letters, digits and / . _ -, whose text appears nowhere in the file, in a file with no \u or \/
39
+ # escape. node prints every protectedBranches value joined, numbers in JavaScript's form and nested
40
+ # arrays joined with commas, so no other name can be ruled out from the text alone. Shell built-ins
41
+ # only, and every character class spelled out, so no locale widens it.
42
+ slicekit_named() {
43
+ [ -f .slicekit/config.json ] || return 1
44
+ case $1 in slice/P*-S-*) ;; *) return 0 ;; esac
45
+ case $1 in *[!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/._-]*) return 0 ;; esac
46
+ while IFS= read -r slicekit_line || [ -n "$slicekit_line" ]; do
47
+ case $slicekit_line in *'\u'* | *'\/'* | *"$1"*) return 0 ;; esac
48
+ done < .slicekit/config.json
49
+ return 1
50
+ }
34
51
  slicekit_check_protected() {
35
52
  [ "$ALLOW_PROTECTED_COMMIT" = "1" ] && return 0
36
- slicekit_b=$(slicekit_branch)
53
+ slicekit_branch
37
54
  [ -n "$slicekit_b" ] || return 0
55
+ # Without node or the file the list is main alone, so a branch other than main that the file never
56
+ # names cannot be protected: decided here without starting node (D-42).
57
+ [ "$slicekit_b" != main ] && ! slicekit_named "$slicekit_b" && return 0
38
58
  slicekit_p=main
39
59
  if [ -f .slicekit/config.json ] && command -v node >/dev/null 2>&1; then
40
60
  if slicekit_l=$(node -e 'const c=JSON.parse(require("fs").readFileSync(process.argv[1],"utf8").replace(/^\uFEFF/,""));const p=c.protectedBranches;if(!Array.isArray(p))process.exit(1);process.stdout.write(p.join("\n"))' .slicekit/config.json 2>/dev/null); then
@@ -2,17 +2,19 @@
2
2
  # slicekit: refuses a commit on a protected branch (REQ-3.9). Installed as pre-commit and as
3
3
  # pre-merge-commit, byte for byte; prepare-commit-msg carries the same check between the markers.
4
4
  # >>> slicekit protected-branch check (identical in every slicekit hook)
5
- # The branch a commit lands on: HEAD's branch, or during a rebase the branch being rebased.
5
+ # Sets slicekit_b to the branch a commit lands on: HEAD's branch, or during a rebase the branch being
6
+ # rebased; empty on a detached HEAD. A variable, not output, so no extra shell starts to read it.
6
7
  slicekit_branch() {
8
+ slicekit_b=
7
9
  # The full ref, stripped here: --short says heads/main when a tag main exists.
8
10
  if slicekit_r=$(git symbolic-ref -q HEAD); then
9
- case $slicekit_r in refs/heads/*) printf '%s\n' "${slicekit_r#refs/heads/}" ;; esac
11
+ case $slicekit_r in refs/heads/*) slicekit_b=${slicekit_r#refs/heads/} ;; esac
10
12
  return 0
11
13
  fi
12
14
  for slicekit_d in rebase-merge rebase-apply; do
13
15
  slicekit_f=$(git rev-parse --git-path "$slicekit_d/head-name")
14
16
  if [ -f "$slicekit_f" ]; then
15
- sed -e 's#^refs/heads/##' "$slicekit_f"
17
+ slicekit_b=$(sed -e 's#^refs/heads/##' "$slicekit_f")
16
18
  return 0
17
19
  fi
18
20
  done
@@ -31,10 +33,28 @@ slicekit_op() {
31
33
  # Refuses when that branch is in protectedBranches of .slicekit/config.json, or is main when node or
32
34
  # the file is absent or unreadable. ALLOW_PROTECTED_COMMIT=1 overrides. Entries are names, never
33
35
  # globs: globbing is off while they are compared.
36
+ # False only when the config's text proves branch $1 cannot be protected, so node need not start; true
37
+ # whenever only node can say (D-42). Proof is kept to the hot path: a slice branch spelled in ASCII
38
+ # letters, digits and / . _ -, whose text appears nowhere in the file, in a file with no \u or \/
39
+ # escape. node prints every protectedBranches value joined, numbers in JavaScript's form and nested
40
+ # arrays joined with commas, so no other name can be ruled out from the text alone. Shell built-ins
41
+ # only, and every character class spelled out, so no locale widens it.
42
+ slicekit_named() {
43
+ [ -f .slicekit/config.json ] || return 1
44
+ case $1 in slice/P*-S-*) ;; *) return 0 ;; esac
45
+ case $1 in *[!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/._-]*) return 0 ;; esac
46
+ while IFS= read -r slicekit_line || [ -n "$slicekit_line" ]; do
47
+ case $slicekit_line in *'\u'* | *'\/'* | *"$1"*) return 0 ;; esac
48
+ done < .slicekit/config.json
49
+ return 1
50
+ }
34
51
  slicekit_check_protected() {
35
52
  [ "$ALLOW_PROTECTED_COMMIT" = "1" ] && return 0
36
- slicekit_b=$(slicekit_branch)
53
+ slicekit_branch
37
54
  [ -n "$slicekit_b" ] || return 0
55
+ # Without node or the file the list is main alone, so a branch other than main that the file never
56
+ # names cannot be protected: decided here without starting node (D-42).
57
+ [ "$slicekit_b" != main ] && ! slicekit_named "$slicekit_b" && return 0
38
58
  slicekit_p=main
39
59
  if [ -f .slicekit/config.json ] && command -v node >/dev/null 2>&1; then
40
60
  if slicekit_l=$(node -e 'const c=JSON.parse(require("fs").readFileSync(process.argv[1],"utf8").replace(/^\uFEFF/,""));const p=c.protectedBranches;if(!Array.isArray(p))process.exit(1);process.stdout.write(p.join("\n"))' .slicekit/config.json 2>/dev/null); then
@@ -4,17 +4,19 @@
4
4
  # a non-zero exit aborts the commit, so the check here covers what pre-commit never sees.
5
5
  # Arguments: <message file> [source [sha]].
6
6
  # >>> slicekit protected-branch check (identical in every slicekit hook)
7
- # The branch a commit lands on: HEAD's branch, or during a rebase the branch being rebased.
7
+ # Sets slicekit_b to the branch a commit lands on: HEAD's branch, or during a rebase the branch being
8
+ # rebased; empty on a detached HEAD. A variable, not output, so no extra shell starts to read it.
8
9
  slicekit_branch() {
10
+ slicekit_b=
9
11
  # The full ref, stripped here: --short says heads/main when a tag main exists.
10
12
  if slicekit_r=$(git symbolic-ref -q HEAD); then
11
- case $slicekit_r in refs/heads/*) printf '%s\n' "${slicekit_r#refs/heads/}" ;; esac
13
+ case $slicekit_r in refs/heads/*) slicekit_b=${slicekit_r#refs/heads/} ;; esac
12
14
  return 0
13
15
  fi
14
16
  for slicekit_d in rebase-merge rebase-apply; do
15
17
  slicekit_f=$(git rev-parse --git-path "$slicekit_d/head-name")
16
18
  if [ -f "$slicekit_f" ]; then
17
- sed -e 's#^refs/heads/##' "$slicekit_f"
19
+ slicekit_b=$(sed -e 's#^refs/heads/##' "$slicekit_f")
18
20
  return 0
19
21
  fi
20
22
  done
@@ -33,10 +35,28 @@ slicekit_op() {
33
35
  # Refuses when that branch is in protectedBranches of .slicekit/config.json, or is main when node or
34
36
  # the file is absent or unreadable. ALLOW_PROTECTED_COMMIT=1 overrides. Entries are names, never
35
37
  # globs: globbing is off while they are compared.
38
+ # False only when the config's text proves branch $1 cannot be protected, so node need not start; true
39
+ # whenever only node can say (D-42). Proof is kept to the hot path: a slice branch spelled in ASCII
40
+ # letters, digits and / . _ -, whose text appears nowhere in the file, in a file with no \u or \/
41
+ # escape. node prints every protectedBranches value joined, numbers in JavaScript's form and nested
42
+ # arrays joined with commas, so no other name can be ruled out from the text alone. Shell built-ins
43
+ # only, and every character class spelled out, so no locale widens it.
44
+ slicekit_named() {
45
+ [ -f .slicekit/config.json ] || return 1
46
+ case $1 in slice/P*-S-*) ;; *) return 0 ;; esac
47
+ case $1 in *[!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/._-]*) return 0 ;; esac
48
+ while IFS= read -r slicekit_line || [ -n "$slicekit_line" ]; do
49
+ case $slicekit_line in *'\u'* | *'\/'* | *"$1"*) return 0 ;; esac
50
+ done < .slicekit/config.json
51
+ return 1
52
+ }
36
53
  slicekit_check_protected() {
37
54
  [ "$ALLOW_PROTECTED_COMMIT" = "1" ] && return 0
38
- slicekit_b=$(slicekit_branch)
55
+ slicekit_branch
39
56
  [ -n "$slicekit_b" ] || return 0
57
+ # Without node or the file the list is main alone, so a branch other than main that the file never
58
+ # names cannot be protected: decided here without starting node (D-42).
59
+ [ "$slicekit_b" != main ] && ! slicekit_named "$slicekit_b" && return 0
40
60
  slicekit_p=main
41
61
  if [ -f .slicekit/config.json ] && command -v node >/dev/null 2>&1; then
42
62
  if slicekit_l=$(node -e 'const c=JSON.parse(require("fs").readFileSync(process.argv[1],"utf8").replace(/^\uFEFF/,""));const p=c.protectedBranches;if(!Array.isArray(p))process.exit(1);process.stdout.write(p.join("\n"))' .slicekit/config.json 2>/dev/null); then
@@ -65,7 +85,23 @@ case "$2" in
65
85
  merge) exit 0 ;;
66
86
  esac
67
87
 
68
- slice=$(slicekit_branch | sed -n 's#^slice/P\([0-9][0-9]*\)-S-\([0-9][0-9]\)\(-.*\)\{0,1\}$#P\1/S-\2#p')
88
+ # The branch the check read; under ALLOW_PROTECTED_COMMIT=1 the check reads none, so it is read here.
89
+ [ "$ALLOW_PROTECTED_COMMIT" = "1" ] && slicekit_branch
90
+ # slice/P<n>-S-<nn>[-<descr>] gives P<n>/S-<nn>, with shell built-ins only.
91
+ slice=
92
+ case $slicekit_b in
93
+ slice/P*-S-*)
94
+ slicekit_n=${slicekit_b#slice/P}
95
+ slicekit_s=${slicekit_n#*-S-}
96
+ slicekit_n=${slicekit_n%%-S-*}
97
+ case $slicekit_s in
98
+ [0123456789][0123456789] | [0123456789][0123456789]-*) slicekit_s=${slicekit_s%%-*} ;;
99
+ *) slicekit_s= ;;
100
+ esac
101
+ case $slicekit_n in '' | *[!0123456789]*) slicekit_s= ;; esac
102
+ [ -n "$slicekit_s" ] && slice="P$slicekit_n/S-$slicekit_s"
103
+ ;;
104
+ esac
69
105
  [ -n "$slice" ] || exit 0
70
106
 
71
107
  # The trailer joins the message's final trailer block as its first line, or starts one; a block
@@ -1,13 +1,14 @@
1
1
  # Brief: reviewer
2
2
 
3
- You review one slice and write one verdict file. You try to break the change: run its tests, read its diff against the slice file, the requirements it cites and the writing rules. The command that spawned you records your verdict and commits it.
3
+ You review one slice and write one verdict file. You try to break the change: run its tests, read its diff against the slice file, the requirements it cites and the writing rules.
4
4
 
5
5
  ## You write
6
6
 
7
- One verdict file and nothing else. The command gives you the absolute path to write it at; the path ends `.slicekit/reviews/P<n>-S-<nn>[i]-r<k>.md` and is in the session root, never under the worktree. It is the one file you write outside the worktree. `k` is the round; the letter `i` marks an independent review. The file has this shape:
7
+ One verdict file and nothing else. The command gives you the absolute path to write it at; the path ends `.slicekit/reviews/P<n>-S-<nn>[i]-r<k>.md` and is in the session root, never under the worktree. `k` is the round; the letter `i` marks an independent review. The file has this shape:
8
8
 
9
9
  ```
10
10
  Verdict: BLOCK
11
+ Head: 3f2a9c1e0b7d4a5c8e6f1029384756abcdef0123
11
12
 
12
13
  | ID | File:line | What is wrong | Why it matters | How verified |
13
14
  |---|---|---|---|---|
@@ -24,7 +25,7 @@ Verdict: BLOCK
24
25
  - The CI run; it had not finished.
25
26
  ```
26
27
 
27
- The first line is the verdict, and the file holds no other `Verdict:` line. Choose it by these rules:
28
+ The first line is `Verdict: BLOCK|CHANGES|APPROVE`; the file holds no other `Verdict:` line. Choose it by these rules:
28
29
 
29
30
  - `Verdict: BLOCK` when any blocker is open.
30
31
  - `Verdict: CHANGES` when there is no blocker and at least one should-have.
@@ -32,6 +33,7 @@ The first line is the verdict, and the file holds no other `Verdict:` line. Choo
32
33
 
33
34
  The rest of the file:
34
35
 
36
+ - `Head: <sha>` is the full id of the commit you reviewed (`git log -1 --format=%H`); another head is refused.
35
37
  - A blocker's ID is `B-<n>` and a should-have's ID is `H-<n>`, each used once.
36
38
  - Every finding names its file and line, what is wrong, why it matters and how you verified it: the command you ran and its output, or `read only`. A finding with no "How verified" entry is refused.
37
39
  - `## Checklists run` lists each checklist you ran, one item per line; at least one.
@@ -39,15 +41,13 @@ The rest of the file:
39
41
 
40
42
  ## Reviewing a slice
41
43
 
42
- The command gives you the pull request number, the worktree, the round `k` and the verdict file's absolute path. Write the verdict at that path, with the first line one of:
43
-
44
- Verdict: BLOCK|CHANGES|APPROVE
44
+ The command gives you the pull request number, the worktree, the round `k` and the verdict file's absolute path. Write the verdict at that path.
45
45
 
46
46
  1. Read the slice file in the worktree, the change with `git diff <base>...HEAD` run in the worktree (read only; `<base>` is `defaultBranch` in `.slicekit/config.json`), and the pull request body.
47
47
  2. Run the test command and `{{cli}} check` in the worktree. Quote each one's summary line in the "How verified" column of the findings it supports.
48
48
  3. A blocker is one of these: a Done when check that fails; a REQ or D row the change breaks; a rule weakened or a baseline raised (REQ-3.7); a writing-rule breach in the pull request body. Every other finding is a should-have.
49
49
  4. Finding IDs are unique within the slice. A finding that survives from an earlier round keeps its ID. A new finding takes the next number never used in this slice, B and H counted apart: after B-1 and B-2, a new blocker is B-3 even when B-2 was fixed. A verdict that reuses a number, or gives a finding that went away its old ID, is refused.
50
- 5. A verdict that uses a phrase from `style.banned` in `.slicekit/config.json` is refused; reword it. The pull request body quotes each "What is wrong" as a code span, so a `<!--` in it is refused.
50
+ 5. A verdict that uses a phrase from `style.banned` in `.slicekit/config.json`, or names missing IDs or backticked paths, is refused; reword it. The pull request body quotes each "What is wrong" as a code span, so a `<!--` in it is refused.
51
51
  6. A should-have whose issue the pull request body lists under "Should-haves declined" is not raised again.
52
52
  7. A finding states the fault and stops: no praise, no question, no code.
53
53
 
@@ -86,6 +86,11 @@ change. On no, tell the developer the test stands. On yes:
86
86
  3. Run `{{cli}} build amend <id> --test <test path> --reason "<why>" --worktree <path>`, and tell
87
87
  the developer it may change that one test.
88
88
 
89
+ `build amend` also runs at `draft-pr`, `in-review` and `changes-requested`, for a finding that sits
90
+ inside a frozen test: the same three steps, then the slice is back at `building`. The fixer (or the
91
+ developer) changes that test, and step 7's `build commit` and `build pr` take the slice back to
92
+ `draft-pr` on the same pull request.
93
+
89
94
  ## 5. Green, then the draft pull request
90
95
 
91
96
  When the developer reports every test passing, run
@@ -93,6 +98,27 @@ When the developer reports every test passing, run
93
98
  `<sha7> exit 0`, or `nothing to commit` with exit 0 when step 4 already committed everything; both
94
99
  are success. A failing test run is refused: send the developer back with the printed summary.
95
100
 
101
+ When the slice changes the kit's own version, run `{{cli}} build render <id> --worktree <path>`
102
+ next, with the kit the slice ships. It runs `update --yes` in the worktree and commits only the files
103
+ update writes, as `chore(slicekit): <id> render`, and prints `<sha7> render (<n> files)`, or
104
+ `nothing to render`. Never commit those files by hand: `build commit` accepts a render commit only
105
+ when it holds nothing but the files update writes, and only while those files, at the slice's head,
106
+ are what a fresh render writes. A refusal that says `run slicekit build render <id> again` means
107
+ they differ (the kit changed since the render, a template fix): run `build render` again, then
108
+ `build commit`.
109
+
110
+ When the slice changes the kit's own config and its Expected changes name `.slicekit/config.json`,
111
+ run `{{cli}} build config <id> --worktree <path>` once the config holds the change. It commits the
112
+ config alone, as `chore(slicekit): <id> config`, and prints `<sha7> config`, or `nothing to commit`.
113
+ `build commit` refuses a changed config with `; run slicekit build config <id>`, and accepts the
114
+ config commit only while the slice file names the config. Never commit the config by hand.
115
+
116
+ A machine that cannot run the whole test command at once may set it in `.slicekit/local.json` in
117
+ the main checkout, for example `{"testCommand": "node --test --test-concurrency=2 \"test/**/*.test.js\""}`.
118
+ `build red`, `build commit` and `build pr` then run that command and print
119
+ `ran the test command from .slicekit/local.json: <command>`. Under CI the file is never read, and
120
+ `{{cli}} check --ci` judges the committed command; never commit the file.
121
+
96
122
  Write the notes file from the developer's report to a file outside the repository:
97
123
  `slicekit-notes-<id>.json` in your scratchpad or temp directory, with the `/` in `<id>` written as
98
124
  `-` (for example `slicekit-notes-P1-S-01.json`). It is one JSON object:
@@ -127,14 +153,18 @@ When the reviewer stops, run `{{cli}} build verdict <id> <file> --worktree <path
127
153
  path. It commits the verdict into the worktree, pushes, and prints `next: <step>`,
128
154
  `blockers: <IDs or none>`, `should-haves: <IDs or none>` and `rounds: <used> of 2`, and last a new
129
155
  `verdict <file>` line when another round is allowed. A refusal that names the verdict's content (a
130
- finding with no "How verified", a reused finding number, a banned phrase, a `<!--`) goes back to the
131
- reviewer with the printed message; run this command again with the file it writes. A refusal that
156
+ finding with no "How verified", a reused finding number, a banned phrase, a `<!--`, an unknown ID or
157
+ path) goes back to the reviewer with the printed message; run this command again with the file it writes. A refusal that
132
158
  says `a new verdict needs a fresh fetch` means origin could not be reached: print it and stop, and
133
159
  tell the human to run the step again once origin answers. A refusal that
134
160
  says `run slicekit build pr <id> first` means code was committed that `build pr` has not seen: run
135
161
  step 5's `build pr`, then step 6 again from the start with the path it prints, since that code needs
136
- a review of its own. A refusal that says a file `differs from` another goes to the human: print it
137
- and stop. Then act on `next:`:
162
+ a review of its own. At `draft-pr` that `build pr` records the moved head (a merge of the default
163
+ branch, or any commit) in a bookkeeping commit and prints `head <sha> recorded; the next verdict
164
+ reviews it` before the verdict path. A refusal that says a verdict `reviewed head <a>; the recorded
165
+ head is <b>` means the verdict is on an older head: spawn the reviewer again on the recorded head,
166
+ with the same verdict path. A refusal that says a file `differs from` another goes to the human:
167
+ print it and stop. Then act on `next:`:
138
168
 
139
169
  - `next: fix`: step 7.
140
170
  - `next: ask`: step 8.
@@ -2,5 +2,6 @@
2
2
  "resolved": "2026-10-25",
3
3
  "actions/checkout": { "tag": "v4.2.2", "sha": "11bd71901bbe5b1630ceea73d27597364c9af683" },
4
4
  "actions/setup-node": { "tag": "v4.1.0", "sha": "39370e3970a6d050c480ffad4ff0ed4d3fdee5af" },
5
- "actions/upload-artifact": { "tag": "v4.4.3", "sha": "b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882" }
5
+ "actions/upload-artifact": { "tag": "v4.4.3", "sha": "b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882" },
6
+ "actions/cache": { "tag": "v4.2.3", "sha": "5a3ec84eff668545956fd18022155c47e93e2684" }
6
7
  }
@@ -22,6 +22,12 @@ jobs:
22
22
  gate:
23
23
  runs-on: ubuntu-latest
24
24
  timeout-minutes: {{timeoutMinutes}}
25
+ permissions:
26
+ actions: read
27
+ contents: read
28
+ pull-requests: read
29
+ outputs:
30
+ kind: ${{ steps.bookkeeping.outputs.kind }}
25
31
  steps:
26
32
  - uses: actions/checkout@{{checkoutSha}} # {{checkoutTag}}
27
33
  with:
@@ -35,8 +41,33 @@ jobs:
35
41
  - name: Install
36
42
  if: hashFiles('package-lock.json') != ''
37
43
  run: npm ci
44
+ - name: Bookkeeping or code (D-49)
45
+ id: bookkeeping
46
+ env:
47
+ GH_TOKEN: ${{ github.token }}
48
+ SLICEKIT_PR_HEAD: ${{ github.event.pull_request.head.sha }}
49
+ SLICEKIT_PR_BASE_BRANCH: ${{ github.base_ref }}
50
+ run: {{cli}} ci bookkeeping --head "$SLICEKIT_PR_HEAD" --base-branch "$SLICEKIT_PR_BASE_BRANCH" --output "$GITHUB_OUTPUT"
38
51
  - name: Use the repository's git hooks
39
52
  run: git config core.hooksPath .githooks
53
+ # The pull request cache (D-52): only a merged answer is final, so a run fetches only open,
54
+ # closed and new pull requests. A pull request run saves only to its own branch's cache.
55
+ - name: Restore the pull request cache
56
+ uses: actions/cache/restore@{{cacheSha}} # {{cacheTag}}
57
+ with:
58
+ path: .slicekit/graph/cache
59
+ key: slicekit-pr-cache-${{ github.run_id }}
60
+ restore-keys: slicekit-pr-cache-
61
+ - name: Build the graph
62
+ env:
63
+ GH_TOKEN: ${{ github.token }}
64
+ run: {{cli}} graph
65
+ - name: Save the pull request cache
66
+ if: always()
67
+ uses: actions/cache/save@{{cacheSha}} # {{cacheTag}}
68
+ with:
69
+ path: .slicekit/graph/cache
70
+ key: slicekit-pr-cache-${{ github.run_id }}
40
71
  {{gateExtraSteps}}
41
72
  - name: slicekit check
42
73
  run: {{cli}} check --ci
@@ -74,7 +105,7 @@ jobs:
74
105
  - name: Ready label
75
106
  env:
76
107
  GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77
- SLICEKIT_CHECKS_OK: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') && !contains(needs.*.result, 'skipped') }}
108
+ SLICEKIT_CHECKS_OK: {{checksOk}}
78
109
  run: {{cli}} ready-label
79
110
 
80
111
  sync: