pikakit 1.0.8 → 1.0.10

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.
@@ -1,5 +1,11 @@
1
1
  /**
2
2
  * Main Menu UI - Interactive CLI interface
3
+ * AutoLearn v6.0 - Passive Learning Architecture
4
+ *
5
+ * Changes from v1:
6
+ * - Removed "Scan All" option (now runs passively in background)
7
+ * - Renamed to "Insights" view
8
+ * - Added background observer startup
3
9
  */
4
10
  import { showIntro, showActionMenu, theme } from "./clack-helpers.js";
5
11
  import { loadSettings } from "../settings.js";
@@ -62,14 +68,37 @@ function showAgentBanner() {
62
68
  console.log(''); // Empty line to break vertical connector
63
69
  }
64
70
 
71
+ // ============================================================================
72
+ // BACKGROUND OBSERVER (AutoLearn v6.0)
73
+ // ============================================================================
74
+
75
+ let backgroundObserverStarted = false;
76
+
77
+ /**
78
+ * Start background observers for passive learning
79
+ * This runs silently without user intervention
80
+ */
81
+ async function startBackgroundObserver() {
82
+ if (backgroundObserverStarted) return;
83
+ backgroundObserverStarted = true;
84
+
85
+ // Note: Actual implementation would integrate with file watcher
86
+ // For now, we just mark that passive learning is active
87
+ console.log(theme.dim(' 🧠 AutoLearn v6.0 - Passive learning active'));
88
+ }
89
+
65
90
  // ============================================================================
66
91
  // MAIN MENU
67
92
  // ============================================================================
68
93
 
69
94
  /**
70
95
  * Show main interactive menu
96
+ * AutoLearn v6.0 - No more manual "Scan All" needed
71
97
  */
