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,196 +1 @@
1
- /**
2
- * Embedding Provider Interface — Vendor-agnostic embedding generation
3
- *
4
- * @copyright 2026 Ghost Protocol (Pvt) Ltd.
5
- * @license AGPL-3.0-or-later — dual-licensed; commercial terms: ghosts.lk@proton.me. See LICENSE.
6
- *
7
- * All embedding providers implement this interface so the rest of Wyrm
8
- * never needs to know which provider is active.
9
- */
10
- /**
11
- * Hash-based local embedding — zero dependencies, deterministic, fast.
12
- * NOT semantically meaningful — useful for testing and as a fallback.
13
- * Will be replaced by ONNX transformers in Phase 1.
14
- */
15
- export class LocalHashProvider {
16
- name = 'local-hash';
17
- model = 'hash-384';
18
- dimensions = 384;
19
- async embed(text) {
20
- const embedding = new Float32Array(this.dimensions);
21
- const words = text.toLowerCase().split(/\s+/);
22
- for (let i = 0; i < words.length; i++) {
23
- const word = words[i];
24
- for (let j = 0; j < word.length; j++) {
25
- const idx = (word.charCodeAt(j) * (i + 1) * (j + 1)) % this.dimensions;
26
- embedding[idx] += 1 / words.length;
27
- }
28
- }
29
- // L2 normalize
30
- const magnitude = Math.sqrt(embedding.reduce((sum, val) => sum + val * val, 0));
31
- if (magnitude > 0) {
32
- for (let i = 0; i < embedding.length; i++) {
33
- embedding[i] /= magnitude;
34
- }
35
- }
36
- return embedding;
37
- }
38
- async isReady() {
39
- return true; // Always ready — no external deps
40
- }
41
- }
42
- /**
43
- * OpenAI embeddings via REST API.
44
- */
45
- export class OpenAIProvider {
46
- name = 'openai';
47
- model;
48
- dimensions;
49
- apiKey;
50
- constructor(apiKey, model) {
51
- this.apiKey = apiKey;
52
- this.model = model || 'text-embedding-3-small';
53
- this.dimensions = this.model.includes('large') ? 3072 : 1536;
54
- }
55
- async embed(text) {
56
- const response = await fetch('https://api.openai.com/v1/embeddings', {
57
- method: 'POST',
58
- headers: {
59
- 'Authorization': `Bearer ${this.apiKey}`,
60
- 'Content-Type': 'application/json',
61
- },
62
- body: JSON.stringify({ input: text, model: this.model }),
63
- });
64
- if (!response.ok) {
65
- const body = await response.text();
66
- throw new Error(`OpenAI embedding API error ${response.status}: ${body}`);
67
- }
68
- const data = await response.json();
69
- return new Float32Array(data.data[0].embedding);
70
- }
71
- async isReady() {
72
- return !!this.apiKey;
73
- }
74
- }
75
- /**
76
- * Ollama embeddings via local API.
77
- */
78
- export class OllamaProvider {
79
- name = 'ollama';
80
- model;
81
- dimensions;
82
- baseUrl;
83
- constructor(baseUrl, model) {
84
- this.baseUrl = baseUrl || 'http://localhost:11434';
85
- this.model = model || 'nomic-embed-text';
86
- // Dimensions vary by model — these are common defaults
87
- this.dimensions = this.model.includes('mxbai') ? 1024 : 768;
88
- }
89
- async embed(text) {
90
- const response = await fetch(`${this.baseUrl}/api/embeddings`, {
91
- method: 'POST',
92
- headers: { 'Content-Type': 'application/json' },
93
- body: JSON.stringify({ model: this.model, prompt: text }),
94
- });
95
- if (!response.ok) {
96
- const body = await response.text();
97
- throw new Error(`Ollama embedding API error ${response.status}: ${body}`);
98
- }
99
- const data = await response.json();
100
- return new Float32Array(data.embedding);
101
- }
102
- async isReady() {
103
- try {
104
- const res = await fetch(`${this.baseUrl}/api/tags`, { signal: AbortSignal.timeout(2000) });
105
- return res.ok;
106
- }
107
- catch {
108
- return false;
109
- }
110
- }
111
- }
112
- /**
113
- * No-op provider — returns nothing, used when embeddings are disabled.
114
- */
115
- export class NoneProvider {
116
- name = 'none';
117
- model = 'none';
118
- dimensions = 0;
119
- async embed(_text) {
120
- return new Float32Array(0);
121
- }
122
- async isReady() {
123
- return true;
124
- }
125
- }
126
- /**
127
- * Auto-detecting Ollama provider — checks if Ollama is running with nomic-embed-text.
128
- * Falls back to NoneProvider behaviour if Ollama is unavailable.
129
- * Re-probes every 60 s so a Wyrm instance started before Ollama can still pick it up.
130
- */
131
- export class OllamaAutoProvider {
132
- delegate = new NoneProvider();
133
- lastProbe = 0;
134
- probeIntervalMs = 60_000;
135
- baseUrl;
136
- name = 'ollama-auto';
137
- get model() { return this.delegate.model; }
138
- get dimensions() { return this.delegate.dimensions; }
139
- constructor(baseUrl) {
140
- this.baseUrl = baseUrl || process.env.OLLAMA_URL || 'http://localhost:11434';
141
- }
142
- async probe() {
143
- const now = Date.now();
144
- const alreadyReady = this.delegate.name === 'ollama';
145
- if (alreadyReady || now - this.lastProbe < this.probeIntervalMs)
146
- return;
147
- this.lastProbe = now;
148
- try {
149
- const res = await fetch(`${this.baseUrl}/api/tags`, { signal: AbortSignal.timeout(2000) });
150
- if (!res.ok)
151
- return;
152
- const data = await res.json();
153
- const hasModel = data.models?.some(m => m.name.startsWith('nomic-embed-text')) ?? false;
154
- if (hasModel) {
155
- this.delegate = new OllamaProvider(this.baseUrl, 'nomic-embed-text');
156
- }
157
- }
158
- catch {
159
- // Ollama not available — stay as NoneProvider
160
- }
161
- }
162
- async embed(text) {
163
- await this.probe();
164
- return this.delegate.embed(text);
165
- }
166
- async isReady() {
167
- await this.probe();
168
- return this.delegate.name === 'ollama';
169
- }
170
- }
171
- /**
172
- * Factory: create the right provider from config / environment.
173
- */
174
- export function createProvider(config) {
175
- const provider = config?.provider
176
- || process.env.WYRM_VECTOR_PROVIDER
177
- || 'auto';
178
- switch (provider) {
179
- case 'openai': {
180
- const key = config?.apiKey || process.env.OPENAI_API_KEY;
181
- if (!key)
182
- throw new Error('OpenAI provider requires OPENAI_API_KEY');
183
- return new OpenAIProvider(key, config?.model);
184
- }
185
- case 'ollama':
186
- return new OllamaProvider(config?.ollamaUrl || process.env.OLLAMA_URL, config?.model);
187
- case 'none':
188
- return new NoneProvider();
189
- case 'auto':
190
- return new OllamaAutoProvider(config?.ollamaUrl || process.env.OLLAMA_URL);
191
- case 'local':
192
- default:
193
- return new LocalHashProvider();
194
- }
195
- }
196
- //# sourceMappingURL=embedding-provider.js.map
1
+ class c{name="local-hash";model="hash-384";dimensions=384;async embed(t){const e=new Float32Array(this.dimensions),o=t.toLowerCase().split(/\s+/);for(let a=0;a<o.length;a++){const n=o[a];for(let i=0;i<n.length;i++){const m=n.charCodeAt(i)*(a+1)*(i+1)%this.dimensions;e[m]+=1/o.length}}const r=Math.sqrt(e.reduce((a,n)=>a+n*n,0));if(r>0)for(let a=0;a<e.length;a++)e[a]/=r;return e}async isReady(){return!0}}class h{name="openai";model;dimensions;apiKey;constructor(t,e){this.apiKey=t,this.model=e||"text-embedding-3-small",this.dimensions=this.model.includes("large")?3072:1536}async embed(t){const e=await fetch("https://api.openai.com/v1/embeddings",{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({input:t,model:this.model})});if(!e.ok){const r=await e.text();throw new Error(`OpenAI embedding API error ${e.status}: ${r}`)}const o=await e.json();return new Float32Array(o.data[0].embedding)}async isReady(){return!!this.apiKey}}class d{name="ollama";model;dimensions;baseUrl;constructor(t,e){this.baseUrl=t||"http://localhost:11434",this.model=e||"nomic-embed-text",this.dimensions=this.model.includes("mxbai")?1024:768}async embed(t){const e=await fetch(`${this.baseUrl}/api/embeddings`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:this.model,prompt:t})});if(!e.ok){const r=await e.text();throw new Error(`Ollama embedding API error ${e.status}: ${r}`)}const o=await e.json();return new Float32Array(o.embedding)}async isReady(){try{return(await fetch(`${this.baseUrl}/api/tags`,{signal:AbortSignal.timeout(2e3)})).ok}catch{return!1}}}class l{name="none";model="none";dimensions=0;async embed(t){return new Float32Array(0)}async isReady(){return!0}}class p{delegate=new l;lastProbe=0;probeIntervalMs=6e4;baseUrl;name="ollama-auto";get model(){return this.delegate.model}get dimensions(){return this.delegate.dimensions}constructor(t){this.baseUrl=t||process.env.OLLAMA_URL||"http://localhost:11434"}async probe(){const t=Date.now();if(!(this.delegate.name==="ollama"||t-this.lastProbe<this.probeIntervalMs)){this.lastProbe=t;try{const o=await fetch(`${this.baseUrl}/api/tags`,{signal:AbortSignal.timeout(2e3)});if(!o.ok)return;((await o.json()).models?.some(n=>n.name.startsWith("nomic-embed-text"))??!1)&&(this.delegate=new d(this.baseUrl,"nomic-embed-text"))}catch{}}}async embed(t){return await this.probe(),this.delegate.embed(t)}async isReady(){return await this.probe(),this.delegate.name==="ollama"}}function u(s){switch(s?.provider||process.env.WYRM_VECTOR_PROVIDER||"auto"){case"openai":{const e=s?.apiKey||process.env.OPENAI_API_KEY;if(!e)throw new Error("OpenAI provider requires OPENAI_API_KEY");return new h(e,s?.model)}case"ollama":return new d(s?.ollamaUrl||process.env.OLLAMA_URL,s?.model);case"none":return new l;case"auto":return new p(s?.ollamaUrl||process.env.OLLAMA_URL);default:return new c}}export{c as LocalHashProvider,l as NoneProvider,p as OllamaAutoProvider,d as OllamaProvider,h as OpenAIProvider,u as createProvider};
@@ -1,29 +1 @@
1
- /**
2
- * Read-only / public-view gate predicate.
3
- *
4
- * Pure and side-effect-free (no DB, no server) so the security boundary can be
5
- * unit-tested directly, without booting the HTTP server. http-fast.ts calls this
6
- * as a single dispatcher-level chokepoint when WYRM_UI_READONLY=1.
7
- *
8
- * Returns true if the request must be 403'd in read-only mode.
9
- *
10
- * Design note: blocking by HTTP METHOD catches every current AND future write
11
- * route automatically (every mutator in the server is a POST), so a newly-added
12
- * write route cannot silently slip the gate. The explicit read list adds the GET
13
- * endpoints that ship is_shared rows off the box (federation / replication pull),
14
- * plus the two reads that over-share machine internals to a public viewer.
15
- */
16
- /** GET endpoints blocked in read-only mode: off-box egress + machine-internal over-shares. */
17
- export const READONLY_BLOCKED_READS = new Set([
18
- '/sync/push', // federation pull: egresses is_shared rows
19
- '/events', // ?shared=1 remote pull surface
20
- '/events/stream', // long-lived SSE egress of shared events
21
- '/ui/homes', // enumerates every Wyrm home/account + DB path on the machine
22
- '/audit', // dumps the full audit_log
23
- ]);
24
- export function readonlyBlocks(method, pathname) {
25
- const m = (method || 'GET').toUpperCase();
26
- const isWrite = m === 'POST' || m === 'PUT' || m === 'DELETE' || m === 'PATCH';
27
- return isWrite || READONLY_BLOCKED_READS.has(pathname);
28
- }
29
- //# sourceMappingURL=readonly-gate.js.map
1
+ const n=new Set(["/sync/push","/events","/events/stream","/ui/homes","/audit"]);function r(t,s){const e=(t||"GET").toUpperCase();return e==="POST"||e==="PUT"||e==="DELETE"||e==="PATCH"||n.has(s)}export{n as READONLY_BLOCKED_READS,r as readonlyBlocks};
@@ -1,44 +1,11 @@
1
- /**
2
- * Lossless session rehydration (Tier 3.11).
3
- *
4
- * `wyrm_session_rehydrate(sessionId)` produces a complete "briefing
5
- * markdown" that a fresh AI agent can ingest to inherit the prior
6
- * session's full state: objectives, completed work, notes, summary,
7
- * attached ground truths, related quests, project scaffold pointer.
8
- *
9
- * This is the cross-session continuity feature that no other AI memory
10
- * tool offers — past-Claude's reasoning surface, fully restored, ready
11
- * to be picked up by current-Claude on a new conversation.
12
- *
13
- * @copyright 2026 Ghost Protocol (Pvt) Ltd.
14
- * @license AGPL-3.0-or-later — dual-licensed; commercial terms: ghosts.lk@proton.me. See LICENSE.
15
- */
16
- export class Rehydration {
17
- db;
18
- constructor(db) {
19
- this.db = db;
20
- }
21
- rehydrate(sessionId, opts) {
22
- const session = this.db.prepare('SELECT * FROM sessions WHERE id = ?').get(sessionId);
23
- if (!session)
24
- return null;
25
- const project = this.db.prepare('SELECT name, path FROM projects WHERE id = ?').get(session.project_id);
26
- if (!project)
27
- return null;
28
- const includeArtifacts = opts?.include_artifacts ?? true;
29
- const includeFailures = opts?.include_failures ?? true;
30
- const truthCap = Math.max(200, Math.min(opts?.max_truth_chars ?? 2000, 10000));
31
- // Current ground truths for the project
32
- const truths = this.db.prepare(`
1
+ class m{db;constructor(c){this.db=c}rehydrate(c,p){const s=this.db.prepare("SELECT * FROM sessions WHERE id = ?").get(c);if(!s)return null;const a=this.db.prepare("SELECT name, path FROM projects WHERE id = ?").get(s.project_id);if(!a)return null;const f=p?.include_artifacts??!0,_=p?.include_failures??!0,u=Math.max(200,Math.min(p?.max_truth_chars??2e3,1e4)),h=this.db.prepare(`
33
2
  SELECT category, key, value, rationale, confidence, last_verified_at,
34
3
  ttl_days,
35
4
  CAST((julianday('now') - julianday(last_verified_at)) AS REAL) AS age_days
36
5
  FROM ground_truths
37
6
  WHERE project_id = ? AND is_current = 1
38
7
  ORDER BY category, key
39
- `).all(session.project_id);
40
- // Open quests for the project
41
- const quests = this.db.prepare(`
8
+ `).all(s.project_id),i=this.db.prepare(`
42
9
  SELECT id, title, description, priority, status, tags
43
10
  FROM quests
44
11
  WHERE project_id = ? AND status IN ('pending','in_progress')
@@ -46,133 +13,18 @@ export class Rehydration {
46
13
  CASE priority WHEN 'critical' THEN 0 WHEN 'high' THEN 1
47
14
  WHEN 'medium' THEN 2 ELSE 3 END,
48
15
  created_at DESC
49
- `).all(session.project_id);
50
- let artifacts = [];
51
- if (includeArtifacts) {
52
- try {
53
- artifacts = this.db.prepare(`
16
+ `).all(s.project_id);let n=[];if(f)try{n=this.db.prepare(`
54
17
  SELECT id, problem, constraints, validated_fix, why_it_worked, tags
55
18
  FROM memory_artifacts
56
19
  WHERE project_id = ? AND (needs_review = 0 OR needs_review IS NULL)
57
20
  ORDER BY id DESC LIMIT 20
58
- `).all(session.project_id);
59
- }
60
- catch {
61
- artifacts = [];
62
- }
63
- }
64
- let failures = [];
65
- if (includeFailures) {
66
- try {
67
- failures = this.db.prepare(`
21
+ `).all(s.project_id)}catch{n=[]}let o=[];if(_)try{o=this.db.prepare(`
68
22
  SELECT id, scope, target, description, why_failed, occurrences, severity, last_seen
69
23
  FROM failure_patterns
70
24
  WHERE (project_id = ? OR project_id IS NULL) AND resolved = 0
71
25
  ORDER BY last_seen DESC LIMIT 15
72
- `).all(session.project_id);
73
- }
74
- catch {
75
- failures = [];
76
- }
77
- }
78
- // Compose markdown briefing
79
- const lines = [];
80
- lines.push(`# Session Rehydration Brief`);
81
- lines.push('');
82
- lines.push(`**Session #${session.id}** · ${project.name} · ${session.date}`);
83
- lines.push(`**Project root:** \`${project.path}\``);
84
- lines.push('');
85
- if (session.objectives) {
86
- lines.push('## Objectives at start');
87
- lines.push(session.objectives);
88
- lines.push('');
89
- }
90
- if (session.completed) {
91
- lines.push('## What was completed');
92
- lines.push(session.completed);
93
- lines.push('');
94
- }
95
- if (session.issues) {
96
- lines.push('## Open issues at session close');
97
- lines.push(session.issues);
98
- lines.push('');
99
- }
100
- if (session.notes) {
101
- lines.push('## Notes');
102
- lines.push(session.notes);
103
- lines.push('');
104
- }
105
- if (session.summary) {
106
- lines.push('## Summary');
107
- lines.push(session.summary);
108
- lines.push('');
109
- }
110
- // Ground truths — load-bearing facts a fresh agent must respect
111
- if (truths.length > 0) {
112
- lines.push('## Ground truths for this project');
113
- lines.push('');
114
- let used = 0;
115
- for (const t of truths) {
116
- const stale = t.ttl_days != null && t.age_days > t.ttl_days;
117
- const marker = stale ? ' [⚠️ STALE]' : '';
118
- const line = `- **${t.category}.${t.key}**${marker}: ${t.value}` +
119
- (t.rationale ? ` *(rationale: ${t.rationale})*` : '') +
120
- (t.confidence < 1.0 ? ` *(conf: ${t.confidence})*` : '');
121
- used += line.length;
122
- if (used > truthCap) {
123
- lines.push(`- _… ${truths.length - (lines.length - 3)} more truths omitted (cap ${truthCap} chars) — query wyrm_truth_get for full list._`);
124
- break;
125
- }
126
- lines.push(line);
127
- }
128
- lines.push('');
129
- }
130
- if (quests.length > 0) {
131
- lines.push(`## Open quests (${quests.length})`);
132
- lines.push('');
133
- for (const q of quests.slice(0, 20)) {
134
- lines.push(`- **#${q.id}** [${q.priority}] ${q.title}` +
135
- (q.description ? `\n ${q.description.slice(0, 200)}` : ''));
136
- }
137
- if (quests.length > 20)
138
- lines.push(`- _… ${quests.length - 20} more — query wyrm_all_quests._`);
139
- lines.push('');
140
- }
141
- if (artifacts.length > 0) {
142
- lines.push('## Validated patterns (memory artifacts)');
143
- lines.push('');
144
- for (const a of artifacts.slice(0, 10)) {
145
- lines.push(`- **${a.problem}**` +
146
- (a.validated_fix ? ` → ${a.validated_fix.slice(0, 150)}` : ''));
147
- }
148
- lines.push('');
149
- }
150
- if (failures.length > 0) {
151
- lines.push('## Unresolved failure patterns — DO NOT repeat these');
152
- lines.push('');
153
- for (const f of failures) {
154
- lines.push(`- 🔴 #${f.id} [${f.severity}] ${f.scope}:${f.target} ×${f.occurrences}` +
155
- `\n ${f.description}` +
156
- (f.why_failed ? `\n Why: ${f.why_failed}` : ''));
157
- }
158
- lines.push('');
159
- }
160
- lines.push('---');
161
- lines.push(`*Rehydrated from session created at ${session.created_at}. Continue from where the prior agent left off.*`);
162
- const briefing = lines.join('\n');
163
- return {
164
- session_id: session.id,
165
- project_name: project.name,
166
- project_path: project.path,
167
- briefing_markdown: briefing,
168
- context_chars: briefing.length,
169
- attached: {
170
- quests: quests.length,
171
- truths: truths.length,
172
- artifacts: artifacts.length,
173
- failures: failures.length,
174
- },
175
- };
176
- }
177
- }
178
- //# sourceMappingURL=rehydration.js.map
26
+ `).all(s.project_id)}catch{o=[]}const e=[];if(e.push("# Session Rehydration Brief"),e.push(""),e.push(`**Session #${s.id}** \xB7 ${a.name} \xB7 ${s.date}`),e.push(`**Project root:** \`${a.path}\``),e.push(""),s.objectives&&(e.push("## Objectives at start"),e.push(s.objectives),e.push("")),s.completed&&(e.push("## What was completed"),e.push(s.completed),e.push("")),s.issues&&(e.push("## Open issues at session close"),e.push(s.issues),e.push("")),s.notes&&(e.push("## Notes"),e.push(s.notes),e.push("")),s.summary&&(e.push("## Summary"),e.push(s.summary),e.push("")),h.length>0){e.push("## Ground truths for this project"),e.push("");let t=0;for(const r of h){const E=r.ttl_days!=null&&r.age_days>r.ttl_days?" [\u26A0\uFE0F STALE]":"",d=`- **${r.category}.${r.key}**${E}: ${r.value}`+(r.rationale?` *(rationale: ${r.rationale})*`:"")+(r.confidence<1?` *(conf: ${r.confidence})*`:"");if(t+=d.length,t>u){e.push(`- _\u2026 ${h.length-(e.length-3)} more truths omitted (cap ${u} chars) \u2014 query wyrm_truth_get for full list._`);break}e.push(d)}e.push("")}if(i.length>0){e.push(`## Open quests (${i.length})`),e.push("");for(const t of i.slice(0,20))e.push(`- **#${t.id}** [${t.priority}] ${t.title}`+(t.description?`
27
+ ${t.description.slice(0,200)}`:""));i.length>20&&e.push(`- _\u2026 ${i.length-20} more \u2014 query wyrm_all_quests._`),e.push("")}if(n.length>0){e.push("## Validated patterns (memory artifacts)"),e.push("");for(const t of n.slice(0,10))e.push(`- **${t.problem}**`+(t.validated_fix?` \u2192 ${t.validated_fix.slice(0,150)}`:""));e.push("")}if(o.length>0){e.push("## Unresolved failure patterns \u2014 DO NOT repeat these"),e.push("");for(const t of o)e.push(`- \u{1F534} #${t.id} [${t.severity}] ${t.scope}:${t.target} \xD7${t.occurrences}
28
+ ${t.description}`+(t.why_failed?`
29
+ Why: ${t.why_failed}`:""));e.push("")}e.push("---"),e.push(`*Rehydrated from session created at ${s.created_at}. Continue from where the prior agent left off.*`);const l=e.join(`
30
+ `);return{session_id:s.id,project_name:a.name,project_path:a.path,briefing_markdown:l,context_chars:l.length,attached:{quests:i.length,truths:h.length,artifacts:n.length,failures:o.length}}}}export{m as Rehydration};
package/dist/reindex.js CHANGED
@@ -1,88 +1 @@
1
- /**
2
- * Vector reindex — v7 F3 (T023).
3
- *
4
- * The `wyrm_reindex` MCP case's project loop (index.ts), extracted VERBATIM
5
- * so the new `wyrm index rebuild` CLI subcommand and the MCP tool run the
6
- * SAME code path (spec FR-4 / T023: CLI commands wrap existing src modules —
7
- * never reimplementations). Iterates sessions, quests, and active memory
8
- * artifacts per project and embeds them via the vector store; per-row
9
- * failures are counted as skips and reported through `onError` (the MCP case
10
- * forwards to the server logger, the CLI prints to stderr).
11
- *
12
- * @copyright 2026 Ghost Protocol (Pvt) Ltd.
13
- * @license AGPL-3.0-or-later — dual-licensed; commercial terms: ghosts.lk@proton.me. See LICENSE.
14
- */
15
- /** Reindex the given projects' content into the vector store. */
16
- export async function reindexProjects(rawDb, vectorStore, projectIds, opts = {}) {
17
- const dryRun = opts.dryRun === true;
18
- const onError = opts.onError ?? (() => { });
19
- let indexed = 0;
20
- let skipped = 0;
21
- for (const projectId of projectIds) {
22
- // Sessions
23
- const sessions = rawDb.prepare('SELECT id, objectives, completed, notes, summary FROM sessions WHERE project_id = ?').all(projectId);
24
- for (const s of sessions) {
25
- const content = [s.objectives, s.completed, s.notes, s.summary].filter(Boolean).join(' ');
26
- if (content && !dryRun) {
27
- try {
28
- const hash = await vectorStore.addVector(content, 'session', s.id, projectId);
29
- if (hash)
30
- indexed++;
31
- else
32
- skipped++;
33
- }
34
- catch (err) {
35
- onError('Reindex session failed', { projectId, sessionId: s.id, error: err.message });
36
- skipped++;
37
- }
38
- }
39
- else if (content) {
40
- indexed++;
41
- }
42
- }
43
- // Quests
44
- const quests = rawDb.prepare('SELECT id, title, description FROM quests WHERE project_id = ?').all(projectId);
45
- for (const q of quests) {
46
- const content = [q.title, q.description].filter(Boolean).join(' ');
47
- if (content && !dryRun) {
48
- try {
49
- const hash = await vectorStore.addVector(content, 'context', q.id, projectId);
50
- if (hash)
51
- indexed++;
52
- else
53
- skipped++;
54
- }
55
- catch (err) {
56
- onError('Reindex quest failed', { projectId, questId: q.id, error: err.message });
57
- skipped++;
58
- }
59
- }
60
- else if (content) {
61
- indexed++;
62
- }
63
- }
64
- // Memory artifacts (active only) — powers hybrid recall (FTS ⊕ vectors)
65
- const artifacts = rawDb.prepare('SELECT id, problem, validated_fix FROM memory_artifacts WHERE project_id = ? AND needs_review = 0 AND supersedes_id IS NULL').all(projectId);
66
- for (const a of artifacts) {
67
- const content = [a.problem, a.validated_fix].filter(Boolean).join(' ');
68
- if (content && !dryRun) {
69
- try {
70
- const hash = await vectorStore.addVector(content, 'artifact', a.id, projectId);
71
- if (hash)
72
- indexed++;
73
- else
74
- skipped++;
75
- }
76
- catch (err) {
77
- onError('Reindex artifact failed', { projectId, artifactId: a.id, error: err.message });
78
- skipped++;
79
- }
80
- }
81
- else if (content) {
82
- indexed++;
83
- }
84
- }
85
- }
86
- return { indexed, skipped };
87
- }
88
- //# sourceMappingURL=reindex.js.map
1
+ async function m(n,a,l,f={}){const d=f.dryRun===!0,c=f.onError??(()=>{});let o=0,r=0;for(const t of l){const p=n.prepare("SELECT id, objectives, completed, notes, summary FROM sessions WHERE project_id = ?").all(t);for(const e of p){const s=[e.objectives,e.completed,e.notes,e.summary].filter(Boolean).join(" ");if(s&&!d)try{await a.addVector(s,"session",e.id,t)?o++:r++}catch(i){c("Reindex session failed",{projectId:t,sessionId:e.id,error:i.message}),r++}else s&&o++}const h=n.prepare("SELECT id, title, description FROM quests WHERE project_id = ?").all(t);for(const e of h){const s=[e.title,e.description].filter(Boolean).join(" ");if(s&&!d)try{await a.addVector(s,"context",e.id,t)?o++:r++}catch(i){c("Reindex quest failed",{projectId:t,questId:e.id,error:i.message}),r++}else s&&o++}const E=n.prepare("SELECT id, problem, validated_fix FROM memory_artifacts WHERE project_id = ? AND needs_review = 0 AND supersedes_id IS NULL").all(t);for(const e of E){const s=[e.problem,e.validated_fix].filter(Boolean).join(" ");if(s&&!d)try{await a.addVector(s,"artifact",e.id,t)?o++:r++}catch(i){c("Reindex artifact failed",{projectId:t,artifactId:e.id,error:i.message}),r++}else s&&o++}}return{indexed:o,skipped:r}}export{m as reindexProjects};