@punks/cli 5.1.0 → 5.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 (89) hide show
  1. package/AGENTS.md +28 -10
  2. package/dist/BASELINE_CHANGELOG.md +11 -1
  3. package/dist/CHANGELOG.md +51 -0
  4. package/dist/baseline/scaffold-baseline/baseline.json +5 -10
  5. package/dist/baseline/scaffold-baseline/data/catalog/packs.json +1 -1
  6. package/dist/baseline/scaffold-baseline/data/catalog/skills.json +0 -8
  7. package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.mjs +118 -41
  8. package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.test.ts +345 -26
  9. package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents-validator.test.ts +39 -0
  10. package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents.mjs +8 -2
  11. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/phases/define-handoffs.md +1 -1
  12. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/phases/model-state.md +1 -1
  13. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/phases/test-routes.md +1 -1
  14. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/phases/write-phases.md +2 -2
  15. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/phases/write-router.md +1 -1
  16. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/references/authoring-contract.md +8 -8
  17. package/dist/baseline/scaffold-baseline/skills/agnostic/quality/autoreview/SKILL.md +1 -1
  18. package/dist/baseline/scaffold-baseline/skills/agnostic/quality/make-tsuite/SKILL.md +2 -2
  19. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/brainstorm/SKILL.md +21 -11
  20. package/dist/baseline/scaffold-baseline/skills/phases/debugging-phase/SKILL.md +3 -4
  21. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/SKILL.md +2 -2
  22. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/debug.md +2 -2
  23. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/human-steering.md +25 -0
  24. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/implement.md +2 -2
  25. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/review.md +2 -2
  26. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/router.md +3 -2
  27. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/context-continuity.md +1 -1
  28. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/failure-continuity.md +1 -1
  29. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/phase-handoff.md +4 -3
  30. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/AUTHORING-HANDOFF.md +9 -9
  31. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/SKILL.md +1 -1
  32. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/ensure-fog.md +1 -1
  33. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/grilling.md +1 -1
  34. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/human-steering.md +25 -0
  35. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/prototype.md +1 -1
  36. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/reconcile.md +1 -1
  37. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/research.md +1 -1
  38. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/router.md +1 -1
  39. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/references/state-graph.md +1 -1
  40. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/return-route.md +6 -5
  41. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/router.md +1 -1
  42. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/run-review.md +2 -1
  43. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/state-graph.md +3 -3
  44. package/dist/baseline/scaffold-baseline.json +5 -5
  45. package/dist/baseline/scaffold-baseline.tgz +0 -0
  46. package/dist/data/AGENTS.md +22 -5
  47. package/dist/data/scripts/commit-gate-runner.mjs +118 -41
  48. package/dist/data/scripts/sync-subagents.mjs +8 -2
  49. package/dist/index.js +117 -110
  50. package/dist/skills/agnostic/docs/write-graph-based-skills/phases/define-handoffs.md +1 -1
  51. package/dist/skills/agnostic/docs/write-graph-based-skills/phases/model-state.md +1 -1
  52. package/dist/skills/agnostic/docs/write-graph-based-skills/phases/test-routes.md +1 -1
  53. package/dist/skills/agnostic/docs/write-graph-based-skills/phases/write-phases.md +2 -2
  54. package/dist/skills/agnostic/docs/write-graph-based-skills/phases/write-router.md +1 -1
  55. package/dist/skills/agnostic/docs/write-graph-based-skills/references/authoring-contract.md +8 -8
  56. package/dist/skills/agnostic/quality/autoreview/SKILL.md +1 -1
  57. package/dist/skills/agnostic/quality/make-tsuite/SKILL.md +2 -2
  58. package/dist/skills/agnostic/requirements/brainstorm/SKILL.md +21 -11
  59. package/dist/skills/phases/debugging-phase/SKILL.md +3 -4
  60. package/dist/skills/phases/delivery-phase/SKILL.md +2 -2
  61. package/dist/skills/phases/delivery-phase/phases/debug.md +2 -2
  62. package/dist/skills/phases/delivery-phase/phases/human-steering.md +25 -0
  63. package/dist/skills/phases/delivery-phase/phases/implement.md +2 -2
  64. package/dist/skills/phases/delivery-phase/phases/review.md +2 -2
  65. package/dist/skills/phases/delivery-phase/phases/router.md +3 -2
  66. package/dist/skills/phases/delivery-phase/references/context-continuity.md +1 -1
  67. package/dist/skills/phases/delivery-phase/references/failure-continuity.md +1 -1
  68. package/dist/skills/phases/delivery-phase/references/phase-handoff.md +4 -3
  69. package/dist/skills/phases/finder-phase/AUTHORING-HANDOFF.md +6 -6
  70. package/dist/skills/phases/finder-phase/SKILL.md +1 -1
  71. package/dist/skills/phases/finder-phase/phases/ensure-fog.md +1 -1
  72. package/dist/skills/phases/finder-phase/phases/grilling.md +1 -1
  73. package/dist/skills/phases/finder-phase/phases/human-steering.md +25 -0
  74. package/dist/skills/phases/finder-phase/phases/prototype.md +1 -1
  75. package/dist/skills/phases/finder-phase/phases/reconcile.md +1 -1
  76. package/dist/skills/phases/finder-phase/phases/research.md +1 -1
  77. package/dist/skills/phases/finder-phase/phases/router.md +1 -1
  78. package/dist/skills/phases/finder-phase/references/state-graph.md +1 -1
  79. package/dist/skills/phases/review-phase/phases/return-route.md +6 -5
  80. package/dist/skills/phases/review-phase/phases/router.md +1 -1
  81. package/dist/skills/phases/review-phase/phases/run-review.md +2 -1
  82. package/dist/skills/phases/review-phase/references/state-graph.md +3 -3
  83. package/package.json +12 -6
  84. package/dist/baseline/scaffold-baseline/skills/agnostic/generic/handback/SKILL.md +0 -27
  85. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/handback.md +0 -27
  86. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/handback.md +0 -29
  87. package/dist/skills/agnostic/generic/handback/SKILL.md +0 -27
  88. package/dist/skills/phases/delivery-phase/phases/handback.md +0 -27
  89. package/dist/skills/phases/finder-phase/phases/handback.md +0 -29
