@fragments-sdk/context 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ function filterPlaceholders(items) {
10
10
  (item) => !PLACEHOLDER_PATTERNS.some((pattern) => pattern.test(item.trim()))
11
11
  );
12
12
  }
13
- function generateContext(segments, options = {}, blocks) {
13
+ function generateContext(fragments, options = {}, blocks) {
14
14
  const format = options.format ?? "markdown";
15
15
  const compact = options.compact ?? false;
16
16
  const include = {
@@ -20,7 +20,7 @@ function generateContext(segments, options = {}, blocks) {
20
20
  relations: options.include?.relations ?? false,
21
21
  code: options.include?.code ?? false
22
22
  };
23
- const sorted = [...segments].sort((a, b) => {
23
+ const sorted = [...fragments].sort((a, b) => {
24
24
  const catCompare = a.meta.category.localeCompare(b.meta.category);
25
25
  if (catCompare !== 0) return catCompare;
26
26
  return a.meta.name.localeCompare(b.meta.name);
@@ -30,7 +30,7 @@ function generateContext(segments, options = {}, blocks) {
30
30
  }
31
31
  return generateMarkdownContext(sorted, include, compact, blocks);
32
32
  }
33
- function generateMarkdownContext(segments, include, compact, blocks) {
33
+ function generateMarkdownContext(fragments, include, compact, blocks) {
34
34
  const lines = [];
35
35
  lines.push("# Design System Reference");
36
36
  lines.push("");
@@ -38,10 +38,10 @@ function generateMarkdownContext(segments, include, compact, blocks) {
38
38
  lines.push("");
39
39
  lines.push("| Component | Category | Use For |");
40
40
  lines.push("|-----------|----------|---------|");
41
- for (const segment of segments) {
42
- const filteredWhen = filterPlaceholders(segment.usage.when);
43
- const useFor = filteredWhen.slice(0, 2).join(", ") || segment.meta.description;
44
- lines.push(`| ${segment.meta.name} | ${segment.meta.category} | ${truncate(useFor, 50)} |`);
41
+ for (const fragment of fragments) {
42
+ const filteredWhen = filterPlaceholders(fragment.usage.when);
43
+ const useFor = filteredWhen.slice(0, 2).join(", ") || fragment.meta.description;
44
+ lines.push(`| ${fragment.meta.name} | ${fragment.meta.category} | ${truncate(useFor, 50)} |`);
45
45
  }
46
46
  lines.push("");
47
47
  if (compact) {
@@ -50,21 +50,21 @@ function generateMarkdownContext(segments, include, compact, blocks) {
50
50
  }
51
51
  lines.push("## Components");
52
52
  lines.push("");
53
- for (const segment of segments) {
54
- lines.push(`### ${segment.meta.name}`);
53
+ for (const fragment of fragments) {
54
+ lines.push(`### ${fragment.meta.name}`);
55
55
  lines.push("");
56
- const statusParts = [`**Category:** ${segment.meta.category}`];
57
- if (segment.meta.status) {
58
- statusParts.push(`**Status:** ${segment.meta.status}`);
56
+ const statusParts = [`**Category:** ${fragment.meta.category}`];
57
+ if (fragment.meta.status) {
58
+ statusParts.push(`**Status:** ${fragment.meta.status}`);
59
59
  }
60
60
  lines.push(statusParts.join(" | "));
61
61
  lines.push("");
62
- if (segment.meta.description) {
63
- lines.push(segment.meta.description);
62
+ if (fragment.meta.description) {
63
+ lines.push(fragment.meta.description);
64
64
  lines.push("");
65
65
  }
66
- const whenFiltered = filterPlaceholders(segment.usage.when);
67
- const whenNotFiltered = filterPlaceholders(segment.usage.whenNot);
66
+ const whenFiltered = filterPlaceholders(fragment.usage.when);
67
+ const whenNotFiltered = filterPlaceholders(fragment.usage.whenNot);
68
68
  if (include.usage && (whenFiltered.length > 0 || whenNotFiltered.length > 0)) {
69
69
  if (whenFiltered.length > 0) {
70
70
  lines.push("**When to use:**");
@@ -81,19 +81,19 @@ function generateMarkdownContext(segments, include, compact, blocks) {
81
81
  lines.push("");
82
82
  }
83
83
  }
84
- if (include.props && Object.keys(segment.props).length > 0) {
84
+ if (include.props && Object.keys(fragment.props).length > 0) {
85
85
  lines.push("**Props:**");
86
- for (const [name, prop] of Object.entries(segment.props)) {
86
+ for (const [name, prop] of Object.entries(fragment.props)) {
87
87
  lines.push(`- \`${name}\`: ${formatPropType(prop)}${prop.required ? " (required)" : ""}`);
88
88
  }
89
89
  lines.push("");
90
90
  }
91
- if (include.variants && segment.variants.length > 0) {
92
- const variantNames = segment.variants.map((v) => v.name).join(", ");
91
+ if (include.variants && fragment.variants.length > 0) {
92
+ const variantNames = fragment.variants.map((v) => v.name).join(", ");
93
93
  lines.push(`**Variants:** ${variantNames}`);
94
94
  lines.push("");
95
95
  if (include.code) {
96
- for (const variant of segment.variants) {
96
+ for (const variant of fragment.variants) {
97
97
  if (variant.code) {
98
98
  lines.push(`*${variant.name}:*`);
99
99
  lines.push("```tsx");
@@ -104,9 +104,9 @@ function generateMarkdownContext(segments, include, compact, blocks) {
104
104
  }
105
105
  }
106
106
  }
107
- if (include.relations && segment.relations && segment.relations.length > 0) {
107
+ if (include.relations && fragment.relations && fragment.relations.length > 0) {
108
108
  lines.push("**Related:**");
109
- for (const relation of segment.relations) {
109
+ for (const relation of fragment.relations) {
110
110
  lines.push(`- ${relation.component} (${relation.relationship}): ${relation.note}`);
111
111
  }
112
112
  lines.push("");
@@ -141,27 +141,27 @@ function generateMarkdownContext(segments, include, compact, blocks) {
141
141
  const content = lines.join("\n");
142
142
  return { content, tokenEstimate: estimateTokens(content) };
143
143
  }
144
- function generateJsonContext(segments, include, compact, blocks) {
145
- const categories = [...new Set(segments.map((s) => s.meta.category))].sort();
144
+ function generateJsonContext(fragments, include, compact, blocks) {
145
+ const categories = [...new Set(fragments.map((s) => s.meta.category))].sort();
146
146
  const components = {};
147
- for (const segment of segments) {
147
+ for (const fragment of fragments) {
148
148
  const component = {
149
- category: segment.meta.category,
150
- description: segment.meta.description
149
+ category: fragment.meta.category,
150
+ description: fragment.meta.description
151
151
  };
152
- if (segment.meta.status) {
153
- component.status = segment.meta.status;
152
+ if (fragment.meta.status) {
153
+ component.status = fragment.meta.status;
154
154
  }
155
155
  if (!compact) {
156
156
  if (include.usage) {
157
- const whenFiltered = filterPlaceholders(segment.usage.when);
158
- const whenNotFiltered = filterPlaceholders(segment.usage.whenNot);
157
+ const whenFiltered = filterPlaceholders(fragment.usage.when);
158
+ const whenNotFiltered = filterPlaceholders(fragment.usage.whenNot);
159
159
  if (whenFiltered.length > 0) component.whenToUse = whenFiltered;
160
160
  if (whenNotFiltered.length > 0) component.whenNotToUse = whenNotFiltered;
161
161
  }
162
- if (include.props && Object.keys(segment.props).length > 0) {
162
+ if (include.props && Object.keys(fragment.props).length > 0) {
163
163
  component.props = {};
164
- for (const [name, prop] of Object.entries(segment.props)) {
164
+ for (const [name, prop] of Object.entries(fragment.props)) {
165
165
  component.props[name] = {
166
166
  type: formatPropType(prop),
167
167
  description: prop.description
@@ -170,18 +170,18 @@ function generateJsonContext(segments, include, compact, blocks) {
170
170
  if (prop.default !== void 0) component.props[name].default = prop.default;
171
171
  }
172
172
  }
173
- if (include.variants && segment.variants.length > 0) {
174
- component.variants = segment.variants.map((v) => v.name);
173
+ if (include.variants && fragment.variants.length > 0) {
174
+ component.variants = fragment.variants.map((v) => v.name);
175
175
  }
176
- if (include.relations && segment.relations && segment.relations.length > 0) {
177
- component.relations = segment.relations.map((r) => ({
176
+ if (include.relations && fragment.relations && fragment.relations.length > 0) {
177
+ component.relations = fragment.relations.map((r) => ({
178
178
  component: r.component,
179
179
  relationship: r.relationship,
180
180
  note: r.note
181
181
  }));
182
182
  }
183
183
  }
184
- components[segment.meta.name] = component;
184
+ components[fragment.meta.name] = component;
185
185
  }
186
186
  const blocksMap = blocks && blocks.length > 0 ? Object.fromEntries(blocks.map((b) => [b.name, {
187
187
  description: b.description,
@@ -194,7 +194,7 @@ function generateJsonContext(segments, include, compact, blocks) {
194
194
  version: "1.0",
195
195
  generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
196
196
  summary: {
197
- totalComponents: segments.length,
197
+ totalComponents: fragments.length,
198
198
  categories,
199
199
  ...blocksMap && { totalBlocks: blocks.length }
200
200
  },
@@ -399,7 +399,7 @@ var CLI_COMMANDS = [
399
399
  options: [
400
400
  { flags: "-c, --config <path>", description: "Path to config file" },
401
401
  { flags: "-o, --output <dir>", description: "Output directory", default: ".storybook/generated" },
402
- { flags: "--watch", description: "Watch for segment changes and regenerate" },
402
+ { flags: "--watch", description: "Watch for fragment changes and regenerate" },
403
403
  { flags: "--format <format>", description: "Story format (csf3)", default: "csf3" }
404
404
  ]
405
405
  },
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  CLI_COMMANDS,
3
3
  CLI_COMMAND_CATEGORIES
4
- } from "../chunk-U4V5NX67.js";
4
+ } from "../chunk-IQMVRBVF.js";
5
5
  export {
6
6
  CLI_COMMANDS,
7
7
  CLI_COMMAND_CATEGORIES
@@ -1,4 +1,4 @@
1
- import { CompiledSegment, CompiledBlock } from '../types/index.js';
1
+ import { CompiledFragment, CompiledBlock } from '../types/index.js';
2
2
  import '../types-DOhSojcf.js';
3
3
 
4
4
  /**
@@ -37,8 +37,8 @@ interface ContextResult {
37
37
  tokenEstimate: number;
38
38
  }
39
39
  /**
40
- * Generate AI-ready context from compiled segments and optional blocks
40
+ * Generate AI-ready context from compiled fragments and optional blocks
41
41
  */
42
- declare function generateContext(segments: CompiledSegment[], options?: ContextOptions, blocks?: CompiledBlock[]): ContextResult;
42
+ declare function generateContext(fragments: CompiledFragment[], options?: ContextOptions, blocks?: CompiledBlock[]): ContextResult;
43
43
 
44
44
  export { type ContextOptions, type ContextResult, PLACEHOLDER_PATTERNS, filterPlaceholders, generateContext };
@@ -2,7 +2,7 @@ import {
2
2
  PLACEHOLDER_PATTERNS,
3
3
  filterPlaceholders,
4
4
  generateContext
5
- } from "../chunk-KKABP4K4.js";
5
+ } from "../chunk-2UQY4VNM.js";
6
6
  export {
7
7
  PLACEHOLDER_PATTERNS,
8
8
  filterPlaceholders,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { AIMetadata, CompiledBlock, CompiledSegment, CompiledSegmentsFile, CompiledTokenData, CompiledTokenEntry, ComponentRelation, PropDefinition, SegmentContract, SegmentGenerated, SegmentMeta, SegmentUsage, Theme, VerifyResult } from './types/index.js';
1
+ export { AIMetadata, CompiledBlock, CompiledFragment, CompiledFragmentsFile, CompiledTokenData, CompiledTokenEntry, ComponentRelation, FragmentContract, FragmentGenerated, FragmentMeta, FragmentUsage, PropDefinition, Theme, VerifyResult } from './types/index.js';
2
2
  export { ContextOptions, ContextResult, PLACEHOLDER_PATTERNS, filterPlaceholders, generateContext } from './generate/index.js';
3
3
  export { ASTChunkerOptions, ChunkOptions, CodeChunk, chunkByAST, chunkByLines, chunkFile } from './chunking/index.js';
4
4
  export { EmbeddingOptions, EmbeddingResult, RerankOptions, RerankResult, generateEmbeddings, rerankResults } from './embeddings/voyage.js';
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  CLI_COMMANDS,
9
9
  CLI_COMMAND_CATEGORIES
10
- } from "./chunk-U4V5NX67.js";
10
+ } from "./chunk-IQMVRBVF.js";
11
11
  import {
12
12
  chunkByAST,
13
13
  chunkByLines,
@@ -36,7 +36,7 @@ import {
36
36
  PLACEHOLDER_PATTERNS,
37
37
  filterPlaceholders,
38
38
  generateContext
39
- } from "./chunk-KKABP4K4.js";
39
+ } from "./chunk-2UQY4VNM.js";
40
40
  import {
41
41
  buildCitationDocuments,
42
42
  resolveCitation,
@@ -9,7 +9,7 @@ import { S as SerializedComponentGraph } from '../types-DOhSojcf.js';
9
9
  /**
10
10
  * Component metadata
11
11
  */
12
- interface SegmentMeta {
12
+ interface FragmentMeta {
13
13
  name: string;
14
14
  description: string;
15
15
  category: string;
@@ -22,7 +22,7 @@ interface SegmentMeta {
22
22
  /**
23
23
  * Usage guidelines for AI agents and developers
24
24
  */
25
- interface SegmentUsage {
25
+ interface FragmentUsage {
26
26
  when: string[];
27
27
  whenNot: string[];
28
28
  guidelines?: string[];
@@ -58,7 +58,7 @@ interface ComponentRelation {
58
58
  /**
59
59
  * Agent-optimized contract metadata
60
60
  */
61
- interface SegmentContract {
61
+ interface FragmentContract {
62
62
  propsSummary?: string[];
63
63
  a11yRules?: string[];
64
64
  bans?: Array<{
@@ -68,9 +68,9 @@ interface SegmentContract {
68
68
  scenarioTags?: string[];
69
69
  }
70
70
  /**
71
- * Provenance tracking for generated segments
71
+ * Provenance tracking for generated fragments
72
72
  */
73
- interface SegmentGenerated {
73
+ interface FragmentGenerated {
74
74
  source: "storybook" | "manual" | "ai";
75
75
  sourceFile?: string;
76
76
  confidence?: number;
@@ -86,12 +86,12 @@ interface AIMetadata {
86
86
  commonPatterns?: string[];
87
87
  }
88
88
  /**
89
- * Compiled segment data (JSON-serializable for AI consumption)
89
+ * Compiled fragment data (JSON-serializable for AI consumption)
90
90
  */
91
- interface CompiledSegment {
91
+ interface CompiledFragment {
92
92
  filePath: string;
93
- meta: SegmentMeta;
94
- usage: SegmentUsage;
93
+ meta: FragmentMeta;
94
+ usage: FragmentUsage;
95
95
  props: Record<string, PropDefinition>;
96
96
  relations?: ComponentRelation[];
97
97
  variants: Array<{
@@ -101,9 +101,9 @@ interface CompiledSegment {
101
101
  figma?: string;
102
102
  args?: Record<string, unknown>;
103
103
  }>;
104
- contract?: SegmentContract;
104
+ contract?: FragmentContract;
105
105
  ai?: AIMetadata;
106
- _generated?: SegmentGenerated;
106
+ _generated?: FragmentGenerated;
107
107
  }
108
108
  /**
109
109
  * Compiled block data (JSON-serializable for AI consumption)
@@ -135,11 +135,11 @@ interface CompiledTokenData {
135
135
  /**
136
136
  * The compiled fragments.json structure
137
137
  */
138
- interface CompiledSegmentsFile {
138
+ interface CompiledFragmentsFile {
139
139
  version: string;
140
140
  generatedAt: string;
141
141
  packageName?: string;
142
- segments: Record<string, CompiledSegment>;
142
+ fragments: Record<string, CompiledFragment>;
143
143
  blocks?: Record<string, CompiledBlock>;
144
144
  tokens?: CompiledTokenData;
145
145
  /** Component relationship graph for AI structural queries */
@@ -171,4 +171,4 @@ interface VerifyResult {
171
171
  };
172
172
  }
173
173
 
174
- export type { AIMetadata, CompiledBlock, CompiledSegment, CompiledSegmentsFile, CompiledTokenData, CompiledTokenEntry, ComponentRelation, PropDefinition, SegmentContract, SegmentGenerated, SegmentMeta, SegmentUsage, Theme, VerifyResult };
174
+ export type { AIMetadata, CompiledBlock, CompiledFragment, CompiledFragmentsFile, CompiledTokenData, CompiledTokenEntry, ComponentRelation, FragmentContract, FragmentGenerated, FragmentMeta, FragmentUsage, PropDefinition, Theme, VerifyResult };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fragments-sdk/context",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Code intelligence and RAG primitives for design system and codebase indexing",
5
5
  "repository": {
6
6
  "type": "git",