wyrm-mcp 7.2.0 → 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 (156) hide show
  1. package/LICENSE +26 -667
  2. package/NOTICE +14 -33
  3. package/dist/activation.d.ts.map +1 -1
  4. package/dist/activation.js +1 -44
  5. package/dist/activation.js.map +1 -1
  6. package/dist/agent-daemon.js +4 -281
  7. package/dist/agent-loop.js +7 -332
  8. package/dist/analytics.js +13 -236
  9. package/dist/attribution.js +1 -49
  10. package/dist/audit.js +2 -457
  11. package/dist/auto-capture.js +3 -138
  12. package/dist/auto-orchestrator.js +1 -325
  13. package/dist/autoconfig.js +39 -840
  14. package/dist/buddy-runner.js +1 -109
  15. package/dist/buddy.js +14 -564
  16. package/dist/build-flags.js +1 -17
  17. package/dist/capabilities.js +3 -183
  18. package/dist/capture.js +1 -56
  19. package/dist/causality.js +6 -107
  20. package/dist/cli.js +20 -281
  21. package/dist/cloud/cli.js +5 -541
  22. package/dist/cloud/client.js +1 -221
  23. package/dist/cloud/crypto.js +1 -85
  24. package/dist/cloud/machine-id.js +2 -113
  25. package/dist/cloud/recovery.js +1 -60
  26. package/dist/cloud/sync-engine.js +7 -543
  27. package/dist/cloud-backup.js +5 -579
  28. package/dist/cloud-profile.js +1 -138
  29. package/dist/cloud-sync-entrypoint.js +1 -47
  30. package/dist/cloud-sync.js +2 -309
  31. package/dist/constellation.js +12 -168
  32. package/dist/context-build-budgeted.js +4 -144
  33. package/dist/context-ranking.js +1 -69
  34. package/dist/crypto.js +1 -179
  35. package/dist/daemon-write-endpoint.js +1 -290
  36. package/dist/daemon-writer.js +2 -406
  37. package/dist/database.js +43 -1110
  38. package/dist/deprecations.js +2 -162
  39. package/dist/design.js +13 -141
  40. package/dist/event-replication.js +1 -112
  41. package/dist/events-sse.js +7 -43
  42. package/dist/events.js +6 -238
  43. package/dist/failure-patterns.js +42 -659
  44. package/dist/federation.js +12 -236
  45. package/dist/goals.js +13 -101
  46. package/dist/golden.js +3 -355
  47. package/dist/handlers/agent.js +4 -165
  48. package/dist/handlers/alias-adapters.js +1 -129
  49. package/dist/handlers/aliases.js +1 -171
  50. package/dist/handlers/audit.js +1 -87
  51. package/dist/handlers/boundary.js +1 -221
  52. package/dist/handlers/capture.js +73 -1109
  53. package/dist/handlers/causality.js +7 -114
  54. package/dist/handlers/cloud.js +85 -382
  55. package/dist/handlers/companion.js +28 -459
  56. package/dist/handlers/datalake.js +7 -187
  57. package/dist/handlers/dispatch-context.js +0 -22
  58. package/dist/handlers/entity.js +25 -256
  59. package/dist/handlers/events.js +16 -335
  60. package/dist/handlers/failure.js +13 -340
  61. package/dist/handlers/goals.js +4 -296
  62. package/dist/handlers/intelligence.js +126 -674
  63. package/dist/handlers/invoicing.js +1 -70
  64. package/dist/handlers/mcpclient.js +6 -137
  65. package/dist/handlers/orchestration.js +40 -125
  66. package/dist/handlers/output-schemas.js +1 -24
  67. package/dist/handlers/presence.js +3 -99
  68. package/dist/handlers/project.js +28 -182
  69. package/dist/handlers/prompts.js +6 -157
  70. package/dist/handlers/quest.js +4 -224
  71. package/dist/handlers/recall.js +11 -218
  72. package/dist/handlers/registry.js +1 -167
  73. package/dist/handlers/resources.js +1 -288
  74. package/dist/handlers/review.js +11 -74
  75. package/dist/handlers/run.js +17 -487
  76. package/dist/handlers/search.js +15 -326
  77. package/dist/handlers/session.js +28 -615
  78. package/dist/handlers/share.js +8 -184
  79. package/dist/handlers/shims.js +1 -464
  80. package/dist/handlers/skill.js +67 -449
  81. package/dist/handlers/survivors.js +1 -120
  82. package/dist/handlers/symbols.js +8 -109
  83. package/dist/handlers/syncops.js +4 -302
  84. package/dist/handlers/types.js +1 -27
  85. package/dist/harvest.js +5 -191
  86. package/dist/hours.js +7 -156
  87. package/dist/http-auth.js +3 -321
  88. package/dist/http-fast.js +21 -1137
  89. package/dist/icons.js +1 -47
  90. package/dist/index.js +2 -924
  91. package/dist/indexer.js +4 -145
  92. package/dist/intelligence.js +31 -261
  93. package/dist/internal-dispatch.js +3 -212
  94. package/dist/keyset.js +1 -110
  95. package/dist/knowledge-graph.js +12 -176
  96. package/dist/license.d.ts +11 -0
  97. package/dist/license.d.ts.map +1 -1
  98. package/dist/license.js +2 -414
  99. package/dist/license.js.map +1 -1
  100. package/dist/logger.js +2 -199
  101. package/dist/maintenance.js +2 -148
  102. package/dist/mcp-client.js +6 -262
  103. package/dist/memory-artifacts.js +30 -449
  104. package/dist/migrate-prompt.js +2 -124
  105. package/dist/migrations.js +40 -655
  106. package/dist/performance.js +1 -228
  107. package/dist/presence.js +11 -140
  108. package/dist/priority-embed.js +5 -164
  109. package/dist/providers/embedding-provider.js +1 -196
  110. package/dist/readonly-gate.js +1 -29
  111. package/dist/rehydration.js +9 -157
  112. package/dist/reindex.js +1 -88
  113. package/dist/render-target.js +21 -514
  114. package/dist/render.js +4 -280
  115. package/dist/repl-guard.js +1 -173
  116. package/dist/replication-daemon-entrypoint.js +1 -31
  117. package/dist/replication-daemon.js +2 -262
  118. package/dist/resilience.js +1 -591
  119. package/dist/reverse-bridge.js +5 -360
  120. package/dist/security.js +1 -244
  121. package/dist/session-seen.js +3 -51
  122. package/dist/setup.js +1 -260
  123. package/dist/skill-author.js +5 -168
  124. package/dist/spec-kit.js +1 -191
  125. package/dist/sqlite-busy.js +1 -154
  126. package/dist/statusline.js +11 -315
  127. package/dist/sub-agent.js +13 -262
  128. package/dist/summarizer.js +13 -139
  129. package/dist/symbols.js +7 -283
  130. package/dist/sync.js +5 -359
  131. package/dist/tasks-dispatch.js +1 -84
  132. package/dist/tasks.js +1 -282
  133. package/dist/token-budget.js +1 -143
  134. package/dist/tool-analytics.js +7 -129
  135. package/dist/tool-annotations.js +1 -365
  136. package/dist/tool-manifest-v2.json +1 -1
  137. package/dist/tool-manifest.json +1 -1
  138. package/dist/tool-profiles.js +1 -75
  139. package/dist/trace-harvest.js +6 -244
  140. package/dist/types.js +1 -30
  141. package/dist/ui-dashboard.js +41 -50
  142. package/dist/ulid.js +1 -81
  143. package/dist/validate.js +1 -129
  144. package/dist/vault.js +1 -534
  145. package/dist/vectors.js +3 -184
  146. package/dist/version-check.js +4 -136
  147. package/dist/visibility.js +19 -155
  148. package/dist/wyrm-cli.js +98 -2451
  149. package/dist/wyrm-cli.js.map +1 -1
  150. package/dist/wyrm-guard.js +14 -424
  151. package/dist/wyrm-loop.js +3 -150
  152. package/dist/wyrm-manifest.json +1 -1
  153. package/dist/wyrm-statusline-daemon.js +1 -11
  154. package/dist/wyrm-statusline.js +4 -56
  155. package/dist/wyrm-ui.js +9 -77
  156. package/package.json +4 -2
