slicekit 0.0.1 → 0.1.1

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 +276 -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 +59 -0
  154. package/templates/githooks/pre-merge-commit +59 -0
  155. package/templates/githooks/prepare-commit-msg +74 -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,90 @@
1
+ {
2
+ "SessionStart": [
3
+ {
4
+ "hooks": [
5
+ {
6
+ "type": "command",
7
+ "command": "{{cli}} hook session-start",
8
+ "timeout": 20
9
+ }
10
+ ]
11
+ }
12
+ ],
13
+ "PreToolUse": [
14
+ {
15
+ "matcher": "Bash",
16
+ "hooks": [
17
+ {
18
+ "type": "command",
19
+ "command": "{{cli}} hook pre-bash",
20
+ "timeout": 20
21
+ }
22
+ ]
23
+ },
24
+ {
25
+ "matcher": "Edit|Write|MultiEdit|NotebookEdit",
26
+ "hooks": [
27
+ {
28
+ "type": "command",
29
+ "command": "{{cli}} hook pre-edit",
30
+ "timeout": 20
31
+ }
32
+ ]
33
+ }
34
+ ],
35
+ "SubagentStart": [
36
+ {
37
+ "hooks": [
38
+ {
39
+ "type": "command",
40
+ "command": "{{cli}} hook subagent-start",
41
+ "timeout": 20
42
+ }
43
+ ]
44
+ }
45
+ ],
46
+ "SubagentStop": [
47
+ {
48
+ "hooks": [
49
+ {
50
+ "type": "command",
51
+ "command": "{{cli}} hook subagent-stop",
52
+ "timeout": 20
53
+ }
54
+ ]
55
+ }
56
+ ],
57
+ "PreCompact": [
58
+ {
59
+ "hooks": [
60
+ {
61
+ "type": "command",
62
+ "command": "{{cli}} hook pre-compact",
63
+ "timeout": 20
64
+ }
65
+ ]
66
+ }
67
+ ],
68
+ "Stop": [
69
+ {
70
+ "hooks": [
71
+ {
72
+ "type": "command",
73
+ "command": "{{cli}} hook stop",
74
+ "timeout": 120
75
+ }
76
+ ]
77
+ }
78
+ ],
79
+ "SessionEnd": [
80
+ {
81
+ "hooks": [
82
+ {
83
+ "type": "command",
84
+ "command": "{{cli}} hook session-end",
85
+ "timeout": 20
86
+ }
87
+ ]
88
+ }
89
+ ]
90
+ }
@@ -0,0 +1,171 @@
1
+ [
2
+ {
3
+ "src": "commands/slicekit.md",
4
+ "dest": ".claude/commands/slicekit.md",
5
+ "shapes": [
6
+ "backend",
7
+ "fullstack",
8
+ "data"
9
+ ]
10
+ },
11
+ {
12
+ "src": "commands/slicekit-intake.md",
13
+ "dest": ".claude/commands/slicekit-intake.md",
14
+ "shapes": [
15
+ "backend",
16
+ "fullstack",
17
+ "data"
18
+ ]
19
+ },
20
+ {
21
+ "src": "commands/slicekit-specify.md",
22
+ "dest": ".claude/commands/slicekit-specify.md",
23
+ "shapes": [
24
+ "backend",
25
+ "fullstack",
26
+ "data"
27
+ ]
28
+ },
29
+ {
30
+ "src": "commands/slicekit-gaps.md",
31
+ "dest": ".claude/commands/slicekit-gaps.md",
32
+ "shapes": [
33
+ "backend",
34
+ "fullstack",
35
+ "data"
36
+ ]
37
+ },
38
+ {
39
+ "src": "commands/slicekit-plan.md",
40
+ "dest": ".claude/commands/slicekit-plan.md",
41
+ "shapes": [
42
+ "backend",
43
+ "fullstack",
44
+ "data"
45
+ ]
46
+ },
47
+ {
48
+ "src": "commands/slicekit-build.md",
49
+ "dest": ".claude/commands/slicekit-build.md",
50
+ "shapes": [
51
+ "backend",
52
+ "fullstack",
53
+ "data"
54
+ ]
55
+ },
56
+ {
57
+ "src": "commands/slicekit-review.md",
58
+ "dest": ".claude/commands/slicekit-review.md",
59
+ "shapes": [
60
+ "backend",
61
+ "fullstack",
62
+ "data"
63
+ ]
64
+ },
65
+ {
66
+ "src": "commands/slicekit-release.md",
67
+ "dest": ".claude/commands/slicekit-release.md",
68
+ "shapes": [
69
+ "backend",
70
+ "fullstack",
71
+ "data"
72
+ ]
73
+ },
74
+ {
75
+ "src": "commands/slicekit-ops.md",
76
+ "dest": ".claude/commands/slicekit-ops.md",
77
+ "shapes": [
78
+ "backend",
79
+ "fullstack",
80
+ "data"
81
+ ]
82
+ },
83
+ {
84
+ "src": "commands/slicekit-audit.md",
85
+ "dest": ".claude/commands/slicekit-audit.md",
86
+ "shapes": [
87
+ "backend",
88
+ "fullstack",
89
+ "data"
90
+ ]
91
+ },
92
+ {
93
+ "src": "agents/developer.md",
94
+ "dest": ".claude/agents/developer.md",
95
+ "shapes": [
96
+ "backend",
97
+ "fullstack",
98
+ "data"
99
+ ]
100
+ },
101
+ {
102
+ "src": "agents/reviewer.md",
103
+ "dest": ".claude/agents/reviewer.md",
104
+ "shapes": [
105
+ "backend",
106
+ "fullstack",
107
+ "data"
108
+ ]
109
+ },
110
+ {
111
+ "src": "agents/fixer.md",
112
+ "dest": ".claude/agents/fixer.md",
113
+ "shapes": [
114
+ "backend",
115
+ "fullstack",
116
+ "data"
117
+ ]
118
+ },
119
+ {
120
+ "src": "agents/auditor.md",
121
+ "dest": ".claude/agents/auditor.md",
122
+ "shapes": [
123
+ "backend",
124
+ "fullstack",
125
+ "data"
126
+ ]
127
+ },
128
+ {
129
+ "src": "agents/ops.md",
130
+ "dest": ".claude/agents/ops.md",
131
+ "shapes": [
132
+ "backend",
133
+ "fullstack",
134
+ "data"
135
+ ]
136
+ },
137
+ {
138
+ "src": "agents/designer.md",
139
+ "dest": ".claude/agents/designer.md",
140
+ "shapes": [
141
+ "fullstack"
142
+ ]
143
+ },
144
+ {
145
+ "src": "skills/slicekit-writing/SKILL.md",
146
+ "dest": ".claude/skills/slicekit-writing/SKILL.md",
147
+ "shapes": [
148
+ "backend",
149
+ "fullstack",
150
+ "data"
151
+ ]
152
+ },
153
+ {
154
+ "src": "skills/slicekit-ids/SKILL.md",
155
+ "dest": ".claude/skills/slicekit-ids/SKILL.md",
156
+ "shapes": [
157
+ "backend",
158
+ "fullstack",
159
+ "data"
160
+ ]
161
+ },
162
+ {
163
+ "src": "skills/slicekit-loop/SKILL.md",
164
+ "dest": ".claude/skills/slicekit-loop/SKILL.md",
165
+ "shapes": [
166
+ "backend",
167
+ "fullstack",
168
+ "data"
169
+ ]
170
+ }
171
+ ]
@@ -0,0 +1,16 @@
1
+ ---
2
+ name: slicekit-ids
3
+ description: The ID forms slicekit uses for requirements, decisions, gaps, contracts, phases, slices, branches, trailers and pull request titles.
4
+ ---
5
+ # IDs
6
+
7
+ - Requirement: `REQ-<section>.<n>`
8
+ - Decision: `D-<n>`
9
+ - Gap: `G-<n>`
10
+ - Contract: `C-<n>`
11
+ - Phase: `P<n>`
12
+ - Slice: `S-<nn>`
13
+ - Slice address: `P<n>/S-<nn>`
14
+ - Slice branch: `slice/P<n>-S-<nn>-<descr>`
15
+ - Commit trailer on a slice branch: `Slice: P<n>/S-<nn>`
16
+ - Pull request title: begins `[P<n>/S-<nn>]`
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: slicekit-loop
3
+ description: The slice states in order and the nine steps of the build loop.
4
+ ---
5
+ # The loop
6
+
7
+ ## States, in order
8
+
9
+ `todo`, `tests-red`, `building`, `draft-pr`, `in-review`, `changes-requested`, `ci-green`, `ready`, `merged`, `released`.
10
+
11
+ Only the CLI writes the state file.
12
+
13
+ ## Build steps
14
+
15
+ 1. Create a worktree and the branch `slice/P<n>-S-<nn>-<descr>` from the default branch.
16
+ 2. Spawn developer with `{{cli}} instructions developer P<n>/S-<nn>`.
17
+ 3. Run the developer's tests, require a non-zero exit, commit, set `tests-red`, freeze the test files.
18
+ 4. Set `building`; developer makes the tests pass; commit each time a new test passes, with the trailer.
19
+ 5. Run the test, lint and build commands and `slicekit check`; push; open a draft pull request; set `draft-pr`.
20
+ 6. Spawn reviewer with the pull request number; receive the verdict file; set `in-review`.
21
+ 7. On blockers spawn fixer and review again, at most two rounds; a blocker after round two sets `changes-requested`.
22
+ 8. For should-haves ask the human once per round; a decline goes in the pull request body and becomes an issue.
23
+ 9. With zero open blockers mark the pull request ready, set `ci-green` when CI passes, stop; a human merges.
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: slicekit-writing
3
+ description: Writing rules for every document, verdict, report and pull request body the kit produces.
4
+ ---
5
+ # Writing rules
6
+
7
+ - State the fact, the consequence, the check. Not the importance.
8
+ - No metaphor in a requirement, a verdict or a runbook.
9
+ - A number goes in a table or on its own line.
10
+ - Every claim of "done" names the command that proved it and quotes its summary line.
11
+ - Every agent reply ends with what it skipped and what it did not check.
12
+
13
+ ## Filler the check rejects
14
+ <!-- slicekit:style-catalogue -->
15
+
16
+ - minting at the gate
17
+ - at the boundary of
18
+ - it's worth noting
19
+ - robust
20
+ - seamlessly
21
+ - leverage
22
+ - delve
23
+
24
+ `slicekit check` fails on these phrases. The reviewer flags filler the list cannot match.
@@ -0,0 +1,5 @@
1
+ # BUILD — the queue
2
+
3
+ One slice, one branch, one pull request. A slice is done when a human has merged it.
4
+ Status is `Todo`, `PR #n`, or `Done`. This file is regenerated by `slicekit status --write`; edit the slice files, not this table.
5
+ Spec: `{{docsRoot}}/spec/`. Decisions: `{{docsRoot}}/decisions.md`. Slice files: `{{docsRoot}}/phases/`.
@@ -0,0 +1,15 @@
1
+ # Decisions
2
+
3
+ Every question that needs an answer from a person gets one row, with an ID the spec cites. Answered rows move to Settled. Rows still waiting stay in Open.
4
+
5
+ **Type.** *Decision* = the team chose. *Action* = only a human can do it. *Information* = a fact we did not have. *Counsel* = an expert view is needed. *Open* = not yet answered.
6
+
7
+ ## Settled
8
+
9
+ | # | Type | Question | Answer | Who, when |
10
+ |---|------|----------|--------|-----------|
11
+
12
+ ## Open
13
+
14
+ | # | Type | Question | Why it matters | Recommendation |
15
+ |---|------|----------|----------------|----------------|
File without changes
@@ -0,0 +1,25 @@
1
+ # Observability
2
+
3
+ ## Dashboards
4
+
5
+ Not yet known
6
+
7
+ ## Alert routes
8
+
9
+ Not yet known
10
+
11
+ ## Log shape and required fields
12
+
13
+ Not yet known
14
+
15
+ ## Trace and correlation IDs
16
+
17
+ Not yet known
18
+
19
+ ## CI steps the monitoring setup requires
20
+
21
+ Not yet known
22
+
23
+ ## On-call contact
24
+
25
+ Not yet known
File without changes
@@ -0,0 +1,25 @@
1
+ # Platform
2
+
3
+ ## Providers and services
4
+
5
+ Not yet known
6
+
7
+ ## Environments
8
+
9
+ Not yet known
10
+
11
+ ## How a change reaches each environment
12
+
13
+ Not yet known
14
+
15
+ ## Access and ownership
16
+
17
+ Not yet known
18
+
19
+ ## Secrets
20
+
21
+ Not yet known
22
+
23
+ ## Network boundaries
24
+
25
+ Not yet known
File without changes
@@ -0,0 +1,21 @@
1
+ # Runbook: {{name}}
2
+
3
+ ## How to run it
4
+
5
+ Not yet known
6
+
7
+ ## Dependencies and their owners
8
+
9
+ Not yet known
10
+
11
+ ## Known failure modes and the first thing to check
12
+
13
+ Not yet known
14
+
15
+ ## Actions and who may take them
16
+
17
+ Not yet known
18
+
19
+ ## Rollback
20
+
21
+ Not yet known
@@ -0,0 +1,8 @@
1
+ # {{name}}: overview
2
+
3
+ Source: ../intake/
4
+ Decisions: ../decisions.md
5
+
6
+ ## Sections
7
+
8
+ - (none yet)
File without changes
@@ -0,0 +1,6 @@
1
+ # Gaps
2
+
3
+ Each row is a place where the spec is silent, vague or in conflict with the intake. A gap stays here until a decision or a spec change closes it.
4
+
5
+ | # | Class | Where | What | Closed by |
6
+ |---|-------|-------|------|-----------|
@@ -0,0 +1,3 @@
1
+ # Stack
2
+
3
+ Not yet known
@@ -0,0 +1,59 @@
1
+ #!/bin/sh
2
+ # slicekit: refuses a commit on a protected branch (REQ-3.9). Installed as pre-commit and as
3
+ # pre-merge-commit, byte for byte; prepare-commit-msg carries the same check between the markers.
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.
6
+ slicekit_branch() {
7
+ # The full ref, stripped here: --short says heads/main when a tag main exists.
8
+ if slicekit_r=$(git symbolic-ref -q HEAD); then
9
+ case $slicekit_r in refs/heads/*) printf '%s\n' "${slicekit_r#refs/heads/}" ;; esac
10
+ return 0
11
+ fi
12
+ for slicekit_d in rebase-merge rebase-apply; do
13
+ slicekit_f=$(git rev-parse --git-path "$slicekit_d/head-name")
14
+ if [ -f "$slicekit_f" ]; then
15
+ sed -e 's#^refs/heads/##' "$slicekit_f"
16
+ return 0
17
+ fi
18
+ done
19
+ return 0
20
+ }
21
+ # The operation in progress, if any, so a refusal can say how to give up on it.
22
+ slicekit_op() {
23
+ slicekit_g=$(git rev-parse --git-dir)
24
+ if [ -f "$slicekit_g/rebase-apply/applying" ]; then echo am
25
+ elif [ -d "$slicekit_g/rebase-merge" ] || [ -d "$slicekit_g/rebase-apply" ]; then echo rebase
26
+ elif [ -f "$slicekit_g/CHERRY_PICK_HEAD" ]; then echo cherry-pick
27
+ elif [ -f "$slicekit_g/REVERT_HEAD" ]; then echo revert
28
+ elif [ -f "$slicekit_g/MERGE_HEAD" ]; then echo merge
29
+ fi
30
+ }
31
+ # Refuses when that branch is in protectedBranches of .slicekit/config.json, or is main when node or
32
+ # the file is absent or unreadable. ALLOW_PROTECTED_COMMIT=1 overrides. Entries are names, never
33
+ # globs: globbing is off while they are compared.
34
+ slicekit_check_protected() {
35
+ [ "$ALLOW_PROTECTED_COMMIT" = "1" ] && return 0
36
+ slicekit_b=$(slicekit_branch)
37
+ [ -n "$slicekit_b" ] || return 0
38
+ slicekit_p=main
39
+ if [ -f .slicekit/config.json ] && command -v node >/dev/null 2>&1; then
40
+ 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
41
+ slicekit_p=$slicekit_l
42
+ fi
43
+ fi
44
+ slicekit_hit=
45
+ set -f
46
+ for slicekit_n in $slicekit_p; do
47
+ [ "$slicekit_n" = "$slicekit_b" ] && slicekit_hit=1
48
+ done
49
+ set +f
50
+ [ -n "$slicekit_hit" ] || return 0
51
+ slicekit_o=$(slicekit_op)
52
+ slicekit_give_up=
53
+ [ -n "$slicekit_o" ] && slicekit_give_up="; to give up, run git $slicekit_o --abort"
54
+ echo "slicekit: $slicekit_b is protected; commit on a slice branch, or set ALLOW_PROTECTED_COMMIT=1$slicekit_give_up" >&2
55
+ return 1
56
+ }
57
+ # <<< slicekit protected-branch check
58
+ slicekit_check_protected || exit 1
59
+ exit 0
@@ -0,0 +1,59 @@
1
+ #!/bin/sh
2
+ # slicekit: refuses a commit on a protected branch (REQ-3.9). Installed as pre-commit and as
3
+ # pre-merge-commit, byte for byte; prepare-commit-msg carries the same check between the markers.
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.
6
+ slicekit_branch() {
7
+ # The full ref, stripped here: --short says heads/main when a tag main exists.
8
+ if slicekit_r=$(git symbolic-ref -q HEAD); then
9
+ case $slicekit_r in refs/heads/*) printf '%s\n' "${slicekit_r#refs/heads/}" ;; esac
10
+ return 0
11
+ fi
12
+ for slicekit_d in rebase-merge rebase-apply; do
13
+ slicekit_f=$(git rev-parse --git-path "$slicekit_d/head-name")
14
+ if [ -f "$slicekit_f" ]; then
15
+ sed -e 's#^refs/heads/##' "$slicekit_f"
16
+ return 0
17
+ fi
18
+ done
19
+ return 0
20
+ }
21
+ # The operation in progress, if any, so a refusal can say how to give up on it.
22
+ slicekit_op() {
23
+ slicekit_g=$(git rev-parse --git-dir)
24
+ if [ -f "$slicekit_g/rebase-apply/applying" ]; then echo am
25
+ elif [ -d "$slicekit_g/rebase-merge" ] || [ -d "$slicekit_g/rebase-apply" ]; then echo rebase
26
+ elif [ -f "$slicekit_g/CHERRY_PICK_HEAD" ]; then echo cherry-pick
27
+ elif [ -f "$slicekit_g/REVERT_HEAD" ]; then echo revert
28
+ elif [ -f "$slicekit_g/MERGE_HEAD" ]; then echo merge
29
+ fi
30
+ }
31
+ # Refuses when that branch is in protectedBranches of .slicekit/config.json, or is main when node or
32
+ # the file is absent or unreadable. ALLOW_PROTECTED_COMMIT=1 overrides. Entries are names, never
33
+ # globs: globbing is off while they are compared.
34
+ slicekit_check_protected() {
35
+ [ "$ALLOW_PROTECTED_COMMIT" = "1" ] && return 0
36
+ slicekit_b=$(slicekit_branch)
37
+ [ -n "$slicekit_b" ] || return 0
38
+ slicekit_p=main
39
+ if [ -f .slicekit/config.json ] && command -v node >/dev/null 2>&1; then
40
+ 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
41
+ slicekit_p=$slicekit_l
42
+ fi
43
+ fi
44
+ slicekit_hit=
45
+ set -f
46
+ for slicekit_n in $slicekit_p; do
47
+ [ "$slicekit_n" = "$slicekit_b" ] && slicekit_hit=1
48
+ done
49
+ set +f
50
+ [ -n "$slicekit_hit" ] || return 0
51
+ slicekit_o=$(slicekit_op)
52
+ slicekit_give_up=
53
+ [ -n "$slicekit_o" ] && slicekit_give_up="; to give up, run git $slicekit_o --abort"
54
+ echo "slicekit: $slicekit_b is protected; commit on a slice branch, or set ALLOW_PROTECTED_COMMIT=1$slicekit_give_up" >&2
55
+ return 1
56
+ }
57
+ # <<< slicekit protected-branch check
58
+ slicekit_check_protected || exit 1
59
+ exit 0
@@ -0,0 +1,74 @@
1
+ #!/bin/sh
2
+ # slicekit: refuses a commit on a protected branch, then adds the Slice trailer on a slice branch
3
+ # (REQ-3.9, REQ-1.9). git runs this hook for commit, merge, cherry-pick, revert and rebase picks, and
4
+ # a non-zero exit aborts the commit, so the check here covers what pre-commit never sees.
5
+ # Arguments: <message file> [source [sha]].
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.
8
+ slicekit_branch() {
9
+ # The full ref, stripped here: --short says heads/main when a tag main exists.
10
+ if slicekit_r=$(git symbolic-ref -q HEAD); then
11
+ case $slicekit_r in refs/heads/*) printf '%s\n' "${slicekit_r#refs/heads/}" ;; esac
12
+ return 0
13
+ fi
14
+ for slicekit_d in rebase-merge rebase-apply; do
15
+ slicekit_f=$(git rev-parse --git-path "$slicekit_d/head-name")
16
+ if [ -f "$slicekit_f" ]; then
17
+ sed -e 's#^refs/heads/##' "$slicekit_f"
18
+ return 0
19
+ fi
20
+ done
21
+ return 0
22
+ }
23
+ # The operation in progress, if any, so a refusal can say how to give up on it.
24
+ slicekit_op() {
25
+ slicekit_g=$(git rev-parse --git-dir)
26
+ if [ -f "$slicekit_g/rebase-apply/applying" ]; then echo am
27
+ elif [ -d "$slicekit_g/rebase-merge" ] || [ -d "$slicekit_g/rebase-apply" ]; then echo rebase
28
+ elif [ -f "$slicekit_g/CHERRY_PICK_HEAD" ]; then echo cherry-pick
29
+ elif [ -f "$slicekit_g/REVERT_HEAD" ]; then echo revert
30
+ elif [ -f "$slicekit_g/MERGE_HEAD" ]; then echo merge
31
+ fi
32
+ }
33
+ # Refuses when that branch is in protectedBranches of .slicekit/config.json, or is main when node or
34
+ # the file is absent or unreadable. ALLOW_PROTECTED_COMMIT=1 overrides. Entries are names, never
35
+ # globs: globbing is off while they are compared.
36
+ slicekit_check_protected() {
37
+ [ "$ALLOW_PROTECTED_COMMIT" = "1" ] && return 0
38
+ slicekit_b=$(slicekit_branch)
39
+ [ -n "$slicekit_b" ] || return 0
40
+ slicekit_p=main
41
+ if [ -f .slicekit/config.json ] && command -v node >/dev/null 2>&1; then
42
+ 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
43
+ slicekit_p=$slicekit_l
44
+ fi
45
+ fi
46
+ slicekit_hit=
47
+ set -f
48
+ for slicekit_n in $slicekit_p; do
49
+ [ "$slicekit_n" = "$slicekit_b" ] && slicekit_hit=1
50
+ done
51
+ set +f
52
+ [ -n "$slicekit_hit" ] || return 0
53
+ slicekit_o=$(slicekit_op)
54
+ slicekit_give_up=
55
+ [ -n "$slicekit_o" ] && slicekit_give_up="; to give up, run git $slicekit_o --abort"
56
+ echo "slicekit: $slicekit_b is protected; commit on a slice branch, or set ALLOW_PROTECTED_COMMIT=1$slicekit_give_up" >&2
57
+ return 1
58
+ }
59
+ # <<< slicekit protected-branch check
60
+ slicekit_check_protected || exit 1
61
+
62
+ # A merge message is left as git wrote it. A squash merge is an ordinary change on the branch, so
63
+ # it is stamped like one.
64
+ case "$2" in
65
+ merge) exit 0 ;;
66
+ esac
67
+
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')
69
+ [ -n "$slice" ] || exit 0
70
+
71
+ # The trailer joins the message's final trailer block as its first line, or starts one; a block
72
+ # that already holds a Slice trailer is left alone, so an amend never adds a second. A `---` line
73
+ # in the body is text, not a patch divider.
74
+ exec git interpret-trailers --in-place --no-divider --where start --if-exists doNothing --trailer "Slice: $slice" "$1"