@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
@@ -1,5 +1,5 @@
1
- import { execFileSync } from "node:child_process";
2
- import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
1
+ import { spawnSync } from "node:child_process";
2
+ import { mkdir, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { tmpdir } from "node:os";
5
5
  import { afterEach, describe, expect, it } from "vitest";
@@ -9,32 +9,22 @@ interface ExecResult {
9
9
  readonly stderr: string;
10
10
  readonly stdout: string;
11
11
  }
12
- const isRecord = (value: unknown): value is Record<string, unknown> =>
13
- typeof value === "object" && value !== null;
14
12
  const run = async (
15
13
  command: string,
16
14
  args: readonly string[],
17
15
  options: { readonly cwd: string },
18
16
  ): Promise<ExecResult> => {
19
17
  await Promise.resolve();
20
- try {
21
- return {
22
- code: 0,
23
- stderr: "",
24
- stdout: execFileSync(command, args, {
25
- cwd: options.cwd,
26
- encoding: "utf-8",
27
- stdio: ["ignore", "pipe", "pipe"],
28
- }),
29
- };
30
- } catch (error) {
31
- const record = isRecord(error) ? error : {};
32
- return {
33
- code: typeof record.status === "number" ? record.status : 1,
34
- stderr: typeof record.stderr === "string" ? record.stderr : "",
35
- stdout: typeof record.stdout === "string" ? record.stdout : "",
36
- };
37
- }
18
+ const result = spawnSync(command, args, {
19
+ cwd: options.cwd,
20
+ encoding: "utf-8",
21
+ stdio: ["ignore", "pipe", "pipe"],
22
+ });
23
+ return {
24
+ code: result.status ?? 1,
25
+ stderr: result.stderr ?? result.error?.message ?? "",
26
+ stdout: result.stdout ?? "",
27
+ };
38
28
  };
39
29
 
40
30
  const runGit = async (args: readonly string[], cwd: string): Promise<void> => {
@@ -60,10 +50,16 @@ const fixture = async (repoName?: string) => {
60
50
  await runGit(["config", "--local", "user.name", "Commit Gate Test"], root);
61
51
  await runGit(["config", "--local", "user.email", "commit-gate-test@example.com"], root);
62
52
  await mkdir(path.join(root, ".devpunks"), { recursive: true });
53
+ await writeFile(path.join(root, ".git/info/exclude"), "/marker.mjs\n/.devpunks/\n");
63
54
  await writeFile(path.join(root, "marker.mjs"), markerScript);
64
55
  return root;
65
56
  };
66
57
 
58
+ const runGate = async (root: string, contracts: readonly unknown[]) => {
59
+ await writeFile(path.join(root, ".devpunks/contracts.json"), JSON.stringify(contracts));
60
+ return await run("node", [runner, "--contracts", ".devpunks/contracts.json"], { cwd: root });
61
+ };
62
+
67
63
  describe("Commit Gate runner", () => {
68
64
  afterEach(async () => {
69
65
  const worktreeResults = await Promise.all(
@@ -90,6 +86,324 @@ describe("Commit Gate runner", () => {
90
86
  }
91
87
  });
92
88
 
89
+ it("preserves successful output once on its original streams in contract and command order", async () => {
90
+ const root = await fixture();
91
+ await writeFile(path.join(root, "a.ts"), "a");
92
+ await runGit(["add", "a.ts"], root);
93
+ await writeFile(
94
+ path.join(root, "diagnostics.mjs"),
95
+ "const [label, delay] = process.argv.slice(2); setTimeout(() => { process.stdout.write(label + ':out\\n'); process.stderr.write(label + ':err\\n'); }, Number(delay));",
96
+ );
97
+ const result = await runGate(root, [
98
+ {
99
+ formatCheck: "node diagnostics.mjs first-format 40",
100
+ lint: "node diagnostics.mjs first-lint 60",
101
+ },
102
+ {
103
+ formatCheck: "node diagnostics.mjs second-format 0",
104
+ lint: "node diagnostics.mjs second-lint 20",
105
+ },
106
+ ]);
107
+ expect(result).toStrictEqual({
108
+ code: 0,
109
+ stderr: "first-lint:err\nfirst-format:err\nsecond-lint:err\nsecond-format:err\n",
110
+ stdout: "first-lint:out\nfirst-format:out\nsecond-lint:out\nsecond-format:out\n",
111
+ });
112
+ await expect(runGate(root, [{ formatCheck: "true", lint: "true" }])).resolves.toStrictEqual({
113
+ code: 0,
114
+ stderr: "",
115
+ stdout: "",
116
+ });
117
+ });
118
+
119
+ it("runs explicit owner commands verbatim and expands only explicit file placeholders", async () => {
120
+ const root = await fixture();
121
+ await mkdir(path.join(root, "apps/web"), { recursive: true });
122
+ const file = "a 'quoted'.ts";
123
+ await writeFile(path.join(root, "apps/web", file), "a");
124
+ await runGit(["add", "apps/web"], root);
125
+ await writeFile(
126
+ path.join(root, "arguments.mjs"),
127
+ "const [label, ...args] = process.argv.slice(2); process.stdout.write(JSON.stringify({ label, args, files: process.env.HI_STAGED_FILES }) + '\\n');",
128
+ );
129
+ const result = await runGate(root, [
130
+ {
131
+ execution: { formatCheck: "files", lint: "owner" },
132
+ formatCheck: "node ../../arguments.mjs files {files} {files}",
133
+ lint: "node ../../arguments.mjs owner . '{files}'",
134
+ owner: "web",
135
+ path: "apps/web",
136
+ },
137
+ ]);
138
+ expect(result.code).toBe(0);
139
+ expect(result.stderr).toBe("");
140
+ expect(
141
+ result.stdout
142
+ .trim()
143
+ .split("\n")
144
+ .map((line): unknown => JSON.parse(line)),
145
+ ).toStrictEqual([
146
+ { args: [".", "{files}"], files: file, label: "owner" },
147
+ { args: [file, file], files: file, label: "files" },
148
+ ]);
149
+ });
150
+
151
+ it.each(["delete", "rename"])(
152
+ "triggers aggregate coverage for %s source paths and nested owners without passing deleted names",
153
+ async (change) => {
154
+ const root = await fixture();
155
+ await mkdir(path.join(root, "apps/source/nested"), { recursive: true });
156
+ await mkdir(path.join(root, "apps/destination"), { recursive: true });
157
+ const oldFile = "apps/source/nested/old\nname.ts";
158
+ const newFile = "apps/destination/new.ts";
159
+ await writeFile(path.join(root, oldFile), "export const value = 1;\n");
160
+ await runGit(["add", oldFile], root);
161
+ await runGit(["commit", "-qm", "seed"], root);
162
+ await (change === "rename"
163
+ ? rename(path.join(root, oldFile), path.join(root, newFile))
164
+ : rm(path.join(root, oldFile)));
165
+ await runGit(["add", "-A"], root);
166
+ await writeFile(
167
+ path.join(root, "arguments.mjs"),
168
+ "process.stdout.write(JSON.stringify({ args: process.argv.slice(2), files: process.env.HI_STAGED_FILES }) + '\\n');",
169
+ );
170
+ const owners = ["apps/source", "apps/source/nested", "apps/destination"];
171
+ const result = await runGate(
172
+ root,
173
+ owners.map((owner) => ({
174
+ execution: { formatCheck: "owner", lint: "owner" },
175
+ formatCheck: `node ${path.relative(owner, "arguments.mjs")} ${owner}-format .`,
176
+ lint: `node ${path.relative(owner, "arguments.mjs")} ${owner}-lint .`,
177
+ owner,
178
+ path: owner,
179
+ })),
180
+ );
181
+ expect(result.code).toBe(0);
182
+ expect(result.stderr).toBe("");
183
+ expect(
184
+ result.stdout
185
+ .trim()
186
+ .split("\n")
187
+ .map((line): unknown => JSON.parse(line)),
188
+ ).toStrictEqual(
189
+ owners.slice(0, change === "rename" ? 3 : 2).flatMap((owner) =>
190
+ ["lint", "format"].map((kind) => ({
191
+ args: [`${owner}-${kind}`, "."],
192
+ files: owner === "apps/destination" ? "new.ts" : "",
193
+ })),
194
+ ),
195
+ );
196
+ },
197
+ );
198
+
199
+ it.each(["root", "root-with-owner", "empty", "deleted-legacy", "deleted-files"])(
200
+ "fails actionably when %s changes have no command coverage",
201
+ async (change) => {
202
+ const root = await fixture();
203
+ await mkdir(path.join(root, "apps/web"), { recursive: true });
204
+ const file = change.startsWith("deleted") ? "apps/web/gone.ts" : "root.ts";
205
+ await writeFile(path.join(root, file), "a");
206
+ await runGit(["add", file], root);
207
+ if (change === "root-with-owner") {
208
+ await writeFile(path.join(root, "apps/web/a.ts"), "a");
209
+ await runGit(["add", "apps/web/a.ts"], root);
210
+ }
211
+ if (change.startsWith("deleted")) {
212
+ await runGit(["commit", "-qm", "seed"], root);
213
+ await runGit(["rm", "-q", file], root);
214
+ await mkdir(path.join(root, "apps/web"), { recursive: true });
215
+ }
216
+ const result = await runGate(
217
+ root,
218
+ change === "empty"
219
+ ? []
220
+ : [
221
+ {
222
+ formatCheck: "node ../../marker.mjs {files}",
223
+ lint: "node ../../marker.mjs {files}",
224
+ owner: "web",
225
+ path: "apps/web",
226
+ ...(change === "deleted-files"
227
+ ? { execution: { formatCheck: "files", lint: "files" } }
228
+ : {}),
229
+ },
230
+ ],
231
+ );
232
+ expect(result.code).toBe(1);
233
+ expect(result.stderr).toContain(file);
234
+ expect(result.stderr).toMatch(
235
+ /coverage.*lint.*formatCheck.*commitGateChecks.repository.*hi update/su,
236
+ );
237
+ await expect(readFile(path.join(root, "apps/web/marker.out"), "utf-8")).rejects.toThrow(
238
+ "ENOENT",
239
+ );
240
+ },
241
+ );
242
+
243
+ it("lets explicit repository authority subsume only the same kind of subordinate check", async () => {
244
+ const root = await fixture();
245
+ await mkdir(path.join(root, "apps/web"), { recursive: true });
246
+ await writeFile(path.join(root, "apps/web/gone.ts"), "gone");
247
+ await runGit(["add", "apps/web/gone.ts"], root);
248
+ await runGit(["commit", "-qm", "seed"], root);
249
+ await runGit(["rm", "-q", "apps/web/gone.ts"], root);
250
+ await mkdir(path.join(root, "apps/web"), { recursive: true });
251
+ await writeFile(path.join(root, "root.ts"), "root");
252
+ await runGit(["add", "root.ts"], root);
253
+ const subordinate = {
254
+ execution: { formatCheck: "owner", lint: "files" },
255
+ formatCheck: "printf web-format",
256
+ lint: "false",
257
+ owner: "web",
258
+ path: "apps/web",
259
+ };
260
+ const repository = {
261
+ execution: { formatCheck: "owner", lint: "repository" },
262
+ formatCheck: "printf root-format",
263
+ lint: "printf root-lint",
264
+ };
265
+ await expect(runGate(root, [subordinate, repository])).resolves.toStrictEqual({
266
+ code: 0,
267
+ stderr: "",
268
+ stdout: "web-formatroot-lintroot-format",
269
+ });
270
+ await expect(
271
+ runGate(root, [
272
+ { ...subordinate, formatCheck: "false" },
273
+ { ...repository, execution: { formatCheck: "repository", lint: "repository" } },
274
+ ]),
275
+ ).resolves.toStrictEqual({ code: 0, stderr: "", stdout: "root-lintroot-format" });
276
+ const ownerOnly = await runGate(root, [
277
+ { ...subordinate, execution: { formatCheck: "owner", lint: "owner" } },
278
+ { ...repository, execution: { formatCheck: "owner", lint: "owner" } },
279
+ ]);
280
+ expect(ownerOnly.code).toBe(1);
281
+ expect(ownerOnly.stderr).toContain("lint failed for web");
282
+ });
283
+
284
+ it("executes identical final invocations once while retaining distinct custom commands and working directories", async () => {
285
+ const root = await fixture();
286
+ await mkdir(path.join(root, "apps/web"), { recursive: true });
287
+ await writeFile(path.join(root, "apps/web/a.ts"), "a");
288
+ await runGit(["add", "apps/web/a.ts"], root);
289
+ await writeFile(
290
+ path.join(root, "record.mjs"),
291
+ "import fs from 'node:fs'; const label = process.argv[2]; fs.appendFileSync('calls.out', label + '\\n'); process.stdout.write(label + ':' + process.env.HI_STAGED_FILES + '\\n');",
292
+ );
293
+ const first = `node '${path.join(root, "record.mjs")}' first`;
294
+ const second = `node '${path.join(root, "record.mjs")}' second`;
295
+ const execution = { formatCheck: "owner", lint: "owner" };
296
+ await expect(
297
+ runGate(root, [
298
+ { execution, formatCheck: first, lint: first },
299
+ { execution, formatCheck: second, lint: first, path: "" },
300
+ { execution, formatCheck: first, lint: first, path: "apps/web" },
301
+ ]),
302
+ ).resolves.toStrictEqual({
303
+ code: 0,
304
+ stderr: "",
305
+ stdout: "first:apps/web/a.ts\nsecond:apps/web/a.ts\nfirst:a.ts\n",
306
+ });
307
+ const calls = await readFile(path.join(root, "calls.out"), "utf-8");
308
+ expect(calls.trim().split("\n").toSorted()).toStrictEqual(["first", "second"]);
309
+ await expect(readFile(path.join(root, "apps/web/calls.out"), "utf-8")).resolves.toBe("first\n");
310
+ });
311
+
312
+ it.each(["missing-placeholder", "unknown-mode", "partial-execution"])(
313
+ "rejects %s execution metadata instead of guessing coverage",
314
+ async (configuration) => {
315
+ const root = await fixture();
316
+ await writeFile(path.join(root, "a.ts"), "a");
317
+ await runGit(["add", "a.ts"], root);
318
+ const execution =
319
+ configuration === "partial-execution"
320
+ ? { formatCheck: "owner" }
321
+ : { formatCheck: "owner", lint: configuration === "unknown-mode" ? "shell" : "files" };
322
+ const result = await runGate(root, [
323
+ {
324
+ execution,
325
+ formatCheck: "true",
326
+ lint: "node marker.mjs .",
327
+ },
328
+ ]);
329
+ expect(result.code).toBe(1);
330
+ expect(result.stderr).toMatch(/coverage.*lint.*hi update/su);
331
+ expect(result.stderr).toContain(
332
+ configuration === "missing-placeholder" ? "{files}" : "execution mode",
333
+ );
334
+ await expect(readFile(path.join(root, "marker.out"), "utf-8")).rejects.toThrow("ENOENT");
335
+ },
336
+ );
337
+
338
+ it("deduplicates legacy templates after expanding their final file arguments", async () => {
339
+ const root = await fixture();
340
+ await writeFile(path.join(root, "a.ts"), "a");
341
+ await runGit(["add", "a.ts"], root);
342
+ await writeFile(
343
+ path.join(root, "count.mjs"),
344
+ "import fs from 'node:fs'; fs.appendFileSync('calls.out', process.argv.slice(2).join(',') + '\\n');",
345
+ );
346
+ await expect(
347
+ runGate(root, [{ formatCheck: "node count.mjs {files}", lint: "node count.mjs ." }]),
348
+ ).resolves.toStrictEqual({
349
+ code: 0,
350
+ stderr: "",
351
+ stdout: "",
352
+ });
353
+ await expect(readFile(path.join(root, "calls.out"), "utf-8")).resolves.toBe("a.ts\n");
354
+ });
355
+
356
+ it("rejects a rename with uncovered source coverage even when destination file checks are available", async () => {
357
+ const root = await fixture();
358
+ await mkdir(path.join(root, "apps/source"), { recursive: true });
359
+ await mkdir(path.join(root, "apps/destination"), { recursive: true });
360
+ await writeFile(path.join(root, "apps/source/a.ts"), "a");
361
+ await runGit(["add", "apps/source/a.ts"], root);
362
+ await runGit(["commit", "-qm", "seed"], root);
363
+ await runGit(["mv", "apps/source/a.ts", "apps/destination/a.ts"], root);
364
+ const result = await runGate(
365
+ root,
366
+ ["apps/source", "apps/destination"].map((owner) => ({
367
+ execution: { formatCheck: "files", lint: "files" },
368
+ formatCheck: "node ../../marker.mjs {files}",
369
+ lint: "node ../../marker.mjs {files}",
370
+ owner,
371
+ path: owner,
372
+ })),
373
+ );
374
+ expect(result.code).toBe(1);
375
+ expect(result.stderr).toContain("coverage");
376
+ expect(result.stderr).toContain("apps/source/a.ts");
377
+ expect(result.stderr).toContain("hi update");
378
+ });
379
+
380
+ it("passes only present staged names to explicit file commands after deletions and renames", async () => {
381
+ const root = await fixture();
382
+ await Promise.all(
383
+ ["old.ts", "gone.ts"].map(async (file) => {
384
+ await writeFile(path.join(root, file), file);
385
+ }),
386
+ );
387
+ await runGit(["add", "old.ts", "gone.ts"], root);
388
+ await runGit(["commit", "-qm", "seed"], root);
389
+ await runGit(["mv", "old.ts", "new.ts"], root);
390
+ await runGit(["rm", "-q", "gone.ts"], root);
391
+ await writeFile(
392
+ path.join(root, "arguments.mjs"),
393
+ "process.stdout.write(JSON.stringify({ args: process.argv.slice(2), files: process.env.HI_STAGED_FILES }));",
394
+ );
395
+ const result = await runGate(root, [
396
+ {
397
+ execution: { formatCheck: "owner", lint: "files" },
398
+ formatCheck: "true",
399
+ lint: "node arguments.mjs {files}",
400
+ },
401
+ ]);
402
+ expect(result.code).toBe(0);
403
+ expect(result.stderr).toBe("");
404
+ expect(JSON.parse(result.stdout)).toStrictEqual({ args: ["new.ts"], files: "new.ts" });
405
+ });
406
+
93
407
  it("ignores a stale legacy root and runs from the active worktree", async () => {
94
408
  const root = await fixture();
95
409
  await writeFile(path.join(root, "a.ts"), "a");
@@ -247,7 +561,7 @@ describe("Commit Gate runner", () => {
247
561
  const result = await run("node", [runner, "--contracts", ".devpunks/contracts.json"], {
248
562
  cwd: root,
249
563
  });
250
- expect(result.stdout).toBe("");
564
+ expect(result).toStrictEqual({ code: 0, stderr: "", stdout: "" });
251
565
  await expect(readFile(path.join(root, "marker.out"), "utf-8")).rejects.toThrow("ENOENT");
252
566
  });
253
567
 
@@ -255,7 +569,10 @@ describe("Commit Gate runner", () => {
255
569
  const root = await fixture();
256
570
  await writeFile(path.join(root, "a.ts"), "a");
257
571
  await run("git", ["add", "."], { cwd: root });
258
- await writeFile(path.join(root, "fail.mjs"), "process.exit(1);");
572
+ await writeFile(
573
+ path.join(root, "fail.mjs"),
574
+ "process.stdout.write('failure-out\\n'); process.stderr.write('failure-err\\n'); process.exit(7);",
575
+ );
259
576
  await writeFile(
260
577
  path.join(root, ".devpunks/contracts.json"),
261
578
  JSON.stringify([
@@ -266,8 +583,10 @@ describe("Commit Gate runner", () => {
266
583
  cwd: root,
267
584
  });
268
585
  expect(result.code).toBe(1);
269
- expect(result.stderr).toContain("lint");
270
- expect(result.stderr).toContain("format");
586
+ expect(result.stderr).toMatch(/lint.*exit 7.*format.*exit 7/su);
587
+ expect(result.stdout).toBe("");
588
+ expect(result.stderr.match(/failure-out/gu)).toHaveLength(1);
589
+ expect(result.stderr.match(/failure-err/gu)).toHaveLength(1);
271
590
  });
272
591
 
273
592
  it("passes root-relative staged files and excludes deletions", async () => {
@@ -52,6 +52,45 @@ describe("sync-subagents context-plan validator", () => {
52
52
  expect(validateCanonicalContextPlan(plan())).toBeUndefined();
53
53
  });
54
54
 
55
+ it.each(["files", "owner", "repository"])("accepts explicit %s execution", (mode) => {
56
+ const entry = {
57
+ ...contribution,
58
+ contract: { ...contribution.contract, execution: { formatCheck: mode, lint: mode } },
59
+ };
60
+ expect(validateCanonicalContextPlan(plan(entry))).toBeUndefined();
61
+ });
62
+
63
+ it("accepts independent execution modes for each command", () => {
64
+ expect(
65
+ validateCanonicalContextPlan(
66
+ plan({
67
+ ...contribution,
68
+ contract: {
69
+ ...contribution.contract,
70
+ execution: { formatCheck: "files", lint: "repository" },
71
+ },
72
+ }),
73
+ ),
74
+ ).toBeUndefined();
75
+ });
76
+
77
+ it.each([
78
+ ["missing formatCheck mode", { lint: "files" }],
79
+ ["missing lint mode", { formatCheck: "owner" }],
80
+ ["unknown lint mode", { formatCheck: "files", lint: "workspace" }],
81
+ ["unknown formatCheck mode", { formatCheck: "workspace", lint: "files" }],
82
+ ["extra execution key", { extra: "owner", formatCheck: "files", lint: "files" }],
83
+ ["null execution", null],
84
+ ["undefined execution", undefined],
85
+ ["non-object execution", "repository"],
86
+ ])("rejects %s", (_label, execution) => {
87
+ expect(
88
+ validateCanonicalContextPlan(
89
+ plan({ ...contribution, contract: { ...contribution.contract, execution } }),
90
+ ),
91
+ ).toMatch(/contract/iu);
92
+ });
93
+
55
94
  it.each(invalidCases)("rejects %s", (_label, mutate) => {
56
95
  const invalid = mutate(contribution);
57
96
  expect(validateCanonicalContextPlan(plan(invalid))).toMatch(/contract|fields/iu);
@@ -2910,12 +2910,18 @@ const compatibilityIssue = (compatibility) =>
2910
2910
  ? undefined
2911
2911
  : "Context contribution compatibility is invalid";
2912
2912
 
2913
+ const qualityCommandExecutionModes = new Set(["files", "owner", "repository"]);
2914
+
2913
2915
  const commitGateContractIssue = (contract) =>
2914
- exactKeys(contract, ["lint", "formatCheck"]) &&
2916
+ (exactKeys(contract, ["lint", "formatCheck"]) ||
2917
+ (exactKeys(contract, ["lint", "formatCheck", "execution"]) &&
2918
+ exactKeys(contract.execution, ["lint", "formatCheck"]) &&
2919
+ qualityCommandExecutionModes.has(contract.execution.lint) &&
2920
+ qualityCommandExecutionModes.has(contract.execution.formatCheck))) &&
2915
2921
  isNonEmptyString(contract.lint) &&
2916
2922
  isNonEmptyString(contract.formatCheck)
2917
2923
  ? undefined
2918
- : "Commit-gate contract must contain non-empty lint and formatCheck strings";
2924
+ : "Commit-gate contract must contain non-empty lint and formatCheck strings and optional execution with lint and formatCheck modes: files, owner, or repository";
2919
2925
 
2920
2926
  const contributionIssue = (contribution) => {
2921
2927
  const expectedKeys =
@@ -16,7 +16,7 @@ Select when target gates exist and their workflow-owned handoff schema, durable
16
16
  - Keep route suggestions optional, advisory, and lowest authority.
17
17
  - Require every declared completion, blocker, skip or no-op, and human-checkpoint exit to write a durable handoff when applicable.
18
18
  - Require the [human steering terminal](../references/authoring-contract.md#human-steering-terminal)
19
- to preserve the `$handback` outcome and authority guard.
19
+ to preserve the required decision and evidence for resuming.
20
20
 
21
21
  ## Checkable Completion State
22
22
 
@@ -19,7 +19,7 @@ Select when obligations are qualified and the evidence-defined state model, topo
19
19
  - Every state has scope, entry guard, exit guard, and reachable next states.
20
20
  - Every mandatory obligation is reachable and evidence-backed.
21
21
  - Each topology form is represented or marked N/A.
22
- - `human_steering_required` is terminal until the `$handback` authority guard passes.
22
+ - `human_steering_required` preserves the defined terminal and resumption conditions.
23
23
 
24
24
  ## Durable Phase Outcome
25
25
 
@@ -10,7 +10,7 @@ Select when disclosure passes and route predictions, derivations, or mismatch re
10
10
  - Record each predicted route before applying the target contracts.
11
11
  - Derive each route from current evidence, authority, guards, and precedence.
12
12
  - Cover all ten scenarios: baseline path, branch path, repair cycle, planned
13
- human checkpoint, failure handback terminal, cold resume, stale or
13
+ human checkpoint, human steering terminal, cold resume, stale or
14
14
  out-of-scope or invalid artifact, contradictory suggested route losing to
15
15
  evidence, narrower executor substitution with a stable actor-like gate
16
16
  boundary, and premature completion rejected by the terminal guard.
@@ -21,8 +21,8 @@ Select when the target router exists and one or more executable target gates are
21
21
  - Every executable gate has exactly one flat phase file.
22
22
  - Every gate defines the normalized contract and emits only declared exits.
23
23
  - Target root and references contain no executable gate body.
24
- - Every applicable gate invokes `$handback` and emits only the terminal's
25
- durable outcome when its guard selects human steering.
24
+ - Every applicable gate records the terminal outcome and stops when its guard
25
+ selects human steering.
26
26
 
27
27
  ## Durable Phase Outcome
28
28
 
@@ -12,7 +12,7 @@ Select when bounds, state, and authority are complete while the target root boot
12
12
  - Make cold resume independent of transcript continuity.
13
13
  - Return exactly one selected gate, terminal, checkpoint, or blocked outcome for every legal state.
14
14
  - Preserve the [human steering terminal](../references/authoring-contract.md#human-steering-terminal)
15
- until the `$handback` authority guard passes.
15
+ with its defined resumption conditions.
16
16
  - Preserve the target's intentional invocation policy.
17
17
 
18
18
  ## Checkable Completion State
@@ -120,9 +120,9 @@ Completion criterion:
120
120
  ## Human Steering Terminal
121
121
 
122
122
  Every graph includes `human_steering_required` as a terminal, non-success
123
- state. The gate that selects it invokes `$handback`, writes that skill's durable
124
- outcome, and stops. The router keeps returning the terminal until the
125
- `$handback` authority guard passes.
123
+ state for actions beyond accepted scope or unresolved human decisions. The gate
124
+ records the blocker, evidence, proposed action, and required decision, then stops.
125
+ The router keeps returning the terminal until the user authorizes continuation.
126
126
 
127
127
  ## Gate Contract
128
128
 
@@ -194,7 +194,7 @@ Completion criterion:
194
194
  | Branch path | | | | |
195
195
  | Repair cycle | | | | |
196
196
  | Human checkpoint | | | | |
197
- | Failure handback terminal | | | | |
197
+ | Human steering terminal | | | | |
198
198
  | Cold resume | | | | |
199
199
  | Stale, out-of-scope, or invalid artifact | | | | |
200
200
  | Contradictory suggested route loses to evidence | | | | |
@@ -204,8 +204,8 @@ Completion criterion:
204
204
  Completion criterion:
205
205
 
206
206
  - all ten rows are filled with stale, out-of-scope, and invalid as subcases.
207
- - the failure-handback row proves the `human_steering_required` terminal and
208
- `$handback` authority guard; the planned human-checkpoint row remains distinct.
207
+ - the human-steering row proves the terminal and resumption conditions defined
208
+ in [Human Steering Terminal](#human-steering-terminal); the planned human-checkpoint row remains distinct.
209
209
  - repairs are present only when match is No.
210
210
 
211
211
  ## Final Audit
@@ -214,8 +214,8 @@ Completion criterion:
214
214
  - Router and gates are deterministic under the authority table.
215
215
  - Cold resume derives from current evidence, workflow-native artifacts, and committed handoffs.
216
216
  - Every exit commits a durable handoff.
217
- - `human_steering_required` invokes `$handback`, commits its outcome, and keeps
218
- the terminal until that skill's authority guard passes.
217
+ - `human_steering_required` records the outcome and preserves the
218
+ [terminal and resumption conditions](#human-steering-terminal).
219
219
  - Terminal guard accounts for every mandatory obligation.
220
220
  - The skill-protocol boundary is the set of written contracts and durable evidence.
221
221
  - Markdown cannot enforce exclusive writers, execution ordering, or atomic persistence; require an external runtime only when one of those guarantees is a correctness requirement.
@@ -27,7 +27,7 @@ Use when:
27
27
  focused tests for changed code. End this invocation without rerunning the
28
28
  helper. A further direct pass requires formal `$review-phase` or a new
29
29
  explicit user instruction after this result.
30
- - When a finding triggers `$handback`, invoke it before any expanded repair.
30
+ - Report repairs beyond accepted scope with the decision needed before proceeding.
31
31
  - For security-audit suppression changes, verify accepted findings remain auditable: suppressed findings stay in structured output, active output keeps an unsuppressible suppression notice, and aggregate findings cannot hide unrelated active risk.
32
32
  - Never switch or override the requested review engine/model. If the review hits model capacity, retry the same command a few times with the same engine/model.
33
33
  - Be patient with large bundles. Structured review can take up to 30 minutes while the model call is active, especially with Codex tools or web search.
@@ -9,11 +9,11 @@ Build a risk-driven automated software test portfolio. `TSuite` means test suite
9
9
 
10
10
  ## Boundary
11
11
 
12
- Production-reachable content is immutable. Writable scope is limited to automated tests and test-scoped fixtures, harnesses, seeds, artifacts, configuration, and dependencies. Inline tests or shared manifests are writable only where changed regions are mechanically isolated to test compilation or execution. Ambiguous isolation is a blocker requiring handback.
12
+ Production-reachable content is immutable. Writable scope is limited to automated tests and test-scoped fixtures, harnesses, seeds, artifacts, configuration, and dependencies. Inline tests or shared manifests are writable only where changed regions are mechanically isolated to test compilation or execution. Ambiguous isolation is a blocker. Report the uncertainty and required scope decision before editing.
13
13
 
14
14
  Before editing, classify every allowed path or hunk as test-scoped. After editing, inspect the complete source-control diff; completion requires every changed region and dependency to remain unreachable from production behavior, artifacts, and deployable wiring.
15
15
 
16
- Keep a product defect visible as a failing test with observed failure evidence, then hand back a separate production requirement. A test-only task reaches GREEN only through test-scoped changes.
16
+ Keep a product defect visible as a failing test with observed failure evidence, then report a separate production requirement. A test-only task reaches GREEN only through test-scoped changes.
17
17
 
18
18
  ## Modes
19
19