@totalreclaw/mcp-server 3.0.0 → 3.2.0-rc.17
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/dist/claims-helper.d.ts +17 -0
- package/dist/claims-helper.d.ts.map +1 -1
- package/dist/claims-helper.js +21 -1
- package/dist/claims-helper.js.map +1 -1
- package/dist/contradiction-sync.d.ts +249 -0
- package/dist/contradiction-sync.d.ts.map +1 -0
- package/dist/contradiction-sync.js +573 -0
- package/dist/contradiction-sync.js.map +1 -0
- package/dist/decision-log-reader.d.ts +37 -0
- package/dist/decision-log-reader.d.ts.map +1 -0
- package/dist/decision-log-reader.js +102 -0
- package/dist/decision-log-reader.js.map +1 -0
- package/dist/index.js +93 -1
- package/dist/index.js.map +1 -1
- package/dist/subgraph/store.d.ts +20 -0
- package/dist/subgraph/store.d.ts.map +1 -1
- package/dist/subgraph/store.js +23 -2
- package/dist/subgraph/store.js.map +1 -1
- package/dist/tools/pin.d.ts +18 -1
- package/dist/tools/pin.d.ts.map +1 -1
- package/dist/tools/pin.js +228 -33
- package/dist/tools/pin.js.map +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TotalReclaw MCP — contradiction detection + auto-resolution (Phase 2 Slice 2d).
|
|
4
|
+
*
|
|
5
|
+
* This is the MCP mirror of `skill/plugin/contradiction-sync.ts` — same
|
|
6
|
+
* pipeline, same decision semantics, same decision-log format. Keeps the MCP
|
|
7
|
+
* write path consistent with the plugin so a fact pinned via OpenClaw and
|
|
8
|
+
* later re-asserted via MCP (or vice versa) produces the same outcome.
|
|
9
|
+
*
|
|
10
|
+
* Runs after store-time dedup and before the canonical v1 claim blob is
|
|
11
|
+
* encrypted + submitted on-chain. For every entity on the new claim, fetches
|
|
12
|
+
* existing active claims that share the same entity trapdoor, decrypts them,
|
|
13
|
+
* and asks the WASM core to detect contradictions in the [0.3, 0.85) band.
|
|
14
|
+
* Each contradicting pair is then resolved via the P2-3 formula; the winner
|
|
15
|
+
* is kept on-chain, the loser is queued for tombstoning.
|
|
16
|
+
*
|
|
17
|
+
* Pinned claims are never touched — a contradiction against a pinned claim
|
|
18
|
+
* always causes the new write to be skipped with reason `existing_pinned`.
|
|
19
|
+
* Pin respect is enforced by the Rust core via `respect_pin_in_resolution`
|
|
20
|
+
* inside `resolve_with_candidates`; the TypeScript side does not need to
|
|
21
|
+
* re-check.
|
|
22
|
+
*
|
|
23
|
+
* Pure functions at the core, I/O behind dependency injection so tests can
|
|
24
|
+
* run the real WASM while stubbing the subgraph + filesystem. The WASM core
|
|
25
|
+
* is NOT mocked in tests — we run against the live @totalreclaw/core bindings
|
|
26
|
+
* so decision-log formats stay byte-for-byte compatible with the plugin.
|
|
27
|
+
*/
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.TIE_ZONE_SCORE_TOLERANCE = exports.CONTRADICTION_CANDIDATE_CAP = exports.DECISION_LOG_MAX_LINES = void 0;
|
|
33
|
+
exports.decisionsLogPath = decisionsLogPath;
|
|
34
|
+
exports.weightsFilePath = weightsFilePath;
|
|
35
|
+
exports.appendDecisionLog = appendDecisionLog;
|
|
36
|
+
exports.loadWeightsFile = loadWeightsFile;
|
|
37
|
+
exports.parseCandidateClaim = parseCandidateClaim;
|
|
38
|
+
exports.isPinnedClaim = isPinnedClaim;
|
|
39
|
+
exports.collectCandidatesForEntities = collectCandidatesForEntities;
|
|
40
|
+
exports.resolveWithCore = resolveWithCore;
|
|
41
|
+
exports.detectAndResolveContradictions = detectAndResolveContradictions;
|
|
42
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
43
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
44
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
45
|
+
const claims_helper_js_1 = require("./claims-helper.js");
|
|
46
|
+
// MCP uses require('@totalreclaw/core') directly (see consolidation.ts,
|
|
47
|
+
// claims-helper.ts) instead of createRequire — match that pattern.
|
|
48
|
+
let _wasm = null;
|
|
49
|
+
function getWasm() {
|
|
50
|
+
if (!_wasm) {
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
52
|
+
_wasm = require('@totalreclaw/core');
|
|
53
|
+
}
|
|
54
|
+
return _wasm;
|
|
55
|
+
}
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
// Paths + file I/O — identical file layout as plugin so the same decisions.jsonl
|
|
58
|
+
// is compatible across clients.
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
function resolveStateDir() {
|
|
61
|
+
const override = process.env.TOTALRECLAW_STATE_DIR;
|
|
62
|
+
if (override && override.length > 0)
|
|
63
|
+
return override;
|
|
64
|
+
return node_path_1.default.join(node_os_1.default.homedir(), '.totalreclaw');
|
|
65
|
+
}
|
|
66
|
+
function ensureStateDir() {
|
|
67
|
+
const dir = resolveStateDir();
|
|
68
|
+
try {
|
|
69
|
+
node_fs_1.default.mkdirSync(dir, { recursive: true });
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Caller handles downstream read/write failures.
|
|
73
|
+
}
|
|
74
|
+
return dir;
|
|
75
|
+
}
|
|
76
|
+
function decisionsLogPath() {
|
|
77
|
+
return node_path_1.default.join(resolveStateDir(), 'decisions.jsonl');
|
|
78
|
+
}
|
|
79
|
+
function weightsFilePath() {
|
|
80
|
+
return node_path_1.default.join(resolveStateDir(), 'weights.json');
|
|
81
|
+
}
|
|
82
|
+
/** Cap on the decisions.jsonl log — oldest lines are dropped above this. */
|
|
83
|
+
exports.DECISION_LOG_MAX_LINES = 10_000;
|
|
84
|
+
/** Soft cap on candidates fetched per entity during contradiction detection. */
|
|
85
|
+
exports.CONTRADICTION_CANDIDATE_CAP = 20;
|
|
86
|
+
/**
|
|
87
|
+
* Minimum score gap required to auto-resolve a `supersede_existing` decision.
|
|
88
|
+
* Calibrated against the 2026-04-14 Postgres/DuckDB false-positive (gap 9 ppm).
|
|
89
|
+
* See plugin's `contradiction-sync.ts` for full rationale.
|
|
90
|
+
*/
|
|
91
|
+
exports.TIE_ZONE_SCORE_TOLERANCE = 0.01;
|
|
92
|
+
/**
|
|
93
|
+
* Append one entry to the decision log, rotating if it grows past the cap.
|
|
94
|
+
* Never throws — logging is best-effort.
|
|
95
|
+
*/
|
|
96
|
+
async function appendDecisionLog(entry) {
|
|
97
|
+
try {
|
|
98
|
+
const dir = ensureStateDir();
|
|
99
|
+
const p = node_path_1.default.join(dir, 'decisions.jsonl');
|
|
100
|
+
let existing = '';
|
|
101
|
+
try {
|
|
102
|
+
existing = node_fs_1.default.readFileSync(p, 'utf-8');
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
existing = '';
|
|
106
|
+
}
|
|
107
|
+
const line = JSON.stringify(entry);
|
|
108
|
+
let next = existing;
|
|
109
|
+
if (next.length === 0) {
|
|
110
|
+
next = line + '\n';
|
|
111
|
+
}
|
|
112
|
+
else if (next.endsWith('\n')) {
|
|
113
|
+
next = next + line + '\n';
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
next = next + '\n' + line + '\n';
|
|
117
|
+
}
|
|
118
|
+
const rotated = getWasm().rotateFeedbackLog(next, BigInt(exports.DECISION_LOG_MAX_LINES));
|
|
119
|
+
node_fs_1.default.writeFileSync(p, rotated, 'utf-8');
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// Logging failures are never fatal.
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Load the per-user weights file, falling back to defaults when the file
|
|
127
|
+
* does not exist or is malformed. Never throws.
|
|
128
|
+
*/
|
|
129
|
+
async function loadWeightsFile(nowUnixSeconds) {
|
|
130
|
+
const core = getWasm();
|
|
131
|
+
const p = weightsFilePath();
|
|
132
|
+
try {
|
|
133
|
+
const raw = node_fs_1.default.readFileSync(p, 'utf-8');
|
|
134
|
+
const parsedJson = core.parseWeightsFile(raw);
|
|
135
|
+
return JSON.parse(parsedJson);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
const freshJson = core.defaultWeightsFile(BigInt(Math.floor(nowUnixSeconds)));
|
|
139
|
+
return JSON.parse(freshJson);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Parse a decrypted Claim blob into a canonical claim object.
|
|
144
|
+
*
|
|
145
|
+
* Accepts the canonical short-key Claim shape (`{t, c, cf, i, sa, ea, ...}`).
|
|
146
|
+
* Returns null for legacy docs, digest blobs, entity-infrastructure claims,
|
|
147
|
+
* or anything that fails to parse — excluded from contradiction detection.
|
|
148
|
+
*
|
|
149
|
+
* Mirrors the plugin's `parseCandidateClaim` byte-for-byte. v1 long-form
|
|
150
|
+
* blobs (`{text, type, entities, ...}`) do not have `t`/`c` and therefore
|
|
151
|
+
* return null here. The Rust core's `Claim` struct only accepts the short-key
|
|
152
|
+
* shape, so v1 blobs are not in-band for contradiction detection in either
|
|
153
|
+
* client. This matches plugin's current behavior — cross-client parity.
|
|
154
|
+
*/
|
|
155
|
+
function parseCandidateClaim(decryptedJson) {
|
|
156
|
+
if ((0, claims_helper_js_1.isDigestBlob)(decryptedJson))
|
|
157
|
+
return null;
|
|
158
|
+
let obj;
|
|
159
|
+
try {
|
|
160
|
+
obj = JSON.parse(decryptedJson);
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
if (typeof obj.t !== 'string' || typeof obj.c !== 'string')
|
|
166
|
+
return null;
|
|
167
|
+
if (obj.c === 'dig' || obj.c === 'ent')
|
|
168
|
+
return null;
|
|
169
|
+
return obj;
|
|
170
|
+
}
|
|
171
|
+
/** Is this candidate claim pinned (status `p`)? Delegates to WASM core. */
|
|
172
|
+
function isPinnedClaim(claim) {
|
|
173
|
+
try {
|
|
174
|
+
return getWasm().isPinnedClaim(JSON.stringify(claim));
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return typeof claim.st === 'string' && claim.st === 'p';
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Collect active claim candidates for every entity on the new claim.
|
|
182
|
+
*
|
|
183
|
+
* For each entity:
|
|
184
|
+
* 1. Compute its trapdoor (same primitive as the write path).
|
|
185
|
+
* 2. Query the subgraph for facts matching that single-element trapdoor.
|
|
186
|
+
* 3. Decrypt + parse each row, filtering infra claims and bad blobs.
|
|
187
|
+
* 4. Recover the embedding (reusing the stored one when possible).
|
|
188
|
+
*
|
|
189
|
+
* Deduplicates by subgraph fact id across entities. Caps total per entity at
|
|
190
|
+
* `CONTRADICTION_CANDIDATE_CAP` to keep the write-path cost bounded.
|
|
191
|
+
*/
|
|
192
|
+
async function collectCandidatesForEntities(newClaim, newClaimId, subgraphOwner, authKeyHex, encryptionKey, deps, logger) {
|
|
193
|
+
const entities = Array.isArray(newClaim.e) ? newClaim.e : [];
|
|
194
|
+
if (entities.length === 0)
|
|
195
|
+
return [];
|
|
196
|
+
const seenIds = new Set();
|
|
197
|
+
const out = [];
|
|
198
|
+
for (const entity of entities) {
|
|
199
|
+
const name = typeof entity?.n === 'string' ? entity.n : null;
|
|
200
|
+
if (!name)
|
|
201
|
+
continue;
|
|
202
|
+
const trapdoor = (0, claims_helper_js_1.computeEntityTrapdoor)(name);
|
|
203
|
+
let rows = [];
|
|
204
|
+
try {
|
|
205
|
+
rows = await deps.searchSubgraph(subgraphOwner, [trapdoor], exports.CONTRADICTION_CANDIDATE_CAP, authKeyHex);
|
|
206
|
+
}
|
|
207
|
+
catch (err) {
|
|
208
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
209
|
+
logger.warn(`Contradiction: subgraph query failed for entity "${name}": ${msg}`);
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
for (const row of rows) {
|
|
213
|
+
if (!row || !row.id || row.id === newClaimId)
|
|
214
|
+
continue;
|
|
215
|
+
if (row.isActive === false)
|
|
216
|
+
continue;
|
|
217
|
+
if (seenIds.has(row.id))
|
|
218
|
+
continue;
|
|
219
|
+
seenIds.add(row.id);
|
|
220
|
+
let decrypted;
|
|
221
|
+
try {
|
|
222
|
+
decrypted = deps.decryptFromHex(row.encryptedBlob, encryptionKey);
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const parsed = parseCandidateClaim(decrypted);
|
|
228
|
+
if (!parsed)
|
|
229
|
+
continue;
|
|
230
|
+
let embedding = [];
|
|
231
|
+
if (row.encryptedEmbedding) {
|
|
232
|
+
try {
|
|
233
|
+
const emb = JSON.parse(deps.decryptFromHex(row.encryptedEmbedding, encryptionKey));
|
|
234
|
+
if (Array.isArray(emb) && emb.every((x) => typeof x === 'number')) {
|
|
235
|
+
embedding = emb;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
embedding = [];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
out.push({ claim: parsed, id: row.id, embedding });
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return out;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Run WASM contradiction detection + resolution on in-memory data only.
|
|
249
|
+
*
|
|
250
|
+
* Uses `core.resolveWithCandidates()` (the full pipeline in one call: detect
|
|
251
|
+
* contradictions + resolve pairs + pin check + tie-zone guard) — introduced in
|
|
252
|
+
* core 1.5.0, shipped live in MCP's `@totalreclaw/core@2.0.0` dependency.
|
|
253
|
+
*
|
|
254
|
+
* If the WASM export is not available (core < 1.5.0) or fails, returns `[]`
|
|
255
|
+
* and the write path falls back to the pre-Phase-2 behaviour. We do NOT ship
|
|
256
|
+
* a legacy `detectContradictions + resolvePair` path — MCP 3.1.0 pins
|
|
257
|
+
* `@totalreclaw/core ^2.0.0` which guarantees the unified export.
|
|
258
|
+
*
|
|
259
|
+
* Split out from `detectAndResolveContradictions` so the write path can test
|
|
260
|
+
* the decision logic without mocking file I/O or the subgraph.
|
|
261
|
+
*/
|
|
262
|
+
function resolveWithCore(input) {
|
|
263
|
+
const { newClaim, newClaimId, newEmbedding, candidates, weightsJson, thresholdLower, thresholdUpper, nowUnixSeconds, mode, logger, } = input;
|
|
264
|
+
if (mode === 'off')
|
|
265
|
+
return [];
|
|
266
|
+
if (candidates.length === 0)
|
|
267
|
+
return [];
|
|
268
|
+
if (newEmbedding.length === 0) {
|
|
269
|
+
logger.warn('Contradiction: new claim has no embedding; skipping detection');
|
|
270
|
+
return [];
|
|
271
|
+
}
|
|
272
|
+
const core = getWasm();
|
|
273
|
+
// Build the WASM candidates payload. Drop any candidate whose embedding
|
|
274
|
+
// is missing — the core short-circuits on empty vectors but we also drop
|
|
275
|
+
// them from the lookup map so we don't waste a reference.
|
|
276
|
+
const items = candidates
|
|
277
|
+
.filter((c) => c.embedding.length > 0)
|
|
278
|
+
.map((c) => ({ claim: c.claim, id: c.id, embedding: c.embedding }));
|
|
279
|
+
if (items.length === 0)
|
|
280
|
+
return [];
|
|
281
|
+
const byId = new Map();
|
|
282
|
+
for (const c of items)
|
|
283
|
+
byId.set(c.id, { claim: c.claim, id: c.id, embedding: c.embedding });
|
|
284
|
+
if (typeof core.resolveWithCandidates !== 'function') {
|
|
285
|
+
// Unexpected: MCP 3.1.0 depends on core ^2.0.0 which ships this export.
|
|
286
|
+
// If this branch triggers, something is materially wrong with the core
|
|
287
|
+
// package — log and fall back to Phase-1 behaviour (no detection).
|
|
288
|
+
logger.warn('Contradiction: core.resolveWithCandidates missing (core < 1.5.0?) — skipping detection');
|
|
289
|
+
return [];
|
|
290
|
+
}
|
|
291
|
+
let actionsJson;
|
|
292
|
+
try {
|
|
293
|
+
actionsJson = core.resolveWithCandidates(JSON.stringify(newClaim), newClaimId, JSON.stringify(newEmbedding), JSON.stringify(items), weightsJson, thresholdLower, thresholdUpper, BigInt(Math.floor(nowUnixSeconds)), exports.TIE_ZONE_SCORE_TOLERANCE);
|
|
294
|
+
}
|
|
295
|
+
catch (err) {
|
|
296
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
297
|
+
logger.warn(`Contradiction: resolveWithCandidates failed: ${msg}`);
|
|
298
|
+
return [];
|
|
299
|
+
}
|
|
300
|
+
let actions;
|
|
301
|
+
try {
|
|
302
|
+
actions = JSON.parse(actionsJson);
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
return [];
|
|
306
|
+
}
|
|
307
|
+
if (actions.length === 0)
|
|
308
|
+
return [];
|
|
309
|
+
// Map core ResolutionAction (tagged enum) → local ResolutionDecision.
|
|
310
|
+
const decisions = [];
|
|
311
|
+
for (const action of actions) {
|
|
312
|
+
const type = action.type;
|
|
313
|
+
if (type === 'supersede_existing') {
|
|
314
|
+
const existing = byId.get(action.existing_id);
|
|
315
|
+
decisions.push({
|
|
316
|
+
action: 'supersede_existing',
|
|
317
|
+
existingFactId: action.existing_id,
|
|
318
|
+
existingClaim: existing?.claim ?? {},
|
|
319
|
+
entityId: action.entity_id ?? '',
|
|
320
|
+
similarity: action.similarity ?? 0,
|
|
321
|
+
winnerScore: action.winner_score ?? 0,
|
|
322
|
+
loserScore: action.loser_score ?? 0,
|
|
323
|
+
winnerComponents: action.winner_components,
|
|
324
|
+
loserComponents: action.loser_components,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
else if (type === 'skip_new') {
|
|
328
|
+
const reason = action.reason;
|
|
329
|
+
decisions.push({
|
|
330
|
+
action: 'skip_new',
|
|
331
|
+
reason: reason === 'existing_pinned' ? 'existing_pinned' : 'existing_wins',
|
|
332
|
+
existingFactId: action.existing_id,
|
|
333
|
+
entityId: action.entity_id ?? '',
|
|
334
|
+
similarity: action.similarity ?? 0,
|
|
335
|
+
winnerScore: action.winner_score,
|
|
336
|
+
loserScore: action.loser_score,
|
|
337
|
+
winnerComponents: action.winner_components,
|
|
338
|
+
loserComponents: action.loser_components,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
else if (type === 'tie_leave_both') {
|
|
342
|
+
decisions.push({
|
|
343
|
+
action: 'tie_leave_both',
|
|
344
|
+
existingFactId: action.existing_id,
|
|
345
|
+
entityId: action.entity_id ?? '',
|
|
346
|
+
similarity: action.similarity ?? 0,
|
|
347
|
+
winnerScore: action.winner_score ?? 0,
|
|
348
|
+
loserScore: action.loser_score ?? 0,
|
|
349
|
+
winnerComponents: action.winner_components,
|
|
350
|
+
loserComponents: action.loser_components,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
// no_contradiction actions are ignored.
|
|
354
|
+
}
|
|
355
|
+
return decisions;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Write-path entry point. See Slice 2d of the Phase 2 design doc.
|
|
359
|
+
*
|
|
360
|
+
* Returns a list of `ResolutionDecision`s:
|
|
361
|
+
* - `supersede_existing`: caller queues a tombstone for `existingFactId`
|
|
362
|
+
* - `skip_new`: caller skips the new write (existing wins or is pinned)
|
|
363
|
+
* - empty list: no contradiction, proceed unchanged
|
|
364
|
+
*
|
|
365
|
+
* Never throws. On any failure (subgraph, decrypt, WASM), returns `[]` so the
|
|
366
|
+
* write path falls back to pre-Phase-2 behaviour.
|
|
367
|
+
*
|
|
368
|
+
* Pin respect is handled inside WASM `resolve_with_candidates` via the core's
|
|
369
|
+
* `respect_pin_in_resolution` — the TypeScript side does not need to re-check.
|
|
370
|
+
*/
|
|
371
|
+
async function detectAndResolveContradictions(input) {
|
|
372
|
+
const { newClaim, newClaimId, newEmbedding, subgraphOwner, authKeyHex, encryptionKey, deps, logger, } = input;
|
|
373
|
+
// Read env per-call so tests can toggle without module reload.
|
|
374
|
+
const raw = (process.env.TOTALRECLAW_AUTO_RESOLVE_MODE ?? '').trim().toLowerCase();
|
|
375
|
+
const mode = raw === 'off' ? 'off' : raw === 'shadow' ? 'shadow' : 'active';
|
|
376
|
+
if (mode === 'off')
|
|
377
|
+
return [];
|
|
378
|
+
// No entities → nothing to check.
|
|
379
|
+
const entities = Array.isArray(newClaim.e) ? newClaim.e : [];
|
|
380
|
+
if (entities.length === 0)
|
|
381
|
+
return [];
|
|
382
|
+
const nowUnixSeconds = typeof deps.nowUnixSeconds === 'number'
|
|
383
|
+
? deps.nowUnixSeconds
|
|
384
|
+
: Math.floor(Date.now() / 1000);
|
|
385
|
+
const weightsFile = await loadWeightsFile(nowUnixSeconds);
|
|
386
|
+
const weightsJson = JSON.stringify(weightsFile.weights ?? {});
|
|
387
|
+
const thresholdLower = typeof weightsFile.threshold_lower === 'number' ? weightsFile.threshold_lower : 0.3;
|
|
388
|
+
const thresholdUpper = typeof weightsFile.threshold_upper === 'number' ? weightsFile.threshold_upper : 0.85;
|
|
389
|
+
let candidates;
|
|
390
|
+
try {
|
|
391
|
+
candidates = await collectCandidatesForEntities(newClaim, newClaimId, subgraphOwner, authKeyHex, encryptionKey, deps, logger);
|
|
392
|
+
}
|
|
393
|
+
catch (err) {
|
|
394
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
395
|
+
logger.warn(`Contradiction: candidate retrieval failed: ${msg}`);
|
|
396
|
+
return [];
|
|
397
|
+
}
|
|
398
|
+
if (candidates.length === 0)
|
|
399
|
+
return [];
|
|
400
|
+
const rawDecisions = resolveWithCore({
|
|
401
|
+
newClaim,
|
|
402
|
+
newClaimId,
|
|
403
|
+
newEmbedding,
|
|
404
|
+
candidates,
|
|
405
|
+
weightsJson,
|
|
406
|
+
thresholdLower,
|
|
407
|
+
thresholdUpper,
|
|
408
|
+
nowUnixSeconds,
|
|
409
|
+
mode,
|
|
410
|
+
logger,
|
|
411
|
+
});
|
|
412
|
+
// Tie-zone guard: when the formula winner beats the loser by less than
|
|
413
|
+
// TIE_ZONE_SCORE_TOLERANCE, the "contradiction" is rounding noise.
|
|
414
|
+
// Core >= 1.5.0 already applies this inside resolveWithCandidates so this
|
|
415
|
+
// map is typically a no-op; kept defensively in case the core path is
|
|
416
|
+
// bypassed.
|
|
417
|
+
const decisions = rawDecisions.map((d) => {
|
|
418
|
+
if (d.action === 'supersede_existing' &&
|
|
419
|
+
Math.abs(d.winnerScore - d.loserScore) < exports.TIE_ZONE_SCORE_TOLERANCE) {
|
|
420
|
+
return {
|
|
421
|
+
action: 'tie_leave_both',
|
|
422
|
+
existingFactId: d.existingFactId,
|
|
423
|
+
entityId: d.entityId,
|
|
424
|
+
similarity: d.similarity,
|
|
425
|
+
winnerScore: d.winnerScore,
|
|
426
|
+
loserScore: d.loserScore,
|
|
427
|
+
winnerComponents: d.winnerComponents,
|
|
428
|
+
loserComponents: d.loserComponents,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
return d;
|
|
432
|
+
});
|
|
433
|
+
// Build decision-log entries. Prefer core.buildDecisionLogEntries (>= 1.5.0)
|
|
434
|
+
// so the log format stays byte-for-byte compatible with the plugin.
|
|
435
|
+
const core = getWasm();
|
|
436
|
+
const useCoreDecisionLog = typeof core.buildDecisionLogEntries === 'function';
|
|
437
|
+
if (useCoreDecisionLog) {
|
|
438
|
+
try {
|
|
439
|
+
const coreActions = _decisionsToCoreActions(decisions, newClaimId);
|
|
440
|
+
const existingClaimsMap = {};
|
|
441
|
+
for (const d of decisions) {
|
|
442
|
+
if (d.action === 'supersede_existing') {
|
|
443
|
+
try {
|
|
444
|
+
existingClaimsMap[d.existingFactId] = JSON.stringify(d.existingClaim);
|
|
445
|
+
}
|
|
446
|
+
catch { /* skip */ }
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
const entriesJson = core.buildDecisionLogEntries(JSON.stringify(coreActions), JSON.stringify(newClaim), JSON.stringify(existingClaimsMap), mode === 'shadow' ? 'shadow' : mode, BigInt(Math.floor(nowUnixSeconds)));
|
|
450
|
+
const entries = JSON.parse(entriesJson);
|
|
451
|
+
for (const entry of entries) {
|
|
452
|
+
await appendDecisionLog(entry);
|
|
453
|
+
if (entry.action === 'tie_leave_both') {
|
|
454
|
+
logger.info(`Contradiction: tie (gap=${Math.abs((entry.winner_score ?? 0) - (entry.loser_score ?? 0)).toFixed(6)} < ${exports.TIE_ZONE_SCORE_TOLERANCE}, sim=${entry.similarity.toFixed(3)}, entity=${entry.entity_id}) — leaving both active`);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
catch (err) {
|
|
459
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
460
|
+
logger.warn(`Contradiction: buildDecisionLogEntries failed, falling back to inline: ${msg}`);
|
|
461
|
+
await _appendDecisionLogInline(decisions, newClaimId, nowUnixSeconds, mode, logger);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
await _appendDecisionLogInline(decisions, newClaimId, nowUnixSeconds, mode, logger);
|
|
466
|
+
}
|
|
467
|
+
// Shadow-mode filtering via core.filterShadowMode (>= 1.5.0).
|
|
468
|
+
if (typeof core.filterShadowMode === 'function') {
|
|
469
|
+
try {
|
|
470
|
+
const coreActions = _decisionsToCoreActions(decisions, newClaimId);
|
|
471
|
+
const filteredJson = core.filterShadowMode(JSON.stringify(coreActions), mode);
|
|
472
|
+
const filteredActions = JSON.parse(filteredJson);
|
|
473
|
+
const byExistingId = new Map();
|
|
474
|
+
for (const d of decisions) {
|
|
475
|
+
if (d.action === 'supersede_existing' || d.action === 'skip_new' || d.action === 'tie_leave_both') {
|
|
476
|
+
byExistingId.set(d.existingFactId, d);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return filteredActions
|
|
480
|
+
.map((a) => byExistingId.get(a.existing_id))
|
|
481
|
+
.filter((d) => d !== undefined);
|
|
482
|
+
}
|
|
483
|
+
catch {
|
|
484
|
+
// Fall through to local filtering.
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
// Local fallback: shadow → empty, active → filter out ties.
|
|
488
|
+
if (mode === 'shadow')
|
|
489
|
+
return [];
|
|
490
|
+
return decisions.filter((d) => d.action !== 'tie_leave_both');
|
|
491
|
+
}
|
|
492
|
+
/** Convert ResolutionDecision[] to core ResolutionAction JSON format. */
|
|
493
|
+
function _decisionsToCoreActions(decisions, newClaimId) {
|
|
494
|
+
return decisions.map((d) => {
|
|
495
|
+
if (d.action === 'supersede_existing') {
|
|
496
|
+
return {
|
|
497
|
+
type: 'supersede_existing',
|
|
498
|
+
existing_id: d.existingFactId, new_id: newClaimId,
|
|
499
|
+
similarity: d.similarity, score_gap: Math.abs(d.winnerScore - d.loserScore),
|
|
500
|
+
entity_id: d.entityId, winner_score: d.winnerScore, loser_score: d.loserScore,
|
|
501
|
+
winner_components: d.winnerComponents, loser_components: d.loserComponents,
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
else if (d.action === 'skip_new') {
|
|
505
|
+
return {
|
|
506
|
+
type: 'skip_new', reason: d.reason,
|
|
507
|
+
existing_id: d.existingFactId, new_id: newClaimId,
|
|
508
|
+
entity_id: d.entityId, similarity: d.similarity,
|
|
509
|
+
winner_score: d.winnerScore, loser_score: d.loserScore,
|
|
510
|
+
winner_components: d.winnerComponents, loser_components: d.loserComponents,
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
else if (d.action === 'tie_leave_both') {
|
|
514
|
+
return {
|
|
515
|
+
type: 'tie_leave_both',
|
|
516
|
+
existing_id: d.existingFactId, new_id: newClaimId,
|
|
517
|
+
similarity: d.similarity, score_gap: Math.abs(d.winnerScore - d.loserScore),
|
|
518
|
+
entity_id: d.entityId, winner_score: d.winnerScore, loser_score: d.loserScore,
|
|
519
|
+
winner_components: d.winnerComponents, loser_components: d.loserComponents,
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
return { type: 'no_contradiction' };
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
/** Inline decision-log fallback (used when core.buildDecisionLogEntries unavailable). */
|
|
526
|
+
async function _appendDecisionLogInline(decisions, newClaimId, nowUnixSeconds, mode, logger) {
|
|
527
|
+
for (const d of decisions) {
|
|
528
|
+
if (d.action === 'supersede_existing') {
|
|
529
|
+
let loserClaimJson;
|
|
530
|
+
try {
|
|
531
|
+
loserClaimJson = JSON.stringify(d.existingClaim);
|
|
532
|
+
}
|
|
533
|
+
catch {
|
|
534
|
+
loserClaimJson = undefined;
|
|
535
|
+
}
|
|
536
|
+
await appendDecisionLog({
|
|
537
|
+
ts: nowUnixSeconds, entity_id: d.entityId,
|
|
538
|
+
new_claim_id: newClaimId, existing_claim_id: d.existingFactId,
|
|
539
|
+
similarity: d.similarity,
|
|
540
|
+
action: mode === 'shadow' ? 'shadow' : 'supersede_existing',
|
|
541
|
+
reason: 'new_wins',
|
|
542
|
+
winner_score: d.winnerScore, loser_score: d.loserScore,
|
|
543
|
+
winner_components: d.winnerComponents, loser_components: d.loserComponents,
|
|
544
|
+
loser_claim_json: loserClaimJson, mode,
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
else if (d.action === 'skip_new') {
|
|
548
|
+
await appendDecisionLog({
|
|
549
|
+
ts: nowUnixSeconds, entity_id: d.entityId,
|
|
550
|
+
new_claim_id: newClaimId, existing_claim_id: d.existingFactId,
|
|
551
|
+
similarity: d.similarity,
|
|
552
|
+
action: mode === 'shadow' ? 'shadow' : 'skip_new',
|
|
553
|
+
reason: d.reason,
|
|
554
|
+
winner_score: d.winnerScore, loser_score: d.loserScore,
|
|
555
|
+
winner_components: d.winnerComponents, loser_components: d.loserComponents,
|
|
556
|
+
mode,
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
else if (d.action === 'tie_leave_both') {
|
|
560
|
+
await appendDecisionLog({
|
|
561
|
+
ts: nowUnixSeconds, entity_id: d.entityId,
|
|
562
|
+
new_claim_id: newClaimId, existing_claim_id: d.existingFactId,
|
|
563
|
+
similarity: d.similarity,
|
|
564
|
+
action: 'tie_leave_both', reason: 'tie_below_tolerance',
|
|
565
|
+
winner_score: d.winnerScore, loser_score: d.loserScore,
|
|
566
|
+
winner_components: d.winnerComponents, loser_components: d.loserComponents,
|
|
567
|
+
mode,
|
|
568
|
+
});
|
|
569
|
+
logger.info(`Contradiction: tie (gap=${Math.abs(d.winnerScore - d.loserScore).toFixed(6)} < ${exports.TIE_ZONE_SCORE_TOLERANCE}, sim=${d.similarity.toFixed(3)}, entity=${d.entityId}) — leaving both active`);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
//# sourceMappingURL=contradiction-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contradiction-sync.js","sourceRoot":"","sources":["../src/contradiction-sync.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;;;;AAkJH,4CAEC;AAED,0CAEC;AAmBD,8CAwBC;AAMD,0CAWC;AA4CD,kDAWC;AAGD,sCAMC;AAyBD,oEAoEC;AAkCD,0CAoHC;AAsCD,wEA2JC;AAtsBD,sDAAyB;AACzB,sDAAyB;AACzB,0DAA6B;AAC7B,yDAAyE;AAEzE,wEAAwE;AACxE,mEAAmE;AACnE,IAAI,KAAK,GAA8C,IAAI,CAAC;AAC5D,SAAS,OAAO;IACd,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,iEAAiE;QACjE,KAAK,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,KAAM,CAAC;AAChB,CAAC;AA6GD,8EAA8E;AAC9E,iFAAiF;AACjF,gCAAgC;AAChC,8EAA8E;AAE9E,SAAS,eAAe;IACtB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC;IACnD,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,QAAQ,CAAC;IACrD,OAAO,mBAAI,CAAC,IAAI,CAAC,iBAAE,CAAC,OAAO,EAAE,EAAE,cAAc,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,cAAc;IACrB,MAAM,GAAG,GAAG,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C,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,CAAC,CAAC,eAAe;gBAC1E,IAAI;aACL,CAAC,CAAC;QACL,CAAC;aAAM,IAAI,CAAC,CAAC,MAAM,KAAK,gBAAgB,EAAE,CAAC;YACzC,MAAM,iBAAiB,CAAC;gBACtB,EAAE,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC,CAAC,QAAQ;gBACzC,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC,CAAC,cAAc;gBAC7D,UAAU,EAAE,CAAC,CAAC,UAAU;gBACxB,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,qBAAqB;gBACvD,YAAY,EAAE,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC,UAAU;gBACtD,iBAAiB,EAAE,CAAC,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,CAAC,CAAC,eAAe;gBAC1E,IAAI;aACL,CAAC,CAAC;YACH,MAAM,CAAC,IAAI,CACT,2BAA2B,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,gCAAwB,SAAS,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,QAAQ,yBAAyB,CAC1L,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decision-log reader for the pin-on-tombstone recovery path.
|
|
3
|
+
*
|
|
4
|
+
* When a user pins fact F1 via one client, later forgets F1 via another client
|
|
5
|
+
* (which writes a 1-byte `0x00` tombstone on-chain), then asks to re-pin F1,
|
|
6
|
+
* the pin tool must reconstruct F1's plaintext Claim from the decision log —
|
|
7
|
+
* the on-chain ciphertext is no longer decryptable.
|
|
8
|
+
*
|
|
9
|
+
* Plugin parity: mirrors `findLoserClaimInDecisionLog` in
|
|
10
|
+
* `skill/plugin/contradiction-sync.ts` (see §Phase 2.1). Both clients resolve
|
|
11
|
+
* `decisions.jsonl` from the same state dir (`$TOTALRECLAW_STATE_DIR`, default
|
|
12
|
+
* `~/.totalreclaw/`), so plugin writes and MCP reads see the same file.
|
|
13
|
+
*
|
|
14
|
+
* Delegates to the Rust-core WASM export `findLoserClaimInDecisionLog` and
|
|
15
|
+
* falls back to a local JSONL walk if the WASM call throws. Matches the
|
|
16
|
+
* plugin's fallback pattern byte-for-byte so the two implementations agree
|
|
17
|
+
* on edge cases.
|
|
18
|
+
*/
|
|
19
|
+
/** Path to `decisions.jsonl` in the active state dir. */
|
|
20
|
+
export declare function decisionsLogPath(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Walk `decisions.jsonl` in reverse and return the most recent canonical
|
|
23
|
+
* Claim JSON for a fact that was tombstoned by a `supersede_existing`
|
|
24
|
+
* decision. Returns `null` when the log is missing, empty, or has no matching
|
|
25
|
+
* row. Never throws — the recovery path treats any failure as "no recovery
|
|
26
|
+
* available" and lets the caller surface a clean error.
|
|
27
|
+
*
|
|
28
|
+
* Only matches `supersede_existing` rows (not `tie_leave_both` or `skip_new`)
|
|
29
|
+
* because those are the only rows that actually tombstone the existing fact.
|
|
30
|
+
* Only returns rows that have `loser_claim_json` populated — pre-Phase-2.1
|
|
31
|
+
* supersede rows do not carry the field and cannot be recovered from.
|
|
32
|
+
*
|
|
33
|
+
* Mirrors `findLoserClaimInDecisionLog` in
|
|
34
|
+
* `skill/plugin/contradiction-sync.ts:1090`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function findLoserClaimInDecisionLog(factId: string): string | null;
|
|
37
|
+
//# sourceMappingURL=decision-log-reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decision-log-reader.d.ts","sourceRoot":"","sources":["../src/decision-log-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA8BH,yDAAyD;AACzD,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAgCzE"}
|