specdx 0.4.0-alpha.1 → 0.4.0-alpha.10

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 (81) hide show
  1. package/LICENSE +21 -0
  2. package/dist/{changelog-OUP2RXWN.js → changelog-GR53T6IG.js} +18 -11
  3. package/dist/{changelog-OUP2RXWN.js.map → changelog-GR53T6IG.js.map} +1 -1
  4. package/dist/{check-3XQYO3HU.js → check-OMWCIY5D.js} +37 -10
  5. package/dist/check-OMWCIY5D.js.map +1 -0
  6. package/dist/{chunk-HMXUNURD.js → chunk-3GMYCATE.js} +50 -14
  7. package/dist/chunk-3GMYCATE.js.map +1 -0
  8. package/dist/{chunk-6BWZEAST.js → chunk-N77RNV7J.js} +161 -26
  9. package/dist/chunk-N77RNV7J.js.map +1 -0
  10. package/dist/{chunk-4THCEWAK.js → chunk-SDDTD4R3.js} +95 -10
  11. package/dist/chunk-SDDTD4R3.js.map +1 -0
  12. package/dist/{chunk-ZX4HVL5M.js → chunk-SJCIM4TC.js} +119 -17
  13. package/dist/chunk-SJCIM4TC.js.map +1 -0
  14. package/dist/{chunk-DDFLMRPC.js → chunk-VMMTEGYN.js} +15 -11
  15. package/dist/chunk-VMMTEGYN.js.map +1 -0
  16. package/dist/{chunk-PHR7AV6I.js → chunk-Z77VQUZ3.js} +156 -2
  17. package/dist/chunk-Z77VQUZ3.js.map +1 -0
  18. package/dist/diff-AUBYOQWU.js +107 -0
  19. package/dist/diff-AUBYOQWU.js.map +1 -0
  20. package/dist/{dist-QXLX77XG.js → dist-BXYQB2UO.js} +36 -9
  21. package/dist/dist-BXYQB2UO.js.map +1 -0
  22. package/dist/dist-RL2DT3ZE.js +15 -0
  23. package/dist/{explain-I7AQMEEH.js → explain-EUID6MZF.js} +35 -28
  24. package/dist/explain-EUID6MZF.js.map +1 -0
  25. package/dist/{generate-PC7BIB7G.js → generate-U3EFOCNS.js} +3 -3
  26. package/dist/{generate-story-7WHPPFHY.js → generate-story-U6FMQIYZ.js} +8 -4
  27. package/dist/generate-story-U6FMQIYZ.js.map +1 -0
  28. package/dist/{generate-test-plan-U5LMWGKX.js → generate-test-plan-HOCWDYKF.js} +11 -6
  29. package/dist/generate-test-plan-HOCWDYKF.js.map +1 -0
  30. package/dist/graph-TA54D4XA.js +102 -0
  31. package/dist/graph-TA54D4XA.js.map +1 -0
  32. package/dist/index.js +546 -156
  33. package/dist/index.js.map +1 -1
  34. package/dist/{lint-XPAFMLZN.js → lint-L5WOBD25.js} +17 -6
  35. package/dist/lint-L5WOBD25.js.map +1 -0
  36. package/dist/main.js +100 -16
  37. package/dist/main.js.map +1 -1
  38. package/dist/{mcp-6RCSHMXD.js → mcp-GNQQGD7X.js} +2 -2
  39. package/dist/{migrate-L7W5RHSS.js → migrate-YEJQWIMX.js} +4 -4
  40. package/dist/migrate-YEJQWIMX.js.map +1 -0
  41. package/dist/{pack-QCOXMURY.js → pack-AQH5XQUF.js} +7 -6
  42. package/dist/{pack-QCOXMURY.js.map → pack-AQH5XQUF.js.map} +1 -1
  43. package/dist/ready-DB5ORK2E.js +229 -0
  44. package/dist/ready-DB5ORK2E.js.map +1 -0
  45. package/dist/skills/specdx-check-drift.md +1 -1
  46. package/dist/skills/specdx-verify.md +12 -1
  47. package/dist/{status-EKWK47O5.js → status-3QUQMF4L.js} +46 -31
  48. package/dist/status-3QUQMF4L.js.map +1 -0
  49. package/dist/{update-HIWDDEZQ.js → update-PE2DPYDR.js} +5 -5
  50. package/dist/update-PE2DPYDR.js.map +1 -0
  51. package/dist/validate-YNZMV6KZ.js +86 -0
  52. package/dist/validate-YNZMV6KZ.js.map +1 -0
  53. package/hooks/session-start +0 -0
  54. package/package.json +49 -17
  55. package/dist/check-3XQYO3HU.js.map +0 -1
  56. package/dist/chunk-4THCEWAK.js.map +0 -1
  57. package/dist/chunk-6BWZEAST.js.map +0 -1
  58. package/dist/chunk-DDFLMRPC.js.map +0 -1
  59. package/dist/chunk-HMXUNURD.js.map +0 -1
  60. package/dist/chunk-PHR7AV6I.js.map +0 -1
  61. package/dist/chunk-ZX4HVL5M.js.map +0 -1
  62. package/dist/diff-275PLXYH.js +0 -100
  63. package/dist/diff-275PLXYH.js.map +0 -1
  64. package/dist/dist-PQCG2XXF.js +0 -11
  65. package/dist/dist-QXLX77XG.js.map +0 -1
  66. package/dist/explain-I7AQMEEH.js.map +0 -1
  67. package/dist/generate-story-7WHPPFHY.js.map +0 -1
  68. package/dist/generate-test-plan-U5LMWGKX.js.map +0 -1
  69. package/dist/graph-RCAPF55A.js +0 -54
  70. package/dist/graph-RCAPF55A.js.map +0 -1
  71. package/dist/lint-XPAFMLZN.js.map +0 -1
  72. package/dist/migrate-L7W5RHSS.js.map +0 -1
  73. package/dist/ready-ZXG74W7Y.js +0 -159
  74. package/dist/ready-ZXG74W7Y.js.map +0 -1
  75. package/dist/status-EKWK47O5.js.map +0 -1
  76. package/dist/update-HIWDDEZQ.js.map +0 -1
  77. package/dist/validate-N2WSG75W.js +0 -34
  78. package/dist/validate-N2WSG75W.js.map +0 -1
  79. /package/dist/{dist-PQCG2XXF.js.map → dist-RL2DT3ZE.js.map} +0 -0
  80. /package/dist/{generate-PC7BIB7G.js.map → generate-U3EFOCNS.js.map} +0 -0
  81. /package/dist/{mcp-6RCSHMXD.js.map → mcp-GNQQGD7X.js.map} +0 -0
