@a-company/paradigm 1.5.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 (114) hide show
  1. package/README.md +142 -0
  2. package/dist/accept-orchestration-CWZNCGZX.js +188 -0
  3. package/dist/agents-suggest-35LIQKDH.js +83 -0
  4. package/dist/aggregate-W7Q6VIM2.js +88 -0
  5. package/dist/auto-IU7VN55K.js +470 -0
  6. package/dist/beacon-B47XSTL7.js +251 -0
  7. package/dist/chunk-2M6OSOIG.js +1302 -0
  8. package/dist/chunk-4NCFWYGG.js +110 -0
  9. package/dist/chunk-5C4SGQKH.js +705 -0
  10. package/dist/chunk-5GOA7WYD.js +1095 -0
  11. package/dist/chunk-5JGJACDU.js +37 -0
  12. package/dist/chunk-6QC3YGB6.js +114 -0
  13. package/dist/chunk-753RICFF.js +325 -0
  14. package/dist/chunk-AD2LSCHB.js +1595 -0
  15. package/dist/chunk-CHSHON3O.js +669 -0
  16. package/dist/chunk-ELLR7WP6.js +3175 -0
  17. package/dist/chunk-ILOWBJRC.js +12 -0
  18. package/dist/chunk-IRKUEJVW.js +405 -0
  19. package/dist/chunk-MC7XC7XQ.js +533 -0
  20. package/dist/chunk-MO4EEYFW.js +38 -0
  21. package/dist/chunk-MQWH7PFI.js +13366 -0
  22. package/dist/chunk-N6PJAPDE.js +364 -0
  23. package/dist/chunk-PBHIFAL4.js +259 -0
  24. package/dist/chunk-PMXRGPRQ.js +305 -0
  25. package/dist/chunk-PW2EXJQT.js +689 -0
  26. package/dist/chunk-TAP5N3HH.js +245 -0
  27. package/dist/chunk-THFVK5AE.js +148 -0
  28. package/dist/chunk-UM54F7G5.js +1533 -0
  29. package/dist/chunk-UUZ2DMG5.js +185 -0
  30. package/dist/chunk-WS5KM7OL.js +780 -0
  31. package/dist/chunk-YDNKXH4Z.js +2316 -0
  32. package/dist/chunk-YO6DVTL7.js +99 -0
  33. package/dist/claude-SUYNN72C.js +362 -0
  34. package/dist/claude-cli-OF43XAO3.js +276 -0
  35. package/dist/claude-code-PW6SKD2M.js +126 -0
  36. package/dist/claude-code-teams-JLZ5IXB6.js +199 -0
  37. package/dist/constellation-K3CIQCHI.js +225 -0
  38. package/dist/cost-AEK6R7HK.js +174 -0
  39. package/dist/cost-KYXIQ62X.js +93 -0
  40. package/dist/cursor-cli-IHJMPRCW.js +269 -0
  41. package/dist/cursorrules-KI5QWHIX.js +84 -0
  42. package/dist/diff-AJJ5H6HV.js +125 -0
  43. package/dist/dist-7MPIRMTZ-IOQOREMZ.js +10866 -0
  44. package/dist/dist-NHJQVVUW.js +68 -0
  45. package/dist/dist-ZEMSQV74.js +20 -0
  46. package/dist/doctor-6Y6L6HEB.js +11 -0
  47. package/dist/echo-VYZW3OTT.js +248 -0
  48. package/dist/export-R4FJ5NOH.js +38 -0
  49. package/dist/history-EVO3L6SC.js +277 -0
  50. package/dist/hooks-MBWE4ILT.js +12 -0
  51. package/dist/index.d.ts +2 -0
  52. package/dist/index.js +568 -0
  53. package/dist/lint-HXKTWRNO.js +316 -0
  54. package/dist/manual-Y3QOXWYA.js +204 -0
  55. package/dist/mcp.js +14745 -0
  56. package/dist/orchestrate-4ZH5GUQH.js +323 -0
  57. package/dist/probe-OYCP4JYG.js +151 -0
  58. package/dist/promote-Z52ZJTJU.js +181 -0
  59. package/dist/providers-4PGPZEWP.js +104 -0
  60. package/dist/remember-6VZ74B7E.js +77 -0
  61. package/dist/ripple-SBQOSTZD.js +215 -0
  62. package/dist/sentinel-LCFD56OJ.js +43 -0
  63. package/dist/server-F5ITNK6T.js +9846 -0
  64. package/dist/server-T6WIFYRQ.js +16076 -0
  65. package/dist/setup-DF4F3ICN.js +25 -0
  66. package/dist/setup-JHBPZAG7.js +296 -0
  67. package/dist/shift-HKIAP4ZN.js +226 -0
  68. package/dist/snapshot-GTVPRYZG.js +62 -0
  69. package/dist/spawn-BJRQA2NR.js +196 -0
  70. package/dist/summary-H6J6N6PJ.js +140 -0
  71. package/dist/switch-6EANJ7O6.js +232 -0
  72. package/dist/sync-BEOCW7TZ.js +11 -0
  73. package/dist/team-NWP2KJAB.js +32 -0
  74. package/dist/test-MA5TWJQV.js +934 -0
  75. package/dist/thread-JCJVRUQR.js +258 -0
  76. package/dist/triage-ETVXXFMV.js +1880 -0
  77. package/dist/tutorial-L5Q3ZDHK.js +666 -0
  78. package/dist/university-R2WDQLSI.js +40 -0
  79. package/dist/upgrade-5B3YGGC6.js +550 -0
  80. package/dist/validate-F3YHBCRZ.js +39 -0
  81. package/dist/validate-QEEY6KFS.js +64 -0
  82. package/dist/watch-4LT4O6K7.js +123 -0
  83. package/dist/watch-6IIWPWDN.js +111 -0
  84. package/dist/wisdom-LRM4FFCH.js +319 -0
  85. package/package.json +68 -0
  86. package/templates/paradigm/config.yaml +175 -0
  87. package/templates/paradigm/docs/commands.md +727 -0
  88. package/templates/paradigm/docs/decisions/000-template.md +47 -0
  89. package/templates/paradigm/docs/decisions/README.md +26 -0
  90. package/templates/paradigm/docs/error-patterns.md +215 -0
  91. package/templates/paradigm/docs/patterns.md +358 -0
  92. package/templates/paradigm/docs/queries.md +200 -0
  93. package/templates/paradigm/docs/troubleshooting.md +477 -0
  94. package/templates/paradigm/echoes.yaml +25 -0
  95. package/templates/paradigm/prompts/add-feature.md +152 -0
  96. package/templates/paradigm/prompts/add-gate.md +117 -0
  97. package/templates/paradigm/prompts/debug-auth.md +174 -0
  98. package/templates/paradigm/prompts/implement-ftux.md +722 -0
  99. package/templates/paradigm/prompts/implement-sandbox.md +651 -0
  100. package/templates/paradigm/prompts/read-docs.md +84 -0
  101. package/templates/paradigm/prompts/refactor.md +106 -0
  102. package/templates/paradigm/prompts/run-e2e-tests.md +340 -0
  103. package/templates/paradigm/prompts/trace-flow.md +202 -0
  104. package/templates/paradigm/prompts/validate-portals.md +279 -0
  105. package/templates/paradigm/specs/context-tracking.md +200 -0
  106. package/templates/paradigm/specs/context.md +461 -0
  107. package/templates/paradigm/specs/disciplines.md +413 -0
  108. package/templates/paradigm/specs/history.md +339 -0
  109. package/templates/paradigm/specs/logger.md +303 -0
  110. package/templates/paradigm/specs/navigator.md +236 -0
  111. package/templates/paradigm/specs/purpose.md +265 -0
  112. package/templates/paradigm/specs/scan.md +177 -0
  113. package/templates/paradigm/specs/symbols.md +451 -0
  114. package/templates/paradigm/specs/wisdom.md +294 -0
