@jeiemgi/cckit 0.8.0 → 0.10.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 (309) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +169 -21
  3. package/README.md +505 -35
  4. package/SECURITY.md +5 -0
  5. package/bin/cckit +189 -20
  6. package/cckit.config.json +1 -1
  7. package/commands/kit-doctor.md +13 -5
  8. package/commands/kit-export-project.md +0 -2
  9. package/commands/kit-export-training.md +6 -9
  10. package/commands/kit-init.md +43 -13
  11. package/commands/kit-routines.md +1 -1
  12. package/commands/kit-update.md +11 -6
  13. package/databases/supabase/guide.html +106 -0
  14. package/databases/supabase/nextjs/lib/supabase/client.ts +9 -0
  15. package/databases/supabase/nextjs/lib/supabase/server.ts +29 -0
  16. package/databases/supabase.json +70 -0
  17. package/integrations/emil-design-eng.json +41 -0
  18. package/integrations/graft.json +81 -0
  19. package/integrations/impeccable.json +42 -0
  20. package/integrations/integration.schema.json +215 -0
  21. package/integrations/lavish.json +43 -0
  22. package/integrations/mempalace.json +28 -0
  23. package/integrations/mlx-lm.json +32 -0
  24. package/integrations/web-design-guidelines.json +42 -0
  25. package/kit.config.schema.json +183 -5
  26. package/package.json +4 -1
  27. package/profiles/automation.json +7 -1
  28. package/profiles/content.json +10 -2
  29. package/profiles/marketing.json +57 -0
  30. package/profiles/minimal.json +7 -1
  31. package/profiles/research.json +7 -1
  32. package/profiles/software.json +7 -1
  33. package/recipes/nextjs-shadcn.json +49 -0
  34. package/scripts/agent-skills-external.txt +45 -0
  35. package/scripts/agent-skills-lint-test.sh +131 -0
  36. package/scripts/agent-skills-lint.sh +115 -0
  37. package/scripts/agent-template-lint-test.sh +42 -0
  38. package/scripts/agent-template-lint.sh +58 -0
  39. package/scripts/annotate-setup.sh +1 -1
  40. package/scripts/autopilot-run-test.sh +338 -0
  41. package/scripts/autopilot-run.sh +448 -0
  42. package/scripts/autopilot-test.sh +8 -0
  43. package/scripts/autopilot.sh +10 -1
  44. package/scripts/benchmark/benchmark-test.sh +85 -0
  45. package/scripts/benchmark/checkpoint-test.sh +314 -0
  46. package/scripts/benchmark/checkpoint.sh +408 -0
  47. package/scripts/benchmark/lib/model.sh +31 -6
  48. package/scripts/benchmark/report.sh +17 -2
  49. package/scripts/benchmark/run-quality.sh +36 -10
  50. package/scripts/benchmark/verb-timings-test.sh +124 -0
  51. package/scripts/benchmark/verb-timings.sh +149 -0
  52. package/scripts/check.sh +29 -19
  53. package/scripts/content-skills-test.sh +144 -0
  54. package/scripts/copilot-loop-test.sh +25 -0
  55. package/scripts/database-supabase-test.sh +121 -0
  56. package/scripts/docs-marketing-words-test.sh +73 -0
  57. package/scripts/docs-record-tables-test.sh +72 -0
  58. package/scripts/guard-raw-git-ops-test.sh +8 -0
  59. package/scripts/hook-adapter-test.sh +193 -0
  60. package/scripts/init-content-test.sh +225 -0
  61. package/scripts/init-guided-test.sh +474 -0
  62. package/scripts/init-recipes-test.sh +104 -0
  63. package/scripts/init-upgrade-test.sh +341 -2
  64. package/scripts/init.sh +746 -95
  65. package/scripts/instruction-budget-baseline.txt +8 -0
  66. package/scripts/instruction-budget-lint-test.sh +166 -0
  67. package/scripts/instruction-budget-lint.sh +219 -0
  68. package/scripts/integrations-check-test.sh +200 -0
  69. package/scripts/integrations-check.sh +157 -0
  70. package/scripts/kit-add-test.sh +214 -0
  71. package/scripts/kit-add.sh +305 -5
  72. package/scripts/kit-adopt-test.sh +16 -0
  73. package/scripts/kit-adopt.sh +3 -2
  74. package/scripts/kit-digest.sh +2 -2
  75. package/scripts/kit-doctor-test.sh +293 -0
  76. package/scripts/kit-doctor.sh +272 -140
  77. package/scripts/kit-export-project-test.sh +3 -3
  78. package/scripts/kit-remove-test.sh +19 -0
  79. package/scripts/kit-routines.sh +2 -2
  80. package/scripts/kit-self-update.sh +1 -1
  81. package/scripts/kit-version-check-test.sh +4 -0
  82. package/scripts/kit-version-check.sh +4 -2
  83. package/scripts/knowledge-lint.sh +4 -4
  84. package/scripts/leak-fence-test.sh +89 -0
  85. package/scripts/lib/adapter-select-test.sh +136 -0
  86. package/scripts/lib/adapter-select.sh +158 -0
  87. package/scripts/lib/agent-def-test.sh +69 -0
  88. package/scripts/lib/agent-def.sh +106 -0
  89. package/scripts/lib/agent-launch-test.sh +212 -0
  90. package/scripts/lib/agent-launch.sh +335 -0
  91. package/scripts/lib/board-view-test.sh +11 -0
  92. package/scripts/lib/board-view.sh +42 -26
  93. package/scripts/lib/branch-owner-test.sh +26 -0
  94. package/scripts/lib/branch-owner.sh +16 -9
  95. package/scripts/lib/captain-test.sh +105 -0
  96. package/scripts/lib/captain.sh +87 -8
  97. package/scripts/lib/codex-hooks-test.sh +100 -0
  98. package/scripts/lib/codex-hooks.sh +69 -0
  99. package/scripts/lib/commitlint.sh +1 -1
  100. package/scripts/lib/content-kinds-gc-test.sh +88 -0
  101. package/scripts/lib/copilot-test.sh +70 -4
  102. package/scripts/lib/copilot.sh +66 -14
  103. package/scripts/lib/effort-dispatch-test.sh +3 -3
  104. package/scripts/lib/effort-metrics-test.sh +178 -1
  105. package/scripts/lib/effort-metrics.sh +188 -35
  106. package/scripts/lib/effort-ops-test.sh +217 -7
  107. package/scripts/lib/effort-ops.sh +281 -49
  108. package/scripts/lib/effort-parity-test.sh +49 -13
  109. package/scripts/lib/effort-plan-test.sh +337 -0
  110. package/scripts/lib/effort-plan.sh +200 -23
  111. package/scripts/lib/effort-slug.sh +16 -2
  112. package/scripts/lib/effort.sh +67 -12
  113. package/scripts/lib/errors-header-test.sh +1 -1
  114. package/scripts/lib/gh-project-test.sh +35 -1
  115. package/scripts/lib/gh-project.sh +37 -16
  116. package/scripts/lib/gh-rest-test.sh +330 -0
  117. package/scripts/lib/gh-rest.sh +304 -0
  118. package/scripts/lib/hook-refresh.sh +1 -1
  119. package/scripts/lib/init-github.sh +412 -0
  120. package/scripts/lib/init-guide.sh +630 -0
  121. package/scripts/lib/integration-install-test.sh +343 -0
  122. package/scripts/lib/integration-install.sh +257 -0
  123. package/scripts/lib/integrations-test.sh +366 -0
  124. package/scripts/lib/integrations.sh +244 -0
  125. package/scripts/lib/kinds-test.sh +125 -0
  126. package/scripts/lib/kinds.sh +66 -0
  127. package/scripts/lib/kit-brief-test.sh +22 -3
  128. package/scripts/lib/kit-brief.sh +45 -5
  129. package/scripts/lib/kit-config-resolve.sh +2 -2
  130. package/scripts/lib/kit-config-test.sh +64 -1
  131. package/scripts/lib/kit-config.sh +37 -1
  132. package/scripts/lib/kit-events.sh +7 -0
  133. package/scripts/lib/kit-gc-test.sh +173 -1
  134. package/scripts/lib/kit-gc.sh +244 -37
  135. package/scripts/lib/kit-hotfix.sh +216 -0
  136. package/scripts/lib/kit-interview-test.sh +93 -0
  137. package/scripts/lib/kit-interview.sh +117 -8
  138. package/scripts/lib/kit-lib-test.sh +1 -1
  139. package/scripts/lib/kit-lib.sh +3 -3
  140. package/scripts/lib/kit-local.sh +2 -2
  141. package/scripts/lib/kit-manifest.sh +33 -1
  142. package/scripts/lib/kit-profile-test.sh +3 -3
  143. package/scripts/lib/kit-status-test.sh +112 -4
  144. package/scripts/lib/kit-status.sh +246 -16
  145. package/scripts/lib/kit-task-ops-test.sh +37 -0
  146. package/scripts/lib/kit-task-ops.sh +362 -89
  147. package/scripts/lib/kto-hotfix-test.sh +232 -0
  148. package/scripts/lib/kto-task-close-test.sh +83 -0
  149. package/scripts/lib/kto-task-new-test.sh +95 -0
  150. package/scripts/lib/kto-task-pr-merge-test.sh +97 -6
  151. package/scripts/lib/kto-task-pr-test.sh +70 -0
  152. package/scripts/lib/leak-fence.sh +89 -0
  153. package/scripts/lib/light-task-run-test.sh +255 -0
  154. package/scripts/lib/light-task-test.sh +309 -0
  155. package/scripts/lib/light-task.sh +706 -0
  156. package/scripts/lib/next-test.sh +99 -0
  157. package/scripts/lib/next.sh +9 -3
  158. package/scripts/lib/orchestration-runtime-test.sh +72 -0
  159. package/scripts/lib/orchestration-runtime.sh +57 -5
  160. package/scripts/lib/plan-machine-test.sh +15 -2
  161. package/scripts/lib/plan-machine.sh +20 -7
  162. package/scripts/lib/plan-next-test.sh +1 -1
  163. package/scripts/lib/plan-next.sh +4 -4
  164. package/scripts/lib/pr-evidence-test.sh +3 -3
  165. package/scripts/lib/pr-evidence.sh +1 -1
  166. package/scripts/lib/qa-lane-test.sh +626 -0
  167. package/scripts/lib/qa-lane.sh +1357 -0
  168. package/scripts/lib/qa-lanes-test.sh +175 -0
  169. package/scripts/lib/react-detect.sh +1 -1
  170. package/scripts/lib/render-test.sh +1 -1
  171. package/scripts/lib/review-page-test.sh +318 -0
  172. package/scripts/lib/review-page.sh +369 -0
  173. package/scripts/lib/review-stage-test.sh +62 -11
  174. package/scripts/lib/review-stage.sh +42 -60
  175. package/scripts/lib/role-identity-test.sh +65 -0
  176. package/scripts/lib/role-identity.sh +25 -2
  177. package/scripts/lib/secret-guard.sh +3 -3
  178. package/scripts/lib/session-registry-test.sh +111 -0
  179. package/scripts/lib/session-registry.sh +233 -0
  180. package/scripts/lib/stage-receipt-test.sh +14 -1
  181. package/scripts/lib/stage-receipt.sh +13 -8
  182. package/scripts/lib/task-source-file.sh +309 -0
  183. package/scripts/lib/task-source.sh +130 -0
  184. package/scripts/lib/test-env-test.sh +3 -3
  185. package/scripts/lib/test-env.sh +7 -4
  186. package/scripts/lib/upgrade-report-test.sh +120 -0
  187. package/scripts/lib/upgrade-report.sh +138 -0
  188. package/scripts/lib/version-bump.sh +3 -3
  189. package/scripts/lib/wave-result-test.sh +80 -0
  190. package/scripts/lib/wave-result.sh +127 -0
  191. package/scripts/lib/worker-brief-test.sh +5 -0
  192. package/scripts/lib/worker-brief.sh +2 -2
  193. package/scripts/lib/worktree-issue-test.sh +30 -1
  194. package/scripts/lib/worktree-issue.sh +93 -9
  195. package/scripts/lib/worktree-ports-test.sh +57 -4
  196. package/scripts/lib/worktree-start-test.sh +197 -0
  197. package/scripts/lib/worktree-start.sh +169 -32
  198. package/scripts/lib/zsh-safety-test.sh +19 -3
  199. package/scripts/marketing-walkthrough-test.sh +152 -0
  200. package/scripts/night-grant-test.sh +37 -0
  201. package/scripts/night-grant.sh +448 -0
  202. package/scripts/night-run-test.sh +8 -0
  203. package/scripts/night-run.mjs +275 -0
  204. package/scripts/night-run.test.mjs +324 -0
  205. package/scripts/orchestrate-test.sh +190 -0
  206. package/scripts/orchestrate.sh +79 -8
  207. package/scripts/portable-test.sh +11 -2
  208. package/scripts/publish.sh +28 -3
  209. package/scripts/review-lint-test.sh +7 -7
  210. package/scripts/review-lint.sh +2 -2
  211. package/scripts/review-rules.conf +8 -0
  212. package/scripts/rule-recipes-test.sh +96 -0
  213. package/scripts/self-install-test.sh +39 -9
  214. package/scripts/setup-labels.sh +18 -1
  215. package/scripts/setup-milestones.sh +1 -1
  216. package/scripts/showcase.sh +1 -1
  217. package/scripts/skill-frontmatter-lint-test.sh +4 -4
  218. package/scripts/skill-frontmatter-lint.sh +1 -1
  219. package/scripts/status-test.sh +113 -2
  220. package/scripts/status.sh +16 -3
  221. package/scripts/task-sync-test.sh +154 -0
  222. package/scripts/task-sync.sh +243 -32
  223. package/scripts/test-runner-test.sh +158 -0
  224. package/scripts/test.sh +131 -23
  225. package/scripts/update-path-test.sh +279 -0
  226. package/scripts/ux-ds-audit.sh +1 -1
  227. package/scripts/ux-graph-scan.sh +6 -6
  228. package/scripts/wave-worker.sh +54 -0
  229. package/skills/kit-add/SKILL.md +77 -0
  230. package/skills/kit-autopilot/SKILL.md +123 -12
  231. package/skills/kit-cleanup/SKILL.md +5 -2
  232. package/skills/kit-contribute/SKILL.md +4 -4
  233. package/skills/kit-docs-writer/SKILL.md +16 -6
  234. package/skills/kit-effort-close/SKILL.md +17 -8
  235. package/skills/kit-effort-new/SKILL.md +15 -9
  236. package/skills/kit-effort-pr/SKILL.md +15 -7
  237. package/skills/kit-effort-start/SKILL.md +5 -2
  238. package/skills/kit-gc/SKILL.md +5 -2
  239. package/skills/kit-next/SKILL.md +5 -1
  240. package/skills/kit-onboard/SKILL.md +3 -3
  241. package/skills/kit-page/SKILL.md +93 -0
  242. package/skills/kit-plan-next/SKILL.md +8 -4
  243. package/skills/kit-security-sweep/SKILL.md +1 -3
  244. package/skills/kit-ship/SKILL.md +2 -3
  245. package/skills/kit-status/SKILL.md +35 -4
  246. package/skills/kit-task-new/SKILL.md +3 -3
  247. package/skills/kit-task-pr/SKILL.md +7 -2
  248. package/skills/kit-task-pr-merge/SKILL.md +7 -2
  249. package/skills/kit-task-start/SKILL.md +7 -7
  250. package/skills/kit-task-sync/SKILL.md +19 -3
  251. package/skills/kit-ux-audit/SKILL.md +3 -2
  252. package/templates/agents/auto-dev.md +5 -4
  253. package/templates/agents/backend.md +1 -1
  254. package/templates/agents/designer.md +2 -0
  255. package/templates/agents/devops.md +1 -1
  256. package/templates/agents/editor.md +9 -1
  257. package/templates/agents/frontend.md +1 -1
  258. package/templates/agents/local-delegate.md +1 -1
  259. package/templates/agents/pm.md +5 -5
  260. package/templates/agents/tech-lead.md +1 -1
  261. package/templates/benchmarks/SCHEMA.md +9 -3
  262. package/templates/codex/hooks.json.tmpl +89 -0
  263. package/templates/hooks/guard-base-branch-commit.sh.tmpl +13 -7
  264. package/templates/hooks/guard-raw-git-ops.sh.tmpl +27 -14
  265. package/templates/hooks/mempal_followup.sh.tmpl +2 -2
  266. package/templates/hooks/mempal_session_start.sh.tmpl +1 -1
  267. package/templates/hooks/prepush_gate.sh.tmpl +4 -2
  268. package/templates/hooks/repo-hygiene.sh.tmpl +3 -2
  269. package/templates/instructions.md.tmpl +174 -0
  270. package/templates/kit.config.json.tmpl +3 -3
  271. package/templates/knowledge-INDEX.md.tmpl +1 -1
  272. package/templates/lib/kit-sigil.sh.tmpl +1 -1
  273. package/templates/rules/authoring.md +106 -0
  274. package/templates/rules/branch-naming.md +40 -4
  275. package/templates/rules/code-retrieval.md +63 -0
  276. package/templates/rules/delegation-brief.md +0 -3
  277. package/templates/rules/design-routing.md +3 -3
  278. package/templates/rules/effort-model.md +14 -10
  279. package/templates/rules/gate-and-review.md +94 -0
  280. package/templates/rules/issue-lifecycle.md +88 -0
  281. package/templates/rules/knowledge-base.md +1 -1
  282. package/templates/rules/mempalace.md +1 -1
  283. package/templates/rules/merge-safety.md +108 -0
  284. package/templates/rules/naming-and-ids.md +23 -17
  285. package/templates/rules/plain-language.md +59 -0
  286. package/templates/rules/plan-next.md +9 -11
  287. package/templates/rules/react-annotate.md +6 -0
  288. package/templates/rules/review-pages.md +49 -0
  289. package/templates/rules/risk-tiered-review.md +13 -4
  290. package/templates/rules/shared-checkout.md +106 -0
  291. package/templates/rules/skill-gaps.md +2 -7
  292. package/templates/rules/task-management.md +13 -1
  293. package/templates/skills/brand-voice/SKILL.md +91 -0
  294. package/templates/skills/brand-voice/references/voice-template.md +61 -0
  295. package/templates/skills/campaign/SKILL.md +123 -0
  296. package/templates/skills/campaign/references/plan-template.md +55 -0
  297. package/templates/skills/concrete/SKILL.md +2 -2
  298. package/templates/skills/copywriting/SKILL.md +8 -1
  299. package/templates/skills/feature-build-refine/SKILL.md +2 -4
  300. package/templates/skills/morning-briefing/SKILL.md +2 -2
  301. package/templates/skills/page-design/SKILL.md +145 -0
  302. package/templates/skills/page-design/add.json +5 -0
  303. package/templates/skills/page-design/references/design-file-template.md +40 -0
  304. package/templates/skills/page-design/references/generic-page-patterns.md +43 -0
  305. package/templates/skills/page-design/references/minimum-rules.md +42 -0
  306. package/templates/skills/speckit/SKILL.md +4 -5
  307. package/templates/skills/supabase-patterns/SKILL.md +1 -1
  308. package/commands/kit-add.md +0 -42
  309. package/templates/CLAUDE.md.tmpl +0 -106
