specdx 0.3.0-alpha.2 → 0.4.0-alpha.1

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 (64) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/dist/{changelog-URU2TFNM.js → changelog-OUP2RXWN.js} +4 -4
  3. package/dist/check-3XQYO3HU.js +109 -0
  4. package/dist/check-3XQYO3HU.js.map +1 -0
  5. package/dist/{pack-OJAC7JF2.js → chunk-4THCEWAK.js} +53 -169
  6. package/dist/chunk-4THCEWAK.js.map +1 -0
  7. package/dist/chunk-6BWZEAST.js +1051 -0
  8. package/dist/chunk-6BWZEAST.js.map +1 -0
  9. package/dist/{chunk-LU6M5O63.js → chunk-DDFLMRPC.js} +2 -2
  10. package/dist/chunk-HMXUNURD.js +490 -0
  11. package/dist/chunk-HMXUNURD.js.map +1 -0
  12. package/dist/{chunk-276J7LR6.js → chunk-PHR7AV6I.js} +2 -2
  13. package/dist/{chunk-XLEN6ZYM.js → chunk-ZX4HVL5M.js} +92 -4
  14. package/dist/chunk-ZX4HVL5M.js.map +1 -0
  15. package/dist/{diff-55PTEVB3.js → diff-275PLXYH.js} +4 -4
  16. package/dist/dist-PQCG2XXF.js +11 -0
  17. package/dist/dist-PQCG2XXF.js.map +1 -0
  18. package/dist/dist-QXLX77XG.js +279 -0
  19. package/dist/dist-QXLX77XG.js.map +1 -0
  20. package/dist/{explain-YXUILNEA.js → explain-I7AQMEEH.js} +3 -3
  21. package/dist/generate-PC7BIB7G.js +13 -0
  22. package/dist/generate-PC7BIB7G.js.map +1 -0
  23. package/dist/generate-story-7WHPPFHY.js +192 -0
  24. package/dist/generate-story-7WHPPFHY.js.map +1 -0
  25. package/dist/generate-test-plan-U5LMWGKX.js +154 -0
  26. package/dist/generate-test-plan-U5LMWGKX.js.map +1 -0
  27. package/dist/{graph-OWQJWVSN.js → graph-RCAPF55A.js} +3 -3
  28. package/dist/index.js +390 -16
  29. package/dist/index.js.map +1 -1
  30. package/dist/{lint-U7VLGS75.js → lint-XPAFMLZN.js} +4 -4
  31. package/dist/main.js +23 -14
  32. package/dist/main.js.map +1 -1
  33. package/dist/mcp-6RCSHMXD.js +17 -0
  34. package/dist/mcp-6RCSHMXD.js.map +1 -0
  35. package/dist/migrate-L7W5RHSS.js +56 -0
  36. package/dist/migrate-L7W5RHSS.js.map +1 -0
  37. package/dist/pack-QCOXMURY.js +167 -0
  38. package/dist/pack-QCOXMURY.js.map +1 -0
  39. package/dist/{ready-3OIF4QHM.js → ready-ZXG74W7Y.js} +5 -5
  40. package/dist/skills/specdx-check-drift.md +71 -0
  41. package/dist/skills/specdx-review-spec.md +77 -0
  42. package/dist/skills/specdx-verify.md +70 -0
  43. package/dist/{skills-XJYTWGDK.js → skills-3GBBWZW2.js} +5 -2
  44. package/dist/skills-3GBBWZW2.js.map +1 -0
  45. package/dist/{status-LYZUO6AJ.js → status-EKWK47O5.js} +5 -5
  46. package/dist/update-HIWDDEZQ.js +132 -0
  47. package/dist/update-HIWDDEZQ.js.map +1 -0
  48. package/dist/{validate-DOZZEZFC.js → validate-N2WSG75W.js} +3 -3
  49. package/package.json +3 -1
  50. package/dist/chunk-ATLVRGHI.js +0 -237
  51. package/dist/chunk-ATLVRGHI.js.map +0 -1
  52. package/dist/chunk-XLEN6ZYM.js.map +0 -1
  53. package/dist/pack-OJAC7JF2.js.map +0 -1
  54. package/dist/skills-XJYTWGDK.js.map +0 -1
  55. /package/dist/{changelog-URU2TFNM.js.map → changelog-OUP2RXWN.js.map} +0 -0
  56. /package/dist/{chunk-LU6M5O63.js.map → chunk-DDFLMRPC.js.map} +0 -0
  57. /package/dist/{chunk-276J7LR6.js.map → chunk-PHR7AV6I.js.map} +0 -0
  58. /package/dist/{diff-55PTEVB3.js.map → diff-275PLXYH.js.map} +0 -0
  59. /package/dist/{explain-YXUILNEA.js.map → explain-I7AQMEEH.js.map} +0 -0
  60. /package/dist/{graph-OWQJWVSN.js.map → graph-RCAPF55A.js.map} +0 -0
  61. /package/dist/{lint-U7VLGS75.js.map → lint-XPAFMLZN.js.map} +0 -0
  62. /package/dist/{ready-3OIF4QHM.js.map → ready-ZXG74W7Y.js.map} +0 -0
  63. /package/dist/{status-LYZUO6AJ.js.map → status-EKWK47O5.js.map} +0 -0
  64. /package/dist/{validate-DOZZEZFC.js.map → validate-N2WSG75W.js.map} +0 -0