@@ -0,0 +1,705 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ extractAspects,
4
+ extractComponents,
5
+ extractFeatures,
6
+ extractFlows,
7
+ extractGates,
8
+ extractSignals,
9
+ extractStates,
10
+ extractSymbolReferences,
11
+ getAllPurposeFiles
12
+ } from "./chunk-PW2EXJQT.js";
13
+ import {
14
+ findGateFiles,
15
+ parseGateConfig
16
+ } from "./chunk-IRKUEJVW.js";
17
+
18
+ // ../premise/core/dist/index.js
19
+ import * as fs from "fs";
20
+ import * as yaml from "js-yaml";
21
+ import { z } from "zod";
22
+ import * as path from "path";
23
+ var SYMBOL_PREFIXES = {
24
+ component: "#",
25
+ flow: "$",
26
+ gate: "^",
27
+ signal: "!",
28
+ aspect: "~"
29
+ };
30
+ var PREFIX_TO_TYPE = {
31
+ "#": "component",
32
+ "$": "flow",
33
+ "^": "gate",
34
+ "!": "signal",
35
+ "~": "aspect"
36
+ };
37
+ var VALID_PREFIXES = ["#", "$", "^", "!", "~"];
38
+ function isValidPrefix(prefix) {
39
+ return VALID_PREFIXES.includes(prefix);
40
+ }
41
+ var PositionSchema = z.object({
42
+ x: z.number(),
43
+ y: z.number()
44
+ });
45
+ var ViewportSchema = z.object({
46
+ x: z.number(),
47
+ y: z.number(),
48
+ zoom: z.number()
49
+ });
50
+ var PremiseSourceConfigSchema = z.object({
51
+ path: z.string(),
52
+ include: z.array(z.string()).optional(),
53
+ exclude: z.array(z.string()).optional()
54
+ });
55
+ var PremiseNodeSchema = z.object({
56
+ id: z.string(),
57
+ symbol: z.string(),
58
+ type: z.enum(["feature", "component", "flow", "state", "aspect", "gate", "signal", "idea"]),
59
+ content: z.string().optional(),
60
+ position: PositionSchema,
61
+ tags: z.array(z.string()).optional(),
62
+ created: z.string(),
63
+ modified: z.string().optional()
64
+ });
65
+ var PremiseConnectionSchema = z.object({
66
+ from: z.string(),
67
+ to: z.string(),
68
+ label: z.string().optional(),
69
+ type: z.string().optional()
70
+ });
71
+ var PremiseGroupSchema = z.object({
72
+ id: z.string(),
73
+ name: z.string(),
74
+ nodes: z.array(z.string()),
75
+ color: z.string().optional()
76
+ });
77
+ var PremiseLayoutSchema = z.object({
78
+ viewport: ViewportSchema,
79
+ groups: z.array(PremiseGroupSchema).optional()
80
+ });
81
+ var PremiseSnapshotStateSchema = z.object({
82
+ nodes: z.array(PremiseNodeSchema),
83
+ connections: z.array(PremiseConnectionSchema),
84
+ layout: PremiseLayoutSchema
85
+ });
86
+ var PremiseSnapshotSchema = z.object({
87
+ id: z.string(),
88
+ name: z.string(),
89
+ timestamp: z.string(),
90
+ description: z.string().optional(),
91
+ state: PremiseSnapshotStateSchema
92
+ });
93
+ var PremiseFileSchema = z.object({
94
+ version: z.string(),
95
+ metadata: z.object({
96
+ name: z.string(),
97
+ created: z.string(),
98
+ modified: z.string()
99
+ }),
100
+ sources: z.object({
101
+ purpose: z.array(PremiseSourceConfigSchema).optional(),
102
+ portal: z.array(PremiseSourceConfigSchema).optional()
103
+ }),
104
+ nodes: z.array(PremiseNodeSchema),
105
+ connections: z.array(PremiseConnectionSchema),
106
+ layout: PremiseLayoutSchema,
107
+ snapshots: z.array(PremiseSnapshotSchema).optional()
108
+ });
109
+ function parsePremiseFile(filePath) {
110
+ const errors = [];
111
+ let rawContent;
112
+ try {
113
+ rawContent = fs.readFileSync(filePath, "utf8");
114
+ } catch (e) {
115
+ errors.push(`Cannot read file: ${e.message}`);
116
+ return { data: null, errors, rawContent: void 0 };
117
+ }
118
+ return parsePremiseContent(rawContent);
119
+ }
120
+ function parsePremiseContent(content) {
121
+ const errors = [];
122
+ let data = null;
123
+ try {
124
+ data = yaml.load(content);
125
+ } catch (e) {
126
+ const yamlError = e;
127
+ const line = yamlError.mark?.line ? yamlError.mark.line + 1 : void 0;
128
+ errors.push(`YAML syntax error: ${yamlError.reason || e.message}${line ? ` (line ${line})` : ""}`);
129
+ return { data: null, errors, rawContent: content };
130
+ }
131
+ if (data === null || data === void 0) {
132
+ return {
133
+ data: createEmptyPremiseFile(),
134
+ errors: [],
135
+ rawContent: content
136
+ };
137
+ }
138
+ const parseResult = PremiseFileSchema.safeParse(data);
139
+ if (!parseResult.success) {
140
+ for (const issue of parseResult.error.issues) {
141
+ const path2 = issue.path.join(".");
142
+ errors.push(`Schema error at ${path2 || "/"}: ${issue.message}`);
143
+ }
144
+ return { data, errors, rawContent: content };
145
+ }
146
+ return { data: parseResult.data, errors: [], rawContent: content };
147
+ }
148
+ function createEmptyPremiseFile(name = "Untitled") {
149
+ const now = (/* @__PURE__ */ new Date()).toISOString();
150
+ return {
151
+ version: "1.0.0",
152
+ metadata: {
153
+ name,
154
+ created: now,
155
+ modified: now
156
+ },
157
+ sources: {
158
+ purpose: [{ path: "./" }],
159
+ portal: [{ path: "./portal.yaml" }]
160
+ },
161
+ nodes: [],
162
+ connections: [],
163
+ layout: {
164
+ viewport: { x: 0, y: 0, zoom: 1 }
165
+ }
166
+ };
167
+ }
168
+ function serializePremiseFile(data) {
169
+ data.metadata.modified = (/* @__PURE__ */ new Date()).toISOString();
170
+ return yaml.dump(data, {
171
+ indent: 2,
172
+ lineWidth: -1,
173
+ noRefs: true,
174
+ sortKeys: false
175
+ });
176
+ }
177
+ function getDefaultPremiseContent(projectName = "My Project") {
178
+ return serializePremiseFile(createEmptyPremiseFile(projectName));
179
+ }
180
+ function addPremiseNode(premiseFile, node) {
181
+ return {
182
+ ...premiseFile,
183
+ nodes: [...premiseFile.nodes, node],
184
+ metadata: {
185
+ ...premiseFile.metadata,
186
+ modified: (/* @__PURE__ */ new Date()).toISOString()
187
+ }
188
+ };
189
+ }
190
+ function updateNodePosition(premiseFile, nodeId, position) {
191
+ return {
192
+ ...premiseFile,
193
+ nodes: premiseFile.nodes.map(
194
+ (n) => n.id === nodeId ? { ...n, position, modified: (/* @__PURE__ */ new Date()).toISOString() } : n
195
+ ),
196
+ metadata: {
197
+ ...premiseFile.metadata,
198
+ modified: (/* @__PURE__ */ new Date()).toISOString()
199
+ }
200
+ };
201
+ }
202
+ function addConnection(premiseFile, connection) {
203
+ const exists = premiseFile.connections.some(
204
+ (c) => c.from === connection.from && c.to === connection.to
205
+ );
206
+ if (exists) return premiseFile;
207
+ return {
208
+ ...premiseFile,
209
+ connections: [...premiseFile.connections, connection],
210
+ metadata: {
211
+ ...premiseFile.metadata,
212
+ modified: (/* @__PURE__ */ new Date()).toISOString()
213
+ }
214
+ };
215
+ }
216
+ function createSnapshot(premiseFile, name, description) {
217
+ const snapshot = {
218
+ id: `snap-${Date.now()}`,
219
+ name,
220
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
221
+ description,
222
+ state: {
223
+ nodes: [...premiseFile.nodes],
224
+ connections: [...premiseFile.connections],
225
+ layout: { ...premiseFile.layout }
226
+ }
227
+ };
228
+ return {
229
+ ...premiseFile,
230
+ snapshots: [...premiseFile.snapshots || [], snapshot],
231
+ metadata: {
232
+ ...premiseFile.metadata,
233
+ modified: (/* @__PURE__ */ new Date()).toISOString()
234
+ }
235
+ };
236
+ }
237
+ async function aggregateFromPremise(premiseFile, rootDir) {
238
+ const symbols = [];
239
+ const errors = [];
240
+ const purposeFiles = [];
241
+ const portalFiles = [];
242
+ if (premiseFile.sources.purpose) {
243
+ for (const source of premiseFile.sources.purpose) {
244
+ const sourcePath = path.resolve(rootDir, source.path);
245
+ try {
246
+ const parsed = await getAllPurposeFiles(sourcePath);
247
+ purposeFiles.push(...parsed.map((p) => p.filePath));
248
+ const features = extractFeatures(parsed);
249
+ for (const [id, { item, filePath }] of features) {
250
+ symbols.push(createSymbolEntry({
251
+ id: `purpose-feature-${id}`,
252
+ symbol: `#${id}`,
253
+ type: "component",
254
+ source: "purpose",
255
+ filePath,
256
+ data: item,
257
+ description: item.description,
258
+ tags: ["feature"]
259
+ }));
260
+ }
261
+ const components = extractComponents(parsed);
262
+ for (const [id, { item, filePath }] of components) {
263
+ symbols.push(createSymbolEntry({
264
+ id: `purpose-component-${id}`,
265
+ symbol: `#${id}`,
266
+ type: "component",
267
+ source: "purpose",
268
+ filePath,
269
+ data: item,
270
+ description: item.description
271
+ }));
272
+ }
273
+ const gates = extractGates(parsed);
274
+ for (const [id, { item, filePath }] of gates) {
275
+ symbols.push(createSymbolEntry({
276
+ id: `purpose-gate-${id}`,
277
+ symbol: `^${id}`,
278
+ type: "gate",
279
+ source: "purpose",
280
+ filePath,
281
+ data: item,
282
+ description: item.description
283
+ }));
284
+ }
285
+ const states = extractStates(parsed);
286
+ for (const [id, { item, filePath }] of states) {
287
+ symbols.push(createSymbolEntry({
288
+ id: `purpose-state-${id}`,
289
+ symbol: `#${id}`,
290
+ type: "component",
291
+ source: "purpose",
292
+ filePath,
293
+ data: item,
294
+ description: item.description,
295
+ tags: ["state"]
296
+ }));
297
+ }
298
+ const flows = extractFlows(parsed);
299
+ for (const [id, { item, filePath }] of flows) {
300
+ symbols.push(createSymbolEntry({
301
+ id: `purpose-flow-${id}`,
302
+ symbol: `$${id}`,
303
+ type: "flow",
304
+ source: "purpose",
305
+ filePath,
306
+ data: item,
307
+ description: item.description
308
+ }));
309
+ }
310
+ const signals = extractSignals(parsed);
311
+ for (const [id, { item, filePath }] of signals) {
312
+ symbols.push(createSymbolEntry({
313
+ id: `purpose-signal-${id}`,
314
+ symbol: `!${id}`,
315
+ type: "signal",
316
+ source: "purpose",
317
+ filePath,
318
+ data: item,
319
+ description: item.description
320
+ }));
321
+ }
322
+ const aspects = extractAspects(parsed);
323
+ for (const [id, { item, filePath }] of aspects) {
324
+ symbols.push(createSymbolEntry({
325
+ id: `purpose-aspect-${id}`,
326
+ symbol: `~${id}`,
327
+ type: "aspect",
328
+ source: "purpose",
329
+ filePath,
330
+ data: item,
331
+ description: item.description,
332
+ anchors: item.anchors?.map((a) => parseAnchorString(a)),
333
+ appliesTo: item["applies-to"]
334
+ }));
335
+ }
336
+ const symbolRefs = extractSymbolReferences(parsed);
337
+ const existingSymbols = new Set(symbols.map((s) => s.symbol));
338
+ for (const ref of symbolRefs) {
339
+ if (!existingSymbols.has(ref.symbol)) {
340
+ existingSymbols.add(ref.symbol);
341
+ symbols.push(createSymbolEntry({
342
+ id: `purpose-ref-${ref.type}-${ref.symbol.slice(1)}`,
343
+ symbol: ref.symbol,
344
+ type: ref.type,
345
+ source: "purpose",
346
+ filePath: ref.filePath,
347
+ data: { referencedFrom: ref.sourceSymbol },
348
+ description: `Referenced from ${ref.sourceSymbol}`
349
+ }));
350
+ }
351
+ }
352
+ } catch (e) {
353
+ errors.push({
354
+ source: "purpose",
355
+ filePath: sourcePath,
356
+ message: e.message
357
+ });
358
+ }
359
+ }
360
+ }
361
+ if (premiseFile.sources.portal) {
362
+ for (const source of premiseFile.sources.portal) {
363
+ const sourcePath = path.resolve(rootDir, source.path);
364
+ try {
365
+ let gateConfig;
366
+ if (sourcePath.endsWith(".yaml") || sourcePath.endsWith(".yml")) {
367
+ gateConfig = await parseGateConfig(sourcePath);
368
+ portalFiles.push(sourcePath);
369
+ } else {
370
+ const files = await findGateFiles(sourcePath);
371
+ portalFiles.push(...files);
372
+ if (files.length > 0) {
373
+ gateConfig = await parseGateConfig(files[0]);
374
+ for (let i = 1; i < files.length; i++) {
375
+ const additional = await parseGateConfig(files[i]);
376
+ gateConfig.gates.push(...additional.gates);
377
+ gateConfig.flows.push(...additional.flows);
378
+ }
379
+ } else {
380
+ continue;
381
+ }
382
+ }
383
+ for (const gate of gateConfig.gates) {
384
+ symbols.push(createGateSymbol(gate, sourcePath));
385
+ for (const prize of gate.prizes) {
386
+ symbols.push(createSymbolEntry({
387
+ id: `gate-signal-${gate.id}-${prize.id}`,
388
+ symbol: `!${prize.id}`,
389
+ type: "signal",
390
+ source: "portal",
391
+ filePath: sourcePath,
392
+ data: prize,
393
+ description: `Signal from gate ${gate.id}`
394
+ }));
395
+ }
396
+ }
397
+ for (const flow of gateConfig.flows) {
398
+ symbols.push(createFlowSymbol(flow, sourcePath));
399
+ }
400
+ } catch (e) {
401
+ errors.push({
402
+ source: "portal",
403
+ filePath: sourcePath,
404
+ message: e.message
405
+ });
406
+ }
407
+ }
408
+ }
409
+ for (const node of premiseFile.nodes) {
410
+ const hasIdeaTag = node.tags?.includes("idea");
411
+ if (!node.content && !hasIdeaTag) {
412
+ const existing = symbols.find((s) => s.symbol === node.symbol);
413
+ if (existing) {
414
+ existing.position = node.position;
415
+ existing.tags = node.tags;
416
+ continue;
417
+ }
418
+ }
419
+ symbols.push(createSymbolEntry({
420
+ id: node.id,
421
+ symbol: node.symbol,
422
+ type: node.type,
423
+ source: "premise",
424
+ filePath: ".premise",
425
+ data: node,
426
+ description: node.content,
427
+ position: node.position,
428
+ tags: node.tags,
429
+ created: node.created,
430
+ modified: node.modified
431
+ }));
432
+ }
433
+ resolveReferences(symbols);
434
+ return {
435
+ symbols,
436
+ purposeFiles,
437
+ portalFiles,
438
+ errors,
439
+ timestamp: Date.now()
440
+ };
441
+ }
442
+ function createSymbolEntry(partial) {
443
+ return {
444
+ ...partial,
445
+ data: partial.data ?? null,
446
+ references: partial.references ?? [],
447
+ referencedBy: partial.referencedBy ?? []
448
+ };
449
+ }
450
+ function createGateSymbol(gate, filePath) {
451
+ return createSymbolEntry({
452
+ id: `gate-${gate.id}`,
453
+ symbol: `^${gate.id}`,
454
+ type: "gate",
455
+ source: "portal",
456
+ filePath,
457
+ data: gate,
458
+ description: gate.description,
459
+ position: gate.position
460
+ });
461
+ }
462
+ function createFlowSymbol(flow, filePath) {
463
+ return createSymbolEntry({
464
+ id: `gate-flow-${flow.id}`,
465
+ symbol: `$${flow.id}`,
466
+ type: "flow",
467
+ source: "portal",
468
+ filePath,
469
+ data: flow,
470
+ description: flow.description
471
+ });
472
+ }
473
+ function parseAnchorString(raw) {
474
+ const colonIndex = raw.lastIndexOf(":");
475
+ if (colonIndex === -1 || colonIndex === raw.length - 1) {
476
+ return { path: raw, lines: 0, raw };
477
+ }
478
+ const afterColon = raw.slice(colonIndex + 1);
479
+ const filePath = raw.slice(0, colonIndex);
480
+ if (!/^[\d,\- ]+$/.test(afterColon)) {
481
+ return { path: raw, lines: 0, raw };
482
+ }
483
+ if (afterColon.includes("-")) {
484
+ const [start, end] = afterColon.split("-").map(Number);
485
+ return { path: filePath, lines: [start, end], raw };
486
+ } else if (afterColon.includes(",")) {
487
+ const lines = afterColon.split(",").map(Number);
488
+ return { path: filePath, lines, raw };
489
+ } else {
490
+ return { path: filePath, lines: Number(afterColon), raw };
491
+ }
492
+ }
493
+ var SYMBOL_BLOCKLIST = /* @__PURE__ */ new Set([
494
+ "$lib",
495
+ "$env",
496
+ "$app",
497
+ "$service-worker",
498
+ "$virtual",
499
+ "$schema",
500
+ "$ref",
501
+ "$id",
502
+ "$type"
503
+ ]);
504
+ function resolveReferences(symbols) {
505
+ const symbolMap = new Map(symbols.map((s) => [s.symbol, s]));
506
+ for (const symbol of symbols) {
507
+ const dataStr = JSON.stringify(symbol.data);
508
+ const refPattern = /(?:\?[@#$%~^!]|[@#$%~^!?])[a-zA-Z][\w-]*/g;
509
+ const matches = (dataStr.match(refPattern) || []).filter((m) => !SYMBOL_BLOCKLIST.has(m));
510
+ for (const match of matches) {
511
+ if (match !== symbol.symbol && symbolMap.has(match)) {
512
+ if (!symbol.references.includes(match)) {
513
+ symbol.references.push(match);
514
+ }
515
+ const target = symbolMap.get(match);
516
+ if (target && !target.referencedBy.includes(symbol.symbol)) {
517
+ target.referencedBy.push(symbol.symbol);
518
+ }
519
+ }
520
+ }
521
+ }
522
+ }
523
+ async function aggregateFromDirectory(rootDir) {
524
+ const premiseFile = {
525
+ version: "1.0.0",
526
+ metadata: {
527
+ name: path.basename(rootDir),
528
+ created: (/* @__PURE__ */ new Date()).toISOString(),
529
+ modified: (/* @__PURE__ */ new Date()).toISOString()
530
+ },
531
+ sources: {
532
+ purpose: [{ path: "./" }],
533
+ portal: [{ path: "./" }]
534
+ },
535
+ nodes: [],
536
+ connections: [],
537
+ layout: {
538
+ viewport: { x: 0, y: 0, zoom: 1 }
539
+ }
540
+ };
541
+ return aggregateFromPremise(premiseFile, rootDir);
542
+ }
543
+ function createSymbolIndex() {
544
+ return {
545
+ entries: /* @__PURE__ */ new Map(),
546
+ byType: /* @__PURE__ */ new Map(),
547
+ bySource: /* @__PURE__ */ new Map(),
548
+ timestamp: 0
549
+ };
550
+ }
551
+ function buildSymbolIndex(result) {
552
+ const index = createSymbolIndex();
553
+ index.timestamp = result.timestamp;
554
+ for (const symbol of result.symbols) {
555
+ index.entries.set(symbol.id, symbol);
556
+ if (!index.byType.has(symbol.type)) {
557
+ index.byType.set(symbol.type, []);
558
+ }
559
+ index.byType.get(symbol.type).push(symbol);
560
+ if (!index.bySource.has(symbol.source)) {
561
+ index.bySource.set(symbol.source, []);
562
+ }
563
+ index.bySource.get(symbol.source).push(symbol);
564
+ }
565
+ return index;
566
+ }
567
+ function getSymbol(index, symbol) {
568
+ for (const entry of index.entries.values()) {
569
+ if (entry.symbol === symbol) {
570
+ return entry;
571
+ }
572
+ }
573
+ return void 0;
574
+ }
575
+ function getSymbolById(index, id) {
576
+ return index.entries.get(id);
577
+ }
578
+ function getSymbolsByType(index, type) {
579
+ return index.byType.get(type) || [];
580
+ }
581
+ function getSymbolsBySource(index, source) {
582
+ return index.bySource.get(source) || [];
583
+ }
584
+ function searchSymbols(index, query) {
585
+ const lowerQuery = query.toLowerCase();
586
+ const results = [];
587
+ for (const entry of index.entries.values()) {
588
+ if (entry.symbol.toLowerCase().includes(lowerQuery)) {
589
+ results.push(entry);
590
+ continue;
591
+ }
592
+ if (entry.description?.toLowerCase().includes(lowerQuery)) {
593
+ results.push(entry);
594
+ continue;
595
+ }
596
+ if (entry.tags?.some((tag) => tag.toLowerCase().includes(lowerQuery))) {
597
+ results.push(entry);
598
+ }
599
+ }
600
+ return results;
601
+ }
602
+ function getReferencesTo(index, symbol) {
603
+ const entry = getSymbol(index, symbol);
604
+ if (!entry) return [];
605
+ return entry.referencedBy.map((ref) => getSymbol(index, ref)).filter((e) => e !== void 0);
606
+ }
607
+ function getReferencesFrom(index, symbol) {
608
+ const entry = getSymbol(index, symbol);
609
+ if (!entry) return [];
610
+ return entry.references.map((ref) => getSymbol(index, ref)).filter((e) => e !== void 0);
611
+ }
612
+ function getSymbolsByTag(index, tag) {
613
+ const results = [];
614
+ for (const entry of index.entries.values()) {
615
+ if (entry.tags?.includes(tag)) {
616
+ results.push(entry);
617
+ }
618
+ }
619
+ return results;
620
+ }
621
+ function getAllTags(index) {
622
+ const tags = /* @__PURE__ */ new Set();
623
+ for (const entry of index.entries.values()) {
624
+ for (const tag of entry.tags || []) {
625
+ tags.add(tag);
626
+ }
627
+ }
628
+ return Array.from(tags).sort();
629
+ }
630
+ function getSymbolCounts(index) {
631
+ const counts = {
632
+ component: 0,
633
+ flow: 0,
634
+ gate: 0,
635
+ signal: 0,
636
+ aspect: 0
637
+ };
638
+ for (const [type, symbols] of index.byType) {
639
+ if (type in counts) {
640
+ counts[type] = symbols.length;
641
+ }
642
+ }
643
+ return counts;
644
+ }
645
+ function getAllSymbols(index) {
646
+ return Array.from(index.entries.values());
647
+ }
648
+ function parseSymbol(symbol) {
649
+ if (symbol.length < 2) return null;
650
+ const prefix = symbol[0];
651
+ const name = symbol.slice(1);
652
+ if (!isValidPrefix(prefix)) {
653
+ return null;
654
+ }
655
+ const type = PREFIX_TO_TYPE[prefix];
656
+ return { type, name };
657
+ }
658
+ function createSymbolString(type, name) {
659
+ return `${SYMBOL_PREFIXES[type]}${name}`;
660
+ }
661
+ function isValidSymbol(symbol) {
662
+ return parseSymbol(symbol) !== null;
663
+ }
664
+ function getAutocompleteSuggestions(index, partial, limit = 10) {
665
+ const lowerPartial = partial.toLowerCase();
666
+ const parsed = parseSymbol(partial);
667
+ if (parsed) {
668
+ const typeSymbols = getSymbolsByType(index, parsed.type);
669
+ return typeSymbols.filter((s) => s.symbol.toLowerCase().includes(lowerPartial)).slice(0, limit);
670
+ }
671
+ return searchSymbols(index, partial).slice(0, limit);
672
+ }
673
+
674
+ export {
675
+ SYMBOL_PREFIXES,
676
+ PREFIX_TO_TYPE,
677
+ parsePremiseFile,
678
+ parsePremiseContent,
679
+ createEmptyPremiseFile,
680
+ serializePremiseFile,
681
+ getDefaultPremiseContent,
682
+ addPremiseNode,
683
+ updateNodePosition,
684
+ addConnection,
685
+ createSnapshot,
686
+ aggregateFromPremise,
687
+ aggregateFromDirectory,
688
+ createSymbolIndex,
689
+ buildSymbolIndex,
690
+ getSymbol,
691
+ getSymbolById,
692
+ getSymbolsByType,
693
+ getSymbolsBySource,
694
+ searchSymbols,
695
+ getReferencesTo,
696
+ getReferencesFrom,
697
+ getSymbolsByTag,
698
+ getAllTags,
699
+ getSymbolCounts,
700
+ getAllSymbols,
701
+ parseSymbol,
702
+ createSymbolString,
703
+ isValidSymbol,
704
+ getAutocompleteSuggestions
705
+ };