@cortexkit/opencode-magic-context 0.49.82 → 0.49.83
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/{context-00f1hdz2.js → context-xmyke353.js} +8 -3
- package/dist/features/magic-context/dreamer/map-memories-retry.d.ts +18 -0
- package/dist/features/magic-context/dreamer/map-memories-retry.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts +2 -0
- package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-gates.d.ts +1 -1
- package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-registry.d.ts +7 -0
- package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts +9 -0
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
- package/dist/{index-jvr9ba9y.js → index-eyk7msgw.js} +193 -122
- package/dist/{index-nda0zgna.js → index-kknjvmpx.js} +2 -1
- package/dist/index.js +4 -4
- package/dist/{task-config-t6bpyka7.js → task-config-qt6n4bxm.js} +1 -1
- package/dist/v2/{context-gwkgh0wd.js → context-zn18k0yk.js} +280 -202
- package/dist/v2/retrospective-raw-provider.d.ts.map +1 -1
- package/dist/v2/{server-92g7d776.js → server-2kswss3d.js} +2 -1
- package/dist/v2/server.js +2 -2
- package/dist/v2/{task-config-7md27rx8.js → task-config-ex2vajr2.js} +1 -1
- package/package.json +1 -1
- package/src/features/magic-context/dreamer/task-registry.ts +8 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CANONICAL_DREAM_TASKS,
|
|
3
|
+
MIN_POOL_TO_CLASSIFY,
|
|
3
4
|
DREAM_TASK_CAPABILITIES,
|
|
4
5
|
toolLoopDreamTasks,
|
|
5
6
|
formatDreamTaskBacklogs,
|
|
@@ -13,7 +14,7 @@ import {
|
|
|
13
14
|
compareTaskOrder,
|
|
14
15
|
buildDreamTaskRuntimeConfigs2,
|
|
15
16
|
userMemoryCollectionEnabled2
|
|
16
|
-
} from "./index-
|
|
17
|
+
} from "./index-kknjvmpx.js";
|
|
17
18
|
import {
|
|
18
19
|
getHarness2,
|
|
19
20
|
harnessOwnsOpenCodeStore2
|
|
@@ -1965,6 +1966,33 @@ ${buildFrictionGatePrompt({ userLines })}`;
|
|
|
1965
1966
|
function retrospectiveGatePromptTokens(messages) {
|
|
1966
1967
|
return estimateTokens(retrospectiveGatePrompt(messages));
|
|
1967
1968
|
}
|
|
1969
|
+
function admitRetrospectiveCohorts(rows, firstUnreadTs, maxMessages, promptInputLimitTokens) {
|
|
1970
|
+
const kept = [];
|
|
1971
|
+
let start = 0;
|
|
1972
|
+
for (let first = rows[start];first && first.ts < firstUnreadTs; first = rows[start]) {
|
|
1973
|
+
const ts = first.ts;
|
|
1974
|
+
let end = start + 1;
|
|
1975
|
+
while (end < rows.length && rows[end]?.ts === ts)
|
|
1976
|
+
end += 1;
|
|
1977
|
+
const cohort = rows.slice(start, end);
|
|
1978
|
+
const tooManyRows = end > maxMessages;
|
|
1979
|
+
const tooManyTokens = !tooManyRows && promptInputLimitTokens !== undefined && retrospectiveGatePromptTokens([...kept, ...cohort]) > promptInputLimitTokens;
|
|
1980
|
+
if (tooManyRows || tooManyTokens) {
|
|
1981
|
+
return {
|
|
1982
|
+
kept,
|
|
1983
|
+
budgetTruncated: tooManyTokens,
|
|
1984
|
+
...kept.length === 0 ? { oversized: { ts, rows: cohort } } : {}
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1987
|
+
kept.push(...cohort);
|
|
1988
|
+
start = end;
|
|
1989
|
+
}
|
|
1990
|
+
return { kept, budgetTruncated: false };
|
|
1991
|
+
}
|
|
1992
|
+
function logSkippedRetrospectiveCohort(sessionIds, ts, count, lowerBound) {
|
|
1993
|
+
const sessions = [...new Set(sessionIds)].join(",");
|
|
1994
|
+
log2(`[dreamer] retrospective: oversized timestamp cohort sessionIds=${sessions} timestamp=${ts} ${lowerBound ? "skippedAtLeast" : "skipped"}=${count}`);
|
|
1995
|
+
}
|
|
1968
1996
|
async function readRetrospectiveScanWindow(provider, projectIdentity, watermarkMs, overlapUserCount, options) {
|
|
1969
1997
|
const maxMessages = options?.maxMessagesPerRun ?? RETROSPECTIVE_MAX_MESSAGES_PER_RUN;
|
|
1970
1998
|
const capPerSession = options?.capPerSession ?? RETROSPECTIVE_MAX_MESSAGES_PER_SESSION;
|
|
@@ -1994,59 +2022,57 @@ async function readRetrospectiveScanWindow(provider, projectIdentity, watermarkM
|
|
|
1994
2022
|
if (sessionsToRead.length > 0) {
|
|
1995
2023
|
sinceReads.push(...await Promise.all(sessionsToRead.map((session) => provider.readUserMessagesSince(session.sessionId, scanSinceMs, capPerSession))));
|
|
1996
2024
|
}
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
if (!row)
|
|
2014
|
-
continue;
|
|
2015
|
-
const candidate = [...keptSince, row];
|
|
2016
|
-
if (retrospectiveGatePromptTokens(candidate) <= promptInputLimitTokens) {
|
|
2017
|
-
keptSince.push(row);
|
|
2018
|
-
continue;
|
|
2019
|
-
}
|
|
2020
|
-
budgetDropped = countCandidates.slice(index);
|
|
2021
|
-
break;
|
|
2025
|
+
const allSince = sinceReads.flatMap((read) => read.messages).filter((message) => message.ts > scanSinceMs).map(clampRetrospectiveMessage).sort((a, b) => a.ts - b.ts || a.ordinal - b.ordinal);
|
|
2026
|
+
let unknownBoundary = !!firstExcludedSession && firstExcludedPendingTs === undefined;
|
|
2027
|
+
let firstUnreadTs = firstExcludedPendingTs ?? Number.POSITIVE_INFINITY;
|
|
2028
|
+
const oversizedSessions = new Map;
|
|
2029
|
+
for (const [index, read] of sinceReads.entries()) {
|
|
2030
|
+
if (!read.truncated)
|
|
2031
|
+
continue;
|
|
2032
|
+
const unreadTs = read.firstOmittedTs ?? read.messages.at(-1)?.ts;
|
|
2033
|
+
if (unreadTs === undefined) {
|
|
2034
|
+
unknownBoundary = true;
|
|
2035
|
+
continue;
|
|
2036
|
+
}
|
|
2037
|
+
firstUnreadTs = Math.min(firstUnreadTs, unreadTs);
|
|
2038
|
+
const sessionId = sessionsToRead[index]?.sessionId;
|
|
2039
|
+
if (sessionId !== undefined && read.firstOmittedTs !== undefined && read.firstOmittedTs === oldestBySession?.get(sessionId)) {
|
|
2040
|
+
oversizedSessions.set(sessionId, read.firstOmittedTs);
|
|
2022
2041
|
}
|
|
2023
2042
|
}
|
|
2024
|
-
const
|
|
2043
|
+
const {
|
|
2044
|
+
kept: keptSince,
|
|
2045
|
+
budgetTruncated,
|
|
2046
|
+
oversized
|
|
2047
|
+
} = admitRetrospectiveCohorts(allSince, unknownBoundary ? scanSinceMs : firstUnreadTs, maxMessages, promptInputLimitTokens);
|
|
2048
|
+
const lastKept = keptSince.at(-1);
|
|
2025
2049
|
let maxScannedTs = scanSinceMs;
|
|
2026
|
-
if (
|
|
2027
|
-
|
|
2028
|
-
maxScannedTs =
|
|
2050
|
+
if (!unknownBoundary) {
|
|
2051
|
+
if (oversized) {
|
|
2052
|
+
maxScannedTs = oversized.ts;
|
|
2053
|
+
logSkippedRetrospectiveCohort(oversized.rows.map(({ sessionId }) => sessionId), maxScannedTs, oversized.rows.length, false);
|
|
2054
|
+
} else if (lastKept) {
|
|
2055
|
+
maxScannedTs = lastKept.ts;
|
|
2056
|
+
} else if (Number.isFinite(firstUnreadTs)) {
|
|
2057
|
+
const blockedSessions = sessions.filter(({ session }) => oldestBySession?.get(session.sessionId) === firstUnreadTs);
|
|
2058
|
+
const hitSessionReadCap = blockedSessions.some(({ session }) => oversizedSessions.get(session.sessionId) === firstUnreadTs);
|
|
2059
|
+
if (hitSessionReadCap || blockedSessions.length > sessionLimit) {
|
|
2060
|
+
maxScannedTs = firstUnreadTs;
|
|
2061
|
+
logSkippedRetrospectiveCohort(blockedSessions.map(({ session }) => session.sessionId), maxScannedTs, Math.max(blockedSessions.length, hitSessionReadCap ? capPerSession + 1 : 0), true);
|
|
2062
|
+
} else {
|
|
2063
|
+
maxScannedTs = Math.max(scanSinceMs, firstUnreadTs - 1);
|
|
2064
|
+
}
|
|
2065
|
+
} else if (oldestBySession && allSince.length === 0) {
|
|
2066
|
+
for (const { session } of eligibleSessions) {
|
|
2067
|
+
maxScannedTs = Math.max(maxScannedTs, session.updatedAt ?? scanSinceMs);
|
|
2068
|
+
}
|
|
2029
2069
|
}
|
|
2030
2070
|
}
|
|
2031
|
-
for (const row of keptSince) {
|
|
2032
|
-
if (row.ts > maxScannedTs)
|
|
2033
|
-
maxScannedTs = row.ts;
|
|
2034
|
-
}
|
|
2035
|
-
let frontier = saturatedFrontier;
|
|
2036
|
-
const firstDropped = droppedSince[0];
|
|
2037
|
-
if (firstDropped)
|
|
2038
|
-
frontier = Math.min(frontier, firstDropped.ts - 1);
|
|
2039
|
-
if (typeof firstExcludedPendingTs === "number") {
|
|
2040
|
-
frontier = Math.min(frontier, firstExcludedPendingTs - 1);
|
|
2041
|
-
} else if (typeof firstExcludedSession?.updatedAt === "number") {
|
|
2042
|
-
frontier = Math.min(frontier, firstExcludedSession.updatedAt - 1);
|
|
2043
|
-
}
|
|
2044
|
-
maxScannedTs = Math.max(scanSinceMs, Math.min(maxScannedTs, frontier));
|
|
2045
2071
|
const keptSessionIds = new Set(keptSince.map((message) => message.sessionId));
|
|
2046
2072
|
const overlapSessions = sessionsToRead.filter((session) => keptSessionIds.has(session.sessionId));
|
|
2047
2073
|
const overlapBatches = overlapUserCount > 0 && watermarkMs > 0 && watermarkMs >= recencyCutoffMs ? await Promise.all(overlapSessions.map((session) => provider.readUserMessagesBefore(session.sessionId, watermarkMs, overlapUserCount))) : [];
|
|
2048
2074
|
const seen = new Set;
|
|
2049
|
-
const merged = [];
|
|
2075
|
+
const merged = [...keptSince];
|
|
2050
2076
|
const appendUnique = (row) => {
|
|
2051
2077
|
const key = `${row.sessionId}\x00${row.ts}\x00${row.role}\x00${row.toolName ?? ""}`;
|
|
2052
2078
|
if (seen.has(key))
|
|
@@ -2055,9 +2081,7 @@ async function readRetrospectiveScanWindow(provider, projectIdentity, watermarkM
|
|
|
2055
2081
|
merged.push(row);
|
|
2056
2082
|
return true;
|
|
2057
2083
|
};
|
|
2058
|
-
|
|
2059
|
-
appendUnique(row);
|
|
2060
|
-
const overlapRows = overlapBatches.flat().filter((message) => message.ts >= recencyCutoffMs).map(clampRetrospectiveMessage).sort((a, b) => a.ts - b.ts || a.ordinal - b.ordinal);
|
|
2084
|
+
const overlapRows = overlapBatches.flat().filter((message) => message.ts >= recencyCutoffMs && message.ts <= watermarkMs).map(clampRetrospectiveMessage).sort((a, b) => a.ts - b.ts || a.ordinal - b.ordinal);
|
|
2061
2085
|
for (const row of overlapRows) {
|
|
2062
2086
|
const beforeLength = merged.length;
|
|
2063
2087
|
if (!appendUnique(row))
|
|
@@ -2077,7 +2101,7 @@ async function readRetrospectiveScanWindow(provider, projectIdentity, watermarkM
|
|
|
2077
2101
|
maxScannedTs,
|
|
2078
2102
|
promptTokens,
|
|
2079
2103
|
...promptInputLimitTokens === undefined ? {} : { promptInputLimitTokens },
|
|
2080
|
-
budgetTruncated
|
|
2104
|
+
budgetTruncated
|
|
2081
2105
|
};
|
|
2082
2106
|
} finally {
|
|
2083
2107
|
provider.dispose?.();
|
|
@@ -2110,7 +2134,12 @@ function readOpenCodeMessagesSince(db, sessionId, sinceMs, capPerSession) {
|
|
|
2110
2134
|
LIMIT ?`).all(sessionId, sinceMs, limit + 1);
|
|
2111
2135
|
const truncated = rows.length > limit;
|
|
2112
2136
|
const kept = truncated ? rows.slice(0, limit) : rows;
|
|
2113
|
-
|
|
2137
|
+
const firstOmitted = rows[limit];
|
|
2138
|
+
return {
|
|
2139
|
+
messages: normalizeOpenCodeRows(db, sessionId, kept),
|
|
2140
|
+
truncated,
|
|
2141
|
+
...firstOmitted ? { firstOmittedTs: firstOmitted.time_created } : {}
|
|
2142
|
+
};
|
|
2114
2143
|
}
|
|
2115
2144
|
function readOpenCodeOldestMessageTimesSince(db, sessionIds, sinceMs) {
|
|
2116
2145
|
const result = new Map;
|
|
@@ -2406,7 +2435,7 @@ function recordRetrospectiveWindowProcessed(db, projectPath, windowKey) {
|
|
|
2406
2435
|
}
|
|
2407
2436
|
|
|
2408
2437
|
// src/features/magic-context/dreamer/task-executor.ts
|
|
2409
|
-
import { createHash as
|
|
2438
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
2410
2439
|
import { existsSync as existsSync5, readFileSync as readFileSync3 } from "node:fs";
|
|
2411
2440
|
|
|
2412
2441
|
// src/features/magic-context/mural/compress-cues.ts
|
|
@@ -3482,7 +3511,6 @@ async function readFailedChildMessages(client, sessionId, directory) {
|
|
|
3482
3511
|
}
|
|
3483
3512
|
|
|
3484
3513
|
// src/features/magic-context/dreamer/classify.ts
|
|
3485
|
-
var MIN_POOL_TO_CLASSIFY = 10;
|
|
3486
3514
|
var FULL_POOL_CEILING = 100;
|
|
3487
3515
|
var STAGE3_ANCHOR_COUNT = 30;
|
|
3488
3516
|
var CLASSIFY_CHUNK_SIZE = 100;
|
|
@@ -6989,7 +7017,7 @@ function snapshotMaintainDocsFiles(docsDir) {
|
|
|
6989
7017
|
}
|
|
6990
7018
|
|
|
6991
7019
|
// src/features/magic-context/dreamer/map-memories.ts
|
|
6992
|
-
import { createHash as
|
|
7020
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
6993
7021
|
|
|
6994
7022
|
// src/features/magic-context/dreamer/map-memories-prompt.ts
|
|
6995
7023
|
import { execFile as execFile2 } from "node:child_process";
|
|
@@ -7194,17 +7222,14 @@ function parsePartialMapMemoriesManifest(text, expectedIds) {
|
|
|
7194
7222
|
return [...entries.values()];
|
|
7195
7223
|
}
|
|
7196
7224
|
|
|
7197
|
-
// src/features/magic-context/dreamer/map-memories.ts
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
var CONSECUTIVE_TIMEOUT_LIMIT2 = 2;
|
|
7201
|
-
var MAX_INDEPENDENT_REQUEUE_PER_RUN = MAP_BATCH_SIZE;
|
|
7202
|
-
function retryKey(project) {
|
|
7225
|
+
// src/features/magic-context/dreamer/map-memories-retry.ts
|
|
7226
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
7227
|
+
function mapMemoryRetryKey(project) {
|
|
7203
7228
|
return `map-memories:retry:${project}`;
|
|
7204
7229
|
}
|
|
7205
|
-
function
|
|
7230
|
+
function readMapMemoryRetries(db, project) {
|
|
7206
7231
|
try {
|
|
7207
|
-
const parsed = JSON.parse(getDreamState(db,
|
|
7232
|
+
const parsed = JSON.parse(getDreamState(db, mapMemoryRetryKey(project)) ?? "{}");
|
|
7208
7233
|
if (!isRecord(parsed))
|
|
7209
7234
|
return {};
|
|
7210
7235
|
const retries = {};
|
|
@@ -7226,10 +7251,26 @@ function contentKey(memory) {
|
|
|
7226
7251
|
return createHash5("sha256").update(`${memory.category}
|
|
7227
7252
|
${memory.content}`).digest("hex");
|
|
7228
7253
|
}
|
|
7229
|
-
function
|
|
7254
|
+
function isMapMemoryDeferred(memory, retries, now = Date.now()) {
|
|
7230
7255
|
const retry = retries[memory.id];
|
|
7231
|
-
return !!retry && retry.
|
|
7256
|
+
return !!retry && retry.deferUntil > now && retry.content === contentKey(memory);
|
|
7232
7257
|
}
|
|
7258
|
+
function nextMapMemoryRetry(memory, prior) {
|
|
7259
|
+
const content = contentKey(memory);
|
|
7260
|
+
const failures = (prior?.content === content ? prior.failures : 0) + 1;
|
|
7261
|
+
const maxWaitHours = 7 * 24;
|
|
7262
|
+
return {
|
|
7263
|
+
content,
|
|
7264
|
+
failures,
|
|
7265
|
+
deferUntil: failures < 2 ? 0 : Date.now() + Math.min(maxWaitHours, 2 ** (failures - 2)) * 3600000
|
|
7266
|
+
};
|
|
7267
|
+
}
|
|
7268
|
+
|
|
7269
|
+
// src/features/magic-context/dreamer/map-memories.ts
|
|
7270
|
+
var MAP_BATCH_SIZE = 5;
|
|
7271
|
+
var MAP_BATCH_FLOOR_MS = 240000;
|
|
7272
|
+
var CONSECUTIVE_TIMEOUT_LIMIT2 = 2;
|
|
7273
|
+
var MAX_INDEPENDENT_REQUEUE_PER_RUN = MAP_BATCH_SIZE;
|
|
7233
7274
|
function assistantText(messages) {
|
|
7234
7275
|
const joined = messages.filter((message) => isRecord(message) && (message.role === "assistant" || isRecord(message.info) && message.info.role === "assistant")).map((message) => extractLatestAssistantText([message]) ?? (isRecord(message) && Array.isArray(message.content) ? message.content.filter(isRecord).filter((part) => part.type === "text" && typeof part.text === "string").map((part) => part.text).join(`
|
|
7235
7276
|
`) : "")).join(`
|
|
@@ -7298,8 +7339,8 @@ function selectMapMemoryInputs(db, projectIdentity, repoDir, includeDeferred = f
|
|
|
7298
7339
|
if (requeue.length >= MAX_INDEPENDENT_REQUEUE_PER_RUN)
|
|
7299
7340
|
break;
|
|
7300
7341
|
}
|
|
7301
|
-
const retries =
|
|
7302
|
-
return [...unmappedInputs, ...requeue].filter((memory) => includeDeferred || !
|
|
7342
|
+
const retries = readMapMemoryRetries(db, projectIdentity);
|
|
7343
|
+
return [...unmappedInputs, ...requeue].filter((memory) => includeDeferred || !isMapMemoryDeferred(memory, retries));
|
|
7303
7344
|
}
|
|
7304
7345
|
async function mapMemories(args) {
|
|
7305
7346
|
const result = {
|
|
@@ -7310,12 +7351,12 @@ async function mapMemories(args) {
|
|
|
7310
7351
|
complete: true
|
|
7311
7352
|
};
|
|
7312
7353
|
const allInputs = selectMapMemoryInputs(args.db, args.projectIdentity, args.sessionDirectory, true);
|
|
7313
|
-
const retries =
|
|
7354
|
+
const retries = readMapMemoryRetries(args.db, args.projectIdentity);
|
|
7314
7355
|
const activeIds = new Set(allInputs.map((memory) => String(memory.id)));
|
|
7315
7356
|
for (const id of Object.keys(retries))
|
|
7316
7357
|
if (!activeIds.has(id))
|
|
7317
7358
|
delete retries[id];
|
|
7318
|
-
const inputs = allInputs.filter((memory) => !
|
|
7359
|
+
const inputs = allInputs.filter((memory) => !isMapMemoryDeferred(memory, retries));
|
|
7319
7360
|
result.remaining = allInputs.length;
|
|
7320
7361
|
result.complete = result.remaining === 0;
|
|
7321
7362
|
if (inputs.length === 0) {
|
|
@@ -7332,6 +7373,7 @@ async function mapMemories(args) {
|
|
|
7332
7373
|
try {
|
|
7333
7374
|
let consecutiveTimeouts = 0;
|
|
7334
7375
|
let timeoutStreakElapsedMs = [];
|
|
7376
|
+
const countedMisses = new Set;
|
|
7335
7377
|
for (let i = 0;i < batches.length; i += 1) {
|
|
7336
7378
|
const remainingMs = Math.max(0, args.deadline - Date.now());
|
|
7337
7379
|
if (remainingMs <= 0) {
|
|
@@ -7354,22 +7396,19 @@ async function mapMemories(args) {
|
|
|
7354
7396
|
}
|
|
7355
7397
|
const committed = outcome.mapped + outcome.independent;
|
|
7356
7398
|
const committedIds = new Set(outcome.committedIds);
|
|
7399
|
+
const missedIds = new Set(outcome.missedIds);
|
|
7357
7400
|
runLeaseGuardedWrite(args.db, args.holderId, args.leaseKey, () => {
|
|
7358
7401
|
for (const memory of batch.inputs) {
|
|
7359
7402
|
if (committedIds.has(memory.id)) {
|
|
7360
7403
|
delete retries[memory.id];
|
|
7361
7404
|
continue;
|
|
7362
7405
|
}
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
|
|
7367
|
-
content,
|
|
7368
|
-
failures,
|
|
7369
|
-
deferUntil: failures < 2 ? 0 : Date.now() + Math.min(24, 2 ** (failures - 2)) * 3600000
|
|
7370
|
-
};
|
|
7406
|
+
if (missedIds.has(memory.id) && !countedMisses.has(memory.id)) {
|
|
7407
|
+
countedMisses.add(memory.id);
|
|
7408
|
+
retries[memory.id] = nextMapMemoryRetry(memory, retries[memory.id]);
|
|
7409
|
+
}
|
|
7371
7410
|
}
|
|
7372
|
-
setDreamState(args.db,
|
|
7411
|
+
setDreamState(args.db, mapMemoryRetryKey(args.projectIdentity), JSON.stringify(retries));
|
|
7373
7412
|
});
|
|
7374
7413
|
result.mapped += outcome.mapped;
|
|
7375
7414
|
result.independent += outcome.independent;
|
|
@@ -7381,7 +7420,7 @@ async function mapMemories(args) {
|
|
|
7381
7420
|
if (outcome.requeue?.length) {
|
|
7382
7421
|
if (!batch.isOmissionRetry) {
|
|
7383
7422
|
batches.push({
|
|
7384
|
-
inputs: outcome.requeue.filter((memory) => !
|
|
7423
|
+
inputs: outcome.requeue.filter((memory) => !isMapMemoryDeferred(memory, retries)),
|
|
7385
7424
|
isOmissionRetry: true
|
|
7386
7425
|
});
|
|
7387
7426
|
log2(`[dreamer] map-memories: committed ${committed}/${batch.inputs.length} mapping(s); requeueing ${outcome.requeue.length} omitted id(s) in a targeted retry`);
|
|
@@ -7469,11 +7508,7 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
7469
7508
|
stage = "apply";
|
|
7470
7509
|
const outcome = await applyParsedBatchMappings(args, batch, run.validated, budgetFinalized, true);
|
|
7471
7510
|
logBatchUsage(run.completion.messages ?? [], outcome.mapped + outcome.independent, startedAt);
|
|
7472
|
-
|
|
7473
|
-
return {
|
|
7474
|
-
...outcome,
|
|
7475
|
-
requeue: budgetFinalized ? [] : batch.filter((memory) => !returnedIds.has(memory.id))
|
|
7476
|
-
};
|
|
7511
|
+
return completedMapBatch(outcome, batch, run.validated, budgetFinalized);
|
|
7477
7512
|
}
|
|
7478
7513
|
const client = args.client;
|
|
7479
7514
|
if (!client)
|
|
@@ -7527,11 +7562,7 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
7527
7562
|
stage = "apply";
|
|
7528
7563
|
const outcome = await applyParsedBatchMappings(args, batch, run.validated, budgetFinalized, true);
|
|
7529
7564
|
logBatchUsage(run.output, outcome.mapped + outcome.independent, startedAt);
|
|
7530
|
-
|
|
7531
|
-
return {
|
|
7532
|
-
...outcome,
|
|
7533
|
-
requeue: budgetFinalized ? [] : batch.filter((memory) => !returnedIds.has(memory.id))
|
|
7534
|
-
};
|
|
7565
|
+
return completedMapBatch(outcome, batch, run.validated, budgetFinalized);
|
|
7535
7566
|
} catch (error) {
|
|
7536
7567
|
const desc = describeError(error);
|
|
7537
7568
|
log2(`[dreamer] map-memories batch failed: ${desc.brief}`, desc.stackHead ? { stackHead: desc.stackHead } : undefined);
|
|
@@ -7573,6 +7604,17 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
7573
7604
|
});
|
|
7574
7605
|
}
|
|
7575
7606
|
}
|
|
7607
|
+
function completedMapBatch(outcome, batch, parsed, budgetFinalized) {
|
|
7608
|
+
if (budgetFinalized)
|
|
7609
|
+
return outcome;
|
|
7610
|
+
const decided = new Set(parsed.map(({ id }) => id));
|
|
7611
|
+
const committed = new Set(outcome.committedIds);
|
|
7612
|
+
return {
|
|
7613
|
+
...outcome,
|
|
7614
|
+
missedIds: batch.filter(({ id }) => !decided.has(id)).map(({ id }) => id),
|
|
7615
|
+
requeue: batch.filter(({ id }) => !committed.has(id))
|
|
7616
|
+
};
|
|
7617
|
+
}
|
|
7576
7618
|
async function applyParsedBatchMappings(args, batch, parsed, budgetFinalized = false, allowPartial = false) {
|
|
7577
7619
|
const batchIds = new Set(batch.map((memory) => memory.id));
|
|
7578
7620
|
const valid = parsed.filter((entry) => batchIds.has(entry.id));
|
|
@@ -7664,7 +7706,7 @@ async function applyParsedBatchMappings(args, batch, parsed, budgetFinalized = f
|
|
|
7664
7706
|
name: "memory.set_mapping",
|
|
7665
7707
|
arguments: {
|
|
7666
7708
|
memory_project: args.projectIdentity,
|
|
7667
|
-
command_id: `${args.moduleRoute.moduleCommandId}:${
|
|
7709
|
+
command_id: `${args.moduleRoute.moduleCommandId}:${createHash6("sha256").update(rows.map((row) => row.memory_id).join(",")).digest("hex").slice(0, 16)}`,
|
|
7668
7710
|
rows
|
|
7669
7711
|
}
|
|
7670
7712
|
}
|
|
@@ -8518,16 +8560,24 @@ function countLiveMemories(db, projectPath, options = {}) {
|
|
|
8518
8560
|
const row = options.category ? db.prepare(`${sql} AND category = ?`).get(projectPath, Date.now(), options.category) : db.prepare(sql).get(projectPath, Date.now());
|
|
8519
8561
|
return row?.cnt ?? 0;
|
|
8520
8562
|
}
|
|
8563
|
+
var UNMAPPED_LIVE_MEMORIES_SQL = `FROM memories m
|
|
8564
|
+
WHERE m.project_path = ?
|
|
8565
|
+
AND m.status IN ('active','permanent')
|
|
8566
|
+
AND (m.expires_at IS NULL OR m.expires_at > ?)
|
|
8567
|
+
AND NOT EXISTS (SELECT 1 FROM memory_verifications v WHERE v.memory_id = m.id)`;
|
|
8521
8568
|
function countUnmappedActiveMemories(db, projectPath) {
|
|
8522
|
-
const
|
|
8523
|
-
|
|
8524
|
-
|
|
8525
|
-
|
|
8526
|
-
|
|
8527
|
-
|
|
8528
|
-
|
|
8529
|
-
|
|
8530
|
-
|
|
8569
|
+
const now = Date.now();
|
|
8570
|
+
const row = db.prepare(`SELECT COUNT(*) AS cnt ${UNMAPPED_LIVE_MEMORIES_SQL}`).get(projectPath, now);
|
|
8571
|
+
const total = row?.cnt ?? 0;
|
|
8572
|
+
if (total === 0)
|
|
8573
|
+
return 0;
|
|
8574
|
+
const retries = readMapMemoryRetries(db, projectPath);
|
|
8575
|
+
const waitingIds = Object.entries(retries).filter(([, retry]) => retry.deferUntil > now).map(([id]) => id);
|
|
8576
|
+
if (waitingIds.length === 0)
|
|
8577
|
+
return total;
|
|
8578
|
+
const waiting = db.prepare(`SELECT m.id, m.category, m.content ${UNMAPPED_LIVE_MEMORIES_SQL}
|
|
8579
|
+
AND m.id IN (SELECT CAST(value AS INTEGER) FROM json_each(?))`).all(projectPath, now, JSON.stringify(waitingIds));
|
|
8580
|
+
return total - waiting.filter((memory) => isMapMemoryDeferred(memory, retries, now)).length;
|
|
8531
8581
|
}
|
|
8532
8582
|
function countCompartmentsSince(db, projectPath, since) {
|
|
8533
8583
|
const row = db.prepare(`SELECT COUNT(*) AS cnt
|
|
@@ -8710,7 +8760,7 @@ function getDreamTaskBacklog(db, projectPath, task, options = {}) {
|
|
|
8710
8760
|
case "classify-memories": {
|
|
8711
8761
|
const total = countLiveMemories(db, projectPath);
|
|
8712
8762
|
return {
|
|
8713
|
-
pending: countLiveMemories(db, projectPath, { unclassifiedOnly: true }),
|
|
8763
|
+
pending: total >= MIN_POOL_TO_CLASSIFY ? countLiveMemories(db, projectPath, { unclassifiedOnly: true }) : 0,
|
|
8714
8764
|
total
|
|
8715
8765
|
};
|
|
8716
8766
|
}
|
|
@@ -8816,6 +8866,9 @@ function getDreamTaskBacklogs(db, projectPath, tasks = CANONICAL_DREAM_TASKS, op
|
|
|
8816
8866
|
cache.eligibleProjects.clear();
|
|
8817
8867
|
cache.eligibleProjects.set(projectPath, eligible);
|
|
8818
8868
|
}
|
|
8869
|
+
if (eligible && tasks.includes("map-memories")) {
|
|
8870
|
+
eligible = !Object.values(readMapMemoryRetries(db, projectPath)).some(({ deferUntil }) => deferUntil > 0);
|
|
8871
|
+
}
|
|
8819
8872
|
const optionKey = (value) => value === undefined ? "omitted" : value === null ? "null" : `number:${value}`;
|
|
8820
8873
|
const key = JSON.stringify([
|
|
8821
8874
|
getHarness2(),
|
|
@@ -8851,7 +8904,7 @@ function evaluateTaskGate(task, ctx) {
|
|
|
8851
8904
|
case "compress-cues":
|
|
8852
8905
|
return countLiveMemories(db, project) > 0;
|
|
8853
8906
|
case "classify-memories":
|
|
8854
|
-
return countLiveMemories(db, project)
|
|
8907
|
+
return countLiveMemories(db, project) >= MIN_POOL_TO_CLASSIFY;
|
|
8855
8908
|
case "retrospective":
|
|
8856
8909
|
return countProjectSessionsSince(db, project, ctx.retrospectiveWatermarkMs ?? null) > 0;
|
|
8857
8910
|
case "maintain-docs":
|
|
@@ -8872,7 +8925,7 @@ function evaluateTaskGate(task, ctx) {
|
|
|
8872
8925
|
}
|
|
8873
8926
|
|
|
8874
8927
|
// src/features/magic-context/dreamer/verify.ts
|
|
8875
|
-
import { createHash as
|
|
8928
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
8876
8929
|
|
|
8877
8930
|
// src/features/magic-context/dreamer/verify-diff.ts
|
|
8878
8931
|
import { execFile as execFile3 } from "node:child_process";
|
|
@@ -8996,7 +9049,7 @@ Read only these changed line ranges if they may affect the claim.`
|
|
|
8996
9049
|
import path5 from "node:path";
|
|
8997
9050
|
|
|
8998
9051
|
// src/features/magic-context/dreamer/verify-state.ts
|
|
8999
|
-
import { createHash as
|
|
9052
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
9000
9053
|
import { readFile, realpath as realpath2 } from "node:fs/promises";
|
|
9001
9054
|
import path4 from "node:path";
|
|
9002
9055
|
function verificationMetadata(memory) {
|
|
@@ -9009,7 +9062,7 @@ function verificationMetadata(memory) {
|
|
|
9009
9062
|
}
|
|
9010
9063
|
async function verificationFilesFingerprint(directory, files) {
|
|
9011
9064
|
const root = await resolveGitTopLevel(directory) ?? path4.resolve(directory);
|
|
9012
|
-
const hash =
|
|
9065
|
+
const hash = createHash7("sha256");
|
|
9013
9066
|
for (const file of [...new Set(files)].sort()) {
|
|
9014
9067
|
const absolute = path4.resolve(root, file);
|
|
9015
9068
|
const withinRoot = (candidate) => {
|
|
@@ -9022,7 +9075,7 @@ async function verificationFilesFingerprint(directory, files) {
|
|
|
9022
9075
|
try {
|
|
9023
9076
|
if (!withinRoot(await realpath2(absolute)))
|
|
9024
9077
|
return null;
|
|
9025
|
-
hash.update(
|
|
9078
|
+
hash.update(createHash7("sha256").update(await readFile(absolute)).digest("hex"));
|
|
9026
9079
|
} catch (error) {
|
|
9027
9080
|
if (error.code !== "ENOENT")
|
|
9028
9081
|
return null;
|
|
@@ -9827,7 +9880,7 @@ async function applyParsedVerifyManifest(args, batch, parsed, headAtPrompt, budg
|
|
|
9827
9880
|
name: "memory.set_verification",
|
|
9828
9881
|
arguments: {
|
|
9829
9882
|
memory_project: args.projectIdentity,
|
|
9830
|
-
command_id: `${args.moduleRoute.moduleCommandId}:${
|
|
9883
|
+
command_id: `${args.moduleRoute.moduleCommandId}:${createHash8("sha256").update(rows.map((row) => row.memory_id).join(",")).digest("hex").slice(0, 16)}`,
|
|
9831
9884
|
rows
|
|
9832
9885
|
}
|
|
9833
9886
|
}
|
|
@@ -10741,7 +10794,7 @@ function parseFrictionGateVerdict(verdict) {
|
|
|
10741
10794
|
}
|
|
10742
10795
|
function computeRetrospectiveWindowKey(flagged) {
|
|
10743
10796
|
const anchors = flagged.map((message) => `${message.sessionId}:${message.ts}`).sort().join("|");
|
|
10744
|
-
return
|
|
10797
|
+
return createHash9("sha256").update(anchors).digest("hex").slice(0, 32);
|
|
10745
10798
|
}
|
|
10746
10799
|
function renderFrictionWindow(messages, flaggedOrdinals, radius = 2) {
|
|
10747
10800
|
const flagged = new Set(flaggedOrdinals);
|
|
@@ -10860,6 +10913,13 @@ async function runRetrospectiveTask(config, ctx, helpers) {
|
|
|
10860
10913
|
const recencyDays = Math.max(1, Math.floor(config.retrospectiveRecencyDays ?? 30));
|
|
10861
10914
|
const recencyCutoffMs = helpers.invocationStartedAt - recencyDays * RETROSPECTIVE_DAY_MS;
|
|
10862
10915
|
const scan = await readRetrospectiveScanWindow(provider, projectIdentity, watermarkMs, RETROSPECTIVE_OVERLAP_USER_LINES, { usableInputTokens, recencyCutoffMs });
|
|
10916
|
+
ctx.onRetrospectiveScan?.({
|
|
10917
|
+
watermarkMs,
|
|
10918
|
+
maxScannedTs: scan.maxScannedTs,
|
|
10919
|
+
usableInputTokens,
|
|
10920
|
+
recencyCutoffMs,
|
|
10921
|
+
budgetTruncated: scan.budgetTruncated
|
|
10922
|
+
});
|
|
10863
10923
|
const clearedTaskStateJson = activeOverflow ? writeRetrospectiveOverflowState(taskState.root, null) : undefined;
|
|
10864
10924
|
const completedWindow = (retrospectiveWatermarkMs, noOpReason) => ({
|
|
10865
10925
|
retrospectiveWatermarkMs,
|
|
@@ -11647,6 +11707,7 @@ async function runDomainGroup(deps, group, cb) {
|
|
|
11647
11707
|
}
|
|
11648
11708
|
}
|
|
11649
11709
|
let outcome;
|
|
11710
|
+
const diagnostics = {};
|
|
11650
11711
|
const startedAt = Date.now();
|
|
11651
11712
|
try {
|
|
11652
11713
|
outcome = await executor(due.config, {
|
|
@@ -11654,7 +11715,12 @@ async function runDomainGroup(deps, group, cb) {
|
|
|
11654
11715
|
projectIdentity,
|
|
11655
11716
|
holderId,
|
|
11656
11717
|
leaseKey,
|
|
11657
|
-
leaseAcquisition: acquisition
|
|
11718
|
+
leaseAcquisition: acquisition,
|
|
11719
|
+
...due.config.task === "retrospective" ? {
|
|
11720
|
+
onRetrospectiveScan: (scan) => {
|
|
11721
|
+
diagnostics.retrospectiveScan = scan;
|
|
11722
|
+
}
|
|
11723
|
+
} : {}
|
|
11658
11724
|
});
|
|
11659
11725
|
} catch (error) {
|
|
11660
11726
|
outcome = { status: "failed", transient: true, error: String(error) };
|
|
@@ -11665,6 +11731,11 @@ async function runDomainGroup(deps, group, cb) {
|
|
|
11665
11731
|
cb?.onSkipped?.(due.config.task, outcome.detail);
|
|
11666
11732
|
} else if (outcome.status === "completed") {
|
|
11667
11733
|
advanceAfterRun(db, projectIdentity, due, finishedAt, "completed", null, outcome.schedulePatch, startedAt);
|
|
11734
|
+
const scan = diagnostics.retrospectiveScan;
|
|
11735
|
+
if (scan) {
|
|
11736
|
+
const stored = readRetrospectiveWatermark(db, projectIdentity, due.config.task);
|
|
11737
|
+
log2(`[dreamer] retrospective: watermark start=${scan.watermarkMs} maxScannedTs=${scan.maxScannedTs} patch=${outcome.schedulePatch?.retrospectiveWatermarkMs ?? "none"} stored=${stored ?? "none"} usableInputTokens=${scan.usableInputTokens} recencyCutoffMs=${scan.recencyCutoffMs} budgetTruncated=${scan.budgetTruncated}`, { projectIdentity });
|
|
11738
|
+
}
|
|
11668
11739
|
cb?.onRan?.(due.config.task, outcome.detail, outcome.backlog);
|
|
11669
11740
|
} else if (outcome.transient) {
|
|
11670
11741
|
recordTransientFailure(db, projectIdentity, due, finishedAt, outcome.error ?? null, outcome.schedulePatch);
|
|
@@ -12309,7 +12380,7 @@ function createDreamTimerModuleClient(moduleClient) {
|
|
|
12309
12380
|
import { readFileSync as readFileSync4, statSync as statSync3 } from "node:fs";
|
|
12310
12381
|
|
|
12311
12382
|
// src/plugin/embedding-bootstrap-helpers.ts
|
|
12312
|
-
import { createHash as
|
|
12383
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
12313
12384
|
var EMBEDDING_AFFECTING_KEYS = new Set([
|
|
12314
12385
|
"embedding.api_key",
|
|
12315
12386
|
"embedding.endpoint",
|
|
@@ -12358,7 +12429,7 @@ var EMBEDDING_WARNING_TERMS = [
|
|
|
12358
12429
|
];
|
|
12359
12430
|
var loggedFailureSignatures = new Map;
|
|
12360
12431
|
function sha256Prefix(value, length = 16) {
|
|
12361
|
-
return
|
|
12432
|
+
return createHash10("sha256").update(value).digest("hex").slice(0, length);
|
|
12362
12433
|
}
|
|
12363
12434
|
function warningLooksEmbeddingRelated(message) {
|
|
12364
12435
|
const lower = message.toLowerCase();
|
|
@@ -16666,7 +16737,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16666
16737
|
const buildManagedCtx = async (db) => {
|
|
16667
16738
|
const { deriveHistorianChunkTokens, resolveHistorianContextLimit } = await importPluginModule(() => import("./derive-budgets-2z6xxm7e.js"));
|
|
16668
16739
|
const { resolveHistorianModel } = await importPluginModule(() => import("./model-resolution-280gmqvd.js"));
|
|
16669
|
-
const { userObservationCollectionEnabled, userObservationsRequested } = await importPluginModule(() => import("./task-config-
|
|
16740
|
+
const { userObservationCollectionEnabled, userObservationsRequested } = await importPluginModule(() => import("./task-config-qt6n4bxm.js"));
|
|
16670
16741
|
const DEFAULT_HISTORIAN_TIMEOUT_MS = 10 * 60 * 1000;
|
|
16671
16742
|
const runConfig = historianRunConfig(config, currentPluginConfigReader(directory)?.poll().effective ?? config);
|
|
16672
16743
|
const historianModel = resolveHistorianModel(runConfig, "opencode");
|
|
@@ -18181,7 +18252,7 @@ function evaluateRequestToolsRelease(args) {
|
|
|
18181
18252
|
}
|
|
18182
18253
|
|
|
18183
18254
|
// src/hooks/magic-context/rust-mode-transform.ts
|
|
18184
|
-
import { createHash as
|
|
18255
|
+
import { createHash as createHash14, randomUUID as randomUUID6 } from "node:crypto";
|
|
18185
18256
|
|
|
18186
18257
|
// src/features/magic-context/memory/single-store-embedding-drain.ts
|
|
18187
18258
|
function isWatermarkRow(row) {
|
|
@@ -18245,7 +18316,7 @@ function advanceEmbeddedWatermark(db, projectPath, upTo) {
|
|
|
18245
18316
|
}
|
|
18246
18317
|
|
|
18247
18318
|
// src/features/magic-context/mural/source-revision.ts
|
|
18248
|
-
import { createHash as
|
|
18319
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
18249
18320
|
var statements = new WeakMap;
|
|
18250
18321
|
function muralSourceRevision(db, projectPath) {
|
|
18251
18322
|
let statement = statements.get(db);
|
|
@@ -18262,7 +18333,7 @@ function muralSourceRevision(db, projectPath) {
|
|
|
18262
18333
|
statements.set(db, statement);
|
|
18263
18334
|
}
|
|
18264
18335
|
const row = statement.get(projectPath, Date.now());
|
|
18265
|
-
return
|
|
18336
|
+
return createHash11("sha256").update(row.revision).digest("hex");
|
|
18266
18337
|
}
|
|
18267
18338
|
|
|
18268
18339
|
// src/features/magic-context/install-instance-id.ts
|
|
@@ -20723,7 +20794,7 @@ function noteExternalLkgReplay(participant, sessionId, inputMessages, servedMess
|
|
|
20723
20794
|
}
|
|
20724
20795
|
|
|
20725
20796
|
// src/hooks/magic-context/rust-served-raw.ts
|
|
20726
|
-
import { createHash as
|
|
20797
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
20727
20798
|
class RustServedRawConflict extends EmergencyFailClosedError {
|
|
20728
20799
|
reason;
|
|
20729
20800
|
messageIds;
|
|
@@ -20737,7 +20808,7 @@ class RustServedRawConflict extends EmergencyFailClosedError {
|
|
|
20737
20808
|
}
|
|
20738
20809
|
function partDigest(part) {
|
|
20739
20810
|
const serialized = JSON.stringify(part);
|
|
20740
|
-
return
|
|
20811
|
+
return createHash13("sha256").update(stableStringify(serialized === undefined ? undefined : JSON.parse(serialized))).digest("hex");
|
|
20741
20812
|
}
|
|
20742
20813
|
function records(doc) {
|
|
20743
20814
|
if (doc.rustServedRaw === undefined)
|
|
@@ -21456,10 +21527,10 @@ function messageCacheSignature(message) {
|
|
|
21456
21527
|
const parts = Array.isArray(message.parts) ? message.parts : [];
|
|
21457
21528
|
const serializedParts = JSON.stringify(parts) ?? "null";
|
|
21458
21529
|
const serializedMessage = JSON.stringify(message) ?? "null";
|
|
21459
|
-
return `${messageIdOf(message) ?? ""}:${parts.length}:${Buffer.byteLength(serializedParts)}:${
|
|
21530
|
+
return `${messageIdOf(message) ?? ""}:${parts.length}:${Buffer.byteLength(serializedParts)}:${createHash14("sha256").update(serializedMessage).digest("hex")}`;
|
|
21460
21531
|
}
|
|
21461
21532
|
function advanceWireFingerprint(previous, encoded) {
|
|
21462
|
-
return
|
|
21533
|
+
return createHash14("sha256").update(previous).update("\\0").update(JSON.stringify(encoded) ?? "null").digest("hex");
|
|
21463
21534
|
}
|
|
21464
21535
|
function buildWireFingerprint(encoded) {
|
|
21465
21536
|
let fingerprint = "rust-wire-v1";
|
|
@@ -23258,7 +23329,7 @@ ${notice}`, {}));
|
|
|
23258
23329
|
const id = messageIdOf(message) ?? `index:${todoStart + offset}`;
|
|
23259
23330
|
const parts = message.parts?.filter((part) => isRecord3(part) && part.type === "tool" && part.tool === "todowrite");
|
|
23260
23331
|
if (parts?.length) {
|
|
23261
|
-
todoCalls.set(id,
|
|
23332
|
+
todoCalls.set(id, createHash14("sha256").update(JSON.stringify(parts)).digest("hex"));
|
|
23262
23333
|
} else {
|
|
23263
23334
|
todoCalls.delete(id);
|
|
23264
23335
|
}
|
|
@@ -27325,12 +27396,12 @@ function systemPromptDates(prompt, sticky) {
|
|
|
27325
27396
|
}
|
|
27326
27397
|
|
|
27327
27398
|
// src/hooks/magic-context/system-prompt-diagnostics.ts
|
|
27328
|
-
import { createHash as
|
|
27399
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
27329
27400
|
function snapshotSystemPrompt(system, preset) {
|
|
27330
27401
|
return { elements: system.map((element) => Buffer.from(element)), preset };
|
|
27331
27402
|
}
|
|
27332
27403
|
function describeSystemPromptChange(previous, current) {
|
|
27333
|
-
const metadata = (element) => element === undefined ? "absent" : `bytes=${element.length},md5=${
|
|
27404
|
+
const metadata = (element) => element === undefined ? "absent" : `bytes=${element.length},md5=${createHash15("md5").update(element).digest("hex")}`;
|
|
27334
27405
|
const elements = [];
|
|
27335
27406
|
for (let index = 0;index < Math.max(previous?.elements.length ?? 0, current.elements.length); index++) {
|
|
27336
27407
|
const before = previous?.elements[index];
|
|
@@ -29979,7 +30050,7 @@ function formatCtxReduceReply(stampedCount, selfStampCount = 0) {
|
|
|
29979
30050
|
return parts.join(" ");
|
|
29980
30051
|
}
|
|
29981
30052
|
// src/tools/ctx-reduce/tools.ts
|
|
29982
|
-
import { createHash as
|
|
30053
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
29983
30054
|
import { tool as tool4 } from "@opencode-ai/plugin";
|
|
29984
30055
|
|
|
29985
30056
|
// src/features/magic-context/range-parser.ts
|
|
@@ -30043,11 +30114,11 @@ function createCtxReduceTool(deps) {
|
|
|
30043
30114
|
const stableId = `oc-${sessionId}-${callId}`;
|
|
30044
30115
|
if (Buffer.byteLength(stableId) <= 128)
|
|
30045
30116
|
return stableId;
|
|
30046
|
-
return `oc-${
|
|
30117
|
+
return `oc-${createHash16("sha256").update(stableId).digest("hex")}`;
|
|
30047
30118
|
}
|
|
30048
30119
|
fallbackCommandSequence += 1;
|
|
30049
30120
|
const monotonicId = `oc-${sessionId}-${fallbackCommandSequence}`;
|
|
30050
|
-
return Buffer.byteLength(monotonicId) <= 128 ? monotonicId : `oc-${
|
|
30121
|
+
return Buffer.byteLength(monotonicId) <= 128 ? monotonicId : `oc-${createHash16("sha256").update(monotonicId).digest("hex")}`;
|
|
30051
30122
|
};
|
|
30052
30123
|
return tool4({
|
|
30053
30124
|
description: CTX_REDUCE_DESCRIPTION,
|