dino-spec 9.10.0 → 9.14.0

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 (66) hide show
  1. package/README.md +8 -1
  2. package/dist/core/budget/cross-section-dedup.d.ts +146 -0
  3. package/dist/core/budget/cross-section-dedup.d.ts.map +1 -0
  4. package/dist/core/budget/cross-section-dedup.js +396 -0
  5. package/dist/core/budget/cross-section-dedup.js.map +1 -0
  6. package/dist/core/budget/index.d.ts +10 -0
  7. package/dist/core/budget/index.d.ts.map +1 -1
  8. package/dist/core/budget/index.js +12 -0
  9. package/dist/core/budget/index.js.map +1 -1
  10. package/dist/core/budget/language-entropy-profiles.d.ts +144 -0
  11. package/dist/core/budget/language-entropy-profiles.d.ts.map +1 -0
  12. package/dist/core/budget/language-entropy-profiles.js +438 -0
  13. package/dist/core/budget/language-entropy-profiles.js.map +1 -0
  14. package/dist/core/embeddings/adapters/index.d.ts +61 -0
  15. package/dist/core/embeddings/adapters/index.d.ts.map +1 -0
  16. package/dist/core/embeddings/adapters/index.js +130 -0
  17. package/dist/core/embeddings/adapters/index.js.map +1 -0
  18. package/dist/core/embeddings/adapters/local.d.ts +55 -0
  19. package/dist/core/embeddings/adapters/local.d.ts.map +1 -0
  20. package/dist/core/embeddings/adapters/local.js +317 -0
  21. package/dist/core/embeddings/adapters/local.js.map +1 -0
  22. package/dist/core/embeddings/adapters/qdrant.d.ts +53 -0
  23. package/dist/core/embeddings/adapters/qdrant.d.ts.map +1 -0
  24. package/dist/core/embeddings/adapters/qdrant.js +410 -0
  25. package/dist/core/embeddings/adapters/qdrant.js.map +1 -0
  26. package/dist/core/embeddings/adapters/types.d.ts +245 -0
  27. package/dist/core/embeddings/adapters/types.d.ts.map +1 -0
  28. package/dist/core/embeddings/adapters/types.js +104 -0
  29. package/dist/core/embeddings/adapters/types.js.map +1 -0
  30. package/dist/core/embeddings/index.d.ts +5 -2
  31. package/dist/core/embeddings/index.d.ts.map +1 -1
  32. package/dist/core/embeddings/index.js +4 -2
  33. package/dist/core/embeddings/index.js.map +1 -1
  34. package/dist/core/memory/index.d.ts +4 -1
  35. package/dist/core/memory/index.d.ts.map +1 -1
  36. package/dist/core/memory/index.js +22 -1
  37. package/dist/core/memory/index.js.map +1 -1
  38. package/dist/core/memory/memory-rehearsal-agent.d.ts +148 -0
  39. package/dist/core/memory/memory-rehearsal-agent.d.ts.map +1 -0
  40. package/dist/core/memory/memory-rehearsal-agent.js +354 -0
  41. package/dist/core/memory/memory-rehearsal-agent.js.map +1 -0
  42. package/dist/core/memory/spaced-repetition.d.ts +173 -0
  43. package/dist/core/memory/spaced-repetition.d.ts.map +1 -0
  44. package/dist/core/memory/spaced-repetition.js +400 -0
  45. package/dist/core/memory/spaced-repetition.js.map +1 -0
  46. package/dist/core/memory/types.d.ts +8 -1
  47. package/dist/core/memory/types.d.ts.map +1 -1
  48. package/dist/core/memory/types.js +2 -1
  49. package/dist/core/memory/types.js.map +1 -1
  50. package/dist/mcp/index.d.ts +6 -2
  51. package/dist/mcp/index.d.ts.map +1 -1
  52. package/dist/mcp/index.js +7 -2
  53. package/dist/mcp/index.js.map +1 -1
  54. package/dist/mcp/registry.d.ts +28 -1
  55. package/dist/mcp/registry.d.ts.map +1 -1
  56. package/dist/mcp/registry.js +70 -1
  57. package/dist/mcp/registry.js.map +1 -1
  58. package/dist/mcp/tool-loader.d.ts +191 -0
  59. package/dist/mcp/tool-loader.d.ts.map +1 -0
  60. package/dist/mcp/tool-loader.js +381 -0
  61. package/dist/mcp/tool-loader.js.map +1 -0
  62. package/dist/mcp/tool-tiers.d.ts +133 -0
  63. package/dist/mcp/tool-tiers.d.ts.map +1 -0
  64. package/dist/mcp/tool-tiers.js +297 -0
  65. package/dist/mcp/tool-tiers.js.map +1 -0
  66. package/package.json +1 -1