package/dist/index.js CHANGED
@@ -3,6 +3,23 @@ import { defineCommand } from "citty";
3
3
  import { mkdir, writeFile } from "fs/promises";
4
4
  import { join } from "path";
5
5
 
6
+ // ../schema/dist/types.js
7
+ var SPEC_TYPES = [
8
+ "prd",
9
+ "technical-design",
10
+ "user-story",
11
+ "test-plan",
12
+ "adr",
13
+ "api-contract",
14
+ "epic",
15
+ "quick-spec",
16
+ "project-context"
17
+ ];
18
+ var DEPENDENCY_RELATIONSHIPS = {
19
+ "depends-on": "self-requires-target",
20
+ "implemented-by": "target-requires-self"
21
+ };
22
+
6
23
  // ../schema/dist/sections.js
7
24
  var REQUIRED_SECTIONS = {
8
25
  prd: ["Problem Statement", "Goals", "Non-Goals", "Features", "Success Criteria"],
@@ -33,30 +50,123 @@ var base_spec_default = {
33
50
  $schema: "http://json-schema.org/draft-07/schema#",
34
51
  type: "object",
35
52
  properties: {
36
- id: { type: "string", minLength: 1 },
37
- type: { type: "string", enum: ["prd", "technical-design", "user-story", "test-plan", "adr", "api-contract", "epic", "quick-spec", "project-context"] },
38
- title: { type: "string", minLength: 1 },
39
- status: { type: "string", enum: ["draft", "review", "approved", "superseded"] },
40
- version: { type: "string" },
41
- created: { type: "string", format: "date" },
42
- updated: { type: "string", format: "date" },
43
- authors: { type: "array", items: { type: "string" }, minItems: 1 },
44
- tags: { type: "array", items: { type: "string" }, default: [] },
53
+ id: {
54
+ type: "string",
55
+ minLength: 1
56
+ },
57
+ type: {
58
+ type: "string",
59
+ enum: [
60
+ "prd",
61
+ "technical-design",
62
+ "user-story",
63
+ "test-plan",
64
+ "adr",
65
+ "api-contract",
66
+ "epic",
67
+ "quick-spec",
68
+ "project-context"
69
+ ]
70
+ },
71
+ title: {
72
+ type: "string",
73
+ minLength: 1
74
+ },
75
+ status: {
76
+ type: "string",
77
+ enum: [
78
+ "draft",
79
+ "review",
80
+ "approved",
81
+ "superseded"
82
+ ]
83
+ },
84
+ version: {
85
+ type: "string"
86
+ },
87
+ created: {
88
+ type: "string",
89
+ format: "date"
90
+ },
91
+ updated: {
92
+ type: "string",
93
+ format: "date"
94
+ },
95
+ authors: {
96
+ type: "array",
97
+ items: {
98
+ type: "string"
99
+ },
100
+ minItems: 1
101
+ },
102
+ tags: {
103
+ type: "array",
104
+ items: {
105
+ type: "string"
106
+ },
107
+ default: []
108
+ },
45
109
  references: {
46
110
  type: "array",
47
111
  items: {
48
112
  type: "object",
49
113
  properties: {
50
- id: { type: "string" },
51
- relationship: { type: "string", enum: ["implemented-by", "decomposed-into", "depends-on", "supersedes", "related-to"] }
114
+ id: {
115
+ type: "string"
116
+ },
117
+ relationship: {
118
+ type: "string",
119
+ enum: [
120
+ "implemented-by",
121
+ "decomposed-into",
122
+ "depends-on",
123
+ "supersedes",
124
+ "related-to"
125
+ ]
126
+ }
127
+ },
128
+ required: [
129
+ "id",
130
+ "relationship"
131
+ ],
132
+ additionalProperties: false
133
+ },
134
+ default: []
135
+ },
136
+ artifacts: {
137
+ type: "array",
138
+ items: {
139
+ type: "object",
140
+ properties: {
141
+ path: {
142
+ type: "string",
143
+ minLength: 1
144
+ },
145
+ exports: {
146
+ type: "array",
147
+ items: {
148
+ type: "string",
149
+ minLength: 1
150
+ }
151
+ }
52
152
  },
53
- required: ["id", "relationship"],
153
+ required: [
154
+ "path"
155
+ ],
54
156
  additionalProperties: false
55
157
  },
56
158
  default: []
57
159
  }
58
160
  },
59
- required: ["id", "type", "title", "status", "version", "created", "authors"],
161
+ required: [
162
+ "id",
163
+ "type",
164
+ "title",
165
+ "status",
166
+ "version",
167
+ "created",
168
+ "authors"
169
+ ],
60
170
  additionalProperties: true
61
171
  };
62
172
 
@@ -81,7 +191,7 @@ var config_default = {
81
191
  type: "object",
82
192
  properties: {
83
193
  path: { type: "string" },
84
- type: { type: "string", enum: ["prd", "technical-design", "user-story", "test-plan", "adr", "api-contract"] },
194
+ type: { type: "string", enum: ["prd", "technical-design", "user-story", "test-plan", "adr", "api-contract", "epic", "quick-spec", "project-context"] },
85
195
  required: { type: "boolean", default: false },
86
196
  requires: { type: "array", items: { type: "string" } },
87
197
  owner: { type: "string" }
@@ -290,9 +400,13 @@ var project_context_default = {
290
400
  // ../schema/dist/validator.js
291
401
  import * as addFormatsNs from "ajv-formats";
292
402
  var addFormats = addFormatsNs.default ?? addFormatsNs;
403
+ var runtimeBaseSpecSchema = structuredClone(base_spec_default);
404
+ runtimeBaseSpecSchema.properties.type.enum = [...SPEC_TYPES];
405
+ var runtimeConfigSchema = structuredClone(config_default);
406
+ runtimeConfigSchema.properties.specs.additionalProperties.properties.type.enum = [...SPEC_TYPES];
293
407
  var ajv = new AjvClass({ allErrors: true, strict: true });
294
408
  addFormats(ajv, ["date"]);
295
- ajv.addSchema(base_spec_default);
409
+ ajv.addSchema(runtimeBaseSpecSchema);
296
410
  var specValidators = {
297
411
  prd: ajv.compile(prd_default),
298
412
  "technical-design": ajv.compile(technical_design_default),
@@ -304,7 +418,7 @@ var specValidators = {
304
418
  "quick-spec": ajv.compile(quick_spec_default),
305
419
  "project-context": ajv.compile(project_context_default)
306
420
  };
307
- var configValidator = ajv.compile(config_default);
421
+ var configValidator = ajv.compile(runtimeConfigSchema);
308
422
  function validateSpec(type, data) {
309
423
  const validate = specValidators[type];
310
424
  if (!validate) {
@@ -699,6 +813,112 @@ function buildGraph(config) {
699
813
  };
700
814
  }
701
815
 
816
+ // ../core/dist/relations.js
817
+ function mapEntriesToIds(config, specsByEntry) {
818
+ const entryIds = /* @__PURE__ */ new Map();
819
+ for (const key of Object.keys(config.specs)) {
820
+ const ids = [];
821
+ for (const spec of specsByEntry.get(key) ?? []) {
822
+ const id = spec.frontmatter.id;
823
+ if (typeof id === "string")
824
+ ids.push(id);
825
+ }
826
+ entryIds.set(key, ids);
827
+ }
828
+ return entryIds;
829
+ }
830
+ function collectKnownIds(specsByEntry) {
831
+ const ids = /* @__PURE__ */ new Set();
832
+ for (const specs of specsByEntry.values()) {
833
+ for (const spec of specs) {
834
+ const id = spec.frontmatter.id;
835
+ if (typeof id === "string")
836
+ ids.add(id);
837
+ }
838
+ }
839
+ return ids;
840
+ }
841
+ function walk(specId, adjacency) {
842
+ const visited = /* @__PURE__ */ new Set();
843
+ const stack = [specId];
844
+ while (stack.length > 0) {
845
+ const current = stack.pop();
846
+ for (const next of adjacency.get(current) ?? []) {
847
+ if (!visited.has(next)) {
848
+ visited.add(next);
849
+ stack.push(next);
850
+ }
851
+ }
852
+ }
853
+ visited.delete(specId);
854
+ return [...visited];
855
+ }
856
+ function buildRelationResolver(config, specsByEntry) {
857
+ const entryIds = config ? mapEntriesToIds(config, specsByEntry) : /* @__PURE__ */ new Map();
858
+ const knownIds = collectKnownIds(specsByEntry);
859
+ const edgeSources = /* @__PURE__ */ new Map();
860
+ const addEdge = (from, to, source) => {
861
+ if (from === to)
862
+ return;
863
+ const key = `${from}\0${to}`;
864
+ const existing = edgeSources.get(key);
865
+ if (!existing) {
866
+ edgeSources.set(key, source);
867
+ } else if (existing !== source) {
868
+ edgeSources.set(key, "both");
869
+ }
870
+ };
871
+ for (const [key, entry] of Object.entries(config?.specs ?? {})) {
872
+ const requires = entry.requires ?? [];
873
+ for (const dep of requires) {
874
+ for (const from of entryIds.get(dep) ?? []) {
875
+ for (const to of entryIds.get(key) ?? []) {
876
+ addEdge(from, to, "requires");
877
+ }
878
+ }
879
+ }
880
+ }
881
+ for (const specs of specsByEntry.values()) {
882
+ for (const spec of specs) {
883
+ const selfId = spec.frontmatter.id;
884
+ if (typeof selfId !== "string")
885
+ continue;
886
+ const refs = spec.frontmatter.references;
887
+ if (!Array.isArray(refs))
888
+ continue;
889
+ for (const ref of refs) {
890
+ if (!ref || typeof ref !== "object")
891
+ continue;
892
+ const { id: targetId, relationship } = ref;
893
+ if (typeof targetId !== "string" || typeof relationship !== "string")
894
+ continue;
895
+ if (!knownIds.has(targetId))
896
+ continue;
897
+ const direction = DEPENDENCY_RELATIONSHIPS[relationship];
898
+ if (direction === "self-requires-target") {
899
+ addEdge(targetId, selfId, "references");
900
+ } else if (direction === "target-requires-self") {
901
+ addEdge(selfId, targetId, "references");
902
+ }
903
+ }
904
+ }
905
+ }
906
+ const edges = [];
907
+ const downstreamAdj = /* @__PURE__ */ new Map();
908
+ const upstreamAdj = /* @__PURE__ */ new Map();
909
+ for (const [key, source] of edgeSources) {
910
+ const [from, to] = key.split("\0");
911
+ edges.push({ from, to, source });
912
+ downstreamAdj.set(from, [...downstreamAdj.get(from) ?? [], to]);
913
+ upstreamAdj.set(to, [...upstreamAdj.get(to) ?? [], from]);
914
+ }
915
+ return {
916
+ edges,
917
+ getUpstream: (specId) => walk(specId, upstreamAdj),
918
+ getDownstream: (specId) => walk(specId, downstreamAdj)
919
+ };
920
+ }
921
+
702
922
  // ../core/dist/glob.js
703
923
  import { glob } from "tinyglobby";
704
924
  import { join as join3, isAbsolute } from "path";
@@ -847,30 +1067,57 @@ var storyCoverageRule = {
847
1067
  };
848
1068
 
849
1069
  // ../lint/dist/rules/staleness-check.js
1070
+ function groupByEntry(config, specs) {
1071
+ const byEntry = /* @__PURE__ */ new Map();
1072
+ for (const key of Object.keys(config.specs))
1073
+ byEntry.set(key, []);
1074
+ for (const spec of specs) {
1075
+ let bestKey;
1076
+ let bestLen = -1;
1077
+ for (const [key, entry] of Object.entries(config.specs)) {
1078
+ const prefix = entry.path.split("*")[0] ?? "";
1079
+ const normalized = spec.filePath.replace(/\\/g, "/");
1080
+ if (normalized.includes(prefix) && prefix.length > bestLen) {
1081
+ bestKey = key;
1082
+ bestLen = prefix.length;
1083
+ }
1084
+ }
1085
+ if (bestKey)
1086
+ byEntry.get(bestKey).push(spec);
1087
+ }
1088
+ return byEntry;
1089
+ }
1090
+ function lastUpdated(spec) {
1091
+ return spec.frontmatter.updated ?? spec.frontmatter.created ?? "";
1092
+ }
850
1093
  var stalenessCheckRule = {
851
1094
  id: "freshness/staleness-check",
852
1095
  description: "Warns if a spec hasn't been updated since its upstream dependency changed",
853
1096
  severity: "warn",
854
1097
  run(context) {
855
- const refs = context.spec.frontmatter.references;
856
- if (!refs || refs.length === 0)
1098
+ const specId = context.spec.frontmatter.id;
1099
+ if (typeof specId !== "string")
1100
+ return [];
1101
+ const specUpdated = lastUpdated(context.spec);
1102
+ if (!specUpdated)
857
1103
  return [];
858
- const specUpdated = context.spec.frontmatter.updated ?? context.spec.frontmatter.created;
859
1104
  const specDate = new Date(specUpdated);
1105
+ const byEntry = context.config ? groupByEntry(context.config, context.allSpecs) : /* @__PURE__ */ new Map([["", context.allSpecs]]);
1106
+ const relations = buildRelationResolver(context.config, byEntry);
1107
+ const upstreamIds = relations.getUpstream(specId);
860
1108
  const diagnostics = [];
861
- for (const ref of refs) {
862
- if (ref.relationship !== "depends-on" && ref.relationship !== "implemented-by")
863
- continue;
864
- const upstream = context.allSpecs.find((s) => s.frontmatter.id === ref.id);
1109
+ for (const upstreamId of upstreamIds) {
1110
+ const upstream = context.allSpecs.find((s) => s.frontmatter.id === upstreamId);
865
1111
  if (!upstream)
866
1112
  continue;
867
- const upstreamUpdated = upstream.frontmatter.updated ?? upstream.frontmatter.created;
868
- const upstreamDate = new Date(upstreamUpdated);
869
- if (upstreamDate > specDate) {
1113
+ const upstreamUpdated = lastUpdated(upstream);
1114
+ if (!upstreamUpdated)
1115
+ continue;
1116
+ if (new Date(upstreamUpdated) > specDate) {
870
1117
  diagnostics.push({
871
1118
  ruleId: "freshness/staleness-check",
872
1119
  severity: "warn",
873
- message: `Potentially stale: upstream "${upstream.frontmatter.id}" was updated on ${upstreamUpdated}, but this spec was last updated on ${specUpdated}`,
1120
+ message: `Potentially stale: upstream "${upstreamId}" was updated on ${upstreamUpdated}, but this spec was last updated on ${specUpdated}`,
874
1121
  filePath: context.spec.filePath
875
1122
  });
876
1123
  }
@@ -1017,7 +1264,13 @@ var EDGE_CASE_KEYWORDS = [
1017
1264
  "missing",
1018
1265
  "malformed",
1019
1266
  "overflow",
1020
- "duplicate"
1267
+ "duplicate",
1268
+ "graceful",
1269
+ "fall back",
1270
+ "fallback",
1271
+ "crash",
1272
+ "nonexistent",
1273
+ "corrupt"
1021
1274
  ];
1022
1275
  var edgeCaseCoverageRule = {
1023
1276
  id: "completeness/edge-case-coverage",
@@ -1247,7 +1500,6 @@ async function runLint(options) {
1247
1500
  for (const [, entry] of Object.entries(config.specs)) {
1248
1501
  const files = await resolveGlob(entry.path, options.configDir);
1249
1502
  for (const file of files) {
1250
- if (options.specPath && !file.includes(options.specPath)) continue;
1251
1503
  specs.push(await parseSpec(file));
1252
1504
  }
1253
1505
  }
@@ -1260,6 +1512,12 @@ async function runLint(options) {
1260
1512
  }
1261
1513
  const engine = createLintEngine({ rules, config, graph });
1262
1514
  const results = engine.lint(specs);
1515
+ if (options.specPath) {
1516
+ const specPath = options.specPath;
1517
+ results.diagnostics = results.diagnostics.filter((d) => d.filePath.includes(specPath));
1518
+ results.hasErrors = results.diagnostics.some((d) => d.severity === "error");
1519
+ results.hasWarnings = results.diagnostics.some((d) => d.severity === "warn");
1520
+ }
1263
1521
  if (graphError) {
1264
1522
  results.diagnostics.push({
1265
1523
  ruleId: "structure/no-circular-deps",
@@ -1269,7 +1527,7 @@ async function runLint(options) {
1269
1527
  });
1270
1528
  results.hasErrors = true;
1271
1529
  }
1272
- return results;
1530
+ return { ...results, specCount: specs.length, assessed: specs.length > 0 };
1273
1531
  }
1274
1532
  var lint_default = defineCommand2({
1275
1533
  meta: { name: "lint", description: "Lint all specs in the suite" },
@@ -1291,6 +1549,12 @@ var lint_default = defineCommand2({
1291
1549
  preset: args.preset
1292
1550
  });
1293
1551
  const formatter = args.format === "json" ? formatJson : args.format === "github" ? formatGithub : formatPretty;
1552
+ if (!results.assessed) {
1553
+ console.error(
1554
+ "\n \u26A0 No specs found \u2014 nothing was linted. Check the spec paths in spec.config.yaml.\n"
1555
+ );
1556
+ process.exit(3);
1557
+ }
1294
1558
  console.log(formatter(results.diagnostics));
1295
1559
  if (results.hasErrors) process.exit(1);
1296
1560
  } catch (err) {
@@ -1389,6 +1653,7 @@ var WEIGHT_TAGS = 3;
1389
1653
  var WEIGHT_TITLE = 3;
1390
1654
  var WEIGHT_SECTIONS = 2;
1391
1655
  var WEIGHT_BODY = 1;
1656
+ var ID_MATCH_MIN_LENGTH = 3;
1392
1657
  var GRAPH_BOOST_FACTOR = 0.5;
1393
1658
  var SCORE_THRESHOLD = 0.1;
1394
1659
  function scoreSpecs(specs, task, graph) {
@@ -1408,9 +1673,15 @@ function scoreSpecs(specs, task, graph) {
1408
1673
  }
1409
1674
  const rawScores = /* @__PURE__ */ new Map();
1410
1675
  const matchedMap = /* @__PURE__ */ new Map();
1676
+ const idMatchedSet = /* @__PURE__ */ new Set();
1677
+ const taskLower = (task ?? "").toLowerCase();
1411
1678
  for (const [specId, spec] of specs) {
1412
1679
  let weightedHits = 0;
1413
1680
  const matched = /* @__PURE__ */ new Set();
1681
+ const idLower = specId.toLowerCase();
1682
+ if (idLower.length >= ID_MATCH_MIN_LENGTH && taskLower.includes(idLower)) {
1683
+ idMatchedSet.add(specId);
1684
+ }
1414
1685
  for (const keyword of keywords) {
1415
1686
  let hit = false;
1416
1687
  const tags = spec.frontmatter.tags ?? [];
@@ -1482,7 +1753,8 @@ function scoreSpecs(specs, task, graph) {
1482
1753
  const results = [];
1483
1754
  for (const [specId] of specs) {
1484
1755
  const combined = finalRawScores.get(specId) ?? 0;
1485
- const normalized = maxScore > 0 ? combined / maxScore : 0;
1756
+ const idMatched = idMatchedSet.has(specId);
1757
+ const normalized = idMatched ? 1 : maxScore > 0 ? combined / maxScore : 0;
1486
1758
  if (normalized < SCORE_THRESHOLD)
1487
1759
  continue;
1488
1760
  results.push({
@@ -1490,10 +1762,11 @@ function scoreSpecs(specs, task, graph) {
1490
1762
  score: normalized,
1491
1763
  rawScore: rawScores.get(specId) ?? 0,
1492
1764
  matchedKeywords: [...matchedMap.get(specId) ?? []],
1493
- graphBoosted: boostedSet.has(specId)
1765
+ graphBoosted: boostedSet.has(specId),
1766
+ idMatched
1494
1767
  });
1495
1768
  }
1496
- results.sort((a, b) => b.score - a.score);
1769
+ results.sort((a, b) => b.score - a.score || Number(b.idMatched ?? false) - Number(a.idMatched ?? false));
1497
1770
  return results;
1498
1771
  }
1499
1772
  function scoreSpecsByIds(specs, specIds, graph) {
@@ -1586,6 +1859,69 @@ function compressSpec(specId, type, title, status, updatedDate, parsedSections,
1586
1859
  }
1587
1860
 
1588
1861
  // ../pack/dist/allocator.js
1862
+ var HIGH_RELEVANCE = 0.75;
1863
+ var MIN_TRIM_BUDGET = 150;
1864
+ function omissionMarker(sections) {
1865
+ const names = sections.map((s) => s.heading || "(untitled)");
1866
+ const noun = names.length === 1 ? "section" : "sections";
1867
+ return `[${names.length} ${noun} omitted to fit token budget: ${names.join(", ")}]`;
1868
+ }
1869
+ function trimToBudget(compressed, budget) {
1870
+ const sections = compressed.sections;
1871
+ let reserve = 0;
1872
+ for (; ; ) {
1873
+ const effective = budget - reserve;
1874
+ const keep = new Array(sections.length).fill(false);
1875
+ let used = 0;
1876
+ let keptReal = false;
1877
+ for (let i = 0; i < sections.length; i++) {
1878
+ if (used + sections[i].tokens <= effective) {
1879
+ keep[i] = true;
1880
+ used += sections[i].tokens;
1881
+ keptReal = true;
1882
+ }
1883
+ }
1884
+ if (!keptReal)
1885
+ return null;
1886
+ const runs = [];
1887
+ for (let i = 0; i < sections.length; i++) {
1888
+ if (keep[i])
1889
+ continue;
1890
+ const start = i;
1891
+ const run = [];
1892
+ while (i < sections.length && !keep[i]) {
1893
+ run.push(sections[i]);
1894
+ i++;
1895
+ }
1896
+ i--;
1897
+ const marker = omissionMarker(run);
1898
+ runs.push({ start, sections: run, marker, markerTokens: countTokens(marker) });
1899
+ }
1900
+ const markerTokens = runs.reduce((sum, r) => sum + r.markerTokens, 0);
1901
+ if (markerTokens > reserve) {
1902
+ reserve = markerTokens;
1903
+ continue;
1904
+ }
1905
+ const out = [];
1906
+ for (let i = 0; i < sections.length; i++) {
1907
+ const run = runs.find((r) => r.start === i);
1908
+ if (run) {
1909
+ out.push({
1910
+ heading: "",
1911
+ content: run.marker,
1912
+ tokens: run.markerTokens,
1913
+ compressed: true,
1914
+ originalTokens: run.sections.reduce((sum, s) => sum + s.tokens, 0),
1915
+ omittedSections: run.sections.length
1916
+ });
1917
+ i += run.sections.length - 1;
1918
+ continue;
1919
+ }
1920
+ out.push(sections[i]);
1921
+ }
1922
+ return { spec: { ...compressed, sections: out }, tokens: used + markerTokens };
1923
+ }
1924
+ }
1589
1925
  function allocate(specs, scores, options) {
1590
1926
  const specMap = /* @__PURE__ */ new Map();
1591
1927
  for (const spec of specs) {
@@ -1623,9 +1959,9 @@ function allocate(specs, scores, options) {
1623
1959
  tokens += section.tokens;
1624
1960
  }
1625
1961
  }
1626
- items.push({ compressed, relevance: score.score, tokens });
1962
+ items.push({ compressed, relevance: score.score, tokens, idMatched: score.idMatched ?? false });
1627
1963
  }
1628
- items.sort((a, b) => b.relevance - a.relevance);
1964
+ items.sort((a, b) => b.relevance - a.relevance || Number(b.idMatched) - Number(a.idMatched));
1629
1965
  const totalTokens = items.reduce((sum, item) => sum + item.tokens, 0);
1630
1966
  const withinBudget = totalTokens <= options.budget;
1631
1967
  const included = [];
@@ -1641,17 +1977,28 @@ function allocate(specs, scores, options) {
1641
1977
  if (usedTokens + item.tokens <= options.budget) {
1642
1978
  included.push(item);
1643
1979
  usedTokens += item.tokens;
1644
- } else {
1645
- excluded.push(item);
1980
+ continue;
1646
1981
  }
1982
+ const remaining = options.budget - usedTokens;
1983
+ if ((item.idMatched || item.relevance >= HIGH_RELEVANCE) && remaining >= MIN_TRIM_BUDGET && !item.compressed.collapsed) {
1984
+ const trimmed = trimToBudget(item.compressed, remaining);
1985
+ if (trimmed) {
1986
+ included.push({ ...item, compressed: trimmed.spec, tokens: trimmed.tokens });
1987
+ usedTokens += trimmed.tokens;
1988
+ continue;
1989
+ }
1990
+ }
1991
+ excluded.push(item);
1647
1992
  }
1648
1993
  }
1649
1994
  let sectionsCompressed = 0;
1995
+ let sectionsOmitted = 0;
1650
1996
  for (const item of included) {
1651
1997
  for (const section of item.compressed.sections) {
1652
1998
  if (section.compressed) {
1653
1999
  sectionsCompressed++;
1654
2000
  }
2001
+ sectionsOmitted += section.omittedSections ?? 0;
1655
2002
  }
1656
2003
  }
1657
2004
  const allocations = [];
@@ -1681,6 +2028,7 @@ function allocate(specs, scores, options) {
1681
2028
  specsIncluded: included.length,
1682
2029
  specsExcluded: excluded.length,
1683
2030
  sectionsCompressed,
2031
+ sectionsOmitted,
1684
2032
  allocations
1685
2033
  };
1686
2034
  return {
@@ -1695,7 +2043,7 @@ function escapeXml(text) {
1695
2043
  }
1696
2044
  function formatXml(specs, stats) {
1697
2045
  const lines = [];
1698
- lines.push(`<context budget="${stats.budget}" used="${stats.used}" specs="${stats.specsIncluded}" compressed="${stats.sectionsCompressed}">`);
2046
+ lines.push(`<context budget="${stats.budget}" used="${stats.used}" specs="${stats.specsIncluded}" compressed="${stats.sectionsCompressed}" omitted="${stats.sectionsOmitted}">`);
1699
2047
  for (const spec of specs) {
1700
2048
  const alloc = stats.allocations.find((a) => a.specId === spec.specId);
1701
2049
  const relevance = alloc?.relevance ?? 0;
@@ -1754,6 +2102,7 @@ function formatJson2(specs, stats) {
1754
2102
  const output = {
1755
2103
  budget: stats.budget,
1756
2104
  used: stats.used,
2105
+ sectionsOmitted: stats.sectionsOmitted,
1757
2106
  specs: specs.map((spec) => {
1758
2107
  const alloc = stats.allocations.find((a) => a.specId === spec.specId);
1759
2108
  const relevance = alloc?.relevance ?? 0;
@@ -1997,7 +2346,8 @@ var pack_default = defineCommand3({
1997
2346
  console.log(
1998
2347
  ` Included: ${stats.specsIncluded} / ${stats.specsIncluded + stats.specsExcluded} specs`
1999
2348
  );
2000
- console.log(` Sections compressed: ${stats.sectionsCompressed}
2349
+ console.log(` Sections compressed: ${stats.sectionsCompressed}`);
2350
+ console.log(` Sections omitted: ${stats.sectionsOmitted}
2001
2351
  `);
2002
2352
  return;
2003
2353
  }
@@ -2014,7 +2364,7 @@ var pack_default = defineCommand3({
2014
2364
  }
2015
2365
  const total = stats.specsIncluded + stats.specsExcluded;
2016
2366
  process.stderr.write(
2017
- `Packed ${stats.specsIncluded}/${total} specs \u2022 ${stats.used} / ${stats.budget} tokens \u2022 ${stats.sectionsCompressed} sections compressed
2367
+ `Packed ${stats.specsIncluded}/${total} specs \u2022 ${stats.used} / ${stats.budget} tokens \u2022 ${stats.sectionsCompressed} sections compressed \u2022 ${stats.sectionsOmitted} sections omitted
2018
2368
  `
2019
2369
  );
2020
2370
  } catch (err) {
@@ -2917,10 +3267,10 @@ var STRUCTURAL_SECTIONS = /* @__PURE__ */ new Set([
2917
3267
  "API Design",
2918
3268
  "Problem Statement"
2919
3269
  ]);
2920
- function bfsDistances(startId, graph) {
3270
+ function bfsDistances(startId, relations) {
2921
3271
  const distances = /* @__PURE__ */ new Map();
2922
3272
  const queue = [];
2923
- for (const edge of graph.edges) {
3273
+ for (const edge of relations.edges) {
2924
3274
  if (edge.from === startId) {
2925
3275
  if (!distances.has(edge.to)) {
2926
3276
  distances.set(edge.to, 1);
@@ -2931,7 +3281,7 @@ function bfsDistances(startId, graph) {
2931
3281
  while (queue.length > 0) {
2932
3282
  const item = queue.shift();
2933
3283
  const currentDist = item.distance;
2934
- for (const edge of graph.edges) {
3284
+ for (const edge of relations.edges) {
2935
3285
  if (edge.from === item.id && !distances.has(edge.to)) {
2936
3286
  distances.set(edge.to, currentDist + 1);
2937
3287
  queue.push({ id: edge.to, distance: currentDist + 1 });
@@ -2948,8 +3298,8 @@ function daysBetween(dateStr) {
2948
3298
  function clamp(min, max, value) {
2949
3299
  return Math.min(max, Math.max(min, value));
2950
3300
  }
2951
- function analyzeImpact(changedSpecId, diff2, graph, allSpecs, thresholdDays = 14) {
2952
- const distanceMap = bfsDistances(changedSpecId, graph);
3301
+ function analyzeImpact(changedSpecId, diff2, relations, allSpecs, thresholdDays = 14) {
3302
+ const distanceMap = bfsDistances(changedSpecId, relations);
2953
3303
  if (distanceMap.size === 0) {
2954
3304
  return {
2955
3305
  changedSpec: changedSpecId,
@@ -2968,11 +3318,11 @@ function analyzeImpact(changedSpecId, diff2, graph, allSpecs, thresholdDays = 14
2968
3318
  const downstream = [];
2969
3319
  for (const [specId, distance] of distanceMap) {
2970
3320
  const spec = specById.get(specId);
2971
- const lastUpdated = spec?.frontmatter.updated ?? spec?.frontmatter.created ?? null;
3321
+ const lastUpdated2 = spec?.frontmatter.updated ?? spec?.frontmatter.created ?? null;
2972
3322
  const filePath = spec?.filePath ?? `specs/${specId}.md`;
2973
3323
  let staleness;
2974
- if (lastUpdated) {
2975
- const daysSinceUpdate = daysBetween(lastUpdated);
3324
+ if (lastUpdated2) {
3325
+ const daysSinceUpdate = daysBetween(lastUpdated2);
2976
3326
  staleness = clamp(0, 1, daysSinceUpdate / thresholdDays * 0.5 + structuralSectionsChanged / totalSections * 0.3 + 1 / distance * 0.2);
2977
3327
  } else {
2978
3328
  staleness = clamp(0, 1, structuralSectionsChanged / totalSections * 0.3 + 1 / distance * 0.2);
@@ -2982,8 +3332,8 @@ function analyzeImpact(changedSpecId, diff2, graph, allSpecs, thresholdDays = 14
2982
3332
  if (structuralSectionsChanged > 0) {
2983
3333
  parts.push(`${structuralSectionsChanged} structural section(s) changed`);
2984
3334
  }
2985
- if (lastUpdated) {
2986
- const days = Math.round(daysBetween(lastUpdated));
3335
+ if (lastUpdated2) {
3336
+ const days = Math.round(daysBetween(lastUpdated2));
2987
3337
  parts.push(`last updated ${days} day(s) ago`);
2988
3338
  }
2989
3339
  const reason = parts.join("; ");
@@ -2991,7 +3341,7 @@ function analyzeImpact(changedSpecId, diff2, graph, allSpecs, thresholdDays = 14
2991
3341
  specId,
2992
3342
  filePath,
2993
3343
  distance,
2994
- lastUpdated,
3344
+ lastUpdated: lastUpdated2,
2995
3345
  staleness,
2996
3346
  reason
2997
3347
  });
@@ -3123,20 +3473,24 @@ async function diffBetweenRefs(configPath, baseRef, headRef) {
3123
3473
  }
3124
3474
  const added = changed.added.map((p) => specIdByPath.get(p)).filter((id) => id !== void 0);
3125
3475
  const removed = changed.deleted.map((p) => specIdByPath.get(p)).filter((id) => id !== void 0);
3126
- const graph = buildGraph(config);
3127
3476
  const impact = [];
3128
3477
  const allSpecs = [];
3129
- for (const entry of Object.values(config.specs)) {
3478
+ const specsByEntry = /* @__PURE__ */ new Map();
3479
+ for (const [key, entry] of Object.entries(config.specs)) {
3480
+ const forEntry = [];
3130
3481
  try {
3131
3482
  const content = gitShow(headRef, entry.path, projectRoot, repoRoot);
3132
3483
  const parsed = await parseSpecFromString(content, entry.path);
3484
+ forEntry.push(parsed);
3133
3485
  allSpecs.push(parsed);
3134
3486
  } catch {
3135
3487
  }
3488
+ specsByEntry.set(key, forEntry);
3136
3489
  }
3490
+ const relations = buildRelationResolver(config, specsByEntry);
3137
3491
  const thresholdDays = config.diff?.staleness_threshold_days ?? 14;
3138
3492
  for (const diff2 of diffs) {
3139
- const analysis = analyzeImpact(diff2.specId, diff2, graph, allSpecs, thresholdDays);
3493
+ const analysis = analyzeImpact(diff2.specId, diff2, relations, allSpecs, thresholdDays);
3140
3494
  if (analysis.totalAffected > 0) {
3141
3495
  impact.push(analysis);
3142
3496
  }
@@ -3191,58 +3545,65 @@ var diff_default = defineCommand4({
3191
3545
  },
3192
3546
  async run({ args }) {
3193
3547
  try {
3194
- const result = await runDiff({
3195
- base: args.base,
3196
- head: args.head,
3197
- spec: args.spec,
3198
- format: args.format
3199
- });
3200
- if (args.format === "json") {
3201
- console.log(JSON.stringify(result, null, 2));
3202
- return;
3203
- }
3204
- if (result.diffs.length === 0 && result.added.length === 0 && result.removed.length === 0) {
3205
- console.log(" \u2713 No spec changes detected.");
3206
- return;
3207
- }
3208
- console.log(result.summary);
3209
- console.log();
3210
- for (const diff2 of result.diffs) {
3211
- console.log(` ${diff2.specId}:`);
3212
- for (const fc of diff2.frontmatter) {
3213
- const detail = fc.before !== void 0 || fc.after !== void 0 ? ` (${String(fc.before)} \u2192 ${String(fc.after)})` : "";
3214
- console.log(` ${fc.type}: ${fc.field}${detail}`);
3548
+ try {
3549
+ const result = await runDiff({
3550
+ base: args.base,
3551
+ head: args.head,
3552
+ spec: args.spec,
3553
+ format: args.format
3554
+ });
3555
+ if (args.format === "json") {
3556
+ console.log(JSON.stringify(result, null, 2));
3557
+ return;
3215
3558
  }
3216
- for (const sc of diff2.sections) {
3217
- console.log(` ${sc.type}: ${sc.heading}`);
3559
+ if (result.diffs.length === 0 && result.added.length === 0 && result.removed.length === 0) {
3560
+ console.log(" \u2713 No spec changes detected.");
3561
+ return;
3218
3562
  }
3219
- }
3220
- if (result.added.length > 0) {
3221
- console.log(`
3563
+ console.log(result.summary);
3564
+ console.log();
3565
+ for (const diff2 of result.diffs) {
3566
+ console.log(` ${diff2.specId}:`);
3567
+ for (const fc of diff2.frontmatter) {
3568
+ const detail = fc.before !== void 0 || fc.after !== void 0 ? ` (${String(fc.before)} \u2192 ${String(fc.after)})` : "";
3569
+ console.log(` ${fc.type}: ${fc.field}${detail}`);
3570
+ }
3571
+ for (const sc of diff2.sections) {
3572
+ console.log(` ${sc.type}: ${sc.heading}`);
3573
+ }
3574
+ }
3575
+ if (result.added.length > 0) {
3576
+ console.log(`
3222
3577
  Added: ${result.added.join(", ")}`);
3223
- }
3224
- if (result.removed.length > 0) {
3225
- console.log(`
3578
+ }
3579
+ if (result.removed.length > 0) {
3580
+ console.log(`
3226
3581
  Removed: ${result.removed.join(", ")}`);
3227
- }
3228
- if (result.impact.length > 0) {
3229
- console.log("\n Downstream Impact:");
3230
- for (const impact of result.impact) {
3231
- for (const d of impact.downstream) {
3232
- console.log(
3233
- ` ${d.specId} \u2014 staleness: ${d.staleness.toFixed(2)} \u2014 ${d.reason}`
3234
- );
3582
+ }
3583
+ if (result.impact.length > 0) {
3584
+ console.log("\n Downstream Impact:");
3585
+ for (const impact of result.impact) {
3586
+ for (const d of impact.downstream) {
3587
+ console.log(
3588
+ ` ${d.specId} \u2014 staleness: ${d.staleness.toFixed(2)} \u2014 ${d.reason}`
3589
+ );
3590
+ }
3235
3591
  }
3236
3592
  }
3593
+ } catch (err) {
3594
+ if (err instanceof DiffError) {
3595
+ console.error(`
3596
+ \u2717 ${err.message}
3597
+ `);
3598
+ process.exit(1);
3599
+ }
3600
+ throw err;
3237
3601
  }
3238
3602
  } catch (err) {
3239
- if (err instanceof DiffError) {
3240
- console.error(`
3603
+ console.error(`
3241
3604
  \u2717 ${err.message}
3242
3605
  `);
3243
- process.exit(1);
3244
- }
3245
- throw err;
3606
+ process.exit(1);
3246
3607
  }
3247
3608
  }
3248
3609
  });
@@ -3318,6 +3679,7 @@ async function runStatus(_options = {}) {
3318
3679
  let verdict = "healthy";
3319
3680
  if (errors > 0) verdict = "errors";
3320
3681
  else if (warnings > 0 || staleSpecs.length > 0) verdict = "warnings";
3682
+ else if (specs.length === 0) verdict = "unassessed";
3321
3683
  return {
3322
3684
  project: config.project?.name ?? "unknown",
3323
3685
  specCount: specs.length,
@@ -3338,38 +3700,52 @@ var status_default = defineCommand5({
3338
3700
  }
3339
3701
  },
3340
3702
  async run({ args }) {
3341
- const result = await runStatus({ format: args.format });
3342
- if (args.format === "json") {
3343
- console.log(JSON.stringify(result, null, 2));
3344
- return;
3345
- }
3346
- if (args.format === "github") {
3347
- for (const s of result.staleSpecs) {
3348
- console.log(
3349
- `::warning::Spec "${s.specId}" is stale (${s.daysSinceUpdate} days since update)`
3350
- );
3703
+ try {
3704
+ const result = await runStatus({ format: args.format });
3705
+ if (args.format === "json") {
3706
+ console.log(JSON.stringify(result, null, 2));
3707
+ return;
3351
3708
  }
3352
- for (const issue of result.integrityIssues) {
3353
- console.log(`::error::${issue}`);
3709
+ if (args.format === "github") {
3710
+ for (const s of result.staleSpecs) {
3711
+ console.log(
3712
+ `::warning::Spec "${s.specId}" is stale (${s.daysSinceUpdate} days since update)`
3713
+ );
3714
+ }
3715
+ for (const issue of result.integrityIssues) {
3716
+ console.log(`::error::${issue}`);
3717
+ }
3718
+ return;
3354
3719
  }
3355
- return;
3356
- }
3357
- const icon = result.verdict === "healthy" ? "\u2713" : result.verdict === "warnings" ? "\u26A0" : "\u2717";
3358
- console.log(`
3720
+ const icon = result.verdict === "healthy" ? "\u2713" : result.verdict === "warnings" || result.verdict === "unassessed" ? "\u26A0" : "\u2717";
3721
+ console.log(`
3359
3722
  ${icon} ${result.project} \u2014 ${result.verdict}`);
3360
- console.log(
3361
- ` ${result.specCount} specs: ${Object.entries(result.byStatus).map(([k, v]) => `${v} ${k}`).join(", ")}`
3362
- );
3363
- console.log(` Lint: ${result.lintHealth.errors} errors, ${result.lintHealth.warnings} warnings`);
3364
- if (result.staleSpecs.length > 0) {
3723
+ if (result.verdict === "unassessed") {
3724
+ console.log(
3725
+ " No specs resolved \u2014 nothing was assessed. Check the spec paths in spec.config.yaml."
3726
+ );
3727
+ }
3365
3728
  console.log(
3366
- ` Stale: ${result.staleSpecs.map((s) => `${s.specId} (${s.daysSinceUpdate}d)`).join(", ")}`
3729
+ ` ${result.specCount} specs: ${Object.entries(result.byStatus).map(([k, v]) => `${v} ${k}`).join(", ")}`
3367
3730
  );
3731
+ console.log(
3732
+ ` Lint: ${result.lintHealth.errors} errors, ${result.lintHealth.warnings} warnings`
3733
+ );
3734
+ if (result.staleSpecs.length > 0) {
3735
+ console.log(
3736
+ ` Stale: ${result.staleSpecs.map((s) => `${s.specId} (${s.daysSinceUpdate}d)`).join(", ")}`
3737
+ );
3738
+ }
3739
+ if (result.integrityIssues.length > 0) {
3740
+ console.log(` Issues: ${result.integrityIssues.join("; ")}`);
3741
+ }
3742
+ console.log();
3743
+ } catch (err) {
3744
+ console.error(`
3745
+ \u2717 ${err.message}
3746
+ `);
3747
+ process.exit(1);
3368
3748
  }
3369
- if (result.integrityIssues.length > 0) {
3370
- console.log(` Issues: ${result.integrityIssues.join("; ")}`);
3371
- }
3372
- console.log();
3373
3749
  }
3374
3750
  });
3375
3751
 
@@ -3431,16 +3807,23 @@ var changelog_default = defineCommand6({
3431
3807
  },
3432
3808
  async run({ args }) {
3433
3809
  try {
3434
- const output = await runChangelog(args);
3435
- console.log(output);
3436
- } catch (err) {
3437
- if (err instanceof DiffError) {
3438
- console.error(`
3810
+ try {
3811
+ const output = await runChangelog(args);
3812
+ console.log(output);
3813
+ } catch (err) {
3814
+ if (err instanceof DiffError) {
3815
+ console.error(`
3439
3816
  \u2717 ${err.message}
3440
3817
  `);
3441
- process.exit(1);
3818
+ process.exit(1);
3819
+ }
3820
+ throw err;
3442
3821
  }
3443
- throw err;
3822
+ } catch (err) {
3823
+ console.error(`
3824
+ \u2717 ${err.message}
3825
+ `);
3826
+ process.exit(1);
3444
3827
  }
3445
3828
  }
3446
3829
  });
@@ -3503,35 +3886,42 @@ var explain_default = defineCommand7({
3503
3886
  format: { type: "string", description: "Output format: pretty, json", default: "pretty" }
3504
3887
  },
3505
3888
  async run({ args }) {
3506
- const result = await runExplain({ format: args.format });
3507
- if (args.format === "json") {
3508
- console.log(JSON.stringify(result, null, 2));
3509
- return;
3510
- }
3511
- console.log(`
3889
+ try {
3890
+ const result = await runExplain({ format: args.format });
3891
+ if (args.format === "json") {
3892
+ console.log(JSON.stringify(result, null, 2));
3893
+ return;
3894
+ }
3895
+ console.log(`
3512
3896
  ${result.project}`);
3513
- if (result.description) {
3514
- console.log(` ${result.description}`);
3515
- }
3516
- console.log(
3517
- `
3897
+ if (result.description) {
3898
+ console.log(` ${result.description}`);
3899
+ }
3900
+ console.log(
3901
+ `
3518
3902
  ${result.specCount} specs: ${Object.entries(result.byType).map(([k, v]) => `${v} ${k}`).join(", ")}`
3519
- );
3520
- console.log(
3521
- ` Status: ${Object.entries(result.byStatus).map(([k, v]) => `${v} ${k}`).join(", ")}`
3522
- );
3523
- console.log("\n Specs:");
3524
- for (const spec of result.specs) {
3525
- console.log(` ${spec.id} (${spec.type}, ${spec.status}) \u2014 ${spec.title}`);
3526
- if (spec.firstLine) {
3527
- console.log(` ${spec.firstLine}`);
3528
- }
3529
- }
3530
- console.log("\n Dependencies:");
3531
- for (const line of result.graph) {
3532
- console.log(` ${line}`);
3533
- }
3534
- console.log();
3903
+ );
3904
+ console.log(
3905
+ ` Status: ${Object.entries(result.byStatus).map(([k, v]) => `${v} ${k}`).join(", ")}`
3906
+ );
3907
+ console.log("\n Specs:");
3908
+ for (const spec of result.specs) {
3909
+ console.log(` ${spec.id} (${spec.type}, ${spec.status}) \u2014 ${spec.title}`);
3910
+ if (spec.firstLine) {
3911
+ console.log(` ${spec.firstLine}`);
3912
+ }
3913
+ }
3914
+ console.log("\n Dependencies:");
3915
+ for (const line of result.graph) {
3916
+ console.log(` ${line}`);
3917
+ }
3918
+ console.log();
3919
+ } catch (err) {
3920
+ console.error(`
3921
+ \u2717 ${err.message}
3922
+ `);
3923
+ process.exit(1);
3924
+ }
3535
3925
  }
3536
3926
  });
3537
3927
  export {