wyrm-mcp 7.3.2 → 7.3.3

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 (184) hide show
  1. package/README.md +8 -14
  2. package/dist/activation.js +59 -1
  3. package/dist/agent-daemon.js +281 -4
  4. package/dist/agent-loop.js +332 -7
  5. package/dist/analytics.js +236 -13
  6. package/dist/attribution.js +49 -1
  7. package/dist/audit.js +457 -2
  8. package/dist/auto-capture.js +138 -3
  9. package/dist/auto-orchestrator.js +325 -1
  10. package/dist/autoconfig.d.ts +50 -0
  11. package/dist/autoconfig.d.ts.map +1 -1
  12. package/dist/autoconfig.js +1115 -39
  13. package/dist/autoconfig.js.map +1 -1
  14. package/dist/buddy-runner.js +109 -1
  15. package/dist/buddy.js +564 -14
  16. package/dist/build-flags.js +15 -1
  17. package/dist/capabilities.js +183 -3
  18. package/dist/capture.js +56 -1
  19. package/dist/causality.js +148 -8
  20. package/dist/cli.js +281 -20
  21. package/dist/cloud/cli.js +541 -5
  22. package/dist/cloud/client.js +221 -1
  23. package/dist/cloud/crypto.js +85 -1
  24. package/dist/cloud/machine-id.js +113 -2
  25. package/dist/cloud/recovery.js +60 -1
  26. package/dist/cloud/sync-engine.js +543 -7
  27. package/dist/cloud-backup.js +579 -5
  28. package/dist/cloud-profile.js +138 -1
  29. package/dist/cloud-sync-entrypoint.js +47 -1
  30. package/dist/cloud-sync.js +309 -2
  31. package/dist/connectors/bridge-source.d.ts +46 -0
  32. package/dist/connectors/bridge-source.d.ts.map +1 -0
  33. package/dist/connectors/bridge-source.js +77 -0
  34. package/dist/connectors/bridge-source.js.map +1 -0
  35. package/dist/connectors/index.d.ts +24 -0
  36. package/dist/connectors/index.d.ts.map +1 -0
  37. package/dist/connectors/index.js +69 -0
  38. package/dist/connectors/index.js.map +1 -0
  39. package/dist/connectors/ingest.d.ts +16 -0
  40. package/dist/connectors/ingest.d.ts.map +1 -0
  41. package/dist/connectors/ingest.js +116 -0
  42. package/dist/connectors/ingest.js.map +1 -0
  43. package/dist/connectors/types.d.ts +99 -0
  44. package/dist/connectors/types.d.ts.map +1 -0
  45. package/dist/connectors/types.js +17 -0
  46. package/dist/connectors/types.js.map +1 -0
  47. package/dist/constellation.js +168 -12
  48. package/dist/content-signature.js +45 -1
  49. package/dist/context-build-budgeted.js +144 -4
  50. package/dist/context-ranking.js +69 -1
  51. package/dist/crypto.js +179 -1
  52. package/dist/daemon-write-endpoint.js +290 -1
  53. package/dist/daemon-writer.js +406 -2
  54. package/dist/database.js +1278 -53
  55. package/dist/deprecations.js +162 -2
  56. package/dist/design.js +141 -13
  57. package/dist/event-replication.js +112 -1
  58. package/dist/events-sse.js +43 -7
  59. package/dist/events.js +238 -6
  60. package/dist/failure-patterns.d.ts +107 -0
  61. package/dist/failure-patterns.d.ts.map +1 -1
  62. package/dist/failure-patterns.js +924 -43
  63. package/dist/failure-patterns.js.map +1 -1
  64. package/dist/federation.js +236 -12
  65. package/dist/goals.js +101 -13
  66. package/dist/golden.js +355 -3
  67. package/dist/handlers/agent.js +165 -4
  68. package/dist/handlers/alias-adapters.js +129 -1
  69. package/dist/handlers/aliases.js +171 -1
  70. package/dist/handlers/audit.js +87 -1
  71. package/dist/handlers/boundary.js +221 -1
  72. package/dist/handlers/capture.js +1114 -73
  73. package/dist/handlers/causality.js +119 -9
  74. package/dist/handlers/cloud.js +382 -85
  75. package/dist/handlers/companion.js +459 -28
  76. package/dist/handlers/datalake.js +187 -7
  77. package/dist/handlers/dispatch-context.js +22 -0
  78. package/dist/handlers/entity.js +256 -25
  79. package/dist/handlers/events.js +335 -16
  80. package/dist/handlers/failure.d.ts.map +1 -1
  81. package/dist/handlers/failure.js +408 -13
  82. package/dist/handlers/failure.js.map +1 -1
  83. package/dist/handlers/goals.js +296 -4
  84. package/dist/handlers/intelligence.js +681 -126
  85. package/dist/handlers/invoicing.js +70 -1
  86. package/dist/handlers/mcpclient.js +137 -6
  87. package/dist/handlers/orchestration.js +125 -40
  88. package/dist/handlers/output-schemas.js +24 -1
  89. package/dist/handlers/presence.js +99 -3
  90. package/dist/handlers/project.js +182 -28
  91. package/dist/handlers/prompts.js +157 -6
  92. package/dist/handlers/quest.js +224 -4
  93. package/dist/handlers/recall.js +237 -13
  94. package/dist/handlers/registry.js +167 -1
  95. package/dist/handlers/resources.js +288 -1
  96. package/dist/handlers/review.js +74 -11
  97. package/dist/handlers/run.js +498 -16
  98. package/dist/handlers/search.js +338 -15
  99. package/dist/handlers/session.js +643 -31
  100. package/dist/handlers/share.js +184 -8
  101. package/dist/handlers/shims.js +464 -1
  102. package/dist/handlers/skill.js +449 -67
  103. package/dist/handlers/survivors.js +120 -1
  104. package/dist/handlers/symbols.js +109 -8
  105. package/dist/handlers/syncops.js +302 -4
  106. package/dist/handlers/types.js +27 -1
  107. package/dist/harvest.js +191 -5
  108. package/dist/hours.js +156 -7
  109. package/dist/http-auth.js +321 -3
  110. package/dist/http-fast.js +1302 -22
  111. package/dist/icons.js +47 -1
  112. package/dist/importers.js +268 -1
  113. package/dist/index.js +840 -2
  114. package/dist/indexer.js +145 -4
  115. package/dist/intelligence.js +261 -31
  116. package/dist/internal-dispatch.js +212 -3
  117. package/dist/keyset.js +110 -1
  118. package/dist/knowledge-graph.js +176 -12
  119. package/dist/license.js +441 -2
  120. package/dist/logger.js +199 -2
  121. package/dist/maintenance.js +148 -2
  122. package/dist/mcp-client.js +262 -6
  123. package/dist/memory-artifacts.js +596 -32
  124. package/dist/migrate-prompt.js +124 -2
  125. package/dist/migrations.d.ts.map +1 -1
  126. package/dist/migrations.js +799 -42
  127. package/dist/migrations.js.map +1 -1
  128. package/dist/performance.js +228 -1
  129. package/dist/presence.js +140 -11
  130. package/dist/priority-embed.js +164 -5
  131. package/dist/providers/embedding-provider.js +196 -1
  132. package/dist/readonly-gate.js +29 -1
  133. package/dist/receipt.js +43 -1
  134. package/dist/rehydration.js +157 -9
  135. package/dist/reindex.js +88 -1
  136. package/dist/render-target.js +544 -21
  137. package/dist/render.js +280 -4
  138. package/dist/repl-guard.js +173 -1
  139. package/dist/replication-daemon-entrypoint.js +31 -1
  140. package/dist/replication-daemon.js +262 -2
  141. package/dist/rerank.js +142 -1
  142. package/dist/resilience.js +591 -1
  143. package/dist/reverse-bridge.js +360 -5
  144. package/dist/security.js +244 -1
  145. package/dist/session-seen.js +51 -3
  146. package/dist/setup.js +260 -1
  147. package/dist/skill-author.js +168 -5
  148. package/dist/spec-kit.js +191 -1
  149. package/dist/sqlite-busy.js +154 -1
  150. package/dist/statusline.js +315 -11
  151. package/dist/sub-agent.js +262 -13
  152. package/dist/summarizer.js +139 -13
  153. package/dist/symbols.js +283 -7
  154. package/dist/sync.js +359 -5
  155. package/dist/tasks-dispatch.js +84 -1
  156. package/dist/tasks.js +282 -1
  157. package/dist/token-budget.js +143 -1
  158. package/dist/tool-analytics.js +129 -7
  159. package/dist/tool-annotations.js +365 -1
  160. package/dist/tool-manifest-v2.json +1 -1
  161. package/dist/tool-manifest.json +1 -1
  162. package/dist/tool-profiles.js +75 -1
  163. package/dist/trace-harvest.js +244 -6
  164. package/dist/types.js +30 -1
  165. package/dist/ui-dashboard.js +50 -41
  166. package/dist/ulid.js +81 -1
  167. package/dist/usage-tracker.js +66 -1
  168. package/dist/validate.js +129 -1
  169. package/dist/vault.js +534 -1
  170. package/dist/vector-init.js +67 -1
  171. package/dist/vectors.js +184 -3
  172. package/dist/version-check.js +136 -4
  173. package/dist/visibility.js +155 -19
  174. package/dist/wyrm-cli.js +2845 -101
  175. package/dist/wyrm-cli.js.map +1 -1
  176. package/dist/wyrm-guard.d.ts.map +1 -1
  177. package/dist/wyrm-guard.js +475 -14
  178. package/dist/wyrm-guard.js.map +1 -1
  179. package/dist/wyrm-loop.js +150 -3
  180. package/dist/wyrm-manifest.json +1 -1
  181. package/dist/wyrm-statusline-daemon.js +11 -1
  182. package/dist/wyrm-statusline.js +56 -4
  183. package/dist/wyrm-ui.js +77 -9
  184. package/package.json +1 -1