package/dist/index.js CHANGED
@@ -18,7 +18,10 @@ var REQUIRED_SECTIONS = {
18
18
  "user-story": ["Description", "Acceptance Criteria", "Dependencies", "Notes"],
19
19
  "test-plan": ["Scope", "Test Cases", "Coverage Matrix", "Edge Cases"],
20
20
  adr: ["Context", "Decision", "Status", "Consequences"],
21
- "api-contract": ["Endpoints", "Request/Response Schemas", "Auth", "Error Codes"]
21
+ "api-contract": ["Endpoints", "Request/Response Schemas", "Auth", "Error Codes"],
22
+ epic: ["Overview", "Stories", "Acceptance Criteria", "Dependencies"],
23
+ "quick-spec": ["Intent", "Boundaries", "Tasks"],
24
+ "project-context": ["Technology Stack", "Critical Implementation Rules", "Coding Patterns"]
22
25
  };
23
26
 
24
27
  // ../schema/dist/validator.js
@@ -31,7 +34,7 @@ var base_spec_default = {
31
34
  type: "object",
32
35
  properties: {
33
36
  id: { type: "string", minLength: 1 },
34
- type: { type: "string", enum: ["prd", "technical-design", "user-story", "test-plan", "adr", "api-contract"] },
37
+ type: { type: "string", enum: ["prd", "technical-design", "user-story", "test-plan", "adr", "api-contract", "epic", "quick-spec", "project-context"] },
35
38
  title: { type: "string", minLength: 1 },
36
39
  status: { type: "string", enum: ["draft", "review", "approved", "superseded"] },
37
40
  version: { type: "string" },
@@ -141,6 +144,24 @@ var config_default = {
141
144
  }
142
145
  },
143
146
  additionalProperties: false
147
+ },
148
+ check: {
149
+ type: "object",
150
+ properties: {
151
+ framework: {
152
+ type: "string",
153
+ enum: ["auto", "express", "hono", "nextjs"]
154
+ },
155
+ routes_dir: { type: "string" },
156
+ app_dir: { type: "string" },
157
+ types_dir: { type: "string" },
158
+ tests_dir: { type: "string" },
159
+ ignore: {
160
+ type: "array",
161
+ items: { type: "string" }
162
+ }
163
+ },
164
+ additionalProperties: false
144
165
  }
145
166
  },
146
167
  required: ["version", "specs"],
@@ -216,6 +237,56 @@ var api_contract_default = {
216
237
  ]
217
238
  };
218
239
 