72
98
  export async function showMainMenu() {
99
+ // Start background observer on first run
100
+ startBackgroundObserver();
101
+
73
102
  while (true) {
74
103
  showAgentBanner();
75
104
 
@@ -78,12 +107,8 @@ export async function showMainMenu() {
78
107
  const autoLearningEnabled = settings.autoLearn !== false; // Default to true
79
108
 
80
109
  // Build menu options dynamically
110
+ // NOTE: "Scan All" removed in v6.0 - scanning now runs passively
81
111
  const menuOptions = [
82
- // ═════════════════════════════════════════════
83
- // 🔍 SCANNING & ACTIONS
84
- // ═════════════════════════════════════════════
85
- { value: "scanall", label: "🔎 Scan All", hint: "Check & fix violations" },
86
-
87
112
  // ═════════════════════════════════════════════
88
113
  // 📚 LEARNING & KNOWLEDGE
89
114
  // ═════════════════════════════════════════════
@@ -98,9 +123,9 @@ export async function showMainMenu() {
98
123
  { value: "lessons", label: "📚 Lessons", hint: "View & manage" },
99
124
 
100
125
  // ═════════════════════════════════════════════
101
- // 📊 ANALYTICS
126
+ // 📊 ANALYTICS (renamed from Stats)
102
127
  // ═════════════════════════════════════════════
103
- { value: "stats", label: "💡 Insights", hint: "Stats & signals" },
128
+ { value: "insights", label: "💡 Insights", hint: "Metrics & patterns" },
104
129
 
105
130
  // ═════════════════════════════════════════════
106
131
  // ⚙️ SETTINGS & MANAGEMENT
@@ -111,7 +136,7 @@ export async function showMainMenu() {
111
136
  // ═════════════════════════════════════════════
112
137
  // 📊 DASHBOARD
113
138
  // ═════════════════════════════════════════════
114
- { value: "dashboard", label: "📊 Dashboard", hint: "Web UI & Help" },
139
+ { value: "dashboard", label: "📊 Dashboard", hint: "Web UI & metrics" },
115
140
 
116
141
  { value: "exit", label: "👋 Exit" }
117
142
  );
@@ -127,6 +152,7 @@ export async function showMainMenu() {
127
152
  }
128
153
 
129
154
  // Execute action directly (no submenus)
155
+ // NOTE: scanall case removed - use Dashboard for viewing scan results
130
156
  switch (action) {
131
157
  case "learn":
132
158
  await runLearnUI();
@@ -134,11 +160,8 @@ export async function showMainMenu() {
134
160
  case "lessons":
135
161
  await runLessonsUI();
136
162
  break;
137
- case "scanall":
138
- await runRecallUI(true); // Auto-scan mode with fix option
139
- break;
140
- case "stats":
141
- await runStatsUI(); // Now includes signals
163
+ case "insights":
164
+ await runStatsUI(); // Insights view (formerly stats + signals)
142
165
  break;
143
166
  case "settings":
144
167
  await runSettingsUI();
@@ -192,7 +215,7 @@ async function runRoutingUI() {
192
215
  // ============================================================================
193
216
 
194
217
  // Run if executed directly
195
- if (process.argv[1].includes("index.js") || process.argv[1].includes("ui")) {
218
+ if (process.argv[1]?.includes("index.js") || process.argv[1]?.includes("ui")) {
196
219
  showMainMenu().catch(console.error);
197
220
  }
198
221
 
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * Dashboard Server - Local web server for Auto-Learn Dashboard
3
+ * Dashboard Server v6.0 - AutoLearn Precision Learning Engine
4
4
  *
5
- * Part of FAANG-Grade Auto-Learn System Phase 4
6
- *
7
- * Serves:
8
- * - Static dashboard HTML
9
- * - API endpoints for data
5
+ * Serves real-time metrics from the new v6.0 modules:
6
+ * - metrics-collector.js (18 KPIs)
7
+ * - dashboard-data.js (aggregation)
8
+ * - causality-engine.js (patterns)
9
+ * - reinforcement.js (loop stats)
10
+ * - ab-testing.js (experiment stats)
11
+ * - precision-skill-generator.js (skills)
10
12
  *
11
13
  * Usage:
12
14
  * node dashboard_server.js --start
@@ -18,6 +20,14 @@ import path from 'path';
18
20
  import http from 'http';
19
21
  import { fileURLToPath } from 'url';
20
22
 
23
+ // Import v6.0 modules
24
+ import { getDashboardData, getSummary, getMetricHistory } from '../lib/metrics-collector.js';
25
+ import { getFullDashboardData, getKeyTrends, generateAlerts, getGaugeWidgets, getCounterWidgets } from '../lib/dashboard-data.js';
26
+ import { getReinforcementStats } from '../lib/reinforcement.js';
27
+ import { getABTestStats, getActiveTests } from '../lib/ab-testing.js';
28
+ import { getSkillStats, loadAutoSkills } from '../lib/precision-skill-generator.js';
29
+ import { loadCausalPatterns } from '../lib/causality-engine.js';
30
+
21
31
  const __filename = fileURLToPath(import.meta.url);
22
32
  const __dirname = path.dirname(__filename);
23
33
 
@@ -45,62 +55,158 @@ function findProjectRoot() {
45
55
  }
46
56
 
47
57
  const projectRoot = findProjectRoot();
48
- const knowledgePath = path.join(projectRoot, '.agent', 'knowledge');
49
58
  const dashboardPath = path.join(__dirname, '..', 'dashboard');
50
59
 
51
- // Load JSON files
52
- function loadJson(filename) {
53
- const filePath = path.join(knowledgePath, filename);
54
- try {
55
- if (fs.existsSync(filePath)) {
56
- return JSON.parse(fs.readFileSync(filePath, 'utf8'));
57
- }
58
- } catch { }
59
- return null;
60
- }
60
+ // ============================================================================
61
+ // API v6.0 HANDLERS
62
+ // ============================================================================
61
63
 
62
- // API handlers
63
64
  const api = {
64
- '/api/errors': () => {
65
- const data = loadJson('detected-errors.json');
66
- return data || { errors: [], totalErrors: 0 };
65
+ // Full dashboard data (all metrics aggregated)
66
+ '/api/dashboard': () => {
67
+ try {
68
+ return getFullDashboardData();
69
+ } catch (e) {
70
+ return { error: e.message, version: '6.0.0' };
71
+ }
67
72
  },
68
73
 
69
- '/api/corrections': () => {
70
- const data = loadJson('user-corrections.json');
71
- return data || { corrections: [], totalCorrections: 0 };
74
+ // KPIs only
75
+ '/api/kpis': () => {
76
+ try {
77
+ return getDashboardData();
78
+ } catch (e) {
79
+ return { error: e.message };
80
+ }
72
81
  },
73
82
 
74
- '/api/lessons': () => {
75
- const data = loadJson('lessons-learned.json');
76
- return data || { lessons: [] };
83
+ // Summary stats
84
+ '/api/summary': () => {
85
+ try {
86
+ return getSummary();
87
+ } catch (e) {
88
+ return { error: e.message };
89
+ }
90
+ },
91
+
92
+ // Trends over time
93
+ '/api/trends': () => {
94
+ try {
95
+ return getKeyTrends();
96
+ } catch (e) {
97
+ return { error: e.message };
98
+ }
99
+ },
100
+
101
+ // Active alerts
102
+ '/api/alerts': () => {
103
+ try {
104
+ return { alerts: generateAlerts() };
105
+ } catch (e) {
106
+ return { alerts: [], error: e.message };
107
+ }
108
+ },
109
+
110
+ // Gauge widget data
111
+ '/api/gauges': () => {
112
+ try {
113
+ return { gauges: getGaugeWidgets() };
114
+ } catch (e) {
115
+ return { gauges: [], error: e.message };
116
+ }
117
+ },
118
+
119
+ // Counter widget data
120
+ '/api/counters': () => {
121
+ try {
122
+ return { counters: getCounterWidgets() };
123
+ } catch (e) {
124
+ return { counters: [], error: e.message };
125
+ }
126
+ },
127
+
128
+ // Reinforcement loop stats
129
+ '/api/reinforcement': () => {
130
+ try {
131
+ return getReinforcementStats();
132
+ } catch (e) {
133
+ return { error: e.message };
134
+ }
135
+ },
136
+
137
+ // A/B testing stats
138
+ '/api/ab-testing': () => {
139
+ try {
140
+ return {
141
+ stats: getABTestStats(),
142
+ active: getActiveTests()
143
+ };
144
+ } catch (e) {
145
+ return { error: e.message };
146
+ }
147
+ },
148
+
149
+ // Auto-generated skills
150
+ '/api/skills': () => {
151
+ try {
152
+ return {
153
+ stats: getSkillStats(),
154
+ skills: loadAutoSkills()
155
+ };
156
+ } catch (e) {
157
+ return { error: e.message };
158
+ }
77
159
  },
78
160
 
161
+ // Causal patterns
79
162
  '/api/patterns': () => {
80
- const data = loadJson('patterns.json');
81
- return data || { errors: {}, corrections: {}, highFrequency: [] };
163
+ try {
164
+ const patterns = loadCausalPatterns();
165
+ return {
166
+ total: patterns.length,
167
+ patterns: patterns.slice(0, 20) // Limit to 20 most recent
168
+ };
169
+ } catch (e) {
170
+ return { total: 0, patterns: [], error: e.message };
171
+ }
82
172
  },
83
173
 
84
- '/api/summary': () => {
85
- const errors = loadJson('detected-errors.json');
86
- const corrections = loadJson('user-corrections.json');
87
- const lessons = loadJson('lessons-learned.json');
88
- const patterns = loadJson('patterns.json');
89
-
90
- return {
91
- errors: {
92
- total: errors?.errors?.length || 0,
93
- byType: patterns?.errors?.byType || {},
94
- bySeverity: patterns?.errors?.bySeverity || {}
95
- },
96
- corrections: {
97
- total: corrections?.corrections?.length || 0,
98
- byCategory: patterns?.corrections?.byCategory || {}
99
- },
100
- lessons: lessons?.lessons?.length || 0,
101
- highFrequency: patterns?.highFrequency || [],
102
- lastUpdated: patterns?.analyzedAt || null
103
- };
174
+ // Metric history (query param: ?metric=task_success_rate&limit=168)
175
+ '/api/history': (query) => {
176
+ try {
177
+ const metric = query.get('metric') || 'task_success_rate';
178
+ const limit = parseInt(query.get('limit') || '168', 10);
179
+ return {
180
+ metric,
181
+ history: getMetricHistory(metric, limit)
182
+ };
183
+ } catch (e) {
184
+ return { error: e.message };
185
+ }
186
+ }
187
+ };
188
+
189
+ // ============================================================================
190
+ // LEGACY API COMPATIBILITY (v4.0 endpoints that still work)
191
+ // ============================================================================
192
+
193
+ const legacyApi = {
194
+ '/api/errors': () => ({
195
+ deprecation: 'Use /api/patterns instead',
196
+ redirect: '/api/patterns'
197
+ }),
198
+ '/api/corrections': () => ({
199
+ deprecation: 'Use /api/patterns instead',
200
+ redirect: '/api/patterns'
201
+ }),
202
+ '/api/lessons': () => {
203
+ const filePath = path.join(projectRoot, '.agent', 'knowledge', 'lessons-learned.json');
204
+ try {
205
+ if (fs.existsSync(filePath)) {
206
+ return JSON.parse(fs.readFileSync(filePath, 'utf8'));
207
+ }
208
+ } catch { }
209
+ return { lessons: [] };
104
210
  }
105
211
  };
106
212
 
@@ -118,7 +224,9 @@ const mimeTypes = {
118
224
  // Create server
119
225
  function createServer(port) {
120
226
  const server = http.createServer((req, res) => {
121
- const url = req.url.split('?')[0];
227
+ const urlParts = req.url.split('?');
228
+ const url = urlParts[0];
229
+ const query = new URLSearchParams(urlParts[1] || '');
122
230
 
123
231
  // CORS headers for local development
124
232
  res.setHeader('Access-Control-Allow-Origin', '*');
@@ -127,14 +235,14 @@ function createServer(port) {
127
235
 
128
236
  // Handle API requests
129
237
  if (url.startsWith('/api/')) {
130
- const handler = api[url];
238
+ const handler = api[url] || legacyApi[url];
131
239
  if (handler) {
132
240
  res.setHeader('Content-Type', 'application/json');
133
241
  res.writeHead(200);
134
- res.end(JSON.stringify(handler()));
242
+ res.end(JSON.stringify(handler(query)));
135
243
  } else {
136
244
  res.writeHead(404);
137
- res.end(JSON.stringify({ error: 'Not found' }));
245
+ res.end(JSON.stringify({ error: 'Not found', availableEndpoints: Object.keys(api) }));
138
246
  }
139
247
  return;
140
248
  }
@@ -163,17 +271,22 @@ function startServer(port = 3030) {
163
271
  const server = createServer(port);
164
272
 
165
273
  server.listen(port, () => {
166
- console.log(`${c.cyan}╔════════════════════════════════════════╗${c.reset}`);
167
- console.log(`${c.cyan}║${c.reset} 🧠 Auto-Learn Dashboard Server ${c.cyan}║${c.reset}`);
168
- console.log(`${c.cyan}╚════════════════════════════════════════╝${c.reset}\n`);
274
+ console.log(`${c.cyan}╔════════════════════════════════════════════════════╗${c.reset}`);
275
+ console.log(`${c.cyan}║${c.reset} 🧠 AutoLearn v6.0 Dashboard Server ${c.cyan}║${c.reset}`);
276
+ console.log(`${c.cyan}║${c.reset} ${c.green}Precision Learning Engine${c.reset} ${c.cyan}║${c.reset}`);
277
+ console.log(`${c.cyan}╚════════════════════════════════════════════════════╝${c.reset}\n`);
169
278
  console.log(`${c.green}✓ Server running at:${c.reset}`);
170
279
  console.log(` ${c.bold}http://localhost:${port}${c.reset}\n`);
171
- console.log(`${c.gray}API Endpoints:${c.reset}`);
172
- console.log(` GET /api/errors - Detected errors`);
173
- console.log(` GET /api/corrections - User corrections`);
174
- console.log(` GET /api/lessons - Lessons learned`);
175
- console.log(` GET /api/patterns - Pattern analysis`);
176
- console.log(` GET /api/summary - Dashboard summary\n`);
280
+ console.log(`${c.gray}API Endpoints (v6.0):${c.reset}`);
281
+ console.log(` GET /api/dashboard - Full dashboard data`);
282
+ console.log(` GET /api/kpis - 18 KPIs`);
283
+ console.log(` GET /api/summary - Summary stats`);
284
+ console.log(` GET /api/trends - Key trends`);
285
+ console.log(` GET /api/alerts - Active alerts`);
286
+ console.log(` GET /api/reinforcement - Reinforcement loop`);
287
+ console.log(` GET /api/ab-testing - A/B experiments`);
288
+ console.log(` GET /api/skills - Auto-generated skills`);
289
+ console.log(` GET /api/patterns - Causal patterns\n`);
177
290
  console.log(`${c.yellow}Press Ctrl+C to stop${c.reset}`);
178
291
  });
179
292
 
@@ -201,19 +314,26 @@ if (args.includes('--start') || args.includes('-s') || args.length === 0 || args
201
314
  }
202
315
  startServer(port);
203
316
  } else if (args.includes('--help') || args.includes('-h')) {
204
- console.log(`${c.cyan}dashboard_server - Auto-Learn Dashboard Web Server${c.reset}
317
+ console.log(`${c.cyan}AutoLearn v6.0 Dashboard Server${c.reset}
205
318
 
206
319
  ${c.bold}Usage:${c.reset}
207
320
  node dashboard_server.js Start server (default port 3030)
208
321
  node dashboard_server.js --port 8080 Start on custom port
209
322
  node dashboard_server.js --help Show this help
210
323
 
211
- ${c.bold}API Endpoints:${c.reset}
212
- GET /api/errors - All detected errors
213
- GET /api/corrections - All user corrections
214
- GET /api/lessons - All lessons learned
215
- GET /api/patterns - Pattern analysis results
216
- GET /api/summary - Dashboard summary data
324
+ ${c.bold}API Endpoints (v6.0):${c.reset}
325
+ GET /api/dashboard - Full dashboard aggregation
326
+ GET /api/kpis - 18 KPIs for Dashboard
327
+ GET /api/summary - Summary statistics
328
+ GET /api/trends - Week-over-week trends
329
+ GET /api/alerts - Active alerts
330
+ GET /api/gauges - Gauge widget data
331
+ GET /api/counters - Counter widget data
332
+ GET /api/reinforcement - Reinforcement loop stats
333
+ GET /api/ab-testing - A/B testing experiments
334
+ GET /api/skills - Auto-generated skills
335
+ GET /api/patterns - Causal patterns
336
+ GET /api/history?metric=X - Metric history
217
337
 
218
338
  ${c.bold}Example:${c.reset}
219
339
  node dashboard_server.js --port 3030
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pikakit",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Enterprise-grade Agent Skill Manager with Antigravity Skills support, Progressive Disclosure detection, and semantic routing validation",
5
5
  "license": "MIT",
6
6
  "author": "pikakit <pikakit@gmail.com>",
@@ -78,4 +78,4 @@
78
78
  "prettier": "^3.2.5",
79
79
  "vitest": "^4.0.18"
80
80
  }
81
- }
81
+ }