wyrm-mcp 7.2.1 → 7.2.2

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 (150) hide show
  1. package/LICENSE +26 -667
  2. package/NOTICE +14 -33
  3. package/dist/activation.js +1 -60
  4. package/dist/agent-daemon.js +4 -281
  5. package/dist/agent-loop.js +7 -332
  6. package/dist/analytics.js +13 -236
  7. package/dist/attribution.js +1 -49
  8. package/dist/audit.js +2 -457
  9. package/dist/auto-capture.js +3 -138
  10. package/dist/auto-orchestrator.js +1 -325
  11. package/dist/autoconfig.js +39 -840
  12. package/dist/buddy-runner.js +1 -109
  13. package/dist/buddy.js +14 -564
  14. package/dist/build-flags.js +1 -17
  15. package/dist/capabilities.js +3 -183
  16. package/dist/capture.js +1 -56
  17. package/dist/causality.js +6 -107
  18. package/dist/cli.js +20 -281
  19. package/dist/cloud/cli.js +5 -541
  20. package/dist/cloud/client.js +1 -221
  21. package/dist/cloud/crypto.js +1 -85
  22. package/dist/cloud/machine-id.js +2 -113
  23. package/dist/cloud/recovery.js +1 -60
  24. package/dist/cloud/sync-engine.js +7 -543
  25. package/dist/cloud-backup.js +5 -579
  26. package/dist/cloud-profile.js +1 -138
  27. package/dist/cloud-sync-entrypoint.js +1 -47
  28. package/dist/cloud-sync.js +2 -309
  29. package/dist/constellation.js +12 -168
  30. package/dist/context-build-budgeted.js +4 -144
  31. package/dist/context-ranking.js +1 -69
  32. package/dist/crypto.js +1 -179
  33. package/dist/daemon-write-endpoint.js +1 -290
  34. package/dist/daemon-writer.js +2 -406
  35. package/dist/database.js +43 -1110
  36. package/dist/deprecations.js +2 -162
  37. package/dist/design.js +13 -141
  38. package/dist/event-replication.js +1 -112
  39. package/dist/events-sse.js +7 -43
  40. package/dist/events.js +6 -238
  41. package/dist/failure-patterns.js +42 -659
  42. package/dist/federation.js +12 -236
  43. package/dist/goals.js +13 -101
  44. package/dist/golden.js +3 -355
  45. package/dist/handlers/agent.js +4 -165
  46. package/dist/handlers/alias-adapters.js +1 -129
  47. package/dist/handlers/aliases.js +1 -171
  48. package/dist/handlers/audit.js +1 -87
  49. package/dist/handlers/boundary.js +1 -221
  50. package/dist/handlers/capture.js +73 -1109
  51. package/dist/handlers/causality.js +7 -114
  52. package/dist/handlers/cloud.js +85 -382
  53. package/dist/handlers/companion.js +28 -459
  54. package/dist/handlers/datalake.js +7 -187
  55. package/dist/handlers/dispatch-context.js +0 -22
  56. package/dist/handlers/entity.js +25 -256
  57. package/dist/handlers/events.js +16 -335
  58. package/dist/handlers/failure.js +13 -340
  59. package/dist/handlers/goals.js +4 -296
  60. package/dist/handlers/intelligence.js +126 -674
  61. package/dist/handlers/invoicing.js +1 -70
  62. package/dist/handlers/mcpclient.js +6 -137
  63. package/dist/handlers/orchestration.js +40 -125
  64. package/dist/handlers/output-schemas.js +1 -24
  65. package/dist/handlers/presence.js +3 -99
  66. package/dist/handlers/project.js +28 -182
  67. package/dist/handlers/prompts.js +6 -157
  68. package/dist/handlers/quest.js +4 -224
  69. package/dist/handlers/recall.js +11 -218
  70. package/dist/handlers/registry.js +1 -167
  71. package/dist/handlers/resources.js +1 -288
  72. package/dist/handlers/review.js +11 -74
  73. package/dist/handlers/run.js +17 -487
  74. package/dist/handlers/search.js +15 -326
  75. package/dist/handlers/session.js +28 -615
  76. package/dist/handlers/share.js +8 -184
  77. package/dist/handlers/shims.js +1 -464
  78. package/dist/handlers/skill.js +67 -449
  79. package/dist/handlers/survivors.js +1 -120
  80. package/dist/handlers/symbols.js +8 -109
  81. package/dist/handlers/syncops.js +4 -302
  82. package/dist/handlers/types.js +1 -27
  83. package/dist/harvest.js +5 -191
  84. package/dist/hours.js +7 -156
  85. package/dist/http-auth.js +3 -321
  86. package/dist/http-fast.js +21 -1137
  87. package/dist/icons.js +1 -47
  88. package/dist/index.js +2 -924
  89. package/dist/indexer.js +4 -145
  90. package/dist/intelligence.js +31 -261
  91. package/dist/internal-dispatch.js +3 -212
  92. package/dist/keyset.js +1 -110
  93. package/dist/knowledge-graph.js +12 -176
  94. package/dist/license.js +2 -441
  95. package/dist/logger.js +2 -199
  96. package/dist/maintenance.js +2 -148
  97. package/dist/mcp-client.js +6 -262
  98. package/dist/memory-artifacts.js +30 -449
  99. package/dist/migrate-prompt.js +2 -124
  100. package/dist/migrations.js +40 -655
  101. package/dist/performance.js +1 -228
  102. package/dist/presence.js +11 -140
  103. package/dist/priority-embed.js +5 -164
  104. package/dist/providers/embedding-provider.js +1 -196
  105. package/dist/readonly-gate.js +1 -29
  106. package/dist/rehydration.js +9 -157
  107. package/dist/reindex.js +1 -88
  108. package/dist/render-target.js +21 -514
  109. package/dist/render.js +4 -280
  110. package/dist/repl-guard.js +1 -173
  111. package/dist/replication-daemon-entrypoint.js +1 -31
  112. package/dist/replication-daemon.js +2 -262
  113. package/dist/resilience.js +1 -591
  114. package/dist/reverse-bridge.js +5 -360
  115. package/dist/security.js +1 -244
  116. package/dist/session-seen.js +3 -51
  117. package/dist/setup.js +1 -260
  118. package/dist/skill-author.js +5 -168
  119. package/dist/spec-kit.js +1 -191
  120. package/dist/sqlite-busy.js +1 -154
  121. package/dist/statusline.js +11 -315
  122. package/dist/sub-agent.js +13 -262
  123. package/dist/summarizer.js +13 -139
  124. package/dist/symbols.js +7 -283
  125. package/dist/sync.js +5 -359
  126. package/dist/tasks-dispatch.js +1 -84
  127. package/dist/tasks.js +1 -282
  128. package/dist/token-budget.js +1 -143
  129. package/dist/tool-analytics.js +7 -129
  130. package/dist/tool-annotations.js +1 -365
  131. package/dist/tool-manifest-v2.json +1 -1
  132. package/dist/tool-manifest.json +1 -1
  133. package/dist/tool-profiles.js +1 -75
  134. package/dist/trace-harvest.js +6 -244
  135. package/dist/types.js +1 -30
  136. package/dist/ui-dashboard.js +41 -50
  137. package/dist/ulid.js +1 -81
  138. package/dist/validate.js +1 -129
  139. package/dist/vault.js +1 -534
  140. package/dist/vectors.js +3 -184
  141. package/dist/version-check.js +4 -136
  142. package/dist/visibility.js +19 -155
  143. package/dist/wyrm-cli.js +98 -2464
  144. package/dist/wyrm-guard.js +14 -424
  145. package/dist/wyrm-loop.js +3 -150
  146. package/dist/wyrm-manifest.json +1 -1
  147. package/dist/wyrm-statusline-daemon.js +1 -11
  148. package/dist/wyrm-statusline.js +4 -56
  149. package/dist/wyrm-ui.js +9 -77
  150. package/package.json +4 -2
@@ -1,139 +1,13 @@
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
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};
package/dist/symbols.js CHANGED
@@ -1,291 +1,15 @@
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 AGPL-3.0-or-later — dual-licensed; commercial terms: ghosts.lk@proton.me. 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(`
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(`
131
2
  INSERT OR IGNORE INTO symbol_index
132
3
  (project_id, file_path, symbol, kind, language, line, signature)
133
4
  VALUES (?, ?, ?, ?, ?, ?, ?)
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(`
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(`
242
8
  SELECT * FROM symbol_index
243
- WHERE ${clauses.join(' AND ')}
9
+ WHERE ${e.join(" AND ")}
244
10
  ORDER BY project_id, file_path, line
245
11
  LIMIT ?
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 = `
12
+ `).all(...t)}callers(s,n){const e=[`%${s}%`];let t=`
255
13
  SELECT * FROM symbol_index
256
14
  WHERE signature LIKE ? AND symbol != ?
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
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};