package/AGENTS.md CHANGED
@@ -1,20 +1,38 @@
1
1
  ## CLI App Guidance
2
2
 
3
- Recovery keeps changed changelog paths as the sole product selector. `RELEASE_RECOVERY.json` must bind its failure, target commit/tree, note hash, first-parent order, and provider identities. An exact already-published provider-readback recovery creates no artifacts, mutates no product, and advances authority only after complete readback. Publication uses an immutable current commit/tree input and performs no prior pull-request Candidate Evidence lookup.
3
+ This app owns the `hi`/`hint` executable, repository detection, local scaffold and update writes, bundled baseline fallback, diff ergonomics, and release/baseline publishing scripts. Keep remote registry, provenance, auth, telemetry, and artifact access behind the control-plane boundary.
4
4
 
5
- Primary skills here: `autoreview`, `codebase-design`, `effect`, `effect-backend-structure`, `effect-recoverable-actions`, `effect-service-design`, `improve-codebase-architecture`, `parallel-research`, `prototype`, `quality-types`, `review`, `simplify`, `swarm-planner`, `tdd`, `turborepo`.
5
+ Work within the accepted goal. Obtain explicit user authorization before changing requirements, weakening a gate, or substantially redesigning implementation.
6
6
 
7
- This app owns the `hi`/`hint` executable, repo detection flow, local scaffold application, bundled baseline fallback, update/diff ergonomics, and release/baseline publishing scripts. Preserve current CLI behavior during monorepo work.
8
- Autonomy ends at accepted goal bounds. If progress requires changed requirements, a weaker gate, or substantial implementation redesign, invoke `$handback` before expanding work.
7
+ Use [Rule Registry](../../.agents/rules/index.md) as the exhaustive codebase-rule index. Activate every rule whose path or task trigger matches the work, read its linked file, and record `pass`, `fail`, or `not-applicable` with evidence in the current handoff work log.
9
8
 
