specdx 0.4.0-alpha.6 → 0.4.0-alpha.8

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 (65) hide show
  1. package/dist/{changelog-XPX4LD7B.js → changelog-FJIQBEBB.js} +4 -4
  2. package/dist/{check-5GQPH66L.js → check-ULQYDDRD.js} +8 -6
  3. package/dist/check-ULQYDDRD.js.map +1 -0
  4. package/dist/{chunk-RVVQKLNL.js → chunk-7JXW2GTJ.js} +107 -14
  5. package/dist/chunk-7JXW2GTJ.js.map +1 -0
  6. package/dist/{chunk-VIYRGPX5.js → chunk-AKNPCB37.js} +64 -25
  7. package/dist/chunk-AKNPCB37.js.map +1 -0
  8. package/dist/{chunk-KAWB5K44.js → chunk-DAZCOUVK.js} +2 -2
  9. package/dist/{chunk-GTMNEGQG.js → chunk-IHTYAW7C.js} +4 -4
  10. package/dist/chunk-IHTYAW7C.js.map +1 -0
  11. package/dist/{chunk-UKSPVBYC.js → chunk-OTDEP6WZ.js} +106 -8
  12. package/dist/chunk-OTDEP6WZ.js.map +1 -0
  13. package/dist/{chunk-WQJLG5KJ.js → chunk-UZ2E6LX7.js} +2 -2
  14. package/dist/{diff-WH4KL2AK.js → diff-ZN2YTGE2.js} +4 -4
  15. package/dist/dist-4MXKMRHE.js +15 -0
  16. package/dist/{dist-ZOIXQ2UW.js → dist-HKVTEPU5.js} +11 -7
  17. package/dist/dist-HKVTEPU5.js.map +1 -0
  18. package/dist/{explain-JFKOAFCD.js → explain-QBV3AESQ.js} +3 -3
  19. package/dist/{generate-33LQORSQ.js → generate-7GNPT2WJ.js} +3 -3
  20. package/dist/{generate-story-EOU6CEHU.js → generate-story-EFHGINHA.js} +3 -3
  21. package/dist/{generate-test-plan-MRK5MFZA.js → generate-test-plan-BO7444RG.js} +3 -3
  22. package/dist/{graph-7PUHYZ5G.js → graph-5XINV7PT.js} +15 -5
  23. package/dist/graph-5XINV7PT.js.map +1 -0
  24. package/dist/index.js +177 -39
  25. package/dist/index.js.map +1 -1
  26. package/dist/{lint-KA4RRYY7.js → lint-PGA7JFKM.js} +10 -5
  27. package/dist/lint-PGA7JFKM.js.map +1 -0
  28. package/dist/main.js +16 -16
  29. package/dist/main.js.map +1 -1
  30. package/dist/{mcp-7PNSMMWB.js → mcp-QTIA76DS.js} +2 -2
  31. package/dist/{migrate-EGF6SSUE.js → migrate-4KF6GHLO.js} +3 -3
  32. package/dist/{pack-VONQOQFP.js → pack-DSOODXAN.js} +7 -6
  33. package/dist/{pack-VONQOQFP.js.map → pack-DSOODXAN.js.map} +1 -1
  34. package/dist/{ready-7YI7BYBE.js → ready-GTCDQOIC.js} +5 -5
  35. package/dist/skills/specdx-verify.md +9 -0
  36. package/dist/{status-ARUBEEOM.js → status-C3YDBH2L.js} +5 -5
  37. package/dist/{update-WD2YAEH4.js → update-ULMSL5XZ.js} +4 -4
  38. package/dist/validate-E7F3Q5BE.js +49 -0
  39. package/dist/validate-E7F3Q5BE.js.map +1 -0
  40. package/package.json +3 -3
  41. package/dist/check-5GQPH66L.js.map +0 -1
  42. package/dist/chunk-GTMNEGQG.js.map +0 -1
  43. package/dist/chunk-RVVQKLNL.js.map +0 -1
  44. package/dist/chunk-UKSPVBYC.js.map +0 -1
  45. package/dist/chunk-VIYRGPX5.js.map +0 -1
  46. package/dist/dist-U7CZLXM5.js +0 -11
  47. package/dist/dist-ZOIXQ2UW.js.map +0 -1
  48. package/dist/graph-7PUHYZ5G.js.map +0 -1
  49. package/dist/lint-KA4RRYY7.js.map +0 -1
  50. package/dist/validate-VPPQWEW5.js +0 -34
  51. package/dist/validate-VPPQWEW5.js.map +0 -1
  52. /package/dist/{changelog-XPX4LD7B.js.map → changelog-FJIQBEBB.js.map} +0 -0
  53. /package/dist/{chunk-KAWB5K44.js.map → chunk-DAZCOUVK.js.map} +0 -0
  54. /package/dist/{chunk-WQJLG5KJ.js.map → chunk-UZ2E6LX7.js.map} +0 -0
  55. /package/dist/{diff-WH4KL2AK.js.map → diff-ZN2YTGE2.js.map} +0 -0
  56. /package/dist/{dist-U7CZLXM5.js.map → dist-4MXKMRHE.js.map} +0 -0
  57. /package/dist/{explain-JFKOAFCD.js.map → explain-QBV3AESQ.js.map} +0 -0
  58. /package/dist/{generate-33LQORSQ.js.map → generate-7GNPT2WJ.js.map} +0 -0
  59. /package/dist/{generate-story-EOU6CEHU.js.map → generate-story-EFHGINHA.js.map} +0 -0
  60. /package/dist/{generate-test-plan-MRK5MFZA.js.map → generate-test-plan-BO7444RG.js.map} +0 -0
  61. /package/dist/{mcp-7PNSMMWB.js.map → mcp-QTIA76DS.js.map} +0 -0
  62. /package/dist/{migrate-EGF6SSUE.js.map → migrate-4KF6GHLO.js.map} +0 -0
  63. /package/dist/{ready-7YI7BYBE.js.map → ready-GTCDQOIC.js.map} +0 -0
  64. /package/dist/{status-ARUBEEOM.js.map → status-C3YDBH2L.js.map} +0 -0
  65. /package/dist/{update-WD2YAEH4.js.map → update-ULMSL5XZ.js.map} +0 -0
