@punks/cli 5.1.1 → 5.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +28 -10
- package/dist/BASELINE_CHANGELOG.md +19 -1
- package/dist/CHANGELOG.md +49 -0
- package/dist/baseline/scaffold-baseline/baseline.json +5 -10
- package/dist/baseline/scaffold-baseline/data/catalog/packs.json +1 -1
- package/dist/baseline/scaffold-baseline/data/catalog/skills.json +0 -8
- package/dist/baseline/scaffold-baseline/data/hooks/format-edited-file.mjs +408 -309
- package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.d.ts +1 -0
- package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.mjs +206 -58
- package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.test.ts +496 -29
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.d.mts +55 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.mjs +323 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.test.ts +821 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.d.mts +97 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.mjs +658 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.test.ts +614 -0
- package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents-validator.test.ts +39 -0
- package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents.mjs +8 -2
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/SKILL.md +2 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/commands.md +6 -7
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/managed-lint.md +165 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/post-command-flow.md +20 -19
- package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/phases/define-handoffs.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/phases/model-state.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/phases/test-routes.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/phases/write-phases.md +2 -2
- package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/phases/write-router.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/references/authoring-contract.md +8 -8
- package/dist/baseline/scaffold-baseline/skills/agnostic/quality/autoreview/SKILL.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/agnostic/quality/make-tsuite/SKILL.md +2 -2
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/brainstorm/SKILL.md +21 -11
- package/dist/baseline/scaffold-baseline/skills/phases/debugging-phase/SKILL.md +3 -4
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/SKILL.md +2 -2
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/debug.md +2 -2
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/human-steering.md +25 -0
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/implement.md +2 -2
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/review.md +2 -2
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/router.md +3 -2
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/context-continuity.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/failure-continuity.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/phase-handoff.md +4 -3
- package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/AUTHORING-HANDOFF.md +9 -9
- package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/SKILL.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/ensure-fog.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/grilling.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/human-steering.md +25 -0
- package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/prototype.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/reconcile.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/research.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/router.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/references/state-graph.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/return-route.md +6 -5
- package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/router.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/run-review.md +2 -1
- package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/state-graph.md +3 -3
- package/dist/baseline/scaffold-baseline.json +5 -5
- package/dist/baseline/scaffold-baseline.tgz +0 -0
- package/dist/data/AGENTS.md +22 -5
- package/dist/data/hooks/format-edited-file.mjs +237 -325
- package/dist/data/scripts/commit-gate-runner.mjs +206 -58
- package/dist/data/scripts/managed-lint-runner.d.mts +55 -0
- package/dist/data/scripts/managed-lint-runner.mjs +323 -0
- package/dist/data/scripts/managed-lint.d.mts +97 -0
- package/dist/data/scripts/managed-lint.mjs +658 -0
- package/dist/data/scripts/sync-subagents.mjs +8 -2
- package/dist/index.js +131 -153
- package/dist/skills/agnostic/cli/hi-cli/SKILL.md +2 -0
- package/dist/skills/agnostic/cli/hi-cli/references/commands.md +6 -7
- package/dist/skills/agnostic/cli/hi-cli/references/managed-lint.md +165 -0
- package/dist/skills/agnostic/cli/hi-cli/references/post-command-flow.md +6 -5
- package/dist/skills/agnostic/docs/write-graph-based-skills/phases/define-handoffs.md +1 -1
- package/dist/skills/agnostic/docs/write-graph-based-skills/phases/model-state.md +1 -1
- package/dist/skills/agnostic/docs/write-graph-based-skills/phases/test-routes.md +1 -1
- package/dist/skills/agnostic/docs/write-graph-based-skills/phases/write-phases.md +2 -2
- package/dist/skills/agnostic/docs/write-graph-based-skills/phases/write-router.md +1 -1
- package/dist/skills/agnostic/docs/write-graph-based-skills/references/authoring-contract.md +8 -8
- package/dist/skills/agnostic/quality/autoreview/SKILL.md +1 -1
- package/dist/skills/agnostic/quality/make-tsuite/SKILL.md +2 -2
- package/dist/skills/agnostic/requirements/brainstorm/SKILL.md +21 -11
- package/dist/skills/phases/debugging-phase/SKILL.md +3 -4
- package/dist/skills/phases/delivery-phase/SKILL.md +2 -2
- package/dist/skills/phases/delivery-phase/phases/debug.md +2 -2
- package/dist/skills/phases/delivery-phase/phases/human-steering.md +25 -0
- package/dist/skills/phases/delivery-phase/phases/implement.md +2 -2
- package/dist/skills/phases/delivery-phase/phases/review.md +2 -2
- package/dist/skills/phases/delivery-phase/phases/router.md +3 -2
- package/dist/skills/phases/delivery-phase/references/context-continuity.md +1 -1
- package/dist/skills/phases/delivery-phase/references/failure-continuity.md +1 -1
- package/dist/skills/phases/delivery-phase/references/phase-handoff.md +4 -3
- package/dist/skills/phases/finder-phase/AUTHORING-HANDOFF.md +6 -6
- package/dist/skills/phases/finder-phase/SKILL.md +1 -1
- package/dist/skills/phases/finder-phase/phases/ensure-fog.md +1 -1
- package/dist/skills/phases/finder-phase/phases/grilling.md +1 -1
- package/dist/skills/phases/finder-phase/phases/human-steering.md +25 -0
- package/dist/skills/phases/finder-phase/phases/prototype.md +1 -1
- package/dist/skills/phases/finder-phase/phases/reconcile.md +1 -1
- package/dist/skills/phases/finder-phase/phases/research.md +1 -1
- package/dist/skills/phases/finder-phase/phases/router.md +1 -1
- package/dist/skills/phases/finder-phase/references/state-graph.md +1 -1
- package/dist/skills/phases/review-phase/phases/return-route.md +6 -5
- package/dist/skills/phases/review-phase/phases/router.md +1 -1
- package/dist/skills/phases/review-phase/phases/run-review.md +2 -1
- package/dist/skills/phases/review-phase/references/state-graph.md +3 -3
- package/package.json +12 -6
- package/dist/baseline/scaffold-baseline/skills/agnostic/generic/handback/SKILL.md +0 -27
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/handback.md +0 -27
- package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/handback.md +0 -29
- package/dist/skills/agnostic/generic/handback/SKILL.md +0 -27
- package/dist/skills/phases/delivery-phase/phases/handback.md +0 -27
- package/dist/skills/phases/finder-phase/phases/handback.md +0 -29
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
|
|
3
4
|
import { execFile as execFileCallback } from "node:child_process";
|
|
4
5
|
import { readFile } from "node:fs/promises";
|
|
@@ -6,7 +7,25 @@ import process from "node:process";
|
|
|
6
7
|
import path from "node:path";
|
|
7
8
|
import { promisify } from "node:util";
|
|
8
9
|
|
|
10
|
+
import { loadManagedLint } from "./managed-lint-runner.mjs";
|
|
11
|
+
|
|
9
12
|
const execFile = promisify(execFileCallback);
|
|
13
|
+
/** @param {unknown} value - Untrusted decoded input. @returns {value is Record<string, unknown>} */
|
|
14
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15
|
+
/** @param {unknown} value - Decoded generated contract. @returns {value is import("./commit-gate-runner.d.ts").CommitGateRunnerContract} */
|
|
16
|
+
const isContract = (value) =>
|
|
17
|
+
isRecord(value) &&
|
|
18
|
+
typeof value.lint === "string" &&
|
|
19
|
+
typeof value.formatCheck === "string" &&
|
|
20
|
+
["owner", "path", "root"].every(
|
|
21
|
+
(key) => value[key] === undefined || typeof value[key] === "string",
|
|
22
|
+
) &&
|
|
23
|
+
(value.execution === undefined ||
|
|
24
|
+
(isRecord(value.execution) &&
|
|
25
|
+
["lint", "formatCheck"].every(
|
|
26
|
+
(key) => value.execution[key] === undefined || typeof value.execution[key] === "string",
|
|
27
|
+
)));
|
|
28
|
+
/** @param {string} command - Authored check command. @param {string} cwd - Selected owner. @param {NodeJS.ProcessEnv} environment - Staged inputs. */
|
|
10
29
|
|
|
11
30
|
const run = async (command, cwd, environment) => {
|
|
12
31
|
try {
|
|
@@ -17,42 +36,61 @@ const run = async (command, cwd, environment) => {
|
|
|
17
36
|
});
|
|
18
37
|
return { code: 0, launchError: "", stderr: result.stderr, stdout: result.stdout };
|
|
19
38
|
} catch (error) {
|
|
39
|
+
/** @type {unknown} */
|
|
40
|
+
const failure = error;
|
|
41
|
+
const details = isRecord(failure) ? failure : {};
|
|
42
|
+
const message = failure instanceof Error ? failure.message : String(failure);
|
|
20
43
|
const launchError =
|
|
21
|
-
typeof
|
|
44
|
+
typeof details.code === "number"
|
|
22
45
|
? ""
|
|
23
|
-
:
|
|
24
|
-
typeof error.code === "string" ? error.code : "",
|
|
25
|
-
error instanceof Error ? error.message : String(error),
|
|
26
|
-
]
|
|
27
|
-
.filter(Boolean)
|
|
28
|
-
.join(": ");
|
|
46
|
+
: `${typeof details.code === "string" ? details.code : ""}: ${message}`;
|
|
29
47
|
return {
|
|
30
|
-
code: typeof
|
|
48
|
+
code: typeof details.code === "number" ? details.code : 1,
|
|
31
49
|
launchError,
|
|
32
|
-
stderr:
|
|
33
|
-
stdout:
|
|
50
|
+
stderr: typeof details.stderr === "string" ? details.stderr : "",
|
|
51
|
+
stdout: typeof details.stdout === "string" ? details.stdout : "",
|
|
34
52
|
};
|
|
35
53
|
}
|
|
36
54
|
};
|
|
37
55
|
|
|
38
56
|
const stagedPaths = async () => {
|
|
39
|
-
const { stdout } = await execFile(
|
|
40
|
-
"
|
|
41
|
-
"--cached",
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
const { stdout } = await execFile(
|
|
58
|
+
"git",
|
|
59
|
+
["diff", "--cached", "--name-status", "--find-renames", "-z"],
|
|
60
|
+
{},
|
|
61
|
+
);
|
|
62
|
+
const entries = stdout.split("\0").filter(Boolean);
|
|
63
|
+
/** @type {Set<string>} */
|
|
64
|
+
const triggers = new Set();
|
|
65
|
+
/** @type {Set<string>} */
|
|
66
|
+
const files = new Set();
|
|
67
|
+
for (let index = 0; index < entries.length; index += 2) {
|
|
68
|
+
const status = entries[index];
|
|
69
|
+
let file = entries[index + 1];
|
|
70
|
+
if (status.startsWith("R") || status.startsWith("C")) {
|
|
71
|
+
if (status.startsWith("R")) {
|
|
72
|
+
triggers.add(file);
|
|
73
|
+
}
|
|
74
|
+
index += 1;
|
|
75
|
+
file = entries[index + 1];
|
|
76
|
+
}
|
|
77
|
+
triggers.add(file);
|
|
78
|
+
if (status !== "D") {
|
|
79
|
+
files.add(file);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return { files: [...files], triggers: [...triggers] };
|
|
47
83
|
};
|
|
48
84
|
|
|
49
85
|
const activeWorktreeRoot = async () => {
|
|
50
|
-
const { stdout } = await execFile("git", ["rev-parse", "--show-toplevel"]);
|
|
86
|
+
const { stdout } = await execFile("git", ["rev-parse", "--show-toplevel"], {});
|
|
51
87
|
return stdout.replace(/\n$/u, "");
|
|
52
88
|
};
|
|
53
89
|
|
|
90
|
+
/** @param {string} value - A filename passed through an explicit authored shell template. */
|
|
54
91
|
const shellQuote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
55
92
|
|
|
93
|
+
/** @param {string} name - Public command option. */
|
|
56
94
|
const argument = (name) => {
|
|
57
95
|
const index = process.argv.indexOf(name);
|
|
58
96
|
return index === -1 ? null : (process.argv[index + 1] ?? null);
|
|
@@ -65,53 +103,163 @@ if (contractsPath === null) {
|
|
|
65
103
|
} else {
|
|
66
104
|
try {
|
|
67
105
|
const contractsContent = await readFile(contractsPath, "utf-8");
|
|
68
|
-
|
|
106
|
+
/** @type {unknown} */
|
|
107
|
+
const decodedContracts = JSON.parse(contractsContent);
|
|
108
|
+
if (!Array.isArray(decodedContracts) || !decodedContracts.every(isContract)) {
|
|
109
|
+
throw new Error("Commit Gate contracts must contain explicit lint and formatCheck commands.");
|
|
110
|
+
}
|
|
111
|
+
const contracts = decodedContracts;
|
|
69
112
|
const worktreeRoot = await activeWorktreeRoot();
|
|
70
113
|
const staged = await stagedPaths();
|
|
71
|
-
if (staged.length === 0) {
|
|
114
|
+
if (staged.triggers.length === 0) {
|
|
72
115
|
process.exit(0);
|
|
73
116
|
}
|
|
74
117
|
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
}),
|
|
118
|
+
const resolution = await loadManagedLint(worktreeRoot, staged.triggers);
|
|
119
|
+
if (resolution.status === "disabled") {
|
|
120
|
+
process.exit(0);
|
|
121
|
+
}
|
|
122
|
+
if (resolution.status !== "ready") {
|
|
123
|
+
throw new Error(resolution.diagnostics.join("\n"));
|
|
124
|
+
}
|
|
125
|
+
const routes = new Map(resolution.routes.map((route) => [route.scope, route]));
|
|
126
|
+
const eligible = new Set(resolution.routes.flatMap((route) => route.files));
|
|
127
|
+
staged.triggers = staged.triggers.filter(
|
|
128
|
+
(file) =>
|
|
129
|
+
eligible.has(file) ||
|
|
130
|
+
resolution.routes.some(
|
|
131
|
+
(route) =>
|
|
132
|
+
route.triggered &&
|
|
133
|
+
(route.inputs.includes(file) ||
|
|
134
|
+
route.config === file ||
|
|
135
|
+
file === ".devpunks/settings.json" ||
|
|
136
|
+
file === ".devpunks/specs/lint/selection.json"),
|
|
137
|
+
),
|
|
106
138
|
);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
139
|
+
staged.files = staged.files.filter((file) => eligible.has(file));
|
|
140
|
+
if (staged.triggers.length === 0) {
|
|
141
|
+
process.exit(0);
|
|
142
|
+
}
|
|
143
|
+
const complete = resolution.routes.some((route) => route.triggered)
|
|
144
|
+
? await loadManagedLint(worktreeRoot)
|
|
145
|
+
: resolution;
|
|
146
|
+
if (complete.status !== "ready") {
|
|
147
|
+
throw new Error(complete.diagnostics.join("\n"));
|
|
148
|
+
}
|
|
149
|
+
/** @type {Map<string, {checks: {kind: string, owner: string}[], command: string, cwd: string, files: string[]}>} */
|
|
150
|
+
const commands = new Map();
|
|
151
|
+
/** @type {readonly ("lint" | "formatCheck")[]} */
|
|
152
|
+
const kinds = ["lint", "formatCheck"];
|
|
153
|
+
const repositoryKinds = new Set(
|
|
154
|
+
kinds.filter((kind) =>
|
|
155
|
+
contracts.some((contract) => contract.execution?.[kind] === "repository"),
|
|
156
|
+
),
|
|
157
|
+
);
|
|
158
|
+
const covered = new Map(kinds.map((kind) => [kind, new Set()]));
|
|
159
|
+
const coverageFailures = [];
|
|
160
|
+
for (const contract of contracts) {
|
|
161
|
+
const relativePath = path.posix.normalize(contract.path ?? ".");
|
|
162
|
+
const ownerCwd = path.resolve(worktreeRoot, relativePath);
|
|
163
|
+
const owner = contract.owner ?? ownerCwd;
|
|
164
|
+
const route = routes.get(relativePath);
|
|
165
|
+
const ownerTriggers = staged.triggers.filter(
|
|
166
|
+
(file) =>
|
|
167
|
+
(route?.files.includes(file) ?? false) ||
|
|
168
|
+
(route?.triggered === true &&
|
|
169
|
+
(route.inputs.includes(file) ||
|
|
170
|
+
route.config === file ||
|
|
171
|
+
file === ".devpunks/settings.json" ||
|
|
172
|
+
file === ".devpunks/specs/lint/selection.json")),
|
|
112
173
|
);
|
|
174
|
+
const ownerFiles =
|
|
175
|
+
route?.triggered === true
|
|
176
|
+
? (complete.routes.find((item) => item.scope === relativePath)?.files ?? [])
|
|
177
|
+
: staged.files.filter((file) => route?.files.includes(file) ?? false);
|
|
178
|
+
for (const kind of kinds) {
|
|
179
|
+
const template = contract[kind];
|
|
180
|
+
const mode = contract.execution?.[kind];
|
|
181
|
+
const triggers = mode === "repository" ? staged.triggers : ownerTriggers;
|
|
182
|
+
const routedFiles = mode === "repository" ? staged.files : ownerFiles;
|
|
183
|
+
const files = routedFiles.map((file) =>
|
|
184
|
+
path.relative(ownerCwd, path.resolve(worktreeRoot, file)).split(path.sep).join("/"),
|
|
185
|
+
);
|
|
186
|
+
const fileArguments = files.map(shellQuote).join(" ");
|
|
187
|
+
if (repositoryKinds.has(kind) && mode !== "repository") {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (triggers.length === 0 && mode !== "repository") {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (contract.execution !== undefined && !["files", "owner", "repository"].includes(mode)) {
|
|
194
|
+
coverageFailures.push(
|
|
195
|
+
`${kind} for ${owner} requires an execution mode of files, owner, or repository`,
|
|
196
|
+
);
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (mode === "files" && !template.includes("{files}")) {
|
|
200
|
+
coverageFailures.push(
|
|
201
|
+
`${kind} for ${owner} in files mode requires an explicit {files} placeholder`,
|
|
202
|
+
);
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if ((mode === undefined || mode === "files") && files.length === 0) {
|
|
206
|
+
coverageFailures.push(
|
|
207
|
+
`${kind} for ${owner} needs existing staged files: ${triggers.join(", ")}`,
|
|
208
|
+
);
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
let command = template;
|
|
212
|
+
if (mode === "files") {
|
|
213
|
+
command = template.replaceAll("{files}", fileArguments);
|
|
214
|
+
} else if (mode === undefined) {
|
|
215
|
+
const scopedTemplate = template.replace(/(?<prefix>^|\s)\.\s*$/u, "$<prefix>{files}");
|
|
216
|
+
command = scopedTemplate.includes("{files}")
|
|
217
|
+
? scopedTemplate.replaceAll("{files}", fileArguments)
|
|
218
|
+
: `${scopedTemplate} -- ${fileArguments}`;
|
|
219
|
+
}
|
|
220
|
+
for (const file of mode === "repository" ? staged.triggers : triggers) {
|
|
221
|
+
covered.get(kind).add(file);
|
|
222
|
+
}
|
|
223
|
+
const key = JSON.stringify([ownerCwd, command, files]);
|
|
224
|
+
const existing = commands.get(key);
|
|
225
|
+
if (existing === undefined) {
|
|
226
|
+
commands.set(key, { checks: [{ kind, owner }], command, cwd: ownerCwd, files });
|
|
227
|
+
} else {
|
|
228
|
+
existing.checks.push({ kind, owner });
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
for (const kind of kinds) {
|
|
233
|
+
const uncovered = staged.triggers.filter((file) => !covered.get(kind).has(file));
|
|
234
|
+
if (uncovered.length > 0) {
|
|
235
|
+
coverageFailures.push(`${kind} has no command for: ${uncovered.join(", ")}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (coverageFailures.length > 0) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
`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.`,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
const results = await Promise.all(
|
|
244
|
+
[...commands.values()].map(async (command) => ({
|
|
245
|
+
...command,
|
|
246
|
+
...(await run(command.command, command.cwd, { HI_STAGED_FILES: command.files.join("\n") })),
|
|
247
|
+
})),
|
|
248
|
+
);
|
|
249
|
+
for (const result of results) {
|
|
250
|
+
if (result.code === 0) {
|
|
251
|
+
process.stdout.write(result.stdout);
|
|
252
|
+
process.stderr.write(result.stderr);
|
|
253
|
+
} else {
|
|
254
|
+
for (const check of result.checks) {
|
|
255
|
+
process.stderr.write(
|
|
256
|
+
`Commit Gate ${check.kind} failed for ${check.owner} in ${result.cwd} (exit ${result.code})${result.launchError === "" ? "" : `: ${result.launchError}`}.\n`,
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
process.stderr.write(`${result.stdout}${result.stderr}`);
|
|
260
|
+
}
|
|
113
261
|
}
|
|
114
|
-
process.exitCode =
|
|
262
|
+
process.exitCode = results.some((result) => result.code !== 0) ? 1 : 0;
|
|
115
263
|
} catch (error) {
|
|
116
264
|
console.error(error instanceof Error ? error.message : String(error));
|
|
117
265
|
process.exitCode = 1;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ManagedLintResolution, ManagedLintCommand } from "./managed-lint.mjs";
|
|
2
|
+
import type { SpawnSyncReturns } from "node:child_process";
|
|
3
|
+
|
|
4
|
+
export interface ManagedLintRunOptions {
|
|
5
|
+
readonly root: string;
|
|
6
|
+
readonly scope?: string | undefined;
|
|
7
|
+
readonly paths?: readonly string[] | undefined;
|
|
8
|
+
readonly output?: "human" | "json" | undefined;
|
|
9
|
+
}
|
|
10
|
+
export interface ManagedLintDiagnostic {
|
|
11
|
+
readonly message: string;
|
|
12
|
+
readonly filename?: string;
|
|
13
|
+
readonly code?: string;
|
|
14
|
+
readonly severity?: string;
|
|
15
|
+
readonly [key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
export type ReadyManagedLintCommand = Extract<ManagedLintCommand, { readonly status: "ready" }>;
|
|
18
|
+
export interface ManagedLintExecutionOptions {
|
|
19
|
+
readonly root: string;
|
|
20
|
+
/** A resolver-produced command, optionally with --fix for a controlled mirror. */
|
|
21
|
+
readonly command: ReadyManagedLintCommand;
|
|
22
|
+
readonly output?: "human" | "json";
|
|
23
|
+
}
|
|
24
|
+
/** Execute and classify one local command using the same rules as root/package runs. */
|
|
25
|
+
export function executeManagedLintCommand(
|
|
26
|
+
options: ManagedLintExecutionOptions,
|
|
27
|
+
): ManagedLintExecution;
|
|
28
|
+
export interface ManagedLintExecution extends Readonly<
|
|
29
|
+
Pick<SpawnSyncReturns<string>, "status" | "signal" | "error">
|
|
30
|
+
> {
|
|
31
|
+
/** Normalized classification; native process evidence remains in status/signal/error. */
|
|
32
|
+
readonly code: 0 | 1 | 2;
|
|
33
|
+
readonly command: ReadyManagedLintCommand;
|
|
34
|
+
readonly scope: string;
|
|
35
|
+
readonly stdout: string;
|
|
36
|
+
readonly stderr: string;
|
|
37
|
+
readonly diagnostics?: readonly ManagedLintDiagnostic[];
|
|
38
|
+
readonly failure?: {
|
|
39
|
+
readonly kind: "config-load" | "process" | "malformed-output";
|
|
40
|
+
readonly phase: "config" | "lint";
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface ManagedLintRunResult {
|
|
44
|
+
readonly code: 0 | 1 | 2;
|
|
45
|
+
readonly status: "clean" | "findings" | "operational-failure" | "conflict" | "selection-needed";
|
|
46
|
+
readonly diagnostics?: readonly string[];
|
|
47
|
+
readonly results?: readonly ManagedLintExecution[];
|
|
48
|
+
}
|
|
49
|
+
export function loadManagedLint(
|
|
50
|
+
root: string,
|
|
51
|
+
paths?: readonly string[],
|
|
52
|
+
scope?: string,
|
|
53
|
+
): Promise<ManagedLintResolution>;
|
|
54
|
+
export function managedLintEnvironment(root: string, cwd: string): NodeJS.ProcessEnv;
|
|
55
|
+
export function runManagedLint(options: ManagedLintRunOptions): Promise<ManagedLintRunResult>;
|