nexus-prime 3.0.3 → 3.2.0

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 (62) hide show
  1. package/README.md +37 -6
  2. package/dist/agents/adapters/mcp.d.ts +2 -0
  3. package/dist/agents/adapters/mcp.d.ts.map +1 -1
  4. package/dist/agents/adapters/mcp.js +353 -83
  5. package/dist/agents/adapters/mcp.js.map +1 -1
  6. package/dist/cli.js +52 -2
  7. package/dist/cli.js.map +1 -1
  8. package/dist/core/types.d.ts +1 -0
  9. package/dist/core/types.d.ts.map +1 -1
  10. package/dist/dashboard/index.html +455 -722
  11. package/dist/dashboard/server.d.ts +13 -14
  12. package/dist/dashboard/server.d.ts.map +1 -1
  13. package/dist/dashboard/server.js +101 -29
  14. package/dist/dashboard/server.js.map +1 -1
  15. package/dist/engines/index.d.ts +8 -1
  16. package/dist/engines/index.d.ts.map +1 -1
  17. package/dist/engines/index.js +3 -0
  18. package/dist/engines/index.js.map +1 -1
  19. package/dist/engines/memory.d.ts +1 -0
  20. package/dist/engines/memory.d.ts.map +1 -1
  21. package/dist/engines/memory.js +8 -0
  22. package/dist/engines/memory.js.map +1 -1
  23. package/dist/engines/nxl-interpreter.d.ts +22 -0
  24. package/dist/engines/nxl-interpreter.d.ts.map +1 -1
  25. package/dist/engines/nxl-interpreter.js +73 -1
  26. package/dist/engines/nxl-interpreter.js.map +1 -1
  27. package/dist/engines/orchestrator.d.ts +7 -6
  28. package/dist/engines/orchestrator.d.ts.map +1 -1
  29. package/dist/engines/orchestrator.js +34 -12
  30. package/dist/engines/orchestrator.js.map +1 -1
  31. package/dist/engines/pod-network.d.ts.map +1 -1
  32. package/dist/engines/pod-network.js +20 -4
  33. package/dist/engines/pod-network.js.map +1 -1
  34. package/dist/engines/runtime-assets.d.ts +60 -0
  35. package/dist/engines/runtime-assets.d.ts.map +1 -0
  36. package/dist/engines/runtime-assets.js +252 -0
  37. package/dist/engines/runtime-assets.js.map +1 -0
  38. package/dist/engines/runtime-backends.d.ts +130 -0
  39. package/dist/engines/runtime-backends.d.ts.map +1 -0
  40. package/dist/engines/runtime-backends.js +278 -0
  41. package/dist/engines/runtime-backends.js.map +1 -0
  42. package/dist/engines/skill-runtime.d.ts +85 -0
  43. package/dist/engines/skill-runtime.d.ts.map +1 -0
  44. package/dist/engines/skill-runtime.js +370 -0
  45. package/dist/engines/skill-runtime.js.map +1 -0
  46. package/dist/engines/workflow-runtime.d.ts +78 -0
  47. package/dist/engines/workflow-runtime.d.ts.map +1 -0
  48. package/dist/engines/workflow-runtime.js +288 -0
  49. package/dist/engines/workflow-runtime.js.map +1 -0
  50. package/dist/index.d.ts +7 -2
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +43 -15
  53. package/dist/index.js.map +1 -1
  54. package/dist/phantom/index.d.ts +3 -1
  55. package/dist/phantom/index.d.ts.map +1 -1
  56. package/dist/phantom/index.js +9 -10
  57. package/dist/phantom/index.js.map +1 -1
  58. package/dist/phantom/runtime.d.ts +221 -0
  59. package/dist/phantom/runtime.d.ts.map +1 -0
  60. package/dist/phantom/runtime.js +1067 -0
  61. package/dist/phantom/runtime.js.map +1 -0
  62. package/package.json +2 -2
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <h1>🧬 Nexus Prime</h1>
3
3
  <p><strong>The Cognitive Operating System for Multi-Agent Swarms</strong></p>
4
4
 
