@soleri/core 2.0.0 → 2.0.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 (68) hide show
  1. package/dist/brain/brain.d.ts +3 -12
  2. package/dist/brain/brain.d.ts.map +1 -1
  3. package/dist/brain/brain.js +13 -245
  4. package/dist/brain/brain.js.map +1 -1
  5. package/dist/curator/curator.d.ts +28 -0
  6. package/dist/curator/curator.d.ts.map +1 -0
  7. package/dist/curator/curator.js +523 -0
  8. package/dist/curator/curator.js.map +1 -0
  9. package/dist/curator/types.d.ts +87 -0
  10. package/dist/curator/types.d.ts.map +1 -0
  11. package/dist/curator/types.js +3 -0
  12. package/dist/curator/types.js.map +1 -0
  13. package/dist/facades/types.d.ts +1 -1
  14. package/dist/index.d.ts +9 -2
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +10 -2
  17. package/dist/index.js.map +1 -1
  18. package/dist/llm/llm-client.d.ts +28 -0
  19. package/dist/llm/llm-client.d.ts.map +1 -0
  20. package/dist/llm/llm-client.js +219 -0
  21. package/dist/llm/llm-client.js.map +1 -0
  22. package/dist/runtime/core-ops.d.ts +17 -0
  23. package/dist/runtime/core-ops.d.ts.map +1 -0
  24. package/dist/runtime/core-ops.js +448 -0
  25. package/dist/runtime/core-ops.js.map +1 -0
  26. package/dist/runtime/domain-ops.d.ts +25 -0
  27. package/dist/runtime/domain-ops.d.ts.map +1 -0
  28. package/dist/runtime/domain-ops.js +130 -0
  29. package/dist/runtime/domain-ops.js.map +1 -0
  30. package/dist/runtime/runtime.d.ts +19 -0
  31. package/dist/runtime/runtime.d.ts.map +1 -0
  32. package/dist/runtime/runtime.js +62 -0
  33. package/dist/runtime/runtime.js.map +1 -0
  34. package/dist/runtime/types.d.ts +39 -0
  35. package/dist/runtime/types.d.ts.map +1 -0
  36. package/dist/runtime/types.js +2 -0
  37. package/dist/{cognee → runtime}/types.js.map +1 -1
  38. package/dist/text/similarity.d.ts +8 -0
  39. package/dist/text/similarity.d.ts.map +1 -0
  40. package/dist/text/similarity.js +161 -0
  41. package/dist/text/similarity.js.map +1 -0
  42. package/package.json +6 -2
  43. package/src/__tests__/brain.test.ts +27 -222
  44. package/src/__tests__/core-ops.test.ts +190 -0
  45. package/src/__tests__/curator.test.ts +479 -0
  46. package/src/__tests__/domain-ops.test.ts +124 -0
  47. package/src/__tests__/llm-client.test.ts +69 -0
  48. package/src/__tests__/runtime.test.ts +93 -0
  49. package/src/brain/brain.ts +19 -275
  50. package/src/curator/curator.ts +662 -0
  51. package/src/curator/types.ts +114 -0
  52. package/src/index.ts +40 -11
  53. package/src/llm/llm-client.ts +316 -0
  54. package/src/runtime/core-ops.ts +472 -0
  55. package/src/runtime/domain-ops.ts +144 -0
  56. package/src/runtime/runtime.ts +71 -0
  57. package/src/runtime/types.ts +37 -0
  58. package/src/text/similarity.ts +168 -0
  59. package/dist/cognee/client.d.ts +0 -35
  60. package/dist/cognee/client.d.ts.map +0 -1
  61. package/dist/cognee/client.js +0 -289
  62. package/dist/cognee/client.js.map +0 -1
  63. package/dist/cognee/types.d.ts +0 -46
  64. package/dist/cognee/types.d.ts.map +0 -1
  65. package/dist/cognee/types.js +0 -3
  66. package/src/__tests__/cognee-client.test.ts +0 -524
  67. package/src/cognee/client.ts +0 -350
  68. package/src/cognee/types.ts +0 -62
