nexus-prime 3.15.1 → 3.17.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.
- package/README.md +32 -7
- package/dist/agents/adapters/mcp.d.ts +0 -1
- package/dist/agents/adapters/mcp.d.ts.map +1 -1
- package/dist/agents/adapters/mcp.js +115 -43
- package/dist/agents/adapters/mcp.js.map +1 -1
- package/dist/cli.js +101 -22
- package/dist/cli.js.map +1 -1
- package/dist/dashboard/index.html +282 -5
- package/dist/dashboard/server.d.ts +1 -0
- package/dist/dashboard/server.d.ts.map +1 -1
- package/dist/dashboard/server.js +51 -3
- package/dist/dashboard/server.js.map +1 -1
- package/dist/engines/client-bootstrap.d.ts +6 -1
- package/dist/engines/client-bootstrap.d.ts.map +1 -1
- package/dist/engines/client-bootstrap.js +129 -22
- package/dist/engines/client-bootstrap.js.map +1 -1
- package/dist/engines/compaction-sentinel.d.ts +20 -0
- package/dist/engines/compaction-sentinel.d.ts.map +1 -0
- package/dist/engines/compaction-sentinel.js +58 -0
- package/dist/engines/compaction-sentinel.js.map +1 -0
- package/dist/engines/context-assembler.d.ts +2 -0
- package/dist/engines/context-assembler.d.ts.map +1 -1
- package/dist/engines/context-assembler.js +8 -0
- package/dist/engines/context-assembler.js.map +1 -1
- package/dist/engines/context-compressor.d.ts +32 -0
- package/dist/engines/context-compressor.d.ts.map +1 -0
- package/dist/engines/context-compressor.js +132 -0
- package/dist/engines/context-compressor.js.map +1 -0
- package/dist/engines/event-bus.d.ts +30 -1
- package/dist/engines/event-bus.d.ts.map +1 -1
- package/dist/engines/event-bus.js.map +1 -1
- package/dist/engines/federation.d.ts +1 -0
- package/dist/engines/federation.d.ts.map +1 -1
- package/dist/engines/federation.js +13 -0
- package/dist/engines/federation.js.map +1 -1
- package/dist/engines/hook-runtime.d.ts.map +1 -1
- package/dist/engines/hook-runtime.js +11 -0
- package/dist/engines/hook-runtime.js.map +1 -1
- package/dist/engines/index.d.ts +2 -0
- package/dist/engines/index.d.ts.map +1 -1
- package/dist/engines/index.js +2 -0
- package/dist/engines/index.js.map +1 -1
- package/dist/engines/memory-background.d.ts +14 -0
- package/dist/engines/memory-background.d.ts.map +1 -0
- package/dist/engines/memory-background.js +35 -0
- package/dist/engines/memory-background.js.map +1 -0
- package/dist/engines/memory.d.ts +21 -1
- package/dist/engines/memory.d.ts.map +1 -1
- package/dist/engines/memory.js +61 -2
- package/dist/engines/memory.js.map +1 -1
- package/dist/engines/orchestrator.d.ts +11 -0
- package/dist/engines/orchestrator.d.ts.map +1 -1
- package/dist/engines/orchestrator.js +161 -30
- package/dist/engines/orchestrator.js.map +1 -1
- package/dist/engines/peer-connectors.d.ts +15 -0
- package/dist/engines/peer-connectors.d.ts.map +1 -0
- package/dist/engines/peer-connectors.js +59 -0
- package/dist/engines/peer-connectors.js.map +1 -0
- package/dist/engines/pod-network.d.ts +16 -0
- package/dist/engines/pod-network.d.ts.map +1 -1
- package/dist/engines/pod-network.js +31 -0
- package/dist/engines/pod-network.js.map +1 -1
- package/dist/engines/repo-tree.d.ts +18 -0
- package/dist/engines/repo-tree.d.ts.map +1 -0
- package/dist/engines/repo-tree.js +57 -0
- package/dist/engines/repo-tree.js.map +1 -0
- package/dist/engines/runtime-assets.d.ts +1 -1
- package/dist/engines/runtime-assets.d.ts.map +1 -1
- package/dist/engines/runtime-assets.js.map +1 -1
- package/dist/engines/session-dna.d.ts +3 -1
- package/dist/engines/session-dna.d.ts.map +1 -1
- package/dist/engines/session-dna.js +6 -2
- package/dist/engines/session-dna.js.map +1 -1
- package/dist/engines/skill-learner.d.ts +8 -0
- package/dist/engines/skill-learner.d.ts.map +1 -0
- package/dist/engines/skill-learner.js +40 -0
- package/dist/engines/skill-learner.js.map +1 -0
- package/dist/engines/skill-runtime.d.ts +5 -1
- package/dist/engines/skill-runtime.d.ts.map +1 -1
- package/dist/engines/skill-runtime.js +57 -6
- package/dist/engines/skill-runtime.js.map +1 -1
- package/dist/engines/tiered-context.d.ts +18 -0
- package/dist/engines/tiered-context.d.ts.map +1 -0
- package/dist/engines/tiered-context.js +66 -0
- package/dist/engines/tiered-context.js.map +1 -0
- package/dist/engines/token-analytics.d.ts +39 -0
- package/dist/engines/token-analytics.d.ts.map +1 -0
- package/dist/engines/token-analytics.js +75 -0
- package/dist/engines/token-analytics.js.map +1 -0
- package/dist/engines/token-supremacy.d.ts +2 -0
- package/dist/engines/token-supremacy.d.ts.map +1 -1
- package/dist/engines/token-supremacy.js +8 -0
- package/dist/engines/token-supremacy.js.map +1 -1
- package/dist/engines/work-ledger.d.ts +36 -0
- package/dist/engines/work-ledger.d.ts.map +1 -0
- package/dist/engines/work-ledger.js +93 -0
- package/dist/engines/work-ledger.js.map +1 -0
- package/dist/phantom/runtime.d.ts +1 -0
- package/dist/phantom/runtime.d.ts.map +1 -1
- package/dist/phantom/runtime.js +28 -6
- package/dist/phantom/runtime.js.map +1 -1
- package/dist/postinstall-bootstrap.js +53 -12
- package/dist/postinstall-bootstrap.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,7 +68,7 @@ Every coding agent eventually hits the same ceiling. Not model quality — infra
|
|
|
68
68
|
|
|
69
69
|
**Nexus Prime** is a local-first MCP control plane for coding agents. It gives clients a default path that starts with bootstrap context, flows through orchestrated execution, and ends with persisted runtime truth instead of ad-hoc tool chaining.
|
|
70
70
|
|
|
71
|
-
**Website:** [
|
|
71
|
+
**Website:** [nexus-prime.cfd](https://nexus-prime.cfd/)<br>
|
|
72
72
|
**Documentation:** [Catalog](https://sir-ad.github.io/nexus-prime/catalog.html) · [Comparison](https://sir-ad.github.io/nexus-prime/comparison.html) · [Knowledge Base](https://sir-ad.github.io/nexus-prime/knowledge-base.html) · [Integrations](https://sir-ad.github.io/nexus-prime/integrations.html) · [Architecture Diagrams](https://sir-ad.github.io/nexus-prime/architecture-diagrams.html)
|
|
73
73
|
|
|
74
74
|
## ⚡ Quick Install
|
|
@@ -129,12 +129,12 @@ Use `nexus_plan_execution` only when you explicitly want the ledger before mutat
|
|
|
129
129
|
|
|
130
130
|
### 2. Files read without question → Ghost Pass + Token Budgeting
|
|
131
131
|
**Problem:** Agents read 25 files to answer a question that needed 3. No pre-read analysis. No decision about whether a file should even be read.
|
|
132
|
-
**How:** `nexus_ghost_pass` runs a pre-read analysis pass. Source-aware token budgeting then allocates budget across repo, memory, RAG, patterns, and runtime traces — recording what was selected and what was dropped.
|
|
133
|
-
**Proof:** Lifetime token
|
|
132
|
+
**How:** `nexus_ghost_pass` runs a pre-read analysis pass. Source-aware token budgeting then allocates budget across repo, memory, RAG, patterns, and runtime traces — recording what was selected and what was dropped. Tiered context loading (L0/L1/L2) progressively deepens reads based on relevance instead of loading everything at full depth. Background context compaction strips low-signal content while retaining structural elements.
|
|
133
|
+
**Proof:** Lifetime token analytics with per-session breakdowns, compression ratios, and USD savings — persisted in SQLite, surviving restarts.
|
|
134
134
|
|
|
135
135
|
### 3. Memory that grows but never learns → Memory Fabric
|
|
136
136
|
**Problem:** Memory accumulates without decay. Old notes outrank recent updates. No mechanism for deciding what's ephemeral vs. durable.
|
|
137
|
-
**How:** The memory control plane applies fact extraction, reconciliation, quarantine, and vault projection on top of SQLite + graph base. Memories are scored, contradictions detected, and stale facts fade.
|
|
137
|
+
**How:** The memory control plane applies fact extraction, reconciliation, quarantine, and vault projection on top of SQLite + graph base. Memories are scored, contradictions detected, and stale facts fade. A compaction sentinel flushes working memory to durable storage before context window compaction. Background maintenance runs on a 5-minute cycle for entropy-based expiration and deduplication.
|
|
138
138
|
**Proof:** Dashboard exposes memory health, scope, trace, and shared-worker context.
|
|
139
139
|
|
|
140
140
|
### 4. RAG as prompt stuffing → Session-First RAG Gate
|
|
@@ -219,10 +219,10 @@ flowchart TD
|
|
|
219
219
|
## Client Setup and Runtime Contract
|
|
220
220
|
|
|
221
221
|
### Supported MCP Clients
|
|
222
|
-
Nexus Prime provides automated setup for **
|
|
222
|
+
Nexus Prime provides automated setup for **12 coding agents**:
|
|
223
223
|
- 🔴 **Codex**
|
|
224
224
|
- 🔵 **Cursor**
|
|
225
|
-
- 🍊 **Claude Code**
|
|
225
|
+
- 🍊 **Claude Code** (CLI + Desktop + VS Code extension)
|
|
226
226
|
- 🟢 **Opencode**
|
|
227
227
|
- 🌊 **Windsurf**
|
|
228
228
|
- 🛡️ **Antigravity / OpenClaw**
|
|
@@ -230,7 +230,7 @@ Nexus Prime provides automated setup for **9 coding agents**:
|
|
|
230
230
|
- 🔗 **Continue.dev**
|
|
231
231
|
- ⚙️ **Cline**
|
|
232
232
|
|
|
233
|
-
All agent configurations are written automatically on `npm install
|
|
233
|
+
All agent configurations are written automatically on `npm install` with XDG-aware path resolution. The first Nexus run inside a repo writes workspace-scoped client files. `nexus-prime setup <client>` and `nexus-prime setup all` remain the explicit refresh/fix path. Run `nexus-prime setup diagnose` for a dry-run validation of all client paths.
|
|
234
234
|
|
|
235
235
|
### Automated Integration
|
|
236
236
|
```bash
|
|
@@ -626,6 +626,31 @@ Inventory Snapshot: 109 skills · 64 workflows · 5 hooks · 3 automations · 7
|
|
|
626
626
|
## 📜 Release History
|
|
627
627
|
|
|
628
628
|
<details open>
|
|
629
|
+
<summary><b>v3.17.0</b> · 2026-03-20 · Agent adoption hardening, memory readability, atlas code intelligence peer</summary>
|
|
630
|
+
|
|
631
|
+
- **Hard bootstrap enforcement**: Non-bootstrap MCP tool calls return a structured `blocked` response with next-step guidance instead of a soft warning agents ignored. Read-only tools remain exempt.
|
|
632
|
+
- **Atlas code intelligence peer**: Auto-detects Atlas (AST parsing, semantic search, impact analysis) and writes MCP config for all clients when available.
|
|
633
|
+
- **Memory readability**: Fixed text overflow on memory cards/timeline, default-filtered phantom and quarantine noise from dashboard, added phantom toggle.
|
|
634
|
+
- **Imperative tool descriptions**: Rewrote MCP tool descriptions from "Preferred" to "REQUIRED" and planning nudges from "consider" to "Next: call".
|
|
635
|
+
- **Streamlined CLAUDE.md**: 134-line protocol manual → 16-line imperative instruction set. Full protocol moved to `docs/nexus-protocol.md`.
|
|
636
|
+
|
|
637
|
+
Full notes: [CHANGELOG.md](./CHANGELOG.md)
|
|
638
|
+
</details>
|
|
639
|
+
|
|
640
|
+
<details>
|
|
641
|
+
<summary><b>v3.16.0</b> · 2026-03-20 · Compaction sentinel, tiered context, token analytics, peer federation, installation hardening</summary>
|
|
642
|
+
|
|
643
|
+
- **Compaction Sentinel + Tiered Context**: Pre-compaction memory flush and L0/L1/L2 progressive file loading.
|
|
644
|
+
- **Token Analytics**: Lifetime optimization reporting with per-session breakdowns, persisted in SQLite.
|
|
645
|
+
- **Self-Learning Skills + Repo Tree**: Automatic skill derivation and cached repo tree visualization.
|
|
646
|
+
- **Peer Connectors**: Auto-detect and sync with OpenClaw, Hermes, PicoClaw peers.
|
|
647
|
+
- **Installation Hardening**: XDG-aware config, path validation, install logging, `nexus-prime setup diagnose`, 12 client targets.
|
|
648
|
+
- **Multi-Intent Classification**: Orchestrator scores all intents, surfaces secondary when within 80% of primary.
|
|
649
|
+
|
|
650
|
+
Full notes: [CHANGELOG.md](./CHANGELOG.md)
|
|
651
|
+
</details>
|
|
652
|
+
|
|
653
|
+
<details>
|
|
629
654
|
<summary><b>v3.14.0</b> · 2026-03-16 · Ollama/HuggingFace embeddings, autonomous memory, agent ecosystem expansion</summary>
|
|
630
655
|
|
|
631
656
|
- **Embedding backend chain**: Added Ollama and HuggingFace Inference API as embedding backends with automatic fallback (Ollama → HuggingFace → OpenAI → Local TF-IDF).
|
|
@@ -29,7 +29,6 @@ export declare class MCPAdapter implements Adapter {
|
|
|
29
29
|
private decorateToolDescription;
|
|
30
30
|
debugListTools(profile?: McpToolProfile): McpToolDefinition[];
|
|
31
31
|
private buildToolDefinitions;
|
|
32
|
-
private shouldAppendTelemetryFooter;
|
|
33
32
|
private setupToolHandlers;
|
|
34
33
|
private handleToolCall;
|
|
35
34
|
scanSourceFiles(cwd: string): string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../../src/agents/adapters/mcp.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../../src/agents/adapters/mcp.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAiE5C,KAAK,cAAc,GAAG,YAAY,GAAG,MAAM,CAAC;AAC5C,KAAK,iBAAiB,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC,CAAC;AAmKF,qBAAa,UAAW,YAAW,OAAO;IACtC,IAAI,EAAE,MAAM,CAAC;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,cAAc;IA+BtB,OAAO,CAAC,GAAG;;IAmBX,OAAO,CAAC,gBAAgB;IA4BxB,WAAW,CAAC,KAAK,EAAE,UAAU;IAI7B,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,+BAA+B;IAMvC,OAAO,CAAC,uBAAuB;IAqB/B,OAAO,CAAC,uBAAuB;IAsB/B,cAAc,CAAC,OAAO,GAAE,cAAsC,GAAG,iBAAiB,EAAE;IAIpF,OAAO,CAAC,oBAAoB;IA8yB5B,OAAO,CAAC,iBAAiB;YAyFX,cAAc;IAy1D5B,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;IAmB3B,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAClD,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;CACzC"}
|
|
@@ -20,6 +20,7 @@ import { DarwinLoop } from '../../engines/darwin-loop.js';
|
|
|
20
20
|
import { nexusNetRelay } from '../../engines/nexusnet-relay.js';
|
|
21
21
|
import { entanglementEngine, ContinuousAttentionStream, createKVBridge, nxl, OrchestratorEngine } from '../../engines/index.js';
|
|
22
22
|
import { FederationEngine } from '../../engines/federation.js';
|
|
23
|
+
import { TokenAnalyticsEngine } from '../../engines/token-analytics.js';
|
|
23
24
|
const tokenEngine = new TokenSupremacyEngine();
|
|
24
25
|
const guardrailEngine = new GuardrailEngine();
|
|
25
26
|
const darwinLoop = new DarwinLoop();
|
|
@@ -61,6 +62,7 @@ const AUTONOMOUS_TOOL_ORDER = [
|
|
|
61
62
|
'nexus_mindkit_check',
|
|
62
63
|
'nexus_ghost_pass',
|
|
63
64
|
'nexus_spawn_workers',
|
|
65
|
+
'nexus_token_report',
|
|
64
66
|
'nexus_session_dna',
|
|
65
67
|
'nexus_list_skills',
|
|
66
68
|
'nexus_list_workflows',
|
|
@@ -128,6 +130,7 @@ class SessionTelemetry {
|
|
|
128
130
|
tokensOptimized = 0;
|
|
129
131
|
memoriesStored = 0;
|
|
130
132
|
memoriesRecalled = 0;
|
|
133
|
+
bootstrapped = false;
|
|
131
134
|
recordCall() { this.callCount++; }
|
|
132
135
|
recordTokens(saved) { this.tokensOptimized += saved; }
|
|
133
136
|
recordStore() { this.memoriesStored++; }
|
|
@@ -147,39 +150,39 @@ class SessionTelemetry {
|
|
|
147
150
|
switch (event) {
|
|
148
151
|
case 'recall':
|
|
149
152
|
if ((context.count ?? 0) > 3) {
|
|
150
|
-
nudges.push('
|
|
153
|
+
nudges.push('Next: call nexus_optimize_tokens before reading the files mentioned.');
|
|
151
154
|
}
|
|
152
155
|
if ((context.count ?? 0) === 0) {
|
|
153
|
-
nudges.push('No memories found
|
|
156
|
+
nudges.push('No memories found — fresh topic. Next: explore carefully and call nexus_store_memory with key findings.');
|
|
154
157
|
}
|
|
155
158
|
break;
|
|
156
159
|
case 'optimize':
|
|
157
160
|
if ((context.fullReads ?? 0) > 3) {
|
|
158
|
-
nudges.push('
|
|
161
|
+
nudges.push('Next: call nexus_ghost_pass before modifying these files.');
|
|
159
162
|
}
|
|
160
163
|
break;
|
|
161
164
|
case 'ghost_pass':
|
|
162
165
|
if ((context.risks ?? 0) > 0) {
|
|
163
|
-
nudges.push('Risks detected
|
|
166
|
+
nudges.push('Risks detected. Next: call nexus_spawn_workers for parallel execution.');
|
|
164
167
|
}
|
|
165
168
|
break;
|
|
166
169
|
case 'store':
|
|
167
170
|
if ((context.priority ?? 0) > 0.8) {
|
|
168
|
-
nudges.push('High-priority insight stored.
|
|
171
|
+
nudges.push('High-priority insight stored. Next: call nexus_store_memory to persist related findings.');
|
|
169
172
|
}
|
|
170
173
|
break;
|
|
171
174
|
case 'mindkit_fail':
|
|
172
|
-
nudges.push('Guardrail FAILED. Do NOT proceed. Re-scope the task or
|
|
175
|
+
nudges.push('Guardrail FAILED. Do NOT proceed. Re-scope the task or call nexus_ghost_pass for a safer approach.');
|
|
173
176
|
break;
|
|
174
177
|
case 'high_call_count':
|
|
175
178
|
if (this.callCount > 20) {
|
|
176
|
-
nudges.push('
|
|
179
|
+
nudges.push('20+ tool calls reached. Next: call nexus_store_memory with a session summary.');
|
|
177
180
|
}
|
|
178
181
|
break;
|
|
179
182
|
}
|
|
180
183
|
if (nudges.length === 0)
|
|
181
184
|
return '';
|
|
182
|
-
return `\n<
|
|
185
|
+
return `\n<nexus-next-step>\n${nudges.map(n => ` → ${n}`).join('\n')}\n</nexus-next-step>`;
|
|
183
186
|
}
|
|
184
187
|
format(memStats) {
|
|
185
188
|
const uptime = Math.round((Date.now() - this.startTime) / 1000);
|
|
@@ -335,19 +338,19 @@ export class MCPAdapter {
|
|
|
335
338
|
}
|
|
336
339
|
decorateToolDescription(name, description, profile) {
|
|
337
340
|
if (name === 'nexus_session_bootstrap') {
|
|
338
|
-
return '
|
|
341
|
+
return 'REQUIRED: Call this BEFORE any other Nexus tool or file operation. Recovers memory, context, catalog health, and execution plan. Returns recommended next step.';
|
|
339
342
|
}
|
|
340
343
|
if (name === 'nexus_orchestrate') {
|
|
341
|
-
return '
|
|
344
|
+
return 'REQUIRED after bootstrap: Pass the user\'s raw request. Nexus handles task decomposition, skill selection, worker allocation, and execution automatically. Do NOT manually explore files instead.';
|
|
342
345
|
}
|
|
343
346
|
if (name === 'nexus_plan_execution') {
|
|
344
|
-
return 'Optional
|
|
347
|
+
return 'Optional: Inspect the execution ledger before calling nexus_orchestrate. Skip unless you need pre-run visibility into what Nexus will choose.';
|
|
345
348
|
}
|
|
346
349
|
if (name === 'nexus_optimize_tokens') {
|
|
347
|
-
return '
|
|
350
|
+
return 'Call when reading 3+ files. Returns a reading plan that saves 50-90% tokens. Follow the plan output — do not bulk-read the repo.';
|
|
348
351
|
}
|
|
349
352
|
if (name === 'nexus_spawn_workers') {
|
|
350
|
-
return '
|
|
353
|
+
return 'Call when modifying 3+ interrelated files or when nexus_ghost_pass recommends parallel execution. Prefer nexus_orchestrate for automatic worker management.';
|
|
351
354
|
}
|
|
352
355
|
if (MANUAL_OR_DIAGNOSTIC_TOOLS.has(name) && profile === 'full') {
|
|
353
356
|
return `Advanced/manual surface. ${description}`;
|
|
@@ -500,11 +503,12 @@ export class MCPAdapter {
|
|
|
500
503
|
inputSchema: {
|
|
501
504
|
type: 'object',
|
|
502
505
|
properties: {
|
|
503
|
-
|
|
506
|
+
goal: { type: 'string', description: 'What you are trying to accomplish' },
|
|
507
|
+
task: { type: 'string', description: 'Alias for goal (deprecated, use goal)' },
|
|
504
508
|
files: { type: 'array', items: { type: 'string' }, description: 'File paths to analyze. If omitted, auto-scans src/' },
|
|
505
509
|
budget: { type: 'number', description: 'Token budget override' }
|
|
506
510
|
},
|
|
507
|
-
required: [
|
|
511
|
+
required: [],
|
|
508
512
|
},
|
|
509
513
|
},
|
|
510
514
|
// ── Mindkit ──────────────────────────────────────────────────────
|
|
@@ -598,6 +602,18 @@ export class MCPAdapter {
|
|
|
598
602
|
},
|
|
599
603
|
},
|
|
600
604
|
// ── Session DNA ──────────────────────────────────────────────────
|
|
605
|
+
{
|
|
606
|
+
name: 'nexus_token_report',
|
|
607
|
+
description: 'Get persistent token usage analytics, including lifetime tokens optimized, saved, forwarded, and cost savings across sessions.',
|
|
608
|
+
inputSchema: {
|
|
609
|
+
type: 'object',
|
|
610
|
+
properties: {
|
|
611
|
+
scope: { type: 'string', enum: ['lifetime', 'recent'], description: 'Whether to get lifetime aggregate or recent sessions summary (default: lifetime)' },
|
|
612
|
+
limit: { type: 'number', description: 'Number of recent sessions to view if scope is recent (default: 10)' }
|
|
613
|
+
},
|
|
614
|
+
required: [],
|
|
615
|
+
},
|
|
616
|
+
},
|
|
601
617
|
{
|
|
602
618
|
name: 'nexus_session_dna',
|
|
603
619
|
description: 'Generate or load a Session DNA snapshot. Captures files accessed/modified, decisions made, skills used, and recommended next steps for perfect session handover. Use "generate" to create a snapshot of the current session, "load" to retrieve the most recent previous session\'s DNA.',
|
|
@@ -1155,15 +1171,6 @@ export class MCPAdapter {
|
|
|
1155
1171
|
},
|
|
1156
1172
|
];
|
|
1157
1173
|
}
|
|
1158
|
-
shouldAppendTelemetryFooter(toolName) {
|
|
1159
|
-
return !new Set([
|
|
1160
|
-
'nexus_session_bootstrap',
|
|
1161
|
-
'nexus_orchestrate',
|
|
1162
|
-
'nexus_memory_stats',
|
|
1163
|
-
'nexus_store_memory',
|
|
1164
|
-
'nexus_ghost_pass',
|
|
1165
|
-
]).has(toolName);
|
|
1166
|
-
}
|
|
1167
1174
|
setupToolHandlers() {
|
|
1168
1175
|
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
1169
1176
|
const profile = this.getToolProfile();
|
|
@@ -1185,14 +1192,59 @@ export class MCPAdapter {
|
|
|
1185
1192
|
}
|
|
1186
1193
|
this.telemetry.recordCall();
|
|
1187
1194
|
this.sessionDNA.recordToolCall();
|
|
1188
|
-
const
|
|
1189
|
-
if (
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1195
|
+
const toolName = String(request.params?.name ?? '');
|
|
1196
|
+
if (toolName === 'nexus_session_bootstrap') {
|
|
1197
|
+
this.telemetry.bootstrapped = true;
|
|
1198
|
+
}
|
|
1199
|
+
const callId = `mcp_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
1200
|
+
const startTimeMs = Date.now();
|
|
1201
|
+
nexusEventBus.emit('mcp.call.start', {
|
|
1202
|
+
callId,
|
|
1203
|
+
serverName: 'nexus-prime',
|
|
1204
|
+
toolName,
|
|
1205
|
+
args: request.params?.arguments ?? {}
|
|
1206
|
+
});
|
|
1207
|
+
let result;
|
|
1208
|
+
try {
|
|
1209
|
+
result = await this.handleToolCall(request);
|
|
1210
|
+
const resultPayload = JSON.stringify(result);
|
|
1211
|
+
nexusEventBus.emit('mcp.call.complete', {
|
|
1212
|
+
callId,
|
|
1213
|
+
serverName: 'nexus-prime',
|
|
1214
|
+
toolName,
|
|
1215
|
+
durationMs: Date.now() - startTimeMs,
|
|
1216
|
+
resultByteSize: Buffer.byteLength(resultPayload, 'utf8'),
|
|
1217
|
+
result
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
catch (error) {
|
|
1221
|
+
nexusEventBus.emit('mcp.call.complete', {
|
|
1222
|
+
callId,
|
|
1223
|
+
serverName: 'nexus-prime',
|
|
1224
|
+
toolName,
|
|
1225
|
+
durationMs: Date.now() - startTimeMs,
|
|
1226
|
+
resultByteSize: 0,
|
|
1227
|
+
error: error.message || String(error)
|
|
1228
|
+
});
|
|
1229
|
+
throw error;
|
|
1230
|
+
}
|
|
1231
|
+
if (!this.telemetry.bootstrapped &&
|
|
1232
|
+
toolName !== 'nexus_session_bootstrap' &&
|
|
1233
|
+
toolName !== 'nexus_memory_stats' &&
|
|
1234
|
+
!toolName.startsWith('nexus_list_') &&
|
|
1235
|
+
toolName !== 'nexus_federation_status' &&
|
|
1236
|
+
toolName !== 'nexus_status') {
|
|
1237
|
+
return {
|
|
1238
|
+
content: [{
|
|
1239
|
+
type: 'text',
|
|
1240
|
+
text: JSON.stringify({
|
|
1241
|
+
status: 'blocked',
|
|
1242
|
+
reason: 'nexus_session_bootstrap has not been called yet',
|
|
1243
|
+
action: 'Call nexus_session_bootstrap(goal="<your task>") first, then retry this tool',
|
|
1244
|
+
hint: 'Bootstrap recovers memory and context — skipping it means working blind'
|
|
1245
|
+
}, null, 2)
|
|
1246
|
+
}]
|
|
1247
|
+
};
|
|
1196
1248
|
}
|
|
1197
1249
|
return result;
|
|
1198
1250
|
});
|
|
@@ -1269,6 +1321,7 @@ export class MCPAdapter {
|
|
|
1269
1321
|
`Execution mode: ${bootstrap.recommendedExecutionMode || 'autonomous'}`,
|
|
1270
1322
|
`Token optimization: ${bootstrap.tokenOptimization?.required ? 'required before broad reading' : 'not required yet'}`,
|
|
1271
1323
|
`Catalog health: ${bootstrap.catalogHealth?.overall || 'unknown'} · selected ${bootstrap.artifactSelectionAudit?.selected?.length || 0}`,
|
|
1324
|
+
`Shortlist: ${bootstrap.shortlist?.skills?.slice(0, 3).join(', ') || 'none'} (skills), ${bootstrap.shortlist?.specialists?.slice(0, 3).join(', ') || 'none'} (specialists)`,
|
|
1272
1325
|
`Knowledge fabric: ${bootstrap.sourceMixRecommendation?.dominantSource || bootstrap.knowledgeFabric?.dominantSource || 'awaiting source mix'}`,
|
|
1273
1326
|
`RAG: ${bootstrap.ragCandidateStatus?.attachedCollections || 0} attached · ${bootstrap.ragCandidateStatus?.retrievedChunks || 0} retrieved`,
|
|
1274
1327
|
`Task graph: ${bootstrap.taskGraphPreview?.phases?.length || 0} phases · ${bootstrap.taskGraphPreview?.independentBranches || 0} branches`,
|
|
@@ -1460,15 +1513,7 @@ export class MCPAdapter {
|
|
|
1460
1513
|
content: [{
|
|
1461
1514
|
type: 'text',
|
|
1462
1515
|
text: [
|
|
1463
|
-
'Memory stored.',
|
|
1464
|
-
formatBullets([
|
|
1465
|
-
`ID: ${id}`,
|
|
1466
|
-
`Priority: ${priority.toFixed(2)}`,
|
|
1467
|
-
`Tags: ${tags.join(', ') || 'none'}`,
|
|
1468
|
-
`Content: ${content.slice(0, 140).replace(/\n+/g, ' ')}`,
|
|
1469
|
-
autoGistNote ? autoGistNote.replace(/^\s+/, '') : 'Relay publish: skipped',
|
|
1470
|
-
]),
|
|
1471
|
-
notification,
|
|
1516
|
+
'Memory stored. ID: ' + id,
|
|
1472
1517
|
nudge,
|
|
1473
1518
|
].filter(Boolean).join('\n\n'),
|
|
1474
1519
|
}],
|
|
@@ -1494,7 +1539,7 @@ export class MCPAdapter {
|
|
|
1494
1539
|
type: 'text',
|
|
1495
1540
|
text: (memories.length > 0
|
|
1496
1541
|
? `🧠 ${memories.length} memories recalled for "${query}":\n\n${memories.map((m, i) => `${i + 1}. ${m}`).join('\n\n')}`
|
|
1497
|
-
: `No memories found for "${query}". Fresh session or new topic.`) +
|
|
1542
|
+
: `No memories found for "${query}". Fresh session or new topic.`) + '\n\n' + nudge,
|
|
1498
1543
|
}],
|
|
1499
1544
|
};
|
|
1500
1545
|
}
|
|
@@ -1679,7 +1724,7 @@ export class MCPAdapter {
|
|
|
1679
1724
|
};
|
|
1680
1725
|
}
|
|
1681
1726
|
case 'nexus_optimize_tokens': {
|
|
1682
|
-
const task = String(request.params.arguments?.task ?? '');
|
|
1727
|
+
const task = String(request.params.arguments?.goal ?? request.params.arguments?.task ?? '');
|
|
1683
1728
|
const rawFiles = Array.isArray(request.params.arguments?.files)
|
|
1684
1729
|
? request.params.arguments.files.map(String)
|
|
1685
1730
|
: null;
|
|
@@ -2002,6 +2047,31 @@ export class MCPAdapter {
|
|
|
2002
2047
|
}],
|
|
2003
2048
|
};
|
|
2004
2049
|
}
|
|
2050
|
+
case 'nexus_token_report': {
|
|
2051
|
+
const scope = String(request.params.arguments?.scope ?? 'lifetime');
|
|
2052
|
+
const limit = Number(request.params.arguments?.limit ?? 10);
|
|
2053
|
+
const engine = new TokenAnalyticsEngine(this.nexusRef.memory);
|
|
2054
|
+
if (scope === 'recent') {
|
|
2055
|
+
const history = engine.getSessionHistory(limit);
|
|
2056
|
+
return {
|
|
2057
|
+
content: [{
|
|
2058
|
+
type: 'text',
|
|
2059
|
+
text: history.length > 0
|
|
2060
|
+
? `📊 Recent Sessions Token Analytics:\n\n${history.map(s => `Session ID: ${s.sessionId}\n- Events: ${s.events}\n- Tokens Optimally Saved: ${s.tokensSaved.toLocaleString()} (x${s.compressionRatio.toFixed(2)} compression)\n- USD Saved: $${s.usdValueSaved.toFixed(4)}`).join('\n\n')}`
|
|
2061
|
+
: 'No recent sessions found in token ledger.'
|
|
2062
|
+
}]
|
|
2063
|
+
};
|
|
2064
|
+
}
|
|
2065
|
+
else {
|
|
2066
|
+
const report = engine.getLifetimeReport();
|
|
2067
|
+
return {
|
|
2068
|
+
content: [{
|
|
2069
|
+
type: 'text',
|
|
2070
|
+
text: `📊 Lifetime Token Analytics:\n\n- Total Sessions: ${report.totalSessions}\n- Total MCP Events: ${report.totalEvents}\n- Tokens Optimally Saved: ${report.totalTokensSaved.toLocaleString()} (overall x${report.overallCompressionRatio.toFixed(2)} compression)\n- USD Saved: $${report.totalUsdSaved.toFixed(4)}`
|
|
2071
|
+
}]
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2005
2075
|
case 'nexus_session_dna': {
|
|
2006
2076
|
const action = String(request.params.arguments?.action ?? 'load');
|
|
2007
2077
|
const sessionId = request.params.arguments?.sessionId
|
|
@@ -2013,6 +2083,7 @@ export class MCPAdapter {
|
|
|
2013
2083
|
callCount: this.telemetry.callCount ?? 0,
|
|
2014
2084
|
memoriesStored: this.telemetry.memoriesStored ?? 0,
|
|
2015
2085
|
memoriesRecalled: this.telemetry.memoriesRecalled ?? 0,
|
|
2086
|
+
tokensOptimized: this.telemetry.tokensOptimized ?? 0,
|
|
2016
2087
|
});
|
|
2017
2088
|
const dna = this.sessionDNA.flush();
|
|
2018
2089
|
const formatted = SessionDNAManager.format(dna);
|
|
@@ -2928,6 +2999,7 @@ export class MCPAdapter {
|
|
|
2928
2999
|
callCount: this.telemetry.callCount ?? 0,
|
|
2929
3000
|
memoriesStored: this.telemetry.memoriesStored ?? 0,
|
|
2930
3001
|
memoriesRecalled: this.telemetry.memoriesRecalled ?? 0,
|
|
3002
|
+
tokensOptimized: this.telemetry.tokensOptimized ?? 0,
|
|
2931
3003
|
});
|
|
2932
3004
|
this.sessionDNA.flush();
|
|
2933
3005
|
console.error('[MCP Adapter] Session DNA flushed');
|