agentic-qe 3.8.11 → 3.8.13
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/qe-code-intelligence/SKILL.md +29 -20
- package/.claude/skills/qe-code-intelligence/evals/qe-code-intelligence.yaml +3 -3
- package/.claude/skills/qe-quality-assessment/SKILL.md +1 -1
- package/.claude/skills/qe-test-generation/SKILL.md +1 -1
- package/.claude/skills/skills-manifest.json +1 -1
- package/CHANGELOG.md +45 -0
- package/README.md +9 -0
- package/assets/skills/qe-code-intelligence/SKILL.md +29 -20
- package/assets/skills/qe-code-intelligence/evals/qe-code-intelligence.yaml +3 -3
- package/assets/skills/qe-quality-assessment/SKILL.md +1 -1
- package/assets/skills/qe-test-generation/SKILL.md +1 -1
- package/dist/cli/bundle.js +1162 -1046
- package/dist/cli/commands/code.js +149 -11
- package/dist/cli/commands/init.js +3 -2
- package/dist/cli/commands/ruvector-commands.js +17 -0
- package/dist/cli/handlers/init-handler.d.ts +1 -0
- package/dist/cli/handlers/init-handler.js +15 -10
- package/dist/cli/utils/file-discovery.d.ts +1 -0
- package/dist/cli/utils/file-discovery.js +1 -1
- package/dist/domains/code-intelligence/coordinator-gnn.d.ts +21 -0
- package/dist/domains/code-intelligence/coordinator-gnn.js +102 -0
- package/dist/domains/contract-testing/coordinator.js +13 -0
- package/dist/domains/coverage-analysis/coordinator.js +5 -0
- package/dist/domains/defect-intelligence/coordinator.d.ts +1 -0
- package/dist/domains/defect-intelligence/coordinator.js +43 -0
- package/dist/domains/quality-assessment/coordinator.js +26 -0
- package/dist/domains/test-generation/coordinator.js +14 -0
- package/dist/init/orchestrator.js +1 -0
- package/dist/init/phases/08-mcp.js +4 -4
- package/dist/init/phases/phase-interface.d.ts +3 -1
- package/dist/integrations/agentic-flow/reasoning-bank/experience-replay.d.ts +11 -0
- package/dist/integrations/agentic-flow/reasoning-bank/experience-replay.js +44 -1
- package/dist/integrations/rl-suite/algorithms/eprop.d.ts +79 -0
- package/dist/integrations/rl-suite/algorithms/eprop.js +284 -0
- package/dist/integrations/rl-suite/algorithms/index.d.ts +2 -1
- package/dist/integrations/rl-suite/algorithms/index.js +2 -1
- package/dist/integrations/rl-suite/index.d.ts +2 -2
- package/dist/integrations/rl-suite/index.js +2 -2
- package/dist/integrations/rl-suite/interfaces.d.ts +3 -3
- package/dist/integrations/rl-suite/interfaces.js +1 -1
- package/dist/integrations/rl-suite/orchestrator.d.ts +2 -2
- package/dist/integrations/rl-suite/orchestrator.js +3 -2
- package/dist/integrations/rl-suite/reward-signals.d.ts +1 -1
- package/dist/integrations/rl-suite/reward-signals.js +1 -1
- package/dist/integrations/ruvector/coherence-gate-cohomology.d.ts +41 -0
- package/dist/integrations/ruvector/coherence-gate-cohomology.js +47 -0
- package/dist/integrations/ruvector/coherence-gate-core.d.ts +200 -0
- package/dist/integrations/ruvector/coherence-gate-core.js +294 -0
- package/dist/integrations/ruvector/coherence-gate-energy.d.ts +136 -0
- package/dist/integrations/ruvector/coherence-gate-energy.js +373 -0
- package/dist/integrations/ruvector/coherence-gate-vector.d.ts +38 -0
- package/dist/integrations/ruvector/coherence-gate-vector.js +76 -0
- package/dist/integrations/ruvector/coherence-gate.d.ts +10 -311
- package/dist/integrations/ruvector/coherence-gate.js +10 -652
- package/dist/integrations/ruvector/cold-tier-trainer.d.ts +103 -0
- package/dist/integrations/ruvector/cold-tier-trainer.js +377 -0
- package/dist/integrations/ruvector/cusum-detector.d.ts +70 -0
- package/dist/integrations/ruvector/cusum-detector.js +142 -0
- package/dist/integrations/ruvector/delta-tracker.d.ts +122 -0
- package/dist/integrations/ruvector/delta-tracker.js +311 -0
- package/dist/integrations/ruvector/domain-transfer.d.ts +79 -1
- package/dist/integrations/ruvector/domain-transfer.js +158 -2
- package/dist/integrations/ruvector/eprop-learner.d.ts +135 -0
- package/dist/integrations/ruvector/eprop-learner.js +351 -0
- package/dist/integrations/ruvector/feature-flags.d.ts +177 -0
- package/dist/integrations/ruvector/feature-flags.js +145 -0
- package/dist/integrations/ruvector/graphmae-encoder.d.ts +88 -0
- package/dist/integrations/ruvector/graphmae-encoder.js +360 -0
- package/dist/integrations/ruvector/hdc-fingerprint.d.ts +127 -0
- package/dist/integrations/ruvector/hdc-fingerprint.js +222 -0
- package/dist/integrations/ruvector/hopfield-memory.d.ts +97 -0
- package/dist/integrations/ruvector/hopfield-memory.js +238 -0
- package/dist/integrations/ruvector/index.d.ts +13 -2
- package/dist/integrations/ruvector/index.js +46 -2
- package/dist/integrations/ruvector/mincut-wrapper.d.ts +7 -0
- package/dist/integrations/ruvector/mincut-wrapper.js +54 -2
- package/dist/integrations/ruvector/reservoir-replay.d.ts +172 -0
- package/dist/integrations/ruvector/reservoir-replay.js +335 -0
- package/dist/integrations/ruvector/solver-adapter.d.ts +93 -0
- package/dist/integrations/ruvector/solver-adapter.js +299 -0
- package/dist/integrations/ruvector/sona-persistence.d.ts +33 -0
- package/dist/integrations/ruvector/sona-persistence.js +47 -0
- package/dist/integrations/ruvector/spectral-sparsifier.d.ts +154 -0
- package/dist/integrations/ruvector/spectral-sparsifier.js +389 -0
- package/dist/integrations/ruvector/temporal-causality.d.ts +63 -0
- package/dist/integrations/ruvector/temporal-causality.js +317 -0
- package/dist/learning/pattern-promotion.d.ts +63 -0
- package/dist/learning/pattern-promotion.js +235 -1
- package/dist/learning/pattern-store.d.ts +2 -0
- package/dist/learning/pattern-store.js +187 -1
- package/dist/learning/sqlite-persistence.d.ts +2 -0
- package/dist/learning/sqlite-persistence.js +4 -0
- package/dist/mcp/bundle.js +506 -427
- package/dist/shared/utils/index.d.ts +1 -0
- package/dist/shared/utils/index.js +1 -0
- package/dist/shared/utils/xorshift128.d.ts +24 -0
- package/dist/shared/utils/xorshift128.js +50 -0
- package/package.json +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* R3: Delta Event Sourcing for Pattern History
|
|
3
|
+
*
|
|
4
|
+
* Tracks pattern version history as a sequence of delta events.
|
|
5
|
+
* Enables rollback to any previous state and incremental sync between agents.
|
|
6
|
+
* Uses SQLite for persistence via the existing database layer.
|
|
7
|
+
*
|
|
8
|
+
* @module integrations/ruvector/delta-tracker
|
|
9
|
+
*/
|
|
10
|
+
import { type Database as DatabaseType } from 'better-sqlite3';
|
|
11
|
+
/**
|
|
12
|
+
* RFC 6902 JSON Patch operation
|
|
13
|
+
*/
|
|
14
|
+
export interface JsonPatch {
|
|
15
|
+
op: 'add' | 'remove' | 'replace' | 'move' | 'copy' | 'test';
|
|
16
|
+
path: string;
|
|
17
|
+
value?: unknown;
|
|
18
|
+
from?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A single delta event representing a change to a pattern
|
|
22
|
+
*/
|
|
23
|
+
export interface DeltaEvent {
|
|
24
|
+
/** Unique delta ID (UUID) */
|
|
25
|
+
id: string;
|
|
26
|
+
/** Pattern being tracked */
|
|
27
|
+
patternId: string;
|
|
28
|
+
/** Sequential version number (0 = genesis) */
|
|
29
|
+
version: number;
|
|
30
|
+
/** Unix timestamp in milliseconds */
|
|
31
|
+
timestamp: number;
|
|
32
|
+
/** Event type */
|
|
33
|
+
type: 'genesis' | 'update' | 'rollback';
|
|
34
|
+
/** RFC 6902 JSON Patch operations (forward) */
|
|
35
|
+
patch: JsonPatch[];
|
|
36
|
+
/** RFC 6902 JSON Patch operations (reverse, for undo) */
|
|
37
|
+
reversePatch: JsonPatch[];
|
|
38
|
+
/** Optional metadata */
|
|
39
|
+
metadata?: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Configuration for the DeltaTracker
|
|
43
|
+
*/
|
|
44
|
+
export interface DeltaTrackerConfig {
|
|
45
|
+
/** Maximum versions to retain per pattern. Default: 100 */
|
|
46
|
+
maxVersionsPerPattern?: number;
|
|
47
|
+
/** Reserved for future LZ4 compression support. Default: false */
|
|
48
|
+
compressDeltas?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* DDL for the pattern_deltas table
|
|
52
|
+
*/
|
|
53
|
+
export declare const PATTERN_DELTAS_SCHEMA = "\n CREATE TABLE IF NOT EXISTS pattern_deltas (\n id TEXT PRIMARY KEY,\n pattern_id TEXT NOT NULL,\n version INTEGER NOT NULL,\n timestamp INTEGER NOT NULL,\n type TEXT NOT NULL CHECK (type IN ('genesis', 'update', 'rollback')),\n patch TEXT NOT NULL DEFAULT '[]',\n reverse_patch TEXT NOT NULL DEFAULT '[]',\n metadata TEXT\n );\n CREATE INDEX IF NOT EXISTS idx_pattern_deltas_pid_version\n ON pattern_deltas (pattern_id, version);\n CREATE INDEX IF NOT EXISTS idx_pattern_deltas_timestamp\n ON pattern_deltas (timestamp);\n";
|
|
54
|
+
/**
|
|
55
|
+
* Tracks pattern version history as delta events with rollback support.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const tracker = new DeltaTracker(db);
|
|
60
|
+
* tracker.initialize();
|
|
61
|
+
*
|
|
62
|
+
* tracker.createGenesis('pat-1', { name: 'Login test', confidence: 0.5 });
|
|
63
|
+
* tracker.recordDelta('pat-1', { name: 'Login test', confidence: 0.5 }, { name: 'Login test', confidence: 0.9 });
|
|
64
|
+
*
|
|
65
|
+
* const state = tracker.rollback('pat-1', 0); // back to genesis
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare class DeltaTracker {
|
|
69
|
+
private readonly db;
|
|
70
|
+
private readonly config;
|
|
71
|
+
private prepared;
|
|
72
|
+
private initialized;
|
|
73
|
+
constructor(db: DatabaseType, config?: DeltaTrackerConfig);
|
|
74
|
+
/**
|
|
75
|
+
* Create the pattern_deltas table and indexes if they do not exist.
|
|
76
|
+
*/
|
|
77
|
+
initialize(): void;
|
|
78
|
+
private prepareStatements;
|
|
79
|
+
private ensureInitialized;
|
|
80
|
+
/**
|
|
81
|
+
* Create a genesis snapshot for a pattern (version 0).
|
|
82
|
+
* The full object is stored in metadata.snapshot; patches are empty.
|
|
83
|
+
*/
|
|
84
|
+
createGenesis(patternId: string, snapshot: object, metadata?: Record<string, unknown>): DeltaEvent;
|
|
85
|
+
/**
|
|
86
|
+
* Record a delta between two states of a pattern.
|
|
87
|
+
* Computes forward and reverse patches automatically.
|
|
88
|
+
*/
|
|
89
|
+
recordDelta(patternId: string, before: object, after: object, metadata?: Record<string, unknown>): DeltaEvent;
|
|
90
|
+
/**
|
|
91
|
+
* Rollback a pattern to a specific version by applying reverse patches
|
|
92
|
+
* from the current version back to the target version.
|
|
93
|
+
*
|
|
94
|
+
* Returns the reconstructed object at the target version.
|
|
95
|
+
*/
|
|
96
|
+
rollback(patternId: string, toVersion: number): object;
|
|
97
|
+
/**
|
|
98
|
+
* Get the full delta history for a pattern, ordered by version ascending.
|
|
99
|
+
*/
|
|
100
|
+
getHistory(patternId: string): DeltaEvent[];
|
|
101
|
+
/**
|
|
102
|
+
* Get all delta events created after a given timestamp (for incremental sync).
|
|
103
|
+
*/
|
|
104
|
+
incrementalSync(since: number): DeltaEvent[];
|
|
105
|
+
/**
|
|
106
|
+
* Get the current (highest) version number for a pattern.
|
|
107
|
+
* Returns -1 if no events exist for the pattern.
|
|
108
|
+
*/
|
|
109
|
+
getCurrentVersion(patternId: string): number;
|
|
110
|
+
private insertEvent;
|
|
111
|
+
/**
|
|
112
|
+
* Reconstruct pattern state at a given version by replaying patches
|
|
113
|
+
* from genesis forward.
|
|
114
|
+
*/
|
|
115
|
+
private reconstructState;
|
|
116
|
+
/**
|
|
117
|
+
* Enforce maxVersionsPerPattern retention by deleting oldest deltas.
|
|
118
|
+
* Always keeps the genesis event (version 0).
|
|
119
|
+
*/
|
|
120
|
+
private enforceRetention;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=delta-tracker.d.ts.map
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* R3: Delta Event Sourcing for Pattern History
|
|
3
|
+
*
|
|
4
|
+
* Tracks pattern version history as a sequence of delta events.
|
|
5
|
+
* Enables rollback to any previous state and incremental sync between agents.
|
|
6
|
+
* Uses SQLite for persistence via the existing database layer.
|
|
7
|
+
*
|
|
8
|
+
* @module integrations/ruvector/delta-tracker
|
|
9
|
+
*/
|
|
10
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
11
|
+
import * as fastJsonPatch from 'fast-json-patch';
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Schema
|
|
14
|
+
// ============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* DDL for the pattern_deltas table
|
|
17
|
+
*/
|
|
18
|
+
export const PATTERN_DELTAS_SCHEMA = `
|
|
19
|
+
CREATE TABLE IF NOT EXISTS pattern_deltas (
|
|
20
|
+
id TEXT PRIMARY KEY,
|
|
21
|
+
pattern_id TEXT NOT NULL,
|
|
22
|
+
version INTEGER NOT NULL,
|
|
23
|
+
timestamp INTEGER NOT NULL,
|
|
24
|
+
type TEXT NOT NULL CHECK (type IN ('genesis', 'update', 'rollback')),
|
|
25
|
+
patch TEXT NOT NULL DEFAULT '[]',
|
|
26
|
+
reverse_patch TEXT NOT NULL DEFAULT '[]',
|
|
27
|
+
metadata TEXT
|
|
28
|
+
);
|
|
29
|
+
CREATE INDEX IF NOT EXISTS idx_pattern_deltas_pid_version
|
|
30
|
+
ON pattern_deltas (pattern_id, version);
|
|
31
|
+
CREATE INDEX IF NOT EXISTS idx_pattern_deltas_timestamp
|
|
32
|
+
ON pattern_deltas (timestamp);
|
|
33
|
+
`;
|
|
34
|
+
// ============================================================================
|
|
35
|
+
// Internal helpers
|
|
36
|
+
// ============================================================================
|
|
37
|
+
/**
|
|
38
|
+
* Compute forward and reverse RFC 6902 patches between two objects.
|
|
39
|
+
* Uses fast-json-patch for reliable diff generation.
|
|
40
|
+
*/
|
|
41
|
+
function computePatches(before, after) {
|
|
42
|
+
const forward = fastJsonPatch.compare(before, after);
|
|
43
|
+
const reverse = fastJsonPatch.compare(after, before);
|
|
44
|
+
return { forward, reverse };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Apply a sequence of JSON Patch operations to an object (immutable).
|
|
48
|
+
* Returns a deep clone with patches applied.
|
|
49
|
+
*/
|
|
50
|
+
function applyPatches(obj, patches) {
|
|
51
|
+
const cloned = JSON.parse(JSON.stringify(obj));
|
|
52
|
+
const result = fastJsonPatch.applyPatch(cloned, patches);
|
|
53
|
+
return result.newDocument;
|
|
54
|
+
}
|
|
55
|
+
function rowToEvent(row) {
|
|
56
|
+
return {
|
|
57
|
+
id: row.id,
|
|
58
|
+
patternId: row.pattern_id,
|
|
59
|
+
version: row.version,
|
|
60
|
+
timestamp: row.timestamp,
|
|
61
|
+
type: row.type,
|
|
62
|
+
patch: JSON.parse(row.patch),
|
|
63
|
+
reversePatch: JSON.parse(row.reverse_patch),
|
|
64
|
+
metadata: row.metadata ? JSON.parse(row.metadata) : undefined,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// ============================================================================
|
|
68
|
+
// DeltaTracker
|
|
69
|
+
// ============================================================================
|
|
70
|
+
/**
|
|
71
|
+
* Tracks pattern version history as delta events with rollback support.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const tracker = new DeltaTracker(db);
|
|
76
|
+
* tracker.initialize();
|
|
77
|
+
*
|
|
78
|
+
* tracker.createGenesis('pat-1', { name: 'Login test', confidence: 0.5 });
|
|
79
|
+
* tracker.recordDelta('pat-1', { name: 'Login test', confidence: 0.5 }, { name: 'Login test', confidence: 0.9 });
|
|
80
|
+
*
|
|
81
|
+
* const state = tracker.rollback('pat-1', 0); // back to genesis
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export class DeltaTracker {
|
|
85
|
+
db;
|
|
86
|
+
config;
|
|
87
|
+
prepared = new Map();
|
|
88
|
+
initialized = false;
|
|
89
|
+
constructor(db, config) {
|
|
90
|
+
this.db = db;
|
|
91
|
+
this.config = {
|
|
92
|
+
maxVersionsPerPattern: config?.maxVersionsPerPattern ?? 100,
|
|
93
|
+
compressDeltas: config?.compressDeltas ?? false,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
// --------------------------------------------------------------------------
|
|
97
|
+
// Initialization
|
|
98
|
+
// --------------------------------------------------------------------------
|
|
99
|
+
/**
|
|
100
|
+
* Create the pattern_deltas table and indexes if they do not exist.
|
|
101
|
+
*/
|
|
102
|
+
initialize() {
|
|
103
|
+
if (this.initialized)
|
|
104
|
+
return;
|
|
105
|
+
this.db.exec(PATTERN_DELTAS_SCHEMA);
|
|
106
|
+
this.prepareStatements();
|
|
107
|
+
this.initialized = true;
|
|
108
|
+
}
|
|
109
|
+
prepareStatements() {
|
|
110
|
+
this.prepared.set('insert', this.db.prepare(`
|
|
111
|
+
INSERT INTO pattern_deltas (id, pattern_id, version, timestamp, type, patch, reverse_patch, metadata)
|
|
112
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
113
|
+
`));
|
|
114
|
+
this.prepared.set('getHistory', this.db.prepare(`
|
|
115
|
+
SELECT * FROM pattern_deltas
|
|
116
|
+
WHERE pattern_id = ?
|
|
117
|
+
ORDER BY version ASC
|
|
118
|
+
`));
|
|
119
|
+
this.prepared.set('currentVersion', this.db.prepare(`
|
|
120
|
+
SELECT MAX(version) as max_version FROM pattern_deltas
|
|
121
|
+
WHERE pattern_id = ?
|
|
122
|
+
`));
|
|
123
|
+
this.prepared.set('incrementalSync', this.db.prepare(`
|
|
124
|
+
SELECT * FROM pattern_deltas
|
|
125
|
+
WHERE timestamp > ?
|
|
126
|
+
ORDER BY timestamp ASC
|
|
127
|
+
`));
|
|
128
|
+
this.prepared.set('countForPattern', this.db.prepare(`
|
|
129
|
+
SELECT COUNT(*) as cnt FROM pattern_deltas
|
|
130
|
+
WHERE pattern_id = ?
|
|
131
|
+
`));
|
|
132
|
+
this.prepared.set('deleteOldest', this.db.prepare(`
|
|
133
|
+
DELETE FROM pattern_deltas
|
|
134
|
+
WHERE pattern_id = ? AND version IN (
|
|
135
|
+
SELECT version FROM pattern_deltas
|
|
136
|
+
WHERE pattern_id = ?
|
|
137
|
+
ORDER BY version ASC
|
|
138
|
+
LIMIT ?
|
|
139
|
+
)
|
|
140
|
+
`));
|
|
141
|
+
}
|
|
142
|
+
ensureInitialized() {
|
|
143
|
+
if (!this.initialized) {
|
|
144
|
+
throw new Error('DeltaTracker not initialized. Call initialize() first.');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// --------------------------------------------------------------------------
|
|
148
|
+
// Public API
|
|
149
|
+
// --------------------------------------------------------------------------
|
|
150
|
+
/**
|
|
151
|
+
* Create a genesis snapshot for a pattern (version 0).
|
|
152
|
+
* The full object is stored in metadata.snapshot; patches are empty.
|
|
153
|
+
*/
|
|
154
|
+
createGenesis(patternId, snapshot, metadata) {
|
|
155
|
+
this.ensureInitialized();
|
|
156
|
+
const existing = this.getCurrentVersion(patternId);
|
|
157
|
+
if (existing >= 0) {
|
|
158
|
+
throw new Error(`Genesis already exists for pattern ${patternId} (current version: ${existing})`);
|
|
159
|
+
}
|
|
160
|
+
const event = {
|
|
161
|
+
id: uuidv4(),
|
|
162
|
+
patternId,
|
|
163
|
+
version: 0,
|
|
164
|
+
timestamp: Date.now(),
|
|
165
|
+
type: 'genesis',
|
|
166
|
+
patch: [],
|
|
167
|
+
reversePatch: [],
|
|
168
|
+
metadata: { ...metadata, snapshot },
|
|
169
|
+
};
|
|
170
|
+
this.insertEvent(event);
|
|
171
|
+
return event;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Record a delta between two states of a pattern.
|
|
175
|
+
* Computes forward and reverse patches automatically.
|
|
176
|
+
*/
|
|
177
|
+
recordDelta(patternId, before, after, metadata) {
|
|
178
|
+
this.ensureInitialized();
|
|
179
|
+
const currentVersion = this.getCurrentVersion(patternId);
|
|
180
|
+
if (currentVersion < 0) {
|
|
181
|
+
throw new Error(`No genesis found for pattern ${patternId}. Call createGenesis() first.`);
|
|
182
|
+
}
|
|
183
|
+
const { forward, reverse } = computePatches(before, after);
|
|
184
|
+
const event = {
|
|
185
|
+
id: uuidv4(),
|
|
186
|
+
patternId,
|
|
187
|
+
version: currentVersion + 1,
|
|
188
|
+
timestamp: Date.now(),
|
|
189
|
+
type: 'update',
|
|
190
|
+
patch: forward,
|
|
191
|
+
reversePatch: reverse,
|
|
192
|
+
metadata,
|
|
193
|
+
};
|
|
194
|
+
this.insertEvent(event);
|
|
195
|
+
this.enforceRetention(patternId);
|
|
196
|
+
return event;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Rollback a pattern to a specific version by applying reverse patches
|
|
200
|
+
* from the current version back to the target version.
|
|
201
|
+
*
|
|
202
|
+
* Returns the reconstructed object at the target version.
|
|
203
|
+
*/
|
|
204
|
+
rollback(patternId, toVersion) {
|
|
205
|
+
this.ensureInitialized();
|
|
206
|
+
const history = this.getHistory(patternId);
|
|
207
|
+
if (history.length === 0) {
|
|
208
|
+
throw new Error(`No history found for pattern ${patternId}`);
|
|
209
|
+
}
|
|
210
|
+
const currentVersion = history[history.length - 1].version;
|
|
211
|
+
if (toVersion < 0 || toVersion > currentVersion) {
|
|
212
|
+
throw new Error(`Invalid rollback version ${toVersion}. Valid range: 0-${currentVersion}`);
|
|
213
|
+
}
|
|
214
|
+
if (toVersion === currentVersion) {
|
|
215
|
+
// Already at target; reconstruct current state
|
|
216
|
+
return this.reconstructState(history, currentVersion);
|
|
217
|
+
}
|
|
218
|
+
// Reconstruct the state at the target version
|
|
219
|
+
const targetState = this.reconstructState(history, toVersion);
|
|
220
|
+
// Record a rollback event from current to target
|
|
221
|
+
const currentState = this.reconstructState(history, currentVersion);
|
|
222
|
+
const { forward, reverse } = computePatches(currentState, targetState);
|
|
223
|
+
const rollbackEvent = {
|
|
224
|
+
id: uuidv4(),
|
|
225
|
+
patternId,
|
|
226
|
+
version: currentVersion + 1,
|
|
227
|
+
timestamp: Date.now(),
|
|
228
|
+
type: 'rollback',
|
|
229
|
+
patch: forward,
|
|
230
|
+
reversePatch: reverse,
|
|
231
|
+
metadata: { rolledBackTo: toVersion },
|
|
232
|
+
};
|
|
233
|
+
this.insertEvent(rollbackEvent);
|
|
234
|
+
this.enforceRetention(patternId);
|
|
235
|
+
return targetState;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Get the full delta history for a pattern, ordered by version ascending.
|
|
239
|
+
*/
|
|
240
|
+
getHistory(patternId) {
|
|
241
|
+
this.ensureInitialized();
|
|
242
|
+
const rows = this.prepared.get('getHistory').all(patternId);
|
|
243
|
+
return rows.map(rowToEvent);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Get all delta events created after a given timestamp (for incremental sync).
|
|
247
|
+
*/
|
|
248
|
+
incrementalSync(since) {
|
|
249
|
+
this.ensureInitialized();
|
|
250
|
+
const rows = this.prepared.get('incrementalSync').all(since);
|
|
251
|
+
return rows.map(rowToEvent);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Get the current (highest) version number for a pattern.
|
|
255
|
+
* Returns -1 if no events exist for the pattern.
|
|
256
|
+
*/
|
|
257
|
+
getCurrentVersion(patternId) {
|
|
258
|
+
this.ensureInitialized();
|
|
259
|
+
const row = this.prepared.get('currentVersion').get(patternId);
|
|
260
|
+
return row.max_version ?? -1;
|
|
261
|
+
}
|
|
262
|
+
// --------------------------------------------------------------------------
|
|
263
|
+
// Internal helpers
|
|
264
|
+
// --------------------------------------------------------------------------
|
|
265
|
+
insertEvent(event) {
|
|
266
|
+
this.prepared.get('insert').run(event.id, event.patternId, event.version, event.timestamp, event.type, JSON.stringify(event.patch), JSON.stringify(event.reversePatch), event.metadata ? JSON.stringify(event.metadata) : null);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Reconstruct pattern state at a given version by replaying patches
|
|
270
|
+
* from genesis forward.
|
|
271
|
+
*/
|
|
272
|
+
reconstructState(history, targetVersion) {
|
|
273
|
+
const genesis = history.find((e) => e.type === 'genesis');
|
|
274
|
+
if (!genesis || !genesis.metadata?.snapshot) {
|
|
275
|
+
throw new Error('Cannot reconstruct state: no genesis snapshot found');
|
|
276
|
+
}
|
|
277
|
+
let state = JSON.parse(JSON.stringify(genesis.metadata.snapshot));
|
|
278
|
+
// Apply forward patches from version 1 up to targetVersion
|
|
279
|
+
for (const event of history) {
|
|
280
|
+
if (event.version === 0)
|
|
281
|
+
continue;
|
|
282
|
+
if (event.version > targetVersion)
|
|
283
|
+
break;
|
|
284
|
+
state = applyPatches(state, event.patch);
|
|
285
|
+
}
|
|
286
|
+
return state;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Enforce maxVersionsPerPattern retention by deleting oldest deltas.
|
|
290
|
+
* Always keeps the genesis event (version 0).
|
|
291
|
+
*/
|
|
292
|
+
enforceRetention(patternId) {
|
|
293
|
+
const { maxVersionsPerPattern } = this.config;
|
|
294
|
+
const row = this.prepared.get('countForPattern').get(patternId);
|
|
295
|
+
const count = row.cnt;
|
|
296
|
+
if (count > maxVersionsPerPattern) {
|
|
297
|
+
const excess = count - maxVersionsPerPattern;
|
|
298
|
+
// Delete oldest non-genesis events
|
|
299
|
+
this.db
|
|
300
|
+
.prepare(`DELETE FROM pattern_deltas
|
|
301
|
+
WHERE pattern_id = ? AND version != 0 AND id IN (
|
|
302
|
+
SELECT id FROM pattern_deltas
|
|
303
|
+
WHERE pattern_id = ? AND version != 0
|
|
304
|
+
ORDER BY version ASC
|
|
305
|
+
LIMIT ?
|
|
306
|
+
)`)
|
|
307
|
+
.run(patternId, patternId, excess);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=delta-tracker.js.map
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Enables knowledge transfer between QE domains using Thompson Sampling
|
|
5
5
|
* with Beta priors, sqrt-dampening, transfer verification gates, domain
|
|
6
|
-
* pair affinity scoring,
|
|
6
|
+
* pair affinity scoring, coherence gate integration, and R7 meta-learning
|
|
7
|
+
* enhancements (DecayingBeta, PlateauDetector, ParetoFront, CuriosityBonus).
|
|
7
8
|
*
|
|
8
9
|
* @module integrations/ruvector/domain-transfer
|
|
9
10
|
*/
|
|
@@ -59,9 +60,70 @@ export interface DomainTransferConfig {
|
|
|
59
60
|
verification: Partial<TransferVerificationConfig>;
|
|
60
61
|
/** Maximum transfer records to retain in history */
|
|
61
62
|
maxHistorySize: number;
|
|
63
|
+
/** Enable R7 meta-learning enhancements (ADR-087, Milestone 3) */
|
|
64
|
+
useMetaLearningEnhancements: boolean;
|
|
62
65
|
}
|
|
63
66
|
/** Default domain transfer configuration */
|
|
64
67
|
export declare const DEFAULT_DOMAIN_TRANSFER_CONFIG: DomainTransferConfig;
|
|
68
|
+
/** Point on the Pareto front, tracking multi-objective performance */
|
|
69
|
+
export interface ParetoPoint {
|
|
70
|
+
pairKey: string;
|
|
71
|
+
successRate: number;
|
|
72
|
+
speed: number;
|
|
73
|
+
confidence: number;
|
|
74
|
+
}
|
|
75
|
+
/** Applies time-based decay to Thompson Sampler exploration variance. */
|
|
76
|
+
export declare class DecayingBeta {
|
|
77
|
+
private readonly decayThreshold;
|
|
78
|
+
constructor(decayThreshold?: number);
|
|
79
|
+
/** Decay multiplier: 0.5^(successCount/threshold). 1.0 when count=0, 0.5 at threshold. */
|
|
80
|
+
getDecayMultiplier(successCount: number): number;
|
|
81
|
+
/** Shrink sampled value toward mean by the decay multiplier. */
|
|
82
|
+
applyDecay(sampled: number, mean: number, successCount: number): number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Detects when transfer success rate has plateaued using CUSUM (R2).
|
|
86
|
+
*
|
|
87
|
+
* Feeds a running success rate into a CusumDetector on the 'learn' gate.
|
|
88
|
+
* Plateau is detected when CUSUM does NOT fire — i.e., the rate is
|
|
89
|
+
* stationary (no drift in either direction) for enough samples.
|
|
90
|
+
* CUSUM firing means the rate is changing, so NOT plateaued.
|
|
91
|
+
*/
|
|
92
|
+
export declare class PlateauDetector {
|
|
93
|
+
private readonly cusum;
|
|
94
|
+
private readonly outcomes;
|
|
95
|
+
private readonly windowSize;
|
|
96
|
+
constructor(windowSize?: number);
|
|
97
|
+
record(success: boolean): void;
|
|
98
|
+
/**
|
|
99
|
+
* Plateau = we have enough data AND CUSUM has not detected drift.
|
|
100
|
+
* No drift means the rate is stationary — learning has stalled.
|
|
101
|
+
*/
|
|
102
|
+
isPlateaued(): boolean;
|
|
103
|
+
getCurrentRate(): number;
|
|
104
|
+
getOutcomeCount(): number;
|
|
105
|
+
/** Expose CUSUM state for observability */
|
|
106
|
+
getCusumState(): import("./cusum-detector.js").CusumResult;
|
|
107
|
+
}
|
|
108
|
+
/** Tracks Pareto-optimal transfer candidates across multiple objectives. */
|
|
109
|
+
export declare class ParetoFront {
|
|
110
|
+
private readonly front;
|
|
111
|
+
dominates(a: ParetoPoint, b: ParetoPoint): boolean;
|
|
112
|
+
add(point: ParetoPoint): void;
|
|
113
|
+
getFront(): ParetoPoint[];
|
|
114
|
+
isNonDominated(point: ParetoPoint): boolean;
|
|
115
|
+
}
|
|
116
|
+
/** Curiosity bonus for novel/untried source-target domain pairs. */
|
|
117
|
+
export declare class CuriosityBonus {
|
|
118
|
+
private readonly bonusScale;
|
|
119
|
+
private readonly triedPairs;
|
|
120
|
+
constructor(bonusScale?: number);
|
|
121
|
+
markTried(pairKey: string): void;
|
|
122
|
+
isTried(pairKey: string): boolean;
|
|
123
|
+
getBonus(pairKey: string): number;
|
|
124
|
+
apply(sampledProbability: number, pairKey: string): number;
|
|
125
|
+
getTriedCount(): number;
|
|
126
|
+
}
|
|
65
127
|
/**
|
|
66
128
|
* Cross-domain transfer learning engine. Moves learned patterns between QE
|
|
67
129
|
* domains using Thompson Sampling, sqrt-dampening, and a double verification gate.
|
|
@@ -76,10 +138,15 @@ export declare class DomainTransferEngine {
|
|
|
76
138
|
private performanceProvider;
|
|
77
139
|
private transferExecutor;
|
|
78
140
|
private nativeModule;
|
|
141
|
+
private readonly decayingBeta;
|
|
142
|
+
private readonly plateauDetector;
|
|
143
|
+
private readonly paretoFront;
|
|
144
|
+
private readonly curiosityBonus;
|
|
79
145
|
constructor(config?: Partial<DomainTransferConfig>);
|
|
80
146
|
/**
|
|
81
147
|
* Evaluate whether a transfer between two domains should be attempted.
|
|
82
148
|
* Uses Thompson Sampling to balance exploration and exploitation.
|
|
149
|
+
* When meta-learning is enabled, applies DecayingBeta and CuriosityBonus.
|
|
83
150
|
*/
|
|
84
151
|
evaluateTransfer(sourceDomain: string, targetDomain: string): TransferCandidate;
|
|
85
152
|
/**
|
|
@@ -104,7 +171,18 @@ export declare class DomainTransferEngine {
|
|
|
104
171
|
getSampler(): ThompsonSampler;
|
|
105
172
|
/** Get the coherence gate (for testing). */
|
|
106
173
|
getCoherenceGate(): ITransferCoherenceGate;
|
|
174
|
+
/** Get the DecayingBeta component (for testing). */
|
|
175
|
+
getDecayingBeta(): DecayingBeta;
|
|
176
|
+
/** Get the PlateauDetector component (for testing). */
|
|
177
|
+
getPlateauDetector(): PlateauDetector;
|
|
178
|
+
/** Get the ParetoFront component (for testing). */
|
|
179
|
+
getParetoFront(): ParetoFront;
|
|
180
|
+
/** Get the CuriosityBonus component (for testing). */
|
|
181
|
+
getCuriosityBonus(): CuriosityBonus;
|
|
182
|
+
/** Check if learning has plateaued */
|
|
183
|
+
isLearningPlateaued(): boolean;
|
|
107
184
|
private isEnabled;
|
|
185
|
+
private isMetaLearningEnabled;
|
|
108
186
|
private makePairKey;
|
|
109
187
|
/**
|
|
110
188
|
* Sqrt-dampening: sqrt(observations / (observations + warmup)).
|