add-skill-kit 3.2.3 → 3.2.4
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/lib/agent-cli/lib/audit.js +154 -0
- package/lib/agent-cli/lib/audit.test.js +100 -0
- package/lib/agent-cli/lib/auto-learn.js +319 -0
- package/lib/agent-cli/lib/auto_preview.py +148 -0
- package/lib/agent-cli/lib/backup.js +138 -0
- package/lib/agent-cli/lib/backup.test.js +78 -0
- package/lib/agent-cli/lib/checklist.py +222 -0
- package/lib/agent-cli/lib/cognitive-lesson.js +476 -0
- package/lib/agent-cli/lib/completion.js +149 -0
- package/lib/agent-cli/lib/config.js +35 -0
- package/lib/agent-cli/lib/eslint-fix.js +238 -0
- package/lib/agent-cli/lib/evolution-signal.js +215 -0
- package/lib/agent-cli/lib/export.js +86 -0
- package/lib/agent-cli/lib/export.test.js +65 -0
- package/lib/agent-cli/lib/fix.js +337 -0
- package/lib/agent-cli/lib/fix.test.js +80 -0
- package/lib/agent-cli/lib/gemini-export.js +83 -0
- package/lib/agent-cli/lib/generate-registry.js +42 -0
- package/lib/agent-cli/lib/hooks/install-hooks.js +152 -0
- package/lib/agent-cli/lib/hooks/lint-learn.js +172 -0
- package/lib/agent-cli/lib/ignore.js +116 -0
- package/lib/agent-cli/lib/ignore.test.js +58 -0
- package/lib/agent-cli/lib/init.js +124 -0
- package/lib/agent-cli/lib/learn.js +255 -0
- package/lib/agent-cli/lib/learn.test.js +70 -0
- package/lib/agent-cli/lib/migrate-to-v4.js +322 -0
- package/lib/agent-cli/lib/proposals.js +199 -0
- package/lib/agent-cli/lib/proposals.test.js +56 -0
- package/lib/agent-cli/lib/recall.js +820 -0
- package/lib/agent-cli/lib/recall.test.js +107 -0
- package/lib/agent-cli/lib/selfevolution-bridge.js +167 -0
- package/lib/agent-cli/lib/session_manager.py +120 -0
- package/lib/agent-cli/lib/settings.js +203 -0
- package/lib/agent-cli/lib/skill-learn.js +296 -0
- package/lib/agent-cli/lib/stats.js +132 -0
- package/lib/agent-cli/lib/stats.test.js +94 -0
- package/lib/agent-cli/lib/types.js +33 -0
- package/lib/agent-cli/lib/ui/audit-ui.js +146 -0
- package/lib/agent-cli/lib/ui/backup-ui.js +107 -0
- package/lib/agent-cli/lib/ui/clack-helpers.js +317 -0
- package/lib/agent-cli/lib/ui/common.js +83 -0
- package/lib/agent-cli/lib/ui/completion-ui.js +126 -0
- package/lib/agent-cli/lib/ui/custom-select.js +69 -0
- package/lib/agent-cli/lib/ui/dashboard-ui.js +123 -0
- package/lib/agent-cli/lib/ui/evolution-signals-ui.js +107 -0
- package/lib/agent-cli/lib/ui/export-ui.js +94 -0
- package/lib/agent-cli/lib/ui/fix-all-ui.js +191 -0
- package/lib/agent-cli/lib/ui/help-ui.js +49 -0
- package/lib/agent-cli/lib/ui/index.js +169 -0
- package/lib/agent-cli/lib/ui/init-ui.js +56 -0
- package/lib/agent-cli/lib/ui/knowledge-ui.js +55 -0
- package/lib/agent-cli/lib/ui/learn-ui.js +706 -0
- package/lib/agent-cli/lib/ui/lessons-ui.js +148 -0
- package/lib/agent-cli/lib/ui/pretty.js +145 -0
- package/lib/agent-cli/lib/ui/proposals-ui.js +99 -0
- package/lib/agent-cli/lib/ui/recall-ui.js +342 -0
- package/lib/agent-cli/lib/ui/routing-demo.js +79 -0
- package/lib/agent-cli/lib/ui/routing-ui.js +325 -0
- package/lib/agent-cli/lib/ui/settings-ui.js +381 -0
- package/lib/agent-cli/lib/ui/stats-ui.js +123 -0
- package/lib/agent-cli/lib/ui/watch-ui.js +236 -0
- package/lib/agent-cli/lib/verify_all.py +327 -0
- package/lib/agent-cli/lib/watcher.js +181 -0
- package/lib/agent-cli/lib/watcher.test.js +85 -0
- package/lib/agent-cli/package.json +51 -0
- package/lib/agentskillskit-cli/README.md +21 -0
- package/lib/agentskillskit-cli/ag-smart.js +158 -0
- package/lib/agentskillskit-cli/package.json +51 -0
- package/package.json +10 -6
- /package/{node_modules/agentskillskit-cli → lib/agent-cli}/README.md +0 -0
- /package/{node_modules/agentskillskit-cli → lib/agent-cli}/bin/ag-smart.js +0 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* ESLint Fix Integration
|
|
4
|
+
*
|
|
5
|
+
* Wrapper around ESLint --fix to combine with pattern-based fix.
|
|
6
|
+
* Auto-detects ESLint config and runs fixes.
|
|
7
|
+
*
|
|
8
|
+
* Usage: ag-smart fix --eslint <path>
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { execSync, spawnSync } from "child_process";
|
|
12
|
+
import fs from "fs";
|
|
13
|
+
import path from "path";
|
|
14
|
+
import { VERSION } from "./config.js";
|
|
15
|
+
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// ESLINT DETECTION
|
|
18
|
+
// ============================================================================
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Find ESLint config file in project
|
|
22
|
+
* @param {string} dir
|
|
23
|
+
* @returns {string|null}
|
|
24
|
+
*/
|
|
25
|
+
function findEslintConfig(dir) {
|
|
26
|
+
const configFiles = [
|
|
27
|
+
".eslintrc.js",
|
|
28
|
+
".eslintrc.cjs",
|
|
29
|
+
".eslintrc.json",
|
|
30
|
+
".eslintrc.yaml",
|
|
31
|
+
".eslintrc.yml",
|
|
32
|
+
".eslintrc",
|
|
33
|
+
"eslint.config.js",
|
|
34
|
+
"eslint.config.mjs"
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
let current = dir;
|
|
38
|
+
while (current !== path.dirname(current)) {
|
|
39
|
+
for (const config of configFiles) {
|
|
40
|
+
const configPath = path.join(current, config);
|
|
41
|
+
if (fs.existsSync(configPath)) {
|
|
42
|
+
return configPath;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Check package.json for eslintConfig
|
|
46
|
+
const pkgPath = path.join(current, "package.json");
|
|
47
|
+
if (fs.existsSync(pkgPath)) {
|
|
48
|
+
try {
|
|
49
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
50
|
+
if (pkg.eslintConfig) {
|
|
51
|
+
return pkgPath; // ESLint config in package.json
|
|
52
|
+
}
|
|
53
|
+
} catch (e) { }
|
|
54
|
+
}
|
|
55
|
+
current = path.dirname(current);
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Check if ESLint is available
|
|
62
|
+
* @returns {boolean}
|
|
63
|
+
*/
|
|
64
|
+
function isEslintAvailable() {
|
|
65
|
+
try {
|
|
66
|
+
execSync("npx eslint --version", { stdio: "ignore" });
|
|
67
|
+
return true;
|
|
68
|
+
} catch (e) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ============================================================================
|
|
74
|
+
// ESLINT FIX
|
|
75
|
+
// ============================================================================
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Run ESLint --fix on a path
|
|
79
|
+
* @param {string} targetPath
|
|
80
|
+
* @param {object} options
|
|
81
|
+
* @returns {{ success: boolean, fixed: number, errors: number }}
|
|
82
|
+
*/
|
|
83
|
+
export function runEslintFix(targetPath, options = {}) {
|
|
84
|
+
const result = {
|
|
85
|
+
success: false,
|
|
86
|
+
fixed: 0,
|
|
87
|
+
errors: 0,
|
|
88
|
+
output: ""
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
if (!isEslintAvailable()) {
|
|
92
|
+
console.log("⚠️ ESLint not found. Install with: npm install eslint -D");
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const configPath = findEslintConfig(process.cwd());
|
|
97
|
+
if (!configPath && !options.noConfig) {
|
|
98
|
+
console.log("⚠️ No ESLint config found. Run: npx eslint --init");
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
console.log(`\n🔧 Running ESLint --fix...`);
|
|
103
|
+
if (configPath) {
|
|
104
|
+
console.log(` Config: ${path.relative(process.cwd(), configPath)}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
// Run ESLint with --fix
|
|
109
|
+
const args = [
|
|
110
|
+
"eslint",
|
|
111
|
+
targetPath,
|
|
112
|
+
"--fix",
|
|
113
|
+
"--format", "json"
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
const proc = spawnSync("npx", args, {
|
|
117
|
+
encoding: "utf8",
|
|
118
|
+
shell: true,
|
|
119
|
+
maxBuffer: 10 * 1024 * 1024
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Parse output
|
|
123
|
+
if (proc.stdout) {
|
|
124
|
+
try {
|
|
125
|
+
const results = JSON.parse(proc.stdout);
|
|
126
|
+
let totalFixed = 0;
|
|
127
|
+
let totalErrors = 0;
|
|
128
|
+
|
|
129
|
+
results.forEach(file => {
|
|
130
|
+
if (file.output) {
|
|
131
|
+
// File was fixed (output contains fixed content)
|
|
132
|
+
totalFixed++;
|
|
133
|
+
}
|
|
134
|
+
totalErrors += file.errorCount || 0;
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
result.fixed = totalFixed;
|
|
138
|
+
result.errors = totalErrors;
|
|
139
|
+
result.success = true;
|
|
140
|
+
result.output = proc.stdout;
|
|
141
|
+
|
|
142
|
+
console.log(` ✅ Fixed: ${totalFixed} file(s)`);
|
|
143
|
+
if (totalErrors > 0) {
|
|
144
|
+
console.log(` ⚠️ Remaining errors: ${totalErrors}`);
|
|
145
|
+
}
|
|
146
|
+
} catch (e) {
|
|
147
|
+
// JSON parse failed, but fix might still have worked
|
|
148
|
+
result.success = proc.status === 0;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (proc.status === 0) {
|
|
153
|
+
result.success = true;
|
|
154
|
+
console.log(" ✅ ESLint fix completed");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.error(` ❌ ESLint error: ${error.message}`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ============================================================================
|
|
165
|
+
// COMBINED FIX
|
|
166
|
+
// ============================================================================
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Run combined fix (ESLint + pattern-based)
|
|
170
|
+
* @param {string} targetPath
|
|
171
|
+
* @param {object} options
|
|
172
|
+
*/
|
|
173
|
+
export async function runCombinedFix(targetPath, options = {}) {
|
|
174
|
+
console.log(`\n🔧 Combined Fix v${VERSION}`);
|
|
175
|
+
console.log(`📂 Target: ${targetPath}`);
|
|
176
|
+
console.log("─".repeat(50));
|
|
177
|
+
|
|
178
|
+
// Step 1: ESLint fix
|
|
179
|
+
if (options.eslint !== false) {
|
|
180
|
+
runEslintFix(targetPath, options);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Step 2: Pattern-based fix (import dynamically)
|
|
184
|
+
console.log("\n🧠 Running pattern-based fix...");
|
|
185
|
+
try {
|
|
186
|
+
const { fixDirectory } = await import("./fix.js");
|
|
187
|
+
const { loadKnowledge } = await import("./recall.js");
|
|
188
|
+
|
|
189
|
+
const db = loadKnowledge();
|
|
190
|
+
const results = fixDirectory(targetPath, db, options.mode || "safe");
|
|
191
|
+
|
|
192
|
+
if (results.length > 0) {
|
|
193
|
+
let total = 0;
|
|
194
|
+
results.forEach(r => total += r.fixes);
|
|
195
|
+
console.log(` ✅ Pattern fixes: ${total}`);
|
|
196
|
+
} else {
|
|
197
|
+
console.log(" ✅ No pattern violations to fix");
|
|
198
|
+
}
|
|
199
|
+
} catch (e) {
|
|
200
|
+
console.log(` ⚠️ Pattern fix skipped: ${e.message}`);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
console.log("\n" + "─".repeat(50));
|
|
204
|
+
console.log("🎉 Combined fix completed!");
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// ============================================================================
|
|
208
|
+
// CLI
|
|
209
|
+
// ============================================================================
|
|
210
|
+
|
|
211
|
+
const args = process.argv.slice(2);
|
|
212
|
+
|
|
213
|
+
if (args.includes("--help") || args.length === 0) {
|
|
214
|
+
console.log(`
|
|
215
|
+
🔧 ESLint Fix Integration v${VERSION}
|
|
216
|
+
|
|
217
|
+
Usage:
|
|
218
|
+
node eslint-fix.js <path> [options]
|
|
219
|
+
|
|
220
|
+
Options:
|
|
221
|
+
--no-eslint Skip ESLint fix
|
|
222
|
+
--no-pattern Skip pattern-based fix
|
|
223
|
+
--mode <mode> Pattern fix mode (safe|aggressive)
|
|
224
|
+
--help Show this help
|
|
225
|
+
|
|
226
|
+
This combines ESLint --fix with pattern-based fixes.
|
|
227
|
+
`);
|
|
228
|
+
process.exit(0);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const target = args[0];
|
|
232
|
+
const options = {
|
|
233
|
+
eslint: !args.includes("--no-eslint"),
|
|
234
|
+
pattern: !args.includes("--no-pattern"),
|
|
235
|
+
mode: args.includes("--mode") ? args[args.indexOf("--mode") + 1] : "safe"
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
runCombinedFix(target, options);
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evolution Signal Layer - Backward Compatibility Adapter
|
|
3
|
+
*
|
|
4
|
+
* This file maintains the old API while delegating to the new architecture.
|
|
5
|
+
* Allows gradual migration without breaking existing code.
|
|
6
|
+
*
|
|
7
|
+
* OLD LOCATION: lib/evolution-signal.js
|
|
8
|
+
* NEW LOCATION: src/core/evolution/* + src/data/repositories/*
|
|
9
|
+
*
|
|
10
|
+
* @deprecated Use new architecture: import from 'src/core/evolution'
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Import new architecture components
|
|
14
|
+
import { EvolutionSignal } from '../src/core/evolution/evolution-signal.js';
|
|
15
|
+
import { ThresholdChecker } from '../src/core/evolution/threshold-checker.js';
|
|
16
|
+
import { ReviewGate } from '../src/core/evolution/review-gate.js';
|
|
17
|
+
import { SignalRepository } from '../src/data/repositories/signal-repository.js';
|
|
18
|
+
import { JsonStorage } from '../src/data/storage/json-storage.js';
|
|
19
|
+
import { SignalDetector as SignalService } from '../src/core/evolution/signal-detector.js';
|
|
20
|
+
import { KNOWLEDGE_DIR } from './config.js';
|
|
21
|
+
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// BACKWARD COMPATIBLE EXPORTS
|
|
24
|
+
// ============================================================================
|
|
25
|
+
|
|
26
|
+
// Re-export EvolutionSignal class
|
|
27
|
+
export { EvolutionSignal };
|
|
28
|
+
|
|
29
|
+
// Lazy-initialized singleton instances
|
|
30
|
+
let _storage = null;
|
|
31
|
+
let _repository = null;
|
|
32
|
+
let _detector = null;
|
|
33
|
+
|
|
34
|
+
function getDetector() {
|
|
35
|
+
if (!_detector) {
|
|
36
|
+
_storage = new JsonStorage(KNOWLEDGE_DIR);
|
|
37
|
+
_repository = new SignalRepository(_storage);
|
|
38
|
+
_detector = new SignalService(_repository);
|
|
39
|
+
}
|
|
40
|
+
return _detector;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// ============================================================================
|
|
44
|
+
// THRESHOLD CHECKER (Backward Compatible)
|
|
45
|
+
// ============================================================================
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated Use ThresholdChecker.check() from src/core/evolution
|
|
49
|
+
*/
|
|
50
|
+
export function checkEvolutionThreshold(lesson, threshold = 10) {
|
|
51
|
+
return ThresholdChecker.check(lesson, threshold);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated Use ThresholdChecker.calculateStability() from src/core/evolution
|
|
56
|
+
*/
|
|
57
|
+
export function calculatePatternStability(violationHistory = []) {
|
|
58
|
+
return ThresholdChecker.calculateStability(violationHistory);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ============================================================================
|
|
62
|
+
// SIGNAL QUEUE (Backward Compatible)
|
|
63
|
+
// ============================================================================
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* SignalQueue - Backward compatible class
|
|
67
|
+
* @deprecated Use SignalRepository + SignalDetector from new architecture
|
|
68
|
+
*/
|
|
69
|
+
class SignalQueueCompat {
|
|
70
|
+
get signals() {
|
|
71
|
+
// Return cached signals (sync access)
|
|
72
|
+
if (!this._cachedSignals) {
|
|
73
|
+
// Synchronous fallback - load on first access
|
|
74
|
+
this._cachedSignals = [];
|
|
75
|
+
this.load().then(signals => {
|
|
76
|
+
this._cachedSignals = signals;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return this._cachedSignals;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async load() {
|
|
83
|
+
const detector = getDetector();
|
|
84
|
+
const all = await detector.signalRepository.findAll();
|
|
85
|
+
this._cachedSignals = all;
|
|
86
|
+
return all;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async save() {
|
|
90
|
+
// Auto-save through repository (no-op for compatibility)
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async add(signal) {
|
|
95
|
+
const detector = getDetector();
|
|
96
|
+
const result = await detector.queue(
|
|
97
|
+
signal.lessonId,
|
|
98
|
+
{ ready: true, reason: signal.reason, confidence: signal.confidence },
|
|
99
|
+
signal.metadata
|
|
100
|
+
);
|
|
101
|
+
await this.load(); // Refresh cache
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
getPending() {
|
|
106
|
+
return this.signals.filter(s => s.status === 'pending');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
getByLesson(lessonId) {
|
|
110
|
+
return this.signals.filter(s => s.lessonId === lessonId);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async approve(signalId) {
|
|
114
|
+
const detector = getDetector();
|
|
115
|
+
const result = await detector.approve(signalId);
|
|
116
|
+
await this.load(); // Refresh cache
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async reject(signalId) {
|
|
121
|
+
const detector = getDetector();
|
|
122
|
+
const result = await detector.reject(signalId);
|
|
123
|
+
await this.load(); // Refresh cache
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async execute(signalId) {
|
|
128
|
+
const detector = getDetector();
|
|
129
|
+
const result = await detector.execute(signalId);
|
|
130
|
+
await this.load(); // Refresh cache
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async cleanup() {
|
|
135
|
+
const detector = getDetector();
|
|
136
|
+
await detector.signalRepository.cleanup();
|
|
137
|
+
await this.load(); // Refresh cache
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Singleton instance for backward compatibility
|
|
142
|
+
const signalQueueInstance = new SignalQueueCompat();
|
|
143
|
+
|
|
144
|
+
// Initialize on module load
|
|
145
|
+
signalQueueInstance.load().catch(err => {
|
|
146
|
+
console.error('Failed to initialize signal queue:', err);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
export { signalQueueInstance as signalQueue };
|
|
150
|
+
|
|
151
|
+
// ============================================================================
|
|
152
|
+
// REVIEW GATE (Backward Compatible)
|
|
153
|
+
// ============================================================================
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @deprecated Use ReviewGate.evaluate() from src/core/evolution
|
|
157
|
+
*/
|
|
158
|
+
export function reviewGate(signal, settings = {}) {
|
|
159
|
+
return ReviewGate.evaluate(signal, settings);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ============================================================================
|
|
163
|
+
// HELPER FUNCTIONS (Backward Compatible)
|
|
164
|
+
// ============================================================================
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @deprecated Use SignalDetector.queue() from new architecture
|
|
168
|
+
*/
|
|
169
|
+
export async function queueEvolutionSignal(lessonId, checkResult, metadata = {}) {
|
|
170
|
+
if (!checkResult.ready) return null;
|
|
171
|
+
|
|
172
|
+
const signal = new EvolutionSignal(
|
|
173
|
+
lessonId,
|
|
174
|
+
checkResult.reason,
|
|
175
|
+
checkResult.confidence,
|
|
176
|
+
metadata
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
return signalQueueInstance.add(signal);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @deprecated Use SignalDetector.getStats() from new architecture
|
|
184
|
+
*/
|
|
185
|
+
export async function getEvolutionStats() {
|
|
186
|
+
const detector = getDetector();
|
|
187
|
+
return detector.getStats();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// ============================================================================
|
|
191
|
+
// MIGRATION GUIDE
|
|
192
|
+
// ============================================================================
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* HOW TO MIGRATE TO NEW ARCHITECTURE:
|
|
196
|
+
*
|
|
197
|
+
* OLD CODE:
|
|
198
|
+
* ```
|
|
199
|
+
* import { signalQueue, checkEvolutionThreshold } from './evolution-signal.js';
|
|
200
|
+
*
|
|
201
|
+
* const check = checkEvolutionThreshold(lesson, 10);
|
|
202
|
+
* await signalQueue.add(signal);
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* NEW CODE:
|
|
206
|
+
* ```
|
|
207
|
+
* import { ThresholdChecker } from '../src/core/evolution/threshold-checker.js';
|
|
208
|
+
* import { SignalRepository } from '../src/data/repositories/signal-repository.js';
|
|
209
|
+
* import { SignalDetector } from '../src/core/evolution/signal-detector.js';
|
|
210
|
+
*
|
|
211
|
+
* const check = ThresholdChecker.check(lesson, 10);
|
|
212
|
+
* const detector = new SignalDetector(repository);
|
|
213
|
+
* await detector.queue(lessonId, check, metadata);
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Export and Import for Agent Skill Kit
|
|
3
|
+
* Share settings between projects
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import yaml from "js-yaml";
|
|
9
|
+
import { LESSONS_PATH } from "./config.js";
|
|
10
|
+
import { SETTINGS_PATH, loadSettings } from "./settings.js";
|
|
11
|
+
import { loadKnowledge, saveKnowledge } from "./recall.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Export lessons and settings to JSON file
|
|
15
|
+
* @param {string} outputPath - Output file path
|
|
16
|
+
* @returns {boolean}
|
|
17
|
+
*/
|
|
18
|
+
export function exportData(outputPath) {
|
|
19
|
+
try {
|
|
20
|
+
const data = {
|
|
21
|
+
version: 1,
|
|
22
|
+
exportedAt: new Date().toISOString(),
|
|
23
|
+
lessons: loadKnowledge().lessons || [],
|
|
24
|
+
settings: loadSettings()
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
fs.writeFileSync(outputPath, JSON.stringify(data, null, 2), "utf8");
|
|
28
|
+
return true;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
console.error("Failed to export:", e.message);
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Import data from JSON file
|
|
37
|
+
* @param {string} inputPath - Input file path
|
|
38
|
+
* @param {"merge" | "replace"} mode - Import mode
|
|
39
|
+
* @returns {{ success: boolean, lessonsCount: number, hasSettings: boolean }}
|
|
40
|
+
*/
|
|
41
|
+
export function importData(inputPath, mode = "merge") {
|
|
42
|
+
try {
|
|
43
|
+
if (!fs.existsSync(inputPath)) {
|
|
44
|
+
return { success: false, lessonsCount: 0, hasSettings: false };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const content = fs.readFileSync(inputPath, "utf8");
|
|
48
|
+
const data = JSON.parse(content);
|
|
49
|
+
|
|
50
|
+
// Import lessons
|
|
51
|
+
const currentDb = loadKnowledge();
|
|
52
|
+
|
|
53
|
+
if (mode === "replace") {
|
|
54
|
+
currentDb.lessons = data.lessons || [];
|
|
55
|
+
} else {
|
|
56
|
+
// Merge - add new lessons, skip duplicates by pattern
|
|
57
|
+
const existingPatterns = new Set(currentDb.lessons.map(l => l.pattern));
|
|
58
|
+
for (const lesson of (data.lessons || [])) {
|
|
59
|
+
if (!existingPatterns.has(lesson.pattern)) {
|
|
60
|
+
currentDb.lessons.push(lesson);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
saveKnowledge(currentDb);
|
|
66
|
+
|
|
67
|
+
// Import settings if present
|
|
68
|
+
let hasSettings = false;
|
|
69
|
+
if (data.settings) {
|
|
70
|
+
const settingsPath = SETTINGS_PATH;
|
|
71
|
+
fs.writeFileSync(settingsPath, yaml.dump(data.settings), "utf8");
|
|
72
|
+
hasSettings = true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
success: true,
|
|
77
|
+
lessonsCount: data.lessons?.length || 0,
|
|
78
|
+
hasSettings
|
|
79
|
+
};
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.error("Failed to import:", e.message);
|
|
82
|
+
return { success: false, lessonsCount: 0, hasSettings: false };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export default { exportData, importData };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Tests for export module
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import os from "os";
|
|
9
|
+
|
|
10
|
+
describe("export", () => {
|
|
11
|
+
const testDir = path.join(os.tmpdir(), "test-export-" + Date.now());
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
fs.mkdirSync(testDir, { recursive: true });
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
if (fs.existsSync(testDir)) {
|
|
19
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("export format", () => {
|
|
24
|
+
it("creates valid JSON structure", () => {
|
|
25
|
+
const data = {
|
|
26
|
+
version: 1,
|
|
27
|
+
exportedAt: new Date().toISOString(),
|
|
28
|
+
lessons: [{ id: "TEST", pattern: "x" }]
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const outputPath = path.join(testDir, "export.json");
|
|
32
|
+
fs.writeFileSync(outputPath, JSON.stringify(data, null, 2));
|
|
33
|
+
|
|
34
|
+
const loaded = JSON.parse(fs.readFileSync(outputPath, "utf8"));
|
|
35
|
+
expect(loaded.version).toBe(1);
|
|
36
|
+
expect(loaded.lessons).toHaveLength(1);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("supports lesson array format", () => {
|
|
40
|
+
const lessons = [
|
|
41
|
+
{ id: "L1", pattern: "a", message: "msg" },
|
|
42
|
+
{ id: "L2", pattern: "b", message: "msg2" }
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
const data = { version: 1, lessons };
|
|
46
|
+
const json = JSON.stringify(data);
|
|
47
|
+
const parsed = JSON.parse(json);
|
|
48
|
+
|
|
49
|
+
expect(parsed.lessons).toHaveLength(2);
|
|
50
|
+
expect(parsed.lessons[0].id).toBe("L1");
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("import validation", () => {
|
|
55
|
+
it("validates version field", () => {
|
|
56
|
+
const valid = { version: 1, lessons: [] };
|
|
57
|
+
expect(valid.version).toBe(1);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("validates lessons array", () => {
|
|
61
|
+
const valid = { version: 1, lessons: [{ id: "X", pattern: "y" }] };
|
|
62
|
+
expect(Array.isArray(valid.lessons)).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|