specdx 0.4.0-alpha.5 → 0.4.0-alpha.7
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/dist/{changelog-HL6HA7HG.js → changelog-IP7PNCWG.js} +3 -3
- package/dist/{check-XTL2VATS.js → check-UFMPBHJ4.js} +25 -6
- package/dist/check-UFMPBHJ4.js.map +1 -0
- package/dist/{chunk-HSUMIDA6.js → chunk-EMMWQV52.js} +95 -10
- package/dist/chunk-EMMWQV52.js.map +1 -0
- package/dist/{chunk-W3BBJIRQ.js → chunk-LDV7UXZ7.js} +51 -1
- package/dist/chunk-LDV7UXZ7.js.map +1 -0
- package/dist/{chunk-QEUZJWBY.js → chunk-UKSPVBYC.js} +34 -21
- package/dist/{chunk-QEUZJWBY.js.map → chunk-UKSPVBYC.js.map} +1 -1
- package/dist/{chunk-OK5MT4Q6.js → chunk-YYMQPWSZ.js} +2 -2
- package/dist/{diff-GJYKGIG6.js → diff-EJJSEI5Z.js} +3 -3
- package/dist/{dist-WIK7F2PJ.js → dist-U7CZLXM5.js} +2 -2
- package/dist/{dist-7GA3NJ3Y.js → dist-UAS5655D.js} +31 -6
- package/dist/dist-UAS5655D.js.map +1 -0
- package/dist/{explain-2I3M7ICY.js → explain-NLWMVXFQ.js} +2 -2
- package/dist/{generate-O6FWRGND.js → generate-ORC5WQ4Z.js} +3 -3
- package/dist/{generate-story-YRMLUF2A.js → generate-story-RQ6L5C3O.js} +2 -2
- package/dist/{generate-test-plan-Q5C52KPL.js → generate-test-plan-7MDFBSQN.js} +2 -2
- package/dist/graph-CXFIP6ZA.js +102 -0
- package/dist/graph-CXFIP6ZA.js.map +1 -0
- package/dist/index.js +96 -10
- package/dist/index.js.map +1 -1
- package/dist/{lint-ZXZQTEU6.js → lint-UW7DVZAS.js} +2 -2
- package/dist/main.js +99 -15
- package/dist/main.js.map +1 -1
- package/dist/{mcp-DKM3YAHJ.js → mcp-56I3BENN.js} +2 -2
- package/dist/{migrate-677E4C5U.js → migrate-S7PFFBYI.js} +2 -2
- package/dist/{pack-I53KTKHL.js → pack-2N5KF75X.js} +6 -5
- package/dist/{pack-I53KTKHL.js.map → pack-2N5KF75X.js.map} +1 -1
- package/dist/{ready-CYFUHCV3.js → ready-BHLNDART.js} +53 -19
- package/dist/ready-BHLNDART.js.map +1 -0
- package/dist/{status-ZWDR2EZN.js → status-R6MALIAF.js} +3 -3
- package/dist/{update-P52U4ROV.js → update-S54E2Y4J.js} +3 -3
- package/dist/validate-3ZDFA3MM.js +49 -0
- package/dist/validate-3ZDFA3MM.js.map +1 -0
- package/package.json +3 -3
- package/dist/check-XTL2VATS.js.map +0 -1
- package/dist/chunk-HSUMIDA6.js.map +0 -1
- package/dist/chunk-W3BBJIRQ.js.map +0 -1
- package/dist/dist-7GA3NJ3Y.js.map +0 -1
- package/dist/graph-TYAPGOZJ.js +0 -54
- package/dist/graph-TYAPGOZJ.js.map +0 -1
- package/dist/ready-CYFUHCV3.js.map +0 -1
- package/dist/validate-4JSBHBW5.js +0 -34
- package/dist/validate-4JSBHBW5.js.map +0 -1
- /package/dist/{changelog-HL6HA7HG.js.map → changelog-IP7PNCWG.js.map} +0 -0
- /package/dist/{chunk-OK5MT4Q6.js.map → chunk-YYMQPWSZ.js.map} +0 -0
- /package/dist/{diff-GJYKGIG6.js.map → diff-EJJSEI5Z.js.map} +0 -0
- /package/dist/{dist-WIK7F2PJ.js.map → dist-U7CZLXM5.js.map} +0 -0
- /package/dist/{explain-2I3M7ICY.js.map → explain-NLWMVXFQ.js.map} +0 -0
- /package/dist/{generate-O6FWRGND.js.map → generate-ORC5WQ4Z.js.map} +0 -0
- /package/dist/{generate-story-YRMLUF2A.js.map → generate-story-RQ6L5C3O.js.map} +0 -0
- /package/dist/{generate-test-plan-Q5C52KPL.js.map → generate-test-plan-7MDFBSQN.js.map} +0 -0
- /package/dist/{lint-ZXZQTEU6.js.map → lint-UW7DVZAS.js.map} +0 -0
- /package/dist/{mcp-DKM3YAHJ.js.map → mcp-56I3BENN.js.map} +0 -0
- /package/dist/{migrate-677E4C5U.js.map → migrate-S7PFFBYI.js.map} +0 -0
- /package/dist/{status-ZWDR2EZN.js.map → status-R6MALIAF.js.map} +0 -0
- /package/dist/{update-P52U4ROV.js.map → update-S54E2Y4J.js.map} +0 -0
|
@@ -3,11 +3,11 @@ import { defineCommand } from "citty";
|
|
|
3
3
|
var generate_default = defineCommand({
|
|
4
4
|
meta: { name: "generate", description: "Generate spec stubs from existing specs" },
|
|
5
5
|
subCommands: {
|
|
6
|
-
story: () => import("./generate-story-
|
|
7
|
-
"test-plan": () => import("./generate-test-plan-
|
|
6
|
+
story: () => import("./generate-story-RQ6L5C3O.js").then((m) => m.default),
|
|
7
|
+
"test-plan": () => import("./generate-test-plan-7MDFBSQN.js").then((m) => m.default)
|
|
8
8
|
}
|
|
9
9
|
});
|
|
10
10
|
export {
|
|
11
11
|
generate_default as default
|
|
12
12
|
};
|
|
13
|
-
//# sourceMappingURL=generate-
|
|
13
|
+
//# sourceMappingURL=generate-ORC5WQ4Z.js.map
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
loadConfig,
|
|
4
4
|
parseSpec,
|
|
5
5
|
resolveGlob
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-LDV7UXZ7.js";
|
|
7
7
|
import {
|
|
8
8
|
REQUIRED_SECTIONS
|
|
9
9
|
} from "./chunk-RVVQKLNL.js";
|
|
@@ -193,4 +193,4 @@ export {
|
|
|
193
193
|
defineCommandExport,
|
|
194
194
|
generateStories
|
|
195
195
|
};
|
|
196
|
-
//# sourceMappingURL=generate-story-
|
|
196
|
+
//# sourceMappingURL=generate-story-RQ6L5C3O.js.map
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
loadConfig,
|
|
4
4
|
parseSpec,
|
|
5
5
|
resolveGlob
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-LDV7UXZ7.js";
|
|
7
7
|
import "./chunk-RVVQKLNL.js";
|
|
8
8
|
|
|
9
9
|
// src/commands/generate-test-plan.ts
|
|
@@ -156,4 +156,4 @@ export {
|
|
|
156
156
|
generate_test_plan_default as default,
|
|
157
157
|
generateTestPlan
|
|
158
158
|
};
|
|
159
|
-
//# sourceMappingURL=generate-test-plan-
|
|
159
|
+
//# sourceMappingURL=generate-test-plan-7MDFBSQN.js.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sharedArgs
|
|
3
|
+
} from "./chunk-GAM4MXPC.js";
|
|
4
|
+
import {
|
|
5
|
+
GraphError,
|
|
6
|
+
buildGraph,
|
|
7
|
+
collectReferenceEdges,
|
|
8
|
+
findUnreflectedReferences,
|
|
9
|
+
loadConfig,
|
|
10
|
+
parseSpec,
|
|
11
|
+
resolveGlob
|
|
12
|
+
} from "./chunk-LDV7UXZ7.js";
|
|
13
|
+
import "./chunk-RVVQKLNL.js";
|
|
14
|
+
|
|
15
|
+
// src/commands/graph.ts
|
|
16
|
+
import { defineCommand } from "citty";
|
|
17
|
+
var graph_default = defineCommand({
|
|
18
|
+
meta: { name: "graph", description: "Print the spec dependency graph" },
|
|
19
|
+
args: { ...sharedArgs },
|
|
20
|
+
async run({ args }) {
|
|
21
|
+
let config;
|
|
22
|
+
const configDir = process.cwd();
|
|
23
|
+
try {
|
|
24
|
+
config = await loadConfig(void 0, configDir);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.error(`
|
|
27
|
+
\u2717 ${err.message}
|
|
28
|
+
`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const graph = buildGraph(config);
|
|
33
|
+
const sorted = graph.topologicalSort();
|
|
34
|
+
const idToEntry = /* @__PURE__ */ new Map();
|
|
35
|
+
const specs = [];
|
|
36
|
+
for (const [key, entry] of Object.entries(config.specs)) {
|
|
37
|
+
const paths = await resolveGlob(entry.path, configDir);
|
|
38
|
+
for (const p of paths) {
|
|
39
|
+
const spec = await parseSpec(p);
|
|
40
|
+
specs.push(spec);
|
|
41
|
+
if (typeof spec.frontmatter.id === "string") {
|
|
42
|
+
idToEntry.set(spec.frontmatter.id, key);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const referenceEdges = collectReferenceEdges(specs);
|
|
47
|
+
const unreflected = findUnreflectedReferences(referenceEdges, idToEntry, graph);
|
|
48
|
+
if (args.format === "dot") {
|
|
49
|
+
console.log("digraph specs {");
|
|
50
|
+
for (const edge of graph.edges) console.log(` "${edge.from}" -> "${edge.to}";`);
|
|
51
|
+
for (const ref of referenceEdges) {
|
|
52
|
+
console.log(
|
|
53
|
+
` "${ref.fromId}" -> "${ref.toId}" [style=dashed, label="${ref.relationship}"];`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
console.log("}");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
console.log("\n Spec Dependency Graph:\n");
|
|
60
|
+
for (const node of sorted) {
|
|
61
|
+
const downstream = graph.getDownstream(node);
|
|
62
|
+
const arrow = downstream.length > 0 ? ` \u2192 ${downstream.join(", ")}` : "";
|
|
63
|
+
console.log(` ${node}${arrow}`);
|
|
64
|
+
}
|
|
65
|
+
if (referenceEdges.length > 0) {
|
|
66
|
+
console.log("\n Reference edges (frontmatter):\n");
|
|
67
|
+
for (const ref of referenceEdges) {
|
|
68
|
+
console.log(` ${ref.fromId} \u2014${ref.relationship}\u2192 ${ref.toId}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const suggestions = unreflected.filter((u) => !u.createsCycle);
|
|
72
|
+
const conflicts = unreflected.filter((u) => u.createsCycle);
|
|
73
|
+
if (suggestions.length > 0) {
|
|
74
|
+
console.log("\n \u26A0 References not reflected in config requires:\n");
|
|
75
|
+
for (const { edge, requiringEntry, requiredEntry } of suggestions) {
|
|
76
|
+
console.log(
|
|
77
|
+
` ${edge.fromId} ${edge.relationship} ${edge.toId} \u2014 add "requires: [${requiredEntry}]" to the "${requiringEntry}" entry in spec.config.yaml`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
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
|
+
}
|
|
89
|
+
console.log("");
|
|
90
|
+
} catch (err) {
|
|
91
|
+
if (err instanceof GraphError) {
|
|
92
|
+
console.error(` \u2717 ${err.message}`);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
export {
|
|
100
|
+
graph_default as default
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=graph-CXFIP6ZA.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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SAAS,KAAK;AACZ,UAAI,eAAe,YAAY;AAC7B,gBAAQ,MAAM,YAAO,IAAI,OAAO,EAAE;AAClC,gBAAQ,KAAK,CAAC;AAAA,MAChB;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACF,CAAC;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -1412,6 +1412,7 @@ var WEIGHT_TAGS = 3;
|
|
|
1412
1412
|
var WEIGHT_TITLE = 3;
|
|
1413
1413
|
var WEIGHT_SECTIONS = 2;
|
|
1414
1414
|
var WEIGHT_BODY = 1;
|
|
1415
|
+
var ID_MATCH_MIN_LENGTH = 3;
|
|
1415
1416
|
var GRAPH_BOOST_FACTOR = 0.5;
|
|
1416
1417
|
var SCORE_THRESHOLD = 0.1;
|
|
1417
1418
|
function scoreSpecs(specs, task, graph) {
|
|
@@ -1431,9 +1432,15 @@ function scoreSpecs(specs, task, graph) {
|
|
|
1431
1432
|
}
|
|
1432
1433
|
const rawScores = /* @__PURE__ */ new Map();
|
|
1433
1434
|
const matchedMap = /* @__PURE__ */ new Map();
|
|
1435
|
+
const idMatchedSet = /* @__PURE__ */ new Set();
|
|
1436
|
+
const taskLower = (task ?? "").toLowerCase();
|
|
1434
1437
|
for (const [specId, spec] of specs) {
|
|
1435
1438
|
let weightedHits = 0;
|
|
1436
1439
|
const matched = /* @__PURE__ */ new Set();
|
|
1440
|
+
const idLower = specId.toLowerCase();
|
|
1441
|
+
if (idLower.length >= ID_MATCH_MIN_LENGTH && taskLower.includes(idLower)) {
|
|
1442
|
+
idMatchedSet.add(specId);
|
|
1443
|
+
}
|
|
1437
1444
|
for (const keyword of keywords) {
|
|
1438
1445
|
let hit = false;
|
|
1439
1446
|
const tags = spec.frontmatter.tags ?? [];
|
|
@@ -1505,7 +1512,8 @@ function scoreSpecs(specs, task, graph) {
|
|
|
1505
1512
|
const results = [];
|
|
1506
1513
|
for (const [specId] of specs) {
|
|
1507
1514
|
const combined = finalRawScores.get(specId) ?? 0;
|
|
1508
|
-
const
|
|
1515
|
+
const idMatched = idMatchedSet.has(specId);
|
|
1516
|
+
const normalized = idMatched ? 1 : maxScore > 0 ? combined / maxScore : 0;
|
|
1509
1517
|
if (normalized < SCORE_THRESHOLD)
|
|
1510
1518
|
continue;
|
|
1511
1519
|
results.push({
|
|
@@ -1513,10 +1521,11 @@ function scoreSpecs(specs, task, graph) {
|
|
|
1513
1521
|
score: normalized,
|
|
1514
1522
|
rawScore: rawScores.get(specId) ?? 0,
|
|
1515
1523
|
matchedKeywords: [...matchedMap.get(specId) ?? []],
|
|
1516
|
-
graphBoosted: boostedSet.has(specId)
|
|
1524
|
+
graphBoosted: boostedSet.has(specId),
|
|
1525
|
+
idMatched
|
|
1517
1526
|
});
|
|
1518
1527
|
}
|
|
1519
|
-
results.sort((a, b) => b.score - a.score);
|
|
1528
|
+
results.sort((a, b) => b.score - a.score || Number(b.idMatched ?? false) - Number(a.idMatched ?? false));
|
|
1520
1529
|
return results;
|
|
1521
1530
|
}
|
|
1522
1531
|
function scoreSpecsByIds(specs, specIds, graph) {
|
|
@@ -1609,6 +1618,69 @@ function compressSpec(specId, type, title, status, updatedDate, parsedSections,
|
|
|
1609
1618
|
}
|
|
1610
1619
|
|
|
1611
1620
|
// ../pack/dist/allocator.js
|
|
1621
|
+
var HIGH_RELEVANCE = 0.75;
|
|
1622
|
+
var MIN_TRIM_BUDGET = 150;
|
|
1623
|
+
function omissionMarker(sections) {
|
|
1624
|
+
const names = sections.map((s) => s.heading || "(untitled)");
|
|
1625
|
+
const noun = names.length === 1 ? "section" : "sections";
|
|
1626
|
+
return `[${names.length} ${noun} omitted to fit token budget: ${names.join(", ")}]`;
|
|
1627
|
+
}
|
|
1628
|
+
function trimToBudget(compressed, budget) {
|
|
1629
|
+
const sections = compressed.sections;
|
|
1630
|
+
let reserve = 0;
|
|
1631
|
+
for (; ; ) {
|
|
1632
|
+
const effective = budget - reserve;
|
|
1633
|
+
const keep = new Array(sections.length).fill(false);
|
|
1634
|
+
let used = 0;
|
|
1635
|
+
let keptReal = false;
|
|
1636
|
+
for (let i = 0; i < sections.length; i++) {
|
|
1637
|
+
if (used + sections[i].tokens <= effective) {
|
|
1638
|
+
keep[i] = true;
|
|
1639
|
+
used += sections[i].tokens;
|
|
1640
|
+
keptReal = true;
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
if (!keptReal)
|
|
1644
|
+
return null;
|
|
1645
|
+
const runs = [];
|
|
1646
|
+
for (let i = 0; i < sections.length; i++) {
|
|
1647
|
+
if (keep[i])
|
|
1648
|
+
continue;
|
|
1649
|
+
const start = i;
|
|
1650
|
+
const run = [];
|
|
1651
|
+
while (i < sections.length && !keep[i]) {
|
|
1652
|
+
run.push(sections[i]);
|
|
1653
|
+
i++;
|
|
1654
|
+
}
|
|
1655
|
+
i--;
|
|
1656
|
+
const marker = omissionMarker(run);
|
|
1657
|
+
runs.push({ start, sections: run, marker, markerTokens: countTokens(marker) });
|
|
1658
|
+
}
|
|
1659
|
+
const markerTokens = runs.reduce((sum, r) => sum + r.markerTokens, 0);
|
|
1660
|
+
if (markerTokens > reserve) {
|
|
1661
|
+
reserve = markerTokens;
|
|
1662
|
+
continue;
|
|
1663
|
+
}
|
|
1664
|
+
const out = [];
|
|
1665
|
+
for (let i = 0; i < sections.length; i++) {
|
|
1666
|
+
const run = runs.find((r) => r.start === i);
|
|
1667
|
+
if (run) {
|
|
1668
|
+
out.push({
|
|
1669
|
+
heading: "",
|
|
1670
|
+
content: run.marker,
|
|
1671
|
+
tokens: run.markerTokens,
|
|
1672
|
+
compressed: true,
|
|
1673
|
+
originalTokens: run.sections.reduce((sum, s) => sum + s.tokens, 0),
|
|
1674
|
+
omittedSections: run.sections.length
|
|
1675
|
+
});
|
|
1676
|
+
i += run.sections.length - 1;
|
|
1677
|
+
continue;
|
|
1678
|
+
}
|
|
1679
|
+
out.push(sections[i]);
|
|
1680
|
+
}
|
|
1681
|
+
return { spec: { ...compressed, sections: out }, tokens: used + markerTokens };
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1612
1684
|
function allocate(specs, scores, options) {
|
|
1613
1685
|
const specMap = /* @__PURE__ */ new Map();
|
|
1614
1686
|
for (const spec of specs) {
|
|
@@ -1646,9 +1718,9 @@ function allocate(specs, scores, options) {
|
|
|
1646
1718
|
tokens += section.tokens;
|
|
1647
1719
|
}
|
|
1648
1720
|
}
|
|
1649
|
-
items.push({ compressed, relevance: score.score, tokens });
|
|
1721
|
+
items.push({ compressed, relevance: score.score, tokens, idMatched: score.idMatched ?? false });
|
|
1650
1722
|
}
|
|
1651
|
-
items.sort((a, b) => b.relevance - a.relevance);
|
|
1723
|
+
items.sort((a, b) => b.relevance - a.relevance || Number(b.idMatched) - Number(a.idMatched));
|
|
1652
1724
|
const totalTokens = items.reduce((sum, item) => sum + item.tokens, 0);
|
|
1653
1725
|
const withinBudget = totalTokens <= options.budget;
|
|
1654
1726
|
const included = [];
|
|
@@ -1664,17 +1736,28 @@ function allocate(specs, scores, options) {
|
|
|
1664
1736
|
if (usedTokens + item.tokens <= options.budget) {
|
|
1665
1737
|
included.push(item);
|
|
1666
1738
|
usedTokens += item.tokens;
|
|
1667
|
-
|
|
1668
|
-
|
|
1739
|
+
continue;
|
|
1740
|
+
}
|
|
1741
|
+
const remaining = options.budget - usedTokens;
|
|
1742
|
+
if ((item.idMatched || item.relevance >= HIGH_RELEVANCE) && remaining >= MIN_TRIM_BUDGET && !item.compressed.collapsed) {
|
|
1743
|
+
const trimmed = trimToBudget(item.compressed, remaining);
|
|
1744
|
+
if (trimmed) {
|
|
1745
|
+
included.push({ ...item, compressed: trimmed.spec, tokens: trimmed.tokens });
|
|
1746
|
+
usedTokens += trimmed.tokens;
|
|
1747
|
+
continue;
|
|
1748
|
+
}
|
|
1669
1749
|
}
|
|
1750
|
+
excluded.push(item);
|
|
1670
1751
|
}
|
|
1671
1752
|
}
|
|
1672
1753
|
let sectionsCompressed = 0;
|
|
1754
|
+
let sectionsOmitted = 0;
|
|
1673
1755
|
for (const item of included) {
|
|
1674
1756
|
for (const section of item.compressed.sections) {
|
|
1675
1757
|
if (section.compressed) {
|
|
1676
1758
|
sectionsCompressed++;
|
|
1677
1759
|
}
|
|
1760
|
+
sectionsOmitted += section.omittedSections ?? 0;
|
|
1678
1761
|
}
|
|
1679
1762
|
}
|
|
1680
1763
|
const allocations = [];
|
|
@@ -1704,6 +1787,7 @@ function allocate(specs, scores, options) {
|
|
|
1704
1787
|
specsIncluded: included.length,
|
|
1705
1788
|
specsExcluded: excluded.length,
|
|
1706
1789
|
sectionsCompressed,
|
|
1790
|
+
sectionsOmitted,
|
|
1707
1791
|
allocations
|
|
1708
1792
|
};
|
|
1709
1793
|
return {
|
|
@@ -1718,7 +1802,7 @@ function escapeXml(text) {
|
|
|
1718
1802
|
}
|
|
1719
1803
|
function formatXml(specs, stats) {
|
|
1720
1804
|
const lines = [];
|
|
1721
|
-
lines.push(`<context budget="${stats.budget}" used="${stats.used}" specs="${stats.specsIncluded}" compressed="${stats.sectionsCompressed}">`);
|
|
1805
|
+
lines.push(`<context budget="${stats.budget}" used="${stats.used}" specs="${stats.specsIncluded}" compressed="${stats.sectionsCompressed}" omitted="${stats.sectionsOmitted}">`);
|
|
1722
1806
|
for (const spec of specs) {
|
|
1723
1807
|
const alloc = stats.allocations.find((a) => a.specId === spec.specId);
|
|
1724
1808
|
const relevance = alloc?.relevance ?? 0;
|
|
@@ -1777,6 +1861,7 @@ function formatJson2(specs, stats) {
|
|
|
1777
1861
|
const output = {
|
|
1778
1862
|
budget: stats.budget,
|
|
1779
1863
|
used: stats.used,
|
|
1864
|
+
sectionsOmitted: stats.sectionsOmitted,
|
|
1780
1865
|
specs: specs.map((spec) => {
|
|
1781
1866
|
const alloc = stats.allocations.find((a) => a.specId === spec.specId);
|
|
1782
1867
|
const relevance = alloc?.relevance ?? 0;
|
|
@@ -2020,7 +2105,8 @@ var pack_default = defineCommand3({
|
|
|
2020
2105
|
console.log(
|
|
2021
2106
|
` Included: ${stats.specsIncluded} / ${stats.specsIncluded + stats.specsExcluded} specs`
|
|
2022
2107
|
);
|
|
2023
|
-
console.log(` Sections compressed: ${stats.sectionsCompressed}
|
|
2108
|
+
console.log(` Sections compressed: ${stats.sectionsCompressed}`);
|
|
2109
|
+
console.log(` Sections omitted: ${stats.sectionsOmitted}
|
|
2024
2110
|
`);
|
|
2025
2111
|
return;
|
|
2026
2112
|
}
|
|
@@ -2037,7 +2123,7 @@ var pack_default = defineCommand3({
|
|
|
2037
2123
|
}
|
|
2038
2124
|
const total = stats.specsIncluded + stats.specsExcluded;
|
|
2039
2125
|
process.stderr.write(
|
|
2040
|
-
`Packed ${stats.specsIncluded}/${total} specs \u2022 ${stats.used} / ${stats.budget} tokens \u2022 ${stats.sectionsCompressed} sections compressed
|
|
2126
|
+
`Packed ${stats.specsIncluded}/${total} specs \u2022 ${stats.used} / ${stats.budget} tokens \u2022 ${stats.sectionsCompressed} sections compressed \u2022 ${stats.sectionsOmitted} sections omitted
|
|
2041
2127
|
`
|
|
2042
2128
|
);
|
|
2043
2129
|
} catch (err) {
|