specdx 0.3.0-alpha.3 → 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.
- package/.claude-plugin/plugin.json +1 -1
- package/LICENSE +21 -0
- package/dist/{changelog-OUP2RXWN.js → changelog-GR53T6IG.js} +18 -11
- package/dist/{changelog-OUP2RXWN.js.map → changelog-GR53T6IG.js.map} +1 -1
- package/dist/{check-3XQYO3HU.js → check-OMWCIY5D.js} +37 -10
- package/dist/check-OMWCIY5D.js.map +1 -0
- package/dist/chunk-3GMYCATE.js +526 -0
- package/dist/chunk-3GMYCATE.js.map +1 -0
- package/dist/{chunk-6BWZEAST.js → chunk-N77RNV7J.js} +161 -26
- package/dist/chunk-N77RNV7J.js.map +1 -0
- package/dist/{pack-PI6V6OR2.js → chunk-SDDTD4R3.js} +97 -171
- package/dist/chunk-SDDTD4R3.js.map +1 -0
- package/dist/{chunk-ZX4HVL5M.js → chunk-SJCIM4TC.js} +119 -17
- package/dist/chunk-SJCIM4TC.js.map +1 -0
- package/dist/{chunk-DDFLMRPC.js → chunk-VMMTEGYN.js} +15 -11
- package/dist/chunk-VMMTEGYN.js.map +1 -0
- package/dist/{chunk-PHR7AV6I.js → chunk-Z77VQUZ3.js} +156 -2
- package/dist/chunk-Z77VQUZ3.js.map +1 -0
- package/dist/diff-AUBYOQWU.js +107 -0
- package/dist/diff-AUBYOQWU.js.map +1 -0
- package/dist/dist-BXYQB2UO.js +306 -0
- package/dist/dist-BXYQB2UO.js.map +1 -0
- package/dist/dist-RL2DT3ZE.js +15 -0
- package/dist/{explain-I7AQMEEH.js → explain-EUID6MZF.js} +35 -28
- package/dist/explain-EUID6MZF.js.map +1 -0
- package/dist/{generate-PC7BIB7G.js → generate-U3EFOCNS.js} +3 -3
- package/dist/{generate-story-7WHPPFHY.js → generate-story-U6FMQIYZ.js} +8 -4
- package/dist/generate-story-U6FMQIYZ.js.map +1 -0
- package/dist/{generate-test-plan-U5LMWGKX.js → generate-test-plan-HOCWDYKF.js} +11 -6
- package/dist/generate-test-plan-HOCWDYKF.js.map +1 -0
- package/dist/graph-TA54D4XA.js +102 -0
- package/dist/graph-TA54D4XA.js.map +1 -0
- package/dist/index.js +777 -158
- package/dist/index.js.map +1 -1
- package/dist/{lint-6Z2TVWAQ.js → lint-L5WOBD25.js} +17 -6
- package/dist/lint-L5WOBD25.js.map +1 -0
- package/dist/main.js +100 -15
- package/dist/main.js.map +1 -1
- package/dist/mcp-GNQQGD7X.js +17 -0
- package/dist/mcp-GNQQGD7X.js.map +1 -0
- package/dist/{migrate-L7W5RHSS.js → migrate-YEJQWIMX.js} +4 -4
- package/dist/migrate-YEJQWIMX.js.map +1 -0
- package/dist/pack-AQH5XQUF.js +168 -0
- package/dist/pack-AQH5XQUF.js.map +1 -0
- package/dist/ready-DB5ORK2E.js +229 -0
- package/dist/ready-DB5ORK2E.js.map +1 -0
- package/dist/skills/specdx-check-drift.md +1 -1
- package/dist/skills/specdx-verify.md +12 -1
- package/dist/{status-AV5GSWVI.js → status-3QUQMF4L.js} +46 -31
- package/dist/status-3QUQMF4L.js.map +1 -0
- package/dist/{update-HIWDDEZQ.js → update-PE2DPYDR.js} +5 -5
- package/dist/update-PE2DPYDR.js.map +1 -0
- package/dist/validate-YNZMV6KZ.js +86 -0
- package/dist/validate-YNZMV6KZ.js.map +1 -0
- package/hooks/session-start +0 -0
- package/package.json +49 -16
- package/dist/check-3XQYO3HU.js.map +0 -1
- package/dist/chunk-6BWZEAST.js.map +0 -1
- package/dist/chunk-DDFLMRPC.js.map +0 -1
- package/dist/chunk-PHR7AV6I.js.map +0 -1
- package/dist/chunk-WTFWNYJA.js +0 -261
- package/dist/chunk-WTFWNYJA.js.map +0 -1
- package/dist/chunk-ZX4HVL5M.js.map +0 -1
- package/dist/diff-275PLXYH.js +0 -100
- package/dist/diff-275PLXYH.js.map +0 -1
- package/dist/dist-PQCG2XXF.js +0 -11
- package/dist/explain-I7AQMEEH.js.map +0 -1
- package/dist/generate-story-7WHPPFHY.js.map +0 -1
- package/dist/generate-test-plan-U5LMWGKX.js.map +0 -1
- package/dist/graph-RCAPF55A.js +0 -54
- package/dist/graph-RCAPF55A.js.map +0 -1
- package/dist/lint-6Z2TVWAQ.js.map +0 -1
- package/dist/migrate-L7W5RHSS.js.map +0 -1
- package/dist/pack-PI6V6OR2.js.map +0 -1
- package/dist/ready-B7IFPL3S.js +0 -159
- package/dist/ready-B7IFPL3S.js.map +0 -1
- package/dist/status-AV5GSWVI.js.map +0 -1
- package/dist/update-HIWDDEZQ.js.map +0 -1
- package/dist/validate-N2WSG75W.js +0 -34
- package/dist/validate-N2WSG75W.js.map +0 -1
- /package/dist/{dist-PQCG2XXF.js.map → dist-RL2DT3ZE.js.map} +0 -0
- /package/dist/{generate-PC7BIB7G.js.map → generate-U3EFOCNS.js.map} +0 -0
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import {
|
|
5
|
-
buildGraph,
|
|
6
|
-
countTokens,
|
|
7
|
-
createLogger,
|
|
8
|
-
loadConfig,
|
|
9
|
-
parseSpec,
|
|
10
|
-
resolveGlob
|
|
11
|
-
} from "./chunk-PHR7AV6I.js";
|
|
12
|
-
import "./chunk-ZX4HVL5M.js";
|
|
13
|
-
|
|
14
|
-
// src/commands/pack.ts
|
|
15
|
-
import { defineCommand } from "citty";
|
|
2
|
+
countTokens
|
|
3
|
+
} from "./chunk-Z77VQUZ3.js";
|
|
16
4
|
|
|
17
5
|
// ../pack/dist/resolver.js
|
|
18
6
|
var STOPWORDS = /* @__PURE__ */ new Set([
|
|
@@ -98,6 +86,7 @@ var WEIGHT_TAGS = 3;
|
|
|
98
86
|
var WEIGHT_TITLE = 3;
|
|
99
87
|
var WEIGHT_SECTIONS = 2;
|
|
100
88
|
var WEIGHT_BODY = 1;
|
|
89
|
+
var ID_MATCH_MIN_LENGTH = 3;
|
|
101
90
|
var GRAPH_BOOST_FACTOR = 0.5;
|
|
102
91
|
var SCORE_THRESHOLD = 0.1;
|
|
103
92
|
function scoreSpecs(specs, task, graph) {
|
|
@@ -117,9 +106,15 @@ function scoreSpecs(specs, task, graph) {
|
|
|
117
106
|
}
|
|
118
107
|
const rawScores = /* @__PURE__ */ new Map();
|
|
119
108
|
const matchedMap = /* @__PURE__ */ new Map();
|
|
109
|
+
const idMatchedSet = /* @__PURE__ */ new Set();
|
|
110
|
+
const taskLower = (task ?? "").toLowerCase();
|
|
120
111
|
for (const [specId, spec] of specs) {
|
|
121
112
|
let weightedHits = 0;
|
|
122
113
|
const matched = /* @__PURE__ */ new Set();
|
|
114
|
+
const idLower = specId.toLowerCase();
|
|
115
|
+
if (idLower.length >= ID_MATCH_MIN_LENGTH && taskLower.includes(idLower)) {
|
|
116
|
+
idMatchedSet.add(specId);
|
|
117
|
+
}
|
|
123
118
|
for (const keyword of keywords) {
|
|
124
119
|
let hit = false;
|
|
125
120
|
const tags = spec.frontmatter.tags ?? [];
|
|
@@ -191,7 +186,8 @@ function scoreSpecs(specs, task, graph) {
|
|
|
191
186
|
const results = [];
|
|
192
187
|
for (const [specId] of specs) {
|
|
193
188
|
const combined = finalRawScores.get(specId) ?? 0;
|
|
194
|
-
const
|
|
189
|
+
const idMatched = idMatchedSet.has(specId);
|
|
190
|
+
const normalized = idMatched ? 1 : maxScore > 0 ? combined / maxScore : 0;
|
|
195
191
|
if (normalized < SCORE_THRESHOLD)
|
|
196
192
|
continue;
|
|
197
193
|
results.push({
|
|
@@ -199,10 +195,11 @@ function scoreSpecs(specs, task, graph) {
|
|
|
199
195
|
score: normalized,
|
|
200
196
|
rawScore: rawScores.get(specId) ?? 0,
|
|
201
197
|
matchedKeywords: [...matchedMap.get(specId) ?? []],
|
|
202
|
-
graphBoosted: boostedSet.has(specId)
|
|
198
|
+
graphBoosted: boostedSet.has(specId),
|
|
199
|
+
idMatched
|
|
203
200
|
});
|
|
204
201
|
}
|
|
205
|
-
results.sort((a, b) => b.score - a.score);
|
|
202
|
+
results.sort((a, b) => b.score - a.score || Number(b.idMatched ?? false) - Number(a.idMatched ?? false));
|
|
206
203
|
return results;
|
|
207
204
|
}
|
|
208
205
|
function scoreSpecsByIds(specs, specIds, graph) {
|
|
@@ -295,6 +292,69 @@ function compressSpec(specId, type, title, status, updatedDate, parsedSections,
|
|
|
295
292
|
}
|
|
296
293
|
|
|
297
294
|
// ../pack/dist/allocator.js
|
|
295
|
+
var HIGH_RELEVANCE = 0.75;
|
|
296
|
+
var MIN_TRIM_BUDGET = 150;
|
|
297
|
+
function omissionMarker(sections) {
|
|
298
|
+
const names = sections.map((s) => s.heading || "(untitled)");
|
|
299
|
+
const noun = names.length === 1 ? "section" : "sections";
|
|
300
|
+
return `[${names.length} ${noun} omitted to fit token budget: ${names.join(", ")}]`;
|
|
301
|
+
}
|
|
302
|
+
function trimToBudget(compressed, budget) {
|
|
303
|
+
const sections = compressed.sections;
|
|
304
|
+
let reserve = 0;
|
|
305
|
+
for (; ; ) {
|
|
306
|
+
const effective = budget - reserve;
|
|
307
|
+
const keep = new Array(sections.length).fill(false);
|
|
308
|
+
let used = 0;
|
|
309
|
+
let keptReal = false;
|
|
310
|
+
for (let i = 0; i < sections.length; i++) {
|
|
311
|
+
if (used + sections[i].tokens <= effective) {
|
|
312
|
+
keep[i] = true;
|
|
313
|
+
used += sections[i].tokens;
|
|
314
|
+
keptReal = true;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (!keptReal)
|
|
318
|
+
return null;
|
|
319
|
+
const runs = [];
|
|
320
|
+
for (let i = 0; i < sections.length; i++) {
|
|
321
|
+
if (keep[i])
|
|
322
|
+
continue;
|
|
323
|
+
const start = i;
|
|
324
|
+
const run = [];
|
|
325
|
+
while (i < sections.length && !keep[i]) {
|
|
326
|
+
run.push(sections[i]);
|
|
327
|
+
i++;
|
|
328
|
+
}
|
|
329
|
+
i--;
|
|
330
|
+
const marker = omissionMarker(run);
|
|
331
|
+
runs.push({ start, sections: run, marker, markerTokens: countTokens(marker) });
|
|
332
|
+
}
|
|
333
|
+
const markerTokens = runs.reduce((sum, r) => sum + r.markerTokens, 0);
|
|
334
|
+
if (markerTokens > reserve) {
|
|
335
|
+
reserve = markerTokens;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
const out = [];
|
|
339
|
+
for (let i = 0; i < sections.length; i++) {
|
|
340
|
+
const run = runs.find((r) => r.start === i);
|
|
341
|
+
if (run) {
|
|
342
|
+
out.push({
|
|
343
|
+
heading: "",
|
|
344
|
+
content: run.marker,
|
|
345
|
+
tokens: run.markerTokens,
|
|
346
|
+
compressed: true,
|
|
347
|
+
originalTokens: run.sections.reduce((sum, s) => sum + s.tokens, 0),
|
|
348
|
+
omittedSections: run.sections.length
|
|
349
|
+
});
|
|
350
|
+
i += run.sections.length - 1;
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
out.push(sections[i]);
|
|
354
|
+
}
|
|
355
|
+
return { spec: { ...compressed, sections: out }, tokens: used + markerTokens };
|
|
356
|
+
}
|
|
357
|
+
}
|
|
298
358
|
function allocate(specs, scores, options) {
|
|
299
359
|
const specMap = /* @__PURE__ */ new Map();
|
|
300
360
|
for (const spec of specs) {
|
|
@@ -332,9 +392,9 @@ function allocate(specs, scores, options) {
|
|
|
332
392
|
tokens += section.tokens;
|
|
333
393
|
}
|
|
334
394
|
}
|
|
335
|
-
items.push({ compressed, relevance: score.score, tokens });
|
|
395
|
+
items.push({ compressed, relevance: score.score, tokens, idMatched: score.idMatched ?? false });
|
|
336
396
|
}
|
|
337
|
-
items.sort((a, b) => b.relevance - a.relevance);
|
|
397
|
+
items.sort((a, b) => b.relevance - a.relevance || Number(b.idMatched) - Number(a.idMatched));
|
|
338
398
|
const totalTokens = items.reduce((sum, item) => sum + item.tokens, 0);
|
|
339
399
|
const withinBudget = totalTokens <= options.budget;
|
|
340
400
|
const included = [];
|
|
@@ -350,17 +410,28 @@ function allocate(specs, scores, options) {
|
|
|
350
410
|
if (usedTokens + item.tokens <= options.budget) {
|
|
351
411
|
included.push(item);
|
|
352
412
|
usedTokens += item.tokens;
|
|
353
|
-
|
|
354
|
-
excluded.push(item);
|
|
413
|
+
continue;
|
|
355
414
|
}
|
|
415
|
+
const remaining = options.budget - usedTokens;
|
|
416
|
+
if ((item.idMatched || item.relevance >= HIGH_RELEVANCE) && remaining >= MIN_TRIM_BUDGET && !item.compressed.collapsed) {
|
|
417
|
+
const trimmed = trimToBudget(item.compressed, remaining);
|
|
418
|
+
if (trimmed) {
|
|
419
|
+
included.push({ ...item, compressed: trimmed.spec, tokens: trimmed.tokens });
|
|
420
|
+
usedTokens += trimmed.tokens;
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
excluded.push(item);
|
|
356
425
|
}
|
|
357
426
|
}
|
|
358
427
|
let sectionsCompressed = 0;
|
|
428
|
+
let sectionsOmitted = 0;
|
|
359
429
|
for (const item of included) {
|
|
360
430
|
for (const section of item.compressed.sections) {
|
|
361
431
|
if (section.compressed) {
|
|
362
432
|
sectionsCompressed++;
|
|
363
433
|
}
|
|
434
|
+
sectionsOmitted += section.omittedSections ?? 0;
|
|
364
435
|
}
|
|
365
436
|
}
|
|
366
437
|
const allocations = [];
|
|
@@ -390,6 +461,7 @@ function allocate(specs, scores, options) {
|
|
|
390
461
|
specsIncluded: included.length,
|
|
391
462
|
specsExcluded: excluded.length,
|
|
392
463
|
sectionsCompressed,
|
|
464
|
+
sectionsOmitted,
|
|
393
465
|
allocations
|
|
394
466
|
};
|
|
395
467
|
return {
|
|
@@ -404,7 +476,7 @@ function escapeXml(text) {
|
|
|
404
476
|
}
|
|
405
477
|
function formatXml(specs, stats) {
|
|
406
478
|
const lines = [];
|
|
407
|
-
lines.push(`<context budget="${stats.budget}" used="${stats.used}" specs="${stats.specsIncluded}" compressed="${stats.sectionsCompressed}">`);
|
|
479
|
+
lines.push(`<context budget="${stats.budget}" used="${stats.used}" specs="${stats.specsIncluded}" compressed="${stats.sectionsCompressed}" omitted="${stats.sectionsOmitted}">`);
|
|
408
480
|
for (const spec of specs) {
|
|
409
481
|
const alloc = stats.allocations.find((a) => a.specId === spec.specId);
|
|
410
482
|
const relevance = alloc?.relevance ?? 0;
|
|
@@ -463,6 +535,7 @@ function formatJson(specs, stats) {
|
|
|
463
535
|
const output = {
|
|
464
536
|
budget: stats.budget,
|
|
465
537
|
used: stats.used,
|
|
538
|
+
sectionsOmitted: stats.sectionsOmitted,
|
|
466
539
|
specs: specs.map((spec) => {
|
|
467
540
|
const alloc = stats.allocations.find((a) => a.specId === spec.specId);
|
|
468
541
|
const relevance = alloc?.relevance ?? 0;
|
|
@@ -588,154 +661,7 @@ function pack(specs, options, packConfig, graph) {
|
|
|
588
661
|
return { output, stats };
|
|
589
662
|
}
|
|
590
663
|
|
|
591
|
-
// src/commands/pack.ts
|
|
592
|
-
import { writeFile } from "fs/promises";
|
|
593
|
-
import { execSync } from "child_process";
|
|
594
|
-
function copyToClipboard(text) {
|
|
595
|
-
const platform = process.platform;
|
|
596
|
-
let cmd;
|
|
597
|
-
if (platform === "darwin") {
|
|
598
|
-
cmd = "pbcopy";
|
|
599
|
-
} else if (platform === "linux") {
|
|
600
|
-
cmd = "xclip -selection clipboard";
|
|
601
|
-
} else if (platform === "win32") {
|
|
602
|
-
cmd = "clip";
|
|
603
|
-
} else {
|
|
604
|
-
throw new Error(`Clipboard not supported on platform: ${platform}`);
|
|
605
|
-
}
|
|
606
|
-
execSync(cmd, { input: text, stdio: ["pipe", "ignore", "ignore"] });
|
|
607
|
-
}
|
|
608
|
-
async function runPack(options) {
|
|
609
|
-
const config = await loadConfig(void 0, options.configDir);
|
|
610
|
-
const allSpecs = [];
|
|
611
|
-
for (const [, entry] of Object.entries(config.specs)) {
|
|
612
|
-
const files = await resolveGlob(entry.path, options.configDir);
|
|
613
|
-
for (const file of files) {
|
|
614
|
-
allSpecs.push(await parseSpec(file));
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
let graph;
|
|
618
|
-
try {
|
|
619
|
-
graph = buildGraph(config);
|
|
620
|
-
} catch {
|
|
621
|
-
}
|
|
622
|
-
const result = pack(
|
|
623
|
-
allSpecs,
|
|
624
|
-
{
|
|
625
|
-
task: options.task,
|
|
626
|
-
specs: options.specs,
|
|
627
|
-
budget: options.budget,
|
|
628
|
-
format: options.format,
|
|
629
|
-
full: options.full,
|
|
630
|
-
dryRun: options.dryRun
|
|
631
|
-
},
|
|
632
|
-
config.pack,
|
|
633
|
-
graph
|
|
634
|
-
);
|
|
635
|
-
return result;
|
|
636
|
-
}
|
|
637
|
-
var pack_default = defineCommand({
|
|
638
|
-
meta: { name: "pack", description: "Pack specs into AI-ready context" },
|
|
639
|
-
args: {
|
|
640
|
-
quiet: sharedArgs.quiet,
|
|
641
|
-
verbose: sharedArgs.verbose,
|
|
642
|
-
task: { type: "string", description: "Task or context to optimise relevance for" },
|
|
643
|
-
specs: { type: "string", description: "Comma-separated spec IDs or glob patterns to include" },
|
|
644
|
-
budget: { type: "string", description: "Maximum token budget for the output" },
|
|
645
|
-
format: {
|
|
646
|
-
type: "string",
|
|
647
|
-
description: "Output format (xml, markdown, json)",
|
|
648
|
-
default: "xml"
|
|
649
|
-
},
|
|
650
|
-
out: { type: "string", description: "Write output to file instead of stdout" },
|
|
651
|
-
copy: { type: "boolean", description: "Copy output to system clipboard" },
|
|
652
|
-
full: { type: "boolean", description: "Include all specs without budget trimming" },
|
|
653
|
-
"dry-run": {
|
|
654
|
-
type: "boolean",
|
|
655
|
-
description: "Preview what would be packed without writing output"
|
|
656
|
-
}
|
|
657
|
-
},
|
|
658
|
-
async run({ args }) {
|
|
659
|
-
const logger = createLogger({ quiet: args.quiet, verbose: args.verbose });
|
|
660
|
-
if (args.task && args.specs) {
|
|
661
|
-
console.error("\n \u2717 --task and --specs are mutually exclusive\n");
|
|
662
|
-
process.exit(1);
|
|
663
|
-
}
|
|
664
|
-
if (args.copy && args["dry-run"]) {
|
|
665
|
-
console.error("\n \u2717 --copy and --dry-run are mutually exclusive\n");
|
|
666
|
-
process.exit(1);
|
|
667
|
-
}
|
|
668
|
-
let budget;
|
|
669
|
-
if (args.budget) {
|
|
670
|
-
budget = Number(args.budget);
|
|
671
|
-
if (Number.isNaN(budget)) {
|
|
672
|
-
console.error("\n \u2717 --budget must be a valid number\n");
|
|
673
|
-
process.exit(1);
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
const format = args.format;
|
|
677
|
-
if (format && !["xml", "markdown", "json"].includes(format)) {
|
|
678
|
-
console.error(`
|
|
679
|
-
\u2717 --format must be one of: xml, markdown, json
|
|
680
|
-
`);
|
|
681
|
-
process.exit(1);
|
|
682
|
-
}
|
|
683
|
-
try {
|
|
684
|
-
const specsList = args.specs ? args.specs.split(",").map((s) => s.trim()) : void 0;
|
|
685
|
-
const result = await runPack({
|
|
686
|
-
configDir: process.cwd(),
|
|
687
|
-
task: args.task,
|
|
688
|
-
specs: specsList,
|
|
689
|
-
budget,
|
|
690
|
-
format,
|
|
691
|
-
full: args.full,
|
|
692
|
-
dryRun: args["dry-run"]
|
|
693
|
-
});
|
|
694
|
-
const { stats } = result;
|
|
695
|
-
if (args["dry-run"]) {
|
|
696
|
-
console.log("\n Dry Run Summary:\n");
|
|
697
|
-
for (const alloc of stats.allocations) {
|
|
698
|
-
const status = alloc.included ? "\u2713" : "\u2717";
|
|
699
|
-
const compressed = alloc.compressed ? " (compressed)" : "";
|
|
700
|
-
console.log(
|
|
701
|
-
` ${status} ${alloc.specId} relevance=${alloc.relevance.toFixed(2)} tokens=${alloc.tokens}${compressed}`
|
|
702
|
-
);
|
|
703
|
-
}
|
|
704
|
-
console.log(`
|
|
705
|
-
Budget: ${stats.used} / ${stats.budget} tokens`);
|
|
706
|
-
console.log(
|
|
707
|
-
` Included: ${stats.specsIncluded} / ${stats.specsIncluded + stats.specsExcluded} specs`
|
|
708
|
-
);
|
|
709
|
-
console.log(` Sections compressed: ${stats.sectionsCompressed}
|
|
710
|
-
`);
|
|
711
|
-
return;
|
|
712
|
-
}
|
|
713
|
-
if (args.out) {
|
|
714
|
-
await writeFile(args.out, result.output, "utf-8");
|
|
715
|
-
logger.info(`Output written to ${args.out}`);
|
|
716
|
-
}
|
|
717
|
-
if (args.copy) {
|
|
718
|
-
copyToClipboard(result.output);
|
|
719
|
-
logger.info("Output copied to clipboard");
|
|
720
|
-
}
|
|
721
|
-
if (!args.out && !args.copy) {
|
|
722
|
-
process.stdout.write(result.output);
|
|
723
|
-
}
|
|
724
|
-
const total = stats.specsIncluded + stats.specsExcluded;
|
|
725
|
-
process.stderr.write(
|
|
726
|
-
`Packed ${stats.specsIncluded}/${total} specs \u2022 ${stats.used} / ${stats.budget} tokens \u2022 ${stats.sectionsCompressed} sections compressed
|
|
727
|
-
`
|
|
728
|
-
);
|
|
729
|
-
} catch (err) {
|
|
730
|
-
console.error(`
|
|
731
|
-
\u2717 ${err.message}
|
|
732
|
-
`);
|
|
733
|
-
process.exit(1);
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
});
|
|
737
664
|
export {
|
|
738
|
-
|
|
739
|
-
runPack
|
|
665
|
+
pack
|
|
740
666
|
};
|
|
741
|
-
//# sourceMappingURL=
|
|
667
|
+
//# sourceMappingURL=chunk-SDDTD4R3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../pack/src/resolver.ts","../../pack/src/compressor.ts","../../pack/src/allocator.ts","../../pack/src/formatters/xml.ts","../../pack/src/formatters/markdown.ts","../../pack/src/formatters/json.ts","../../pack/src/index.ts"],"sourcesContent":["import type { ParsedSpec, DependencyGraph } from \"@specdx/core\";\nimport type { RelevanceScore } from \"./types.js\";\n\n/**\n * Common English stopwords to filter from task tokenization.\n */\nconst STOPWORDS = new Set([\n \"a\",\n \"an\",\n \"and\",\n \"are\",\n \"as\",\n \"at\",\n \"be\",\n \"but\",\n \"by\",\n \"do\",\n \"for\",\n \"from\",\n \"had\",\n \"has\",\n \"have\",\n \"he\",\n \"her\",\n \"his\",\n \"how\",\n \"i\",\n \"if\",\n \"in\",\n \"into\",\n \"is\",\n \"it\",\n \"its\",\n \"just\",\n \"me\",\n \"my\",\n \"no\",\n \"nor\",\n \"not\",\n \"of\",\n \"on\",\n \"or\",\n \"our\",\n \"out\",\n \"own\",\n \"say\",\n \"she\",\n \"so\",\n \"some\",\n \"such\",\n \"than\",\n \"that\",\n \"the\",\n \"their\",\n \"them\",\n \"then\",\n \"there\",\n \"these\",\n \"they\",\n \"this\",\n \"to\",\n \"too\",\n \"up\",\n \"us\",\n \"very\",\n \"was\",\n \"we\",\n \"were\",\n \"what\",\n \"when\",\n \"where\",\n \"which\",\n \"while\",\n \"who\",\n \"whom\",\n \"why\",\n \"will\",\n \"with\",\n \"would\",\n \"you\",\n \"your\",\n]);\n\n/** Tokenize a task string into lowercase keywords, dropping stopwords and short tokens. */\nfunction tokenize(task: string): string[] {\n return task\n .split(/[\\s\\-_/.,;:!?()[\\]{}'\"]+/)\n .map((t) => t.toLowerCase())\n .filter((t) => t.length > 1 && !STOPWORDS.has(t));\n}\n\n/** Field weights for keyword matching. */\nconst WEIGHT_TAGS = 3;\nconst WEIGHT_TITLE = 3;\nconst WEIGHT_SECTIONS = 2;\nconst WEIGHT_BODY = 1;\n\n/** Minimum id length considered for verbatim matching (avoids ids like \"a\"). */\nconst ID_MATCH_MIN_LENGTH = 3;\n\n/** Graph propagation factor for immediate neighbors. */\nconst GRAPH_BOOST_FACTOR = 0.5;\n\n/** Minimum normalized score to include a spec. */\nconst SCORE_THRESHOLD = 0.1;\n\n/**\n * Score specs by keyword relevance to a task string with graph propagation.\n *\n * - If no task or empty keywords after stopword removal, all specs get score 1.0.\n * - Keywords are matched with substring includes across weighted fields.\n * - Immediate graph neighbors of matching specs receive a boost.\n * - Results are normalized 0-1 and filtered by threshold.\n */\nexport function scoreSpecs(\n specs: Map<string, ParsedSpec>,\n task: string | undefined,\n graph: DependencyGraph,\n): RelevanceScore[] {\n const keywords = task ? tokenize(task) : [];\n\n // No keywords: all specs equally relevant\n if (keywords.length === 0) {\n const results: RelevanceScore[] = [];\n for (const specId of specs.keys()) {\n results.push({\n specId,\n score: 1.0,\n rawScore: 1.0,\n matchedKeywords: [],\n graphBoosted: false,\n });\n }\n return results;\n }\n\n // Score each spec by keyword hits across weighted fields\n const rawScores = new Map<string, number>();\n const matchedMap = new Map<string, Set<string>>();\n const idMatchedSet = new Set<string>();\n const taskLower = (task ?? \"\").toLowerCase();\n\n for (const [specId, spec] of specs) {\n let weightedHits = 0;\n const matched = new Set<string>();\n\n // Verbatim id match: a task that names a spec dominates keyword scoring\n const idLower = specId.toLowerCase();\n if (idLower.length >= ID_MATCH_MIN_LENGTH && taskLower.includes(idLower)) {\n idMatchedSet.add(specId);\n }\n\n for (const keyword of keywords) {\n let hit = false;\n\n // Tags (3x)\n const tags: unknown[] = (spec.frontmatter.tags as unknown[] | undefined) ?? [];\n for (const tag of tags) {\n if (typeof tag === \"string\" && tag.toLowerCase().includes(keyword)) {\n weightedHits += WEIGHT_TAGS;\n hit = true;\n break;\n }\n }\n\n // Title (3x)\n const title = spec.frontmatter.title;\n if (typeof title === \"string\" && title.toLowerCase().includes(keyword)) {\n weightedHits += WEIGHT_TITLE;\n hit = true;\n }\n\n // Sections (2x)\n for (const heading of spec.sections) {\n if (heading.toLowerCase().includes(keyword)) {\n weightedHits += WEIGHT_SECTIONS;\n hit = true;\n break;\n }\n }\n\n // Body content (1x)\n if (spec.content.toLowerCase().includes(keyword)) {\n weightedHits += WEIGHT_BODY;\n hit = true;\n }\n\n if (hit) {\n matched.add(keyword);\n }\n }\n\n const raw = weightedHits / keywords.length;\n rawScores.set(specId, raw);\n matchedMap.set(specId, matched);\n }\n\n // Graph propagation: boost immediate neighbors\n const boostScores = new Map<string, number>();\n const boostedSet = new Set<string>();\n\n for (const [specId, rawScore] of rawScores) {\n if (rawScore <= 0) continue;\n\n const boostAmount = rawScore * GRAPH_BOOST_FACTOR;\n\n // Find immediate neighbors from graph edges\n for (const edge of graph.edges) {\n let neighborId: string | undefined;\n if (edge.from === specId) {\n neighborId = edge.to;\n } else if (edge.to === specId) {\n neighborId = edge.from;\n }\n\n if (neighborId !== undefined && specs.has(neighborId)) {\n const existing = boostScores.get(neighborId) ?? 0;\n boostScores.set(neighborId, Math.max(existing, boostAmount));\n }\n }\n }\n\n // Combine raw + boost scores\n const finalRawScores = new Map<string, number>();\n for (const specId of specs.keys()) {\n const raw = rawScores.get(specId) ?? 0;\n const boost = boostScores.get(specId) ?? 0;\n const combined = raw + boost;\n finalRawScores.set(specId, combined);\n if (boost > 0 && raw === 0) {\n boostedSet.add(specId);\n }\n }\n\n // Find max for normalization\n let maxScore = 0;\n for (const score of finalRawScores.values()) {\n if (score > maxScore) maxScore = score;\n }\n\n // Build results, normalize, and filter. A spec the task names verbatim is\n // clamped to 1.0 — an explicit mention always outranks keyword inference —\n // without distorting the normalization of the other specs' scores.\n const results: RelevanceScore[] = [];\n for (const [specId] of specs) {\n const combined = finalRawScores.get(specId) ?? 0;\n const idMatched = idMatchedSet.has(specId);\n const normalized = idMatched ? 1.0 : maxScore > 0 ? combined / maxScore : 0;\n\n if (normalized < SCORE_THRESHOLD) continue;\n\n results.push({\n specId,\n score: normalized,\n rawScore: rawScores.get(specId) ?? 0,\n matchedKeywords: [...(matchedMap.get(specId) ?? [])],\n graphBoosted: boostedSet.has(specId),\n idMatched,\n });\n }\n\n // Sort descending by score; ties prefer specs the task named explicitly\n results.sort(\n (a, b) => b.score - a.score || Number(b.idMatched ?? false) - Number(a.idMatched ?? false),\n );\n\n return results;\n}\n\n/**\n * Score specs by explicit IDs. Named specs get 1.0, their transitive\n * upstream dependencies get 0.5.\n *\n * Throws if any specId is not found in the specs map.\n */\nexport function scoreSpecsByIds(\n specs: Map<string, ParsedSpec>,\n specIds: string[],\n graph: DependencyGraph,\n): RelevanceScore[] {\n // Validate all IDs exist\n for (const id of specIds) {\n if (!specs.has(id)) {\n const available = [...specs.keys()].join(\", \");\n throw new Error(`Unknown spec: \"${id}\". Available specs: ${available}`);\n }\n }\n\n const scoreMap = new Map<string, number>();\n\n // Named specs get 1.0\n for (const id of specIds) {\n scoreMap.set(id, 1.0);\n }\n\n // Upstream deps get 0.5 (unless already named at 1.0)\n for (const id of specIds) {\n const upstream = graph.getUpstream(id);\n for (const depId of upstream) {\n if (!scoreMap.has(depId) && specs.has(depId)) {\n scoreMap.set(depId, 0.5);\n }\n }\n }\n\n const results: RelevanceScore[] = [];\n for (const [specId, score] of scoreMap) {\n results.push({\n specId,\n score,\n rawScore: score,\n matchedKeywords: [],\n graphBoosted: score < 1.0,\n });\n }\n\n // Sort descending by score\n results.sort((a, b) => b.score - a.score);\n\n return results;\n}\n","import { countTokens } from \"@specdx/core\";\nimport type { ParsedSection } from \"@specdx/core\";\nimport type { CompressedSpec, CompressedSection, CompressionOptions } from \"./types.js\";\n\n/**\n * Returns true when `dateStr` is more than `days` days before now.\n * Returns false for invalid / missing dates (treat as fresh).\n */\nfunction isOlderThanDays(dateStr: string | undefined, days: number): boolean {\n if (!dateStr) return false;\n const ms = Date.parse(dateStr);\n if (Number.isNaN(ms)) return false;\n const diffMs = Date.now() - ms;\n return diffMs > days * 24 * 60 * 60 * 1000;\n}\n\n/**\n * Compress a single spec according to the provided options.\n */\nexport function compressSpec(\n specId: string,\n type: string,\n title: string,\n status: string | undefined,\n updatedDate: string | undefined,\n parsedSections: ParsedSection[],\n options: CompressionOptions,\n): CompressedSpec {\n // 1. Collapse superseded ADRs\n if (type === \"adr\" && status === \"superseded\" && options.collapseResolvedAdrs) {\n return {\n specId,\n type,\n title,\n sections: [],\n collapsed: true,\n collapsedSummary: `[ADR] ${title} — superseded`,\n };\n }\n\n // 2. Determine staleness\n const stale = options.stableDays > 0 && isOlderThanDays(updatedDate, options.stableDays);\n\n // 3. Process sections\n const boilerplateSet = new Set(options.boilerplateSections.map((s) => s.toLowerCase()));\n\n const sections: CompressedSection[] = [];\n\n for (const section of parsedSections) {\n // 3a. Strip boilerplate\n if (\n options.stripBoilerplate &&\n section.heading &&\n boilerplateSet.has(section.heading.toLowerCase())\n ) {\n continue;\n }\n\n // 3b. Collapse stale headed sections (preserve preamble)\n if (stale && section.heading) {\n const stub = `[Unchanged since ${updatedDate} — ${section.tokens} tokens omitted]`;\n sections.push({\n heading: section.heading,\n content: stub,\n tokens: countTokens(stub),\n compressed: true,\n originalTokens: section.tokens,\n });\n continue;\n }\n\n // 3c. Pass through unchanged\n sections.push({\n heading: section.heading,\n content: section.content,\n tokens: section.tokens,\n compressed: false,\n originalTokens: section.tokens,\n });\n }\n\n return {\n specId,\n type,\n title,\n sections,\n collapsed: false,\n };\n}\n","import { countTokens } from \"@specdx/core\";\nimport type { ParsedSpec } from \"@specdx/core\";\nimport { compressSpec } from \"./compressor.js\";\nimport type {\n CompressedSpec,\n CompressionOptions,\n PackStats,\n RelevanceScore,\n SpecAllocation,\n} from \"./types.js\";\n\n/** Options for the token allocator. */\nexport interface AllocatorOptions {\n /** Maximum token budget. */\n budget: number;\n /** When true, include full spec content without compression. */\n full: boolean;\n /** Compression settings (used when `full` is false). */\n compression: CompressionOptions;\n}\n\n/** Result of the allocation pass. */\nexport interface AllocationResult {\n /** Compressed specs that fit within the budget. */\n specs: CompressedSpec[];\n /** Statistics about how the budget was spent. */\n stats: PackStats;\n}\n\n/** Relevance at or above which a spec is trimmed to fit rather than excluded. */\nconst HIGH_RELEVANCE = 0.75;\n\n/** Minimum remaining budget worth trimming into. */\nconst MIN_TRIM_BUDGET = 150;\n\n/** Build the marker text for a contiguous run of omitted sections. */\nfunction omissionMarker(sections: CompressedSpec[\"sections\"]): string {\n const names = sections.map((s) => s.heading || \"(untitled)\");\n const noun = names.length === 1 ? \"section\" : \"sections\";\n return `[${names.length} ${noun} omitted to fit token budget: ${names.join(\", \")}]`;\n}\n\n/**\n * Produce a variant of `compressed` that fits within `budget` by keeping\n * sections in order while they fit and replacing each contiguous run of\n * omitted sections with an explicit marker naming them. Marker cost is\n * reserved out of the budget before sections are kept, so markers are always\n * emitted — a trimmed spec must never read as complete (issue #12).\n * Returns null when not even one real section fits.\n */\nfunction trimToBudget(\n compressed: CompressedSpec,\n budget: number,\n): { spec: CompressedSpec; tokens: number } | null {\n const sections = compressed.sections;\n let reserve = 0;\n\n // The kept set only shrinks as the reserve grows, so this converges.\n for (;;) {\n const effective = budget - reserve;\n const keep: boolean[] = new Array(sections.length).fill(false);\n let used = 0;\n let keptReal = false;\n\n for (let i = 0; i < sections.length; i++) {\n if (used + sections[i]!.tokens <= effective) {\n keep[i] = true;\n used += sections[i]!.tokens;\n keptReal = true;\n }\n }\n\n if (!keptReal) return null;\n\n // Group omitted sections into contiguous runs and price their markers.\n interface OmittedRun {\n start: number;\n sections: CompressedSpec[\"sections\"];\n marker: string;\n markerTokens: number;\n }\n const runs: OmittedRun[] = [];\n for (let i = 0; i < sections.length; i++) {\n if (keep[i]) continue;\n const start = i;\n const run: CompressedSpec[\"sections\"] = [];\n while (i < sections.length && !keep[i]) {\n run.push(sections[i]!);\n i++;\n }\n i--;\n const marker = omissionMarker(run);\n runs.push({ start, sections: run, marker, markerTokens: countTokens(marker) });\n }\n\n const markerTokens = runs.reduce((sum, r) => sum + r.markerTokens, 0);\n if (markerTokens > reserve) {\n reserve = markerTokens;\n continue;\n }\n\n // Assemble output: kept sections in order, markers at each cut.\n const out: CompressedSpec[\"sections\"] = [];\n for (let i = 0; i < sections.length; i++) {\n const run = runs.find((r) => r.start === i);\n if (run) {\n out.push({\n heading: \"\",\n content: run.marker,\n tokens: run.markerTokens,\n compressed: true,\n originalTokens: run.sections.reduce((sum, s) => sum + s.tokens, 0),\n omittedSections: run.sections.length,\n });\n i += run.sections.length - 1;\n continue;\n }\n out.push(sections[i]!);\n }\n\n return { spec: { ...compressed, sections: out }, tokens: used + markerTokens };\n }\n}\n\n/**\n * Allocate a token budget across specs, sorted by relevance.\n *\n * 1. Build specId -> ParsedSpec map\n * 2. Compress each spec (or pass through in full mode)\n * 3. Calculate token counts\n * 4. Sort by relevance descending\n * 5. Greedily include specs until budget is exhausted\n * 6. Build stats\n */\nexport function allocate(\n specs: ParsedSpec[],\n scores: RelevanceScore[],\n options: AllocatorOptions,\n): AllocationResult {\n // 1. Build specId -> ParsedSpec map\n const specMap = new Map<string, ParsedSpec>();\n for (const spec of specs) {\n specMap.set(spec.frontmatter.id, spec);\n }\n\n // 2. Compress each scored spec and compute token counts\n interface ScoredCompressed {\n compressed: CompressedSpec;\n relevance: number;\n tokens: number;\n idMatched: boolean;\n }\n\n const items: ScoredCompressed[] = [];\n\n for (const score of scores) {\n const spec = specMap.get(score.specId);\n if (!spec) continue;\n\n let compressed: CompressedSpec;\n\n if (options.full) {\n // No compression: pass through sections unchanged\n compressed = {\n specId: score.specId,\n type: String(spec.frontmatter.type),\n title: String(spec.frontmatter.title),\n sections: spec.parsedSections.map((s) => ({\n heading: s.heading,\n content: s.content,\n tokens: s.tokens,\n compressed: false,\n originalTokens: s.tokens,\n })),\n collapsed: false,\n };\n } else {\n compressed = compressSpec(\n score.specId,\n String(spec.frontmatter.type),\n String(spec.frontmatter.title),\n spec.frontmatter.status as string | undefined,\n spec.frontmatter.updated as string | undefined,\n spec.parsedSections,\n options.compression,\n );\n }\n\n // 3. Calculate token count\n let tokens: number;\n if (compressed.collapsed) {\n tokens = countTokens(compressed.collapsedSummary ?? \"\");\n } else {\n tokens = 0;\n for (const section of compressed.sections) {\n tokens += section.tokens;\n }\n }\n\n items.push({ compressed, relevance: score.score, tokens, idMatched: score.idMatched ?? false });\n }\n\n // 4. Sort by relevance descending; ties prefer specs the task named explicitly\n items.sort((a, b) => b.relevance - a.relevance || Number(b.idMatched) - Number(a.idMatched));\n\n // 5. Greedy selection within budget\n const totalTokens = items.reduce((sum, item) => sum + item.tokens, 0);\n const withinBudget = totalTokens <= options.budget;\n\n const included: ScoredCompressed[] = [];\n const excluded: ScoredCompressed[] = [];\n let usedTokens = 0;\n\n if (withinBudget) {\n // Everything fits\n for (const item of items) {\n included.push(item);\n usedTokens += item.tokens;\n }\n } else {\n // Greedy: include from highest to lowest relevance. High-relevance specs\n // that don't fit are trimmed into the remaining budget before being\n // excluded — a task-named spec should never silently drop out.\n for (const item of items) {\n if (usedTokens + item.tokens <= options.budget) {\n included.push(item);\n usedTokens += item.tokens;\n continue;\n }\n const remaining = options.budget - usedTokens;\n if (\n (item.idMatched || item.relevance >= HIGH_RELEVANCE) &&\n remaining >= MIN_TRIM_BUDGET &&\n !item.compressed.collapsed\n ) {\n const trimmed = trimToBudget(item.compressed, remaining);\n if (trimmed) {\n included.push({ ...item, compressed: trimmed.spec, tokens: trimmed.tokens });\n usedTokens += trimmed.tokens;\n continue;\n }\n }\n excluded.push(item);\n }\n }\n\n // 6. Build stats\n let sectionsCompressed = 0;\n let sectionsOmitted = 0;\n for (const item of included) {\n for (const section of item.compressed.sections) {\n if (section.compressed) {\n sectionsCompressed++;\n }\n sectionsOmitted += section.omittedSections ?? 0;\n }\n }\n\n const allocations: SpecAllocation[] = [];\n\n // Add included specs\n for (const item of included) {\n allocations.push({\n specId: item.compressed.specId,\n type: item.compressed.type,\n relevance: item.relevance,\n tokens: item.tokens,\n compressed: item.compressed.collapsed || item.compressed.sections.some((s) => s.compressed),\n included: true,\n });\n }\n\n // Add excluded specs\n for (const item of excluded) {\n allocations.push({\n specId: item.compressed.specId,\n type: item.compressed.type,\n relevance: item.relevance,\n tokens: item.tokens,\n compressed: item.compressed.collapsed || item.compressed.sections.some((s) => s.compressed),\n included: false,\n });\n }\n\n const stats: PackStats = {\n budget: options.budget,\n used: usedTokens,\n specsIncluded: included.length,\n specsExcluded: excluded.length,\n sectionsCompressed,\n sectionsOmitted,\n allocations,\n };\n\n return {\n specs: included.map((item) => item.compressed),\n stats,\n };\n}\n","import type { CompressedSpec, PackStats } from \"../types.js\";\n\nfunction escapeXml(text: string): string {\n return text\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\");\n}\n\n/**\n * Format compressed specs as XML.\n *\n * @param specs - Compressed specs to render.\n * @param stats - Pack statistics with allocation details.\n * @returns An XML string representing the packed context.\n */\nexport function formatXml(specs: CompressedSpec[], stats: PackStats): string {\n const lines: string[] = [];\n\n lines.push(\n `<context budget=\"${stats.budget}\" used=\"${stats.used}\" specs=\"${stats.specsIncluded}\" compressed=\"${stats.sectionsCompressed}\" omitted=\"${stats.sectionsOmitted}\">`,\n );\n\n for (const spec of specs) {\n const alloc = stats.allocations.find((a) => a.specId === spec.specId);\n const relevance = alloc?.relevance ?? 0;\n const tokens = alloc?.tokens ?? 0;\n\n if (spec.collapsed) {\n lines.push(\n ` <spec id=\"${escapeXml(spec.specId)}\" type=\"${escapeXml(spec.type)}\" relevance=\"${relevance}\" tokens=\"${tokens}\" collapsed=\"true\">`,\n );\n lines.push(` ${escapeXml(spec.collapsedSummary ?? \"\")}`);\n lines.push(\" </spec>\");\n } else {\n lines.push(\n ` <spec id=\"${escapeXml(spec.specId)}\" type=\"${escapeXml(spec.type)}\" relevance=\"${relevance}\" tokens=\"${tokens}\">`,\n );\n for (const section of spec.sections) {\n const compressedAttr = section.compressed ? ' compressed=\"true\"' : \"\";\n lines.push(` <section name=\"${escapeXml(section.heading)}\"${compressedAttr}>`);\n lines.push(` ${escapeXml(section.content)}`);\n lines.push(\" </section>\");\n }\n lines.push(\" </spec>\");\n }\n }\n\n lines.push(\"</context>\");\n\n return lines.join(\"\\n\");\n}\n","import type { CompressedSpec, PackStats } from \"../types.js\";\n\n/**\n * Format compressed specs as Markdown.\n *\n * @param specs - Compressed specs to render.\n * @param stats - Pack statistics with allocation details.\n * @returns A Markdown string representing the packed context.\n */\nexport function formatMarkdown(specs: CompressedSpec[], stats: PackStats): string {\n const parts: string[] = [];\n\n for (let i = 0; i < specs.length; i++) {\n const spec = specs[i]!;\n const alloc = stats.allocations.find((a) => a.specId === spec.specId);\n const relevance = alloc?.relevance ?? 0;\n\n if (i > 0) {\n parts.push(\"---\");\n parts.push(\"\");\n }\n\n parts.push(`# ${spec.specId} (${spec.type}) [relevance: ${relevance}]`);\n parts.push(\"\");\n\n if (spec.collapsed) {\n parts.push(spec.collapsedSummary ?? \"\");\n parts.push(\"\");\n } else {\n for (const section of spec.sections) {\n if (section.heading) {\n parts.push(`## ${section.heading}`);\n parts.push(\"\");\n }\n parts.push(section.content);\n parts.push(\"\");\n }\n }\n }\n\n return parts.join(\"\\n\");\n}\n","import type { CompressedSpec, PackStats } from \"../types.js\";\n\ninterface JsonSection {\n name: string;\n content: string;\n compressed: boolean;\n}\n\ninterface JsonSpec {\n id: string;\n type: string;\n relevance: number;\n tokens: number;\n collapsed: boolean;\n summary?: string;\n sections: JsonSection[];\n}\n\ninterface JsonOutput {\n budget: number;\n used: number;\n sectionsOmitted: number;\n specs: JsonSpec[];\n}\n\n/**\n * Format compressed specs as a JSON string.\n *\n * @param specs - Compressed specs to render.\n * @param stats - Pack statistics with allocation details.\n * @returns A pretty-printed JSON string representing the packed context.\n */\nexport function formatJson(specs: CompressedSpec[], stats: PackStats): string {\n const output: JsonOutput = {\n budget: stats.budget,\n used: stats.used,\n sectionsOmitted: stats.sectionsOmitted,\n specs: specs.map((spec) => {\n const alloc = stats.allocations.find((a) => a.specId === spec.specId);\n const relevance = alloc?.relevance ?? 0;\n const tokens = alloc?.tokens ?? 0;\n\n const jsonSpec: JsonSpec = {\n id: spec.specId,\n type: spec.type,\n relevance,\n tokens,\n collapsed: spec.collapsed,\n sections: spec.sections.map((s) => ({\n name: s.heading,\n content: s.content,\n compressed: s.compressed,\n })),\n };\n\n if (spec.collapsed) {\n jsonSpec.summary = spec.collapsedSummary ?? \"\";\n }\n\n return jsonSpec;\n }),\n };\n\n return JSON.stringify(output, null, 2);\n}\n","import type { ParsedSpec, DependencyGraph } from \"@specdx/core\";\nimport type { PackConfig } from \"@specdx/schema\";\nimport type {\n PackOptions,\n PackResult,\n CompressionOptions,\n CompressedSpec,\n RelevanceScore,\n} from \"./types.js\";\nimport { scoreSpecs, scoreSpecsByIds } from \"./resolver.js\";\nimport { allocate } from \"./allocator.js\";\nimport { formatXml } from \"./formatters/xml.js\";\nimport { formatMarkdown } from \"./formatters/markdown.js\";\nimport { formatJson } from \"./formatters/json.js\";\n\nexport type {\n PackOptions,\n PackResult,\n PackStats,\n SpecAllocation,\n RelevanceScore,\n CompressedSpec,\n CompressedSection,\n CompressionOptions,\n} from \"./types.js\";\n\nexport { scoreSpecs, scoreSpecsByIds } from \"./resolver.js\";\nexport { allocate, type AllocatorOptions, type AllocationResult } from \"./allocator.js\";\nexport { compressSpec } from \"./compressor.js\";\nexport { formatXml } from \"./formatters/xml.js\";\nexport { formatMarkdown } from \"./formatters/markdown.js\";\nexport { formatJson } from \"./formatters/json.js\";\n\n/**\n * Default empty dependency graph used when none is provided.\n */\nfunction emptyGraph(): DependencyGraph {\n return {\n nodes: [],\n edges: [],\n topologicalSort: () => [],\n getDownstream: () => [],\n getUpstream: () => [],\n };\n}\n\n/**\n * Build CompressionOptions from PackConfig with sensible defaults.\n */\nfunction buildCompressionOptions(packConfig: PackConfig | undefined): CompressionOptions {\n const compression = packConfig?.compression;\n return {\n stripBoilerplate: compression?.strip_boilerplate ?? true,\n stableDays: compression?.stable_days ?? 7,\n collapseResolvedAdrs: compression?.collapse_resolved_adrs ?? true,\n boilerplateSections: packConfig?.boilerplate_sections ?? [\n \"Changelog\",\n \"Revision History\",\n \"Document History\",\n ],\n };\n}\n\n/**\n * Pack specs into a formatted context string within a token budget.\n *\n * Pipeline:\n * 1. Resolve relevance scores\n * 2. Allocate token budget across specs\n * 3. Format output in the requested format\n */\nexport function pack(\n specs: ParsedSpec[],\n options: PackOptions,\n packConfig: PackConfig | undefined,\n graph: DependencyGraph | undefined,\n): PackResult {\n // 1. Resolve defaults\n const budget = options.budget ?? packConfig?.max_tokens ?? 12000;\n const format = options.format ?? packConfig?.format ?? \"xml\";\n const full = options.full ?? false;\n const compression = buildCompressionOptions(packConfig);\n const resolvedGraph = graph ?? emptyGraph();\n\n // 2. Extract project-context specs and reserve budget\n const projectContextSpecs: ParsedSpec[] = [];\n const regularSpecs: ParsedSpec[] = [];\n for (const spec of specs) {\n if (spec.frontmatter.type === \"project-context\") {\n projectContextSpecs.push(spec);\n } else {\n regularSpecs.push(spec);\n }\n }\n\n let reservedTokens = 0;\n let reservedCompressed: CompressedSpec[] = [];\n if (projectContextSpecs.length > 0) {\n const maxReserved = Math.min(budget, 2000);\n const ctxScores: RelevanceScore[] = projectContextSpecs.map((s) => ({\n specId: s.frontmatter.id,\n score: 1.0,\n rawScore: 1.0,\n matchedKeywords: [],\n graphBoosted: false,\n }));\n const ctxResult = allocate(projectContextSpecs, ctxScores, {\n budget: maxReserved,\n full: true,\n compression,\n });\n reservedCompressed = ctxResult.specs;\n reservedTokens = ctxResult.stats.used;\n }\n\n const regularBudget = Math.max(0, budget - reservedTokens);\n\n // 3. Build spec map for resolver (regular specs only)\n const specMap = new Map<string, ParsedSpec>();\n for (const spec of regularSpecs) {\n specMap.set(spec.frontmatter.id, spec);\n }\n\n // 4. Stage 1 - Resolve\n const scores = options.specs\n ? scoreSpecsByIds(specMap, options.specs, resolvedGraph)\n : scoreSpecs(specMap, options.task, resolvedGraph);\n\n // 5. Stage 2 - Allocate\n const { specs: compressedSpecs, stats } = allocate(regularSpecs, scores, {\n budget: regularBudget,\n full,\n compression,\n });\n\n // 6. Combine project-context and regular specs\n const allCompressed = [...reservedCompressed, ...compressedSpecs];\n\n // Update stats to include reserved specs\n stats.budget = budget;\n stats.used += reservedTokens;\n stats.specsIncluded += reservedCompressed.length;\n for (const ctx of reservedCompressed) {\n stats.allocations.unshift({\n specId: ctx.specId,\n type: ctx.type,\n relevance: 1.0,\n tokens: reservedTokens,\n compressed: false,\n included: true,\n });\n }\n\n // 7. Dry run: return stats without output\n if (options.dryRun) {\n return { output: \"\", stats };\n }\n\n // 8. Stage 3 - Format\n let output: string;\n switch (format) {\n case \"markdown\":\n output = formatMarkdown(allCompressed, stats);\n break;\n case \"json\":\n output = formatJson(allCompressed, stats);\n break;\n default:\n output = formatXml(allCompressed, stats);\n break;\n }\n\n return { output, stats };\n}\n"],"mappings":";;;;;AAMA,IAAM,YAAY,oBAAI,IAAI;EACxB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD;AAGD,SAAS,SAAS,MAAY;AAC5B,SAAO,KACJ,MAAM,0BAA0B,EAChC,IAAI,CAAC,MAAM,EAAE,YAAW,CAAE,EAC1B,OAAO,CAAC,MAAM,EAAE,SAAS,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC;AACpD;AAGA,IAAM,cAAc;AACpB,IAAM,eAAe;AACrB,IAAM,kBAAkB;AACxB,IAAM,cAAc;AAGpB,IAAM,sBAAsB;AAG5B,IAAM,qBAAqB;AAG3B,IAAM,kBAAkB;AAUlB,SAAU,WACd,OACA,MACA,OAAsB;AAEtB,QAAM,WAAW,OAAO,SAAS,IAAI,IAAI,CAAA;AAGzC,MAAI,SAAS,WAAW,GAAG;AACzB,UAAMA,WAA4B,CAAA;AAClC,eAAW,UAAU,MAAM,KAAI,GAAI;AACjC,MAAAA,SAAQ,KAAK;QACX;QACA,OAAO;QACP,UAAU;QACV,iBAAiB,CAAA;QACjB,cAAc;OACf;IACH;AACA,WAAOA;EACT;AAGA,QAAM,YAAY,oBAAI,IAAG;AACzB,QAAM,aAAa,oBAAI,IAAG;AAC1B,QAAM,eAAe,oBAAI,IAAG;AAC5B,QAAM,aAAa,QAAQ,IAAI,YAAW;A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Q,IAAI,KAAK,YAAY,IAAI,IAAI;EACvC;AAGA,QAAM,SAAS,QAAQ,QACnB,gBAAgB,SAAS,QAAQ,OAAO,aAAa,IACrD,WAAW,SAAS,QAAQ,MAAM,aAAa;AAGnD,QAAM,EAAE,OAAO,iBAAiB,MAAK,IAAK,SAAS,cAAc,QAAQ;IACvE,QAAQ;IACR;IACA;GACD;AAGD,QAAM,gBAAgB,CAAC,GAAG,oBAAoB,GAAG,eAAe;AAGhE,QAAM,SAAS;AACf,QAAM,QAAQ;AACd,QAAM,iBAAiB,mBAAmB;AAC1C,aAAW,OAAO,oBAAoB;AACpC,UAAM,YAAY,QAAQ;MACxB,QAAQ,IAAI;MACZ,MAAM,IAAI;MACV,WAAW;MACX,QAAQ;MACR,YAAY;MACZ,UAAU;KACX;EACH;AAGA,MAAI,QAAQ,QAAQ;AAClB,WAAO,EAAE,QAAQ,IAAI,MAAK;EAC5B;AAGA,MAAI;AACJ,UAAQ,QAAQ;IACd,KAAK;AACH,eAAS,eAAe,eAAe,KAAK;AAC5C;IACF,KAAK;AACH,eAAS,WAAW,eAAe,KAAK;AACxC;IACF;AACE,eAAS,UAAU,eAAe,KAAK;AACvC;EACJ;AAEA,SAAO,EAAE,QAAQ,MAAK;AACxB;","names":["results"]}
|
|
@@ -10,6 +10,10 @@ var SPEC_TYPES = [
|
|
|
10
10
|
"quick-spec",
|
|
11
11
|
"project-context"
|
|
12
12
|
];
|
|
13
|
+
var DEPENDENCY_RELATIONSHIPS = {
|
|
14
|
+
"depends-on": "self-requires-target",
|
|
15
|
+
"implemented-by": "target-requires-self"
|
|
16
|
+
};
|
|
13
17
|
|
|
14
18
|
// ../schema/dist/sections.js
|
|
15
19
|
var REQUIRED_SECTIONS = {
|
|
@@ -41,30 +45,123 @@ var base_spec_default = {
|
|
|
41
45
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
42
46
|
type: "object",
|
|
43
47
|
properties: {
|
|
44
|
-
id: {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
id: {
|
|
49
|
+
type: "string",
|
|
50
|
+
minLength: 1
|
|
51
|
+
},
|
|
52
|
+
type: {
|
|
53
|
+
type: "string",
|
|
54
|
+
enum: [
|
|
55
|
+
"prd",
|
|
56
|
+
"technical-design",
|
|
57
|
+
"user-story",
|
|
58
|
+
"test-plan",
|
|
59
|
+
"adr",
|
|
60
|
+
"api-contract",
|
|
61
|
+
"epic",
|
|
62
|
+
"quick-spec",
|
|
63
|
+
"project-context"
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
title: {
|
|
67
|
+
type: "string",
|
|
68
|
+
minLength: 1
|
|
69
|
+
},
|
|
70
|
+
status: {
|
|
71
|
+
type: "string",
|
|
72
|
+
enum: [
|
|
73
|
+
"draft",
|
|
74
|
+
"review",
|
|
75
|
+
"approved",
|
|
76
|
+
"superseded"
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
version: {
|
|
80
|
+
type: "string"
|
|
81
|
+
},
|
|
82
|
+
created: {
|
|
83
|
+
type: "string",
|
|
84
|
+
format: "date"
|
|
85
|
+
},
|
|
86
|
+
updated: {
|
|
87
|
+
type: "string",
|
|
88
|
+
format: "date"
|
|
89
|
+
},
|
|
90
|
+
authors: {
|
|
91
|
+
type: "array",
|
|
92
|
+
items: {
|
|
93
|
+
type: "string"
|
|
94
|
+
},
|
|
95
|
+
minItems: 1
|
|
96
|
+
},
|
|
97
|
+
tags: {
|
|
98
|
+
type: "array",
|
|
99
|
+
items: {
|
|
100
|
+
type: "string"
|
|
101
|
+
},
|
|
102
|
+
default: []
|
|
103
|
+
},
|
|
53
104
|
references: {
|
|
54
105
|
type: "array",
|
|
55
106
|
items: {
|
|
56
107
|
type: "object",
|
|
57
108
|
properties: {
|
|
58
|
-
id: {
|
|
59
|
-
|
|
109
|
+
id: {
|
|
110
|
+
type: "string"
|
|
111
|
+
},
|
|
112
|
+
relationship: {
|
|
113
|
+
type: "string",
|
|
114
|
+
enum: [
|
|
115
|
+
"implemented-by",
|
|
116
|
+
"decomposed-into",
|
|
117
|
+
"depends-on",
|
|
118
|
+
"supersedes",
|
|
119
|
+
"related-to"
|
|
120
|
+
]
|
|
121
|
+
}
|
|
60
122
|
},
|
|
61
|
-
required: [
|
|
123
|
+
required: [
|
|
124
|
+
"id",
|
|
125
|
+
"relationship"
|
|
126
|
+
],
|
|
127
|
+
additionalProperties: false
|
|
128
|
+
},
|
|
129
|
+
default: []
|
|
130
|
+
},
|
|
131
|
+
artifacts: {
|
|
132
|
+
type: "array",
|
|
133
|
+
items: {
|
|
134
|
+
type: "object",
|
|
135
|
+
properties: {
|
|
136
|
+
path: {
|
|
137
|
+
type: "string",
|
|
138
|
+
minLength: 1
|
|
139
|
+
},
|
|
140
|
+
exports: {
|
|
141
|
+
type: "array",
|
|
142
|
+
items: {
|
|
143
|
+
type: "string",
|
|
144
|
+
minLength: 1
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
required: [
|
|
149
|
+
"path"
|
|
150
|
+
],
|
|
62
151
|
additionalProperties: false
|
|
63
152
|
},
|
|
64
153
|
default: []
|
|
65
154
|
}
|
|
66
155
|
},
|
|
67
|
-
required: [
|
|
156
|
+
required: [
|
|
157
|
+
"id",
|
|
158
|
+
"type",
|
|
159
|
+
"title",
|
|
160
|
+
"status",
|
|
161
|
+
"version",
|
|
162
|
+
"created",
|
|
163
|
+
"authors"
|
|
164
|
+
],
|
|
68
165
|
additionalProperties: true
|
|
69
166
|
};
|
|
70
167
|
|
|
@@ -89,7 +186,7 @@ var config_default = {
|
|
|
89
186
|
type: "object",
|
|
90
187
|
properties: {
|
|
91
188
|
path: { type: "string" },
|
|
92
|
-
type: { type: "string", enum: ["prd", "technical-design", "user-story", "test-plan", "adr", "api-contract"] },
|
|
189
|
+
type: { type: "string", enum: ["prd", "technical-design", "user-story", "test-plan", "adr", "api-contract", "epic", "quick-spec", "project-context"] },
|
|
93
190
|
required: { type: "boolean", default: false },
|
|
94
191
|
requires: { type: "array", items: { type: "string" } },
|
|
95
192
|
owner: { type: "string" }
|
|
@@ -298,9 +395,13 @@ var project_context_default = {
|
|
|
298
395
|
// ../schema/dist/validator.js
|
|
299
396
|
import * as addFormatsNs from "ajv-formats";
|
|
300
397
|
var addFormats = addFormatsNs.default ?? addFormatsNs;
|
|
398
|
+
var runtimeBaseSpecSchema = structuredClone(base_spec_default);
|
|
399
|
+
runtimeBaseSpecSchema.properties.type.enum = [...SPEC_TYPES];
|
|
400
|
+
var runtimeConfigSchema = structuredClone(config_default);
|
|
401
|
+
runtimeConfigSchema.properties.specs.additionalProperties.properties.type.enum = [...SPEC_TYPES];
|
|
301
402
|
var ajv = new AjvClass({ allErrors: true, strict: true });
|
|
302
403
|
addFormats(ajv, ["date"]);
|
|
303
|
-
ajv.addSchema(
|
|
404
|
+
ajv.addSchema(runtimeBaseSpecSchema);
|
|
304
405
|
var specValidators = {
|
|
305
406
|
prd: ajv.compile(prd_default),
|
|
306
407
|
"technical-design": ajv.compile(technical_design_default),
|
|
@@ -312,7 +413,7 @@ var specValidators = {
|
|
|
312
413
|
"quick-spec": ajv.compile(quick_spec_default),
|
|
313
414
|
"project-context": ajv.compile(project_context_default)
|
|
314
415
|
};
|
|
315
|
-
var configValidator = ajv.compile(
|
|
416
|
+
var configValidator = ajv.compile(runtimeConfigSchema);
|
|
316
417
|
function validateSpec(type, data) {
|
|
317
418
|
const validate = specValidators[type];
|
|
318
419
|
if (!validate) {
|
|
@@ -328,8 +429,9 @@ function validateConfig(data) {
|
|
|
328
429
|
|
|
329
430
|
export {
|
|
330
431
|
SPEC_TYPES,
|
|
432
|
+
DEPENDENCY_RELATIONSHIPS,
|
|
331
433
|
REQUIRED_SECTIONS,
|
|
332
434
|
validateSpec,
|
|
333
435
|
validateConfig
|
|
334
436
|
};
|
|
335
|
-
//# sourceMappingURL=chunk-
|
|
437
|
+
//# sourceMappingURL=chunk-SJCIM4TC.js.map
|