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,335 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Knowledge Metrics Collector
|
|
4
|
-
*
|
|
5
|
-
* Aggregates KPIs from knowledge base for observability.
|
|
6
|
-
* Metrics are collected on-demand or on scan completion.
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* agent metrics # Show dashboard
|
|
10
|
-
* agent metrics --json # JSON output for CI
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import fs from 'fs';
|
|
14
|
-
import path from 'path';
|
|
15
|
-
import yaml from 'js-yaml';
|
|
16
|
-
import { KNOWLEDGE_DIR } from './config.js';
|
|
17
|
-
import { loadIndex } from './knowledge-index.js';
|
|
18
|
-
|
|
19
|
-
const METRICS_PATH = path.join(KNOWLEDGE_DIR, 'metrics.json');
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Load mistakes and improvements
|
|
23
|
-
* @returns {{ mistakes: Array, improvements: Array }}
|
|
24
|
-
*/
|
|
25
|
-
function loadKnowledge() {
|
|
26
|
-
const mistakes = [];
|
|
27
|
-
const improvements = [];
|
|
28
|
-
|
|
29
|
-
const mistakesPath = path.join(KNOWLEDGE_DIR, 'mistakes.yaml');
|
|
30
|
-
if (fs.existsSync(mistakesPath)) {
|
|
31
|
-
const data = yaml.load(fs.readFileSync(mistakesPath, 'utf8'));
|
|
32
|
-
if (data?.mistakes) mistakes.push(...data.mistakes);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const improvementsPath = path.join(KNOWLEDGE_DIR, 'improvements.yaml');
|
|
36
|
-
if (fs.existsSync(improvementsPath)) {
|
|
37
|
-
const data = yaml.load(fs.readFileSync(improvementsPath, 'utf8'));
|
|
38
|
-
if (data?.improvements) improvements.push(...data.improvements);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return { mistakes, improvements };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Calculate average confidence score
|
|
46
|
-
* @param {Array} lessons
|
|
47
|
-
* @returns {number}
|
|
48
|
-
*/
|
|
49
|
-
function calculateAvgConfidence(lessons) {
|
|
50
|
-
if (lessons.length === 0) return 0;
|
|
51
|
-
|
|
52
|
-
const total = lessons.reduce((sum, l) => {
|
|
53
|
-
return sum + (l.cognitive?.confidence || 0.3);
|
|
54
|
-
}, 0);
|
|
55
|
-
|
|
56
|
-
return total / lessons.length;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Calculate escalation rate
|
|
61
|
-
* @param {Array} mistakes
|
|
62
|
-
* @returns {number}
|
|
63
|
-
*/
|
|
64
|
-
function calculateEscalationRate(mistakes) {
|
|
65
|
-
if (mistakes.length === 0) return 0;
|
|
66
|
-
|
|
67
|
-
const escalated = mistakes.filter(m => m.autoEscalated === true).length;
|
|
68
|
-
return escalated / mistakes.length;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Calculate fix rate
|
|
73
|
-
* @param {Array} improvements
|
|
74
|
-
* @returns {number}
|
|
75
|
-
*/
|
|
76
|
-
function calculateFixRate(improvements) {
|
|
77
|
-
if (improvements.length === 0) return 0;
|
|
78
|
-
|
|
79
|
-
const applied = improvements.filter(i => (i.appliedCount || 0) > 0).length;
|
|
80
|
-
return applied / improvements.length;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Get 7-day hit trend
|
|
85
|
-
* @param {Array} lessons
|
|
86
|
-
* @returns {number[]}
|
|
87
|
-
*/
|
|
88
|
-
function get7DayTrend(lessons) {
|
|
89
|
-
const now = Date.now();
|
|
90
|
-
const dayMs = 24 * 60 * 60 * 1000;
|
|
91
|
-
const trend = new Array(7).fill(0);
|
|
92
|
-
|
|
93
|
-
for (const lesson of lessons) {
|
|
94
|
-
if (lesson.lastHit) {
|
|
95
|
-
const hitTime = new Date(lesson.lastHit).getTime();
|
|
96
|
-
const daysAgo = Math.floor((now - hitTime) / dayMs);
|
|
97
|
-
|
|
98
|
-
if (daysAgo >= 0 && daysAgo < 7) {
|
|
99
|
-
trend[6 - daysAgo] += lesson.hitCount || 0;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return trend;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Get new lessons in last 30 days
|
|
109
|
-
* @param {Array} lessons
|
|
110
|
-
* @returns {number}
|
|
111
|
-
*/
|
|
112
|
-
function getNewLessonsLast30Days(lessons) {
|
|
113
|
-
const now = Date.now();
|
|
114
|
-
const thirtyDaysMs = 30 * 24 * 60 * 60 * 1000;
|
|
115
|
-
|
|
116
|
-
return lessons.filter(l => {
|
|
117
|
-
if (l.addedAt) {
|
|
118
|
-
const addedTime = new Date(l.addedAt).getTime();
|
|
119
|
-
return (now - addedTime) < thirtyDaysMs;
|
|
120
|
-
}
|
|
121
|
-
return false;
|
|
122
|
-
}).length;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Get top violations
|
|
127
|
-
* @param {Array} mistakes
|
|
128
|
-
* @param {number} limit
|
|
129
|
-
* @returns {Array}
|
|
130
|
-
*/
|
|
131
|
-
function getTopViolations(mistakes, limit = 5) {
|
|
132
|
-
return mistakes
|
|
133
|
-
.map(m => ({
|
|
134
|
-
id: m.id,
|
|
135
|
-
pattern: m.pattern,
|
|
136
|
-
hitCount: m.hitCount || 0,
|
|
137
|
-
severity: m.severity || 'WARNING'
|
|
138
|
-
}))
|
|
139
|
-
.sort((a, b) => b.hitCount - a.hitCount)
|
|
140
|
-
.slice(0, limit);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Get stale lessons (no hits, old)
|
|
145
|
-
* @param {Array} lessons
|
|
146
|
-
* @returns {number}
|
|
147
|
-
*/
|
|
148
|
-
function getStaleLessonsCount(lessons) {
|
|
149
|
-
const now = Date.now();
|
|
150
|
-
const ninetyDaysMs = 90 * 24 * 60 * 60 * 1000;
|
|
151
|
-
|
|
152
|
-
return lessons.filter(l => {
|
|
153
|
-
const noHits = !l.hitCount || l.hitCount === 0;
|
|
154
|
-
const isOld = l.addedAt && (now - new Date(l.addedAt).getTime()) > ninetyDaysMs;
|
|
155
|
-
return noHits && isOld;
|
|
156
|
-
}).length;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Collect all metrics
|
|
161
|
-
* @returns {Object}
|
|
162
|
-
*/
|
|
163
|
-
export function collectMetrics() {
|
|
164
|
-
const { mistakes, improvements } = loadKnowledge();
|
|
165
|
-
const allLessons = [...mistakes, ...improvements];
|
|
166
|
-
|
|
167
|
-
// Load index for additional stats
|
|
168
|
-
let indexStats = { totalPatterns: 0, totalTags: 0 };
|
|
169
|
-
try {
|
|
170
|
-
const index = loadIndex();
|
|
171
|
-
indexStats = index.stats || indexStats;
|
|
172
|
-
} catch (e) {
|
|
173
|
-
// Index may not exist yet
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const metrics = {
|
|
177
|
-
version: 1,
|
|
178
|
-
lastUpdated: new Date().toISOString(),
|
|
179
|
-
|
|
180
|
-
kpis: {
|
|
181
|
-
totalLessons: allLessons.length,
|
|
182
|
-
totalMistakes: mistakes.length,
|
|
183
|
-
totalImprovements: improvements.length,
|
|
184
|
-
activePatterns: allLessons.filter(l => (l.hitCount || 0) > 0).length,
|
|
185
|
-
totalHits: allLessons.reduce((sum, l) => sum + (l.hitCount || 0), 0),
|
|
186
|
-
avgConfidence: parseFloat(calculateAvgConfidence(allLessons).toFixed(2)),
|
|
187
|
-
escalationRate: parseFloat(calculateEscalationRate(mistakes).toFixed(2)),
|
|
188
|
-
fixRate: parseFloat(calculateFixRate(improvements).toFixed(2)),
|
|
189
|
-
staleLessons: getStaleLessonsCount(allLessons)
|
|
190
|
-
},
|
|
191
|
-
|
|
192
|
-
trends: {
|
|
193
|
-
hitsLast7Days: get7DayTrend(allLessons),
|
|
194
|
-
newLessonsLast30Days: getNewLessonsLast30Days(allLessons)
|
|
195
|
-
},
|
|
196
|
-
|
|
197
|
-
topViolations: getTopViolations(mistakes, 5),
|
|
198
|
-
|
|
199
|
-
breakdown: {
|
|
200
|
-
bySeverity: {
|
|
201
|
-
ERROR: mistakes.filter(m => m.severity === 'ERROR').length,
|
|
202
|
-
WARNING: mistakes.filter(m => m.severity === 'WARNING').length,
|
|
203
|
-
INFO: improvements.length
|
|
204
|
-
},
|
|
205
|
-
byMaturity: {
|
|
206
|
-
stable: allLessons.filter(l => l.cognitive?.maturity === 'stable').length,
|
|
207
|
-
learning: allLessons.filter(l => l.cognitive?.maturity === 'learning').length,
|
|
208
|
-
deprecated: allLessons.filter(l => l.cognitive?.maturity === 'deprecated').length
|
|
209
|
-
}
|
|
210
|
-
},
|
|
211
|
-
|
|
212
|
-
index: indexStats
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
return metrics;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Save metrics to file
|
|
220
|
-
* @param {Object} metrics
|
|
221
|
-
*/
|
|
222
|
-
export function saveMetrics(metrics) {
|
|
223
|
-
fs.writeFileSync(METRICS_PATH, JSON.stringify(metrics, null, 2), 'utf8');
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Load cached metrics
|
|
228
|
-
* @returns {Object|null}
|
|
229
|
-
*/
|
|
230
|
-
export function loadMetrics() {
|
|
231
|
-
if (!fs.existsSync(METRICS_PATH)) {
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
try {
|
|
236
|
-
return JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8'));
|
|
237
|
-
} catch (e) {
|
|
238
|
-
return null;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Display metrics dashboard
|
|
244
|
-
* @param {Object} metrics
|
|
245
|
-
*/
|
|
246
|
-
function displayDashboard(metrics) {
|
|
247
|
-
console.log(`
|
|
248
|
-
📊 Knowledge Metrics Dashboard
|
|
249
|
-
${'─'.repeat(50)}
|
|
250
|
-
|
|
251
|
-
📈 KPIs:
|
|
252
|
-
Total Lessons: ${metrics.kpis.totalLessons}
|
|
253
|
-
Active Patterns: ${metrics.kpis.activePatterns} (${Math.round((metrics.kpis.activePatterns / metrics.kpis.totalLessons) * 100)}%)
|
|
254
|
-
Total Hits: ${metrics.kpis.totalHits}
|
|
255
|
-
Avg Confidence: ${metrics.kpis.avgConfidence}
|
|
256
|
-
Escalation Rate: ${Math.round(metrics.kpis.escalationRate * 100)}%
|
|
257
|
-
Fix Rate: ${Math.round(metrics.kpis.fixRate * 100)}%
|
|
258
|
-
Stale Lessons: ${metrics.kpis.staleLessons}
|
|
259
|
-
|
|
260
|
-
📊 Breakdown:
|
|
261
|
-
Mistakes: ${metrics.kpis.totalMistakes}
|
|
262
|
-
ERROR: ${metrics.breakdown.bySeverity.ERROR}
|
|
263
|
-
WARNING: ${metrics.breakdown.bySeverity.WARNING}
|
|
264
|
-
Improvements: ${metrics.kpis.totalImprovements}
|
|
265
|
-
|
|
266
|
-
🧠 Maturity:
|
|
267
|
-
Stable: ${metrics.breakdown.byMaturity.stable}
|
|
268
|
-
Learning: ${metrics.breakdown.byMaturity.learning}
|
|
269
|
-
Deprecated: ${metrics.breakdown.byMaturity.deprecated}
|
|
270
|
-
|
|
271
|
-
📈 Trends:
|
|
272
|
-
7-Day Hits: ${sparkline(metrics.trends.hitsLast7Days)}
|
|
273
|
-
New (30d): ${metrics.trends.newLessonsLast30Days}
|
|
274
|
-
|
|
275
|
-
🔥 Top Violations:`);
|
|
276
|
-
|
|
277
|
-
metrics.topViolations.forEach((v, i) => {
|
|
278
|
-
console.log(` ${i + 1}. ${v.id}: ${v.hitCount} hits (${v.severity})`);
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
console.log(`
|
|
282
|
-
🔎 Index:
|
|
283
|
-
Patterns: ${metrics.index.totalPatterns}
|
|
284
|
-
Tags: ${metrics.index.totalTags}
|
|
285
|
-
|
|
286
|
-
Last Updated: ${new Date(metrics.lastUpdated).toLocaleString()}
|
|
287
|
-
`);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Generate ASCII sparkline
|
|
292
|
-
* @param {number[]} data
|
|
293
|
-
* @returns {string}
|
|
294
|
-
*/
|
|
295
|
-
function sparkline(data) {
|
|
296
|
-
const chars = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'];
|
|
297
|
-
const max = Math.max(...data, 1);
|
|
298
|
-
|
|
299
|
-
return data.map(val => {
|
|
300
|
-
const index = Math.floor((val / max) * (chars.length - 1));
|
|
301
|
-
return chars[index];
|
|
302
|
-
}).join('');
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* CLI entry point
|
|
307
|
-
*/
|
|
308
|
-
function main() {
|
|
309
|
-
const args = process.argv.slice(2);
|
|
310
|
-
const jsonMode = args.includes('--json');
|
|
311
|
-
|
|
312
|
-
console.log('🔄 Collecting metrics...');
|
|
313
|
-
const metrics = collectMetrics();
|
|
314
|
-
|
|
315
|
-
// Save for caching
|
|
316
|
-
saveMetrics(metrics);
|
|
317
|
-
|
|
318
|
-
if (jsonMode) {
|
|
319
|
-
console.log(JSON.stringify(metrics, null, 2));
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
displayDashboard(metrics);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// Run if called directly
|
|
327
|
-
if (process.argv[1]?.includes('knowledge-metrics')) {
|
|
328
|
-
main();
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
export default {
|
|
332
|
-
collectMetrics,
|
|
333
|
-
saveMetrics,
|
|
334
|
-
loadMetrics
|
|
335
|
-
};
|