@cortexkit/opencode-magic-context 0.49.31 → 0.49.33
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/auto-search-worker.js +4 -4
- package/dist/chunk-embedding-write-worker.js +1 -1
- package/dist/{compartment-chunk-embedding-qgp0tbf7.js → compartment-chunk-embedding-5q5gj67r.js} +1 -1
- package/dist/{context-9a0f8mzh.js → context-jyzkstnr.js} +17 -10
- package/dist/{embedding-backfill-mms9nb0h.js → embedding-backfill-0jgtqxen.js} +3 -3
- package/dist/features/magic-context/chunk-scope-repair-revision.d.ts +4 -0
- package/dist/features/magic-context/chunk-scope-repair-revision.d.ts.map +1 -0
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-gates.d.ts +2 -0
- package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -1
- package/dist/features/magic-context/message-index-async.d.ts +3 -0
- package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/request-tool-definitions.d.ts +25 -0
- package/dist/features/magic-context/request-tool-definitions.d.ts.map +1 -0
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/hooks/magic-context/apply-operations.d.ts +1 -1
- package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-branch-index.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-branch-index.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
- package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-render-epoch.d.ts +7 -0
- package/dist/hooks/magic-context/compartment-render-epoch.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +7 -2
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +1 -0
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-gxkhzmjq.js → index-2743x98y.js} +65 -2
- package/dist/{index-kmayq4kq.js → index-2xh37qn5.js} +89 -11
- package/dist/{index-22e7khnr.js → index-3fkk2gwj.js} +57 -372
- package/dist/{index-0bjktrjt.js → index-43vqx0za.js} +2 -2
- package/dist/index-94ef0qe2.js +429 -0
- package/dist/{index-pe6b4bhs.js → index-as2amvn3.js} +1 -1
- package/dist/{index-qathsvz2.js → index-b7w46fp2.js} +16 -4
- package/dist/{index-y6ynjghv.js → index-dq5xzeb9.js} +2 -2
- package/dist/{index-vtz789ex.js → index-qr2mb02j.js} +16 -5
- package/dist/{index-vnn5405n.js → index-rfxzazzy.js} +1 -1
- package/dist/{index-mm93m7y6.js → index-v7287tzq.js} +47 -7
- package/dist/index.js +16 -14
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/{project-embedding-registry-cg281d9j.js → project-embedding-registry-6yex0r9f.js} +2 -2
- package/dist/{recomp-orchestrator-ynehxbya.js → recomp-orchestrator-skqzzvby.js} +6 -6
- package/dist/{search-fbaz1m8r.js → search-040pac3a.js} +6 -5
- package/dist/{transform-postprocess-phase-50h70ft8.js → transform-postprocess-phase-zx1peqma.js} +7 -6
- package/dist/v2/auto-search-worker.js +4 -4
- package/dist/v2/chunk-embedding-write-worker.js +1 -1
- package/dist/v2/{compartment-chunk-embedding-63dzs31c.js → compartment-chunk-embedding-rc31e6md.js} +1 -1
- package/dist/v2/{context-cdqw9jex.js → context-3c4z2wj5.js} +82 -264
- package/dist/v2/{embedding-backfill-35k6czrr.js → embedding-backfill-f43hd8y6.js} +3 -3
- package/dist/v2/hooks/context.d.ts +3 -3
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/{project-embedding-registry-p1p10ks7.js → project-embedding-registry-1x5qe2fy.js} +2 -2
- package/dist/v2/{recomp-orchestrator-kdxr4tx8.js → recomp-orchestrator-qfqdvbta.js} +5 -5
- package/dist/v2/{search-q3jjw6zp.js → search-q3wkpe8t.js} +5 -5
- package/dist/v2/{server-p0snacz3.js → server-2aasmpsp.js} +1 -1
- package/dist/v2/{server-zh3esb0z.js → server-ab8017gw.js} +65 -2
- package/dist/v2/{server-rdjgz95f.js → server-aqbm9c8d.js} +113 -35
- package/dist/v2/{server-4sn3at8p.js → server-h1byrhwx.js} +47 -7
- package/dist/v2/{server-42nebt63.js → server-n14edf07.js} +336 -25
- package/dist/v2/{server-ph300d6m.js → server-tkdabx8q.js} +1 -1
- package/dist/v2/server.js +2 -2
- package/dist/v2/{wrapup-orchestrator-prfvyqbb.js → wrapup-orchestrator-ga5vfmwr.js} +5 -5
- package/dist/{wrapup-orchestrator-4zhkcsz0.js → wrapup-orchestrator-dy8r3gp8.js} +7 -7
- package/package.json +1 -1
|
@@ -50,7 +50,7 @@ import {
|
|
|
50
50
|
countSessionCompartmentEmbedCoverage2,
|
|
51
51
|
countSessionCompartmentEmbedCoveragePolite2,
|
|
52
52
|
countUnembeddedSessionCompartmentsPolite2
|
|
53
|
-
} from "./server-
|
|
53
|
+
} from "./server-h1byrhwx.js";
|
|
54
54
|
import {
|
|
55
55
|
acquireGitSweepLease,
|
|
56
56
|
renewGitSweepLease,
|
|
@@ -74,6 +74,9 @@ import {
|
|
|
74
74
|
getEmbeddingProviderIdentity,
|
|
75
75
|
LocalEmbeddingProvider
|
|
76
76
|
} from "./server-vr4szghm.js";
|
|
77
|
+
import {
|
|
78
|
+
isKnownAutocommit
|
|
79
|
+
} from "./server-8ajstryz.js";
|
|
77
80
|
import {
|
|
78
81
|
logSlowWriteTransaction
|
|
79
82
|
} from "./server-gyy4k6mf.js";
|
|
@@ -276,6 +279,51 @@ function createChunkEmbeddingWriter(db) {
|
|
|
276
279
|
};
|
|
277
280
|
}
|
|
278
281
|
|
|
282
|
+
// src/features/magic-context/chunk-scope-repair-revision.ts
|
|
283
|
+
var revisions = new WeakMap;
|
|
284
|
+
var KEY = "chunk_scope_repair_revision";
|
|
285
|
+
function readChunkScopeRepairRevision(db) {
|
|
286
|
+
if (!isKnownAutocommit(db))
|
|
287
|
+
return null;
|
|
288
|
+
let state = revisions.get(db);
|
|
289
|
+
if (!state) {
|
|
290
|
+
if (!db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'schema_migrations_meta'").get())
|
|
291
|
+
return null;
|
|
292
|
+
const bump = `INSERT INTO schema_migrations_meta(key, value) VALUES ('${KEY}', lower(hex(randomblob(16))))
|
|
293
|
+
ON CONFLICT(key) DO UPDATE SET value = excluded.value;`;
|
|
294
|
+
db.exec(`CREATE TEMP TRIGGER IF NOT EXISTS mc_chunk_scope_binding_bi
|
|
295
|
+
BEFORE INSERT ON main.session_projects
|
|
296
|
+
WHEN NOT EXISTS (SELECT 1 FROM session_projects WHERE session_id = NEW.session_id
|
|
297
|
+
AND harness = NEW.harness AND project_path = NEW.project_path)
|
|
298
|
+
BEGIN ${bump} END;
|
|
299
|
+
CREATE TEMP TRIGGER IF NOT EXISTS mc_chunk_scope_binding_au
|
|
300
|
+
AFTER UPDATE ON main.session_projects
|
|
301
|
+
WHEN OLD.session_id IS NOT NEW.session_id OR OLD.harness IS NOT NEW.harness
|
|
302
|
+
OR OLD.project_path IS NOT NEW.project_path
|
|
303
|
+
BEGIN ${bump} END;
|
|
304
|
+
CREATE TEMP TRIGGER IF NOT EXISTS mc_chunk_scope_rows_bi
|
|
305
|
+
BEFORE INSERT ON main.compartment_chunk_embeddings BEGIN ${bump} END;
|
|
306
|
+
CREATE TEMP TRIGGER IF NOT EXISTS mc_chunk_scope_rows_au
|
|
307
|
+
AFTER UPDATE OF project_path, session_id, harness ON main.compartment_chunk_embeddings
|
|
308
|
+
WHEN NOT EXISTS (SELECT 1 FROM session_projects WHERE session_id = NEW.session_id
|
|
309
|
+
AND harness = NEW.harness AND project_path = NEW.project_path)
|
|
310
|
+
BEGIN ${bump} END;`);
|
|
311
|
+
const statement = db.prepare(`SELECT
|
|
312
|
+
(SELECT value FROM schema_migrations_meta WHERE key = '${KEY}') AS local,
|
|
313
|
+
(SELECT data_version FROM pragma_data_version) AS external,
|
|
314
|
+
(SELECT schema_version FROM pragma_schema_version) AS schemaVersion`);
|
|
315
|
+
state = { statement };
|
|
316
|
+
revisions.set(db, state);
|
|
317
|
+
}
|
|
318
|
+
const row = state.statement.get();
|
|
319
|
+
if (state.schemaVersion !== undefined && state.schemaVersion !== row.schemaVersion) {
|
|
320
|
+
revisions.delete(db);
|
|
321
|
+
return readChunkScopeRepairRevision(db);
|
|
322
|
+
}
|
|
323
|
+
state.schemaVersion = row.schemaVersion;
|
|
324
|
+
return JSON.stringify(row);
|
|
325
|
+
}
|
|
326
|
+
|
|
279
327
|
// src/features/magic-context/git-commits/storage-git-commit-embeddings.ts
|
|
280
328
|
var saveStatements = new WeakMap;
|
|
281
329
|
var loadProjectStatements = new WeakMap;
|
|
@@ -1465,6 +1513,7 @@ function recordScopeActiveIdentity(db, projectIdentity, scope, modelId, now) {
|
|
|
1465
1513
|
getUpsertActiveIdentityStatement(db).run(projectIdentity, scope, modelId, now);
|
|
1466
1514
|
}
|
|
1467
1515
|
var legacyDiscoveryComplete = new WeakMap;
|
|
1516
|
+
var chunkScopeRepairComplete = new WeakMap;
|
|
1468
1517
|
function recordActiveEmbeddingIdentity(db, projectIdentity, currentProviderIdentity, currentChunkIdentity, features) {
|
|
1469
1518
|
if (currentProviderIdentity === OFF_PROVIDER_IDENTITY) {
|
|
1470
1519
|
return false;
|
|
@@ -1486,7 +1535,21 @@ function recordActiveEmbeddingIdentity(db, projectIdentity, currentProviderIdent
|
|
|
1486
1535
|
model,
|
|
1487
1536
|
rows: getBackfillActiveIdentityStatement(db, scope).all(projectIdentity, projectIdentity, scope)
|
|
1488
1537
|
}));
|
|
1489
|
-
const
|
|
1538
|
+
const repairKey = JSON.stringify([projectIdentity, currentChunkIdentity]);
|
|
1539
|
+
const repairRevision = readChunkScopeRepairRevision(db);
|
|
1540
|
+
let completed = chunkScopeRepairComplete.get(db);
|
|
1541
|
+
if (!completed) {
|
|
1542
|
+
completed = new Map;
|
|
1543
|
+
chunkScopeRepairComplete.set(db, completed);
|
|
1544
|
+
}
|
|
1545
|
+
if (repairRevision === null)
|
|
1546
|
+
completed.clear();
|
|
1547
|
+
const repairIds = repairRevision !== null && completed.get(repairKey) === repairRevision ? [] : findMisScopedCompartmentChunkEmbeddingIdsForProject(db, projectIdentity);
|
|
1548
|
+
if (repairIds.length === 0 && repairRevision !== null) {
|
|
1549
|
+
if (completed.size >= 256)
|
|
1550
|
+
completed.delete(completed.keys().next().value);
|
|
1551
|
+
completed.set(repairKey, repairRevision);
|
|
1552
|
+
}
|
|
1490
1553
|
if (legacy.every(({ rows }) => rows.length === 0) && scopes.every(([scope, model]) => active.get(projectIdentity, scope, model)) && repairIds.length === 0) {
|
|
1491
1554
|
for (const { scope, model } of legacy)
|
|
1492
1555
|
discovered.add(discoveryKey(scope, model));
|
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
getProjectChunkEmbeddingModelId2,
|
|
43
43
|
getProjectEmbeddingMaxInputTokens2,
|
|
44
44
|
embedItemsForProject2
|
|
45
|
-
} from "./server-
|
|
45
|
+
} from "./server-ab8017gw.js";
|
|
46
46
|
import {
|
|
47
47
|
hasMeaningfulUserText2,
|
|
48
48
|
estimateTokens,
|
|
@@ -77,7 +77,7 @@ import {
|
|
|
77
77
|
replaceCompartmentChunkEmbeddings2,
|
|
78
78
|
deleteChunkEmbedBackoffForSession2,
|
|
79
79
|
chunkWindowSourceKey2
|
|
80
|
-
} from "./server-
|
|
80
|
+
} from "./server-h1byrhwx.js";
|
|
81
81
|
import {
|
|
82
82
|
isPidAlive,
|
|
83
83
|
readProcessStartTime
|
|
@@ -264,7 +264,7 @@ import {
|
|
|
264
264
|
userFacingFailureCode,
|
|
265
265
|
promoteSessionFactsDurable,
|
|
266
266
|
embedPromotedFacts
|
|
267
|
-
} from "./server-
|
|
267
|
+
} from "./server-tkdabx8q.js";
|
|
268
268
|
import {
|
|
269
269
|
isMarkerCandidateBasisCurrent2,
|
|
270
270
|
invalidateMarkerCandidateBasis2,
|
|
@@ -550,6 +550,44 @@ function withLiveDreamerOutputCap(executor, boot, fresh) {
|
|
|
550
550
|
};
|
|
551
551
|
}
|
|
552
552
|
|
|
553
|
+
// src/features/magic-context/request-tool-definitions.ts
|
|
554
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
555
|
+
var IDENTITY_SCOPE = "names-descriptions-v1";
|
|
556
|
+
var sha = (value) => createHash2("sha256").update(JSON.stringify(value)).digest("hex");
|
|
557
|
+
function v2ToolDefinitionsHash(tools) {
|
|
558
|
+
const pairs = Object.entries(tools).map(([name, tool]) => [name, tool.description]).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0);
|
|
559
|
+
return JSON.stringify({
|
|
560
|
+
scope: IDENTITY_SCOPE,
|
|
561
|
+
hash: sha(pairs),
|
|
562
|
+
tools: pairs.map(([name, description]) => [name, sha([name, description])])
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
function needsRequestToolIdentityAdoption(previous, current) {
|
|
566
|
+
return readIdentity(current).scope === IDENTITY_SCOPE && readIdentity(previous).scope !== IDENTITY_SCOPE;
|
|
567
|
+
}
|
|
568
|
+
function readIdentity(value) {
|
|
569
|
+
try {
|
|
570
|
+
const parsed = JSON.parse(value);
|
|
571
|
+
if (typeof parsed.hash === "string" && Array.isArray(parsed.tools) && parsed.tools.every((item) => Array.isArray(item) && item.length === 2 && item.every((part) => typeof part === "string")))
|
|
572
|
+
return parsed;
|
|
573
|
+
} catch {}
|
|
574
|
+
return { hash: value, tools: [] };
|
|
575
|
+
}
|
|
576
|
+
function describeRequestToolDefinitionChange(previous, current) {
|
|
577
|
+
const before = readIdentity(previous);
|
|
578
|
+
const after = readIdentity(current);
|
|
579
|
+
let firstDifferingTool = "unknown";
|
|
580
|
+
for (let index = 0;index < Math.max(before.tools.length, after.tools.length); index++) {
|
|
581
|
+
const left = before.tools[index];
|
|
582
|
+
const right = after.tools[index];
|
|
583
|
+
if (left?.[0] === right?.[0] && left?.[1] === right?.[1])
|
|
584
|
+
continue;
|
|
585
|
+
firstDifferingTool = left?.[0] === right?.[0] ? left?.[0] ?? "unknown" : `${left?.[0] ?? "(absent)"}→${right?.[0] ?? "(absent)"}`;
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
return { previousHash: before.hash, currentHash: after.hash, firstDifferingTool };
|
|
589
|
+
}
|
|
590
|
+
|
|
553
591
|
// src/features/magic-context/compartment-lease.ts
|
|
554
592
|
var COMPARTMENT_LEASE_TTL_MS = 5 * 60 * 1000;
|
|
555
593
|
var COMPARTMENT_LEASE_RENEWAL_MS = 60 * 1000;
|
|
@@ -905,7 +943,7 @@ function isPartialCompartmentEnd(db, sessionId, messageId) {
|
|
|
905
943
|
return Boolean(db.prepare("SELECT 1 FROM compartments WHERE session_id=? AND end_message_id=? AND end_block_index IS NOT NULL LIMIT 1").get(sessionId, messageId));
|
|
906
944
|
}
|
|
907
945
|
// src/features/magic-context/project-docs-hash.ts
|
|
908
|
-
import { createHash as
|
|
946
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
909
947
|
import { lstatSync, readFileSync as readFileSync2, statSync as statSync2 } from "node:fs";
|
|
910
948
|
import path from "node:path";
|
|
911
949
|
var PROJECT_DOC_FILES = ["ARCHITECTURE.md", "STRUCTURE.md"];
|
|
@@ -1004,7 +1042,7 @@ function hashCanonicalPieces(hashPieces) {
|
|
|
1004
1042
|
if (hashPieces.length === 0) {
|
|
1005
1043
|
return "";
|
|
1006
1044
|
}
|
|
1007
|
-
return
|
|
1045
|
+
return createHash3("sha256").update(hashPieces.join(PROJECT_DOCS_DELIMITER), "utf8").digest("hex");
|
|
1008
1046
|
}
|
|
1009
1047
|
function readProjectDocsCanonical(projectDirectory) {
|
|
1010
1048
|
canonicalReadCountForTests += 1;
|
|
@@ -1030,10 +1068,10 @@ function readProjectDocsCanonical(projectDirectory) {
|
|
|
1030
1068
|
return { renderedBlock, canonicalHash };
|
|
1031
1069
|
}
|
|
1032
1070
|
// src/hooks/magic-context/lkg-slot.ts
|
|
1033
|
-
import { createHash as
|
|
1071
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
1034
1072
|
|
|
1035
1073
|
// src/hooks/magic-context/lkg-measured-request.ts
|
|
1036
|
-
import { createHash as
|
|
1074
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
1037
1075
|
|
|
1038
1076
|
// src/shared/provider-response-completion.ts
|
|
1039
1077
|
function providerResponseFailed(input) {
|
|
@@ -1051,16 +1089,16 @@ function isSuccessfulProviderCompletion(input) {
|
|
|
1051
1089
|
import { Buffer as Buffer2 } from "node:buffer";
|
|
1052
1090
|
|
|
1053
1091
|
// src/hooks/magic-context/lkg-recovery-fence.ts
|
|
1054
|
-
import { createHash as
|
|
1092
|
+
import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
|
|
1055
1093
|
import { lstatSync as lstatSync2, readdirSync as readdirSync2, readFileSync as readFileSync4, rmdirSync, rmSync as rmSync2 } from "node:fs";
|
|
1056
1094
|
import { basename, dirname, join as join2 } from "node:path";
|
|
1057
1095
|
|
|
1058
1096
|
// src/shared/storage-file-mutex.ts
|
|
1059
1097
|
import { execFileSync } from "node:child_process";
|
|
1060
|
-
import { createHash as
|
|
1098
|
+
import { createHash as createHash4, randomUUID } from "node:crypto";
|
|
1061
1099
|
import { readdirSync, readFileSync as readFileSync3, rmSync } from "node:fs";
|
|
1062
1100
|
import { join } from "node:path";
|
|
1063
|
-
var ticketChecksum = (name, ticket) =>
|
|
1101
|
+
var ticketChecksum = (name, ticket) => createHash4("sha256").update(JSON.stringify([name, ticket.choosing, ticket.number, ticket.birth])).digest("hex");
|
|
1064
1102
|
function processBirth(pid) {
|
|
1065
1103
|
if (process.platform === "linux") {
|
|
1066
1104
|
try {
|
|
@@ -1190,7 +1228,7 @@ function clearLkgFenceProcessState(sessionId) {
|
|
|
1190
1228
|
knownFences.clear();
|
|
1191
1229
|
}
|
|
1192
1230
|
var durableFencesSupported = () => platform !== "win32";
|
|
1193
|
-
var hash = (value) =>
|
|
1231
|
+
var hash = (value) => createHash5("sha256").update(value).digest("hex");
|
|
1194
1232
|
var lkgServedArrayDigest = hash;
|
|
1195
1233
|
function lkgRecoveryFencePath(sessionId) {
|
|
1196
1234
|
return join2(getMagicContextStorageDir(), "lkg-recovery-fences", `${hash(sessionId)}.json`);
|
|
@@ -1207,7 +1245,7 @@ function metadata(slot) {
|
|
|
1207
1245
|
];
|
|
1208
1246
|
}
|
|
1209
1247
|
function representationKey(slot) {
|
|
1210
|
-
return
|
|
1248
|
+
return createHash5("sha256").update(slot.jsonPrefix).update(JSON.stringify(metadata(slot))).digest("hex");
|
|
1211
1249
|
}
|
|
1212
1250
|
function lkgRecoverySlotKey(slot) {
|
|
1213
1251
|
return hash(JSON.stringify([
|
|
@@ -1526,7 +1564,7 @@ function cancelAutoSearchWork(sessionId) {
|
|
|
1526
1564
|
}
|
|
1527
1565
|
|
|
1528
1566
|
// src/v2/store-reader.ts
|
|
1529
|
-
import { createHash as
|
|
1567
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
1530
1568
|
import { statSync as statSync3 } from "node:fs";
|
|
1531
1569
|
import { hostname } from "node:os";
|
|
1532
1570
|
import { resolve } from "node:path";
|
|
@@ -1798,7 +1836,7 @@ class V2StoreReader {
|
|
|
1798
1836
|
this.db = this.connection.db;
|
|
1799
1837
|
}
|
|
1800
1838
|
hostIdentity() {
|
|
1801
|
-
return
|
|
1839
|
+
return createHash6("sha256").update(JSON.stringify([hostname(), resolve(this.path), this.connection.identity])).digest("hex");
|
|
1802
1840
|
}
|
|
1803
1841
|
prepare(sql) {
|
|
1804
1842
|
if (this.closed)
|
|
@@ -2842,7 +2880,7 @@ function lkgProviderInputTotal(tokens) {
|
|
|
2842
2880
|
return counts.every((count) => Number.isSafeInteger(count) && count >= 0) ? counts.reduce((sum, count) => sum + count, 0) : Number.NaN;
|
|
2843
2881
|
}
|
|
2844
2882
|
function identity(slot) {
|
|
2845
|
-
return
|
|
2883
|
+
return createHash7("sha256").update(JSON.stringify([
|
|
2846
2884
|
slot.capturedAt,
|
|
2847
2885
|
slot.captureSequence,
|
|
2848
2886
|
slot.rowVersion,
|
|
@@ -2938,7 +2976,7 @@ function clearCapturedLkgMeasurement(sessionId) {
|
|
|
2938
2976
|
}
|
|
2939
2977
|
|
|
2940
2978
|
// src/hooks/magic-context/lkg-persist.ts
|
|
2941
|
-
import { createHash as
|
|
2979
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
2942
2980
|
function parseStringArray(value) {
|
|
2943
2981
|
if (typeof value !== "string")
|
|
2944
2982
|
return null;
|
|
@@ -3052,7 +3090,7 @@ function rememberFingerprint(db, sessionId, fingerprint) {
|
|
|
3052
3090
|
saved.set(sessionId, fingerprint);
|
|
3053
3091
|
}
|
|
3054
3092
|
function slotFingerprint(slot) {
|
|
3055
|
-
return
|
|
3093
|
+
return createHash8("sha256").update(JSON.stringify([
|
|
3056
3094
|
slot.jsonPrefix,
|
|
3057
3095
|
slot.inputIdSeq,
|
|
3058
3096
|
slot.inputContentDigests,
|
|
@@ -4225,7 +4263,7 @@ var DIGEST_CHUNK_BYTES = 64 * 1024;
|
|
|
4225
4263
|
var digestChunk;
|
|
4226
4264
|
function lkgContentDigestFromFields(fields) {
|
|
4227
4265
|
lkgDigestsComputed += 1;
|
|
4228
|
-
const hash =
|
|
4266
|
+
const hash = createHash9("sha256");
|
|
4229
4267
|
digestChunk ??= Buffer.allocUnsafe(DIGEST_CHUNK_BYTES);
|
|
4230
4268
|
const chunk = digestChunk;
|
|
4231
4269
|
let offset = 0;
|
|
@@ -4288,7 +4326,7 @@ function legacyLkgDigestFromFields(fields) {
|
|
|
4288
4326
|
const value = typeof field === "symbol" ? field.description ?? "" : String(field);
|
|
4289
4327
|
key += `${typeof field}:${value.length}:${value}\x00`;
|
|
4290
4328
|
}
|
|
4291
|
-
return
|
|
4329
|
+
return createHash9("sha256").update(key).digest("base64url");
|
|
4292
4330
|
}
|
|
4293
4331
|
function legacyLkgContentDigest(message) {
|
|
4294
4332
|
const fields = flattenContentFields(withoutEmptyUserDiffSummary(message));
|
|
@@ -6383,14 +6421,14 @@ class HiddenCompletionRefusal extends Error {
|
|
|
6383
6421
|
}
|
|
6384
6422
|
|
|
6385
6423
|
// src/features/magic-context/compaction-marker.ts
|
|
6386
|
-
import { createHash as
|
|
6424
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
6387
6425
|
import { existsSync, statSync as statSync4 } from "node:fs";
|
|
6388
6426
|
var BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
6389
6427
|
var ID_PREFIX_HEX_LENGTH = 12;
|
|
6390
6428
|
var ID_SUFFIX_LENGTH = 14;
|
|
6391
6429
|
var ID_PREFIX_MASK = (1n << BigInt(ID_PREFIX_HEX_LENGTH * 4)) - 1n;
|
|
6392
6430
|
function deterministicBase62(seed, length) {
|
|
6393
|
-
let value = BigInt(`0x${
|
|
6431
|
+
let value = BigInt(`0x${createHash10("sha256").update(seed).digest("hex")}`);
|
|
6394
6432
|
const chars = Array(length);
|
|
6395
6433
|
for (let index = length - 1;index >= 0; index -= 1) {
|
|
6396
6434
|
chars[index] = BASE62_CHARS[Number(value % 62n)];
|
|
@@ -7240,7 +7278,7 @@ function parseUserMemoryRow(row) {
|
|
|
7240
7278
|
}
|
|
7241
7279
|
// src/features/magic-context/dreamer/provider-output-failure.ts
|
|
7242
7280
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7243
|
-
import { createHash as
|
|
7281
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
7244
7282
|
var MAX_NEAR_ZERO_OUTPUT_TOKENS = 32;
|
|
7245
7283
|
|
|
7246
7284
|
class DreamerProviderOutputFailureError extends Error {
|
|
@@ -7337,12 +7375,12 @@ function providerOutputFailureFromInvalidManifest(messages, responseText, now =
|
|
|
7337
7375
|
const resetAt = quotaResetAt(responseText, now);
|
|
7338
7376
|
if (resetAt === undefined && completion.outputTokens > MAX_NEAR_ZERO_OUTPUT_TOKENS)
|
|
7339
7377
|
return null;
|
|
7340
|
-
const fingerprint =
|
|
7378
|
+
const fingerprint = createHash11("sha256").update(normalized).digest("hex").slice(0, 16);
|
|
7341
7379
|
return new DreamerProviderOutputFailureError(fingerprint, completion.outputTokens, completion.reasoningTokens, responseText, resetAt);
|
|
7342
7380
|
}
|
|
7343
7381
|
|
|
7344
7382
|
// src/v2/hooks/hidden-child.ts
|
|
7345
|
-
import { createHash as
|
|
7383
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
7346
7384
|
|
|
7347
7385
|
// src/agents/dreamer.ts
|
|
7348
7386
|
var DREAMER_AGENT = "dreamer";
|
|
@@ -7567,7 +7605,7 @@ function markerCandidates(text) {
|
|
|
7567
7605
|
function textDigest(text) {
|
|
7568
7606
|
return {
|
|
7569
7607
|
length: text.length,
|
|
7570
|
-
sha256:
|
|
7608
|
+
sha256: createHash12("sha256").update(text).digest("hex").slice(0, 16)
|
|
7571
7609
|
};
|
|
7572
7610
|
}
|
|
7573
7611
|
function firstDifference(a, b) {
|
|
@@ -9167,7 +9205,7 @@ async function promptAsyncAndWaitForIdle(client, request, options = {}) {
|
|
|
9167
9205
|
}
|
|
9168
9206
|
}
|
|
9169
9207
|
// src/shared/prompt-surface-runtime.ts
|
|
9170
|
-
import { createHash as
|
|
9208
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
9171
9209
|
import { existsSync as existsSync2, readFileSync as readFileSync5, statSync as statSync5 } from "node:fs";
|
|
9172
9210
|
import { dirname as dirname2, isAbsolute, resolve as resolve2 } from "node:path";
|
|
9173
9211
|
|
|
@@ -9200,7 +9238,7 @@ function promptSurfaceHashMaterial(systemContent, preset = "full") {
|
|
|
9200
9238
|
\x00magic-context-prompt-surface:${preset}`;
|
|
9201
9239
|
}
|
|
9202
9240
|
function systemPromptFingerprint(systemContent, preset = "full") {
|
|
9203
|
-
return
|
|
9241
|
+
return createHash13("md5").update(promptSurfaceHashMaterial(systemContent, preset)).digest("hex");
|
|
9204
9242
|
}
|
|
9205
9243
|
var PROMPT_SURFACE_TOOL_ID_SET = new Set(ACTIVE_TOOL_IDS);
|
|
9206
9244
|
function resolveUserConfigDirectory(options) {
|
|
@@ -11098,7 +11136,7 @@ function compareMemorySelectionPriority(left, right) {
|
|
|
11098
11136
|
}
|
|
11099
11137
|
|
|
11100
11138
|
// src/features/magic-context/mural/render-trigger.ts
|
|
11101
|
-
import { createHash as
|
|
11139
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
11102
11140
|
|
|
11103
11141
|
// src/features/magic-context/mural/mural-selection.ts
|
|
11104
11142
|
var DEFAULT_MURAL_MEMORY_BUDGET = 8000;
|
|
@@ -11802,7 +11840,7 @@ function ensureMuralRendered(db, projectIdentity, budgetTokens = DEFAULT_MURAL_M
|
|
|
11802
11840
|
return { ...cached.result };
|
|
11803
11841
|
}
|
|
11804
11842
|
const plan = planMuralRender(entries);
|
|
11805
|
-
const textHash =
|
|
11843
|
+
const textHash = createHash14("sha256").update(plan.layout.text).digest("hex");
|
|
11806
11844
|
if (existing && existing.contentHash === textHash && existing.width === plan.width && existing.height === plan.height) {
|
|
11807
11845
|
return rememberRender(db, projectIdentity, key, existing.image, {
|
|
11808
11846
|
hasMural: true,
|
|
@@ -11867,6 +11905,7 @@ var MURAL_COMPONENT_PREFIX = "|mural-enabled:";
|
|
|
11867
11905
|
var BUDGET_COMPONENT_PREFIX = "|render-budgets:";
|
|
11868
11906
|
var RENDERED_BUDGETS_COMPONENT_PREFIX = "|rendered-budgets:";
|
|
11869
11907
|
var M0_MEMORY_IDS_COMPONENT_PREFIX = "|m0-memory-ids:";
|
|
11908
|
+
var TOOL_DEFINITIONS_COMPONENT_PREFIX = "|request-tool-definitions:";
|
|
11870
11909
|
function encodeCachedM0UpgradeIdentity(upgradeState, compartmentRenderEpoch = COMPARTMENT_RENDER_EPOCH, muralEnabled = null, renderBudgetIdentity = null, memoryRenderEpoch = MEMORY_RENDER_FORMAT_EPOCH, renderedBudgets = null) {
|
|
11871
11910
|
let encoded = upgradeState ?? "";
|
|
11872
11911
|
if (compartmentRenderEpoch !== null) {
|
|
@@ -11912,7 +11951,8 @@ function decodeCachedM0UpgradeIdentity(value) {
|
|
|
11912
11951
|
value.indexOf(MURAL_COMPONENT_PREFIX),
|
|
11913
11952
|
value.indexOf(BUDGET_COMPONENT_PREFIX),
|
|
11914
11953
|
value.indexOf(RENDERED_BUDGETS_COMPONENT_PREFIX),
|
|
11915
|
-
value.indexOf(M0_MEMORY_IDS_COMPONENT_PREFIX)
|
|
11954
|
+
value.indexOf(M0_MEMORY_IDS_COMPONENT_PREFIX),
|
|
11955
|
+
value.indexOf(TOOL_DEFINITIONS_COMPONENT_PREFIX)
|
|
11916
11956
|
].filter((index) => index >= 0);
|
|
11917
11957
|
const identityEnd = componentIndexes.length > 0 ? Math.min(...componentIndexes) : value.length;
|
|
11918
11958
|
const upgradeState = value.slice(0, identityEnd);
|
|
@@ -11930,6 +11970,22 @@ function withCachedM0MemoryIds(identity, ids) {
|
|
|
11930
11970
|
const withoutIds = (identity ?? "").replace(/\|m0-memory-ids:[^|]*/g, "");
|
|
11931
11971
|
return `${withoutIds}${M0_MEMORY_IDS_COMPONENT_PREFIX}${JSON.stringify(ids)}`;
|
|
11932
11972
|
}
|
|
11973
|
+
function withCachedM0ToolDefinitionsHash(identity, hash) {
|
|
11974
|
+
const withoutHash = (identity ?? "").replace(/\|request-tool-definitions:[^|]*/g, "");
|
|
11975
|
+
if (hash === null)
|
|
11976
|
+
return withoutHash || null;
|
|
11977
|
+
return `${withoutHash}${TOOL_DEFINITIONS_COMPONENT_PREFIX}${encodeURIComponent(hash)}`;
|
|
11978
|
+
}
|
|
11979
|
+
function readCachedM0ToolDefinitionsHash(identity) {
|
|
11980
|
+
const encoded = component(identity ?? "", TOOL_DEFINITIONS_COMPONENT_PREFIX);
|
|
11981
|
+
if (!encoded)
|
|
11982
|
+
return null;
|
|
11983
|
+
try {
|
|
11984
|
+
return decodeURIComponent(encoded) || null;
|
|
11985
|
+
} catch {
|
|
11986
|
+
return null;
|
|
11987
|
+
}
|
|
11988
|
+
}
|
|
11933
11989
|
function readCachedM0MemoryIds(identity, legacyVisibleIds, maxMemoryId) {
|
|
11934
11990
|
const encoded = component(identity ?? "", M0_MEMORY_IDS_COMPONENT_PREFIX);
|
|
11935
11991
|
if (encoded !== null) {
|
|
@@ -13026,6 +13082,7 @@ function readCurrentM0SnapshotMarkersUncached(args) {
|
|
|
13026
13082
|
memoryRenderEpoch: MEMORY_RENDER_FORMAT_EPOCH,
|
|
13027
13083
|
systemHash: hard.systemHash,
|
|
13028
13084
|
toolSetHash: hard.toolSetHash ?? "",
|
|
13085
|
+
toolDefinitionsHash: hard.toolDefinitionsHash ?? null,
|
|
13029
13086
|
modelKey: piModelRefToCanonical(hard.modelKey),
|
|
13030
13087
|
projectIdentity: args.projectPath ?? null,
|
|
13031
13088
|
muralEnabled: args.memoryEnabled !== false && args.muralEnabled === true,
|
|
@@ -13041,6 +13098,7 @@ function refreshVolatileMarkerInputs(markers, args) {
|
|
|
13041
13098
|
materializedAt: Date.now(),
|
|
13042
13099
|
systemHash: hard.systemHash,
|
|
13043
13100
|
toolSetHash: hard.toolSetHash ?? "",
|
|
13101
|
+
toolDefinitionsHash: hard.toolDefinitionsHash ?? null,
|
|
13044
13102
|
modelKey: hard.modelKey,
|
|
13045
13103
|
projectIdentity: args.projectPath ?? null,
|
|
13046
13104
|
muralEnabled: args.memoryEnabled !== false && args.muralEnabled === true,
|
|
@@ -13111,6 +13169,7 @@ function snapshotMarkersFromCachedM0(state) {
|
|
|
13111
13169
|
memoryRenderEpoch: cachedUpgradeIdentity.memoryRenderEpoch,
|
|
13112
13170
|
systemHash: state.cachedM0SystemHash ?? "",
|
|
13113
13171
|
toolSetHash: state.cachedM0ToolSetHash ?? "",
|
|
13172
|
+
toolDefinitionsHash: readCachedM0ToolDefinitionsHash(state.cachedM0UpgradeState),
|
|
13114
13173
|
modelKey: state.cachedM0ModelKey ?? "",
|
|
13115
13174
|
projectIdentity: state.cachedM0ProjectIdentity ?? null,
|
|
13116
13175
|
muralHash: state.cachedM0MuralHash ?? null,
|
|
@@ -13171,6 +13230,23 @@ function mustMaterialize(args) {
|
|
|
13171
13230
|
systemHashNew: hard.systemHash
|
|
13172
13231
|
};
|
|
13173
13232
|
}
|
|
13233
|
+
const liveDefinitionsHash = hard.toolDefinitionsHash;
|
|
13234
|
+
if (liveDefinitionsHash) {
|
|
13235
|
+
const cachedDefinitionsHash = readCachedM0ToolDefinitionsHash(args.state.cachedM0UpgradeState);
|
|
13236
|
+
if (!cachedDefinitionsHash || needsRequestToolIdentityAdoption(cachedDefinitionsHash, liveDefinitionsHash)) {
|
|
13237
|
+
const previousIdentity = args.state.cachedM0UpgradeState;
|
|
13238
|
+
const adoptedIdentity = withCachedM0ToolDefinitionsHash(previousIdentity, liveDefinitionsHash);
|
|
13239
|
+
const adopted = args.db.prepare("UPDATE session_meta SET cached_m0_upgrade_state = ? WHERE session_id = ? AND cached_m0_upgrade_state IS ?").run(adoptedIdentity, args.sessionId, previousIdentity);
|
|
13240
|
+
if (adopted.changes > 0)
|
|
13241
|
+
args.state.cachedM0UpgradeState = adoptedIdentity;
|
|
13242
|
+
} else if (cachedDefinitionsHash !== liveDefinitionsHash) {
|
|
13243
|
+
return {
|
|
13244
|
+
value: true,
|
|
13245
|
+
reason: "tool_definitions",
|
|
13246
|
+
toolDefinitionsChange: describeRequestToolDefinitionChange(cachedDefinitionsHash, liveDefinitionsHash)
|
|
13247
|
+
};
|
|
13248
|
+
}
|
|
13249
|
+
}
|
|
13174
13250
|
const liveToolSetHash = hard.toolSetHash ?? "";
|
|
13175
13251
|
const toolSetHashComparison = liveToolSetHash !== "" ? {
|
|
13176
13252
|
m0ToolSetHashPrev: args.state.cachedM0ToolSetHash,
|
|
@@ -13504,7 +13580,7 @@ function applyMarkersToState(state, m0Bytes, markers, m1Bytes, renderedM0Ids) {
|
|
|
13504
13580
|
state.cachedM0ProjectDocsHash = markers.projectDocsHash;
|
|
13505
13581
|
state.cachedM0MaterializedAt = markers.materializedAt;
|
|
13506
13582
|
state.cachedM0SessionFactsVersion = markers.sessionFactsVersion;
|
|
13507
|
-
state.cachedM0UpgradeState = withCachedM0MemoryIds(encodeCachedM0UpgradeIdentity(markers.upgradeState, markers.compartmentRenderEpoch, markers.muralEnabled, markers.renderBudgetIdentity, markers.memoryRenderEpoch, markers.renderedBudgets ?? null), renderedM0Ids);
|
|
13583
|
+
state.cachedM0UpgradeState = withCachedM0ToolDefinitionsHash(withCachedM0MemoryIds(encodeCachedM0UpgradeIdentity(markers.upgradeState, markers.compartmentRenderEpoch, markers.muralEnabled, markers.renderBudgetIdentity, markers.memoryRenderEpoch, markers.renderedBudgets ?? null), renderedM0Ids), markers.toolDefinitionsHash ?? null);
|
|
13508
13584
|
state.cachedM0SystemHash = markers.systemHash;
|
|
13509
13585
|
state.cachedM0ToolSetHash = markers.toolSetHash;
|
|
13510
13586
|
state.cachedM0ModelKey = markers.modelKey;
|
|
@@ -13629,7 +13705,7 @@ function materializeM0(options) {
|
|
|
13629
13705
|
const renderedMemoryIds = trimmed.renderOrder.map((m) => m.id);
|
|
13630
13706
|
options.beforePhase3ForTest?.();
|
|
13631
13707
|
const steps = new WriteTransactionSteps;
|
|
13632
|
-
const upgradeIdentity = withCachedM0MemoryIds(encodeCachedM0UpgradeIdentity(snapshotMarkers.upgradeState, snapshotMarkers.compartmentRenderEpoch, snapshotMarkers.muralEnabled, snapshotMarkers.renderBudgetIdentity, snapshotMarkers.memoryRenderEpoch, snapshotMarkers.renderedBudgets ?? null), renderedMemoryIds);
|
|
13708
|
+
const upgradeIdentity = withCachedM0ToolDefinitionsHash(withCachedM0MemoryIds(encodeCachedM0UpgradeIdentity(snapshotMarkers.upgradeState, snapshotMarkers.compartmentRenderEpoch, snapshotMarkers.muralEnabled, snapshotMarkers.renderBudgetIdentity, snapshotMarkers.memoryRenderEpoch, snapshotMarkers.renderedBudgets ?? null), renderedMemoryIds), snapshotMarkers.toolDefinitionsHash ?? null);
|
|
13633
13709
|
const baselineEndMessageId = lastCompartmentBoundaryId(compartments);
|
|
13634
13710
|
steps.mark("pre_metadata");
|
|
13635
13711
|
const commitFold = options.onFoldPrepare?.();
|
|
@@ -13662,6 +13738,7 @@ function materializeM0(options) {
|
|
|
13662
13738
|
memoryRenderEpoch: MEMORY_RENDER_FORMAT_EPOCH,
|
|
13663
13739
|
systemHash: snapshotMarkers.systemHash,
|
|
13664
13740
|
toolSetHash: snapshotMarkers.toolSetHash,
|
|
13741
|
+
toolDefinitionsHash: snapshotMarkers.toolDefinitionsHash,
|
|
13665
13742
|
modelKey: snapshotMarkers.modelKey,
|
|
13666
13743
|
projectIdentity: projectPath ?? null,
|
|
13667
13744
|
muralEnabled: snapshotMarkers.muralEnabled,
|
|
@@ -13919,7 +13996,7 @@ function readCachedM0M1Row(db, sessionId) {
|
|
|
13919
13996
|
cached_m0_session_facts_version,
|
|
13920
13997
|
cached_m0_upgrade_state,
|
|
13921
13998
|
cached_m0_system_hash,
|
|
13922
|
-
|
|
13999
|
+
cached_m0_tool_set_hash,
|
|
13923
14000
|
cached_m0_model_key,
|
|
13924
14001
|
cached_m0_project_identity,
|
|
13925
14002
|
cached_m0_last_baseline_end_message_id,
|
|
@@ -13961,6 +14038,7 @@ function markersFromCachedRow(row) {
|
|
|
13961
14038
|
memoryRenderEpoch: cachedUpgradeIdentity.memoryRenderEpoch,
|
|
13962
14039
|
systemHash: row.cached_m0_system_hash ?? "",
|
|
13963
14040
|
toolSetHash: row.cached_m0_tool_set_hash ?? "",
|
|
14041
|
+
toolDefinitionsHash: readCachedM0ToolDefinitionsHash(row.cached_m0_upgrade_state),
|
|
13964
14042
|
modelKey: row.cached_m0_model_key ?? "",
|
|
13965
14043
|
projectIdentity: row.cached_m0_project_identity ?? null,
|
|
13966
14044
|
muralHash: row.cached_m0_mural_hash ?? null,
|
|
@@ -13991,7 +14069,7 @@ function applyCachedRowToState(state, row) {
|
|
|
13991
14069
|
state.cachedM0ProjectDocsHash = markers.projectDocsHash;
|
|
13992
14070
|
state.cachedM0MaterializedAt = markers.materializedAt;
|
|
13993
14071
|
state.cachedM0SessionFactsVersion = markers.sessionFactsVersion;
|
|
13994
|
-
state.cachedM0UpgradeState = encodeCachedM0UpgradeIdentity(markers.upgradeState, markers.compartmentRenderEpoch, markers.muralEnabled, markers.renderBudgetIdentity, markers.memoryRenderEpoch, markers.renderedBudgets ?? null);
|
|
14072
|
+
state.cachedM0UpgradeState = withCachedM0ToolDefinitionsHash(encodeCachedM0UpgradeIdentity(markers.upgradeState, markers.compartmentRenderEpoch, markers.muralEnabled, markers.renderBudgetIdentity, markers.memoryRenderEpoch, markers.renderedBudgets ?? null), markers.toolDefinitionsHash ?? null);
|
|
13995
14073
|
state.cachedM0SystemHash = markers.systemHash;
|
|
13996
14074
|
state.cachedM0ToolSetHash = markers.toolSetHash;
|
|
13997
14075
|
state.cachedM0ModelKey = markers.modelKey;
|
|
@@ -20575,4 +20653,4 @@ ${failure}`;
|
|
|
20575
20653
|
}
|
|
20576
20654
|
}
|
|
20577
20655
|
|
|
20578
|
-
export { historianRunConfig, dreamerRunConfig, pluginConfigReader, currentPluginConfigReader, withLiveDreamerOutputCap, COMPARTMENT_LEASE_RENEWAL_MS, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLeaseBestEffort, isCompartmentLeaseHeld, queueM0Mutation, getMaxM0MutationId, getCompartments, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, getUncoveredCompartmentEndsThrough, providerResponseFailed, isSuccessfulProviderCompletion, LkgRecoveryFenceError, lkgServedArrayDigest, hasCleanLkgRecoveryFence, dirtyLkgRecoveryRevision, ownsLkgDirtyFence, invalidateCleanLkgRecoveryFence, prepareLkgCaptureFence, certifyCommittedLkgCapture, markLkgRecoveryDirty, rememberUnpublishedAutoSearchNoHint, getUnpublishedAutoSearchNoHint, forgetUnpublishedAutoSearchNoHint, registerAutoSearchWork, gaDatabasePath, RAW_MESSAGE_TYPES, V2StoreReaderPool, V2StoreReader, advanceSessionActivity, backfillSessionActivity, getOrCreateSessionMeta, updateSessionMeta, advanceToolReclaimWatermark, markSessionCleanupPending, retryPendingSessionCleanups, retryPendingRustSessionCleanupsForProject, clearSession, requestPendingMaterialization, pendingMaterializationOrigin, hasPendingMaterializationOrigin, clearPendingMaterialization, recordSystemPromptForRequest, recordHeldHeadForRequest, bindSystemPromptResponse, isHeldHeadForRequest, deferDeliveredSystemRefresh, retirePendingSystemPromptDelivery, lkgProviderInputTotal, beginV2LkgRequest, claimLkgRequestIdentity, currentLkgRequestIdentity, noteCapturedLkgRequest, noteLkgProviderResponse, measuredLkgPrefix, clearLkgMeasuredRequest, saveLkgSlotToDb, clearPersistedLkgSlotStrict, loadPersistedLkgSlot, drainStaleLkgSlots, resolveLkgModelKeys, createLkgEntryProjector, captureLkgSlot, validateAnthropicReasoningRuns, validateLkgSeam, replayLkg, coldStartRawServedIndex, coldStartUncapturedReplay, noteUncertifiedNormalLkg, hasProcessLocalLkgProof, lkgDirtyRevision, rememberLkgDirtyRevision, readPersistedLkgUntaggedInputIds, persistLkgUntaggedInputIds, noteLkgRecoveryPrefix, readLkgRecoveryPrefix, noteLkgHealthyPrefix, lkgRecoveryReplayUnproven, lkgRecoveryEntryUnproven, lkgInputIdentity, beginLkgPass, visitMessageContentFields, contentSnapshotValue, messageContentFields, signatureForFields, exactReusablePrefix, incrementalLkgContentDigests, lkgSlotRejection, captureSlot, getInMemorySlot, getSlot, forgetInMemorySlot, dropSlot, noteEntry, getLkgSlotHeapStats, TOOL_SWEEP_SCOPED_MARKER, useScopedToolSweep, createPreAdoptionToolSweepResolver, copySessionStateForClone, queueMemoryMutation, getMaxMemoryMutationIdForProjects, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectUserProfileVersion, saveSourceContent, replaceSourceContent, getSourceContents, readCoordinateGeneration, rebaseSessionCoordinatesAsync, HiddenCompletionRefusal, getOpenCodeDbPath, compareOpenCodeMessagesByCanonicalOrder, prepareCompactionMarkerCandidates, removeMcOwnedCompactionMarkers, getCompartmentEvents, USER_MEMORY_CANDIDATE_TTL_MS, insertUserMemoryCandidates, getUserMemoryCandidates, deleteUserMemoryCandidates, pruneExpiredUserMemoryCandidates, insertUserMemory, getActiveUserMemories, updateUserMemoryContent, dismissUserMemory, DreamerProviderOutputFailureError, withDreamerModelCooldown, providerOutputFailureFromInvalidManifest, DREAMER_AGENT, DREAMER_RETROSPECTIVE_AGENT, DREAMER_PRIMER_INVESTIGATOR_AGENT, DREAMER_MEMORY_MAPPER_AGENT, DREAMER_CLASSIFIER_AGENT, DREAMER_DOCS_AGENT, DREAMER_REVIEWER_AGENT, HIDDEN_HISTORIAN_AGENT, HIDDEN_DREAMER_AGENT, HIDDEN_CURATE_AGENT, hiddenAgentFor, hiddenToolLoop, HIDDEN_RUN_DISPOSED_REASON, noteChildOfDisposedInstance, hiddenChildPermissions, registerHiddenChildAgents, hiddenToolCallRefusal, HiddenAgentStepLimit, HiddenChildHook, extractLatestAssistantText, hasLengthCappedOutput, parseProviderModel, modelBodyField, toModelEntry, ModelProducedNoOutputError, noteModelActivityMonitored, noteModelOutputReceived, isPromptTimeoutError, getPromptFailureDetail, raceWithSignal, promptSyncWithValidatedOutputRetry, normalizeSDKResponse, annotateSubagentInvocationError, failedInvocationStatus, emptyTokenTotals, sumTokensFromChildMessages, recordChildInvocation, createPromptAsyncTransport, CTX_NOTE_LIGHT_DESCRIPTION, ACTIVE_TOOL_IDS, systemPromptFingerprint, createPromptSurfaceRuntime, createPromptSurfaceGuidanceEpochCache, MARKER_SUMMARY_TEXT, markerUpdateDefinitelyDidNotCut, applyDeferredCompactionMarker, teardownChildSession, runTokenLog, formatRunTokenLog, createChildSessionWithFence, buildMagicContextSection, getMuralIdentity, getMural, modelKeyAcceptsImages, resolveMuralWire, extractM0Block, formatDate, TEMPORAL_MARKER_REPLAY_PATTERN, collectTemporalCandidates, injectTemporalMarkers, clearInjectionCache, getVisibleMemoryIds, selectHiddenMessagesAtCompactionSeam, prepareCompartmentInjection, renderCompartmentInjection, MaterializeContentionError, mustMaterialize, trimMemoriesToBudgetV2, renderMemoryBlockV2, materializeM0, hydrateCachedM0Mural, resetPrefixTrimFallbackState, findHostCompactionWindow, capturePrefixTrimSourceOrder, prepareCachedM0M1Replay, hasCompleteCachedM0M1, injectM0M1, clampProducerAtomChars, producerInputTokenLimit, historianProducerReserve, producerPromptFailureReason, resolveHiddenCompletionExecutor, createV1HiddenCompletionExecutor, shouldWaitForNewHistorianHistory, EMPTY_READ_REPLY, noteTouchedAt, renderGlance, renderNotesById, formatWriteReply, observeNoteNudgeServe, onNoteTrigger, peekNoteNudgeText, markNoteNudgeDelivered, clearNoteNudgeTriggerAndCooldown, omitIncompleteFileTokenTotals, describeBoundaryDiagnostics, RECOVERY_NO_HEAD_LIMIT, deriveProtectedTailTokenTarget, selectPerRunCap, resolveOpenCodeProtectedTailBoundary, resolveWrapupProtectedTailBoundary, getRawHistoryEligibility, hasRunnableCompartmentWindow, recordHighPressureNoEligibleHead, noteTransformPassForExactOrdinalReads, runCompartmentAgent, getActiveCompartmentRun, markActiveCompartmentRunPublished, registerActiveCompartmentRun, startCompartmentAgent, isRecompFailure2, isRecompSkip2, extractRecompReason2, setRecompStarting2, setRecompNote2, setRecompTerminal2, buildRecompDeps2, runManagedRecomp2 };
|
|
20656
|
+
export { historianRunConfig, dreamerRunConfig, pluginConfigReader, currentPluginConfigReader, withLiveDreamerOutputCap, v2ToolDefinitionsHash, COMPARTMENT_LEASE_RENEWAL_MS, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLeaseBestEffort, isCompartmentLeaseHeld, queueM0Mutation, getMaxM0MutationId, getCompartments, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, getUncoveredCompartmentEndsThrough, providerResponseFailed, isSuccessfulProviderCompletion, LkgRecoveryFenceError, lkgServedArrayDigest, hasCleanLkgRecoveryFence, dirtyLkgRecoveryRevision, ownsLkgDirtyFence, invalidateCleanLkgRecoveryFence, prepareLkgCaptureFence, certifyCommittedLkgCapture, markLkgRecoveryDirty, rememberUnpublishedAutoSearchNoHint, getUnpublishedAutoSearchNoHint, forgetUnpublishedAutoSearchNoHint, registerAutoSearchWork, gaDatabasePath, RAW_MESSAGE_TYPES, V2StoreReaderPool, V2StoreReader, advanceSessionActivity, backfillSessionActivity, getOrCreateSessionMeta, updateSessionMeta, advanceToolReclaimWatermark, markSessionCleanupPending, retryPendingSessionCleanups, retryPendingRustSessionCleanupsForProject, clearSession, requestPendingMaterialization, pendingMaterializationOrigin, hasPendingMaterializationOrigin, clearPendingMaterialization, recordSystemPromptForRequest, recordHeldHeadForRequest, bindSystemPromptResponse, isHeldHeadForRequest, deferDeliveredSystemRefresh, retirePendingSystemPromptDelivery, lkgProviderInputTotal, beginV2LkgRequest, claimLkgRequestIdentity, currentLkgRequestIdentity, noteCapturedLkgRequest, noteLkgProviderResponse, measuredLkgPrefix, clearLkgMeasuredRequest, saveLkgSlotToDb, clearPersistedLkgSlotStrict, loadPersistedLkgSlot, drainStaleLkgSlots, resolveLkgModelKeys, createLkgEntryProjector, captureLkgSlot, validateAnthropicReasoningRuns, validateLkgSeam, replayLkg, coldStartRawServedIndex, coldStartUncapturedReplay, noteUncertifiedNormalLkg, hasProcessLocalLkgProof, lkgDirtyRevision, rememberLkgDirtyRevision, readPersistedLkgUntaggedInputIds, persistLkgUntaggedInputIds, noteLkgRecoveryPrefix, readLkgRecoveryPrefix, noteLkgHealthyPrefix, lkgRecoveryReplayUnproven, lkgRecoveryEntryUnproven, lkgInputIdentity, beginLkgPass, visitMessageContentFields, contentSnapshotValue, messageContentFields, signatureForFields, exactReusablePrefix, incrementalLkgContentDigests, lkgSlotRejection, captureSlot, getInMemorySlot, getSlot, forgetInMemorySlot, dropSlot, noteEntry, getLkgSlotHeapStats, TOOL_SWEEP_SCOPED_MARKER, useScopedToolSweep, createPreAdoptionToolSweepResolver, copySessionStateForClone, queueMemoryMutation, getMaxMemoryMutationIdForProjects, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectUserProfileVersion, saveSourceContent, replaceSourceContent, getSourceContents, readCoordinateGeneration, rebaseSessionCoordinatesAsync, HiddenCompletionRefusal, getOpenCodeDbPath, compareOpenCodeMessagesByCanonicalOrder, prepareCompactionMarkerCandidates, removeMcOwnedCompactionMarkers, getCompartmentEvents, USER_MEMORY_CANDIDATE_TTL_MS, insertUserMemoryCandidates, getUserMemoryCandidates, deleteUserMemoryCandidates, pruneExpiredUserMemoryCandidates, insertUserMemory, getActiveUserMemories, updateUserMemoryContent, dismissUserMemory, DreamerProviderOutputFailureError, withDreamerModelCooldown, providerOutputFailureFromInvalidManifest, DREAMER_AGENT, DREAMER_RETROSPECTIVE_AGENT, DREAMER_PRIMER_INVESTIGATOR_AGENT, DREAMER_MEMORY_MAPPER_AGENT, DREAMER_CLASSIFIER_AGENT, DREAMER_DOCS_AGENT, DREAMER_REVIEWER_AGENT, HIDDEN_HISTORIAN_AGENT, HIDDEN_DREAMER_AGENT, HIDDEN_CURATE_AGENT, hiddenAgentFor, hiddenToolLoop, HIDDEN_RUN_DISPOSED_REASON, noteChildOfDisposedInstance, hiddenChildPermissions, registerHiddenChildAgents, hiddenToolCallRefusal, HiddenAgentStepLimit, HiddenChildHook, extractLatestAssistantText, hasLengthCappedOutput, parseProviderModel, modelBodyField, toModelEntry, ModelProducedNoOutputError, noteModelActivityMonitored, noteModelOutputReceived, isPromptTimeoutError, getPromptFailureDetail, raceWithSignal, promptSyncWithValidatedOutputRetry, normalizeSDKResponse, annotateSubagentInvocationError, failedInvocationStatus, emptyTokenTotals, sumTokensFromChildMessages, recordChildInvocation, createPromptAsyncTransport, CTX_NOTE_LIGHT_DESCRIPTION, ACTIVE_TOOL_IDS, systemPromptFingerprint, createPromptSurfaceRuntime, createPromptSurfaceGuidanceEpochCache, MARKER_SUMMARY_TEXT, markerUpdateDefinitelyDidNotCut, applyDeferredCompactionMarker, teardownChildSession, runTokenLog, formatRunTokenLog, createChildSessionWithFence, buildMagicContextSection, getMuralIdentity, getMural, modelKeyAcceptsImages, resolveMuralWire, extractM0Block, formatDate, TEMPORAL_MARKER_REPLAY_PATTERN, collectTemporalCandidates, injectTemporalMarkers, clearInjectionCache, getVisibleMemoryIds, selectHiddenMessagesAtCompactionSeam, prepareCompartmentInjection, renderCompartmentInjection, MaterializeContentionError, mustMaterialize, trimMemoriesToBudgetV2, renderMemoryBlockV2, materializeM0, hydrateCachedM0Mural, resetPrefixTrimFallbackState, findHostCompactionWindow, capturePrefixTrimSourceOrder, prepareCachedM0M1Replay, hasCompleteCachedM0M1, injectM0M1, clampProducerAtomChars, producerInputTokenLimit, historianProducerReserve, producerPromptFailureReason, resolveHiddenCompletionExecutor, createV1HiddenCompletionExecutor, shouldWaitForNewHistorianHistory, EMPTY_READ_REPLY, noteTouchedAt, renderGlance, renderNotesById, formatWriteReply, observeNoteNudgeServe, onNoteTrigger, peekNoteNudgeText, markNoteNudgeDelivered, clearNoteNudgeTriggerAndCooldown, omitIncompleteFileTokenTotals, describeBoundaryDiagnostics, RECOVERY_NO_HEAD_LIMIT, deriveProtectedTailTokenTarget, selectPerRunCap, resolveOpenCodeProtectedTailBoundary, resolveWrapupProtectedTailBoundary, getRawHistoryEligibility, hasRunnableCompartmentWindow, recordHighPressureNoEligibleHead, noteTransformPassForExactOrdinalReads, runCompartmentAgent, getActiveCompartmentRun, markActiveCompartmentRunPublished, registerActiveCompartmentRun, startCompartmentAgent, isRecompFailure2, isRecompSkip2, extractRecompReason2, setRecompStarting2, setRecompNote2, setRecompTerminal2, buildRecompDeps2, runManagedRecomp2 };
|
|
@@ -14,6 +14,9 @@ import {
|
|
|
14
14
|
import {
|
|
15
15
|
messageFtsOrdinalRangeIsMapped2
|
|
16
16
|
} from "./server-awr8qa4c.js";
|
|
17
|
+
import {
|
|
18
|
+
isKnownAutocommit
|
|
19
|
+
} from "./server-8ajstryz.js";
|
|
17
20
|
|
|
18
21
|
// src/features/magic-context/compartment-chunk-embedding.ts
|
|
19
22
|
import { createHash } from "node:crypto";
|
|
@@ -346,15 +349,15 @@ function readDatabaseRevision(db) {
|
|
|
346
349
|
if (!statements) {
|
|
347
350
|
statements = {
|
|
348
351
|
version: db.prepare("PRAGMA data_version"),
|
|
349
|
-
changes: db.prepare("SELECT total_changes() AS changes")
|
|
352
|
+
changes: db.prepare("SELECT total_changes() AS changes, (SELECT schema_version FROM pragma_schema_version) AS schemaVersion")
|
|
350
353
|
};
|
|
351
354
|
revisionStatements.set(db, statements);
|
|
352
355
|
}
|
|
353
356
|
const version = statements.version.get();
|
|
354
357
|
const changes = statements.changes.get();
|
|
355
|
-
if (typeof version?.data_version !== "number" || typeof changes?.changes !== "number")
|
|
358
|
+
if (typeof version?.data_version !== "number" || typeof changes?.changes !== "number" || typeof changes.schemaVersion !== "number")
|
|
356
359
|
return null;
|
|
357
|
-
return `${version.data_version}:${changes.changes}`;
|
|
360
|
+
return `${version.data_version}:${changes.changes}:${changes.schemaVersion}`;
|
|
358
361
|
}
|
|
359
362
|
function sameSearchScope(left, right) {
|
|
360
363
|
return left.rowCount === right.rowCount && left.maxRowId === right.maxRowId && left.rowIdSum === right.rowIdSum && (left.metadata === right.metadata || [...left.metadata].every(([id, value]) => right.metadata.get(id) === value));
|
|
@@ -1198,6 +1201,44 @@ function storedWindowsMatchRecordedSource(db, compartmentId, sourceKey, existing
|
|
|
1198
1201
|
}
|
|
1199
1202
|
var COVERAGE_MEMO_LIMIT = 2048;
|
|
1200
1203
|
var cachedCoverageWindows = new Map;
|
|
1204
|
+
var cachedCoverageSources = new WeakMap;
|
|
1205
|
+
function coverageSource(db, candidate, modelId, maxInputTokens) {
|
|
1206
|
+
const revision = isKnownAutocommit(db) ? readDatabaseRevision(db) : null;
|
|
1207
|
+
if (revision === null)
|
|
1208
|
+
cachedCoverageSources.delete(db);
|
|
1209
|
+
let cache = cachedCoverageSources.get(db);
|
|
1210
|
+
if (revision !== null && cache?.revision !== revision) {
|
|
1211
|
+
cache = { revision, entries: new Map };
|
|
1212
|
+
cachedCoverageSources.set(db, cache);
|
|
1213
|
+
}
|
|
1214
|
+
const key = JSON.stringify([
|
|
1215
|
+
candidate.id,
|
|
1216
|
+
candidate.sessionId,
|
|
1217
|
+
candidate.startMessage,
|
|
1218
|
+
candidate.endMessage,
|
|
1219
|
+
modelId,
|
|
1220
|
+
maxInputTokens,
|
|
1221
|
+
CHUNKER_VERSION,
|
|
1222
|
+
getTokenEstimatorFingerprint()
|
|
1223
|
+
]);
|
|
1224
|
+
const cached = cache?.entries.get(key);
|
|
1225
|
+
if (cached)
|
|
1226
|
+
return cached;
|
|
1227
|
+
const mappedText = buildCanonicalChunkTextFromFts2(db, candidate.sessionId, candidate.startMessage, candidate.endMessage);
|
|
1228
|
+
if (mappedText === null)
|
|
1229
|
+
return null;
|
|
1230
|
+
const canonicalText = mappedText || buildCompartmentSummaryFallbackText2(db, candidate.id);
|
|
1231
|
+
const source = {
|
|
1232
|
+
canonicalText,
|
|
1233
|
+
sourceKey: chunkWindowSourceKey2(canonicalText, candidate.startMessage, candidate.endMessage, maxInputTokens)
|
|
1234
|
+
};
|
|
1235
|
+
if (cache && readDatabaseRevision(db) === revision) {
|
|
1236
|
+
if (cache.entries.size >= 8192)
|
|
1237
|
+
cache.entries.delete(cache.entries.keys().next().value);
|
|
1238
|
+
cache.entries.set(key, source);
|
|
1239
|
+
}
|
|
1240
|
+
return source;
|
|
1241
|
+
}
|
|
1201
1242
|
function memoizedCoverageWindows(candidate, canonicalText, sourceKey, modelId, maxInputTokens) {
|
|
1202
1243
|
const key = JSON.stringify([candidate.id, sourceKey, modelId]);
|
|
1203
1244
|
const cached = cachedCoverageWindows.get(key);
|
|
@@ -1236,14 +1277,13 @@ function renumberOneBasedChunkWindows(db, candidate, projectPath, modelId, windo
|
|
|
1236
1277
|
}).immediate();
|
|
1237
1278
|
}
|
|
1238
1279
|
function classifyChunkCoverageDefect(db, projectPath, modelId, candidate, maxInputTokens) {
|
|
1239
|
-
const
|
|
1240
|
-
if (
|
|
1280
|
+
const source = coverageSource(db, candidate, modelId, maxInputTokens);
|
|
1281
|
+
if (source === null)
|
|
1241
1282
|
return { defect: "deferred", windows: [] };
|
|
1242
|
-
const canonicalText
|
|
1283
|
+
const { canonicalText, sourceKey } = source;
|
|
1243
1284
|
if (!canonicalText || chunkEmbedBackoffActive(db, candidate, projectPath, modelId, canonicalText)) {
|
|
1244
1285
|
return { defect: "deferred", windows: [] };
|
|
1245
1286
|
}
|
|
1246
|
-
const sourceKey = chunkWindowSourceKey2(canonicalText, candidate.startMessage, candidate.endMessage, maxInputTokens);
|
|
1247
1287
|
const existing = getExistingChunkHashes(db, candidate.id, modelId, projectPath);
|
|
1248
1288
|
if (storedWindowsMatchRecordedSource(db, candidate.id, sourceKey, existing)) {
|
|
1249
1289
|
return { defect: null, windows: [], sourceKey, confirmedByRecord: true };
|