pikakit 3.0.5 → 3.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/lib/commands/install.js +119 -242
- package/package.json +3 -4
- package/lib/agent-cli/bin/agent.js +0 -187
- package/lib/agent-cli/dashboard/dashboard_server.js +0 -312
- package/lib/agent-cli/lib/ab-testing.js +0 -364
- package/lib/agent-cli/lib/audit.js +0 -154
- package/lib/agent-cli/lib/audit.test.js +0 -100
- package/lib/agent-cli/lib/auto-learn.js +0 -319
- package/lib/agent-cli/lib/backup.js +0 -138
- package/lib/agent-cli/lib/backup.test.js +0 -78
- package/lib/agent-cli/lib/causality-engine.js +0 -331
- package/lib/agent-cli/lib/cognitive-lesson.js +0 -476
- package/lib/agent-cli/lib/completion.js +0 -149
- package/lib/agent-cli/lib/config.js +0 -35
- package/lib/agent-cli/lib/dashboard-data.js +0 -380
- package/lib/agent-cli/lib/eslint-fix.js +0 -238
- package/lib/agent-cli/lib/evolution-signal.js +0 -215
- package/lib/agent-cli/lib/export.js +0 -86
- package/lib/agent-cli/lib/export.test.js +0 -65
- package/lib/agent-cli/lib/fix.js +0 -337
- package/lib/agent-cli/lib/fix.test.js +0 -80
- package/lib/agent-cli/lib/gemini-export.js +0 -83
- package/lib/agent-cli/lib/generate-registry.js +0 -42
- package/lib/agent-cli/lib/hooks/install-hooks.js +0 -152
- package/lib/agent-cli/lib/hooks/lint-learn.js +0 -172
- package/lib/agent-cli/lib/icons.js +0 -93
- package/lib/agent-cli/lib/ignore.js +0 -116
- package/lib/agent-cli/lib/ignore.test.js +0 -58
- package/lib/agent-cli/lib/init.js +0 -124
- package/lib/agent-cli/lib/knowledge-index.js +0 -326
- package/lib/agent-cli/lib/knowledge-metrics.js +0 -335
- package/lib/agent-cli/lib/knowledge-retention.js +0 -398
- package/lib/agent-cli/lib/knowledge-validator.js +0 -312
- package/lib/agent-cli/lib/learn.js +0 -255
- package/lib/agent-cli/lib/learn.test.js +0 -70
- package/lib/agent-cli/lib/metrics-collector.js +0 -410
- package/lib/agent-cli/lib/proposals.js +0 -199
- package/lib/agent-cli/lib/proposals.test.js +0 -56
- package/lib/agent-cli/lib/recall.js +0 -835
- package/lib/agent-cli/lib/recall.test.js +0 -107
- package/lib/agent-cli/lib/reinforcement.js +0 -299
- package/lib/agent-cli/lib/selfevolution-bridge.js +0 -167
- package/lib/agent-cli/lib/settings.js +0 -203
- package/lib/agent-cli/lib/skill-generator.js +0 -379
- package/lib/agent-cli/lib/skill-learn.js +0 -296
- package/lib/agent-cli/lib/stats.js +0 -132
- package/lib/agent-cli/lib/stats.test.js +0 -94
- package/lib/agent-cli/lib/types.js +0 -33
- package/lib/agent-cli/lib/ui/audit-ui.js +0 -146
- package/lib/agent-cli/lib/ui/backup-ui.js +0 -107
- package/lib/agent-cli/lib/ui/clack-helpers.js +0 -317
- package/lib/agent-cli/lib/ui/common.js +0 -83
- package/lib/agent-cli/lib/ui/completion-ui.js +0 -126
- package/lib/agent-cli/lib/ui/custom-select.js +0 -69
- package/lib/agent-cli/lib/ui/dashboard-ui.js +0 -222
- package/lib/agent-cli/lib/ui/evolution-signals-ui.js +0 -107
- package/lib/agent-cli/lib/ui/export-ui.js +0 -94
- package/lib/agent-cli/lib/ui/fix-all-ui.js +0 -191
- package/lib/agent-cli/lib/ui/help-ui.js +0 -49
- package/lib/agent-cli/lib/ui/index.js +0 -199
- package/lib/agent-cli/lib/ui/init-ui.js +0 -56
- package/lib/agent-cli/lib/ui/knowledge-ui.js +0 -55
- package/lib/agent-cli/lib/ui/learn-ui.js +0 -706
- package/lib/agent-cli/lib/ui/lessons-ui.js +0 -148
- package/lib/agent-cli/lib/ui/pretty.js +0 -145
- package/lib/agent-cli/lib/ui/proposals-ui.js +0 -99
- package/lib/agent-cli/lib/ui/recall-ui.js +0 -342
- package/lib/agent-cli/lib/ui/routing-demo.js +0 -79
- package/lib/agent-cli/lib/ui/routing-ui.js +0 -325
- package/lib/agent-cli/lib/ui/settings-ui.js +0 -381
- package/lib/agent-cli/lib/ui/stats-ui.js +0 -123
- package/lib/agent-cli/lib/ui/watch-ui.js +0 -236
- package/lib/agent-cli/lib/watcher.js +0 -181
- package/lib/agent-cli/lib/watcher.test.js +0 -85
- package/lib/agent-cli/src/MIGRATION.md +0 -418
- package/lib/agent-cli/src/README.md +0 -367
- package/lib/agent-cli/src/core/evolution/evolution-signal.js +0 -42
- package/lib/agent-cli/src/core/evolution/index.js +0 -17
- package/lib/agent-cli/src/core/evolution/review-gate.js +0 -40
- package/lib/agent-cli/src/core/evolution/signal-detector.js +0 -137
- package/lib/agent-cli/src/core/evolution/signal-queue.js +0 -79
- package/lib/agent-cli/src/core/evolution/threshold-checker.js +0 -79
- package/lib/agent-cli/src/core/index.js +0 -15
- package/lib/agent-cli/src/core/learning/cognitive-enhancer.js +0 -282
- package/lib/agent-cli/src/core/learning/index.js +0 -12
- package/lib/agent-cli/src/core/learning/lesson-synthesizer.js +0 -83
- package/lib/agent-cli/src/core/scanning/index.js +0 -14
- package/lib/agent-cli/src/data/index.js +0 -13
- package/lib/agent-cli/src/data/repositories/index.js +0 -8
- package/lib/agent-cli/src/data/repositories/lesson-repository.js +0 -130
- package/lib/agent-cli/src/data/repositories/signal-repository.js +0 -119
- package/lib/agent-cli/src/data/storage/index.js +0 -8
- package/lib/agent-cli/src/data/storage/json-storage.js +0 -64
- package/lib/agent-cli/src/data/storage/yaml-storage.js +0 -66
- package/lib/agent-cli/src/infrastructure/index.js +0 -13
- package/lib/agent-cli/src/presentation/formatters/skill-formatter.js +0 -232
- package/lib/agent-cli/src/services/export-service.js +0 -162
- package/lib/agent-cli/src/services/index.js +0 -13
- package/lib/agent-cli/src/services/learning-service.js +0 -99
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Smart Agent CLI - ESM Version (Production-Ready)
|
|
4
|
-
*
|
|
5
|
-
* The main interface for humans to interact with the Smart Agent Skills system.
|
|
6
|
-
*
|
|
7
|
-
* Commands:
|
|
8
|
-
* learn Add new lessons to memory
|
|
9
|
-
* recall Check files against memory
|
|
10
|
-
* audit Full compliance audit
|
|
11
|
-
* watch Real-time file monitoring
|
|
12
|
-
* stats Knowledge base statistics
|
|
13
|
-
* install-hooks Install git pre-commit hook
|
|
14
|
-
* lint-learn Auto-learn from ESLint output
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { spawn } from "child_process";
|
|
18
|
-
import path from "path";
|
|
19
|
-
import { fileURLToPath } from "url";
|
|
20
|
-
import { VERSION } from "../lib/config.js";
|
|
21
|
-
|
|
22
|
-
// Fix UTF-8 output on Windows PowerShell/Console
|
|
23
|
-
if (process.platform === "win32" && process.stdout.isTTY) {
|
|
24
|
-
process.stdout.setDefaultEncoding("utf8");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
28
|
-
const ARGS = process.argv.slice(2);
|
|
29
|
-
const COMMAND = ARGS[0];
|
|
30
|
-
const SCRIPTS_DIR = path.join(__dirname, "..", "lib");
|
|
31
|
-
const HOOKS_DIR = path.join(SCRIPTS_DIR, "hooks");
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Run a script with given arguments
|
|
35
|
-
* @param {string} script - Script filename (relative to lib/)
|
|
36
|
-
* @param {string[]} args - Arguments to pass
|
|
37
|
-
* @param {string} baseDir - Base directory for script
|
|
38
|
-
*/
|
|
39
|
-
function run(script, args = [], baseDir = SCRIPTS_DIR) {
|
|
40
|
-
const scriptPath = path.join(baseDir, script);
|
|
41
|
-
const child = spawn("node", [scriptPath, ...args], {
|
|
42
|
-
stdio: "inherit",
|
|
43
|
-
shell: true
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
child.on("close", (code) => {
|
|
47
|
-
process.exit(code || 0);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
child.on("error", (err) => {
|
|
51
|
-
console.error(`❌ Failed to run ${script}:`, err.message);
|
|
52
|
-
process.exit(1);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function printHelp() {
|
|
57
|
-
console.log(`
|
|
58
|
-
🤖 PikaKit CLI v${VERSION}
|
|
59
|
-
|
|
60
|
-
Usage: ag-smart <command> [options]
|
|
61
|
-
|
|
62
|
-
${"─".repeat(50)}
|
|
63
|
-
|
|
64
|
-
📚 CORE COMMANDS:
|
|
65
|
-
|
|
66
|
-
learn Teach a new lesson to the memory
|
|
67
|
-
ag-smart learn --add --pattern "var " --message "Use let/const"
|
|
68
|
-
ag-smart learn --list
|
|
69
|
-
ag-smart learn --remove LEARN-001
|
|
70
|
-
|
|
71
|
-
recall Check file(s) against learned patterns
|
|
72
|
-
ag-smart recall src/app.js
|
|
73
|
-
ag-smart recall ./src
|
|
74
|
-
|
|
75
|
-
audit Run full compliance audit
|
|
76
|
-
ag-smart audit [directory]
|
|
77
|
-
|
|
78
|
-
${"─".repeat(50)}
|
|
79
|
-
|
|
80
|
-
🚀 PRODUCTION FEATURES:
|
|
81
|
-
|
|
82
|
-
watch Real-time file monitoring
|
|
83
|
-
ag-smart watch [directory]
|
|
84
|
-
|
|
85
|
-
stats Knowledge base statistics
|
|
86
|
-
ag-smart stats
|
|
87
|
-
|
|
88
|
-
install-hooks Install git pre-commit hook
|
|
89
|
-
ag-smart install-hooks
|
|
90
|
-
ag-smart install-hooks --remove
|
|
91
|
-
|
|
92
|
-
lint-learn Auto-learn from ESLint JSON output
|
|
93
|
-
npx eslint . --format json | ag-smart lint-learn
|
|
94
|
-
|
|
95
|
-
fix 🆕 Auto-fix violations
|
|
96
|
-
ag-smart fix <file|dir> [--mode safe|aggressive]
|
|
97
|
-
|
|
98
|
-
sync-skills 🆕 Sync hot patterns to SKILL.md
|
|
99
|
-
ag-smart sync-skills
|
|
100
|
-
|
|
101
|
-
index 🆕 Knowledge index management
|
|
102
|
-
ag-smart index --rebuild | --status
|
|
103
|
-
|
|
104
|
-
metrics 🆕 Knowledge metrics dashboard
|
|
105
|
-
ag-smart metrics [--json]
|
|
106
|
-
|
|
107
|
-
validate Schema validation for knowledge files
|
|
108
|
-
ag-smart validate [--fix] [--json]
|
|
109
|
-
|
|
110
|
-
retention Retention policy runner
|
|
111
|
-
ag-smart retention [--dry-run] [--apply] [--status]
|
|
112
|
-
|
|
113
|
-
${"─".repeat(50)}
|
|
114
|
-
|
|
115
|
-
📖 HELP:
|
|
116
|
-
|
|
117
|
-
help, --help Show this help message
|
|
118
|
-
--version Show version number
|
|
119
|
-
|
|
120
|
-
💡 Docs: https://github.com/pikakit/agent-skills
|
|
121
|
-
`);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Command routing
|
|
125
|
-
switch (COMMAND) {
|
|
126
|
-
// Core commands (v2 versions)
|
|
127
|
-
case "learn":
|
|
128
|
-
run("learn.js", ARGS.slice(1));
|
|
129
|
-
break;
|
|
130
|
-
case "recall":
|
|
131
|
-
run("recall.js", ARGS.slice(1));
|
|
132
|
-
break;
|
|
133
|
-
case "audit":
|
|
134
|
-
run("audit.js", ARGS.slice(1));
|
|
135
|
-
break;
|
|
136
|
-
|
|
137
|
-
// Production features
|
|
138
|
-
case "watch":
|
|
139
|
-
run("watcher.js", ARGS.slice(1));
|
|
140
|
-
break;
|
|
141
|
-
case "stats":
|
|
142
|
-
run("stats.js", ARGS.slice(1));
|
|
143
|
-
break;
|
|
144
|
-
case "install-hooks":
|
|
145
|
-
run("install-hooks.js", ARGS.slice(1), HOOKS_DIR);
|
|
146
|
-
break;
|
|
147
|
-
case "lint-learn":
|
|
148
|
-
run("lint-learn.js", ARGS.slice(1), HOOKS_DIR);
|
|
149
|
-
break;
|
|
150
|
-
case "fix":
|
|
151
|
-
run("fix.js", ARGS.slice(1));
|
|
152
|
-
break;
|
|
153
|
-
case "sync-skills":
|
|
154
|
-
run("skill-learn.js", ARGS.slice(1));
|
|
155
|
-
break;
|
|
156
|
-
case "index":
|
|
157
|
-
run("knowledge-index.js", ARGS.slice(1));
|
|
158
|
-
break;
|
|
159
|
-
case "metrics":
|
|
160
|
-
run("knowledge-metrics.js", ARGS.slice(1));
|
|
161
|
-
break;
|
|
162
|
-
case "validate":
|
|
163
|
-
run("knowledge-validator.js", ARGS.slice(1));
|
|
164
|
-
break;
|
|
165
|
-
case "retention":
|
|
166
|
-
run("knowledge-retention.js", ARGS.slice(1));
|
|
167
|
-
break;
|
|
168
|
-
|
|
169
|
-
// Meta
|
|
170
|
-
case "--version":
|
|
171
|
-
case "-v":
|
|
172
|
-
console.log(VERSION);
|
|
173
|
-
break;
|
|
174
|
-
case "help":
|
|
175
|
-
case "--help":
|
|
176
|
-
case "-h":
|
|
177
|
-
printHelp();
|
|
178
|
-
break;
|
|
179
|
-
case undefined:
|
|
180
|
-
// No command = show interactive Clack menu
|
|
181
|
-
import("../lib/ui/index.js").then(m => m.showMainMenu()).catch(console.error);
|
|
182
|
-
break;
|
|
183
|
-
default:
|
|
184
|
-
console.log(`❌ Unknown command: ${COMMAND}`);
|
|
185
|
-
console.log(" Run 'ag-smart help' for available commands.\n");
|
|
186
|
-
process.exit(1);
|
|
187
|
-
}
|
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Dashboard Server v7.0 - PikaKit Precision Learning Engine
|
|
4
|
-
*
|
|
5
|
-
* Modern ES Modules server with REST API endpoints.
|
|
6
|
-
* Serves real-time metrics from PikaKit learning system.
|
|
7
|
-
*
|
|
8
|
-
* @version 7.0.0
|
|
9
|
-
* @author PikaKit
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import http from 'http';
|
|
13
|
-
import fs from 'fs';
|
|
14
|
-
import path from 'path';
|
|
15
|
-
import { fileURLToPath } from 'url';
|
|
16
|
-
|
|
17
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
18
|
-
const __dirname = path.dirname(__filename);
|
|
19
|
-
|
|
20
|
-
// Colors for terminal
|
|
21
|
-
const c = {
|
|
22
|
-
reset: '\x1b[0m',
|
|
23
|
-
bold: '\x1b[1m',
|
|
24
|
-
cyan: '\x1b[36m',
|
|
25
|
-
green: '\x1b[32m',
|
|
26
|
-
yellow: '\x1b[33m',
|
|
27
|
-
gray: '\x1b[90m'
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// Find project root
|
|
31
|
-
function findProjectRoot() {
|
|
32
|
-
let dir = process.cwd();
|
|
33
|
-
while (dir !== path.dirname(dir)) {
|
|
34
|
-
if (fs.existsSync(path.join(dir, '.agent'))) return dir;
|
|
35
|
-
if (fs.existsSync(path.join(dir, 'package.json'))) return dir;
|
|
36
|
-
dir = path.dirname(dir);
|
|
37
|
-
}
|
|
38
|
-
return process.cwd();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const projectRoot = findProjectRoot();
|
|
42
|
-
const dashboardPath = path.join(__dirname, '..', 'dashboard');
|
|
43
|
-
|
|
44
|
-
// ============================================================================
|
|
45
|
-
// DATA PROVIDERS
|
|
46
|
-
// ============================================================================
|
|
47
|
-
|
|
48
|
-
// Safe import helper
|
|
49
|
-
async function safeImport(modulePath) {
|
|
50
|
-
try {
|
|
51
|
-
return await import(modulePath);
|
|
52
|
-
} catch (e) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Load data modules dynamically
|
|
58
|
-
let metricsCollector = null;
|
|
59
|
-
let causalityEngine = null;
|
|
60
|
-
let skillGenerator = null;
|
|
61
|
-
let abTesting = null;
|
|
62
|
-
let reinforcement = null;
|
|
63
|
-
|
|
64
|
-
async function loadModules() {
|
|
65
|
-
const libPath = path.join(__dirname, '..', 'lib');
|
|
66
|
-
metricsCollector = await safeImport(path.join(libPath, 'metrics-collector.js'));
|
|
67
|
-
causalityEngine = await safeImport(path.join(libPath, 'causality-engine.js'));
|
|
68
|
-
skillGenerator = await safeImport(path.join(libPath, 'skill-generator.js'));
|
|
69
|
-
abTesting = await safeImport(path.join(libPath, 'ab-testing.js'));
|
|
70
|
-
reinforcement = await safeImport(path.join(libPath, 'reinforcement.js'));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// ============================================================================
|
|
74
|
-
// API HANDLERS
|
|
75
|
-
// ============================================================================
|
|
76
|
-
|
|
77
|
-
const api = {
|
|
78
|
-
// Full dashboard data
|
|
79
|
-
'/api/dashboard': () => {
|
|
80
|
-
try {
|
|
81
|
-
const kpis = metricsCollector?.getKPIs?.() || { kpis: {} };
|
|
82
|
-
const summary = {
|
|
83
|
-
totalTasks: metricsCollector?.getMetricValue?.('total_tasks') || 0,
|
|
84
|
-
patternsLearned: causalityEngine?.getPatternCount?.() || 0,
|
|
85
|
-
skillsGenerated: skillGenerator?.getSkillCount?.() || 0,
|
|
86
|
-
version: '7.0.0'
|
|
87
|
-
};
|
|
88
|
-
return { kpis: { kpis }, summary, version: '7.0.0' };
|
|
89
|
-
} catch (e) {
|
|
90
|
-
return { kpis: { kpis: {} }, summary: {}, error: e.message, version: '7.0.0' };
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
// KPIs only
|
|
95
|
-
'/api/kpis': () => {
|
|
96
|
-
try {
|
|
97
|
-
return metricsCollector?.getKPIs?.() || { kpis: {} };
|
|
98
|
-
} catch (e) {
|
|
99
|
-
return { kpis: {}, error: e.message };
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
// Alerts
|
|
104
|
-
'/api/alerts': () => {
|
|
105
|
-
try {
|
|
106
|
-
const kpis = metricsCollector?.getKPIs?.()?.kpis || {};
|
|
107
|
-
const alerts = [];
|
|
108
|
-
|
|
109
|
-
// Generate alerts based on KPI thresholds
|
|
110
|
-
if (kpis.task_success_rate && parseFloat(kpis.task_success_rate.value) < 80) {
|
|
111
|
-
alerts.push({ id: 'low_success', severity: 'warning', message: 'Task success rate below 80%' });
|
|
112
|
-
}
|
|
113
|
-
if (kpis.error_repeat_rate && parseFloat(kpis.error_repeat_rate.value) > 10) {
|
|
114
|
-
alerts.push({ id: 'high_error', severity: 'warning', message: 'Error repeat rate above 10%' });
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return { alerts, count: alerts.length };
|
|
118
|
-
} catch (e) {
|
|
119
|
-
return { alerts: [], error: e.message };
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
// Skills
|
|
124
|
-
'/api/skills': () => {
|
|
125
|
-
try {
|
|
126
|
-
const skills = skillGenerator?.getAllSkills?.() || [];
|
|
127
|
-
return {
|
|
128
|
-
skills,
|
|
129
|
-
stats: { total: skills.length }
|
|
130
|
-
};
|
|
131
|
-
} catch (e) {
|
|
132
|
-
return { skills: [], stats: { total: 0 }, error: e.message };
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
// A/B Testing
|
|
137
|
-
'/api/ab-testing': () => {
|
|
138
|
-
try {
|
|
139
|
-
const active = abTesting?.getActiveTests?.() || [];
|
|
140
|
-
const completed = abTesting?.getCompletedTests?.() || [];
|
|
141
|
-
return {
|
|
142
|
-
active,
|
|
143
|
-
completed,
|
|
144
|
-
stats: { running: active.length, completed: completed.length }
|
|
145
|
-
};
|
|
146
|
-
} catch (e) {
|
|
147
|
-
return { active: [], completed: [], stats: { running: 0, completed: 0 }, error: e.message };
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
// Reinforcement Loop
|
|
152
|
-
'/api/reinforcement': () => {
|
|
153
|
-
try {
|
|
154
|
-
const stats = reinforcement?.getStats?.() || {};
|
|
155
|
-
return {
|
|
156
|
-
totalRewards: stats.rewards || 0,
|
|
157
|
-
totalPenalties: stats.penalties || 0,
|
|
158
|
-
averageConfidence: stats.avgConfidence || null
|
|
159
|
-
};
|
|
160
|
-
} catch (e) {
|
|
161
|
-
return { totalRewards: 0, totalPenalties: 0, error: e.message };
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
// Patterns
|
|
166
|
-
'/api/patterns': () => {
|
|
167
|
-
try {
|
|
168
|
-
const patterns = causalityEngine?.loadCausalPatterns?.() || [];
|
|
169
|
-
return { total: patterns.length, patterns: patterns.slice(0, 20) };
|
|
170
|
-
} catch (e) {
|
|
171
|
-
return { total: 0, patterns: [], error: e.message };
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
|
|
175
|
-
// Summary (legacy support)
|
|
176
|
-
'/api/summary': () => {
|
|
177
|
-
return { status: 'ok', version: '7.0.0', server: 'PikaKit Dashboard Server' };
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
// ============================================================================
|
|
182
|
-
// MIME TYPES
|
|
183
|
-
// ============================================================================
|
|
184
|
-
|
|
185
|
-
const mimeTypes = {
|
|
186
|
-
'.html': 'text/html',
|
|
187
|
-
'.css': 'text/css',
|
|
188
|
-
'.js': 'application/javascript',
|
|
189
|
-
'.json': 'application/json',
|
|
190
|
-
'.png': 'image/png',
|
|
191
|
-
'.jpg': 'image/jpeg',
|
|
192
|
-
'.svg': 'image/svg+xml'
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
// ============================================================================
|
|
196
|
-
// SERVER
|
|
197
|
-
// ============================================================================
|
|
198
|
-
|
|
199
|
-
function createServer(port) {
|
|
200
|
-
const server = http.createServer(async (req, res) => {
|
|
201
|
-
// CORS headers
|
|
202
|
-
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
203
|
-
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
204
|
-
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
205
|
-
|
|
206
|
-
if (req.method === 'OPTIONS') {
|
|
207
|
-
res.writeHead(204);
|
|
208
|
-
res.end();
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const url = new URL(req.url, `http://localhost:${port}`);
|
|
213
|
-
const pathname = url.pathname;
|
|
214
|
-
|
|
215
|
-
// API routes
|
|
216
|
-
if (api[pathname]) {
|
|
217
|
-
const data = api[pathname](url.searchParams);
|
|
218
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
219
|
-
res.end(JSON.stringify(data, null, 2));
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Static files
|
|
224
|
-
let filePath = pathname === '/' ? 'index.html' : pathname.slice(1);
|
|
225
|
-
filePath = path.join(dashboardPath, filePath);
|
|
226
|
-
|
|
227
|
-
if (fs.existsSync(filePath)) {
|
|
228
|
-
const ext = path.extname(filePath);
|
|
229
|
-
const contentType = mimeTypes[ext] || 'application/octet-stream';
|
|
230
|
-
const content = fs.readFileSync(filePath);
|
|
231
|
-
res.writeHead(200, { 'Content-Type': contentType });
|
|
232
|
-
res.end(content);
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// 404
|
|
237
|
-
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
238
|
-
res.end(JSON.stringify({ error: 'Not found', path: pathname }));
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
return server;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
async function startServer(port = 3030) {
|
|
245
|
-
await loadModules();
|
|
246
|
-
|
|
247
|
-
const server = createServer(port);
|
|
248
|
-
|
|
249
|
-
server.listen(port, () => {
|
|
250
|
-
console.log(`
|
|
251
|
-
${c.bold}${c.cyan}╔════════════════════════════════════════════════════════════╗${c.reset}
|
|
252
|
-
${c.bold}${c.cyan}║${c.reset} ${c.cyan}║${c.reset}
|
|
253
|
-
${c.bold}${c.cyan}║${c.reset} 🧠 ${c.bold}PikaKit Dashboard Server v7.0${c.reset} ${c.cyan}║${c.reset}
|
|
254
|
-
${c.bold}${c.cyan}║${c.reset} ${c.cyan}║${c.reset}
|
|
255
|
-
${c.bold}${c.cyan}║${c.reset} ${c.green}→${c.reset} Dashboard: ${c.yellow}http://localhost:${port}${c.reset} ${c.cyan}║${c.reset}
|
|
256
|
-
${c.bold}${c.cyan}║${c.reset} ${c.green}→${c.reset} API Base: ${c.yellow}http://localhost:${port}/api${c.reset} ${c.cyan}║${c.reset}
|
|
257
|
-
${c.bold}${c.cyan}║${c.reset} ${c.cyan}║${c.reset}
|
|
258
|
-
${c.bold}${c.cyan}║${c.reset} ${c.gray}Press Ctrl+C to stop${c.reset} ${c.cyan}║${c.reset}
|
|
259
|
-
${c.bold}${c.cyan}║${c.reset} ${c.cyan}║${c.reset}
|
|
260
|
-
${c.bold}${c.cyan}╚════════════════════════════════════════════════════════════╝${c.reset}
|
|
261
|
-
`);
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
server.on('error', (e) => {
|
|
265
|
-
if (e.code === 'EADDRINUSE') {
|
|
266
|
-
console.log(`${c.yellow}Port ${port} in use, trying ${port + 1}...${c.reset}`);
|
|
267
|
-
startServer(port + 1);
|
|
268
|
-
} else {
|
|
269
|
-
console.error(`${c.red}Server error:${c.reset}`, e.message);
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
return server;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// CLI handling
|
|
277
|
-
const args = process.argv.slice(2);
|
|
278
|
-
|
|
279
|
-
if (args.includes('--help') || args.includes('-h')) {
|
|
280
|
-
console.log(`
|
|
281
|
-
${c.bold}PikaKit Dashboard Server v7.0${c.reset}
|
|
282
|
-
|
|
283
|
-
${c.bold}Usage:${c.reset}
|
|
284
|
-
node dashboard-server.js [options]
|
|
285
|
-
|
|
286
|
-
${c.bold}Options:${c.reset}
|
|
287
|
-
--port, -p <number> Port to run on (default: 3030)
|
|
288
|
-
--help, -h Show this help
|
|
289
|
-
|
|
290
|
-
${c.bold}API Endpoints:${c.reset}
|
|
291
|
-
GET /api/dashboard Full dashboard data
|
|
292
|
-
GET /api/kpis KPI metrics only
|
|
293
|
-
GET /api/alerts Active alerts
|
|
294
|
-
GET /api/skills Auto-generated skills
|
|
295
|
-
GET /api/ab-testing A/B test experiments
|
|
296
|
-
GET /api/reinforcement Reinforcement loop stats
|
|
297
|
-
GET /api/patterns Causal patterns
|
|
298
|
-
GET /api/summary Server status
|
|
299
|
-
|
|
300
|
-
${c.bold}Example:${c.reset}
|
|
301
|
-
node dashboard-server.js --port 3030
|
|
302
|
-
`);
|
|
303
|
-
} else {
|
|
304
|
-
let port = 3030;
|
|
305
|
-
const portIdx = args.findIndex(a => a === '--port' || a === '-p');
|
|
306
|
-
if (portIdx !== -1 && args[portIdx + 1]) {
|
|
307
|
-
port = parseInt(args[portIdx + 1], 10) || 3030;
|
|
308
|
-
}
|
|
309
|
-
startServer(port);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
export { createServer, startServer };
|