@fragments-sdk/context 0.1.3 → 0.2.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.
- package/dist/chunk-3FEHRHFQ.js +103 -0
- package/dist/chunk-3VPR67FN.js +76 -0
- package/dist/chunk-HINI3FCI.js +42 -0
- package/dist/chunk-JFV27WLV.js +168 -0
- package/dist/chunk-KKABP4K4.js +228 -0
- package/dist/chunk-KQIRG24U.js +260 -0
- package/dist/chunk-ZMBYQK43.js +91 -0
- package/dist/chunking/index.d.ts +53 -0
- package/dist/chunking/index.js +11 -0
- package/dist/citations/index.d.ts +94 -0
- package/dist/citations/index.js +10 -0
- package/dist/embeddings/voyage.d.ts +44 -0
- package/dist/embeddings/voyage.js +8 -0
- package/dist/generate/index.d.ts +43 -0
- package/dist/generate/index.js +10 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +56 -0
- package/dist/indexing/index.d.ts +52 -0
- package/dist/indexing/index.js +20 -0
- package/dist/search/index.d.ts +29 -0
- package/dist/search/index.js +8 -0
- package/dist/types/index.d.ts +170 -0
- package/dist/types/index.js +0 -0
- package/dist/types-B7duBj6U.d.ts +39 -0
- package/package.json +13 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute a SHA-256 hash of the given content.
|
|
3
|
+
* Used for incremental indexing — only re-embed files whose hash has changed.
|
|
4
|
+
*/
|
|
5
|
+
declare function hashContent(content: string): string;
|
|
6
|
+
|
|
7
|
+
interface FileEntry {
|
|
8
|
+
/** File path relative to repo root. */
|
|
9
|
+
filePath: string;
|
|
10
|
+
/** SHA-256 content hash. */
|
|
11
|
+
contentHash: string;
|
|
12
|
+
/** Optional: IDs of chunks generated from this file. */
|
|
13
|
+
chunkIds?: string[];
|
|
14
|
+
}
|
|
15
|
+
interface ChangedFiles {
|
|
16
|
+
/** Files that are new (not in old set). */
|
|
17
|
+
added: string[];
|
|
18
|
+
/** Files that exist in both but have different content hashes. */
|
|
19
|
+
modified: string[];
|
|
20
|
+
/** Files that were in old set but not in new set. */
|
|
21
|
+
deleted: string[];
|
|
22
|
+
/** Files that are unchanged. */
|
|
23
|
+
unchanged: string[];
|
|
24
|
+
}
|
|
25
|
+
/** Mapping from file extension to tree-sitter grammar name. */
|
|
26
|
+
interface GrammarMapping {
|
|
27
|
+
extension: string;
|
|
28
|
+
language: string;
|
|
29
|
+
treeSitterGrammar: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Compare old and new file entry lists to determine which files were
|
|
34
|
+
* added, modified, deleted, or unchanged.
|
|
35
|
+
*
|
|
36
|
+
* Uses content hashes for comparison — two files with identical content
|
|
37
|
+
* are considered unchanged even if their metadata differs.
|
|
38
|
+
*/
|
|
39
|
+
declare function resolveChanges(oldEntries: FileEntry[], newEntries: FileEntry[]): ChangedFiles;
|
|
40
|
+
|
|
41
|
+
declare const INDEXABLE_EXTENSIONS: Set<string>;
|
|
42
|
+
declare function shouldIndexFile(path: string, size: number): boolean;
|
|
43
|
+
/** Languages that have tree-sitter grammar support for AST chunking. */
|
|
44
|
+
declare const AST_SUPPORTED_LANGUAGES: Set<string>;
|
|
45
|
+
declare function detectLanguage(path: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Get the tree-sitter grammar name for a file extension.
|
|
48
|
+
* Returns empty string if no grammar is available (falls back to line chunker).
|
|
49
|
+
*/
|
|
50
|
+
declare function getTreeSitterGrammar(path: string): string;
|
|
51
|
+
|
|
52
|
+
export { AST_SUPPORTED_LANGUAGES, type ChangedFiles, type FileEntry, type GrammarMapping, INDEXABLE_EXTENSIONS, detectLanguage, getTreeSitterGrammar, hashContent, resolveChanges, shouldIndexFile };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hashContent,
|
|
3
|
+
resolveChanges
|
|
4
|
+
} from "../chunk-HINI3FCI.js";
|
|
5
|
+
import {
|
|
6
|
+
AST_SUPPORTED_LANGUAGES,
|
|
7
|
+
INDEXABLE_EXTENSIONS,
|
|
8
|
+
detectLanguage,
|
|
9
|
+
getTreeSitterGrammar,
|
|
10
|
+
shouldIndexFile
|
|
11
|
+
} from "../chunk-JFV27WLV.js";
|
|
12
|
+
export {
|
|
13
|
+
AST_SUPPORTED_LANGUAGES,
|
|
14
|
+
INDEXABLE_EXTENSIONS,
|
|
15
|
+
detectLanguage,
|
|
16
|
+
getTreeSitterGrammar,
|
|
17
|
+
hashContent,
|
|
18
|
+
resolveChanges,
|
|
19
|
+
shouldIndexFile
|
|
20
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { S as SearchResult, F as FusedResult, a as ScoredChunk } from '../types-B7duBj6U.js';
|
|
2
|
+
export { R as RankedResult } from '../types-B7duBj6U.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reciprocal Rank Fusion (RRF) — merges multiple ranked result lists
|
|
6
|
+
* into a single ranking using the formula: score = sum(1 / (k + rank))
|
|
7
|
+
*
|
|
8
|
+
* This is a standard technique for combining results from different
|
|
9
|
+
* search systems (e.g., vector search + BM25 full-text search).
|
|
10
|
+
*
|
|
11
|
+
* @param resultSets - Array of result sets, each with a label and ranked results
|
|
12
|
+
* @param k - Smoothing constant (default: 60, as per the original RRF paper)
|
|
13
|
+
* @returns Fused results sorted by combined score (highest first)
|
|
14
|
+
*/
|
|
15
|
+
declare function reciprocalRankFusion(resultSets: Array<{
|
|
16
|
+
label: string;
|
|
17
|
+
results: SearchResult[];
|
|
18
|
+
}>, k?: number): FusedResult[];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Deduplicate and merge overlapping chunks from the same file.
|
|
22
|
+
*
|
|
23
|
+
* When hybrid search + reranking returns multiple chunks from the same file
|
|
24
|
+
* with overlapping line ranges, merge them into a single contiguous block
|
|
25
|
+
* to avoid redundancy in the LLM context window.
|
|
26
|
+
*/
|
|
27
|
+
declare function deduplicateChunks(chunks: ScoredChunk[]): ScoredChunk[];
|
|
28
|
+
|
|
29
|
+
export { FusedResult, ScoredChunk, SearchResult, deduplicateChunks, reciprocalRankFusion };
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compiled fragment types — shared between CLI and MCP packages.
|
|
3
|
+
*
|
|
4
|
+
* These are the JSON-serializable types used in fragments.json and consumed
|
|
5
|
+
* by AI agents, MCP servers, and context generators.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Component metadata
|
|
9
|
+
*/
|
|
10
|
+
interface SegmentMeta {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
category: string;
|
|
14
|
+
tags?: string[];
|
|
15
|
+
status?: "stable" | "beta" | "deprecated" | "experimental";
|
|
16
|
+
since?: string;
|
|
17
|
+
figma?: string;
|
|
18
|
+
figmaProps?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Usage guidelines for AI agents and developers
|
|
22
|
+
*/
|
|
23
|
+
interface SegmentUsage {
|
|
24
|
+
when: string[];
|
|
25
|
+
whenNot: string[];
|
|
26
|
+
guidelines?: string[];
|
|
27
|
+
accessibility?: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Definition for a single prop
|
|
31
|
+
*/
|
|
32
|
+
interface PropDefinition {
|
|
33
|
+
type: string;
|
|
34
|
+
values?: readonly string[];
|
|
35
|
+
default?: unknown;
|
|
36
|
+
description: string;
|
|
37
|
+
required?: boolean;
|
|
38
|
+
constraints?: string[];
|
|
39
|
+
typeDetails?: Record<string, unknown>;
|
|
40
|
+
controlType?: string;
|
|
41
|
+
controlOptions?: {
|
|
42
|
+
min?: number;
|
|
43
|
+
max?: number;
|
|
44
|
+
step?: number;
|
|
45
|
+
presetColors?: string[];
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Relationship to another component
|
|
50
|
+
*/
|
|
51
|
+
interface ComponentRelation {
|
|
52
|
+
component: string;
|
|
53
|
+
relationship: string;
|
|
54
|
+
note: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Agent-optimized contract metadata
|
|
58
|
+
*/
|
|
59
|
+
interface SegmentContract {
|
|
60
|
+
propsSummary?: string[];
|
|
61
|
+
a11yRules?: string[];
|
|
62
|
+
bans?: Array<{
|
|
63
|
+
pattern: string;
|
|
64
|
+
message: string;
|
|
65
|
+
}>;
|
|
66
|
+
scenarioTags?: string[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Provenance tracking for generated segments
|
|
70
|
+
*/
|
|
71
|
+
interface SegmentGenerated {
|
|
72
|
+
source: "storybook" | "manual" | "ai";
|
|
73
|
+
sourceFile?: string;
|
|
74
|
+
confidence?: number;
|
|
75
|
+
timestamp?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* AI-specific metadata
|
|
79
|
+
*/
|
|
80
|
+
interface AIMetadata {
|
|
81
|
+
compositionPattern?: "compound" | "simple" | "controlled";
|
|
82
|
+
subComponents?: string[];
|
|
83
|
+
requiredChildren?: string[];
|
|
84
|
+
commonPatterns?: string[];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Compiled segment data (JSON-serializable for AI consumption)
|
|
88
|
+
*/
|
|
89
|
+
interface CompiledSegment {
|
|
90
|
+
filePath: string;
|
|
91
|
+
meta: SegmentMeta;
|
|
92
|
+
usage: SegmentUsage;
|
|
93
|
+
props: Record<string, PropDefinition>;
|
|
94
|
+
relations?: ComponentRelation[];
|
|
95
|
+
variants: Array<{
|
|
96
|
+
name: string;
|
|
97
|
+
description: string;
|
|
98
|
+
code?: string;
|
|
99
|
+
figma?: string;
|
|
100
|
+
args?: Record<string, unknown>;
|
|
101
|
+
}>;
|
|
102
|
+
contract?: SegmentContract;
|
|
103
|
+
ai?: AIMetadata;
|
|
104
|
+
_generated?: SegmentGenerated;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Compiled block data (JSON-serializable for AI consumption)
|
|
108
|
+
*/
|
|
109
|
+
interface CompiledBlock {
|
|
110
|
+
filePath: string;
|
|
111
|
+
name: string;
|
|
112
|
+
description: string;
|
|
113
|
+
category: string;
|
|
114
|
+
components: string[];
|
|
115
|
+
code: string;
|
|
116
|
+
tags?: string[];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* A single token entry in the compiled output
|
|
120
|
+
*/
|
|
121
|
+
interface CompiledTokenEntry {
|
|
122
|
+
name: string;
|
|
123
|
+
description?: string;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Compiled token data stored in fragments.json
|
|
127
|
+
*/
|
|
128
|
+
interface CompiledTokenData {
|
|
129
|
+
prefix: string;
|
|
130
|
+
total: number;
|
|
131
|
+
categories: Record<string, CompiledTokenEntry[]>;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The compiled fragments.json structure
|
|
135
|
+
*/
|
|
136
|
+
interface CompiledSegmentsFile {
|
|
137
|
+
version: string;
|
|
138
|
+
generatedAt: string;
|
|
139
|
+
packageName?: string;
|
|
140
|
+
segments: Record<string, CompiledSegment>;
|
|
141
|
+
blocks?: Record<string, CompiledBlock>;
|
|
142
|
+
tokens?: CompiledTokenData;
|
|
143
|
+
/** @deprecated Use blocks instead */
|
|
144
|
+
recipes?: Record<string, CompiledBlock>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Theme identifier
|
|
148
|
+
*/
|
|
149
|
+
type Theme = "light" | "dark";
|
|
150
|
+
/**
|
|
151
|
+
* Verification result
|
|
152
|
+
*/
|
|
153
|
+
interface VerifyResult {
|
|
154
|
+
verdict: "pass" | "fail" | "error";
|
|
155
|
+
matches: boolean;
|
|
156
|
+
diffPercentage: number;
|
|
157
|
+
screenshot: string;
|
|
158
|
+
baseline: string;
|
|
159
|
+
diffImage?: string;
|
|
160
|
+
notes: string[];
|
|
161
|
+
error?: string;
|
|
162
|
+
timing: {
|
|
163
|
+
renderMs: number;
|
|
164
|
+
captureMs: number;
|
|
165
|
+
diffMs: number;
|
|
166
|
+
totalMs: number;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export type { AIMetadata, CompiledBlock, CompiledSegment, CompiledSegmentsFile, CompiledTokenData, CompiledTokenEntry, ComponentRelation, PropDefinition, SegmentContract, SegmentGenerated, SegmentMeta, SegmentUsage, Theme, VerifyResult };
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
interface SearchResult {
|
|
2
|
+
/** Unique identifier for the result. */
|
|
3
|
+
id: string;
|
|
4
|
+
/** Rank position in the result list (0-indexed). */
|
|
5
|
+
rank: number;
|
|
6
|
+
/** Optional score from the search system. */
|
|
7
|
+
score?: number;
|
|
8
|
+
}
|
|
9
|
+
interface RankedResult extends SearchResult {
|
|
10
|
+
/** The content or document associated with this result. */
|
|
11
|
+
content: string;
|
|
12
|
+
/** File path of the source. */
|
|
13
|
+
filePath: string;
|
|
14
|
+
/** Start line in the source file. */
|
|
15
|
+
startLine: number;
|
|
16
|
+
/** End line in the source file. */
|
|
17
|
+
endLine: number;
|
|
18
|
+
}
|
|
19
|
+
interface FusedResult {
|
|
20
|
+
/** Unique identifier for the result. */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Fused RRF score across all result sets. */
|
|
23
|
+
fusedScore: number;
|
|
24
|
+
/** Which result sets contributed to this result. */
|
|
25
|
+
sources: string[];
|
|
26
|
+
}
|
|
27
|
+
interface ScoredChunk {
|
|
28
|
+
id: string;
|
|
29
|
+
content: string;
|
|
30
|
+
filePath: string;
|
|
31
|
+
startLine: number;
|
|
32
|
+
endLine: number;
|
|
33
|
+
language: string;
|
|
34
|
+
score: number;
|
|
35
|
+
symbolName?: string;
|
|
36
|
+
chunkType?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type { FusedResult as F, RankedResult as R, SearchResult as S, ScoredChunk as a };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fragments-sdk/context",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Code intelligence and RAG primitives for design system and codebase indexing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,6 +26,18 @@
|
|
|
26
26
|
"./indexing": {
|
|
27
27
|
"types": "./dist/indexing/index.d.ts",
|
|
28
28
|
"import": "./dist/indexing/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./types": {
|
|
31
|
+
"types": "./dist/types/index.d.ts",
|
|
32
|
+
"import": "./dist/types/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./generate": {
|
|
35
|
+
"types": "./dist/generate/index.d.ts",
|
|
36
|
+
"import": "./dist/generate/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./citations": {
|
|
39
|
+
"types": "./dist/citations/index.d.ts",
|
|
40
|
+
"import": "./dist/citations/index.js"
|
|
29
41
|
}
|
|
30
42
|
},
|
|
31
43
|
"publishConfig": {
|