@cortexkit/opencode-magic-context 0.44.3 → 0.44.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{derive-budgets-vjmvh6pz.js → derive-budgets-ncwn1jk9.js} +2 -2
- package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-openai.d.ts +1 -0
- package/dist/features/magic-context/memory/embedding-openai.d.ts.map +1 -1
- package/dist/features/magic-context/memory/project-identity.d.ts +5 -4
- package/dist/features/magic-context/memory/project-identity.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts +6 -1
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/features/magic-context/v22-deferred-backfill.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-render-epoch.d.ts +12 -1
- package/dist/hooks/magic-context/compartment-render-epoch.d.ts.map +1 -1
- package/dist/hooks/magic-context/drop-stale-reduce-calls.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-resolvers.d.ts +7 -0
- package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
- package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +5 -0
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/module-wire.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-chunk.d.ts +4 -2
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-raw.d.ts +2 -2
- package/dist/hooks/magic-context/read-session-raw.d.ts.map +1 -1
- package/dist/hooks/magic-context/tokenizer-calibration.d.ts +1 -1
- package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +1 -0
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-q5p1aqvv.js → index-mrc0twf3.js} +10 -4
- package/dist/{index-9y5p0d50.js → index-msqr3x6m.js} +1 -1
- package/dist/{index-y5145x8k.js → index-n96ag4rk.js} +15 -1
- package/dist/{index-dgg5y7er.js → index-qm36k34q.js} +55 -12
- package/dist/{index-yhm60r53.js → index-sqp1hz9v.js} +180 -36
- package/dist/{index-rdsaxnf2.js → index-wprsye9w.js} +1 -1
- package/dist/{index-nf9sk8sh.js → index-zx7pmr39.js} +2 -2
- package/dist/index.js +88 -35
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/{read-session-chunk-n072mcq4.js → read-session-chunk-339hg90t.js} +2 -2
- package/dist/{recomp-orchestrator-19tr6zya.js → recomp-orchestrator-0ers6smx.js} +5 -5
- package/dist/shared/rpc-utils.d.ts +7 -0
- package/dist/shared/rpc-utils.d.ts.map +1 -1
- package/dist/shared/transcript.d.ts +2 -0
- package/dist/shared/transcript.d.ts.map +1 -1
- package/dist/shared/user-answer.d.ts +4 -0
- package/dist/shared/user-answer.d.ts.map +1 -0
- package/dist/{transform-postprocess-phase-z2mfc5w1.js → transform-postprocess-phase-ttdkrm6r.js} +5 -5
- package/dist/v2/hooks/payload.d.ts.map +1 -1
- package/dist/v2/hooks/store.d.ts +1 -1
- package/dist/v2/hooks/store.d.ts.map +1 -1
- package/dist/v2/server.js +334 -70
- package/dist/v2/store-reader.d.ts +2 -1
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/{wrapup-orchestrator-sy4m56a7.js → wrapup-orchestrator-x0jvvrqn.js} +6 -6
- package/package.json +1 -1
- package/src/shared/rpc-utils.test.ts +27 -2
- package/src/shared/rpc-utils.ts +44 -15
- package/src/shared/tag-transcript.ts +4 -1
- package/src/shared/transcript.ts +3 -0
- package/src/shared/user-answer.test.ts +40 -0
- package/src/shared/user-answer.ts +17 -0
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
deriveTriggerBudget2,
|
|
38
38
|
resolveHistorianProducerLimits2,
|
|
39
39
|
producerSourceLocalBudget2
|
|
40
|
-
} from "./index-
|
|
40
|
+
} from "./index-msqr3x6m.js";
|
|
41
41
|
import {
|
|
42
42
|
resolveOpenCodeDbPath,
|
|
43
43
|
hasV1MessageTables,
|
|
@@ -102,13 +102,13 @@ import {
|
|
|
102
102
|
getRawSessionTagKeysThrough2,
|
|
103
103
|
getLegacyProtectedTailStartOrdinal2,
|
|
104
104
|
readSessionChunk2
|
|
105
|
-
} from "./index-
|
|
105
|
+
} from "./index-qm36k34q.js";
|
|
106
106
|
import {
|
|
107
107
|
resolveDecisionCalibration,
|
|
108
108
|
providerMass,
|
|
109
109
|
calibrationForModelKey,
|
|
110
110
|
historyLocalBudget
|
|
111
|
-
} from "./index-
|
|
111
|
+
} from "./index-n96ag4rk.js";
|
|
112
112
|
import {
|
|
113
113
|
pushNotification2
|
|
114
114
|
} from "./index-jdxxq8cz.js";
|
|
@@ -8847,6 +8847,8 @@ var transientGitIdentityReuseLoggedDirectories = new Set;
|
|
|
8847
8847
|
var sessionIdentityCache = new Map;
|
|
8848
8848
|
var homeProjectPermission = false;
|
|
8849
8849
|
var homeProjectSkipLogged = false;
|
|
8850
|
+
var pausedIdentityReasons = new Map;
|
|
8851
|
+
var pausedIdentityLogged = new Set;
|
|
8850
8852
|
function setHomeProjectPermission(allowed) {
|
|
8851
8853
|
homeProjectPermission = allowed;
|
|
8852
8854
|
}
|
|
@@ -8945,6 +8947,27 @@ function isGitTimeoutError(error) {
|
|
|
8945
8947
|
const signal = getErrorSignal(error);
|
|
8946
8948
|
return code === "ETIMEDOUT" || signal === "SIGTERM" || signal === "SIGKILL" || getErrorKilled(error);
|
|
8947
8949
|
}
|
|
8950
|
+
function hasUnbornHead(directory) {
|
|
8951
|
+
const options = {
|
|
8952
|
+
cwd: directory,
|
|
8953
|
+
encoding: "utf8",
|
|
8954
|
+
env: { ...process.env, LC_ALL: "C", LANG: "C" },
|
|
8955
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
8956
|
+
timeout: GIT_TIMEOUT_MS,
|
|
8957
|
+
windowsHide: true
|
|
8958
|
+
};
|
|
8959
|
+
try {
|
|
8960
|
+
execFileSyncForIdentity("git", ["rev-parse", "--git-dir"], options);
|
|
8961
|
+
try {
|
|
8962
|
+
execFileSyncForIdentity("git", ["rev-parse", "--verify", "--quiet", "HEAD"], options);
|
|
8963
|
+
return false;
|
|
8964
|
+
} catch (error) {
|
|
8965
|
+
return !isGitTimeoutError(error) && typeof error === "object" && error !== null && "status" in error && error.status === 1 && getErrorStderr(error) === "";
|
|
8966
|
+
}
|
|
8967
|
+
} catch {
|
|
8968
|
+
return false;
|
|
8969
|
+
}
|
|
8970
|
+
}
|
|
8948
8971
|
function classifyGitError(error, rawDirectory) {
|
|
8949
8972
|
if (isGitTimeoutError(error)) {
|
|
8950
8973
|
return new ProjectIdentityError("git_timeout", rawDirectory, `git rev-list timed out after ${GIT_TIMEOUT_MS}ms`, asError(error));
|
|
@@ -8987,7 +9010,11 @@ function resolveProjectIdentityStrict(directory, allowHomeProject = homeProjectP
|
|
|
8987
9010
|
windowsHide: true
|
|
8988
9011
|
});
|
|
8989
9012
|
} catch (error) {
|
|
8990
|
-
|
|
9013
|
+
const classified = classifyGitError(error, directory);
|
|
9014
|
+
if (classified.errorClass === "not_git_repo" && hasUnbornHead(canonical)) {
|
|
9015
|
+
throw new ProjectIdentityError("no_commits", directory, "Git repository has no commits yet");
|
|
9016
|
+
}
|
|
9017
|
+
throw classified;
|
|
8991
9018
|
}
|
|
8992
9019
|
const rootCommit = output.split(`
|
|
8993
9020
|
`).map((line) => line.trim().slice(0, 64)).filter((line) => /^[0-9a-f]{7,64}$/.test(line)).sort()[0];
|
|
@@ -9127,6 +9154,8 @@ function resolveProjectIdentity(directory, allowHomeProject = homeProjectPermiss
|
|
|
9127
9154
|
} catch (error) {
|
|
9128
9155
|
if (error instanceof ProjectIdentityError && shouldUseDirectoryFallback(error)) {
|
|
9129
9156
|
const fallback = directoryFallback(canonical);
|
|
9157
|
+
if (error.errorClass === "no_commits")
|
|
9158
|
+
return fallback;
|
|
9130
9159
|
const hasGitMetadata = hasGitDir(canonical);
|
|
9131
9160
|
if (!hasGitMetadata) {
|
|
9132
9161
|
if (error.errorClass === "permission_denied")
|
|
@@ -9255,9 +9284,18 @@ function resolveProjectIdentityForSession(directory, allowHomeProject = homeProj
|
|
|
9255
9284
|
} catch (error) {
|
|
9256
9285
|
if (!(error instanceof ProjectIdentityError))
|
|
9257
9286
|
throw error;
|
|
9287
|
+
const reason = error.errorClass === "git_identity_unavailable" ? pausedIdentityReasons.get(resolvedDirectory) ?? error.errorClass : error.errorClass;
|
|
9288
|
+
pausedIdentityReasons.set(resolvedDirectory, reason);
|
|
9289
|
+
const logKey = `${resolvedDirectory}\x00${reason}`;
|
|
9290
|
+
if (!pausedIdentityLogged.has(logKey)) {
|
|
9291
|
+
pausedIdentityLogged.add(logKey);
|
|
9292
|
+
log(`[magic-context] memory features paused for ${resolvedDirectory}: ${reason}`);
|
|
9293
|
+
}
|
|
9258
9294
|
identity = undefined;
|
|
9259
9295
|
}
|
|
9260
9296
|
}
|
|
9297
|
+
if (identity !== undefined)
|
|
9298
|
+
pausedIdentityReasons.delete(resolvedDirectory);
|
|
9261
9299
|
sessionIdentityCache.set(cacheKey, {
|
|
9262
9300
|
identity,
|
|
9263
9301
|
revalidateAt: identity?.startsWith("git:") === true ? null : nowMs() + TRANSIENT_FAILURE_COOLDOWN_MS
|
|
@@ -9462,7 +9500,6 @@ var WINDOWS_CIM_PROBE_TIMEOUT_MS = 5000;
|
|
|
9462
9500
|
var WINDOWS_PROCESS_SNAPSHOT_TTL_MS = 2000;
|
|
9463
9501
|
var MAX_ANCESTOR_WALK_DEPTH = 16;
|
|
9464
9502
|
var OPEN_CODE_COMMAND_MARKERS = ["opencode", "node", "bun", "electron"];
|
|
9465
|
-
var TASKLIST_NO_TASKS_PATTERN = /^INFO:\s+No tasks are running which match the specified criteria\.?$/im;
|
|
9466
9503
|
var WINDOWS_CIM_COMMAND = "Get-CimInstance Win32_Process | Select-Object ProcessId,ParentProcessId,Name,CommandLine,CreationDate | ConvertTo-Json -Compress";
|
|
9467
9504
|
var PI_HARNESS_ARC_MARKERS = [
|
|
9468
9505
|
"pi-coding-agent",
|
|
@@ -9556,18 +9593,14 @@ function parseCsvLine(line) {
|
|
|
9556
9593
|
}
|
|
9557
9594
|
function parseTasklistOutput(output) {
|
|
9558
9595
|
const entries = [];
|
|
9559
|
-
let sawHeader = false;
|
|
9560
9596
|
for (const rawLine of output.split(/\r?\n/)) {
|
|
9561
9597
|
const line = rawLine.trim();
|
|
9562
9598
|
if (!line)
|
|
9563
9599
|
continue;
|
|
9564
|
-
if (TASKLIST_NO_TASKS_PATTERN.test(line))
|
|
9565
|
-
return [];
|
|
9566
9600
|
const fields = parseCsvLine(line);
|
|
9567
9601
|
if (!fields)
|
|
9568
9602
|
continue;
|
|
9569
9603
|
if (fields[1]?.trim().toLowerCase() === "pid") {
|
|
9570
|
-
sawHeader = true;
|
|
9571
9604
|
continue;
|
|
9572
9605
|
}
|
|
9573
9606
|
const pid = Number(fields[1]);
|
|
@@ -9575,11 +9608,11 @@ function parseTasklistOutput(output) {
|
|
|
9575
9608
|
continue;
|
|
9576
9609
|
entries.push({ pid, command: fields[0] });
|
|
9577
9610
|
}
|
|
9578
|
-
return entries
|
|
9611
|
+
return entries;
|
|
9579
9612
|
}
|
|
9580
9613
|
function readWindowsProcess(pid) {
|
|
9581
9614
|
try {
|
|
9582
|
-
const output = rpcIdentityExecFileSync("tasklist", ["/FO", "CSV", "/FI", `PID eq ${pid}`], {
|
|
9615
|
+
const output = rpcIdentityExecFileSync("tasklist", ["/FO", "CSV", "/NH", "/FI", `PID eq ${pid}`], {
|
|
9583
9616
|
encoding: "utf8",
|
|
9584
9617
|
timeout: PS_PROBE_TIMEOUT_MS,
|
|
9585
9618
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -9816,7 +9849,11 @@ function tryReadWindowsCimSnapshot(exec) {
|
|
|
9816
9849
|
}
|
|
9817
9850
|
function tryReadWindowsTasklistSnapshot() {
|
|
9818
9851
|
try {
|
|
9819
|
-
const output = execProcessList(rpcProcessListExecFileSync, "tasklist", [
|
|
9852
|
+
const output = execProcessList(rpcProcessListExecFileSync, "tasklist", [
|
|
9853
|
+
"/FO",
|
|
9854
|
+
"CSV",
|
|
9855
|
+
"/NH"
|
|
9856
|
+
]);
|
|
9820
9857
|
const entries = parseTasklistOutput(output);
|
|
9821
9858
|
if (entries === null)
|
|
9822
9859
|
return null;
|
|
@@ -10025,7 +10062,7 @@ function inspectProcessesAsync(forceFresh = false) {
|
|
|
10025
10062
|
snapshot = snapshotFromFacts(facts, "cim");
|
|
10026
10063
|
} catch {}
|
|
10027
10064
|
if (!snapshot) {
|
|
10028
|
-
const entries = parseTasklistOutput(await asyncProcessExec("tasklist", ["/FO", "CSV"], PS_PROBE_TIMEOUT_MS));
|
|
10065
|
+
const entries = parseTasklistOutput(await asyncProcessExec("tasklist", ["/FO", "CSV", "/NH"], PS_PROBE_TIMEOUT_MS));
|
|
10029
10066
|
if (entries)
|
|
10030
10067
|
snapshot = snapshotFromFacts(entries.map(({ pid, command }) => ({
|
|
10031
10068
|
pid,
|
|
@@ -10074,6 +10111,19 @@ function inspectProcessesAsync(forceFresh = false) {
|
|
|
10074
10111
|
});
|
|
10075
10112
|
return asyncInspection;
|
|
10076
10113
|
}
|
|
10114
|
+
function inspectWindowsProcessesSync() {
|
|
10115
|
+
const snapshot = tryReadWindowsCimSnapshot(rpcProcessListExecFileSync) ?? tryReadWindowsTasklistSnapshot();
|
|
10116
|
+
const byPid = new Map(snapshot?.facts.map((fact) => [fact.pid, fact]));
|
|
10117
|
+
return {
|
|
10118
|
+
pi: snapshot ? classifyLivePiSnapshot(snapshot) : { state: "unreadable", processIds: [] },
|
|
10119
|
+
...snapshot ? { processSnapshot: { source: snapshot.source, facts: snapshot.facts } } : {},
|
|
10120
|
+
evidence: (pid) => ({
|
|
10121
|
+
startTime: byPid.get(pid)?.startTime ?? null,
|
|
10122
|
+
commandLine: byPid.get(pid)?.commandLine ?? byPid.get(pid)?.imageName ?? null
|
|
10123
|
+
}),
|
|
10124
|
+
liveness: (pid) => byPid.has(pid) ? "alive" : snapshot ? "dead" : "inconclusive"
|
|
10125
|
+
};
|
|
10126
|
+
}
|
|
10077
10127
|
|
|
10078
10128
|
// src/features/magic-context/context-authority.ts
|
|
10079
10129
|
import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
|
|
@@ -15388,7 +15438,9 @@ function classifyJunkDiscovery(portFile, raw, staleFiles) {
|
|
|
15388
15438
|
log(`[magic-context] removing stale RPC discovery file ${portFile}: ${reason} record older than 10 minutes`);
|
|
15389
15439
|
return null;
|
|
15390
15440
|
}
|
|
15391
|
-
function inspectRpcServerDiscovery(storageDir, processes) {
|
|
15441
|
+
function inspectRpcServerDiscovery(storageDir, processes, options) {
|
|
15442
|
+
const deadline = options?.deadlineMs === undefined ? Number.POSITIVE_INFINITY : Date.now() + options.deadlineMs;
|
|
15443
|
+
let progressAt = Date.now() + 3000;
|
|
15392
15444
|
const rpcRoot = join4(storageDir, "rpc");
|
|
15393
15445
|
let projectEntries;
|
|
15394
15446
|
try {
|
|
@@ -15421,11 +15473,19 @@ function inspectRpcServerDiscovery(storageDir, processes) {
|
|
|
15421
15473
|
if (portFiles.length === 0) {
|
|
15422
15474
|
return { state: "absent", serverPids: [], staleFiles: [] };
|
|
15423
15475
|
}
|
|
15476
|
+
if (!processes && process.platform === "win32")
|
|
15477
|
+
processes = inspectWindowsProcessesSync();
|
|
15424
15478
|
const pids = new Set;
|
|
15425
15479
|
const processByPid = new Map;
|
|
15426
15480
|
const staleFiles = [];
|
|
15427
15481
|
const inconclusivePids = new Set;
|
|
15428
|
-
for (const portFile of portFiles) {
|
|
15482
|
+
for (const [index, portFile] of portFiles.entries()) {
|
|
15483
|
+
if (Date.now() >= deadline)
|
|
15484
|
+
throw new Error(`RPC holder inspection timed out after ${Math.round((options?.deadlineMs ?? 0) / 1000)} seconds (${index}/${portFiles.length} records checked). Close OpenCode and Pi, then retry.`);
|
|
15485
|
+
if (options?.onProgress && Date.now() >= progressAt) {
|
|
15486
|
+
options.onProgress(index, portFiles.length);
|
|
15487
|
+
progressAt = Date.now() + 3000;
|
|
15488
|
+
}
|
|
15429
15489
|
let raw;
|
|
15430
15490
|
try {
|
|
15431
15491
|
raw = rpcDiscoveryFs.readFileSync(portFile, "utf8");
|
|
@@ -15463,7 +15523,7 @@ function inspectRpcServerDiscovery(storageDir, processes) {
|
|
|
15463
15523
|
if (!previous || previous.kind === "process" && detected.kind !== "process") {
|
|
15464
15524
|
processByPid.set(record.pid, detected);
|
|
15465
15525
|
}
|
|
15466
|
-
} else if (identity === "implausible") {
|
|
15526
|
+
} else if (identity === "implausible" && !((processes?.processSnapshot?.source === "cim" || processes?.processSnapshot?.source === "tasklist") && liveness === "alive")) {
|
|
15467
15527
|
staleFiles.push(portFile);
|
|
15468
15528
|
} else {
|
|
15469
15529
|
inconclusivePids.add(record.pid);
|
|
@@ -15614,7 +15674,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
|
|
|
15614
15674
|
{ readRawSessionMessagePage, readRawSessionMessages },
|
|
15615
15675
|
{ startMessageTimeBackfill }
|
|
15616
15676
|
] = await Promise.all([
|
|
15617
|
-
import("./read-session-chunk-
|
|
15677
|
+
import("./read-session-chunk-339hg90t.js"),
|
|
15618
15678
|
import("./message-time-backfill-q374fxc5.js")
|
|
15619
15679
|
]);
|
|
15620
15680
|
await startMessageTimeBackfill(db, Object.assign(readRawSessionMessages, {
|
|
@@ -30072,6 +30132,28 @@ function blockedEmbeddingEndpointReason(endpoint) {
|
|
|
30072
30132
|
}
|
|
30073
30133
|
|
|
30074
30134
|
// src/features/magic-context/memory/embedding-openai.ts
|
|
30135
|
+
function capEmbeddingInput(input, maxInputTokens, purpose) {
|
|
30136
|
+
const ratio = purpose === "query" ? CHUNK_WINDOW_SAFETY_RATIO : 1;
|
|
30137
|
+
const budget = Math.max(1, Math.floor(maxInputTokens * ratio));
|
|
30138
|
+
if (estimateTokens(input) <= budget)
|
|
30139
|
+
return input;
|
|
30140
|
+
let low = 0;
|
|
30141
|
+
let high = input.length;
|
|
30142
|
+
while (low < high) {
|
|
30143
|
+
const mid = Math.ceil((low + high) / 2);
|
|
30144
|
+
if (estimateTokens(input.slice(0, mid)) <= budget)
|
|
30145
|
+
low = mid;
|
|
30146
|
+
else
|
|
30147
|
+
high = mid - 1;
|
|
30148
|
+
}
|
|
30149
|
+
if (low > 0 && low < input.length) {
|
|
30150
|
+
const last = input.charCodeAt(low - 1);
|
|
30151
|
+
const next = input.charCodeAt(low);
|
|
30152
|
+
if (last >= 55296 && last <= 56319 && next >= 56320 && next <= 57343)
|
|
30153
|
+
low -= 1;
|
|
30154
|
+
}
|
|
30155
|
+
return input.slice(0, low);
|
|
30156
|
+
}
|
|
30075
30157
|
function normalizeEndpoint3(endpoint) {
|
|
30076
30158
|
return endpoint?.trim().replace(/\/+$/, "") ?? "";
|
|
30077
30159
|
}
|
|
@@ -30098,6 +30180,7 @@ class OpenAICompatibleEmbeddingProvider {
|
|
|
30098
30180
|
modelMismatchLogged = false;
|
|
30099
30181
|
lastFailureReason = null;
|
|
30100
30182
|
halfOpenProbeInFlight = false;
|
|
30183
|
+
queryTruncationLogged = false;
|
|
30101
30184
|
constructor(options) {
|
|
30102
30185
|
this.endpoint = normalizeEndpoint3(options.endpoint);
|
|
30103
30186
|
this.model = options.model?.trim() ?? "";
|
|
@@ -30151,7 +30234,15 @@ class OpenAICompatibleEmbeddingProvider {
|
|
|
30151
30234
|
return [];
|
|
30152
30235
|
}
|
|
30153
30236
|
const textPrefix = purpose === "query" ? this.queryPrefix : this.documentPrefix;
|
|
30154
|
-
const requestTexts = texts.map((text) =>
|
|
30237
|
+
const requestTexts = texts.map((text) => {
|
|
30238
|
+
const input = `${textPrefix}${text.trim().length === 0 ? " " : text}`;
|
|
30239
|
+
const capped = capEmbeddingInput(input, this.maxInputTokens, purpose);
|
|
30240
|
+
if (purpose === "query" && capped.length < input.length && !this.queryTruncationLogged) {
|
|
30241
|
+
log(`[magic-context] embedding query truncated from ${input.length} to ${capped.length} characters to fit max_input_tokens`);
|
|
30242
|
+
this.queryTruncationLogged = true;
|
|
30243
|
+
}
|
|
30244
|
+
return capped;
|
|
30245
|
+
});
|
|
30155
30246
|
if (!await this.initialize()) {
|
|
30156
30247
|
return Array.from({ length: texts.length }, () => null);
|
|
30157
30248
|
}
|
|
@@ -33426,7 +33517,8 @@ var EPOCH_COMPONENT_PREFIX = "|compartment-render:";
|
|
|
33426
33517
|
var MEMORY_EPOCH_COMPONENT_PREFIX = "|memory-render:";
|
|
33427
33518
|
var MURAL_COMPONENT_PREFIX = "|mural-enabled:";
|
|
33428
33519
|
var BUDGET_COMPONENT_PREFIX = "|render-budgets:";
|
|
33429
|
-
|
|
33520
|
+
var RENDERED_BUDGETS_COMPONENT_PREFIX = "|rendered-budgets:";
|
|
33521
|
+
function encodeCachedM0UpgradeIdentity(upgradeState, compartmentRenderEpoch = COMPARTMENT_RENDER_EPOCH, muralEnabled = null, renderBudgetIdentity = null, memoryRenderEpoch = MEMORY_RENDER_FORMAT_EPOCH, renderedBudgets = null) {
|
|
33430
33522
|
let encoded = upgradeState ?? "";
|
|
33431
33523
|
if (compartmentRenderEpoch !== null) {
|
|
33432
33524
|
encoded += `${EPOCH_COMPONENT_PREFIX}${compartmentRenderEpoch}`;
|
|
@@ -33440,6 +33532,9 @@ function encodeCachedM0UpgradeIdentity(upgradeState, compartmentRenderEpoch = CO
|
|
|
33440
33532
|
if (renderBudgetIdentity !== null) {
|
|
33441
33533
|
encoded += `${BUDGET_COMPONENT_PREFIX}${renderBudgetIdentity}`;
|
|
33442
33534
|
}
|
|
33535
|
+
if (renderedBudgets !== null) {
|
|
33536
|
+
encoded += `${RENDERED_BUDGETS_COMPONENT_PREFIX}${renderedBudgets}`;
|
|
33537
|
+
}
|
|
33443
33538
|
return encoded.length > 0 ? encoded : null;
|
|
33444
33539
|
}
|
|
33445
33540
|
function component(value, prefix) {
|
|
@@ -33458,14 +33553,16 @@ function decodeCachedM0UpgradeIdentity(value) {
|
|
|
33458
33553
|
compartmentRenderEpoch: null,
|
|
33459
33554
|
memoryRenderEpoch: null,
|
|
33460
33555
|
muralEnabled: null,
|
|
33461
|
-
renderBudgetIdentity: null
|
|
33556
|
+
renderBudgetIdentity: null,
|
|
33557
|
+
renderedBudgets: null
|
|
33462
33558
|
};
|
|
33463
33559
|
}
|
|
33464
33560
|
const componentIndexes = [
|
|
33465
33561
|
value.indexOf(EPOCH_COMPONENT_PREFIX),
|
|
33466
33562
|
value.indexOf(MEMORY_EPOCH_COMPONENT_PREFIX),
|
|
33467
33563
|
value.indexOf(MURAL_COMPONENT_PREFIX),
|
|
33468
|
-
value.indexOf(BUDGET_COMPONENT_PREFIX)
|
|
33564
|
+
value.indexOf(BUDGET_COMPONENT_PREFIX),
|
|
33565
|
+
value.indexOf(RENDERED_BUDGETS_COMPONENT_PREFIX)
|
|
33469
33566
|
].filter((index) => index >= 0);
|
|
33470
33567
|
const identityEnd = componentIndexes.length > 0 ? Math.min(...componentIndexes) : value.length;
|
|
33471
33568
|
const upgradeState = value.slice(0, identityEnd);
|
|
@@ -33475,9 +33572,36 @@ function decodeCachedM0UpgradeIdentity(value) {
|
|
|
33475
33572
|
compartmentRenderEpoch: component(value, EPOCH_COMPONENT_PREFIX),
|
|
33476
33573
|
memoryRenderEpoch: component(value, MEMORY_EPOCH_COMPONENT_PREFIX),
|
|
33477
33574
|
muralEnabled: muralComponent === "1" ? true : muralComponent === "0" ? false : null,
|
|
33478
|
-
renderBudgetIdentity: component(value, BUDGET_COMPONENT_PREFIX)
|
|
33575
|
+
renderBudgetIdentity: component(value, BUDGET_COMPONENT_PREFIX),
|
|
33576
|
+
renderedBudgets: component(value, RENDERED_BUDGETS_COMPONENT_PREFIX)
|
|
33479
33577
|
};
|
|
33480
33578
|
}
|
|
33579
|
+
function renderBudgetIdentityChanged(cached, current) {
|
|
33580
|
+
const legacy = /^(m[^-]+)-h\d+$/.exec(cached);
|
|
33581
|
+
if (legacy && current.startsWith("m") && current.includes("-hp")) {
|
|
33582
|
+
return legacy[1] !== current.slice(0, current.indexOf("-h"));
|
|
33583
|
+
}
|
|
33584
|
+
return cached !== current;
|
|
33585
|
+
}
|
|
33586
|
+
function renderedBudgetSnapshot(memoryTokens, historyTokens) {
|
|
33587
|
+
return `m${memoryTokens}-h${historyTokens}`;
|
|
33588
|
+
}
|
|
33589
|
+
function readRenderedBudgets(value) {
|
|
33590
|
+
const match = value?.match(/^m(\d+(?:\.\d+)?)-h(\d+(?:\.\d+)?)$/);
|
|
33591
|
+
if (!match)
|
|
33592
|
+
return null;
|
|
33593
|
+
const memory = Number(match[1]);
|
|
33594
|
+
const history = Number(match[2]);
|
|
33595
|
+
return Number.isFinite(memory) && Number.isFinite(history) ? { memory, history } : null;
|
|
33596
|
+
}
|
|
33597
|
+
function renderedBudgetShrinkReason(cached, current) {
|
|
33598
|
+
const before = readRenderedBudgets(cached);
|
|
33599
|
+
const after = readRenderedBudgets(current);
|
|
33600
|
+
if (!before || !after)
|
|
33601
|
+
return null;
|
|
33602
|
+
const shrunk = (oldTokens, newTokens) => oldTokens - newTokens > Math.max(64, oldTokens * 0.01);
|
|
33603
|
+
return shrunk(before.memory, after.memory) || shrunk(before.history, after.history) ? `render_config:budget_shrink(${cached}→${current})` : null;
|
|
33604
|
+
}
|
|
33481
33605
|
|
|
33482
33606
|
// src/hooks/magic-context/decay-curve.ts
|
|
33483
33607
|
var H50 = 24;
|
|
@@ -34207,8 +34331,8 @@ function lastCompartmentBoundaryId(compartments) {
|
|
|
34207
34331
|
}
|
|
34208
34332
|
var DEFAULT_HISTORY_BUDGET_TOKENS = 60000;
|
|
34209
34333
|
var DEFAULT_MEMORY_BUDGET_TOKENS = 8000;
|
|
34210
|
-
function renderBudgetIdentity(memoryBudget, historyBudget) {
|
|
34211
|
-
return `m${memoryBudget ?? DEFAULT_MEMORY_BUDGET_TOKENS}-h${historyBudget ?? DEFAULT_HISTORY_BUDGET_TOKENS}`;
|
|
34334
|
+
function renderBudgetIdentity(memoryBudget, historyBudget, historyPolicy) {
|
|
34335
|
+
return `m${memoryBudget ?? DEFAULT_MEMORY_BUDGET_TOKENS}-h${historyPolicy ?? historyBudget ?? DEFAULT_HISTORY_BUDGET_TOKENS}`;
|
|
34212
34336
|
}
|
|
34213
34337
|
var DEFAULT_USER_PROFILE_BUDGET_TOKENS = 4000;
|
|
34214
34338
|
var MAX_FORCED_MEMORIES_PER_DELTA = 10;
|
|
@@ -34474,7 +34598,8 @@ function readCurrentM0SnapshotMarkersUncached(args) {
|
|
|
34474
34598
|
modelKey: piModelRefToCanonical(hard.modelKey),
|
|
34475
34599
|
projectIdentity: args.projectPath ?? null,
|
|
34476
34600
|
muralEnabled: args.memoryEnabled !== false && args.muralEnabled === true,
|
|
34477
|
-
renderBudgetIdentity: renderBudgetIdentity(args.memoryInjectionBudgetTokens, args.historyBudgetTokens)
|
|
34601
|
+
renderBudgetIdentity: renderBudgetIdentity(args.memoryInjectionBudgetTokens, args.historyBudgetTokens, args.historyBudgetPolicyIdentity),
|
|
34602
|
+
renderedBudgets: renderedBudgetSnapshot(args.memoryInjectionBudgetTokens ?? DEFAULT_MEMORY_BUDGET_TOKENS, args.historyBudgetTokens ?? DEFAULT_HISTORY_BUDGET_TOKENS)
|
|
34478
34603
|
}
|
|
34479
34604
|
};
|
|
34480
34605
|
}
|
|
@@ -34488,7 +34613,8 @@ function refreshVolatileMarkerInputs(markers, args) {
|
|
|
34488
34613
|
modelKey: hard.modelKey,
|
|
34489
34614
|
projectIdentity: args.projectPath ?? null,
|
|
34490
34615
|
muralEnabled: args.memoryEnabled !== false && args.muralEnabled === true,
|
|
34491
|
-
renderBudgetIdentity: renderBudgetIdentity(args.memoryInjectionBudgetTokens, args.historyBudgetTokens)
|
|
34616
|
+
renderBudgetIdentity: renderBudgetIdentity(args.memoryInjectionBudgetTokens, args.historyBudgetTokens, args.historyBudgetPolicyIdentity),
|
|
34617
|
+
renderedBudgets: renderedBudgetSnapshot(args.memoryInjectionBudgetTokens ?? DEFAULT_MEMORY_BUDGET_TOKENS, args.historyBudgetTokens ?? DEFAULT_HISTORY_BUDGET_TOKENS)
|
|
34492
34618
|
};
|
|
34493
34619
|
}
|
|
34494
34620
|
function readCurrentM0SnapshotMarkers(args) {
|
|
@@ -34558,7 +34684,8 @@ function snapshotMarkersFromCachedM0(state) {
|
|
|
34558
34684
|
projectIdentity: state.cachedM0ProjectIdentity ?? null,
|
|
34559
34685
|
muralHash: state.cachedM0MuralHash ?? null,
|
|
34560
34686
|
muralEnabled: cachedUpgradeIdentity.muralEnabled,
|
|
34561
|
-
renderBudgetIdentity: cachedUpgradeIdentity.renderBudgetIdentity
|
|
34687
|
+
renderBudgetIdentity: cachedUpgradeIdentity.renderBudgetIdentity,
|
|
34688
|
+
renderedBudgets: cachedUpgradeIdentity.renderedBudgets
|
|
34562
34689
|
};
|
|
34563
34690
|
}
|
|
34564
34691
|
var MEMORY_DERIVED_BLOCK_PATTERN = /<(?:project-memory|user-profile|new-user-profile|memory-updates|memory-mural)(?:>|\s)/;
|
|
@@ -34574,14 +34701,26 @@ function mustMaterialize(args) {
|
|
|
34574
34701
|
const current = readCurrentM0SnapshotMarkers(args);
|
|
34575
34702
|
const cachedUpgradeIdentity = decodeCachedM0UpgradeIdentity(args.state.cachedM0UpgradeState);
|
|
34576
34703
|
if (args.memoryEnabled === false && cachedMemoryDerivedSurfacePresent(args.state)) {
|
|
34577
|
-
return { value: true, reason: "render_config" };
|
|
34704
|
+
return { value: true, reason: "render_config:memory_disabled" };
|
|
34578
34705
|
}
|
|
34579
34706
|
if (cachedUpgradeIdentity.compartmentRenderEpoch !== current.compartmentRenderEpoch) {
|
|
34580
34707
|
return { value: true, reason: "compartment_render_epoch" };
|
|
34581
34708
|
}
|
|
34582
|
-
if (cachedUpgradeIdentity.muralEnabled !== null && cachedUpgradeIdentity.muralEnabled !== current.muralEnabled
|
|
34583
|
-
return {
|
|
34709
|
+
if (cachedUpgradeIdentity.muralEnabled !== null && cachedUpgradeIdentity.muralEnabled !== current.muralEnabled) {
|
|
34710
|
+
return {
|
|
34711
|
+
value: true,
|
|
34712
|
+
reason: `render_config:mural(${cachedUpgradeIdentity.muralEnabled}→${current.muralEnabled})`
|
|
34713
|
+
};
|
|
34584
34714
|
}
|
|
34715
|
+
if (cachedUpgradeIdentity.renderBudgetIdentity !== null && current.renderBudgetIdentity != null && renderBudgetIdentityChanged(cachedUpgradeIdentity.renderBudgetIdentity, current.renderBudgetIdentity)) {
|
|
34716
|
+
return {
|
|
34717
|
+
value: true,
|
|
34718
|
+
reason: `render_config:budget(${cachedUpgradeIdentity.renderBudgetIdentity}→${current.renderBudgetIdentity})`
|
|
34719
|
+
};
|
|
34720
|
+
}
|
|
34721
|
+
const budgetShrinkReason = renderedBudgetShrinkReason(cachedUpgradeIdentity.renderedBudgets, current.renderedBudgets);
|
|
34722
|
+
if (budgetShrinkReason)
|
|
34723
|
+
return { value: true, reason: budgetShrinkReason };
|
|
34585
34724
|
const canonicalHardModelKey = piModelRefToCanonical(hard.modelKey);
|
|
34586
34725
|
const canonicalCachedModelKey = piModelRefToCanonical(args.state.cachedM0ModelKey ?? "");
|
|
34587
34726
|
if (canonicalHardModelKey !== "" && canonicalHardModelKey !== canonicalCachedModelKey) {
|
|
@@ -34934,7 +35073,7 @@ function applyMarkersToState(state, m0Bytes, markers, m1Bytes) {
|
|
|
34934
35073
|
state.cachedM0ProjectDocsHash = markers.projectDocsHash;
|
|
34935
35074
|
state.cachedM0MaterializedAt = markers.materializedAt;
|
|
34936
35075
|
state.cachedM0SessionFactsVersion = markers.sessionFactsVersion;
|
|
34937
|
-
state.cachedM0UpgradeState = encodeCachedM0UpgradeIdentity(markers.upgradeState, markers.compartmentRenderEpoch, markers.muralEnabled, markers.renderBudgetIdentity, markers.memoryRenderEpoch);
|
|
35076
|
+
state.cachedM0UpgradeState = encodeCachedM0UpgradeIdentity(markers.upgradeState, markers.compartmentRenderEpoch, markers.muralEnabled, markers.renderBudgetIdentity, markers.memoryRenderEpoch, markers.renderedBudgets ?? null);
|
|
34938
35077
|
state.cachedM0SystemHash = markers.systemHash;
|
|
34939
35078
|
state.cachedM0ToolSetHash = markers.toolSetHash;
|
|
34940
35079
|
state.cachedM0ModelKey = markers.modelKey;
|
|
@@ -34986,6 +35125,7 @@ function materializeM0(options) {
|
|
|
34986
35125
|
muralEnabled: options.muralEnabled,
|
|
34987
35126
|
memoryInjectionBudgetTokens: options.memoryInjectionBudgetTokens,
|
|
34988
35127
|
historyBudgetTokens: options.historyBudgetTokens,
|
|
35128
|
+
historyBudgetPolicyIdentity: options.historyBudgetPolicyIdentity,
|
|
34989
35129
|
hardSignals: options.hardSignals,
|
|
34990
35130
|
workspaceIdentitySet: {
|
|
34991
35131
|
identities: workspace.identities,
|
|
@@ -35086,7 +35226,8 @@ function materializeM0(options) {
|
|
|
35086
35226
|
modelKey: snapshotMarkers.modelKey,
|
|
35087
35227
|
projectIdentity: projectPath ?? null,
|
|
35088
35228
|
muralEnabled: snapshotMarkers.muralEnabled,
|
|
35089
|
-
renderBudgetIdentity: snapshotMarkers.renderBudgetIdentity
|
|
35229
|
+
renderBudgetIdentity: snapshotMarkers.renderBudgetIdentity,
|
|
35230
|
+
renderedBudgets: snapshotMarkers.renderedBudgets
|
|
35090
35231
|
};
|
|
35091
35232
|
const memoryEpochStale = current.workspaceFingerprint !== null || snapshotMarkers.workspaceFingerprint !== null ? current.workspaceFingerprint !== snapshotMarkers.workspaceFingerprint : current.projectMemoryEpoch !== snapshotMarkers.projectMemoryEpoch;
|
|
35092
35233
|
const stale = memoryEpochStale || current.projectUserProfileVersion !== snapshotMarkers.projectUserProfileVersion || current.maxCompartmentSeq !== snapshotMarkers.maxCompartmentSeq || current.maxMutationId !== snapshotMarkers.maxMutationId || current.maxMemoryMutationId !== snapshotMarkers.maxMemoryMutationId || current.sessionFactsVersion !== snapshotMarkers.sessionFactsVersion || current.upgradeState !== snapshotMarkers.upgradeState || (current.projectIdentity ?? null) !== (snapshotMarkers.projectIdentity ?? null);
|
|
@@ -35121,7 +35262,7 @@ function materializeM0(options) {
|
|
|
35121
35262
|
projectDocsHash: snapshotMarkers.projectDocsHash,
|
|
35122
35263
|
materializedAt: snapshotMarkers.materializedAt,
|
|
35123
35264
|
sessionFactsVersion: snapshotMarkers.sessionFactsVersion,
|
|
35124
|
-
upgradeState: encodeCachedM0UpgradeIdentity(snapshotMarkers.upgradeState, snapshotMarkers.compartmentRenderEpoch, snapshotMarkers.muralEnabled, snapshotMarkers.renderBudgetIdentity, snapshotMarkers.memoryRenderEpoch),
|
|
35265
|
+
upgradeState: encodeCachedM0UpgradeIdentity(snapshotMarkers.upgradeState, snapshotMarkers.compartmentRenderEpoch, snapshotMarkers.muralEnabled, snapshotMarkers.renderBudgetIdentity, snapshotMarkers.memoryRenderEpoch, snapshotMarkers.renderedBudgets ?? null),
|
|
35125
35266
|
systemHash: snapshotMarkers.systemHash,
|
|
35126
35267
|
toolSetHash: snapshotMarkers.toolSetHash,
|
|
35127
35268
|
modelKey: snapshotMarkers.modelKey,
|
|
@@ -35384,7 +35525,8 @@ function markersFromCachedRow(row) {
|
|
|
35384
35525
|
projectIdentity: row.cached_m0_project_identity ?? null,
|
|
35385
35526
|
muralHash: row.cached_m0_mural_hash ?? null,
|
|
35386
35527
|
muralEnabled: cachedUpgradeIdentity.muralEnabled,
|
|
35387
|
-
renderBudgetIdentity: cachedUpgradeIdentity.renderBudgetIdentity
|
|
35528
|
+
renderBudgetIdentity: cachedUpgradeIdentity.renderBudgetIdentity,
|
|
35529
|
+
renderedBudgets: cachedUpgradeIdentity.renderedBudgets
|
|
35388
35530
|
};
|
|
35389
35531
|
}
|
|
35390
35532
|
function cachedRowMatchesState(row, state) {
|
|
@@ -35409,7 +35551,7 @@ function applyCachedRowToState(state, row) {
|
|
|
35409
35551
|
state.cachedM0ProjectDocsHash = markers.projectDocsHash;
|
|
35410
35552
|
state.cachedM0MaterializedAt = markers.materializedAt;
|
|
35411
35553
|
state.cachedM0SessionFactsVersion = markers.sessionFactsVersion;
|
|
35412
|
-
state.cachedM0UpgradeState = encodeCachedM0UpgradeIdentity(markers.upgradeState, markers.compartmentRenderEpoch, markers.muralEnabled, markers.renderBudgetIdentity, markers.memoryRenderEpoch);
|
|
35554
|
+
state.cachedM0UpgradeState = encodeCachedM0UpgradeIdentity(markers.upgradeState, markers.compartmentRenderEpoch, markers.muralEnabled, markers.renderBudgetIdentity, markers.memoryRenderEpoch, markers.renderedBudgets ?? null);
|
|
35413
35555
|
state.cachedM0SystemHash = markers.systemHash;
|
|
35414
35556
|
state.cachedM0ToolSetHash = markers.toolSetHash;
|
|
35415
35557
|
state.cachedM0ModelKey = markers.modelKey;
|
|
@@ -35502,6 +35644,7 @@ function renderFreshM0NonPersisted(options) {
|
|
|
35502
35644
|
muralEnabled: options.muralEnabled,
|
|
35503
35645
|
memoryInjectionBudgetTokens: options.memoryInjectionBudgetTokens,
|
|
35504
35646
|
historyBudgetTokens: options.historyBudgetTokens,
|
|
35647
|
+
historyBudgetPolicyIdentity: options.historyBudgetPolicyIdentity,
|
|
35505
35648
|
hardSignals: options.hardSignals,
|
|
35506
35649
|
workspaceIdentitySet: {
|
|
35507
35650
|
identities: workspace.identities,
|
|
@@ -35871,7 +36014,8 @@ function injectM0M1(options) {
|
|
|
35871
36014
|
memoryEnabled: options.memoryEnabled,
|
|
35872
36015
|
muralEnabled: options.muralEnabled,
|
|
35873
36016
|
memoryInjectionBudgetTokens: options.memoryInjectionBudgetTokens,
|
|
35874
|
-
historyBudgetTokens: options.historyBudgetTokens
|
|
36017
|
+
historyBudgetTokens: options.historyBudgetTokens,
|
|
36018
|
+
historyBudgetPolicyIdentity: options.historyBudgetPolicyIdentity
|
|
35875
36019
|
});
|
|
35876
36020
|
let rematerialized = false;
|
|
35877
36021
|
let contentionExhausted = false;
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
getActiveCompartmentRun,
|
|
22
22
|
markActiveCompartmentRunPublished,
|
|
23
23
|
registerActiveCompartmentRun
|
|
24
|
-
} from "./index-
|
|
24
|
+
} from "./index-sqp1hz9v.js";
|
|
25
25
|
import {
|
|
26
26
|
pushNotification2
|
|
27
27
|
} from "./index-jdxxq8cz.js";
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
import {
|
|
32
32
|
setRecompStarting2,
|
|
33
33
|
setRecompTerminal2
|
|
34
|
-
} from "./index-
|
|
34
|
+
} from "./index-wprsye9w.js";
|
|
35
35
|
|
|
36
36
|
// src/hooks/magic-context/wrapup-orchestrator.ts
|
|
37
37
|
import * as crypto from "node:crypto";
|