specdx 0.1.0-alpha.1 → 0.1.0-alpha.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 (59) hide show
  1. package/dist/chunk-ADUPKQBA.js +260 -0
  2. package/dist/chunk-ADUPKQBA.js.map +1 -0
  3. package/dist/chunk-KQKWPO7Y.js +203 -0
  4. package/dist/chunk-KQKWPO7Y.js.map +1 -0
  5. package/dist/graph-XJSNQ7B7.js +44 -0
  6. package/dist/graph-XJSNQ7B7.js.map +1 -0
  7. package/dist/index.js +873 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/lint-BOQDKP7A.js +326 -0
  10. package/dist/lint-BOQDKP7A.js.map +1 -0
  11. package/dist/main.js +132 -9
  12. package/dist/main.js.map +1 -1
  13. package/dist/validate-FFNJWR6V.js +32 -0
  14. package/dist/validate-FFNJWR6V.js.map +1 -0
  15. package/package.json +16 -6
  16. package/dist/commands/graph.d.ts +0 -19
  17. package/dist/commands/graph.d.ts.map +0 -1
  18. package/dist/commands/graph.js +0 -36
  19. package/dist/commands/graph.js.map +0 -1
  20. package/dist/commands/init.d.ts +0 -26
  21. package/dist/commands/init.d.ts.map +0 -1
  22. package/dist/commands/init.js +0 -116
  23. package/dist/commands/init.js.map +0 -1
  24. package/dist/commands/init.test.d.ts +0 -2
  25. package/dist/commands/init.test.d.ts.map +0 -1
  26. package/dist/commands/init.test.js +0 -42
  27. package/dist/commands/init.test.js.map +0 -1
  28. package/dist/commands/lint.d.ts +0 -39
  29. package/dist/commands/lint.d.ts.map +0 -1
  30. package/dist/commands/lint.js +0 -66
  31. package/dist/commands/lint.js.map +0 -1
  32. package/dist/commands/lint.test.d.ts +0 -2
  33. package/dist/commands/lint.test.d.ts.map +0 -1
  34. package/dist/commands/lint.test.js +0 -61
  35. package/dist/commands/lint.test.js.map +0 -1
  36. package/dist/commands/validate.d.ts +0 -19
  37. package/dist/commands/validate.d.ts.map +0 -1
  38. package/dist/commands/validate.js +0 -25
  39. package/dist/commands/validate.js.map +0 -1
  40. package/dist/formatters/github.d.ts +0 -3
  41. package/dist/formatters/github.d.ts.map +0 -1
  42. package/dist/formatters/github.js +0 -10
  43. package/dist/formatters/github.js.map +0 -1
  44. package/dist/formatters/json.d.ts +0 -3
  45. package/dist/formatters/json.d.ts.map +0 -1
  46. package/dist/formatters/json.js +0 -4
  47. package/dist/formatters/json.js.map +0 -1
  48. package/dist/formatters/pretty.d.ts +0 -3
  49. package/dist/formatters/pretty.d.ts.map +0 -1
  50. package/dist/formatters/pretty.js +0 -11
  51. package/dist/formatters/pretty.js.map +0 -1
  52. package/dist/index.d.ts +0 -3
  53. package/dist/index.d.ts.map +0 -1
  54. package/dist/main.d.ts +0 -3
  55. package/dist/main.d.ts.map +0 -1
  56. package/dist/shared-args.d.ts +0 -18
  57. package/dist/shared-args.d.ts.map +0 -1
  58. package/dist/shared-args.js +0 -10
  59. package/dist/shared-args.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,3 +1,874 @@