@@ -0,0 +1,448 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # night-grant.sh — read the owner's night grant and turn it into scripts/night-run.mjs args.
4
+ #
5
+ # The brake on an unattended run is a per-night token budget the owner writes; the waivers are a
6
+ # standing base plus per-night additions; some floors can never be waived; the run stops when the
7
+ # waves are merged and the gate is green, or when an optional stopCommand passes.
8
+ #
9
+ # THE GRANT is ONE comment on the plan parent issue:
10
+ #
11
+ # <!-- night-grant -->
12
+ # Tonight: run the two approved waves; I accept the lockfile floor.
13
+ #
14
+ # ```json
15
+ # { "budget": "+2000k", "waves": [[12],[15]], "waivers": ["lockfile"], "stopCommand": null }
16
+ # ```
17
+ #
18
+ # The latest comment starting with the marker wins — among comments the OWNER wrote. A grant sets
19
+ # the budget, the waivers and a shell `stopCommand`, so a comment counts only when GitHub reports
20
+ # its author_association as OWNER, or its author is `github.owner` or one of `night.grantors` in
21
+ # the kit config. A marker comment from anyone else is ignored and named on stderr.
22
+ #
23
+ # FLOORS. The base vocabulary below matches the engine's BASE_FLOORS / BASE_NEVER_WAIVABLE
24
+ # (scripts/night-run.mjs). A project adds its own in the kit config (cckit.config.json, or
25
+ # .claude/kit.config.json):
26
+ #
27
+ # "night": { "floors": { "auth-dep": "the auth library version" },
28
+ # "neverWaivable": ["auth-dep"], "gate": "pnpm typecheck && pnpm lint",
29
+ # "grantors": ["a-maintainer"], "refuseLabels": ["hold"] }
30
+ #
31
+ # The config is resolved by kit_config_path (scripts/lib/config-path.sh): $KIT_CONFIG, else a walk
32
+ # up from the current directory. The args also carry `wipLimit` — `effort.wipLimit` (default 2,
33
+ # EFFORT_WIP_LIMIT wins) — because every executor runs `cckit effort start`, which refuses a new
34
+ # effort at that limit; the engine runs no wider than it.
35
+ #
36
+ # A bad grant is refused here, before launch, instead of at 3 a.m.; the engine still refuses a
37
+ # never-waivable floor on its own.
38
+ #
39
+ # Usage:
40
+ # scripts/night-grant.sh read <issue> print the engine args JSON, then `budget=+N`
41
+ # scripts/night-grant.sh parse same, from a comment body on stdin
42
+ # scripts/night-grant.sh preflight [<settings.json>]
43
+ # report allowlist entries an unattended run lacks
44
+ # scripts/night-grant.sh --selftest offline fixture test (no gh, no network)
45
+ #
46
+ # bash 3.2 / zsh safe; needs jq.
47
+
48
+ NIGHT_GRANT_MARKER='<!-- night-grant -->'
49
+ NIGHT_GRANT_BASE_FLOORS='lockfile auth security-code security-prose workflows cost secret'
50
+ NIGHT_GRANT_BASE_NEVER='workflows cost secret'
51
+ NIGHT_GRANT_REQUIRED_ALLOW='Bash(gh pr merge:*)
52
+ Bash(git push:*)
53
+ Bash(gh issue comment:*)
54
+ Bash(gh issue edit:*)
55
+ Bash(gh issue close:*)
56
+ Bash(gh api:*)'
57
+
58
+ _ng_err() { printf 'night-grant: %s\n' "$*" >&2; }
59
+
60
+ # The script's own directory, resolved at load time: inside a function zsh reports the function
61
+ # name as $0, so this cannot be deferred to the first call.
62
+ _NG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)"
63
+
64
+ # _ng_config_file — the kit config path, or empty. NIGHT_GRANT_CONFIG overrides the lookup (the
65
+ # test hook; a missing file reads as "no config"). Otherwise kit_config_path resolves it, so
66
+ # $KIT_CONFIG and the walk-up from the current directory are honored like every other kit verb.
67
+ _ng_config_file() {
68
+ if [ -n "${NIGHT_GRANT_CONFIG:-}" ]; then printf '%s\n' "$NIGHT_GRANT_CONFIG"; return 0; fi
69
+ if ! command -v kit_config_path >/dev/null 2>&1; then
70
+ # shellcheck source=/dev/null
71
+ [ -n "$_NG_DIR" ] && [ -f "$_NG_DIR/lib/config-path.sh" ] && . "$_NG_DIR/lib/config-path.sh"
72
+ fi
73
+ command -v kit_config_path >/dev/null 2>&1 || return 0
74
+ kit_config_path 2>/dev/null || true
75
+ }
76
+
77
+ # _ng_cfg_jq <jq-filter> <fallback> — run a filter over the kit config; the fallback when there is
78
+ # no config or the filter fails.
79
+ _ng_cfg_jq() {
80
+ local f; f="$(_ng_config_file)"
81
+ if [ -n "$f" ] && [ -f "$f" ]; then jq -c "$1" "$f" 2>/dev/null || printf '%s\n' "$2"
82
+ else printf '%s\n' "$2"; fi
83
+ }
84
+
85
+ # _ng_night_cfg — the kit config's `night` object as compact JSON, or {} when there is none.
86
+ _ng_night_cfg() {
87
+ _ng_cfg_jq '(.night // {}) | if type == "object" then . else {} end' '{}'
88
+ }
89
+
90
+ # _ng_grantors — a JSON array of the lowercased logins allowed to write a grant: `github.owner`
91
+ # plus `night.grantors`. May be empty; an author_association of OWNER is accepted regardless.
92
+ _ng_grantors() {
93
+ _ng_cfg_jq '[.github.owner?, ((.night.grantors? // []) | if type == "array" then .[] else empty end)]
94
+ | map(select(type == "string" and length > 0) | ascii_downcase) | unique' '[]'
95
+ }
96
+
97
+ # _ng_wip_limit — the effort WIP limit an executor's `cckit effort start` will meet, resolved like
98
+ # _eff_wip_limit (scripts/lib/effort-ops.sh): EFFORT_WIP_LIMIT, else `effort.wipLimit`, else 2. A
99
+ # value that is not a non-negative integer falls back to 2, as it does there.
100
+ _ng_wip_limit() {
101
+ local v="${EFFORT_WIP_LIMIT:-}"
102
+ [ -n "$v" ] || v="$(_ng_cfg_jq '.effort.wipLimit? // empty' '' | tr -d '"')"
103
+ case "$v" in ''|*[!0-9]*) v=2 ;; esac
104
+ printf '%s\n' "$v"
105
+ }
106
+
107
+ # night_grant_parse — stdin: a comment body. stdout: line 1 the engine args JSON
108
+ # `{"waves":…,"grant":{"waivers":…,"stopCommand":…}}`, line 2 `budget=+N`. Exit 1 on a refused grant.
109
+ night_grant_parse() {
110
+ local body block json budget bad
111
+ local cfg floors never wip
112
+ cfg="$(_ng_night_cfg)"
113
+ # Floor names stay JSON arrays end to end: a waiver is compared as one whole string, never
114
+ # word-split or globbed by the shell.
115
+ floors="$(printf '%s' "$cfg" | jq -c --arg base "$NIGHT_GRANT_BASE_FLOORS" \
116
+ '($base | split(" ")) + ((.floors // {}) | if type == "object" then keys else [] end)')"
117
+ never="$(printf '%s' "$cfg" | jq -c --arg base "$NIGHT_GRANT_BASE_NEVER" \
118
+ '($base | split(" ")) + ((.neverWaivable // []) | if type == "array" then map(select(type == "string")) else [] end)')"
119
+ wip="$(_ng_wip_limit)"
120
+ if [ "$wip" -eq 0 ]; then
121
+ _ng_err 'refused: the effort WIP limit is 0 (effort.wipLimit / EFFORT_WIP_LIMIT), so no executor could start an effort'
122
+ return 1
123
+ fi
124
+ body="$(cat | tr -d '\r')"
125
+ case "$body" in
126
+ "$NIGHT_GRANT_MARKER"*) ;;
127
+ *) _ng_err "not a grant: the comment must start with $NIGHT_GRANT_MARKER"; return 1 ;;
128
+ esac
129
+ block="$(printf '%s\n' "$body" | awk '
130
+ !inb && /^```json[[:space:]]*$/ { inb = 1; next }
131
+ inb && /^```[[:space:]]*$/ { exit }
132
+ inb { print }
133
+ ')"
134
+ if [ -z "$block" ]; then _ng_err 'no ```json block in the grant'; return 1; fi
135
+ if ! json="$(printf '%s' "$block" | jq -c . 2>/dev/null)" || [ -z "$json" ]; then
136
+ _ng_err 'the ```json block is not valid JSON'; return 1
137
+ fi
138
+ if [ "$(printf '%s' "$json" | jq -r 'type')" != object ]; then
139
+ _ng_err 'the ```json block must be an object'; return 1
140
+ fi
141
+
142
+ budget="$(printf '%s' "$json" | jq -r 'if (.budget|type) == "string" then .budget else "" end')"
143
+ if ! grep -Eq '^\+[1-9][0-9]*[kM]?$' <<<"$budget"; then
144
+ _ng_err "budget missing or malformed (want +<number>[k|M], e.g. +2000k): '${budget}'"; return 1
145
+ fi
146
+
147
+ if ! printf '%s' "$json" | jq -e '
148
+ (.waves | type) == "array" and (.waves | length) > 0 and
149
+ all(.waves[]; type == "array" and length > 0 and
150
+ all(.[]; type == "number" and . == floor and . > 0))' >/dev/null 2>&1; then
151
+ _ng_err 'waves must be a non-empty array of non-empty arrays of issue numbers'; return 1
152
+ fi
153
+
154
+ if ! printf '%s' "$json" | jq -e '(.waivers // []) | type == "array" and all(.[]; type == "string")' \
155
+ >/dev/null 2>&1; then
156
+ _ng_err 'waivers must be an array of floor names'; return 1
157
+ fi
158
+ bad="$(printf '%s' "$json" | jq -r --argjson never "$never" \
159
+ '[(.waivers // [])[] | select(. as $w | any($never[]; . == $w)) | @json] | join(", ")')"
160
+ if [ -n "$bad" ]; then
161
+ _ng_err "refused: $bad is never waivable — remove it from the grant"; return 1
162
+ fi
163
+ bad="$(printf '%s' "$json" | jq -r --argjson floors "$floors" \
164
+ '[(.waivers // [])[] | select(. as $w | any($floors[]; . == $w) | not) | @json] | join(", ")')"
165
+ if [ -n "$bad" ]; then
166
+ _ng_err "unknown waiver(s): $bad — the floors are: $(printf '%s' "$floors" | jq -r 'join(" ")')"; return 1
167
+ fi
168
+
169
+ if ! printf '%s' "$json" | jq -e '(.stopCommand // null) | . == null or (type == "string" and length > 0)' \
170
+ >/dev/null 2>&1; then
171
+ _ng_err 'stopCommand must be null or a non-empty string'; return 1
172
+ fi
173
+
174
+ printf '%s' "$json" | jq -c --argjson cfg "$cfg" --argjson wip "$wip" '{waves: .waves, wipLimit: $wip}
175
+ + (if ($cfg.gate | type) == "string" then {gate: $cfg.gate} else {} end)
176
+ + (if ($cfg.refuseLabels | type) == "array" then {refuseLabels: $cfg.refuseLabels} else {} end)
177
+ + {grant: {waivers: ((.waivers // []) | unique), stopCommand: (.stopCommand // null),
178
+ extraFloors: ($cfg.floors // {}), neverWaivable: ($cfg.neverWaivable // [])}}'
179
+ printf 'budget=%s\n' "$budget"
180
+ }
181
+
182
+ # night_grant_pick — stdin: a JSON array of comments, oldest first, each
183
+ # `{"body":…,"login":…,"association":…}`. stdout: the latest body that starts with the marker AND
184
+ # was written by the owner — author_association OWNER, or a login in _ng_grantors. Exit 1 when no
185
+ # such comment exists. A marker comment by anyone else never counts, however recent: the grant
186
+ # carries the budget, the waivers and a shell command. An entry with no author (a bare string) is
187
+ # unauthenticated and is skipped too.
188
+ night_grant_pick() {
189
+ local all picked ignored grantors defs
190
+ grantors="$(_ng_grantors)"
191
+ all="$(cat)"
192
+ defs='def grants: [.[] | select(type == "object" and (.body | type) == "string")
193
+ | select(.body | gsub("\r"; "") | startswith($m))];
194
+ def by_owner: .association == "OWNER"
195
+ or (((.login // "") | ascii_downcase) as $l | any($g[]; . == $l));'
196
+ picked="$(printf '%s' "$all" | jq -r --arg m "$NIGHT_GRANT_MARKER" --argjson g "$grantors" \
197
+ "$defs"' [grants[] | select(by_owner) | .body] | last // empty' 2>/dev/null)"
198
+ ignored="$(printf '%s' "$all" | jq -r --arg m "$NIGHT_GRANT_MARKER" --argjson g "$grantors" \
199
+ "$defs"' [grants[] | select(by_owner | not) | (.login // "unknown")] | unique | join(", ")' 2>/dev/null)"
200
+ [ -z "$ignored" ] || _ng_err "ignored a grant comment not written by the owner (from: $ignored)"
201
+ if [ -z "$picked" ]; then
202
+ _ng_err "no comment by the owner starts with $NIGHT_GRANT_MARKER"; return 1
203
+ fi
204
+ printf '%s\n' "$picked"
205
+ }
206
+
207
+ # night_grant_read <issue> — fetch the issue's comments with their authors, pick the owner's latest
208
+ # grant, parse it.
209
+ night_grant_read() {
210
+ local issue="${1:-}" comments picked
211
+ case "$issue" in ''|*[!0-9]*) _ng_err 'usage: night_grant_read <issue-number>'; return 2 ;; esac
212
+ if ! comments="$(gh api --paginate "repos/{owner}/{repo}/issues/$issue/comments" \
213
+ --jq '.[] | {body, login: .user.login, association: .author_association} | @json' < /dev/null)"; then
214
+ _ng_err "could not read the comments of #$issue"; return 1
215
+ fi
216
+ picked="$(printf '%s\n' "$comments" | jq -s . | night_grant_pick)" || return 1
217
+ printf '%s\n' "$picked" | night_grant_parse
218
+ }
219
+
220
+ # night_grant_preflight [<settings.json>] — report what the TRACKED settings allowlist lacks for an
221
+ # unattended run. Exit 1 when anything is missing. Never edits the file.
222
+ night_grant_preflight() {
223
+ local file="${1:-}" top allow req prefix missing=0
224
+ if [ -z "$file" ]; then
225
+ top="$(git rev-parse --show-toplevel 2>/dev/null)" || { _ng_err 'not in a git checkout'; return 2; }
226
+ file="$top/.claude/settings.json"
227
+ fi
228
+ if [ ! -f "$file" ]; then _ng_err "no settings file at $file"; return 2; fi
229
+ if ! allow="$(jq -r '(.permissions.allow // [])[]' "$file" 2>/dev/null)"; then
230
+ _ng_err "unreadable settings file $file"; return 2
231
+ fi
232
+ while IFS= read -r req; do
233
+ [ -n "$req" ] || continue
234
+ prefix="${req#"Bash("}"; prefix="${prefix%":*)"}"
235
+ if _ng_allow_covers "$prefix" "$allow"; then
236
+ printf ' ok %s\n' "$req"
237
+ else
238
+ printf ' MISSING %s\n' "$req"; missing=$((missing + 1))
239
+ fi
240
+ done <<EOF
241
+ $NIGHT_GRANT_REQUIRED_ALLOW
242
+ EOF
243
+ if [ "$missing" -gt 0 ]; then
244
+ printf 'night-grant preflight: %s allowlist entr%s missing in %s (add them by hand; this never edits it)\n' \
245
+ "$missing" "$( [ "$missing" -eq 1 ] && echo y || echo ies)" "$file"
246
+ return 1
247
+ fi
248
+ printf 'night-grant preflight: OK (%s)\n' "$file"
249
+ }
250
+
251
+ # _ng_allow_covers <command-prefix> <allow-list, one per line> — true when an entry allows it:
252
+ # `Bash`, `Bash(*)`, or `Bash(<p>:*)` / `Bash(<p> *)` where the command starts with <p> on a word.
253
+ _ng_allow_covers() {
254
+ local cmd="$1" entry p
255
+ while IFS= read -r entry; do
256
+ case "$entry" in
257
+ Bash|'Bash(*)') return 0 ;;
258
+ 'Bash('*':*)') p="${entry#"Bash("}"; p="${p%":*)"}" ;;
259
+ 'Bash('*' *)') p="${entry#"Bash("}"; p="${p%" *)"}" ;;
260
+ *) continue ;;
261
+ esac
262
+ case "$cmd" in "$p"|"$p "*) return 0 ;; esac
263
+ done <<EOF
264
+ $2
265
+ EOF
266
+ return 1
267
+ }
268
+
269
+ # ── selftest (offline) ────────────────────────────────────────────────────────────────────────
270
+ night_grant_selftest() {
271
+ local fails=0 out st tmp cfg work
272
+ NIGHT_GRANT_CONFIG="${TMPDIR:-/tmp}/night-grant-no-config-$$.json"; export NIGHT_GRANT_CONFIG
273
+ unset EFFORT_WIP_LIMIT KIT_CONFIG
274
+ _t() { # <label> <want> <got>
275
+ if [ "$2" = "$3" ]; then printf ' ok %s\n' "$1"
276
+ else printf ' FAIL %s\n want: %s\n got: %s\n' "$1" "$2" "$3"; fails=$((fails + 1)); fi
277
+ }
278
+ _grant() { # <json> — a grant comment around a json block
279
+ printf '%s\nTonight: two waves.\n\n```json\n%s\n```\n' "$NIGHT_GRANT_MARKER" "$1"
280
+ }
281
+
282
+ # parse — the happy path
283
+ out="$(_grant '{"budget":"+2000k","waves":[[12],[15]],"waivers":["lockfile"],"stopCommand":null}' \
284
+ | night_grant_parse 2>/dev/null)"; st=$?
285
+ _t "parse: a valid grant exits 0" 0 "$st"
286
+ _t "parse: line 1 is the engine args" \
287
+ '{"waves":[[12],[15]],"wipLimit":2,"grant":{"waivers":["lockfile"],"stopCommand":null,"extraFloors":{},"neverWaivable":[]}}' \
288
+ "$(printf '%s\n' "$out" | sed -n 1p)"
289
+ _t "parse: line 2 is the budget" 'budget=+2000k' "$(printf '%s\n' "$out" | sed -n 2p)"
290
+
291
+ out="$(_grant '{"budget":"+3M","waves":[[1,2]],"stopCommand":"pnpm typecheck"}' \
292
+ | night_grant_parse 2>/dev/null | sed -n 1p)"
293
+ _t "parse: absent waivers -> [] and stopCommand kept" \
294
+ '{"waves":[[1,2]],"wipLimit":2,"grant":{"waivers":[],"stopCommand":"pnpm typecheck","extraFloors":{},"neverWaivable":[]}}' "$out"
295
+
296
+ # parse — refusals
297
+ _grant '{"waves":[[1]]}' | night_grant_parse >/dev/null 2>&1; st=$?
298
+ _t "parse: no budget is refused" 1 "$st"
299
+ _grant '{"budget":"2000k","waves":[[1]]}' | night_grant_parse >/dev/null 2>&1; st=$?
300
+ _t "parse: budget without + is refused" 1 "$st"
301
+ _grant '{"budget":"+2000G","waves":[[1]]}' | night_grant_parse >/dev/null 2>&1; st=$?
302
+ _t "parse: budget with a unit other than k|M is refused" 1 "$st"
303
+ _grant '{"budget":"+10k","waves":[]}' | night_grant_parse >/dev/null 2>&1; st=$?
304
+ _t "parse: empty waves is refused" 1 "$st"
305
+ _grant '{"budget":"+10k","waves":[[1],[]]}' | night_grant_parse >/dev/null 2>&1; st=$?
306
+ _t "parse: an empty wave is refused" 1 "$st"
307
+ _grant '{"budget":"+10k","waves":[["12"]]}' | night_grant_parse >/dev/null 2>&1; st=$?
308
+ _t "parse: a non-integer issue is refused" 1 "$st"
309
+ _grant '{"budget":"+10k","waves":[[1]],"waivers":["lockfle"]}' | night_grant_parse >/dev/null 2>&1; st=$?
310
+ _t "parse: a waiver outside the floor vocabulary is refused" 1 "$st"
311
+ out="$(_grant '{"budget":"+10k","waves":[[1]],"waivers":["lockfile","cost"]}' \
312
+ | night_grant_parse 2>&1 >/dev/null)"; st=$?
313
+ _t "parse: a never-waivable waiver is refused" 1 "$st"
314
+ case "$out" in *cost*'never waivable'*) out=named ;; esac
315
+ _t "parse: the refusal names the never-waivable floor" named "$out"
316
+
317
+ # parse — a waiver is one whole string: never word-split, never globbed
318
+ _grant '{"budget":"+10k","waves":[[1]],"waivers":["lockfile auth"]}' | night_grant_parse >/dev/null 2>&1; st=$?
319
+ _t "parse: 'lockfile auth' is one unknown waiver, not two valid ones" 1 "$st"
320
+ work="${TMPDIR:-/tmp}/night-grant-glob-$$"
321
+ mkdir -p "$work" && : >"$work/lockfile"
322
+ ( cd "$work" && _grant '{"budget":"+10k","waves":[[1]],"waivers":["*"]}' | night_grant_parse >/dev/null 2>&1 ); st=$?
323
+ _t "parse: a '*' waiver is refused even where it globs to a floor name" 1 "$st"
324
+ rm -rf "$work"
325
+
326
+ # parse — floors and gate the project declares in its kit config
327
+ cfg="$NIGHT_GRANT_CONFIG.fixture"
328
+ printf '%s' '{"night":{"floors":{"auth-dep":"the auth library","build-config":"the build config"},"neverWaivable":["auth-dep"],"gate":"make check"}}' >"$cfg"
329
+ out="$(_grant '{"budget":"+10k","waves":[[1]],"waivers":["build-config"]}' \
330
+ | NIGHT_GRANT_CONFIG="$cfg" night_grant_parse 2>/dev/null | sed -n 1p)"
331
+ _t "parse: a project floor is waivable and the config travels in the args" \
332
+ '{"waves":[[1]],"wipLimit":2,"gate":"make check","grant":{"waivers":["build-config"],"stopCommand":null,"extraFloors":{"auth-dep":"the auth library","build-config":"the build config"},"neverWaivable":["auth-dep"]}}' "$out"
333
+ _grant '{"budget":"+10k","waves":[[1]],"waivers":["auth-dep"]}' \
334
+ | NIGHT_GRANT_CONFIG="$cfg" night_grant_parse >/dev/null 2>&1; st=$?
335
+ _t "parse: a project never-waivable floor is refused" 1 "$st"
336
+
337
+ # config — resolved through kit_config_path: KIT_CONFIG wins, else a walk up from the cwd
338
+ out="$(_grant '{"budget":"+10k","waves":[[1]],"waivers":["build-config"]}' \
339
+ | ( unset NIGHT_GRANT_CONFIG; KIT_CONFIG="$cfg" night_grant_parse 2>/dev/null ) | sed -n 1p \
340
+ | jq -c '[.gate, .grant.neverWaivable]' 2>/dev/null)"
341
+ _t "config: KIT_CONFIG is honored (floors, never-waivable list and gate travel)" \
342
+ '["make check",["auth-dep"]]' "$out"
343
+ work="${TMPDIR:-/tmp}/night-grant-walk-$$"
344
+ mkdir -p "$work/.claude" "$work/a/b" && cp "$cfg" "$work/.claude/kit.config.json"
345
+ out="$(_grant '{"budget":"+10k","waves":[[1]]}' \
346
+ | ( unset NIGHT_GRANT_CONFIG; cd "$work/a/b" && night_grant_parse 2>/dev/null ) | sed -n 1p \
347
+ | jq -r '.gate' 2>/dev/null)"
348
+ _t "config: a nested directory walks up to the project config" 'make check' "$out"
349
+ rm -rf "$work"
350
+ rm -f "$cfg"
351
+
352
+ # config — the effort WIP limit and the hold labels travel in the args
353
+ printf '%s' '{"effort":{"wipLimit":3},"night":{"refuseLabels":["hold"]}}' >"$cfg"
354
+ out="$(_grant '{"budget":"+10k","waves":[[1]]}' \
355
+ | NIGHT_GRANT_CONFIG="$cfg" night_grant_parse 2>/dev/null | sed -n 1p \
356
+ | jq -c '[.wipLimit, .refuseLabels]' 2>/dev/null)"
357
+ _t "config: effort.wipLimit and night.refuseLabels reach the engine args" '[3,["hold"]]' "$out"
358
+ out="$(_grant '{"budget":"+10k","waves":[[1]]}' \
359
+ | EFFORT_WIP_LIMIT=1 NIGHT_GRANT_CONFIG="$cfg" night_grant_parse 2>/dev/null | sed -n 1p \
360
+ | jq -c '.wipLimit' 2>/dev/null)"
361
+ _t "config: EFFORT_WIP_LIMIT wins over effort.wipLimit" 1 "$out"
362
+ printf '%s' '{"effort":{"wipLimit":0}}' >"$cfg"
363
+ _grant '{"budget":"+10k","waves":[[1]]}' | NIGHT_GRANT_CONFIG="$cfg" night_grant_parse >/dev/null 2>&1; st=$?
364
+ _t "config: a WIP limit of 0 refuses the grant (no effort could start)" 1 "$st"
365
+ rm -f "$cfg"
366
+ for w in workflows cost secret; do
367
+ _grant "{\"budget\":\"+10k\",\"waves\":[[1]],\"waivers\":[\"$w\"]}" | night_grant_parse >/dev/null 2>&1; st=$?
368
+ _t "parse: '$w' is never waivable" 1 "$st"
369
+ done
370
+ printf 'just a comment\n```json\n{"budget":"+10k","waves":[[1]]}\n```\n' \
371
+ | night_grant_parse >/dev/null 2>&1; st=$?
372
+ _t "parse: a body without the marker is refused" 1 "$st"
373
+ printf '%s\nno block here\n' "$NIGHT_GRANT_MARKER" | night_grant_parse >/dev/null 2>&1; st=$?
374
+ _t "parse: a grant without a json block is refused" 1 "$st"
375
+
376
+ # pick — the owner's latest marker comment wins; nobody else's counts
377
+ _c() { # <login> <association> <body> — one comment as the picker reads it
378
+ jq -cn --arg l "$1" --arg a "$2" --arg b "$3" '{body: $b, login: $l, association: $a}'
379
+ }
380
+ out="$( { _c me OWNER "$NIGHT_GRANT_MARKER
381
+ old"; _c me OWNER unrelated; _c me OWNER "$NIGHT_GRANT_MARKER
382
+ new"; _c me OWNER 'also unrelated'; } | jq -s . | night_grant_pick 2>/dev/null | tail -1)"
383
+ _t "pick: the owner's latest grant comment wins" new "$out"
384
+ out="$( { _c me OWNER "$NIGHT_GRANT_MARKER
385
+ mine"; _c stranger NONE "$NIGHT_GRANT_MARKER
386
+ theirs"; } | jq -s . | night_grant_pick 2>/dev/null | tail -1)"
387
+ _t "pick: a later grant from a stranger is ignored" mine "$out"
388
+ out="$( { _c me OWNER "$NIGHT_GRANT_MARKER
389
+ mine"; _c helper CONTRIBUTOR "$NIGHT_GRANT_MARKER
390
+ theirs"; _c bot MEMBER "$NIGHT_GRANT_MARKER
391
+ theirs"; } | jq -s . | night_grant_pick 2>&1 >/dev/null)"
392
+ case "$out" in *'not written by the owner'*bot*helper*) out=named ;; esac
393
+ _t "pick: the ignored authors are named on stderr" named "$out"
394
+ { _c stranger NONE "$NIGHT_GRANT_MARKER
395
+ theirs"; } | jq -s . | night_grant_pick >/dev/null 2>&1; st=$?
396
+ _t "pick: only a stranger's grant exits 1" 1 "$st"
397
+ printf '%s' '["<!-- night-grant -->\nanonymous"]' | night_grant_pick >/dev/null 2>&1; st=$?
398
+ _t "pick: a comment with no author is never a grant" 1 "$st"
399
+ cfg="$NIGHT_GRANT_CONFIG.fixture"
400
+ printf '%s' '{"github":{"owner":"Acme"},"night":{"grantors":["lead"]}}' >"$cfg"
401
+ out="$( { _c acme MEMBER "$NIGHT_GRANT_MARKER
402
+ by-owner-login"; _c stranger NONE "$NIGHT_GRANT_MARKER
403
+ theirs"; } | jq -s . | NIGHT_GRANT_CONFIG="$cfg" night_grant_pick 2>/dev/null | tail -1)"
404
+ _t "pick: github.owner's login is the owner, whatever the letter case" by-owner-login "$out"
405
+ out="$( { _c acme MEMBER "$NIGHT_GRANT_MARKER
406
+ old"; _c Lead MEMBER "$NIGHT_GRANT_MARKER
407
+ by-grantor"; } | jq -s . | NIGHT_GRANT_CONFIG="$cfg" night_grant_pick 2>/dev/null | tail -1)"
408
+ _t "pick: a night.grantors login may write the grant" by-grantor "$out"
409
+ rm -f "$cfg"
410
+ printf '%s' '[{"body":"hello","login":"me","association":"OWNER"}]' | night_grant_pick >/dev/null 2>&1; st=$?
411
+ _t "pick: no grant comment exits 1" 1 "$st"
412
+
413
+ # preflight — against fixture settings files
414
+ tmp="${TMPDIR:-/tmp}/night-grant-selftest-$$.json"
415
+ printf '%s' '{"permissions":{"allow":["Bash(gh pr merge:*)"]}}' >"$tmp"
416
+ out="$(night_grant_preflight "$tmp" 2>/dev/null)"; st=$?
417
+ _t "preflight: a thin allowlist exits 1" 1 "$st"
418
+ _t "preflight: it reports each missing entry" 5 "$(printf '%s\n' "$out" | grep -c '^ MISSING')"
419
+ printf '%s' '{"permissions":{"allow":["Bash(gh:*)","Bash(git push:*)"]}}' >"$tmp"
420
+ night_grant_preflight "$tmp" >/dev/null 2>&1; st=$?
421
+ _t "preflight: a broader prefix covers its commands" 0 "$st"
422
+ printf '%s' '{"permissions":{"allow":["Bash(ghx:*)","Bash(git:*)"]}}' >"$tmp"
423
+ night_grant_preflight "$tmp" >/dev/null 2>&1; st=$?
424
+ _t "preflight: a prefix only covers on a word boundary" 1 "$st"
425
+ rm -f "$tmp"
426
+ night_grant_preflight "$tmp" >/dev/null 2>&1; st=$?
427
+ _t "preflight: a missing file is 2, never a silent 0" 2 "$st"
428
+
429
+ if [ "$fails" -eq 0 ]; then printf 'night-grant selftest OK\n'; return 0; fi
430
+ printf 'night-grant selftest FAILED (%s)\n' "$fails"; return 1
431
+ }
432
+
433
+ # ── dispatch (only when executed by name with a subcommand) ───────────────────────────────────
434
+ case "${0##*/}" in
435
+ night-grant.sh)
436
+ if [ $# -gt 0 ]; then
437
+ _ng_cmd="$1"; shift
438
+ case "$_ng_cmd" in
439
+ read) night_grant_read "$@" ;;
440
+ parse) night_grant_parse ;;
441
+ preflight) night_grant_preflight "$@" ;;
442
+ --selftest|selftest) night_grant_selftest ;;
443
+ -h|--help) sed -n '/^# Usage/,/^# bash/p' "$0" | sed 's/^# \{0,1\}//' ;;
444
+ *) _ng_err "unknown subcommand $_ng_cmd"; exit 2 ;;
445
+ esac
446
+ fi
447
+ ;;
448
+ esac
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ # night-run-test.sh — the night engine's decisions, evaluated with stubbed agents.
3
+ # scripts/night-run.test.mjs loads scripts/night-run.mjs as the Workflow runtime would, with
4
+ # agent()/pipeline()/budget faked, and drives every unattended decision. Needs node; skips without.
5
+ set -u
6
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
7
+ command -v node >/dev/null 2>&1 || { echo "night-run-test: node required — skipping"; exit 0; }
8
+ exec node --test "$ROOT/scripts/night-run.test.mjs"