5
- [![Version](https://img.shields.io/badge/version-3.0.0-00ff88?style=for-the-badge&logoRepository=nexus-prime)](https://github.com/sir-ad/nexus-prime/releases)
5
+ [![Version](https://img.shields.io/badge/version-3.2.0-00ff88?style=for-the-badge&logoRepository=nexus-prime)](https://github.com/sir-ad/nexus-prime/releases)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-00d4ff?style=for-the-badge)](LICENSE)
7
7
  [![Agentic OS](https://img.shields.io/badge/Ecosystem-Agentic_OS-8b5cf6?style=for-the-badge)](https://github.com/topics/agentic-os)
8
8
  [![Build Status](https://img.shields.io/badge/build-passing-success?style=for-the-badge)](https://github.com/sir-ad/nexus-prime/actions)
@@ -29,7 +29,7 @@ npx nexus-prime mcp
29
29
 
30
30
  ---
31
31
 
32
- **Nexus Prime** is an autonomous, hyper-optimized, distributed, Byzantine-fault-tolerant cognitive operating system. Exposed as an MCP (Model Context Protocol) server or integrated programmatically, it provides single and multi-agent systems with **permanent memory, mathematically optimized context limits, safety guardrails, and massively parallel Git-worktree execution.**
32
+ **Nexus Prime** is a local-first coding-agent operating system. Exposed as an MCP (Model Context Protocol) server or integrated programmatically, it provides single and multi-agent systems with **persistent memory, selectable runtime backends, guarded live skills, workflow artifacts, a live dashboard, and parallel Git-worktree execution with verification.**
33
33
 
34
34
  ---
35
35
 
@@ -166,10 +166,21 @@ Formulates file-reading as a **Greedy Knapsack Problem**, solving for maximum in
166
166
  ### 3. Phantom Worker Swarms
167
167
  <details>
168
168
  <summary><b>View Details</b></summary>
169
- Parallelize complex tasks using isolated Git Worktrees. Ghost Pass performs read-only risk analysis, while the Merge Oracle evaluates AST diffs using **Byzantine Fault Tolerance consensus**.
169
+ Parallelize complex tasks using isolated Git Worktrees. Ghost Pass performs read-only risk analysis, coder workers execute real file mutations in detached worktrees, verifier workers run build/test commands independently, and the Merge Oracle selects the final patch with an auditable artifact trail.
170
170
  </details>
171
171
 
172
- ### 4. Quantum-Inspired Entanglement (Phase 9A)
172
+ ### 4. Live Skills, Workflows, and Derivation
173
+ <details>
174
+ <summary><b>View Details</b></summary>
175
+ Nexus Prime now ships bundled domain skill packs and workflow packs for **marketing, product, backend, frontend, sales, finance, workflows, and orchestration**. Runs can generate new skills and workflows, deploy them at runtime checkpoints, and promote them only after verifier evidence plus multi-tier consensus.
176
+ </details>
177
+
178
+ ### 5. Runtime Console
179
+ <details>
180
+ <summary><b>View Details</b></summary>
181
+ The built-in dashboard exposes active and recent runs, worker states, verifier results, backend catalogs, skills, workflows, live events, and docs/release health from the same runtime ledger that powers CLI and MCP execution.
182
+ </details>
183
+ ### 6. Quantum-Inspired Entanglement (Phase 9A)
173
184
  <details>
174
185
  <summary><b>View Details</b></summary>
175
186
  Agents share mathematical state in a high-dimensional Hilbert space. When an agent acts, the shared probabilistic state collapses, causing entangled agents to automatically make correlated decisions across the swarm without explicit communication overhead.
@@ -177,7 +188,7 @@ Agents share mathematical state in a high-dimensional Hilbert space. When an age
177
188
 
178
189
  ---
179
190
 
180
- ## 🛠️ MCP Tooling Checklist (v1.5)
191
+ ## 🛠️ MCP Tooling Checklist
181
192
 
182
193
  Nexus Prime exposes 20 native MCP tools that any agent can invoke. Below are key examples:
183
194
 
@@ -186,11 +197,31 @@ Nexus Prime exposes 20 native MCP tools that any agent can invoke. Below are key
186
197
  | `nexus_store_memory` | Store finding/insight | Core |
187
198
  | `nexus_recall_memory` | Semantically recall context | Core |
188
199
  | `nexus_optimize_tokens` | Mathematical context reduction | Optimization |
189
- | `nexus_spawn_workers` | Dispatch parallel swarm | Autonomy |
200
+ | `nexus_spawn_workers` | Execute parallel worktree swarm with verification and artifacts | Autonomy |
190
201
  | `nexus_mindkit_check` | Guardrail validation | Safety |
191
202
  | `nexus_ghost_pass` | Pre-flight risk analysis | Analysis |
203
+ | `nexus_run_status` | Inspect run ledger state | Runtime |
204
+ | `nexus_skill_generate` | Generate deployable runtime skills | Runtime |
205
+ | `nexus_workflow_run` | Execute workflow artifacts | Runtime |
192
206
  | `nexus_entangle` | Measure entangled agent state | Quantum |
193
207
 
208
+ ### Real Runtime Execution
209
+ ```bash
210
+ # Execute a real runtime task with explicit actions
211
+ nexus-prime execute <agent-id> "apply runtime patch" \
212
+ --files README.md package.json \
213
+ --verify "npm run build" \
214
+ --skills backend-playbook orchestration-playbook \
215
+ --workflows backend-execution-loop \
216
+ --compression-backend meta-compression \
217
+ --actions-file ./actions.json
218
+
219
+ # Execute an NXL graph directly
220
+ nexus-prime execute <agent-id> "ship release workflow" --nxl-file ./plan.nxl.yaml
221
+ ```
222
+
223
+ Each run returns a real execution state plus an artifact directory containing manifests, worker diffs, verifier output, and the final merge decision.
224
+
194
225
  ---
195
226
 
196
227
  ## 🚀 Get Started
@@ -9,9 +9,11 @@ export declare class MCPAdapter implements Adapter {
9
9
  private nexusRef?;
10
10
  private telemetry;
11
11
  private sessionDNA;
12
+ private runtime?;
12
13
  private box;
13
14
  constructor();
14
15
  setNexusRef(nexus: NexusPrime): void;
16
+ private getRuntime;
15
17
  private setupToolHandlers;
16
18
  private handleToolCall;
17
19
  scanSourceFiles(cwd: string): string[];
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../../src/agents/adapters/mcp.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAsK5C,qBAAa,UAAW,YAAW,OAAO;IACtC,IAAI,SAAS;IACb,IAAI,EAAG,KAAK,CAAU;IACtB,SAAS,UAAS;IAClB,MAAM,EAAE,MAAM,EAAE,CAAM;IAEtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAC,CAAa;IAC9B,OAAO,CAAC,SAAS,CAA4C;IAC7D,OAAO,CAAC,UAAU,CAAoB;IAEtC,OAAO,CAAC,GAAG;;IAkBX,WAAW,CAAC,KAAK,EAAE,UAAU;IAI7B,OAAO,CAAC,iBAAiB;YAiWX,cAAc;IAq0B5B,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE;IAItC,OAAO,CAAC,IAAI;IAmBN,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAOxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB3B,IAAI,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IACnD,OAAO,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;CAC1C"}
1
+ {"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../../src/agents/adapters/mcp.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AA0K5C,qBAAa,UAAW,YAAW,OAAO;IACtC,IAAI,SAAS;IACb,IAAI,EAAG,KAAK,CAAU;IACtB,SAAS,UAAS;IAClB,MAAM,EAAE,MAAM,EAAE,CAAM;IAEtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAC,CAAa;IAC9B,OAAO,CAAC,SAAS,CAA4C;IAC7D,OAAO,CAAC,UAAU,CAAoB;IACtC,OAAO,CAAC,OAAO,CAAC,CAAkB;IAElC,OAAO,CAAC,GAAG;;IAkBX,WAAW,CAAC,KAAK,EAAE,UAAU;IAI7B,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,iBAAiB;YAgcX,cAAc;IAk/B5B,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE;IAItC,OAAO,CAAC,IAAI;IAmBN,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAOxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB3B,IAAI,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IACnD,OAAO,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;CAC1C"}
@@ -1,12 +1,11 @@
1
1
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
2
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3
3
  import { CallToolRequestSchema, ErrorCode, ListToolsRequestSchema, McpError, } from '@modelcontextprotocol/sdk/types.js';
4
- import { statSync, readdirSync, readFileSync } from 'fs';
4
+ import { statSync, readdirSync } from 'fs';
5
5
  import * as path from 'path';
6
6
  import { fileURLToPath } from 'url';
7
7
  import { TokenSupremacyEngine, formatReadingPlan } from '../../engines/token-supremacy.js';
8
- import { GhostPass, PhantomWorker } from '../../phantom/index.js';
9
- import { MergeOracle } from '../../phantom/merge-oracle.js';
8
+ import { GhostPass, createSubAgentRuntime, summarizeExecution, } from '../../phantom/index.js';
10
9
  import { GuardrailEngine } from '../../engines/guardrails-bridge.js';
11
10
  import { SessionDNAManager } from '../../engines/session-dna.js';
12
11
  import { ContextAssembler } from '../../engines/context-assembler.js';
@@ -28,6 +27,7 @@ const casEngine = new ContinuousAttentionStream();
28
27
  const kvBridge = createKVBridge({ agents: 3 });
29
28
  const orchestrator = new OrchestratorEngine();
30
29
  const federation = new FederationEngine();
30
+ const fallbackRuntime = createSubAgentRuntime({ repoRoot: process.cwd() });
31
31
  // Lazy-initialized Graph Engine (separate DB from core memory)
32
32
  let _graphEngine = null;
33
33
  let _traversalEngine = null;
@@ -156,6 +156,7 @@ export class MCPAdapter {
156
156
  nexusRef;
157
157
  telemetry = new SessionTelemetry();
158
158
  sessionDNA;
159
+ runtime;
159
160
  box(title, content, color = '34') {
160
161
  const width = 68;
161
162
  console.error(`\n\x1b[${color}m┌─ ${title} ${'─'.repeat(Math.max(0, width - title.length - 4))}┐\x1b[0m`);
@@ -172,6 +173,15 @@ export class MCPAdapter {
172
173
  setNexusRef(nexus) {
173
174
  this.nexusRef = nexus;
174
175
  }
176
+ getRuntime() {
177
+ if (this.nexusRef && typeof this.nexusRef.getRuntime === 'function') {
178
+ return this.nexusRef.getRuntime();
179
+ }
180
+ if (!this.runtime) {
181
+ this.runtime = fallbackRuntime;
182
+ }
183
+ return this.runtime;
184
+ }
175
185
  setupToolHandlers() {
176
186
  this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
177
187
  tools: [
@@ -262,13 +272,22 @@ export class MCPAdapter {
262
272
  },
263
273
  {
264
274
  name: 'nexus_spawn_workers',
265
- description: 'Spawn parallel Phantom Workers when modifying 3+ interrelated files OR when Ghost Pass recommends parallel exploration. Each worker gets an isolated git worktree to independently analyze the goal. Workers sync via POD Network. Returns a synthesized merge decision with confidence score and recommended approach.',
275
+ description: 'Spawn parallel Phantom Workers when modifying 3+ interrelated files OR when Ghost Pass recommends parallel exploration. Each worker gets an isolated git worktree to execute actions, run verification, and return artifacts. The runtime applies merge consensus and reports the final decision truthfully.',
266
276
  inputSchema: {
267
277
  type: 'object',
268
278
  properties: {
269
279
  goal: { type: 'string', description: 'The overall goal for the swarm' },
270
280
  files: { type: 'array', items: { type: 'string' }, description: 'Files relevant to the task' },
271
- workers: { type: 'number', description: 'Number of phantom workers to spawn (max 7)', default: 3 }
281
+ workers: { type: 'number', description: 'Number of phantom workers to spawn (max 7)', default: 3 },
282
+ verify: { type: 'array', items: { type: 'string' }, description: 'Verification commands to run in verifier worktrees' },
283
+ strategies: { type: 'array', items: { type: 'string' }, description: 'Optional worker strategies such as minimal, standard, thorough' },
284
+ actions: { type: 'array', items: { type: 'object' }, description: 'Optional runtime actions or skill bindings to execute in worker worktrees' },
285
+ skills: { type: 'array', items: { type: 'string' }, description: 'Runtime skill selectors' },
286
+ workflows: { type: 'array', items: { type: 'string' }, description: 'Workflow selectors' },
287
+ memoryBackend: { type: 'string', description: 'Memory backend selector' },
288
+ compressionBackend: { type: 'string', description: 'Compression backend selector' },
289
+ dslCompiler: { type: 'string', description: 'DSL compiler selector' },
290
+ backendMode: { type: 'string', enum: ['default', 'shadow', 'experimental'], description: 'Backend execution mode' }
272
291
  },
273
292
  required: ['goal', 'files'],
274
293
  },
@@ -338,6 +357,92 @@ export class MCPAdapter {
338
357
  required: ['card'],
339
358
  },
340
359
  },
360
+ {
361
+ name: 'nexus_skill_generate',
362
+ description: 'Generate a live runtime skill artifact that can be deployed to future runs or promoted after evidence-backed execution.',
363
+ inputSchema: {
364
+ type: 'object',
365
+ properties: {
366
+ name: { type: 'string', description: 'Skill name' },
367
+ instructions: { type: 'string', description: 'Instructions for the generated skill' },
368
+ riskClass: { type: 'string', enum: ['read', 'orchestrate', 'mutate'], description: 'Risk class for the skill' },
369
+ scope: { type: 'string', enum: ['session', 'worker', 'global'], description: 'Initial scope for the skill' }
370
+ },
371
+ required: ['name', 'instructions'],
372
+ },
373
+ },
374
+ {
375
+ name: 'nexus_skill_deploy',
376
+ description: 'Promote or deploy a live runtime skill artifact so future runs can activate it.',
377
+ inputSchema: {
378
+ type: 'object',
379
+ properties: {
380
+ skillId: { type: 'string', description: 'Skill artifact ID or exact name' },
381
+ scope: { type: 'string', enum: ['session', 'worker', 'global'], description: 'Deployment scope' }
382
+ },
383
+ required: ['skillId'],
384
+ },
385
+ },
386
+ {
387
+ name: 'nexus_skill_revoke',
388
+ description: 'Revoke a live runtime skill artifact.',
389
+ inputSchema: {
390
+ type: 'object',
391
+ properties: {
392
+ skillId: { type: 'string', description: 'Skill artifact ID or exact name' }
393
+ },
394
+ required: ['skillId'],
395
+ },
396
+ },
397
+ {
398
+ name: 'nexus_workflow_generate',
399
+ description: 'Generate a workflow artifact that can be deployed to runs or promoted through runtime evidence.',
400
+ inputSchema: {
401
+ type: 'object',
402
+ properties: {
403
+ name: { type: 'string', description: 'Workflow name' },
404
+ description: { type: 'string', description: 'Workflow description' },
405
+ domain: { type: 'string', description: 'Optional workflow domain' },
406
+ scope: { type: 'string', enum: ['session', 'worker', 'global'], description: 'Initial workflow scope' }
407
+ },
408
+ required: ['name', 'description'],
409
+ },
410
+ },
411
+ {
412
+ name: 'nexus_workflow_deploy',
413
+ description: 'Deploy or promote a workflow artifact for future runs.',
414
+ inputSchema: {
415
+ type: 'object',
416
+ properties: {
417
+ workflowId: { type: 'string', description: 'Workflow artifact ID or exact name' },
418
+ scope: { type: 'string', enum: ['session', 'worker', 'global'], description: 'Deployment scope' }
419
+ },
420
+ required: ['workflowId'],
421
+ },
422
+ },
423
+ {
424
+ name: 'nexus_workflow_run',
425
+ description: 'Run a workflow artifact through the real execution runtime.',
426
+ inputSchema: {
427
+ type: 'object',
428
+ properties: {
429
+ workflowId: { type: 'string', description: 'Workflow artifact ID or exact name' },
430
+ goal: { type: 'string', description: 'Optional override goal' }
431
+ },
432
+ required: ['workflowId'],
433
+ },
434
+ },
435
+ {
436
+ name: 'nexus_run_status',
437
+ description: 'Return the current recorded state of a runtime execution run.',
438
+ inputSchema: {
439
+ type: 'object',
440
+ properties: {
441
+ runId: { type: 'string', description: 'Execution run ID' }
442
+ },
443
+ required: ['runId'],
444
+ },
445
+ },
341
446
  // ── Darwin Loop ──────────────────────────────────────────────────
342
447
  {
343
448
  name: 'nexus_darwin_propose',
@@ -474,7 +579,7 @@ export class MCPAdapter {
474
579
  // ── Nexus Layer (v1.5) ──────────────────────────────────────────
475
580
  {
476
581
  name: 'nexus_execute_nxl',
477
- description: 'Execute a declarative Nexus Language (NXL) script or induce an army of specialized agents for a goal.',
582
+ description: 'Execute a declarative Nexus Language (NXL) script as a real runtime graph across worktree-backed sub-agents, verification workers, and merge consensus.',
478
583
  inputSchema: {
479
584
  type: 'object',
480
585
  properties: {
@@ -736,75 +841,92 @@ export class MCPAdapter {
736
841
  const rawFiles = Array.isArray(request.params.arguments?.files)
737
842
  ? request.params.arguments.files.map(String)
738
843
  : [];
739
- const files = rawFiles.map(p => {
740
- try {
741
- const stat = statSync(p);
742
- return { path: p, sizeBytes: stat.size, lastModified: stat.mtimeMs };
743
- }
744
- catch {
745
- return { path: p, sizeBytes: 0 };
844
+ const verifyCommands = Array.isArray(request.params.arguments?.verify)
845
+ ? request.params.arguments.verify.map(String)
846
+ : undefined;
847
+ const strategies = Array.isArray(request.params.arguments?.strategies)
848
+ ? request.params.arguments.strategies.map(String)
849
+ : undefined;
850
+ const actions = Array.isArray(request.params.arguments?.actions)
851
+ ? request.params.arguments.actions
852
+ : [];
853
+ const skills = Array.isArray(request.params.arguments?.skills)
854
+ ? request.params.arguments.skills.map(String)
855
+ : undefined;
856
+ const workflows = Array.isArray(request.params.arguments?.workflows)
857
+ ? request.params.arguments.workflows.map(String)
858
+ : undefined;
859
+ const memoryBackend = request.params.arguments?.memoryBackend
860
+ ? String(request.params.arguments.memoryBackend)
861
+ : undefined;
862
+ const compressionBackend = request.params.arguments?.compressionBackend
863
+ ? String(request.params.arguments.compressionBackend)
864
+ : undefined;
865
+ const dslCompiler = request.params.arguments?.dslCompiler
866
+ ? String(request.params.arguments.dslCompiler)
867
+ : undefined;
868
+ const backendMode = request.params.arguments?.backendMode
869
+ ? String(request.params.arguments.backendMode)
870
+ : undefined;
871
+ const execution = await this.getRuntime().run({
872
+ goal,
873
+ files: rawFiles,
874
+ workers: workersCount,
875
+ roles: ['planner', 'coder', 'verifier', 'skill-maker', 'research-shadow'],
876
+ verifyCommands,
877
+ strategies,
878
+ actions,
879
+ skillNames: skills,
880
+ workflowSelectors: workflows,
881
+ backendSelectors: { memoryBackend, compressionBackend, dslCompiler },
882
+ backendMode,
883
+ });
884
+ const verifiedWorkers = execution.workerResults.filter(result => result.verified).length;
885
+ const modifiedFiles = execution.workerResults.reduce((sum, result) => sum + result.modifiedFiles.length, 0);
886
+ execution.activeSkills.forEach(skill => {
887
+ this.sessionDNA.recordSkill(skill.name);
888
+ if (skill.scope === 'global' || skill.rolloutStatus === 'promoted') {
889
+ this.sessionDNA.recordSkillLearned(skill.name);
746
890
  }
747
891
  });
748
- const ghost = new GhostPass(process.cwd());
749
- const report = await ghost.analyze(goal, files, workersCount);
750
- // Multi-process dispatch with worktree-isolated execution
751
- const workerPromises = report.workerAssignments.map(async (assign) => {
752
- const worker = new PhantomWorker(process.cwd());
753
- return worker.spawn(assign, async (worktreeDir, task, w) => {
754
- const learnings = [];
755
- // Read relevant files in the worktree to build context
756
- for (const file of task.files.slice(0, 5)) {
757
- try {
758
- const fullPath = path.join(worktreeDir, file.path);
759
- const content = readFileSync(fullPath, 'utf-8').slice(0, 500);
760
- learnings.push(`[${task.approach}] Read ${file.path}: ${content.length} chars`);
761
- }
762
- catch {
763
- learnings.push(`[${task.approach}] Could not read ${file.path}`);
764
- }
765
- }
766
- // Broadcast discovery to POD network for cross-worker learning
767
- w.broadcast(`Worker ${w.id} (${task.approach}): analyzed ${task.files.length} files`, 0.7, ['#phantom-swarm', `#approach-${task.approach}`]);
768
- nexusEventBus.emit('phantom.worker.start', { workerId: `W-${w.id}`, approach: task.approach, goal });
769
- // Check what other workers found
770
- const peerFindings = w.receive(['#phantom-swarm']);
771
- if (peerFindings.length > 0) {
772
- learnings.push(`Received ${peerFindings.length} findings from peer workers`);
773
- }
774
- const confidence = learnings.length > 0 ? 0.75 : 0.5;
775
- nexusEventBus.emit('phantom.worker.complete', { workerId: `W-${w.id}`, confidence });
776
- return {
777
- learnings,
778
- confidence,
779
- };
780
- });
892
+ execution.workerResults.forEach(result => {
893
+ result.modifiedFiles.forEach(file => this.sessionDNA.recordFileModified(file));
781
894
  });
782
- const results = await Promise.all(workerPromises);
783
- // Synthesis
784
- const oracle = new MergeOracle(this.nexusRef.memory);
785
- const decision = await oracle.merge(results);
786
- this.nexusRef.storeMemory(`Phantom Swarm executed: ${results.length} workers, action=${decision.action}, confidence=${decision.confidence.toFixed(2)}`, 0.8, ['#phantom-swarm', '#decision']);
787
- nexusEventBus.emit('phantom.merge', { action: decision.action, winner: decision.recommendedStrategy });
788
- // NEW: Agent Learning Loop
789
- await this.nexusRef.analyzeLearning(goal, decision);
790
- // Console ASCII UI
791
- this.box('🐝 PHANTOM SWARM MERGED', [
792
- `Workers: ${results.length.toString().padEnd(5, ' ')} Confidence: ${decision.confidence.toFixed(2).padEnd(36)}`,
793
- `Action: ${decision.action.padEnd(57, ' ')}`
794
- ], '32');
895
+ this.sessionDNA.recordDecision('Runtime swarm execution completed', execution.result || summarizeExecution(execution), execution.state === 'merged' ? 0.94 : execution.state === 'rolled_back' ? 0.45 : 0.3);
896
+ this.nexusRef.storeMemory(`Runtime swarm: state=${execution.state}, workers=${execution.workerResults.length}, verified=${verifiedWorkers}, decision=${execution.finalDecision?.action ?? 'none'}`, execution.state === 'merged' ? 0.92 : 0.72, ['#phantom', '#decision', execution.state]);
897
+ if (execution.finalDecision) {
898
+ nexusEventBus.emit('phantom.merge', {
899
+ action: execution.finalDecision.action,
900
+ winner: execution.finalDecision.recommendedStrategy,
901
+ });
902
+ await this.nexusRef.analyzeLearning(goal, execution.finalDecision);
903
+ }
904
+ this.box('🐝 PHANTOM RUNTIME', [
905
+ `Run: ${execution.runId.padEnd(28, ' ')} State: ${execution.state.padEnd(18, ' ')}`,
906
+ `Workers: ${execution.workerResults.length.toString().padEnd(5, ' ')} Verified: ${verifiedWorkers.toString().padEnd(10, ' ')} Files: ${String(modifiedFiles).padEnd(12, ' ')}`,
907
+ `Decision: ${(execution.finalDecision?.action ?? 'none').padEnd(52, ' ')}`
908
+ ], execution.state === 'merged' ? '32' : execution.state === 'rolled_back' ? '33' : '31');
795
909
  return {
796
910
  content: [{
797
911
  type: 'text',
798
912
  text: [
799
- `🐝 Phantom Swarm Complete — ${results.length} workers synchronized.`,
800
- '',
801
- `🎯 Goal: ${goal}`,
913
+ `🐝 Phantom Runtime — ${summarizeExecution(execution)}`,
802
914
  '',
803
- `🧩 Synthesized Decision:`,
804
- decision.synthesized || 'No changes made.',
915
+ `Run ID: ${execution.runId}`,
916
+ `State: ${execution.state}`,
917
+ `Artifacts: ${execution.artifactsPath}`,
918
+ `Workers: ${execution.workerResults.length}`,
919
+ `Verified Workers: ${verifiedWorkers}`,
920
+ `Modified Files: ${modifiedFiles}`,
921
+ `Decision: ${execution.finalDecision?.action ?? 'none'}`,
922
+ `Recommended Strategy: ${execution.finalDecision?.recommendedStrategy ?? 'n/a'}`,
923
+ `Planner: ${execution.plannerResult?.summary ?? 'n/a'}`,
924
+ `Backends: memory=${execution.selectedBackends.memoryBackend}, compression=${execution.selectedBackends.compressionBackend}, consensus=${execution.selectedBackends.consensusPolicy}, dsl=${execution.selectedBackends.dslCompiler}`,
925
+ `Active Skills: ${execution.activeSkills.length > 0 ? execution.activeSkills.map(skill => `${skill.name}(${skill.riskClass})`).join(', ') : 'none'}`,
926
+ `Active Workflows: ${execution.activeWorkflows.length > 0 ? execution.activeWorkflows.map(workflow => workflow.name).join(', ') : 'none'}`,
927
+ `Promotions: ${execution.promotionDecisions.length > 0 ? execution.promotionDecisions.map(decision => `${decision.kind}:${decision.target}:${decision.approved ? 'approved' : 'held'}`).join(', ') : 'none'}`,
805
928
  '',
806
- `📝 Conflicts: ${decision.conflicts.length > 0 ? decision.conflicts.join(', ') : 'None'}`,
807
- `📈 Strategy: ${decision.recommendedStrategy}`
929
+ `Result: ${execution.result}`
808
930
  ].join('\n')
809
931
  }]
810
932
  };
@@ -972,6 +1094,127 @@ export class MCPAdapter {
972
1094
  }]
973
1095
  };
974
1096
  }
1097
+ case 'nexus_skill_generate': {
1098
+ const name = String(request.params.arguments?.name ?? '');
1099
+ const instructions = String(request.params.arguments?.instructions ?? '');
1100
+ const riskClass = String(request.params.arguments?.riskClass ?? 'orchestrate');
1101
+ const scope = String(request.params.arguments?.scope ?? 'session');
1102
+ const artifact = this.getRuntime().generateSkill({ name, instructions, riskClass, scope, provenance: 'mcp:generate' });
1103
+ this.sessionDNA.recordSkillLearned(artifact.name);
1104
+ return {
1105
+ content: [{
1106
+ type: 'text',
1107
+ text: `🧠 Runtime skill generated\nID: ${artifact.skillId}\nName: ${artifact.name}\nRisk: ${artifact.riskClass}\nScope: ${artifact.scope}\nProvenance: ${artifact.provenance}`,
1108
+ }],
1109
+ };
1110
+ }
1111
+ case 'nexus_skill_deploy': {
1112
+ const skillId = String(request.params.arguments?.skillId ?? '');
1113
+ const scope = String(request.params.arguments?.scope ?? 'session');
1114
+ const runtime = this.getRuntime();
1115
+ const known = runtime.listSkills().find((skill) => skill.skillId === skillId || skill.name === skillId);
1116
+ const artifact = known ? runtime.deploySkill(known.skillId, scope) : undefined;
1117
+ if (!artifact) {
1118
+ return { content: [{ type: 'text', text: `❌ Skill not found: ${skillId}` }] };
1119
+ }
1120
+ this.sessionDNA.recordSkill(artifact.name);
1121
+ return {
1122
+ content: [{
1123
+ type: 'text',
1124
+ text: `🚚 Runtime skill deployed\nID: ${artifact.skillId}\nName: ${artifact.name}\nScope: ${artifact.scope}\nRollout: ${artifact.rolloutStatus}`,
1125
+ }],
1126
+ };
1127
+ }
1128
+ case 'nexus_skill_revoke': {
1129
+ const skillId = String(request.params.arguments?.skillId ?? '');
1130
+ const runtime = this.getRuntime();
1131
+ const known = runtime.listSkills().find((skill) => skill.skillId === skillId || skill.name === skillId);
1132
+ const artifact = known ? runtime.revokeSkill(known.skillId) : undefined;
1133
+ if (!artifact) {
1134
+ return { content: [{ type: 'text', text: `❌ Skill not found: ${skillId}` }] };
1135
+ }
1136
+ return {
1137
+ content: [{
1138
+ type: 'text',
1139
+ text: `🧯 Runtime skill revoked\nID: ${artifact.skillId}\nName: ${artifact.name}\nRollout: ${artifact.rolloutStatus}`,
1140
+ }],
1141
+ };
1142
+ }
1143
+ case 'nexus_workflow_generate': {
1144
+ const name = String(request.params.arguments?.name ?? '');
1145
+ const description = String(request.params.arguments?.description ?? '');
1146
+ const domain = request.params.arguments?.domain ? String(request.params.arguments?.domain) : undefined;
1147
+ const scope = String(request.params.arguments?.scope ?? 'session');
1148
+ const artifact = this.getRuntime().generateWorkflow({ name, description, domain, scope });
1149
+ return {
1150
+ content: [{
1151
+ type: 'text',
1152
+ text: `🧭 Workflow generated\nID: ${artifact.workflowId}\nName: ${artifact.name}\nDomain: ${artifact.domain}\nScope: ${artifact.scope}`,
1153
+ }],
1154
+ };
1155
+ }
1156
+ case 'nexus_workflow_deploy': {
1157
+ const workflowId = String(request.params.arguments?.workflowId ?? '');
1158
+ const scope = String(request.params.arguments?.scope ?? 'session');
1159
+ const runtime = this.getRuntime();
1160
+ const known = runtime.listWorkflows().find((workflow) => workflow.workflowId === workflowId || workflow.name === workflowId);
1161
+ const artifact = known ? runtime.deployWorkflow(known.workflowId, scope) : undefined;
1162
+ if (!artifact) {
1163
+ return { content: [{ type: 'text', text: `❌ Workflow not found: ${workflowId}` }] };
1164
+ }
1165
+ return {
1166
+ content: [{
1167
+ type: 'text',
1168
+ text: `🚚 Workflow deployed\nID: ${artifact.workflowId}\nName: ${artifact.name}\nScope: ${artifact.scope}\nRollout: ${artifact.rolloutStatus}`,
1169
+ }],
1170
+ };
1171
+ }
1172
+ case 'nexus_workflow_run': {
1173
+ const workflowId = String(request.params.arguments?.workflowId ?? '');
1174
+ const goalOverride = request.params.arguments?.goal ? String(request.params.arguments.goal) : undefined;
1175
+ try {
1176
+ const execution = await this.getRuntime().runWorkflow(workflowId, goalOverride);
1177
+ return {
1178
+ content: [{
1179
+ type: 'text',
1180
+ text: [
1181
+ `🧭 Workflow Runtime — ${summarizeExecution(execution)}`,
1182
+ `Run ID: ${execution.runId}`,
1183
+ `Artifacts: ${execution.artifactsPath}`,
1184
+ `Decision: ${execution.finalDecision?.action ?? 'none'}`,
1185
+ `Workflows: ${execution.activeWorkflows.map((workflow) => workflow.name).join(', ') || 'none'}`,
1186
+ `Result: ${execution.result}`,
1187
+ ].join('\n'),
1188
+ }],
1189
+ };
1190
+ }
1191
+ catch (error) {
1192
+ return { content: [{ type: 'text', text: `❌ Workflow runtime error: ${error.message}` }] };
1193
+ }
1194
+ }
1195
+ case 'nexus_run_status': {
1196
+ const runId = String(request.params.arguments?.runId ?? '');
1197
+ const run = this.getRuntime().getRun(runId);
1198
+ if (!run) {
1199
+ return { content: [{ type: 'text', text: `❌ Run not found: ${runId}` }] };
1200
+ }
1201
+ return {
1202
+ content: [{
1203
+ type: 'text',
1204
+ text: JSON.stringify({
1205
+ runId: run.runId,
1206
+ state: run.state,
1207
+ result: run.result,
1208
+ artifactsPath: run.artifactsPath,
1209
+ workers: run.workerResults.length,
1210
+ verifiedWorkers: run.workerResults.filter((worker) => worker.verified).length,
1211
+ workflows: run.activeWorkflows.map((workflow) => workflow.name),
1212
+ promotions: run.promotionDecisions,
1213
+ backends: run.selectedBackends,
1214
+ }, null, 2),
1215
+ }],
1216
+ };
1217
+ }
975
1218
  case 'nexus_darwin_propose': {
976
1219
  const hypothesis = String(request.params.arguments?.hypothesis ?? '');
977
1220
  const targetFile = String(request.params.arguments?.targetFile ?? '');
@@ -1204,22 +1447,49 @@ export class MCPAdapter {
1204
1447
  return { content: [{ type: 'text', text: `❌ NXL Parse Error: ${e.message}` }] };
1205
1448
  }
1206
1449
  }
1207
- const swarm = await orchestrator.executeSwarm(goal);
1208
- const lines = [
1209
- `Goal: ${goal.substring(0, 60)}...`,
1210
- '─'.repeat(66)
1211
- ];
1212
- swarm.agents.forEach((agent, idx) => {
1213
- const prefix = idx === swarm.agents.length - 1 ? '└──' : '├──';
1214
- lines.push(`${prefix} [${agent.archetype?.name}] as ${agent.type.substring(0, 42)}`);
1215
- });
1216
- this.box('🚀 NEXUS SWARM INDUCTED', lines, '34');
1217
- return {
1218
- content: [{
1219
- type: 'text',
1220
- text: `🚀 Nexus Swarm Activated: ${swarm.agents.length} specialized sub-agents induced for: ${goal}\nCheck CLI for worker mapping.`
1221
- }]
1222
- };
1450
+ try {
1451
+ const execution = await this.getRuntime().runNXL(goal, nxlScript || undefined, useCase);
1452
+ const verifiedWorkers = execution.workerResults.filter(result => result.verified).length;
1453
+ execution.activeSkills.forEach(skill => this.sessionDNA.recordSkill(skill.name));
1454
+ execution.workerResults.forEach(result => {
1455
+ result.modifiedFiles.forEach(file => this.sessionDNA.recordFileModified(file));
1456
+ });
1457
+ this.sessionDNA.recordDecision('NXL execution graph completed', execution.result || summarizeExecution(execution), execution.state === 'merged' ? 0.95 : execution.state === 'rolled_back' ? 0.5 : 0.28);
1458
+ this.nexusRef.storeMemory(`NXL runtime: state=${execution.state}, workers=${execution.workerResults.length}, verified=${verifiedWorkers}, useCase=${useCase}`, execution.state === 'merged' ? 0.94 : 0.74, ['#nxl', '#decision', execution.state]);
1459
+ if (execution.finalDecision) {
1460
+ await this.nexusRef.analyzeLearning(goal, execution.finalDecision);
1461
+ }
1462
+ this.box('🚀 NXL RUNTIME GRAPH', [
1463
+ `Goal: ${goal.substring(0, 60).padEnd(60, ' ')}`,
1464
+ `Run: ${execution.runId.padEnd(28, ' ')} State: ${execution.state.padEnd(18, ' ')}`,
1465
+ `Workers: ${execution.workerResults.length.toString().padEnd(5, ' ')} Verified: ${verifiedWorkers.toString().padEnd(10, ' ')}`
1466
+ ], execution.state === 'merged' ? '32' : execution.state === 'rolled_back' ? '33' : '31');
1467
+ return {
1468
+ content: [{
1469
+ type: 'text',
1470
+ text: [
1471
+ `🚀 NXL Runtime — ${summarizeExecution(execution)}`,
1472
+ '',
1473
+ `Run ID: ${execution.runId}`,
1474
+ `Use Case: ${useCase}`,
1475
+ `Artifacts: ${execution.artifactsPath}`,
1476
+ `Workers: ${execution.workerResults.length}`,
1477
+ `Verified Workers: ${verifiedWorkers}`,
1478
+ `Decision: ${execution.finalDecision?.action ?? 'none'}`,
1479
+ `Planner: ${execution.plannerResult?.summary ?? 'n/a'}`,
1480
+ `Backends: memory=${execution.selectedBackends.memoryBackend}, compression=${execution.selectedBackends.compressionBackend}, consensus=${execution.selectedBackends.consensusPolicy}, dsl=${execution.selectedBackends.dslCompiler}`,
1481
+ `Active Skills: ${execution.activeSkills.length > 0 ? execution.activeSkills.map(skill => skill.name).join(', ') : 'none'}`,
1482
+ `Active Workflows: ${execution.activeWorkflows.length > 0 ? execution.activeWorkflows.map(workflow => workflow.name).join(', ') : 'none'}`,
1483
+ `Promotions: ${execution.promotionDecisions.length > 0 ? execution.promotionDecisions.map(decision => `${decision.kind}:${decision.target}:${decision.approved ? 'approved' : 'held'}`).join(', ') : 'none'}`,
1484
+ '',
1485
+ `Result: ${execution.result}`
1486
+ ].join('\n')
1487
+ }]
1488
+ };
1489
+ }
1490
+ catch (e) {
1491
+ return { content: [{ type: 'text', text: `❌ NXL Runtime Error: ${e.message}` }] };
1492
+ }
1223
1493
  }
1224
1494
  case 'nexus_publish_trace': {
1225
1495
  const taskId = String(request.params.arguments?.taskId ?? '');
@@ -1266,7 +1536,7 @@ export class MCPAdapter {
1266
1536
  const transport = new StdioServerTransport();
1267
1537
  await this.server.connect(transport);
1268
1538
  this.connected = true;
1269
- console.error('[MCP Adapter] Connected — 16 tools active');
1539
+ console.error('[MCP Adapter] Connected — runtime tools active');
1270
1540
  }
1271
1541
  async disconnect() {
1272
1542
  // Auto-flush Session DNA on disconnect