@cortexkit/opencode-magic-context 0.41.1 → 0.41.2
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/{derive-budgets-bb7mrpzs.js → derive-budgets-9q2d3r93.js} +1 -1
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts +4 -1
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/compartment-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/curate-memory-safety.d.ts +21 -0
- package/dist/features/magic-context/dreamer/curate-memory-safety.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-prompts.d.ts +1 -6
- package/dist/features/magic-context/dreamer/task-prompts.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-failure.d.ts +10 -2
- package/dist/features/magic-context/memory/embedding-failure.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-local.d.ts +7 -0
- package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
- package/dist/features/magic-context/memory/onnxruntime-node-wasm-shim.d.ts +3 -0
- package/dist/features/magic-context/memory/onnxruntime-node-wasm-shim.d.ts.map +1 -0
- package/dist/features/magic-context/memory/sharp-wasm-shim.d.ts +2 -0
- package/dist/features/magic-context/memory/sharp-wasm-shim.d.ts.map +1 -0
- package/dist/features/magic-context/memory/transformers-node-wasm-entry.d.ts +3 -0
- package/dist/features/magic-context/memory/transformers-node-wasm-entry.d.ts.map +1 -0
- package/dist/features/magic-context/message-fts-rowid-map.d.ts +28 -0
- package/dist/features/magic-context/message-fts-rowid-map.d.ts.map +1 -0
- package/dist/features/magic-context/message-index.d.ts.map +1 -1
- package/dist/features/magic-context/migrations.d.ts.map +1 -1
- package/dist/features/magic-context/overflow-detection.d.ts +15 -2
- package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts +2 -1
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +19 -2
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-session.d.ts +3 -2
- package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta.d.ts +2 -2
- package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
- package/dist/features/magic-context/storage-schema-helpers.d.ts.map +1 -1
- package/dist/features/magic-context/storage-session-tables.d.ts +9 -1
- package/dist/features/magic-context/storage-session-tables.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tags.d.ts +13 -0
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/features/magic-context/storage.d.ts +1 -1
- package/dist/features/magic-context/storage.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts +4 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/format-embed-failure.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook-handlers.d.ts +3 -0
- package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +4 -2
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/live-session-state.d.ts +3 -1
- package/dist/hooks/magic-context/live-session-state.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts +9 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/sentinel.d.ts +13 -37
- package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
- package/dist/hooks/magic-context/strip-content.d.ts +12 -5
- package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-id-fallback.d.ts +3 -1
- package/dist/hooks/magic-context/tag-id-fallback.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +25 -2
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-2d4kf2ve.js → index-cvda5jb3.js} +6 -1
- package/dist/{index-dh0vfghk.js → index-j8r0ejb3.js} +923 -127
- package/dist/{index-z893kjyt.js → index-y1yr57fw.js} +79 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1503 -1059
- package/dist/plugin/dream-timer.d.ts +4 -0
- package/dist/plugin/dream-timer.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts +2 -2
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/{recomp-orchestrator-w7xg48e3.js → recomp-orchestrator-m37p3fq6.js} +3 -3
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/rpc-utils.d.ts +3 -1
- package/dist/shared/rpc-utils.d.ts.map +1 -1
- package/dist/shared/summarize-child-stderr.d.ts +2 -0
- package/dist/shared/summarize-child-stderr.d.ts.map +1 -0
- package/dist/shared/window-geometry.d.ts +2 -0
- package/dist/shared/window-geometry.d.ts.map +1 -1
- package/dist/{storage-meta-session-gr4zn7sq.js → storage-meta-session-dse3qv6s.js} +3 -1
- package/dist/tools/ctx-memory/tools.d.ts.map +1 -1
- package/dist/tools/ctx-memory/types.d.ts +2 -0
- package/dist/tools/ctx-memory/types.d.ts.map +1 -1
- package/dist/tools/ctx-reduce/tools.d.ts.map +1 -1
- package/dist/transformers-node-wasm.js +25676 -0
- package/package.json +4 -3
- package/src/config/index.test.ts +41 -0
- package/src/config/latch-permanence-guard.test.ts +5 -0
- package/src/shared/index.ts +1 -0
- package/src/shared/model-resolution.test.ts +17 -13
- package/src/shared/rpc-utils.test.ts +246 -5
- package/src/shared/rpc-utils.ts +340 -49
- package/src/shared/summarize-child-stderr.test.ts +55 -0
- package/src/shared/summarize-child-stderr.ts +33 -0
- package/src/shared/window-geometry.ts +9 -0
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
deriveTriggerBudget,
|
|
3
3
|
modelSupportsVision,
|
|
4
4
|
shouldEnforcePrivateStoragePermissions
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-cvda5jb3.js";
|
|
6
6
|
import {
|
|
7
7
|
describeError,
|
|
8
8
|
getErrorMessage,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
logSlowWriteTransaction,
|
|
17
17
|
persistCachedM0,
|
|
18
18
|
updateSessionMeta
|
|
19
|
-
} from "./index-
|
|
19
|
+
} from "./index-y1yr57fw.js";
|
|
20
20
|
import {
|
|
21
21
|
modelRefLookupOrder,
|
|
22
22
|
piModelRefToCanonical
|
|
@@ -539,8 +539,8 @@ function formatFailClosedBlockingMessage(reason) {
|
|
|
539
539
|
].join(" ");
|
|
540
540
|
}
|
|
541
541
|
return [
|
|
542
|
-
`Magic Context cannot migrate the shared database because ${formatFailClosedBlockingProcesses(reason.blockingProcesses)} may be running an older Magic Context build that would fail against the migrated database.`,
|
|
543
|
-
"Restart the blocking process
|
|
542
|
+
`Magic Context cannot migrate the shared database (one database serves every project on this machine) because ${formatFailClosedBlockingProcesses(reason.blockingProcesses)} may be running an older Magic Context build that would fail against the migrated database.`,
|
|
543
|
+
"Restart the blocking process — even one from a different project — and it will pick up the new build and migrate on start; or shut it down and retry.",
|
|
544
544
|
`Recovery: ${FAIL_CLOSED_DOCTOR_COMMAND}`
|
|
545
545
|
].join(" ");
|
|
546
546
|
}
|
|
@@ -705,8 +705,19 @@ function isPidAlive(pid) {
|
|
|
705
705
|
var RPC_IDENTITY_SKEW_TOLERANCE_MS = 120000;
|
|
706
706
|
var LINUX_CLOCK_TICKS_PER_SECOND = 100;
|
|
707
707
|
var PS_PROBE_TIMEOUT_MS = 1000;
|
|
708
|
+
var WINDOWS_CIM_PROBE_TIMEOUT_MS = 5000;
|
|
709
|
+
var MAX_ANCESTOR_WALK_DEPTH = 16;
|
|
708
710
|
var OPEN_CODE_COMMAND_MARKERS = ["opencode", "node", "bun", "electron"];
|
|
709
711
|
var TASKLIST_NO_TASKS_PATTERN = /^INFO:\s+No tasks are running which match the specified criteria\.?$/im;
|
|
712
|
+
var WINDOWS_CIM_COMMAND = "Get-CimInstance Win32_Process | Select-Object ProcessId,ParentProcessId,CommandLine,CreationDate | ConvertTo-Json -Compress";
|
|
713
|
+
var PI_HARNESS_ARC_MARKERS = [
|
|
714
|
+
"pi-coding-agent",
|
|
715
|
+
"oh-my-pi",
|
|
716
|
+
"@oh-my-pi",
|
|
717
|
+
"cljs/dist",
|
|
718
|
+
"dist/bundle/cli"
|
|
719
|
+
];
|
|
720
|
+
var PI_IMAGE_NAMES = new Set(["pi", "pi.cmd", "omp", "oh-my-pi"]);
|
|
710
721
|
var rpcIdentityReadFileSync = readFileSync;
|
|
711
722
|
var rpcIdentityExecFileSync = execFileSync;
|
|
712
723
|
var rpcIdentityProcessKill = process.kill;
|
|
@@ -751,7 +762,7 @@ function readPsProcessStartTime(pid) {
|
|
|
751
762
|
function readProcessStartTime(pid) {
|
|
752
763
|
if (!Number.isInteger(pid) || pid <= 0)
|
|
753
764
|
return null;
|
|
754
|
-
return rpcIdentityPlatform === "linux" ? readLinuxProcessStartTime(pid) : rpcIdentityPlatform === "win32" ?
|
|
765
|
+
return rpcIdentityPlatform === "linux" ? readLinuxProcessStartTime(pid) : rpcIdentityPlatform === "win32" ? readWindowsProcessStartTime(pid) : readPsProcessStartTime(pid);
|
|
755
766
|
}
|
|
756
767
|
function readProcessProbeEvidence(pid) {
|
|
757
768
|
return {
|
|
@@ -759,6 +770,10 @@ function readProcessProbeEvidence(pid) {
|
|
|
759
770
|
commandLine: readProcessCommand(pid)
|
|
760
771
|
};
|
|
761
772
|
}
|
|
773
|
+
var windowsProcessFactsCache = null;
|
|
774
|
+
function rememberWindowsProcessFacts(facts) {
|
|
775
|
+
windowsProcessFactsCache = new Map(facts.map((fact) => [fact.pid, fact]));
|
|
776
|
+
}
|
|
762
777
|
function parseCsvLine(line) {
|
|
763
778
|
const fields = [];
|
|
764
779
|
let field = "";
|
|
@@ -823,6 +838,16 @@ function readWindowsProcess(pid) {
|
|
|
823
838
|
return { state: "inconclusive" };
|
|
824
839
|
}
|
|
825
840
|
}
|
|
841
|
+
function readWindowsProcessStartTime(pid) {
|
|
842
|
+
const cached = windowsProcessFactsCache?.get(pid);
|
|
843
|
+
if (cached)
|
|
844
|
+
return cached.startTime;
|
|
845
|
+
const snapshot = tryReadWindowsCimSnapshot(rpcIdentityExecFileSync);
|
|
846
|
+
if (!snapshot)
|
|
847
|
+
return null;
|
|
848
|
+
rememberWindowsProcessFacts(snapshot.facts);
|
|
849
|
+
return windowsProcessFactsCache?.get(pid)?.startTime ?? null;
|
|
850
|
+
}
|
|
826
851
|
function readLinuxProcessCommand(pid) {
|
|
827
852
|
try {
|
|
828
853
|
return String(rpcIdentityReadFileSync(`/proc/${pid}/cmdline`, "utf8"));
|
|
@@ -845,7 +870,15 @@ function readPsProcessCommand(pid) {
|
|
|
845
870
|
function readProcessCommand(pid) {
|
|
846
871
|
if (!Number.isInteger(pid) || pid <= 0)
|
|
847
872
|
return null;
|
|
848
|
-
|
|
873
|
+
if (rpcIdentityPlatform === "linux")
|
|
874
|
+
return readLinuxProcessCommand(pid);
|
|
875
|
+
if (rpcIdentityPlatform === "win32") {
|
|
876
|
+
const cached = windowsProcessFactsCache?.get(pid);
|
|
877
|
+
if (cached?.commandLine)
|
|
878
|
+
return cached.commandLine;
|
|
879
|
+
return readWindowsProcess(pid).command ?? null;
|
|
880
|
+
}
|
|
881
|
+
return readPsProcessCommand(pid);
|
|
849
882
|
}
|
|
850
883
|
function executableName(token) {
|
|
851
884
|
return (token ?? "").replace(/^['"]|['"]$/g, "").split("/").at(-1) ?? "";
|
|
@@ -905,57 +938,262 @@ function isPidIdentityPlausible(record, evidence) {
|
|
|
905
938
|
return "inconclusive";
|
|
906
939
|
return commandLooksLikeOpenCode(command) ? "plausible" : "implausible";
|
|
907
940
|
}
|
|
908
|
-
function
|
|
909
|
-
const
|
|
910
|
-
const
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
941
|
+
function commandLooksLikePiImage(command) {
|
|
942
|
+
const tokens = commandTokens(command);
|
|
943
|
+
const first = executableName(tokens[0]).replace(/\.(?:exe|cmd)$/, "");
|
|
944
|
+
return PI_IMAGE_NAMES.has(first);
|
|
945
|
+
}
|
|
946
|
+
function commandHasPiHarnessArc(command) {
|
|
947
|
+
const normalized = command.trim().toLowerCase().replaceAll("\\", "/").replaceAll("\x00", " ");
|
|
948
|
+
if (!normalized)
|
|
949
|
+
return false;
|
|
950
|
+
const tokens = commandTokens(command);
|
|
951
|
+
if (tokens.length === 0)
|
|
952
|
+
return false;
|
|
953
|
+
const hasArc = PI_HARNESS_ARC_MARKERS.some((marker) => normalized.includes(marker));
|
|
954
|
+
const first = executableName(tokens[0]).replace(/\.(?:exe|cmd)$/, "");
|
|
955
|
+
if (hasArc && ["pi", "omp", "oh-my-pi", "node", "bun", "deno", "cmd"].includes(first)) {
|
|
956
|
+
return true;
|
|
957
|
+
}
|
|
958
|
+
if (hasArc && PI_HARNESS_ARC_MARKERS.some((marker) => tokens[0].includes(marker))) {
|
|
914
959
|
return true;
|
|
960
|
+
}
|
|
915
961
|
if (["node", "bun", "deno"].includes(first)) {
|
|
916
|
-
const script =
|
|
917
|
-
|
|
962
|
+
const script = executableName(tokens[1]).replace(/\.(?:exe|cmd)$/, "");
|
|
963
|
+
if (["pi", "pi.js", "pi.mjs", "pi.cjs"].includes(script))
|
|
964
|
+
return true;
|
|
965
|
+
if (hasArc)
|
|
966
|
+
return true;
|
|
918
967
|
}
|
|
919
968
|
return false;
|
|
920
969
|
}
|
|
970
|
+
function execProcessList(exec, file, args, timeout = PS_PROBE_TIMEOUT_MS) {
|
|
971
|
+
return String(exec(file, [...args], {
|
|
972
|
+
encoding: "utf8",
|
|
973
|
+
timeout,
|
|
974
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
975
|
+
}));
|
|
976
|
+
}
|
|
977
|
+
function parseWindowsCreationDate(value) {
|
|
978
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
979
|
+
return value > 1000000000000 ? value : value * 1000;
|
|
980
|
+
}
|
|
981
|
+
if (typeof value !== "string")
|
|
982
|
+
return null;
|
|
983
|
+
const trimmed = value.trim();
|
|
984
|
+
if (!trimmed)
|
|
985
|
+
return null;
|
|
986
|
+
const wmi = /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})\.(\d{6})([+-])(\d{3})$/.exec(trimmed);
|
|
987
|
+
if (wmi) {
|
|
988
|
+
const utcMs = Date.UTC(Number(wmi[1]), Number(wmi[2]) - 1, Number(wmi[3]), Number(wmi[4]), Number(wmi[5]), Number(wmi[6]), Number(wmi[7]) / 1000);
|
|
989
|
+
if (!Number.isFinite(utcMs))
|
|
990
|
+
return null;
|
|
991
|
+
const offsetMinutes = Number(wmi[9]);
|
|
992
|
+
const sign = wmi[8] === "+" ? 1 : -1;
|
|
993
|
+
return utcMs - sign * offsetMinutes * 60000;
|
|
994
|
+
}
|
|
995
|
+
const dotNet = /^\/Date\((-?\d+)\)\/$/.exec(trimmed);
|
|
996
|
+
if (dotNet) {
|
|
997
|
+
const milliseconds = Number(dotNet[1]);
|
|
998
|
+
return Number.isFinite(milliseconds) ? milliseconds : null;
|
|
999
|
+
}
|
|
1000
|
+
const parsed = Date.parse(trimmed);
|
|
1001
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
1002
|
+
}
|
|
1003
|
+
function parseWindowsCimOutput(output) {
|
|
1004
|
+
const trimmed = output.trim();
|
|
1005
|
+
if (!trimmed)
|
|
1006
|
+
return null;
|
|
1007
|
+
const bracket = trimmed.indexOf("[");
|
|
1008
|
+
const brace = trimmed.indexOf("{");
|
|
1009
|
+
const start = Math.min(bracket === -1 ? Number.POSITIVE_INFINITY : bracket, brace === -1 ? Number.POSITIVE_INFINITY : brace);
|
|
1010
|
+
if (!Number.isFinite(start))
|
|
1011
|
+
return null;
|
|
1012
|
+
let parsed;
|
|
1013
|
+
try {
|
|
1014
|
+
parsed = JSON.parse(trimmed.slice(start));
|
|
1015
|
+
} catch {
|
|
1016
|
+
return null;
|
|
1017
|
+
}
|
|
1018
|
+
if (parsed == null)
|
|
1019
|
+
return null;
|
|
1020
|
+
const rows = Array.isArray(parsed) ? parsed : [parsed];
|
|
1021
|
+
const facts = [];
|
|
1022
|
+
for (const row of rows) {
|
|
1023
|
+
if (!row || typeof row !== "object")
|
|
1024
|
+
continue;
|
|
1025
|
+
const record = row;
|
|
1026
|
+
const pid = Number(record.ProcessId);
|
|
1027
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
1028
|
+
continue;
|
|
1029
|
+
const parentRaw = record.ParentProcessId;
|
|
1030
|
+
const parentPid = parentRaw == null || parentRaw === "" ? Number.NaN : Number(parentRaw);
|
|
1031
|
+
const commandLine = typeof record.CommandLine === "string" ? record.CommandLine : null;
|
|
1032
|
+
facts.push({
|
|
1033
|
+
pid,
|
|
1034
|
+
parentPid: Number.isInteger(parentPid) && parentPid > 0 ? parentPid : null,
|
|
1035
|
+
commandLine,
|
|
1036
|
+
imageName: commandLine ? executableName(commandTokens(commandLine)[0]) : null,
|
|
1037
|
+
startTime: parseWindowsCreationDate(record.CreationDate)
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
return facts.length > 0 ? facts : null;
|
|
1041
|
+
}
|
|
1042
|
+
function snapshotFromFacts(facts, source) {
|
|
1043
|
+
const parentByPid = new Map;
|
|
1044
|
+
for (const fact of facts) {
|
|
1045
|
+
if (fact.parentPid != null)
|
|
1046
|
+
parentByPid.set(fact.pid, fact.parentPid);
|
|
1047
|
+
}
|
|
1048
|
+
return { facts, parentByPid, source };
|
|
1049
|
+
}
|
|
1050
|
+
function tryReadWindowsCimSnapshot(exec) {
|
|
1051
|
+
try {
|
|
1052
|
+
const output = execProcessList(exec, "powershell", ["-NoProfile", "-Command", WINDOWS_CIM_COMMAND], WINDOWS_CIM_PROBE_TIMEOUT_MS);
|
|
1053
|
+
const facts = parseWindowsCimOutput(output);
|
|
1054
|
+
return facts ? snapshotFromFacts(facts, "cim") : null;
|
|
1055
|
+
} catch {
|
|
1056
|
+
return null;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
function tryReadWindowsTasklistSnapshot() {
|
|
1060
|
+
try {
|
|
1061
|
+
const output = execProcessList(rpcProcessListExecFileSync, "tasklist", ["/FO", "CSV"]);
|
|
1062
|
+
const entries = parseTasklistOutput(output);
|
|
1063
|
+
if (entries === null)
|
|
1064
|
+
return null;
|
|
1065
|
+
const facts = entries.map((entry) => ({
|
|
1066
|
+
pid: entry.pid,
|
|
1067
|
+
parentPid: null,
|
|
1068
|
+
commandLine: null,
|
|
1069
|
+
imageName: entry.command,
|
|
1070
|
+
startTime: null
|
|
1071
|
+
}));
|
|
1072
|
+
return snapshotFromFacts(facts, "tasklist");
|
|
1073
|
+
} catch {
|
|
1074
|
+
return null;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
function readPosixProcessSnapshot() {
|
|
1078
|
+
const output = execProcessList(rpcProcessListExecFileSync, "ps", ["-axo", "pid=,command="]);
|
|
1079
|
+
const facts = [];
|
|
1080
|
+
for (const line of output.split(/\r?\n/)) {
|
|
1081
|
+
const match = /^\s*(\d+)\s+(.+)$/.exec(line);
|
|
1082
|
+
if (!match)
|
|
1083
|
+
continue;
|
|
1084
|
+
const pid = Number(match[1]);
|
|
1085
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
1086
|
+
continue;
|
|
1087
|
+
facts.push({
|
|
1088
|
+
pid,
|
|
1089
|
+
parentPid: null,
|
|
1090
|
+
commandLine: match[2],
|
|
1091
|
+
imageName: executableName(commandTokens(match[2])[0]),
|
|
1092
|
+
startTime: null
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
return snapshotFromFacts(facts, "ps");
|
|
1096
|
+
}
|
|
1097
|
+
function readPosixParentPid(pid) {
|
|
1098
|
+
try {
|
|
1099
|
+
const output = execProcessList(rpcProcessListExecFileSync, "ps", [
|
|
1100
|
+
"-o",
|
|
1101
|
+
"ppid=",
|
|
1102
|
+
"-p",
|
|
1103
|
+
String(pid)
|
|
1104
|
+
]);
|
|
1105
|
+
const match = /^\s*(\d+)\s*$/.exec(output);
|
|
1106
|
+
if (!match)
|
|
1107
|
+
return null;
|
|
1108
|
+
const ppid = Number(match[1]);
|
|
1109
|
+
return Number.isInteger(ppid) && ppid > 0 ? ppid : null;
|
|
1110
|
+
} catch {
|
|
1111
|
+
return null;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
function collectAncestorPids(selfPid, parentByPid) {
|
|
1115
|
+
const ancestors = new Set;
|
|
1116
|
+
let current = selfPid;
|
|
1117
|
+
for (let depth = 0;depth < MAX_ANCESTOR_WALK_DEPTH; depth += 1) {
|
|
1118
|
+
let ppid = null;
|
|
1119
|
+
if (parentByPid.has(current)) {
|
|
1120
|
+
ppid = parentByPid.get(current) ?? null;
|
|
1121
|
+
} else if (rpcIdentityPlatform !== "win32") {
|
|
1122
|
+
ppid = readPosixParentPid(current);
|
|
1123
|
+
if (ppid == null && current === process.pid && process.ppid > 0) {
|
|
1124
|
+
ppid = process.ppid;
|
|
1125
|
+
}
|
|
1126
|
+
} else if (current === process.pid && process.ppid > 0) {
|
|
1127
|
+
ppid = process.ppid;
|
|
1128
|
+
} else {
|
|
1129
|
+
break;
|
|
1130
|
+
}
|
|
1131
|
+
if (ppid == null || ppid <= 0 || ppid === current || ancestors.has(ppid))
|
|
1132
|
+
break;
|
|
1133
|
+
ancestors.add(ppid);
|
|
1134
|
+
current = ppid;
|
|
1135
|
+
}
|
|
1136
|
+
return ancestors;
|
|
1137
|
+
}
|
|
1138
|
+
function classifyLivePiSnapshot(snapshot) {
|
|
1139
|
+
const ancestors = collectAncestorPids(process.pid, snapshot.parentByPid);
|
|
1140
|
+
const processIds = new Set;
|
|
1141
|
+
const inconclusivePids = new Set;
|
|
1142
|
+
const skippedAncestorPids = [];
|
|
1143
|
+
for (const fact of snapshot.facts) {
|
|
1144
|
+
if (fact.pid === process.pid)
|
|
1145
|
+
continue;
|
|
1146
|
+
const command = fact.commandLine ?? fact.imageName ?? "";
|
|
1147
|
+
const looksLikeHarness = commandHasPiHarnessArc(command) || commandLooksLikePiImage(command);
|
|
1148
|
+
if (!looksLikeHarness)
|
|
1149
|
+
continue;
|
|
1150
|
+
if (ancestors.has(fact.pid)) {
|
|
1151
|
+
skippedAncestorPids.push(fact.pid);
|
|
1152
|
+
log(`[magic-context] Pi process scan: skipping ancestor PID ${fact.pid} (session launcher shim)`);
|
|
1153
|
+
continue;
|
|
1154
|
+
}
|
|
1155
|
+
if (commandHasPiHarnessArc(command)) {
|
|
1156
|
+
processIds.add(fact.pid);
|
|
1157
|
+
continue;
|
|
1158
|
+
}
|
|
1159
|
+
inconclusivePids.add(fact.pid);
|
|
1160
|
+
log(`[magic-context] Pi process scan: PID ${fact.pid} command line is ambiguous (image-name or missing Pi/OMP arc); treating as inconclusive`);
|
|
1161
|
+
}
|
|
1162
|
+
skippedAncestorPids.sort((left, right) => left - right);
|
|
1163
|
+
const verified = [...processIds].sort((left, right) => left - right);
|
|
1164
|
+
const inconclusive = [...inconclusivePids].sort((left, right) => left - right);
|
|
1165
|
+
if (verified.length === 0 && inconclusive.length > 0) {
|
|
1166
|
+
return {
|
|
1167
|
+
state: "inconclusive",
|
|
1168
|
+
processIds: [],
|
|
1169
|
+
inconclusivePids: inconclusive,
|
|
1170
|
+
...skippedAncestorPids.length > 0 ? { skippedAncestorPids } : {}
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
return {
|
|
1174
|
+
state: "known",
|
|
1175
|
+
processIds: verified,
|
|
1176
|
+
...inconclusive.length > 0 ? { inconclusivePids: inconclusive } : {},
|
|
1177
|
+
...skippedAncestorPids.length > 0 ? { skippedAncestorPids } : {}
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
921
1180
|
function inspectLivePiProcesses() {
|
|
922
1181
|
if (false) {}
|
|
923
1182
|
try {
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
929
|
-
}));
|
|
930
|
-
const pids = new Set;
|
|
931
|
-
if (isWindows) {
|
|
932
|
-
const entries = parseTasklistOutput(output);
|
|
933
|
-
if (entries === null) {
|
|
1183
|
+
if (rpcIdentityPlatform === "win32") {
|
|
1184
|
+
const cim = tryReadWindowsCimSnapshot(rpcProcessListExecFileSync);
|
|
1185
|
+
const snapshot = cim ?? tryReadWindowsTasklistSnapshot();
|
|
1186
|
+
if (!snapshot) {
|
|
934
1187
|
return {
|
|
935
1188
|
state: "unreadable",
|
|
936
1189
|
processIds: [],
|
|
937
|
-
error: "
|
|
1190
|
+
error: "process list unavailable"
|
|
938
1191
|
};
|
|
939
1192
|
}
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
continue;
|
|
943
|
-
if (commandLooksLikePi(entry.command))
|
|
944
|
-
pids.add(entry.pid);
|
|
945
|
-
}
|
|
946
|
-
} else {
|
|
947
|
-
for (const line of output.split(/\r?\n/)) {
|
|
948
|
-
const match = /^\s*(\d+)\s+(.+)$/.exec(line);
|
|
949
|
-
if (!match)
|
|
950
|
-
continue;
|
|
951
|
-
const pid = Number(match[1]);
|
|
952
|
-
if (!Number.isInteger(pid) || pid <= 0 || pid === process.pid)
|
|
953
|
-
continue;
|
|
954
|
-
if (commandLooksLikePi(match[2]))
|
|
955
|
-
pids.add(pid);
|
|
956
|
-
}
|
|
1193
|
+
rememberWindowsProcessFacts(snapshot.facts);
|
|
1194
|
+
return classifyLivePiSnapshot(snapshot);
|
|
957
1195
|
}
|
|
958
|
-
return
|
|
1196
|
+
return classifyLivePiSnapshot(readPosixProcessSnapshot());
|
|
959
1197
|
} catch (error) {
|
|
960
1198
|
return {
|
|
961
1199
|
state: "unreadable",
|
|
@@ -2294,6 +2532,135 @@ function pullMemoryMirrorOnce(args) {
|
|
|
2294
2532
|
return flight;
|
|
2295
2533
|
}
|
|
2296
2534
|
|
|
2535
|
+
// src/features/magic-context/message-fts-rowid-map.ts
|
|
2536
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
2537
|
+
var MESSAGE_FTS_ROWID_MAP_BACKFILL_BATCH_SIZE = 500;
|
|
2538
|
+
var BACKFILL_STATE_ID = 1;
|
|
2539
|
+
var EMPTY_INDEX_CONTENT_HASH = createHash3("sha256").update("").digest("hex");
|
|
2540
|
+
var upsertMapStatements = new WeakMap;
|
|
2541
|
+
var rangeReadyStatements = new WeakMap;
|
|
2542
|
+
var activeBackfills = new WeakMap;
|
|
2543
|
+
function getUpsertMapStatement(db) {
|
|
2544
|
+
let statement = upsertMapStatements.get(db);
|
|
2545
|
+
if (!statement) {
|
|
2546
|
+
statement = db.prepare(`INSERT INTO message_fts_rowid_map (session_id, message_ordinal, fts_rowid)
|
|
2547
|
+
VALUES (?, ?, ?)
|
|
2548
|
+
ON CONFLICT(session_id, message_ordinal) DO UPDATE SET
|
|
2549
|
+
fts_rowid = excluded.fts_rowid`);
|
|
2550
|
+
upsertMapStatements.set(db, statement);
|
|
2551
|
+
}
|
|
2552
|
+
return statement;
|
|
2553
|
+
}
|
|
2554
|
+
function getBackfillState(db) {
|
|
2555
|
+
const row = db.prepare(`SELECT watermark_rowid AS watermarkRowid, completed
|
|
2556
|
+
FROM message_fts_rowid_map_backfill_state
|
|
2557
|
+
WHERE id = ?`).get(BACKFILL_STATE_ID);
|
|
2558
|
+
return {
|
|
2559
|
+
processed: 0,
|
|
2560
|
+
watermarkRowid: typeof row?.watermarkRowid === "number" && Number.isSafeInteger(row.watermarkRowid) ? row.watermarkRowid : 0,
|
|
2561
|
+
completed: row?.completed === 1
|
|
2562
|
+
};
|
|
2563
|
+
}
|
|
2564
|
+
function recordMessageFtsRowid(db, sessionId, messageOrdinal, ftsRowid) {
|
|
2565
|
+
const numericRowid = Number(ftsRowid);
|
|
2566
|
+
if (!Number.isSafeInteger(numericRowid) || numericRowid <= 0) {
|
|
2567
|
+
throw new Error(`invalid message FTS rowid: ${String(ftsRowid)}`);
|
|
2568
|
+
}
|
|
2569
|
+
getUpsertMapStatement(db).run(sessionId, messageOrdinal, numericRowid);
|
|
2570
|
+
}
|
|
2571
|
+
function backfillMessageFtsRowidMapBatch(db, batchSize = MESSAGE_FTS_ROWID_MAP_BACKFILL_BATCH_SIZE) {
|
|
2572
|
+
const boundedBatchSize = Math.max(1, Math.floor(batchSize));
|
|
2573
|
+
let progress = {
|
|
2574
|
+
processed: 0,
|
|
2575
|
+
watermarkRowid: 0,
|
|
2576
|
+
completed: false
|
|
2577
|
+
};
|
|
2578
|
+
db.transaction(() => {
|
|
2579
|
+
const state = getBackfillState(db);
|
|
2580
|
+
if (state.completed) {
|
|
2581
|
+
progress = state;
|
|
2582
|
+
return;
|
|
2583
|
+
}
|
|
2584
|
+
const rows = db.prepare(`SELECT rowid AS ftsRowid,
|
|
2585
|
+
session_id AS sessionId,
|
|
2586
|
+
message_ordinal AS messageOrdinal
|
|
2587
|
+
FROM message_history_fts
|
|
2588
|
+
WHERE rowid > ?
|
|
2589
|
+
ORDER BY rowid ASC
|
|
2590
|
+
LIMIT ?`).all(state.watermarkRowid, boundedBatchSize);
|
|
2591
|
+
let watermarkRowid = state.watermarkRowid;
|
|
2592
|
+
for (const row of rows) {
|
|
2593
|
+
const ftsRowid = Number(row.ftsRowid);
|
|
2594
|
+
const messageOrdinal = Number(row.messageOrdinal);
|
|
2595
|
+
if (Number.isSafeInteger(ftsRowid) && ftsRowid > watermarkRowid) {
|
|
2596
|
+
watermarkRowid = ftsRowid;
|
|
2597
|
+
}
|
|
2598
|
+
if (typeof row.sessionId === "string" && Number.isSafeInteger(messageOrdinal) && messageOrdinal >= 0 && Number.isSafeInteger(ftsRowid) && ftsRowid > 0) {
|
|
2599
|
+
recordMessageFtsRowid(db, row.sessionId, messageOrdinal, ftsRowid);
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
const completed = rows.length < boundedBatchSize;
|
|
2603
|
+
db.prepare(`UPDATE message_fts_rowid_map_backfill_state
|
|
2604
|
+
SET watermark_rowid = ?, completed = ?, updated_at = ?
|
|
2605
|
+
WHERE id = ?`).run(watermarkRowid, completed ? 1 : 0, Date.now(), BACKFILL_STATE_ID);
|
|
2606
|
+
progress = {
|
|
2607
|
+
processed: rows.length,
|
|
2608
|
+
watermarkRowid,
|
|
2609
|
+
completed
|
|
2610
|
+
};
|
|
2611
|
+
})();
|
|
2612
|
+
return progress;
|
|
2613
|
+
}
|
|
2614
|
+
async function runMessageFtsRowidMapBackfill(db) {
|
|
2615
|
+
for (;; ) {
|
|
2616
|
+
const progress = backfillMessageFtsRowidMapBatch(db);
|
|
2617
|
+
if (progress.completed)
|
|
2618
|
+
return;
|
|
2619
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
function startMessageFtsRowidMapBackfill(db) {
|
|
2623
|
+
const active = activeBackfills.get(db);
|
|
2624
|
+
if (active)
|
|
2625
|
+
return active;
|
|
2626
|
+
const run = runMessageFtsRowidMapBackfill(db).finally(() => {
|
|
2627
|
+
activeBackfills.delete(db);
|
|
2628
|
+
});
|
|
2629
|
+
activeBackfills.set(db, run);
|
|
2630
|
+
return run;
|
|
2631
|
+
}
|
|
2632
|
+
function messageFtsOrdinalRangeIsMapped(db, sessionId, startOrdinal, endOrdinal) {
|
|
2633
|
+
if (endOrdinal < startOrdinal)
|
|
2634
|
+
return true;
|
|
2635
|
+
if (getBackfillState(db).completed)
|
|
2636
|
+
return true;
|
|
2637
|
+
let statement = rangeReadyStatements.get(db);
|
|
2638
|
+
if (!statement) {
|
|
2639
|
+
statement = db.prepare(`SELECT COUNT(DISTINCT source.message_ordinal) AS sourceOrdinalCount,
|
|
2640
|
+
COUNT(DISTINCT CASE
|
|
2641
|
+
WHEN source.role IN ('user', 'assistant')
|
|
2642
|
+
AND source.normalized_content_hash != ?
|
|
2643
|
+
THEN source.message_ordinal
|
|
2644
|
+
END) AS expectedMapCount,
|
|
2645
|
+
COUNT(DISTINCT CASE
|
|
2646
|
+
WHEN source.role IN ('user', 'assistant')
|
|
2647
|
+
AND source.normalized_content_hash != ?
|
|
2648
|
+
AND map.fts_rowid IS NOT NULL
|
|
2649
|
+
THEN source.message_ordinal
|
|
2650
|
+
END) AS mappedCount
|
|
2651
|
+
FROM message_history_source AS source
|
|
2652
|
+
LEFT JOIN message_fts_rowid_map AS map
|
|
2653
|
+
ON map.session_id = source.session_id
|
|
2654
|
+
AND map.message_ordinal = source.message_ordinal
|
|
2655
|
+
WHERE source.session_id = ?
|
|
2656
|
+
AND source.message_ordinal BETWEEN ? AND ?`);
|
|
2657
|
+
rangeReadyStatements.set(db, statement);
|
|
2658
|
+
}
|
|
2659
|
+
const row = statement.get(EMPTY_INDEX_CONTENT_HASH, EMPTY_INDEX_CONTENT_HASH, sessionId, startOrdinal, endOrdinal);
|
|
2660
|
+
const ordinalCount = endOrdinal - startOrdinal + 1;
|
|
2661
|
+
return row?.sourceOrdinalCount === ordinalCount && row.expectedMapCount === row.mappedCount;
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2297
2664
|
// src/hooks/magic-context/compartment-parser.ts
|
|
2298
2665
|
var COMPARTMENT_REGEX = /<compartment\s+([^>]*?)\s*>(.*?)<\/compartment>/gs;
|
|
2299
2666
|
var ATTR_START_REGEX = /\bstart="(\d+)"/;
|
|
@@ -2515,6 +2882,7 @@ function healAllNullColumns(db) {
|
|
|
2515
2882
|
["stale_reduce_stripped_ids", ""],
|
|
2516
2883
|
["processed_image_stripped_ids", ""],
|
|
2517
2884
|
["merged_reasoning_stripped_ids", ""],
|
|
2885
|
+
["thinking_binding_recovery_target", ""],
|
|
2518
2886
|
["trailing_blank_decisions", ""],
|
|
2519
2887
|
["memory_block_cache", ""],
|
|
2520
2888
|
["memory_block_ids", ""],
|
|
@@ -2566,7 +2934,7 @@ function healMissingMemoryBlockIds(db, columns) {
|
|
|
2566
2934
|
}
|
|
2567
2935
|
|
|
2568
2936
|
// src/features/magic-context/workspaces.ts
|
|
2569
|
-
import { createHash as
|
|
2937
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
2570
2938
|
|
|
2571
2939
|
// src/features/magic-context/memory/constants.ts
|
|
2572
2940
|
var V2_MEMORY_CATEGORIES = [
|
|
@@ -2620,7 +2988,7 @@ var CATEGORY_DEFAULT_TTL = {
|
|
|
2620
2988
|
|
|
2621
2989
|
// src/features/magic-context/memory/project-identity.ts
|
|
2622
2990
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
2623
|
-
import { createHash as
|
|
2991
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
2624
2992
|
import { existsSync, realpathSync, statSync } from "node:fs";
|
|
2625
2993
|
import { homedir } from "node:os";
|
|
2626
2994
|
import path from "node:path";
|
|
@@ -2690,7 +3058,7 @@ function getErrorStderr(error) {
|
|
|
2690
3058
|
}
|
|
2691
3059
|
function directoryFallback(directory) {
|
|
2692
3060
|
const canonical = path.resolve(directory);
|
|
2693
|
-
const hash =
|
|
3061
|
+
const hash = createHash4("md5").update(canonical, "utf8").digest("hex").slice(0, 12);
|
|
2694
3062
|
return `dir:${hash}`;
|
|
2695
3063
|
}
|
|
2696
3064
|
function assertDirectoryUsable(canonicalDirectory, rawDirectory) {
|
|
@@ -3191,7 +3559,7 @@ function computeWorkspaceEpochFingerprint(db, identities) {
|
|
|
3191
3559
|
const canonical = uniqueSorted(identities.filter((identity) => identity.length > 0));
|
|
3192
3560
|
const epochs = getEpochMap(db, canonical);
|
|
3193
3561
|
const shareCategories = selectWorkspaceShareCategories(db, canonical);
|
|
3194
|
-
const hash =
|
|
3562
|
+
const hash = createHash5("sha256");
|
|
3195
3563
|
hash.update("share_categories", "utf8");
|
|
3196
3564
|
hash.update("\x00");
|
|
3197
3565
|
hash.update(shareCategories === null ? "NO_WORKSPACE" : JSON.stringify(shareCategories), "utf8");
|
|
@@ -5416,6 +5784,30 @@ var MIGRATIONS = [
|
|
|
5416
5784
|
return;
|
|
5417
5785
|
ensureColumn(db, "memory_verifications", "mapping_origin", "TEXT NOT NULL DEFAULT 'mapper'");
|
|
5418
5786
|
}
|
|
5787
|
+
},
|
|
5788
|
+
{
|
|
5789
|
+
version: 83,
|
|
5790
|
+
description: "add indexed rowid access for message FTS content",
|
|
5791
|
+
up(db) {
|
|
5792
|
+
db.exec(`
|
|
5793
|
+
CREATE TABLE IF NOT EXISTS message_fts_rowid_map (
|
|
5794
|
+
session_id TEXT NOT NULL,
|
|
5795
|
+
message_ordinal INTEGER NOT NULL,
|
|
5796
|
+
fts_rowid INTEGER NOT NULL,
|
|
5797
|
+
PRIMARY KEY(session_id, message_ordinal)
|
|
5798
|
+
);
|
|
5799
|
+
|
|
5800
|
+
CREATE TABLE IF NOT EXISTS message_fts_rowid_map_backfill_state (
|
|
5801
|
+
id INTEGER PRIMARY KEY CHECK(id = 1),
|
|
5802
|
+
watermark_rowid INTEGER NOT NULL DEFAULT 0,
|
|
5803
|
+
completed INTEGER NOT NULL DEFAULT 0 CHECK(completed IN (0, 1)),
|
|
5804
|
+
updated_at INTEGER NOT NULL DEFAULT 0
|
|
5805
|
+
);
|
|
5806
|
+
INSERT OR IGNORE INTO message_fts_rowid_map_backfill_state
|
|
5807
|
+
(id, watermark_rowid, completed, updated_at)
|
|
5808
|
+
VALUES (1, 0, 0, 0);
|
|
5809
|
+
`);
|
|
5810
|
+
}
|
|
5419
5811
|
}
|
|
5420
5812
|
];
|
|
5421
5813
|
var LATEST_MIGRATION_VERSION = MIGRATIONS.reduce((max, m) => Math.max(max, m.version), 0);
|
|
@@ -5534,7 +5926,7 @@ async function runMigrationsWithRetry(db, options = {}) {
|
|
|
5534
5926
|
}
|
|
5535
5927
|
|
|
5536
5928
|
// src/features/magic-context/tool-definition-tokens.ts
|
|
5537
|
-
import { createHash as
|
|
5929
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
5538
5930
|
|
|
5539
5931
|
// src/hooks/magic-context/read-session-formatting.ts
|
|
5540
5932
|
import { existsSync as existsSync2, readFileSync as readFileSync2, realpathSync as realpathSync2 } from "node:fs";
|
|
@@ -5873,7 +6265,7 @@ function keyFor(providerID, modelID, agentName) {
|
|
|
5873
6265
|
return `${providerID}/${modelID}/${agent}`;
|
|
5874
6266
|
}
|
|
5875
6267
|
function fingerprintFor(description, parameters) {
|
|
5876
|
-
return
|
|
6268
|
+
return createHash6("sha256").update(description).update("\x00").update(stableStringify(parameters)).digest("hex");
|
|
5877
6269
|
}
|
|
5878
6270
|
function getCurrentToolSetHash(providerID, modelID, agentName) {
|
|
5879
6271
|
if (!providerID || !modelID)
|
|
@@ -5881,7 +6273,7 @@ function getCurrentToolSetHash(providerID, modelID, agentName) {
|
|
|
5881
6273
|
const toolIds = measurements.get(keyFor(providerID, modelID, agentName));
|
|
5882
6274
|
if (!toolIds || toolIds.size === 0)
|
|
5883
6275
|
return "";
|
|
5884
|
-
return
|
|
6276
|
+
return createHash6("sha256").update(Array.from(toolIds.keys()).sort().join("\x00")).digest("hex");
|
|
5885
6277
|
}
|
|
5886
6278
|
function setDatabase(db) {
|
|
5887
6279
|
persistenceDb = db;
|
|
@@ -6224,7 +6616,7 @@ function getSchemaFenceRejection() {
|
|
|
6224
6616
|
function getMigrationOnOpenRefusal() {
|
|
6225
6617
|
return lastMigrationOnOpenRefusal;
|
|
6226
6618
|
}
|
|
6227
|
-
var LATEST_SUPPORTED_VERSION =
|
|
6619
|
+
var LATEST_SUPPORTED_VERSION = 83;
|
|
6228
6620
|
var PERMISSIONS_ENFORCEABLE = process.platform !== "win32";
|
|
6229
6621
|
var defaultStoragePermissionFs = { chmodSync, mkdirSync };
|
|
6230
6622
|
var storagePermissionFs = defaultStoragePermissionFs;
|
|
@@ -6523,13 +6915,18 @@ function createPiBlockingProcess(pid) {
|
|
|
6523
6915
|
function formatInconclusiveOpenCodeMigrationWarning(dbPath, pids) {
|
|
6524
6916
|
return `[magic-context] storage warning: continuing migration for ${dbPath}; OpenCode server PID ${pids.join(", ")} was not confirmed because its liveness or identity check could not run. This commonly means an OS sandbox denied kill(0) or ps. No live OpenCode server was confirmed.`;
|
|
6525
6917
|
}
|
|
6526
|
-
function
|
|
6918
|
+
function formatInconclusivePiMigrationWarning(dbPath, pids) {
|
|
6919
|
+
return `[magic-context] storage warning: continuing migration for ${dbPath}; Pi/OMP PID ${pids.join(", ")} was not confirmed as a live harness because the process image or command line was ambiguous. No live Pi harness was confirmed.`;
|
|
6920
|
+
}
|
|
6921
|
+
function logInconclusiveMigrationProbes(dbPath, discovery, piDiscovery) {
|
|
6527
6922
|
const uncertainPids = discovery.inconclusivePids ?? [];
|
|
6528
6923
|
if (uncertainPids.length > 0) {
|
|
6529
6924
|
log(formatInconclusiveOpenCodeMigrationWarning(dbPath, uncertainPids));
|
|
6530
6925
|
}
|
|
6531
|
-
if (
|
|
6926
|
+
if (piDiscovery.state === "unreadable") {
|
|
6532
6927
|
log(`[magic-context] storage warning: continuing migration for ${dbPath}; the Pi/OMP process-list probe could not run, which commonly means an OS sandbox denied ps. No live Pi harness was confirmed.`);
|
|
6928
|
+
} else if ((piDiscovery.inconclusivePids?.length ?? 0) > 0) {
|
|
6929
|
+
log(formatInconclusivePiMigrationWarning(dbPath, piDiscovery.inconclusivePids ?? []));
|
|
6533
6930
|
}
|
|
6534
6931
|
}
|
|
6535
6932
|
function isDefaultSharedDatabasePath(dbPath) {
|
|
@@ -6564,7 +6961,7 @@ function enforceMigrationOnOpenGuard(db, dbPath, dbDir, latestSupportedVersion)
|
|
|
6564
6961
|
const blockingProcesses = [...serverProcesses, ...piPids.map(createPiBlockingProcess)];
|
|
6565
6962
|
if ((discovery.state === "absent" || discovery.state === "stale" || discovery.state === "inconclusive") && piPids.length === 0) {
|
|
6566
6963
|
lastMigrationOnOpenRefusal = null;
|
|
6567
|
-
logInconclusiveMigrationProbes(dbPath, discovery, piDiscovery
|
|
6964
|
+
logInconclusiveMigrationProbes(dbPath, discovery, piDiscovery);
|
|
6568
6965
|
return true;
|
|
6569
6966
|
}
|
|
6570
6967
|
const blockingPids = [...new Set([...discovery.serverPids, ...piPids])].sort((left, right) => left - right);
|
|
@@ -6611,17 +7008,20 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
|
|
|
6611
7008
|
}
|
|
6612
7009
|
healWedgedChannel2Claims(db);
|
|
6613
7010
|
if (!explicitDbPath) {
|
|
6614
|
-
const
|
|
7011
|
+
const runBackfills = () => {
|
|
6615
7012
|
try {
|
|
6616
7013
|
runToolOwnerBackfill(db);
|
|
6617
7014
|
} catch (error) {
|
|
6618
7015
|
log(`[magic-context] tool-owner backfill failed (continuing with lazy adoption fallback): ${getErrorMessage(error)}`);
|
|
6619
7016
|
}
|
|
7017
|
+
startMessageFtsRowidMapBackfill(db).catch((error) => {
|
|
7018
|
+
log(`[magic-context] message FTS rowid-map backfill failed (will resume next startup): ${getErrorMessage(error)}`);
|
|
7019
|
+
});
|
|
6620
7020
|
};
|
|
6621
7021
|
if (bootQuietRemainingMs() > 0)
|
|
6622
|
-
scheduleAfterBootQuiet(
|
|
7022
|
+
scheduleAfterBootQuiet(runBackfills);
|
|
6623
7023
|
else
|
|
6624
|
-
|
|
7024
|
+
runBackfills();
|
|
6625
7025
|
}
|
|
6626
7026
|
setDatabase(db);
|
|
6627
7027
|
loadToolDefinitionMeasurements(db);
|
|
@@ -7161,6 +7561,23 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
7161
7561
|
tokenize='porter unicode61'
|
|
7162
7562
|
);
|
|
7163
7563
|
|
|
7564
|
+
CREATE TABLE IF NOT EXISTS message_fts_rowid_map (
|
|
7565
|
+
session_id TEXT NOT NULL,
|
|
7566
|
+
message_ordinal INTEGER NOT NULL,
|
|
7567
|
+
fts_rowid INTEGER NOT NULL,
|
|
7568
|
+
PRIMARY KEY(session_id, message_ordinal)
|
|
7569
|
+
);
|
|
7570
|
+
|
|
7571
|
+
CREATE TABLE IF NOT EXISTS message_fts_rowid_map_backfill_state (
|
|
7572
|
+
id INTEGER PRIMARY KEY CHECK(id = 1),
|
|
7573
|
+
watermark_rowid INTEGER NOT NULL DEFAULT 0,
|
|
7574
|
+
completed INTEGER NOT NULL DEFAULT 0 CHECK(completed IN (0, 1)),
|
|
7575
|
+
updated_at INTEGER NOT NULL DEFAULT 0
|
|
7576
|
+
);
|
|
7577
|
+
INSERT OR IGNORE INTO message_fts_rowid_map_backfill_state
|
|
7578
|
+
(id, watermark_rowid, completed, updated_at)
|
|
7579
|
+
VALUES (1, 0, 0, 0);
|
|
7580
|
+
|
|
7164
7581
|
CREATE TABLE IF NOT EXISTS message_history_index (
|
|
7165
7582
|
session_id TEXT PRIMARY KEY,
|
|
7166
7583
|
last_indexed_ordinal INTEGER NOT NULL DEFAULT 0,
|
|
@@ -7304,8 +7721,9 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
7304
7721
|
cached_m0_system_hash TEXT,
|
|
7305
7722
|
cached_m0_tool_set_hash TEXT,
|
|
7306
7723
|
cached_m0_model_key TEXT,
|
|
7307
|
-
|
|
7308
|
-
|
|
7724
|
+
cached_m0_project_identity TEXT,
|
|
7725
|
+
cached_m0_last_baseline_end_message_id TEXT,
|
|
7726
|
+
thinking_binding_recovery_target TEXT NOT NULL DEFAULT '',
|
|
7309
7727
|
upgrade_reminded_at INTEGER,
|
|
7310
7728
|
pi_stable_id_scheme INTEGER
|
|
7311
7729
|
);
|
|
@@ -7527,6 +7945,7 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
7527
7945
|
ensureColumn(db, "session_meta", "stale_reduce_stripped_ids", "TEXT DEFAULT ''");
|
|
7528
7946
|
ensureColumn(db, "session_meta", "processed_image_stripped_ids", "TEXT DEFAULT ''");
|
|
7529
7947
|
ensureColumn(db, "session_meta", "merged_reasoning_stripped_ids", "TEXT DEFAULT ''");
|
|
7948
|
+
ensureColumn(db, "session_meta", "thinking_binding_recovery_target", "TEXT DEFAULT ''");
|
|
7530
7949
|
ensureColumn(db, "session_meta", "trailing_blank_decisions", "TEXT DEFAULT ''");
|
|
7531
7950
|
ensureColumn(db, "compartments", "start_message_id", "TEXT DEFAULT ''");
|
|
7532
7951
|
ensureColumn(db, "compartments", "end_message_id", "TEXT DEFAULT ''");
|
|
@@ -7926,7 +8345,7 @@ function probeChildSpawnFence(db) {
|
|
|
7926
8345
|
return { allowSpawn: true };
|
|
7927
8346
|
}
|
|
7928
8347
|
// src/features/magic-context/message-index.ts
|
|
7929
|
-
import { createHash as
|
|
8348
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
7930
8349
|
|
|
7931
8350
|
// src/hooks/magic-context/read-session-raw.ts
|
|
7932
8351
|
function isRawMessageRow(row) {
|
|
@@ -9695,6 +10114,9 @@ var upsertMessageSourceStatements = new WeakMap;
|
|
|
9695
10114
|
var deleteMessageSourceStatements = new WeakMap;
|
|
9696
10115
|
var deleteMessageSourceRangeStatements = new WeakMap;
|
|
9697
10116
|
var deleteMessageFtsStatements = new WeakMap;
|
|
10117
|
+
var deleteFtsMapStatements = new WeakMap;
|
|
10118
|
+
var deleteFtsMapRangeStatements = new WeakMap;
|
|
10119
|
+
var deleteMessageFtsMapStatements = new WeakMap;
|
|
9698
10120
|
function normalizeIndexText(text) {
|
|
9699
10121
|
return text.replace(/\s+/g, " ").trim();
|
|
9700
10122
|
}
|
|
@@ -9733,7 +10155,10 @@ function getUpsertDirtyFloorStatement(db) {
|
|
|
9733
10155
|
function getDeleteFtsStatement(db) {
|
|
9734
10156
|
let stmt = deleteFtsStatements.get(db);
|
|
9735
10157
|
if (!stmt) {
|
|
9736
|
-
stmt = db.prepare(
|
|
10158
|
+
stmt = db.prepare(`DELETE FROM message_history_fts
|
|
10159
|
+
WHERE rowid IN (
|
|
10160
|
+
SELECT fts_rowid FROM message_fts_rowid_map WHERE session_id = ?
|
|
10161
|
+
)`);
|
|
9737
10162
|
deleteFtsStatements.set(db, stmt);
|
|
9738
10163
|
}
|
|
9739
10164
|
return stmt;
|
|
@@ -9741,7 +10166,12 @@ function getDeleteFtsStatement(db) {
|
|
|
9741
10166
|
function getDeleteFtsRangeStatement(db) {
|
|
9742
10167
|
let stmt = deleteFtsRangeStatements.get(db);
|
|
9743
10168
|
if (!stmt) {
|
|
9744
|
-
stmt = db.prepare(
|
|
10169
|
+
stmt = db.prepare(`DELETE FROM message_history_fts
|
|
10170
|
+
WHERE rowid IN (
|
|
10171
|
+
SELECT fts_rowid
|
|
10172
|
+
FROM message_fts_rowid_map
|
|
10173
|
+
WHERE session_id = ? AND message_ordinal BETWEEN ? AND ?
|
|
10174
|
+
)`);
|
|
9745
10175
|
deleteFtsRangeStatements.set(db, stmt);
|
|
9746
10176
|
}
|
|
9747
10177
|
return stmt;
|
|
@@ -9757,7 +10187,12 @@ function getDeleteIndexStatement(db) {
|
|
|
9757
10187
|
function getCountIndexedMessageStatement(db) {
|
|
9758
10188
|
let stmt = countIndexedMessageStatements.get(db);
|
|
9759
10189
|
if (!stmt) {
|
|
9760
|
-
stmt = db.prepare(
|
|
10190
|
+
stmt = db.prepare(`SELECT COUNT(*) AS count
|
|
10191
|
+
FROM message_history_source AS source
|
|
10192
|
+
JOIN message_fts_rowid_map AS map
|
|
10193
|
+
ON map.session_id = source.session_id
|
|
10194
|
+
AND map.message_ordinal = source.message_ordinal
|
|
10195
|
+
WHERE source.session_id = ? AND source.message_id = ?`);
|
|
9761
10196
|
countIndexedMessageStatements.set(db, stmt);
|
|
9762
10197
|
}
|
|
9763
10198
|
return stmt;
|
|
@@ -9807,11 +10242,53 @@ function getDeleteMessageSourceRangeStatement(db) {
|
|
|
9807
10242
|
function getDeleteMessageFtsStatement(db) {
|
|
9808
10243
|
let stmt = deleteMessageFtsStatements.get(db);
|
|
9809
10244
|
if (!stmt) {
|
|
9810
|
-
stmt = db.prepare(
|
|
10245
|
+
stmt = db.prepare(`DELETE FROM message_history_fts
|
|
10246
|
+
WHERE rowid IN (
|
|
10247
|
+
SELECT map.fts_rowid
|
|
10248
|
+
FROM message_history_source AS source
|
|
10249
|
+
JOIN message_fts_rowid_map AS map
|
|
10250
|
+
ON map.session_id = source.session_id
|
|
10251
|
+
AND map.message_ordinal = source.message_ordinal
|
|
10252
|
+
WHERE source.session_id = ? AND source.message_id = ?
|
|
10253
|
+
)`);
|
|
9811
10254
|
deleteMessageFtsStatements.set(db, stmt);
|
|
9812
10255
|
}
|
|
9813
10256
|
return stmt;
|
|
9814
10257
|
}
|
|
10258
|
+
function getDeleteFtsMapStatement(db) {
|
|
10259
|
+
let stmt = deleteFtsMapStatements.get(db);
|
|
10260
|
+
if (!stmt) {
|
|
10261
|
+
stmt = db.prepare("DELETE FROM message_fts_rowid_map WHERE session_id = ?");
|
|
10262
|
+
deleteFtsMapStatements.set(db, stmt);
|
|
10263
|
+
}
|
|
10264
|
+
return stmt;
|
|
10265
|
+
}
|
|
10266
|
+
function getDeleteFtsMapRangeStatement(db) {
|
|
10267
|
+
let stmt = deleteFtsMapRangeStatements.get(db);
|
|
10268
|
+
if (!stmt) {
|
|
10269
|
+
stmt = db.prepare("DELETE FROM message_fts_rowid_map WHERE session_id = ? AND message_ordinal BETWEEN ? AND ?");
|
|
10270
|
+
deleteFtsMapRangeStatements.set(db, stmt);
|
|
10271
|
+
}
|
|
10272
|
+
return stmt;
|
|
10273
|
+
}
|
|
10274
|
+
function getDeleteMessageFtsMapStatement(db) {
|
|
10275
|
+
let stmt = deleteMessageFtsMapStatements.get(db);
|
|
10276
|
+
if (!stmt) {
|
|
10277
|
+
stmt = db.prepare(`DELETE FROM message_fts_rowid_map
|
|
10278
|
+
WHERE session_id = ?
|
|
10279
|
+
AND message_ordinal = (
|
|
10280
|
+
SELECT message_ordinal
|
|
10281
|
+
FROM message_history_source
|
|
10282
|
+
WHERE session_id = ? AND message_id = ?
|
|
10283
|
+
)`);
|
|
10284
|
+
deleteMessageFtsMapStatements.set(db, stmt);
|
|
10285
|
+
}
|
|
10286
|
+
return stmt;
|
|
10287
|
+
}
|
|
10288
|
+
function insertMessageFtsRow(db, sessionId, messageOrdinal, messageId, role, content) {
|
|
10289
|
+
const result = getInsertMessageStatement(db).run(sessionId, messageOrdinal, messageId, role, content);
|
|
10290
|
+
recordMessageFtsRowid(db, sessionId, messageOrdinal, result.lastInsertRowid);
|
|
10291
|
+
}
|
|
9815
10292
|
function normalizeSourceVersion(version) {
|
|
9816
10293
|
if (typeof version === "number")
|
|
9817
10294
|
return `number:${version}`;
|
|
@@ -9824,7 +10301,7 @@ function getMessageSourceSnapshot(message) {
|
|
|
9824
10301
|
return {
|
|
9825
10302
|
ordinal: message.ordinal,
|
|
9826
10303
|
sourceVersion: normalizeSourceVersion(message.version),
|
|
9827
|
-
contentHash:
|
|
10304
|
+
contentHash: createHash7("sha256").update(content).digest("hex"),
|
|
9828
10305
|
role: message.role,
|
|
9829
10306
|
content
|
|
9830
10307
|
};
|
|
@@ -9884,6 +10361,7 @@ function deleteIndexedMessage(db, sessionId, messageId) {
|
|
|
9884
10361
|
function clearIndexedMessages(db, sessionId) {
|
|
9885
10362
|
db.transaction(() => {
|
|
9886
10363
|
getDeleteFtsStatement(db).run(sessionId);
|
|
10364
|
+
getDeleteFtsMapStatement(db).run(sessionId);
|
|
9887
10365
|
getDeleteMessageSourceStatement(db).run(sessionId);
|
|
9888
10366
|
getDeleteIndexStatement(db).run(sessionId);
|
|
9889
10367
|
clearCompressionDepth(db, sessionId);
|
|
@@ -9908,10 +10386,14 @@ function indexSingleMessageInTransaction(db, sessionId, message, now, dirtyFloor
|
|
|
9908
10386
|
if (isMessageIndexSourceCurrent(db, sessionId, message)) {
|
|
9909
10387
|
return false;
|
|
9910
10388
|
}
|
|
10389
|
+
if (!messageFtsOrdinalRangeIsMapped(db, sessionId, message.ordinal, message.ordinal)) {
|
|
10390
|
+
return false;
|
|
10391
|
+
}
|
|
9911
10392
|
getDeleteMessageFtsStatement(db).run(sessionId, message.id);
|
|
10393
|
+
getDeleteMessageFtsMapStatement(db).run(sessionId, sessionId, message.id);
|
|
9912
10394
|
const content2 = setMessageSource(db, sessionId, message, now);
|
|
9913
10395
|
if (content2.length > 0 && (message.role === "user" || message.role === "assistant")) {
|
|
9914
|
-
|
|
10396
|
+
insertMessageFtsRow(db, sessionId, message.ordinal, message.id, message.role, content2);
|
|
9915
10397
|
}
|
|
9916
10398
|
setIndexProgress(db, sessionId, currentWatermark, dirtyFloorBeforeAttempt === message.ordinal ? null : dirtyFloorBeforeAttempt, now);
|
|
9917
10399
|
return true;
|
|
@@ -9922,7 +10404,7 @@ function indexSingleMessageInTransaction(db, sessionId, message, now, dirtyFloor
|
|
|
9922
10404
|
const content = setMessageSource(db, sessionId, message, now);
|
|
9923
10405
|
let inserted = false;
|
|
9924
10406
|
if (content.length > 0 && (message.role === "user" || message.role === "assistant") && !isMessageAlreadyIndexed(db, sessionId, message.id)) {
|
|
9925
|
-
|
|
10407
|
+
insertMessageFtsRow(db, sessionId, message.ordinal, message.id, message.role, content);
|
|
9926
10408
|
inserted = true;
|
|
9927
10409
|
}
|
|
9928
10410
|
setIndexProgress(db, sessionId, message.ordinal, dirtyFloorBeforeAttempt === message.ordinal ? null : dirtyFloorBeforeAttempt, now);
|
|
@@ -9959,8 +10441,14 @@ function indexMessagesAfterOrdinal(db, sessionId, messages, _lastIndexedOrdinal,
|
|
|
9959
10441
|
const currentWatermark = getLastIndexedOrdinal(db, sessionId);
|
|
9960
10442
|
const dirtyFloor = getDirtyIndexFloor(db, sessionId);
|
|
9961
10443
|
const effectiveWatermark = dirtyFloor === null ? currentWatermark : Math.min(currentWatermark, Math.max(0, dirtyFloor - 1));
|
|
10444
|
+
if (dirtyFloor !== null && dirtyFloor <= currentWatermark && !messageFtsOrdinalRangeIsMapped(db, sessionId, dirtyFloor, Math.min(currentWatermark, finalWatermark))) {
|
|
10445
|
+
db.exec("COMMIT");
|
|
10446
|
+
committed = true;
|
|
10447
|
+
return 0;
|
|
10448
|
+
}
|
|
9962
10449
|
if (dirtyFloor !== null && dirtyFloor <= finalWatermark) {
|
|
9963
10450
|
getDeleteFtsRangeStatement(db).run(sessionId, dirtyFloor, finalWatermark);
|
|
10451
|
+
getDeleteFtsMapRangeStatement(db).run(sessionId, dirtyFloor, finalWatermark);
|
|
9964
10452
|
getDeleteMessageSourceRangeStatement(db).run(sessionId, dirtyFloor, finalWatermark);
|
|
9965
10453
|
}
|
|
9966
10454
|
const messagesByOrdinal = new Map;
|
|
@@ -9981,7 +10469,7 @@ function indexMessagesAfterOrdinal(db, sessionId, messages, _lastIndexedOrdinal,
|
|
|
9981
10469
|
if (content.length === 0 || message.role !== "user" && message.role !== "assistant" || isMessageAlreadyIndexed(db, sessionId, message.id)) {
|
|
9982
10470
|
continue;
|
|
9983
10471
|
}
|
|
9984
|
-
|
|
10472
|
+
insertMessageFtsRow(db, sessionId, message.ordinal, message.id, message.role, content);
|
|
9985
10473
|
inserted += 1;
|
|
9986
10474
|
}
|
|
9987
10475
|
const missingFloor = coveredWatermark < finalWatermark ? coveredWatermark + 1 : null;
|
|
@@ -10075,8 +10563,7 @@ function sweepOrphanedOpenCodeMessageIndexes(db, openReadableOpenCodeDb, options
|
|
|
10075
10563
|
)
|
|
10076
10564
|
LIMIT 1`);
|
|
10077
10565
|
const eligibleSessionIds = missingSessionIds.filter((sessionId) => stillEligible.get(sessionId, cutoff));
|
|
10078
|
-
deleteSessionScopedRows(db, eligibleSessionIds, "opencode");
|
|
10079
|
-
deleted = eligibleSessionIds.length;
|
|
10566
|
+
deleted = deleteSessionScopedRows(db, eligibleSessionIds, "opencode");
|
|
10080
10567
|
persistMessageHistoryOrphanSweepState(db, nextCursor, completedAt);
|
|
10081
10568
|
db.exec("COMMIT");
|
|
10082
10569
|
committed = true;
|
|
@@ -10098,7 +10585,7 @@ function sweepOrphanedOpenCodeMessageIndexes(db, openReadableOpenCodeDb, options
|
|
|
10098
10585
|
}
|
|
10099
10586
|
}
|
|
10100
10587
|
// src/features/magic-context/project-docs-hash.ts
|
|
10101
|
-
import { createHash as
|
|
10588
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
10102
10589
|
import { lstatSync, readFileSync as readFileSync4, statSync as statSync3 } from "node:fs";
|
|
10103
10590
|
import path2 from "node:path";
|
|
10104
10591
|
var PROJECT_DOC_FILES = ["ARCHITECTURE.md", "STRUCTURE.md"];
|
|
@@ -10196,7 +10683,7 @@ function hashCanonicalPieces(hashPieces) {
|
|
|
10196
10683
|
if (hashPieces.length === 0) {
|
|
10197
10684
|
return "";
|
|
10198
10685
|
}
|
|
10199
|
-
return
|
|
10686
|
+
return createHash8("sha256").update(hashPieces.join(PROJECT_DOCS_DELIMITER), "utf8").digest("hex");
|
|
10200
10687
|
}
|
|
10201
10688
|
function readProjectDocsCanonical(projectDirectory) {
|
|
10202
10689
|
const canonicalDirectory = path2.resolve(projectDirectory);
|
|
@@ -10224,10 +10711,10 @@ function computeProjectDocsHash(projectDirectory) {
|
|
|
10224
10711
|
return readProjectDocsCanonical(projectDirectory).canonicalHash;
|
|
10225
10712
|
}
|
|
10226
10713
|
// src/features/magic-context/storage-embedding-measurements.ts
|
|
10227
|
-
import { createHash as
|
|
10714
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
10228
10715
|
function normalizedQueryHash(query) {
|
|
10229
10716
|
const normalized = query.trim().replace(/\s+/g, " ").toLowerCase();
|
|
10230
|
-
return
|
|
10717
|
+
return createHash9("sha256").update(normalized).digest("hex");
|
|
10231
10718
|
}
|
|
10232
10719
|
var MEASUREMENT_CORPUS_SESSION_ROW_CAP = 2000;
|
|
10233
10720
|
function recordEmbeddingMeasurement(db, input, cap = MEASUREMENT_CORPUS_SESSION_ROW_CAP) {
|
|
@@ -11569,6 +12056,29 @@ function removeStrippedPlaceholderId(db, sessionId, messageId) {
|
|
|
11569
12056
|
applyStrippedPlaceholderDelta(db, sessionId, { remove: [messageId] });
|
|
11570
12057
|
return true;
|
|
11571
12058
|
}
|
|
12059
|
+
var NEWEST_REASONING_BEARING_ASSISTANT = "newest_reasoning_bearing_assistant";
|
|
12060
|
+
var THINKING_BINDING_RECOVERY_FROZEN_PREFIX = "binding_mismatch:";
|
|
12061
|
+
function thinkingBindingRecoveryFrozenId(messageId) {
|
|
12062
|
+
return `${THINKING_BINDING_RECOVERY_FROZEN_PREFIX}${messageId}`;
|
|
12063
|
+
}
|
|
12064
|
+
function getThinkingBindingRecoveryTarget(db, sessionId) {
|
|
12065
|
+
const row = db.prepare("SELECT thinking_binding_recovery_target FROM session_meta WHERE session_id = ?").get(sessionId);
|
|
12066
|
+
const target = row?.thinking_binding_recovery_target;
|
|
12067
|
+
return typeof target === "string" && target.length > 0 ? target : null;
|
|
12068
|
+
}
|
|
12069
|
+
function armThinkingBindingRecovery(db, sessionId, messageId) {
|
|
12070
|
+
ensureSessionMetaRow(db, sessionId);
|
|
12071
|
+
const target = typeof messageId === "string" && messageId.length > 0 ? messageId : NEWEST_REASONING_BEARING_ASSISTANT;
|
|
12072
|
+
if (target === NEWEST_REASONING_BEARING_ASSISTANT) {
|
|
12073
|
+
db.prepare("UPDATE session_meta SET thinking_binding_recovery_target = ? WHERE session_id = ? AND COALESCE(thinking_binding_recovery_target, '') = ''").run(target, sessionId);
|
|
12074
|
+
return;
|
|
12075
|
+
}
|
|
12076
|
+
db.prepare("UPDATE session_meta SET thinking_binding_recovery_target = ? WHERE session_id = ?").run(target, sessionId);
|
|
12077
|
+
}
|
|
12078
|
+
function clearThinkingBindingRecoveryIf(db, sessionId, expectedTarget) {
|
|
12079
|
+
const result = db.prepare("UPDATE session_meta SET thinking_binding_recovery_target = '' WHERE session_id = ? AND thinking_binding_recovery_target = ?").run(sessionId, expectedTarget);
|
|
12080
|
+
return result.changes > 0;
|
|
12081
|
+
}
|
|
11572
12082
|
function getMergedReasoningStrippedIds(db, sessionId) {
|
|
11573
12083
|
const row = db.prepare("SELECT merged_reasoning_stripped_ids FROM session_meta WHERE session_id = ?").get(sessionId);
|
|
11574
12084
|
return new Set(parseStrippedBlob(row?.merged_reasoning_stripped_ids));
|
|
@@ -11644,7 +12154,7 @@ function addTrailingBlankDecisions(db, sessionId, additions, options) {
|
|
|
11644
12154
|
let changed = false;
|
|
11645
12155
|
for (const [id, decision] of add) {
|
|
11646
12156
|
const currentDecision = current.get(id);
|
|
11647
|
-
if (currentDecision === undefined || id === options?.overwriteMessageId && currentDecision !== decision) {
|
|
12157
|
+
if (currentDecision === undefined || id === options?.overwriteMessageId && currentDecision !== decision && currentDecision !== "strip") {
|
|
11648
12158
|
current.set(id, decision);
|
|
11649
12159
|
changed = true;
|
|
11650
12160
|
}
|
|
@@ -12618,7 +13128,7 @@ function readUint32BE(b, offset) {
|
|
|
12618
13128
|
}
|
|
12619
13129
|
|
|
12620
13130
|
// src/hooks/magic-context/todo-view.ts
|
|
12621
|
-
import { createHash as
|
|
13131
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
12622
13132
|
var TODO_STATUS_PENDING = "pending";
|
|
12623
13133
|
var TODO_STATUS_IN_PROGRESS = "in_progress";
|
|
12624
13134
|
var TODO_STATUS_COMPLETED = "completed";
|
|
@@ -12686,7 +13196,7 @@ function buildSyntheticTodoPart(stateJson) {
|
|
|
12686
13196
|
};
|
|
12687
13197
|
}
|
|
12688
13198
|
function computeSyntheticCallId(stateJson) {
|
|
12689
|
-
const hash =
|
|
13199
|
+
const hash = createHash10("sha256").update(stateJson).digest("hex").slice(0, 16);
|
|
12690
13200
|
return `${SYNTHETIC_CALL_ID_PREFIX}${hash}`;
|
|
12691
13201
|
}
|
|
12692
13202
|
function isSyntheticTodoPart(part) {
|
|
@@ -13638,7 +14148,10 @@ var getTagNumbersByMessageIdStatements = new WeakMap;
|
|
|
13638
14148
|
var deleteTagsByMessageIdStatements = new WeakMap;
|
|
13639
14149
|
var getMaxTagNumberBySessionStatements = new WeakMap;
|
|
13640
14150
|
var getTagNumberByMessageIdStatements = new WeakMap;
|
|
14151
|
+
var getAssignableTagNumberByMessageIdStatements = new WeakMap;
|
|
13641
14152
|
var hasPiFallbackMessageTagStatements = new WeakMap;
|
|
14153
|
+
var WHITESPACE_ASSISTANT_INERT_MESSAGE_PREFIX = "__mc_whitespace_assistant_inert__:";
|
|
14154
|
+
var WHITESPACE_ASSISTANT_INERT_FINGERPRINT_PREFIX = "mc:whitespace-assistant:";
|
|
13642
14155
|
function getInsertTagStatement(db) {
|
|
13643
14156
|
let stmt = insertTagStatements.get(db);
|
|
13644
14157
|
if (!stmt) {
|
|
@@ -13858,7 +14371,10 @@ function backfillTagTokenCounts(db, sessionId, tagNumber, counts) {
|
|
|
13858
14371
|
function getUpdateTagMessageIdStatement(db) {
|
|
13859
14372
|
let stmt = updateTagMessageIdStatements.get(db);
|
|
13860
14373
|
if (!stmt) {
|
|
13861
|
-
stmt = db.prepare(
|
|
14374
|
+
stmt = db.prepare(`UPDATE tags SET message_id = ?
|
|
14375
|
+
WHERE session_id = ?
|
|
14376
|
+
AND tag_number = ?
|
|
14377
|
+
AND message_id NOT LIKE '${WHITESPACE_ASSISTANT_INERT_MESSAGE_PREFIX}%'`);
|
|
13862
14378
|
updateTagMessageIdStatements.set(db, stmt);
|
|
13863
14379
|
}
|
|
13864
14380
|
return stmt;
|
|
@@ -13895,6 +14411,25 @@ function getTagNumberByMessageIdStatement(db) {
|
|
|
13895
14411
|
}
|
|
13896
14412
|
return stmt;
|
|
13897
14413
|
}
|
|
14414
|
+
function getAssignableTagNumberByMessageIdStatement(db) {
|
|
14415
|
+
let stmt = getAssignableTagNumberByMessageIdStatements.get(db);
|
|
14416
|
+
if (!stmt) {
|
|
14417
|
+
stmt = db.prepare(`SELECT tag_number FROM tags
|
|
14418
|
+
WHERE session_id = ?
|
|
14419
|
+
AND message_id = ?
|
|
14420
|
+
AND NOT (
|
|
14421
|
+
status = 'compacted'
|
|
14422
|
+
AND COALESCE(
|
|
14423
|
+
entry_fingerprint LIKE '${WHITESPACE_ASSISTANT_INERT_FINGERPRINT_PREFIX}%',
|
|
14424
|
+
0
|
|
14425
|
+
) = 1
|
|
14426
|
+
)
|
|
14427
|
+
ORDER BY tag_number ASC
|
|
14428
|
+
LIMIT 1`);
|
|
14429
|
+
getAssignableTagNumberByMessageIdStatements.set(db, stmt);
|
|
14430
|
+
}
|
|
14431
|
+
return stmt;
|
|
14432
|
+
}
|
|
13898
14433
|
function isTagRow(row) {
|
|
13899
14434
|
if (row === null || typeof row !== "object")
|
|
13900
14435
|
return false;
|
|
@@ -13941,6 +14476,25 @@ function insertTag(db, sessionId, messageId, type, byteSize2, tagNumber, reasoni
|
|
|
13941
14476
|
function updateTagStatus(db, sessionId, tagId, status) {
|
|
13942
14477
|
getUpdateTagStatusStatement(db).run(status, sessionId, tagId);
|
|
13943
14478
|
}
|
|
14479
|
+
function markWhitespaceAssistantTagInert(db, sessionId, tagNumber, contentId) {
|
|
14480
|
+
db.prepare(`UPDATE tags
|
|
14481
|
+
SET status = 'compacted',
|
|
14482
|
+
message_id = ?,
|
|
14483
|
+
entry_fingerprint = ?
|
|
14484
|
+
WHERE session_id = ? AND tag_number = ? AND type = 'message'`).run(`${WHITESPACE_ASSISTANT_INERT_MESSAGE_PREFIX}${tagNumber}`, `${WHITESPACE_ASSISTANT_INERT_FINGERPRINT_PREFIX}${contentId}`, sessionId, tagNumber);
|
|
14485
|
+
}
|
|
14486
|
+
function getInertWhitespaceAssistantTags(db, sessionId) {
|
|
14487
|
+
const rows = db.prepare(`SELECT tag_number AS tagNumber, entry_fingerprint AS entryFingerprint
|
|
14488
|
+
FROM tags
|
|
14489
|
+
WHERE session_id = ?
|
|
14490
|
+
AND type = 'message'
|
|
14491
|
+
AND status = 'compacted'
|
|
14492
|
+
AND entry_fingerprint LIKE ?`).all(sessionId, `${WHITESPACE_ASSISTANT_INERT_FINGERPRINT_PREFIX}%`);
|
|
14493
|
+
return rows.flatMap((row) => {
|
|
14494
|
+
const contentId = row.entryFingerprint.slice(WHITESPACE_ASSISTANT_INERT_FINGERPRINT_PREFIX.length);
|
|
14495
|
+
return contentId.length > 0 ? [{ tagNumber: row.tagNumber, contentId }] : [];
|
|
14496
|
+
});
|
|
14497
|
+
}
|
|
13944
14498
|
function updateTagDropMode(db, sessionId, tagNumber, dropMode) {
|
|
13945
14499
|
getUpdateTagDropModeStatement(db).run(dropMode, sessionId, tagNumber);
|
|
13946
14500
|
}
|
|
@@ -13988,6 +14542,10 @@ function getTagNumberByMessageId(db, sessionId, messageId) {
|
|
|
13988
14542
|
const row = getTagNumberByMessageIdStatement(db).get(sessionId, messageId);
|
|
13989
14543
|
return isTagNumberRow(row) ? row.tag_number : null;
|
|
13990
14544
|
}
|
|
14545
|
+
function getAssignableTagNumberByMessageId(db, sessionId, messageId) {
|
|
14546
|
+
const row = getAssignableTagNumberByMessageIdStatement(db).get(sessionId, messageId);
|
|
14547
|
+
return isTagNumberRow(row) ? row.tag_number : null;
|
|
14548
|
+
}
|
|
13991
14549
|
var getMinMessageTagNumberForRawIdStatements = new WeakMap;
|
|
13992
14550
|
function isMinTagNumberRow(row) {
|
|
13993
14551
|
return row !== null && typeof row === "object" && "m" in row;
|
|
@@ -14111,6 +14669,13 @@ function getMaxDroppedTagNumber(db, sessionId) {
|
|
|
14111
14669
|
const row = getMaxDroppedTagNumberStatement(db).get(sessionId);
|
|
14112
14670
|
return isMaxTagNumberRow(row) ? row.max_tag_number : 0;
|
|
14113
14671
|
}
|
|
14672
|
+
function getTagById(db, sessionId, tagId) {
|
|
14673
|
+
const result = db.prepare(`SELECT ${TAG_SELECT_COLUMNS} FROM tags WHERE session_id = ? AND tag_number = ?`).get(sessionId, tagId);
|
|
14674
|
+
if (!isTagRow(result)) {
|
|
14675
|
+
return null;
|
|
14676
|
+
}
|
|
14677
|
+
return toTagEntry(result);
|
|
14678
|
+
}
|
|
14114
14679
|
var getToolTagNumberByOwnerStatements = new WeakMap;
|
|
14115
14680
|
var getNullOwnerToolTagStatements = new WeakMap;
|
|
14116
14681
|
var adoptNullOwnerToolTagStatements = new WeakMap;
|
|
@@ -14317,6 +14882,7 @@ var LIMIT_EXTRACTION_PATTERNS = [
|
|
|
14317
14882
|
];
|
|
14318
14883
|
var MIN_PLAUSIBLE_LIMIT = 1024;
|
|
14319
14884
|
var MAX_PLAUSIBLE_LIMIT = 1e7;
|
|
14885
|
+
var THINKING_BINDING_MISMATCH_PATTERN = /bound to a different conversation/i;
|
|
14320
14886
|
function extractErrorMessage(error) {
|
|
14321
14887
|
if (!error)
|
|
14322
14888
|
return "";
|
|
@@ -14345,6 +14911,70 @@ function extractErrorMessage(error) {
|
|
|
14345
14911
|
}
|
|
14346
14912
|
return String(error);
|
|
14347
14913
|
}
|
|
14914
|
+
function extractThinkingBindingMessageId(error) {
|
|
14915
|
+
if (!error || typeof error !== "object")
|
|
14916
|
+
return;
|
|
14917
|
+
const seen = new Set;
|
|
14918
|
+
const queue = [error];
|
|
14919
|
+
while (queue.length > 0) {
|
|
14920
|
+
const current = queue.shift();
|
|
14921
|
+
if (!current || seen.has(current))
|
|
14922
|
+
continue;
|
|
14923
|
+
seen.add(current);
|
|
14924
|
+
const record = current;
|
|
14925
|
+
for (const key of ["message_id", "messageID", "messageId"]) {
|
|
14926
|
+
const value = record[key];
|
|
14927
|
+
if (typeof value === "string" && value.length > 0)
|
|
14928
|
+
return value;
|
|
14929
|
+
}
|
|
14930
|
+
for (const value of Object.values(record)) {
|
|
14931
|
+
if (value && typeof value === "object")
|
|
14932
|
+
queue.push(value);
|
|
14933
|
+
}
|
|
14934
|
+
}
|
|
14935
|
+
return;
|
|
14936
|
+
}
|
|
14937
|
+
function extractExplicitHttpStatus(error) {
|
|
14938
|
+
if (!error || typeof error !== "object")
|
|
14939
|
+
return;
|
|
14940
|
+
const seen = new Set;
|
|
14941
|
+
const queue = [error];
|
|
14942
|
+
while (queue.length > 0) {
|
|
14943
|
+
const current = queue.shift();
|
|
14944
|
+
if (!current || seen.has(current))
|
|
14945
|
+
continue;
|
|
14946
|
+
seen.add(current);
|
|
14947
|
+
const record = current;
|
|
14948
|
+
for (const key of ["status", "statusCode", "status_code"]) {
|
|
14949
|
+
const value = record[key];
|
|
14950
|
+
if (typeof value === "number")
|
|
14951
|
+
return value;
|
|
14952
|
+
}
|
|
14953
|
+
for (const value of Object.values(record)) {
|
|
14954
|
+
if (value && typeof value === "object")
|
|
14955
|
+
queue.push(value);
|
|
14956
|
+
}
|
|
14957
|
+
}
|
|
14958
|
+
return;
|
|
14959
|
+
}
|
|
14960
|
+
function detectThinkingBindingMismatch(error) {
|
|
14961
|
+
const message = extractErrorMessage(error);
|
|
14962
|
+
const explicitStatus = extractExplicitHttpStatus(error);
|
|
14963
|
+
if (explicitStatus !== undefined && explicitStatus !== 400 || !THINKING_BINDING_MISMATCH_PATTERN.test(message)) {
|
|
14964
|
+
return { isBindingMismatch: false };
|
|
14965
|
+
}
|
|
14966
|
+
const messageId = extractThinkingBindingMessageId(error);
|
|
14967
|
+
return {
|
|
14968
|
+
isBindingMismatch: true,
|
|
14969
|
+
matchedPattern: "bound to a different conversation",
|
|
14970
|
+
...messageId ? { messageId } : {}
|
|
14971
|
+
};
|
|
14972
|
+
}
|
|
14973
|
+
function isFable51ThinkingBindingModel(providerID, modelID) {
|
|
14974
|
+
if (providerID?.toLowerCase() !== "anthropic" || !modelID)
|
|
14975
|
+
return false;
|
|
14976
|
+
return /(?:^|[-_.])fable[-_.]?5[-_.]1(?:$|[-_.])/i.test(modelID);
|
|
14977
|
+
}
|
|
14348
14978
|
function detectOverflow(error) {
|
|
14349
14979
|
const message = extractErrorMessage(error);
|
|
14350
14980
|
if (!message) {
|
|
@@ -15523,9 +16153,9 @@ function parseUserMemoryRow(row) {
|
|
|
15523
16153
|
}
|
|
15524
16154
|
|
|
15525
16155
|
// src/features/magic-context/mural/storage-mural-cues.ts
|
|
15526
|
-
import { createHash as
|
|
16156
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
15527
16157
|
function computeCueContentHash(content) {
|
|
15528
|
-
return
|
|
16158
|
+
return createHash11("sha256").update(content).digest("hex");
|
|
15529
16159
|
}
|
|
15530
16160
|
var muralCueColumnCache = new WeakMap;
|
|
15531
16161
|
var muralCueRejectionColumnCache = new WeakMap;
|
|
@@ -15723,13 +16353,13 @@ function invalidateMemory(projectPath, memoryId) {
|
|
|
15723
16353
|
}
|
|
15724
16354
|
|
|
15725
16355
|
// src/features/magic-context/memory/normalize-hash.ts
|
|
15726
|
-
import { createHash as
|
|
16356
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
15727
16357
|
function normalizeMemoryContent(content) {
|
|
15728
16358
|
return content.toLowerCase().replace(/\s+/g, " ").trim();
|
|
15729
16359
|
}
|
|
15730
16360
|
function computeNormalizedHash(content) {
|
|
15731
16361
|
const normalized = normalizeMemoryContent(content);
|
|
15732
|
-
return
|
|
16362
|
+
return createHash12("md5").update(normalized).digest("hex");
|
|
15733
16363
|
}
|
|
15734
16364
|
|
|
15735
16365
|
// src/features/magic-context/memory/visibility.ts
|
|
@@ -16702,7 +17332,7 @@ async function runMemoryMigration(deps) {
|
|
|
16702
17332
|
}
|
|
16703
17333
|
|
|
16704
17334
|
// src/features/magic-context/compartment-chunk-embedding.ts
|
|
16705
|
-
import { createHash as
|
|
17335
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
16706
17336
|
|
|
16707
17337
|
// src/features/magic-context/recursive-text-splitter.ts
|
|
16708
17338
|
var DEFAULT_SEPARATORS = [`
|
|
@@ -16792,6 +17422,14 @@ function recursiveCharacterSplit(text, options) {
|
|
|
16792
17422
|
// src/features/magic-context/compartment-chunk-embedding.ts
|
|
16793
17423
|
var DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS = 512;
|
|
16794
17424
|
var CHUNK_WINDOW_SAFETY_RATIO = 0.9;
|
|
17425
|
+
var MESSAGE_FTS_CHUNK_LOAD_SQL = `SELECT map.message_ordinal AS messageOrdinal, fts.role, fts.content
|
|
17426
|
+
FROM message_fts_rowid_map AS map
|
|
17427
|
+
CROSS JOIN message_history_fts AS fts
|
|
17428
|
+
ON fts.rowid = map.fts_rowid
|
|
17429
|
+
WHERE map.session_id = ?
|
|
17430
|
+
AND map.message_ordinal BETWEEN ? AND ?
|
|
17431
|
+
AND fts.role IN ('user', 'assistant')
|
|
17432
|
+
ORDER BY map.message_ordinal ASC`;
|
|
16795
17433
|
var loadFtsRowsStatements = new WeakMap;
|
|
16796
17434
|
var existingHashStatements = new WeakMap;
|
|
16797
17435
|
var existingHashByProjectStatements = new WeakMap;
|
|
@@ -16808,13 +17446,7 @@ var decodedSearchPoolBytes = 0;
|
|
|
16808
17446
|
function getLoadFtsRowsStatement(db) {
|
|
16809
17447
|
let stmt = loadFtsRowsStatements.get(db);
|
|
16810
17448
|
if (!stmt) {
|
|
16811
|
-
stmt = db.prepare(
|
|
16812
|
-
FROM message_history_fts
|
|
16813
|
-
WHERE session_id = ?
|
|
16814
|
-
AND message_ordinal >= ?
|
|
16815
|
-
AND message_ordinal <= ?
|
|
16816
|
-
AND role IN ('user', 'assistant')
|
|
16817
|
-
ORDER BY message_ordinal ASC`);
|
|
17449
|
+
stmt = db.prepare(MESSAGE_FTS_CHUNK_LOAD_SQL);
|
|
16818
17450
|
loadFtsRowsStatements.set(db, stmt);
|
|
16819
17451
|
}
|
|
16820
17452
|
return stmt;
|
|
@@ -16987,7 +17619,7 @@ function parseCanonicalLineRange(line) {
|
|
|
16987
17619
|
return { start, end };
|
|
16988
17620
|
}
|
|
16989
17621
|
function hashChunkText(text) {
|
|
16990
|
-
return
|
|
17622
|
+
return createHash13("sha256").update(text).digest("hex");
|
|
16991
17623
|
}
|
|
16992
17624
|
function vectorBlob2(vector) {
|
|
16993
17625
|
return new Uint8Array(vector.buffer, vector.byteOffset, vector.byteLength);
|
|
@@ -17002,6 +17634,8 @@ function toFloat32Array2(blob) {
|
|
|
17002
17634
|
function buildCanonicalChunkTextFromFts(db, sessionId, startOrdinal, endOrdinal) {
|
|
17003
17635
|
if (endOrdinal < startOrdinal)
|
|
17004
17636
|
return "";
|
|
17637
|
+
if (!messageFtsOrdinalRangeIsMapped(db, sessionId, startOrdinal, endOrdinal))
|
|
17638
|
+
return null;
|
|
17005
17639
|
const rows = getLoadFtsRowsStatement(db).all(sessionId, startOrdinal, endOrdinal).map((row) => row);
|
|
17006
17640
|
const lines = [];
|
|
17007
17641
|
let current = null;
|
|
@@ -17277,7 +17911,10 @@ function mapBackfillCandidateRows(rows) {
|
|
|
17277
17911
|
}));
|
|
17278
17912
|
}
|
|
17279
17913
|
function classifyChunkCoverageDefect(db, projectPath, modelId, candidate, maxInputTokens) {
|
|
17280
|
-
const
|
|
17914
|
+
const mappedText = buildCanonicalChunkTextFromFts(db, candidate.sessionId, candidate.startMessage, candidate.endMessage);
|
|
17915
|
+
if (mappedText === null)
|
|
17916
|
+
return "deferred";
|
|
17917
|
+
const canonicalText = mappedText || buildCompartmentSummaryFallbackText(db, candidate.id);
|
|
17281
17918
|
const windows = chunkCanonicalText(canonicalText, candidate.startMessage, candidate.endMessage, maxInputTokens);
|
|
17282
17919
|
const existing = getExistingChunkHashes(db, candidate.id, modelId, projectPath);
|
|
17283
17920
|
if (windows.some((window) => !existing.has(window.windowIndex)))
|
|
@@ -17370,7 +18007,7 @@ function countSessionCompartmentEmbedCoverage(db, projectPath, sessionId, modelI
|
|
|
17370
18007
|
}
|
|
17371
18008
|
|
|
17372
18009
|
// src/features/magic-context/project-embedding-registry.ts
|
|
17373
|
-
import { createHash as
|
|
18010
|
+
import { createHash as createHash15, randomUUID as randomUUID2 } from "node:crypto";
|
|
17374
18011
|
|
|
17375
18012
|
// src/config/schema/magic-context.ts
|
|
17376
18013
|
import { homedir as homedir4 } from "node:os";
|
|
@@ -32581,6 +33218,82 @@ function releaseGitSweepLease(db, projectPath, holderId) {
|
|
|
32581
33218
|
}
|
|
32582
33219
|
|
|
32583
33220
|
// src/features/magic-context/memory/embedding-failure.ts
|
|
33221
|
+
function errorMessage(error51) {
|
|
33222
|
+
return error51 instanceof Error ? error51.message : String(error51 ?? "unknown error");
|
|
33223
|
+
}
|
|
33224
|
+
function nestedMessages(error51) {
|
|
33225
|
+
const messages = [errorMessage(error51)];
|
|
33226
|
+
if (error51 && typeof error51 === "object" && "cause" in error51) {
|
|
33227
|
+
const cause = error51.cause;
|
|
33228
|
+
if (cause !== undefined)
|
|
33229
|
+
messages.push(...nestedMessages(cause));
|
|
33230
|
+
}
|
|
33231
|
+
return messages;
|
|
33232
|
+
}
|
|
33233
|
+
function safeErrorDetail(message) {
|
|
33234
|
+
return message.replace(/https?:\/\/[^\s"']+/gi, "<remote URL>").replace(/\/(?:Users|home)\/[^/\s]+/g, "~").replace(/\s+/g, " ").trim().slice(0, 240);
|
|
33235
|
+
}
|
|
33236
|
+
function hasAny(messages, patterns) {
|
|
33237
|
+
return messages.some((message) => {
|
|
33238
|
+
const lower = message.toLowerCase();
|
|
33239
|
+
return patterns.some((pattern) => lower.includes(pattern));
|
|
33240
|
+
});
|
|
33241
|
+
}
|
|
33242
|
+
function classifyLocalEmbeddingFailure(error51, context = {}) {
|
|
33243
|
+
const primaryMessages = nestedMessages(error51);
|
|
33244
|
+
const nativeMessages = context.nativeError === undefined ? [] : nestedMessages(context.nativeError);
|
|
33245
|
+
if (hasAny(primaryMessages, [
|
|
33246
|
+
"mc_embedding_fs_unavailable",
|
|
33247
|
+
"file system cache is not available"
|
|
33248
|
+
]) || context.usesWasm && hasAny(primaryMessages, ["unable to get model file path or buffer"])) {
|
|
33249
|
+
return {
|
|
33250
|
+
class: "local_fs_unavailable",
|
|
33251
|
+
reason: "the WASM model cache cannot access the Node filesystem",
|
|
33252
|
+
retryable: false
|
|
33253
|
+
};
|
|
33254
|
+
}
|
|
33255
|
+
if (hasAny(primaryMessages, [
|
|
33256
|
+
"failed to fetch",
|
|
33257
|
+
"fetch failed",
|
|
33258
|
+
"network error",
|
|
33259
|
+
"enotfound",
|
|
33260
|
+
"econnreset",
|
|
33261
|
+
"econnrefused",
|
|
33262
|
+
"certificate",
|
|
33263
|
+
"unable to load file",
|
|
33264
|
+
"unauthorized access to file",
|
|
33265
|
+
"forbidden access to file",
|
|
33266
|
+
"not found at"
|
|
33267
|
+
]) || primaryMessages.some((message) => /\bHTTP\s+[45]\d\d\b/i.test(message))) {
|
|
33268
|
+
return {
|
|
33269
|
+
class: "local_download_failure",
|
|
33270
|
+
reason: `the embedding model download failed: ${safeErrorDetail(primaryMessages[0])}`,
|
|
33271
|
+
retryable: true
|
|
33272
|
+
};
|
|
33273
|
+
}
|
|
33274
|
+
const bindingMessages = [...primaryMessages, ...nativeMessages];
|
|
33275
|
+
if (hasAny(bindingMessages, [
|
|
33276
|
+
"onnxruntime_binding.node",
|
|
33277
|
+
"cannot find package 'onnxruntime-node'",
|
|
33278
|
+
'cannot find package "onnxruntime-node"',
|
|
33279
|
+
"cannot find module 'onnxruntime-node'",
|
|
33280
|
+
'cannot find module "onnxruntime-node"',
|
|
33281
|
+
"could not resolve: onnxruntime-node"
|
|
33282
|
+
])) {
|
|
33283
|
+
const platform = context.platform ?? process.platform;
|
|
33284
|
+
const arch = context.arch ?? process.arch;
|
|
33285
|
+
return {
|
|
33286
|
+
class: "local_binding_missing",
|
|
33287
|
+
reason: platform === "darwin" && arch === "x64" ? "onnxruntime-node has no darwin/x64 native binding and the WASM fallback could not complete" : `onnxruntime-node has no usable native binding for ${platform}/${arch} and the WASM fallback could not complete`,
|
|
33288
|
+
retryable: false
|
|
33289
|
+
};
|
|
33290
|
+
}
|
|
33291
|
+
return {
|
|
33292
|
+
class: "local_runtime_error",
|
|
33293
|
+
reason: `the local embedding runtime failed: ${safeErrorDetail(primaryMessages[0])}`,
|
|
33294
|
+
retryable: false
|
|
33295
|
+
};
|
|
33296
|
+
}
|
|
32584
33297
|
function dominantEmbeddingFailure(failures) {
|
|
32585
33298
|
const counts = new Map;
|
|
32586
33299
|
for (const failure of failures) {
|
|
@@ -32600,7 +33313,7 @@ function dominantEmbeddingFailure(failures) {
|
|
|
32600
33313
|
}
|
|
32601
33314
|
|
|
32602
33315
|
// src/features/magic-context/memory/embedding-synapse.ts
|
|
32603
|
-
import { createHash as
|
|
33316
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
32604
33317
|
|
|
32605
33318
|
// ../../node_modules/.bun/@cortexkit+subc-client@0.4.1/node_modules/@cortexkit/subc-client/dist/client.js
|
|
32606
33319
|
import { promises as fs2 } from "node:fs";
|
|
@@ -34081,7 +34794,7 @@ function wait(ms) {
|
|
|
34081
34794
|
return new Promise((resolve4) => setTimeout(resolve4, ms));
|
|
34082
34795
|
}
|
|
34083
34796
|
function sha256(value) {
|
|
34084
|
-
return
|
|
34797
|
+
return createHash14("sha256").update(value).digest("hex");
|
|
34085
34798
|
}
|
|
34086
34799
|
function stableJson(value) {
|
|
34087
34800
|
if (Array.isArray(value))
|
|
@@ -34567,11 +35280,13 @@ import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
|
34567
35280
|
var BUN_NAPI_TEARDOWN_FIX_VERSION = [1, 4, 0];
|
|
34568
35281
|
function currentLocalEmbeddingHost() {
|
|
34569
35282
|
const bun = globalThis.Bun;
|
|
34570
|
-
const
|
|
35283
|
+
const hasProcess = typeof process !== "undefined";
|
|
35284
|
+
const bunVersion = hasProcess && typeof process.versions?.bun === "string" ? process.versions.bun : undefined;
|
|
34571
35285
|
return {
|
|
34572
|
-
isElectron:
|
|
35286
|
+
isElectron: hasProcess && Boolean(process.versions?.electron),
|
|
34573
35287
|
isBun: Boolean(bun) || Boolean(bunVersion),
|
|
34574
|
-
bunVersion
|
|
35288
|
+
bunVersion,
|
|
35289
|
+
hasNodeFilesystem: hasProcess && (typeof process.versions?.node === "string" || typeof bunVersion === "string")
|
|
34575
35290
|
};
|
|
34576
35291
|
}
|
|
34577
35292
|
function bunHasNapiTeardownFix(version2) {
|
|
@@ -34642,6 +35357,7 @@ function startLockHeartbeat(lockPath) {
|
|
|
34642
35357
|
return () => clearInterval(timer);
|
|
34643
35358
|
}
|
|
34644
35359
|
var localEmbeddingRuntimeMode = "native";
|
|
35360
|
+
var localEmbeddingProcessFailure = null;
|
|
34645
35361
|
var wasmRuntimeInjected = false;
|
|
34646
35362
|
var localEmbeddingHostForRuntime = currentLocalEmbeddingHost;
|
|
34647
35363
|
var importWasmOrtForRuntime = async () => {
|
|
@@ -34660,6 +35376,10 @@ var importTransformersWasmFallbackForRuntime = async () => {
|
|
|
34660
35376
|
const webEntry = new URL("./transformers-web.js", import.meta.url).href;
|
|
34661
35377
|
return await import(webEntry);
|
|
34662
35378
|
};
|
|
35379
|
+
var importTransformersNodeWasmFallbackForRuntime = async () => {
|
|
35380
|
+
const nodeWasmEntry = new URL("./transformers-node-wasm.js", import.meta.url).href;
|
|
35381
|
+
return await import(nodeWasmEntry);
|
|
35382
|
+
};
|
|
34663
35383
|
var modelCacheDirForRuntime = () => join6(getMagicContextStorageDir(), "models");
|
|
34664
35384
|
var logForRuntime = log;
|
|
34665
35385
|
var injectWasmOrtForRuntime = injectWasmOrt;
|
|
@@ -34700,9 +35420,35 @@ function likelyMuslHint() {
|
|
|
34700
35420
|
function localEmbeddingRuntimeIsDisabled() {
|
|
34701
35421
|
return localEmbeddingRuntimeMode === "disabled";
|
|
34702
35422
|
}
|
|
35423
|
+
|
|
35424
|
+
class LocalEmbeddingFallbackError extends Error {
|
|
35425
|
+
nativeError;
|
|
35426
|
+
constructor(nativeError, wasmError) {
|
|
35427
|
+
super("the native local embedding runtime and its WASM fallback both failed", {
|
|
35428
|
+
cause: wasmError
|
|
35429
|
+
});
|
|
35430
|
+
this.name = "LocalEmbeddingFallbackError";
|
|
35431
|
+
this.nativeError = nativeError;
|
|
35432
|
+
}
|
|
35433
|
+
}
|
|
35434
|
+
|
|
35435
|
+
class LocalEmbeddingFsUnavailableError extends Error {
|
|
35436
|
+
code = "MC_EMBEDDING_FS_UNAVAILABLE";
|
|
35437
|
+
constructor() {
|
|
35438
|
+
super("MC_EMBEDDING_FS_UNAVAILABLE: Node WASM bundle has no filesystem cache");
|
|
35439
|
+
this.name = "LocalEmbeddingFsUnavailableError";
|
|
35440
|
+
}
|
|
35441
|
+
}
|
|
35442
|
+
async function importWasmTransformersForHost() {
|
|
35443
|
+
const host = localEmbeddingHostForRuntime();
|
|
35444
|
+
if (host.isElectron) {
|
|
35445
|
+
return importTransformersForRuntime();
|
|
35446
|
+
}
|
|
35447
|
+
return host.hasNodeFilesystem ? importTransformersNodeWasmFallbackForRuntime() : importTransformersWasmFallbackForRuntime();
|
|
35448
|
+
}
|
|
34703
35449
|
function disableLocalEmbeddingsAfterRuntimeFailure(detail) {
|
|
34704
35450
|
localEmbeddingRuntimeMode = "disabled";
|
|
34705
|
-
logForRuntime(`[magic-context] local embeddings are disabled because both the onnxruntime-node native binding and the onnxruntime-web (WASM) fallback failed to load. Native failure: ${detail}. Run \`npx @cortexkit/magic-context@latest doctor\` for
|
|
35451
|
+
logForRuntime(`[magic-context] local embeddings are disabled because both the onnxruntime-node native binding and the onnxruntime-web (WASM) fallback failed to load. Native failure: ${detail}. Run \`npx @cortexkit/magic-context@latest doctor\` for diagnostics; reinstalling repairs missing package files but cannot add a native binding that upstream does not ship. Alternatively, configure an \`openai-compatible\` embedding HTTP endpoint. Existing memories are unaffected.`);
|
|
34706
35452
|
}
|
|
34707
35453
|
async function loadTransformersForLocalEmbedding(runtimePreference) {
|
|
34708
35454
|
if (localEmbeddingRuntimeMode === "disabled") {
|
|
@@ -34714,7 +35460,7 @@ async function loadTransformersForLocalEmbedding(runtimePreference) {
|
|
|
34714
35460
|
disableLocalEmbeddingsAfterRuntimeFailure("the selected WASM runtime is unavailable");
|
|
34715
35461
|
throw new Error("onnxruntime-web failed to load");
|
|
34716
35462
|
}
|
|
34717
|
-
return { module: await
|
|
35463
|
+
return { module: await importWasmTransformersForHost(), usesWasm: true };
|
|
34718
35464
|
}
|
|
34719
35465
|
if (localEmbeddingRuntimeMode === "wasm") {
|
|
34720
35466
|
if (!await ensureWasmOrtInjected()) {
|
|
@@ -34722,7 +35468,7 @@ async function loadTransformersForLocalEmbedding(runtimePreference) {
|
|
|
34722
35468
|
throw new Error("onnxruntime-web failed to load");
|
|
34723
35469
|
}
|
|
34724
35470
|
try {
|
|
34725
|
-
return { module: await
|
|
35471
|
+
return { module: await importWasmTransformersForHost(), usesWasm: true };
|
|
34726
35472
|
} catch (wasmError) {
|
|
34727
35473
|
disableLocalEmbeddingsAfterRuntimeFailure("the previously selected WASM runtime failed to load");
|
|
34728
35474
|
throw wasmError;
|
|
@@ -34750,12 +35496,12 @@ async function loadTransformersForLocalEmbedding(runtimePreference) {
|
|
|
34750
35496
|
}
|
|
34751
35497
|
localEmbeddingRuntimeMode = "wasm";
|
|
34752
35498
|
try {
|
|
34753
|
-
const module = await
|
|
35499
|
+
const module = await importWasmTransformersForHost();
|
|
34754
35500
|
logForRuntime("[magic-context] onnxruntime-node failed to load; using onnxruntime-web (WASM) for local embeddings. WASM inference is slower than native; a remote `openai-compatible` provider may be faster." + likelyMuslHint());
|
|
34755
35501
|
return { module, usesWasm: true };
|
|
34756
35502
|
} catch (wasmError) {
|
|
34757
35503
|
disableLocalEmbeddingsAfterRuntimeFailure(nativeError instanceof Error ? nativeError.message : String(nativeError));
|
|
34758
|
-
throw wasmError;
|
|
35504
|
+
throw new LocalEmbeddingFallbackError(nativeError, wasmError);
|
|
34759
35505
|
}
|
|
34760
35506
|
}
|
|
34761
35507
|
}
|
|
@@ -34841,6 +35587,8 @@ class LocalEmbeddingProvider {
|
|
|
34841
35587
|
runtimePreference;
|
|
34842
35588
|
pipeline = null;
|
|
34843
35589
|
initPromise = null;
|
|
35590
|
+
lastFailureReason = null;
|
|
35591
|
+
usesWasm = false;
|
|
34844
35592
|
inFlight = 0;
|
|
34845
35593
|
disposing = false;
|
|
34846
35594
|
disposePromise = null;
|
|
@@ -34865,6 +35613,7 @@ class LocalEmbeddingProvider {
|
|
|
34865
35613
|
return true;
|
|
34866
35614
|
}
|
|
34867
35615
|
if (localEmbeddingRuntimeMode === "disabled") {
|
|
35616
|
+
this.lastFailureReason = localEmbeddingProcessFailure ?? classifyLocalEmbeddingFailure(new Error("local embedding runtime is disabled"));
|
|
34868
35617
|
return false;
|
|
34869
35618
|
}
|
|
34870
35619
|
if (this.initPromise) {
|
|
@@ -34877,11 +35626,16 @@ class LocalEmbeddingProvider {
|
|
|
34877
35626
|
return;
|
|
34878
35627
|
}
|
|
34879
35628
|
const { module: transformersModule, usesWasm } = await loadTransformersForLocalEmbedding(this.runtimePreference);
|
|
35629
|
+
this.usesWasm = usesWasm;
|
|
34880
35630
|
const env = transformersModule.env;
|
|
34881
35631
|
const LogLevel = transformersModule.LogLevel;
|
|
34882
35632
|
if (LogLevel && "ERROR" in LogLevel) {
|
|
34883
35633
|
env.logLevel = LogLevel.ERROR;
|
|
34884
35634
|
}
|
|
35635
|
+
const host = localEmbeddingHostForRuntime();
|
|
35636
|
+
if (usesWasm && host.hasNodeFilesystem && !host.isElectron && (env.useFS !== true || env.useFSCache !== true)) {
|
|
35637
|
+
throw new LocalEmbeddingFsUnavailableError;
|
|
35638
|
+
}
|
|
34885
35639
|
const modelCacheDir = modelCacheDirForRuntime();
|
|
34886
35640
|
try {
|
|
34887
35641
|
if (shouldEnforcePrivateStoragePermissions()) {
|
|
@@ -34930,6 +35684,8 @@ class LocalEmbeddingProvider {
|
|
|
34930
35684
|
}
|
|
34931
35685
|
}
|
|
34932
35686
|
if (this.pipeline) {
|
|
35687
|
+
this.lastFailureReason = null;
|
|
35688
|
+
localEmbeddingProcessFailure = null;
|
|
34933
35689
|
log(`[magic-context] embedding model loaded: ${this.model}`);
|
|
34934
35690
|
} else if (this.disposing) {
|
|
34935
35691
|
return;
|
|
@@ -34941,11 +35697,19 @@ class LocalEmbeddingProvider {
|
|
|
34941
35697
|
await releaseLock();
|
|
34942
35698
|
}
|
|
34943
35699
|
} catch (error51) {
|
|
35700
|
+
const nativeError = error51 instanceof LocalEmbeddingFallbackError ? error51.nativeError : undefined;
|
|
35701
|
+
const failure = classifyLocalEmbeddingFailure(error51, {
|
|
35702
|
+
platform: process.platform,
|
|
35703
|
+
arch: process.arch,
|
|
35704
|
+
usesWasm: this.usesWasm,
|
|
35705
|
+
nativeError
|
|
35706
|
+
});
|
|
35707
|
+
this.lastFailureReason = failure;
|
|
35708
|
+
localEmbeddingProcessFailure = failure;
|
|
34944
35709
|
if (!localEmbeddingRuntimeIsDisabled() && isNativeRuntimeMissingError(error51)) {
|
|
34945
35710
|
disableLocalEmbeddingsAfterRuntimeFailure(error51 instanceof Error ? error51.message : String(error51));
|
|
34946
|
-
} else if (!localEmbeddingRuntimeIsDisabled()) {
|
|
34947
|
-
logForRuntime("[magic-context] embedding model failed to load:", error51);
|
|
34948
35711
|
}
|
|
35712
|
+
logForRuntime(`[magic-context] embedding model failed to load (${failure.class}: ${failure.reason}):`, error51);
|
|
34949
35713
|
this.pipeline = null;
|
|
34950
35714
|
} finally {
|
|
34951
35715
|
this.initPromise = null;
|
|
@@ -34989,9 +35753,17 @@ class LocalEmbeddingProvider {
|
|
|
34989
35753
|
pooling: "mean",
|
|
34990
35754
|
normalize: true
|
|
34991
35755
|
}));
|
|
34992
|
-
|
|
35756
|
+
const embedding = extractBatchEmbeddings(result, 1)[0] ?? null;
|
|
35757
|
+
if (!embedding) {
|
|
35758
|
+
this.lastFailureReason = classifyLocalEmbeddingFailure(new Error("local embedding pipeline returned no vector"), { usesWasm: this.usesWasm });
|
|
35759
|
+
} else {
|
|
35760
|
+
this.lastFailureReason = null;
|
|
35761
|
+
}
|
|
35762
|
+
return embedding;
|
|
34993
35763
|
} catch (error51) {
|
|
34994
|
-
|
|
35764
|
+
const failure = classifyLocalEmbeddingFailure(error51, { usesWasm: this.usesWasm });
|
|
35765
|
+
this.lastFailureReason = failure;
|
|
35766
|
+
logForRuntime(`[magic-context] embedding failed (${failure.class}: ${failure.reason}):`, error51);
|
|
34995
35767
|
return null;
|
|
34996
35768
|
} finally {
|
|
34997
35769
|
this.finishInFlight();
|
|
@@ -35020,9 +35792,17 @@ class LocalEmbeddingProvider {
|
|
|
35020
35792
|
pooling: "mean",
|
|
35021
35793
|
normalize: true
|
|
35022
35794
|
}));
|
|
35023
|
-
|
|
35795
|
+
const embeddings = extractBatchEmbeddings(result, texts.length);
|
|
35796
|
+
if (embeddings.every((embedding) => embedding === null)) {
|
|
35797
|
+
this.lastFailureReason = classifyLocalEmbeddingFailure(new Error("local embedding pipeline returned no vectors"), { usesWasm: this.usesWasm });
|
|
35798
|
+
} else {
|
|
35799
|
+
this.lastFailureReason = null;
|
|
35800
|
+
}
|
|
35801
|
+
return embeddings;
|
|
35024
35802
|
} catch (error51) {
|
|
35025
|
-
|
|
35803
|
+
const failure = classifyLocalEmbeddingFailure(error51, { usesWasm: this.usesWasm });
|
|
35804
|
+
this.lastFailureReason = failure;
|
|
35805
|
+
logForRuntime(`[magic-context] embedding batch failed (${failure.class}: ${failure.reason}):`, error51);
|
|
35026
35806
|
return Array.from({ length: texts.length }, () => null);
|
|
35027
35807
|
} finally {
|
|
35028
35808
|
this.finishInFlight();
|
|
@@ -35055,6 +35835,9 @@ class LocalEmbeddingProvider {
|
|
|
35055
35835
|
isLoaded() {
|
|
35056
35836
|
return this.pipeline !== null;
|
|
35057
35837
|
}
|
|
35838
|
+
getLastFailureReason() {
|
|
35839
|
+
return this.lastFailureReason;
|
|
35840
|
+
}
|
|
35058
35841
|
}
|
|
35059
35842
|
|
|
35060
35843
|
// src/features/magic-context/memory/embedding-ssrf.ts
|
|
@@ -35709,10 +36492,10 @@ function stableStringify2(value) {
|
|
|
35709
36492
|
return JSON.stringify(value);
|
|
35710
36493
|
}
|
|
35711
36494
|
function sha256Prefix(value, length = 16) {
|
|
35712
|
-
return
|
|
36495
|
+
return createHash15("sha256").update(value).digest("hex").slice(0, length);
|
|
35713
36496
|
}
|
|
35714
36497
|
function contentSha256(value) {
|
|
35715
|
-
return
|
|
36498
|
+
return createHash15("sha256").update(value).digest("hex");
|
|
35716
36499
|
}
|
|
35717
36500
|
function getRuntimeFingerprint(config2) {
|
|
35718
36501
|
if (config2.provider === "off") {
|
|
@@ -36351,13 +37134,17 @@ async function processShadowQueueItem(item) {
|
|
|
36351
37134
|
const placeholders3 = boundedIds.map(() => "?").join(",");
|
|
36352
37135
|
const candidates = db.prepare(`SELECT id, session_id, start_message, end_message
|
|
36353
37136
|
FROM compartments WHERE id IN (${placeholders3})`).all(...boundedIds.map((id) => Number(id)));
|
|
36354
|
-
const prepared =
|
|
36355
|
-
|
|
36356
|
-
|
|
36357
|
-
|
|
36358
|
-
|
|
36359
|
-
|
|
36360
|
-
|
|
37137
|
+
const prepared = [];
|
|
37138
|
+
for (const candidate of candidates) {
|
|
37139
|
+
const mappedText = buildCanonicalChunkTextFromFts(db, candidate.session_id, candidate.start_message, candidate.end_message);
|
|
37140
|
+
if (mappedText !== null) {
|
|
37141
|
+
const text = mappedText || buildCompartmentSummaryFallbackText(db, candidate.id);
|
|
37142
|
+
const windows = chunkCanonicalText(text, candidate.start_message, candidate.end_message, SYNAPSE_MAX_INPUT_TOKENS);
|
|
37143
|
+
if (windows.length > 0)
|
|
37144
|
+
prepared.push({ candidate, windows });
|
|
37145
|
+
}
|
|
37146
|
+
await new Promise((resolve4) => setTimeout(resolve4, 0));
|
|
37147
|
+
}
|
|
36361
37148
|
const items = prepared.flatMap((item2) => item2.windows.map((window) => ({
|
|
36362
37149
|
id: `chunk:${item2.candidate.id}:${window.windowIndex}`,
|
|
36363
37150
|
text: window.text,
|
|
@@ -36702,7 +37489,11 @@ async function embedCandidateChunkBatch(db, projectIdentity, modelId, candidates
|
|
|
36702
37489
|
const maxInputTokens = getProjectEmbeddingMaxInputTokens(projectIdentity);
|
|
36703
37490
|
const prepared = [];
|
|
36704
37491
|
for (const candidate of candidates) {
|
|
36705
|
-
|
|
37492
|
+
await new Promise((resolve4) => setTimeout(resolve4, 0));
|
|
37493
|
+
const mappedText = buildCanonicalChunkTextFromFts(db, candidate.sessionId, candidate.startMessage, candidate.endMessage);
|
|
37494
|
+
if (mappedText === null)
|
|
37495
|
+
continue;
|
|
37496
|
+
const canonicalText = mappedText || buildCompartmentSummaryFallbackText(db, candidate.id);
|
|
36706
37497
|
if (canonicalText.length === 0) {
|
|
36707
37498
|
noWork.push(candidate.id);
|
|
36708
37499
|
continue;
|
|
@@ -36937,7 +37728,10 @@ async function embedAndStoreCompartmentChunks(db, sessionId, projectPath, compar
|
|
|
36937
37728
|
for (const compartment of compartments) {
|
|
36938
37729
|
try {
|
|
36939
37730
|
const fromMemory = compartment.sourceChunkText ? canonicalizeInMemoryChunkTextForEmbedding(compartment.sourceChunkText, compartment.startMessage, compartment.endMessage) : "";
|
|
36940
|
-
const
|
|
37731
|
+
const mappedText = fromMemory ? fromMemory : buildCanonicalChunkTextFromFts(db, sessionId, compartment.startMessage, compartment.endMessage);
|
|
37732
|
+
if (mappedText === null)
|
|
37733
|
+
continue;
|
|
37734
|
+
const canonicalText = mappedText || buildCompartmentSummaryFallbackText(db, compartment.id);
|
|
36941
37735
|
if (canonicalText.length === 0)
|
|
36942
37736
|
continue;
|
|
36943
37737
|
const windows = chunkCanonicalText(canonicalText, compartment.startMessage, compartment.endMessage, maxInputTokens);
|
|
@@ -36977,6 +37771,8 @@ async function embedAndStoreCompartmentChunks(db, sessionId, projectPath, compar
|
|
|
36977
37771
|
}
|
|
36978
37772
|
} catch (error51) {
|
|
36979
37773
|
sessionLog(sessionId, `compartment chunk embedding failed for compartment ${compartment.id}:`, error51);
|
|
37774
|
+
} finally {
|
|
37775
|
+
await new Promise((resolve4) => setTimeout(resolve4, 0));
|
|
36980
37776
|
}
|
|
36981
37777
|
}
|
|
36982
37778
|
}
|
|
@@ -37588,7 +38384,7 @@ function tallyFactsByCategory(facts) {
|
|
|
37588
38384
|
import { join as join8 } from "node:path";
|
|
37589
38385
|
|
|
37590
38386
|
// src/features/magic-context/compaction-marker.ts
|
|
37591
|
-
import { createHash as
|
|
38387
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
37592
38388
|
import { existsSync as existsSync8 } from "node:fs";
|
|
37593
38389
|
import { join as join7 } from "node:path";
|
|
37594
38390
|
var BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
@@ -37596,7 +38392,7 @@ var ID_PREFIX_HEX_LENGTH = 12;
|
|
|
37596
38392
|
var ID_SUFFIX_LENGTH = 14;
|
|
37597
38393
|
var ID_PREFIX_MASK = (1n << BigInt(ID_PREFIX_HEX_LENGTH * 4)) - 1n;
|
|
37598
38394
|
function deterministicBase62(seed, length) {
|
|
37599
|
-
let value = BigInt(`0x${
|
|
38395
|
+
let value = BigInt(`0x${createHash16("sha256").update(seed).digest("hex")}`);
|
|
37600
38396
|
const chars = Array(length);
|
|
37601
38397
|
for (let index = length - 1;index >= 0; index -= 1) {
|
|
37602
38398
|
chars[index] = BASE62_CHARS[Number(value % 62n)];
|
|
@@ -39975,7 +40771,7 @@ function sanitizeDumpName(value) {
|
|
|
39975
40771
|
import { Buffer as Buffer2 } from "node:buffer";
|
|
39976
40772
|
|
|
39977
40773
|
// src/features/magic-context/mural/render-trigger.ts
|
|
39978
|
-
import { createHash as
|
|
40774
|
+
import { createHash as createHash17 } from "node:crypto";
|
|
39979
40775
|
|
|
39980
40776
|
// src/features/magic-context/mural/mural-selection.ts
|
|
39981
40777
|
var DEFAULT_MURAL_MEMORY_BUDGET = 8000;
|
|
@@ -40601,7 +41397,7 @@ function ensureMuralRendered(db, projectIdentity, budgetTokens = DEFAULT_MURAL_M
|
|
|
40601
41397
|
return { hasMural: false, rerendered: false };
|
|
40602
41398
|
}
|
|
40603
41399
|
const rendered = renderMural(entries);
|
|
40604
|
-
const textHash =
|
|
41400
|
+
const textHash = createHash17("sha256").update(rendered.sha256Input).digest("hex");
|
|
40605
41401
|
const existing = getMural(db, projectIdentity);
|
|
40606
41402
|
if (existing && existing.contentHash === textHash && existing.width === rendered.width && existing.height === rendered.height) {
|
|
40607
41403
|
return {
|
|
@@ -46774,7 +47570,7 @@ async function executeContextRecomp(deps, options = {}) {
|
|
|
46774
47570
|
}
|
|
46775
47571
|
|
|
46776
47572
|
// src/hooks/magic-context/lkg-slot.ts
|
|
46777
|
-
import { createHash as
|
|
47573
|
+
import { createHash as createHash18 } from "node:crypto";
|
|
46778
47574
|
var LKG_TOTAL_BYTES = 64 * 1024 * 1024;
|
|
46779
47575
|
var LKG_SINGLE_SLOT_BYTES = 24 * 1024 * 1024;
|
|
46780
47576
|
var LKG_METADATA_BYTES = 256;
|
|
@@ -46840,7 +47636,7 @@ function lkgContentFields(value) {
|
|
|
46840
47636
|
}
|
|
46841
47637
|
}
|
|
46842
47638
|
function lkgContentDigestFromFields(fields) {
|
|
46843
|
-
const hash2 =
|
|
47639
|
+
const hash2 = createHash18("sha256");
|
|
46844
47640
|
for (const field of fields) {
|
|
46845
47641
|
const value = typeof field === "symbol" ? field.description ?? "" : String(field);
|
|
46846
47642
|
hash2.update(`${typeof field}:${value.length}:`).update(value).update("\x00");
|
|
@@ -47264,4 +48060,4 @@ async function runUpgradeMemoryMigration(ctx, sessionId, migrationDirectory) {
|
|
|
47264
48060
|
}
|
|
47265
48061
|
}
|
|
47266
48062
|
|
|
47267
|
-
export { withContentLanguageDirective, buildPrimaryLanguageDirective, cortexKitUserConfigBasePath, cortexKitProjectConfigBasePath, resolveLegacyConfigSources, resolveLegacyConfigSourcesForHarness, migrateMagicContextConfigLocations, exports_external, DEFAULT_PROTECTED_TAGS, parseCron, nextOccurrence, nextDueAtMs, promptSurfaceConfigIdentity, resolvePromptSurface, resolveModelConfigOrDefault, DEFAULT_EXECUTE_THRESHOLD_PERCENTAGE, DEFAULT_HISTORIAN_TIMEOUT_MS, DEFAULT_LOCAL_EMBEDDING_MODEL, PER_HARNESS_MIGRATION_INVENTORY, ConfigProfilesSchema, MagicContextConfigSchema, getOpenCodeDbPath, removeMcOwnedCompactionMarkers, isFailClosedBlockingError, shouldBypassFailClosedBlock, resolveAgentNameFromMessages, createFailClosedController, recordHookInitFailure, clearHookInitFailure, getLastHookInitFailure, ProjectIdentityError, resolveProjectIdentityStrict, takeDubiousOwnershipProjectIdentityWarning, resolveProjectIdentity, directoryHasGitMetadata, resolveProjectIdentityForSession, normalizeStoredProjectPath, storedPathBelongsToIdentity, isLinkedGitWorktree, recordSessionProjectIdentity, beginBootQuietPeriod, bootQuietRemainingMs, scheduleAfterBootQuiet, rpcPortDir, rpcPortFilePath, isPidAlive, parseRpcPortFile, observeAuthorityRouting, registerModuleNoteEvaluationBridge, getModuleNoteEvaluationBridge, getContextStoreUuid, ensureContextStoreUuid, getAuthorityManagedMarker, reconcileAuthorityProject, checksumAuthoritySeedRows, prepareAuthority, drainAuthority, getMirrorCursor, applyMirroredNoteCompileFields, applyMirrorPage, pullMemoryMirrorOnce, V2_MEMORY_CATEGORIES, CATEGORY_PRIORITY, resolveWorkspaceShareCategories, resolveWorkspaceIdentitySet, expandWorkspaceIdentitySetWithAliases, resolveStoredPathWorkspaceIdentity, storedPathBelongsToWorkspace, sourceNameForMemory, computeWorkspaceEpochFingerprint, textMentionsRecentCommit, hasMeaningfulUserText, extractTexts, extractToolCallSummaries, preloadTokenizer, estimateTokens, normalizeText, getCurrentToolSetHash, recordToolDefinition, getMeasuredToolDefinitionTokens, getSchemaFenceRejection, getMigrationOnOpenRefusal, LATEST_SUPPORTED_VERSION, getDatabasePath, getPersistedSchemaVersion, setSqlitePragmaConfig, runSqliteOptimize, openDatabase, openDatabaseAsync, isDatabasePersisted, getDatabasePersistenceError, COMPARTMENT_LEASE_RENEWAL_MS, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLease, getCompartments, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, clearRecompStaging, isRawCompactionSummaryInfo, extractInMemoryMessageViews, buildInMemoryTailRawMessages, isRecord, estimateTrueRawMessageTokens, invalidateTrueRawTokenCache, stripPersistedAssistantText, byteSize, stripTagPrefix, prependTag, isThinkingPart, isTextPart, isToolPartWithOutput, isFilePart, buildFileSourceContent, isEditTool, partHasCompletedResult, extractToolCallObservation, ToolMutationBatch, createToolDropTarget, setRawMessageProvider, cleanUserText, withRawSessionMessageCache, readRawSessionMessages, primeTailRawMessageCache, primeInMemoryTailRawMessageCache, readRawSessionMessageOrdinalPage, getRawSessionStoredMessageCount, readRawSessionMessagePartsById, readRawSessionMessageOrdinalById, readRawSessionMessageById, readSessionChunk, getMessageIndexSourceIdentity, isMessageIndexSourceCurrent, getLastIndexedOrdinal, getIndexedMessageCorpusSize, getMessageIndexReconciliationStartOrdinal, isMessageIndexReconciledThrough, deleteIndexedMessage, clearIndexedMessages, indexSingleMessage, indexMessagesAfterOrdinal, sweepOrphanedOpenCodeMessageIndexes, recordEmbeddingMeasurement, getMaxM0MutationId, queueMemoryMutation, getMemoryMutationsForRenderByProjects, getMaxMemoryMutationIdForProjects, MAX_EXECUTE_THRESHOLD, escalationBands, isEmergencyRecoveryArmed, isProviderOverflowReconfirmed, getEmergencyRecoveryArmedAt, loadPersistedUsage, loadProtectedTailMeta, resetProtectedTailNoEligibleHead, getWrapupInProgressState, acquireWrapupInProgress, updateWrapupInProgress, releaseWrapupInProgress, resolveCompactionModeRecord, getCompactionModeRecord, setCompactionModeRecord, getPersistedReasoningWatermark, setPersistedReasoningWatermark, clearPersistedReasoningWatermark, getEmergencyInputSample, setEmergencyDropSample, clearEmergencyDropSample, getLastNudgeUndropped, setLastNudgeUndropped, getChannel1NudgeState, setChannel1NudgeState, markChannel1PostReduceGracePending, captureChannel1PostReduceGraceBaseline, getChannel2NudgeState, getChannel2NudgeClaim, setChannel2NudgeState, casChannel2NudgeState, claimChannel2NudgeState, casChannel2NudgeClaim, getPersistedNoteNudge, getNoteNudgeAnchors, getAutoSearchHintDecisions, appendAutoSearchHintDecision, pruneNoteNudgeAnchors, pruneAutoSearchHintDecisions, removeNoteNudgeAnchorByMessageId, removeAutoSearchHintDecisionByMessageId, getPersistedTodoPermissionDenied, setPersistedTodoPermissionDenied, getPersistedTodoSyntheticAnchor, setPersistedTodoSyntheticAnchor, clearPersistedTodoSyntheticAnchor, setNoteLastReadAt, getHistorianFailureState, clearHistorianFailureState, getOverflowState, recordOverflowDetected, recordDetectedContextLimit, clearEmergencyRecovery, clearDetectedContextLimit, getPersistedCompactionMarkerState, setPersistedCompactionMarkerState, getStrippedPlaceholderIds, applyStrippedPlaceholderDelta, removeStrippedPlaceholderId, getMergedReasoningStrippedIds, addMergedReasoningStrippedIds, getTrailingBlankDecisions, addTrailingBlankDecisions, demoteTrailingBlankKeepDecisions, getStaleReduceStrippedIds, addStaleReduceStrippedIds, getProcessedImageStrippedIds, addProcessedImageStrippedIds, getPendingCompactionMarkerState, clearPendingCompactionMarkerStateIf, peekDeferredExecutePending, setDeferredExecutePendingIfAbsent, clearDeferredExecutePendingIfMatches, getSessionsWithPendingMarker, setSessionWorkMetrics, getNotes, addNote, getSessionNotes, getPendingSmartNotes, getReadySmartNotes, updateNote, dismissNote, markNoteReady, markNoteChecked, queuePendingOp, getPendingOps, getPendingOpsCount, clearPendingOps, removePendingOp, PRIMER_CANDIDATE_TTL_MS, PRIMER_CANDIDATE_MAX_AGE_MS, primerOccurrenceKey, primerOccurrenceUtcDay, updatePrimerCandidateEmbedding, getPrimerCandidatesByIds, getPrimerCandidatesForPromotion, countPrimerCandidatesForProject, getActivePrimers, createPrimer, updatePrimerSupport, updatePrimerAnswer, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectMemoryEpoch, bumpProjectUserProfileVersion, saveSourceContent, replaceSourceContent, getSourceContents, CTX_REDUCE_KEEP, estimateImageTokensFromDataUrl, normalizeTodoStateJson, buildSyntheticTodoPart, computeSyntheticCallId, isSyntheticTodoPart, countRealUserMessages, tailHygieneStructuralSignature, sameTailHygieneStructuralSignature, refreshTailHygieneBaseline, effectiveTailHygiene, assertTailHygieneContentUnchanged, CHANNEL1_SENTINEL, CHANNEL1_FLOOR_TOKENS, toolOutputTokens, decideChannel1, evaluateChannel2, reclaimableToolOutputCount, buildChannel2Reminder, buildChannel1Reminder, estimateEmergencyDropReclaimTokens, planEmergencyDrop, getRecentTagOwnerMessageIds, AGE_RECLAIM_MIN_TOKENS, getOldestActiveUnprotectedToolTags, getActiveToolTagsForAgeReclaim, getTriggerTagTokenUpperBound, getActiveTagTokenTotalsByMessage, tagTokenCountIsNull, backfillTagTokenCounts, insertTag, updateTagStatus, updateTagDropMode, updateCavemanDepth, updateTagMessageId, deleteTagsByMessageId, getMaxTagNumberBySession, getTagNumberByMessageId, deriveTagLoadFloor, getTagsBySession, getActiveTagsBySession, getTailHygieneTags, getDroppedTagsBySession, getTagsByNumbers, getMaxDroppedTagNumber, getToolTagNumberByOwner, getNullOwnerToolTag, adoptNullOwnerToolTag, getCandidateToolOwners, pickNearestPriorOwner, createChildSessionWithFence, detectOverflow, resolveFallbackChain, modelBodyField, toModelEntry, promptSyncWithValidatedOutputRetry, normalizeSDKResponse, promptSurfaceHashMaterial, createPromptSurfaceRuntime, createPromptSurfaceGuidanceEpochCache, extractLatestAssistantText, hasLengthCappedOutput, setKeepSubagents, shouldKeepSubagents, recordChildInvocation, COMPARTMENT_AGENT_SYSTEM_PROMPT, HISTORIAN_EDITOR_SYSTEM_PROMPT, COMPARTMENT_STRUCTURAL_SYSTEM_PROMPT, Priority, AdmissionClass, StaleRouteHandleError, SocketClosedError, SocketTimeoutError, SubcClient, isConsumerReconnectTransient, connectionFileExists, getCompartmentEvents, loadCompartmentChunkEmbeddingsForSearch, cosineSimilarity, SYNAPSE_DEFAULT_MODEL, SynapseEmbeddingProvider, computeNormalizedHash, saveCommitEmbedding, loadProjectCommitEmbeddings, loadUnembeddedCommits, countEmbeddedCommits, upsertCommits, getLatestIndexedCommitTimeMs, enforceProjectCap, GIT_SWEEP_LEASE_RENEWAL_MS, acquireGitSweepLease, renewGitSweepLease, markGitSweepSuccessAndRelease, parkGitSweepNonIndexable, releaseGitSweepLease, saveEmbeddingIfHashMatches, getProjectEmbeddings, peekProjectEmbeddings, invalidateProject, invalidateMemory, markProjectLoadUntrusted, contentSha256, sweepStaleEmbeddingIdentitiesForProject, registerProjectEmbedding, registerProjectShadowEmbedding, getShadowEmbeddingMeasurementCohort, getPrimaryEmbeddingMeasurementCohort, embedShadowTextForProject, enqueueShadowEmbeddingItems, registerProjectInObservationMode, getProjectEmbeddingSnapshot, embedTextForProject, embedBatchForProject, embedItemsForProject, embedUnembeddedMemoriesForProject, drainCommitBacklogForProject, embedSessionCompartmentChunks, getEmbeddingCoverageStatus, isEmbeddingEnabled, embedText, ensureMemoryEmbeddings, computeCueContentHash, hasMuralCueColumns, getMuralCueState, memoryNeedsCue, setMuralCue, recordMuralCueRejection, hasMemoryShareableColumn, hasMemoryClassifiedAtColumn, getUnclassifiedMemoryIds, ModuleMemoryAuthorityError, insertMemory, insertMemoryIdempotent, getMemoryByHash, getMemoriesByProject, buildWorkspaceMemorySqlFilter, getMemoriesByProjects, getMaxMemoryIdForProjects, readNewMemoriesForM1Union, getMemoryById, getMemoriesByIds, updateMemorySeenCount, updateMemoryRetrievalCount, setMemoryClassification, supersededMemory, mergeMemoryStats, archiveMemory, getMemoryCountsByStatus, sanitizeFtsQuery, searchMemoriesFTS, searchMemoriesFTSUnion, recordMemoryMapping, recordMemoryVerifications, getUnmappedMemoryIds, clearMemoryVerifications, getMemoryVerifications, resolveGitTopLevel, readGitHead, readGitChangedFilesSince, readGitFileChangeTimesSince, verificationFileExists, normalizeVerificationFiles, USER_MEMORY_CANDIDATE_TTL_MS, insertUserMemoryCandidates, getUserMemoryCandidates, deleteUserMemoryCandidates, pruneExpiredUserMemoryCandidates, insertUserMemory, getActiveUserMemories, updateUserMemoryContent, dismissUserMemory, getMural, BoundedSessionMap, registerLkgPersistence, LKG_SNAPSHOT_ARRAY, LKG_SNAPSHOT_OBJECT, LKG_SNAPSHOT_KEY, LKG_SNAPSHOT_STRING, LKG_SNAPSHOT_NUMBER, LKG_SNAPSHOT_BOOLEAN, LKG_SNAPSHOT_NULL, LKG_SNAPSHOT_UNDEFINED, incrementalLkgContentDigests, lkgContentDigest, captureSlot, getSlot, dropSlot, noteEntry, onNoteTrigger, peekNoteNudgeText, markNoteNudgeDelivered, clearNoteNudgeTriggerAndCooldown, resetNoteNudgeCooldownOnly, clearNoteNudgeTriggerOnly, MARKER_SUMMARY_TEXT, applyDeferredCompactionMarker, removeCompactionMarkerForSession, checkCompactionMarkerConsistency, resolveMuralWire, extractM0Block, formatDate, injectTemporalMarkers, clearInjectionCache, getVisibleMemoryIds, prepareCompartmentInjection, renderCompartmentInjection, mustMaterialize, trimMemoriesToBudgetV2, renderMemoryBlockV2, injectM0M1, RECOVERY_NO_HEAD_LIMIT, resolveOpenCodeProtectedTailBoundary, resolveWrapupProtectedTailBoundary, getRawHistoryEligibility, hasRunnableCompartmentWindow, recordHighPressureNoEligibleHead, runCompartmentAgent, snapRangeToCompartments, getActiveCompartmentRun, markActiveCompartmentRunPublished, registerActiveCompartmentRun, startCompartmentAgent, isRecompFailure, isRecompSkip, isRecompComplete, extractRecompReason, contextualizeUpgradeReason, setRecompStarting, setRecompNote, setRecompTerminal, runManagedRecomp, runManagedUpgrade };
|
|
48063
|
+
export { withContentLanguageDirective, buildPrimaryLanguageDirective, cortexKitUserConfigBasePath, cortexKitProjectConfigBasePath, resolveLegacyConfigSources, resolveLegacyConfigSourcesForHarness, migrateMagicContextConfigLocations, exports_external, DEFAULT_PROTECTED_TAGS, parseCron, nextOccurrence, nextDueAtMs, promptSurfaceConfigIdentity, resolvePromptSurface, resolveModelConfigOrDefault, DEFAULT_EXECUTE_THRESHOLD_PERCENTAGE, DEFAULT_HISTORIAN_TIMEOUT_MS, DEFAULT_LOCAL_EMBEDDING_MODEL, PER_HARNESS_MIGRATION_INVENTORY, ConfigProfilesSchema, MagicContextConfigSchema, getOpenCodeDbPath, removeMcOwnedCompactionMarkers, isFailClosedBlockingError, shouldBypassFailClosedBlock, resolveAgentNameFromMessages, createFailClosedController, recordHookInitFailure, clearHookInitFailure, getLastHookInitFailure, ProjectIdentityError, resolveProjectIdentityStrict, takeDubiousOwnershipProjectIdentityWarning, resolveProjectIdentity, directoryHasGitMetadata, resolveProjectIdentityForSession, normalizeStoredProjectPath, storedPathBelongsToIdentity, isLinkedGitWorktree, recordSessionProjectIdentity, beginBootQuietPeriod, bootQuietRemainingMs, scheduleAfterBootQuiet, rpcPortDir, rpcPortFilePath, isPidAlive, parseRpcPortFile, observeAuthorityRouting, registerModuleNoteEvaluationBridge, getModuleNoteEvaluationBridge, getContextStoreUuid, ensureContextStoreUuid, getAuthorityManagedMarker, reconcileAuthorityProject, checksumAuthoritySeedRows, prepareAuthority, drainAuthority, getMirrorCursor, applyMirroredNoteCompileFields, applyMirrorPage, pullMemoryMirrorOnce, V2_MEMORY_CATEGORIES, CATEGORY_PRIORITY, resolveWorkspaceShareCategories, resolveWorkspaceIdentitySet, expandWorkspaceIdentitySetWithAliases, resolveStoredPathWorkspaceIdentity, storedPathBelongsToWorkspace, sourceNameForMemory, computeWorkspaceEpochFingerprint, textMentionsRecentCommit, hasMeaningfulUserText, extractTexts, extractToolCallSummaries, preloadTokenizer, estimateTokens, normalizeText, getCurrentToolSetHash, recordToolDefinition, getMeasuredToolDefinitionTokens, getSchemaFenceRejection, getMigrationOnOpenRefusal, LATEST_SUPPORTED_VERSION, getDatabasePath, getPersistedSchemaVersion, setSqlitePragmaConfig, runSqliteOptimize, openDatabase, openDatabaseAsync, isDatabasePersisted, getDatabasePersistenceError, COMPARTMENT_LEASE_RENEWAL_MS, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLease, getCompartments, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, clearRecompStaging, isRawCompactionSummaryInfo, extractInMemoryMessageViews, buildInMemoryTailRawMessages, isRecord, estimateTrueRawMessageTokens, invalidateTrueRawTokenCache, stripPersistedAssistantText, byteSize, stripTagPrefix, prependTag, isThinkingPart, isTextPart, isToolPartWithOutput, isFilePart, buildFileSourceContent, isEditTool, partHasCompletedResult, extractToolCallObservation, ToolMutationBatch, createToolDropTarget, setRawMessageProvider, cleanUserText, withRawSessionMessageCache, readRawSessionMessages, primeTailRawMessageCache, primeInMemoryTailRawMessageCache, readRawSessionMessageOrdinalPage, getRawSessionStoredMessageCount, readRawSessionMessagePartsById, readRawSessionMessageOrdinalById, readRawSessionMessageById, readSessionChunk, getMessageIndexSourceIdentity, isMessageIndexSourceCurrent, getLastIndexedOrdinal, getIndexedMessageCorpusSize, getMessageIndexReconciliationStartOrdinal, isMessageIndexReconciledThrough, deleteIndexedMessage, clearIndexedMessages, indexSingleMessage, indexMessagesAfterOrdinal, sweepOrphanedOpenCodeMessageIndexes, recordEmbeddingMeasurement, getMaxM0MutationId, queueMemoryMutation, getMemoryMutationsForRenderByProjects, getMaxMemoryMutationIdForProjects, MAX_EXECUTE_THRESHOLD, escalationBands, isEmergencyRecoveryArmed, isProviderOverflowReconfirmed, getEmergencyRecoveryArmedAt, loadPersistedUsage, loadProtectedTailMeta, resetProtectedTailNoEligibleHead, getWrapupInProgressState, acquireWrapupInProgress, updateWrapupInProgress, releaseWrapupInProgress, resolveCompactionModeRecord, getCompactionModeRecord, setCompactionModeRecord, getPersistedReasoningWatermark, setPersistedReasoningWatermark, clearPersistedReasoningWatermark, getEmergencyInputSample, setEmergencyDropSample, clearEmergencyDropSample, getLastNudgeUndropped, setLastNudgeUndropped, getChannel1NudgeState, setChannel1NudgeState, markChannel1PostReduceGracePending, captureChannel1PostReduceGraceBaseline, getChannel2NudgeState, getChannel2NudgeClaim, setChannel2NudgeState, casChannel2NudgeState, claimChannel2NudgeState, casChannel2NudgeClaim, getPersistedNoteNudge, getNoteNudgeAnchors, getAutoSearchHintDecisions, appendAutoSearchHintDecision, pruneNoteNudgeAnchors, pruneAutoSearchHintDecisions, removeNoteNudgeAnchorByMessageId, removeAutoSearchHintDecisionByMessageId, getPersistedTodoPermissionDenied, setPersistedTodoPermissionDenied, getPersistedTodoSyntheticAnchor, setPersistedTodoSyntheticAnchor, clearPersistedTodoSyntheticAnchor, setNoteLastReadAt, getHistorianFailureState, clearHistorianFailureState, getOverflowState, recordOverflowDetected, recordDetectedContextLimit, clearEmergencyRecovery, clearDetectedContextLimit, getPersistedCompactionMarkerState, setPersistedCompactionMarkerState, getStrippedPlaceholderIds, applyStrippedPlaceholderDelta, removeStrippedPlaceholderId, NEWEST_REASONING_BEARING_ASSISTANT, THINKING_BINDING_RECOVERY_FROZEN_PREFIX, thinkingBindingRecoveryFrozenId, getThinkingBindingRecoveryTarget, armThinkingBindingRecovery, clearThinkingBindingRecoveryIf, getMergedReasoningStrippedIds, addMergedReasoningStrippedIds, getTrailingBlankDecisions, addTrailingBlankDecisions, demoteTrailingBlankKeepDecisions, getStaleReduceStrippedIds, addStaleReduceStrippedIds, getProcessedImageStrippedIds, addProcessedImageStrippedIds, getPendingCompactionMarkerState, clearPendingCompactionMarkerStateIf, peekDeferredExecutePending, setDeferredExecutePendingIfAbsent, clearDeferredExecutePendingIfMatches, getSessionsWithPendingMarker, setSessionWorkMetrics, getNotes, addNote, getSessionNotes, getPendingSmartNotes, getReadySmartNotes, updateNote, dismissNote, markNoteReady, markNoteChecked, queuePendingOp, getPendingOps, getPendingOpsCount, clearPendingOps, removePendingOp, PRIMER_CANDIDATE_TTL_MS, PRIMER_CANDIDATE_MAX_AGE_MS, primerOccurrenceKey, primerOccurrenceUtcDay, updatePrimerCandidateEmbedding, getPrimerCandidatesByIds, getPrimerCandidatesForPromotion, countPrimerCandidatesForProject, getActivePrimers, createPrimer, updatePrimerSupport, updatePrimerAnswer, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectMemoryEpoch, bumpProjectUserProfileVersion, saveSourceContent, replaceSourceContent, getSourceContents, CTX_REDUCE_KEEP, estimateImageTokensFromDataUrl, normalizeTodoStateJson, buildSyntheticTodoPart, computeSyntheticCallId, isSyntheticTodoPart, countRealUserMessages, tailHygieneStructuralSignature, sameTailHygieneStructuralSignature, refreshTailHygieneBaseline, effectiveTailHygiene, assertTailHygieneContentUnchanged, CHANNEL1_SENTINEL, CHANNEL1_FLOOR_TOKENS, toolOutputTokens, decideChannel1, evaluateChannel2, reclaimableToolOutputCount, buildChannel2Reminder, buildChannel1Reminder, estimateEmergencyDropReclaimTokens, planEmergencyDrop, getRecentTagOwnerMessageIds, AGE_RECLAIM_MIN_TOKENS, getOldestActiveUnprotectedToolTags, getActiveToolTagsForAgeReclaim, getTriggerTagTokenUpperBound, getActiveTagTokenTotalsByMessage, tagTokenCountIsNull, backfillTagTokenCounts, insertTag, updateTagStatus, markWhitespaceAssistantTagInert, getInertWhitespaceAssistantTags, updateTagDropMode, updateCavemanDepth, updateTagMessageId, deleteTagsByMessageId, getMaxTagNumberBySession, getTagNumberByMessageId, getAssignableTagNumberByMessageId, deriveTagLoadFloor, getTagsBySession, getActiveTagsBySession, getTailHygieneTags, getDroppedTagsBySession, getTagsByNumbers, getMaxDroppedTagNumber, getTagById, getToolTagNumberByOwner, getNullOwnerToolTag, adoptNullOwnerToolTag, getCandidateToolOwners, pickNearestPriorOwner, createChildSessionWithFence, detectThinkingBindingMismatch, isFable51ThinkingBindingModel, detectOverflow, resolveFallbackChain, modelBodyField, toModelEntry, promptSyncWithValidatedOutputRetry, normalizeSDKResponse, promptSurfaceHashMaterial, createPromptSurfaceRuntime, createPromptSurfaceGuidanceEpochCache, extractLatestAssistantText, hasLengthCappedOutput, setKeepSubagents, shouldKeepSubagents, recordChildInvocation, COMPARTMENT_AGENT_SYSTEM_PROMPT, HISTORIAN_EDITOR_SYSTEM_PROMPT, COMPARTMENT_STRUCTURAL_SYSTEM_PROMPT, Priority, AdmissionClass, StaleRouteHandleError, SocketClosedError, SocketTimeoutError, SubcClient, isConsumerReconnectTransient, connectionFileExists, getCompartmentEvents, loadCompartmentChunkEmbeddingsForSearch, cosineSimilarity, SYNAPSE_DEFAULT_MODEL, SynapseEmbeddingProvider, computeNormalizedHash, saveCommitEmbedding, loadProjectCommitEmbeddings, loadUnembeddedCommits, countEmbeddedCommits, upsertCommits, getLatestIndexedCommitTimeMs, enforceProjectCap, GIT_SWEEP_LEASE_RENEWAL_MS, acquireGitSweepLease, renewGitSweepLease, markGitSweepSuccessAndRelease, parkGitSweepNonIndexable, releaseGitSweepLease, saveEmbeddingIfHashMatches, getProjectEmbeddings, peekProjectEmbeddings, invalidateProject, invalidateMemory, markProjectLoadUntrusted, contentSha256, sweepStaleEmbeddingIdentitiesForProject, registerProjectEmbedding, registerProjectShadowEmbedding, getShadowEmbeddingMeasurementCohort, getPrimaryEmbeddingMeasurementCohort, embedShadowTextForProject, enqueueShadowEmbeddingItems, registerProjectInObservationMode, getProjectEmbeddingSnapshot, embedTextForProject, embedBatchForProject, embedItemsForProject, embedUnembeddedMemoriesForProject, drainCommitBacklogForProject, embedSessionCompartmentChunks, getEmbeddingCoverageStatus, isEmbeddingEnabled, embedText, ensureMemoryEmbeddings, computeCueContentHash, hasMuralCueColumns, getMuralCueState, memoryNeedsCue, setMuralCue, recordMuralCueRejection, hasMemoryShareableColumn, hasMemoryClassifiedAtColumn, getUnclassifiedMemoryIds, ModuleMemoryAuthorityError, insertMemory, insertMemoryIdempotent, getMemoryByHash, getMemoriesByProject, buildWorkspaceMemorySqlFilter, getMemoriesByProjects, getMaxMemoryIdForProjects, readNewMemoriesForM1Union, getMemoryById, getMemoriesByIds, updateMemorySeenCount, updateMemoryRetrievalCount, setMemoryClassification, supersededMemory, mergeMemoryStats, archiveMemory, getMemoryCountsByStatus, sanitizeFtsQuery, searchMemoriesFTS, searchMemoriesFTSUnion, recordMemoryMapping, recordMemoryVerifications, getUnmappedMemoryIds, clearMemoryVerifications, getMemoryVerifications, resolveGitTopLevel, readGitHead, readGitChangedFilesSince, readGitFileChangeTimesSince, verificationFileExists, normalizeVerificationFiles, USER_MEMORY_CANDIDATE_TTL_MS, insertUserMemoryCandidates, getUserMemoryCandidates, deleteUserMemoryCandidates, pruneExpiredUserMemoryCandidates, insertUserMemory, getActiveUserMemories, updateUserMemoryContent, dismissUserMemory, getMural, BoundedSessionMap, registerLkgPersistence, LKG_SNAPSHOT_ARRAY, LKG_SNAPSHOT_OBJECT, LKG_SNAPSHOT_KEY, LKG_SNAPSHOT_STRING, LKG_SNAPSHOT_NUMBER, LKG_SNAPSHOT_BOOLEAN, LKG_SNAPSHOT_NULL, LKG_SNAPSHOT_UNDEFINED, incrementalLkgContentDigests, lkgContentDigest, captureSlot, getSlot, dropSlot, noteEntry, onNoteTrigger, peekNoteNudgeText, markNoteNudgeDelivered, clearNoteNudgeTriggerAndCooldown, resetNoteNudgeCooldownOnly, clearNoteNudgeTriggerOnly, MARKER_SUMMARY_TEXT, applyDeferredCompactionMarker, removeCompactionMarkerForSession, checkCompactionMarkerConsistency, resolveMuralWire, extractM0Block, formatDate, injectTemporalMarkers, clearInjectionCache, getVisibleMemoryIds, prepareCompartmentInjection, renderCompartmentInjection, mustMaterialize, trimMemoriesToBudgetV2, renderMemoryBlockV2, injectM0M1, RECOVERY_NO_HEAD_LIMIT, resolveOpenCodeProtectedTailBoundary, resolveWrapupProtectedTailBoundary, getRawHistoryEligibility, hasRunnableCompartmentWindow, recordHighPressureNoEligibleHead, runCompartmentAgent, snapRangeToCompartments, getActiveCompartmentRun, markActiveCompartmentRunPublished, registerActiveCompartmentRun, startCompartmentAgent, isRecompFailure, isRecompSkip, isRecompComplete, extractRecompReason, contextualizeUpgradeReason, setRecompStarting, setRecompNote, setRecompTerminal, runManagedRecomp, runManagedUpgrade };
|