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.
Files changed (100) hide show
  1. package/README.md +1 -1
  2. package/bin/lib/commands/install.js +119 -242
  3. package/package.json +3 -4
  4. package/lib/agent-cli/bin/agent.js +0 -187
  5. package/lib/agent-cli/dashboard/dashboard_server.js +0 -312
  6. package/lib/agent-cli/lib/ab-testing.js +0 -364
  7. package/lib/agent-cli/lib/audit.js +0 -154
  8. package/lib/agent-cli/lib/audit.test.js +0 -100
  9. package/lib/agent-cli/lib/auto-learn.js +0 -319
  10. package/lib/agent-cli/lib/backup.js +0 -138
  11. package/lib/agent-cli/lib/backup.test.js +0 -78
  12. package/lib/agent-cli/lib/causality-engine.js +0 -331
  13. package/lib/agent-cli/lib/cognitive-lesson.js +0 -476
  14. package/lib/agent-cli/lib/completion.js +0 -149
  15. package/lib/agent-cli/lib/config.js +0 -35
  16. package/lib/agent-cli/lib/dashboard-data.js +0 -380
  17. package/lib/agent-cli/lib/eslint-fix.js +0 -238
  18. package/lib/agent-cli/lib/evolution-signal.js +0 -215
  19. package/lib/agent-cli/lib/export.js +0 -86
  20. package/lib/agent-cli/lib/export.test.js +0 -65
  21. package/lib/agent-cli/lib/fix.js +0 -337
  22. package/lib/agent-cli/lib/fix.test.js +0 -80
  23. package/lib/agent-cli/lib/gemini-export.js +0 -83
  24. package/lib/agent-cli/lib/generate-registry.js +0 -42
  25. package/lib/agent-cli/lib/hooks/install-hooks.js +0 -152
  26. package/lib/agent-cli/lib/hooks/lint-learn.js +0 -172
  27. package/lib/agent-cli/lib/icons.js +0 -93
  28. package/lib/agent-cli/lib/ignore.js +0 -116
  29. package/lib/agent-cli/lib/ignore.test.js +0 -58
  30. package/lib/agent-cli/lib/init.js +0 -124
  31. package/lib/agent-cli/lib/knowledge-index.js +0 -326
  32. package/lib/agent-cli/lib/knowledge-metrics.js +0 -335
  33. package/lib/agent-cli/lib/knowledge-retention.js +0 -398
  34. package/lib/agent-cli/lib/knowledge-validator.js +0 -312
  35. package/lib/agent-cli/lib/learn.js +0 -255
  36. package/lib/agent-cli/lib/learn.test.js +0 -70
  37. package/lib/agent-cli/lib/metrics-collector.js +0 -410
  38. package/lib/agent-cli/lib/proposals.js +0 -199
  39. package/lib/agent-cli/lib/proposals.test.js +0 -56
  40. package/lib/agent-cli/lib/recall.js +0 -835
  41. package/lib/agent-cli/lib/recall.test.js +0 -107
  42. package/lib/agent-cli/lib/reinforcement.js +0 -299
  43. package/lib/agent-cli/lib/selfevolution-bridge.js +0 -167
  44. package/lib/agent-cli/lib/settings.js +0 -203
  45. package/lib/agent-cli/lib/skill-generator.js +0 -379
  46. package/lib/agent-cli/lib/skill-learn.js +0 -296
  47. package/lib/agent-cli/lib/stats.js +0 -132
  48. package/lib/agent-cli/lib/stats.test.js +0 -94
  49. package/lib/agent-cli/lib/types.js +0 -33
  50. package/lib/agent-cli/lib/ui/audit-ui.js +0 -146
  51. package/lib/agent-cli/lib/ui/backup-ui.js +0 -107
  52. package/lib/agent-cli/lib/ui/clack-helpers.js +0 -317
  53. package/lib/agent-cli/lib/ui/common.js +0 -83
  54. package/lib/agent-cli/lib/ui/completion-ui.js +0 -126
  55. package/lib/agent-cli/lib/ui/custom-select.js +0 -69
  56. package/lib/agent-cli/lib/ui/dashboard-ui.js +0 -222
  57. package/lib/agent-cli/lib/ui/evolution-signals-ui.js +0 -107
  58. package/lib/agent-cli/lib/ui/export-ui.js +0 -94
  59. package/lib/agent-cli/lib/ui/fix-all-ui.js +0 -191
  60. package/lib/agent-cli/lib/ui/help-ui.js +0 -49
  61. package/lib/agent-cli/lib/ui/index.js +0 -199
  62. package/lib/agent-cli/lib/ui/init-ui.js +0 -56
  63. package/lib/agent-cli/lib/ui/knowledge-ui.js +0 -55
  64. package/lib/agent-cli/lib/ui/learn-ui.js +0 -706
  65. package/lib/agent-cli/lib/ui/lessons-ui.js +0 -148
  66. package/lib/agent-cli/lib/ui/pretty.js +0 -145
  67. package/lib/agent-cli/lib/ui/proposals-ui.js +0 -99
  68. package/lib/agent-cli/lib/ui/recall-ui.js +0 -342
  69. package/lib/agent-cli/lib/ui/routing-demo.js +0 -79
  70. package/lib/agent-cli/lib/ui/routing-ui.js +0 -325
  71. package/lib/agent-cli/lib/ui/settings-ui.js +0 -381
  72. package/lib/agent-cli/lib/ui/stats-ui.js +0 -123
  73. package/lib/agent-cli/lib/ui/watch-ui.js +0 -236
  74. package/lib/agent-cli/lib/watcher.js +0 -181
  75. package/lib/agent-cli/lib/watcher.test.js +0 -85
  76. package/lib/agent-cli/src/MIGRATION.md +0 -418
  77. package/lib/agent-cli/src/README.md +0 -367
  78. package/lib/agent-cli/src/core/evolution/evolution-signal.js +0 -42
  79. package/lib/agent-cli/src/core/evolution/index.js +0 -17
  80. package/lib/agent-cli/src/core/evolution/review-gate.js +0 -40
  81. package/lib/agent-cli/src/core/evolution/signal-detector.js +0 -137
  82. package/lib/agent-cli/src/core/evolution/signal-queue.js +0 -79
  83. package/lib/agent-cli/src/core/evolution/threshold-checker.js +0 -79
  84. package/lib/agent-cli/src/core/index.js +0 -15
  85. package/lib/agent-cli/src/core/learning/cognitive-enhancer.js +0 -282
  86. package/lib/agent-cli/src/core/learning/index.js +0 -12
  87. package/lib/agent-cli/src/core/learning/lesson-synthesizer.js +0 -83
  88. package/lib/agent-cli/src/core/scanning/index.js +0 -14
  89. package/lib/agent-cli/src/data/index.js +0 -13
  90. package/lib/agent-cli/src/data/repositories/index.js +0 -8
  91. package/lib/agent-cli/src/data/repositories/lesson-repository.js +0 -130
  92. package/lib/agent-cli/src/data/repositories/signal-repository.js +0 -119
  93. package/lib/agent-cli/src/data/storage/index.js +0 -8
  94. package/lib/agent-cli/src/data/storage/json-storage.js +0 -64
  95. package/lib/agent-cli/src/data/storage/yaml-storage.js +0 -66
  96. package/lib/agent-cli/src/infrastructure/index.js +0 -13
  97. package/lib/agent-cli/src/presentation/formatters/skill-formatter.js +0 -232
  98. package/lib/agent-cli/src/services/export-service.js +0 -162
  99. package/lib/agent-cli/src/services/index.js +0 -13
  100. package/lib/agent-cli/src/services/learning-service.js +0 -99