1
- export { scaffoldProject } from "./commands/init.js";
2
- export { runLint } from "./commands/lint.js";
1
+ // src/commands/init.ts
2
+ import { defineCommand } from "citty";
3
+ import { mkdir, writeFile } from "fs/promises";
4
+ import { join } from "path";
5
+
6
+ // ../schema/dist/sections.js
7
+ var REQUIRED_SECTIONS = {
8
+ prd: ["Problem Statement", "Goals", "Non-Goals", "Features", "Success Criteria"],
9
+ "technical-design": [
10
+ "Overview",
11
+ "Architecture",
12
+ "Data Model",
13
+ "API Design",
14
+ "Dependencies",
15
+ "Risks",
16
+ "Open Questions"
17
+ ],
18
+ "user-story": ["Description", "Acceptance Criteria", "Dependencies", "Notes"],
19
+ "test-plan": ["Scope", "Test Cases", "Coverage Matrix", "Edge Cases"],
20
+ adr: ["Context", "Decision", "Status", "Consequences"],
21
+ "api-contract": ["Endpoints", "Request/Response Schemas", "Auth", "Error Codes"]
22
+ };
23
+
24
+ // ../schema/dist/validator.js
25
+ import { Ajv as AjvClass } from "ajv";
26
+
27
+ // ../schema/dist/schemas/base-spec.json
28
+ var base_spec_default = {
29
+ $id: "base-spec",
30
+ $schema: "http://json-schema.org/draft-07/schema#",
31
+ type: "object",
32
+ properties: {
33
+ id: { type: "string", minLength: 1 },
34
+ type: { type: "string", enum: ["prd", "technical-design", "user-story", "test-plan", "adr", "api-contract"] },
35
+ title: { type: "string", minLength: 1 },
36
+ status: { type: "string", enum: ["draft", "review", "approved", "superseded"] },
37
+ version: { type: "string" },
38
+ created: { type: "string", format: "date" },
39
+ updated: { type: "string", format: "date" },
40
+ authors: { type: "array", items: { type: "string" }, minItems: 1 },
41
+ tags: { type: "array", items: { type: "string" }, default: [] },
42
+ references: {
43
+ type: "array",
44
+ items: {
45
+ type: "object",
46
+ properties: {
47
+ id: { type: "string" },
48
+ relationship: { type: "string", enum: ["implemented-by", "decomposed-into", "depends-on", "supersedes", "related-to"] }
49
+ },
50
+ required: ["id", "relationship"],
51
+ additionalProperties: false
52
+ },
53
+ default: []
54
+ }
55
+ },
56
+ required: ["id", "type", "title", "status", "version", "created", "authors"],
57
+ additionalProperties: true
58
+ };
59
+
60
+ // ../schema/dist/schemas/config.json
61
+ var config_default = {
62
+ $id: "sdx-config",
63
+ $schema: "http://json-schema.org/draft-07/schema#",
64
+ type: "object",
65
+ properties: {
66
+ version: { type: "string" },
67
+ project: {
68
+ type: "object",
69
+ properties: {
70
+ name: { type: "string" },
71
+ description: { type: "string" }
72
+ },
73
+ additionalProperties: false
74
+ },
75
+ specs: {
76
+ type: "object",
77
+ additionalProperties: {
78
+ type: "object",
79
+ properties: {
80
+ path: { type: "string" },
81
+ type: { type: "string", enum: ["prd", "technical-design", "user-story", "test-plan", "adr", "api-contract"] },
82
+ required: { type: "boolean", default: false },
83
+ requires: { type: "array", items: { type: "string" } }
84
+ },
85
+ required: ["path", "type"],
86
+ additionalProperties: false
87
+ }
88
+ },
89
+ lint: {
90
+ type: "object",
91
+ properties: {
92
+ extends: { type: "string", enum: ["minimal", "recommended", "strict"] },
93
+ rules: { type: "object" },
94
+ ignore: { type: "array", items: { type: "string" } }
95
+ },
96
+ additionalProperties: false
97
+ },
98
+ pack: { type: "object" },
99
+ diff: { type: "object" },
100
+ ci: { type: "object" }
101
+ },
102
+ required: ["version", "specs"],
103
+ additionalProperties: false
104
+ };
105
+
106
+ // ../schema/dist/schemas/prd.json
107
+ var prd_default = {
108
+ $id: "prd",
109
+ $schema: "http://json-schema.org/draft-07/schema#",
110
+ allOf: [
111
+ { $ref: "base-spec" },
112
+ { type: "object", properties: { type: { const: "prd" } }, required: ["type"] }
113
+ ]
114
+ };
115
+
116
+ // ../schema/dist/schemas/technical-design.json
117
+ var technical_design_default = {
118
+ $id: "technical-design",
119
+ $schema: "http://json-schema.org/draft-07/schema#",
120
+ allOf: [
121
+ { $ref: "base-spec" },
122
+ { type: "object", properties: { type: { const: "technical-design" } }, required: ["type"] }
123
+ ]
124
+ };
125
+
126
+ // ../schema/dist/schemas/user-story.json
127
+ var user_story_default = {
128
+ $id: "user-story",
129
+ $schema: "http://json-schema.org/draft-07/schema#",
130
+ allOf: [
131
+ { $ref: "base-spec" },
132
+ {
133
+ type: "object",
134
+ properties: {
135
+ type: { const: "user-story" },
136
+ story_id: { type: "string", minLength: 1 },
137
+ priority: { type: "string", enum: ["critical", "high", "medium", "low"] },
138
+ estimate: { type: "string" }
139
+ },
140
+ required: ["type", "story_id", "priority", "estimate"]
141
+ }
142
+ ]
143
+ };
144
+
145
+ // ../schema/dist/schemas/test-plan.json
146
+ var test_plan_default = {
147
+ $id: "test-plan",
148
+ $schema: "http://json-schema.org/draft-07/schema#",
149
+ allOf: [
150
+ { $ref: "base-spec" },
151
+ { type: "object", properties: { type: { const: "test-plan" } }, required: ["type"] }
152
+ ]
153
+ };
154
+
155
+ // ../schema/dist/schemas/adr.json
156
+ var adr_default = {
157
+ $id: "adr",
158
+ $schema: "http://json-schema.org/draft-07/schema#",
159
+ allOf: [
160
+ { $ref: "base-spec" },
161
+ { type: "object", properties: { type: { const: "adr" } }, required: ["type"] }
162
+ ]
163
+ };
164
+
165
+ // ../schema/dist/schemas/api-contract.json
166
+ var api_contract_default = {
167
+ $id: "api-contract",
168
+ $schema: "http://json-schema.org/draft-07/schema#",
169
+ allOf: [
170
+ { $ref: "base-spec" },
171
+ { type: "object", properties: { type: { const: "api-contract" } }, required: ["type"] }
172
+ ]
173
+ };
174
+
175
+ // ../schema/dist/validator.js
176
+ import * as addFormatsNs from "ajv-formats";
177
+ var addFormats = addFormatsNs.default ?? addFormatsNs;
178
+ var ajv = new AjvClass({ allErrors: true, strict: true });
179
+ addFormats(ajv, ["date"]);
180
+ ajv.addSchema(base_spec_default);
181
+ var specValidators = {
182
+ prd: ajv.compile(prd_default),
183
+ "technical-design": ajv.compile(technical_design_default),
184
+ "user-story": ajv.compile(user_story_default),
185
+ "test-plan": ajv.compile(test_plan_default),
186
+ adr: ajv.compile(adr_default),
187
+ "api-contract": ajv.compile(api_contract_default)
188
+ };
189
+ var configValidator = ajv.compile(config_default);
190
+ function validateSpec(type, data) {
191
+ const validate = specValidators[type];
192
+ if (!validate) {
193
+ return { valid: false, errors: [{ message: `Unknown spec type: "${type}"` }] };
194
+ }
195
+ const valid = validate(data);
196
+ return { valid: !!valid, errors: valid ? null : validate.errors ?? null };
197
+ }
198
+ function validateConfig(data) {
199
+ const valid = configValidator(data);
200
+ return { valid: !!valid, errors: valid ? null : configValidator.errors ?? null };
201
+ }
202
+
203
+ // src/commands/init.ts
204
+ var TEMPLATE_SPECS = {
205
+ lightweight: [
206
+ { filename: "prd.md", type: "prd" },
207
+ { filename: "technical-design.md", type: "technical-design" }
208
+ ],
209
+ bmad: [
210
+ { filename: "prd.md", type: "prd" },
211
+ { filename: "technical-design.md", type: "technical-design" },
212
+ { filename: "test-plan.md", type: "test-plan" }
213
+ ],
214
+ "api-first": [
215
+ { filename: "technical-design.md", type: "technical-design" },
216
+ { filename: "api-contract.md", type: "api-contract" },
217
+ { filename: "test-plan.md", type: "test-plan" }
218
+ ]
219
+ };
220
+ var TEMPLATE_EXTRA_DIRS = {
221
+ lightweight: [],
222
+ bmad: ["specs/stories", "specs/adr"],
223
+ "api-first": []
224
+ };
225
+ function specIdFromFilename(filename) {
226
+ return filename.replace(/\.md$/, "");
227
+ }
228
+ function specTitleFromType(type) {
229
+ return type.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
230
+ }
231
+ function buildSpecFile(filename, type, projectName, today) {
232
+ const id = specIdFromFilename(filename);
233
+ const title = `${specTitleFromType(type)} \u2014 ${projectName}`;
234
+ const sections = REQUIRED_SECTIONS[type];
235
+ const frontmatter = [
236
+ "---",
237
+ `id: ${id}`,
238
+ `type: ${type}`,
239
+ `title: "${title}"`,
240
+ `status: draft`,
241
+ `version: "0.1"`,
242
+ `created: ${today}`,
243
+ `authors: []`,
244
+ "---"
245
+ ].join("\n");
246
+ const body = sections.map((section) => `
247
+ ## ${section}
248
+
249
+ <!-- placeholder -->`).join("\n");
250
+ return `${frontmatter}
251
+ ${body}
252
+ `;
253
+ }
254
+ function buildConfigYaml(projectName, specs) {
255
+ const specEntries = specs.map(({ filename, type }) => {
256
+ const key = specIdFromFilename(filename);
257
+ return ` ${key}:
258
+ path: specs/${filename}
259
+ type: ${type}`;
260
+ }).join("\n");
261
+ return [`version: "1.0"`, `project:`, ` name: "${projectName}"`, `specs:`, specEntries].join("\n") + "\n";
262
+ }
263
+ async function scaffoldProject({
264
+ projectName,
265
+ template,
266
+ targetDir
267
+ }) {
268
+ const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
269
+ const specsDir = join(targetDir, "specs");
270
+ await mkdir(specsDir, { recursive: true });
271
+ for (const extraDir of TEMPLATE_EXTRA_DIRS[template]) {
272
+ await mkdir(join(targetDir, extraDir), { recursive: true });
273
+ }
274
+ const specs = TEMPLATE_SPECS[template];
275
+ for (const { filename, type } of specs) {
276
+ const content = buildSpecFile(filename, type, projectName, today);
277
+ await writeFile(join(specsDir, filename), content, "utf-8");
278
+ }
279
+ const configContent = buildConfigYaml(projectName, specs);
280
+ await writeFile(join(targetDir, "spec.config.yaml"), configContent, "utf-8");
281
+ }
282
+ var init_default = defineCommand({
283
+ meta: {
284
+ name: "init",
285
+ description: "Initialize a new SDX project with spec scaffolding"
286
+ },
287
+ args: {
288
+ name: {
289
+ type: "string",
290
+ description: "Project name",
291
+ required: true
292
+ },
293
+ template: {
294
+ type: "string",
295
+ description: "Template to use (lightweight, bmad, api-first)",
296
+ default: "lightweight"
297
+ },
298
+ dir: {
299
+ type: "string",
300
+ description: "Target directory",
301
+ default: "."
302
+ }
303
+ },
304
+ async run({ args }) {
305
+ const { name, template, dir } = args;
306
+ const validTemplates = ["lightweight", "bmad", "api-first"];
307
+ if (!validTemplates.includes(template)) {
308
+ console.error(`Unknown template: ${template}. Choose from: ${validTemplates.join(", ")}`);
309
+ process.exit(1);
310
+ }
311
+ console.log(`Scaffolding "${name}" with template "${template}" in ${dir}...`);
312
+ await scaffoldProject({ projectName: name, template, targetDir: dir });
313
+ console.log(`Done! Project "${name}" scaffolded successfully.`);
314
+ }
315
+ });
316
+
317
+ // src/commands/lint.ts
318
+ import { defineCommand as defineCommand2 } from "citty";
319
+
320
+ // ../core/dist/config.js
321
+ import { readFile } from "fs/promises";
322
+ import { join as join2, dirname } from "path";
323
+ import { parse as parseYaml } from "yaml";
324
+ var ConfigError = class extends Error {
325
+ errors;
326
+ constructor(message, errors) {
327
+ super(message);
328
+ this.errors = errors;
329
+ this.name = "ConfigError";
330
+ }
331
+ };
332
+ var CONFIG_FILENAME = "spec.config.yaml";
333
+ async function loadConfig(filePath, searchFrom) {
334
+ const resolvedPath = filePath ?? await findConfig(searchFrom ?? process.cwd());
335
+ if (!resolvedPath) {
336
+ throw new ConfigError(`No ${CONFIG_FILENAME} found. Run 'sdx init' to create one.`);
337
+ }
338
+ let raw;
339
+ try {
340
+ raw = await readFile(resolvedPath, "utf-8");
341
+ } catch {
342
+ throw new ConfigError(`Cannot read config file: ${resolvedPath}`);
343
+ }
344
+ let data;
345
+ try {
346
+ data = parseYaml(raw);
347
+ } catch (err) {
348
+ throw new ConfigError(`Invalid YAML in ${resolvedPath}: ${err.message}`);
349
+ }
350
+ const result = validateConfig(data);
351
+ if (!result.valid) {
352
+ throw new ConfigError(`Invalid config in ${resolvedPath}`, result.errors ?? void 0);
353
+ }
354
+ return data;
355
+ }
356
+ async function findConfig(from) {
357
+ let dir = from;
358
+ while (true) {
359
+ const candidate = join2(dir, CONFIG_FILENAME);
360
+ try {
361
+ await readFile(candidate, "utf-8");
362
+ return candidate;
363
+ } catch {
364
+ const parent = dirname(dir);
365
+ if (parent === dir)
366
+ return void 0;
367
+ dir = parent;
368
+ }
369
+ }
370
+ }
371
+
372
+ // ../core/dist/parser.js
373
+ import { readFile as readFile2 } from "fs/promises";
374
+ import { extname } from "path";
375
+ import * as grayMatterNs from "gray-matter";
376
+ import { parse as parseYaml2 } from "yaml";
377
+ import { unified } from "unified";
378
+ import remarkParse from "remark-parse";
379
+ import { visit } from "unist-util-visit";
380
+ var matter = grayMatterNs.default ?? grayMatterNs;
381
+ var ParseError = class extends Error {
382
+ constructor(message) {
383
+ super(message);
384
+ this.name = "ParseError";
385
+ }
386
+ };
387
+ async function parseSpec(filePath) {
388
+ let raw;
389
+ try {
390
+ raw = await readFile2(filePath, "utf-8");
391
+ } catch {
392
+ throw new ParseError(`Cannot read spec file: ${filePath}`);
393
+ }
394
+ const ext = extname(filePath).toLowerCase();
395
+ if (ext === ".yaml" || ext === ".yml") {
396
+ return parseYamlSpec(filePath, raw);
397
+ }
398
+ return parseMarkdownSpec(filePath, raw);
399
+ }
400
+ function parseMarkdownSpec(filePath, raw) {
401
+ const { data, content } = matter(raw);
402
+ const sections = extractSections(content);
403
+ const frontmatter = data;
404
+ const specType = frontmatter.type;
405
+ let valid = false;
406
+ let validationErrors = null;
407
+ if (specType) {
408
+ const result = validateSpec(specType, data);
409
+ valid = result.valid;
410
+ validationErrors = result.errors;
411
+ }
412
+ return { filePath, frontmatter, content, sections, valid, validationErrors };
413
+ }
414
+ function parseYamlSpec(filePath, raw) {
415
+ let data;
416
+ try {
417
+ data = parseYaml2(raw);
418
+ } catch (err) {
419
+ throw new ParseError(`Invalid YAML in ${filePath}: ${err.message}`);
420
+ }
421
+ const frontmatter = data;
422
+ const specType = frontmatter.type;
423
+ let valid = false;
424
+ let validationErrors = null;
425
+ if (specType) {
426
+ const result = validateSpec(specType, data);
427
+ valid = result.valid;
428
+ validationErrors = result.errors;
429
+ }
430
+ return { filePath, frontmatter, content: "", sections: [], valid, validationErrors };
431
+ }
432
+ function extractSections(markdown) {
433
+ const tree = unified().use(remarkParse).parse(markdown);
434
+ const sections = [];
435
+ visit(tree, "heading", (node) => {
436
+ if (node.depth === 2) {
437
+ const text = node.children.filter((c) => c.type === "text").map((c) => c.value).join("");
438
+ if (text)
439
+ sections.push(text);
440
+ }
441
+ });
442
+ return sections;
443
+ }
444
+
445
+ // ../core/dist/graph.js
446
+ var GraphError = class extends Error {
447
+ constructor(message) {
448
+ super(message);
449
+ this.name = "GraphError";
450
+ }
451
+ };
452
+ function buildGraph(config) {
453
+ const specNames = Object.keys(config.specs);
454
+ const adjacency = /* @__PURE__ */ new Map();
455
+ const reverseAdj = /* @__PURE__ */ new Map();
456
+ const edges = [];
457
+ for (const name of specNames) {
458
+ adjacency.set(name, []);
459
+ reverseAdj.set(name, []);
460
+ }
461
+ for (const [name, entry] of Object.entries(config.specs)) {
462
+ if (!entry.requires)
463
+ continue;
464
+ for (const dep of entry.requires) {
465
+ if (!adjacency.has(dep)) {
466
+ throw new GraphError(`Spec "${name}" requires "${dep}", which does not exist in the config.`);
467
+ }
468
+ adjacency.get(dep).push(name);
469
+ reverseAdj.get(name).push(dep);
470
+ edges.push({ from: dep, to: name });
471
+ }
472
+ }
473
+ const inDegree = /* @__PURE__ */ new Map();
474
+ for (const name of specNames)
475
+ inDegree.set(name, reverseAdj.get(name).length);
476
+ const queue = [];
477
+ for (const [name, degree] of inDegree) {
478
+ if (degree === 0)
479
+ queue.push(name);
480
+ }
481
+ const sorted = [];
482
+ while (queue.length > 0) {
483
+ const node = queue.shift();
484
+ sorted.push(node);
485
+ for (const neighbor of adjacency.get(node)) {
486
+ const newDegree = inDegree.get(neighbor) - 1;
487
+ inDegree.set(neighbor, newDegree);
488
+ if (newDegree === 0)
489
+ queue.push(neighbor);
490
+ }
491
+ }
492
+ if (sorted.length !== specNames.length) {
493
+ const remaining = specNames.filter((n) => !sorted.includes(n));
494
+ throw new GraphError(`Circular dependency detected involving: ${remaining.join(", ")}`);
495
+ }
496
+ return {
497
+ nodes: specNames,
498
+ edges,
499
+ topologicalSort: () => [...sorted],
500
+ getDownstream(nodeId) {
501
+ const visited = /* @__PURE__ */ new Set();
502
+ const stack = [nodeId];
503
+ while (stack.length > 0) {
504
+ const current = stack.pop();
505
+ for (const neighbor of adjacency.get(current) ?? []) {
506
+ if (!visited.has(neighbor)) {
507
+ visited.add(neighbor);
508
+ stack.push(neighbor);
509
+ }
510
+ }
511
+ }
512
+ return [...visited];
513
+ },
514
+ getUpstream(nodeId) {
515
+ const visited = /* @__PURE__ */ new Set();
516
+ const stack = [nodeId];
517
+ while (stack.length > 0) {
518
+ const current = stack.pop();
519
+ for (const dep of reverseAdj.get(current) ?? []) {
520
+ if (!visited.has(dep)) {
521
+ visited.add(dep);
522
+ stack.push(dep);
523
+ }
524
+ }
525
+ }
526
+ return [...visited];
527
+ }
528
+ };
529
+ }
530
+
531
+ // ../core/dist/glob.js
532
+ import { glob } from "tinyglobby";
533
+ import { join as join3, isAbsolute } from "path";
534
+ async function resolveGlob(pattern, baseDir) {
535
+ const absolutePattern = isAbsolute(pattern) ? pattern : join3(baseDir, pattern);
536
+ return glob([absolutePattern], { absolute: true });
537
+ }
538
+
539
+ // ../core/dist/tokens.js
540
+ import { encodingForModel } from "js-tiktoken";
541
+
542
+ // ../core/dist/logger.js
543
+ import { createConsola } from "consola";
544
+ function createLogger(options) {
545
+ let level = 3;
546
+ if (options?.quiet)
547
+ level = 1;
548
+ if (options?.verbose)
549
+ level = 4;
550
+ return createConsola({ level });
551
+ }
552
+
553
+ // ../lint/dist/engine.js
554
+ function createLintEngine(options) {
555
+ return {
556
+ lint(specs) {
557
+ const diagnostics = [];
558
+ for (const spec of specs) {
559
+ for (const rule of options.rules) {
560
+ const results = rule.run({
561
+ spec,
562
+ allSpecs: specs,
563
+ config: options.config,
564
+ graph: options.graph
565
+ });
566
+ diagnostics.push(...results);
567
+ }
568
+ }
569
+ return {
570
+ diagnostics,
571
+ hasErrors: diagnostics.some((d) => d.severity === "error"),
572
+ hasWarnings: diagnostics.some((d) => d.severity === "warn")
573
+ };
574
+ }
575
+ };
576
+ }
577
+
578
+ // ../lint/dist/rules/valid-frontmatter.js
579
+ var validFrontmatterRule = {
580
+ id: "structure/valid-frontmatter",
581
+ description: "Frontmatter matches the schema for the declared spec type",
582
+ severity: "error",
583
+ run(context) {
584
+ if (context.spec.valid)
585
+ return [];
586
+ const errors = context.spec.validationErrors ?? [];
587
+ return errors.map((err) => ({
588
+ ruleId: "structure/valid-frontmatter",
589
+ severity: "error",
590
+ message: `Invalid frontmatter: ${err.message ?? JSON.stringify(err)}`,
591
+ filePath: context.spec.filePath
592
+ }));
593
+ }
594
+ };
595
+
596
+ // ../lint/dist/rules/required-sections.js
597
+ var requiredSectionsRule = {
598
+ id: "structure/required-sections",
599
+ description: "Spec body contains all required sections for its type",
600
+ severity: "error",
601
+ run(context) {
602
+ const ext = context.spec.filePath.split(".").pop()?.toLowerCase();
603
+ if (ext === "yaml" || ext === "yml")
604
+ return [];
605
+ const specType = context.spec.frontmatter.type;
606
+ const required = REQUIRED_SECTIONS[specType];
607
+ if (!required)
608
+ return [];
609
+ const missing = required.filter((s) => !context.spec.sections.includes(s));
610
+ return missing.map((section) => ({
611
+ ruleId: "structure/required-sections",
612
+ severity: "error",
613
+ message: `Missing required section: "${section}"`,
614
+ filePath: context.spec.filePath,
615
+ section
616
+ }));
617
+ }
618
+ };
619
+
620
+ // ../lint/dist/rules/valid-references.js
621
+ var validReferencesRule = {
622
+ id: "structure/valid-references",
623
+ description: "All references in frontmatter point to specs that exist in the suite",
624
+ severity: "error",
625
+ run(context) {
626
+ const refs = context.spec.frontmatter.references;
627
+ if (!refs || refs.length === 0)
628
+ return [];
629
+ const allIds = new Set(context.allSpecs.map((s) => s.frontmatter.id));
630
+ return refs.filter((ref) => !allIds.has(ref.id)).map((ref) => ({
631
+ ruleId: "structure/valid-references",
632
+ severity: "error",
633
+ message: `Reference "${ref.id}" does not match any spec in the suite`,
634
+ filePath: context.spec.filePath
635
+ }));
636
+ }
637
+ };
638
+
639
+ // ../lint/dist/rules/no-circular-deps.js
640
+ var noCircularDepsRule = {
641
+ id: "structure/no-circular-deps",
642
+ description: "The dependency graph has no cycles",
643
+ severity: "error",
644
+ run() {
645
+ return [];
646
+ }
647
+ };
648
+
649
+ // ../lint/dist/rules/story-coverage.js
650
+ var FEATURE_PATTERN = /\*\*F\d+\*\*:\s*(.+)/g;
651
+ var storyCoverageRule = {
652
+ id: "completeness/story-coverage",
653
+ description: "Every feature listed in a PRD has at least one corresponding user story",
654
+ severity: "warn",
655
+ run(context) {
656
+ if (context.spec.frontmatter.type !== "prd")
657
+ return [];
658
+ const features = [];
659
+ let match;
660
+ const re = new RegExp(FEATURE_PATTERN.source, "g");
661
+ while ((match = re.exec(context.spec.content)) !== null) {
662
+ features.push(match[1].trim());
663
+ }
664
+ if (features.length === 0)
665
+ return [];
666
+ const stories = context.allSpecs.filter((s) => s.frontmatter.type === "user-story");
667
+ const storyContent = stories.map((s) => s.content + " " + s.frontmatter.title).join(" ");
668
+ return features.filter((feature) => !storyContent.toLowerCase().includes(feature.toLowerCase())).map((feature) => ({
669
+ ruleId: "completeness/story-coverage",
670
+ severity: "warn",
671
+ message: `Feature "${feature}" has no corresponding user story`,
672
+ filePath: context.spec.filePath
673
+ }));
674
+ }
675
+ };
676
+
677
+ // ../lint/dist/rules/staleness-check.js
678
+ var stalenessCheckRule = {
679
+ id: "freshness/staleness-check",
680
+ description: "Warns if a spec hasn't been updated since its upstream dependency changed",
681
+ severity: "warn",
682
+ run(context) {
683
+ const refs = context.spec.frontmatter.references;
684
+ if (!refs || refs.length === 0)
685
+ return [];
686
+ const specUpdated = context.spec.frontmatter.updated ?? context.spec.frontmatter.created;
687
+ const specDate = new Date(specUpdated);
688
+ const diagnostics = [];
689
+ for (const ref of refs) {
690
+ if (ref.relationship !== "depends-on" && ref.relationship !== "implemented-by")
691
+ continue;
692
+ const upstream = context.allSpecs.find((s) => s.frontmatter.id === ref.id);
693
+ if (!upstream)
694
+ continue;
695
+ const upstreamUpdated = upstream.frontmatter.updated ?? upstream.frontmatter.created;
696
+ const upstreamDate = new Date(upstreamUpdated);
697
+ if (upstreamDate > specDate) {
698
+ diagnostics.push({
699
+ ruleId: "freshness/staleness-check",
700
+ severity: "warn",
701
+ message: `Potentially stale: upstream "${upstream.frontmatter.id}" was updated on ${upstreamUpdated}, but this spec was last updated on ${specUpdated}`,
702
+ filePath: context.spec.filePath
703
+ });
704
+ }
705
+ }
706
+ return diagnostics;
707
+ }
708
+ };
709
+
710
+ // ../lint/dist/rules/no-vague-language.js
711
+ var DEFAULT_VAGUE_PATTERNS = [
712
+ "as appropriate",
713
+ "handle edge cases",
714
+ "as needed",
715
+ "etc\\.",
716
+ "TBD",
717
+ "TODO",
718
+ "and so on",
719
+ "various",
720
+ "somehow",
721
+ "straightforward",
722
+ "obviously",
723
+ "simply",
724
+ "just need to"
725
+ ];
726
+ var noVagueLanguageRule = {
727
+ id: "clarity/no-vague-language",
728
+ description: "Flags known ambiguous phrases",
729
+ severity: "warn",
730
+ run(context) {
731
+ if (!context.spec.content)
732
+ return [];
733
+ const diagnostics = [];
734
+ for (const pattern of DEFAULT_VAGUE_PATTERNS) {
735
+ const regex = new RegExp(`\\b${pattern}`, "gi");
736
+ let match;
737
+ while ((match = regex.exec(context.spec.content)) !== null) {
738
+ diagnostics.push({
739
+ ruleId: "clarity/no-vague-language",
740
+ severity: "warn",
741
+ message: `Vague language: "${match[0]}"`,
742
+ filePath: context.spec.filePath
743
+ });
744
+ }
745
+ }
746
+ return diagnostics;
747
+ }
748
+ };
749
+
750
+ // ../lint/dist/rules/index.js
751
+ var structureRules = [
752
+ validFrontmatterRule,
753
+ requiredSectionsRule,
754
+ validReferencesRule,
755
+ noCircularDepsRule
756
+ ];
757
+ var contentRules = [
758
+ storyCoverageRule,
759
+ stalenessCheckRule,
760
+ noVagueLanguageRule
761
+ ];
762
+ var allBuiltinRules = [...structureRules, ...contentRules];
763
+
764
+ // ../lint/dist/presets.js
765
+ function getPreset(name) {
766
+ switch (name) {
767
+ case "minimal":
768
+ return structureRules;
769
+ case "recommended":
770
+ return allBuiltinRules;
771
+ case "strict":
772
+ return allBuiltinRules.map((rule) => ({ ...rule, severity: "error" }));
773
+ }
774
+ }
775
+
776
+ // ../lint/dist/custom-rule-loader.js
777
+ import { pathToFileURL } from "url";
778
+
779
+ // src/shared-args.ts
780
+ var sharedArgs = {
781
+ quiet: { type: "boolean", description: "Suppress info output", alias: ["q"] },
782
+ verbose: { type: "boolean", description: "Enable debug output", alias: ["V"] },
783
+ format: {
784
+ type: "string",
785
+ description: "Output format (pretty, json, github)",
786
+ default: "pretty"
787
+ }
788
+ };
789
+
790
+ // src/formatters/pretty.ts
791
+ function formatPretty(diagnostics) {
792
+ if (diagnostics.length === 0) return " \u2713 All specs pass lint checks.\n";
793
+ return diagnostics.map((d) => {
794
+ const icon = d.severity === "error" ? "\u2717" : d.severity === "warn" ? "\u26A0" : "\u2139";
795
+ return ` ${icon} ${d.severity} ${d.message} (${d.ruleId})
796
+ ${d.filePath}${d.line ? `:${d.line}` : ""}`;
797
+ }).join("\n");
798
+ }
799
+
800
+ // src/formatters/json.ts
801
+ function formatJson(diagnostics) {
802
+ return JSON.stringify(diagnostics, null, 2);
803
+ }
804
+
805
+ // src/formatters/github.ts
806
+ function formatGithub(diagnostics) {
807
+ return diagnostics.map((d) => {
808
+ const level = d.severity === "error" ? "error" : "warning";
809
+ const line = d.line ? `,line=${d.line}` : "";
810
+ return `::${level} file=${d.filePath}${line}::${d.message} (${d.ruleId})`;
811
+ }).join("\n");
812
+ }
813
+
814
+ // src/commands/lint.ts
815
+ async function runLint(options) {
816
+ const config = await loadConfig(void 0, options.configDir);
817
+ const preset = options.preset ?? config.lint?.extends ?? "recommended";
818
+ const rules = getPreset(preset);
819
+ const specs = [];
820
+ for (const [, entry] of Object.entries(config.specs)) {
821
+ const files = await resolveGlob(entry.path, options.configDir);
822
+ for (const file of files) {
823
+ if (options.specPath && !file.includes(options.specPath)) continue;
824
+ specs.push(await parseSpec(file));
825
+ }
826
+ }
827
+ let graph;
828
+ let graphError;
829
+ try {
830
+ graph = buildGraph(config);
831
+ } catch (err) {
832
+ graphError = err.message;
833
+ }
834
+ const engine = createLintEngine({ rules, config, graph });
835
+ const results = engine.lint(specs);
836
+ if (graphError) {
837
+ results.diagnostics.push({
838
+ ruleId: "structure/no-circular-deps",
839
+ severity: "error",
840
+ message: graphError,
841
+ filePath: "spec.config.yaml"
842
+ });
843
+ results.hasErrors = true;
844
+ }
845
+ return results;
846
+ }
847
+ var lint_default = defineCommand2({
848
+ meta: { name: "lint", description: "Lint all specs in the suite" },
849
+ args: {
850
+ ...sharedArgs,
851
+ fix: { type: "boolean", description: "Auto-fix issues where possible" },
852
+ path: { type: "positional", description: "Lint a specific spec file", required: false },
853
+ preset: { type: "string", description: "Lint preset (minimal, recommended, strict)" }
854
+ },
855
+ async run({ args }) {
856
+ const logger = createLogger({ quiet: args.quiet, verbose: args.verbose });
857
+ if (args.fix) {
858
+ logger.info("No auto-fixable issues supported yet.");
859
+ }
860
+ const results = await runLint({
861
+ configDir: process.cwd(),
862
+ specPath: args.path,
863
+ preset: args.preset
864
+ });
865
+ const formatter = args.format === "json" ? formatJson : args.format === "github" ? formatGithub : formatPretty;
866
+ console.log(formatter(results.diagnostics));
867
+ if (results.hasErrors) process.exit(1);
868
+ }
869
+ });
870
+ export {
871
+ runLint,
872
+ scaffoldProject
873
+ };
3
874
  //# sourceMappingURL=index.js.map