agentic-qe 3.7.21 → 3.8.0
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/.claude/helpers/brain-checkpoint.cjs +4 -1
- package/.claude/helpers/statusline-v3.cjs +3 -1
- package/.claude/skills/skills-manifest.json +1 -1
- package/CHANGELOG.md +45 -0
- package/README.md +2 -14
- package/assets/helpers/statusline-v3.cjs +3 -1
- package/dist/cli/brain-commands.js +6 -10
- package/dist/cli/bundle.js +7441 -4327
- package/dist/cli/commands/audit.d.ts +43 -0
- package/dist/cli/commands/audit.js +125 -0
- package/dist/cli/commands/hooks.js +29 -6
- package/dist/cli/commands/init.js +1 -73
- package/dist/cli/commands/learning.js +270 -13
- package/dist/cli/commands/ruvector-commands.d.ts +15 -0
- package/dist/cli/commands/ruvector-commands.js +271 -0
- package/dist/cli/handlers/init-handler.d.ts +0 -1
- package/dist/cli/handlers/init-handler.js +0 -6
- package/dist/cli/index.js +4 -2
- package/dist/context/sources/defect-source.js +2 -2
- package/dist/context/sources/memory-source.js +2 -2
- package/dist/context/sources/requirements-source.js +2 -2
- package/dist/coordination/behavior-tree/decorators.d.ts +108 -0
- package/dist/coordination/behavior-tree/decorators.js +251 -0
- package/dist/coordination/behavior-tree/index.d.ts +12 -0
- package/dist/coordination/behavior-tree/index.js +15 -0
- package/dist/coordination/behavior-tree/nodes.d.ts +165 -0
- package/dist/coordination/behavior-tree/nodes.js +338 -0
- package/dist/coordination/behavior-tree/qe-trees.d.ts +105 -0
- package/dist/coordination/behavior-tree/qe-trees.js +181 -0
- package/dist/coordination/coherence-action-gate.d.ts +284 -0
- package/dist/coordination/coherence-action-gate.js +512 -0
- package/dist/coordination/index.d.ts +4 -0
- package/dist/coordination/index.js +8 -0
- package/dist/coordination/reasoning-qec.d.ts +315 -0
- package/dist/coordination/reasoning-qec.js +585 -0
- package/dist/coordination/task-executor.d.ts +16 -0
- package/dist/coordination/task-executor.js +99 -0
- package/dist/coordination/workflow-orchestrator.d.ts +29 -0
- package/dist/coordination/workflow-orchestrator.js +42 -0
- package/dist/domains/visual-accessibility/cnn-visual-regression.d.ts +135 -0
- package/dist/domains/visual-accessibility/cnn-visual-regression.js +327 -0
- package/dist/domains/visual-accessibility/index.d.ts +1 -0
- package/dist/domains/visual-accessibility/index.js +4 -0
- package/dist/governance/coherence-validator.d.ts +112 -0
- package/dist/governance/coherence-validator.js +180 -0
- package/dist/governance/index.d.ts +1 -0
- package/dist/governance/index.js +2 -0
- package/dist/governance/witness-chain.d.ts +311 -0
- package/dist/governance/witness-chain.js +509 -0
- package/dist/init/index.d.ts +0 -2
- package/dist/init/index.js +0 -1
- package/dist/init/init-wizard-steps.d.ts +10 -0
- package/dist/init/init-wizard-steps.js +87 -1
- package/dist/init/init-wizard.d.ts +1 -9
- package/dist/init/init-wizard.js +3 -69
- package/dist/init/orchestrator.js +0 -1
- package/dist/init/phases/01-detection.js +0 -27
- package/dist/init/phases/07-hooks.js +6 -4
- package/dist/init/phases/phase-interface.d.ts +0 -1
- package/dist/init/settings-merge.js +1 -1
- package/dist/integrations/browser/qe-dashboard/clustering.d.ts +48 -0
- package/dist/integrations/browser/qe-dashboard/clustering.js +183 -0
- package/dist/integrations/browser/qe-dashboard/index.d.ts +12 -0
- package/dist/integrations/browser/qe-dashboard/index.js +15 -0
- package/dist/integrations/browser/qe-dashboard/pattern-explorer.d.ts +165 -0
- package/dist/integrations/browser/qe-dashboard/pattern-explorer.js +260 -0
- package/dist/integrations/browser/qe-dashboard/wasm-vector-store.d.ts +144 -0
- package/dist/integrations/browser/qe-dashboard/wasm-vector-store.js +277 -0
- package/dist/integrations/ruvector/cognitive-container-codec.d.ts +51 -0
- package/dist/integrations/ruvector/cognitive-container-codec.js +180 -0
- package/dist/integrations/ruvector/cognitive-container.d.ts +125 -0
- package/dist/integrations/ruvector/cognitive-container.js +306 -0
- package/dist/integrations/ruvector/coherence-gate.d.ts +309 -0
- package/dist/integrations/ruvector/coherence-gate.js +631 -0
- package/dist/integrations/ruvector/compressed-hnsw-integration.d.ts +176 -0
- package/dist/integrations/ruvector/compressed-hnsw-integration.js +301 -0
- package/dist/integrations/ruvector/dither-adapter.d.ts +122 -0
- package/dist/integrations/ruvector/dither-adapter.js +295 -0
- package/dist/integrations/ruvector/domain-transfer.d.ts +129 -0
- package/dist/integrations/ruvector/domain-transfer.js +220 -0
- package/dist/integrations/ruvector/feature-flags.d.ts +214 -2
- package/dist/integrations/ruvector/feature-flags.js +167 -2
- package/dist/integrations/ruvector/filter-adapter.d.ts +71 -0
- package/dist/integrations/ruvector/filter-adapter.js +285 -0
- package/dist/integrations/ruvector/gnn-wrapper.d.ts +20 -0
- package/dist/integrations/ruvector/gnn-wrapper.js +40 -0
- package/dist/integrations/ruvector/hnsw-health-monitor.d.ts +237 -0
- package/dist/integrations/ruvector/hnsw-health-monitor.js +394 -0
- package/dist/integrations/ruvector/index.d.ts +8 -2
- package/dist/integrations/ruvector/index.js +18 -2
- package/dist/integrations/ruvector/interfaces.d.ts +40 -0
- package/dist/integrations/ruvector/sona-persistence.d.ts +54 -0
- package/dist/integrations/ruvector/sona-persistence.js +162 -0
- package/dist/integrations/ruvector/sona-three-loop.d.ts +392 -0
- package/dist/integrations/ruvector/sona-three-loop.js +814 -0
- package/dist/integrations/ruvector/sona-wrapper.d.ts +97 -0
- package/dist/integrations/ruvector/sona-wrapper.js +147 -3
- package/dist/integrations/ruvector/spectral-math.d.ts +101 -0
- package/dist/integrations/ruvector/spectral-math.js +254 -0
- package/dist/integrations/ruvector/temporal-compression.d.ts +163 -0
- package/dist/integrations/ruvector/temporal-compression.js +318 -0
- package/dist/integrations/ruvector/thompson-sampler.d.ts +61 -0
- package/dist/integrations/ruvector/thompson-sampler.js +118 -0
- package/dist/integrations/ruvector/transfer-coherence-stub.d.ts +80 -0
- package/dist/integrations/ruvector/transfer-coherence-stub.js +63 -0
- package/dist/integrations/ruvector/transfer-verification.d.ts +119 -0
- package/dist/integrations/ruvector/transfer-verification.js +115 -0
- package/dist/kernel/hnsw-adapter.d.ts +52 -1
- package/dist/kernel/hnsw-adapter.js +139 -4
- package/dist/kernel/hnsw-index-provider.d.ts +5 -0
- package/dist/kernel/native-hnsw-backend.d.ts +110 -0
- package/dist/kernel/native-hnsw-backend.js +408 -0
- package/dist/kernel/unified-memory.js +5 -6
- package/dist/learning/aqe-learning-engine.d.ts +2 -0
- package/dist/learning/aqe-learning-engine.js +65 -0
- package/dist/learning/experience-capture-middleware.js +20 -0
- package/dist/learning/experience-capture.d.ts +10 -0
- package/dist/learning/experience-capture.js +34 -0
- package/dist/learning/index.d.ts +2 -2
- package/dist/learning/index.js +4 -4
- package/dist/learning/metrics-tracker.d.ts +11 -0
- package/dist/learning/metrics-tracker.js +29 -13
- package/dist/learning/pattern-lifecycle.d.ts +30 -1
- package/dist/learning/pattern-lifecycle.js +92 -20
- package/dist/learning/pattern-store.d.ts +8 -0
- package/dist/learning/pattern-store.js +8 -2
- package/dist/learning/qe-unified-memory.js +1 -28
- package/dist/learning/regret-tracker.d.ts +201 -0
- package/dist/learning/regret-tracker.js +361 -0
- package/dist/mcp/bundle.js +5915 -474
- package/dist/routing/index.d.ts +4 -2
- package/dist/routing/index.js +3 -1
- package/dist/routing/neural-tiny-dancer-router.d.ts +268 -0
- package/dist/routing/neural-tiny-dancer-router.js +514 -0
- package/dist/routing/queen-integration.js +5 -5
- package/dist/routing/routing-config.d.ts +6 -0
- package/dist/routing/routing-config.js +1 -0
- package/dist/routing/simple-neural-router.d.ts +76 -0
- package/dist/routing/simple-neural-router.js +202 -0
- package/dist/routing/tiny-dancer-router.d.ts +20 -1
- package/dist/routing/tiny-dancer-router.js +21 -2
- package/dist/test-scheduling/dag-attention-scheduler.d.ts +81 -0
- package/dist/test-scheduling/dag-attention-scheduler.js +358 -0
- package/dist/test-scheduling/dag-attention-types.d.ts +81 -0
- package/dist/test-scheduling/dag-attention-types.js +10 -0
- package/dist/test-scheduling/index.d.ts +1 -0
- package/dist/test-scheduling/index.js +4 -0
- package/dist/test-scheduling/pipeline.d.ts +8 -0
- package/dist/test-scheduling/pipeline.js +28 -0
- package/package.json +6 -2
- package/dist/cli/commands/migrate.d.ts +0 -9
- package/dist/cli/commands/migrate.js +0 -566
- package/dist/init/init-wizard-migration.d.ts +0 -52
- package/dist/init/init-wizard-migration.js +0 -345
- package/dist/init/migration/config-migrator.d.ts +0 -31
- package/dist/init/migration/config-migrator.js +0 -149
- package/dist/init/migration/data-migrator.d.ts +0 -72
- package/dist/init/migration/data-migrator.js +0 -232
- package/dist/init/migration/detector.d.ts +0 -44
- package/dist/init/migration/detector.js +0 -105
- package/dist/init/migration/index.d.ts +0 -8
- package/dist/init/migration/index.js +0 -8
- package/dist/learning/v2-to-v3-migration.d.ts +0 -86
- package/dist/learning/v2-to-v3-migration.js +0 -529
|
@@ -1,529 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* V2 to V3 Data Migration Module
|
|
3
|
-
* ADR-038: V3 QE Memory Unification
|
|
4
|
-
*
|
|
5
|
-
* Migrates data from V2 AQE fleet (.agentic-qe/memory.db) to V3 systems:
|
|
6
|
-
* - patterns → RealQEReasoningBank (.agentic-qe/memory.db)
|
|
7
|
-
* - captured_experiences → QEUnifiedMemory learning domain
|
|
8
|
-
* - learning_experiences → RL training data
|
|
9
|
-
* - concept_nodes/edges → Code intelligence knowledge graph
|
|
10
|
-
*
|
|
11
|
-
* @module migration
|
|
12
|
-
*/
|
|
13
|
-
import { openDatabase } from '../shared/safe-db.js';
|
|
14
|
-
import { toErrorMessage } from '../shared/error-utils.js';
|
|
15
|
-
import { safeJsonParse } from '../shared/safe-json.js';
|
|
16
|
-
import { LoggerFactory } from '../logging/index.js';
|
|
17
|
-
const logger = LoggerFactory.create('v2-to-v3-migration');
|
|
18
|
-
// ============================================================================
|
|
19
|
-
// V2 to V3 Migration Class
|
|
20
|
-
// ============================================================================
|
|
21
|
-
export class V2ToV3Migrator {
|
|
22
|
-
config;
|
|
23
|
-
v2Db = null;
|
|
24
|
-
v3Db = null;
|
|
25
|
-
startTime = 0;
|
|
26
|
-
constructor(config) {
|
|
27
|
-
this.config = config;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Execute the full migration
|
|
31
|
-
*/
|
|
32
|
-
async migrate() {
|
|
33
|
-
this.startTime = Date.now();
|
|
34
|
-
const errors = [];
|
|
35
|
-
const tablesMigrated = [];
|
|
36
|
-
const counts = {};
|
|
37
|
-
try {
|
|
38
|
-
// Step 1: Connect to databases
|
|
39
|
-
await this.reportProgress('connecting', 0, 1, 'Connecting to databases...');
|
|
40
|
-
await this.connect();
|
|
41
|
-
// Step 2: Read V2 data
|
|
42
|
-
await this.reportProgress('reading', 0, 1, 'Reading V2 data...');
|
|
43
|
-
const v2Data = await this.readV2Data();
|
|
44
|
-
// Step 3: Migrate to V3
|
|
45
|
-
await this.reportProgress('migrating', 0, 1, 'Migrating patterns...');
|
|
46
|
-
// Migrate patterns → RealQEReasoningBank
|
|
47
|
-
const patternCount = await this.migratePatterns(v2Data.patterns);
|
|
48
|
-
if (patternCount > 0) {
|
|
49
|
-
tablesMigrated.push('patterns');
|
|
50
|
-
counts.patterns = patternCount;
|
|
51
|
-
}
|
|
52
|
-
await this.reportProgress('migrating', 1, 4, 'Migrating captured experiences...');
|
|
53
|
-
// Migrate captured experiences → learning domain
|
|
54
|
-
const experienceCount = await this.migrateCapturedExperiences(v2Data.capturedExperiences);
|
|
55
|
-
if (experienceCount > 0) {
|
|
56
|
-
tablesMigrated.push('captured_experiences');
|
|
57
|
-
counts.captured_experiences = experienceCount;
|
|
58
|
-
}
|
|
59
|
-
await this.reportProgress('migrating', 2, 4, 'Migrating learning experiences...');
|
|
60
|
-
// Migrate learning experiences → RL data
|
|
61
|
-
const learningCount = await this.migrateLearningExperiences(v2Data.learningExperiences);
|
|
62
|
-
if (learningCount > 0) {
|
|
63
|
-
tablesMigrated.push('learning_experiences');
|
|
64
|
-
counts.learning_experiences = learningCount;
|
|
65
|
-
}
|
|
66
|
-
await this.reportProgress('migrating', 3, 4, 'Migrating concept graph...');
|
|
67
|
-
// Migrate concept nodes/edges → code intelligence
|
|
68
|
-
const conceptCount = await this.migrateConceptGraph(v2Data.conceptNodes, v2Data.conceptEdges);
|
|
69
|
-
if (conceptCount > 0) {
|
|
70
|
-
tablesMigrated.push('concept_graph');
|
|
71
|
-
counts.concept_graph = conceptCount;
|
|
72
|
-
}
|
|
73
|
-
// Step 4: Validate migration
|
|
74
|
-
await this.reportProgress('validating', 0, 1, 'Validating migration...');
|
|
75
|
-
const validationErrors = await this.validateMigration();
|
|
76
|
-
errors.push(...validationErrors);
|
|
77
|
-
await this.reportProgress('complete', 1, 1, 'Migration complete!');
|
|
78
|
-
return {
|
|
79
|
-
success: errors.length === 0,
|
|
80
|
-
tablesMigrated,
|
|
81
|
-
counts,
|
|
82
|
-
errors,
|
|
83
|
-
duration: Date.now() - this.startTime,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
errors.push(toErrorMessage(error));
|
|
88
|
-
return {
|
|
89
|
-
success: false,
|
|
90
|
-
tablesMigrated,
|
|
91
|
-
counts,
|
|
92
|
-
errors,
|
|
93
|
-
duration: Date.now() - this.startTime,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
finally {
|
|
97
|
-
await this.disconnect();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
// -------------------------------------------------------------------------
|
|
101
|
-
// Private Methods
|
|
102
|
-
// -------------------------------------------------------------------------
|
|
103
|
-
/**
|
|
104
|
-
* Safely parse JSON, returning a wrapper object for non-JSON strings
|
|
105
|
-
* Handles V2 data where state/action columns may contain plain strings like "task-started"
|
|
106
|
-
*/
|
|
107
|
-
safeJsonParse(value, fieldName = 'value') {
|
|
108
|
-
if (value === null || value === undefined || value === '') {
|
|
109
|
-
return {};
|
|
110
|
-
}
|
|
111
|
-
// Trim whitespace
|
|
112
|
-
const trimmed = value.trim();
|
|
113
|
-
// Check if it looks like JSON (starts with { or [)
|
|
114
|
-
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
115
|
-
try {
|
|
116
|
-
return safeJsonParse(trimmed);
|
|
117
|
-
}
|
|
118
|
-
catch (e) {
|
|
119
|
-
// If parsing fails, wrap as string
|
|
120
|
-
logger.debug('JSON parse failed during migration', { field: fieldName, error: e instanceof Error ? e.message : String(e) });
|
|
121
|
-
return { [fieldName]: trimmed, _parseError: true };
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
// Not JSON - wrap the plain string value
|
|
125
|
-
return { [fieldName]: trimmed, _isPlainString: true };
|
|
126
|
-
}
|
|
127
|
-
async reportProgress(stage, current, total, message, table) {
|
|
128
|
-
if (this.config.onProgress) {
|
|
129
|
-
this.config.onProgress({ stage, table, current, total, message });
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
async connect() {
|
|
133
|
-
// Connect to V2 database (readonly)
|
|
134
|
-
this.v2Db = openDatabase(this.config.v2DbPath, { readonly: true });
|
|
135
|
-
// Skip WAL mode for readonly database
|
|
136
|
-
// Connect to V3 patterns database (readwrite, openDatabase sets WAL + busy_timeout)
|
|
137
|
-
this.v3Db = openDatabase(this.config.v3PatternsDbPath);
|
|
138
|
-
// Ensure V3 schema exists
|
|
139
|
-
this.createV3Schema();
|
|
140
|
-
}
|
|
141
|
-
async disconnect() {
|
|
142
|
-
if (this.v2Db) {
|
|
143
|
-
this.v2Db.close();
|
|
144
|
-
this.v2Db = null;
|
|
145
|
-
}
|
|
146
|
-
if (this.v3Db) {
|
|
147
|
-
this.v3Db.close();
|
|
148
|
-
this.v3Db = null;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
createV3Schema() {
|
|
152
|
-
if (!this.v3Db)
|
|
153
|
-
throw new Error('V3 database not connected');
|
|
154
|
-
// This schema should match SQLitePatternStore's schema
|
|
155
|
-
this.v3Db.exec(`
|
|
156
|
-
CREATE TABLE IF NOT EXISTS qe_patterns (
|
|
157
|
-
id TEXT PRIMARY KEY,
|
|
158
|
-
pattern_type TEXT NOT NULL,
|
|
159
|
-
qe_domain TEXT NOT NULL,
|
|
160
|
-
domain TEXT NOT NULL,
|
|
161
|
-
name TEXT NOT NULL,
|
|
162
|
-
description TEXT,
|
|
163
|
-
confidence REAL DEFAULT 0.5,
|
|
164
|
-
usage_count INTEGER DEFAULT 0,
|
|
165
|
-
success_rate REAL DEFAULT 0.0,
|
|
166
|
-
quality_score REAL DEFAULT 0.0,
|
|
167
|
-
tier TEXT DEFAULT 'short-term',
|
|
168
|
-
template_json TEXT,
|
|
169
|
-
context_json TEXT,
|
|
170
|
-
created_at TEXT DEFAULT (datetime('now')),
|
|
171
|
-
updated_at TEXT DEFAULT (datetime('now')),
|
|
172
|
-
last_used_at TEXT,
|
|
173
|
-
successful_uses INTEGER DEFAULT 0
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
CREATE TABLE IF NOT EXISTS qe_pattern_embeddings (
|
|
177
|
-
pattern_id TEXT PRIMARY KEY,
|
|
178
|
-
embedding BLOB NOT NULL,
|
|
179
|
-
dimension INTEGER NOT NULL,
|
|
180
|
-
model TEXT DEFAULT 'all-MiniLM-L6-v2',
|
|
181
|
-
created_at TEXT DEFAULT (datetime('now')),
|
|
182
|
-
FOREIGN KEY (pattern_id) REFERENCES qe_patterns(id) ON DELETE CASCADE
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
CREATE TABLE IF NOT EXISTS qe_pattern_usage (
|
|
186
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
187
|
-
pattern_id TEXT NOT NULL,
|
|
188
|
-
success INTEGER NOT NULL,
|
|
189
|
-
metrics_json TEXT,
|
|
190
|
-
feedback TEXT,
|
|
191
|
-
created_at TEXT DEFAULT (datetime('now'))
|
|
192
|
-
);
|
|
193
|
-
|
|
194
|
-
CREATE INDEX IF NOT EXISTS idx_patterns_domain ON qe_patterns(qe_domain);
|
|
195
|
-
CREATE INDEX IF NOT EXISTS idx_patterns_type ON qe_patterns(pattern_type);
|
|
196
|
-
CREATE INDEX IF NOT EXISTS idx_patterns_tier ON qe_patterns(tier);
|
|
197
|
-
`);
|
|
198
|
-
}
|
|
199
|
-
async readV2Data() {
|
|
200
|
-
if (!this.v2Db)
|
|
201
|
-
throw new Error('V2 database not connected');
|
|
202
|
-
// Helper to safely read from a table that might not exist
|
|
203
|
-
const safeReadTable = (tableName) => {
|
|
204
|
-
try {
|
|
205
|
-
// Check if table exists first
|
|
206
|
-
const tableExists = this.v2Db.prepare(`
|
|
207
|
-
SELECT name FROM sqlite_master
|
|
208
|
-
WHERE type='table' AND name=?
|
|
209
|
-
`).get(tableName);
|
|
210
|
-
if (!tableExists) {
|
|
211
|
-
console.log(` [V2Migration] Table '${tableName}' not found, skipping...`);
|
|
212
|
-
return [];
|
|
213
|
-
}
|
|
214
|
-
return this.v2Db.prepare(`SELECT * FROM ${tableName}`).all();
|
|
215
|
-
}
|
|
216
|
-
catch (error) {
|
|
217
|
-
console.warn(` [V2Migration] Could not read table '${tableName}': ${toErrorMessage(error)}`);
|
|
218
|
-
return [];
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
return {
|
|
222
|
-
patterns: safeReadTable('patterns'),
|
|
223
|
-
capturedExperiences: safeReadTable('captured_experiences'),
|
|
224
|
-
learningExperiences: safeReadTable('learning_experiences'),
|
|
225
|
-
conceptNodes: safeReadTable('concept_nodes'),
|
|
226
|
-
conceptEdges: safeReadTable('concept_edges'),
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Migrate V2 patterns to V3 qe_patterns table
|
|
231
|
-
*/
|
|
232
|
-
async migratePatterns(patterns) {
|
|
233
|
-
if (!this.v3Db)
|
|
234
|
-
throw new Error('V3 database not connected');
|
|
235
|
-
if (patterns.length === 0)
|
|
236
|
-
return 0;
|
|
237
|
-
const insert = this.v3Db.prepare(`
|
|
238
|
-
INSERT OR REPLACE INTO qe_patterns (
|
|
239
|
-
id, pattern_type, qe_domain, domain, name, description,
|
|
240
|
-
confidence, usage_count, success_rate, tier, created_at
|
|
241
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
242
|
-
`);
|
|
243
|
-
const insertEmbedding = this.v3Db.prepare(`
|
|
244
|
-
INSERT OR REPLACE INTO qe_pattern_embeddings (pattern_id, embedding, dimension, model)
|
|
245
|
-
VALUES (?, ?, ?, ?)
|
|
246
|
-
`);
|
|
247
|
-
let count = 0;
|
|
248
|
-
const transaction = this.v3Db.transaction(() => {
|
|
249
|
-
for (const pattern of patterns) {
|
|
250
|
-
try {
|
|
251
|
-
// Parse V2 pattern data - use safe parsing for non-JSON values
|
|
252
|
-
const patternData = this.safeJsonParse(pattern.pattern, 'pattern');
|
|
253
|
-
const metadata = this.safeJsonParse(pattern.metadata, 'metadata');
|
|
254
|
-
// Map V2 domain to V3 QEDomain
|
|
255
|
-
const qeDomain = this.mapV2DomainToV3(pattern.domain || String(metadata.domain || 'general'));
|
|
256
|
-
// Determine pattern type from metadata or pattern content
|
|
257
|
-
const patternType = this.inferPatternType(patternData, metadata);
|
|
258
|
-
// Calculate quality score from confidence and success rate
|
|
259
|
-
const qualityScore = (pattern.confidence * 0.6) + (pattern.success_rate * 0.4);
|
|
260
|
-
// Get pattern name safely
|
|
261
|
-
const patternName = String(patternData.name || metadata.name || pattern.pattern.substring(0, 50));
|
|
262
|
-
// Insert pattern
|
|
263
|
-
insert.run(pattern.id, patternType, qeDomain, pattern.domain || 'general', patternName, String(patternData.description || metadata.description || '') || null, pattern.confidence, pattern.usage_count, pattern.success_rate, this.calculateTier(pattern.usage_count, qualityScore), new Date(pattern.created_at * 1000).toISOString());
|
|
264
|
-
// TODO: Migrate embeddings if available (V2 doesn't store them in patterns table)
|
|
265
|
-
// Would need to generate embeddings or migrate from captured_experiences
|
|
266
|
-
count++;
|
|
267
|
-
}
|
|
268
|
-
catch (error) {
|
|
269
|
-
console.warn(`[V2Migration] Failed to migrate pattern ${pattern.id}:`, error);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
transaction();
|
|
274
|
-
return count;
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Migrate captured experiences to learning domain
|
|
278
|
-
* These are stored in memory_entries for now, could be moved to QEUnifiedMemory
|
|
279
|
-
*/
|
|
280
|
-
async migrateCapturedExperiences(experiences) {
|
|
281
|
-
if (!this.v3Db)
|
|
282
|
-
throw new Error('V3 database not connected');
|
|
283
|
-
if (experiences.length === 0)
|
|
284
|
-
return 0;
|
|
285
|
-
// Store captured experiences as learning patterns
|
|
286
|
-
const insert = this.v3Db.prepare(`
|
|
287
|
-
INSERT OR REPLACE INTO qe_patterns (
|
|
288
|
-
id, pattern_type, qe_domain, domain, name, description,
|
|
289
|
-
confidence, usage_count, success_rate, tier, context_json, created_at
|
|
290
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
291
|
-
`);
|
|
292
|
-
let count = 0;
|
|
293
|
-
for (const exp of experiences) {
|
|
294
|
-
try {
|
|
295
|
-
// Use safe parsing - V2 may store non-JSON values
|
|
296
|
-
const execution = this.safeJsonParse(exp.execution, 'execution');
|
|
297
|
-
const context = this.safeJsonParse(exp.context, 'context');
|
|
298
|
-
const outcome = this.safeJsonParse(exp.outcome, 'outcome');
|
|
299
|
-
const qeDomain = this.mapTaskTypeToDomain(exp.task_type);
|
|
300
|
-
// Safely access outcome.success with fallback
|
|
301
|
-
const isSuccess = typeof outcome.success === 'boolean' ? outcome.success : false;
|
|
302
|
-
insert.run(exp.id, // Use original ID
|
|
303
|
-
'test-template', // Captured experiences become templates
|
|
304
|
-
qeDomain, exp.task_type, `Experience: ${exp.task_type}`, `Agent: ${exp.agent_type}, Task: ${exp.task_type}`, isSuccess ? 0.8 : 0.3, // Confidence based on outcome
|
|
305
|
-
1, // One usage
|
|
306
|
-
isSuccess ? 1.0 : 0.0, // Success rate
|
|
307
|
-
'short-term', JSON.stringify({ context, execution, outcome }), new Date(exp.created_at * 1000).toISOString());
|
|
308
|
-
count++;
|
|
309
|
-
}
|
|
310
|
-
catch (error) {
|
|
311
|
-
console.warn(`[V2Migration] Failed to migrate experience ${exp.id}:`, error);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
return count;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Migrate learning experiences (RL data)
|
|
318
|
-
* Store as learning patterns for SONA integration
|
|
319
|
-
*/
|
|
320
|
-
async migrateLearningExperiences(experiences) {
|
|
321
|
-
if (!this.v3Db)
|
|
322
|
-
throw new Error('V3 database not connected');
|
|
323
|
-
if (experiences.length === 0)
|
|
324
|
-
return 0;
|
|
325
|
-
const insert = this.v3Db.prepare(`
|
|
326
|
-
INSERT OR REPLACE INTO qe_patterns (
|
|
327
|
-
id, pattern_type, qe_domain, domain, name, description,
|
|
328
|
-
confidence, usage_count, success_rate, tier, context_json, created_at
|
|
329
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
330
|
-
`);
|
|
331
|
-
let count = 0;
|
|
332
|
-
for (const exp of experiences) {
|
|
333
|
-
try {
|
|
334
|
-
// Use safe parsing - V2 may store plain strings like "task-started" instead of JSON
|
|
335
|
-
const state = this.safeJsonParse(exp.state, 'state');
|
|
336
|
-
const nextState = exp.next_state ? this.safeJsonParse(exp.next_state, 'nextState') : null;
|
|
337
|
-
const metadata = this.safeJsonParse(exp.metadata, 'metadata');
|
|
338
|
-
const qeDomain = this.mapTaskTypeToDomain(exp.task_type);
|
|
339
|
-
insert.run(`le_${exp.id}`, // Prefix to avoid ID collision
|
|
340
|
-
'test-template', qeDomain, exp.task_type, `RL Experience: ${exp.task_type}`, `Action: ${exp.action}, Reward: ${exp.reward.toFixed(2)}`, Math.min(1.0, Math.max(0.1, exp.reward)), // Confidence from reward
|
|
341
|
-
1, exp.reward > 0 ? 1.0 : 0.0, 'short-term', JSON.stringify({ state, action: exp.action, reward: exp.reward, nextState, metadata }), new Date(exp.created_at).toISOString());
|
|
342
|
-
count++;
|
|
343
|
-
}
|
|
344
|
-
catch (error) {
|
|
345
|
-
console.warn(`[V2Migration] Failed to migrate learning experience ${exp.id}:`, error);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
return count;
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Migrate concept graph (nodes and edges) for code intelligence
|
|
352
|
-
*/
|
|
353
|
-
async migrateConceptGraph(nodes, edges) {
|
|
354
|
-
if (!this.v3Db)
|
|
355
|
-
throw new Error('V3 database not connected');
|
|
356
|
-
if (nodes.length === 0)
|
|
357
|
-
return 0;
|
|
358
|
-
const insert = this.v3Db.prepare(`
|
|
359
|
-
INSERT OR REPLACE INTO qe_patterns (
|
|
360
|
-
id, pattern_type, qe_domain, domain, name, description,
|
|
361
|
-
confidence, usage_count, success_rate, tier, context_json, created_at
|
|
362
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
363
|
-
`);
|
|
364
|
-
let count = 0;
|
|
365
|
-
// Store concept nodes as knowledge graph patterns
|
|
366
|
-
for (const node of nodes) {
|
|
367
|
-
try {
|
|
368
|
-
// Use safe parsing for non-JSON values
|
|
369
|
-
const properties = this.safeJsonParse(node.properties, 'properties');
|
|
370
|
-
const embedding = this.safeJsonParse(node.embedding, 'embedding');
|
|
371
|
-
insert.run(`cn_${node.id}`, // Prefix for concept node
|
|
372
|
-
'test-template', 'code-intelligence', node.type, node.name, String(properties.description || '') || `Concept: ${node.name}`, node.activation_level || 0.5, 0, 1.0, // Concepts are valid by default
|
|
373
|
-
'medium-term', JSON.stringify({
|
|
374
|
-
type: node.type,
|
|
375
|
-
domain: node.domain,
|
|
376
|
-
properties,
|
|
377
|
-
embedding,
|
|
378
|
-
activationLevel: node.activation_level,
|
|
379
|
-
}), new Date(node.created_at * 1000).toISOString());
|
|
380
|
-
count++;
|
|
381
|
-
}
|
|
382
|
-
catch (error) {
|
|
383
|
-
console.warn(`[V2Migration] Failed to migrate concept node ${node.id}:`, error);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
// Store edges as relationship patterns
|
|
387
|
-
for (const edge of edges) {
|
|
388
|
-
try {
|
|
389
|
-
insert.run(`ce_${edge.id}`, // Prefix for concept edge
|
|
390
|
-
'test-template', 'code-intelligence', edge.type, `${edge.source} → ${edge.target}`, `Weight: ${edge.weight.toFixed(2)}, Evidence: ${edge.evidence}`, edge.weight, 0, 1.0, 'short-term', JSON.stringify({
|
|
391
|
-
source: edge.source,
|
|
392
|
-
target: edge.target,
|
|
393
|
-
weight: edge.weight,
|
|
394
|
-
evidence: edge.evidence,
|
|
395
|
-
}), new Date(edge.created_at * 1000).toISOString());
|
|
396
|
-
count++;
|
|
397
|
-
}
|
|
398
|
-
catch (error) {
|
|
399
|
-
console.warn(`[V2Migration] Failed to migrate concept edge ${edge.id}:`, error);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
return count;
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* Validate migration results
|
|
406
|
-
*/
|
|
407
|
-
async validateMigration() {
|
|
408
|
-
if (!this.v3Db)
|
|
409
|
-
throw new Error('V3 database not connected');
|
|
410
|
-
const errors = [];
|
|
411
|
-
// Check pattern counts (0 is valid if v2 had no patterns)
|
|
412
|
-
const patternCount = this.v3Db.prepare('SELECT COUNT(*) as count FROM qe_patterns').get();
|
|
413
|
-
if (patternCount.count === 0) {
|
|
414
|
-
// Not an error - v2 might have had no patterns to migrate
|
|
415
|
-
console.log(' [V2Migration] Note: No patterns were migrated (v2 database may have been empty)');
|
|
416
|
-
}
|
|
417
|
-
// Check for duplicate IDs (actual error)
|
|
418
|
-
const duplicates = this.v3Db.prepare(`
|
|
419
|
-
SELECT id, COUNT(*) as count FROM qe_patterns GROUP BY id HAVING count > 1
|
|
420
|
-
`).all();
|
|
421
|
-
if (duplicates.length > 0) {
|
|
422
|
-
errors.push(`${duplicates.length} duplicate pattern IDs found`);
|
|
423
|
-
}
|
|
424
|
-
return errors;
|
|
425
|
-
}
|
|
426
|
-
// -------------------------------------------------------------------------
|
|
427
|
-
// Mapping Helpers
|
|
428
|
-
// -------------------------------------------------------------------------
|
|
429
|
-
mapV2DomainToV3(v2Domain) {
|
|
430
|
-
const domainMap = {
|
|
431
|
-
'test-generation': 'test-generation',
|
|
432
|
-
'test': 'test-generation',
|
|
433
|
-
'testing': 'test-generation',
|
|
434
|
-
'coverage': 'coverage-analysis',
|
|
435
|
-
'coverage-analysis': 'coverage-analysis',
|
|
436
|
-
'quality': 'quality-assessment',
|
|
437
|
-
'defect': 'defect-intelligence',
|
|
438
|
-
'security': 'security-compliance',
|
|
439
|
-
'code-intelligence': 'code-intelligence',
|
|
440
|
-
'knowledge': 'code-intelligence',
|
|
441
|
-
'learning': 'learning-optimization',
|
|
442
|
-
'contract': 'contract-testing',
|
|
443
|
-
'visual': 'visual-accessibility',
|
|
444
|
-
'a11y': 'visual-accessibility',
|
|
445
|
-
'chaos': 'chaos-resilience',
|
|
446
|
-
'performance': 'chaos-resilience',
|
|
447
|
-
'requirements': 'requirements-validation',
|
|
448
|
-
'general': 'test-generation', // Default to test-generation
|
|
449
|
-
};
|
|
450
|
-
return domainMap[v2Domain.toLowerCase()] || 'test-generation';
|
|
451
|
-
}
|
|
452
|
-
mapTaskTypeToDomain(taskType) {
|
|
453
|
-
const typeLower = taskType.toLowerCase();
|
|
454
|
-
if (typeLower.includes('test') || typeLower.includes('spec'))
|
|
455
|
-
return 'test-generation';
|
|
456
|
-
if (typeLower.includes('coverage'))
|
|
457
|
-
return 'coverage-analysis';
|
|
458
|
-
if (typeLower.includes('defect') || typeLower.includes('bug'))
|
|
459
|
-
return 'defect-intelligence';
|
|
460
|
-
if (typeLower.includes('security') || typeLower.includes('vuln'))
|
|
461
|
-
return 'security-compliance';
|
|
462
|
-
if (typeLower.includes('concept') || typeLower.includes('semantic'))
|
|
463
|
-
return 'code-intelligence';
|
|
464
|
-
if (typeLower.includes('learn') || typeLower.includes('pattern'))
|
|
465
|
-
return 'learning-optimization';
|
|
466
|
-
if (typeLower.includes('contract') || typeLower.includes('api'))
|
|
467
|
-
return 'contract-testing';
|
|
468
|
-
if (typeLower.includes('visual') || typeLower.includes('a11y'))
|
|
469
|
-
return 'visual-accessibility';
|
|
470
|
-
if (typeLower.includes('chaos') || typeLower.includes('performance'))
|
|
471
|
-
return 'chaos-resilience';
|
|
472
|
-
return 'test-generation'; // Default
|
|
473
|
-
}
|
|
474
|
-
inferPatternType(patternData, metadata) {
|
|
475
|
-
const data = patternData;
|
|
476
|
-
const meta = metadata || {};
|
|
477
|
-
// Check metadata first
|
|
478
|
-
if (meta.patternType)
|
|
479
|
-
return String(meta.patternType);
|
|
480
|
-
if (data.type)
|
|
481
|
-
return String(data.type);
|
|
482
|
-
// Infer from pattern content
|
|
483
|
-
const patternStr = JSON.stringify(patternData).toLowerCase();
|
|
484
|
-
const metaStr = JSON.stringify(metadata).toLowerCase();
|
|
485
|
-
if (patternStr.includes('mock') || metaStr.includes('mock'))
|
|
486
|
-
return 'mock-pattern';
|
|
487
|
-
if (patternStr.includes('assert') || metaStr.includes('assert'))
|
|
488
|
-
return 'assertion-pattern';
|
|
489
|
-
if (patternStr.includes('coverage'))
|
|
490
|
-
return 'coverage-strategy';
|
|
491
|
-
if (patternStr.includes('mutation'))
|
|
492
|
-
return 'mutation-strategy';
|
|
493
|
-
if (patternStr.includes('contract') || patternStr.includes('api'))
|
|
494
|
-
return 'api-contract';
|
|
495
|
-
if (patternStr.includes('visual') || patternStr.includes('snapshot'))
|
|
496
|
-
return 'visual-baseline';
|
|
497
|
-
if (patternStr.includes('a11y') || patternStr.includes('accessibility'))
|
|
498
|
-
return 'a11y-check';
|
|
499
|
-
if (patternStr.includes('performance') || patternStr.includes('benchmark'))
|
|
500
|
-
return 'perf-benchmark';
|
|
501
|
-
if (patternStr.includes('flaky'))
|
|
502
|
-
return 'flaky-fix';
|
|
503
|
-
if (patternStr.includes('refactor'))
|
|
504
|
-
return 'refactor-safe';
|
|
505
|
-
return 'test-template'; // Default
|
|
506
|
-
}
|
|
507
|
-
calculateTier(usageCount, qualityScore) {
|
|
508
|
-
if (usageCount >= 10 && qualityScore >= 0.8)
|
|
509
|
-
return 'long-term';
|
|
510
|
-
if (usageCount >= 5 || qualityScore >= 0.6)
|
|
511
|
-
return 'medium-term';
|
|
512
|
-
return 'short-term';
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
// ============================================================================
|
|
516
|
-
// Factory Function
|
|
517
|
-
// ============================================================================
|
|
518
|
-
/**
|
|
519
|
-
* Create and execute a V2 to V3 migration
|
|
520
|
-
*/
|
|
521
|
-
export async function migrateV2ToV3(v2DbPath = '.agentic-qe/memory.db', v3PatternsDbPath = '.agentic-qe/memory.db', onProgress) {
|
|
522
|
-
const migrator = new V2ToV3Migrator({
|
|
523
|
-
v2DbPath,
|
|
524
|
-
v3PatternsDbPath,
|
|
525
|
-
onProgress,
|
|
526
|
-
});
|
|
527
|
-
return migrator.migrate();
|
|
528
|
-
}
|
|
529
|
-
//# sourceMappingURL=v2-to-v3-migration.js.map
|