@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.
Files changed (91) hide show
  1. package/README.md +2 -2
  2. package/dist/BASELINE_CHANGELOG.md +46 -1
  3. package/dist/CHANGELOG.md +37 -0
  4. package/dist/baseline/scaffold-baseline/baseline.json +15 -5
  5. package/dist/baseline/scaffold-baseline/data/catalog/packs.json +2 -0
  6. package/dist/baseline/scaffold-baseline/data/catalog/skills.json +16 -0
  7. package/dist/baseline/scaffold-baseline/data/hooks/format-edited-file.mjs +459 -318
  8. package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.d.ts +1 -0
  9. package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.mjs +98 -27
  10. package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.test.ts +156 -8
  11. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.d.mts +55 -0
  12. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.mjs +329 -0
  13. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.test.ts +864 -0
  14. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.d.mts +97 -0
  15. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.mjs +658 -0
  16. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.test.ts +614 -0
  17. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/SKILL.md +2 -0
  18. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/commands.md +8 -9
  19. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/managed-lint.md +165 -0
  20. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/post-command-flow.md +28 -24
  21. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/wiki-structure.md +16 -0
  22. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/docs-onboarding/SKILL.md +21 -16
  23. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/docs-onboarding/agents/openai.yaml +1 -1
  24. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/docs-onboarding/references/artifact-contract.md +16 -4
  25. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-architecture/SKILL.md +65 -0
  26. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-architecture/assets/ARCHITECTURE-TEMPLATE.md +119 -0
  27. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-architecture/references/artifact-contract.md +200 -0
  28. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/SKILL.md +11 -3
  29. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/architecture-convergence.md +19 -4
  30. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/plan-schema.md +17 -3
  31. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/SKILL.md +38 -20
  32. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/assets/SPEC-TEMPLATE.md +11 -0
  33. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/references/readiness.md +40 -0
  34. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/references/spec-quality-bar.md +8 -0
  35. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/SKILL.md +4 -2
  36. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/references/architecture-conformance.md +10 -6
  37. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/references/lifecycle.md +23 -10
  38. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/brainstorm/SKILL.md +22 -0
  39. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/SKILL.md +2 -1
  40. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +3 -2
  41. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/SKILL.md +6 -3
  42. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/plan.md +4 -2
  43. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/review.md +5 -1
  44. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/router.md +15 -9
  45. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/spec.md +13 -26
  46. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/artifact-state.md +39 -1
  47. package/dist/baseline/scaffold-baseline/skills/phases/requirements-phase/SKILL.md +31 -14
  48. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/prepare-review.md +12 -4
  49. package/dist/baseline/scaffold-baseline.json +5 -5
  50. package/dist/baseline/scaffold-baseline.tgz +0 -0
  51. package/dist/data/hooks/format-edited-file.d.mts +5 -0
  52. package/dist/data/hooks/format-edited-file.mjs +282 -333
  53. package/dist/data/scripts/commit-gate-runner.mjs +98 -27
  54. package/dist/data/scripts/managed-lint-runner.d.mts +55 -0
  55. package/dist/data/scripts/managed-lint-runner.mjs +329 -0
  56. package/dist/data/scripts/managed-lint.d.mts +97 -0
  57. package/dist/data/scripts/managed-lint.mjs +658 -0
  58. package/dist/index.js +86 -1184
  59. package/dist/skills/agnostic/cli/hi-cli/SKILL.md +2 -0
  60. package/dist/skills/agnostic/cli/hi-cli/references/commands.md +8 -9
  61. package/dist/skills/agnostic/cli/hi-cli/references/managed-lint.md +165 -0
  62. package/dist/skills/agnostic/cli/hi-cli/references/post-command-flow.md +15 -11
  63. package/dist/skills/agnostic/cli/hi-cli/references/wiki-structure.md +16 -0
  64. package/dist/skills/agnostic/docs/docs-onboarding/SKILL.md +21 -16
  65. package/dist/skills/agnostic/docs/docs-onboarding/agents/openai.yaml +1 -1
  66. package/dist/skills/agnostic/docs/docs-onboarding/references/artifact-contract.md +16 -4
  67. package/dist/skills/agnostic/planning/create-architecture/SKILL.md +65 -0
  68. package/dist/skills/agnostic/planning/create-architecture/assets/ARCHITECTURE-TEMPLATE.md +119 -0
  69. package/dist/skills/agnostic/planning/create-architecture/references/artifact-contract.md +200 -0
  70. package/dist/skills/agnostic/planning/create-plan/SKILL.md +11 -3
  71. package/dist/skills/agnostic/planning/create-plan/references/architecture-convergence.md +19 -4
  72. package/dist/skills/agnostic/planning/create-plan/references/plan-schema.md +17 -3
  73. package/dist/skills/agnostic/planning/create-spec/SKILL.md +38 -20
  74. package/dist/skills/agnostic/planning/create-spec/assets/SPEC-TEMPLATE.md +11 -0
  75. package/dist/skills/agnostic/planning/create-spec/references/readiness.md +40 -0
  76. package/dist/skills/agnostic/planning/create-spec/references/spec-quality-bar.md +8 -0
  77. package/dist/skills/agnostic/planning/implement-spec/SKILL.md +4 -2
  78. package/dist/skills/agnostic/planning/implement-spec/references/architecture-conformance.md +10 -6
  79. package/dist/skills/agnostic/planning/implement-spec/references/lifecycle.md +23 -10
  80. package/dist/skills/agnostic/requirements/brainstorm/SKILL.md +22 -0
  81. package/dist/skills/agnostic/requirements/requirements-grill/SKILL.md +2 -1
  82. package/dist/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +3 -2
  83. package/dist/skills/phases/delivery-phase/SKILL.md +6 -3
  84. package/dist/skills/phases/delivery-phase/phases/plan.md +4 -2
  85. package/dist/skills/phases/delivery-phase/phases/review.md +5 -1
  86. package/dist/skills/phases/delivery-phase/phases/router.md +15 -9
  87. package/dist/skills/phases/delivery-phase/phases/spec.md +13 -26
  88. package/dist/skills/phases/delivery-phase/references/artifact-state.md +39 -1
  89. package/dist/skills/phases/requirements-phase/SKILL.md +31 -14
  90. package/dist/skills/phases/review-phase/phases/prepare-review.md +12 -4
  91. package/package.json +3 -2
