erne-universal 0.6.3 → 0.8.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 (63) hide show
  1. package/README.md +129 -4
  2. package/bin/cli.js +2 -0
  3. package/dashboard/lib/agents-config.js +30 -0
  4. package/dashboard/lib/context/budget-manager.js +108 -0
  5. package/dashboard/lib/context/content-store.js +478 -0
  6. package/dashboard/lib/context/cross-project.js +32 -0
  7. package/dashboard/lib/context/db.js +89 -0
  8. package/dashboard/lib/context/knowledge-base.js +158 -0
  9. package/dashboard/lib/context/preloader.js +27 -0
  10. package/dashboard/lib/context/schemas/001-initial.sql +121 -0
  11. package/dashboard/lib/context/schemas/002-content-store.sql +56 -0
  12. package/dashboard/lib/context/session-continuity.js +139 -0
  13. package/dashboard/lib/context/session-tracker.js +112 -0
  14. package/dashboard/lib/context/summarizer.js +678 -0
  15. package/dashboard/lib/context/truncation.js +144 -0
  16. package/dashboard/lib/ecosystem/analyzer.js +158 -0
  17. package/dashboard/lib/ecosystem/fetcher.js +231 -0
  18. package/dashboard/lib/ecosystem/handler.js +58 -0
  19. package/dashboard/lib/insights/collector.js +113 -0
  20. package/dashboard/lib/insights/handler.js +52 -0
  21. package/dashboard/lib/insights/trends.js +58 -0
  22. package/dashboard/lib/myapp/handler.js +314 -0
  23. package/dashboard/lib/upgrades/handler.js +104 -0
  24. package/dashboard/lib/upgrades/planner.js +20 -0
  25. package/dashboard/lib/upgrades/scanner.js +131 -0
  26. package/dashboard/package.json +1 -0
  27. package/dashboard/public/audit-panel.js +168 -0
  28. package/dashboard/public/budget-panel.js +76 -0
  29. package/dashboard/public/context-panel.js +54 -0
  30. package/dashboard/public/context-toggle.js +94 -0
  31. package/dashboard/public/ecosystem-tab.js +166 -0
  32. package/dashboard/public/history.js +19 -0
  33. package/dashboard/public/index.html +94 -3
  34. package/dashboard/public/insights-tab.js +129 -0
  35. package/dashboard/public/knowledge-browser.js +77 -0
  36. package/dashboard/public/myapp-tab.js +365 -0
  37. package/dashboard/public/panel.js +107 -9
  38. package/dashboard/public/sidebar-panels.js +198 -0
  39. package/dashboard/public/sparkline.js +72 -0
  40. package/dashboard/public/statsbar.js +32 -8
  41. package/dashboard/public/styles.css +823 -87
  42. package/dashboard/public/tabs.js +180 -0
  43. package/dashboard/public/upgrades-tab.js +202 -0
  44. package/dashboard/public/ws-client.js +9 -1
  45. package/dashboard/server.js +385 -15
  46. package/hooks/hooks.json +43 -0
  47. package/hooks/profiles/minimal.json +5 -1
  48. package/hooks/profiles/standard.json +7 -1
  49. package/hooks/profiles/strict.json +7 -1
  50. package/lib/audit-cli.js +64 -0
  51. package/lib/audit.js +622 -0
  52. package/lib/dashboard.js +13 -4
  53. package/lib/init.js +20 -0
  54. package/mcp-configs/erne-context/index.js +73 -0
  55. package/package.json +2 -2
  56. package/scripts/hooks/context/event-tracker.js +68 -0
  57. package/scripts/hooks/context/knowledge-indexer.js +36 -0
  58. package/scripts/hooks/context/sandbox-router.js +53 -0
  59. package/scripts/hooks/context/session-graduate.js +5 -0
  60. package/scripts/hooks/context/session-restore.js +52 -0
  61. package/scripts/hooks/context/snapshot-builder.js +11 -0
  62. package/scripts/hooks/lib/context-client.js +73 -0
  63. package/scripts/hooks/run-with-flags.js +36 -1
package/README.md CHANGED
@@ -49,7 +49,7 @@ This will:
49
49
 
50
50
  ## 🎮 Agent Dashboard
51
51
 
