agentic-qe 3.6.3 → 3.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/helpers/statusline-v3.cjs +4 -3
- package/.claude/skills/release/SKILL.md +33 -2
- package/.claude/skills/skills-manifest.json +1 -1
- package/package.json +1 -1
- package/v3/CHANGELOG.md +25 -0
- package/v3/dist/adapters/a2a/auth/oauth-provider.d.ts +8 -0
- package/v3/dist/adapters/a2a/auth/oauth-provider.d.ts.map +1 -1
- package/v3/dist/adapters/a2a/auth/oauth-provider.js +32 -7
- package/v3/dist/adapters/a2a/auth/oauth-provider.js.map +1 -1
- package/v3/dist/adapters/claude-flow/detect.d.ts +38 -0
- package/v3/dist/adapters/claude-flow/detect.d.ts.map +1 -0
- package/v3/dist/adapters/claude-flow/detect.js +154 -0
- package/v3/dist/adapters/claude-flow/detect.js.map +1 -0
- package/v3/dist/adapters/claude-flow/index.d.ts +2 -0
- package/v3/dist/adapters/claude-flow/index.d.ts.map +1 -1
- package/v3/dist/adapters/claude-flow/index.js +1 -0
- package/v3/dist/adapters/claude-flow/index.js.map +1 -1
- package/v3/dist/adapters/claude-flow/model-router-bridge.d.ts +1 -1
- package/v3/dist/adapters/claude-flow/model-router-bridge.d.ts.map +1 -1
- package/v3/dist/adapters/claude-flow/model-router-bridge.js +5 -15
- package/v3/dist/adapters/claude-flow/model-router-bridge.js.map +1 -1
- package/v3/dist/adapters/claude-flow/pretrain-bridge.d.ts +1 -1
- package/v3/dist/adapters/claude-flow/pretrain-bridge.d.ts.map +1 -1
- package/v3/dist/adapters/claude-flow/pretrain-bridge.js +6 -16
- package/v3/dist/adapters/claude-flow/pretrain-bridge.js.map +1 -1
- package/v3/dist/adapters/claude-flow/trajectory-bridge.d.ts +1 -1
- package/v3/dist/adapters/claude-flow/trajectory-bridge.d.ts.map +1 -1
- package/v3/dist/adapters/claude-flow/trajectory-bridge.js +6 -16
- package/v3/dist/adapters/claude-flow/trajectory-bridge.js.map +1 -1
- package/v3/dist/cli/bundle.js +73696 -71841
- package/v3/dist/cli/commands/claude-flow-setup.d.ts.map +1 -1
- package/v3/dist/cli/commands/claude-flow-setup.js +42 -80
- package/v3/dist/cli/commands/claude-flow-setup.js.map +1 -1
- package/v3/dist/cli/commands/hooks.d.ts.map +1 -1
- package/v3/dist/cli/commands/hooks.js +170 -0
- package/v3/dist/cli/commands/hooks.js.map +1 -1
- package/v3/dist/cli/commands/learning.d.ts.map +1 -1
- package/v3/dist/cli/commands/learning.js +296 -0
- package/v3/dist/cli/commands/learning.js.map +1 -1
- package/v3/dist/cli/handlers/init-handler.d.ts.map +1 -1
- package/v3/dist/cli/handlers/init-handler.js +9 -1
- package/v3/dist/cli/handlers/init-handler.js.map +1 -1
- package/v3/dist/coordination/mincut/mincut-calculator.d.ts +7 -0
- package/v3/dist/coordination/mincut/mincut-calculator.d.ts.map +1 -1
- package/v3/dist/coordination/mincut/mincut-calculator.js +66 -7
- package/v3/dist/coordination/mincut/mincut-calculator.js.map +1 -1
- package/v3/dist/domains/contract-testing/services/contract-validator.d.ts.map +1 -1
- package/v3/dist/domains/contract-testing/services/contract-validator.js +10 -13
- package/v3/dist/domains/contract-testing/services/contract-validator.js.map +1 -1
- package/v3/dist/domains/contract-testing/services/schema-validator.d.ts.map +1 -1
- package/v3/dist/domains/contract-testing/services/schema-validator.js +4 -2
- package/v3/dist/domains/contract-testing/services/schema-validator.js.map +1 -1
- package/v3/dist/governance/deterministic-gateway-integration.d.ts.map +1 -1
- package/v3/dist/governance/deterministic-gateway-integration.js +3 -1
- package/v3/dist/governance/deterministic-gateway-integration.js.map +1 -1
- package/v3/dist/init/enhancements/claude-flow-adapter.d.ts +1 -1
- package/v3/dist/init/enhancements/claude-flow-adapter.d.ts.map +1 -1
- package/v3/dist/init/enhancements/claude-flow-adapter.js +15 -34
- package/v3/dist/init/enhancements/claude-flow-adapter.js.map +1 -1
- package/v3/dist/init/enhancements/detector.d.ts.map +1 -1
- package/v3/dist/init/enhancements/detector.js +7 -34
- package/v3/dist/init/enhancements/detector.js.map +1 -1
- package/v3/dist/init/phases/06-code-intelligence.d.ts +8 -0
- package/v3/dist/init/phases/06-code-intelligence.d.ts.map +1 -1
- package/v3/dist/init/phases/06-code-intelligence.js +118 -24
- package/v3/dist/init/phases/06-code-intelligence.js.map +1 -1
- package/v3/dist/kernel/unified-memory-migration.d.ts.map +1 -1
- package/v3/dist/kernel/unified-memory-migration.js +4 -3
- package/v3/dist/kernel/unified-memory-migration.js.map +1 -1
- package/v3/dist/kernel/unified-memory.d.ts +3 -1
- package/v3/dist/kernel/unified-memory.d.ts.map +1 -1
- package/v3/dist/kernel/unified-memory.js +119 -44
- package/v3/dist/kernel/unified-memory.js.map +1 -1
- package/v3/dist/learning/dream/concept-graph.d.ts +13 -2
- package/v3/dist/learning/dream/concept-graph.d.ts.map +1 -1
- package/v3/dist/learning/dream/concept-graph.js +69 -7
- package/v3/dist/learning/dream/concept-graph.js.map +1 -1
- package/v3/dist/learning/dream/dream-engine.d.ts +5 -0
- package/v3/dist/learning/dream/dream-engine.d.ts.map +1 -1
- package/v3/dist/learning/dream/dream-engine.js +54 -3
- package/v3/dist/learning/dream/dream-engine.js.map +1 -1
- package/v3/dist/learning/dream/spreading-activation.d.ts.map +1 -1
- package/v3/dist/learning/dream/spreading-activation.js +74 -6
- package/v3/dist/learning/dream/spreading-activation.js.map +1 -1
- package/v3/dist/learning/pattern-store.d.ts.map +1 -1
- package/v3/dist/learning/pattern-store.js +9 -8
- package/v3/dist/learning/pattern-store.js.map +1 -1
- package/v3/dist/learning/qe-patterns.d.ts +2 -0
- package/v3/dist/learning/qe-patterns.d.ts.map +1 -1
- package/v3/dist/learning/qe-patterns.js.map +1 -1
- package/v3/dist/learning/qe-reasoning-bank.d.ts +16 -0
- package/v3/dist/learning/qe-reasoning-bank.d.ts.map +1 -1
- package/v3/dist/learning/qe-reasoning-bank.js +709 -0
- package/v3/dist/learning/qe-reasoning-bank.js.map +1 -1
- package/v3/dist/mcp/bundle.js +1501 -217
- package/v3/dist/mcp/connection-pool.d.ts +1 -1
- package/v3/dist/mcp/connection-pool.d.ts.map +1 -1
- package/v3/dist/mcp/connection-pool.js +27 -13
- package/v3/dist/mcp/connection-pool.js.map +1 -1
- package/v3/dist/mcp/handlers/handler-factory.d.ts +2 -0
- package/v3/dist/mcp/handlers/handler-factory.d.ts.map +1 -1
- package/v3/dist/mcp/handlers/handler-factory.js +52 -4
- package/v3/dist/mcp/handlers/handler-factory.js.map +1 -1
- package/v3/dist/mcp/http-server.d.ts.map +1 -1
- package/v3/dist/mcp/http-server.js +2 -1
- package/v3/dist/mcp/http-server.js.map +1 -1
- package/v3/dist/mcp/security/oauth21-provider.d.ts.map +1 -1
- package/v3/dist/mcp/security/oauth21-provider.js +25 -15
- package/v3/dist/mcp/security/oauth21-provider.js.map +1 -1
- package/v3/dist/mcp/security/rate-limiter.d.ts.map +1 -1
- package/v3/dist/mcp/security/rate-limiter.js +5 -4
- package/v3/dist/mcp/security/rate-limiter.js.map +1 -1
- package/v3/dist/mcp/security/schema-validator.d.ts.map +1 -1
- package/v3/dist/mcp/security/schema-validator.js +13 -9
- package/v3/dist/mcp/security/schema-validator.js.map +1 -1
- package/v3/dist/mcp/tools/contract-testing/validate.d.ts.map +1 -1
- package/v3/dist/mcp/tools/contract-testing/validate.js +3 -2
- package/v3/dist/mcp/tools/contract-testing/validate.js.map +1 -1
- package/v3/dist/mcp/transport/sse/connection-manager.d.ts +1 -0
- package/v3/dist/mcp/transport/sse/connection-manager.d.ts.map +1 -1
- package/v3/dist/mcp/transport/sse/connection-manager.js +31 -10
- package/v3/dist/mcp/transport/sse/connection-manager.js.map +1 -1
- package/v3/dist/mcp/transport/sse/sse-transport.d.ts.map +1 -1
- package/v3/dist/mcp/transport/sse/sse-transport.js +2 -1
- package/v3/dist/mcp/transport/sse/sse-transport.js.map +1 -1
- package/v3/dist/mcp/transport/stdio.d.ts.map +1 -1
- package/v3/dist/mcp/transport/stdio.js +2 -1
- package/v3/dist/mcp/transport/stdio.js.map +1 -1
- package/v3/dist/mcp/transport/websocket/websocket-transport.d.ts.map +1 -1
- package/v3/dist/mcp/transport/websocket/websocket-transport.js +2 -1
- package/v3/dist/mcp/transport/websocket/websocket-transport.js.map +1 -1
- package/v3/dist/performance/optimizer.d.ts.map +1 -1
- package/v3/dist/performance/optimizer.js +19 -3
- package/v3/dist/performance/optimizer.js.map +1 -1
- package/v3/dist/shared/sql-safety.d.ts +18 -0
- package/v3/dist/shared/sql-safety.d.ts.map +1 -0
- package/v3/dist/shared/sql-safety.js +44 -0
- package/v3/dist/shared/sql-safety.js.map +1 -0
- package/v3/dist/sync/embeddings/sync-embedding-generator.d.ts.map +1 -1
- package/v3/dist/sync/embeddings/sync-embedding-generator.js +9 -7
- package/v3/dist/sync/embeddings/sync-embedding-generator.js.map +1 -1
- package/v3/dist/sync/interfaces.js +5 -5
- package/v3/dist/sync/interfaces.js.map +1 -1
- package/v3/dist/sync/readers/sqlite-reader.d.ts.map +1 -1
- package/v3/dist/sync/readers/sqlite-reader.js +5 -4
- package/v3/dist/sync/readers/sqlite-reader.js.map +1 -1
- package/v3/package.json +2 -2
|
@@ -152,6 +152,13 @@ export class QEReasoningBank {
|
|
|
152
152
|
// Load any pre-trained patterns
|
|
153
153
|
await this.loadPretrainedPatterns();
|
|
154
154
|
this.initialized = true;
|
|
155
|
+
// Run cross-domain transfer after initialization to enrich related domains
|
|
156
|
+
try {
|
|
157
|
+
await this.seedCrossDomainPatterns();
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
console.warn('[QEReasoningBank] Cross-domain seeding failed (non-fatal):', error);
|
|
161
|
+
}
|
|
155
162
|
console.log('[QEReasoningBank] Initialized');
|
|
156
163
|
}
|
|
157
164
|
/**
|
|
@@ -279,6 +286,602 @@ Check for:
|
|
|
279
286
|
tags: ['flaky', 'timing', 'async', 'stability'],
|
|
280
287
|
},
|
|
281
288
|
},
|
|
289
|
+
// ================================================================
|
|
290
|
+
// quality-assessment domain seeds
|
|
291
|
+
// ================================================================
|
|
292
|
+
{
|
|
293
|
+
patternType: 'assertion-pattern',
|
|
294
|
+
qeDomain: 'quality-assessment',
|
|
295
|
+
name: 'Quality Gate Checklist',
|
|
296
|
+
description: 'Evaluate deployment readiness against quality gate criteria',
|
|
297
|
+
template: {
|
|
298
|
+
type: 'prompt',
|
|
299
|
+
content: `Quality gate evaluation for {{targetModule}}:
|
|
300
|
+
|
|
301
|
+
1. Test coverage >= {{coverageThreshold}}%
|
|
302
|
+
2. No critical/high severity bugs open
|
|
303
|
+
3. All P1 tests passing
|
|
304
|
+
4. Performance benchmarks within SLA (p95 < {{latencyThresholdMs}}ms)
|
|
305
|
+
5. Security scan clean (no critical CVEs)
|
|
306
|
+
6. Code review approved
|
|
307
|
+
|
|
308
|
+
Fail the gate if ANY criterion is unmet. Report which criteria passed/failed.`,
|
|
309
|
+
variables: [
|
|
310
|
+
{ name: 'targetModule', type: 'string', required: true, description: 'Module or service to evaluate' },
|
|
311
|
+
{ name: 'coverageThreshold', type: 'number', required: false, defaultValue: 80, description: 'Minimum coverage %' },
|
|
312
|
+
{ name: 'latencyThresholdMs', type: 'number', required: false, defaultValue: 500, description: 'P95 latency limit in ms' },
|
|
313
|
+
],
|
|
314
|
+
},
|
|
315
|
+
context: {
|
|
316
|
+
tags: ['quality-gate', 'deployment', 'readiness', 'sla'],
|
|
317
|
+
},
|
|
318
|
+
confidence: 0.6,
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
patternType: 'assertion-pattern',
|
|
322
|
+
qeDomain: 'quality-assessment',
|
|
323
|
+
name: 'Metric Threshold Validator',
|
|
324
|
+
description: 'Validate quality metrics against configurable thresholds',
|
|
325
|
+
template: {
|
|
326
|
+
type: 'code',
|
|
327
|
+
content: `function validateMetrics(metrics: Record<string, number>, thresholds: Record<string, { min?: number; max?: number }>) {
|
|
328
|
+
const violations: string[] = [];
|
|
329
|
+
for (const [metric, value] of Object.entries(metrics)) {
|
|
330
|
+
const threshold = thresholds[metric];
|
|
331
|
+
if (!threshold) continue;
|
|
332
|
+
if (threshold.min !== undefined && value < threshold.min) {
|
|
333
|
+
violations.push(\`\${metric}: \${value} < min \${threshold.min}\`);
|
|
334
|
+
}
|
|
335
|
+
if (threshold.max !== undefined && value > threshold.max) {
|
|
336
|
+
violations.push(\`\${metric}: \${value} > max \${threshold.max}\`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return { pass: violations.length === 0, violations };
|
|
340
|
+
}`,
|
|
341
|
+
variables: [],
|
|
342
|
+
},
|
|
343
|
+
context: {
|
|
344
|
+
tags: ['metrics', 'threshold', 'validation', 'scoring'],
|
|
345
|
+
},
|
|
346
|
+
confidence: 0.6,
|
|
347
|
+
},
|
|
348
|
+
// ================================================================
|
|
349
|
+
// defect-intelligence domain seeds
|
|
350
|
+
// ================================================================
|
|
351
|
+
{
|
|
352
|
+
patternType: 'error-handling',
|
|
353
|
+
qeDomain: 'defect-intelligence',
|
|
354
|
+
name: 'Root Cause Analysis Workflow',
|
|
355
|
+
description: 'Systematic root cause analysis for test failures and production incidents',
|
|
356
|
+
template: {
|
|
357
|
+
type: 'prompt',
|
|
358
|
+
content: `Root cause analysis for: {{incidentDescription}}
|
|
359
|
+
|
|
360
|
+
1. **Reproduce**: Confirm the failure is deterministic
|
|
361
|
+
2. **Isolate**: Narrow down to the smallest failing component
|
|
362
|
+
3. **Timeline**: When did it last pass? What changed since?
|
|
363
|
+
4. **Categorize**: Is it a code bug, config issue, data issue, or environment?
|
|
364
|
+
5. **Five Whys**: Ask why at least 5 times to reach the root cause
|
|
365
|
+
6. **Fix**: Propose fix with test to prevent regression
|
|
366
|
+
7. **Verify**: Run the fix and confirm the original failure is resolved`,
|
|
367
|
+
variables: [
|
|
368
|
+
{ name: 'incidentDescription', type: 'string', required: true, description: 'Description of the failure or incident' },
|
|
369
|
+
],
|
|
370
|
+
},
|
|
371
|
+
context: {
|
|
372
|
+
tags: ['root-cause', 'rca', 'debugging', 'incident'],
|
|
373
|
+
},
|
|
374
|
+
confidence: 0.6,
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
patternType: 'error-handling',
|
|
378
|
+
qeDomain: 'defect-intelligence',
|
|
379
|
+
name: 'Regression Risk Scorer',
|
|
380
|
+
description: 'Score change risk for regression based on code complexity and history',
|
|
381
|
+
template: {
|
|
382
|
+
type: 'prompt',
|
|
383
|
+
content: `Regression risk assessment for {{changePath}}:
|
|
384
|
+
|
|
385
|
+
Risk factors (score each 0-3):
|
|
386
|
+
- Lines changed: {{linesChanged}} → complexity risk
|
|
387
|
+
- Files affected: {{filesAffected}} → blast radius
|
|
388
|
+
- Previous bugs in area: historical defect density
|
|
389
|
+
- Test coverage of changed code: gap risk
|
|
390
|
+
- Dependency depth: cascade risk
|
|
391
|
+
|
|
392
|
+
Total risk = sum / 15 → Low (<0.3), Medium (0.3-0.6), High (>0.6)`,
|
|
393
|
+
variables: [
|
|
394
|
+
{ name: 'changePath', type: 'string', required: true, description: 'File or module changed' },
|
|
395
|
+
{ name: 'linesChanged', type: 'number', required: true, description: 'Number of lines changed' },
|
|
396
|
+
{ name: 'filesAffected', type: 'number', required: true, description: 'Number of files affected' },
|
|
397
|
+
],
|
|
398
|
+
},
|
|
399
|
+
context: {
|
|
400
|
+
tags: ['regression', 'risk', 'prediction', 'change-analysis'],
|
|
401
|
+
},
|
|
402
|
+
confidence: 0.6,
|
|
403
|
+
},
|
|
404
|
+
// ================================================================
|
|
405
|
+
// requirements-validation domain seeds
|
|
406
|
+
// ================================================================
|
|
407
|
+
{
|
|
408
|
+
patternType: 'test-template',
|
|
409
|
+
qeDomain: 'requirements-validation',
|
|
410
|
+
name: 'Gherkin BDD Scenario',
|
|
411
|
+
description: 'Behavior-driven development scenario in Given/When/Then format',
|
|
412
|
+
template: {
|
|
413
|
+
type: 'code',
|
|
414
|
+
content: `Feature: {{featureName}}
|
|
415
|
+
|
|
416
|
+
Scenario: {{scenarioDescription}}
|
|
417
|
+
Given {{precondition}}
|
|
418
|
+
When {{action}}
|
|
419
|
+
Then {{expectedOutcome}}
|
|
420
|
+
|
|
421
|
+
Scenario: {{scenarioDescription}} - error case
|
|
422
|
+
Given {{precondition}}
|
|
423
|
+
When {{errorAction}}
|
|
424
|
+
Then {{errorOutcome}}`,
|
|
425
|
+
variables: [
|
|
426
|
+
{ name: 'featureName', type: 'string', required: true, description: 'Feature under test' },
|
|
427
|
+
{ name: 'scenarioDescription', type: 'string', required: true, description: 'What the scenario validates' },
|
|
428
|
+
{ name: 'precondition', type: 'string', required: true, description: 'Given precondition' },
|
|
429
|
+
{ name: 'action', type: 'string', required: true, description: 'When action' },
|
|
430
|
+
{ name: 'expectedOutcome', type: 'string', required: true, description: 'Then expected result' },
|
|
431
|
+
{ name: 'errorAction', type: 'string', required: true, description: 'When error action' },
|
|
432
|
+
{ name: 'errorOutcome', type: 'string', required: true, description: 'Then error result' },
|
|
433
|
+
],
|
|
434
|
+
},
|
|
435
|
+
context: {
|
|
436
|
+
tags: ['bdd', 'gherkin', 'requirements', 'acceptance'],
|
|
437
|
+
},
|
|
438
|
+
confidence: 0.6,
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
patternType: 'test-template',
|
|
442
|
+
qeDomain: 'requirements-validation',
|
|
443
|
+
name: 'Acceptance Criteria Testability Check',
|
|
444
|
+
description: 'Evaluate whether acceptance criteria are testable and complete',
|
|
445
|
+
template: {
|
|
446
|
+
type: 'prompt',
|
|
447
|
+
content: `Testability assessment for: {{requirementId}} - {{requirementTitle}}
|
|
448
|
+
|
|
449
|
+
Acceptance criteria:
|
|
450
|
+
{{acceptanceCriteria}}
|
|
451
|
+
|
|
452
|
+
Evaluate each criterion:
|
|
453
|
+
1. **Observable**: Can we verify the outcome without internal knowledge?
|
|
454
|
+
2. **Measurable**: Is there a quantifiable threshold or clear pass/fail?
|
|
455
|
+
3. **Atomic**: Does each criterion test exactly one thing?
|
|
456
|
+
4. **Achievable**: Can this be tested with available tools?
|
|
457
|
+
5. **Complete**: Are edge cases and error paths covered?
|
|
458
|
+
|
|
459
|
+
Flag any untestable or ambiguous criteria with suggested rewrites.`,
|
|
460
|
+
variables: [
|
|
461
|
+
{ name: 'requirementId', type: 'string', required: true, description: 'Requirement identifier' },
|
|
462
|
+
{ name: 'requirementTitle', type: 'string', required: true, description: 'Requirement title' },
|
|
463
|
+
{ name: 'acceptanceCriteria', type: 'string', required: true, description: 'The acceptance criteria text' },
|
|
464
|
+
],
|
|
465
|
+
},
|
|
466
|
+
context: {
|
|
467
|
+
tags: ['requirements', 'testability', 'acceptance-criteria', 'validation'],
|
|
468
|
+
},
|
|
469
|
+
confidence: 0.6,
|
|
470
|
+
},
|
|
471
|
+
// ================================================================
|
|
472
|
+
// code-intelligence domain seeds
|
|
473
|
+
// ================================================================
|
|
474
|
+
{
|
|
475
|
+
patternType: 'refactor-safe',
|
|
476
|
+
name: 'Safe Refactoring Checklist',
|
|
477
|
+
description: 'Ensure refactoring preserves behavior with systematic safety checks',
|
|
478
|
+
template: {
|
|
479
|
+
type: 'prompt',
|
|
480
|
+
content: `Safe refactoring checklist for {{targetPath}}:
|
|
481
|
+
|
|
482
|
+
Before refactoring:
|
|
483
|
+
1. Run existing tests — capture baseline results
|
|
484
|
+
2. Check coverage of code being refactored
|
|
485
|
+
3. Identify all callers and dependents via references
|
|
486
|
+
|
|
487
|
+
During refactoring:
|
|
488
|
+
4. Make one semantic change at a time
|
|
489
|
+
5. Keep public API signatures stable (or update all callers)
|
|
490
|
+
6. Preserve error handling contracts
|
|
491
|
+
|
|
492
|
+
After refactoring:
|
|
493
|
+
7. Run full test suite — compare to baseline
|
|
494
|
+
8. Check for any new uncovered paths
|
|
495
|
+
9. Verify no unused imports or dead code introduced`,
|
|
496
|
+
variables: [
|
|
497
|
+
{ name: 'targetPath', type: 'string', required: true, description: 'Path to refactor' },
|
|
498
|
+
],
|
|
499
|
+
},
|
|
500
|
+
context: {
|
|
501
|
+
tags: ['refactor', 'safety', 'code-change', 'impact'],
|
|
502
|
+
},
|
|
503
|
+
confidence: 0.6,
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
patternType: 'refactor-safe',
|
|
507
|
+
name: 'Dependency Impact Analysis',
|
|
508
|
+
description: 'Analyze the blast radius of a code change through the dependency graph',
|
|
509
|
+
template: {
|
|
510
|
+
type: 'prompt',
|
|
511
|
+
content: `Impact analysis for changes in {{changedFile}}:
|
|
512
|
+
|
|
513
|
+
1. Direct dependents: files that import/require {{changedFile}}
|
|
514
|
+
2. Transitive dependents: files that depend on direct dependents
|
|
515
|
+
3. Test coverage: which tests exercise the changed code?
|
|
516
|
+
4. Integration points: does this affect API contracts or events?
|
|
517
|
+
5. Risk tier: Critical (auth/payments) > High (business logic) > Medium (utils)
|
|
518
|
+
|
|
519
|
+
Output: sorted list of affected files with risk scores.`,
|
|
520
|
+
variables: [
|
|
521
|
+
{ name: 'changedFile', type: 'string', required: true, description: 'File being changed' },
|
|
522
|
+
],
|
|
523
|
+
},
|
|
524
|
+
context: {
|
|
525
|
+
tags: ['impact', 'dependency', 'blast-radius', 'analysis'],
|
|
526
|
+
},
|
|
527
|
+
confidence: 0.6,
|
|
528
|
+
},
|
|
529
|
+
// ================================================================
|
|
530
|
+
// security-compliance domain seeds
|
|
531
|
+
// ================================================================
|
|
532
|
+
{
|
|
533
|
+
patternType: 'assertion-pattern',
|
|
534
|
+
qeDomain: 'security-compliance',
|
|
535
|
+
name: 'OWASP Top 10 Security Audit',
|
|
536
|
+
description: 'Check code against OWASP Top 10 vulnerability categories',
|
|
537
|
+
template: {
|
|
538
|
+
type: 'prompt',
|
|
539
|
+
content: `Security audit for {{targetPath}} against OWASP Top 10:
|
|
540
|
+
|
|
541
|
+
1. **A01 Broken Access Control**: Check authorization on every endpoint
|
|
542
|
+
2. **A02 Cryptographic Failures**: No plaintext secrets, proper hashing
|
|
543
|
+
3. **A03 Injection**: Parameterized queries, input sanitization
|
|
544
|
+
4. **A04 Insecure Design**: Threat modeling, least privilege
|
|
545
|
+
5. **A05 Security Misconfiguration**: Default creds, verbose errors
|
|
546
|
+
6. **A06 Vulnerable Components**: Check dependencies for CVEs
|
|
547
|
+
7. **A07 Auth Failures**: Brute force protection, session management
|
|
548
|
+
8. **A08 Data Integrity Failures**: Verify signatures, safe deserialization
|
|
549
|
+
9. **A09 Logging Failures**: Audit trail, no sensitive data in logs
|
|
550
|
+
10. **A10 SSRF**: Validate/allowlist outbound URLs
|
|
551
|
+
|
|
552
|
+
Flag findings as Critical/High/Medium/Low with remediation guidance.`,
|
|
553
|
+
variables: [
|
|
554
|
+
{ name: 'targetPath', type: 'string', required: true, description: 'Code path to audit' },
|
|
555
|
+
],
|
|
556
|
+
},
|
|
557
|
+
context: {
|
|
558
|
+
tags: ['owasp', 'security', 'audit', 'vulnerability'],
|
|
559
|
+
},
|
|
560
|
+
confidence: 0.6,
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
patternType: 'assertion-pattern',
|
|
564
|
+
qeDomain: 'security-compliance',
|
|
565
|
+
name: 'Input Sanitization Pattern',
|
|
566
|
+
description: 'Validate and sanitize inputs at system boundaries to prevent injection',
|
|
567
|
+
template: {
|
|
568
|
+
type: 'code',
|
|
569
|
+
content: `// Input validation at system boundary
|
|
570
|
+
function validateInput(input: unknown, schema: {
|
|
571
|
+
type: 'string' | 'number' | 'boolean';
|
|
572
|
+
maxLength?: number;
|
|
573
|
+
pattern?: RegExp;
|
|
574
|
+
allowedValues?: unknown[];
|
|
575
|
+
}): { valid: boolean; sanitized: unknown; errors: string[] } {
|
|
576
|
+
const errors: string[] = [];
|
|
577
|
+
if (typeof input !== schema.type) {
|
|
578
|
+
errors.push(\`Expected \${schema.type}, got \${typeof input}\`);
|
|
579
|
+
return { valid: false, sanitized: null, errors };
|
|
580
|
+
}
|
|
581
|
+
if (schema.type === 'string') {
|
|
582
|
+
let str = input as string;
|
|
583
|
+
if (schema.maxLength && str.length > schema.maxLength) {
|
|
584
|
+
str = str.slice(0, schema.maxLength);
|
|
585
|
+
errors.push('Input truncated to max length');
|
|
586
|
+
}
|
|
587
|
+
if (schema.pattern && !schema.pattern.test(str)) {
|
|
588
|
+
errors.push('Input does not match expected pattern');
|
|
589
|
+
return { valid: false, sanitized: null, errors };
|
|
590
|
+
}
|
|
591
|
+
return { valid: errors.length === 0, sanitized: str, errors };
|
|
592
|
+
}
|
|
593
|
+
return { valid: true, sanitized: input, errors };
|
|
594
|
+
}`,
|
|
595
|
+
variables: [],
|
|
596
|
+
},
|
|
597
|
+
context: {
|
|
598
|
+
tags: ['security', 'validation', 'sanitization', 'injection-prevention'],
|
|
599
|
+
},
|
|
600
|
+
confidence: 0.6,
|
|
601
|
+
},
|
|
602
|
+
// ================================================================
|
|
603
|
+
// contract-testing domain seeds
|
|
604
|
+
// ================================================================
|
|
605
|
+
{
|
|
606
|
+
patternType: 'api-contract',
|
|
607
|
+
name: 'OpenAPI Contract Validator',
|
|
608
|
+
description: 'Validate API responses against OpenAPI/Swagger schema',
|
|
609
|
+
template: {
|
|
610
|
+
type: 'code',
|
|
611
|
+
content: `describe('{{apiEndpoint}} contract', () => {
|
|
612
|
+
it('should match the OpenAPI schema for {{operationId}}', async () => {
|
|
613
|
+
const response = await request(app).{{httpMethod}}('{{apiEndpoint}}');
|
|
614
|
+
expect(response.status).toBe({{expectedStatus}});
|
|
615
|
+
expect(response.body).toMatchSchema(openApiSpec.paths['{{apiEndpoint}}'].{{httpMethod}}.responses['{{expectedStatus}}'].content['application/json'].schema);
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
it('should return proper error for invalid input', async () => {
|
|
619
|
+
const response = await request(app).{{httpMethod}}('{{apiEndpoint}}').send({{invalidPayload}});
|
|
620
|
+
expect(response.status).toBe(400);
|
|
621
|
+
expect(response.body).toHaveProperty('errors');
|
|
622
|
+
});
|
|
623
|
+
});`,
|
|
624
|
+
variables: [
|
|
625
|
+
{ name: 'apiEndpoint', type: 'string', required: true, description: 'API endpoint path' },
|
|
626
|
+
{ name: 'operationId', type: 'string', required: true, description: 'OpenAPI operation ID' },
|
|
627
|
+
{ name: 'httpMethod', type: 'string', required: true, description: 'HTTP method (get/post/put/delete)' },
|
|
628
|
+
{ name: 'expectedStatus', type: 'number', required: true, description: 'Expected HTTP status code' },
|
|
629
|
+
{ name: 'invalidPayload', type: 'object', required: true, description: 'Invalid request body for error case' },
|
|
630
|
+
],
|
|
631
|
+
},
|
|
632
|
+
context: {
|
|
633
|
+
tags: ['api', 'contract', 'openapi', 'schema-validation'],
|
|
634
|
+
},
|
|
635
|
+
confidence: 0.6,
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
patternType: 'api-contract',
|
|
639
|
+
name: 'Consumer-Driven Contract Test',
|
|
640
|
+
description: 'Pact-style consumer-driven contract testing between services',
|
|
641
|
+
template: {
|
|
642
|
+
type: 'code',
|
|
643
|
+
content: `// Consumer side contract
|
|
644
|
+
const pact = new Pact({
|
|
645
|
+
consumer: '{{consumerName}}',
|
|
646
|
+
provider: '{{providerName}}',
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
describe('{{consumerName}} -> {{providerName}} contract', () => {
|
|
650
|
+
beforeAll(() => pact.setup());
|
|
651
|
+
afterAll(() => pact.finalize());
|
|
652
|
+
|
|
653
|
+
it('should receive {{expectedResource}}', async () => {
|
|
654
|
+
await pact.addInteraction({
|
|
655
|
+
state: '{{providerState}}',
|
|
656
|
+
uponReceiving: '{{interactionDescription}}',
|
|
657
|
+
withRequest: { method: '{{httpMethod}}', path: '{{requestPath}}' },
|
|
658
|
+
willRespondWith: {
|
|
659
|
+
status: 200,
|
|
660
|
+
body: like({{expectedShape}}),
|
|
661
|
+
},
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
const result = await client.{{clientMethod}}();
|
|
665
|
+
expect(result).toBeDefined();
|
|
666
|
+
});
|
|
667
|
+
});`,
|
|
668
|
+
variables: [
|
|
669
|
+
{ name: 'consumerName', type: 'string', required: true, description: 'Consumer service name' },
|
|
670
|
+
{ name: 'providerName', type: 'string', required: true, description: 'Provider service name' },
|
|
671
|
+
{ name: 'expectedResource', type: 'string', required: true, description: 'Resource being consumed' },
|
|
672
|
+
{ name: 'providerState', type: 'string', required: true, description: 'Provider state precondition' },
|
|
673
|
+
{ name: 'interactionDescription', type: 'string', required: true, description: 'Interaction description' },
|
|
674
|
+
{ name: 'httpMethod', type: 'string', required: true, description: 'HTTP method' },
|
|
675
|
+
{ name: 'requestPath', type: 'string', required: true, description: 'Request path' },
|
|
676
|
+
{ name: 'expectedShape', type: 'object', required: true, description: 'Expected response shape' },
|
|
677
|
+
{ name: 'clientMethod', type: 'string', required: true, description: 'Client method to call' },
|
|
678
|
+
],
|
|
679
|
+
},
|
|
680
|
+
context: {
|
|
681
|
+
tags: ['contract', 'pact', 'consumer-driven', 'microservice'],
|
|
682
|
+
},
|
|
683
|
+
confidence: 0.6,
|
|
684
|
+
},
|
|
685
|
+
// ================================================================
|
|
686
|
+
// visual-accessibility domain seeds
|
|
687
|
+
// ================================================================
|
|
688
|
+
{
|
|
689
|
+
patternType: 'a11y-check',
|
|
690
|
+
name: 'WCAG Contrast and ARIA Check',
|
|
691
|
+
description: 'Validate WCAG 2.2 color contrast ratios and ARIA attribute correctness',
|
|
692
|
+
template: {
|
|
693
|
+
type: 'prompt',
|
|
694
|
+
content: `Accessibility audit for {{componentName}}:
|
|
695
|
+
|
|
696
|
+
WCAG 2.2 AA Compliance:
|
|
697
|
+
1. **Color Contrast**: Text contrast ratio >= 4.5:1 (normal), >= 3:1 (large)
|
|
698
|
+
2. **ARIA Roles**: All interactive elements have correct role attributes
|
|
699
|
+
3. **ARIA Labels**: Forms and buttons have aria-label or aria-labelledby
|
|
700
|
+
4. **Focus Management**: Tab order is logical, focus visible on all interactive elements
|
|
701
|
+
5. **Screen Reader**: Content is meaningful when linearized
|
|
702
|
+
6. **Keyboard**: All functionality accessible via keyboard alone
|
|
703
|
+
|
|
704
|
+
Test with: axe-core, pa11y, or lighthouse --accessibility`,
|
|
705
|
+
variables: [
|
|
706
|
+
{ name: 'componentName', type: 'string', required: true, description: 'UI component to audit' },
|
|
707
|
+
],
|
|
708
|
+
},
|
|
709
|
+
context: {
|
|
710
|
+
tags: ['wcag', 'accessibility', 'aria', 'contrast', 'a11y'],
|
|
711
|
+
},
|
|
712
|
+
confidence: 0.6,
|
|
713
|
+
},
|
|
714
|
+
{
|
|
715
|
+
patternType: 'visual-baseline',
|
|
716
|
+
name: 'Visual Regression Baseline',
|
|
717
|
+
description: 'Capture and compare screenshots for visual regression detection',
|
|
718
|
+
template: {
|
|
719
|
+
type: 'code',
|
|
720
|
+
content: `describe('{{pageName}} visual regression', () => {
|
|
721
|
+
it('should match baseline screenshot', async () => {
|
|
722
|
+
await page.goto('{{pageUrl}}');
|
|
723
|
+
await page.waitForLoadState('networkidle');
|
|
724
|
+
|
|
725
|
+
const screenshot = await page.screenshot({ fullPage: {{fullPage}} });
|
|
726
|
+
expect(screenshot).toMatchSnapshot('{{pageName}}-baseline.png', {
|
|
727
|
+
maxDiffPixelRatio: {{maxDiffRatio}},
|
|
728
|
+
});
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
it('should match baseline at mobile viewport', async () => {
|
|
732
|
+
await page.setViewportSize({ width: 375, height: 812 });
|
|
733
|
+
await page.goto('{{pageUrl}}');
|
|
734
|
+
const screenshot = await page.screenshot({ fullPage: {{fullPage}} });
|
|
735
|
+
expect(screenshot).toMatchSnapshot('{{pageName}}-mobile-baseline.png', {
|
|
736
|
+
maxDiffPixelRatio: {{maxDiffRatio}},
|
|
737
|
+
});
|
|
738
|
+
});
|
|
739
|
+
});`,
|
|
740
|
+
variables: [
|
|
741
|
+
{ name: 'pageName', type: 'string', required: true, description: 'Page name for snapshot naming' },
|
|
742
|
+
{ name: 'pageUrl', type: 'string', required: true, description: 'Page URL to capture' },
|
|
743
|
+
{ name: 'fullPage', type: 'boolean', required: false, defaultValue: true, description: 'Capture full page' },
|
|
744
|
+
{ name: 'maxDiffRatio', type: 'number', required: false, defaultValue: 0.01, description: 'Max pixel diff ratio' },
|
|
745
|
+
],
|
|
746
|
+
},
|
|
747
|
+
context: {
|
|
748
|
+
tags: ['visual', 'screenshot', 'regression', 'baseline', 'playwright'],
|
|
749
|
+
},
|
|
750
|
+
confidence: 0.6,
|
|
751
|
+
},
|
|
752
|
+
// ================================================================
|
|
753
|
+
// chaos-resilience domain seeds
|
|
754
|
+
// ================================================================
|
|
755
|
+
{
|
|
756
|
+
patternType: 'perf-benchmark',
|
|
757
|
+
name: 'Load Test Scenario',
|
|
758
|
+
description: 'k6-style load test with ramp-up stages and SLA assertions',
|
|
759
|
+
template: {
|
|
760
|
+
type: 'code',
|
|
761
|
+
content: `import http from 'k6/http';
|
|
762
|
+
import { check, sleep } from 'k6';
|
|
763
|
+
|
|
764
|
+
export const options = {
|
|
765
|
+
stages: [
|
|
766
|
+
{ duration: '{{rampUpDuration}}', target: {{peakUsers}} },
|
|
767
|
+
{ duration: '{{steadyDuration}}', target: {{peakUsers}} },
|
|
768
|
+
{ duration: '{{rampDownDuration}}', target: 0 },
|
|
769
|
+
],
|
|
770
|
+
thresholds: {
|
|
771
|
+
http_req_duration: ['p(95)<{{p95ThresholdMs}}'],
|
|
772
|
+
http_req_failed: ['rate<{{errorRateThreshold}}'],
|
|
773
|
+
},
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
export default function () {
|
|
777
|
+
const res = http.get('{{targetUrl}}');
|
|
778
|
+
check(res, {
|
|
779
|
+
'status is 200': (r) => r.status === 200,
|
|
780
|
+
'response time < {{p95ThresholdMs}}ms': (r) => r.timings.duration < {{p95ThresholdMs}},
|
|
781
|
+
});
|
|
782
|
+
sleep(1);
|
|
783
|
+
}`,
|
|
784
|
+
variables: [
|
|
785
|
+
{ name: 'targetUrl', type: 'string', required: true, description: 'Target URL to load test' },
|
|
786
|
+
{ name: 'peakUsers', type: 'number', required: true, description: 'Peak concurrent users' },
|
|
787
|
+
{ name: 'rampUpDuration', type: 'string', required: false, defaultValue: '2m', description: 'Ramp-up duration' },
|
|
788
|
+
{ name: 'steadyDuration', type: 'string', required: false, defaultValue: '5m', description: 'Steady state duration' },
|
|
789
|
+
{ name: 'rampDownDuration', type: 'string', required: false, defaultValue: '1m', description: 'Ramp-down duration' },
|
|
790
|
+
{ name: 'p95ThresholdMs', type: 'number', required: false, defaultValue: 500, description: 'P95 latency threshold in ms' },
|
|
791
|
+
{ name: 'errorRateThreshold', type: 'number', required: false, defaultValue: 0.01, description: 'Max error rate (0-1)' },
|
|
792
|
+
],
|
|
793
|
+
},
|
|
794
|
+
context: {
|
|
795
|
+
tags: ['load-test', 'k6', 'performance', 'sla'],
|
|
796
|
+
},
|
|
797
|
+
confidence: 0.6,
|
|
798
|
+
},
|
|
799
|
+
{
|
|
800
|
+
patternType: 'perf-benchmark',
|
|
801
|
+
name: 'Circuit Breaker Resilience Test',
|
|
802
|
+
description: 'Test circuit breaker behavior under fault injection',
|
|
803
|
+
template: {
|
|
804
|
+
type: 'prompt',
|
|
805
|
+
content: `Resilience test for {{serviceName}} circuit breaker:
|
|
806
|
+
|
|
807
|
+
1. **Closed state**: Verify normal requests pass through
|
|
808
|
+
2. **Fault injection**: Inject {{faultType}} faults at {{faultRate}}% rate
|
|
809
|
+
3. **Trip threshold**: Verify breaker opens after {{failureThreshold}} consecutive failures
|
|
810
|
+
4. **Open state**: Verify requests fail fast (no upstream calls)
|
|
811
|
+
5. **Half-open probe**: After {{cooldownMs}}ms, verify single probe request
|
|
812
|
+
6. **Recovery**: On probe success, verify breaker closes and traffic resumes
|
|
813
|
+
7. **Metrics**: Verify circuit state changes are logged and observable`,
|
|
814
|
+
variables: [
|
|
815
|
+
{ name: 'serviceName', type: 'string', required: true, description: 'Service with circuit breaker' },
|
|
816
|
+
{ name: 'faultType', type: 'string', required: false, defaultValue: 'latency', description: 'Type of fault (latency/error/timeout)' },
|
|
817
|
+
{ name: 'faultRate', type: 'number', required: false, defaultValue: 50, description: 'Fault injection rate %' },
|
|
818
|
+
{ name: 'failureThreshold', type: 'number', required: false, defaultValue: 5, description: 'Failures to trip breaker' },
|
|
819
|
+
{ name: 'cooldownMs', type: 'number', required: false, defaultValue: 30000, description: 'Cooldown before half-open' },
|
|
820
|
+
],
|
|
821
|
+
},
|
|
822
|
+
context: {
|
|
823
|
+
tags: ['chaos', 'circuit-breaker', 'resilience', 'fault-injection'],
|
|
824
|
+
},
|
|
825
|
+
confidence: 0.6,
|
|
826
|
+
},
|
|
827
|
+
// ================================================================
|
|
828
|
+
// learning-optimization domain seeds
|
|
829
|
+
// ================================================================
|
|
830
|
+
{
|
|
831
|
+
patternType: 'coverage-strategy',
|
|
832
|
+
qeDomain: 'learning-optimization',
|
|
833
|
+
name: 'Cross-Domain Pattern Transfer',
|
|
834
|
+
description: 'Strategy for transferring useful patterns from one QE domain to related domains',
|
|
835
|
+
template: {
|
|
836
|
+
type: 'prompt',
|
|
837
|
+
content: `Pattern transfer from {{sourceDomain}} to {{targetDomain}}:
|
|
838
|
+
|
|
839
|
+
1. Identify generalizable patterns in source domain (success rate > 70%)
|
|
840
|
+
2. Check domain compatibility (related domains get 80% relevance, unrelated 50%)
|
|
841
|
+
3. Adapt pattern context: replace domain-specific terms with target equivalents
|
|
842
|
+
4. Set transferred pattern confidence to source * compatibility factor
|
|
843
|
+
5. Store in target domain with provenance metadata
|
|
844
|
+
6. Track transfer outcomes to learn which transfers are valuable`,
|
|
845
|
+
variables: [
|
|
846
|
+
{ name: 'sourceDomain', type: 'string', required: true, description: 'Source QE domain' },
|
|
847
|
+
{ name: 'targetDomain', type: 'string', required: true, description: 'Target QE domain' },
|
|
848
|
+
],
|
|
849
|
+
},
|
|
850
|
+
context: {
|
|
851
|
+
tags: ['transfer', 'cross-domain', 'learning', 'pattern-reuse'],
|
|
852
|
+
},
|
|
853
|
+
confidence: 0.6,
|
|
854
|
+
},
|
|
855
|
+
{
|
|
856
|
+
patternType: 'coverage-strategy',
|
|
857
|
+
qeDomain: 'learning-optimization',
|
|
858
|
+
name: 'Pattern Quality Promotion Pipeline',
|
|
859
|
+
description: 'Pipeline for promoting short-term patterns to long-term based on success evidence',
|
|
860
|
+
template: {
|
|
861
|
+
type: 'prompt',
|
|
862
|
+
content: `Pattern promotion evaluation for {{patternName}}:
|
|
863
|
+
|
|
864
|
+
Criteria (all must pass):
|
|
865
|
+
1. Usage count >= 3 successful applications
|
|
866
|
+
2. Success rate >= 70%
|
|
867
|
+
3. Confidence score >= 0.6
|
|
868
|
+
4. Coherence check: no contradiction with existing long-term patterns
|
|
869
|
+
5. Age: pattern has existed for at least 24 hours (not rushed)
|
|
870
|
+
|
|
871
|
+
On promotion:
|
|
872
|
+
- Move from short-term to long-term tier
|
|
873
|
+
- Boost confidence by 10%
|
|
874
|
+
- Enable for cross-domain transfer to related domains
|
|
875
|
+
- Mark as reusable for token savings optimization`,
|
|
876
|
+
variables: [
|
|
877
|
+
{ name: 'patternName', type: 'string', required: true, description: 'Pattern to evaluate for promotion' },
|
|
878
|
+
],
|
|
879
|
+
},
|
|
880
|
+
context: {
|
|
881
|
+
tags: ['promotion', 'learning', 'quality', 'pipeline'],
|
|
882
|
+
},
|
|
883
|
+
confidence: 0.6,
|
|
884
|
+
},
|
|
282
885
|
];
|
|
283
886
|
for (const options of foundationalPatterns) {
|
|
284
887
|
try {
|
|
@@ -290,6 +893,100 @@ Check for:
|
|
|
290
893
|
}
|
|
291
894
|
console.log(`[QEReasoningBank] Loaded ${foundationalPatterns.length} foundational patterns`);
|
|
292
895
|
}
|
|
896
|
+
/**
|
|
897
|
+
* Seed cross-domain patterns by transferring generalizable patterns
|
|
898
|
+
* from populated domains to their related domains.
|
|
899
|
+
*
|
|
900
|
+
* Uses the domain compatibility matrix to determine which domains
|
|
901
|
+
* are related and applies a relevance decay to transferred patterns.
|
|
902
|
+
*/
|
|
903
|
+
async seedCrossDomainPatterns() {
|
|
904
|
+
if (!this.initialized) {
|
|
905
|
+
await this.initialize();
|
|
906
|
+
}
|
|
907
|
+
const stats = await this.patternStore.getStats();
|
|
908
|
+
let transferred = 0;
|
|
909
|
+
let skipped = 0;
|
|
910
|
+
// Domain compatibility matrix (same as TransferSpecialistService)
|
|
911
|
+
const relatedDomains = {
|
|
912
|
+
'test-generation': ['test-execution', 'coverage-analysis', 'requirements-validation'],
|
|
913
|
+
'test-execution': ['test-generation', 'coverage-analysis', 'quality-assessment'],
|
|
914
|
+
'coverage-analysis': ['test-generation', 'test-execution', 'quality-assessment'],
|
|
915
|
+
'quality-assessment': ['test-execution', 'coverage-analysis', 'defect-intelligence'],
|
|
916
|
+
'defect-intelligence': ['quality-assessment', 'code-intelligence'],
|
|
917
|
+
'requirements-validation': ['test-generation', 'quality-assessment'],
|
|
918
|
+
'code-intelligence': ['defect-intelligence', 'security-compliance'],
|
|
919
|
+
'security-compliance': ['code-intelligence', 'quality-assessment'],
|
|
920
|
+
'contract-testing': ['test-generation', 'test-execution'],
|
|
921
|
+
'visual-accessibility': ['quality-assessment'],
|
|
922
|
+
'chaos-resilience': ['test-execution', 'quality-assessment'],
|
|
923
|
+
'learning-optimization': ['test-generation', 'test-execution', 'coverage-analysis', 'quality-assessment', 'defect-intelligence'],
|
|
924
|
+
};
|
|
925
|
+
// For each domain that has patterns, transfer to related domains
|
|
926
|
+
for (const [sourceDomainStr, targetDomains] of Object.entries(relatedDomains)) {
|
|
927
|
+
const sourceDomain = sourceDomainStr;
|
|
928
|
+
const sourceCount = stats.byDomain[sourceDomain] || 0;
|
|
929
|
+
if (sourceCount === 0)
|
|
930
|
+
continue;
|
|
931
|
+
// Get source domain patterns
|
|
932
|
+
const sourceResult = await this.searchPatterns('', {
|
|
933
|
+
domain: sourceDomain,
|
|
934
|
+
limit: 50,
|
|
935
|
+
});
|
|
936
|
+
if (!sourceResult.success)
|
|
937
|
+
continue;
|
|
938
|
+
for (const targetDomain of targetDomains) {
|
|
939
|
+
// Only transfer to domains that have few patterns (less than source)
|
|
940
|
+
const targetCount = stats.byDomain[targetDomain] || 0;
|
|
941
|
+
if (targetCount >= sourceCount) {
|
|
942
|
+
skipped++;
|
|
943
|
+
continue;
|
|
944
|
+
}
|
|
945
|
+
// Transfer each source pattern to the target domain
|
|
946
|
+
for (const { pattern: sourcePattern } of sourceResult.value) {
|
|
947
|
+
// Check if a similar pattern already exists in target domain
|
|
948
|
+
const existingCheck = await this.searchPatterns(sourcePattern.name, {
|
|
949
|
+
domain: targetDomain,
|
|
950
|
+
limit: 1,
|
|
951
|
+
});
|
|
952
|
+
if (existingCheck.success && existingCheck.value.length > 0) {
|
|
953
|
+
const bestMatch = existingCheck.value[0];
|
|
954
|
+
if (bestMatch.score > 0.8) {
|
|
955
|
+
skipped++;
|
|
956
|
+
continue; // Similar pattern already exists
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
// Create transferred pattern with reduced confidence
|
|
960
|
+
const transferredConfidence = Math.max(0.3, (sourcePattern.confidence || 0.5) * 0.8);
|
|
961
|
+
const transferResult = await this.storePattern({
|
|
962
|
+
patternType: sourcePattern.patternType,
|
|
963
|
+
qeDomain: targetDomain,
|
|
964
|
+
name: `${sourcePattern.name} (from ${sourceDomain})`,
|
|
965
|
+
description: `${sourcePattern.description} [Transferred from ${sourceDomain} domain]`,
|
|
966
|
+
template: sourcePattern.template,
|
|
967
|
+
context: {
|
|
968
|
+
...sourcePattern.context,
|
|
969
|
+
relatedDomains: [sourceDomain, targetDomain],
|
|
970
|
+
tags: [
|
|
971
|
+
...sourcePattern.context.tags,
|
|
972
|
+
'cross-domain-transfer',
|
|
973
|
+
`source:${sourceDomain}`,
|
|
974
|
+
],
|
|
975
|
+
},
|
|
976
|
+
confidence: transferredConfidence,
|
|
977
|
+
});
|
|
978
|
+
if (transferResult.success) {
|
|
979
|
+
transferred++;
|
|
980
|
+
}
|
|
981
|
+
else {
|
|
982
|
+
skipped++;
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
console.log(`[QEReasoningBank] Cross-domain transfer complete: ${transferred} transferred, ${skipped} skipped`);
|
|
988
|
+
return { transferred, skipped };
|
|
989
|
+
}
|
|
293
990
|
/**
|
|
294
991
|
* Store a new pattern
|
|
295
992
|
*/
|
|
@@ -357,6 +1054,18 @@ Check for:
|
|
|
357
1054
|
return ok(undefined);
|
|
358
1055
|
}
|
|
359
1056
|
const result = await this.patternStore.recordUsage(outcome.patternId, outcome.success);
|
|
1057
|
+
// Write to qe_pattern_usage table for analytics/feedback loop
|
|
1058
|
+
try {
|
|
1059
|
+
const { getUnifiedMemory } = await import('../kernel/unified-memory.js');
|
|
1060
|
+
const db = getUnifiedMemory().getDatabase();
|
|
1061
|
+
db.prepare(`
|
|
1062
|
+
INSERT INTO qe_pattern_usage (pattern_id, success, metrics_json, feedback)
|
|
1063
|
+
VALUES (?, ?, ?, ?)
|
|
1064
|
+
`).run(outcome.patternId, outcome.success ? 1 : 0, outcome.metrics ? JSON.stringify(outcome.metrics) : null, outcome.feedback || null);
|
|
1065
|
+
}
|
|
1066
|
+
catch {
|
|
1067
|
+
// Non-critical — don't fail if analytics insert fails
|
|
1068
|
+
}
|
|
360
1069
|
if (result.success) {
|
|
361
1070
|
this.stats.learningOutcomes++;
|
|
362
1071
|
if (outcome.success) {
|