@@ -1,331 +0,0 @@
1
- /**
2
- * Causality Engine v7.0 - Pattern Analysis
3
- *
4
- * Analyzes cause-effect patterns from lessons and errors.
5
- * Provides root cause analysis and pattern detection.
6
- *
7
- * @version 7.0.0
8
- * @author PikaKit
9
- */
10
-
11
- import fs from 'fs';
12
- import path from 'path';
13
- import { fileURLToPath } from 'url';
14
-
15
- const __filename = fileURLToPath(import.meta.url);
16
- const __dirname = path.dirname(__filename);
17
-
18
- // Find project root
19
- function findProjectRoot() {
20
- let dir = process.cwd();
21
- while (dir !== path.dirname(dir)) {
22
- if (fs.existsSync(path.join(dir, '.agent'))) return dir;
23
- if (fs.existsSync(path.join(dir, 'package.json'))) return dir;
24
- dir = path.dirname(dir);
25
- }
26
- return process.cwd();
27
- }
28
-
29
- const projectRoot = findProjectRoot();
30
- const KNOWLEDGE_DIR = path.join(projectRoot, '.agent', 'knowledge');
31
- const PATTERNS_FILE = path.join(KNOWLEDGE_DIR, 'causal-patterns.json');
32
-
33
- // ============================================================================
34
- // PATTERN DATA STRUCTURES
35
- // ============================================================================
36
-
37
- /**
38
- * Pattern structure:
39
- * {
40
- * id: string,
41
- * cause: string, // What triggered the error
42
- * effect: string, // What was the result
43
- * resolution: string, // How it was fixed
44
- * confidence: number, // 0-1 confidence score
45
- * occurrences: number, // How many times seen
46
- * lastSeen: string, // ISO timestamp
47
- * category: string, // Category of pattern
48
- * tags: string[] // Related tags
49
- * }
50
- */
51
-
52
- // ============================================================================
53
- // DATA LOADERS
54
- // ============================================================================
55
-
56
- /**
57
- * Load lessons from knowledge base
58
- */
59
- function loadLessons() {
60
- const paths = [
61
- path.join(KNOWLEDGE_DIR, 'lessons-learned.json'),
62
- path.join(KNOWLEDGE_DIR, 'lessons-learned.yaml')
63
- ];
64
-
65
- for (const filePath of paths) {
66
- if (fs.existsSync(filePath)) {
67
- try {
68
- const content = fs.readFileSync(filePath, 'utf8');
69
- if (filePath.endsWith('.json')) {
70
- const data = JSON.parse(content);
71
- return data.lessons || [];
72
- }
73
- } catch (e) {
74
- // Continue to next path
75
- }
76
- }
77
- }
78
- return [];
79
- }
80
-
81
- /**
82
- * Load causal patterns from file
83
- */
84
- export function loadCausalPatterns() {
85
- if (fs.existsSync(PATTERNS_FILE)) {
86
- try {
87
- const data = JSON.parse(fs.readFileSync(PATTERNS_FILE, 'utf8'));
88
- return data.patterns || [];
89
- } catch (e) {
90
- return [];
91
- }
92
- }
93
-
94
- // Generate patterns from lessons if no patterns file
95
- return generatePatternsFromLessons();
96
- }
97
-
98
- /**
99
- * Save causal patterns
100
- */
101
- function saveCausalPatterns(patterns) {
102
- const dir = path.dirname(PATTERNS_FILE);
103
- if (!fs.existsSync(dir)) {
104
- fs.mkdirSync(dir, { recursive: true });
105
- }
106
-
107
- fs.writeFileSync(PATTERNS_FILE, JSON.stringify({
108
- patterns,
109
- lastUpdated: new Date().toISOString(),
110
- version: '7.0.0'
111
- }, null, 2));
112
- }
113
-
114
- /**
115
- * Generate patterns from existing lessons
116
- */
117
- function generatePatternsFromLessons() {
118
- const lessons = loadLessons();
119
- const patterns = [];
120
-
121
- for (const lesson of lessons) {
122
- const pattern = {
123
- id: lesson.id || `pattern-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,
124
- cause: lesson.trigger || lesson.pattern || lesson.cause || 'Unknown cause',
125
- effect: lesson.effect || lesson.message || 'Error occurred',
126
- resolution: lesson.resolution || lesson.fix || lesson.solution || 'Apply learned fix',
127
- confidence: parseFloat(lesson.confidence) || 0.7,
128
- occurrences: parseInt(lesson.occurrences) || 1,
129
- lastSeen: lesson.lastSeen || lesson.created || new Date().toISOString(),
130
- category: lesson.category || categorizePattern(lesson),
131
- tags: lesson.tags || extractTags(lesson)
132
- };
133
-
134
- patterns.push(pattern);
135
- }
136
-
137
- // Save generated patterns
138
- if (patterns.length > 0) {
139
- saveCausalPatterns(patterns);
140
- }
141
-
142
- return patterns;
143
- }
144
-
145
- /**
146
- * Categorize a pattern based on its content
147
- */
148
- function categorizePattern(lesson) {
149
- const content = JSON.stringify(lesson).toLowerCase();
150
-
151
- if (content.includes('import') || content.includes('module')) return 'import-error';
152
- if (content.includes('type') || content.includes('typescript')) return 'type-error';
153
- if (content.includes('syntax')) return 'syntax-error';
154
- if (content.includes('null') || content.includes('undefined')) return 'null-reference';
155
- if (content.includes('async') || content.includes('await') || content.includes('promise')) return 'async-error';
156
- if (content.includes('api') || content.includes('fetch') || content.includes('request')) return 'api-error';
157
- if (content.includes('file') || content.includes('path')) return 'file-error';
158
- if (content.includes('config') || content.includes('env')) return 'config-error';
159
-
160
- return 'general';
161
- }
162
-
163
- /**
164
- * Extract tags from lesson content
165
- */
166
- function extractTags(lesson) {
167
- const tags = [];
168
- const content = JSON.stringify(lesson).toLowerCase();
169
-
170
- const tagPatterns = [
171
- 'javascript', 'typescript', 'react', 'node', 'npm',
172
- 'import', 'export', 'async', 'await', 'promise',
173
- 'error', 'warning', 'critical', 'fix', 'workaround'
174
- ];
175
-
176
- for (const tag of tagPatterns) {
177
- if (content.includes(tag)) {
178
- tags.push(tag);
179
- }
180
- }
181
-
182
- return tags.slice(0, 5); // Limit to 5 tags
183
- }
184
-
185
- // ============================================================================
186
- // PATTERN ANALYSIS
187
- // ============================================================================
188
-
189
- /**
190
- * Get pattern count
191
- */
192
- export function getPatternCount() {
193
- const patterns = loadCausalPatterns();
194
- return patterns.length;
195
- }
196
-
197
- /**
198
- * Analyze an error and find matching patterns
199
- */
200
- export function analyzeError(errorMessage, context = {}) {
201
- const patterns = loadCausalPatterns();
202
- const matches = [];
203
-
204
- const errorLower = errorMessage.toLowerCase();
205
-
206
- for (const pattern of patterns) {
207
- let score = 0;
208
-
209
- // Check cause match
210
- if (pattern.cause && errorLower.includes(pattern.cause.toLowerCase())) {
211
- score += 0.4;
212
- }
213
-
214
- // Check category match
215
- if (pattern.category && errorLower.includes(pattern.category.replace('-', ' '))) {
216
- score += 0.2;
217
- }
218
-
219
- // Check tags match
220
- for (const tag of pattern.tags || []) {
221
- if (errorLower.includes(tag)) {
222
- score += 0.1;
223
- }
224
- }
225
-
226
- // Boost by confidence and occurrences
227
- score *= pattern.confidence || 0.5;
228
- score *= Math.min(pattern.occurrences || 1, 5) / 5;
229
-
230
- if (score > 0.1) {
231
- matches.push({
232
- pattern,
233
- score,
234
- suggestedResolution: pattern.resolution
235
- });
236
- }
237
- }
238
-
239
- // Sort by score descending
240
- matches.sort((a, b) => b.score - a.score);
241
-
242
- return {
243
- matches: matches.slice(0, 5),
244
- analyzed: true,
245
- timestamp: new Date().toISOString()
246
- };
247
- }
248
-
249
- /**
250
- * Add a new causal pattern
251
- */
252
- export function addPattern(cause, effect, resolution, metadata = {}) {
253
- const patterns = loadCausalPatterns();
254
-
255
- // Check for existing similar pattern
256
- const existing = patterns.find(p =>
257
- p.cause.toLowerCase() === cause.toLowerCase()
258
- );
259
-
260
- if (existing) {
261
- // Update existing pattern
262
- existing.occurrences = (existing.occurrences || 1) + 1;
263
- existing.lastSeen = new Date().toISOString();
264
- existing.confidence = Math.min((existing.confidence || 0.7) + 0.05, 1);
265
- saveCausalPatterns(patterns);
266
- return existing;
267
- }
268
-
269
- // Create new pattern
270
- const newPattern = {
271
- id: `pattern-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,
272
- cause,
273
- effect,
274
- resolution,
275
- confidence: metadata.confidence || 0.7,
276
- occurrences: 1,
277
- lastSeen: new Date().toISOString(),
278
- category: metadata.category || 'general',
279
- tags: metadata.tags || []
280
- };
281
-
282
- patterns.push(newPattern);
283
- saveCausalPatterns(patterns);
284
-
285
- return newPattern;
286
- }
287
-
288
- /**
289
- * Get patterns by category
290
- */
291
- export function getPatternsByCategory(category) {
292
- const patterns = loadCausalPatterns();
293
- return patterns.filter(p => p.category === category);
294
- }
295
-
296
- /**
297
- * Get pattern statistics
298
- */
299
- export function getPatternStats() {
300
- const patterns = loadCausalPatterns();
301
-
302
- const categories = {};
303
- let totalOccurrences = 0;
304
- let avgConfidence = 0;
305
-
306
- for (const pattern of patterns) {
307
- categories[pattern.category] = (categories[pattern.category] || 0) + 1;
308
- totalOccurrences += pattern.occurrences || 1;
309
- avgConfidence += pattern.confidence || 0.5;
310
- }
311
-
312
- return {
313
- totalPatterns: patterns.length,
314
- byCategory: categories,
315
- totalOccurrences,
316
- avgConfidence: patterns.length > 0 ? avgConfidence / patterns.length : 0
317
- };
318
- }
319
-
320
- // ============================================================================
321
- // EXPORTS
322
- // ============================================================================
323
-
324
- export default {
325
- loadCausalPatterns,
326
- getPatternCount,
327
- analyzeError,
328
- addPattern,
329
- getPatternsByCategory,
330
- getPatternStats
331
- };