10
- Reusable skill changes in distributed assets are complete only after the root source-first flow: before editing, verify `git -C /Users/stefan/Desktop/repos/wearedevpunks-skills branch --show-current` returns exactly `main`; stop otherwise. Edit and commit the canonical source only on that checked-out `main` branch; alternate branches or worktrees are out of scope for this flow. Then push, run `bun run sync:skills`, verify the exact receipt SHA, and publish the baseline when requested.
9
+ ### Skills
11
10
 
12
- Keep consumer-repo product logic out of the CLI. The future backend owns registry, provenance, auth, telemetry, and artifact access; the CLI remains the local scanner, cache, prompt/skill/hook placer, and filesystem writer.
11
+ Read the installed skill on its exact invocation below; phase routing remains inherited from the root guidance.
13
12
 
14
- Before completing CLI release-bearing changes, run `bun run release:classify -- --base <base-ref> --head <head-ref>`. Changed changelog paths alone select the product: `BASELINE_CHANGELOG.md` selects `baseline`, `CHANGELOG.md` selects `npm`, both select `mixed`, and neither selects `none`; artifact differences remain diagnostics. A selected baseline needs reviewed non-empty `Unreleased` notes or an exact-tag section plus compatibility. Selected npm needs a bumped `apps/cli/package.json` version and matching non-empty `CHANGELOG.md` version notes. Completion requires the classifier to pass. `bun run release:publish` publishes `@punks/cli`, pushes the matching `v<version>` tag, and creates the GitHub release from that changelog entry; baseline-only releases stay on `baseline/stable/*`.
13
+ | Skill | Exact trigger |
14
+ | --- | --- |
15
+ | `autoreview` | When the task explicitly invokes `autoreview`, read `../../.agents/skills/autoreview/SKILL.md`. |
16
+ | `codebase-design` | When the task explicitly invokes `codebase-design`, read `../../.agents/skills/codebase-design/SKILL.md`. |
17
+ | `effect` | When the task explicitly invokes `effect`, read `../../.agents/skills/effect/SKILL.md`. |
18
+ | `effect-backend-structure` | When the task explicitly invokes `effect-backend-structure`, read `../../.agents/skills/effect-backend-structure/SKILL.md`. |
19
+ | `effect-recoverable-actions` | When the task explicitly invokes `effect-recoverable-actions`, read `../../.agents/skills/effect-recoverable-actions/SKILL.md`. |
20
+ | `effect-service-design` | When the task explicitly invokes `effect-service-design`, read `../../.agents/skills/effect-service-design/SKILL.md`. |
21
+ | `improve-codebase-architecture` | When the task explicitly invokes `improve-codebase-architecture`, read `../../.agents/skills/improve-codebase-architecture/SKILL.md`. |
22
+ | `make-tsuite` | When the task explicitly invokes `make-tsuite`, read `../../.agents/skills/make-tsuite/SKILL.md`. |
23
+ | `parallel-research` | When the task explicitly invokes `parallel-research`, read `../../.agents/skills/parallel-research/SKILL.md`. |
24
+ | `prototype` | When the task explicitly invokes `prototype`, read `../../.agents/skills/prototype/SKILL.md`. |
25
+ | `quality-types` | When the task explicitly invokes `quality-types`, read `../../.agents/skills/quality-types/SKILL.md`. |
26
+ | `review` | When the task explicitly invokes `review`, read `../../.agents/skills/review/SKILL.md`. |
27
+ | `simplify` | When the task explicitly invokes `simplify`, read `../../.agents/skills/simplify/SKILL.md`. |
28
+ | `swarm-planner` | When the task explicitly invokes `swarm-planner`, read `../../.agents/skills/swarm-planner/SKILL.md`. |
29
+ | `tdd` | When the task explicitly invokes `tdd`, read `../../.agents/skills/tdd/SKILL.md`. |
30
+ | `turborepo` | When the task explicitly invokes `turborepo`, read `../../.agents/skills/turborepo/SKILL.md`. |
15
31
 