package/README.md CHANGED
@@ -15,6 +15,11 @@
15
15
  ## Features
16
16
 
17
17
  - **MCP Integration** - 47 tools + 29 resources auto-configured during init
18
+ - **Phase 4 Advanced Optimizations** (v9.14.0)
19
+ - **MCP Tool Filtering** - Phase-based tool tiering for 60-70% context overhead reduction
20
+ - **Memory Recitation** - SM-2 spaced repetition for long-term memory retention
21
+ - **Entropy Enhancement** - Language-specific profiles and cross-section deduplication
22
+ - **External Vector DB** - Qdrant/Pinecone adapter support for scalable embeddings
18
23
  - **Enhanced Observability** - Execution tree, memory access log, context transitions with HTML/JSON export (v9.10.0)
19
24
  - **Session State** - Automatic tracking of focus, test/build/lint status, blockers
20
25
  - **Persistent Memory** - Decisions, patterns, learnings survive across sessions
@@ -27,7 +32,7 @@
27
32
  - **Recursive Retrieval** - RLM-style query decomposition with quality feedback
28
33
  - **Dynamic Partitioning** - Intelligent codebase segmentation (directory, feature, dependency, time)
29
34
  - **Context REPL** - Declarative DSL for model-driven exploration
30
- - **Context Engineering** - Research-backed token optimization (v9.6.0, v9.7.0)
35
+ - **Context Engineering** - Research-backed token optimization (v9.6.0, v9.7.0, v9.14.0)
31
36
  - Tool result summarization (~50-70% better retention)
32
37
  - Positional context optimization (~15-25% recall improvement)
33
38
  - Just-in-time context loading (~60-80% initial context reduction)
@@ -35,6 +40,8 @@
35
40
  - Virtual memory management (~40-50% memory overhead reduction)
36
41
  - Multi-agent context isolation (~70-80% token reduction for parallel agents)
37
42
  - Semantic memory validation (~20-30% better relevance)
43
+ - Language-specific entropy profiles (v9.14.0)
44
+ - Cross-section deduplication (v9.14.0)
38
45
  - Reference docs and skills (`/research`, `/context-optimize`)
39
46
 