240
+ // ../schema/dist/schemas/epic.json
241
+ var epic_default = {
242
+ $id: "epic",
243
+ $schema: "http://json-schema.org/draft-07/schema#",
244
+ allOf: [
245
+ { $ref: "base-spec" },
246
+ {
247
+ type: "object",
248
+ properties: {
249
+ type: { const: "epic" },
250
+ epic_id: { type: "string", minLength: 1 },
251
+ priority: { type: "string", enum: ["critical", "high", "medium", "low"] }
252
+ },
253
+ required: ["type", "epic_id", "priority"]
254
+ }
255
+ ]
256
+ };
257
+
258
+ // ../schema/dist/schemas/quick-spec.json
259
+ var quick_spec_default = {
260
+ $id: "quick-spec",
261
+ $schema: "http://json-schema.org/draft-07/schema#",
262
+ allOf: [
263
+ { $ref: "base-spec" },
264
+ {
265
+ type: "object",
266
+ properties: {
267
+ type: { const: "quick-spec" }
268
+ },
269
+ required: ["type"]
270
+ }
271
+ ]
272
+ };
273
+
274
+ // ../schema/dist/schemas/project-context.json
275
+ var project_context_default = {
276
+ $id: "project-context",
277
+ $schema: "http://json-schema.org/draft-07/schema#",
278
+ allOf: [
279
+ { $ref: "base-spec" },
280
+ {
281
+ type: "object",
282
+ properties: {
283
+ type: { const: "project-context" }
284
+ },
285
+ required: ["type"]
286
+ }
287
+ ]
288
+ };
289
+
219
290
  // ../schema/dist/validator.js
220
291
  import * as addFormatsNs from "ajv-formats";
221
292
  var addFormats = addFormatsNs.default ?? addFormatsNs;
@@ -228,7 +299,10 @@ var specValidators = {
228
299
  "user-story": ajv.compile(user_story_default),
229
300
  "test-plan": ajv.compile(test_plan_default),
230
301
  adr: ajv.compile(adr_default),
231
- "api-contract": ajv.compile(api_contract_default)
302
+ "api-contract": ajv.compile(api_contract_default),
303
+ epic: ajv.compile(epic_default),
304
+ "quick-spec": ajv.compile(quick_spec_default),
305
+ "project-context": ajv.compile(project_context_default)
232
306
  };
233
307
  var configValidator = ajv.compile(config_default);
234
308
  function validateSpec(type, data) {
@@ -259,12 +333,16 @@ var TEMPLATE_SPECS = {
259
333
  { filename: "technical-design.md", type: "technical-design" },
260
334
  { filename: "api-contract.md", type: "api-contract" },
261
335
  { filename: "test-plan.md", type: "test-plan" }
262
- ]
336
+ ],
337
+ quick: [{ filename: "quick-spec.md", type: "quick-spec" }],
338
+ context: [{ filename: "project-context.md", type: "project-context" }]
263
339
  };
264
340
  var TEMPLATE_EXTRA_DIRS = {
265
341
  lightweight: [],
266
342
  bmad: ["specs/stories", "specs/adr"],
267
- "api-first": []
343
+ "api-first": [],
344
+ quick: [],
345
+ context: []
268
346
  };