52
- ERNE includes a real-time pixel-art dashboard that visualizes all 11 agents working in an animated office environment.
52
+ ERNE includes a real-time pixel-art dashboard with 4 tabs, a context sidebar, and animated office visualization.
53
53
 
54
54
  ```bash
55
55
  erne dashboard # Start on port 3333, open browser
@@ -58,7 +58,12 @@ erne dashboard --no-open # Don't open browser
58
58
  erne start # Init project + dashboard in background
59
59
  ```
60
60
 
61
- **Features:**
61
+ ### HQ — Pixel-Art Office
62
+
63
+ <p align="center">
64
+ <img src="docs/screenshots/dashboard-hq.png" alt="ERNE HQ — 4 office rooms with 11 animated agents" width="800" />
65
+ </p>
66
+
62
67
  - 🏢 4 office rooms — Development, Code Review, Testing, and Conference
63
68
  - 🎨 11 animated agent sprites with walking, typing, and done animations
64
69
  - 💬 Thought bubbles showing the current task above working agents
@@ -69,6 +74,56 @@ erne start # Init project + dashboard in background
69
74
  - 🎯 Pipeline orchestrator coordination view in conference room
70
75
  - 🔄 Real-time WebSocket updates with auto-reconnect
71
76
 
77
+ ### My App — Project Intelligence
78
+
79
+ <p align="center">
80
+ <img src="docs/screenshots/dashboard-myapp.png" alt="My App tab — project overview, MCP integrations, audit, environment" width="800" />
81
+ </p>
82
+
83
+ - 📋 App overview with framework detection, health grade, and stack chips
84
+ - 🔌 10 MCP integration statuses with requirements
85
+ - 🔍 Project audit with score, findings (with FIX buttons), and strengths
86
+ - ⚡ Quick actions — run tests, lint, start dev, build iOS/Android, pod install
87
+ - 💡 Smart recommendations based on audit findings
88
+ - 🛠️ Environment checks for all dev tools (Node, Xcode, CocoaPods, etc.)
89
+
90
+ ### Ecosystem — Release Radar
91
+
92
+ <p align="center">
93
+ <img src="docs/screenshots/dashboard-ecosystem.png" alt="Ecosystem tab — release feed for React Native packages" width="800" />
94
+ </p>
95
+
96
+ - 📰 Live release feed for React Native ecosystem packages
97
+ - 🏷️ Tags: NEW, BREAK, security patches
98
+ - 🔍 Filter by category: Updates, Trending, Tips, Security
99
+ - 📊 Quick stats sidebar
100
+
101
+ ### Insights — Project Analytics
102
+
103
+ <p align="center">
104
+ <img src="docs/screenshots/dashboard-insights.png" alt="Insights tab — audit score, outdated deps, agent utilization" width="800" />
105
+ </p>
106
+
107
+ - 📈 KPI cards: Audit Score, Outdated Deps, Agent Tasks (with deltas)
108
+ - 📊 Agent utilization breakdown with horizontal bar chart
109
+
110
+ ### Context Sidebar
111
+
112
+ <p align="center">
113
+ <img src="docs/screenshots/dashboard-sidebar.png" alt="Context sidebar — system info, audit, activity, knowledge base" width="800" />
114
+ </p>
115
+
116
+ The sidebar auto-enables with the dashboard and provides 6 collapsible panels:
117
+
118
+ - 🖥️ **System Info** — project metadata, environment checks, git branch
119
+ - 🔍 **Project Audit** — 22-point score with one-click FIX buttons and strength checks
120
+ - 📋 **Agent Activity** — real-time task history with timestamps
121
+ - 💾 **Context Savings** — live savings percentage, KB saved, and event timeline
122
+ - 📚 **Knowledge Base** — FTS5-powered search across 5 categories (pattern, decision, error, api, component)
123
+ - 💰 **Context Budget** — set session/agent token limits, choose overflow strategy (truncate / warn / stop)
124
+
125
+ Context optimization runs automatically — no flags or configuration needed. See [Context Optimization](#-context-optimization) for details.
126
+
72
127
  ---
73
128
 
74
129
  ## 🎯 Multi-Agent Orchestration
@@ -117,9 +172,69 @@ Each agent has a distinct personality, quantified success metrics, and memory in
117
172
 
118
173
  ---
119
174
 
175
+ ## 🧠 Context Optimization
176
+
177
+ ERNE includes a built-in context intelligence system that reduces tool output bloat by **97–100%**, preserves exact code examples via FTS5 search, and manages your context budget — all auto-enabled with the dashboard.
178
+
179
+ ```
180
+ erne dashboard # Context system starts automatically
181
+ ```
182
+
183
+ ### Benchmark-verified savings
184
+
185
+ | Layer | What it does | Savings |
186
+ |-------|-------------|---------|
187
+ | **Summarizer** | Auto-detects 14 content types (docs, JSON, logs, test output, build output, CSV, git history, etc.) and compresses to statistical summaries | **97–100%** |
188
+ | **Index + Search** | Chunks content by headings, indexes in FTS5 with BM25 ranking. Returns only relevant chunks — code examples preserved exactly | **80%** |
189
+ | **Full session** | Combined summarizer + search across a real debugging session (docs, snapshots, issues, tests, builds) | **99%** |
190
+
191
+ > **Real numbers:** 537 KB of tool outputs → 2.6 KB of context. That's **0.4%** of a 200K context window instead of 44.5%. See [BENCHMARK.md](BENCHMARK.md) for the full 21-scenario breakdown.
192
+
193
+ ### How it works
194
+
195
+ ```
196
+ Tool Output ──▶ Smart Summarizer ──▶ 97-100% compression (14 content types)
197
+
198
+ Raw Docs ──▶ FTS5 Index+Search ──▶ 80% savings, exact code preserved
199
+
200
+ Session Events ──▶ Session Tracker ──▶ Error→Fix correlation
201
+
202
+ Knowledge ──▶ 3-Layer Search (FTS5 → Trigram → Levenshtein)
203
+
204
+ Session End ──▶ Snapshot (<2KB) ──▶ Next session restores context
205
+ ```
206
+
207
+ | Feature | What it does |
208
+ |---------|-------------|
209
+ | **Content summarizer** | 14 auto-detected content types: markdown, HTML, JSON, test output, TypeScript errors, build output, logs, git history, CSV, and more. Each type gets a specialized summary format |
210
+ | **Content store** | FTS5-powered index with Porter stemming. Markdown chunked by headings, code blocks never split or truncated. BM25 relevance ranking with byte budget management |
211
+ | **Smart truncation** | 4-tier fallback cascade: Structured → Pattern → Head/Tail → Hash. Handles anything the summarizer doesn't cover |
212
+ | **Knowledge base** | SQLite-backed with FTS5 full-text search, trigram fuzzy matching, and Levenshtein fallback. Entries scored by recency + access frequency |
213
+ | **Session continuity** | Snapshots capture active tasks, decisions, errors, and commits at session end. Next session restores context in <2KB |
214
+ | **Budget manager** | Set per-session and per-agent token limits. Throttles at 80%, supports aggressive truncation / warn / hard stop overflow strategies |
215
+ | **Agent preloader** | Tracks agent-to-agent transitions and predicts the next agent for parallel context warmup |
216
+ | **Error→Fix tracking** | Correlates errors with subsequent file modifications to build fix patterns over time |
217
+
218
+ ### Dashboard sidebar panels
219
+
220
+ The context sidebar (toggle with the chevron button) shows 6 live panels:
221
+
222
+ - **System Info** — project metadata, environment health, git branch
223
+ - **Project Audit** — 22-point audit with score, one-click FIX buttons, and strengths
224
+ - **Agent Activity** — real-time task history with timestamps
225
+ - **Context Savings** — live savings percentage, KB saved, and event timeline
226
+ - **Knowledge Base** — searchable entries with category filters (pattern, decision, error, api, component)
227
+ - **Context Budget** — configure session limits and overflow strategy directly from the UI
228
+
229
+ If the context system is disabled, the sidebar shows an **Enable Context** button to activate it at runtime.
230
+
231
+ ---
232
+
120
233
  ## 💰 Token Efficiency
121
234
 
122
- ERNE's architecture is designed to minimize token usage through six layered mechanisms:
235
+ ERNE minimizes token usage through two complementary systems: **architecture-level savings** (what gets loaded into context) and **runtime context optimization** (how tool outputs and session state are compressed).
236
+
237
+ ### Architecture savings
123
238
 
124
239
  | Mechanism | How it works | Savings |
125
240
  |-----------|-------------|---------|
@@ -130,7 +245,17 @@ ERNE's architecture is designed to minimize token usage through six layered mech
130
245
  | **Task-specific commands** | 19 focused prompts instead of one monolithic instruction set | ~13% |
131
246
  | **Context-based behavior** | Modes change behavior dynamically without loading new rulesets | ~3% |
132
247
 
133
- **Result:** Typical workflows use **60–67% fewer tokens** compared to a naive all-in-context approach.
248
+ ### Runtime context optimization (benchmark-verified)
249
+
250
+ | Mechanism | How it works | Savings |
251
+ |-----------|-------------|---------|
252
+ | **Content summarizer** | Auto-detects 14 content types, produces statistical summaries | **97–100%** per output |
253
+ | **Index + Search** | FTS5 BM25 retrieval returns only relevant chunks, code preserved exactly | **80%** per search |
254
+ | **Smart truncation** | 4-tier fallback: Structured → Pattern → Head/Tail → Hash | 85–100% per output |
255
+ | **Session snapshots** | Captures full session state in <2KB | ~50% vs log replay |
256
+ | **Budget enforcement** | Throttling at 80% prevents runaway token usage | Prevents overflow |
257
+
258
+ **Result:** Architecture saves **60–67%** on what enters context. Runtime optimization achieves **97–100%** compression on tool outputs (verified across 21 benchmark scenarios with 537 KB of real data). In a full debugging session, **99% of tool output tokens are eliminated** — leaving 99.6% of your context window free for actual problem solving. See [BENCHMARK.md](BENCHMARK.md) for complete results.
134
259
 
135
260
  ---
136
261
 
package/bin/cli.js CHANGED
@@ -17,6 +17,7 @@ const COMMANDS = {
17
17
  'add-agent': () => require('../lib/add-agent'),
18
18
  doctor: () => require('../lib/doctor'),
19
19
  status: () => require('../lib/status'),
20
+ audit: () => require('../lib/audit-cli'),
20
21
  'sync-configs': () => require('../lib/sync-configs'),
21
22
  sync: () => require('../lib/sync-configs'),
22
23
  version: () => {
@@ -33,6 +34,7 @@ const COMMANDS = {
33
34
 
34
35
  Commands:
35
36
  init Set up ERNE in your project
37
+ audit Run project audit and generate report
36
38
  update Update to the latest version
37
39
  add-agent Create a new custom agent definition
38
40
  dashboard Launch the ERNE Agent Dashboard
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Canonical agent list — single source of truth for server + browser.
5
+ * panel.js inlines a copy; server modules require() this file.
6
+ */
7
+
8
+ const AGENT_DEFINITIONS = [
9
+ { name: 'architect', room: 'development' },
10
+ { name: 'native-bridge-builder', room: 'development' },
11
+ { name: 'expo-config-resolver', room: 'development' },
12
+ { name: 'ui-designer', room: 'development' },
13
+ { name: 'code-reviewer', room: 'review' },
14
+ { name: 'upgrade-assistant', room: 'review' },
15
+ { name: 'tdd-guide', room: 'testing' },
16
+ { name: 'performance-profiler', room: 'testing' },
17
+ { name: 'senior-developer', room: 'development' },
18
+ { name: 'feature-builder', room: 'development' },
19
+ { name: 'pipeline-orchestrator', room: 'conference' },
20
+ ];
21
+
22
+ const AGENT_ORDER = [
23
+ 'architect', 'senior-developer', 'feature-builder',
24
+ 'native-bridge-builder', 'expo-config-resolver', 'ui-designer',
25
+ 'code-reviewer', 'upgrade-assistant',
26
+ 'tdd-guide', 'performance-profiler',
27
+ 'pipeline-orchestrator',
28
+ ];
29
+
30
+ module.exports = { AGENT_ORDER, AGENT_DEFINITIONS };
@@ -0,0 +1,108 @@
1
+ 'use strict';
2
+
3
+ class BudgetManager {
4
+ constructor(db) {
5
+ this.db = db;
6
+ this.agentUsage = new Map();
7
+ this.sessionUsage = 0;
8
+ this._ensureSettings();
9
+ }
10
+
11
+ _ensureSettings() {
12
+ const existing = this.db.prepare('SELECT * FROM budget_settings WHERE id = 1').get();
13
+ if (!existing) {
14
+ this.db.prepare("INSERT INTO budget_settings (id, enabled, session_limit, overflow, agent_limits) VALUES (1, 0, 50000, 'aggressive_truncation', '{}')").run();
15
+ }
16
+ }
17
+
18
+ getSettings() {
19
+ const row = this.db.prepare('SELECT * FROM budget_settings WHERE id = 1').get();
20
+ return {
21
+ enabled: !!row.enabled,
22
+ session_limit: row.session_limit,
23
+ overflow: row.overflow,
24
+ agent_limits: JSON.parse(row.agent_limits || '{}'),
25
+ session_usage: this.sessionUsage,
26
+ session_pct: row.session_limit > 0 ? Math.round((this.sessionUsage / row.session_limit) * 100) : 0,
27
+ agents: Object.fromEntries(
28
+ [...this.agentUsage.entries()].map(([k, v]) => [k, { limit: JSON.parse(row.agent_limits || '{}')[k] || 0, used: v }])
29
+ )
30
+ };
31
+ }
32
+
33
+ updateSettings({ enabled, session_limit, overflow, agent_limits }) {
34
+ const current = this.getSettings();
35
+ this.db.prepare(`UPDATE budget_settings SET
36
+ enabled = ?, session_limit = ?, overflow = ?, agent_limits = ? WHERE id = 1`
37
+ ).run(
38
+ enabled !== undefined ? (enabled ? 1 : 0) : (current.enabled ? 1 : 0),
39
+ session_limit || current.session_limit,
40
+ overflow || current.overflow,
41
+ JSON.stringify(agent_limits || current.agent_limits)
42
+ );
43
+ }
44
+
45
+ trackUsage(agent, bytes) {
46
+ const current = this.agentUsage.get(agent) || 0;
47
+ this.agentUsage.set(agent, current + bytes);
48
+ this.sessionUsage += bytes;
49
+ }
50
+
51
+ getUsage(agent) {
52
+ return this.agentUsage.get(agent) || 0;
53
+ }
54
+
55
+ /**
56
+ * Check if an agent should be throttled (at 80% of limit).
57
+ * Returns false if budget is disabled or no limit is set.
58
+ */
59
+ shouldThrottle(agent) {
60
+ const settings = this.getSettings();
61
+ if (!settings.enabled) return false;
62
+
63
+ // Check session-level limit
64
+ if (this.sessionUsage >= settings.session_limit * 0.8) return true;
65
+
66
+ // Check per-agent limit
67
+ const agentLimit = settings.agent_limits[agent];
68
+ if (agentLimit && this.getUsage(agent) >= agentLimit * 0.8) return true;
69
+
70
+ return false;
71
+ }
72
+
73
+ /**
74
+ * Check if output should be blocked entirely (hard_stop overflow at 100%).
75
+ * Returns { blocked: bool, reason: string }
76
+ */
77
+ shouldBlock(agent) {
78
+ const settings = this.getSettings();
79
+ if (!settings.enabled) return { blocked: false, reason: null };
80
+ if (settings.overflow !== 'hard_stop') return { blocked: false, reason: null };
81
+
82
+ if (this.sessionUsage >= settings.session_limit) {
83
+ return { blocked: true, reason: `Session budget exceeded (${this.sessionUsage}/${settings.session_limit} bytes)` };
84
+ }
85
+
86
+ const agentLimit = settings.agent_limits[agent];
87
+ if (agentLimit && this.getUsage(agent) >= agentLimit) {
88
+ return { blocked: true, reason: `Agent ${agent} budget exceeded (${this.getUsage(agent)}/${agentLimit} bytes)` };
89
+ }
90
+
91
+ return { blocked: false, reason: null };
92
+ }
93
+
94
+ /**
95
+ * Get the overflow strategy for the current settings.
96
+ * Returns 'aggressive_truncation' | 'warn' | 'hard_stop'
97
+ */
98
+ getOverflowStrategy() {
99
+ return this.getSettings().overflow;
100
+ }
101
+
102
+ resetSession() {
103
+ this.agentUsage.clear();
104
+ this.sessionUsage = 0;
105
+ }
106
+ }
107
+
108
+ module.exports = { BudgetManager };