@@ -1,13 +1,139 @@
1
- function p(e){const s=[];if(s.push(`[${e.date}]`),e.objectives){const t=e.objectives.split(`
2
- `)[0].trim();t&&s.push(`Goal: ${t}`)}if(e.completed){const t=g(e.completed);t.length>0&&s.push(`Done: ${t.slice(0,3).join(", ")}`)}if(e.issues){const t=d(e.issues);t.length>0&&s.push(`Fixed: ${t.slice(0,2).join("; ")}`)}if(e.commits){const t=e.commits.match(/[a-f0-9]{7,}/gi);t&&t.length>0&&s.push(`Commits: ${t.slice(0,3).join(", ")}`)}if(e.files_changed){const t=e.files_changed.split(`
3
- `).filter(c=>c.trim());t.length>0&&s.push(`Files: ${t.length} changed`)}const i=s.join(" | "),n=Math.ceil(i.length/4);return{summary:i,tokenEstimate:n}}function $(e){const i=e.map(n=>p(n).summary).join(`
4
- `);return{summary:i,tokenEstimate:Math.ceil(i.length/4)}}function g(e){const s=e.split(`
5
- `),i=[];for(const n of s){const t=n.match(/^[\s]*[-*•\d.]+[\s]+(.+)/);t&&i.push(t[1].trim().slice(0,50))}return i}function d(e){const s=[],i=e.match(/(?:problem|issue|bug|fix(?:ed)?)[:\s]+([^.\n]+)/gi);if(i)for(const n of i.slice(0,3)){const t=n.replace(/^(?:problem|issue|bug|fix(?:ed)?)[:\s]+/i,"").trim();t.length>5&&s.push(t.slice(0,40))}return s}function r(e){return Math.ceil(e.length/4)}function b(e,s,i,n,t=4e3){const c=[];let o=0;const a=`# ${e.name}
6
- Stack: ${e.stack||"Unknown"}`;c.push(a),o+=r(a);const m=s.architecture;m&&o+r(m)<t*.4&&(c.push(`
7
- ## Architecture
8
- ${m}`),o+=r(m));const h=s.credentials;if(h&&o+r(h)<t*.5&&(c.push(`
9
- ## Credentials
10
- ${h}`),o+=r(h)),i.length>0){c.push(`
11
- ## Recent Sessions`);for(const l of i){const u=l.summary||p(l).summary,f=r(u);if(o+f<t*.8)c.push(u),o+=f;else break}}if(n.length>0&&o<t*.9){c.push(`
12
- ## Pending Tasks`);for(const l of n.slice(0,10)){const u=`- [${l.priority}] ${l.title}`;o+r(u)<t&&(c.push(u),o+=r(u))}}return c.join(`
13
- `)}export{b as createContextBundle,r as estimateTokens,$ as summarizeMultipleSessions,p as summarizeSession};
1
+ /**
2
+ * Wyrm Summarizer - Compresses old sessions to save tokens
3
+ *
4
+ * Uses a simple extractive summarization:
5
+ * - Keeps key information (commits, files, major issues)
6
+ * - Drops verbose descriptions
7
+ * - Creates a condensed summary for archived sessions
8
+ */
9
+ export function summarizeSession(session) {
10
+ const parts = [];
11
+ // Date
12
+ parts.push(`[${session.date}]`);
13
+ // Objectives - just first line
14
+ if (session.objectives) {
15
+ const firstLine = session.objectives.split('\n')[0].trim();
16
+ if (firstLine)
17
+ parts.push(`Goal: ${firstLine}`);
18
+ }
19
+ // Completed - extract bullet points
20
+ if (session.completed) {
21
+ const items = extractBulletPoints(session.completed);
22
+ if (items.length > 0) {
23
+ parts.push(`Done: ${items.slice(0, 3).join(', ')}`);
24
+ }
25
+ }
26
+ // Issues - keep key problems
27
+ if (session.issues) {
28
+ const issues = extractKeyIssues(session.issues);
29
+ if (issues.length > 0) {
30
+ parts.push(`Fixed: ${issues.slice(0, 2).join('; ')}`);
31
+ }
32
+ }
33
+ // Commits - always keep
34
+ if (session.commits) {
35
+ const commits = session.commits.match(/[a-f0-9]{7,}/gi);
36
+ if (commits && commits.length > 0) {
37
+ parts.push(`Commits: ${commits.slice(0, 3).join(', ')}`);
38
+ }
39
+ }
40
+ // Files - just count
41
+ if (session.files_changed) {
42
+ const files = session.files_changed.split('\n').filter(f => f.trim());
43
+ if (files.length > 0) {
44
+ parts.push(`Files: ${files.length} changed`);
45
+ }
46
+ }
47
+ const summary = parts.join(' | ');
48
+ const tokenEstimate = Math.ceil(summary.length / 4);
49
+ return { summary, tokenEstimate };
50
+ }
51
+ export function summarizeMultipleSessions(sessions) {
52
+ const summaries = sessions.map(s => summarizeSession(s).summary);
53
+ const combined = summaries.join('\n');
54
+ return {
55
+ summary: combined,
56
+ tokenEstimate: Math.ceil(combined.length / 4)
57
+ };
58
+ }
59
+ function extractBulletPoints(text) {
60
+ const lines = text.split('\n');
61
+ const bullets = [];
62
+ for (const line of lines) {
63
+ const match = line.match(/^[\s]*[-*•\d.]+[\s]+(.+)/);
64
+ if (match) {
65
+ bullets.push(match[1].trim().slice(0, 50));
66
+ }
67
+ }
68
+ return bullets;
69
+ }
70
+ function extractKeyIssues(text) {
71
+ const issues = [];
72
+ // Look for "Problem:" or "Issue:" patterns
73
+ const problemMatch = text.match(/(?:problem|issue|bug|fix(?:ed)?)[:\s]+([^.\n]+)/gi);
74
+ if (problemMatch) {
75
+ for (const match of problemMatch.slice(0, 3)) {
76
+ const clean = match.replace(/^(?:problem|issue|bug|fix(?:ed)?)[:\s]+/i, '').trim();
77
+ if (clean.length > 5)
78
+ issues.push(clean.slice(0, 40));
79
+ }
80
+ }
81
+ return issues;
82
+ }
83
+ /**
84
+ * Estimate tokens in a string (rough approximation)
85
+ */
86
+ export function estimateTokens(text) {
87
+ return Math.ceil(text.length / 4);
88
+ }
89
+ /**
90
+ * Create a compressed context bundle under a token limit
91
+ */
92
+ export function createContextBundle(project, currentContext, recentSessions, pendingQuests, maxTokens = 4000) {
93
+ const parts = [];
94
+ let currentTokens = 0;
95
+ // Project header (always include)
96
+ const header = `# ${project.name}\nStack: ${project.stack || 'Unknown'}`;
97
+ parts.push(header);
98
+ currentTokens += estimateTokens(header);
99
+ // Architecture/key info from context
100
+ const arch = currentContext['architecture'];
101
+ if (arch && currentTokens + estimateTokens(arch) < maxTokens * 0.4) {
102
+ parts.push(`\n## Architecture\n${arch}`);
103
+ currentTokens += estimateTokens(arch);
104
+ }
105
+ // Credentials (if any)
106
+ const creds = currentContext['credentials'];
107
+ if (creds && currentTokens + estimateTokens(creds) < maxTokens * 0.5) {
108
+ parts.push(`\n## Credentials\n${creds}`);
109
+ currentTokens += estimateTokens(creds);
110
+ }
111
+ // Recent sessions (summarized if needed)
112
+ if (recentSessions.length > 0) {
113
+ parts.push('\n## Recent Sessions');
114
+ for (const session of recentSessions) {
115
+ const sessionText = session.summary || summarizeSession(session).summary;
116
+ const tokens = estimateTokens(sessionText);
117
+ if (currentTokens + tokens < maxTokens * 0.8) {
118
+ parts.push(sessionText);
119
+ currentTokens += tokens;
120
+ }
121
+ else {
122
+ break;
123
+ }
124
+ }
125
+ }
126
+ // Pending quests
127
+ if (pendingQuests.length > 0 && currentTokens < maxTokens * 0.9) {
128
+ parts.push('\n## Pending Tasks');
129
+ for (const quest of pendingQuests.slice(0, 10)) {
130
+ const questText = `- [${quest.priority}] ${quest.title}`;
131
+ if (currentTokens + estimateTokens(questText) < maxTokens) {
132
+ parts.push(questText);
133
+ currentTokens += estimateTokens(questText);
134
+ }
135
+ }
136
+ }
137
+ return parts.join('\n');
138
+ }
139
+ //# sourceMappingURL=summarizer.js.map
package/dist/symbols.js CHANGED
@@ -1,15 +1,291 @@
1
- import{readdirSync as T,readFileSync as S,statSync as j}from"fs";import{join as v,extname as E,relative as C,basename as F}from"path";const M=[{language:"ts",extensions:[".ts",".mts",".cts"],patterns:[{kind:"function",re:/^\s*(?:export\s+)?(?:async\s+)?function\s+(\w+)/},{kind:"function",re:/^\s*(?:export\s+)?const\s+(\w+)\s*[:=][^=]*=>/},{kind:"class",re:/^\s*(?:export\s+)?(?:abstract\s+)?class\s+(\w+)/},{kind:"interface",re:/^\s*(?:export\s+)?interface\s+(\w+)/},{kind:"type",re:/^\s*(?:export\s+)?type\s+(\w+)/},{kind:"const",re:/^\s*(?:export\s+)?(?:const|let|var)\s+(\w+)\s*[:=]/}]},{language:"tsx",extensions:[".tsx"],patterns:[{kind:"function",re:/^\s*(?:export\s+)?(?:async\s+)?function\s+(\w+)/},{kind:"function",re:/^\s*(?:export\s+)?const\s+(\w+)\s*[:=][^=]*=>/},{kind:"class",re:/^\s*(?:export\s+)?(?:abstract\s+)?class\s+(\w+)/},{kind:"interface",re:/^\s*(?:export\s+)?interface\s+(\w+)/},{kind:"type",re:/^\s*(?:export\s+)?type\s+(\w+)/}]},{language:"js",extensions:[".js",".mjs",".cjs"],patterns:[{kind:"function",re:/^\s*(?:export\s+)?(?:async\s+)?function\s+(\w+)/},{kind:"function",re:/^\s*(?:export\s+)?const\s+(\w+)\s*=\s*(?:async\s+)?\(/},{kind:"class",re:/^\s*(?:export\s+)?class\s+(\w+)/},{kind:"const",re:/^\s*(?:export\s+)?const\s+(\w+)\s*=/}]},{language:"jsx",extensions:[".jsx"],patterns:[{kind:"function",re:/^\s*(?:export\s+)?(?:async\s+)?function\s+(\w+)/},{kind:"function",re:/^\s*(?:export\s+)?const\s+(\w+)\s*=\s*\(/},{kind:"class",re:/^\s*(?:export\s+)?class\s+(\w+)/}]},{language:"py",extensions:[".py"],patterns:[{kind:"function",re:/^\s*(?:async\s+)?def\s+(\w+)/},{kind:"class",re:/^\s*class\s+(\w+)/}]},{language:"rs",extensions:[".rs"],patterns:[{kind:"function",re:/^\s*(?:pub(?:\([^)]+\))?\s+)?(?:async\s+|unsafe\s+|const\s+)*fn\s+(\w+)/},{kind:"class",re:/^\s*(?:pub(?:\([^)]+\))?\s+)?struct\s+(\w+)/},{kind:"interface",re:/^\s*(?:pub(?:\([^)]+\))?\s+)?trait\s+(\w+)/},{kind:"type",re:/^\s*(?:pub(?:\([^)]+\))?\s+)?(?:type|enum)\s+(\w+)/}]},{language:"go",extensions:[".go"],patterns:[{kind:"function",re:/^func\s+(?:\([^)]+\)\s+)?(\w+)/},{kind:"type",re:/^type\s+(\w+)\s+(?:struct|interface|=)/}]},{language:"php",extensions:[".php"],patterns:[{kind:"function",re:/^\s*(?:public\s+|private\s+|protected\s+|static\s+)*function\s+(\w+)/},{kind:"class",re:/^\s*(?:abstract\s+|final\s+)*class\s+(\w+)/},{kind:"interface",re:/^\s*interface\s+(\w+)/}]},{language:"rb",extensions:[".rb"],patterns:[{kind:"function",re:/^\s*def\s+(?:self\.)?(\w+)/},{kind:"class",re:/^\s*class\s+(\w+)/}]}],b=new Map;for(const a of M)for(const s of a.extensions)b.set(s,a);const m=new Set(["node_modules",".git","dist","build","target","__pycache__",".next",".nuxt","venv",".venv","env",".env","vendor","coverage",".cache",".parcel-cache",".svelte-kit","out"]),I=256*1024;class U{db;constructor(s){this.db=s}indexProject(s,n){let e=0,t=0;const o=this.db.prepare(`
1
+ /**
2
+ * Cross-repo symbol graph.
3
+ *
4
+ * Light-weight regex-based symbol index across all enrolled projects.
5
+ * Not a real LSP — no scope analysis, no type resolution. Just "where is
6
+ * `validateEmail` defined and which files mention it?" workspace-wide.
7
+ *
8
+ * Cursor's workspace-symbols stops at the repo boundary. Wyrm doesn't.
9
+ *
10
+ * Supported languages (regex-based heuristics):
11
+ * - TypeScript / JavaScript (.ts, .tsx, .js, .jsx, .mjs, .cjs)
12
+ * - Python (.py)
13
+ * - Rust (.rs)
14
+ * - Go (.go)
15
+ * - PHP (.php)
16
+ * - Ruby (.rb)
17
+ *
18
+ * @copyright 2026 Ghost Protocol (Pvt) Ltd.
19
+ * @license Proprietary — (c) 2026 Ghost Protocol (Pvt) Ltd. All rights reserved. See LICENSE.
20
+ */
21
+ import { readdirSync, readFileSync, statSync } from 'fs';
22
+ import { join, extname, relative, basename } from 'path';
23
+ const EXTRACTORS = [
24
+ {
25
+ language: 'ts',
26
+ extensions: ['.ts', '.mts', '.cts'],
27
+ patterns: [
28
+ { kind: 'function', re: /^\s*(?:export\s+)?(?:async\s+)?function\s+(\w+)/ },
29
+ { kind: 'function', re: /^\s*(?:export\s+)?const\s+(\w+)\s*[:=][^=]*=>/ },
30
+ { kind: 'class', re: /^\s*(?:export\s+)?(?:abstract\s+)?class\s+(\w+)/ },
31
+ { kind: 'interface', re: /^\s*(?:export\s+)?interface\s+(\w+)/ },
32
+ { kind: 'type', re: /^\s*(?:export\s+)?type\s+(\w+)/ },
33
+ { kind: 'const', re: /^\s*(?:export\s+)?(?:const|let|var)\s+(\w+)\s*[:=]/ },
34
+ ],
35
+ },
36
+ {
37
+ language: 'tsx',
38
+ extensions: ['.tsx'],
39
+ patterns: [
40
+ { kind: 'function', re: /^\s*(?:export\s+)?(?:async\s+)?function\s+(\w+)/ },
41
+ { kind: 'function', re: /^\s*(?:export\s+)?const\s+(\w+)\s*[:=][^=]*=>/ },
42
+ { kind: 'class', re: /^\s*(?:export\s+)?(?:abstract\s+)?class\s+(\w+)/ },
43
+ { kind: 'interface', re: /^\s*(?:export\s+)?interface\s+(\w+)/ },
44
+ { kind: 'type', re: /^\s*(?:export\s+)?type\s+(\w+)/ },
45
+ ],
46
+ },
47
+ {
48
+ language: 'js',
49
+ extensions: ['.js', '.mjs', '.cjs'],
50
+ patterns: [
51
+ { kind: 'function', re: /^\s*(?:export\s+)?(?:async\s+)?function\s+(\w+)/ },
52
+ { kind: 'function', re: /^\s*(?:export\s+)?const\s+(\w+)\s*=\s*(?:async\s+)?\(/ },
53
+ { kind: 'class', re: /^\s*(?:export\s+)?class\s+(\w+)/ },
54
+ { kind: 'const', re: /^\s*(?:export\s+)?const\s+(\w+)\s*=/ },
55
+ ],
56
+ },
57
+ {
58
+ language: 'jsx',
59
+ extensions: ['.jsx'],
60
+ patterns: [
61
+ { kind: 'function', re: /^\s*(?:export\s+)?(?:async\s+)?function\s+(\w+)/ },
62
+ { kind: 'function', re: /^\s*(?:export\s+)?const\s+(\w+)\s*=\s*\(/ },
63
+ { kind: 'class', re: /^\s*(?:export\s+)?class\s+(\w+)/ },
64
+ ],
65
+ },
66
+ {
67
+ language: 'py',
68
+ extensions: ['.py'],
69
+ patterns: [
70
+ { kind: 'function', re: /^\s*(?:async\s+)?def\s+(\w+)/ },
71
+ { kind: 'class', re: /^\s*class\s+(\w+)/ },
72
+ ],
73
+ },
74
+ {
75
+ language: 'rs',
76
+ extensions: ['.rs'],
77
+ patterns: [
78
+ { kind: 'function', re: /^\s*(?:pub(?:\([^)]+\))?\s+)?(?:async\s+|unsafe\s+|const\s+)*fn\s+(\w+)/ },
79
+ { kind: 'class', re: /^\s*(?:pub(?:\([^)]+\))?\s+)?struct\s+(\w+)/ },
80
+ { kind: 'interface', re: /^\s*(?:pub(?:\([^)]+\))?\s+)?trait\s+(\w+)/ },
81
+ { kind: 'type', re: /^\s*(?:pub(?:\([^)]+\))?\s+)?(?:type|enum)\s+(\w+)/ },
82
+ ],
83
+ },
84
+ {
85
+ language: 'go',
86
+ extensions: ['.go'],
87
+ patterns: [
88
+ { kind: 'function', re: /^func\s+(?:\([^)]+\)\s+)?(\w+)/ },
89
+ { kind: 'type', re: /^type\s+(\w+)\s+(?:struct|interface|=)/ },
90
+ ],
91
+ },
92
+ {
93
+ language: 'php',
94
+ extensions: ['.php'],
95
+ patterns: [
96
+ { kind: 'function', re: /^\s*(?:public\s+|private\s+|protected\s+|static\s+)*function\s+(\w+)/ },
97
+ { kind: 'class', re: /^\s*(?:abstract\s+|final\s+)*class\s+(\w+)/ },
98
+ { kind: 'interface', re: /^\s*interface\s+(\w+)/ },
99
+ ],
100
+ },
101
+ {
102
+ language: 'rb',
103
+ extensions: ['.rb'],
104
+ patterns: [
105
+ { kind: 'function', re: /^\s*def\s+(?:self\.)?(\w+)/ },
106
+ { kind: 'class', re: /^\s*class\s+(\w+)/ },
107
+ ],
108
+ },
109
+ ];
110
+ const EXT_LOOKUP = new Map();
111
+ for (const e of EXTRACTORS) {
112
+ for (const ext of e.extensions)
113
+ EXT_LOOKUP.set(ext, e);
114
+ }
115
+ const SKIP_DIRS = new Set([
116
+ 'node_modules', '.git', 'dist', 'build', 'target', '__pycache__',
117
+ '.next', '.nuxt', 'venv', '.venv', 'env', '.env', 'vendor',
118
+ 'coverage', '.cache', '.parcel-cache', '.svelte-kit', 'out',
119
+ ]);
120
+ const MAX_FILE_SIZE = 256 * 1024; // 256 KB - skip generated/minified files
121
+ export class SymbolGraph {
122
+ db;
123
+ constructor(db) {
124
+ this.db = db;
125
+ }
126
+ /** Walk a project directory, extract symbols, store in DB. Returns counts. */
127
+ indexProject(projectId, rootPath) {
128
+ let fileCount = 0;
129
+ let symbolCount = 0;
130
+ const insert = this.db.prepare(`
2
131
  INSERT OR IGNORE INTO symbol_index
3
132
  (project_id, file_path, symbol, kind, language, line, signature)
4
133
  VALUES (?, ?, ?, ?, ?, ?, ?)
5
- `);this.db.prepare("DELETE FROM symbol_index WHERE project_id = ?").run(s);const u=this.db.transaction(p=>{for(const i of p)o.run(s,i.file,i.symbol,i.kind,i.lang,i.line,i.signature),t++}),r=p=>{let i;try{i=T(p)}catch{return}for(const c of i){if(c.startsWith(".")&&m.has(c)||m.has(c))continue;const d=v(p,c);let f;try{f=j(d)}catch{continue}if(f.isDirectory()){r(d);continue}if(!f.isFile()||f.size>I)continue;const _=E(c).toLowerCase(),x=b.get(_);if(!x)continue;let l;try{l=S(d,"utf-8")}catch{continue}if(l.length>0&&l.length/(l.split(`
6
- `).length||1)>500)continue;e++;const R=C(n,d),h=[],w=l.split(`
7
- `);for(let g=0;g<w.length;g++){const y=w[g];if(!(y.length>500))for(const{kind:O,re:L}of x.patterns){const k=L.exec(y);if(k&&k[1]){h.push({file:R,symbol:k[1],kind:O,lang:x.language,line:g+1,signature:y.trim().slice(0,300)});break}}}h.length>0&&u(h)}};return r(n),{files:e,symbols:t}}search(s,n){const e=[],t=[];return n?.exact?(e.push("symbol = ?"),t.push(s)):(e.push("symbol LIKE ?"),t.push(`%${s}%`)),n?.projectId!=null&&(e.push("project_id = ?"),t.push(n.projectId)),n?.kind&&(e.push("kind = ?"),t.push(n.kind)),n?.language&&(e.push("language = ?"),t.push(n.language)),t.push(n?.limit??50),this.db.prepare(`
134
+ `);
135
+ // Clear stale rows for this project before re-indexing.
136
+ this.db.prepare('DELETE FROM symbol_index WHERE project_id = ?').run(projectId);
137
+ const insertMany = this.db.transaction((rows) => {
138
+ for (const r of rows) {
139
+ insert.run(projectId, r.file, r.symbol, r.kind, r.lang, r.line, r.signature);
140
+ symbolCount++;
141
+ }
142
+ });
143
+ const walk = (dir) => {
144
+ let entries;
145
+ try {
146
+ entries = readdirSync(dir);
147
+ }
148
+ catch {
149
+ return;
150
+ }
151
+ for (const name of entries) {
152
+ if (name.startsWith('.') && SKIP_DIRS.has(name))
153
+ continue;
154
+ if (SKIP_DIRS.has(name))
155
+ continue;
156
+ const full = join(dir, name);
157
+ let stat;
158
+ try {
159
+ stat = statSync(full);
160
+ }
161
+ catch {
162
+ continue;
163
+ }
164
+ if (stat.isDirectory()) {
165
+ walk(full);
166
+ continue;
167
+ }
168
+ if (!stat.isFile())
169
+ continue;
170
+ if (stat.size > MAX_FILE_SIZE)
171
+ continue;
172
+ const ext = extname(name).toLowerCase();
173
+ const extractor = EXT_LOOKUP.get(ext);
174
+ if (!extractor)
175
+ continue;
176
+ let content;
177
+ try {
178
+ content = readFileSync(full, 'utf-8');
179
+ }
180
+ catch {
181
+ continue;
182
+ }
183
+ // Skip likely-minified / generated files
184
+ if (content.length > 0 && content.length / (content.split('\n').length || 1) > 500)
185
+ continue;
186
+ fileCount++;
187
+ const relativeFile = relative(rootPath, full);
188
+ const rows = [];
189
+ const lines = content.split('\n');
190
+ for (let i = 0; i < lines.length; i++) {
191
+ const line = lines[i];
192
+ if (line.length > 500)
193
+ continue; // skip overlong lines
194
+ for (const { kind, re } of extractor.patterns) {
195
+ const m = re.exec(line);
196
+ if (m && m[1]) {
197
+ rows.push({
198
+ file: relativeFile,
199
+ symbol: m[1],
200
+ kind,
201
+ lang: extractor.language,
202
+ line: i + 1,
203
+ signature: line.trim().slice(0, 300),
204
+ });
205
+ break; // one symbol per line is enough
206
+ }
207
+ }
208
+ }
209
+ if (rows.length > 0)
210
+ insertMany(rows);
211
+ }
212
+ };
213
+ walk(rootPath);
214
+ return { files: fileCount, symbols: symbolCount };
215
+ }
216
+ /** Workspace-wide symbol lookup. Optionally scope to a project, kind, language. */
217
+ search(symbol, opts) {
218
+ const clauses = [];
219
+ const params = [];
220
+ if (opts?.exact) {
221
+ clauses.push('symbol = ?');
222
+ params.push(symbol);
223
+ }
224
+ else {
225
+ clauses.push('symbol LIKE ?');
226
+ params.push(`%${symbol}%`);
227
+ }
228
+ if (opts?.projectId != null) {
229
+ clauses.push('project_id = ?');
230
+ params.push(opts.projectId);
231
+ }
232
+ if (opts?.kind) {
233
+ clauses.push('kind = ?');
234
+ params.push(opts.kind);
235
+ }
236
+ if (opts?.language) {
237
+ clauses.push('language = ?');
238
+ params.push(opts.language);
239
+ }
240
+ params.push(opts?.limit ?? 50);
241
+ const rows = this.db.prepare(`
8
242
  SELECT * FROM symbol_index
9
- WHERE ${e.join(" AND ")}
243
+ WHERE ${clauses.join(' AND ')}
10
244
  ORDER BY project_id, file_path, line
11
245
  LIMIT ?
12
- `).all(...t)}callers(s,n){const e=[`%${s}%`];let t=`
246
+ `).all(...params);
247
+ return rows;
248
+ }
249
+ /** Best-effort caller graph: which files in the project mention this symbol?
250
+ * Uses ripgrep-style grep over the symbol_index `signature` field (cheap,
251
+ * approximate — for a true caller graph use LSP). */
252
+ callers(symbol, projectId) {
253
+ const params = [`%${symbol}%`];
254
+ let sql = `
13
255
  SELECT * FROM symbol_index
14
256
  WHERE signature LIKE ? AND symbol != ?
15
- `;return e.push(s),n!=null&&(t+=" AND project_id = ?",e.push(n)),t+=" ORDER BY project_id, file_path, line LIMIT 200",this.db.prepare(t).all(...e)}stats(s){const n=s!=null?"WHERE project_id = ?":"",e=s!=null?[s]:[],t=this.db.prepare(`SELECT COUNT(*) as c FROM symbol_index ${n}`).get(...e).c,o={};for(const r of this.db.prepare(`SELECT language, COUNT(*) as c FROM symbol_index ${n} GROUP BY language`).all(...e))o[r.language]=r.c;const u={};for(const r of this.db.prepare(`SELECT kind, COUNT(*) as c FROM symbol_index ${n} GROUP BY kind`).all(...e))u[r.kind]=r.c;return{total:t,by_language:o,by_kind:u}}clear(s){return this.db.prepare("DELETE FROM symbol_index WHERE project_id = ?").run(s).changes}}function A(a){const s=E(F(a)).toLowerCase();return b.get(s)?.language??null}export{U as SymbolGraph,A as languageForFile};
257
+ `;
258
+ params.push(symbol);
259
+ if (projectId != null) {
260
+ sql += ' AND project_id = ?';
261
+ params.push(projectId);
262
+ }
263
+ sql += ' ORDER BY project_id, file_path, line LIMIT 200';
264
+ return this.db.prepare(sql).all(...params);
265
+ }
266
+ /** Total symbol count + per-language breakdown. */
267
+ stats(projectId) {
268
+ const where = projectId != null ? 'WHERE project_id = ?' : '';
269
+ const params = projectId != null ? [projectId] : [];
270
+ const total = this.db.prepare(`SELECT COUNT(*) as c FROM symbol_index ${where}`).get(...params).c;
271
+ const byLang = {};
272
+ for (const r of this.db.prepare(`SELECT language, COUNT(*) as c FROM symbol_index ${where} GROUP BY language`).all(...params)) {
273
+ byLang[r.language] = r.c;
274
+ }
275
+ const byKind = {};
276
+ for (const r of this.db.prepare(`SELECT kind, COUNT(*) as c FROM symbol_index ${where} GROUP BY kind`).all(...params)) {
277
+ byKind[r.kind] = r.c;
278
+ }
279
+ return { total, by_language: byLang, by_kind: byKind };
280
+ }
281
+ /** Wipe all symbols for a project (e.g. before a fresh re-index). */
282
+ clear(projectId) {
283
+ return this.db.prepare('DELETE FROM symbol_index WHERE project_id = ?').run(projectId).changes;
284
+ }
285
+ }
286
+ // Helper exposed for tests / debugging — language detection by extension
287
+ export function languageForFile(file) {
288
+ const ext = extname(basename(file)).toLowerCase();
289
+ return EXT_LOOKUP.get(ext)?.language ?? null;
290
+ }
291
+ //# sourceMappingURL=symbols.js.map