269
347
  function specIdFromFilename(filename) {
270
348
  return filename.replace(/\.md$/, "");
@@ -347,7 +425,7 @@ var init_default = defineCommand({
347
425
  },
348
426
  async run({ args }) {
349
427
  const { name, template, dir } = args;
350
- const validTemplates = ["lightweight", "bmad", "api-first"];
428
+ const validTemplates = ["lightweight", "bmad", "api-first", "quick", "context"];
351
429
  if (!validTemplates.includes(template)) {
352
430
  console.error(`Unknown template: ${template}. Choose from: ${validTemplates.join(", ")}`);
353
431
  process.exit(1);
@@ -841,17 +919,270 @@ var noVagueLanguageRule = {
841
919
  }
842
920
  };
843
921
 
922
+ // ../lint/dist/rules/single-project-context.js
923
+ var singleProjectContextRule = {
924
+ id: "structure/single-project-context",
925
+ description: "Only one project-context spec should exist per suite",
926
+ severity: "warn",
927
+ run(context) {
928
+ if (context.spec.frontmatter.type !== "project-context")
929
+ return [];
930
+ const contextSpecs = context.allSpecs.filter((s) => s.frontmatter.type === "project-context");
931
+ if (contextSpecs.length > 1) {
932
+ return [
933
+ {
934
+ ruleId: "structure/single-project-context",
935
+ severity: "warn",
936
+ message: `Multiple project-context specs found (${contextSpecs.length}). Only one should exist per suite.`,
937
+ filePath: context.spec.filePath
938
+ }
939
+ ];
940
+ }
941
+ return [];
942
+ }
943
+ };
944
+
945
+ // ../lint/dist/rules/terminology.js
946
+ function normalizeCompound(term) {
947
+ return term.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[-_]/g, " ").toLowerCase().trim();
948
+ }
949
+ function extractCompoundTerms(content) {
950
+ const terms = [];
951
+ const camelCaseRegex = /\b[a-zA-Z]*[a-z][A-Z][a-zA-Z]*\b/g;
952
+ let match;
953
+ while ((match = camelCaseRegex.exec(content)) !== null) {
954
+ terms.push(match[0]);
955
+ }
956
+ const hyphenatedRegex = /\b[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)+\b/g;
957
+ while ((match = hyphenatedRegex.exec(content)) !== null) {
958
+ terms.push(match[0]);
959
+ }
960
+ return terms;
961
+ }
962
+ var terminologyRule = {
963
+ id: "consistency/terminology",
964
+ description: "Detects terminology drift (e.g., user-profile vs UserProfile vs user profile) across specs",
965
+ severity: "warn",
966
+ run(context) {
967
+ if (context.spec !== context.allSpecs[0])
968
+ return [];
969
+ const termMap = /* @__PURE__ */ new Map();
970
+ for (const spec of context.allSpecs) {
971
+ if (!spec.content)
972
+ continue;
973
+ const terms = extractCompoundTerms(spec.content);
974
+ for (const term of terms) {
975
+ const normalized = normalizeCompound(term);
976
+ if (!normalized.includes(" "))
977
+ continue;
978
+ if (!termMap.has(normalized)) {
979
+ termMap.set(normalized, /* @__PURE__ */ new Set());
980
+ }
981
+ termMap.get(normalized).add(term);
982
+ }
983
+ }
984
+ const diagnostics = [];
985
+ for (const [normalized, variants] of termMap) {
986
+ if (variants.size >= 2) {
987
+ const variantList = [...variants].join(", ");
988
+ diagnostics.push({
989
+ ruleId: "consistency/terminology",
990
+ severity: "warn",
991
+ message: `Inconsistent terminology for "${normalized}": found variants [${variantList}]. Standardize terminology across specs.`,
992
+ filePath: context.spec.filePath
993
+ });
994
+ }
995
+ }
996
+ return diagnostics;
997
+ }
998
+ };
999
+
1000
+ // ../lint/dist/rules/edge-case-coverage.js
1001
+ var EDGE_CASE_KEYWORDS = [
1002
+ "error",
1003
+ "invalid",
1004
+ "empty",
1005
+ "timeout",
1006
+ "fails",
1007
+ "failure",
1008
+ "boundary",
1009
+ "edge case",
1010
+ "null",
1011
+ "undefined",
1012
+ "reject",
1013
+ "unauthorized",
1014
+ "forbidden",
1015
+ "404",
1016
+ "500",
1017
+ "missing",
1018
+ "malformed",
1019
+ "overflow",
1020
+ "duplicate"
1021
+ ];
1022
+ var edgeCaseCoverageRule = {
1023
+ id: "completeness/edge-case-coverage",
1024
+ description: "Flag user stories or test plans that don't mention error states or edge cases",
1025
+ severity: "warn",
1026
+ run(context) {
1027
+ const type = context.spec.frontmatter.type;
1028
+ if (type !== "user-story" && type !== "test-plan")
1029
+ return [];
1030
+ const content = context.spec.content.toLowerCase();
1031
+ const hasEdgeCases = EDGE_CASE_KEYWORDS.some((kw) => content.includes(kw));
1032
+ if (hasEdgeCases)
1033
+ return [];
1034
+ return [
1035
+ {
1036
+ ruleId: "completeness/edge-case-coverage",
1037
+ severity: "warn",
1038
+ message: "No error states or edge cases mentioned. Consider adding error handling, boundary conditions, or failure mode scenarios.",
1039
+ filePath: context.spec.filePath
1040
+ }
1041
+ ];
1042
+ }
1043
+ };
1044
+
1045
+ // ../lint/dist/rules/naming-conventions.js
1046
+ var namingConventionsRule = {
1047
+ id: "consistency/naming-conventions",
1048
+ description: "Enforce consistent naming conventions across specs",
1049
+ severity: "warn",
1050
+ run(context) {
1051
+ const { spec } = context;
1052
+ const type = spec.frontmatter.type;
1053
+ const diagnostics = [];
1054
+ if (type === "prd") {
1055
+ const sectionParts = spec.content.split(/^(?=## )/m);
1056
+ const featuresSection = sectionParts.find((p) => /^## Features\b/.test(p));
1057
+ if (featuresSection) {
1058
+ const bullets = featuresSection.match(/^- .+$/gm) ?? [];
1059
+ for (const bullet of bullets) {
1060
+ if (bullet.match(/^- \*\*F\d+\*\*:/) === null && bullet.trim().length > 2) {
1061
+ diagnostics.push({
1062
+ ruleId: "consistency/naming-conventions",
1063
+ severity: "warn",
1064
+ message: `PRD feature missing feature ID pattern (**F<N>**:): "${bullet.slice(0, 60)}"`,
1065
+ filePath: spec.filePath
1066
+ });
1067
+ }
1068
+ }
1069
+ }
1070
+ }
1071
+ if (type === "user-story") {
1072
+ const id = spec.frontmatter.id;
1073
+ if (!id.startsWith("story-")) {
1074
+ diagnostics.push({
1075
+ ruleId: "consistency/naming-conventions",
1076
+ severity: "warn",
1077
+ message: `User story ID "${id}" should start with "story-" (e.g., "story-${id}")`,
1078
+ filePath: spec.filePath
1079
+ });
1080
+ }
1081
+ }
1082
+ if (type === "api-contract") {
1083
+ const endpointRe = /^###\s+(GET|POST|PUT|PATCH|DELETE)\s+(\S+)/gm;
1084
+ let match;
1085
+ while ((match = endpointRe.exec(spec.content)) !== null) {
1086
+ const path = match[2];
1087
+ if (/\/[a-z]+[A-Z]/.test(path)) {
1088
+ diagnostics.push({
1089
+ ruleId: "consistency/naming-conventions",
1090
+ severity: "warn",
1091
+ message: `Endpoint path "${path}" uses camelCase \u2014 use kebab-case instead (e.g., "${path.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()}")`,
1092
+ filePath: spec.filePath
1093
+ });
1094
+ }
1095
+ }
1096
+ }
1097
+ return diagnostics;
1098
+ }
1099
+ };
1100
+
1101
+ // ../lint/dist/rules/threat-coverage.js
1102
+ var STOPWORDS = /* @__PURE__ */ new Set(["the", "and", "for", "with", "from", "that", "this", "into", "via"]);
1103
+ function extractThreats(content) {
1104
+ const parts = content.split(/^(?=## )/m);
1105
+ const threats = [];
1106
+ for (const part of parts) {
1107
+ if (!/^##\s+(Threats|Security)\b/i.test(part))
1108
+ continue;
1109
+ const bullets = part.match(/^- .+$/gm) ?? [];
1110
+ threats.push(...bullets.map((b) => b.slice(2).trim()));
1111
+ }
1112
+ return threats;
1113
+ }
1114
+ function extractKeyTerms(text) {
1115
+ return text.toLowerCase().split(/\W+/).filter((w) => w.length > 3).filter((w) => !STOPWORDS.has(w));
1116
+ }
1117
+ var threatCoverageRule = {
1118
+ id: "security/threat-coverage",
1119
+ description: "Technical design specs must address threats identified in other specs",
1120
+ severity: "warn",
1121
+ run(context) {
1122
+ if (context.spec.frontmatter.type !== "technical-design")
1123
+ return [];
1124
+ const allThreats = [];
1125
+ for (const spec of context.allSpecs) {
1126
+ if (spec.filePath === context.spec.filePath)
1127
+ continue;
1128
+ allThreats.push(...extractThreats(spec.content));
1129
+ }
1130
+ if (allThreats.length === 0)
1131
+ return [];
1132
+ const techContent = context.spec.content.toLowerCase();
1133
+ const diagnostics = [];
1134
+ for (const threat of allThreats) {
1135
+ const keyTerms = extractKeyTerms(threat);
1136
+ const covered = keyTerms.some((term) => techContent.includes(term));
1137
+ if (!covered) {
1138
+ diagnostics.push({
1139
+ ruleId: "security/threat-coverage",
1140
+ severity: "warn",
1141
+ message: `Threat not addressed in technical design: "${threat}". Ensure the design covers this threat.`,
1142
+ filePath: context.spec.filePath
1143
+ });
1144
+ }
1145
+ }
1146
+ return diagnostics;
1147
+ }
1148
+ };
1149
+
1150
+ // ../lint/dist/rules/ambiguity-score-ai.js
1151
+ var ambiguityScoreAiRule = {
1152
+ id: "clarity/ambiguity-score-ai",
1153
+ description: "AI-powered ambiguity detection (requires ANTHROPIC_API_KEY)",
1154
+ severity: "info",
1155
+ run(context) {
1156
+ if (!process.env["ANTHROPIC_API_KEY"])
1157
+ return [];
1158
+ return [
1159
+ {
1160
+ ruleId: "clarity/ambiguity-score-ai",
1161
+ severity: "info",
1162
+ message: "AI ambiguity analysis available \u2014 run `sdx check --ai` for LLM-powered ambiguity detection",
1163
+ filePath: context.spec.filePath
1164
+ }
1165
+ ];
1166
+ }
1167
+ };
1168
+
844
1169
  // ../lint/dist/rules/index.js
845
1170
  var structureRules = [
846
1171
  validFrontmatterRule,
847
1172
  requiredSectionsRule,
848
1173
  validReferencesRule,
849
- noCircularDepsRule
1174
+ noCircularDepsRule,
1175
+ singleProjectContextRule
850
1176
  ];
851
1177
  var contentRules = [
852
1178
  storyCoverageRule,
853
1179
  stalenessCheckRule,
854
- noVagueLanguageRule
1180
+ noVagueLanguageRule,
1181
+ terminologyRule,
1182
+ edgeCaseCoverageRule,
1183
+ namingConventionsRule,
1184
+ threatCoverageRule,
1185
+ ambiguityScoreAiRule
855
1186
  ];
856
1187
  var allBuiltinRules = [...structureRules, ...contentRules];
857
1188
 
@@ -975,7 +1306,7 @@ var lint_default = defineCommand2({
975
1306
  import { defineCommand as defineCommand3 } from "citty";
976
1307
 
977
1308
  // ../pack/dist/resolver.js
978
- var STOPWORDS = /* @__PURE__ */ new Set([
1309
+ var STOPWORDS2 = /* @__PURE__ */ new Set([
979
1310
  "a",
980
1311
  "an",
981
1312
  "and",
@@ -1052,7 +1383,7 @@ var STOPWORDS = /* @__PURE__ */ new Set([
1052
1383
  "your"
1053
1384
  ]);
1054
1385
  function tokenize(task) {
1055
- return task.split(/[\s\-_/.,;:!?()[\]{}'"]+/).map((t) => t.toLowerCase()).filter((t) => t.length > 1 && !STOPWORDS.has(t));
1386
+ return task.split(/[\s\-_/.,;:!?()[\]{}'"]+/).map((t) => t.toLowerCase()).filter((t) => t.length > 1 && !STOPWORDS2.has(t));
1056
1387
  }
1057
1388
  var WEIGHT_TAGS = 3;
1058
1389
  var WEIGHT_TITLE = 3;
@@ -1477,29 +1808,72 @@ function pack(specs, options, packConfig, graph) {
1477
1808
  const full = options.full ?? false;
1478
1809
  const compression = buildCompressionOptions(packConfig);
1479
1810
  const resolvedGraph = graph ?? emptyGraph();
1480
- const specMap = /* @__PURE__ */ new Map();
1811
+ const projectContextSpecs = [];
1812
+ const regularSpecs = [];
1481
1813
  for (const spec of specs) {
1814
+ if (spec.frontmatter.type === "project-context") {
1815
+ projectContextSpecs.push(spec);
1816
+ } else {
1817
+ regularSpecs.push(spec);
1818
+ }
1819
+ }
1820
+ let reservedTokens = 0;
1821
+ let reservedCompressed = [];
1822
+ if (projectContextSpecs.length > 0) {
1823
+ const maxReserved = Math.min(budget, 2e3);
1824
+ const ctxScores = projectContextSpecs.map((s) => ({
1825
+ specId: s.frontmatter.id,
1826
+ score: 1,
1827
+ rawScore: 1,
1828
+ matchedKeywords: [],
1829
+ graphBoosted: false
1830
+ }));
1831
+ const ctxResult = allocate(projectContextSpecs, ctxScores, {
1832
+ budget: maxReserved,
1833
+ full: true,
1834
+ compression
1835
+ });
1836
+ reservedCompressed = ctxResult.specs;
1837
+ reservedTokens = ctxResult.stats.used;
1838
+ }
1839
+ const regularBudget = Math.max(0, budget - reservedTokens);
1840
+ const specMap = /* @__PURE__ */ new Map();
1841
+ for (const spec of regularSpecs) {
1482
1842
  specMap.set(spec.frontmatter.id, spec);
1483
1843
  }
1484
1844
  const scores = options.specs ? scoreSpecsByIds(specMap, options.specs, resolvedGraph) : scoreSpecs(specMap, options.task, resolvedGraph);
1485
- const { specs: compressedSpecs, stats } = allocate(specs, scores, {
1486
- budget,
1845
+ const { specs: compressedSpecs, stats } = allocate(regularSpecs, scores, {
1846
+ budget: regularBudget,
1487
1847
  full,
1488
1848
  compression
1489
1849
  });
1850
+ const allCompressed = [...reservedCompressed, ...compressedSpecs];
1851
+ stats.budget = budget;
1852
+ stats.used += reservedTokens;
1853
+ stats.specsIncluded += reservedCompressed.length;
1854
+ for (const ctx of reservedCompressed) {
1855
+ stats.allocations.unshift({
1856
+ specId: ctx.specId,
1857
+ type: ctx.type,
1858
+ relevance: 1,
1859
+ tokens: reservedTokens,
1860
+ compressed: false,
1861
+ included: true
1862
+ });
1863
+ }
1490
1864
  if (options.dryRun) {
1491
1865
  return { output: "", stats };
1492
1866
  }
1493
1867
  let output;
1494
1868
  switch (format) {
1495
1869
  case "markdown":
1496
- output = formatMarkdown(compressedSpecs, stats);
1870
+ output = formatMarkdown(allCompressed, stats);
1497
1871
  break;
1498
1872
  case "json":
1499
- output = formatJson2(compressedSpecs, stats);
1873
+ output = formatJson2(allCompressed, stats);
1500
1874
  break;
1501
1875
  default:
1502
- output = formatXml(compressedSpecs, stats);
1876
+ output = formatXml(allCompressed, stats);
1503
1877
  break;
1504
1878
  }
1505
1879
  return { output, stats };