@@ -0,0 +1,329 @@
1
+ #!/usr/bin/env node
2
+ /// <reference types="node" />
3
+ import { readFile, access } from "node:fs/promises";
4
+ import { spawnSync } from "node:child_process";
5
+ import path from "node:path";
6
+ import { resolveManagedLint, buildManagedLintCommand } from "./managed-lint.mjs";
7
+
8
+ /** @param {unknown} error - A filesystem or subprocess boundary failure. */
9
+ const missingFile = (error) => error instanceof Error && "code" in error && error.code === "ENOENT";
10
+ /** @param {unknown} error - A filesystem or subprocess boundary failure. */
11
+ const errorMessage = (error) => (error instanceof Error ? error.message : String(error));
12
+ /** @param {unknown} value @returns {value is Record<string, unknown>} */
13
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
14
+ /** @param {unknown} value @returns {value is import("./managed-lint-runner.mjs").ManagedLintDiagnostic} */
15
+ const isDiagnostic = (value) =>
16
+ isRecord(value) &&
17
+ typeof value.message === "string" &&
18
+ ["filename", "code", "severity"].every(
19
+ (key) => value[key] === undefined || typeof value[key] === "string",
20
+ );
21
+ /** @param {string} file @param {unknown} [missingValue] @returns {Promise<unknown>} */
22
+ const readJson = async (file, missingValue = null) => {
23
+ try {
24
+ /** @type {unknown} */
25
+ const value = JSON.parse(await readFile(file, "utf-8"));
26
+ return value;
27
+ } catch (error) {
28
+ if (missingFile(error)) {
29
+ return missingValue;
30
+ }
31
+ throw error;
32
+ }
33
+ };
34
+ /** @param {string} root @param {readonly string[]} [paths] @param {string} [scope] */
35
+ export const loadManagedLint = async (root, paths, scope) =>
36
+ await resolveManagedLint({
37
+ root,
38
+ selection: await readJson(path.join(root, ".devpunks/specs/lint/selection.json")),
39
+ settings: await readJson(path.join(root, ".devpunks/settings.json"), {}),
40
+ ...(paths === undefined ? {} : { paths }),
41
+ ...(scope === undefined ? {} : { scope }),
42
+ });
43
+ /** @param {string} cwd @returns {Promise<string>} */
44
+ const discoverRoot = async (cwd) => {
45
+ try {
46
+ await access(path.join(cwd, ".devpunks/settings.json"));
47
+ return cwd;
48
+ } catch (error) {
49
+ if (!missingFile(error)) {
50
+ throw error;
51
+ }
52
+ }
53
+ const parent = path.dirname(cwd);
54
+ if (parent === cwd) {
55
+ throw new Error(
56
+ "Select software scopes in .devpunks/settings.json lint.scopes, or pass --root.",
57
+ );
58
+ }
59
+ return await discoverRoot(parent);
60
+ };
61
+ /** @param {string} root @param {string} cwd @returns {NodeJS.ProcessEnv} */
62
+ export const managedLintEnvironment = (root, cwd) => {
63
+ const bins = [];
64
+ let current = cwd;
65
+ while (true) {
66
+ bins.push(path.join(current, "node_modules/.bin"));
67
+ if (current === root) {
68
+ break;
69
+ }
70
+ const parent = path.dirname(current);
71
+ if (parent === current) {
72
+ break;
73
+ }
74
+ current = parent;
75
+ }
76
+ bins.push(path.dirname(process.execPath));
77
+ const node = spawnSync("node", ["--print", "process.execPath"], { encoding: "utf-8" });
78
+ const nodePath = node.stdout?.trim();
79
+ if (node.status === 0 && nodePath !== undefined && path.isAbsolute(nodePath)) {
80
+ bins.push(path.dirname(nodePath));
81
+ }
82
+ return { ...process.env, PATH: [...new Set(bins)].join(path.delimiter) };
83
+ };
84
+ /** @param {import("./managed-lint-runner.mjs").ManagedLintRunOptions} options @returns {Promise<import("./managed-lint-runner.mjs").ManagedLintRunResult>} */
85
+ export const runManagedLint = async (options) => {
86
+ try {
87
+ return await executeManagedLint(options);
88
+ } catch (error) {
89
+ return { code: 2, diagnostics: [errorMessage(error)], status: "conflict" };
90
+ }
91
+ };
92
+ /** @param {import("./managed-lint-runner.mjs").ManagedLintRunOptions} options @returns {Promise<import("./managed-lint-runner.mjs").ManagedLintRunResult>} */
93
+ const executeManagedLint = async ({ root, scope, paths, output = "human" }) => {
94
+ let resolution = await loadManagedLint(root, paths, scope);
95
+ if (resolution.status === "disabled") {
96
+ return { code: 0, results: [], status: "clean" };
97
+ }
98
+ if (resolution.status !== "ready") {
99
+ return { ...resolution, code: 2 };
100
+ }
101
+ if (resolution.routes.some((route) => route.triggered)) {
102
+ const complete = await loadManagedLint(root);
103
+ if (complete.status !== "ready") {
104
+ return { ...complete, code: 2 };
105
+ }
106
+ resolution = {
107
+ ...resolution,
108
+ routes: resolution.routes.map((route) =>
109
+ route.triggered
110
+ ? (complete.routes.find((item) => item.scope === route.scope) ?? route)
111
+ : route,
112
+ ),
113
+ };
114
+ }
115
+ const commands = await Promise.all(
116
+ resolution.routes
117
+ .filter((item) => scope === undefined || scope === item.scope)
118
+ .map(async (route) => await buildManagedLintCommand({ output: "json", root, route })),
119
+ );
120
+ const failure = commands.find(
121
+ (command) => command.status !== "ready" && command.status !== "empty",
122
+ );
123
+ if (failure !== undefined) {
124
+ return { ...failure, code: 2, results: [] };
125
+ }
126
+ const results = commands
127
+ .filter((command) => command.status === "ready")
128
+ .map((command) => executeManagedLintCommand({ command, output, root }));
129
+ /** @type {0 | 1 | 2} */
130
+ let code = 0;
131
+ if (results.some((result) => result.code !== 0)) {
132
+ code = 1;
133
+ }
134
+ if (results.some((result) => result.code === 2)) {
135
+ code = 2;
136
+ }
137
+ /** @type {readonly ["clean", "findings", "operational-failure"]} */
138
+ const statuses = ["clean", "findings", "operational-failure"];
139
+ return { code, results, status: statuses[code] };
140
+ };
141
+ /** @param {string} stdout - Structured output from the local Oxlint subprocess.
142
+ * @returns {{ diagnostics: readonly import("./managed-lint-runner.mjs").ManagedLintDiagnostic[], empty: boolean } | null} A valid report, or null for malformed output.
143
+ */
144
+ const readLintOutput = (stdout) => {
145
+ const notice = [
146
+ "No files found matching the given patterns.",
147
+ "No files found to lint. Please check your paths and ignore patterns.",
148
+ ].find((candidate) => stdout.startsWith(`${candidate}\n`));
149
+ try {
150
+ /** @type {unknown} */
151
+ const value = JSON.parse(notice === undefined ? stdout : stdout.slice(notice.length + 1));
152
+ if (
153
+ isRecord(value) &&
154
+ Array.isArray(value.diagnostics) &&
155
+ value.diagnostics.every(isDiagnostic) &&
156
+ (notice === undefined || (value.diagnostics.length === 0 && value.number_of_files === 0))
157
+ ) {
158
+ return { diagnostics: value.diagnostics, empty: notice !== undefined };
159
+ }
160
+ } catch {
161
+ // Malformed/config output is operational, even if the subprocess exits zero.
162
+ }
163
+ return null;
164
+ };
165
+ /** @param {string} stderr - Node's benign warning for a typeless package's ESM config. */
166
+ const hasOnlyModuleTypeWarnings = (stderr) =>
167
+ stderr
168
+ .split(/\r?\n/u)
169
+ .map((line) => line.trim())
170
+ .filter((line) => line.length > 0)
171
+ .every(
172
+ (line) =>
173
+ /^\(node:\d+\) \[MODULE_TYPELESS_PACKAGE_JSON\] Warning: Module type of .+ is not specified and it doesn't parse as CommonJS\.$/u.test(
174
+ line,
175
+ ) ||
176
+ line ===
177
+ "Reparsing as ES module because module syntax was detected. This incurs a performance overhead." ||
178
+ /^To eliminate this warning, add "type": "module" to .+\.$/u.test(line) ||
179
+ line === "(Use `node --trace-warnings ...` to show where the warning was created)",
180
+ );
181
+ /** @param {import("node:child_process").SpawnSyncReturns<string>} result - The local Oxlint process result.
182
+ * @param {ReturnType<typeof readLintOutput>} report - Its validated structured output.
183
+ * @returns {0 | 1 | 2} The public clean, findings, or operational-failure exit code.
184
+ */
185
+ const lintExitCode = (result, report) => {
186
+ if (result.error !== undefined || result.signal !== null || report === null) {
187
+ return 2;
188
+ }
189
+ if (!hasOnlyModuleTypeWarnings(result.stderr ?? "")) {
190
+ return 2;
191
+ }
192
+ if (result.status === 0) {
193
+ return 0;
194
+ }
195
+ if (result.status !== 1) {
196
+ return 2;
197
+ }
198
+ if (report.empty) {
199
+ return 0;
200
+ }
201
+ return report.diagnostics.length > 0 ? 1 : 2;
202
+ };
203
+ /** @param {import("node:child_process").SpawnSyncReturns<string>} result - Original process evidence.
204
+ * @param {ReturnType<typeof readLintOutput>} report - Validated structured output.
205
+ * @returns {NonNullable<import("./managed-lint-runner.mjs").ManagedLintExecution["failure"]>} The operational failure's presentation context.
206
+ */
207
+ const lintFailure = (result, report) => {
208
+ if (result.error !== undefined || result.signal !== null || result.status === null) {
209
+ return { kind: "process", phase: "lint" };
210
+ }
211
+ if (
212
+ result.status !== 0 &&
213
+ /^Failed to parse oxlint configuration file\./mu.test(result.stdout ?? "")
214
+ ) {
215
+ return { kind: "config-load", phase: "config" };
216
+ }
217
+ const stderr = result.stderr ?? "";
218
+ if (!hasOnlyModuleTypeWarnings(stderr) && /config|load/iu.test(stderr)) {
219
+ return { kind: "config-load", phase: "lint" };
220
+ }
221
+ return { kind: report === null ? "malformed-output" : "process", phase: "lint" };
222
+ };
223
+ /** @param {import("./managed-lint-runner.mjs").ManagedLintExecutionOptions} options @returns {import("./managed-lint-runner.mjs").ManagedLintExecution} */
224
+ export const executeManagedLintCommand = ({ root, command, output = "json" }) => {
225
+ const result = spawnSync(command.executable, command.args, {
226
+ cwd: command.cwd,
227
+ encoding: "utf-8",
228
+ env: managedLintEnvironment(root, command.cwd),
229
+ maxBuffer: 10 * 1024 * 1024,
230
+ });
231
+ const report = readLintOutput(result.stdout ?? "");
232
+ const stderr = result.stderr ?? "";
233
+ const diagnostics = report?.diagnostics;
234
+ const code = lintExitCode(result, report);
235
+ const stdout =
236
+ output === "json" || code === 2 || diagnostics === undefined
237
+ ? (result.stdout ?? "")
238
+ : diagnostics
239
+ .map(
240
+ (item) =>
241
+ `${item.filename ?? command.scope}: ${item.severity ?? "error"}: ${item.message} (${item.code ?? "lint"})`,
242
+ )
243
+ .join("\n") + (diagnostics.length > 0 ? "\n" : "");
244
+ return {
245
+ code,
246
+ command,
247
+ error: result.error,
248
+ scope: command.scope,
249
+ signal: result.signal,
250
+ status: result.status,
251
+ stderr: stderr === "" ? (result.error?.message ?? "") : stderr,
252
+ stdout,
253
+ ...(code === 2 ? { failure: lintFailure(result, report) } : {}),
254
+ ...(diagnostics === undefined ? {} : { diagnostics }),
255
+ };
256
+ };
257
+
258
+ const main = async () => {
259
+ const args = process.argv.slice(2);
260
+ let root;
261
+ let scope;
262
+ /** @type {"human" | "json"} */
263
+ let output = "human";
264
+ let paths;
265
+ for (let index = 0; index < args.length; index += 1) {
266
+ const arg = args[index];
267
+ if (arg === "--") {
268
+ paths = args.slice(index + 1);
269
+ break;
270
+ }
271
+ if (!["--root", "--scope", "--format"].includes(arg) || args[index + 1] === undefined) {
272
+ throw new Error(`Unknown or incomplete argument: ${arg}`);
273
+ }
274
+ index += 1;
275
+ const value = args[index];
276
+ if (value.startsWith("--")) {
277
+ throw new Error(`Missing value for ${arg}`);
278
+ }
279
+ if (arg === "--root") {
280
+ root = path.resolve(value);
281
+ }
282
+ if (arg === "--scope") {
283
+ scope = value;
284
+ }
285
+ if (arg === "--format") {
286
+ if (value !== "human" && value !== "json") {
287
+ throw new Error("--format must be human or json");
288
+ }
289
+ output = value;
290
+ }
291
+ }
292
+ if (!["human", "json"].includes(output)) {
293
+ throw new Error("--format must be human or json");
294
+ }
295
+ const resolvedRoot = root ?? (await discoverRoot(process.cwd()));
296
+ const result = await runManagedLint({
297
+ output,
298
+ paths: paths?.map((file) =>
299
+ path.relative(resolvedRoot, path.resolve(file)).split(path.sep).join("/"),
300
+ ),
301
+ root: resolvedRoot,
302
+ scope,
303
+ });
304
+ if (output === "json") {
305
+ process.stdout.write(`${JSON.stringify(result)}\n`);
306
+ } else {
307
+ for (const owner of result.results ?? []) {
308
+ process.stdout.write(owner.stdout);
309
+ process.stderr.write(owner.stderr);
310
+ }
311
+ }
312
+ for (const diagnostic of result.diagnostics ?? []) {
313
+ process.stderr.write(`${diagnostic}\n`);
314
+ }
315
+ process.exitCode = result.code;
316
+ };
317
+ // Bundling rewrites import.meta.filename to the host CLI; retain the standalone asset identity.
318
+ if (
319
+ process.argv[1] !== undefined &&
320
+ path.basename(process.argv[1]) === "managed-lint-runner.mjs" &&
321
+ path.resolve(process.argv[1]) === import.meta.filename
322
+ ) {
323
+ try {
324
+ await main();
325
+ } catch (error) {
326
+ console.error(errorMessage(error));
327
+ process.exitCode = 2;
328
+ }
329
+ }