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,15 +1,338 @@
1
- import{TOOL_ANNOTATIONS as A}from"../tool-annotations.js";import{renderResult as I,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","artifacts","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:A.wyrm_search,aliases:[],handler:async(j,{store:l,graph:$,vectors:b,cache:w,decrypt:S})=>{const{query:d,type:_,mode:k,projectPath:m}=j,y=b(),u=Q(d),n=(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(u,n);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(u);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(u,n);c.note=e.map((t,s)=>({id:t.id,snippet:`${t.category}/${t.key}: ${S(t.value).slice(0,60)}`,rank:s+1}))}if((i==="all"||i==="artifacts")&&p!=="semantic"){const e=l.searchArtifacts(u,n);c.artifact=e.map((t,s)=>({id:t.id,snippet:`#${t.id}: ${(t.problem||"").slice(0,80)}`,rank:s+1}))}let x=[];if(y&&p!=="lexical"&&(i==="all"||i==="data"||i==="sessions"||i==="quests"))try{x=await y.search(d,20,n)}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(u,10).map(e=>({name:e.name,category:e.category||"uncategorized",active:!!e.is_active,description:e.description})));let F=[];(i==="all"||i==="entities")&&n!==void 0&&(F=$.searchEntities(n,d,10).map(e=>({name:e.name,type:e.type,relationships:$.getRelationships(e.id,"both").length})));const O=I({query:d,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:A.wyrm_constellation,aliases:[],handler:(j,{store:l,raw:$})=>{const{query:b,kinds:w,visibility:S,per_project_limit:d,caller_project_path:_}=j;let k;_&&(k=l.getProject(_)?.id);const m=E($(),{query:b,kinds:w,visibility:S,perProjectLimit:d,callerProjectId:k}),y=new Map;for(const o of m){const n=y.get(o.projectName)??[];n.push(o),y.set(o.projectName,n)}const u={query:b,count:m.length,projects:Array.from(y.entries()).map(([o,n])=>({project:o,hits:n.map(i=>({kind:i.kind,id:i.id,title:i.title,visibility:i.visibility,snippet:i.snippet??null}))}))};return I(u,(o,n)=>{if(o.count===0)return q(n.brand,`No constellation matches for *${o.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(n.brand,`**Constellation** -- ${o.count} match(es) for *${o.query}* across ${o.projects.length} project(s)`)];for(const p of o.projects){i.push(""),i.push(`### ${p.project}`);for(const c of p.hits)i.push(`${n.bullet} \`${c.kind}:${c.id}\` **${c.title}** (${c.visibility})`),c.snippet&&i.push(` ${c.snippet}`)}return i.join(`
15
- `)})}}];export{B as searchToolSpecs};
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 Proprietary — (c) 2026 Ghost Protocol (Pvt) Ltd. All rights reserved. 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", "artifacts", "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
+ // Memory artifacts: lexical peer of the vector 'artifact' channel below,
102
+ // so keyword search finds patterns/lessons too (RRF-fused by artifact id).
103
+ if (searchType === 'all' || searchType === 'artifacts') {
104
+ if (searchMode !== 'semantic') {
105
+ const artifacts = store.searchArtifacts(sanitizedQuery, projectId);
106
+ ftsResultsByType['artifact'] = artifacts.map((a, i) => ({
107
+ id: a.id,
108
+ snippet: `#${a.id}: ${(a.problem || '').slice(0, 80)}`,
109
+ rank: i + 1,
110
+ }));
111
+ }
112
+ }
113
+ let vectorResults = [];
114
+ if (vectorStore && searchMode !== 'lexical' && (searchType === 'all' || searchType === 'data' || searchType === 'sessions' || searchType === 'quests')) {
115
+ try {
116
+ vectorResults = await vectorStore.search(query, 20, projectId);
117
+ }
118
+ catch {
119
+ // Vector search failed gracefully — continue with FTS
120
+ }
121
+ }
122
+ // ── Reciprocal Rank Fusion (RRF) ──────────────────────────────────────
123
+ // Score formula: Σ 1/(k + rank) where k=60
124
+ const RRF_K = 60;
125
+ const rrfScores = new Map();
126
+ const addFtsToRrf = (contentType, results) => {
127
+ results.forEach((r, idx) => {
128
+ const key = `${contentType}:${r.id}`;
129
+ const existing = rrfScores.get(key);
130
+ const score = 1 / (RRF_K + (idx + 1));
131
+ if (existing) {
132
+ existing.score += score;
133
+ }
134
+ else {
135
+ rrfScores.set(key, { score, snippet: r.snippet, type: contentType, id: r.id });
136
+ }
137
+ });
138
+ };
139
+ for (const [contentType, results] of Object.entries(ftsResultsByType)) {
140
+ addFtsToRrf(contentType, results);
141
+ }
142
+ // Add vector results to RRF (sorted by similarity desc → rank 1=most similar)
143
+ const vecByType = {};
144
+ for (const vr of vectorResults) {
145
+ if (!vecByType[vr.content_type])
146
+ vecByType[vr.content_type] = [];
147
+ vecByType[vr.content_type].push(vr);
148
+ }
149
+ for (const [contentType, results] of Object.entries(vecByType)) {
150
+ results.forEach((vr, idx) => {
151
+ const key = `${contentType}:${vr.content_id}`;
152
+ const existing = rrfScores.get(key);
153
+ const score = 1 / (RRF_K + (idx + 1));
154
+ if (existing) {
155
+ existing.score += score;
156
+ existing.snippet += ` (semantic: ${(vr.similarity * 100).toFixed(0)}%)`;
157
+ }
158
+ else {
159
+ rrfScores.set(key, { score, snippet: `${contentType} #${vr.content_id} (semantic: ${(vr.similarity * 100).toFixed(0)}%)`, type: contentType, id: vr.content_id });
160
+ }
161
+ });
162
+ }
163
+ // Sort by RRF score, group fused results by content type
164
+ const fused = Array.from(rrfScores.values()).sort((a, b) => b.score - a.score);
165
+ const sections = [];
166
+ if (fused.length > 0) {
167
+ const byType = {};
168
+ for (const r of fused) {
169
+ if (!byType[r.type])
170
+ byType[r.type] = [];
171
+ byType[r.type].push(r);
172
+ }
173
+ for (const [contentType, results] of Object.entries(byType)) {
174
+ const label = contentType === 'note' ? 'Data' : contentType.charAt(0).toUpperCase() + contentType.slice(1) + 's';
175
+ sections.push({ label, count: results.length, items: results.slice(0, 10).map((r) => r.snippet) });
176
+ }
177
+ }
178
+ // Skills search (FTS only — no vector indexing for skills)
179
+ let skills = [];
180
+ if (searchType === 'all' || searchType === 'skills') {
181
+ skills = store.searchSkills(sanitizedQuery, 10).map((s) => ({
182
+ name: s.name,
183
+ category: s.category || 'uncategorized',
184
+ active: !!s.is_active,
185
+ description: s.description,
186
+ }));
187
+ }
188
+ // Entity graph search
189
+ let entities = [];
190
+ if ((searchType === 'all' || searchType === 'entities') && projectId !== undefined) {
191
+ entities = graph.searchEntities(projectId, query, 10).map((e) => ({
192
+ name: e.name,
193
+ type: e.type,
194
+ relationships: graph.getRelationships(e.id, 'both').length,
195
+ }));
196
+ }
197
+ const body = { query, mode: searchMode, sections, skills, entities };
198
+ const response = renderResult(body, (b, g) => {
199
+ let text = withGlyph(g.brand, `**Search Results for "${b.query}"** _(mode: ${b.mode})_`) + '\n\n';
200
+ for (const section of b.sections) {
201
+ text += `## ${section.label} (${section.count})\n`;
202
+ for (const item of section.items)
203
+ text += `${g.bullet} ${item}\n`;
204
+ text += '\n';
205
+ }
206
+ if (b.skills.length > 0) {
207
+ text += `## Skills (${b.skills.length})\n`;
208
+ for (const s of b.skills) {
209
+ text += `${g.bullet} **${s.name}** (${s.category}) [${s.active ? 'active' : 'inactive'}]\n`;
210
+ text += ` ${s.description}\n`;
211
+ }
212
+ text += '\n';
213
+ }
214
+ if (b.entities.length > 0) {
215
+ text += `## Entities (${b.entities.length})\n`;
216
+ for (const e of b.entities) {
217
+ text += `${g.bullet} **${e.name}** _(${e.type})_ -- ${e.relationships} relationship${e.relationships !== 1 ? 's' : ''}\n`;
218
+ }
219
+ text += '\n';
220
+ }
221
+ if (b.sections.length === 0 && b.skills.length === 0 && b.entities.length === 0) {
222
+ text += '_No results found._\n';
223
+ }
224
+ return text;
225
+ }, {
226
+ // WYRM_CHANNEL=structured summary seam: grouped section/skill/entity
227
+ // counts ride structuredContent unchanged; the text channel collapses
228
+ // to this header + a count roll-up so the model still sees the shape.
229
+ summary: (b, g) => {
230
+ const total = b.sections.reduce((n, s) => n + s.count, 0) + b.skills.length + b.entities.length;
231
+ return withGlyph(g.brand, `**Search Results for "${b.query}"** _(mode: ${b.mode})_ -- ${total} result${total !== 1 ? 's' : ''}`);
232
+ },
233
+ });
234
+ // READ_ONLY_TOOLS cache publish — dispatcher key convention.
235
+ cache.set(cacheKeyFor('wyrm_search', JSON.stringify(args)), response, 20000);
236
+ return response;
237
+ },
238
+ },
239
+ {
240
+ name: "wyrm_constellation",
241
+ 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).",
242
+ inputSchema: {
243
+ type: "object",
244
+ properties: {
245
+ query: { type: "string", description: "Search keywords. Sanitised; safe FTS5 subset only." },
246
+ kinds: { type: "array", items: { type: "string", enum: ["truth", "artifact", "quest", "decision", "reference"] }, description: "Restrict to specific kinds. Default: all kinds." },
247
+ visibility: { type: "array", items: { type: "string", enum: ["within", "org", "public"] }, description: "Which visibility levels to include. Default: ['org','public'] — strict cross-project gate." },
248
+ per_project_limit: { type: "number", description: "Max hits per project (default 5, max 50)." },
249
+ caller_project_path: { type: "string", description: "Caller's current project path — excluded from results unless 'within' is in visibility." },
250
+ },
251
+ required: ["query"],
252
+ },
253
+ outputSchema: {
254
+ type: "object",
255
+ properties: {
256
+ query: { type: "string" },
257
+ count: { type: "integer" },
258
+ projects: {
259
+ type: "array",
260
+ items: {
261
+ type: "object",
262
+ properties: {
263
+ project: { type: "string" },
264
+ hits: {
265
+ type: "array",
266
+ items: {
267
+ type: "object",
268
+ properties: {
269
+ kind: { type: "string" },
270
+ id: { type: "integer" },
271
+ title: { type: "string" },
272
+ visibility: { type: "string" },
273
+ snippet: { type: ["string", "null"] },
274
+ },
275
+ required: ["kind", "id", "title", "visibility", "snippet"],
276
+ },
277
+ },
278
+ },
279
+ required: ["project", "hits"],
280
+ },
281
+ },
282
+ },
283
+ required: ["query", "count", "projects"],
284
+ },
285
+ annotations: TOOL_ANNOTATIONS.wyrm_constellation,
286
+ aliases: [],
287
+ handler: (args, { store, raw }) => {
288
+ const { query: cQuery, kinds: cKinds, visibility: cVis, per_project_limit: cPerProjLimit, caller_project_path: cCallerPath, } = args;
289
+ let callerProjectId;
290
+ if (cCallerPath) {
291
+ const proj = store.getProject(cCallerPath);
292
+ callerProjectId = proj?.id;
293
+ }
294
+ const hits = constellationQuery(raw(), {
295
+ query: cQuery,
296
+ kinds: cKinds,
297
+ visibility: cVis,
298
+ perProjectLimit: cPerProjLimit,
299
+ callerProjectId,
300
+ });
301
+ // Group by project (the 6.x renderConstellation grouping, now body-side).
302
+ const byProject = new Map();
303
+ for (const h of hits) {
304
+ const arr = byProject.get(h.projectName) ?? [];
305
+ arr.push(h);
306
+ byProject.set(h.projectName, arr);
307
+ }
308
+ const body = {
309
+ query: cQuery,
310
+ count: hits.length,
311
+ projects: Array.from(byProject.entries()).map(([project, items]) => ({
312
+ project,
313
+ hits: items.map((h) => ({
314
+ kind: h.kind, id: h.id, title: h.title, visibility: h.visibility, snippet: h.snippet ?? null,
315
+ })),
316
+ })),
317
+ };
318
+ return renderResult(body, (b, g) => {
319
+ if (b.count === 0) {
320
+ return withGlyph(g.brand, `No constellation matches for *${b.query}* across registered projects.`) +
321
+ `\n\n_Set \`cross_project_visibility\` to \`'org'\` or \`'public'\` on the items you want surfaced here. Default is \`'within'\` -- within-project only._`;
322
+ }
323
+ const lines = [withGlyph(g.brand, `**Constellation** -- ${b.count} match(es) for *${b.query}* across ${b.projects.length} project(s)`)];
324
+ for (const p of b.projects) {
325
+ lines.push('');
326
+ lines.push(`### ${p.project}`);
327
+ for (const h of p.hits) {
328
+ lines.push(`${g.bullet} \`${h.kind}:${h.id}\` **${h.title}** (${h.visibility})`);
329
+ if (h.snippet)
330
+ lines.push(` ${h.snippet}`);
331
+ }
332
+ }
333
+ return lines.join('\n');
334
+ });
335
+ },
336
+ },
337
+ ];
338
+ //# sourceMappingURL=search.js.map