@@ -3,10 +3,10 @@ import {
3
3
  loadConfig,
4
4
  parseSpec,
5
5
  resolveGlob
6
- } from "./chunk-GTMNEGQG.js";
6
+ } from "./chunk-IHTYAW7C.js";
7
7
  import {
8
8
  REQUIRED_SECTIONS
9
- } from "./chunk-RVVQKLNL.js";
9
+ } from "./chunk-7JXW2GTJ.js";
10
10
 
11
11
  // src/commands/generate-story.ts
12
12
  import { defineCommand } from "citty";
@@ -193,4 +193,4 @@ export {
193
193
  defineCommandExport,
194
194
  generateStories
195
195
  };
196
- //# sourceMappingURL=generate-story-EOU6CEHU.js.map
196
+ //# sourceMappingURL=generate-story-EFHGINHA.js.map
@@ -3,8 +3,8 @@ import {
3
3
  loadConfig,
4
4
  parseSpec,
5
5
  resolveGlob
6
- } from "./chunk-GTMNEGQG.js";
7
- import "./chunk-RVVQKLNL.js";
6
+ } from "./chunk-IHTYAW7C.js";
7
+ import "./chunk-7JXW2GTJ.js";
8
8
 
9
9
  // src/commands/generate-test-plan.ts
10
10
  import { defineCommand } from "citty";
@@ -156,4 +156,4 @@ export {
156
156
  generate_test_plan_default as default,
157
157
  generateTestPlan
158
158
  };
159
- //# sourceMappingURL=generate-test-plan-MRK5MFZA.js.map
159
+ //# sourceMappingURL=generate-test-plan-BO7444RG.js.map
@@ -9,8 +9,8 @@ import {
9
9
  loadConfig,
10
10
  parseSpec,
11
11
  resolveGlob
12
- } from "./chunk-GTMNEGQG.js";
13
- import "./chunk-RVVQKLNL.js";
12
+ } from "./chunk-IHTYAW7C.js";
13
+ import "./chunk-7JXW2GTJ.js";
14
14
 
15
15
  // src/commands/graph.ts
16
16
  import { defineCommand } from "citty";
@@ -68,14 +68,24 @@ var graph_default = defineCommand({
68
68
  console.log(` ${ref.fromId} \u2014${ref.relationship}\u2192 ${ref.toId}`);
69
69
  }
70
70
  }