16
- For direct CLI UX, packaging, and release behavior guidance, inspect:
32
+ ### Source and validation seams
17
33
 
18
- - `opensrc path cevr/sentry-cli` (`https://github.com/cevr/sentry-cli`)
34
+ Read the [Source Guide](../../opensrc/README.md) when work depends on third-party library behavior. For CLI UX, packaging, or release behavior patterns, inspect `opensrc path cevr/sentry-cli` (`https://github.com/cevr/sentry-cli`).
19
35
 
20
- If work here changes operator workflow, setup, or AI scaffolding behavior, update `docs/README.md` and `docs/runbooks/hi-cli-scaffolding.md` in the same task.
36
+ Validate the changed CLI behavior with the narrowest applicable tests and checks in `package.json`; use the nested source guidance for source and packaged-data changes. For release-bearing work, run `bun run release:classify -- --base <base-ref> --head <head-ref>` from the repository root and require it to pass.
37
+
38
+ When work changes operator workflow, setup, or AI scaffolding behavior, update [docs index](../../docs/README.md) and [CLI scaffolding runbook](../../docs/runbooks/hi-cli-scaffolding.md) in the same task.
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
- Compatibility: `>=5.1.0 <5.2.0`
5
+ Compatibility: `>=5.2.0 <5.3.0`
6
6
 
7
7
  ### Added
8
8
 
@@ -12,6 +12,16 @@ Compatibility: `>=5.1.0 <5.2.0`
12
12
 
13
13
  ### Fixed
14
14
 