@@ -0,0 +1,472 @@
1
+ /**
2
+ * Generic core operations factory — 26 ops that every agent gets.
3
+ *
4
+ * These ops are agent-agnostic (no persona, no activation).
5
+ * The 5 agent-specific ops (health, identity, activate, inject_claude_md, setup)
6
+ * stay in generated code because they reference agent-specific modules.
7
+ */
8
+
9
+ import { z } from 'zod';
10
+ import type { OpDefinition } from '../facades/types.js';
11
+ import type { IntelligenceEntry } from '../intelligence/types.js';
12
+ import type { AgentRuntime } from './types.js';
13
+
14
+ /**
15
+ * Create the 26 generic core operations for an agent runtime.
16
+ *
17
+ * Groups: search/vault (4), memory (4), export (1), planning (5),
18
+ * brain (4), curator (8).
19
+ */
20
+ export function createCoreOps(runtime: AgentRuntime): OpDefinition[] {
21
+ const { vault, brain, planner, curator, llmClient, keyPool } = runtime;
22
+
23
+ return [
24
+ // ─── Search / Vault ──────────────────────────────────────────
25
+ {
26
+ name: 'search',
27
+ description: 'Search across all knowledge domains. Results ranked by TF-IDF + severity + recency + tag overlap + domain match.',
28
+ auth: 'read',
29
+ schema: z.object({
30
+ query: z.string(),
31
+ domain: z.string().optional(),
32
+ type: z.enum(['pattern', 'anti-pattern', 'rule']).optional(),
33
+ severity: z.enum(['critical', 'warning', 'suggestion']).optional(),
34
+ tags: z.array(z.string()).optional(),
35
+ limit: z.number().optional(),
36
+ }),
37
+ handler: async (params) => {
38
+ return brain.intelligentSearch(params.query as string, {
39
+ domain: params.domain as string | undefined,
40
+ type: params.type as string | undefined,
41
+ severity: params.severity as string | undefined,
42
+ tags: params.tags as string[] | undefined,
43
+ limit: (params.limit as number) ?? 10,
44
+ });
45
+ },
46
+ },
47
+ {
48
+ name: 'vault_stats',
49
+ description: 'Get vault statistics — entry counts by type, domain, severity.',
50
+ auth: 'read',
51
+ handler: async () => vault.stats(),
52
+ },
53
+ {
54
+ name: 'list_all',
55
+ description: 'List all knowledge entries with optional filters.',
56
+ auth: 'read',
57
+ schema: z.object({
58
+ domain: z.string().optional(),
59
+ type: z.enum(['pattern', 'anti-pattern', 'rule']).optional(),
60
+ severity: z.enum(['critical', 'warning', 'suggestion']).optional(),
61
+ tags: z.array(z.string()).optional(),
62
+ limit: z.number().optional(),
63
+ offset: z.number().optional(),
64
+ }),
65
+ handler: async (params) => {
66
+ return vault.list({
67
+ domain: params.domain as string | undefined,
68
+ type: params.type as string | undefined,
69
+ severity: params.severity as string | undefined,
70
+ tags: params.tags as string[] | undefined,
71
+ limit: (params.limit as number) ?? 50,
72
+ offset: (params.offset as number) ?? 0,
73
+ });
74
+ },
75
+ },
76
+ {
77
+ name: 'register',
78
+ description: 'Register a project for this session. Call on every new session to track usage and get context.',
79
+ auth: 'write',
80
+ schema: z.object({
81
+ projectPath: z.string().optional().default('.'),
82
+ name: z.string().optional().describe('Project display name (derived from path if omitted)'),
83
+ }),
84
+ handler: async (params) => {
85
+ const { resolve } = await import('node:path');
86
+ const projectPath = resolve((params.projectPath as string) ?? '.');
87
+ const project = vault.registerProject(projectPath, params.name as string | undefined);
88
+ const stats = vault.stats();
89
+ const isNew = project.sessionCount === 1;
90
+
91
+ return {
92
+ project,
93
+ is_new: isNew,
94
+ message: isNew
95
+ ? 'Welcome! New project registered.'
96
+ : 'Welcome back! Session #' + project.sessionCount + ' for ' + project.name + '.',
97
+ vault: { entries: stats.totalEntries, domains: Object.keys(stats.byDomain) },
98
+ };
99
+ },
100
+ },
101
+
102
+ // ─── Memory ──────────────────────────────────────────────────
103
+ {
104
+ name: 'memory_search',
105
+ description: 'Search memories using full-text search.',
106
+ auth: 'read',
107
+ schema: z.object({
108
+ query: z.string(),
109
+ type: z.enum(['session', 'lesson', 'preference']).optional(),
110
+ projectPath: z.string().optional(),
111
+ limit: z.number().optional(),
112
+ }),
113
+ handler: async (params) => {
114
+ return vault.searchMemories(params.query as string, {
115
+ type: params.type as string | undefined,
116
+ projectPath: params.projectPath as string | undefined,
117
+ limit: (params.limit as number) ?? 10,
118
+ });
119
+ },
120
+ },
121
+ {
122
+ name: 'memory_capture',
123
+ description: 'Capture a memory — session summary, lesson learned, or preference.',
124
+ auth: 'write',
125
+ schema: z.object({
126
+ projectPath: z.string(),
127
+ type: z.enum(['session', 'lesson', 'preference']),
128
+ context: z.string(),
129
+ summary: z.string(),
130
+ topics: z.array(z.string()).optional().default([]),
131
+ filesModified: z.array(z.string()).optional().default([]),
132
+ toolsUsed: z.array(z.string()).optional().default([]),
133
+ }),
134
+ handler: async (params) => {
135
+ const memory = vault.captureMemory({
136
+ projectPath: params.projectPath as string,
137
+ type: params.type as 'session' | 'lesson' | 'preference',
138
+ context: params.context as string,
139
+ summary: params.summary as string,
140
+ topics: (params.topics as string[]) ?? [],
141
+ filesModified: (params.filesModified as string[]) ?? [],
142
+ toolsUsed: (params.toolsUsed as string[]) ?? [],
143
+ });
144
+ return { captured: true, memory };
145
+ },
146
+ },
147
+ {
148
+ name: 'memory_list',
149
+ description: 'List memories with optional filters.',
150
+ auth: 'read',
151
+ schema: z.object({
152
+ type: z.enum(['session', 'lesson', 'preference']).optional(),
153
+ projectPath: z.string().optional(),
154
+ limit: z.number().optional(),
155
+ offset: z.number().optional(),
156
+ }),
157
+ handler: async (params) => {
158
+ const memories = vault.listMemories({
159
+ type: params.type as string | undefined,
160
+ projectPath: params.projectPath as string | undefined,
161
+ limit: (params.limit as number) ?? 50,
162
+ offset: (params.offset as number) ?? 0,
163
+ });
164
+ const stats = vault.memoryStats();
165
+ return { memories, stats };
166
+ },
167
+ },
168
+ {
169
+ name: 'session_capture',
170
+ description: 'Capture a session summary before context compaction. Called automatically by PreCompact hook.',
171
+ auth: 'write',
172
+ schema: z.object({
173
+ projectPath: z.string().optional().default('.'),
174
+ summary: z.string().describe('Brief summary of what was accomplished in this session'),
175
+ topics: z.array(z.string()).optional().default([]),
176
+ filesModified: z.array(z.string()).optional().default([]),
177
+ toolsUsed: z.array(z.string()).optional().default([]),
178
+ }),
179
+ handler: async (params) => {
180
+ const { resolve } = await import('node:path');
181
+ const projectPath = resolve((params.projectPath as string) ?? '.');
182
+ const memory = vault.captureMemory({
183
+ projectPath,
184
+ type: 'session',
185
+ context: 'Auto-captured before context compaction',
186
+ summary: params.summary as string,
187
+ topics: (params.topics as string[]) ?? [],
188
+ filesModified: (params.filesModified as string[]) ?? [],
189
+ toolsUsed: (params.toolsUsed as string[]) ?? [],
190
+ });
191
+ return { captured: true, memory, message: 'Session summary saved to memory.' };
192
+ },
193
+ },
194
+
195
+ // ─── Export ───────────────────────────────────────────────────
196
+ {
197
+ name: 'export',
198
+ description: 'Export vault entries as JSON intelligence bundles — one per domain. Enables version control and sharing.',
199
+ auth: 'read',
200
+ schema: z.object({
201
+ domain: z.string().optional().describe('Export only this domain. Omit to export all.'),
202
+ }),
203
+ handler: async (params) => {
204
+ const stats = vault.stats();
205
+ const domains = params.domain
206
+ ? [params.domain as string]
207
+ : Object.keys(stats.byDomain);
208
+ const bundles: Array<{ domain: string; version: string; entries: IntelligenceEntry[] }> = [];
209
+ for (const d of domains) {
210
+ const entries = vault.list({ domain: d, limit: 10000 });
211
+ bundles.push({ domain: d, version: '1.0.0', entries });
212
+ }
213
+ return {
214
+ exported: true,
215
+ bundles,
216
+ totalEntries: bundles.reduce((sum, b) => sum + b.entries.length, 0),
217
+ domains: bundles.map((b) => b.domain),
218
+ };
219
+ },
220
+ },
221
+
222
+ // ─── Planning ────────────────────────────────────────────────
223
+ {
224
+ name: 'create_plan',
225
+ description: 'Create a new plan in draft status. Plans track multi-step tasks with decisions and sub-tasks.',
226
+ auth: 'write',
227
+ schema: z.object({
228
+ objective: z.string().describe('What the plan aims to achieve'),
229
+ scope: z.string().describe('Which parts of the codebase are affected'),
230
+ decisions: z.array(z.string()).optional().default([]),
231
+ tasks: z.array(z.object({ title: z.string(), description: z.string() })).optional().default([]),
232
+ }),
233
+ handler: async (params) => {
234
+ const plan = planner.create({
235
+ objective: params.objective as string,
236
+ scope: params.scope as string,
237
+ decisions: (params.decisions as string[]) ?? [],
238
+ tasks: (params.tasks as Array<{ title: string; description: string }>) ?? [],
239
+ });
240
+ return { created: true, plan };
241
+ },
242
+ },
243
+ {
244
+ name: 'get_plan',
245
+ description: 'Get a plan by ID, or list all active plans if no ID provided.',
246
+ auth: 'read',
247
+ schema: z.object({
248
+ planId: z.string().optional().describe('Plan ID. Omit to list all active plans.'),
249
+ }),
250
+ handler: async (params) => {
251
+ if (params.planId) {
252
+ const plan = planner.get(params.planId as string);
253
+ if (!plan) return { error: 'Plan not found: ' + params.planId };
254
+ return plan;
255
+ }
256
+ return { active: planner.getActive(), executing: planner.getExecuting() };
257
+ },
258
+ },
259
+ {
260
+ name: 'approve_plan',
261
+ description: 'Approve a draft plan and optionally start execution.',
262
+ auth: 'write',
263
+ schema: z.object({
264
+ planId: z.string(),
265
+ startExecution: z.boolean().optional().default(false).describe('If true, immediately start execution after approval'),
266
+ }),
267
+ handler: async (params) => {
268
+ let plan = planner.approve(params.planId as string);
269
+ if (params.startExecution) {
270
+ plan = planner.startExecution(plan.id);
271
+ }
272
+ return { approved: true, executing: plan.status === 'executing', plan };
273
+ },
274
+ },
275
+ {
276
+ name: 'update_task',
277
+ description: 'Update a task status within an executing plan.',
278
+ auth: 'write',
279
+ schema: z.object({
280
+ planId: z.string(),
281
+ taskId: z.string(),
282
+ status: z.enum(['pending', 'in_progress', 'completed', 'skipped', 'failed']),
283
+ }),
284
+ handler: async (params) => {
285
+ const plan = planner.updateTask(
286
+ params.planId as string,
287
+ params.taskId as string,
288
+ params.status as 'pending' | 'in_progress' | 'completed' | 'skipped' | 'failed',
289
+ );
290
+ const task = plan.tasks.find((t) => t.id === params.taskId);
291
+ return { updated: true, task, plan: { id: plan.id, status: plan.status } };
292
+ },
293
+ },
294
+ {
295
+ name: 'complete_plan',
296
+ description: 'Mark an executing plan as completed.',
297
+ auth: 'write',
298
+ schema: z.object({
299
+ planId: z.string(),
300
+ }),
301
+ handler: async (params) => {
302
+ const plan = planner.complete(params.planId as string);
303
+ const taskSummary = {
304
+ completed: plan.tasks.filter((t) => t.status === 'completed').length,
305
+ skipped: plan.tasks.filter((t) => t.status === 'skipped').length,
306
+ failed: plan.tasks.filter((t) => t.status === 'failed').length,
307
+ total: plan.tasks.length,
308
+ };
309
+ return { completed: true, plan, taskSummary };
310
+ },
311
+ },
312
+
313
+ // ─── Brain ───────────────────────────────────────────────────
314
+ {
315
+ name: 'record_feedback',
316
+ description: 'Record feedback on a search result — accepted or dismissed. Used for adaptive weight tuning.',
317
+ auth: 'write',
318
+ schema: z.object({
319
+ query: z.string().describe('The original search query'),
320
+ entryId: z.string().describe('The entry ID that was accepted or dismissed'),
321
+ action: z.enum(['accepted', 'dismissed']),
322
+ }),
323
+ handler: async (params) => {
324
+ brain.recordFeedback(
325
+ params.query as string,
326
+ params.entryId as string,
327
+ params.action as 'accepted' | 'dismissed',
328
+ );
329
+ return { recorded: true, query: params.query, entryId: params.entryId, action: params.action };
330
+ },
331
+ },
332
+ {
333
+ name: 'rebuild_vocabulary',
334
+ description: 'Force rebuild the TF-IDF vocabulary from all vault entries.',
335
+ auth: 'write',
336
+ handler: async () => {
337
+ brain.rebuildVocabulary();
338
+ return { rebuilt: true, vocabularySize: brain.getVocabularySize() };
339
+ },
340
+ },
341
+ {
342
+ name: 'brain_stats',
343
+ description: 'Get brain intelligence stats — vocabulary size, feedback count, current scoring weights.',
344
+ auth: 'read',
345
+ handler: async () => {
346
+ return brain.getStats();
347
+ },
348
+ },
349
+ {
350
+ name: 'llm_status',
351
+ description: 'LLM client status — provider availability, key pool status, model routing config.',
352
+ auth: 'read',
353
+ handler: async () => {
354
+ const available = llmClient.isAvailable();
355
+ return {
356
+ providers: {
357
+ openai: {
358
+ available: available.openai,
359
+ keyPool: keyPool.openai.hasKeys ? keyPool.openai.getStatus() : null,
360
+ },
361
+ anthropic: {
362
+ available: available.anthropic,
363
+ keyPool: keyPool.anthropic.hasKeys ? keyPool.anthropic.getStatus() : null,
364
+ },
365
+ },
366
+ routes: llmClient.getRoutes(),
367
+ };
368
+ },
369
+ },
370
+
371
+ // ─── Curator ─────────────────────────────────────────────────
372
+ {
373
+ name: 'curator_status',
374
+ description: 'Curator status — table row counts, last groomed timestamp.',
375
+ auth: 'read',
376
+ handler: async () => {
377
+ return curator.getStatus();
378
+ },
379
+ },
380
+ {
381
+ name: 'curator_detect_duplicates',
382
+ description: 'Detect duplicate entries using TF-IDF cosine similarity.',
383
+ auth: 'read',
384
+ schema: z.object({
385
+ entryId: z.string().optional().describe('Check a specific entry. Omit to scan all.'),
386
+ threshold: z.number().optional().describe('Similarity threshold (0-1). Default 0.45.'),
387
+ }),
388
+ handler: async (params) => {
389
+ return curator.detectDuplicates(
390
+ params.entryId as string | undefined,
391
+ params.threshold as number | undefined,
392
+ );
393
+ },
394
+ },
395
+ {
396
+ name: 'curator_contradictions',
397
+ description: 'List or detect contradictions between patterns and anti-patterns.',
398
+ auth: 'read',
399
+ schema: z.object({
400
+ status: z.enum(['open', 'resolved', 'dismissed']).optional().describe('Filter by status.'),
401
+ detect: z.boolean().optional().describe('If true, run detection before listing.'),
402
+ }),
403
+ handler: async (params) => {
404
+ if (params.detect) {
405
+ curator.detectContradictions();
406
+ }
407
+ return curator.getContradictions(params.status as 'open' | 'resolved' | 'dismissed' | undefined);
408
+ },
409
+ },
410
+ {
411
+ name: 'curator_resolve_contradiction',
412
+ description: 'Resolve or dismiss a contradiction.',
413
+ auth: 'write',
414
+ schema: z.object({
415
+ id: z.number().describe('Contradiction ID.'),
416
+ resolution: z.enum(['resolved', 'dismissed']),
417
+ }),
418
+ handler: async (params) => {
419
+ return curator.resolveContradiction(
420
+ params.id as number,
421
+ params.resolution as 'resolved' | 'dismissed',
422
+ );
423
+ },
424
+ },
425
+ {
426
+ name: 'curator_groom',
427
+ description: 'Groom a single entry — normalize tags, check staleness.',
428
+ auth: 'write',
429
+ schema: z.object({
430
+ entryId: z.string().describe('Entry ID to groom.'),
431
+ }),
432
+ handler: async (params) => {
433
+ return curator.groomEntry(params.entryId as string);
434
+ },
435
+ },
436
+ {
437
+ name: 'curator_groom_all',
438
+ description: 'Groom all vault entries — normalize tags, detect staleness.',
439
+ auth: 'write',
440
+ handler: async () => {
441
+ return curator.groomAll();
442
+ },
443
+ },
444
+ {
445
+ name: 'curator_consolidate',
446
+ description: 'Consolidate vault — find duplicates, stale entries, contradictions. Dry-run by default.',
447
+ auth: 'write',
448
+ schema: z.object({
449
+ dryRun: z.boolean().optional().describe('Default true. Set false to apply mutations.'),
450
+ staleDaysThreshold: z.number().optional().describe('Days before entry is stale. Default 90.'),
451
+ duplicateThreshold: z.number().optional().describe('Cosine similarity threshold. Default 0.45.'),
452
+ contradictionThreshold: z.number().optional().describe('Contradiction threshold. Default 0.4.'),
453
+ }),
454
+ handler: async (params) => {
455
+ return curator.consolidate({
456
+ dryRun: params.dryRun as boolean | undefined,
457
+ staleDaysThreshold: params.staleDaysThreshold as number | undefined,
458
+ duplicateThreshold: params.duplicateThreshold as number | undefined,
459
+ contradictionThreshold: params.contradictionThreshold as number | undefined,
460
+ });
461
+ },
462
+ },
463
+ {
464
+ name: 'curator_health_audit',
465
+ description: 'Audit vault health — score (0-100), coverage, freshness, quality, tag health, recommendations.',
466
+ auth: 'read',
467
+ handler: async () => {
468
+ return curator.healthAudit();
469
+ },
470
+ },
471
+ ];
472
+ }
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Domain facade factory — creates the standard 5-op domain facade pattern.
3
+ *
4
+ * Every domain gets: get_patterns, search, get_entry, capture, remove.
5
+ * This replaces per-domain generated facade files.
6
+ */
7
+
8
+ import { z } from 'zod';
9
+ import type { FacadeConfig, OpDefinition } from '../facades/types.js';
10
+ import type { AgentRuntime } from './types.js';
11
+
12
+ function capitalize(s: string): string {
13
+ return s.charAt(0).toUpperCase() + s.slice(1);
14
+ }
15
+
16
+ /**
17
+ * Create a single domain facade with 5 standard ops.
18
+ *
19
+ * @param runtime - The agent runtime (vault + brain)
20
+ * @param agentId - Agent identifier (used for facade naming)
21
+ * @param domain - Domain name (e.g. 'security', 'api-design')
22
+ */
23
+ export function createDomainFacade(
24
+ runtime: AgentRuntime,
25
+ agentId: string,
26
+ domain: string,
27
+ ): FacadeConfig {
28
+ const { vault, brain } = runtime;
29
+ const facadeName = `${agentId}_${domain.replace(/-/g, '_')}`;
30
+
31
+ const ops: OpDefinition[] = [
32
+ {
33
+ name: 'get_patterns',
34
+ description: `Get ${domain} patterns filtered by tags or severity.`,
35
+ auth: 'read',
36
+ schema: z.object({
37
+ tags: z.array(z.string()).optional(),
38
+ severity: z.enum(['critical', 'warning', 'suggestion']).optional(),
39
+ type: z.enum(['pattern', 'anti-pattern', 'rule']).optional(),
40
+ limit: z.number().optional(),
41
+ }),
42
+ handler: async (params) => {
43
+ return vault.list({
44
+ domain,
45
+ severity: params.severity as string | undefined,
46
+ type: params.type as string | undefined,
47
+ tags: params.tags as string[] | undefined,
48
+ limit: (params.limit as number) ?? 20,
49
+ });
50
+ },
51
+ },
52
+ {
53
+ name: 'search',
54
+ description: `Search ${domain} knowledge with natural language query. Results ranked by TF-IDF + severity + recency.`,
55
+ auth: 'read',
56
+ schema: z.object({
57
+ query: z.string(),
58
+ tags: z.array(z.string()).optional(),
59
+ limit: z.number().optional(),
60
+ }),
61
+ handler: async (params) => {
62
+ return brain.intelligentSearch(params.query as string, {
63
+ domain,
64
+ tags: params.tags as string[] | undefined,
65
+ limit: (params.limit as number) ?? 10,
66
+ });
67
+ },
68
+ },
69
+ {
70
+ name: 'get_entry',
71
+ description: `Get a specific ${domain} knowledge entry by ID.`,
72
+ auth: 'read',
73
+ schema: z.object({ id: z.string() }),
74
+ handler: async (params) => {
75
+ const entry = vault.get(params.id as string);
76
+ if (!entry) return { error: 'Entry not found: ' + params.id };
77
+ return entry;
78
+ },
79
+ },
80
+ {
81
+ name: 'capture',
82
+ description: `Capture a new ${domain} pattern, anti-pattern, or rule. Auto-tags and checks for duplicates.`,
83
+ auth: 'write',
84
+ schema: z.object({
85
+ id: z.string(),
86
+ type: z.enum(['pattern', 'anti-pattern', 'rule']),
87
+ title: z.string(),
88
+ severity: z.enum(['critical', 'warning', 'suggestion']),
89
+ description: z.string(),
90
+ context: z.string().optional(),
91
+ example: z.string().optional(),
92
+ counterExample: z.string().optional(),
93
+ why: z.string().optional(),
94
+ tags: z.array(z.string()).optional().default([]),
95
+ }),
96
+ handler: async (params) => {
97
+ return brain.enrichAndCapture({
98
+ id: params.id as string,
99
+ type: params.type as 'pattern' | 'anti-pattern' | 'rule',
100
+ domain,
101
+ title: params.title as string,
102
+ severity: params.severity as 'critical' | 'warning' | 'suggestion',
103
+ description: params.description as string,
104
+ context: params.context as string | undefined,
105
+ example: params.example as string | undefined,
106
+ counterExample: params.counterExample as string | undefined,
107
+ why: params.why as string | undefined,
108
+ tags: params.tags as string[],
109
+ });
110
+ },
111
+ },
112
+ {
113
+ name: 'remove',
114
+ description: `Remove a ${domain} knowledge entry by ID.`,
115
+ auth: 'admin',
116
+ schema: z.object({ id: z.string() }),
117
+ handler: async (params) => {
118
+ const removed = vault.remove(params.id as string);
119
+ return { removed, id: params.id };
120
+ },
121
+ },
122
+ ];
123
+
124
+ return {
125
+ name: facadeName,
126
+ description: `${capitalize(domain.replace(/-/g, ' '))} patterns, rules, and guidance.`,
127
+ ops,
128
+ };
129
+ }
130
+
131
+ /**
132
+ * Create domain facades for all domains.
133
+ *
134
+ * @param runtime - The agent runtime
135
+ * @param agentId - Agent identifier
136
+ * @param domains - Array of domain names
137
+ */
138
+ export function createDomainFacades(
139
+ runtime: AgentRuntime,
140
+ agentId: string,
141
+ domains: string[],
142
+ ): FacadeConfig[] {
143
+ return domains.map((d) => createDomainFacade(runtime, agentId, d));
144
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Agent runtime factory — one call to initialize all modules.
3
+ *
4
+ * ```ts
5
+ * const runtime = createAgentRuntime({ agentId: 'my-agent' });
6
+ * // runtime.vault, runtime.brain, runtime.planner, etc. all ready
7
+ * ```
8
+ */
9
+
10
+ import { join } from 'node:path';
11
+ import { homedir } from 'node:os';
12
+ import { Vault } from '../vault/vault.js';
13
+ import { Brain } from '../brain/brain.js';
14
+ import { Planner } from '../planning/planner.js';
15
+ import { Curator } from '../curator/curator.js';
16
+ import { KeyPool, loadKeyPoolConfig } from '../llm/key-pool.js';
17
+ import { loadIntelligenceData } from '../intelligence/loader.js';
18
+ import { LLMClient } from '../llm/llm-client.js';
19
+ import type { AgentRuntimeConfig, AgentRuntime } from './types.js';
20
+
21
+ /**
22
+ * Create a fully initialized agent runtime.
23
+ *
24
+ * All modules (vault, brain, planner, curator, key pools, LLM client)
25
+ * are initialized and wired together. New modules added to core in
26
+ * future versions will be included automatically — existing agents
27
+ * just `npm update @soleri/core`.
28
+ */
29
+ export function createAgentRuntime(config: AgentRuntimeConfig): AgentRuntime {
30
+ const { agentId } = config;
31
+ const agentHome = join(homedir(), `.${agentId}`);
32
+ const vaultPath = config.vaultPath ?? join(agentHome, 'vault.db');
33
+ const plansPath = config.plansPath ?? join(agentHome, 'plans.json');
34
+
35
+ // Vault — persistent SQLite knowledge store
36
+ const vault = new Vault(vaultPath);
37
+
38
+ // Seed intelligence data if dataDir provided
39
+ if (config.dataDir) {
40
+ const entries = loadIntelligenceData(config.dataDir);
41
+ if (entries.length > 0) {
42
+ vault.seed(entries);
43
+ }
44
+ }
45
+
46
+ // Planner — multi-step task tracking
47
+ const planner = new Planner(plansPath);
48
+
49
+ // Brain — intelligence layer (TF-IDF scoring, auto-tagging, dedup)
50
+ const brain = new Brain(vault);
51
+
52
+ // Curator — vault self-maintenance (dedup, contradictions, grooming, health)
53
+ const curator = new Curator(vault);
54
+
55
+ // LLM key pools and client
56
+ const keyPoolFiles = loadKeyPoolConfig(agentId);
57
+ const openaiKeyPool = new KeyPool(keyPoolFiles.openai);
58
+ const anthropicKeyPool = new KeyPool(keyPoolFiles.anthropic);
59
+ const llmClient = new LLMClient(openaiKeyPool, anthropicKeyPool, agentId);
60
+
61
+ return {
62
+ config,
63
+ vault,
64
+ brain,
65
+ planner,
66
+ curator,
67
+ keyPool: { openai: openaiKeyPool, anthropic: anthropicKeyPool },
68
+ llmClient,
69
+ close: () => vault.close(),
70
+ };
71
+ }