71
- if (unreflected.length > 0) {
71
+ const suggestions = unreflected.filter((u) => !u.createsCycle);
72
+ const conflicts = unreflected.filter((u) => u.createsCycle);
73
+ if (suggestions.length > 0) {
72
74
  console.log("\n \u26A0 References not reflected in config requires:\n");
73
- for (const { edge, requiringEntry, requiredEntry } of unreflected) {
75
+ for (const { edge, requiringEntry, requiredEntry } of suggestions) {
74
76
  console.log(
75
77
  ` ${edge.fromId} ${edge.relationship} ${edge.toId} \u2014 add "requires: [${requiredEntry}]" to the "${requiringEntry}" entry in spec.config.yaml`
76
78
  );
77
79
  }
78
80
  }
81
+ if (conflicts.length > 0) {
82
+ console.log("\n \u26A0 References that conflict with the requires chain:\n");
83
+ for (const { edge, requiringEntry, requiredEntry } of conflicts) {
84
+ console.log(
85
+ ` ${edge.fromId} ${edge.relationship} ${edge.toId} \u2014 implies "${requiringEntry}" requires "${requiredEntry}", but that would create a cycle; review the reference or the config requires`
86
+ );
87
+ }
88
+ }
79
89
  console.log("");
80
90
  } catch (err) {
81
91
  if (err instanceof GraphError) {
@@ -89,4 +99,4 @@ var graph_default = defineCommand({
89
99
  export {
90
100
  graph_default as default
91
101
  };
92
- //# sourceMappingURL=graph-7PUHYZ5G.js.map
102
+ //# sourceMappingURL=graph-5XINV7PT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/graph.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport {\n loadConfig,\n buildGraph,\n GraphError,\n parseSpec,\n resolveGlob,\n collectReferenceEdges,\n findUnreflectedReferences,\n} from \"@specdx/core\";\nimport type { ParsedSpec } from \"@specdx/core\";\nimport { sharedArgs } from \"../shared-args.js\";\n\nexport default defineCommand({\n meta: { name: \"graph\", description: \"Print the spec dependency graph\" },\n args: { ...sharedArgs },\n async run({ args }) {\n let config;\n const configDir = process.cwd();\n try {\n config = await loadConfig(undefined, configDir);\n } catch (err) {\n console.error(`\\n ✗ ${(err as Error).message}\\n`);\n process.exit(1);\n }\n try {\n const graph = buildGraph(config);\n const sorted = graph.topologicalSort();\n\n // Frontmatter references are a second, richer source of relationships;\n // surface them alongside config requires instead of silently ignoring\n // them (issue #8).\n const idToEntry = new Map<string, string>();\n const specs: ParsedSpec[] = [];\n for (const [key, entry] of Object.entries(config.specs)) {\n const paths = await resolveGlob(entry.path, configDir);\n for (const p of paths) {\n const spec = await parseSpec(p);\n specs.push(spec);\n if (typeof spec.frontmatter.id === \"string\") {\n idToEntry.set(spec.frontmatter.id, key);\n }\n }\n }\n const referenceEdges = collectReferenceEdges(specs);\n const unreflected = findUnreflectedReferences(referenceEdges, idToEntry, graph);\n\n if (args.format === \"dot\") {\n console.log(\"digraph specs {\");\n for (const edge of graph.edges) console.log(` \"${edge.from}\" -> \"${edge.to}\";`);\n for (const ref of referenceEdges) {\n console.log(\n ` \"${ref.fromId}\" -> \"${ref.toId}\" [style=dashed, label=\"${ref.relationship}\"];`,\n );\n }\n console.log(\"}\");\n return;\n }\n\n console.log(\"\\n Spec Dependency Graph:\\n\");\n for (const node of sorted) {\n const downstream = graph.getDownstream(node);\n const arrow = downstream.length > 0 ? ` → ${downstream.join(\", \")}` : \"\";\n console.log(` ${node}${arrow}`);\n }\n\n if (referenceEdges.length > 0) {\n console.log(\"\\n Reference edges (frontmatter):\\n\");\n for (const ref of referenceEdges) {\n console.log(` ${ref.fromId} —${ref.relationship}→ ${ref.toId}`);\n }\n }\n\n const suggestions = unreflected.filter((u) => !u.createsCycle);\n const conflicts = unreflected.filter((u) => u.createsCycle);\n\n if (suggestions.length > 0) {\n console.log(\"\\n ⚠ References not reflected in config requires:\\n\");\n for (const { edge, requiringEntry, requiredEntry } of suggestions) {\n console.log(\n ` ${edge.fromId} ${edge.relationship} ${edge.toId} — add \"requires: [${requiredEntry}]\" to the \"${requiringEntry}\" entry in spec.config.yaml`,\n );\n }\n }\n\n if (conflicts.length > 0) {\n console.log(\"\\n ⚠ References that conflict with the requires chain:\\n\");\n for (const { edge, requiringEntry, requiredEntry } of conflicts) {\n console.log(\n ` ${edge.fromId} ${edge.relationship} ${edge.toId} — implies \"${requiringEntry}\" requires \"${requiredEntry}\", but that would create a cycle; review the reference or the config requires`,\n );\n }\n }\n\n console.log(\"\");\n } catch (err) {\n if (err instanceof GraphError) {\n console.error(` ✗ ${err.message}`);\n process.exit(1);\n }\n throw err;\n }\n },\n});\n"],"mappings":"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","names":[]}
package/dist/index.js CHANGED
@@ -46,30 +46,123 @@ var base_spec_default = {
46
46
  $schema: "http://json-schema.org/draft-07/schema#",
47
47
  type: "object",
48
48
  properties: {
49
- id: { type: "string", minLength: 1 },
50
- type: { type: "string", enum: ["prd", "technical-design", "user-story", "test-plan", "adr", "api-contract", "epic", "quick-spec", "project-context"] },
51
- title: { type: "string", minLength: 1 },
52
- status: { type: "string", enum: ["draft", "review", "approved", "superseded"] },
53
- version: { type: "string" },
54
- created: { type: "string", format: "date" },
55
- updated: { type: "string", format: "date" },
56
- authors: { type: "array", items: { type: "string" }, minItems: 1 },
57
- tags: { type: "array", items: { type: "string" }, default: [] },
49
+ id: {
50
+ type: "string",
51
+ minLength: 1
52
+ },
53
+ type: {
54
+ type: "string",
55
+ enum: [
56
+ "prd",
57
+ "technical-design",
58
+ "user-story",
59
+ "test-plan",
60
+ "adr",
61
+ "api-contract",
62
+ "epic",
63
+ "quick-spec",
64
+ "project-context"
65
+ ]
66
+ },
67
+ title: {
68
+ type: "string",
69
+ minLength: 1
70
+ },
71
+ status: {
72
+ type: "string",
73
+ enum: [
74
+ "draft",
75
+ "review",
76
+ "approved",
77
+ "superseded"
78
+ ]
79
+ },
80
+ version: {
81
+ type: "string"
82
+ },
83
+ created: {
84
+ type: "string",
85
+ format: "date"
86
+ },
87
+ updated: {
88
+ type: "string",
89
+ format: "date"
90
+ },
91
+ authors: {
92
+ type: "array",
93
+ items: {
94
+ type: "string"
95
+ },
96
+ minItems: 1
97
+ },
98
+ tags: {
99
+ type: "array",
100
+ items: {
101
+ type: "string"
102
+ },
103
+ default: []
104
+ },
58
105
  references: {
59
106
  type: "array",
60
107
  items: {
61
108
  type: "object",
62
109
  properties: {
63
- id: { type: "string" },
64
- relationship: { type: "string", enum: ["implemented-by", "decomposed-into", "depends-on", "supersedes", "related-to"] }
110
+ id: {
111
+ type: "string"
112
+ },
113
+ relationship: {
114
+ type: "string",
115
+ enum: [
116
+ "implemented-by",
117
+ "decomposed-into",
118
+ "depends-on",
119
+ "supersedes",
120
+ "related-to"
121
+ ]
122
+ }
123
+ },
124
+ required: [
125
+ "id",
126
+ "relationship"
127
+ ],
128
+ additionalProperties: false
129
+ },
130
+ default: []
131
+ },
132
+ artifacts: {
133
+ type: "array",
134
+ items: {
135
+ type: "object",
136
+ properties: {
137
+ path: {
138
+ type: "string",
139
+ minLength: 1
140
+ },
141
+ exports: {
142
+ type: "array",
143
+ items: {
144
+ type: "string",
145
+ minLength: 1
146
+ }
147
+ }
65
148
  },
66
- required: ["id", "relationship"],
149
+ required: [
150
+ "path"
151
+ ],
67
152
  additionalProperties: false
68
153
  },
69
154
  default: []
70
155
  }
71
156
  },
72
- required: ["id", "type", "title", "status", "version", "created", "authors"],
157
+ required: [
158
+ "id",
159
+ "type",
160
+ "title",
161
+ "status",
162
+ "version",
163
+ "created",
164
+ "authors"
165
+ ],
73
166
  additionalProperties: true
74
167
  };
75
168
 
@@ -1270,7 +1363,6 @@ async function runLint(options) {
1270
1363
  for (const [, entry] of Object.entries(config.specs)) {
1271
1364
  const files = await resolveGlob(entry.path, options.configDir);
1272
1365
  for (const file of files) {
1273
- if (options.specPath && !file.includes(options.specPath)) continue;
1274
1366
  specs.push(await parseSpec(file));
1275
1367
  }
1276
1368
  }
@@ -1283,6 +1375,12 @@ async function runLint(options) {
1283
1375
  }
1284
1376
  const engine = createLintEngine({ rules, config, graph });
1285
1377
  const results = engine.lint(specs);
1378
+ if (options.specPath) {
1379
+ const specPath = options.specPath;
1380
+ results.diagnostics = results.diagnostics.filter((d) => d.filePath.includes(specPath));
1381
+ results.hasErrors = results.diagnostics.some((d) => d.severity === "error");
1382
+ results.hasWarnings = results.diagnostics.some((d) => d.severity === "warn");
1383
+ }
1286
1384
  if (graphError) {
1287
1385
  results.diagnostics.push({
1288
1386
  ruleId: "structure/no-circular-deps",
@@ -1620,31 +1718,66 @@ function compressSpec(specId, type, title, status, updatedDate, parsedSections,
1620
1718
  // ../pack/dist/allocator.js
1621
1719
  var HIGH_RELEVANCE = 0.75;
1622
1720
  var MIN_TRIM_BUDGET = 150;
1623
- var OMITTED_MARKER = "[section omitted to fit token budget]";
1721
+ function omissionMarker(sections) {
1722
+ const names = sections.map((s) => s.heading || "(untitled)");
1723
+ const noun = names.length === 1 ? "section" : "sections";
1724
+ return `[${names.length} ${noun} omitted to fit token budget: ${names.join(", ")}]`;
1725
+ }
1624
1726
  function trimToBudget(compressed, budget) {
1625
- const markerTokens = countTokens(OMITTED_MARKER);
1626
- const kept = [];
1627
- let used = 0;
1628
- let keptReal = false;
1629
- for (const section of compressed.sections) {
1630
- if (used + section.tokens <= budget) {
1631
- kept.push(section);
1632
- used += section.tokens;
1633
- keptReal = true;
1634
- } else if (used + markerTokens <= budget) {
1635
- kept.push({
1636
- heading: section.heading,
1637
- content: OMITTED_MARKER,
1638
- tokens: markerTokens,
1639
- compressed: true,
1640
- originalTokens: section.tokens
1641
- });
1642
- used += markerTokens;
1727
+ const sections = compressed.sections;
1728
+ let reserve = 0;
1729
+ for (; ; ) {
1730
+ const effective = budget - reserve;
1731
+ const keep = new Array(sections.length).fill(false);
1732
+ let used = 0;
1733
+ let keptReal = false;
1734
+ for (let i = 0; i < sections.length; i++) {
1735
+ if (used + sections[i].tokens <= effective) {
1736
+ keep[i] = true;
1737
+ used += sections[i].tokens;
1738
+ keptReal = true;
1739
+ }
1740
+ }
1741
+ if (!keptReal)
1742
+ return null;
1743
+ const runs = [];
1744
+ for (let i = 0; i < sections.length; i++) {
1745
+ if (keep[i])
1746
+ continue;
1747
+ const start = i;
1748
+ const run = [];
1749
+ while (i < sections.length && !keep[i]) {
1750
+ run.push(sections[i]);
1751
+ i++;
1752
+ }
1753
+ i--;
1754
+ const marker = omissionMarker(run);
1755
+ runs.push({ start, sections: run, marker, markerTokens: countTokens(marker) });
1756
+ }
1757
+ const markerTokens = runs.reduce((sum, r) => sum + r.markerTokens, 0);
1758
+ if (markerTokens > reserve) {
1759
+ reserve = markerTokens;
1760
+ continue;
1761
+ }
1762
+ const out = [];
1763
+ for (let i = 0; i < sections.length; i++) {
1764
+ const run = runs.find((r) => r.start === i);
1765
+ if (run) {
1766
+ out.push({
1767
+ heading: "",
1768
+ content: run.marker,
1769
+ tokens: run.markerTokens,
1770
+ compressed: true,
1771
+ originalTokens: run.sections.reduce((sum, s) => sum + s.tokens, 0),
1772
+ omittedSections: run.sections.length
1773
+ });
1774
+ i += run.sections.length - 1;
1775
+ continue;
1776
+ }
1777
+ out.push(sections[i]);
1643
1778
  }
1779
+ return { spec: { ...compressed, sections: out }, tokens: used + markerTokens };
1644
1780
  }
1645
- if (!keptReal)
1646
- return null;
1647
- return { spec: { ...compressed, sections: kept }, tokens: used };
1648
1781
  }
1649
1782
  function allocate(specs, scores, options) {
1650
1783
  const specMap = /* @__PURE__ */ new Map();
@@ -1716,11 +1849,13 @@ function allocate(specs, scores, options) {
1716
1849
  }
1717
1850
  }
1718
1851
  let sectionsCompressed = 0;
1852
+ let sectionsOmitted = 0;
1719
1853
  for (const item of included) {
1720
1854
  for (const section of item.compressed.sections) {
1721
1855
  if (section.compressed) {
1722
1856
  sectionsCompressed++;
1723
1857
  }
1858
+ sectionsOmitted += section.omittedSections ?? 0;
1724
1859
  }
1725
1860
  }
1726
1861
  const allocations = [];
@@ -1750,6 +1885,7 @@ function allocate(specs, scores, options) {
1750
1885
  specsIncluded: included.length,
1751
1886
  specsExcluded: excluded.length,
1752
1887
  sectionsCompressed,
1888
+ sectionsOmitted,
1753
1889
  allocations
1754
1890
  };
1755
1891
  return {
@@ -1764,7 +1900,7 @@ function escapeXml(text) {
1764
1900
  }
1765
1901
  function formatXml(specs, stats) {
1766
1902
  const lines = [];
1767
- lines.push(`<context budget="${stats.budget}" used="${stats.used}" specs="${stats.specsIncluded}" compressed="${stats.sectionsCompressed}">`);
1903
+ lines.push(`<context budget="${stats.budget}" used="${stats.used}" specs="${stats.specsIncluded}" compressed="${stats.sectionsCompressed}" omitted="${stats.sectionsOmitted}">`);
1768
1904
  for (const spec of specs) {
1769
1905
  const alloc = stats.allocations.find((a) => a.specId === spec.specId);
1770
1906
  const relevance = alloc?.relevance ?? 0;
@@ -1823,6 +1959,7 @@ function formatJson2(specs, stats) {
1823
1959
  const output = {
1824
1960
  budget: stats.budget,
1825
1961
  used: stats.used,
1962
+ sectionsOmitted: stats.sectionsOmitted,
1826
1963
  specs: specs.map((spec) => {
1827
1964
  const alloc = stats.allocations.find((a) => a.specId === spec.specId);
1828
1965
  const relevance = alloc?.relevance ?? 0;
@@ -2066,7 +2203,8 @@ var pack_default = defineCommand3({
2066
2203
  console.log(
2067
2204
  ` Included: ${stats.specsIncluded} / ${stats.specsIncluded + stats.specsExcluded} specs`
2068
2205
  );
2069
- console.log(` Sections compressed: ${stats.sectionsCompressed}
2206
+ console.log(` Sections compressed: ${stats.sectionsCompressed}`);
2207
+ console.log(` Sections omitted: ${stats.sectionsOmitted}
2070
2208
  `);
2071
2209
  return;
2072
2210
  }
@@ -2083,7 +2221,7 @@ var pack_default = defineCommand3({
2083
2221
  }
2084
2222
  const total = stats.specsIncluded + stats.specsExcluded;
2085
2223
  process.stderr.write(
2086
- `Packed ${stats.specsIncluded}/${total} specs \u2022 ${stats.used} / ${stats.budget} tokens \u2022 ${stats.sectionsCompressed} sections compressed
2224
+ `Packed ${stats.specsIncluded}/${total} specs \u2022 ${stats.used} / ${stats.budget} tokens \u2022 ${stats.sectionsCompressed} sections compressed \u2022 ${stats.sectionsOmitted} sections omitted
2087
2225
  `
2088
2226
  );
2089
2227
  } catch (err) {