@@ -1,326 +1,15 @@
1
- /**
2
- * Search domain — ToolSpec contract v2 (v7 F3 T026, hot-path extraction).
3
- *
4
- * wyrm_search (FTS vector RRF fusion across sessions/quests/data + skills
5
- * + entities) and wyrm_constellation (the cross-project scoped mode the
6
- * search survivor absorbs per the task routing), moved VERBATIM from the
7
- * index.ts dispatch switch + buildAllTools(). The constellation alias keeps
8
- * routing here through the spine (identity route → this registry entry —
9
- * same handler code path, never a reimplementation).
10
- *
11
- * T019 renderer: the fused section list is the canonical structured body;
12
- * the 6.x markdown derives from it (ASCII default — ✅/❌ skill markers
13
- * became [active]/[inactive], spec §6 reformat).
14
- *
15
- * @copyright 2026 Ghost Protocol (Pvt) Ltd.
16
- * @license AGPL-3.0-or-later — dual-licensed; commercial terms: ghosts.lk@proton.me. See LICENSE.
17
- */
18
- import { TOOL_ANNOTATIONS } from '../tool-annotations.js';
19
- import { renderResult, withGlyph, cacheKeyFor } from '../render.js';
20
- import { sanitizeFtsQuery } from '../security.js';
21
- import { constellationQuery } from '../constellation.js';
22
- export const searchToolSpecs = [
23
- {
24
- name: "wyrm_search",
25
- description: "Use to find anything by keyword or meaning across all projects - find past sessions that mention a topic, look up everything we have about a service, or ask have I solved this problem before in any other project (cross-project constellation). FTS/vector/hybrid; where a function or symbol is defined across repos lives here too (wyrm_symbol_search).",
26
- inputSchema: {
27
- type: "object",
28
- properties: {
29
- // v7 F3 (T026): property prose compressed to fund the hot-path
30
- // outputSchemas under the 8K default-surface pin (T022/T025 trade).
31
- query: { type: "string" },
32
- type: { type: "string", enum: ["all", "sessions", "quests", "data", "entities"] },
33
- mode: { type: "string", enum: ["lexical", "semantic", "hybrid"], description: "Default hybrid, else lexical" },
34
- projectPath: { type: "string", description: "Limit to one project" },
35
- },
36
- required: ["query"],
37
- },
38
- outputSchema: {
39
- type: "object",
40
- properties: {
41
- query: { type: "string" },
42
- mode: { type: "string", enum: ["lexical", "semantic", "hybrid"] },
43
- sections: {
44
- type: "array",
45
- items: {
46
- type: "object",
47
- properties: {
48
- label: { type: "string" },
49
- count: { type: "integer" },
50
- items: { type: "array", items: { type: "string" } },
51
- },
52
- required: ["label", "count", "items"],
53
- },
54
- },
55
- skills: { type: "array" },
56
- entities: { type: "array" },
57
- },
58
- required: ["query", "mode", "sections", "skills", "entities"],
59
- },
60
- annotations: TOOL_ANNOTATIONS.wyrm_search,
61
- aliases: [],
62
- handler: async (args, { store, graph, vectors, cache, decrypt }) => {
63
- const { query, type, mode, projectPath } = args;
64
- const vectorStore = vectors();
65
- const sanitizedQuery = sanitizeFtsQuery(query);
66
- const project = projectPath ? store.getProject(projectPath) : undefined;
67
- const projectId = project?.id;
68
- const searchType = type || 'all';
69
- const searchMode = mode || (vectorStore ? 'hybrid' : 'lexical');
70
- const ftsResultsByType = {};
71
- if (searchType === 'all' || searchType === 'sessions') {
72
- if (searchMode !== 'semantic') {
73
- const sessions = store.searchSessions(sanitizedQuery, projectId);
74
- ftsResultsByType['session'] = sessions.map((s, i) => ({
75
- id: s.id,
76
- snippet: `${s.date}: ${(s.objectives || s.completed || 'No info').slice(0, 80)}`,
77
- rank: i + 1,
78
- }));
79
- }
80
- }
81
- if (searchType === 'all' || searchType === 'quests') {
82
- if (searchMode !== 'semantic') {
83
- const quests = store.searchQuests(sanitizedQuery);
84
- ftsResultsByType['quest'] = quests.map((q, i) => ({
85
- id: q.id,
86
- snippet: `#${q.id}: ${q.title}`,
87
- rank: i + 1,
88
- }));
89
- }
90
- }
91
- if (searchType === 'all' || searchType === 'data') {
92
- if (searchMode !== 'semantic') {
93
- const data = store.searchData(sanitizedQuery, projectId);
94
- ftsResultsByType['note'] = data.map((d, i) => ({
95
- id: d.id,
96
- snippet: `${d.category}/${d.key}: ${decrypt(d.value).slice(0, 60)}`,
97
- rank: i + 1,
98
- }));
99
- }
100
- }
101
- let vectorResults = [];
102
- if (vectorStore && searchMode !== 'lexical' && (searchType === 'all' || searchType === 'data' || searchType === 'sessions' || searchType === 'quests')) {
103
- try {
104
- vectorResults = await vectorStore.search(query, 20, projectId);
105
- }
106
- catch {
107
- // Vector search failed gracefully — continue with FTS
108
- }
109
- }
110
- // ── Reciprocal Rank Fusion (RRF) ──────────────────────────────────────
111
- // Score formula: Σ 1/(k + rank) where k=60
112
- const RRF_K = 60;
113
- const rrfScores = new Map();
114
- const addFtsToRrf = (contentType, results) => {
115
- results.forEach((r, idx) => {
116
- const key = `${contentType}:${r.id}`;
117
- const existing = rrfScores.get(key);
118
- const score = 1 / (RRF_K + (idx + 1));
119
- if (existing) {
120
- existing.score += score;
121
- }
122
- else {
123
- rrfScores.set(key, { score, snippet: r.snippet, type: contentType, id: r.id });
124
- }
125
- });
126
- };
127
- for (const [contentType, results] of Object.entries(ftsResultsByType)) {
128
- addFtsToRrf(contentType, results);
129
- }
130
- // Add vector results to RRF (sorted by similarity desc → rank 1=most similar)
131
- const vecByType = {};
132
- for (const vr of vectorResults) {
133
- if (!vecByType[vr.content_type])
134
- vecByType[vr.content_type] = [];
135
- vecByType[vr.content_type].push(vr);
136
- }
137
- for (const [contentType, results] of Object.entries(vecByType)) {
138
- results.forEach((vr, idx) => {
139
- const key = `${contentType}:${vr.content_id}`;
140
- const existing = rrfScores.get(key);
141
- const score = 1 / (RRF_K + (idx + 1));
142
- if (existing) {
143
- existing.score += score;
144
- existing.snippet += ` (semantic: ${(vr.similarity * 100).toFixed(0)}%)`;
145
- }
146
- else {
147
- rrfScores.set(key, { score, snippet: `${contentType} #${vr.content_id} (semantic: ${(vr.similarity * 100).toFixed(0)}%)`, type: contentType, id: vr.content_id });
148
- }
149
- });
150
- }
151
- // Sort by RRF score, group fused results by content type
152
- const fused = Array.from(rrfScores.values()).sort((a, b) => b.score - a.score);
153
- const sections = [];
154
- if (fused.length > 0) {
155
- const byType = {};
156
- for (const r of fused) {
157
- if (!byType[r.type])
158
- byType[r.type] = [];
159
- byType[r.type].push(r);
160
- }
161
- for (const [contentType, results] of Object.entries(byType)) {
162
- const label = contentType === 'note' ? 'Data' : contentType.charAt(0).toUpperCase() + contentType.slice(1) + 's';
163
- sections.push({ label, count: results.length, items: results.slice(0, 10).map((r) => r.snippet) });
164
- }
165
- }
166
- // Skills search (FTS only — no vector indexing for skills)
167
- let skills = [];
168
- if (searchType === 'all' || searchType === 'skills') {
169
- skills = store.searchSkills(sanitizedQuery, 10).map((s) => ({
170
- name: s.name,
171
- category: s.category || 'uncategorized',
172
- active: !!s.is_active,
173
- description: s.description,
174
- }));
175
- }
176
- // Entity graph search
177
- let entities = [];
178
- if ((searchType === 'all' || searchType === 'entities') && projectId !== undefined) {
179
- entities = graph.searchEntities(projectId, query, 10).map((e) => ({
180
- name: e.name,
181
- type: e.type,
182
- relationships: graph.getRelationships(e.id, 'both').length,
183
- }));
184
- }
185
- const body = { query, mode: searchMode, sections, skills, entities };
186
- const response = renderResult(body, (b, g) => {
187
- let text = withGlyph(g.brand, `**Search Results for "${b.query}"** _(mode: ${b.mode})_`) + '\n\n';
188
- for (const section of b.sections) {
189
- text += `## ${section.label} (${section.count})\n`;
190
- for (const item of section.items)
191
- text += `${g.bullet} ${item}\n`;
192
- text += '\n';
193
- }
194
- if (b.skills.length > 0) {
195
- text += `## Skills (${b.skills.length})\n`;
196
- for (const s of b.skills) {
197
- text += `${g.bullet} **${s.name}** (${s.category}) [${s.active ? 'active' : 'inactive'}]\n`;
198
- text += ` ${s.description}\n`;
199
- }
200
- text += '\n';
201
- }
202
- if (b.entities.length > 0) {
203
- text += `## Entities (${b.entities.length})\n`;
204
- for (const e of b.entities) {
205
- text += `${g.bullet} **${e.name}** _(${e.type})_ -- ${e.relationships} relationship${e.relationships !== 1 ? 's' : ''}\n`;
206
- }
207
- text += '\n';
208
- }
209
- if (b.sections.length === 0 && b.skills.length === 0 && b.entities.length === 0) {
210
- text += '_No results found._\n';
211
- }
212
- return text;
213
- }, {
214
- // WYRM_CHANNEL=structured summary seam: grouped section/skill/entity
215
- // counts ride structuredContent unchanged; the text channel collapses
216
- // to this header + a count roll-up so the model still sees the shape.
217
- summary: (b, g) => {
218
- const total = b.sections.reduce((n, s) => n + s.count, 0) + b.skills.length + b.entities.length;
219
- return withGlyph(g.brand, `**Search Results for "${b.query}"** _(mode: ${b.mode})_ -- ${total} result${total !== 1 ? 's' : ''}`);
220
- },
221
- });
222
- // READ_ONLY_TOOLS cache publish — dispatcher key convention.
223
- cache.set(cacheKeyFor('wyrm_search', JSON.stringify(args)), response, 20000);
224
- return response;
225
- },
226
- },
227
- {
228
- name: "wyrm_constellation",
229
- description: "Cross-project memory query — search every registered Wyrm project at once for matching truths, artifacts, quests, or design references. Returns candidates grouped by project; the calling AI does semantic ranking on its side. Use this when the operator asks 'have I solved this before?', 'where else have I used X?', or any portfolio-spanning question. Honours per-row cross_project_visibility ('within' = invisible across projects, 'org' = shared, 'public' = anywhere).",
230
- inputSchema: {
231
- type: "object",
232
- properties: {
233
- query: { type: "string", description: "Search keywords. Sanitised; safe FTS5 subset only." },
234
- kinds: { type: "array", items: { type: "string", enum: ["truth", "artifact", "quest", "decision", "reference"] }, description: "Restrict to specific kinds. Default: all kinds." },
235
- visibility: { type: "array", items: { type: "string", enum: ["within", "org", "public"] }, description: "Which visibility levels to include. Default: ['org','public'] — strict cross-project gate." },
236
- per_project_limit: { type: "number", description: "Max hits per project (default 5, max 50)." },
237
- caller_project_path: { type: "string", description: "Caller's current project path — excluded from results unless 'within' is in visibility." },
238
- },
239
- required: ["query"],
240
- },
241
- outputSchema: {
242
- type: "object",
243
- properties: {
244
- query: { type: "string" },
245
- count: { type: "integer" },
246
- projects: {
247
- type: "array",
248
- items: {
249
- type: "object",
250
- properties: {
251
- project: { type: "string" },
252
- hits: {
253
- type: "array",
254
- items: {
255
- type: "object",
256
- properties: {
257
- kind: { type: "string" },
258
- id: { type: "integer" },
259
- title: { type: "string" },
260
- visibility: { type: "string" },
261
- snippet: { type: ["string", "null"] },
262
- },
263
- required: ["kind", "id", "title", "visibility", "snippet"],
264
- },
265
- },
266
- },
267
- required: ["project", "hits"],
268
- },
269
- },
270
- },
271
- required: ["query", "count", "projects"],
272
- },
273
- annotations: TOOL_ANNOTATIONS.wyrm_constellation,
274
- aliases: [],
275
- handler: (args, { store, raw }) => {
276
- const { query: cQuery, kinds: cKinds, visibility: cVis, per_project_limit: cPerProjLimit, caller_project_path: cCallerPath, } = args;
277
- let callerProjectId;
278
- if (cCallerPath) {
279
- const proj = store.getProject(cCallerPath);
280
- callerProjectId = proj?.id;
281
- }
282
- const hits = constellationQuery(raw(), {
283
- query: cQuery,
284
- kinds: cKinds,
285
- visibility: cVis,
286
- perProjectLimit: cPerProjLimit,
287
- callerProjectId,
288
- });
289
- // Group by project (the 6.x renderConstellation grouping, now body-side).
290
- const byProject = new Map();
291
- for (const h of hits) {
292
- const arr = byProject.get(h.projectName) ?? [];
293
- arr.push(h);
294
- byProject.set(h.projectName, arr);
295
- }
296
- const body = {
297
- query: cQuery,
298
- count: hits.length,
299
- projects: Array.from(byProject.entries()).map(([project, items]) => ({
300
- project,
301
- hits: items.map((h) => ({
302
- kind: h.kind, id: h.id, title: h.title, visibility: h.visibility, snippet: h.snippet ?? null,
303
- })),
304
- })),
305
- };
306
- return renderResult(body, (b, g) => {
307
- if (b.count === 0) {
308
- return withGlyph(g.brand, `No constellation matches for *${b.query}* across registered projects.`) +
309
- `\n\n_Set \`cross_project_visibility\` to \`'org'\` or \`'public'\` on the items you want surfaced here. Default is \`'within'\` -- within-project only._`;
310
- }
311
- const lines = [withGlyph(g.brand, `**Constellation** -- ${b.count} match(es) for *${b.query}* across ${b.projects.length} project(s)`)];
312
- for (const p of b.projects) {
313
- lines.push('');
314
- lines.push(`### ${p.project}`);
315
- for (const h of p.hits) {
316
- lines.push(`${g.bullet} \`${h.kind}:${h.id}\` **${h.title}** (${h.visibility})`);
317
- if (h.snippet)
318
- lines.push(` ${h.snippet}`);
319
- }
320
- }
321
- return lines.join('\n');
322
- });
323
- },
324
- },
325
- ];
326
- //# sourceMappingURL=search.js.map
1
+ import{TOOL_ANNOTATIONS as I}from"../tool-annotations.js";import{renderResult as A,withGlyph as q,cacheKeyFor as C}from"../render.js";import{sanitizeFtsQuery as Q}from"../security.js";import{constellationQuery as E}from"../constellation.js";const B=[{name:"wyrm_search",description:"Use to find anything by keyword or meaning across all projects - find past sessions that mention a topic, look up everything we have about a service, or ask have I solved this problem before in any other project (cross-project constellation). FTS/vector/hybrid; where a function or symbol is defined across repos lives here too (wyrm_symbol_search).",inputSchema:{type:"object",properties:{query:{type:"string"},type:{type:"string",enum:["all","sessions","quests","data","entities"]},mode:{type:"string",enum:["lexical","semantic","hybrid"],description:"Default hybrid, else lexical"},projectPath:{type:"string",description:"Limit to one project"}},required:["query"]},outputSchema:{type:"object",properties:{query:{type:"string"},mode:{type:"string",enum:["lexical","semantic","hybrid"]},sections:{type:"array",items:{type:"object",properties:{label:{type:"string"},count:{type:"integer"},items:{type:"array",items:{type:"string"}}},required:["label","count","items"]}},skills:{type:"array"},entities:{type:"array"}},required:["query","mode","sections","skills","entities"]},annotations:I.wyrm_search,aliases:[],handler:async(j,{store:l,graph:$,vectors:b,cache:w,decrypt:S})=>{const{query:u,type:_,mode:k,projectPath:m}=j,y=b(),d=Q(u),o=(m?l.getProject(m):void 0)?.id,i=_||"all",p=k||(y?"hybrid":"lexical"),c={};if((i==="all"||i==="sessions")&&p!=="semantic"){const e=l.searchSessions(d,o);c.session=e.map((t,s)=>({id:t.id,snippet:`${t.date}: ${(t.objectives||t.completed||"No info").slice(0,80)}`,rank:s+1}))}if((i==="all"||i==="quests")&&p!=="semantic"){const e=l.searchQuests(d);c.quest=e.map((t,s)=>({id:t.id,snippet:`#${t.id}: ${t.title}`,rank:s+1}))}if((i==="all"||i==="data")&&p!=="semantic"){const e=l.searchData(d,o);c.note=e.map((t,s)=>({id:t.id,snippet:`${t.category}/${t.key}: ${S(t.value).slice(0,60)}`,rank:s+1}))}let x=[];if(y&&p!=="lexical"&&(i==="all"||i==="data"||i==="sessions"||i==="quests"))try{x=await y.search(u,20,o)}catch{}const T=60,f=new Map,D=(e,t)=>{t.forEach((s,r)=>{const a=`${e}:${s.id}`,h=f.get(a),g=1/(T+(r+1));h?h.score+=g:f.set(a,{score:g,snippet:s.snippet,type:e,id:s.id})})};for(const[e,t]of Object.entries(c))D(e,t);const v={};for(const e of x)v[e.content_type]||(v[e.content_type]=[]),v[e.content_type].push(e);for(const[e,t]of Object.entries(v))t.forEach((s,r)=>{const a=`${e}:${s.content_id}`,h=f.get(a),g=1/(T+(r+1));h?(h.score+=g,h.snippet+=` (semantic: ${(s.similarity*100).toFixed(0)}%)`):f.set(a,{score:g,snippet:`${e} #${s.content_id} (semantic: ${(s.similarity*100).toFixed(0)}%)`,type:e,id:s.content_id})});const R=Array.from(f.values()).sort((e,t)=>t.score-e.score),P=[];if(R.length>0){const e={};for(const t of R)e[t.type]||(e[t.type]=[]),e[t.type].push(t);for(const[t,s]of Object.entries(e)){const r=t==="note"?"Data":t.charAt(0).toUpperCase()+t.slice(1)+"s";P.push({label:r,count:s.length,items:s.slice(0,10).map(a=>a.snippet)})}}let N=[];(i==="all"||i==="skills")&&(N=l.searchSkills(d,10).map(e=>({name:e.name,category:e.category||"uncategorized",active:!!e.is_active,description:e.description})));let F=[];(i==="all"||i==="entities")&&o!==void 0&&(F=$.searchEntities(o,u,10).map(e=>({name:e.name,type:e.type,relationships:$.getRelationships(e.id,"both").length})));const O=A({query:u,mode:p,sections:P,skills:N,entities:F},(e,t)=>{let s=q(t.brand,`**Search Results for "${e.query}"** _(mode: ${e.mode})_`)+`
2
+
3
+ `;for(const r of e.sections){s+=`## ${r.label} (${r.count})
4
+ `;for(const a of r.items)s+=`${t.bullet} ${a}
5
+ `;s+=`
6
+ `}if(e.skills.length>0){s+=`## Skills (${e.skills.length})
7
+ `;for(const r of e.skills)s+=`${t.bullet} **${r.name}** (${r.category}) [${r.active?"active":"inactive"}]
8
+ `,s+=` ${r.description}
9
+ `;s+=`
10
+ `}if(e.entities.length>0){s+=`## Entities (${e.entities.length})
11
+ `;for(const r of e.entities)s+=`${t.bullet} **${r.name}** _(${r.type})_ -- ${r.relationships} relationship${r.relationships!==1?"s":""}
12
+ `;s+=`
13
+ `}return e.sections.length===0&&e.skills.length===0&&e.entities.length===0&&(s+=`_No results found._
14
+ `),s},{summary:(e,t)=>{const s=e.sections.reduce((r,a)=>r+a.count,0)+e.skills.length+e.entities.length;return q(t.brand,`**Search Results for "${e.query}"** _(mode: ${e.mode})_ -- ${s} result${s!==1?"s":""}`)}});return w.set(C("wyrm_search",JSON.stringify(j)),O,2e4),O}},{name:"wyrm_constellation",description:"Cross-project memory query \u2014 search every registered Wyrm project at once for matching truths, artifacts, quests, or design references. Returns candidates grouped by project; the calling AI does semantic ranking on its side. Use this when the operator asks 'have I solved this before?', 'where else have I used X?', or any portfolio-spanning question. Honours per-row cross_project_visibility ('within' = invisible across projects, 'org' = shared, 'public' = anywhere).",inputSchema:{type:"object",properties:{query:{type:"string",description:"Search keywords. Sanitised; safe FTS5 subset only."},kinds:{type:"array",items:{type:"string",enum:["truth","artifact","quest","decision","reference"]},description:"Restrict to specific kinds. Default: all kinds."},visibility:{type:"array",items:{type:"string",enum:["within","org","public"]},description:"Which visibility levels to include. Default: ['org','public'] \u2014 strict cross-project gate."},per_project_limit:{type:"number",description:"Max hits per project (default 5, max 50)."},caller_project_path:{type:"string",description:"Caller's current project path \u2014 excluded from results unless 'within' is in visibility."}},required:["query"]},outputSchema:{type:"object",properties:{query:{type:"string"},count:{type:"integer"},projects:{type:"array",items:{type:"object",properties:{project:{type:"string"},hits:{type:"array",items:{type:"object",properties:{kind:{type:"string"},id:{type:"integer"},title:{type:"string"},visibility:{type:"string"},snippet:{type:["string","null"]}},required:["kind","id","title","visibility","snippet"]}}},required:["project","hits"]}}},required:["query","count","projects"]},annotations:I.wyrm_constellation,aliases:[],handler:(j,{store:l,raw:$})=>{const{query:b,kinds:w,visibility:S,per_project_limit:u,caller_project_path:_}=j;let k;_&&(k=l.getProject(_)?.id);const m=E($(),{query:b,kinds:w,visibility:S,perProjectLimit:u,callerProjectId:k}),y=new Map;for(const n of m){const o=y.get(n.projectName)??[];o.push(n),y.set(n.projectName,o)}const d={query:b,count:m.length,projects:Array.from(y.entries()).map(([n,o])=>({project:n,hits:o.map(i=>({kind:i.kind,id:i.id,title:i.title,visibility:i.visibility,snippet:i.snippet??null}))}))};return A(d,(n,o)=>{if(n.count===0)return q(o.brand,`No constellation matches for *${n.query}* across registered projects.`)+"\n\n_Set `cross_project_visibility` to `'org'` or `'public'` on the items you want surfaced here. Default is `'within'` -- within-project only._";const i=[q(o.brand,`**Constellation** -- ${n.count} match(es) for *${n.query}* across ${n.projects.length} project(s)`)];for(const p of n.projects){i.push(""),i.push(`### ${p.project}`);for(const c of p.hits)i.push(`${o.bullet} \`${c.kind}:${c.id}\` **${c.title}** (${c.visibility})`),c.snippet&&i.push(` ${c.snippet}`)}return i.join(`
15
+ `)})}}];export{B as searchToolSpecs};