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,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Tests for recall.js functionality
|
|
3
|
-
*/
|
|
4
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
5
|
-
import fs from "fs";
|
|
6
|
-
import path from "path";
|
|
7
|
-
import os from "os";
|
|
8
|
-
|
|
9
|
-
const TEST_DIR = path.join(os.tmpdir(), "agent-skill-kit-recall-test");
|
|
10
|
-
const KNOWLEDGE_DIR = path.join(TEST_DIR, ".agent", "knowledge");
|
|
11
|
-
const LESSONS_PATH = path.join(KNOWLEDGE_DIR, "lessons-learned.yaml");
|
|
12
|
-
const TEST_FILE = path.join(TEST_DIR, "test-code.js");
|
|
13
|
-
|
|
14
|
-
describe("Recall - Pattern Matching", () => {
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
fs.mkdirSync(KNOWLEDGE_DIR, { recursive: true });
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
afterEach(() => {
|
|
20
|
-
fs.rmSync(TEST_DIR, { recursive: true, force: true });
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("detects pattern matches in code", () => {
|
|
24
|
-
const codeContent = `
|
|
25
|
-
console.log("debug");
|
|
26
|
-
const x = 1;
|
|
27
|
-
`;
|
|
28
|
-
const pattern = /console\.log/g;
|
|
29
|
-
const matches = codeContent.match(pattern);
|
|
30
|
-
|
|
31
|
-
expect(matches).not.toBeNull();
|
|
32
|
-
expect(matches.length).toBe(1);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("returns null when no pattern matches", () => {
|
|
36
|
-
const codeContent = `const x = 1;`;
|
|
37
|
-
const pattern = /console\.log/g;
|
|
38
|
-
const matches = codeContent.match(pattern);
|
|
39
|
-
|
|
40
|
-
expect(matches).toBeNull();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("counts multiple occurrences", () => {
|
|
44
|
-
const codeContent = `
|
|
45
|
-
console.log("one");
|
|
46
|
-
console.log("two");
|
|
47
|
-
console.log("three");
|
|
48
|
-
`;
|
|
49
|
-
const pattern = /console\.log/g;
|
|
50
|
-
const matches = codeContent.match(pattern);
|
|
51
|
-
|
|
52
|
-
expect(matches).not.toBeNull();
|
|
53
|
-
expect(matches.length).toBe(3);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("can scan files from filesystem", () => {
|
|
57
|
-
const testCode = `console.log("test");`;
|
|
58
|
-
fs.writeFileSync(TEST_FILE, testCode, "utf8");
|
|
59
|
-
|
|
60
|
-
const content = fs.readFileSync(TEST_FILE, "utf8");
|
|
61
|
-
expect(content).toContain("console.log");
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("finds line numbers for matches", () => {
|
|
65
|
-
const lines = [
|
|
66
|
-
"const a = 1;",
|
|
67
|
-
"console.log('found');",
|
|
68
|
-
"const b = 2;"
|
|
69
|
-
];
|
|
70
|
-
const pattern = /console\.log/;
|
|
71
|
-
|
|
72
|
-
const matchingLines = lines
|
|
73
|
-
.map((line, idx) => ({ line, num: idx + 1 }))
|
|
74
|
-
.filter(({ line }) => pattern.test(line));
|
|
75
|
-
|
|
76
|
-
expect(matchingLines.length).toBe(1);
|
|
77
|
-
expect(matchingLines[0].num).toBe(2);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe("Recall - Directory Scanning", () => {
|
|
82
|
-
beforeEach(() => {
|
|
83
|
-
fs.mkdirSync(KNOWLEDGE_DIR, { recursive: true });
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
afterEach(() => {
|
|
87
|
-
fs.rmSync(TEST_DIR, { recursive: true, force: true });
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("filters files by extension", () => {
|
|
91
|
-
const extensions = [".js", ".ts", ".tsx"];
|
|
92
|
-
const testFiles = ["app.js", "util.ts", "readme.md", "style.css"];
|
|
93
|
-
|
|
94
|
-
const filtered = testFiles.filter(f =>
|
|
95
|
-
extensions.some(ext => f.endsWith(ext))
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
expect(filtered).toEqual(["app.js", "util.ts"]);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("skips node_modules directory", () => {
|
|
102
|
-
const skipDirs = ["node_modules", ".git", "dist"];
|
|
103
|
-
const testDir = "node_modules";
|
|
104
|
-
|
|
105
|
-
expect(skipDirs.includes(testDir)).toBe(true);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reinforcement Loop v7.0 - Reward/Penalty Tracking
|
|
3
|
-
*
|
|
4
|
-
* Implements reinforcement learning loop for pattern confidence.
|
|
5
|
-
* Tracks rewards (correct fixes) and penalties (wrong fixes).
|
|
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 METRICS_DIR = path.join(projectRoot, '.agent', 'metrics');
|
|
31
|
-
const REINFORCEMENT_FILE = path.join(METRICS_DIR, 'reinforcement.json');
|
|
32
|
-
|
|
33
|
-
// ============================================================================
|
|
34
|
-
// DATA STRUCTURES
|
|
35
|
-
// ============================================================================
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Reinforcement data structure:
|
|
39
|
-
* {
|
|
40
|
-
* rewards: number,
|
|
41
|
-
* penalties: number,
|
|
42
|
-
* history: [{
|
|
43
|
-
* timestamp: string,
|
|
44
|
-
* patternId: string,
|
|
45
|
-
* action: 'reward' | 'penalty',
|
|
46
|
-
* amount: number,
|
|
47
|
-
* reason: string,
|
|
48
|
-
* confidenceBefore: number,
|
|
49
|
-
* confidenceAfter: number
|
|
50
|
-
* }],
|
|
51
|
-
* lastUpdated: string
|
|
52
|
-
* }
|
|
53
|
-
*/
|
|
54
|
-
|
|
55
|
-
// ============================================================================
|
|
56
|
-
// DATA LOADERS
|
|
57
|
-
// ============================================================================
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Ensure metrics directory exists
|
|
61
|
-
*/
|
|
62
|
-
function ensureMetricsDir() {
|
|
63
|
-
if (!fs.existsSync(METRICS_DIR)) {
|
|
64
|
-
fs.mkdirSync(METRICS_DIR, { recursive: true });
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Load reinforcement data
|
|
70
|
-
*/
|
|
71
|
-
function loadReinforcementData() {
|
|
72
|
-
if (fs.existsSync(REINFORCEMENT_FILE)) {
|
|
73
|
-
try {
|
|
74
|
-
return JSON.parse(fs.readFileSync(REINFORCEMENT_FILE, 'utf8'));
|
|
75
|
-
} catch (e) {
|
|
76
|
-
return getDefaultData();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return getDefaultData();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Save reinforcement data
|
|
84
|
-
*/
|
|
85
|
-
function saveReinforcementData(data) {
|
|
86
|
-
ensureMetricsDir();
|
|
87
|
-
data.lastUpdated = new Date().toISOString();
|
|
88
|
-
fs.writeFileSync(REINFORCEMENT_FILE, JSON.stringify(data, null, 2));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Get default data structure
|
|
93
|
-
*/
|
|
94
|
-
function getDefaultData() {
|
|
95
|
-
return {
|
|
96
|
-
rewards: 0,
|
|
97
|
-
penalties: 0,
|
|
98
|
-
history: [],
|
|
99
|
-
patterns: {}, // patternId -> { rewards, penalties, confidence }
|
|
100
|
-
lastUpdated: new Date().toISOString()
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// ============================================================================
|
|
105
|
-
// REINFORCEMENT OPERATIONS
|
|
106
|
-
// ============================================================================
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Apply reward to a pattern (correct fix)
|
|
110
|
-
*/
|
|
111
|
-
export function applyReward(patternId, amount = 1, reason = 'Correct fix applied') {
|
|
112
|
-
const data = loadReinforcementData();
|
|
113
|
-
|
|
114
|
-
// Update global rewards
|
|
115
|
-
data.rewards = (data.rewards || 0) + amount;
|
|
116
|
-
|
|
117
|
-
// Update pattern-specific data
|
|
118
|
-
if (!data.patterns[patternId]) {
|
|
119
|
-
data.patterns[patternId] = { rewards: 0, penalties: 0, confidence: 0.5 };
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const pattern = data.patterns[patternId];
|
|
123
|
-
const confidenceBefore = pattern.confidence;
|
|
124
|
-
|
|
125
|
-
pattern.rewards += amount;
|
|
126
|
-
|
|
127
|
-
// Increase confidence (max 1.0)
|
|
128
|
-
pattern.confidence = Math.min(pattern.confidence + 0.05 * amount, 1.0);
|
|
129
|
-
|
|
130
|
-
// Add to history
|
|
131
|
-
data.history.push({
|
|
132
|
-
timestamp: new Date().toISOString(),
|
|
133
|
-
patternId,
|
|
134
|
-
action: 'reward',
|
|
135
|
-
amount,
|
|
136
|
-
reason,
|
|
137
|
-
confidenceBefore,
|
|
138
|
-
confidenceAfter: pattern.confidence
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
// Keep history manageable (last 1000 entries)
|
|
142
|
-
if (data.history.length > 1000) {
|
|
143
|
-
data.history = data.history.slice(-1000);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
saveReinforcementData(data);
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
success: true,
|
|
150
|
-
newConfidence: pattern.confidence,
|
|
151
|
-
totalRewards: data.rewards
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Apply penalty to a pattern (wrong fix)
|
|
157
|
-
*/
|
|
158
|
-
export function applyPenalty(patternId, amount = 1, reason = 'Fix did not work') {
|
|
159
|
-
const data = loadReinforcementData();
|
|
160
|
-
|
|
161
|
-
// Update global penalties
|
|
162
|
-
data.penalties = (data.penalties || 0) + amount;
|
|
163
|
-
|
|
164
|
-
// Update pattern-specific data
|
|
165
|
-
if (!data.patterns[patternId]) {
|
|
166
|
-
data.patterns[patternId] = { rewards: 0, penalties: 0, confidence: 0.5 };
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const pattern = data.patterns[patternId];
|
|
170
|
-
const confidenceBefore = pattern.confidence;
|
|
171
|
-
|
|
172
|
-
pattern.penalties += amount;
|
|
173
|
-
|
|
174
|
-
// Decrease confidence (min 0.1)
|
|
175
|
-
pattern.confidence = Math.max(pattern.confidence - 0.1 * amount, 0.1);
|
|
176
|
-
|
|
177
|
-
// Add to history
|
|
178
|
-
data.history.push({
|
|
179
|
-
timestamp: new Date().toISOString(),
|
|
180
|
-
patternId,
|
|
181
|
-
action: 'penalty',
|
|
182
|
-
amount,
|
|
183
|
-
reason,
|
|
184
|
-
confidenceBefore,
|
|
185
|
-
confidenceAfter: pattern.confidence
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
// Keep history manageable
|
|
189
|
-
if (data.history.length > 1000) {
|
|
190
|
-
data.history = data.history.slice(-1000);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
saveReinforcementData(data);
|
|
194
|
-
|
|
195
|
-
return {
|
|
196
|
-
success: true,
|
|
197
|
-
newConfidence: pattern.confidence,
|
|
198
|
-
totalPenalties: data.penalties
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// ============================================================================
|
|
203
|
-
// STATS AND QUERIES
|
|
204
|
-
// ============================================================================
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Get reinforcement statistics
|
|
208
|
-
*/
|
|
209
|
-
export function getStats() {
|
|
210
|
-
const data = loadReinforcementData();
|
|
211
|
-
|
|
212
|
-
// Calculate average confidence
|
|
213
|
-
const patternIds = Object.keys(data.patterns || {});
|
|
214
|
-
let avgConfidence = 0;
|
|
215
|
-
|
|
216
|
-
if (patternIds.length > 0) {
|
|
217
|
-
const total = patternIds.reduce((sum, id) => sum + (data.patterns[id].confidence || 0.5), 0);
|
|
218
|
-
avgConfidence = total / patternIds.length;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return {
|
|
222
|
-
rewards: data.rewards || 0,
|
|
223
|
-
penalties: data.penalties || 0,
|
|
224
|
-
avgConfidence: Math.round(avgConfidence * 100),
|
|
225
|
-
totalPatterns: patternIds.length,
|
|
226
|
-
recentActions: (data.history || []).slice(-10)
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Get reinforcement stats (alias)
|
|
232
|
-
*/
|
|
233
|
-
export function getReinforcementStats() {
|
|
234
|
-
return getStats();
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Get pattern confidence
|
|
239
|
-
*/
|
|
240
|
-
export function getPatternConfidence(patternId) {
|
|
241
|
-
const data = loadReinforcementData();
|
|
242
|
-
return data.patterns?.[patternId]?.confidence ?? 0.5;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Get all pattern confidences
|
|
247
|
-
*/
|
|
248
|
-
export function getAllPatternConfidences() {
|
|
249
|
-
const data = loadReinforcementData();
|
|
250
|
-
return data.patterns || {};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Get history for a specific pattern
|
|
255
|
-
*/
|
|
256
|
-
export function getPatternHistory(patternId, limit = 20) {
|
|
257
|
-
const data = loadReinforcementData();
|
|
258
|
-
return (data.history || [])
|
|
259
|
-
.filter(h => h.patternId === patternId)
|
|
260
|
-
.slice(-limit);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Get recent history
|
|
265
|
-
*/
|
|
266
|
-
export function getRecentHistory(limit = 50) {
|
|
267
|
-
const data = loadReinforcementData();
|
|
268
|
-
return (data.history || []).slice(-limit);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Reset pattern confidence (for testing)
|
|
273
|
-
*/
|
|
274
|
-
export function resetPattern(patternId) {
|
|
275
|
-
const data = loadReinforcementData();
|
|
276
|
-
|
|
277
|
-
if (data.patterns?.[patternId]) {
|
|
278
|
-
data.patterns[patternId] = { rewards: 0, penalties: 0, confidence: 0.5 };
|
|
279
|
-
saveReinforcementData(data);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return { success: true };
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// ============================================================================
|
|
286
|
-
// EXPORTS
|
|
287
|
-
// ============================================================================
|
|
288
|
-
|
|
289
|
-
export default {
|
|
290
|
-
applyReward,
|
|
291
|
-
applyPenalty,
|
|
292
|
-
getStats,
|
|
293
|
-
getReinforcementStats,
|
|
294
|
-
getPatternConfidence,
|
|
295
|
-
getAllPatternConfidences,
|
|
296
|
-
getPatternHistory,
|
|
297
|
-
getRecentHistory,
|
|
298
|
-
resetPattern
|
|
299
|
-
};
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SelfEvolution Bridge Module
|
|
3
|
-
* Connects Settings API keys with SelfEvolution's AI-powered optimization
|
|
4
|
-
*
|
|
5
|
-
* @module selfevolution-bridge
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { getApiKey } from './settings.js';
|
|
9
|
-
import fs from 'fs';
|
|
10
|
-
import path from 'path';
|
|
11
|
-
import { fileURLToPath } from 'url';
|
|
12
|
-
import { spawn } from 'child_process';
|
|
13
|
-
|
|
14
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
-
const __dirname = path.dirname(__filename);
|
|
16
|
-
const PROJECT_ROOT = path.resolve(__dirname, '../../..');
|
|
17
|
-
const SELFEVOLUTION_DIR = path.join(PROJECT_ROOT, '.agent/skills/self-evolution');
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Export API keys from Settings to SelfEvolution .env file
|
|
21
|
-
* This allows Python scripts to auto-detect and use the keys
|
|
22
|
-
*
|
|
23
|
-
* @returns {{success: boolean, exported?: {gemini: boolean, claude: boolean}, path?: string, reason?: string}}
|
|
24
|
-
*/
|
|
25
|
-
export function exportApiKeysToSelfEvolution() {
|
|
26
|
-
try {
|
|
27
|
-
const geminiKey = getApiKey('gemini');
|
|
28
|
-
const claudeKey = getApiKey('claude');
|
|
29
|
-
|
|
30
|
-
// Check if any keys are configured
|
|
31
|
-
if (!geminiKey && !claudeKey) {
|
|
32
|
-
return {
|
|
33
|
-
success: false,
|
|
34
|
-
reason: 'No API keys configured in Settings'
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Ensure SelfEvolution directory exists
|
|
39
|
-
if (!fs.existsSync(SELFEVOLUTION_DIR)) {
|
|
40
|
-
return {
|
|
41
|
-
success: false,
|
|
42
|
-
reason: 'SelfEvolution skill directory not found'
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Build .env content
|
|
47
|
-
const envContent = [];
|
|
48
|
-
|
|
49
|
-
if (geminiKey) {
|
|
50
|
-
envContent.push(`GEMINI_API_KEY=${geminiKey}`);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (claudeKey) {
|
|
54
|
-
envContent.push(`CLAUDE_API_KEY=${claudeKey}`);
|
|
55
|
-
envContent.push(`ANTHROPIC_API_KEY=${claudeKey}`); // Alternative name
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
envContent.push('');
|
|
59
|
-
envContent.push('# Auto-generated from Settings');
|
|
60
|
-
envContent.push(`# Last updated: ${new Date().toISOString()}`);
|
|
61
|
-
envContent.push('# DO NOT EDIT - Managed by CLI Settings');
|
|
62
|
-
|
|
63
|
-
// Write .env file
|
|
64
|
-
const envPath = path.join(SELFEVOLUTION_DIR, '.env');
|
|
65
|
-
fs.writeFileSync(envPath, envContent.join('\n'), 'utf8');
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
success: true,
|
|
69
|
-
exported: {
|
|
70
|
-
gemini: !!geminiKey,
|
|
71
|
-
claude: !!claudeKey
|
|
72
|
-
},
|
|
73
|
-
path: envPath
|
|
74
|
-
};
|
|
75
|
-
} catch (error) {
|
|
76
|
-
return {
|
|
77
|
-
success: false,
|
|
78
|
-
reason: `Export failed: ${error.message}`
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Verify that SelfEvolution can access the exported API keys
|
|
85
|
-
* Runs Python api_key_resolver.py --test
|
|
86
|
-
*
|
|
87
|
-
* @returns {Promise<{success: boolean, output?: string, error?: string, keyDetected?: boolean}>}
|
|
88
|
-
*/
|
|
89
|
-
export async function verifySelfEvolutionAccess() {
|
|
90
|
-
return new Promise((resolve) => {
|
|
91
|
-
const scriptPath = path.join(SELFEVOLUTION_DIR, 'scripts/api_key_resolver.py');
|
|
92
|
-
|
|
93
|
-
// Check if script exists
|
|
94
|
-
if (!fs.existsSync(scriptPath)) {
|
|
95
|
-
resolve({
|
|
96
|
-
success: false,
|
|
97
|
-
error: 'api_key_resolver.py not found'
|
|
98
|
-
});
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Run Python script with --test flag
|
|
103
|
-
const python = spawn('python', [scriptPath, '--test'], {
|
|
104
|
-
cwd: PROJECT_ROOT,
|
|
105
|
-
env: { ...process.env }
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
let stdout = '';
|
|
109
|
-
let stderr = '';
|
|
110
|
-
|
|
111
|
-
python.stdout.on('data', (data) => {
|
|
112
|
-
stdout += data.toString();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
python.stderr.on('data', (data) => {
|
|
116
|
-
stderr += data.toString();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
python.on('close', (code) => {
|
|
120
|
-
const success = code === 0;
|
|
121
|
-
const keyDetected = stdout.includes('✓') || stdout.includes('detected');
|
|
122
|
-
|
|
123
|
-
resolve({
|
|
124
|
-
success,
|
|
125
|
-
output: stdout.trim(),
|
|
126
|
-
error: stderr.trim(),
|
|
127
|
-
keyDetected
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
python.on('error', (error) => {
|
|
132
|
-
resolve({
|
|
133
|
-
success: false,
|
|
134
|
-
error: `Failed to run Python: ${error.message}`
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Remove SelfEvolution .env file (cleanup)
|
|
142
|
-
* Called when user removes all API keys from Settings
|
|
143
|
-
*
|
|
144
|
-
* @returns {{success: boolean, reason?: string}}
|
|
145
|
-
*/
|
|
146
|
-
export function cleanupSelfEvolutionEnv() {
|
|
147
|
-
try {
|
|
148
|
-
const envPath = path.join(SELFEVOLUTION_DIR, '.env');
|
|
149
|
-
|
|
150
|
-
if (fs.existsSync(envPath)) {
|
|
151
|
-
fs.unlinkSync(envPath);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return { success: true };
|
|
155
|
-
} catch (error) {
|
|
156
|
-
return {
|
|
157
|
-
success: false,
|
|
158
|
-
reason: `Cleanup failed: ${error.message}`
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export default {
|
|
164
|
-
exportApiKeysToSelfEvolution,
|
|
165
|
-
verifySelfEvolutionAccess,
|
|
166
|
-
cleanupSelfEvolutionEnv
|
|
167
|
-
};
|