agentic-qe 3.6.9 → 3.6.11
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/skills/.validation/schemas/skill-eval.schema.json +11 -1
- package/.claude/skills/pr-review/SKILL.md +2 -2
- package/.claude/skills/qcsd-production-swarm/SKILL.md +2781 -0
- package/.claude/skills/qcsd-production-swarm/evals/qcsd-production-swarm.yaml +246 -0
- package/.claude/skills/qcsd-production-swarm/schemas/output.json +505 -0
- package/.claude/skills/qcsd-production-swarm/scripts/validate-config.json +25 -0
- package/.claude/skills/skills-manifest.json +5 -5
- package/package.json +1 -1
- package/scripts/benchmark-hnsw-loading.ts +480 -0
- package/scripts/benchmark-kg-assisted.ts +725 -0
- package/scripts/collect-production-telemetry.sh +291 -0
- package/scripts/detect-skill-conflicts.ts +347 -0
- package/scripts/eval-driven-workflow.ts +704 -0
- package/scripts/run-skill-eval.ts +210 -10
- package/scripts/score-skill-quality.ts +511 -0
- package/v3/CHANGELOG.md +44 -0
- package/v3/assets/skills/pr-review/SKILL.md +2 -2
- package/v3/dist/cli/bundle.js +1526 -700
- package/v3/dist/cli/commands/code.d.ts.map +1 -1
- package/v3/dist/cli/commands/code.js +9 -85
- package/v3/dist/cli/commands/code.js.map +1 -1
- package/v3/dist/cli/commands/coverage.d.ts.map +1 -1
- package/v3/dist/cli/commands/coverage.js +3 -28
- package/v3/dist/cli/commands/coverage.js.map +1 -1
- package/v3/dist/cli/commands/hooks.d.ts.map +1 -1
- package/v3/dist/cli/commands/hooks.js +143 -2
- package/v3/dist/cli/commands/hooks.js.map +1 -1
- package/v3/dist/cli/commands/security.d.ts.map +1 -1
- package/v3/dist/cli/commands/security.js +3 -29
- package/v3/dist/cli/commands/security.js.map +1 -1
- package/v3/dist/cli/commands/test.d.ts.map +1 -1
- package/v3/dist/cli/commands/test.js +11 -58
- package/v3/dist/cli/commands/test.js.map +1 -1
- package/v3/dist/cli/utils/file-discovery.d.ts +27 -0
- package/v3/dist/cli/utils/file-discovery.d.ts.map +1 -0
- package/v3/dist/cli/utils/file-discovery.js +105 -0
- package/v3/dist/cli/utils/file-discovery.js.map +1 -0
- package/v3/dist/coordination/task-executor.d.ts.map +1 -1
- package/v3/dist/coordination/task-executor.js +304 -44
- package/v3/dist/coordination/task-executor.js.map +1 -1
- package/v3/dist/domains/code-intelligence/coordinator.d.ts.map +1 -1
- package/v3/dist/domains/code-intelligence/coordinator.js +8 -1
- package/v3/dist/domains/code-intelligence/coordinator.js.map +1 -1
- package/v3/dist/domains/code-intelligence/services/metric-collector/index.d.ts.map +1 -1
- package/v3/dist/domains/code-intelligence/services/metric-collector/index.js +10 -0
- package/v3/dist/domains/code-intelligence/services/metric-collector/index.js.map +1 -1
- package/v3/dist/domains/code-intelligence/services/metric-collector/interfaces.d.ts +7 -1
- package/v3/dist/domains/code-intelligence/services/metric-collector/interfaces.d.ts.map +1 -1
- package/v3/dist/domains/code-intelligence/services/metric-collector/interfaces.js +10 -1
- package/v3/dist/domains/code-intelligence/services/metric-collector/interfaces.js.map +1 -1
- package/v3/dist/domains/code-intelligence/services/metric-collector/loc-counter.js +34 -10
- package/v3/dist/domains/code-intelligence/services/metric-collector/loc-counter.js.map +1 -1
- package/v3/dist/domains/coverage-analysis/services/hnsw-index.d.ts +9 -0
- package/v3/dist/domains/coverage-analysis/services/hnsw-index.d.ts.map +1 -1
- package/v3/dist/domains/coverage-analysis/services/hnsw-index.js +38 -3
- package/v3/dist/domains/coverage-analysis/services/hnsw-index.js.map +1 -1
- package/v3/dist/domains/test-generation/generators/jest-vitest-generator.d.ts.map +1 -1
- package/v3/dist/domains/test-generation/generators/jest-vitest-generator.js +58 -6
- package/v3/dist/domains/test-generation/generators/jest-vitest-generator.js.map +1 -1
- package/v3/dist/domains/test-generation/generators/mocha-generator.d.ts.map +1 -1
- package/v3/dist/domains/test-generation/generators/mocha-generator.js +79 -7
- package/v3/dist/domains/test-generation/generators/mocha-generator.js.map +1 -1
- package/v3/dist/domains/test-generation/generators/pytest-generator.d.ts +4 -0
- package/v3/dist/domains/test-generation/generators/pytest-generator.d.ts.map +1 -1
- package/v3/dist/domains/test-generation/generators/pytest-generator.js +77 -10
- package/v3/dist/domains/test-generation/generators/pytest-generator.js.map +1 -1
- package/v3/dist/domains/test-generation/interfaces/test-generator.interface.d.ts +21 -0
- package/v3/dist/domains/test-generation/interfaces/test-generator.interface.d.ts.map +1 -1
- package/v3/dist/domains/test-generation/interfaces.d.ts +21 -0
- package/v3/dist/domains/test-generation/interfaces.d.ts.map +1 -1
- package/v3/dist/domains/test-generation/services/test-generator.d.ts +22 -0
- package/v3/dist/domains/test-generation/services/test-generator.d.ts.map +1 -1
- package/v3/dist/domains/test-generation/services/test-generator.js +163 -3
- package/v3/dist/domains/test-generation/services/test-generator.js.map +1 -1
- package/v3/dist/init/init-wizard-hooks.d.ts +8 -1
- package/v3/dist/init/init-wizard-hooks.d.ts.map +1 -1
- package/v3/dist/init/init-wizard-hooks.js +47 -39
- package/v3/dist/init/init-wizard-hooks.js.map +1 -1
- package/v3/dist/init/phases/07-hooks.d.ts +11 -1
- package/v3/dist/init/phases/07-hooks.d.ts.map +1 -1
- package/v3/dist/init/phases/07-hooks.js +46 -50
- package/v3/dist/init/phases/07-hooks.js.map +1 -1
- package/v3/dist/init/settings-merge.d.ts +35 -0
- package/v3/dist/init/settings-merge.d.ts.map +1 -0
- package/v3/dist/init/settings-merge.js +140 -0
- package/v3/dist/init/settings-merge.js.map +1 -0
- package/v3/dist/integrations/agentic-flow/model-router/router.js +1 -1
- package/v3/dist/integrations/agentic-flow/model-router/router.js.map +1 -1
- package/v3/dist/integrations/agentic-flow/model-router/score-calculator.d.ts.map +1 -1
- package/v3/dist/integrations/agentic-flow/model-router/score-calculator.js +18 -3
- package/v3/dist/integrations/agentic-flow/model-router/score-calculator.js.map +1 -1
- package/v3/dist/integrations/agentic-flow/model-router/signal-collector.d.ts +3 -3
- package/v3/dist/integrations/agentic-flow/model-router/signal-collector.d.ts.map +1 -1
- package/v3/dist/integrations/agentic-flow/model-router/signal-collector.js +18 -0
- package/v3/dist/integrations/agentic-flow/model-router/signal-collector.js.map +1 -1
- package/v3/dist/kernel/unified-memory-hnsw.d.ts +29 -0
- package/v3/dist/kernel/unified-memory-hnsw.d.ts.map +1 -1
- package/v3/dist/kernel/unified-memory-hnsw.js +136 -0
- package/v3/dist/kernel/unified-memory-hnsw.js.map +1 -1
- package/v3/dist/kernel/unified-memory.d.ts +2 -2
- package/v3/dist/kernel/unified-memory.d.ts.map +1 -1
- package/v3/dist/kernel/unified-memory.js +7 -9
- package/v3/dist/kernel/unified-memory.js.map +1 -1
- package/v3/dist/learning/qe-hooks.d.ts.map +1 -1
- package/v3/dist/learning/qe-hooks.js +34 -3
- package/v3/dist/learning/qe-hooks.js.map +1 -1
- package/v3/dist/mcp/bundle.js +1403 -425
- package/v3/dist/mcp/handlers/domain-handler-configs.d.ts.map +1 -1
- package/v3/dist/mcp/handlers/domain-handler-configs.js +40 -31
- package/v3/dist/mcp/handlers/domain-handler-configs.js.map +1 -1
- package/v3/dist/mcp/handlers/task-handlers.d.ts.map +1 -1
- package/v3/dist/mcp/handlers/task-handlers.js +68 -5
- package/v3/dist/mcp/handlers/task-handlers.js.map +1 -1
- package/v3/dist/mcp/protocol-server.d.ts.map +1 -1
- package/v3/dist/mcp/protocol-server.js +16 -2
- package/v3/dist/mcp/protocol-server.js.map +1 -1
- package/v3/package.json +1 -1
package/v3/dist/cli/bundle.js
CHANGED
|
@@ -1144,13 +1144,90 @@ var init_sql_safety = __esm({
|
|
|
1144
1144
|
}
|
|
1145
1145
|
});
|
|
1146
1146
|
|
|
1147
|
+
// native-require:@ruvector/gnn
|
|
1148
|
+
var gnn_exports = {};
|
|
1149
|
+
__export(gnn_exports, {
|
|
1150
|
+
DotProductAttention: () => DotProductAttention2,
|
|
1151
|
+
FlashAttention: () => FlashAttention2,
|
|
1152
|
+
HyperbolicAttention: () => HyperbolicAttention2,
|
|
1153
|
+
LinearAttention: () => LinearAttention2,
|
|
1154
|
+
MoEAttention: () => MoEAttention2,
|
|
1155
|
+
MultiHeadAttention: () => MultiHeadAttention2,
|
|
1156
|
+
RuvectorLayer: () => RuvectorLayer2,
|
|
1157
|
+
SonaEngine: () => SonaEngine2,
|
|
1158
|
+
TensorCompress: () => TensorCompress2,
|
|
1159
|
+
default: () => gnn_default,
|
|
1160
|
+
differentiableSearch: () => differentiableSearch2,
|
|
1161
|
+
getCompressionLevel: () => getCompressionLevel2,
|
|
1162
|
+
hierarchicalForward: () => hierarchicalForward2,
|
|
1163
|
+
init: () => init2,
|
|
1164
|
+
pipeline: () => pipeline2
|
|
1165
|
+
});
|
|
1166
|
+
import { createRequire as createRequire2 } from "module";
|
|
1167
|
+
var __require3, __mod2, gnn_default, RuvectorLayer2, TensorCompress2, differentiableSearch2, hierarchicalForward2, getCompressionLevel2, init2, FlashAttention2, DotProductAttention2, MultiHeadAttention2, HyperbolicAttention2, LinearAttention2, MoEAttention2, SonaEngine2, pipeline2;
|
|
1168
|
+
var init_gnn = __esm({
|
|
1169
|
+
"native-require:@ruvector/gnn"() {
|
|
1170
|
+
__require3 = createRequire2(import.meta.url);
|
|
1171
|
+
__mod2 = __require3("@ruvector/gnn");
|
|
1172
|
+
gnn_default = __mod2;
|
|
1173
|
+
({
|
|
1174
|
+
RuvectorLayer: (
|
|
1175
|
+
// @ruvector/gnn
|
|
1176
|
+
RuvectorLayer2
|
|
1177
|
+
),
|
|
1178
|
+
TensorCompress: TensorCompress2,
|
|
1179
|
+
differentiableSearch: differentiableSearch2,
|
|
1180
|
+
hierarchicalForward: hierarchicalForward2,
|
|
1181
|
+
getCompressionLevel: getCompressionLevel2,
|
|
1182
|
+
init: init2,
|
|
1183
|
+
FlashAttention: (
|
|
1184
|
+
// @ruvector/attention
|
|
1185
|
+
FlashAttention2
|
|
1186
|
+
),
|
|
1187
|
+
DotProductAttention: DotProductAttention2,
|
|
1188
|
+
MultiHeadAttention: MultiHeadAttention2,
|
|
1189
|
+
HyperbolicAttention: HyperbolicAttention2,
|
|
1190
|
+
LinearAttention: LinearAttention2,
|
|
1191
|
+
MoEAttention: MoEAttention2,
|
|
1192
|
+
SonaEngine: (
|
|
1193
|
+
// @ruvector/sona
|
|
1194
|
+
SonaEngine2
|
|
1195
|
+
),
|
|
1196
|
+
pipeline: (
|
|
1197
|
+
// @xenova/transformers
|
|
1198
|
+
pipeline2
|
|
1199
|
+
)
|
|
1200
|
+
} = __mod2 || {});
|
|
1201
|
+
}
|
|
1202
|
+
});
|
|
1203
|
+
|
|
1147
1204
|
// src/kernel/unified-memory-hnsw.ts
|
|
1148
|
-
|
|
1205
|
+
function computeNorm(v62) {
|
|
1206
|
+
let sum = 0;
|
|
1207
|
+
for (let i58 = 0; i58 < v62.length; i58++) sum += v62[i58] * v62[i58];
|
|
1208
|
+
return Math.sqrt(sum);
|
|
1209
|
+
}
|
|
1210
|
+
function fastCosine(a37, b68, normA, normB) {
|
|
1211
|
+
const denom = normA * normB;
|
|
1212
|
+
if (denom === 0) return 0;
|
|
1213
|
+
let dot = 0;
|
|
1214
|
+
for (let i58 = 0; i58 < a37.length; i58++) dot += a37[i58] * b68[i58];
|
|
1215
|
+
return dot / denom;
|
|
1216
|
+
}
|
|
1217
|
+
var ruvectorDifferentiableSearch, ruvectorInit, BinaryHeap, InMemoryHNSWIndex, RuvectorFlatIndex;
|
|
1149
1218
|
var init_unified_memory_hnsw = __esm({
|
|
1150
1219
|
"src/kernel/unified-memory-hnsw.ts"() {
|
|
1151
1220
|
"use strict";
|
|
1152
1221
|
init_vector_math();
|
|
1153
1222
|
init_constants();
|
|
1223
|
+
ruvectorDifferentiableSearch = null;
|
|
1224
|
+
ruvectorInit = null;
|
|
1225
|
+
try {
|
|
1226
|
+
const gnn = (init_gnn(), __toCommonJS(gnn_exports));
|
|
1227
|
+
ruvectorDifferentiableSearch = gnn.differentiableSearch;
|
|
1228
|
+
ruvectorInit = gnn.init;
|
|
1229
|
+
} catch {
|
|
1230
|
+
}
|
|
1154
1231
|
BinaryHeap = class {
|
|
1155
1232
|
data = [];
|
|
1156
1233
|
compareFn;
|
|
@@ -1483,6 +1560,94 @@ var init_unified_memory_hnsw = __esm({
|
|
|
1483
1560
|
this.currentMaxLevel = -1;
|
|
1484
1561
|
}
|
|
1485
1562
|
};
|
|
1563
|
+
RuvectorFlatIndex = class {
|
|
1564
|
+
ids = [];
|
|
1565
|
+
vectors = [];
|
|
1566
|
+
/** Pre-computed L2 norms for each vector (enables dot-product-only cosine). */
|
|
1567
|
+
norms = [];
|
|
1568
|
+
idToIndex = /* @__PURE__ */ new Map();
|
|
1569
|
+
initialized = false;
|
|
1570
|
+
constructor() {
|
|
1571
|
+
if (ruvectorInit && !this.initialized) {
|
|
1572
|
+
try {
|
|
1573
|
+
ruvectorInit();
|
|
1574
|
+
this.initialized = true;
|
|
1575
|
+
} catch {
|
|
1576
|
+
this.initialized = ruvectorDifferentiableSearch !== null;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
add(id, embedding) {
|
|
1581
|
+
const f322 = new Float32Array(embedding);
|
|
1582
|
+
const norm = computeNorm(f322);
|
|
1583
|
+
if (this.idToIndex.has(id)) {
|
|
1584
|
+
const idx2 = this.idToIndex.get(id);
|
|
1585
|
+
this.vectors[idx2] = f322;
|
|
1586
|
+
this.norms[idx2] = norm;
|
|
1587
|
+
return;
|
|
1588
|
+
}
|
|
1589
|
+
const idx = this.ids.length;
|
|
1590
|
+
this.ids.push(id);
|
|
1591
|
+
this.vectors.push(f322);
|
|
1592
|
+
this.norms.push(norm);
|
|
1593
|
+
this.idToIndex.set(id, idx);
|
|
1594
|
+
}
|
|
1595
|
+
search(query, k68) {
|
|
1596
|
+
if (this.ids.length === 0) return [];
|
|
1597
|
+
const actualK = Math.min(k68, this.ids.length);
|
|
1598
|
+
if (ruvectorDifferentiableSearch && this.vectors.length > 0) {
|
|
1599
|
+
const queryF322 = new Float32Array(query);
|
|
1600
|
+
const queryNorm2 = computeNorm(queryF322);
|
|
1601
|
+
const result = ruvectorDifferentiableSearch(
|
|
1602
|
+
queryF322,
|
|
1603
|
+
this.vectors,
|
|
1604
|
+
actualK,
|
|
1605
|
+
1
|
|
1606
|
+
);
|
|
1607
|
+
return result.indices.map((idx) => ({
|
|
1608
|
+
id: this.ids[idx],
|
|
1609
|
+
score: fastCosine(queryF322, this.vectors[idx], queryNorm2, this.norms[idx])
|
|
1610
|
+
}));
|
|
1611
|
+
}
|
|
1612
|
+
const queryF32 = new Float32Array(query);
|
|
1613
|
+
const queryNorm = computeNorm(queryF32);
|
|
1614
|
+
const scored = [];
|
|
1615
|
+
for (let i58 = 0; i58 < this.ids.length; i58++) {
|
|
1616
|
+
scored.push({
|
|
1617
|
+
id: this.ids[i58],
|
|
1618
|
+
score: fastCosine(queryF32, this.vectors[i58], queryNorm, this.norms[i58])
|
|
1619
|
+
});
|
|
1620
|
+
}
|
|
1621
|
+
scored.sort((a37, b68) => b68.score - a37.score);
|
|
1622
|
+
return scored.slice(0, actualK);
|
|
1623
|
+
}
|
|
1624
|
+
remove(id) {
|
|
1625
|
+
const idx = this.idToIndex.get(id);
|
|
1626
|
+
if (idx === void 0) return false;
|
|
1627
|
+
const lastIdx = this.ids.length - 1;
|
|
1628
|
+
if (idx !== lastIdx) {
|
|
1629
|
+
const lastId = this.ids[lastIdx];
|
|
1630
|
+
this.ids[idx] = lastId;
|
|
1631
|
+
this.vectors[idx] = this.vectors[lastIdx];
|
|
1632
|
+
this.norms[idx] = this.norms[lastIdx];
|
|
1633
|
+
this.idToIndex.set(lastId, idx);
|
|
1634
|
+
}
|
|
1635
|
+
this.ids.pop();
|
|
1636
|
+
this.vectors.pop();
|
|
1637
|
+
this.norms.pop();
|
|
1638
|
+
this.idToIndex.delete(id);
|
|
1639
|
+
return true;
|
|
1640
|
+
}
|
|
1641
|
+
clear() {
|
|
1642
|
+
this.ids = [];
|
|
1643
|
+
this.vectors = [];
|
|
1644
|
+
this.norms = [];
|
|
1645
|
+
this.idToIndex.clear();
|
|
1646
|
+
}
|
|
1647
|
+
size() {
|
|
1648
|
+
return this.ids.length;
|
|
1649
|
+
}
|
|
1650
|
+
};
|
|
1486
1651
|
}
|
|
1487
1652
|
});
|
|
1488
1653
|
|
|
@@ -3037,6 +3202,7 @@ __export(unified_memory_exports, {
|
|
|
3037
3202
|
BinaryHeap: () => BinaryHeap,
|
|
3038
3203
|
DEFAULT_UNIFIED_MEMORY_CONFIG: () => DEFAULT_UNIFIED_MEMORY_CONFIG,
|
|
3039
3204
|
InMemoryHNSWIndex: () => InMemoryHNSWIndex,
|
|
3205
|
+
RuvectorFlatIndex: () => RuvectorFlatIndex,
|
|
3040
3206
|
UnifiedMemoryManager: () => UnifiedMemoryManager,
|
|
3041
3207
|
clearProjectRootCache: () => clearProjectRootCache,
|
|
3042
3208
|
findProjectRoot: () => findProjectRoot,
|
|
@@ -3167,7 +3333,7 @@ var init_unified_memory = __esm({
|
|
|
3167
3333
|
vectorsLoaded = false;
|
|
3168
3334
|
initPromise = null;
|
|
3169
3335
|
preparedStatements = /* @__PURE__ */ new Map();
|
|
3170
|
-
vectorIndex = new
|
|
3336
|
+
vectorIndex = new RuvectorFlatIndex();
|
|
3171
3337
|
// CRDT store for distributed state synchronization
|
|
3172
3338
|
crdtStore = null;
|
|
3173
3339
|
constructor(config) {
|
|
@@ -3335,7 +3501,7 @@ var init_unified_memory = __esm({
|
|
|
3335
3501
|
this.vectorIndex.add(row.id, embedding);
|
|
3336
3502
|
}
|
|
3337
3503
|
this.vectorsLoaded = true;
|
|
3338
|
-
console.log(`[UnifiedMemory] Loaded ${rows.length} vectors into
|
|
3504
|
+
console.log(`[UnifiedMemory] Loaded ${rows.length} vectors into vector index (ruvector flat)`);
|
|
3339
3505
|
}
|
|
3340
3506
|
// ============================================================================
|
|
3341
3507
|
// KV Store Operations (v2 compatible)
|
|
@@ -3639,9 +3805,8 @@ var init_unified_memory = __esm({
|
|
|
3639
3805
|
return buffer;
|
|
3640
3806
|
}
|
|
3641
3807
|
bufferToFloatArray(buffer, dimensions) {
|
|
3642
|
-
const
|
|
3643
|
-
|
|
3644
|
-
return arr;
|
|
3808
|
+
const f322 = new Float32Array(buffer.buffer, buffer.byteOffset, dimensions);
|
|
3809
|
+
return Array.from(f322);
|
|
3645
3810
|
}
|
|
3646
3811
|
};
|
|
3647
3812
|
exitHandlersRegistered = false;
|
|
@@ -3652,57 +3817,57 @@ var init_unified_memory = __esm({
|
|
|
3652
3817
|
// native-require:@xenova/transformers
|
|
3653
3818
|
var transformers_exports = {};
|
|
3654
3819
|
__export(transformers_exports, {
|
|
3655
|
-
DotProductAttention: () =>
|
|
3656
|
-
FlashAttention: () =>
|
|
3657
|
-
HyperbolicAttention: () =>
|
|
3658
|
-
LinearAttention: () =>
|
|
3659
|
-
MoEAttention: () =>
|
|
3660
|
-
MultiHeadAttention: () =>
|
|
3661
|
-
RuvectorLayer: () =>
|
|
3662
|
-
SonaEngine: () =>
|
|
3663
|
-
TensorCompress: () =>
|
|
3820
|
+
DotProductAttention: () => DotProductAttention3,
|
|
3821
|
+
FlashAttention: () => FlashAttention3,
|
|
3822
|
+
HyperbolicAttention: () => HyperbolicAttention3,
|
|
3823
|
+
LinearAttention: () => LinearAttention3,
|
|
3824
|
+
MoEAttention: () => MoEAttention3,
|
|
3825
|
+
MultiHeadAttention: () => MultiHeadAttention3,
|
|
3826
|
+
RuvectorLayer: () => RuvectorLayer3,
|
|
3827
|
+
SonaEngine: () => SonaEngine3,
|
|
3828
|
+
TensorCompress: () => TensorCompress3,
|
|
3664
3829
|
default: () => transformers_default,
|
|
3665
|
-
differentiableSearch: () =>
|
|
3666
|
-
getCompressionLevel: () =>
|
|
3667
|
-
hierarchicalForward: () =>
|
|
3668
|
-
init: () =>
|
|
3669
|
-
pipeline: () =>
|
|
3830
|
+
differentiableSearch: () => differentiableSearch3,
|
|
3831
|
+
getCompressionLevel: () => getCompressionLevel3,
|
|
3832
|
+
hierarchicalForward: () => hierarchicalForward3,
|
|
3833
|
+
init: () => init3,
|
|
3834
|
+
pipeline: () => pipeline3
|
|
3670
3835
|
});
|
|
3671
|
-
import { createRequire as
|
|
3672
|
-
var
|
|
3836
|
+
import { createRequire as createRequire3 } from "module";
|
|
3837
|
+
var __require4, __mod3, transformers_default, RuvectorLayer3, TensorCompress3, differentiableSearch3, hierarchicalForward3, getCompressionLevel3, init3, FlashAttention3, DotProductAttention3, MultiHeadAttention3, HyperbolicAttention3, LinearAttention3, MoEAttention3, SonaEngine3, pipeline3;
|
|
3673
3838
|
var init_transformers = __esm({
|
|
3674
3839
|
"native-require:@xenova/transformers"() {
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
transformers_default =
|
|
3840
|
+
__require4 = createRequire3(import.meta.url);
|
|
3841
|
+
__mod3 = __require4("@xenova/transformers");
|
|
3842
|
+
transformers_default = __mod3;
|
|
3678
3843
|
({
|
|
3679
3844
|
RuvectorLayer: (
|
|
3680
3845
|
// @ruvector/gnn
|
|
3681
|
-
|
|
3846
|
+
RuvectorLayer3
|
|
3682
3847
|
),
|
|
3683
|
-
TensorCompress:
|
|
3684
|
-
differentiableSearch:
|
|
3685
|
-
hierarchicalForward:
|
|
3686
|
-
getCompressionLevel:
|
|
3687
|
-
init:
|
|
3848
|
+
TensorCompress: TensorCompress3,
|
|
3849
|
+
differentiableSearch: differentiableSearch3,
|
|
3850
|
+
hierarchicalForward: hierarchicalForward3,
|
|
3851
|
+
getCompressionLevel: getCompressionLevel3,
|
|
3852
|
+
init: init3,
|
|
3688
3853
|
FlashAttention: (
|
|
3689
3854
|
// @ruvector/attention
|
|
3690
|
-
|
|
3855
|
+
FlashAttention3
|
|
3691
3856
|
),
|
|
3692
|
-
DotProductAttention:
|
|
3693
|
-
MultiHeadAttention:
|
|
3694
|
-
HyperbolicAttention:
|
|
3695
|
-
LinearAttention:
|
|
3696
|
-
MoEAttention:
|
|
3857
|
+
DotProductAttention: DotProductAttention3,
|
|
3858
|
+
MultiHeadAttention: MultiHeadAttention3,
|
|
3859
|
+
HyperbolicAttention: HyperbolicAttention3,
|
|
3860
|
+
LinearAttention: LinearAttention3,
|
|
3861
|
+
MoEAttention: MoEAttention3,
|
|
3697
3862
|
SonaEngine: (
|
|
3698
3863
|
// @ruvector/sona
|
|
3699
|
-
|
|
3864
|
+
SonaEngine3
|
|
3700
3865
|
),
|
|
3701
3866
|
pipeline: (
|
|
3702
3867
|
// @xenova/transformers
|
|
3703
|
-
|
|
3868
|
+
pipeline3
|
|
3704
3869
|
)
|
|
3705
|
-
} =
|
|
3870
|
+
} = __mod3 || {});
|
|
3706
3871
|
}
|
|
3707
3872
|
});
|
|
3708
3873
|
|
|
@@ -3730,10 +3895,10 @@ async function initializeModel(config = {}) {
|
|
|
3730
3895
|
initPromise = (async () => {
|
|
3731
3896
|
try {
|
|
3732
3897
|
const transformers = await Promise.resolve().then(() => (init_transformers(), transformers_exports));
|
|
3733
|
-
|
|
3898
|
+
pipeline4 = transformers.pipeline;
|
|
3734
3899
|
console.log(`[RealEmbeddings] Loading model: ${fullConfig.modelName}`);
|
|
3735
3900
|
const startTime = performance.now();
|
|
3736
|
-
embeddingModel = await
|
|
3901
|
+
embeddingModel = await pipeline4("feature-extraction", fullConfig.modelName, {
|
|
3737
3902
|
quantized: fullConfig.quantized
|
|
3738
3903
|
});
|
|
3739
3904
|
const loadTime = performance.now() - startTime;
|
|
@@ -3851,20 +4016,20 @@ function getEmbeddingDimension() {
|
|
|
3851
4016
|
return 384;
|
|
3852
4017
|
}
|
|
3853
4018
|
function resetInitialization() {
|
|
3854
|
-
|
|
4019
|
+
pipeline4 = null;
|
|
3855
4020
|
embeddingModel = null;
|
|
3856
4021
|
initPromise = null;
|
|
3857
4022
|
initializationFailed = false;
|
|
3858
4023
|
failureReason = "";
|
|
3859
4024
|
embeddingCache.clear();
|
|
3860
4025
|
}
|
|
3861
|
-
var
|
|
4026
|
+
var pipeline4, embeddingModel, initPromise, initializationFailed, failureReason, DEFAULT_EMBEDDING_CONFIG, embeddingCache, CACHE_TTL_MS;
|
|
3862
4027
|
var init_real_embeddings = __esm({
|
|
3863
4028
|
"src/learning/real-embeddings.ts"() {
|
|
3864
4029
|
"use strict";
|
|
3865
4030
|
init_vector_math();
|
|
3866
4031
|
init_error_utils();
|
|
3867
|
-
|
|
4032
|
+
pipeline4 = null;
|
|
3868
4033
|
embeddingModel = null;
|
|
3869
4034
|
initPromise = null;
|
|
3870
4035
|
initializationFailed = false;
|
|
@@ -4688,6 +4853,120 @@ var init_embeddings = __esm({
|
|
|
4688
4853
|
}
|
|
4689
4854
|
});
|
|
4690
4855
|
|
|
4856
|
+
// src/learning/qe-patterns.ts
|
|
4857
|
+
function detectQEDomain(taskDescription) {
|
|
4858
|
+
for (const [domain, pattern] of Object.entries(QE_DOMAINS)) {
|
|
4859
|
+
if (pattern.test(taskDescription)) {
|
|
4860
|
+
return domain;
|
|
4861
|
+
}
|
|
4862
|
+
}
|
|
4863
|
+
return null;
|
|
4864
|
+
}
|
|
4865
|
+
function detectQEDomains(taskDescription) {
|
|
4866
|
+
const detected = [];
|
|
4867
|
+
for (const [domain, pattern] of Object.entries(QE_DOMAINS)) {
|
|
4868
|
+
if (pattern.test(taskDescription)) {
|
|
4869
|
+
detected.push(domain);
|
|
4870
|
+
}
|
|
4871
|
+
}
|
|
4872
|
+
return detected;
|
|
4873
|
+
}
|
|
4874
|
+
function mapQEDomainToAQE(qeDomain) {
|
|
4875
|
+
return qeDomain;
|
|
4876
|
+
}
|
|
4877
|
+
function calculateQualityScore(pattern) {
|
|
4878
|
+
const usageScore = Math.min(pattern.usageCount / 100, 1);
|
|
4879
|
+
return pattern.confidence * 0.3 + usageScore * 0.2 + pattern.successRate * 0.5;
|
|
4880
|
+
}
|
|
4881
|
+
function shouldPromotePattern(pattern, coherenceEnergy, coherenceThreshold = 0.4) {
|
|
4882
|
+
const meetsUsageCriteria = pattern.tier === "short-term" && pattern.successfulUses >= 3;
|
|
4883
|
+
const meetsQualityCriteria = pattern.successRate >= 0.7 && pattern.confidence >= 0.6;
|
|
4884
|
+
const meetsCoherenceCriteria = coherenceEnergy === void 0 || coherenceEnergy < coherenceThreshold;
|
|
4885
|
+
let blockReason;
|
|
4886
|
+
if (!meetsUsageCriteria) {
|
|
4887
|
+
blockReason = "insufficient_usage";
|
|
4888
|
+
} else if (!meetsQualityCriteria) {
|
|
4889
|
+
blockReason = "low_quality";
|
|
4890
|
+
} else if (!meetsCoherenceCriteria) {
|
|
4891
|
+
blockReason = "coherence_violation";
|
|
4892
|
+
}
|
|
4893
|
+
return {
|
|
4894
|
+
meetsUsageCriteria,
|
|
4895
|
+
meetsQualityCriteria,
|
|
4896
|
+
meetsCoherenceCriteria,
|
|
4897
|
+
blockReason
|
|
4898
|
+
};
|
|
4899
|
+
}
|
|
4900
|
+
function validateQEPattern(pattern) {
|
|
4901
|
+
const errors = [];
|
|
4902
|
+
if (!pattern.id) errors.push("Pattern ID is required");
|
|
4903
|
+
if (!pattern.patternType) errors.push("Pattern type is required");
|
|
4904
|
+
if (!pattern.qeDomain) errors.push("QE domain is required");
|
|
4905
|
+
if (!pattern.name) errors.push("Pattern name is required");
|
|
4906
|
+
if (!pattern.template?.content) errors.push("Template content is required");
|
|
4907
|
+
if (pattern.confidence !== void 0 && (pattern.confidence < 0 || pattern.confidence > 1)) {
|
|
4908
|
+
errors.push("Confidence must be between 0 and 1");
|
|
4909
|
+
}
|
|
4910
|
+
if (pattern.successRate !== void 0 && (pattern.successRate < 0 || pattern.successRate > 1)) {
|
|
4911
|
+
errors.push("Success rate must be between 0 and 1");
|
|
4912
|
+
}
|
|
4913
|
+
if (pattern.template?.variables) {
|
|
4914
|
+
const variableNames = /* @__PURE__ */ new Set();
|
|
4915
|
+
for (const variable of pattern.template.variables) {
|
|
4916
|
+
if (variableNames.has(variable.name)) {
|
|
4917
|
+
errors.push(`Duplicate variable name: ${variable.name}`);
|
|
4918
|
+
}
|
|
4919
|
+
variableNames.add(variable.name);
|
|
4920
|
+
if (!pattern.template.content.includes(`{{${variable.name}}}`)) {
|
|
4921
|
+
errors.push(
|
|
4922
|
+
`Variable ${variable.name} not referenced in template`
|
|
4923
|
+
);
|
|
4924
|
+
}
|
|
4925
|
+
}
|
|
4926
|
+
}
|
|
4927
|
+
return { valid: errors.length === 0, errors };
|
|
4928
|
+
}
|
|
4929
|
+
function applyPatternTemplate(template, variables) {
|
|
4930
|
+
let content = template.content;
|
|
4931
|
+
for (const variable of template.variables) {
|
|
4932
|
+
const value = variables[variable.name] ?? variable.defaultValue;
|
|
4933
|
+
if (variable.required && value === void 0) {
|
|
4934
|
+
throw new Error(`Required variable ${variable.name} not provided`);
|
|
4935
|
+
}
|
|
4936
|
+
if (value !== void 0) {
|
|
4937
|
+
const placeholder = `{{${variable.name}}}`;
|
|
4938
|
+
const stringValue = typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
4939
|
+
content = content.split(placeholder).join(stringValue);
|
|
4940
|
+
}
|
|
4941
|
+
}
|
|
4942
|
+
return content;
|
|
4943
|
+
}
|
|
4944
|
+
var QE_DOMAINS, QE_DOMAIN_LIST;
|
|
4945
|
+
var init_qe_patterns = __esm({
|
|
4946
|
+
"src/learning/qe-patterns.ts"() {
|
|
4947
|
+
"use strict";
|
|
4948
|
+
QE_DOMAINS = {
|
|
4949
|
+
// Core Testing Domains
|
|
4950
|
+
"test-generation": /test|spec|describe|it\(|expect|assert|mock|stub|fixture|tdd|bdd/i,
|
|
4951
|
+
"test-execution": /run|execute|parallel|retry|flaky|timeout|worker|orchestrat/i,
|
|
4952
|
+
"coverage-analysis": /coverage|branch|line|uncovered|gap|untested|percentage|sublinear/i,
|
|
4953
|
+
// Quality Domains
|
|
4954
|
+
"quality-assessment": /quality|gate|deploy|readiness|metric|threshold|sla|score/i,
|
|
4955
|
+
"defect-intelligence": /defect|bug|predict|root.?cause|regression|failure|incident/i,
|
|
4956
|
+
"requirements-validation": /requirement|bdd|gherkin|testabil|accept|criteri|scenario/i,
|
|
4957
|
+
// Analysis Domains
|
|
4958
|
+
"code-intelligence": /semantic|knowledge|graph|ast|symbol|reference|impact|depend/i,
|
|
4959
|
+
"security-compliance": /vuln|cve|owasp|xss|sqli|injection|csrf|auth|secret|compliance|sast|dast/i,
|
|
4960
|
+
"contract-testing": /contract|pact|openapi|swagger|graphql|schema|endpoint|api/i,
|
|
4961
|
+
// Specialized Testing Domains
|
|
4962
|
+
"visual-accessibility": /screenshot|visual|snapshot|pixel|percy|a11y|aria|wcag|screen.?reader|accessible|contrast/i,
|
|
4963
|
+
"chaos-resilience": /chaos|resilience|fault|inject|blast|recover|latency|failure|stress|load/i,
|
|
4964
|
+
"learning-optimization": /learn|pattern|optim|neural|embedding|vector|memory|adapt|train/i
|
|
4965
|
+
};
|
|
4966
|
+
QE_DOMAIN_LIST = Object.keys(QE_DOMAINS);
|
|
4967
|
+
}
|
|
4968
|
+
});
|
|
4969
|
+
|
|
4691
4970
|
// src/coordination/consensus/model-provider.ts
|
|
4692
4971
|
function buildVerificationPrompt(finding, options = {}) {
|
|
4693
4972
|
const {
|
|
@@ -6683,57 +6962,57 @@ var init_regex_safety_validator = __esm({
|
|
|
6683
6962
|
// native-require:@ruvector/sona
|
|
6684
6963
|
var sona_exports = {};
|
|
6685
6964
|
__export(sona_exports, {
|
|
6686
|
-
DotProductAttention: () =>
|
|
6687
|
-
FlashAttention: () =>
|
|
6688
|
-
HyperbolicAttention: () =>
|
|
6689
|
-
LinearAttention: () =>
|
|
6690
|
-
MoEAttention: () =>
|
|
6691
|
-
MultiHeadAttention: () =>
|
|
6692
|
-
RuvectorLayer: () =>
|
|
6693
|
-
SonaEngine: () =>
|
|
6694
|
-
TensorCompress: () =>
|
|
6965
|
+
DotProductAttention: () => DotProductAttention4,
|
|
6966
|
+
FlashAttention: () => FlashAttention4,
|
|
6967
|
+
HyperbolicAttention: () => HyperbolicAttention4,
|
|
6968
|
+
LinearAttention: () => LinearAttention4,
|
|
6969
|
+
MoEAttention: () => MoEAttention4,
|
|
6970
|
+
MultiHeadAttention: () => MultiHeadAttention4,
|
|
6971
|
+
RuvectorLayer: () => RuvectorLayer4,
|
|
6972
|
+
SonaEngine: () => SonaEngine4,
|
|
6973
|
+
TensorCompress: () => TensorCompress4,
|
|
6695
6974
|
default: () => sona_default,
|
|
6696
|
-
differentiableSearch: () =>
|
|
6697
|
-
getCompressionLevel: () =>
|
|
6698
|
-
hierarchicalForward: () =>
|
|
6699
|
-
init: () =>
|
|
6700
|
-
pipeline: () =>
|
|
6975
|
+
differentiableSearch: () => differentiableSearch4,
|
|
6976
|
+
getCompressionLevel: () => getCompressionLevel4,
|
|
6977
|
+
hierarchicalForward: () => hierarchicalForward4,
|
|
6978
|
+
init: () => init4,
|
|
6979
|
+
pipeline: () => pipeline5
|
|
6701
6980
|
});
|
|
6702
|
-
import { createRequire as
|
|
6703
|
-
var
|
|
6981
|
+
import { createRequire as createRequire4 } from "module";
|
|
6982
|
+
var __require5, __mod4, sona_default, RuvectorLayer4, TensorCompress4, differentiableSearch4, hierarchicalForward4, getCompressionLevel4, init4, FlashAttention4, DotProductAttention4, MultiHeadAttention4, HyperbolicAttention4, LinearAttention4, MoEAttention4, SonaEngine4, pipeline5;
|
|
6704
6983
|
var init_sona = __esm({
|
|
6705
6984
|
"native-require:@ruvector/sona"() {
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
sona_default =
|
|
6985
|
+
__require5 = createRequire4(import.meta.url);
|
|
6986
|
+
__mod4 = __require5("@ruvector/sona");
|
|
6987
|
+
sona_default = __mod4;
|
|
6709
6988
|
({
|
|
6710
6989
|
RuvectorLayer: (
|
|
6711
6990
|
// @ruvector/gnn
|
|
6712
|
-
|
|
6991
|
+
RuvectorLayer4
|
|
6713
6992
|
),
|
|
6714
|
-
TensorCompress:
|
|
6715
|
-
differentiableSearch:
|
|
6716
|
-
hierarchicalForward:
|
|
6717
|
-
getCompressionLevel:
|
|
6718
|
-
init:
|
|
6993
|
+
TensorCompress: TensorCompress4,
|
|
6994
|
+
differentiableSearch: differentiableSearch4,
|
|
6995
|
+
hierarchicalForward: hierarchicalForward4,
|
|
6996
|
+
getCompressionLevel: getCompressionLevel4,
|
|
6997
|
+
init: init4,
|
|
6719
6998
|
FlashAttention: (
|
|
6720
6999
|
// @ruvector/attention
|
|
6721
|
-
|
|
7000
|
+
FlashAttention4
|
|
6722
7001
|
),
|
|
6723
|
-
DotProductAttention:
|
|
6724
|
-
MultiHeadAttention:
|
|
6725
|
-
HyperbolicAttention:
|
|
6726
|
-
LinearAttention:
|
|
6727
|
-
MoEAttention:
|
|
7002
|
+
DotProductAttention: DotProductAttention4,
|
|
7003
|
+
MultiHeadAttention: MultiHeadAttention4,
|
|
7004
|
+
HyperbolicAttention: HyperbolicAttention4,
|
|
7005
|
+
LinearAttention: LinearAttention4,
|
|
7006
|
+
MoEAttention: MoEAttention4,
|
|
6728
7007
|
SonaEngine: (
|
|
6729
7008
|
// @ruvector/sona
|
|
6730
|
-
|
|
7009
|
+
SonaEngine4
|
|
6731
7010
|
),
|
|
6732
7011
|
pipeline: (
|
|
6733
7012
|
// @xenova/transformers
|
|
6734
|
-
|
|
7013
|
+
pipeline5
|
|
6735
7014
|
)
|
|
6736
|
-
} =
|
|
7015
|
+
} = __mod4 || {});
|
|
6737
7016
|
}
|
|
6738
7017
|
});
|
|
6739
7018
|
|
|
@@ -6875,7 +7154,7 @@ var init_sona_wrapper = __esm({
|
|
|
6875
7154
|
qualityThreshold: this.config.qualityThreshold,
|
|
6876
7155
|
enableSimd: this.config.enableSimd
|
|
6877
7156
|
};
|
|
6878
|
-
this.engine =
|
|
7157
|
+
this.engine = SonaEngine4.withConfig(jsConfig);
|
|
6879
7158
|
this.registry = new QESONAPatternRegistry(this.config.maxPatterns ?? 1e4);
|
|
6880
7159
|
}
|
|
6881
7160
|
/**
|
|
@@ -7304,57 +7583,57 @@ var init_sona_wrapper = __esm({
|
|
|
7304
7583
|
// native-require:@ruvector/attention
|
|
7305
7584
|
var attention_exports = {};
|
|
7306
7585
|
__export(attention_exports, {
|
|
7307
|
-
DotProductAttention: () =>
|
|
7308
|
-
FlashAttention: () =>
|
|
7309
|
-
HyperbolicAttention: () =>
|
|
7310
|
-
LinearAttention: () =>
|
|
7311
|
-
MoEAttention: () =>
|
|
7312
|
-
MultiHeadAttention: () =>
|
|
7313
|
-
RuvectorLayer: () =>
|
|
7314
|
-
SonaEngine: () =>
|
|
7315
|
-
TensorCompress: () =>
|
|
7586
|
+
DotProductAttention: () => DotProductAttention5,
|
|
7587
|
+
FlashAttention: () => FlashAttention5,
|
|
7588
|
+
HyperbolicAttention: () => HyperbolicAttention5,
|
|
7589
|
+
LinearAttention: () => LinearAttention5,
|
|
7590
|
+
MoEAttention: () => MoEAttention5,
|
|
7591
|
+
MultiHeadAttention: () => MultiHeadAttention5,
|
|
7592
|
+
RuvectorLayer: () => RuvectorLayer5,
|
|
7593
|
+
SonaEngine: () => SonaEngine5,
|
|
7594
|
+
TensorCompress: () => TensorCompress5,
|
|
7316
7595
|
default: () => attention_default,
|
|
7317
|
-
differentiableSearch: () =>
|
|
7318
|
-
getCompressionLevel: () =>
|
|
7319
|
-
hierarchicalForward: () =>
|
|
7320
|
-
init: () =>
|
|
7321
|
-
pipeline: () =>
|
|
7596
|
+
differentiableSearch: () => differentiableSearch5,
|
|
7597
|
+
getCompressionLevel: () => getCompressionLevel5,
|
|
7598
|
+
hierarchicalForward: () => hierarchicalForward5,
|
|
7599
|
+
init: () => init5,
|
|
7600
|
+
pipeline: () => pipeline6
|
|
7322
7601
|
});
|
|
7323
|
-
import { createRequire as
|
|
7324
|
-
var
|
|
7602
|
+
import { createRequire as createRequire5 } from "module";
|
|
7603
|
+
var __require6, __mod5, attention_default, RuvectorLayer5, TensorCompress5, differentiableSearch5, hierarchicalForward5, getCompressionLevel5, init5, FlashAttention5, DotProductAttention5, MultiHeadAttention5, HyperbolicAttention5, LinearAttention5, MoEAttention5, SonaEngine5, pipeline6;
|
|
7325
7604
|
var init_attention = __esm({
|
|
7326
7605
|
"native-require:@ruvector/attention"() {
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
attention_default =
|
|
7606
|
+
__require6 = createRequire5(import.meta.url);
|
|
7607
|
+
__mod5 = __require6("@ruvector/attention");
|
|
7608
|
+
attention_default = __mod5;
|
|
7330
7609
|
({
|
|
7331
7610
|
RuvectorLayer: (
|
|
7332
7611
|
// @ruvector/gnn
|
|
7333
|
-
|
|
7612
|
+
RuvectorLayer5
|
|
7334
7613
|
),
|
|
7335
|
-
TensorCompress:
|
|
7336
|
-
differentiableSearch:
|
|
7337
|
-
hierarchicalForward:
|
|
7338
|
-
getCompressionLevel:
|
|
7339
|
-
init:
|
|
7614
|
+
TensorCompress: TensorCompress5,
|
|
7615
|
+
differentiableSearch: differentiableSearch5,
|
|
7616
|
+
hierarchicalForward: hierarchicalForward5,
|
|
7617
|
+
getCompressionLevel: getCompressionLevel5,
|
|
7618
|
+
init: init5,
|
|
7340
7619
|
FlashAttention: (
|
|
7341
7620
|
// @ruvector/attention
|
|
7342
|
-
|
|
7621
|
+
FlashAttention5
|
|
7343
7622
|
),
|
|
7344
|
-
DotProductAttention:
|
|
7345
|
-
MultiHeadAttention:
|
|
7346
|
-
HyperbolicAttention:
|
|
7347
|
-
LinearAttention:
|
|
7348
|
-
MoEAttention:
|
|
7623
|
+
DotProductAttention: DotProductAttention5,
|
|
7624
|
+
MultiHeadAttention: MultiHeadAttention5,
|
|
7625
|
+
HyperbolicAttention: HyperbolicAttention5,
|
|
7626
|
+
LinearAttention: LinearAttention5,
|
|
7627
|
+
MoEAttention: MoEAttention5,
|
|
7349
7628
|
SonaEngine: (
|
|
7350
7629
|
// @ruvector/sona
|
|
7351
|
-
|
|
7630
|
+
SonaEngine5
|
|
7352
7631
|
),
|
|
7353
7632
|
pipeline: (
|
|
7354
7633
|
// @xenova/transformers
|
|
7355
|
-
|
|
7634
|
+
pipeline6
|
|
7356
7635
|
)
|
|
7357
|
-
} =
|
|
7636
|
+
} = __mod5 || {});
|
|
7358
7637
|
}
|
|
7359
7638
|
});
|
|
7360
7639
|
|
|
@@ -7512,23 +7791,23 @@ var init_attention_wrapper = __esm({
|
|
|
7512
7791
|
static create(config) {
|
|
7513
7792
|
switch (config.strategy) {
|
|
7514
7793
|
case "flash":
|
|
7515
|
-
return new
|
|
7794
|
+
return new FlashAttention5(config.dim, config.blockSize);
|
|
7516
7795
|
case "dot-product":
|
|
7517
|
-
return new
|
|
7796
|
+
return new DotProductAttention5(config.dim);
|
|
7518
7797
|
case "multi-head":
|
|
7519
|
-
return new
|
|
7798
|
+
return new MultiHeadAttention5(config.dim, config.numHeads ?? 8);
|
|
7520
7799
|
case "hyperbolic":
|
|
7521
|
-
return new
|
|
7800
|
+
return new HyperbolicAttention5(config.dim, config.curvature);
|
|
7522
7801
|
case "linear":
|
|
7523
|
-
return new
|
|
7802
|
+
return new LinearAttention5(config.dim, config.features);
|
|
7524
7803
|
case "moe":
|
|
7525
|
-
return
|
|
7804
|
+
return MoEAttention5.simple(
|
|
7526
7805
|
config.dim,
|
|
7527
7806
|
config.moeConfig?.numExperts ?? 8,
|
|
7528
7807
|
config.moeConfig?.topK ?? 2
|
|
7529
7808
|
);
|
|
7530
7809
|
default:
|
|
7531
|
-
return new
|
|
7810
|
+
return new FlashAttention5(config.dim, config.blockSize);
|
|
7532
7811
|
}
|
|
7533
7812
|
}
|
|
7534
7813
|
};
|
|
@@ -7585,20 +7864,20 @@ var init_attention_wrapper = __esm({
|
|
|
7585
7864
|
const keys = this.splitMatrix(K58, seqLen, dim);
|
|
7586
7865
|
const values = this.splitMatrix(V45, seqLen, dim);
|
|
7587
7866
|
let output;
|
|
7588
|
-
if (this.attention instanceof
|
|
7867
|
+
if (this.attention instanceof FlashAttention5) {
|
|
7589
7868
|
output = this.attention.compute(query, keys, values);
|
|
7590
|
-
} else if (this.attention instanceof
|
|
7869
|
+
} else if (this.attention instanceof DotProductAttention5) {
|
|
7591
7870
|
output = this.attention.compute(query, keys, values);
|
|
7592
|
-
} else if (this.attention instanceof
|
|
7871
|
+
} else if (this.attention instanceof MultiHeadAttention5) {
|
|
7593
7872
|
output = this.attention.compute(query, keys, values);
|
|
7594
|
-
} else if (this.attention instanceof
|
|
7873
|
+
} else if (this.attention instanceof HyperbolicAttention5) {
|
|
7595
7874
|
output = this.attention.compute(query, keys, values);
|
|
7596
|
-
} else if (this.attention instanceof
|
|
7875
|
+
} else if (this.attention instanceof LinearAttention5) {
|
|
7597
7876
|
output = this.attention.compute(query, keys, values);
|
|
7598
|
-
} else if (this.attention instanceof
|
|
7877
|
+
} else if (this.attention instanceof MoEAttention5) {
|
|
7599
7878
|
output = this.attention.compute(query, keys, values);
|
|
7600
7879
|
} else {
|
|
7601
|
-
const fallback = new
|
|
7880
|
+
const fallback = new FlashAttention5(this.config.dim);
|
|
7602
7881
|
output = fallback.compute(query, keys, values);
|
|
7603
7882
|
}
|
|
7604
7883
|
const endTime = performance.now();
|
|
@@ -7843,77 +8122,20 @@ var init_attention_wrapper = __esm({
|
|
|
7843
8122
|
}
|
|
7844
8123
|
});
|
|
7845
8124
|
|
|
7846
|
-
// native-require:@ruvector/gnn
|
|
7847
|
-
var gnn_exports = {};
|
|
7848
|
-
__export(gnn_exports, {
|
|
7849
|
-
DotProductAttention: () => DotProductAttention5,
|
|
7850
|
-
FlashAttention: () => FlashAttention5,
|
|
7851
|
-
HyperbolicAttention: () => HyperbolicAttention5,
|
|
7852
|
-
LinearAttention: () => LinearAttention5,
|
|
7853
|
-
MoEAttention: () => MoEAttention5,
|
|
7854
|
-
MultiHeadAttention: () => MultiHeadAttention5,
|
|
7855
|
-
RuvectorLayer: () => RuvectorLayer5,
|
|
7856
|
-
SonaEngine: () => SonaEngine5,
|
|
7857
|
-
TensorCompress: () => TensorCompress5,
|
|
7858
|
-
default: () => gnn_default,
|
|
7859
|
-
differentiableSearch: () => differentiableSearch5,
|
|
7860
|
-
getCompressionLevel: () => getCompressionLevel5,
|
|
7861
|
-
hierarchicalForward: () => hierarchicalForward5,
|
|
7862
|
-
init: () => init5,
|
|
7863
|
-
pipeline: () => pipeline6
|
|
7864
|
-
});
|
|
7865
|
-
import { createRequire as createRequire5 } from "module";
|
|
7866
|
-
var __require6, __mod5, gnn_default, RuvectorLayer5, TensorCompress5, differentiableSearch5, hierarchicalForward5, getCompressionLevel5, init5, FlashAttention5, DotProductAttention5, MultiHeadAttention5, HyperbolicAttention5, LinearAttention5, MoEAttention5, SonaEngine5, pipeline6;
|
|
7867
|
-
var init_gnn = __esm({
|
|
7868
|
-
"native-require:@ruvector/gnn"() {
|
|
7869
|
-
__require6 = createRequire5(import.meta.url);
|
|
7870
|
-
__mod5 = __require6("@ruvector/gnn");
|
|
7871
|
-
gnn_default = __mod5;
|
|
7872
|
-
({
|
|
7873
|
-
RuvectorLayer: (
|
|
7874
|
-
// @ruvector/gnn
|
|
7875
|
-
RuvectorLayer5
|
|
7876
|
-
),
|
|
7877
|
-
TensorCompress: TensorCompress5,
|
|
7878
|
-
differentiableSearch: differentiableSearch5,
|
|
7879
|
-
hierarchicalForward: hierarchicalForward5,
|
|
7880
|
-
getCompressionLevel: getCompressionLevel5,
|
|
7881
|
-
init: init5,
|
|
7882
|
-
FlashAttention: (
|
|
7883
|
-
// @ruvector/attention
|
|
7884
|
-
FlashAttention5
|
|
7885
|
-
),
|
|
7886
|
-
DotProductAttention: DotProductAttention5,
|
|
7887
|
-
MultiHeadAttention: MultiHeadAttention5,
|
|
7888
|
-
HyperbolicAttention: HyperbolicAttention5,
|
|
7889
|
-
LinearAttention: LinearAttention5,
|
|
7890
|
-
MoEAttention: MoEAttention5,
|
|
7891
|
-
SonaEngine: (
|
|
7892
|
-
// @ruvector/sona
|
|
7893
|
-
SonaEngine5
|
|
7894
|
-
),
|
|
7895
|
-
pipeline: (
|
|
7896
|
-
// @xenova/transformers
|
|
7897
|
-
pipeline6
|
|
7898
|
-
)
|
|
7899
|
-
} = __mod5 || {});
|
|
7900
|
-
}
|
|
7901
|
-
});
|
|
7902
|
-
|
|
7903
8125
|
// src/integrations/ruvector/gnn-wrapper.ts
|
|
7904
8126
|
var gnn_wrapper_exports = {};
|
|
7905
8127
|
__export(gnn_wrapper_exports, {
|
|
7906
8128
|
GNNLayerFactory: () => GNNLayerFactory,
|
|
7907
8129
|
QEGNNEmbeddingIndex: () => QEGNNEmbeddingIndex,
|
|
7908
8130
|
QEGNNIndexFactory: () => QEGNNIndexFactory,
|
|
7909
|
-
RuvectorLayer: () =>
|
|
7910
|
-
TensorCompress: () =>
|
|
8131
|
+
RuvectorLayer: () => RuvectorLayer2,
|
|
8132
|
+
TensorCompress: () => TensorCompress2,
|
|
7911
8133
|
TensorCompressionFactory: () => TensorCompressionFactory,
|
|
7912
8134
|
batchDifferentiableSearch: () => batchDifferentiableSearch,
|
|
7913
|
-
differentiableSearch: () =>
|
|
7914
|
-
getCompressionLevel: () =>
|
|
7915
|
-
hierarchicalForward: () =>
|
|
7916
|
-
init: () =>
|
|
8135
|
+
differentiableSearch: () => differentiableSearch2,
|
|
8136
|
+
getCompressionLevel: () => getCompressionLevel2,
|
|
8137
|
+
hierarchicalForward: () => hierarchicalForward2,
|
|
8138
|
+
init: () => init2,
|
|
7917
8139
|
initGNN: () => initGNN,
|
|
7918
8140
|
toFloat32Array: () => toFloat32Array2,
|
|
7919
8141
|
toIEmbedding: () => toIEmbedding,
|
|
@@ -7921,7 +8143,7 @@ __export(gnn_wrapper_exports, {
|
|
|
7921
8143
|
});
|
|
7922
8144
|
function initGNN() {
|
|
7923
8145
|
if (!gnnInitialized) {
|
|
7924
|
-
const result =
|
|
8146
|
+
const result = init2();
|
|
7925
8147
|
gnnInitialized = true;
|
|
7926
8148
|
return result;
|
|
7927
8149
|
}
|
|
@@ -7962,7 +8184,7 @@ function batchDifferentiableSearch(queries, candidateEmbeddings, k68, temperatur
|
|
|
7962
8184
|
);
|
|
7963
8185
|
for (const query of queries) {
|
|
7964
8186
|
const queryFloat32 = query instanceof Float32Array ? query : new Float32Array(query);
|
|
7965
|
-
const result =
|
|
8187
|
+
const result = differentiableSearch2(
|
|
7966
8188
|
queryFloat32,
|
|
7967
8189
|
candidatesFloat32,
|
|
7968
8190
|
k68,
|
|
@@ -8000,7 +8222,7 @@ var init_gnn_wrapper = __esm({
|
|
|
8000
8222
|
this.indexes = /* @__PURE__ */ new Map();
|
|
8001
8223
|
this.nextId = /* @__PURE__ */ new Map();
|
|
8002
8224
|
this.gnnLayers = /* @__PURE__ */ new Map();
|
|
8003
|
-
this.compressor = new
|
|
8225
|
+
this.compressor = new TensorCompress2();
|
|
8004
8226
|
initGNN();
|
|
8005
8227
|
}
|
|
8006
8228
|
/**
|
|
@@ -8061,7 +8283,7 @@ var init_gnn_wrapper = __esm({
|
|
|
8061
8283
|
}
|
|
8062
8284
|
const queryFloat32 = new Float32Array(query.vector);
|
|
8063
8285
|
const candidateFloat32s = candidates.map((c70) => new Float32Array(c70.vector));
|
|
8064
|
-
const result =
|
|
8286
|
+
const result = differentiableSearch2(
|
|
8065
8287
|
queryFloat32,
|
|
8066
8288
|
candidateFloat32s,
|
|
8067
8289
|
Math.min(k68, candidates.length),
|
|
@@ -8084,7 +8306,7 @@ var init_gnn_wrapper = __esm({
|
|
|
8084
8306
|
const candidateVectors = candidates.map(
|
|
8085
8307
|
(c70) => new Float32Array(c70.embedding.vector)
|
|
8086
8308
|
);
|
|
8087
|
-
const result =
|
|
8309
|
+
const result = differentiableSearch2(
|
|
8088
8310
|
queryVector,
|
|
8089
8311
|
candidateVectors,
|
|
8090
8312
|
Math.min(k68, candidates.length),
|
|
@@ -8105,7 +8327,7 @@ var init_gnn_wrapper = __esm({
|
|
|
8105
8327
|
if (!this.gnnLayers.has(layerKey)) {
|
|
8106
8328
|
const layers = [];
|
|
8107
8329
|
for (const config of layerConfigs) {
|
|
8108
|
-
const layer2 = new
|
|
8330
|
+
const layer2 = new RuvectorLayer2(
|
|
8109
8331
|
config.inputDim,
|
|
8110
8332
|
config.hiddenDim,
|
|
8111
8333
|
config.heads,
|
|
@@ -8121,7 +8343,7 @@ var init_gnn_wrapper = __esm({
|
|
|
8121
8343
|
const layerEmbeddingsFloat32 = layerEmbeddings.map(
|
|
8122
8344
|
(layer2) => layer2.map((emb) => new Float32Array(emb))
|
|
8123
8345
|
);
|
|
8124
|
-
return Array.from(
|
|
8346
|
+
return Array.from(hierarchicalForward2(
|
|
8125
8347
|
queryFloat32,
|
|
8126
8348
|
layerEmbeddingsFloat32,
|
|
8127
8349
|
[gnnLayerJson]
|
|
@@ -8136,7 +8358,7 @@ var init_gnn_wrapper = __esm({
|
|
|
8136
8358
|
* - Cold data (low access): product quantization
|
|
8137
8359
|
*/
|
|
8138
8360
|
compressEmbedding(embedding, accessFreq) {
|
|
8139
|
-
const rawLevel =
|
|
8361
|
+
const rawLevel = getCompressionLevel2(accessFreq);
|
|
8140
8362
|
const levelMap = {
|
|
8141
8363
|
"none": "none",
|
|
8142
8364
|
"half": "half",
|
|
@@ -8182,7 +8404,7 @@ var init_gnn_wrapper = __esm({
|
|
|
8182
8404
|
* Get compression level for access frequency
|
|
8183
8405
|
*/
|
|
8184
8406
|
getCompressionLevelForFrequency(accessFreq) {
|
|
8185
|
-
return
|
|
8407
|
+
return getCompressionLevel2(accessFreq);
|
|
8186
8408
|
}
|
|
8187
8409
|
/**
|
|
8188
8410
|
* Get index statistics
|
|
@@ -8326,7 +8548,7 @@ var init_gnn_wrapper = __esm({
|
|
|
8326
8548
|
static getLayer(config) {
|
|
8327
8549
|
const key = `${config.inputDim}-${config.hiddenDim}-${config.heads}-${config.dropout}`;
|
|
8328
8550
|
if (!this.layers.has(key)) {
|
|
8329
|
-
const layer = new
|
|
8551
|
+
const layer = new RuvectorLayer2(
|
|
8330
8552
|
config.inputDim,
|
|
8331
8553
|
config.hiddenDim,
|
|
8332
8554
|
config.heads,
|
|
@@ -8340,7 +8562,7 @@ var init_gnn_wrapper = __esm({
|
|
|
8340
8562
|
* Create layer from JSON
|
|
8341
8563
|
*/
|
|
8342
8564
|
static layerFromJson(json) {
|
|
8343
|
-
return
|
|
8565
|
+
return RuvectorLayer2.fromJson(json);
|
|
8344
8566
|
}
|
|
8345
8567
|
/**
|
|
8346
8568
|
* Clear cached layers
|
|
@@ -8350,7 +8572,7 @@ var init_gnn_wrapper = __esm({
|
|
|
8350
8572
|
}
|
|
8351
8573
|
};
|
|
8352
8574
|
TensorCompressionFactory = class {
|
|
8353
|
-
static compressor = new
|
|
8575
|
+
static compressor = new TensorCompress2();
|
|
8354
8576
|
/**
|
|
8355
8577
|
* Compress tensor with specific level
|
|
8356
8578
|
*/
|
|
@@ -8376,7 +8598,7 @@ var init_gnn_wrapper = __esm({
|
|
|
8376
8598
|
* Get compression level for frequency
|
|
8377
8599
|
*/
|
|
8378
8600
|
static getLevel(accessFreq) {
|
|
8379
|
-
return
|
|
8601
|
+
return getCompressionLevel2(accessFreq);
|
|
8380
8602
|
}
|
|
8381
8603
|
};
|
|
8382
8604
|
}
|
|
@@ -8393,14 +8615,14 @@ __export(wrappers_exports, {
|
|
|
8393
8615
|
QE_FLASH_ATTENTION_CONFIG: () => QE_FLASH_ATTENTION_CONFIG,
|
|
8394
8616
|
QE_PERFORMANCE_TARGETS: () => QE_PERFORMANCE_TARGETS,
|
|
8395
8617
|
QE_SONA_CONFIG: () => QE_SONA_CONFIG,
|
|
8396
|
-
RuvectorDotProductAttention: () =>
|
|
8397
|
-
RuvectorFlashAttention: () =>
|
|
8398
|
-
RuvectorHyperbolicAttention: () =>
|
|
8399
|
-
RuvectorLayer: () =>
|
|
8400
|
-
RuvectorLinearAttention: () =>
|
|
8401
|
-
RuvectorMoEAttention: () =>
|
|
8402
|
-
RuvectorMultiHeadAttention: () =>
|
|
8403
|
-
TensorCompress: () =>
|
|
8618
|
+
RuvectorDotProductAttention: () => DotProductAttention5,
|
|
8619
|
+
RuvectorFlashAttention: () => FlashAttention5,
|
|
8620
|
+
RuvectorHyperbolicAttention: () => HyperbolicAttention5,
|
|
8621
|
+
RuvectorLayer: () => RuvectorLayer2,
|
|
8622
|
+
RuvectorLinearAttention: () => LinearAttention5,
|
|
8623
|
+
RuvectorMoEAttention: () => MoEAttention5,
|
|
8624
|
+
RuvectorMultiHeadAttention: () => MultiHeadAttention5,
|
|
8625
|
+
TensorCompress: () => TensorCompress2,
|
|
8404
8626
|
TensorCompressionFactory: () => TensorCompressionFactory,
|
|
8405
8627
|
batchComputeAttention: () => batchComputeAttention,
|
|
8406
8628
|
batchDifferentiableSearch: () => batchDifferentiableSearch,
|
|
@@ -8408,14 +8630,14 @@ __export(wrappers_exports, {
|
|
|
8408
8630
|
createDomainQESONA: () => createDomainQESONA,
|
|
8409
8631
|
createQEFlashAttention: () => createQEFlashAttention,
|
|
8410
8632
|
createQESONA: () => createQESONA,
|
|
8411
|
-
differentiableSearch: () =>
|
|
8412
|
-
getCompressionLevel: () =>
|
|
8633
|
+
differentiableSearch: () => differentiableSearch2,
|
|
8634
|
+
getCompressionLevel: () => getCompressionLevel2,
|
|
8413
8635
|
getOptimalBlockConfig: () => getOptimalBlockConfig,
|
|
8414
8636
|
getQEFlashAttentionConfig: () => getQEFlashAttentionConfig,
|
|
8415
8637
|
getRuvectorPackageVersions: () => getRuvectorPackageVersions,
|
|
8416
8638
|
getWorkloadTypes: () => getWorkloadTypes,
|
|
8417
|
-
hierarchicalForward: () =>
|
|
8418
|
-
init: () =>
|
|
8639
|
+
hierarchicalForward: () => hierarchicalForward2,
|
|
8640
|
+
init: () => init2,
|
|
8419
8641
|
initAllRuvectorPackages: () => initAllRuvectorPackages,
|
|
8420
8642
|
initGNN: () => initGNN,
|
|
8421
8643
|
toFloat32Array: () => toFloat32Array,
|
|
@@ -8619,7 +8841,7 @@ var init_hnsw_index = __esm({
|
|
|
8619
8841
|
if (!this.initialized) {
|
|
8620
8842
|
await this.initialize();
|
|
8621
8843
|
}
|
|
8622
|
-
this.validateVector(vector);
|
|
8844
|
+
vector = this.validateVector(vector);
|
|
8623
8845
|
if (this.keyToLabel.has(key)) {
|
|
8624
8846
|
await this.delete(key);
|
|
8625
8847
|
}
|
|
@@ -8648,7 +8870,7 @@ var init_hnsw_index = __esm({
|
|
|
8648
8870
|
if (!this.initialized) {
|
|
8649
8871
|
await this.initialize();
|
|
8650
8872
|
}
|
|
8651
|
-
this.validateVector(query);
|
|
8873
|
+
query = this.validateVector(query);
|
|
8652
8874
|
const startTime = performance.now();
|
|
8653
8875
|
const results = this.stats.vectorCount > 0 ? this.searchRuvector(query, k68) : [];
|
|
8654
8876
|
const endTime = performance.now();
|
|
@@ -8773,17 +8995,46 @@ var init_hnsw_index = __esm({
|
|
|
8773
8995
|
// ============================================================================
|
|
8774
8996
|
// Private Helper Methods
|
|
8775
8997
|
// ============================================================================
|
|
8998
|
+
/**
|
|
8999
|
+
* Validate and auto-resize vectors to match HNSW configured dimensions.
|
|
9000
|
+
* Fix #279: Prevents Rust WASM panic when RealEmbeddings (768-dim) are
|
|
9001
|
+
* passed to a 128-dim HNSW index.
|
|
9002
|
+
*/
|
|
8776
9003
|
validateVector(vector) {
|
|
8777
9004
|
if (vector.length !== this.config.dimensions) {
|
|
8778
|
-
|
|
8779
|
-
`Vector dimension mismatch: expected ${this.config.dimensions}, got ${vector.length}`
|
|
8780
|
-
);
|
|
9005
|
+
return this.resizeVector(vector, this.config.dimensions);
|
|
8781
9006
|
}
|
|
8782
9007
|
for (let i58 = 0; i58 < vector.length; i58++) {
|
|
8783
9008
|
if (!Number.isFinite(vector[i58])) {
|
|
8784
9009
|
throw new Error(`Invalid vector value at index ${i58}: ${vector[i58]}`);
|
|
8785
9010
|
}
|
|
8786
9011
|
}
|
|
9012
|
+
return vector;
|
|
9013
|
+
}
|
|
9014
|
+
/**
|
|
9015
|
+
* Resize vector to target dimensions using averaging (shrink) or zero-padding (grow).
|
|
9016
|
+
*/
|
|
9017
|
+
resizeVector(vector, targetDim) {
|
|
9018
|
+
if (vector.length === targetDim) return vector;
|
|
9019
|
+
if (vector.length > targetDim) {
|
|
9020
|
+
const result2 = new Array(targetDim).fill(0);
|
|
9021
|
+
const ratio = vector.length / targetDim;
|
|
9022
|
+
for (let i58 = 0; i58 < targetDim; i58++) {
|
|
9023
|
+
const start = Math.floor(i58 * ratio);
|
|
9024
|
+
const end = Math.floor((i58 + 1) * ratio);
|
|
9025
|
+
let sum = 0;
|
|
9026
|
+
for (let j52 = start; j52 < end; j52++) {
|
|
9027
|
+
sum += vector[j52];
|
|
9028
|
+
}
|
|
9029
|
+
result2[i58] = sum / (end - start);
|
|
9030
|
+
}
|
|
9031
|
+
return result2;
|
|
9032
|
+
}
|
|
9033
|
+
const result = new Array(targetDim).fill(0);
|
|
9034
|
+
for (let i58 = 0; i58 < vector.length; i58++) {
|
|
9035
|
+
result[i58] = vector[i58];
|
|
9036
|
+
}
|
|
9037
|
+
return result;
|
|
8787
9038
|
}
|
|
8788
9039
|
buildKey(key) {
|
|
8789
9040
|
return `${this.config.namespace}:${key}`;
|
|
@@ -14095,120 +14346,6 @@ var init_dream = __esm({
|
|
|
14095
14346
|
}
|
|
14096
14347
|
});
|
|
14097
14348
|
|
|
14098
|
-
// src/learning/qe-patterns.ts
|
|
14099
|
-
function detectQEDomain(taskDescription) {
|
|
14100
|
-
for (const [domain, pattern] of Object.entries(QE_DOMAINS)) {
|
|
14101
|
-
if (pattern.test(taskDescription)) {
|
|
14102
|
-
return domain;
|
|
14103
|
-
}
|
|
14104
|
-
}
|
|
14105
|
-
return null;
|
|
14106
|
-
}
|
|
14107
|
-
function detectQEDomains(taskDescription) {
|
|
14108
|
-
const detected = [];
|
|
14109
|
-
for (const [domain, pattern] of Object.entries(QE_DOMAINS)) {
|
|
14110
|
-
if (pattern.test(taskDescription)) {
|
|
14111
|
-
detected.push(domain);
|
|
14112
|
-
}
|
|
14113
|
-
}
|
|
14114
|
-
return detected;
|
|
14115
|
-
}
|
|
14116
|
-
function mapQEDomainToAQE(qeDomain) {
|
|
14117
|
-
return qeDomain;
|
|
14118
|
-
}
|
|
14119
|
-
function calculateQualityScore(pattern) {
|
|
14120
|
-
const usageScore = Math.min(pattern.usageCount / 100, 1);
|
|
14121
|
-
return pattern.confidence * 0.3 + usageScore * 0.2 + pattern.successRate * 0.5;
|
|
14122
|
-
}
|
|
14123
|
-
function shouldPromotePattern(pattern, coherenceEnergy, coherenceThreshold = 0.4) {
|
|
14124
|
-
const meetsUsageCriteria = pattern.tier === "short-term" && pattern.successfulUses >= 3;
|
|
14125
|
-
const meetsQualityCriteria = pattern.successRate >= 0.7 && pattern.confidence >= 0.6;
|
|
14126
|
-
const meetsCoherenceCriteria = coherenceEnergy === void 0 || coherenceEnergy < coherenceThreshold;
|
|
14127
|
-
let blockReason;
|
|
14128
|
-
if (!meetsUsageCriteria) {
|
|
14129
|
-
blockReason = "insufficient_usage";
|
|
14130
|
-
} else if (!meetsQualityCriteria) {
|
|
14131
|
-
blockReason = "low_quality";
|
|
14132
|
-
} else if (!meetsCoherenceCriteria) {
|
|
14133
|
-
blockReason = "coherence_violation";
|
|
14134
|
-
}
|
|
14135
|
-
return {
|
|
14136
|
-
meetsUsageCriteria,
|
|
14137
|
-
meetsQualityCriteria,
|
|
14138
|
-
meetsCoherenceCriteria,
|
|
14139
|
-
blockReason
|
|
14140
|
-
};
|
|
14141
|
-
}
|
|
14142
|
-
function validateQEPattern(pattern) {
|
|
14143
|
-
const errors = [];
|
|
14144
|
-
if (!pattern.id) errors.push("Pattern ID is required");
|
|
14145
|
-
if (!pattern.patternType) errors.push("Pattern type is required");
|
|
14146
|
-
if (!pattern.qeDomain) errors.push("QE domain is required");
|
|
14147
|
-
if (!pattern.name) errors.push("Pattern name is required");
|
|
14148
|
-
if (!pattern.template?.content) errors.push("Template content is required");
|
|
14149
|
-
if (pattern.confidence !== void 0 && (pattern.confidence < 0 || pattern.confidence > 1)) {
|
|
14150
|
-
errors.push("Confidence must be between 0 and 1");
|
|
14151
|
-
}
|
|
14152
|
-
if (pattern.successRate !== void 0 && (pattern.successRate < 0 || pattern.successRate > 1)) {
|
|
14153
|
-
errors.push("Success rate must be between 0 and 1");
|
|
14154
|
-
}
|
|
14155
|
-
if (pattern.template?.variables) {
|
|
14156
|
-
const variableNames = /* @__PURE__ */ new Set();
|
|
14157
|
-
for (const variable of pattern.template.variables) {
|
|
14158
|
-
if (variableNames.has(variable.name)) {
|
|
14159
|
-
errors.push(`Duplicate variable name: ${variable.name}`);
|
|
14160
|
-
}
|
|
14161
|
-
variableNames.add(variable.name);
|
|
14162
|
-
if (!pattern.template.content.includes(`{{${variable.name}}}`)) {
|
|
14163
|
-
errors.push(
|
|
14164
|
-
`Variable ${variable.name} not referenced in template`
|
|
14165
|
-
);
|
|
14166
|
-
}
|
|
14167
|
-
}
|
|
14168
|
-
}
|
|
14169
|
-
return { valid: errors.length === 0, errors };
|
|
14170
|
-
}
|
|
14171
|
-
function applyPatternTemplate(template, variables) {
|
|
14172
|
-
let content = template.content;
|
|
14173
|
-
for (const variable of template.variables) {
|
|
14174
|
-
const value = variables[variable.name] ?? variable.defaultValue;
|
|
14175
|
-
if (variable.required && value === void 0) {
|
|
14176
|
-
throw new Error(`Required variable ${variable.name} not provided`);
|
|
14177
|
-
}
|
|
14178
|
-
if (value !== void 0) {
|
|
14179
|
-
const placeholder = `{{${variable.name}}}`;
|
|
14180
|
-
const stringValue = typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
14181
|
-
content = content.split(placeholder).join(stringValue);
|
|
14182
|
-
}
|
|
14183
|
-
}
|
|
14184
|
-
return content;
|
|
14185
|
-
}
|
|
14186
|
-
var QE_DOMAINS, QE_DOMAIN_LIST;
|
|
14187
|
-
var init_qe_patterns = __esm({
|
|
14188
|
-
"src/learning/qe-patterns.ts"() {
|
|
14189
|
-
"use strict";
|
|
14190
|
-
QE_DOMAINS = {
|
|
14191
|
-
// Core Testing Domains
|
|
14192
|
-
"test-generation": /test|spec|describe|it\(|expect|assert|mock|stub|fixture|tdd|bdd/i,
|
|
14193
|
-
"test-execution": /run|execute|parallel|retry|flaky|timeout|worker|orchestrat/i,
|
|
14194
|
-
"coverage-analysis": /coverage|branch|line|uncovered|gap|untested|percentage|sublinear/i,
|
|
14195
|
-
// Quality Domains
|
|
14196
|
-
"quality-assessment": /quality|gate|deploy|readiness|metric|threshold|sla|score/i,
|
|
14197
|
-
"defect-intelligence": /defect|bug|predict|root.?cause|regression|failure|incident/i,
|
|
14198
|
-
"requirements-validation": /requirement|bdd|gherkin|testabil|accept|criteri|scenario/i,
|
|
14199
|
-
// Analysis Domains
|
|
14200
|
-
"code-intelligence": /semantic|knowledge|graph|ast|symbol|reference|impact|depend/i,
|
|
14201
|
-
"security-compliance": /vuln|cve|owasp|xss|sqli|injection|csrf|auth|secret|compliance|sast|dast/i,
|
|
14202
|
-
"contract-testing": /contract|pact|openapi|swagger|graphql|schema|endpoint|api/i,
|
|
14203
|
-
// Specialized Testing Domains
|
|
14204
|
-
"visual-accessibility": /screenshot|visual|snapshot|pixel|percy|a11y|aria|wcag|screen.?reader|accessible|contrast/i,
|
|
14205
|
-
"chaos-resilience": /chaos|resilience|fault|inject|blast|recover|latency|failure|stress|load/i,
|
|
14206
|
-
"learning-optimization": /learn|pattern|optim|neural|embedding|vector|memory|adapt|train/i
|
|
14207
|
-
};
|
|
14208
|
-
QE_DOMAIN_LIST = Object.keys(QE_DOMAINS);
|
|
14209
|
-
}
|
|
14210
|
-
});
|
|
14211
|
-
|
|
14212
14349
|
// src/learning/pattern-store.ts
|
|
14213
14350
|
function createPatternStore(memory, config) {
|
|
14214
14351
|
return new PatternStore(memory, config);
|
|
@@ -25341,7 +25478,7 @@ var JestVitestGenerator = class extends BaseTestGenerator {
|
|
|
25341
25478
|
* Generate complete test file from analysis
|
|
25342
25479
|
*/
|
|
25343
25480
|
generateTests(context2) {
|
|
25344
|
-
const { moduleName, importPath, testType, patterns, analysis } = context2;
|
|
25481
|
+
const { moduleName, importPath, testType, patterns, analysis, dependencies } = context2;
|
|
25345
25482
|
if (!analysis || analysis.functions.length === 0 && analysis.classes.length === 0) {
|
|
25346
25483
|
return this.generateStubTests(context2);
|
|
25347
25484
|
}
|
|
@@ -25351,8 +25488,23 @@ var JestVitestGenerator = class extends BaseTestGenerator {
|
|
|
25351
25488
|
const mockImport = this.framework === "vitest" ? ", vi" : "";
|
|
25352
25489
|
let testCode = `${patternComment}import { describe, it, expect, beforeEach${mockImport} } from '${this.framework}';
|
|
25353
25490
|
${importStatement}
|
|
25354
|
-
|
|
25355
25491
|
`;
|
|
25492
|
+
if (dependencies && dependencies.imports.length > 0) {
|
|
25493
|
+
const mockFn = this.framework === "vitest" ? "vi.fn()" : "jest.fn()";
|
|
25494
|
+
testCode += `
|
|
25495
|
+
// Auto-generated mocks from Knowledge Graph dependency analysis
|
|
25496
|
+
`;
|
|
25497
|
+
for (const dep of dependencies.imports.slice(0, 10)) {
|
|
25498
|
+
const depName = dep.split("/").pop()?.replace(/[^a-zA-Z0-9_]/g, "_") || dep;
|
|
25499
|
+
testCode += `${this.framework === "vitest" ? "vi" : "jest"}.mock('${dep}', () => ({ default: ${mockFn} }));
|
|
25500
|
+
`;
|
|
25501
|
+
}
|
|
25502
|
+
testCode += `
|
|
25503
|
+
`;
|
|
25504
|
+
} else {
|
|
25505
|
+
testCode += `
|
|
25506
|
+
`;
|
|
25507
|
+
}
|
|
25356
25508
|
for (const fn of analysis.functions) {
|
|
25357
25509
|
testCode += this.generateFunctionTests(fn, testType);
|
|
25358
25510
|
}
|
|
@@ -25472,22 +25624,80 @@ ${importStatement}
|
|
|
25472
25624
|
* Generate stub tests when no AST analysis is available
|
|
25473
25625
|
*/
|
|
25474
25626
|
generateStubTests(context2) {
|
|
25475
|
-
const { moduleName, importPath, testType, patterns } = context2;
|
|
25627
|
+
const { moduleName, importPath, testType, patterns, dependencies, similarCode } = context2;
|
|
25476
25628
|
const patternComment = this.generatePatternComment(patterns);
|
|
25477
25629
|
const basicOpsTest = this.generateBasicOpsTest(moduleName, patterns);
|
|
25478
25630
|
const edgeCaseTest = this.generateEdgeCaseTest(moduleName, patterns);
|
|
25479
25631
|
const errorHandlingTest = this.generateErrorHandlingTest(moduleName, patterns);
|
|
25632
|
+
let mockDeclarations = "";
|
|
25633
|
+
if (dependencies && dependencies.imports.length > 0) {
|
|
25634
|
+
const mockFn = this.framework === "vitest" ? "vi.fn()" : "jest.fn()";
|
|
25635
|
+
mockDeclarations += `
|
|
25636
|
+
// Auto-generated mocks from Knowledge Graph dependency analysis
|
|
25637
|
+
`;
|
|
25638
|
+
for (const dep of dependencies.imports.slice(0, 10)) {
|
|
25639
|
+
mockDeclarations += `${this.mockUtil}.mock('${dep}', () => ({ default: ${mockFn} }));
|
|
25640
|
+
`;
|
|
25641
|
+
}
|
|
25642
|
+
}
|
|
25643
|
+
let similarityComment = "";
|
|
25644
|
+
if (similarCode && similarCode.snippets.length > 0) {
|
|
25645
|
+
similarityComment += ` // KG: Similar modules found - consider testing shared patterns:
|
|
25646
|
+
`;
|
|
25647
|
+
for (const s70 of similarCode.snippets.slice(0, 3)) {
|
|
25648
|
+
similarityComment += ` // - ${s70.file} (${(s70.score * 100).toFixed(0)}% similar)
|
|
25649
|
+
`;
|
|
25650
|
+
}
|
|
25651
|
+
similarityComment += `
|
|
25652
|
+
`;
|
|
25653
|
+
}
|
|
25654
|
+
let depTest = "";
|
|
25655
|
+
if (dependencies && dependencies.imports.length > 0) {
|
|
25656
|
+
depTest += `
|
|
25657
|
+
it('should interact with dependencies correctly', () => {
|
|
25658
|
+
`;
|
|
25659
|
+
depTest += ` // KG-informed: module depends on ${dependencies.imports.length} imports
|
|
25660
|
+
`;
|
|
25661
|
+
depTest += ` const instance = typeof ${moduleName} === 'function'
|
|
25662
|
+
`;
|
|
25663
|
+
depTest += ` ? new ${moduleName}()
|
|
25664
|
+
`;
|
|
25665
|
+
depTest += ` : ${moduleName};
|
|
25666
|
+
`;
|
|
25667
|
+
depTest += ` expect(instance).toBeDefined();
|
|
25668
|
+
`;
|
|
25669
|
+
depTest += ` });
|
|
25670
|
+
`;
|
|
25671
|
+
}
|
|
25672
|
+
let callerTest = "";
|
|
25673
|
+
if (dependencies && dependencies.importedBy.length > 0) {
|
|
25674
|
+
callerTest += `
|
|
25675
|
+
it('should expose stable API for ${dependencies.importedBy.length} consumers', () => {
|
|
25676
|
+
`;
|
|
25677
|
+
callerTest += ` // KG-informed: used by ${dependencies.importedBy.slice(0, 3).join(", ")}
|
|
25678
|
+
`;
|
|
25679
|
+
callerTest += ` const publicKeys = Object.keys(typeof ${moduleName} === 'function'
|
|
25680
|
+
`;
|
|
25681
|
+
callerTest += ` ? ${moduleName}.prototype || {}
|
|
25682
|
+
`;
|
|
25683
|
+
callerTest += ` : ${moduleName});
|
|
25684
|
+
`;
|
|
25685
|
+
callerTest += ` expect(publicKeys.length).toBeGreaterThan(0);
|
|
25686
|
+
`;
|
|
25687
|
+
callerTest += ` });
|
|
25688
|
+
`;
|
|
25689
|
+
}
|
|
25480
25690
|
return `${patternComment}import { ${moduleName} } from '${importPath}';
|
|
25481
|
-
|
|
25691
|
+
${mockDeclarations}
|
|
25482
25692
|
describe('${moduleName}', () => {
|
|
25483
|
-
describe('${testType} tests', () => {
|
|
25693
|
+
${similarityComment} describe('${testType} tests', () => {
|
|
25484
25694
|
it('should be defined', () => {
|
|
25485
25695
|
expect(${moduleName}).toBeDefined();
|
|
25486
25696
|
});
|
|
25487
25697
|
|
|
25488
25698
|
${basicOpsTest}
|
|
25489
25699
|
${edgeCaseTest}
|
|
25490
|
-
${errorHandlingTest}
|
|
25700
|
+
${errorHandlingTest}${depTest}${callerTest}
|
|
25491
25701
|
});
|
|
25492
25702
|
});
|
|
25493
25703
|
`;
|
|
@@ -25695,18 +25905,51 @@ var MochaGenerator = class extends BaseTestGenerator {
|
|
|
25695
25905
|
* Generate complete test file from analysis
|
|
25696
25906
|
*/
|
|
25697
25907
|
generateTests(context2) {
|
|
25698
|
-
const { moduleName, importPath, testType, patterns, analysis } = context2;
|
|
25908
|
+
const { moduleName, importPath, testType, patterns, analysis, dependencies } = context2;
|
|
25699
25909
|
if (!analysis || analysis.functions.length === 0 && analysis.classes.length === 0) {
|
|
25700
25910
|
return this.generateStubTests(context2);
|
|
25701
25911
|
}
|
|
25702
25912
|
const patternComment = this.generatePatternComment(patterns);
|
|
25703
25913
|
const exports = this.extractExports(analysis.functions, analysis.classes);
|
|
25704
25914
|
const importStatement = this.generateImportStatement(exports, importPath, moduleName);
|
|
25915
|
+
let sinonImport = "";
|
|
25916
|
+
let stubSetup = "";
|
|
25917
|
+
if (dependencies && dependencies.imports.length > 0) {
|
|
25918
|
+
sinonImport = `import sinon from 'sinon';
|
|
25919
|
+
`;
|
|
25920
|
+
const depsToMock = dependencies.imports.slice(0, 5);
|
|
25921
|
+
stubSetup += ` // Auto-generated stubs from Knowledge Graph dependency analysis
|
|
25922
|
+
`;
|
|
25923
|
+
stubSetup += ` let stubs;
|
|
25924
|
+
|
|
25925
|
+
`;
|
|
25926
|
+
stubSetup += ` beforeEach(function() {
|
|
25927
|
+
`;
|
|
25928
|
+
stubSetup += ` stubs = {
|
|
25929
|
+
`;
|
|
25930
|
+
for (const dep of depsToMock) {
|
|
25931
|
+
const depName = dep.split("/").pop()?.replace(/[^a-zA-Z0-9_]/g, "_") || dep;
|
|
25932
|
+
stubSetup += ` ${depName}: sinon.stub(),
|
|
25933
|
+
`;
|
|
25934
|
+
}
|
|
25935
|
+
stubSetup += ` };
|
|
25936
|
+
`;
|
|
25937
|
+
stubSetup += ` });
|
|
25938
|
+
|
|
25939
|
+
`;
|
|
25940
|
+
stubSetup += ` afterEach(function() {
|
|
25941
|
+
`;
|
|
25942
|
+
stubSetup += ` sinon.restore();
|
|
25943
|
+
`;
|
|
25944
|
+
stubSetup += ` });
|
|
25945
|
+
|
|
25946
|
+
`;
|
|
25947
|
+
}
|
|
25705
25948
|
let code = `${patternComment}import { expect } from 'chai';
|
|
25706
|
-
${importStatement}
|
|
25949
|
+
${sinonImport}${importStatement}
|
|
25707
25950
|
|
|
25708
25951
|
describe('${moduleName} - ${testType} tests', function() {
|
|
25709
|
-
`;
|
|
25952
|
+
${stubSetup}`;
|
|
25710
25953
|
for (const fn of analysis.functions) {
|
|
25711
25954
|
code += this.generateFunctionTests(fn, testType);
|
|
25712
25955
|
}
|
|
@@ -25796,18 +26039,100 @@ describe('${moduleName} - ${testType} tests', function() {
|
|
|
25796
26039
|
* Generate stub tests when no AST analysis is available
|
|
25797
26040
|
*/
|
|
25798
26041
|
generateStubTests(context2) {
|
|
25799
|
-
const { moduleName, importPath, testType, patterns } = context2;
|
|
26042
|
+
const { moduleName, importPath, testType, patterns, dependencies, similarCode } = context2;
|
|
25800
26043
|
const patternComment = this.generatePatternComment(patterns);
|
|
25801
26044
|
const isAsync = patterns.some(
|
|
25802
26045
|
(p74) => p74.name.toLowerCase().includes("async") || p74.name.toLowerCase().includes("promise")
|
|
25803
26046
|
);
|
|
25804
26047
|
const asyncSetup = isAsync ? "async " : "";
|
|
26048
|
+
let sinonImport = "";
|
|
26049
|
+
let stubSetup = "";
|
|
26050
|
+
let stubTeardown = "";
|
|
26051
|
+
if (dependencies && dependencies.imports.length > 0) {
|
|
26052
|
+
sinonImport = `import sinon from 'sinon';
|
|
26053
|
+
`;
|
|
26054
|
+
const depsToMock = dependencies.imports.slice(0, 5);
|
|
26055
|
+
stubSetup += `
|
|
26056
|
+
// Auto-generated stubs from Knowledge Graph dependency analysis
|
|
26057
|
+
`;
|
|
26058
|
+
stubSetup += ` let stubs;
|
|
26059
|
+
|
|
26060
|
+
`;
|
|
26061
|
+
stubSetup += ` beforeEach(function() {
|
|
26062
|
+
`;
|
|
26063
|
+
stubSetup += ` stubs = {
|
|
26064
|
+
`;
|
|
26065
|
+
for (const dep of depsToMock) {
|
|
26066
|
+
const depName = dep.split("/").pop()?.replace(/[^a-zA-Z0-9_]/g, "_") || dep;
|
|
26067
|
+
stubSetup += ` ${depName}: sinon.stub(),
|
|
26068
|
+
`;
|
|
26069
|
+
}
|
|
26070
|
+
stubSetup += ` };
|
|
26071
|
+
`;
|
|
26072
|
+
stubSetup += ` });
|
|
26073
|
+
|
|
26074
|
+
`;
|
|
26075
|
+
stubTeardown += ` afterEach(function() {
|
|
26076
|
+
`;
|
|
26077
|
+
stubTeardown += ` sinon.restore();
|
|
26078
|
+
`;
|
|
26079
|
+
stubTeardown += ` });
|
|
26080
|
+
|
|
26081
|
+
`;
|
|
26082
|
+
}
|
|
26083
|
+
let similarityComment = "";
|
|
26084
|
+
if (similarCode && similarCode.snippets.length > 0) {
|
|
26085
|
+
similarityComment += ` // KG: Similar modules found - consider testing shared patterns:
|
|
26086
|
+
`;
|
|
26087
|
+
for (const s70 of similarCode.snippets.slice(0, 3)) {
|
|
26088
|
+
similarityComment += ` // - ${s70.file} (${(s70.score * 100).toFixed(0)}% similar)
|
|
26089
|
+
`;
|
|
26090
|
+
}
|
|
26091
|
+
similarityComment += `
|
|
26092
|
+
`;
|
|
26093
|
+
}
|
|
26094
|
+
let depTest = "";
|
|
26095
|
+
if (dependencies && dependencies.imports.length > 0) {
|
|
26096
|
+
depTest += `
|
|
26097
|
+
it('should interact with dependencies correctly', function() {
|
|
26098
|
+
`;
|
|
26099
|
+
depTest += ` // KG-informed: module depends on ${dependencies.imports.length} imports
|
|
26100
|
+
`;
|
|
26101
|
+
depTest += ` const instance = typeof ${moduleName} === 'function'
|
|
26102
|
+
`;
|
|
26103
|
+
depTest += ` ? new ${moduleName}()
|
|
26104
|
+
`;
|
|
26105
|
+
depTest += ` : ${moduleName};
|
|
26106
|
+
`;
|
|
26107
|
+
depTest += ` expect(instance).to.exist;
|
|
26108
|
+
`;
|
|
26109
|
+
depTest += ` });
|
|
26110
|
+
`;
|
|
26111
|
+
}
|
|
26112
|
+
let callerTest = "";
|
|
26113
|
+
if (dependencies && dependencies.importedBy.length > 0) {
|
|
26114
|
+
callerTest += `
|
|
26115
|
+
it('should expose stable API for ${dependencies.importedBy.length} consumers', function() {
|
|
26116
|
+
`;
|
|
26117
|
+
callerTest += ` // KG-informed: used by ${dependencies.importedBy.slice(0, 3).join(", ")}
|
|
26118
|
+
`;
|
|
26119
|
+
callerTest += ` const publicKeys = Object.keys(typeof ${moduleName} === 'function'
|
|
26120
|
+
`;
|
|
26121
|
+
callerTest += ` ? ${moduleName}.prototype || {}
|
|
26122
|
+
`;
|
|
26123
|
+
callerTest += ` : ${moduleName});
|
|
26124
|
+
`;
|
|
26125
|
+
callerTest += ` expect(publicKeys.length).to.be.greaterThan(0);
|
|
26126
|
+
`;
|
|
26127
|
+
callerTest += ` });
|
|
26128
|
+
`;
|
|
26129
|
+
}
|
|
25805
26130
|
return `${patternComment}import { expect } from 'chai';
|
|
25806
|
-
import { ${moduleName} } from '${importPath}';
|
|
26131
|
+
${sinonImport}import { ${moduleName} } from '${importPath}';
|
|
25807
26132
|
|
|
25808
26133
|
describe('${moduleName}', function() {
|
|
25809
26134
|
describe('${testType} tests', function() {
|
|
25810
|
-
it('should be defined', function() {
|
|
26135
|
+
${stubSetup}${stubTeardown}${similarityComment} it('should be defined', function() {
|
|
25811
26136
|
expect(${moduleName}).to.not.be.undefined;
|
|
25812
26137
|
});
|
|
25813
26138
|
|
|
@@ -25841,7 +26166,7 @@ describe('${moduleName}', function() {
|
|
|
25841
26166
|
: ${moduleName};
|
|
25842
26167
|
return instance;
|
|
25843
26168
|
}).to.not.throw();
|
|
25844
|
-
})
|
|
26169
|
+
});${depTest}${callerTest}
|
|
25845
26170
|
});
|
|
25846
26171
|
});
|
|
25847
26172
|
`;
|
|
@@ -25889,7 +26214,7 @@ var PytestGenerator = class extends BaseTestGenerator {
|
|
|
25889
26214
|
* Generate complete test file from analysis
|
|
25890
26215
|
*/
|
|
25891
26216
|
generateTests(context2) {
|
|
25892
|
-
const { moduleName, importPath, testType, patterns, analysis } = context2;
|
|
26217
|
+
const { moduleName, importPath, testType, patterns, analysis, dependencies } = context2;
|
|
25893
26218
|
if (!analysis || analysis.functions.length === 0 && analysis.classes.length === 0) {
|
|
25894
26219
|
return this.generateStubTests(context2);
|
|
25895
26220
|
}
|
|
@@ -25897,8 +26222,18 @@ var PytestGenerator = class extends BaseTestGenerator {
|
|
|
25897
26222
|
const exports = this.extractExports(analysis.functions, analysis.classes);
|
|
25898
26223
|
const pythonImport = importPath.replace(/\//g, ".").replace(/\.(ts|js)$/, "");
|
|
25899
26224
|
const importStatement = exports.length > 0 ? `from ${pythonImport} import ${exports.join(", ")}` : `import ${pythonImport} as ${moduleName}`;
|
|
26225
|
+
let mockImport = "";
|
|
26226
|
+
if (dependencies && dependencies.imports.length > 0) {
|
|
26227
|
+
mockImport = `from unittest.mock import patch, MagicMock
|
|
26228
|
+
`;
|
|
26229
|
+
}
|
|
26230
|
+
const depsToMock = dependencies?.imports.slice(0, 5) || [];
|
|
26231
|
+
const patchDecorators = depsToMock.map((dep) => {
|
|
26232
|
+
const depModule = dep.replace(/\//g, ".").replace(/\.py$/, "");
|
|
26233
|
+
return `@patch('${depModule}')`;
|
|
26234
|
+
});
|
|
25900
26235
|
let code = `${patternComment}import pytest
|
|
25901
|
-
${importStatement}
|
|
26236
|
+
${mockImport}${importStatement}
|
|
25902
26237
|
|
|
25903
26238
|
|
|
25904
26239
|
class Test${this.pascalCase(moduleName)}:
|
|
@@ -25906,7 +26241,7 @@ class Test${this.pascalCase(moduleName)}:
|
|
|
25906
26241
|
|
|
25907
26242
|
`;
|
|
25908
26243
|
for (const fn of analysis.functions) {
|
|
25909
|
-
code += this.
|
|
26244
|
+
code += this.generateFunctionTestsWithPatches(fn, testType, patchDecorators);
|
|
25910
26245
|
}
|
|
25911
26246
|
for (const cls of analysis.classes) {
|
|
25912
26247
|
code += this.generateClassTests(cls, testType);
|
|
@@ -25917,8 +26252,18 @@ class Test${this.pascalCase(moduleName)}:
|
|
|
25917
26252
|
* Generate tests for a standalone function
|
|
25918
26253
|
*/
|
|
25919
26254
|
generateFunctionTests(fn, _testType) {
|
|
26255
|
+
return this.generateFunctionTestsWithPatches(fn, _testType, []);
|
|
26256
|
+
}
|
|
26257
|
+
/**
|
|
26258
|
+
* Generate tests for a function with @patch decorators from KG dependencies
|
|
26259
|
+
*/
|
|
26260
|
+
generateFunctionTestsWithPatches(fn, _testType, patchDecorators) {
|
|
25920
26261
|
const validParams = fn.parameters.map((p74) => this.generatePythonTestValue(p74)).join(", ");
|
|
25921
|
-
|
|
26262
|
+
const mockParams = patchDecorators.map((_56, i58) => `mock_dep_${i58}`).reverse().join(", ");
|
|
26263
|
+
const allParams = mockParams ? `self, ${mockParams}` : "self";
|
|
26264
|
+
const patchPrefix = patchDecorators.map((d74) => ` ${d74}
|
|
26265
|
+
`).join("");
|
|
26266
|
+
let code = `${patchPrefix} def test_${fn.name}_valid_input(${allParams}):
|
|
25922
26267
|
`;
|
|
25923
26268
|
code += ` """Test ${fn.name} with valid input"""
|
|
25924
26269
|
`;
|
|
@@ -25929,7 +26274,7 @@ class Test${this.pascalCase(moduleName)}:
|
|
|
25929
26274
|
`;
|
|
25930
26275
|
for (const param of fn.parameters) {
|
|
25931
26276
|
if (!param.optional && param.type?.includes("str")) {
|
|
25932
|
-
code +=
|
|
26277
|
+
code += `${patchPrefix} def test_${fn.name}_empty_${param.name}(${allParams}):
|
|
25933
26278
|
`;
|
|
25934
26279
|
code += ` """Test ${fn.name} with empty ${param.name}"""
|
|
25935
26280
|
`;
|
|
@@ -25984,21 +26329,84 @@ class Test${cls.name}:
|
|
|
25984
26329
|
* Generate stub tests when no AST analysis is available
|
|
25985
26330
|
*/
|
|
25986
26331
|
generateStubTests(context2) {
|
|
25987
|
-
const { moduleName, importPath, testType, patterns } = context2;
|
|
26332
|
+
const { moduleName, importPath, testType, patterns, dependencies, similarCode } = context2;
|
|
25988
26333
|
const patternComment = this.generatePythonPatternComment(patterns);
|
|
25989
26334
|
const isAsync = patterns.some(
|
|
25990
26335
|
(p74) => p74.name.toLowerCase().includes("async") || p74.name.toLowerCase().includes("promise")
|
|
25991
26336
|
);
|
|
25992
26337
|
const asyncDecorator = isAsync ? "@pytest.mark.asyncio\n " : "";
|
|
25993
26338
|
const asyncDef = isAsync ? "async def" : "def";
|
|
26339
|
+
let mockImports = "";
|
|
26340
|
+
let mockPatches = "";
|
|
26341
|
+
if (dependencies && dependencies.imports.length > 0) {
|
|
26342
|
+
mockImports = `from unittest.mock import patch, MagicMock
|
|
26343
|
+
`;
|
|
26344
|
+
const depsToMock = dependencies.imports.slice(0, 5);
|
|
26345
|
+
for (const dep of depsToMock) {
|
|
26346
|
+
const depModule = dep.replace(/\//g, ".").replace(/\.py$/, "");
|
|
26347
|
+
mockPatches += ` @patch('${depModule}')
|
|
26348
|
+
`;
|
|
26349
|
+
}
|
|
26350
|
+
}
|
|
26351
|
+
let similarityComment = "";
|
|
26352
|
+
if (similarCode && similarCode.snippets.length > 0) {
|
|
26353
|
+
similarityComment = ` # KG: Similar modules found - consider testing shared patterns:
|
|
26354
|
+
`;
|
|
26355
|
+
for (const s70 of similarCode.snippets.slice(0, 3)) {
|
|
26356
|
+
similarityComment += ` # - ${s70.file} (${(s70.score * 100).toFixed(0)}% similar)
|
|
26357
|
+
`;
|
|
26358
|
+
}
|
|
26359
|
+
similarityComment += `
|
|
26360
|
+
`;
|
|
26361
|
+
}
|
|
26362
|
+
let depTests = "";
|
|
26363
|
+
if (dependencies && dependencies.imports.length > 0) {
|
|
26364
|
+
depTests += `
|
|
26365
|
+
def test_dependencies_importable(self):
|
|
26366
|
+
`;
|
|
26367
|
+
depTests += ` """Verify all dependencies are importable (KG-informed)."""
|
|
26368
|
+
`;
|
|
26369
|
+
for (const dep of dependencies.imports.slice(0, 5)) {
|
|
26370
|
+
const depModule = dep.replace(/\//g, ".").replace(/\.py$/, "");
|
|
26371
|
+
depTests += ` import importlib
|
|
26372
|
+
`;
|
|
26373
|
+
depTests += ` mod = importlib.import_module('${depModule}')
|
|
26374
|
+
`;
|
|
26375
|
+
depTests += ` assert mod is not None
|
|
26376
|
+
`;
|
|
26377
|
+
}
|
|
26378
|
+
depTests += `
|
|
26379
|
+
def test_dependency_interactions(self):
|
|
26380
|
+
`;
|
|
26381
|
+
depTests += ` """Test module interactions with its dependencies (KG-informed)."""
|
|
26382
|
+
`;
|
|
26383
|
+
depTests += ` # Module should handle dependency failures gracefully
|
|
26384
|
+
`;
|
|
26385
|
+
depTests += ` assert ${moduleName} is not None
|
|
26386
|
+
`;
|
|
26387
|
+
depTests += ` assert hasattr(${moduleName}, '__name__') or hasattr(${moduleName}, '__class__')
|
|
26388
|
+
`;
|
|
26389
|
+
}
|
|
26390
|
+
let callerTests = "";
|
|
26391
|
+
if (dependencies && dependencies.importedBy.length > 0) {
|
|
26392
|
+
callerTests += `
|
|
26393
|
+
def test_public_api_surface(self):
|
|
26394
|
+
`;
|
|
26395
|
+
callerTests += ` """Verify public API used by ${dependencies.importedBy.length} consumers (KG-informed)."""
|
|
26396
|
+
`;
|
|
26397
|
+
callerTests += ` public_attrs = [a for a in dir(${moduleName}) if not a.startswith('_')]
|
|
26398
|
+
`;
|
|
26399
|
+
callerTests += ` assert len(public_attrs) > 0, "Module should expose public API"
|
|
26400
|
+
`;
|
|
26401
|
+
}
|
|
25994
26402
|
return `${patternComment}import pytest
|
|
25995
|
-
from ${importPath} import ${moduleName}
|
|
26403
|
+
${mockImports}from ${importPath} import ${moduleName}
|
|
25996
26404
|
|
|
25997
26405
|
|
|
25998
26406
|
class Test${this.pascalCase(moduleName)}:
|
|
25999
26407
|
"""${testType} tests for ${moduleName}"""
|
|
26000
26408
|
|
|
26001
|
-
def test_is_defined(self):
|
|
26409
|
+
${similarityComment} def test_is_defined(self):
|
|
26002
26410
|
"""Verify the module is properly exported and defined."""
|
|
26003
26411
|
assert ${moduleName} is not None
|
|
26004
26412
|
|
|
@@ -26032,7 +26440,7 @@ class Test${this.pascalCase(moduleName)}:
|
|
|
26032
26440
|
except TypeError:
|
|
26033
26441
|
# Expected if constructor requires arguments
|
|
26034
26442
|
pass
|
|
26035
|
-
`;
|
|
26443
|
+
${depTests}${callerTests}`;
|
|
26036
26444
|
}
|
|
26037
26445
|
/**
|
|
26038
26446
|
* Generate coverage-focused tests for specific lines
|
|
@@ -27050,10 +27458,46 @@ var TestGeneratorService = class {
|
|
|
27050
27458
|
* Enhance generated test code using LLM
|
|
27051
27459
|
* Adds edge cases, improves assertions, and adds documentation
|
|
27052
27460
|
*/
|
|
27053
|
-
async enhanceTestWithLLM(testCode, sourceCode, analysis) {
|
|
27461
|
+
async enhanceTestWithLLM(testCode, sourceCode, analysis, context2) {
|
|
27054
27462
|
if (!this.llmRouter) return testCode;
|
|
27055
27463
|
try {
|
|
27056
|
-
|
|
27464
|
+
let prompt = this.buildTestEnhancementPrompt(testCode, sourceCode, analysis);
|
|
27465
|
+
if (context2?.dependencies) {
|
|
27466
|
+
prompt += `
|
|
27467
|
+
## Dependency Context (from Knowledge Graph):
|
|
27468
|
+
`;
|
|
27469
|
+
if (context2.dependencies.imports.length > 0) {
|
|
27470
|
+
prompt += `- Imports: ${context2.dependencies.imports.join(", ")}
|
|
27471
|
+
`;
|
|
27472
|
+
prompt += ` \u2192 Generate mock declarations for these dependencies
|
|
27473
|
+
`;
|
|
27474
|
+
}
|
|
27475
|
+
if (context2.dependencies.importedBy.length > 0) {
|
|
27476
|
+
prompt += `- Imported by: ${context2.dependencies.importedBy.join(", ")}
|
|
27477
|
+
`;
|
|
27478
|
+
prompt += ` \u2192 Focus tests on the public API surface these consumers use
|
|
27479
|
+
`;
|
|
27480
|
+
}
|
|
27481
|
+
if (context2.dependencies.callers.length > 0) {
|
|
27482
|
+
prompt += `- Called by: ${context2.dependencies.callers.join(", ")}
|
|
27483
|
+
`;
|
|
27484
|
+
}
|
|
27485
|
+
if (context2.dependencies.callees.length > 0) {
|
|
27486
|
+
prompt += `- Calls: ${context2.dependencies.callees.join(", ")}
|
|
27487
|
+
`;
|
|
27488
|
+
}
|
|
27489
|
+
}
|
|
27490
|
+
if (context2?.similarCode && context2.similarCode.snippets.length > 0) {
|
|
27491
|
+
prompt += `
|
|
27492
|
+
## Similar Code Patterns (from Knowledge Graph):
|
|
27493
|
+
`;
|
|
27494
|
+
for (const s70 of context2.similarCode.snippets.slice(0, 3)) {
|
|
27495
|
+
prompt += `- ${s70.file} (similarity: ${(s70.score * 100).toFixed(0)}%): ${s70.snippet}
|
|
27496
|
+
`;
|
|
27497
|
+
}
|
|
27498
|
+
prompt += ` \u2192 Use similar patterns as templates for assertions
|
|
27499
|
+
`;
|
|
27500
|
+
}
|
|
27057
27501
|
const modelId = this.getModelForTier(this.config.llmModelTier);
|
|
27058
27502
|
const response = await this.llmRouter.chat({
|
|
27059
27503
|
messages: [
|
|
@@ -27293,6 +27737,15 @@ ${sourceCode}
|
|
|
27293
27737
|
codeAnalysis = this.analyzeSourceCode(sourceContent, sourceFile);
|
|
27294
27738
|
} catch {
|
|
27295
27739
|
}
|
|
27740
|
+
let dependencies;
|
|
27741
|
+
let similarCode;
|
|
27742
|
+
if (this.memory && sourceContent) {
|
|
27743
|
+
const hasKGVectors = await this.hasKGVectors();
|
|
27744
|
+
if (hasKGVectors) {
|
|
27745
|
+
dependencies = await this.queryKGDependencies(sourceFile, sourceContent);
|
|
27746
|
+
similarCode = await this.queryKGSimilarCode(sourceContent);
|
|
27747
|
+
}
|
|
27748
|
+
}
|
|
27296
27749
|
const generator = this.generatorFactory.create(framework);
|
|
27297
27750
|
const moduleName = this.extractModuleName(sourceFile);
|
|
27298
27751
|
const importPath = this.getImportPath(sourceFile);
|
|
@@ -27301,11 +27754,13 @@ ${sourceCode}
|
|
|
27301
27754
|
importPath,
|
|
27302
27755
|
testType,
|
|
27303
27756
|
patterns: applicablePatterns,
|
|
27304
|
-
analysis: codeAnalysis ?? void 0
|
|
27757
|
+
analysis: codeAnalysis ?? void 0,
|
|
27758
|
+
dependencies,
|
|
27759
|
+
similarCode
|
|
27305
27760
|
};
|
|
27306
27761
|
let testCode = generator.generateTests(context2);
|
|
27307
27762
|
if (this.isLLMEnhancementAvailable() && sourceContent) {
|
|
27308
|
-
testCode = await this.enhanceTestWithLLM(testCode, sourceContent, codeAnalysis);
|
|
27763
|
+
testCode = await this.enhanceTestWithLLM(testCode, sourceContent, codeAnalysis, context2);
|
|
27309
27764
|
}
|
|
27310
27765
|
const test = {
|
|
27311
27766
|
id: v4_default(),
|
|
@@ -27500,6 +27955,107 @@ ${sourceCode}
|
|
|
27500
27955
|
return complexity;
|
|
27501
27956
|
}
|
|
27502
27957
|
// ============================================================================
|
|
27958
|
+
// Private Helper Methods - Knowledge Graph Queries
|
|
27959
|
+
// ============================================================================
|
|
27960
|
+
/**
|
|
27961
|
+
* Check if KG vectors exist by probing a vector search.
|
|
27962
|
+
* Returns true if vectorSearch returns any results (indicating indexed code exists).
|
|
27963
|
+
*/
|
|
27964
|
+
async hasKGVectors() {
|
|
27965
|
+
try {
|
|
27966
|
+
const probe = new Array(768).fill(0);
|
|
27967
|
+
probe[0] = 1;
|
|
27968
|
+
const results = await this.memory.vectorSearch(probe, 1);
|
|
27969
|
+
return results.length > 0;
|
|
27970
|
+
} catch {
|
|
27971
|
+
return false;
|
|
27972
|
+
}
|
|
27973
|
+
}
|
|
27974
|
+
/**
|
|
27975
|
+
* Query KG for dependency information about a file.
|
|
27976
|
+
* Extracts imports from source and cross-references with KG vector index
|
|
27977
|
+
* to find which indexed modules this file depends on and which depend on it.
|
|
27978
|
+
*/
|
|
27979
|
+
async queryKGDependencies(filePath, sourceContent) {
|
|
27980
|
+
try {
|
|
27981
|
+
const imports = [];
|
|
27982
|
+
const importedBy = [];
|
|
27983
|
+
const callees = [];
|
|
27984
|
+
const callers = [];
|
|
27985
|
+
const tsImports = sourceContent.matchAll(/(?:import|from)\s+['"]([^'"]+)['"]/g);
|
|
27986
|
+
const pyImports = sourceContent.matchAll(/(?:^|\n)\s*(?:from\s+(\S+)\s+import|import\s+(\S+))/g);
|
|
27987
|
+
for (const match of tsImports) {
|
|
27988
|
+
imports.push(match[1]);
|
|
27989
|
+
}
|
|
27990
|
+
for (const match of pyImports) {
|
|
27991
|
+
imports.push(match[1] || match[2]);
|
|
27992
|
+
}
|
|
27993
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
27994
|
+
const baseName = normalizedPath.split("/").pop()?.replace(/\.(ts|js|tsx|jsx|py)$/, "") || "";
|
|
27995
|
+
const nodeKeys = await this.memory.search(`code-intelligence:kg:node:*${baseName}*`, 50);
|
|
27996
|
+
for (const key of nodeKeys) {
|
|
27997
|
+
if (!key.includes(baseName)) continue;
|
|
27998
|
+
const parts = key.split(":");
|
|
27999
|
+
const nodeType = parts[parts.length - 2];
|
|
28000
|
+
const nodeName = parts[parts.length - 1];
|
|
28001
|
+
if (nodeType === "function") {
|
|
28002
|
+
callees.push(nodeName);
|
|
28003
|
+
}
|
|
28004
|
+
}
|
|
28005
|
+
if (imports.length === 0 && importedBy.length === 0 && callees.length === 0 && callers.length === 0) {
|
|
28006
|
+
return void 0;
|
|
28007
|
+
}
|
|
28008
|
+
return { imports, importedBy, callees, callers };
|
|
28009
|
+
} catch {
|
|
28010
|
+
return void 0;
|
|
28011
|
+
}
|
|
28012
|
+
}
|
|
28013
|
+
/**
|
|
28014
|
+
* Query KG for semantically similar code snippets.
|
|
28015
|
+
* Uses vector search against the persisted vectors table.
|
|
28016
|
+
* KG nodes are stored as vectors with IDs like code-intelligence:kg:node:*
|
|
28017
|
+
*/
|
|
28018
|
+
async queryKGSimilarCode(sourceContent) {
|
|
28019
|
+
try {
|
|
28020
|
+
const embedding = this.generatePseudoEmbedding(sourceContent);
|
|
28021
|
+
const results = await this.memory.vectorSearch(embedding, 5);
|
|
28022
|
+
if (results.length === 0) return void 0;
|
|
28023
|
+
const snippets = [];
|
|
28024
|
+
for (const result of results) {
|
|
28025
|
+
if (result.score < 0.1) continue;
|
|
28026
|
+
const metadata = result.metadata;
|
|
28027
|
+
const file = metadata?.file || result.key;
|
|
28028
|
+
const snippet = metadata?.name || metadata?.type || result.key.split(":").pop() || "";
|
|
28029
|
+
snippets.push({ file, snippet, score: result.score });
|
|
28030
|
+
}
|
|
28031
|
+
return snippets.length > 0 ? { snippets } : void 0;
|
|
28032
|
+
} catch {
|
|
28033
|
+
return void 0;
|
|
28034
|
+
}
|
|
28035
|
+
}
|
|
28036
|
+
/**
|
|
28037
|
+
* Generate a simple pseudo-embedding for vector search.
|
|
28038
|
+
* Uses token-based feature extraction similar to semantic-analyzer.
|
|
28039
|
+
*/
|
|
28040
|
+
generatePseudoEmbedding(code) {
|
|
28041
|
+
const dimension = 768;
|
|
28042
|
+
const embedding = new Array(dimension).fill(0);
|
|
28043
|
+
const tokens = code.split(/[^a-zA-Z0-9_$]+/).filter((t50) => t50.length > 1);
|
|
28044
|
+
for (let i58 = 0; i58 < tokens.length; i58++) {
|
|
28045
|
+
const token = tokens[i58];
|
|
28046
|
+
for (let j52 = 0; j52 < token.length && j52 < embedding.length; j52++) {
|
|
28047
|
+
embedding[(i58 + j52) % dimension] += token.charCodeAt(j52) / 1e3;
|
|
28048
|
+
}
|
|
28049
|
+
}
|
|
28050
|
+
const magnitude2 = Math.sqrt(embedding.reduce((sum, v62) => sum + v62 * v62, 0));
|
|
28051
|
+
if (magnitude2 > 0) {
|
|
28052
|
+
for (let i58 = 0; i58 < dimension; i58++) {
|
|
28053
|
+
embedding[i58] /= magnitude2;
|
|
28054
|
+
}
|
|
28055
|
+
}
|
|
28056
|
+
return embedding;
|
|
28057
|
+
}
|
|
28058
|
+
// ============================================================================
|
|
27503
28059
|
// Private Helper Methods - Utility Functions
|
|
27504
28060
|
// ============================================================================
|
|
27505
28061
|
async findApplicablePatterns(sourceFile, requestedPatterns) {
|
|
@@ -28853,6 +29409,7 @@ var TypeScriptASTParser = class {
|
|
|
28853
29409
|
// src/learning/qe-hooks.ts
|
|
28854
29410
|
init_error_utils();
|
|
28855
29411
|
init_logging();
|
|
29412
|
+
init_qe_patterns();
|
|
28856
29413
|
var logger5 = LoggerFactory.create("qe-hooks");
|
|
28857
29414
|
var QE_HOOK_EVENTS = {
|
|
28858
29415
|
// Test lifecycle
|
|
@@ -29133,9 +29690,36 @@ ${suggestedTests}`,
|
|
|
29133
29690
|
},
|
|
29134
29691
|
[QE_HOOK_EVENTS.QEAgentCompletion]: async (ctx) => {
|
|
29135
29692
|
const { agentType, task, success, duration, patternId, feedback } = ctx.data;
|
|
29136
|
-
|
|
29693
|
+
let patternsLearned = 0;
|
|
29694
|
+
const effectivePatternId = patternId;
|
|
29695
|
+
if (effectivePatternId) {
|
|
29696
|
+
try {
|
|
29697
|
+
const existing = await reasoningBank.getPattern(effectivePatternId);
|
|
29698
|
+
if (!existing) {
|
|
29699
|
+
const agent = agentType || "unknown";
|
|
29700
|
+
const domain = detectQEDomain(task || agent) || "learning-optimization";
|
|
29701
|
+
await reasoningBank.storePattern({
|
|
29702
|
+
patternType: "test-template",
|
|
29703
|
+
qeDomain: domain,
|
|
29704
|
+
name: `Auto: ${agent} completion`,
|
|
29705
|
+
description: `Auto-created pattern for ${agent} task completion tracking`,
|
|
29706
|
+
template: {
|
|
29707
|
+
type: "prompt",
|
|
29708
|
+
content: `Agent ${agent} task pattern`,
|
|
29709
|
+
variables: []
|
|
29710
|
+
},
|
|
29711
|
+
context: {
|
|
29712
|
+
tags: ["auto-created", "agent-completion", agent]
|
|
29713
|
+
},
|
|
29714
|
+
confidence: 0.5
|
|
29715
|
+
});
|
|
29716
|
+
patternsLearned = 1;
|
|
29717
|
+
}
|
|
29718
|
+
} catch (e20) {
|
|
29719
|
+
logger5.debug("Auto-create pattern failed", { error: e20 instanceof Error ? e20.message : String(e20) });
|
|
29720
|
+
}
|
|
29137
29721
|
await reasoningBank.recordOutcome({
|
|
29138
|
-
patternId,
|
|
29722
|
+
patternId: effectivePatternId,
|
|
29139
29723
|
success,
|
|
29140
29724
|
metrics: {
|
|
29141
29725
|
executionTimeMs: duration
|
|
@@ -29145,6 +29729,7 @@ ${suggestedTests}`,
|
|
|
29145
29729
|
}
|
|
29146
29730
|
return {
|
|
29147
29731
|
success: true,
|
|
29732
|
+
patternsLearned,
|
|
29148
29733
|
data: { agentType, success, duration }
|
|
29149
29734
|
};
|
|
29150
29735
|
},
|
|
@@ -70260,7 +70845,35 @@ import { join as join10, extname as extname3 } from "path";
|
|
|
70260
70845
|
// src/domains/code-intelligence/services/metric-collector/interfaces.ts
|
|
70261
70846
|
var DEFAULT_METRIC_CONFIG = {
|
|
70262
70847
|
timeout: 6e4,
|
|
70263
|
-
excludeDirs: [
|
|
70848
|
+
excludeDirs: [
|
|
70849
|
+
// JS/TS ecosystem
|
|
70850
|
+
"node_modules",
|
|
70851
|
+
"dist",
|
|
70852
|
+
"build",
|
|
70853
|
+
"coverage",
|
|
70854
|
+
".nyc_output",
|
|
70855
|
+
".next",
|
|
70856
|
+
".nuxt",
|
|
70857
|
+
".output",
|
|
70858
|
+
// Python ecosystem
|
|
70859
|
+
"__pycache__",
|
|
70860
|
+
".venv",
|
|
70861
|
+
"venv",
|
|
70862
|
+
".tox",
|
|
70863
|
+
".mypy_cache",
|
|
70864
|
+
".pytest_cache",
|
|
70865
|
+
".eggs",
|
|
70866
|
+
"*.egg-info",
|
|
70867
|
+
// Rust / Java / Go
|
|
70868
|
+
"target",
|
|
70869
|
+
".gradle",
|
|
70870
|
+
"vendor",
|
|
70871
|
+
".bundle",
|
|
70872
|
+
// General
|
|
70873
|
+
".git",
|
|
70874
|
+
".svn",
|
|
70875
|
+
".hg"
|
|
70876
|
+
],
|
|
70264
70877
|
testPatterns: ["**/*.test.ts", "**/*.spec.ts", "**/*.test.js", "**/*.spec.js"],
|
|
70265
70878
|
enableCache: true,
|
|
70266
70879
|
cacheTTL: 3e5
|
|
@@ -70268,7 +70881,7 @@ var DEFAULT_METRIC_CONFIG = {
|
|
|
70268
70881
|
|
|
70269
70882
|
// src/domains/code-intelligence/services/metric-collector/loc-counter.ts
|
|
70270
70883
|
import { execSync as execSync3, spawnSync as spawnSync2 } from "child_process";
|
|
70271
|
-
import { existsSync as existsSync6, readdirSync, readFileSync as readFileSync5 } from "fs";
|
|
70884
|
+
import { existsSync as existsSync6, readdirSync, readFileSync as readFileSync5, statSync as statSync2 } from "fs";
|
|
70272
70885
|
import { join as join8, extname } from "path";
|
|
70273
70886
|
init_safe_json();
|
|
70274
70887
|
async function countLOC(projectPath, config = {}) {
|
|
@@ -70412,22 +71025,35 @@ function getLanguageForExtension(ext) {
|
|
|
70412
71025
|
function manualLOCCount(projectPath, config) {
|
|
70413
71026
|
const byLanguage = {};
|
|
70414
71027
|
let total = 0;
|
|
70415
|
-
|
|
70416
|
-
|
|
71028
|
+
const excludeSet = new Set(config.excludeDirs);
|
|
71029
|
+
const MAX_FILE_SIZE = 2 * 1024 * 1024;
|
|
71030
|
+
function walkDirectory3(dirPath, depth) {
|
|
71031
|
+
if (!existsSync6(dirPath) || depth > 20) {
|
|
71032
|
+
return;
|
|
71033
|
+
}
|
|
71034
|
+
let entries;
|
|
71035
|
+
try {
|
|
71036
|
+
entries = readdirSync(dirPath, { withFileTypes: true });
|
|
71037
|
+
} catch {
|
|
70417
71038
|
return;
|
|
70418
71039
|
}
|
|
70419
|
-
const entries = readdirSync(dirPath, { withFileTypes: true });
|
|
70420
71040
|
for (const entry of entries) {
|
|
70421
71041
|
const fullPath = join8(dirPath, entry.name);
|
|
70422
71042
|
if (entry.isDirectory()) {
|
|
70423
|
-
if (
|
|
71043
|
+
if (excludeSet.has(entry.name) || entry.name.startsWith(".")) {
|
|
70424
71044
|
continue;
|
|
70425
71045
|
}
|
|
70426
|
-
walkDirectory3(fullPath);
|
|
71046
|
+
walkDirectory3(fullPath, depth + 1);
|
|
70427
71047
|
} else if (entry.isFile()) {
|
|
70428
71048
|
const ext = extname(entry.name);
|
|
70429
71049
|
const language = getLanguageForExtension(ext);
|
|
70430
71050
|
if (language) {
|
|
71051
|
+
try {
|
|
71052
|
+
const stat4 = statSync2(fullPath);
|
|
71053
|
+
if (stat4.size > MAX_FILE_SIZE) continue;
|
|
71054
|
+
} catch {
|
|
71055
|
+
continue;
|
|
71056
|
+
}
|
|
70431
71057
|
const lines = countFileLines(fullPath);
|
|
70432
71058
|
byLanguage[language] = (byLanguage[language] || 0) + lines;
|
|
70433
71059
|
total += lines;
|
|
@@ -70435,11 +71061,11 @@ function manualLOCCount(projectPath, config) {
|
|
|
70435
71061
|
}
|
|
70436
71062
|
}
|
|
70437
71063
|
}
|
|
70438
|
-
walkDirectory3(projectPath);
|
|
71064
|
+
walkDirectory3(projectPath, 0);
|
|
70439
71065
|
return {
|
|
70440
71066
|
total,
|
|
70441
71067
|
byLanguage,
|
|
70442
|
-
source: "
|
|
71068
|
+
source: "node-native",
|
|
70443
71069
|
excludedDirs: config.excludeDirs
|
|
70444
71070
|
};
|
|
70445
71071
|
}
|
|
@@ -71070,12 +71696,19 @@ var MetricCollectorService = class {
|
|
|
71070
71696
|
const toolsUsed = [];
|
|
71071
71697
|
if (loc.source !== "fallback") toolsUsed.push(loc.source);
|
|
71072
71698
|
if (tests.source !== "fallback") toolsUsed.push(tests.source);
|
|
71699
|
+
const locAccuracy = loc.source === "fallback" ? "approximate" : "accurate";
|
|
71700
|
+
const testAccuracy = tests.source === "fallback" ? "approximate" : "accurate";
|
|
71073
71701
|
const metrics = {
|
|
71074
71702
|
loc,
|
|
71075
71703
|
tests,
|
|
71076
71704
|
patterns,
|
|
71077
71705
|
collectedAt: /* @__PURE__ */ new Date(),
|
|
71078
|
-
toolsUsed
|
|
71706
|
+
toolsUsed,
|
|
71707
|
+
accuracy: {
|
|
71708
|
+
loc: locAccuracy,
|
|
71709
|
+
tests: testAccuracy,
|
|
71710
|
+
overall: locAccuracy === "accurate" && testAccuracy === "accurate" ? "accurate" : "approximate"
|
|
71711
|
+
}
|
|
71079
71712
|
};
|
|
71080
71713
|
if (this.config.enableCache) {
|
|
71081
71714
|
this.setInCache(cacheKey, metrics);
|
|
@@ -73305,9 +73938,15 @@ var CodeIntelligenceCoordinator = class extends BaseDomainCoordinator {
|
|
|
73305
73938
|
try {
|
|
73306
73939
|
console.log(`[CodeIntelligence] Collecting real metrics for ${projectPath}`);
|
|
73307
73940
|
const metrics = await this.metricCollector.collectAll(projectPath);
|
|
73941
|
+
const toolsLabel = metrics.toolsUsed.length > 0 ? metrics.toolsUsed.join(", ") : metrics.loc.source === "node-native" ? "node-native" : "fallback";
|
|
73308
73942
|
console.log(
|
|
73309
|
-
`[CodeIntelligence] Real metrics collected: ${metrics.loc.total} LOC, ${metrics.tests.total} tests, tools: ${
|
|
73943
|
+
`[CodeIntelligence] Real metrics collected: ${metrics.loc.total} LOC, ${metrics.tests.total} tests, tools: ${toolsLabel}`
|
|
73310
73944
|
);
|
|
73945
|
+
if (metrics.loc.source === "node-native") {
|
|
73946
|
+
console.log(
|
|
73947
|
+
`[CodeIntelligence] Using Node.js-native line counter (no cloc/tokei needed)`
|
|
73948
|
+
);
|
|
73949
|
+
}
|
|
73311
73950
|
await this.storeProjectMetricsInMemory(projectPath, metrics);
|
|
73312
73951
|
if (this.config.publishEvents) {
|
|
73313
73952
|
const event = createEvent(
|
|
@@ -114762,7 +115401,7 @@ var ALL_DOMAINS2 = [
|
|
|
114762
115401
|
"enterprise-integration"
|
|
114763
115402
|
];
|
|
114764
115403
|
function getAQEVersion() {
|
|
114765
|
-
return true ? "3.6.
|
|
115404
|
+
return true ? "3.6.11" : "3.0.0";
|
|
114766
115405
|
}
|
|
114767
115406
|
function createDefaultConfig(projectName, projectRoot) {
|
|
114768
115407
|
return {
|
|
@@ -115969,6 +116608,110 @@ function readJsonSafe(filePath) {
|
|
|
115969
116608
|
init_safe_json();
|
|
115970
116609
|
import { existsSync as existsSync16, mkdirSync as mkdirSync6, writeFileSync as writeFileSync3, readFileSync as readFileSync13, copyFileSync as copyFileSync3 } from "fs";
|
|
115971
116610
|
import { join as join18, dirname as dirname5 } from "path";
|
|
116611
|
+
|
|
116612
|
+
// src/init/settings-merge.ts
|
|
116613
|
+
var AQE_COMMAND_PATTERNS = [
|
|
116614
|
+
/\baqe\b/i,
|
|
116615
|
+
/\bagentic-qe\b/i,
|
|
116616
|
+
/\bnpx\s+agentic-qe\b/i,
|
|
116617
|
+
/\bnpx\s+@anthropics\/agentic-qe\b/i
|
|
116618
|
+
];
|
|
116619
|
+
function isAqeHookEntry(entry) {
|
|
116620
|
+
const hookEntry = entry;
|
|
116621
|
+
if (!hookEntry?.hooks || !Array.isArray(hookEntry.hooks)) return false;
|
|
116622
|
+
return hookEntry.hooks.some((h66) => {
|
|
116623
|
+
if (!h66.command || typeof h66.command !== "string") return false;
|
|
116624
|
+
return AQE_COMMAND_PATTERNS.some((pattern) => pattern.test(h66.command));
|
|
116625
|
+
});
|
|
116626
|
+
}
|
|
116627
|
+
function mergeHooksSmart(existingHooks, newAqeHooks) {
|
|
116628
|
+
const merged = {};
|
|
116629
|
+
for (const [hookType, newEntries] of Object.entries(newAqeHooks)) {
|
|
116630
|
+
const existing = existingHooks[hookType] || [];
|
|
116631
|
+
const userEntries = Array.isArray(existing) ? existing.filter((entry) => !isAqeHookEntry(entry)) : [];
|
|
116632
|
+
merged[hookType] = [...newEntries, ...userEntries];
|
|
116633
|
+
}
|
|
116634
|
+
for (const [hookType, hookArray] of Object.entries(existingHooks)) {
|
|
116635
|
+
if (!merged[hookType]) {
|
|
116636
|
+
merged[hookType] = hookArray;
|
|
116637
|
+
}
|
|
116638
|
+
}
|
|
116639
|
+
return merged;
|
|
116640
|
+
}
|
|
116641
|
+
function generateAqeEnvVars(config) {
|
|
116642
|
+
const domains = config.domains?.enabled || [];
|
|
116643
|
+
return {
|
|
116644
|
+
AQE_MEMORY_PATH: ".agentic-qe/memory.db",
|
|
116645
|
+
AQE_MEMORY_ENABLED: "true",
|
|
116646
|
+
AQE_LEARNING_ENABLED: config.learning?.enabled ? "true" : "false",
|
|
116647
|
+
AQE_V3_MODE: "true",
|
|
116648
|
+
AQE_V3_DDD_ENABLED: "true",
|
|
116649
|
+
AQE_V3_DOMAINS: domains.join(","),
|
|
116650
|
+
AQE_V3_SWARM_SIZE: String(config.agents?.maxConcurrent ?? 15),
|
|
116651
|
+
AQE_V3_TOPOLOGY: "hierarchical",
|
|
116652
|
+
AQE_V3_SUBLINEAR_ENABLED: "true",
|
|
116653
|
+
AQE_V3_HNSW_ENABLED: config.learning?.hnswConfig ? "true" : "false",
|
|
116654
|
+
AQE_V3_HOOKS_ENABLED: "true",
|
|
116655
|
+
AQE_V3_HOOK_BRIDGE: ".claude/hooks/v3-qe-bridge.sh",
|
|
116656
|
+
AQE_V3_DOMAIN_WORKERS: ".claude/hooks/v3-domain-workers.json",
|
|
116657
|
+
AQE_V3_AISP_ENABLED: "true",
|
|
116658
|
+
AQE_V3_REASONING_BANK: ".agentic-qe/memory.db",
|
|
116659
|
+
AQE_V3_PATTERN_PROMOTION_THRESHOLD: String(config.learning?.promotionThreshold ?? 3),
|
|
116660
|
+
AQE_V3_SUCCESS_RATE_THRESHOLD: String(config.learning?.qualityThreshold ?? 0.7)
|
|
116661
|
+
};
|
|
116662
|
+
}
|
|
116663
|
+
function generateV3SettingsSections(config) {
|
|
116664
|
+
const domains = config.domains?.enabled || [];
|
|
116665
|
+
return {
|
|
116666
|
+
aqe: {
|
|
116667
|
+
version: config.version ?? "3.0.0",
|
|
116668
|
+
initialized: (/* @__PURE__ */ new Date()).toISOString(),
|
|
116669
|
+
hooksConfigured: true
|
|
116670
|
+
},
|
|
116671
|
+
statusLine: {
|
|
116672
|
+
type: "command",
|
|
116673
|
+
command: 'node .claude/helpers/statusline-v3.cjs 2>/dev/null || .claude/statusline-v3.sh 2>/dev/null || echo "\u258A Agentic QE v3"',
|
|
116674
|
+
refreshMs: 5e3,
|
|
116675
|
+
enabled: true
|
|
116676
|
+
},
|
|
116677
|
+
permissions: {
|
|
116678
|
+
allow: [
|
|
116679
|
+
"Bash(npx claude-flow:*)",
|
|
116680
|
+
"Bash(npx @claude-flow/cli:*)",
|
|
116681
|
+
"mcp__claude-flow__:*",
|
|
116682
|
+
"mcp__agentic_qe__*"
|
|
116683
|
+
],
|
|
116684
|
+
deny: [
|
|
116685
|
+
"Bash(rm -rf /)"
|
|
116686
|
+
]
|
|
116687
|
+
},
|
|
116688
|
+
includeCoAuthoredBy: true,
|
|
116689
|
+
v3Configuration: {
|
|
116690
|
+
domains: {
|
|
116691
|
+
total: domains.length,
|
|
116692
|
+
names: domains
|
|
116693
|
+
},
|
|
116694
|
+
swarm: {
|
|
116695
|
+
totalAgents: config.agents?.maxConcurrent ?? 15,
|
|
116696
|
+
topology: "hierarchical",
|
|
116697
|
+
coordination: "queen-led"
|
|
116698
|
+
}
|
|
116699
|
+
},
|
|
116700
|
+
v3Learning: {
|
|
116701
|
+
enabled: config.learning?.enabled ?? true,
|
|
116702
|
+
reasoningBank: {
|
|
116703
|
+
dbPath: ".agentic-qe/memory.db",
|
|
116704
|
+
enableHNSW: !!config.learning?.hnswConfig
|
|
116705
|
+
},
|
|
116706
|
+
patternPromotion: {
|
|
116707
|
+
threshold: config.learning?.promotionThreshold ?? 3,
|
|
116708
|
+
successRateMin: config.learning?.qualityThreshold ?? 0.7
|
|
116709
|
+
}
|
|
116710
|
+
}
|
|
116711
|
+
};
|
|
116712
|
+
}
|
|
116713
|
+
|
|
116714
|
+
// src/init/init-wizard-hooks.ts
|
|
115972
116715
|
async function configureHooks(projectRoot, config) {
|
|
115973
116716
|
if (!config.hooks.claudeCode) {
|
|
115974
116717
|
return false;
|
|
@@ -115987,14 +116730,25 @@ async function configureHooks(projectRoot, config) {
|
|
|
115987
116730
|
settings = {};
|
|
115988
116731
|
}
|
|
115989
116732
|
}
|
|
115990
|
-
const
|
|
116733
|
+
const aqeHooks = {
|
|
115991
116734
|
PreToolUse: [
|
|
115992
116735
|
{
|
|
115993
116736
|
matcher: "^(Write|Edit|MultiEdit)$",
|
|
115994
116737
|
hooks: [
|
|
115995
116738
|
{
|
|
115996
116739
|
type: "command",
|
|
115997
|
-
command: '
|
|
116740
|
+
command: 'npx agentic-qe hooks guard --file "$TOOL_INPUT_file_path" --json',
|
|
116741
|
+
timeout: 3e3,
|
|
116742
|
+
continueOnError: true
|
|
116743
|
+
}
|
|
116744
|
+
]
|
|
116745
|
+
},
|
|
116746
|
+
{
|
|
116747
|
+
matcher: "^(Write|Edit|MultiEdit)$",
|
|
116748
|
+
hooks: [
|
|
116749
|
+
{
|
|
116750
|
+
type: "command",
|
|
116751
|
+
command: 'npx agentic-qe hooks pre-edit --file "$TOOL_INPUT_file_path" --json',
|
|
115998
116752
|
timeout: 5e3,
|
|
115999
116753
|
continueOnError: true
|
|
116000
116754
|
}
|
|
@@ -116005,8 +116759,8 @@ async function configureHooks(projectRoot, config) {
|
|
|
116005
116759
|
hooks: [
|
|
116006
116760
|
{
|
|
116007
116761
|
type: "command",
|
|
116008
|
-
command: '
|
|
116009
|
-
timeout:
|
|
116762
|
+
command: 'npx agentic-qe hooks pre-command --command "$TOOL_INPUT_command" --json',
|
|
116763
|
+
timeout: 3e3,
|
|
116010
116764
|
continueOnError: true
|
|
116011
116765
|
}
|
|
116012
116766
|
]
|
|
@@ -116016,7 +116770,7 @@ async function configureHooks(projectRoot, config) {
|
|
|
116016
116770
|
hooks: [
|
|
116017
116771
|
{
|
|
116018
116772
|
type: "command",
|
|
116019
|
-
command: '
|
|
116773
|
+
command: 'npx agentic-qe hooks pre-task --description "$TOOL_INPUT_prompt" --json',
|
|
116020
116774
|
timeout: 5e3,
|
|
116021
116775
|
continueOnError: true
|
|
116022
116776
|
}
|
|
@@ -116029,7 +116783,7 @@ async function configureHooks(projectRoot, config) {
|
|
|
116029
116783
|
hooks: [
|
|
116030
116784
|
{
|
|
116031
116785
|
type: "command",
|
|
116032
|
-
command: '
|
|
116786
|
+
command: 'npx agentic-qe hooks post-edit --file "$TOOL_INPUT_file_path" --success --json',
|
|
116033
116787
|
timeout: 5e3,
|
|
116034
116788
|
continueOnError: true
|
|
116035
116789
|
}
|
|
@@ -116040,7 +116794,7 @@ async function configureHooks(projectRoot, config) {
|
|
|
116040
116794
|
hooks: [
|
|
116041
116795
|
{
|
|
116042
116796
|
type: "command",
|
|
116043
|
-
command: '
|
|
116797
|
+
command: 'npx agentic-qe hooks post-command --command "$TOOL_INPUT_command" --success --json',
|
|
116044
116798
|
timeout: 5e3,
|
|
116045
116799
|
continueOnError: true
|
|
116046
116800
|
}
|
|
@@ -116051,7 +116805,7 @@ async function configureHooks(projectRoot, config) {
|
|
|
116051
116805
|
hooks: [
|
|
116052
116806
|
{
|
|
116053
116807
|
type: "command",
|
|
116054
|
-
command: '
|
|
116808
|
+
command: 'npx agentic-qe hooks post-task --task-id "$TOOL_RESULT_agent_id" --success --json',
|
|
116055
116809
|
timeout: 5e3,
|
|
116056
116810
|
continueOnError: true
|
|
116057
116811
|
}
|
|
@@ -116063,7 +116817,7 @@ async function configureHooks(projectRoot, config) {
|
|
|
116063
116817
|
hooks: [
|
|
116064
116818
|
{
|
|
116065
116819
|
type: "command",
|
|
116066
|
-
command: '
|
|
116820
|
+
command: 'npx agentic-qe hooks route --task "$PROMPT" --json',
|
|
116067
116821
|
timeout: 5e3,
|
|
116068
116822
|
continueOnError: true
|
|
116069
116823
|
}
|
|
@@ -116075,7 +116829,7 @@ async function configureHooks(projectRoot, config) {
|
|
|
116075
116829
|
hooks: [
|
|
116076
116830
|
{
|
|
116077
116831
|
type: "command",
|
|
116078
|
-
command: '
|
|
116832
|
+
command: 'npx agentic-qe hooks session-start --session-id "$SESSION_ID" --json',
|
|
116079
116833
|
timeout: 1e4,
|
|
116080
116834
|
continueOnError: true
|
|
116081
116835
|
}
|
|
@@ -116087,7 +116841,7 @@ async function configureHooks(projectRoot, config) {
|
|
|
116087
116841
|
hooks: [
|
|
116088
116842
|
{
|
|
116089
116843
|
type: "command",
|
|
116090
|
-
command: "
|
|
116844
|
+
command: "npx agentic-qe hooks session-end --save-state --json",
|
|
116091
116845
|
timeout: 5e3,
|
|
116092
116846
|
continueOnError: true
|
|
116093
116847
|
}
|
|
@@ -116096,33 +116850,22 @@ async function configureHooks(projectRoot, config) {
|
|
|
116096
116850
|
]
|
|
116097
116851
|
};
|
|
116098
116852
|
const existingHooks = settings.hooks || {};
|
|
116099
|
-
|
|
116100
|
-
for (const [hookType, hookArray] of Object.entries(hooks)) {
|
|
116101
|
-
const existing = existingHooks[hookType] || [];
|
|
116102
|
-
mergedHooks[hookType] = [...existing, ...hookArray];
|
|
116103
|
-
}
|
|
116104
|
-
for (const [hookType, hookArray] of Object.entries(existingHooks)) {
|
|
116105
|
-
if (!mergedHooks[hookType]) {
|
|
116106
|
-
mergedHooks[hookType] = hookArray;
|
|
116107
|
-
}
|
|
116108
|
-
}
|
|
116109
|
-
settings.hooks = mergedHooks;
|
|
116853
|
+
settings.hooks = mergeHooksSmart(existingHooks, aqeHooks);
|
|
116110
116854
|
const existingEnv = settings.env || {};
|
|
116111
116855
|
settings.env = {
|
|
116112
116856
|
...existingEnv,
|
|
116113
|
-
|
|
116114
|
-
AQE_V3_MODE: "true",
|
|
116115
|
-
AQE_LEARNING_ENABLED: config.learning.enabled ? "true" : "false"
|
|
116116
|
-
};
|
|
116117
|
-
settings.aqe = {
|
|
116118
|
-
version: config.version,
|
|
116119
|
-
initialized: (/* @__PURE__ */ new Date()).toISOString(),
|
|
116120
|
-
hooksConfigured: true
|
|
116857
|
+
...generateAqeEnvVars(config)
|
|
116121
116858
|
};
|
|
116122
|
-
const
|
|
116123
|
-
|
|
116124
|
-
settings
|
|
116859
|
+
const v3Sections = generateV3SettingsSections(config);
|
|
116860
|
+
for (const [key, value] of Object.entries(v3Sections)) {
|
|
116861
|
+
settings[key] = value;
|
|
116862
|
+
}
|
|
116863
|
+
let existingMcp = settings.enabledMcpjsonServers || [];
|
|
116864
|
+
existingMcp = existingMcp.filter((s70) => s70 !== "aqe");
|
|
116865
|
+
if (!existingMcp.includes("agentic-qe")) {
|
|
116866
|
+
existingMcp.push("agentic-qe");
|
|
116125
116867
|
}
|
|
116868
|
+
settings.enabledMcpjsonServers = existingMcp;
|
|
116126
116869
|
writeFileSync3(settingsPath, JSON.stringify(settings, null, 2), "utf-8");
|
|
116127
116870
|
await installCrossPhaseMemoryHooks(projectRoot);
|
|
116128
116871
|
return true;
|
|
@@ -119121,7 +119864,8 @@ var HooksPhase = class extends BasePhase {
|
|
|
119121
119864
|
return {
|
|
119122
119865
|
configured: false,
|
|
119123
119866
|
settingsPath: "",
|
|
119124
|
-
hookTypes: []
|
|
119867
|
+
hookTypes: [],
|
|
119868
|
+
existingAqeDetected: false
|
|
119125
119869
|
};
|
|
119126
119870
|
}
|
|
119127
119871
|
const claudeDir = join27(projectRoot, ".claude");
|
|
@@ -119138,61 +119882,51 @@ var HooksPhase = class extends BasePhase {
|
|
|
119138
119882
|
settings = {};
|
|
119139
119883
|
}
|
|
119140
119884
|
}
|
|
119141
|
-
const
|
|
119142
|
-
const hookTypes = Object.keys(
|
|
119885
|
+
const aqeHooks = this.generateHooksConfig(config);
|
|
119886
|
+
const hookTypes = Object.keys(aqeHooks);
|
|
119143
119887
|
const existingHooks = settings.hooks || {};
|
|
119144
|
-
const
|
|
119145
|
-
|
|
119146
|
-
|
|
119147
|
-
const newHooks = hookArray;
|
|
119148
|
-
const existingCommands = /* @__PURE__ */ new Set();
|
|
119149
|
-
for (const hook of existing) {
|
|
119150
|
-
const h66 = hook;
|
|
119151
|
-
if (h66.hooks) {
|
|
119152
|
-
for (const innerHook of h66.hooks) {
|
|
119153
|
-
if (innerHook.command) {
|
|
119154
|
-
existingCommands.add(innerHook.command);
|
|
119155
|
-
}
|
|
119156
|
-
}
|
|
119157
|
-
}
|
|
119158
|
-
}
|
|
119159
|
-
const uniqueNewHooks = newHooks.filter((hook) => {
|
|
119160
|
-
if (!hook.hooks) return true;
|
|
119161
|
-
return !hook.hooks.some((h66) => h66.command && existingCommands.has(h66.command));
|
|
119162
|
-
});
|
|
119163
|
-
mergedHooks[hookType] = [...existing, ...uniqueNewHooks];
|
|
119164
|
-
}
|
|
119165
|
-
for (const [hookType, hookArray] of Object.entries(existingHooks)) {
|
|
119166
|
-
if (!mergedHooks[hookType]) {
|
|
119167
|
-
mergedHooks[hookType] = hookArray;
|
|
119168
|
-
}
|
|
119888
|
+
const existingAqeDetected = this.hasExistingAqeHooks(existingHooks);
|
|
119889
|
+
if (existingAqeDetected) {
|
|
119890
|
+
context2.services.log(" Detected existing AQE hooks \u2014 replacing with updated config");
|
|
119169
119891
|
}
|
|
119170
|
-
settings.hooks =
|
|
119892
|
+
settings.hooks = mergeHooksSmart(existingHooks, aqeHooks);
|
|
119171
119893
|
const existingEnv = settings.env || {};
|
|
119172
119894
|
settings.env = {
|
|
119173
119895
|
...existingEnv,
|
|
119174
|
-
|
|
119175
|
-
AQE_V3_MODE: "true",
|
|
119176
|
-
AQE_LEARNING_ENABLED: config.learning.enabled ? "true" : "false"
|
|
119177
|
-
};
|
|
119178
|
-
settings.aqe = {
|
|
119179
|
-
version: config.version,
|
|
119180
|
-
initialized: (/* @__PURE__ */ new Date()).toISOString(),
|
|
119181
|
-
hooksConfigured: true
|
|
119896
|
+
...generateAqeEnvVars(config)
|
|
119182
119897
|
};
|
|
119183
|
-
const
|
|
119184
|
-
|
|
119185
|
-
settings
|
|
119898
|
+
const v3Sections = generateV3SettingsSections(config);
|
|
119899
|
+
for (const [key, value] of Object.entries(v3Sections)) {
|
|
119900
|
+
settings[key] = value;
|
|
119186
119901
|
}
|
|
119902
|
+
let existingMcp = settings.enabledMcpjsonServers || [];
|
|
119903
|
+
existingMcp = existingMcp.filter((s70) => s70 !== "aqe");
|
|
119904
|
+
if (!existingMcp.includes("agentic-qe")) {
|
|
119905
|
+
existingMcp.push("agentic-qe");
|
|
119906
|
+
}
|
|
119907
|
+
settings.enabledMcpjsonServers = existingMcp;
|
|
119187
119908
|
writeFileSync9(settingsPath, JSON.stringify(settings, null, 2), "utf-8");
|
|
119188
119909
|
context2.services.log(` Settings: ${settingsPath}`);
|
|
119189
119910
|
context2.services.log(` Hook types: ${hookTypes.join(", ")}`);
|
|
119190
119911
|
return {
|
|
119191
119912
|
configured: true,
|
|
119192
119913
|
settingsPath,
|
|
119193
|
-
hookTypes
|
|
119914
|
+
hookTypes,
|
|
119915
|
+
existingAqeDetected
|
|
119194
119916
|
};
|
|
119195
119917
|
}
|
|
119918
|
+
/**
|
|
119919
|
+
* Check if existing hooks contain any AQE/agentic-qe entries
|
|
119920
|
+
*/
|
|
119921
|
+
hasExistingAqeHooks(hooks) {
|
|
119922
|
+
for (const hookArray of Object.values(hooks)) {
|
|
119923
|
+
if (!Array.isArray(hookArray)) continue;
|
|
119924
|
+
for (const entry of hookArray) {
|
|
119925
|
+
if (isAqeHookEntry(entry)) return true;
|
|
119926
|
+
}
|
|
119927
|
+
}
|
|
119928
|
+
return false;
|
|
119929
|
+
}
|
|
119196
119930
|
/**
|
|
119197
119931
|
* Generate hooks configuration
|
|
119198
119932
|
*
|
|
@@ -122534,6 +123268,116 @@ function createCommandRegistry(context2, cleanupAndExit2, ensureInitialized2) {
|
|
|
122534
123268
|
// src/cli/commands/test.ts
|
|
122535
123269
|
import { Command } from "commander";
|
|
122536
123270
|
import chalk9 from "chalk";
|
|
123271
|
+
|
|
123272
|
+
// src/cli/utils/file-discovery.ts
|
|
123273
|
+
import { existsSync as existsSync35, readdirSync as readdirSync10, statSync as statSync9 } from "fs";
|
|
123274
|
+
import { join as join37, extname as extname7 } from "path";
|
|
123275
|
+
var SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
123276
|
+
// JavaScript / TypeScript
|
|
123277
|
+
".ts",
|
|
123278
|
+
".tsx",
|
|
123279
|
+
".js",
|
|
123280
|
+
".jsx",
|
|
123281
|
+
".mjs",
|
|
123282
|
+
".cjs",
|
|
123283
|
+
// Python
|
|
123284
|
+
".py",
|
|
123285
|
+
".pyw",
|
|
123286
|
+
// Go
|
|
123287
|
+
".go",
|
|
123288
|
+
// Rust
|
|
123289
|
+
".rs",
|
|
123290
|
+
// Java / Kotlin
|
|
123291
|
+
".java",
|
|
123292
|
+
".kt",
|
|
123293
|
+
".kts",
|
|
123294
|
+
// Ruby
|
|
123295
|
+
".rb",
|
|
123296
|
+
// C#
|
|
123297
|
+
".cs",
|
|
123298
|
+
// PHP
|
|
123299
|
+
".php",
|
|
123300
|
+
// Swift
|
|
123301
|
+
".swift",
|
|
123302
|
+
// C / C++
|
|
123303
|
+
".c",
|
|
123304
|
+
".h",
|
|
123305
|
+
".cpp",
|
|
123306
|
+
".hpp",
|
|
123307
|
+
".cc",
|
|
123308
|
+
// Scala
|
|
123309
|
+
".scala"
|
|
123310
|
+
]);
|
|
123311
|
+
var TEST_PATTERNS = [".test.", ".spec.", "_test.", "_spec."];
|
|
123312
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
123313
|
+
"node_modules",
|
|
123314
|
+
"dist",
|
|
123315
|
+
"build",
|
|
123316
|
+
"coverage",
|
|
123317
|
+
".git",
|
|
123318
|
+
"__pycache__",
|
|
123319
|
+
".venv",
|
|
123320
|
+
"venv",
|
|
123321
|
+
".tox",
|
|
123322
|
+
".mypy_cache",
|
|
123323
|
+
"target",
|
|
123324
|
+
".gradle",
|
|
123325
|
+
"vendor",
|
|
123326
|
+
".bundle",
|
|
123327
|
+
".next",
|
|
123328
|
+
".nuxt",
|
|
123329
|
+
".output"
|
|
123330
|
+
]);
|
|
123331
|
+
function walkSourceFiles(targetPath, options = {}) {
|
|
123332
|
+
const {
|
|
123333
|
+
maxDepth = 6,
|
|
123334
|
+
includeTests = false,
|
|
123335
|
+
testsOnly = false,
|
|
123336
|
+
extraExtensions = []
|
|
123337
|
+
} = options;
|
|
123338
|
+
if (!existsSync35(targetPath)) {
|
|
123339
|
+
return [];
|
|
123340
|
+
}
|
|
123341
|
+
const stat4 = statSync9(targetPath);
|
|
123342
|
+
if (stat4.isFile()) {
|
|
123343
|
+
return [targetPath];
|
|
123344
|
+
}
|
|
123345
|
+
if (!stat4.isDirectory()) {
|
|
123346
|
+
return [];
|
|
123347
|
+
}
|
|
123348
|
+
const extraSet = new Set(extraExtensions.map((e20) => e20.startsWith(".") ? e20 : `.${e20}`));
|
|
123349
|
+
const result = [];
|
|
123350
|
+
function walk(dir, depth) {
|
|
123351
|
+
if (depth > maxDepth) return;
|
|
123352
|
+
let entries;
|
|
123353
|
+
try {
|
|
123354
|
+
entries = readdirSync10(dir, { withFileTypes: true });
|
|
123355
|
+
} catch {
|
|
123356
|
+
return;
|
|
123357
|
+
}
|
|
123358
|
+
for (const entry of entries) {
|
|
123359
|
+
if (entry.isDirectory()) {
|
|
123360
|
+
if (SKIP_DIRS.has(entry.name)) continue;
|
|
123361
|
+
walk(join37(dir, entry.name), depth + 1);
|
|
123362
|
+
} else if (entry.isFile()) {
|
|
123363
|
+
const ext = extname7(entry.name).toLowerCase();
|
|
123364
|
+
const isSourceExt = SOURCE_EXTENSIONS.has(ext) || extraSet.has(ext);
|
|
123365
|
+
if (!isSourceExt) continue;
|
|
123366
|
+
if (entry.name.endsWith(".d.ts")) continue;
|
|
123367
|
+
const isTestFile2 = TEST_PATTERNS.some((p74) => entry.name.includes(p74)) || entry.name.startsWith("test_");
|
|
123368
|
+
if (testsOnly) {
|
|
123369
|
+
if (isTestFile2) result.push(join37(dir, entry.name));
|
|
123370
|
+
} else if (includeTests || !isTestFile2) {
|
|
123371
|
+
result.push(join37(dir, entry.name));
|
|
123372
|
+
}
|
|
123373
|
+
}
|
|
123374
|
+
}
|
|
123375
|
+
}
|
|
123376
|
+
walk(targetPath, 0);
|
|
123377
|
+
return result;
|
|
123378
|
+
}
|
|
123379
|
+
|
|
123380
|
+
// src/cli/commands/test.ts
|
|
122537
123381
|
function createTestCommand(context2, cleanupAndExit2, ensureInitialized2) {
|
|
122538
123382
|
const testCmd = new Command("test").description("Test generation shortcut").argument("<action>", "Action (generate|execute)").argument("[target]", "Target file or directory").option("-f, --framework <framework>", "Test framework", "vitest").option("-t, --type <type>", "Test type (unit|integration|e2e)", "unit").action(async (action, target, options) => {
|
|
122539
123383
|
if (!await ensureInitialized2()) return;
|
|
@@ -122547,33 +123391,9 @@ function createTestCommand(context2, cleanupAndExit2, ensureInitialized2) {
|
|
|
122547
123391
|
console.log(chalk9.red("Test generation domain not available"));
|
|
122548
123392
|
return;
|
|
122549
123393
|
}
|
|
122550
|
-
const fs23 = await import("fs");
|
|
122551
123394
|
const path26 = await import("path");
|
|
122552
123395
|
const targetPath = path26.resolve(target || ".");
|
|
122553
|
-
|
|
122554
|
-
if (fs23.existsSync(targetPath)) {
|
|
122555
|
-
if (fs23.statSync(targetPath).isDirectory()) {
|
|
122556
|
-
const walkDir2 = (dir, depth = 0) => {
|
|
122557
|
-
if (depth > 4) return [];
|
|
122558
|
-
const result2 = [];
|
|
122559
|
-
const items = fs23.readdirSync(dir);
|
|
122560
|
-
for (const item of items) {
|
|
122561
|
-
if (item === "node_modules" || item === "dist" || item === "tests" || item.includes(".test.") || item.includes(".spec.")) continue;
|
|
122562
|
-
const fullPath = path26.join(dir, item);
|
|
122563
|
-
const stat4 = fs23.statSync(fullPath);
|
|
122564
|
-
if (stat4.isDirectory()) {
|
|
122565
|
-
result2.push(...walkDir2(fullPath, depth + 1));
|
|
122566
|
-
} else if (item.endsWith(".ts") && !item.endsWith(".d.ts")) {
|
|
122567
|
-
result2.push(fullPath);
|
|
122568
|
-
}
|
|
122569
|
-
}
|
|
122570
|
-
return result2;
|
|
122571
|
-
};
|
|
122572
|
-
sourceFiles = walkDir2(targetPath);
|
|
122573
|
-
} else {
|
|
122574
|
-
sourceFiles = [targetPath];
|
|
122575
|
-
}
|
|
122576
|
-
}
|
|
123396
|
+
const sourceFiles = walkSourceFiles(targetPath, { includeTests: false });
|
|
122577
123397
|
if (sourceFiles.length === 0) {
|
|
122578
123398
|
console.log(chalk9.yellow("No source files found"));
|
|
122579
123399
|
return;
|
|
@@ -122595,6 +123415,14 @@ function createTestCommand(context2, cleanupAndExit2, ensureInitialized2) {
|
|
|
122595
123415
|
console.log(` ${chalk9.white(test.name)}`);
|
|
122596
123416
|
console.log(chalk9.gray(` Source: ${path26.basename(test.sourceFile)}`));
|
|
122597
123417
|
console.log(chalk9.gray(` Assertions: ${test.assertions}`));
|
|
123418
|
+
if (test.testCode) {
|
|
123419
|
+
console.log(chalk9.gray(` Test File: ${test.testFile}`));
|
|
123420
|
+
console.log(`
|
|
123421
|
+
--- Generated Code ---`);
|
|
123422
|
+
console.log(test.testCode);
|
|
123423
|
+
console.log(`--- End Generated Code ---
|
|
123424
|
+
`);
|
|
123425
|
+
}
|
|
122598
123426
|
}
|
|
122599
123427
|
if (generated.tests.length > 10) {
|
|
122600
123428
|
console.log(chalk9.gray(` ... and ${generated.tests.length - 10} more`));
|
|
@@ -122616,33 +123444,9 @@ function createTestCommand(context2, cleanupAndExit2, ensureInitialized2) {
|
|
|
122616
123444
|
console.log(chalk9.red("Test execution domain not available"));
|
|
122617
123445
|
return;
|
|
122618
123446
|
}
|
|
122619
|
-
const fs23 = await import("fs");
|
|
122620
123447
|
const path26 = await import("path");
|
|
122621
123448
|
const targetPath = path26.resolve(target || ".");
|
|
122622
|
-
|
|
122623
|
-
if (fs23.existsSync(targetPath)) {
|
|
122624
|
-
if (fs23.statSync(targetPath).isDirectory()) {
|
|
122625
|
-
const walkDir2 = (dir, depth = 0) => {
|
|
122626
|
-
if (depth > 4) return [];
|
|
122627
|
-
const result2 = [];
|
|
122628
|
-
const items = fs23.readdirSync(dir);
|
|
122629
|
-
for (const item of items) {
|
|
122630
|
-
if (item === "node_modules" || item === "dist") continue;
|
|
122631
|
-
const fullPath = path26.join(dir, item);
|
|
122632
|
-
const stat4 = fs23.statSync(fullPath);
|
|
122633
|
-
if (stat4.isDirectory()) {
|
|
122634
|
-
result2.push(...walkDir2(fullPath, depth + 1));
|
|
122635
|
-
} else if ((item.includes(".test.") || item.includes(".spec.")) && item.endsWith(".ts")) {
|
|
122636
|
-
result2.push(fullPath);
|
|
122637
|
-
}
|
|
122638
|
-
}
|
|
122639
|
-
return result2;
|
|
122640
|
-
};
|
|
122641
|
-
testFiles = walkDir2(targetPath);
|
|
122642
|
-
} else {
|
|
122643
|
-
testFiles = [targetPath];
|
|
122644
|
-
}
|
|
122645
|
-
}
|
|
123449
|
+
const testFiles = walkSourceFiles(targetPath, { testsOnly: true });
|
|
122646
123450
|
if (testFiles.length === 0) {
|
|
122647
123451
|
console.log(chalk9.yellow("No test files found"));
|
|
122648
123452
|
return;
|
|
@@ -122719,13 +123523,13 @@ var BaseWizardCommand = class {
|
|
|
122719
123523
|
|
|
122720
123524
|
// src/cli/wizards/core/wizard-step.ts
|
|
122721
123525
|
import chalk11 from "chalk";
|
|
122722
|
-
import { existsSync as
|
|
123526
|
+
import { existsSync as existsSync37 } from "fs";
|
|
122723
123527
|
import { resolve as resolve8 } from "path";
|
|
122724
123528
|
|
|
122725
123529
|
// src/cli/wizards/core/wizard-utils.ts
|
|
122726
123530
|
import chalk10 from "chalk";
|
|
122727
|
-
import { existsSync as
|
|
122728
|
-
import { join as
|
|
123531
|
+
import { existsSync as existsSync36, statSync as statSync10 } from "fs";
|
|
123532
|
+
import { join as join38, relative as relative6 } from "path";
|
|
122729
123533
|
var WizardPrompt = class {
|
|
122730
123534
|
/**
|
|
122731
123535
|
* Generic prompt helper - wraps readline.question in a Promise
|
|
@@ -122816,8 +123620,8 @@ var WizardSuggestions = class _WizardSuggestions {
|
|
|
122816
123620
|
const suggestions = [];
|
|
122817
123621
|
const commonDirs = ["src", "lib", "app", "packages", "api"];
|
|
122818
123622
|
for (const dir of commonDirs) {
|
|
122819
|
-
const dirPath =
|
|
122820
|
-
if (
|
|
123623
|
+
const dirPath = join38(cwd, dir);
|
|
123624
|
+
if (existsSync36(dirPath) && statSync10(dirPath).isDirectory()) {
|
|
122821
123625
|
suggestions.push(dir);
|
|
122822
123626
|
}
|
|
122823
123627
|
}
|
|
@@ -122835,8 +123639,8 @@ var WizardSuggestions = class _WizardSuggestions {
|
|
|
122835
123639
|
".nyc_output"
|
|
122836
123640
|
];
|
|
122837
123641
|
for (const loc of coverageLocations) {
|
|
122838
|
-
const locPath =
|
|
122839
|
-
if (
|
|
123642
|
+
const locPath = join38(cwd, loc);
|
|
123643
|
+
if (existsSync36(locPath)) {
|
|
122840
123644
|
suggestions.push(loc);
|
|
122841
123645
|
}
|
|
122842
123646
|
}
|
|
@@ -122858,8 +123662,8 @@ var WizardSuggestions = class _WizardSuggestions {
|
|
|
122858
123662
|
"Dockerfile"
|
|
122859
123663
|
];
|
|
122860
123664
|
for (const file of securityFiles) {
|
|
122861
|
-
const filePath =
|
|
122862
|
-
if (
|
|
123665
|
+
const filePath = join38(cwd, file);
|
|
123666
|
+
if (existsSync36(filePath)) {
|
|
122863
123667
|
suggestions.push(file);
|
|
122864
123668
|
}
|
|
122865
123669
|
}
|
|
@@ -122872,13 +123676,13 @@ var WizardSuggestions = class _WizardSuggestions {
|
|
|
122872
123676
|
const suggestions = [];
|
|
122873
123677
|
const commonDirs = ["src", "lib", "app", "packages"];
|
|
122874
123678
|
for (const dir of commonDirs) {
|
|
122875
|
-
const dirPath =
|
|
122876
|
-
if (
|
|
123679
|
+
const dirPath = join38(cwd, dir);
|
|
123680
|
+
if (existsSync36(dirPath) && statSync10(dirPath).isDirectory()) {
|
|
122877
123681
|
suggestions.push(`${dir}/**/*.ts`);
|
|
122878
123682
|
suggestions.push(dir);
|
|
122879
123683
|
}
|
|
122880
123684
|
}
|
|
122881
|
-
if (
|
|
123685
|
+
if (existsSync36(join38(cwd, "src"))) {
|
|
122882
123686
|
suggestions.push("src/services/**/*.ts");
|
|
122883
123687
|
suggestions.push("src/utils/**/*.ts");
|
|
122884
123688
|
suggestions.push("src/components/**/*.tsx");
|
|
@@ -122890,12 +123694,12 @@ var WizardSuggestions = class _WizardSuggestions {
|
|
|
122890
123694
|
*/
|
|
122891
123695
|
static checkPatternsExist(cwd) {
|
|
122892
123696
|
const patternLocations = [
|
|
122893
|
-
|
|
122894
|
-
|
|
122895
|
-
|
|
122896
|
-
|
|
123697
|
+
join38(cwd, ".agentic-qe", "patterns"),
|
|
123698
|
+
join38(cwd, ".agentic-qe", "memory.db"),
|
|
123699
|
+
join38(cwd, ".aqe", "patterns"),
|
|
123700
|
+
join38(cwd, "data", "patterns")
|
|
122897
123701
|
];
|
|
122898
|
-
return patternLocations.some((loc) =>
|
|
123702
|
+
return patternLocations.some((loc) => existsSync36(loc));
|
|
122899
123703
|
}
|
|
122900
123704
|
};
|
|
122901
123705
|
var WizardFormat = class {
|
|
@@ -123172,7 +123976,7 @@ var PathInputStep = class extends BaseWizardCommand {
|
|
|
123172
123976
|
async execute(context2) {
|
|
123173
123977
|
if (context2.nonInteractive) {
|
|
123174
123978
|
const resolved2 = resolve8(context2.cwd, this.defaultValue);
|
|
123175
|
-
return this.success(
|
|
123979
|
+
return this.success(existsSync37(resolved2) ? resolved2 : context2.cwd);
|
|
123176
123980
|
}
|
|
123177
123981
|
WizardPrompt.printStepHeader(this.stepNumber, this.title, this.description);
|
|
123178
123982
|
if (this.examples) {
|
|
@@ -123195,7 +123999,7 @@ var PathInputStep = class extends BaseWizardCommand {
|
|
|
123195
123999
|
);
|
|
123196
124000
|
const value = input.trim() || this.defaultValue;
|
|
123197
124001
|
const resolved = resolve8(context2.cwd, value);
|
|
123198
|
-
if (this.validatePath && !
|
|
124002
|
+
if (this.validatePath && !existsSync37(resolved)) {
|
|
123199
124003
|
console.log(chalk11.yellow(` Warning: '${value}' does not exist, using current directory.`));
|
|
123200
124004
|
return this.success(context2.cwd);
|
|
123201
124005
|
}
|
|
@@ -123547,30 +124351,7 @@ function createCoverageCommand(context2, cleanupAndExit2, ensureInitialized2) {
|
|
|
123547
124351
|
const fs23 = await import("fs");
|
|
123548
124352
|
const path26 = await import("path");
|
|
123549
124353
|
const targetPath = path26.resolve(analyzeTarget);
|
|
123550
|
-
|
|
123551
|
-
if (fs23.existsSync(targetPath)) {
|
|
123552
|
-
if (fs23.statSync(targetPath).isDirectory()) {
|
|
123553
|
-
const walkDir2 = (dir, depth = 0) => {
|
|
123554
|
-
if (depth > 4) return [];
|
|
123555
|
-
const result2 = [];
|
|
123556
|
-
const items = fs23.readdirSync(dir);
|
|
123557
|
-
for (const item of items) {
|
|
123558
|
-
if (item === "node_modules" || item === "dist") continue;
|
|
123559
|
-
const fullPath = path26.join(dir, item);
|
|
123560
|
-
const stat4 = fs23.statSync(fullPath);
|
|
123561
|
-
if (stat4.isDirectory()) {
|
|
123562
|
-
result2.push(...walkDir2(fullPath, depth + 1));
|
|
123563
|
-
} else if (item.endsWith(".ts") && !item.endsWith(".d.ts")) {
|
|
123564
|
-
result2.push(fullPath);
|
|
123565
|
-
}
|
|
123566
|
-
}
|
|
123567
|
-
return result2;
|
|
123568
|
-
};
|
|
123569
|
-
sourceFiles = walkDir2(targetPath);
|
|
123570
|
-
} else {
|
|
123571
|
-
sourceFiles = [targetPath];
|
|
123572
|
-
}
|
|
123573
|
-
}
|
|
124354
|
+
const sourceFiles = walkSourceFiles(targetPath, { includeTests: false });
|
|
123574
124355
|
if (sourceFiles.length === 0) {
|
|
123575
124356
|
console.log(chalk13.yellow("No source files found"));
|
|
123576
124357
|
return;
|
|
@@ -123756,33 +124537,9 @@ function createSecurityCommand(context2, cleanupAndExit2, ensureInitialized2) {
|
|
|
123756
124537
|
console.log(chalk15.red("Security domain not available"));
|
|
123757
124538
|
return;
|
|
123758
124539
|
}
|
|
123759
|
-
const fs23 = await import("fs");
|
|
123760
124540
|
const path26 = await import("path");
|
|
123761
124541
|
const targetPath = path26.resolve(options.target);
|
|
123762
|
-
|
|
123763
|
-
if (fs23.existsSync(targetPath)) {
|
|
123764
|
-
if (fs23.statSync(targetPath).isDirectory()) {
|
|
123765
|
-
const walkDir2 = (dir, depth = 0) => {
|
|
123766
|
-
if (depth > 4) return [];
|
|
123767
|
-
const result = [];
|
|
123768
|
-
const items = fs23.readdirSync(dir);
|
|
123769
|
-
for (const item of items) {
|
|
123770
|
-
if (item === "node_modules" || item === "dist") continue;
|
|
123771
|
-
const fullPath = path26.join(dir, item);
|
|
123772
|
-
const stat4 = fs23.statSync(fullPath);
|
|
123773
|
-
if (stat4.isDirectory()) {
|
|
123774
|
-
result.push(...walkDir2(fullPath, depth + 1));
|
|
123775
|
-
} else if (item.endsWith(".ts") && !item.endsWith(".d.ts")) {
|
|
123776
|
-
result.push(fullPath);
|
|
123777
|
-
}
|
|
123778
|
-
}
|
|
123779
|
-
return result;
|
|
123780
|
-
};
|
|
123781
|
-
files = walkDir2(targetPath);
|
|
123782
|
-
} else {
|
|
123783
|
-
files = [targetPath];
|
|
123784
|
-
}
|
|
123785
|
-
}
|
|
124542
|
+
const files = walkSourceFiles(targetPath, { includeTests: true });
|
|
123786
124543
|
if (files.length === 0) {
|
|
123787
124544
|
console.log(chalk15.yellow("No files found to scan"));
|
|
123788
124545
|
return;
|
|
@@ -123857,37 +124614,15 @@ function createCodeCommand(context2, cleanupAndExit2, ensureInitialized2) {
|
|
|
123857
124614
|
console.log(chalk16.red("Code intelligence domain not available"));
|
|
123858
124615
|
return;
|
|
123859
124616
|
}
|
|
123860
|
-
const fs23 = await import("fs");
|
|
123861
124617
|
const path26 = await import("path");
|
|
123862
124618
|
if (action === "index") {
|
|
123863
124619
|
console.log(chalk16.blue(`
|
|
123864
124620
|
Indexing codebase at ${target || "."}...
|
|
123865
124621
|
`));
|
|
123866
124622
|
const targetPath = path26.resolve(target || ".");
|
|
123867
|
-
|
|
123868
|
-
|
|
123869
|
-
|
|
123870
|
-
const walkDir2 = (dir, depth = 0) => {
|
|
123871
|
-
if (depth > 4) return [];
|
|
123872
|
-
const result2 = [];
|
|
123873
|
-
const items = fs23.readdirSync(dir);
|
|
123874
|
-
for (const item of items) {
|
|
123875
|
-
if (item === "node_modules" || item === "dist") continue;
|
|
123876
|
-
const fullPath = path26.join(dir, item);
|
|
123877
|
-
const stat4 = fs23.statSync(fullPath);
|
|
123878
|
-
if (stat4.isDirectory()) {
|
|
123879
|
-
result2.push(...walkDir2(fullPath, depth + 1));
|
|
123880
|
-
} else if (item.endsWith(".ts") && !item.endsWith(".d.ts")) {
|
|
123881
|
-
result2.push(fullPath);
|
|
123882
|
-
}
|
|
123883
|
-
}
|
|
123884
|
-
return result2;
|
|
123885
|
-
};
|
|
123886
|
-
paths = walkDir2(targetPath);
|
|
123887
|
-
} else {
|
|
123888
|
-
paths = [targetPath];
|
|
123889
|
-
}
|
|
123890
|
-
}
|
|
124623
|
+
const paths = walkSourceFiles(targetPath, {
|
|
124624
|
+
includeTests: options.includeTests || false
|
|
124625
|
+
});
|
|
123891
124626
|
console.log(chalk16.gray(` Found ${paths.length} files to index...
|
|
123892
124627
|
`));
|
|
123893
124628
|
const result = await codeAPI.index({
|
|
@@ -123946,30 +124681,7 @@ function createCodeCommand(context2, cleanupAndExit2, ensureInitialized2) {
|
|
|
123946
124681
|
Analyzing impact for ${target || "recent changes"}...
|
|
123947
124682
|
`));
|
|
123948
124683
|
const targetPath = path26.resolve(target || ".");
|
|
123949
|
-
|
|
123950
|
-
if (fs23.existsSync(targetPath)) {
|
|
123951
|
-
if (fs23.statSync(targetPath).isFile()) {
|
|
123952
|
-
changedFiles = [targetPath];
|
|
123953
|
-
} else {
|
|
123954
|
-
const walkDir2 = (dir, depth = 0) => {
|
|
123955
|
-
if (depth > 2) return [];
|
|
123956
|
-
const result2 = [];
|
|
123957
|
-
const items = fs23.readdirSync(dir);
|
|
123958
|
-
for (const item of items) {
|
|
123959
|
-
if (item === "node_modules" || item === "dist") continue;
|
|
123960
|
-
const fullPath = path26.join(dir, item);
|
|
123961
|
-
const stat4 = fs23.statSync(fullPath);
|
|
123962
|
-
if (stat4.isDirectory()) {
|
|
123963
|
-
result2.push(...walkDir2(fullPath, depth + 1));
|
|
123964
|
-
} else if (item.endsWith(".ts") && !item.endsWith(".d.ts")) {
|
|
123965
|
-
result2.push(fullPath);
|
|
123966
|
-
}
|
|
123967
|
-
}
|
|
123968
|
-
return result2;
|
|
123969
|
-
};
|
|
123970
|
-
changedFiles = walkDir2(targetPath).slice(0, 10);
|
|
123971
|
-
}
|
|
123972
|
-
}
|
|
124684
|
+
const changedFiles = walkSourceFiles(targetPath, { maxDepth: 2 }).slice(0, 10);
|
|
123973
124685
|
const result = await codeAPI.analyzeImpact({
|
|
123974
124686
|
changedFiles,
|
|
123975
124687
|
depth: parseInt(options.depth),
|
|
@@ -124015,30 +124727,7 @@ function createCodeCommand(context2, cleanupAndExit2, ensureInitialized2) {
|
|
|
124015
124727
|
Mapping dependencies for ${target || "."}...
|
|
124016
124728
|
`));
|
|
124017
124729
|
const targetPath = path26.resolve(target || ".");
|
|
124018
|
-
|
|
124019
|
-
if (fs23.existsSync(targetPath)) {
|
|
124020
|
-
if (fs23.statSync(targetPath).isFile()) {
|
|
124021
|
-
files = [targetPath];
|
|
124022
|
-
} else {
|
|
124023
|
-
const walkDir2 = (dir, depth = 0) => {
|
|
124024
|
-
if (depth > 2) return [];
|
|
124025
|
-
const result2 = [];
|
|
124026
|
-
const items = fs23.readdirSync(dir);
|
|
124027
|
-
for (const item of items) {
|
|
124028
|
-
if (item === "node_modules" || item === "dist") continue;
|
|
124029
|
-
const fullPath = path26.join(dir, item);
|
|
124030
|
-
const stat4 = fs23.statSync(fullPath);
|
|
124031
|
-
if (stat4.isDirectory()) {
|
|
124032
|
-
result2.push(...walkDir2(fullPath, depth + 1));
|
|
124033
|
-
} else if (item.endsWith(".ts") && !item.endsWith(".d.ts")) {
|
|
124034
|
-
result2.push(fullPath);
|
|
124035
|
-
}
|
|
124036
|
-
}
|
|
124037
|
-
return result2;
|
|
124038
|
-
};
|
|
124039
|
-
files = walkDir2(targetPath).slice(0, 50);
|
|
124040
|
-
}
|
|
124041
|
-
}
|
|
124730
|
+
const files = walkSourceFiles(targetPath, { maxDepth: 2 }).slice(0, 50);
|
|
124042
124731
|
const result = await codeAPI.mapDependencies({
|
|
124043
124732
|
files,
|
|
124044
124733
|
direction: "both",
|
|
@@ -126284,8 +126973,8 @@ import chalk20 from "chalk";
|
|
|
126284
126973
|
// src/init/fleet-integration.ts
|
|
126285
126974
|
init_error_utils();
|
|
126286
126975
|
import chalk19 from "chalk";
|
|
126287
|
-
import { existsSync as
|
|
126288
|
-
import { join as
|
|
126976
|
+
import { existsSync as existsSync38 } from "fs";
|
|
126977
|
+
import { join as join40 } from "path";
|
|
126289
126978
|
var FleetInitEnhancer = class {
|
|
126290
126979
|
projectRoot;
|
|
126291
126980
|
options;
|
|
@@ -126397,7 +127086,7 @@ var FleetInitEnhancer = class {
|
|
|
126397
127086
|
});
|
|
126398
127087
|
console.log(chalk19.gray(` Indexing ${files.length} files...`));
|
|
126399
127088
|
const result = await kgService.index({
|
|
126400
|
-
paths: files.map((f74) =>
|
|
127089
|
+
paths: files.map((f74) => join40(this.projectRoot, f74)),
|
|
126401
127090
|
incremental: false,
|
|
126402
127091
|
includeTests: true
|
|
126403
127092
|
});
|
|
@@ -126432,8 +127121,8 @@ var FleetInitEnhancer = class {
|
|
|
126432
127121
|
* Checks the memory database for code-intelligence:kg namespace entries
|
|
126433
127122
|
*/
|
|
126434
127123
|
async hasCodeIntelligenceIndex() {
|
|
126435
|
-
const dbPath =
|
|
126436
|
-
if (!
|
|
127124
|
+
const dbPath = join40(this.projectRoot, ".agentic-qe", "memory.db");
|
|
127125
|
+
if (!existsSync38(dbPath)) {
|
|
126437
127126
|
return false;
|
|
126438
127127
|
}
|
|
126439
127128
|
try {
|
|
@@ -126453,7 +127142,7 @@ var FleetInitEnhancer = class {
|
|
|
126453
127142
|
* Get count of knowledge graph entries
|
|
126454
127143
|
*/
|
|
126455
127144
|
async getKGEntryCount() {
|
|
126456
|
-
const dbPath =
|
|
127145
|
+
const dbPath = join40(this.projectRoot, ".agentic-qe", "memory.db");
|
|
126457
127146
|
try {
|
|
126458
127147
|
const Database = (await Promise.resolve().then(() => (init_better_sqlite3(), better_sqlite3_exports))).default;
|
|
126459
127148
|
const db = new Database(dbPath);
|
|
@@ -127959,7 +128648,7 @@ function createParallelEvalRunner(skillValidationLearner, config = {}, executor2
|
|
|
127959
128648
|
|
|
127960
128649
|
// src/validation/validation-result-aggregator.ts
|
|
127961
128650
|
init_safe_json();
|
|
127962
|
-
import { readFileSync as readFileSync28, writeFileSync as writeFileSync17, existsSync as
|
|
128651
|
+
import { readFileSync as readFileSync28, writeFileSync as writeFileSync17, existsSync as existsSync40 } from "fs";
|
|
127963
128652
|
var DEFAULT_CONFIG60 = {
|
|
127964
128653
|
varianceThreshold: 0.04,
|
|
127965
128654
|
// ~20% standard deviation
|
|
@@ -128304,7 +128993,7 @@ var ValidationResultAggregator = class {
|
|
|
128304
128993
|
* Update trust tier manifest with new pass rates
|
|
128305
128994
|
*/
|
|
128306
128995
|
async updateManifest(report) {
|
|
128307
|
-
if (!
|
|
128996
|
+
if (!existsSync40(this.manifestPath)) {
|
|
128308
128997
|
throw new Error(`Manifest file not found: ${this.manifestPath}`);
|
|
128309
128998
|
}
|
|
128310
128999
|
const manifest = safeJsonParse(readFileSync28(this.manifestPath, "utf-8"));
|
|
@@ -130091,18 +130780,18 @@ function formatDuration2(ms) {
|
|
|
130091
130780
|
// src/cli/commands/validate.ts
|
|
130092
130781
|
init_safe_json();
|
|
130093
130782
|
import { Command as Command10 } from "commander";
|
|
130094
|
-
import { readFileSync as readFileSync29, writeFileSync as writeFileSync18, existsSync as
|
|
130095
|
-
import { join as
|
|
130783
|
+
import { readFileSync as readFileSync29, writeFileSync as writeFileSync18, existsSync as existsSync41, readdirSync as readdirSync11, statSync as statSync12 } from "fs";
|
|
130784
|
+
import { join as join42, resolve as resolve9, basename as basename7 } from "path";
|
|
130096
130785
|
import chalk22 from "chalk";
|
|
130097
130786
|
function loadValidationResults(inputPath) {
|
|
130098
130787
|
const resolvedPath = resolve9(inputPath);
|
|
130099
|
-
if (!
|
|
130788
|
+
if (!existsSync41(resolvedPath)) {
|
|
130100
130789
|
throw new Error(`Input path not found: ${resolvedPath}`);
|
|
130101
130790
|
}
|
|
130102
|
-
const stat4 =
|
|
130791
|
+
const stat4 = statSync12(resolvedPath);
|
|
130103
130792
|
if (stat4.isDirectory()) {
|
|
130104
130793
|
const results = [];
|
|
130105
|
-
const files =
|
|
130794
|
+
const files = readdirSync11(resolvedPath).filter((f74) => f74.endsWith(".json")).map((f74) => join42(resolvedPath, f74));
|
|
130106
130795
|
for (const file of files) {
|
|
130107
130796
|
try {
|
|
130108
130797
|
const content = safeJsonParse(readFileSync29(file, "utf-8"));
|
|
@@ -130152,15 +130841,15 @@ function createMockLearner() {
|
|
|
130152
130841
|
function getDefaultManifestPath() {
|
|
130153
130842
|
const cwd = process.cwd();
|
|
130154
130843
|
const candidates = [
|
|
130155
|
-
|
|
130156
|
-
|
|
130844
|
+
join42(cwd, ".claude/skills/trust-tier-manifest.json"),
|
|
130845
|
+
join42(cwd, ".claude/skills/skills-manifest.json")
|
|
130157
130846
|
];
|
|
130158
130847
|
for (const candidate of candidates) {
|
|
130159
|
-
if (
|
|
130848
|
+
if (existsSync41(candidate)) {
|
|
130160
130849
|
return candidate;
|
|
130161
130850
|
}
|
|
130162
130851
|
}
|
|
130163
|
-
return
|
|
130852
|
+
return join42(cwd, ".claude/skills/trust-tier-manifest.json");
|
|
130164
130853
|
}
|
|
130165
130854
|
function writeReport(report, aggregator, options) {
|
|
130166
130855
|
const format = options.format || "markdown";
|
|
@@ -136251,8 +136940,8 @@ async function createCoherenceService(wasmLoader2, config, logger19) {
|
|
|
136251
136940
|
init_error_utils();
|
|
136252
136941
|
import { createRequire as createRequire12 } from "node:module";
|
|
136253
136942
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
136254
|
-
import { dirname as dirname13, join as
|
|
136255
|
-
import { readFileSync as readFileSync32, existsSync as
|
|
136943
|
+
import { dirname as dirname13, join as join44 } from "node:path";
|
|
136944
|
+
import { readFileSync as readFileSync32, existsSync as existsSync44 } from "node:fs";
|
|
136256
136945
|
var FALLBACK_RETRY_DELAYS_MS = [1e3, 2e3, 4e3];
|
|
136257
136946
|
var WasmLoader = class {
|
|
136258
136947
|
state = "unloaded";
|
|
@@ -136510,15 +137199,15 @@ var WasmLoader = class {
|
|
|
136510
137199
|
(() => {
|
|
136511
137200
|
try {
|
|
136512
137201
|
const modulePath = require5.resolve("prime-radiant-advanced-wasm");
|
|
136513
|
-
return
|
|
137202
|
+
return join44(dirname13(modulePath), "prime_radiant_advanced_wasm_bg.wasm");
|
|
136514
137203
|
} catch {
|
|
136515
137204
|
return null;
|
|
136516
137205
|
}
|
|
136517
137206
|
})(),
|
|
136518
|
-
|
|
137207
|
+
join44(process.cwd(), "node_modules/prime-radiant-advanced-wasm/prime_radiant_advanced_wasm_bg.wasm")
|
|
136519
137208
|
].filter((p74) => p74 !== null);
|
|
136520
137209
|
for (const path26 of wasmPaths) {
|
|
136521
|
-
if (
|
|
137210
|
+
if (existsSync44(path26)) {
|
|
136522
137211
|
return true;
|
|
136523
137212
|
}
|
|
136524
137213
|
}
|
|
@@ -136769,19 +137458,19 @@ var WasmLoader = class {
|
|
|
136769
137458
|
(() => {
|
|
136770
137459
|
try {
|
|
136771
137460
|
const modulePath = require5.resolve("prime-radiant-advanced-wasm");
|
|
136772
|
-
return
|
|
137461
|
+
return join44(dirname13(modulePath), "prime_radiant_advanced_wasm_bg.wasm");
|
|
136773
137462
|
} catch {
|
|
136774
137463
|
return null;
|
|
136775
137464
|
}
|
|
136776
137465
|
})(),
|
|
136777
137466
|
// Direct node_modules path from current file
|
|
136778
|
-
|
|
137467
|
+
join44(dirname13(fileURLToPath6(import.meta.url)), "../../../../node_modules/prime-radiant-advanced-wasm/prime_radiant_advanced_wasm_bg.wasm"),
|
|
136779
137468
|
// Workspace root
|
|
136780
|
-
|
|
137469
|
+
join44(process.cwd(), "node_modules/prime-radiant-advanced-wasm/prime_radiant_advanced_wasm_bg.wasm")
|
|
136781
137470
|
].filter((p74) => p74 !== null);
|
|
136782
137471
|
let wasmPath = null;
|
|
136783
137472
|
for (const path26 of wasmPaths) {
|
|
136784
|
-
if (
|
|
137473
|
+
if (existsSync44(path26)) {
|
|
136785
137474
|
wasmPath = path26;
|
|
136786
137475
|
break;
|
|
136787
137476
|
}
|
|
@@ -137156,6 +137845,34 @@ async function incrementDreamExperience(memoryBackend2) {
|
|
|
137156
137845
|
return 0;
|
|
137157
137846
|
}
|
|
137158
137847
|
}
|
|
137848
|
+
async function persistCommandExperience(opts) {
|
|
137849
|
+
try {
|
|
137850
|
+
const { getUnifiedMemory: getUnifiedMemory2 } = await Promise.resolve().then(() => (init_unified_memory(), unified_memory_exports));
|
|
137851
|
+
const um = getUnifiedMemory2();
|
|
137852
|
+
if (!um.isInitialized()) {
|
|
137853
|
+
await um.initialize();
|
|
137854
|
+
}
|
|
137855
|
+
const db = um.getDatabase();
|
|
137856
|
+
const id = `cli-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
137857
|
+
db.prepare(`
|
|
137858
|
+
INSERT OR REPLACE INTO captured_experiences
|
|
137859
|
+
(id, task, agent, domain, success, quality, duration_ms,
|
|
137860
|
+
started_at, completed_at, source)
|
|
137861
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'), ?)
|
|
137862
|
+
`).run(
|
|
137863
|
+
id,
|
|
137864
|
+
opts.task.slice(0, 500),
|
|
137865
|
+
opts.agent,
|
|
137866
|
+
opts.domain,
|
|
137867
|
+
opts.success ? 1 : 0,
|
|
137868
|
+
opts.success ? 0.7 : 0.3,
|
|
137869
|
+
opts.durationMs || 0,
|
|
137870
|
+
opts.source
|
|
137871
|
+
);
|
|
137872
|
+
} catch (error) {
|
|
137873
|
+
console.error(chalk27.dim(`[hooks] persistCommandExperience: ${error instanceof Error ? error.message : "unknown"}`));
|
|
137874
|
+
}
|
|
137875
|
+
}
|
|
137159
137876
|
function printGuidance(guidance) {
|
|
137160
137877
|
if (guidance.length === 0) {
|
|
137161
137878
|
console.log(chalk27.dim(" No specific guidance"));
|
|
@@ -137237,14 +137954,39 @@ Examples:
|
|
|
137237
137954
|
try {
|
|
137238
137955
|
const { hookRegistry } = await getHooksSystem();
|
|
137239
137956
|
const success = options.success || !options.failure;
|
|
137957
|
+
const filePath = options.file || "";
|
|
137958
|
+
const fileName = filePath.split("/").pop() || "unknown";
|
|
137959
|
+
const isTestFile2 = /\.(test|spec)\.(ts|js|tsx|jsx)$/.test(fileName);
|
|
137960
|
+
const domain = isTestFile2 ? "test-generation" : "code-intelligence";
|
|
137961
|
+
const syntheticPatternId = options.patternId || `edit:${domain}:${fileName}`;
|
|
137240
137962
|
const results = await hookRegistry.emit(QE_HOOK_EVENTS.PostTestGeneration, {
|
|
137241
137963
|
targetFile: options.file,
|
|
137242
137964
|
success,
|
|
137243
|
-
patternId:
|
|
137965
|
+
patternId: syntheticPatternId,
|
|
137244
137966
|
generatedTests: null,
|
|
137245
137967
|
testCount: 0
|
|
137246
137968
|
});
|
|
137247
137969
|
const result = results[0] || { success: true, patternsLearned: 0 };
|
|
137970
|
+
try {
|
|
137971
|
+
const { reasoningBank } = await getHooksSystem();
|
|
137972
|
+
await reasoningBank.recordOutcome({
|
|
137973
|
+
patternId: syntheticPatternId,
|
|
137974
|
+
success,
|
|
137975
|
+
metrics: { executionTimeMs: 0 },
|
|
137976
|
+
feedback: `Edit ${success ? "succeeded" : "failed"}: ${filePath}`
|
|
137977
|
+
});
|
|
137978
|
+
} catch {
|
|
137979
|
+
}
|
|
137980
|
+
try {
|
|
137981
|
+
await persistCommandExperience({
|
|
137982
|
+
task: `edit: ${filePath}`,
|
|
137983
|
+
agent: "cli-hook",
|
|
137984
|
+
domain,
|
|
137985
|
+
success,
|
|
137986
|
+
source: "cli-hook-post-edit"
|
|
137987
|
+
});
|
|
137988
|
+
} catch {
|
|
137989
|
+
}
|
|
137248
137990
|
let dreamTriggered = false;
|
|
137249
137991
|
try {
|
|
137250
137992
|
const projectRoot = findProjectRoot();
|
|
@@ -137314,6 +138056,45 @@ Examples:
|
|
|
137314
138056
|
printGuidance(routing.guidance);
|
|
137315
138057
|
console.log(chalk27.bold("\n\u{1F4D6} Reasoning:"), chalk27.dim(routing.reasoning));
|
|
137316
138058
|
}
|
|
138059
|
+
try {
|
|
138060
|
+
const { getUnifiedMemory: getUnifiedMemory2 } = await Promise.resolve().then(() => (init_unified_memory(), unified_memory_exports));
|
|
138061
|
+
const um = getUnifiedMemory2();
|
|
138062
|
+
if (!um.isInitialized()) {
|
|
138063
|
+
await um.initialize();
|
|
138064
|
+
}
|
|
138065
|
+
const db = um.getDatabase();
|
|
138066
|
+
const outcomeId = `route-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
138067
|
+
db.prepare(`
|
|
138068
|
+
INSERT OR REPLACE INTO routing_outcomes (
|
|
138069
|
+
id, task_json, decision_json, used_agent,
|
|
138070
|
+
followed_recommendation, success, quality_score,
|
|
138071
|
+
duration_ms, error
|
|
138072
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
138073
|
+
`).run(
|
|
138074
|
+
outcomeId,
|
|
138075
|
+
JSON.stringify({ description: options.task, domain: options.domain }),
|
|
138076
|
+
JSON.stringify({
|
|
138077
|
+
recommended: routing.recommendedAgent,
|
|
138078
|
+
confidence: routing.confidence,
|
|
138079
|
+
alternatives: routing.alternatives
|
|
138080
|
+
}),
|
|
138081
|
+
routing.recommendedAgent,
|
|
138082
|
+
1,
|
|
138083
|
+
// followed_recommendation = true (recommendation stage)
|
|
138084
|
+
1,
|
|
138085
|
+
// success = true (routing itself succeeded)
|
|
138086
|
+
routing.confidence,
|
|
138087
|
+
0,
|
|
138088
|
+
// duration not tracked at routing stage
|
|
138089
|
+
null
|
|
138090
|
+
);
|
|
138091
|
+
const projectRoot = findProjectRoot();
|
|
138092
|
+
const dataDir = path22.join(projectRoot, ".agentic-qe");
|
|
138093
|
+
const memoryBackend2 = await createHybridBackendWithTimeout(dataDir);
|
|
138094
|
+
await incrementDreamExperience(memoryBackend2);
|
|
138095
|
+
} catch (persistError) {
|
|
138096
|
+
console.error(chalk27.dim(`[hooks] route persist: ${persistError instanceof Error ? persistError.message : "unknown"}`));
|
|
138097
|
+
}
|
|
137317
138098
|
process.exit(0);
|
|
137318
138099
|
} catch (error) {
|
|
137319
138100
|
printError(`route failed: ${error instanceof Error ? error.message : "unknown"}`);
|
|
@@ -137828,12 +138609,57 @@ Registered: ${events.length}/${Object.keys(QE_HOOK_EVENTS).length}`)
|
|
|
137828
138609
|
try {
|
|
137829
138610
|
const success = options.success === "true" || options.success === true;
|
|
137830
138611
|
const exitCode = options.exitCode ? parseInt(options.exitCode, 10) : success ? 0 : 1;
|
|
138612
|
+
const command = (options.command || "").substring(0, 200);
|
|
138613
|
+
const isTestCmd = /\b(test|vitest|jest|pytest|mocha)\b/i.test(command);
|
|
138614
|
+
const isBuildCmd = /\b(build|compile|tsc)\b/i.test(command);
|
|
138615
|
+
const isLintCmd = /\b(lint|eslint|prettier)\b/i.test(command);
|
|
138616
|
+
let patternsLearned = 0;
|
|
138617
|
+
let experienceRecorded = false;
|
|
138618
|
+
try {
|
|
138619
|
+
const { reasoningBank } = await getHooksSystem();
|
|
138620
|
+
if (isTestCmd) {
|
|
138621
|
+
const { hookRegistry } = await getHooksSystem();
|
|
138622
|
+
await hookRegistry.emit(QE_HOOK_EVENTS.TestExecutionResult, {
|
|
138623
|
+
runId: `cmd-${Date.now()}`,
|
|
138624
|
+
patternId: `cmd:test:${command.split(/\s+/).slice(0, 3).join("-")}`,
|
|
138625
|
+
passed: success ? 1 : 0,
|
|
138626
|
+
failed: success ? 0 : 1,
|
|
138627
|
+
duration: 0,
|
|
138628
|
+
flaky: false
|
|
138629
|
+
});
|
|
138630
|
+
}
|
|
138631
|
+
const cmdSlug = command.replace(/[^a-zA-Z0-9]/g, "-").slice(0, 80);
|
|
138632
|
+
const domain = isTestCmd ? "test-execution" : isBuildCmd ? "code-intelligence" : isLintCmd ? "quality-assessment" : "code-intelligence";
|
|
138633
|
+
await reasoningBank.recordOutcome({
|
|
138634
|
+
patternId: `cmd:${cmdSlug}`,
|
|
138635
|
+
success,
|
|
138636
|
+
metrics: { executionTimeMs: 0 },
|
|
138637
|
+
feedback: `Command: ${command}, exit: ${exitCode}`
|
|
138638
|
+
});
|
|
138639
|
+
patternsLearned = 1;
|
|
138640
|
+
await persistCommandExperience({
|
|
138641
|
+
task: `bash: ${command}`,
|
|
138642
|
+
agent: "cli-hook",
|
|
138643
|
+
domain,
|
|
138644
|
+
success,
|
|
138645
|
+
source: "cli-hook-post-command"
|
|
138646
|
+
});
|
|
138647
|
+
experienceRecorded = true;
|
|
138648
|
+
const projectRoot = findProjectRoot();
|
|
138649
|
+
const dataDir = path22.join(projectRoot, ".agentic-qe");
|
|
138650
|
+
const memoryBackend2 = await createHybridBackendWithTimeout(dataDir);
|
|
138651
|
+
await incrementDreamExperience(memoryBackend2);
|
|
138652
|
+
} catch (initError) {
|
|
138653
|
+
console.error(chalk27.dim(`[hooks] post-command learning: ${initError instanceof Error ? initError.message : "unknown"}`));
|
|
138654
|
+
}
|
|
137831
138655
|
if (options.json) {
|
|
137832
138656
|
printJson({
|
|
137833
138657
|
success: true,
|
|
137834
|
-
command:
|
|
138658
|
+
command: command.substring(0, 100),
|
|
137835
138659
|
commandSuccess: success,
|
|
137836
|
-
exitCode
|
|
138660
|
+
exitCode,
|
|
138661
|
+
patternsLearned,
|
|
138662
|
+
experienceRecorded
|
|
137837
138663
|
});
|
|
137838
138664
|
}
|
|
137839
138665
|
process.exit(0);
|
|
@@ -137854,7 +138680,7 @@ init_qe_patterns();
|
|
|
137854
138680
|
import { Command as Command16 } from "commander";
|
|
137855
138681
|
import chalk29 from "chalk";
|
|
137856
138682
|
import path25 from "node:path";
|
|
137857
|
-
import { existsSync as
|
|
138683
|
+
import { existsSync as existsSync46, writeFileSync as writeFileSync22, readFileSync as readFileSync33, mkdirSync as mkdirSync19, copyFileSync as copyFileSync8 } from "node:fs";
|
|
137858
138684
|
import { stat as stat3, unlink } from "node:fs/promises";
|
|
137859
138685
|
|
|
137860
138686
|
// src/learning/metrics-tracker.ts
|
|
@@ -137863,7 +138689,7 @@ init_qe_patterns();
|
|
|
137863
138689
|
init_safe_json();
|
|
137864
138690
|
init_logging();
|
|
137865
138691
|
import path23 from "node:path";
|
|
137866
|
-
import { existsSync as
|
|
138692
|
+
import { existsSync as existsSync45 } from "node:fs";
|
|
137867
138693
|
var logger18 = LoggerFactory.create("metrics-tracker");
|
|
137868
138694
|
var LearningMetricsTracker = class {
|
|
137869
138695
|
db = null;
|
|
@@ -137877,7 +138703,7 @@ var LearningMetricsTracker = class {
|
|
|
137877
138703
|
*/
|
|
137878
138704
|
async initialize() {
|
|
137879
138705
|
if (this.initialized) return;
|
|
137880
|
-
if (!
|
|
138706
|
+
if (!existsSync45(this.dbPath)) {
|
|
137881
138707
|
throw new Error(`Database not found: ${this.dbPath}. Run "aqe init --auto" first.`);
|
|
137882
138708
|
}
|
|
137883
138709
|
this.db = new better_sqlite3_default(this.dbPath, { readonly: false });
|
|
@@ -138666,7 +139492,7 @@ function registerImportCommand(learning) {
|
|
|
138666
139492
|
learning.command("import").description("Import patterns from file").requiredOption("-i, --input <file>", "Input file path").option("--dry-run", "Show what would be imported without making changes").option("--json", "Output as JSON").action(async (options) => {
|
|
138667
139493
|
try {
|
|
138668
139494
|
const inputPath = path25.resolve(options.input);
|
|
138669
|
-
if (!
|
|
139495
|
+
if (!existsSync46(inputPath)) throw new Error(`File not found: ${inputPath}`);
|
|
138670
139496
|
const content = readFileSync33(inputPath, "utf-8");
|
|
138671
139497
|
const importData = safeJsonParse(content);
|
|
138672
139498
|
if (!importData.patterns || !Array.isArray(importData.patterns)) throw new Error("Invalid pattern file format");
|
|
@@ -138735,7 +139561,7 @@ function registerResetCommand(learning) {
|
|
|
138735
139561
|
if (!options.patternsOnly) filesToReset.push(path25.join(dataDir, "data", "learning-config.json"));
|
|
138736
139562
|
console.log(chalk29.bold("\n\u{1F5D1}\uFE0F Resetting Learning Data\n"));
|
|
138737
139563
|
for (const file of filesToReset) {
|
|
138738
|
-
if (
|
|
139564
|
+
if (existsSync46(file)) console.log(chalk29.dim(` Removing: ${path25.relative(projectRoot, file)}`));
|
|
138739
139565
|
}
|
|
138740
139566
|
printSuccess2('Learning data reset. Run "aqe init --auto" to reinitialize.\n');
|
|
138741
139567
|
process.exit(0);
|
|
@@ -138750,7 +139576,7 @@ function registerExtractCommand(learning) {
|
|
|
138750
139576
|
try {
|
|
138751
139577
|
const projectRoot = findProjectRoot();
|
|
138752
139578
|
const dbPath = path25.join(projectRoot, ".agentic-qe", "memory.db");
|
|
138753
|
-
if (!
|
|
139579
|
+
if (!existsSync46(dbPath)) throw new Error('No memory database found. Run "aqe init --auto" first.');
|
|
138754
139580
|
const minReward = parseFloat(options.minReward);
|
|
138755
139581
|
const minCount = parseInt(options.minCount, 10);
|
|
138756
139582
|
console.log(chalk29.bold("\n\u{1F52C} Pattern Extraction from Learning Experiences\n"));
|
|
@@ -138904,22 +139730,22 @@ function registerBackupCommand(learning) {
|
|
|
138904
139730
|
learning.command("backup").description("Backup learning database to a file").option("-o, --output <path>", "Output file path").option("--compress", "Compress backup with gzip").option("--verify", "Verify backup integrity after creation").option("--json", "Output as JSON").action(async (options) => {
|
|
138905
139731
|
try {
|
|
138906
139732
|
const dbPath = getDbPath();
|
|
138907
|
-
if (!
|
|
139733
|
+
if (!existsSync46(dbPath)) throw new Error(`No learning database found at: ${dbPath}`);
|
|
138908
139734
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
138909
139735
|
const defaultOutput = path25.join(process.cwd(), "backups", `learning-${timestamp}.db`);
|
|
138910
139736
|
let outputPath = options.output ? path25.resolve(options.output) : defaultOutput;
|
|
138911
139737
|
const backupDir = path25.dirname(outputPath);
|
|
138912
|
-
if (!
|
|
139738
|
+
if (!existsSync46(backupDir)) mkdirSync19(backupDir, { recursive: true });
|
|
138913
139739
|
const sourceStats = await stat3(dbPath);
|
|
138914
139740
|
const sourceSizeKB = (sourceStats.size / 1024).toFixed(2);
|
|
138915
139741
|
copyFileSync8(dbPath, outputPath);
|
|
138916
139742
|
const walPath = `${dbPath}-wal`;
|
|
138917
|
-
if (
|
|
139743
|
+
if (existsSync46(walPath)) copyFileSync8(walPath, `${outputPath}-wal`);
|
|
138918
139744
|
let finalPath = outputPath;
|
|
138919
139745
|
if (options.compress) {
|
|
138920
139746
|
finalPath = await compressFile(outputPath);
|
|
138921
139747
|
await unlink(outputPath);
|
|
138922
|
-
if (
|
|
139748
|
+
if (existsSync46(`${outputPath}-wal`)) await unlink(`${outputPath}-wal`);
|
|
138923
139749
|
}
|
|
138924
139750
|
const finalStats = await stat3(finalPath);
|
|
138925
139751
|
const finalSizeKB = (finalStats.size / 1024).toFixed(2);
|
|
@@ -138957,7 +139783,7 @@ function registerRestoreCommand(learning) {
|
|
|
138957
139783
|
try {
|
|
138958
139784
|
const inputPath = path25.resolve(options.input);
|
|
138959
139785
|
const dbPath = getDbPath();
|
|
138960
|
-
if (!
|
|
139786
|
+
if (!existsSync46(inputPath)) throw new Error(`Backup file not found: ${inputPath}`);
|
|
138961
139787
|
const isCompressed = inputPath.endsWith(".gz");
|
|
138962
139788
|
let restorePath = inputPath;
|
|
138963
139789
|
if (isCompressed) {
|
|
@@ -138968,23 +139794,23 @@ function registerRestoreCommand(learning) {
|
|
|
138968
139794
|
if (options.verify) {
|
|
138969
139795
|
const verificationResult = await verifyDatabaseIntegrity(restorePath);
|
|
138970
139796
|
if (!verificationResult.valid) {
|
|
138971
|
-
if (isCompressed &&
|
|
139797
|
+
if (isCompressed && existsSync46(restorePath)) await unlink(restorePath);
|
|
138972
139798
|
throw new Error(`Backup verification failed: ${verificationResult.message}`);
|
|
138973
139799
|
}
|
|
138974
139800
|
}
|
|
138975
|
-
if (
|
|
139801
|
+
if (existsSync46(dbPath) && !options.force) {
|
|
138976
139802
|
printError2(`Database already exists at: ${dbPath}`);
|
|
138977
139803
|
console.log(chalk29.yellow(" Use --force to overwrite"));
|
|
138978
|
-
if (isCompressed &&
|
|
139804
|
+
if (isCompressed && existsSync46(restorePath)) await unlink(restorePath);
|
|
138979
139805
|
process.exit(1);
|
|
138980
139806
|
}
|
|
138981
139807
|
const targetDir = path25.dirname(dbPath);
|
|
138982
|
-
if (!
|
|
138983
|
-
if (
|
|
138984
|
-
if (
|
|
138985
|
-
if (
|
|
139808
|
+
if (!existsSync46(targetDir)) mkdirSync19(targetDir, { recursive: true });
|
|
139809
|
+
if (existsSync46(dbPath)) await unlink(dbPath);
|
|
139810
|
+
if (existsSync46(`${dbPath}-wal`)) await unlink(`${dbPath}-wal`);
|
|
139811
|
+
if (existsSync46(`${dbPath}-shm`)) await unlink(`${dbPath}-shm`);
|
|
138986
139812
|
copyFileSync8(restorePath, dbPath);
|
|
138987
|
-
if (isCompressed &&
|
|
139813
|
+
if (isCompressed && existsSync46(restorePath)) await unlink(restorePath);
|
|
138988
139814
|
const restoredStats = await stat3(dbPath);
|
|
138989
139815
|
const schemaVersion = await getSchemaVersion(dbPath);
|
|
138990
139816
|
if (options.json) {
|
|
@@ -139008,7 +139834,7 @@ function registerVerifyCommand(learning) {
|
|
|
139008
139834
|
learning.command("verify").description("Verify learning database integrity").option("-f, --file <path>", "Database file to verify (defaults to current)").option("--json", "Output as JSON").action(async (options) => {
|
|
139009
139835
|
try {
|
|
139010
139836
|
const dbPath = options.file ? path25.resolve(options.file) : getDbPath();
|
|
139011
|
-
if (!
|
|
139837
|
+
if (!existsSync46(dbPath)) throw new Error(`Database file not found: ${dbPath}`);
|
|
139012
139838
|
const verificationResult = await verifyDatabaseIntegrity(dbPath);
|
|
139013
139839
|
const schemaVersion = await getSchemaVersion(dbPath);
|
|
139014
139840
|
const fileStats = await stat3(dbPath);
|
|
@@ -139051,7 +139877,7 @@ function registerExportFullCommand(learning) {
|
|
|
139051
139877
|
learning.command("export-full").description("Export all learning data including patterns, trajectories, and experiences").option("-o, --output <file>", "Output file path", "aqe-learning-export.json").option("--compress", "Compress output with gzip").option("--include-trajectories", "Include learning trajectories").option("--include-experiences", "Include learning experiences").option("--json", "Output as JSON (to stdout)").action(async (options) => {
|
|
139052
139878
|
try {
|
|
139053
139879
|
const dbPath = getDbPath();
|
|
139054
|
-
if (!
|
|
139880
|
+
if (!existsSync46(dbPath)) throw new Error('No learning database found. Run "aqe init --auto" first.');
|
|
139055
139881
|
const reasoningBank = await initializeLearningSystem2();
|
|
139056
139882
|
const schemaVersion = await getSchemaVersion(dbPath);
|
|
139057
139883
|
const searchResult = await reasoningBank.searchPatterns("*", { limit: 1e4 });
|
|
@@ -139132,7 +139958,7 @@ function registerImportMergeCommand(learning) {
|
|
|
139132
139958
|
learning.command("import-merge").description("Import and merge patterns from export file (preserves existing data)").requiredOption("-i, --input <file>", "Input file path").option("--skip-duplicates", "Skip patterns with matching names (default: update)").option("--dry-run", "Show what would be imported without making changes").option("--json", "Output as JSON").action(async (options) => {
|
|
139133
139959
|
try {
|
|
139134
139960
|
let inputPath = path25.resolve(options.input);
|
|
139135
|
-
if (!
|
|
139961
|
+
if (!existsSync46(inputPath)) throw new Error(`File not found: ${inputPath}`);
|
|
139136
139962
|
let content;
|
|
139137
139963
|
if (inputPath.endsWith(".gz")) {
|
|
139138
139964
|
const tempPath = inputPath.replace(".gz", ".tmp.json");
|
|
@@ -139414,8 +140240,8 @@ function registerDreamCommand(learning) {
|
|
|
139414
140240
|
// src/cli/commands/mcp.ts
|
|
139415
140241
|
import { Command as Command17 } from "commander";
|
|
139416
140242
|
import { spawn as spawn7 } from "child_process";
|
|
139417
|
-
import { join as
|
|
139418
|
-
import { existsSync as
|
|
140243
|
+
import { join as join45, dirname as dirname14 } from "path";
|
|
140244
|
+
import { existsSync as existsSync47 } from "fs";
|
|
139419
140245
|
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
139420
140246
|
function createMcpCommand() {
|
|
139421
140247
|
const cmd = new Command17("mcp").description("Start the MCP protocol server for Claude Code integration").option("--http <port>", "Also start HTTP server for AG-UI/A2A protocols", "0").option("--verbose", "Enable verbose logging").action(async (options) => {
|
|
@@ -139457,17 +140283,17 @@ function findMcpEntry() {
|
|
|
139457
140283
|
const __dirname5 = dirname14(__filename5);
|
|
139458
140284
|
const candidates = [
|
|
139459
140285
|
// 1. Bundled dist (production)
|
|
139460
|
-
|
|
140286
|
+
join45(__dirname5, "..", "..", "mcp", "bundle.js"),
|
|
139461
140287
|
// 2. Compiled dist
|
|
139462
|
-
|
|
140288
|
+
join45(__dirname5, "..", "..", "mcp", "entry.js"),
|
|
139463
140289
|
// 3. Source (development with tsx)
|
|
139464
|
-
|
|
140290
|
+
join45(__dirname5, "..", "..", "mcp", "entry.ts"),
|
|
139465
140291
|
// 4. From node_modules (when used as dependency)
|
|
139466
|
-
|
|
139467
|
-
|
|
140292
|
+
join45(process.cwd(), "node_modules", "agentic-qe", "v3", "dist", "mcp", "bundle.js"),
|
|
140293
|
+
join45(process.cwd(), "node_modules", "agentic-qe", "v3", "dist", "mcp", "entry.js")
|
|
139468
140294
|
];
|
|
139469
140295
|
for (const candidate of candidates) {
|
|
139470
|
-
if (
|
|
140296
|
+
if (existsSync47(candidate)) {
|
|
139471
140297
|
return candidate;
|
|
139472
140298
|
}
|
|
139473
140299
|
}
|
|
@@ -139589,7 +140415,7 @@ async function cleanupAndExit(code = 0) {
|
|
|
139589
140415
|
process.exit(code);
|
|
139590
140416
|
}
|
|
139591
140417
|
var program = new Command18();
|
|
139592
|
-
var VERSION = true ? "3.6.
|
|
140418
|
+
var VERSION = true ? "3.6.11" : "0.0.0-dev";
|
|
139593
140419
|
program.name("aqe").description("Agentic QE - Domain-Driven Quality Engineering").version(VERSION);
|
|
139594
140420
|
var registry = createCommandRegistry(context, cleanupAndExit, ensureInitialized);
|
|
139595
140421
|
registry.registerAll(program);
|