@punks/cli 5.2.0 → 5.2.2
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/README.md +2 -2
- package/dist/BASELINE_CHANGELOG.md +46 -1
- package/dist/CHANGELOG.md +37 -0
- package/dist/baseline/scaffold-baseline/baseline.json +15 -5
- package/dist/baseline/scaffold-baseline/data/catalog/packs.json +2 -0
- package/dist/baseline/scaffold-baseline/data/catalog/skills.json +16 -0
- package/dist/baseline/scaffold-baseline/data/hooks/format-edited-file.mjs +459 -318
- 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 +98 -27
- package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.test.ts +156 -8
- 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 +329 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.test.ts +864 -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/skills/agnostic/cli/hi-cli/SKILL.md +2 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/commands.md +8 -9
- 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 +28 -24
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/wiki-structure.md +16 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/docs/docs-onboarding/SKILL.md +21 -16
- package/dist/baseline/scaffold-baseline/skills/agnostic/docs/docs-onboarding/agents/openai.yaml +1 -1
- package/dist/baseline/scaffold-baseline/skills/agnostic/docs/docs-onboarding/references/artifact-contract.md +16 -4
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-architecture/SKILL.md +65 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-architecture/assets/ARCHITECTURE-TEMPLATE.md +119 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-architecture/references/artifact-contract.md +200 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/SKILL.md +11 -3
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/architecture-convergence.md +19 -4
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/plan-schema.md +17 -3
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/SKILL.md +38 -20
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/assets/SPEC-TEMPLATE.md +11 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/references/readiness.md +40 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/references/spec-quality-bar.md +8 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/SKILL.md +4 -2
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/references/architecture-conformance.md +10 -6
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/references/lifecycle.md +23 -10
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/brainstorm/SKILL.md +22 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/SKILL.md +2 -1
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +3 -2
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/SKILL.md +6 -3
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/plan.md +4 -2
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/review.md +5 -1
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/router.md +15 -9
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/spec.md +13 -26
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/artifact-state.md +39 -1
- package/dist/baseline/scaffold-baseline/skills/phases/requirements-phase/SKILL.md +31 -14
- package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/prepare-review.md +12 -4
- package/dist/baseline/scaffold-baseline.json +5 -5
- package/dist/baseline/scaffold-baseline.tgz +0 -0
- package/dist/data/hooks/format-edited-file.d.mts +5 -0
- package/dist/data/hooks/format-edited-file.mjs +282 -333
- package/dist/data/scripts/commit-gate-runner.mjs +98 -27
- package/dist/data/scripts/managed-lint-runner.d.mts +55 -0
- package/dist/data/scripts/managed-lint-runner.mjs +329 -0
- package/dist/data/scripts/managed-lint.d.mts +97 -0
- package/dist/data/scripts/managed-lint.mjs +658 -0
- package/dist/index.js +86 -1184
- package/dist/skills/agnostic/cli/hi-cli/SKILL.md +2 -0
- package/dist/skills/agnostic/cli/hi-cli/references/commands.md +8 -9
- 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 +15 -11
- package/dist/skills/agnostic/cli/hi-cli/references/wiki-structure.md +16 -0
- package/dist/skills/agnostic/docs/docs-onboarding/SKILL.md +21 -16
- package/dist/skills/agnostic/docs/docs-onboarding/agents/openai.yaml +1 -1
- package/dist/skills/agnostic/docs/docs-onboarding/references/artifact-contract.md +16 -4
- package/dist/skills/agnostic/planning/create-architecture/SKILL.md +65 -0
- package/dist/skills/agnostic/planning/create-architecture/assets/ARCHITECTURE-TEMPLATE.md +119 -0
- package/dist/skills/agnostic/planning/create-architecture/references/artifact-contract.md +200 -0
- package/dist/skills/agnostic/planning/create-plan/SKILL.md +11 -3
- package/dist/skills/agnostic/planning/create-plan/references/architecture-convergence.md +19 -4
- package/dist/skills/agnostic/planning/create-plan/references/plan-schema.md +17 -3
- package/dist/skills/agnostic/planning/create-spec/SKILL.md +38 -20
- package/dist/skills/agnostic/planning/create-spec/assets/SPEC-TEMPLATE.md +11 -0
- package/dist/skills/agnostic/planning/create-spec/references/readiness.md +40 -0
- package/dist/skills/agnostic/planning/create-spec/references/spec-quality-bar.md +8 -0
- package/dist/skills/agnostic/planning/implement-spec/SKILL.md +4 -2
- package/dist/skills/agnostic/planning/implement-spec/references/architecture-conformance.md +10 -6
- package/dist/skills/agnostic/planning/implement-spec/references/lifecycle.md +23 -10
- package/dist/skills/agnostic/requirements/brainstorm/SKILL.md +22 -0
- package/dist/skills/agnostic/requirements/requirements-grill/SKILL.md +2 -1
- package/dist/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +3 -2
- package/dist/skills/phases/delivery-phase/SKILL.md +6 -3
- package/dist/skills/phases/delivery-phase/phases/plan.md +4 -2
- package/dist/skills/phases/delivery-phase/phases/review.md +5 -1
- package/dist/skills/phases/delivery-phase/phases/router.md +15 -9
- package/dist/skills/phases/delivery-phase/phases/spec.md +13 -26
- package/dist/skills/phases/delivery-phase/references/artifact-state.md +39 -1
- package/dist/skills/phases/requirements-phase/SKILL.md +31 -14
- package/dist/skills/phases/review-phase/phases/prepare-review.md +12 -4
- package/package.json +3 -2
|
@@ -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,34 +36,33 @@ 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
|
-
"-z",
|
|
45
|
-
]);
|
|
57
|
+
const { stdout } = await execFile(
|
|
58
|
+
"git",
|
|
59
|
+
["diff", "--cached", "--name-status", "--find-renames", "-z"],
|
|
60
|
+
{},
|
|
61
|
+
);
|
|
46
62
|
const entries = stdout.split("\0").filter(Boolean);
|
|
63
|
+
/** @type {Set<string>} */
|
|
47
64
|
const triggers = new Set();
|
|
65
|
+
/** @type {Set<string>} */
|
|
48
66
|
const files = new Set();
|
|
49
67
|
for (let index = 0; index < entries.length; index += 2) {
|
|
50
68
|
const status = entries[index];
|
|
@@ -65,12 +83,14 @@ const stagedPaths = async () => {
|
|
|
65
83
|
};
|
|
66
84
|
|
|
67
85
|
const activeWorktreeRoot = async () => {
|
|
68
|
-
const { stdout } = await execFile("git", ["rev-parse", "--show-toplevel"]);
|
|
86
|
+
const { stdout } = await execFile("git", ["rev-parse", "--show-toplevel"], {});
|
|
69
87
|
return stdout.replace(/\n$/u, "");
|
|
70
88
|
};
|
|
71
89
|
|
|
90
|
+
/** @param {string} value - A filename passed through an explicit authored shell template. */
|
|
72
91
|
const shellQuote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
73
92
|
|
|
93
|
+
/** @param {string} name - Public command option. */
|
|
74
94
|
const argument = (name) => {
|
|
75
95
|
const index = process.argv.indexOf(name);
|
|
76
96
|
return index === -1 ? null : (process.argv[index + 1] ?? null);
|
|
@@ -83,14 +103,52 @@ if (contractsPath === null) {
|
|
|
83
103
|
} else {
|
|
84
104
|
try {
|
|
85
105
|
const contractsContent = await readFile(contractsPath, "utf-8");
|
|
86
|
-
|
|
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;
|
|
87
112
|
const worktreeRoot = await activeWorktreeRoot();
|
|
88
113
|
const staged = await stagedPaths();
|
|
89
114
|
if (staged.triggers.length === 0) {
|
|
90
115
|
process.exit(0);
|
|
91
116
|
}
|
|
92
117
|
|
|
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
|
+
),
|
|
138
|
+
);
|
|
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[]}>} */
|
|
93
150
|
const commands = new Map();
|
|
151
|
+
/** @type {readonly ("lint" | "formatCheck")[]} */
|
|
94
152
|
const kinds = ["lint", "formatCheck"];
|
|
95
153
|
const repositoryKinds = new Set(
|
|
96
154
|
kinds.filter((kind) =>
|
|
@@ -100,19 +158,32 @@ if (contractsPath === null) {
|
|
|
100
158
|
const covered = new Map(kinds.map((kind) => [kind, new Set()]));
|
|
101
159
|
const coverageFailures = [];
|
|
102
160
|
for (const contract of contracts) {
|
|
103
|
-
const relativePath = contract.path ?? ".";
|
|
161
|
+
const relativePath = path.posix.normalize(contract.path ?? ".");
|
|
104
162
|
const ownerCwd = path.resolve(worktreeRoot, relativePath);
|
|
105
163
|
const owner = contract.owner ?? ownerCwd;
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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")),
|
|
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);
|
|
113
178
|
for (const kind of kinds) {
|
|
114
179
|
const template = contract[kind];
|
|
115
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(" ");
|
|
116
187
|
if (repositoryKinds.has(kind) && mode !== "repository") {
|
|
117
188
|
continue;
|
|
118
189
|
}
|
|
@@ -9,12 +9,64 @@ interface ExecResult {
|
|
|
9
9
|
readonly stderr: string;
|
|
10
10
|
readonly stdout: string;
|
|
11
11
|
}
|
|
12
|
+
const authorSelection = async (root: string, contracts: readonly unknown[]) => {
|
|
13
|
+
const scopes = [
|
|
14
|
+
...new Set([
|
|
15
|
+
".",
|
|
16
|
+
...contracts.map((contract) => {
|
|
17
|
+
if (typeof contract !== "object" || contract === null) {
|
|
18
|
+
throw new Error("Invalid test contract");
|
|
19
|
+
}
|
|
20
|
+
return "path" in contract && typeof contract.path === "string"
|
|
21
|
+
? path.posix.normalize(contract.path)
|
|
22
|
+
: ".";
|
|
23
|
+
}),
|
|
24
|
+
]),
|
|
25
|
+
];
|
|
26
|
+
await mkdir(path.join(root, ".devpunks/specs/lint"), { recursive: true });
|
|
27
|
+
await writeFile(path.join(root, ".devpunks/settings.json"), JSON.stringify({ lint: { scopes } }));
|
|
28
|
+
await Promise.all(
|
|
29
|
+
scopes.map(async (scope) => {
|
|
30
|
+
try {
|
|
31
|
+
await writeFile(path.join(root, scope, "package.json"), "{}");
|
|
32
|
+
} catch {
|
|
33
|
+
/* intentional missing owner */
|
|
34
|
+
}
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
await writeFile(
|
|
38
|
+
path.join(root, ".devpunks/specs/lint/selection.json"),
|
|
39
|
+
JSON.stringify({
|
|
40
|
+
managedLint: {
|
|
41
|
+
exclude: [],
|
|
42
|
+
routes: scopes.map((scope) => ({
|
|
43
|
+
config: path.posix.join(scope, "oxlint.config.ts"),
|
|
44
|
+
inputs: ["shared-policy.json"],
|
|
45
|
+
maxWarnings: 0,
|
|
46
|
+
scope,
|
|
47
|
+
tool: { package: "oxlint", version: "1.80.0" },
|
|
48
|
+
})),
|
|
49
|
+
scopes,
|
|
50
|
+
version: 1,
|
|
51
|
+
},
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
const runner = path.resolve(import.meta.dirname, "commit-gate-runner.mjs");
|
|
12
56
|
const run = async (
|
|
13
57
|
command: string,
|
|
14
58
|
args: readonly string[],
|
|
15
59
|
options: { readonly cwd: string },
|
|
16
60
|
): Promise<ExecResult> => {
|
|
17
|
-
|
|
61
|
+
if (command === "node" && args[0] === runner) {
|
|
62
|
+
const contracts: unknown = JSON.parse(
|
|
63
|
+
await readFile(path.join(options.cwd, ".devpunks/contracts.json"), "utf-8"),
|
|
64
|
+
);
|
|
65
|
+
if (!Array.isArray(contracts)) {
|
|
66
|
+
throw new TypeError("Invalid test contracts");
|
|
67
|
+
}
|
|
68
|
+
await authorSelection(options.cwd, contracts);
|
|
69
|
+
}
|
|
18
70
|
const result = spawnSync(command, args, {
|
|
19
71
|
cwd: options.cwd,
|
|
20
72
|
encoding: "utf-8",
|
|
@@ -33,7 +85,6 @@ const runGit = async (args: readonly string[], cwd: string): Promise<void> => {
|
|
|
33
85
|
throw new Error(`git ${args.join(" ")} failed (${result.code}): ${result.stderr}`);
|
|
34
86
|
}
|
|
35
87
|
};
|
|
36
|
-
const runner = path.resolve(import.meta.dirname, "commit-gate-runner.mjs");
|
|
37
88
|
const roots = new Set<string>();
|
|
38
89
|
const linkedWorktrees = new Map<string, string>();
|
|
39
90
|
const markerScript =
|
|
@@ -86,6 +137,105 @@ describe("Commit Gate runner", () => {
|
|
|
86
137
|
}
|
|
87
138
|
});
|
|
88
139
|
|
|
140
|
+
it.each([false, true])(
|
|
141
|
+
"dispatches root repository lint for child-only changes when root selected=%s",
|
|
142
|
+
async (rootSelected) => {
|
|
143
|
+
const root = await fixture();
|
|
144
|
+
await mkdir(path.join(root, "apps/web/fixtures/demo"), { recursive: true });
|
|
145
|
+
await mkdir(path.join(root, "wiki"));
|
|
146
|
+
await writeFile(path.join(root, "apps/web/source.ts"), "export const source = 1;");
|
|
147
|
+
await writeFile(path.join(root, "apps/web/fixtures/demo/package.json"), "{}");
|
|
148
|
+
await writeFile(path.join(root, "apps/web/fixtures/demo/ignored.ts"), "console.log(1)");
|
|
149
|
+
await writeFile(path.join(root, "wiki/ignored.ts"), "console.log(2)");
|
|
150
|
+
await runGit(["add", "apps", "wiki"], root);
|
|
151
|
+
await authorSelection(root, [{ path: "apps/web" }]);
|
|
152
|
+
if (!rootSelected) {
|
|
153
|
+
await writeFile(
|
|
154
|
+
path.join(root, ".devpunks/settings.json"),
|
|
155
|
+
JSON.stringify({ lint: { scopes: ["apps/web"] } }),
|
|
156
|
+
);
|
|
157
|
+
await writeFile(
|
|
158
|
+
path.join(root, ".devpunks/specs/lint/selection.json"),
|
|
159
|
+
JSON.stringify({
|
|
160
|
+
managedLint: {
|
|
161
|
+
exclude: [],
|
|
162
|
+
routes: [
|
|
163
|
+
{
|
|
164
|
+
config: "apps/web/oxlint.config.ts",
|
|
165
|
+
inputs: [],
|
|
166
|
+
maxWarnings: 0,
|
|
167
|
+
scope: "apps/web",
|
|
168
|
+
tool: { package: "oxlint", version: "1.80.0" },
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
scopes: ["apps/web"],
|
|
172
|
+
version: 1,
|
|
173
|
+
},
|
|
174
|
+
}),
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
await writeFile(
|
|
178
|
+
path.join(root, "record.mjs"),
|
|
179
|
+
'console.log(process.argv[2]+":"+process.env.HI_STAGED_FILES)',
|
|
180
|
+
);
|
|
181
|
+
await writeFile(
|
|
182
|
+
path.join(root, ".devpunks/contracts.json"),
|
|
183
|
+
JSON.stringify([
|
|
184
|
+
{
|
|
185
|
+
execution: { formatCheck: "files", lint: "repository" },
|
|
186
|
+
formatCheck: "exit 91",
|
|
187
|
+
lint: "node record.mjs lint",
|
|
188
|
+
path: ".",
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
execution: { formatCheck: "files", lint: "files" },
|
|
192
|
+
formatCheck: "node ../../record.mjs format {files}",
|
|
193
|
+
lint: "exit 92",
|
|
194
|
+
path: "apps/web",
|
|
195
|
+
},
|
|
196
|
+
]),
|
|
197
|
+
);
|
|
198
|
+
const result = spawnSync("node", [runner, "--contracts", ".devpunks/contracts.json"], {
|
|
199
|
+
cwd: root,
|
|
200
|
+
encoding: "utf-8",
|
|
201
|
+
});
|
|
202
|
+
expect({ code: result.status, stderr: result.stderr, stdout: result.stdout }).toStrictEqual({
|
|
203
|
+
code: 0,
|
|
204
|
+
stderr: "",
|
|
205
|
+
stdout: "lint:apps/web/source.ts\nformat:source.ts\n",
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
it("skips wiki-only staging before command coverage and execution", async () => {
|
|
211
|
+
const root = await fixture();
|
|
212
|
+
await mkdir(path.join(root, "wiki"));
|
|
213
|
+
await writeFile(path.join(root, "wiki/page.ts"), "export const wiki = true;");
|
|
214
|
+
await runGit(["add", "wiki/page.ts"], root);
|
|
215
|
+
const result = await runGate(root, [{ formatCheck: "exit 19", lint: "exit 19" }]);
|
|
216
|
+
expect(result.code).toBe(0);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("fans shared policy edits out to dependent owners using readonly check commands", async () => {
|
|
220
|
+
const root = await fixture();
|
|
221
|
+
await mkdir(path.join(root, "apps/web"), { recursive: true });
|
|
222
|
+
await writeFile(path.join(root, "apps/web/source.ts"), "export const web=1;");
|
|
223
|
+
await writeFile(path.join(root, "shared-policy.json"), "{}");
|
|
224
|
+
await runGit(["add", "shared-policy.json"], root);
|
|
225
|
+
const result = await runGate(root, [
|
|
226
|
+
{
|
|
227
|
+
execution: { formatCheck: "files", lint: "files" },
|
|
228
|
+
formatCheck: "node ../../marker.mjs {files}",
|
|
229
|
+
lint: "node ../../marker.mjs {files}",
|
|
230
|
+
path: "apps/web",
|
|
231
|
+
},
|
|
232
|
+
]);
|
|
233
|
+
expect(result.code).toBe(0);
|
|
234
|
+
await expect(readFile(path.join(root, "apps/web/marker.out"), "utf-8")).resolves.toContain(
|
|
235
|
+
"source.ts",
|
|
236
|
+
);
|
|
237
|
+
});
|
|
238
|
+
|
|
89
239
|
it("preserves successful output once on its original streams in contract and command order", async () => {
|
|
90
240
|
const root = await fixture();
|
|
91
241
|
await writeFile(path.join(root, "a.ts"), "a");
|
|
@@ -186,7 +336,7 @@ describe("Commit Gate runner", () => {
|
|
|
186
336
|
.split("\n")
|
|
187
337
|
.map((line): unknown => JSON.parse(line)),
|
|
188
338
|
).toStrictEqual(
|
|
189
|
-
owners.slice(
|
|
339
|
+
owners.slice(1, change === "rename" ? 3 : 2).flatMap((owner) =>
|
|
190
340
|
["lint", "format"].map((kind) => ({
|
|
191
341
|
args: [`${owner}-${kind}`, "."],
|
|
192
342
|
files: owner === "apps/destination" ? "new.ts" : "",
|
|
@@ -302,10 +452,9 @@ describe("Commit Gate runner", () => {
|
|
|
302
452
|
).resolves.toStrictEqual({
|
|
303
453
|
code: 0,
|
|
304
454
|
stderr: "",
|
|
305
|
-
stdout: "first:
|
|
455
|
+
stdout: "first:a.ts\n",
|
|
306
456
|
});
|
|
307
|
-
|
|
308
|
-
expect(calls.trim().split("\n").toSorted()).toStrictEqual(["first", "second"]);
|
|
457
|
+
await expect(readFile(path.join(root, "calls.out"), "utf-8")).rejects.toThrow("ENOENT");
|
|
309
458
|
await expect(readFile(path.join(root, "apps/web/calls.out"), "utf-8")).resolves.toBe("first\n");
|
|
310
459
|
});
|
|
311
460
|
|
|
@@ -541,8 +690,7 @@ describe("Commit Gate runner", () => {
|
|
|
541
690
|
expect(result.code).toBe(1);
|
|
542
691
|
expect(result.stderr).toContain("missing-owner");
|
|
543
692
|
expect(result.stderr).toContain("lint");
|
|
544
|
-
expect(result.stderr).toContain(
|
|
545
|
-
expect(result.stderr).toMatch(/ENOENT|no such file/u);
|
|
693
|
+
expect(result.stderr).toContain("Selected owner is missing");
|
|
546
694
|
});
|
|
547
695
|
|
|
548
696
|
it("does not spawn quality commands when no files are staged", async () => {
|
|
@@ -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>;
|