40
47
  ## Installation
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Cross-Section Deduplication - v9.13.0
3
+ *
4
+ * Detects and removes redundant content across context sections.
5
+ * Uses normalized code hashing and similarity clustering to identify
6
+ * duplicated patterns, reducing token waste.
7
+ *
8
+ * Key techniques:
9
+ * 1. Code normalization (remove whitespace, comments)
10
+ * 2. Fragment hashing for exact match detection
11
+ * 3. Similarity clustering for near-duplicates (>90% similar)
12
+ * 4. Canonical selection and reference replacement
13
+ *
14
+ * Usage:
15
+ * ```typescript
16
+ * const result = deduplicateSections(sections);
17
+ * // result.canonicals: unique sections to include
18
+ * // result.references: sections replaced with references
19
+ * // result.savings: tokens saved
20
+ * ```
21
+ */
22
+ import type { ContentSection } from './entropy-budget.js';
23
+ /**
24
+ * Normalized content for comparison
25
+ */
26
+ export interface NormalizedContent {
27
+ original: string;
28
+ normalized: string;
29
+ hash: string;
30
+ tokens: string[];
31
+ }
32
+ /**
33
+ * Similarity match between two sections
34
+ */
35
+ export interface SimilarityMatch {
36
+ section1Id: string;
37
+ section2Id: string;
38
+ similarity: number;
39
+ matchType: 'exact' | 'near-duplicate' | 'partial';
40
+ }
41
+ /**
42
+ * Section cluster (group of similar sections)
43
+ */
44
+ export interface SectionCluster {
45
+ /** Canonical section (to keep) */
46
+ canonicalId: string;
47
+ /** IDs of sections that are duplicates */
48
+ duplicateIds: string[];
49
+ /** Average similarity within cluster */
50
+ avgSimilarity: number;
51
+ /** Total tokens saved by deduplication */
52
+ tokensSaved: number;
53
+ }
54
+ /**
55
+ * Deduplication result
56
+ */
57
+ export interface DeduplicationResult {
58
+ /** Original section count */
59
+ originalCount: number;
60
+ /** Sections after deduplication */
61
+ uniqueCount: number;
62
+ /** Canonical sections to keep */
63
+ canonicals: ContentSection[];
64
+ /** Sections replaced with references */
65
+ references: Array<{
66
+ sectionId: string;
67
+ canonicalId: string;
68
+ similarity: number;
69
+ }>;
70
+ /** Similarity clusters found */
71
+ clusters: SectionCluster[];
72
+ /** Total tokens saved */
73
+ tokensSaved: number;
74
+ /** Deduplication percentage */
75
+ dedupPercent: number;
76
+ /** Processing time in ms */
77
+ processingTimeMs: number;
78
+ }
79
+ /**
80
+ * Deduplication options
81
+ */
82
+ export interface DeduplicationOptions {
83
+ /** Minimum similarity to consider duplicate (default: 0.9) */
84
+ similarityThreshold: number;
85
+ /** Remove comments before comparison (default: true) */
86
+ removeComments: boolean;
87
+ /** Normalize whitespace (default: true) */
88
+ normalizeWhitespace: boolean;
89
+ /** Minimum section size to consider (default: 50 chars) */
90
+ minSectionSize: number;
91
+ /** Maximum sections to compare (default: 100) */
92
+ maxSections: number;
93
+ }
94
+ /**
95
+ * Default deduplication options
96
+ */
97
+ export declare const DEFAULT_DEDUP_OPTIONS: DeduplicationOptions;
98
+ /**
99
+ * Remove comments from code
100
+ */
101
+ export declare function removeComments(content: string): string;
102
+ /**
103
+ * Normalize whitespace
104
+ */
105
+ export declare function normalizeWhitespace(content: string): string;
106
+ /**
107
+ * Normalize content for comparison
108
+ */
109
+ export declare function normalizeContent(content: string, options?: Partial<DeduplicationOptions>): NormalizedContent;
110
+ /**
111
+ * Simple tokenizer for similarity comparison
112
+ */
113
+ export declare function tokenize(content: string): string[];
114
+ /**
115
+ * Calculate Jaccard similarity between two token sets
116
+ */
117
+ export declare function jaccardSimilarity(tokens1: string[], tokens2: string[]): number;
118
+ /**
119
+ * Calculate similarity using longest common subsequence
120
+ */
121
+ export declare function lcsSimilarity(str1: string, str2: string): number;
122
+ /**
123
+ * Calculate combined similarity score
124
+ */
125
+ export declare function calculateSimilarity(content1: NormalizedContent, content2: NormalizedContent): number;
126
+ /**
127
+ * Find all similarity matches between sections
128
+ */
129
+ export declare function findSimilarityMatches(sections: ContentSection[], options?: Partial<DeduplicationOptions>): SimilarityMatch[];
130
+ /**
131
+ * Build clusters from similarity matches using union-find
132
+ */
133
+ export declare function buildClusters(sections: ContentSection[], matches: SimilarityMatch[], options?: Partial<DeduplicationOptions>): SectionCluster[];
134
+ /**
135
+ * Deduplicate content sections
136
+ */
137
+ export declare function deduplicateSections(sections: ContentSection[], options?: Partial<DeduplicationOptions>): DeduplicationResult;
138
+ /**
139
+ * Format deduplication result for display
140
+ */
141
+ export declare function formatDeduplicationResult(result: DeduplicationResult): string;
142
+ /**
143
+ * Create reference placeholder for deduplicated section
144
+ */
145
+ export declare function createReferencePlaceholder(canonicalId: string, similarity: number): string;
146
+ //# sourceMappingURL=cross-section-dedup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cross-section-dedup.d.ts","sourceRoot":"","sources":["../../../src/core/budget/cross-section-dedup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAM1D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,OAAO,GAAG,gBAAgB,GAAG,SAAS,CAAC;CACnD;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,wCAAwC;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,6BAA6B;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,iCAAiC;IACjC,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,wCAAwC;IACxC,UAAU,EAAE,KAAK,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;IACH,gCAAgC;IAChC,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,yBAAyB;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,YAAY,EAAE,MA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GAEG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,cAAc,EAAE,EAC1B,OAAO,EAAE,eAAe,EAAE,EAC1B,OAAO,GAAE,OAAO,CAAC,oBAAoB,CAAM,GAC1C,cAAc,EAAE,CAqGlB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,cAAc,EAAE,EAC1B,OAAO,GAAE,OAAO,CAAC,oBAAoB,CAAM,GAC1C,mBAAmB,CA8DrB;AAMD;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CA0B7E;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,MAAM,CAER"}
@@ -0,0 +1,396 @@
1
+ /**
2
+ * Cross-Section Deduplication - v9.13.0
3
+ *
4
+ * Detects and removes redundant content across context sections.
5
+ * Uses normalized code hashing and similarity clustering to identify
6
+ * duplicated patterns, reducing token waste.
7
+ *
8
+ * Key techniques:
9
+ * 1. Code normalization (remove whitespace, comments)
10
+ * 2. Fragment hashing for exact match detection
11
+ * 3. Similarity clustering for near-duplicates (>90% similar)
12
+ * 4. Canonical selection and reference replacement
13
+ *
14
+ * Usage:
15
+ * ```typescript
16
+ * const result = deduplicateSections(sections);
17
+ * // result.canonicals: unique sections to include
18
+ * // result.references: sections replaced with references
19
+ * // result.savings: tokens saved
20
+ * ```
21
+ */
22
+ import { createHash } from 'crypto';
23
+ /**
24
+ * Default deduplication options
25
+ */
26
+ export const DEFAULT_DEDUP_OPTIONS = {
27
+ similarityThreshold: 0.9,
28
+ removeComments: true,
29
+ normalizeWhitespace: true,
30
+ minSectionSize: 50,
31
+ maxSections: 100,
32
+ };
33
+ // =============================================================================
34
+ // Normalization
35
+ // =============================================================================
36
+ /**
37
+ * Remove comments from code
38
+ */
39
+ export function removeComments(content) {
40
+ // Remove single-line comments
41
+ let result = content.replace(/\/\/.*$/gm, '');
42
+ // Remove multi-line comments
43
+ result = result.replace(/\/\*[\s\S]*?\*\//g, '');
44
+ // Remove Python comments
45
+ result = result.replace(/#.*$/gm, '');
46
+ return result;
47
+ }
48
+ /**
49
+ * Normalize whitespace
50
+ */
51
+ export function normalizeWhitespace(content) {
52
+ // Collapse multiple spaces/tabs to single space
53
+ let result = content.replace(/[ \t]+/g, ' ');
54
+ // Normalize newlines
55
+ result = result.replace(/\r\n/g, '\n');
56
+ result = result.replace(/\n+/g, '\n');
57
+ // Trim lines
58
+ result = result.split('\n').map(line => line.trim()).join('\n');
59
+ return result.trim();
60
+ }
61
+ /**
62
+ * Normalize content for comparison
63
+ */
64
+ export function normalizeContent(content, options = {}) {
65
+ const opts = { ...DEFAULT_DEDUP_OPTIONS, ...options };
66
+ let normalized = content;
67
+ if (opts.removeComments) {
68
+ normalized = removeComments(normalized);
69
+ }
70
+ if (opts.normalizeWhitespace) {
71
+ normalized = normalizeWhitespace(normalized);
72
+ }
73
+ // Create hash
74
+ const hash = createHash('sha256').update(normalized).digest('hex').substring(0, 16);
75
+ // Tokenize for similarity comparison
76
+ const tokens = tokenize(normalized);
77
+ return {
78
+ original: content,
79
+ normalized,
80
+ hash,
81
+ tokens,
82
+ };
83
+ }
84
+ /**
85
+ * Simple tokenizer for similarity comparison
86
+ */
87
+ export function tokenize(content) {
88
+ // Split on word boundaries and punctuation
89
+ return content
90
+ .toLowerCase()
91
+ .split(/[\s\W]+/)
92
+ .filter(token => token.length >= 2);
93
+ }
94
+ // =============================================================================
95
+ // Similarity Calculation
96
+ // =============================================================================
97
+ /**
98
+ * Calculate Jaccard similarity between two token sets
99
+ */
100
+ export function jaccardSimilarity(tokens1, tokens2) {
101
+ if (tokens1.length === 0 && tokens2.length === 0)
102
+ return 1;
103
+ if (tokens1.length === 0 || tokens2.length === 0)
104
+ return 0;
105
+ const set1 = new Set(tokens1);
106
+ const set2 = new Set(tokens2);
107
+ let intersection = 0;
108
+ for (const token of set1) {
109
+ if (set2.has(token)) {
110
+ intersection++;
111
+ }
112
+ }
113
+ const union = set1.size + set2.size - intersection;
114
+ return union > 0 ? intersection / union : 0;
115
+ }
116
+ /**
117
+ * Calculate similarity using longest common subsequence
118
+ */
119
+ export function lcsSimilarity(str1, str2) {
120
+ if (str1.length === 0 && str2.length === 0)
121
+ return 1;
122
+ if (str1.length === 0 || str2.length === 0)
123
+ return 0;
124
+ // Use shorter strings for performance
125
+ const shortStr = str1.length < str2.length ? str1 : str2;
126
+ const longStr = str1.length < str2.length ? str2 : str1;
127
+ // Simplified LCS for performance
128
+ const n = shortStr.length;
129
+ const m = longStr.length;
130
+ if (n > 1000 || m > 1000) {
131
+ // Fall back to Jaccard for very long strings
132
+ return jaccardSimilarity(tokenize(str1), tokenize(str2));
133
+ }
134
+ const dp = Array(n + 1).fill(null).map(() => Array(m + 1).fill(0));
135
+ for (let i = 1; i <= n; i++) {
136
+ for (let j = 1; j <= m; j++) {
137
+ if (shortStr[i - 1] === longStr[j - 1]) {
138
+ dp[i][j] = dp[i - 1][j - 1] + 1;
139
+ }
140
+ else {
141
+ dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
142
+ }
143
+ }
144
+ }
145
+ const lcsLength = dp[n][m];
146
+ return (2 * lcsLength) / (n + m);
147
+ }
148
+ /**
149
+ * Calculate combined similarity score
150
+ */
151
+ export function calculateSimilarity(content1, content2) {
152
+ // Exact match via hash
153
+ if (content1.hash === content2.hash) {
154
+ return 1.0;
155
+ }
156
+ // Weighted combination of Jaccard and structural similarity
157
+ const jaccard = jaccardSimilarity(content1.tokens, content2.tokens);
158
+ // Only compute LCS if Jaccard is promising
159
+ if (jaccard < 0.5) {
160
+ return jaccard;
161
+ }
162
+ // Weight: 60% Jaccard, 40% LCS
163
+ const lcs = lcsSimilarity(content1.normalized, content2.normalized);
164
+ return jaccard * 0.6 + lcs * 0.4;
165
+ }
166
+ // =============================================================================
167
+ // Deduplication
168
+ // =============================================================================
169
+ /**
170
+ * Find all similarity matches between sections
171
+ */
172
+ export function findSimilarityMatches(sections, options = {}) {
173
+ const opts = { ...DEFAULT_DEDUP_OPTIONS, ...options };
174
+ const matches = [];
175
+ // Normalize all sections
176
+ const normalized = sections
177
+ .filter(s => s.content.length >= opts.minSectionSize)
178
+ .slice(0, opts.maxSections)
179
+ .map(s => ({
180
+ section: s,
181
+ normalized: normalizeContent(s.content, opts),
182
+ }));
183
+ // Compare all pairs
184
+ for (let i = 0; i < normalized.length; i++) {
185
+ for (let j = i + 1; j < normalized.length; j++) {
186
+ // Quick check via hash
187
+ if (normalized[i].normalized.hash === normalized[j].normalized.hash) {
188
+ matches.push({
189
+ section1Id: normalized[i].section.id,
190
+ section2Id: normalized[j].section.id,
191
+ similarity: 1.0,
192
+ matchType: 'exact',
193
+ });
194
+ continue;
195
+ }
196
+ const similarity = calculateSimilarity(normalized[i].normalized, normalized[j].normalized);
197
+ if (similarity >= opts.similarityThreshold) {
198
+ matches.push({
199
+ section1Id: normalized[i].section.id,
200
+ section2Id: normalized[j].section.id,
201
+ similarity,
202
+ matchType: similarity === 1.0 ? 'exact' : 'near-duplicate',
203
+ });
204
+ }
205
+ else if (similarity >= 0.7) {
206
+ matches.push({
207
+ section1Id: normalized[i].section.id,
208
+ section2Id: normalized[j].section.id,
209
+ similarity,
210
+ matchType: 'partial',
211
+ });
212
+ }
213
+ }
214
+ }
215
+ return matches;
216
+ }
217
+ /**
218
+ * Build clusters from similarity matches using union-find
219
+ */
220
+ export function buildClusters(sections, matches, options = {}) {
221
+ const opts = { ...DEFAULT_DEDUP_OPTIONS, ...options };
222
+ const sectionMap = new Map(sections.map(s => [s.id, s]));
223
+ // Union-find structure
224
+ const parent = new Map();
225
+ const rank = new Map();
226
+ const find = (id) => {
227
+ if (!parent.has(id)) {
228
+ parent.set(id, id);
229
+ rank.set(id, 0);
230
+ }
231
+ if (parent.get(id) !== id) {
232
+ parent.set(id, find(parent.get(id)));
233
+ }
234
+ return parent.get(id);
235
+ };
236
+ const union = (id1, id2) => {
237
+ const root1 = find(id1);
238
+ const root2 = find(id2);
239
+ if (root1 !== root2) {
240
+ const rank1 = rank.get(root1) || 0;
241
+ const rank2 = rank.get(root2) || 0;
242
+ if (rank1 < rank2) {
243
+ parent.set(root1, root2);
244
+ }
245
+ else if (rank1 > rank2) {
246
+ parent.set(root2, root1);
247
+ }
248
+ else {
249
+ parent.set(root2, root1);
250
+ rank.set(root1, rank1 + 1);
251
+ }
252
+ }
253
+ };
254
+ // Build clusters from high-similarity matches
255
+ for (const match of matches) {
256
+ if (match.similarity >= opts.similarityThreshold) {
257
+ union(match.section1Id, match.section2Id);
258
+ }
259
+ }
260
+ // Group by cluster root
261
+ const clusterMembers = new Map();
262
+ for (const section of sections) {
263
+ const root = find(section.id);
264
+ if (!clusterMembers.has(root)) {
265
+ clusterMembers.set(root, []);
266
+ }
267
+ clusterMembers.get(root).push(section.id);
268
+ }
269
+ // Build cluster objects (only for clusters with duplicates)
270
+ const clusters = [];
271
+ for (const [_root, members] of clusterMembers) {
272
+ if (members.length <= 1)
273
+ continue;
274
+ // Select canonical (highest importance, or largest)
275
+ const sorted = members
276
+ .map(id => sectionMap.get(id))
277
+ .filter(Boolean)
278
+ .sort((a, b) => {
279
+ // Prefer higher importance
280
+ if (a.importance !== b.importance) {
281
+ return b.importance - a.importance;
282
+ }
283
+ // Then larger content
284
+ return b.content.length - a.content.length;
285
+ });
286
+ if (sorted.length === 0)
287
+ continue;
288
+ const canonical = sorted[0];
289
+ const duplicates = sorted.slice(1).map(s => s.id);
290
+ // Calculate tokens saved
291
+ const tokensSaved = duplicates.reduce((sum, id) => {
292
+ const section = sectionMap.get(id);
293
+ return sum + (section ? Math.ceil(section.content.length / 4) : 0);
294
+ }, 0);
295
+ // Calculate average similarity
296
+ const clusterMatches = matches.filter(m => members.includes(m.section1Id) && members.includes(m.section2Id));
297
+ const avgSimilarity = clusterMatches.length > 0
298
+ ? clusterMatches.reduce((sum, m) => sum + m.similarity, 0) / clusterMatches.length
299
+ : 1.0;
300
+ clusters.push({
301
+ canonicalId: canonical.id,
302
+ duplicateIds: duplicates,
303
+ avgSimilarity,
304
+ tokensSaved,
305
+ });
306
+ }
307
+ return clusters;
308
+ }
309
+ /**
310
+ * Deduplicate content sections
311
+ */
312
+ export function deduplicateSections(sections, options = {}) {
313
+ const startTime = Date.now();
314
+ const opts = { ...DEFAULT_DEDUP_OPTIONS, ...options };
315
+ if (sections.length === 0) {
316
+ return {
317
+ originalCount: 0,
318
+ uniqueCount: 0,
319
+ canonicals: [],
320
+ references: [],
321
+ clusters: [],
322
+ tokensSaved: 0,
323
+ dedupPercent: 0,
324
+ processingTimeMs: 0,
325
+ };
326
+ }
327
+ // Find similarity matches
328
+ const matches = findSimilarityMatches(sections, opts);
329
+ // Build clusters
330
+ const clusters = buildClusters(sections, matches, opts);
331
+ // Determine canonical and duplicate sections
332
+ const duplicateIds = new Set(clusters.flatMap(c => c.duplicateIds));
333
+ const canonicals = sections.filter(s => !duplicateIds.has(s.id));
334
+ // Build references
335
+ const references = clusters.flatMap(cluster => cluster.duplicateIds.map(dupId => {
336
+ const match = matches.find(m => (m.section1Id === dupId && m.section2Id === cluster.canonicalId) ||
337
+ (m.section2Id === dupId && m.section1Id === cluster.canonicalId));
338
+ return {
339
+ sectionId: dupId,
340
+ canonicalId: cluster.canonicalId,
341
+ similarity: match?.similarity ?? 1.0,
342
+ };
343
+ }));
344
+ // Calculate savings
345
+ const tokensSaved = clusters.reduce((sum, c) => sum + c.tokensSaved, 0);
346
+ const totalOriginalTokens = sections.reduce((sum, s) => sum + Math.ceil(s.content.length / 4), 0);
347
+ const dedupPercent = totalOriginalTokens > 0
348
+ ? Math.round((tokensSaved / totalOriginalTokens) * 100)
349
+ : 0;
350
+ return {
351
+ originalCount: sections.length,
352
+ uniqueCount: canonicals.length,
353
+ canonicals,
354
+ references,
355
+ clusters,
356
+ tokensSaved,
357
+ dedupPercent,
358
+ processingTimeMs: Date.now() - startTime,
359
+ };
360
+ }
361
+ // =============================================================================
362
+ // Formatting
363
+ // =============================================================================
364
+ /**
365
+ * Format deduplication result for display
366
+ */
367
+ export function formatDeduplicationResult(result) {
368
+ const lines = [
369
+ '## Cross-Section Deduplication',
370
+ '',
371
+ `**Original Sections:** ${result.originalCount}`,
372
+ `**Unique Sections:** ${result.uniqueCount}`,
373
+ `**Duplicates Removed:** ${result.originalCount - result.uniqueCount}`,
374
+ `**Tokens Saved:** ~${result.tokensSaved} (${result.dedupPercent}%)`,
375
+ `**Processing Time:** ${result.processingTimeMs}ms`,
376
+ '',
377
+ ];
378
+ if (result.clusters.length > 0) {
379
+ lines.push('**Clusters Found:**');
380
+ for (const cluster of result.clusters.slice(0, 5)) {
381
+ lines.push(`- ${cluster.canonicalId}: ${cluster.duplicateIds.length} duplicates ` +
382
+ `(${cluster.avgSimilarity.toFixed(2)} avg similarity, ${cluster.tokensSaved} tokens saved)`);
383
+ }
384
+ if (result.clusters.length > 5) {
385
+ lines.push(`- ... and ${result.clusters.length - 5} more clusters`);
386
+ }
387
+ }
388
+ return lines.join('\n');
389
+ }
390
+ /**
391
+ * Create reference placeholder for deduplicated section
392
+ */
393
+ export function createReferencePlaceholder(canonicalId, similarity) {
394
+ return `[Duplicate of ${canonicalId}, ${Math.round(similarity * 100)}% similar]`;
395
+ }
396
+ //# sourceMappingURL=cross-section-dedup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cross-section-dedup.js","sourceRoot":"","sources":["../../../src/core/budget/cross-section-dedup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAmFpC;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAyB;IACzD,mBAAmB,EAAE,GAAG;IACxB,cAAc,EAAE,IAAI;IACpB,mBAAmB,EAAE,IAAI;IACzB,cAAc,EAAE,EAAE;IAClB,WAAW,EAAE,GAAG;CACjB,CAAC;AAEF,gFAAgF;AAChF,gBAAgB;AAChB,gFA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,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,0BAA0B,CACxC,WAAmB,EACnB,UAAkB;IAElB,OAAO,iBAAiB,WAAW,KAAK,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,GAAG,CAAC,YAAY,CAAC;AACnF,CAAC"}
@@ -1,3 +1,13 @@
1
+ /**
2
+ * Budget Module - v9.13.0
3
+ *
4
+ * Token budget management and entropy-guided allocation.
5
+ *
6
+ * v9.6.0: Added entropy-guided context budgeting
7
+ * v9.13.0: Added language-specific entropy profiles and cross-section deduplication
8
+ */
1
9
  export * from './token-estimator.js';
2
10
  export * from './entropy-budget.js';
11
+ export * from './language-entropy-profiles.js';
12
+ export * from './cross-section-dedup.js';
3
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/budget/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/budget/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,gCAAgC,CAAC;AAG/C,cAAc,0BAA0B,CAAC"}
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Budget Module - v9.13.0
3
+ *
4
+ * Token budget management and entropy-guided allocation.
5
+ *
6
+ * v9.6.0: Added entropy-guided context budgeting
7
+ * v9.13.0: Added language-specific entropy profiles and cross-section deduplication
8
+ */
1
9
  export * from './token-estimator.js';
2
10
  export * from './entropy-budget.js';
11
+ // v9.13.0: Language-specific entropy profiles
12
+ export * from './language-entropy-profiles.js';
13
+ // v9.13.0: Cross-section deduplication
14
+ export * from './cross-section-dedup.js';
3
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/budget/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/budget/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AAEpC,8CAA8C;AAC9C,cAAc,gCAAgC,CAAC;AAE/C,uCAAuC;AACvC,cAAc,0BAA0B,CAAC"}