15
+ - Cover staged deletions, root changes, and cross-owner renames in the bundled
16
+ Commit Gate runner. Honor explicit file, owner, and repository execution modes,
17
+ deduplicate identical checks, and preserve successful command diagnostics;
18
+ accept the matching execution metadata in generated subagent contracts (#222).
19
+ - Retire the standalone `handback` skill from the shipped catalog and interaction
20
+ pack; keep human steering and scope decisions within their owning workflow
21
+ phases (#222).
22
+ - Update bundled brainstorm guidance to trace the system from the operating
23
+ agent's perspective and reconcile affected design documents and plans when
24
+ their edits are authorized (#222).
15
25
  - Restore Effect internal-module topology and repository-boundary guidance; keep
16
26
  service qualification and application policy in `effect-service-design` (#205).
17
27
  - Sync canonical `wearedevpunks/skills@0519d685213a8085928bde8a5d744fcd6737c931`
package/dist/CHANGELOG.md CHANGED
@@ -2,6 +2,57 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 5.2.0 - 2026-09-22
6
+
7
+ ### Added
8
+
9
+ - Add explicit file, owner, and repository execution scopes for Commit Gate checks,
10
+ including repository lint and format authority in project settings (#222).
11
+
12
+ ### Fixed
13
+
14
+ - Validate the complete update candidate, including live guidance targets, staged
15
+ replacements, and removals, before publishing managed changes (#222).
16
+ - Limit update installation and lint work to affected consumers, including optional
17
+ dependency consumers; support generated backoffice Vitest overrides and preserve
18
+ actionable installation and configuration errors (#222).
19
+ - Keep unrelated archives and migration payloads out of generation freshness while
20
+ retaining validation of explicitly referenced inputs (#222).
21
+ - Cover root changes, deletions, and cross-owner renames in Commit Gate checks;
22
+ preserve command output, deduplicate identical checks, and enforce zero warnings
23
+ for generated Oxlint commands (#222).
24
+
25
+ ### Changed
26
+
27
+ - Retire the standalone handback skill and its generated prompt pointers in favor
28
+ of handback guidance owned by lifecycle phases (#222).
29
+ - Use Bun 1.4.0 for repository tooling and two-vCPU Linux CI workers, removing
30
+ automated macOS jobs and provisioning browsers only for selected consumers (#223).
31
+ - Reuse verification results across unrelated documentation changes while tracking
32
+ consumed inputs and runtime capabilities; remove duplicate task execution (#223).
33
+ - Reduce routine test setup and repeated assertions, use minimal real release
34
+ recovery histories, and retain full historical recovery replay and updater
35
+ benchmarking as on-demand diagnostics (#223).
36
+
37
+ ## 5.1.1 - 2026-09-17
38
+
39
+ ### Added
40
+
41
+ - Make `hi update` derive managed artifacts from a shared manifest-driven plan,
42
+ validate in an isolated candidate, and reuse validation and prepared-install
43
+ results only for matching relevant inputs (#215).
44
+ - Report update lifecycle progress while preserving a single final JSON stdout
45
+ document, with local cache clearing and optional signed remote-cache
46
+ transport outcomes surfaced explicitly (#215).
47
+
48
+ ### Fixed
49
+
50
+ - Fail closed before dependent update work when validation inputs are
51
+ incomplete, uncontained through canonical path aliases, or use uncontrolled
52
+ executable configuration; retain precise subprocess failure facts (#215).
53
+ - Keep update planned and completed operations truthful across no-change,
54
+ recovery, cache-reuse, and managed-drift outcomes (#215).
55
+
5
56
  ## 5.1.0 - 2026-09-15
6
57
 
7
58
  ### Added
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
3
  "channel": "stable",
4
- "version": "2026.09.15-1ee7f8b7",
5
- "tag": "baseline/stable/2026.09.15-1ee7f8b7",
6
- "commit": "1ee7f8b72f8fe116ad74aa15923238d3b985c751",
4
+ "version": "2026.09.22-71e84184",
5
+ "tag": "baseline/stable/2026.09.22-71e84184",
6
+ "commit": "71e84184be2e0eff48cffae43face01df5d300ab",
7
7
  "sha256": null,
8
8
  "compatibility": {
9
- "cliVersionRange": ">=5.1.0 <5.2.0"
9
+ "cliVersionRange": ">=5.2.0 <5.3.0"
10
10
  },
11
- "generatedAt": "2026-09-15T22:12:46.000Z",
11
+ "generatedAt": "2026-09-22T14:24:57.000Z",
12
12
  "capabilities": {
13
13
  "scopedAuthoring": {
14
14
  "revision": "1",
@@ -358,11 +358,6 @@
358
358
  "authoringRevision": "1",
359
359
  "id": "handoff"
360
360
  },
361
- {
362
- "activationRevision": "1",
363
- "authoringRevision": "1",
364
- "id": "handback"
365
- },
366
361
  {
367
362
  "activationRevision": "1",
368
363
  "authoringRevision": "1",
@@ -67,7 +67,7 @@
67
67
  "lintAssets": [],
68
68
  "promptDetails": ["shared agent interaction helpers"],
69
69
  "promptSurfaces": ["shared-agents"],
70
- "skills": ["handback", "show-me", "wait-what"],
70
+ "skills": ["show-me", "wait-what"],
71
71
  "triggerPackages": []
72
72
  },
73
73
  {
@@ -551,14 +551,6 @@
551
551
  "sourceDirectory": "skills/agnostic/generic/handoff",
552
552
  "tier": "agnostic"
553
553
  },
554
- {
555
- "framework": null,
556
- "id": "handback",
557
- "language": null,
558
- "requiresTools": [],
559
- "sourceDirectory": "skills/agnostic/generic/handback",
560
- "tier": "agnostic"
561
- },
562
554
  {
563
555
  "framework": null,
564
556
  "id": "improve-codebase-architecture",
@@ -39,11 +39,29 @@ const stagedPaths = async () => {
39
39
  const { stdout } = await execFile("git", [
40
40
  "diff",
41
41
  "--cached",
42
- "--name-only",
43
- "--diff-filter=ACMR",
42
+ "--name-status",
43
+ "--find-renames",
44
44
  "-z",
45
45
  ]);
46
- return stdout.split("\0").filter(Boolean);
46
+ const entries = stdout.split("\0").filter(Boolean);
47
+ const triggers = new Set();
48
+ const files = new Set();
49
+ for (let index = 0; index < entries.length; index += 2) {
50
+ const status = entries[index];
51
+ let file = entries[index + 1];
52
+ if (status.startsWith("R") || status.startsWith("C")) {
53
+ if (status.startsWith("R")) {
54
+ triggers.add(file);
55
+ }
56
+ index += 1;
57
+ file = entries[index + 1];
58
+ }
59
+ triggers.add(file);
60
+ if (status !== "D") {
61
+ files.add(file);
62
+ }
63
+ }
64
+ return { files: [...files], triggers: [...triggers] };
47
65
  };
48
66
 
49
67
  const activeWorktreeRoot = async () => {
@@ -68,50 +86,109 @@ if (contractsPath === null) {
68
86
  const contracts = JSON.parse(contractsContent);
69
87
  const worktreeRoot = await activeWorktreeRoot();
70
88
  const staged = await stagedPaths();
71
- if (staged.length === 0) {
89
+ if (staged.triggers.length === 0) {
72
90
  process.exit(0);
73
91
  }
74
92
 
75
- const failuresByContract = await Promise.all(
76
- contracts.map(async (contract) => {
77
- const relativePath = contract.path ?? ".";
78
- const ownerCwd = path.resolve(worktreeRoot, relativePath);
79
- const prefix =
80
- relativePath === "." || relativePath === "" ? "" : `${relativePath.replace(/\/$/u, "")}/`;
81
- const files = staged
82
- .filter((file) => prefix === "" || file.startsWith(prefix))
83
- .map((file) => (prefix === "" ? file : file.slice(prefix.length)));
84
- if (files.length === 0) {
85
- return [];
86
- }
87
- const fileArguments = files.map(shellQuote).join(" ");
88
- const commands = [
89
- ["lint", contract.lint],
90
- ["formatCheck", contract.formatCheck],
91
- ];
92
- const results = await Promise.all(
93
- commands.map(async ([kind, template]) => {
94
- const scopedTemplate = template.replace(/(?<prefix>^|\s)\.\s*$/u, "$<prefix>{files}");
95
- const command = scopedTemplate.includes("{files}")
96
- ? scopedTemplate.replaceAll("{files}", fileArguments)
97
- : `${scopedTemplate} -- ${fileArguments}`;
98
- const result = await run(command, ownerCwd, {
99
- HI_STAGED_FILES: files.join("\n"),
100
- });
101
- return { ...result, cwd: ownerCwd, kind, owner: contract.owner ?? ownerCwd };
102
- }),
103
- );
104
- return results.filter((result) => result.code !== 0);
105
- }),
93
+ const commands = new Map();
94
+ const kinds = ["lint", "formatCheck"];
95
+ const repositoryKinds = new Set(
96
+ kinds.filter((kind) =>
97
+ contracts.some((contract) => contract.execution?.[kind] === "repository"),
98
+ ),
106
99
  );
107
- const failures = failuresByContract.flat();
108
-
109
- for (const failure of failures) {
110
- process.stderr.write(
111
- `Commit Gate ${failure.kind} failed for ${failure.owner} in ${failure.cwd} (exit ${failure.code})${failure.launchError === "" ? "" : `: ${failure.launchError}`}.\n${failure.stdout}${failure.stderr}`,
100
+ const covered = new Map(kinds.map((kind) => [kind, new Set()]));
101
+ const coverageFailures = [];
102
+ for (const contract of contracts) {
103
+ const relativePath = contract.path ?? ".";
104
+ const ownerCwd = path.resolve(worktreeRoot, relativePath);
105
+ const owner = contract.owner ?? ownerCwd;
106
+ const prefix =
107
+ relativePath === "." || relativePath === "" ? "" : `${relativePath.replace(/\/$/u, "")}/`;
108
+ const triggers = staged.triggers.filter((file) => prefix === "" || file.startsWith(prefix));
109
+ const files = staged.files
110
+ .filter((file) => prefix === "" || file.startsWith(prefix))
111
+ .map((file) => (prefix === "" ? file : file.slice(prefix.length)));
112
+ const fileArguments = files.map(shellQuote).join(" ");
113
+ for (const kind of kinds) {
114
+ const template = contract[kind];
115
+ const mode = contract.execution?.[kind];
116
+ if (repositoryKinds.has(kind) && mode !== "repository") {
117
+ continue;
118
+ }
119
+ if (triggers.length === 0 && mode !== "repository") {
120
+ continue;
121
+ }
122
+ if (contract.execution !== undefined && !["files", "owner", "repository"].includes(mode)) {
123
+ coverageFailures.push(
124
+ `${kind} for ${owner} requires an execution mode of files, owner, or repository`,
125
+ );
126
+ continue;
127
+ }
128
+ if (mode === "files" && !template.includes("{files}")) {
129
+ coverageFailures.push(
130
+ `${kind} for ${owner} in files mode requires an explicit {files} placeholder`,
131
+ );
132
+ continue;
133
+ }
134
+ if ((mode === undefined || mode === "files") && files.length === 0) {
135
+ coverageFailures.push(
136
+ `${kind} for ${owner} needs existing staged files: ${triggers.join(", ")}`,
137
+ );
138
+ continue;
139
+ }
140
+ let command = template;
141
+ if (mode === "files") {
142
+ command = template.replaceAll("{files}", fileArguments);
143
+ } else if (mode === undefined) {
144
+ const scopedTemplate = template.replace(/(?<prefix>^|\s)\.\s*$/u, "$<prefix>{files}");
145
+ command = scopedTemplate.includes("{files}")
146
+ ? scopedTemplate.replaceAll("{files}", fileArguments)
147
+ : `${scopedTemplate} -- ${fileArguments}`;
148
+ }
149
+ for (const file of mode === "repository" ? staged.triggers : triggers) {
150
+ covered.get(kind).add(file);
151
+ }
152
+ const key = JSON.stringify([ownerCwd, command, files]);
153
+ const existing = commands.get(key);
154
+ if (existing === undefined) {
155
+ commands.set(key, { checks: [{ kind, owner }], command, cwd: ownerCwd, files });
156
+ } else {
157
+ existing.checks.push({ kind, owner });
158
+ }
159
+ }
160
+ }
161
+ for (const kind of kinds) {
162
+ const uncovered = staged.triggers.filter((file) => !covered.get(kind).has(file));
163
+ if (uncovered.length > 0) {
164
+ coverageFailures.push(`${kind} has no command for: ${uncovered.join(", ")}`);
165
+ }
166
+ }
167
+ if (coverageFailures.length > 0) {
168
+ throw new Error(
169
+ `Commit Gate coverage missing:\n${coverageFailures.join("\n")}\nConfigure owner aggregate checks or commitGateChecks.repository.lint / commitGateChecks.repository.formatCheck, then run hi update to regenerate contracts.`,
112
170
  );
113
171
  }
114
- process.exitCode = failures.length === 0 ? 0 : 1;
172
+ const results = await Promise.all(
173
+ [...commands.values()].map(async (command) => ({
174
+ ...command,
175
+ ...(await run(command.command, command.cwd, { HI_STAGED_FILES: command.files.join("\n") })),
176
+ })),
177
+ );
178
+ for (const result of results) {
179
+ if (result.code === 0) {
180
+ process.stdout.write(result.stdout);
181
+ process.stderr.write(result.stderr);
182
+ } else {
183
+ for (const check of result.checks) {
184
+ process.stderr.write(
185
+ `Commit Gate ${check.kind} failed for ${check.owner} in ${result.cwd} (exit ${result.code})${result.launchError === "" ? "" : `: ${result.launchError}`}.\n`,
186
+ );
187
+ }
188
+ process.stderr.write(`${result.stdout}${result.stderr}`);
189
+ }
190
+ }
191
+ process.exitCode = results.some((result) => result.code !== 0) ? 1 : 0;
115
192
  } catch (error) {
116
193
  console.error(error instanceof Error ? error.message : String(error));
117
194
  process.exitCode = 1;