@cortexkit/opencode-magic-context 0.49.27 → 0.49.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-search-worker.js +3 -3
- package/dist/chunk-embedding-write-worker.js +1 -1
- package/dist/config/commit-retention-recovery.d.ts +9 -0
- package/dist/config/commit-retention-recovery.d.ts.map +1 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/live-child-output-cap.d.ts.map +1 -1
- package/dist/config/live-run-config.d.ts.map +1 -1
- package/dist/config/project-security.d.ts +1 -0
- package/dist/config/project-security.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-tgnw019g.js → conflict-warning-hook-xgskea1v.js} +3 -3
- package/dist/{context-t2k97d6v.js → context-836j3vte.js} +63 -27
- package/dist/{embedding-backfill-cwnyr4fj.js → embedding-backfill-mms9nb0h.js} +2 -2
- package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/hidden-single-shot.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/map-memories.d.ts +2 -2
- package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify-diff.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/git-commits/indexer.d.ts +2 -0
- package/dist/features/magic-context/git-commits/indexer.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts +3 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/smart-notes/compiler.d.ts.map +1 -1
- package/dist/features/magic-context/work-metrics.d.ts +5 -3
- package/dist/features/magic-context/work-metrics.d.ts.map +1 -1
- package/dist/hooks/magic-context/apply-operations.d.ts +2 -0
- package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts +5 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts +3 -1
- package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-replay.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-slot.d.ts +7 -0
- package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-db.d.ts +3 -2
- package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/replay-committed-drops.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-n8qmmd7f.js → index-093c4g1c.js} +3 -3
- package/dist/{index-89k1w6x2.js → index-a1h316s9.js} +2 -2
- package/dist/{index-fq2p158w.js → index-bps8vn9r.js} +13 -7
- package/dist/{index-tvzvjggy.js → index-gkee6p4g.js} +1 -1
- package/dist/{index-a2fz9hpa.js → index-gxkhzmjq.js} +4 -2
- package/dist/{index-4cpc59jv.js → index-h4s5jk7f.js} +1 -1
- package/dist/{index-t3rbb8wr.js → index-pe6b4bhs.js} +1 -1
- package/dist/{index-dcqk0y27.js → index-q9zvphbq.js} +104 -24
- package/dist/{index-7gbcg8xv.js → index-tx68g9nc.js} +1 -1
- package/dist/{index-4ypqzvhf.js → index-vnn5405n.js} +1 -1
- package/dist/{index-077ht5cq.js → index-waktfbjy.js} +1 -1
- package/dist/{index-qzbpbnqt.js → index-wpcdk76y.js} +343 -252
- package/dist/{index-dzfevacx.js → index-wvffze8y.js} +10 -6
- package/dist/{index-31y1mznz.js → index-wyt5m81v.js} +4 -4
- package/dist/{index-v0dhhxsq.js → index-y1qwzvxn.js} +5 -5
- package/dist/{index-yzjhx10y.js → index-zhgqgxtt.js} +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -30
- package/dist/{message-index-bounded-7ayzb2ah.js → message-index-bounded-7qsn4fd3.js} +3 -3
- package/dist/migration-worker.js +1 -1
- package/dist/plugin/dream-timer.d.ts.map +1 -1
- package/dist/plugin/embedding-bootstrap-helpers.d.ts +5 -1
- package/dist/plugin/embedding-bootstrap-helpers.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/{project-embedding-registry-94nncs5g.js → project-embedding-registry-cg281d9j.js} +1 -1
- package/dist/raw-ordinal-warmup-worker.js +2 -2
- package/dist/{read-session-chunk-jzb6w9w5.js → read-session-chunk-a5d0q3m0.js} +2 -2
- package/dist/{recomp-orchestrator-02sa2ngr.js → recomp-orchestrator-na34m4c5.js} +10 -10
- package/dist/{search-spq6nfyf.js → search-0cd6hx7a.js} +7 -7
- package/dist/{search-archive-q1vw7zg4.js → search-archive-66pm17gm.js} +3 -3
- package/dist/{send-session-notification-afzzqy5b.js → send-session-notification-vz86nt79.js} +2 -2
- package/dist/{transform-postprocess-phase-6menyyxc.js → transform-postprocess-phase-27we33af.js} +10 -10
- package/dist/v2/auto-search-worker.js +3 -3
- package/dist/v2/chunk-embedding-write-worker.js +1 -1
- package/dist/v2/{context-na0esngr.js → context-g4ptae4x.js} +215 -83
- package/dist/v2/{embedding-backfill-rh5dgsva.js → embedding-backfill-35k6czrr.js} +2 -2
- package/dist/v2/hidden-completion.d.ts.map +1 -1
- package/dist/v2/hooks/dream-timer.d.ts.map +1 -1
- package/dist/v2/hooks/store.d.ts.map +1 -1
- package/dist/v2/{message-index-bounded-n09b74vr.js → message-index-bounded-7363502m.js} +3 -3
- package/dist/v2/migration-worker.js +1 -1
- package/dist/v2/{project-embedding-registry-6pak822h.js → project-embedding-registry-p1p10ks7.js} +1 -1
- package/dist/v2/raw-ordinal-warmup-worker.js +2 -2
- package/dist/v2/{read-session-chunk-vpt69tw9.js → read-session-chunk-kkppfhft.js} +2 -2
- package/dist/v2/{recomp-orchestrator-txsmbnvw.js → recomp-orchestrator-f1df1gb8.js} +10 -10
- package/dist/v2/{search-dcy9b6gd.js → search-2v3xyzse.js} +7 -7
- package/dist/v2/{search-archive-t9bcz4ht.js → search-archive-v07jpw25.js} +3 -3
- package/dist/v2/{send-session-notification-vdsgnf4c.js → send-session-notification-x5nzy34v.js} +2 -2
- package/dist/v2/{server-e3hc93wk.js → server-77gznpmf.js} +1 -1
- package/dist/v2/{server-94wk1ey3.js → server-835q39kd.js} +45 -5
- package/dist/v2/{server-txbc3czn.js → server-976dxaxh.js} +10 -6
- package/dist/v2/{server-3vhxy2k5.js → server-a7x00tw8.js} +5 -5
- package/dist/v2/{server-z2n2xaeh.js → server-k9je35ev.js} +1 -1
- package/dist/v2/{server-xkvxss5g.js → server-mxzj3r0y.js} +5 -1
- package/dist/v2/{server-6avtp9jp.js → server-p0snacz3.js} +1 -1
- package/dist/v2/{server-z3mk9jdc.js → server-ph300d6m.js} +1 -1
- package/dist/v2/{server-jj9qye8y.js → server-q50ttc2g.js} +62 -21
- package/dist/v2/{server-6v3cdzsx.js → server-qc915kw2.js} +1 -1
- package/dist/v2/{server-zmcrvpm3.js → server-w79f8ejn.js} +2 -2
- package/dist/v2/{server-yqek3s4k.js → server-zh3esb0z.js} +4 -2
- package/dist/v2/server.js +3 -3
- package/dist/v2/{wrapup-orchestrator-gjkszser.js → wrapup-orchestrator-jq33fda8.js} +10 -10
- package/dist/{wrapup-orchestrator-n5h5sr1x.js → wrapup-orchestrator-f0xr7pft.js} +11 -11
- package/package.json +1 -1
- package/src/config/commit-retention-recovery.ts +34 -0
- package/src/config/index.ts +22 -2
- package/src/config/live-child-output-cap.test.ts +28 -0
- package/src/config/live-child-output-cap.ts +2 -0
- package/src/config/live-run-config.test.ts +44 -1
- package/src/config/live-run-config.ts +8 -1
- package/src/config/project-config-trust-boundary.test.ts +57 -0
- package/src/config/project-security.ts +6 -2
- package/src/shared/windows-hidden-spawns.test.ts +133 -23
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getMagicContextBuiltinCommands,
|
|
3
3
|
readJsoncFile,
|
|
4
|
+
isCommitRetentionPaused,
|
|
4
5
|
cortexKitUserConfigBasePath,
|
|
5
6
|
cortexKitProjectConfigBasePath,
|
|
6
7
|
resolveLegacyConfigSources,
|
|
7
8
|
getProtectedTokensTierOverrides,
|
|
8
9
|
loadPluginConfigDetailed
|
|
9
|
-
} from "./server-
|
|
10
|
+
} from "./server-835q39kd.js";
|
|
10
11
|
import {
|
|
11
12
|
getHarness2,
|
|
12
13
|
harnessOwnsOpenCodeStore2
|
|
@@ -149,6 +150,7 @@ import {
|
|
|
149
150
|
noteLkgHealthyPrefix,
|
|
150
151
|
lkgRecoveryReplayUnproven,
|
|
151
152
|
lkgRecoveryEntryUnproven,
|
|
153
|
+
lkgInputIdentity,
|
|
152
154
|
beginLkgPass,
|
|
153
155
|
visitMessageContentFields,
|
|
154
156
|
contentSnapshotValue,
|
|
@@ -230,6 +232,7 @@ import {
|
|
|
230
232
|
normalizeSDKResponse,
|
|
231
233
|
annotateSubagentInvocationError,
|
|
232
234
|
failedInvocationStatus,
|
|
235
|
+
emptyTokenTotals,
|
|
233
236
|
sumTokensFromChildMessages,
|
|
234
237
|
recordChildInvocation,
|
|
235
238
|
createPromptAsyncTransport,
|
|
@@ -302,7 +305,7 @@ import {
|
|
|
302
305
|
startCompartmentAgent,
|
|
303
306
|
setRecompStarting2,
|
|
304
307
|
setRecompTerminal2
|
|
305
|
-
} from "./server-
|
|
308
|
+
} from "./server-q50ttc2g.js";
|
|
306
309
|
import {
|
|
307
310
|
resolveHistorianModel2
|
|
308
311
|
} from "./server-5kym00ag.js";
|
|
@@ -327,7 +330,7 @@ import {
|
|
|
327
330
|
openDatabaseAsync,
|
|
328
331
|
isDatabasePersisted,
|
|
329
332
|
getDatabasePersistenceError
|
|
330
|
-
} from "./server-
|
|
333
|
+
} from "./server-77gznpmf.js";
|
|
331
334
|
import {
|
|
332
335
|
pruneMissingProjectIdentities,
|
|
333
336
|
setHomeProjectPermission,
|
|
@@ -500,7 +503,7 @@ import {
|
|
|
500
503
|
latestRealUserTurnIdFromOpenCodeDb,
|
|
501
504
|
getMessageTimesFromOpenCodeDb,
|
|
502
505
|
findLastAssistantModelFromOpenCodeDb
|
|
503
|
-
} from "./server-
|
|
506
|
+
} from "./server-a7x00tw8.js";
|
|
504
507
|
import {
|
|
505
508
|
expandToolPart,
|
|
506
509
|
askAnswerLines,
|
|
@@ -699,7 +702,7 @@ import {
|
|
|
699
702
|
readRawSessionMessageById2,
|
|
700
703
|
readSessionChunk2,
|
|
701
704
|
readRawSessionSeedTail2
|
|
702
|
-
} from "./server-
|
|
705
|
+
} from "./server-mxzj3r0y.js";
|
|
703
706
|
import {
|
|
704
707
|
BoundedSessionMap,
|
|
705
708
|
recordToolDefinitionSet,
|
|
@@ -714,7 +717,7 @@ import {
|
|
|
714
717
|
isMessageIndexReconciledThrough,
|
|
715
718
|
clearIndexedMessages,
|
|
716
719
|
indexMessagesAfterOrdinal
|
|
717
|
-
} from "./server-
|
|
720
|
+
} from "./server-k9je35ev.js";
|
|
718
721
|
import"./server-awr8qa4c.js";
|
|
719
722
|
import {
|
|
720
723
|
embedPauseBySession,
|
|
@@ -745,7 +748,7 @@ import {
|
|
|
745
748
|
embedSessionCompartmentChunks2,
|
|
746
749
|
getEmbeddingCoverageStatus2,
|
|
747
750
|
getAutoEmbeddingSessionCoverage2
|
|
748
|
-
} from "./server-
|
|
751
|
+
} from "./server-zh3esb0z.js";
|
|
749
752
|
import {
|
|
750
753
|
SubcClient,
|
|
751
754
|
connectionFileExists,
|
|
@@ -822,7 +825,7 @@ import {
|
|
|
822
825
|
readGitFileChangeTimesSince,
|
|
823
826
|
verificationFileExists,
|
|
824
827
|
normalizeVerificationFiles
|
|
825
|
-
} from "./server-
|
|
828
|
+
} from "./server-ph300d6m.js";
|
|
826
829
|
import {
|
|
827
830
|
deriveTriggerBudget2,
|
|
828
831
|
deriveHistorianChunkTokens2,
|
|
@@ -856,7 +859,7 @@ import {
|
|
|
856
859
|
} from "./server-vr4szghm.js";
|
|
857
860
|
import {
|
|
858
861
|
cosineSimilarity
|
|
859
|
-
} from "./server-
|
|
862
|
+
} from "./server-p0snacz3.js";
|
|
860
863
|
import {
|
|
861
864
|
computeCueContentHash,
|
|
862
865
|
hasMuralCueColumns,
|
|
@@ -893,7 +896,7 @@ import"./server-1bw1wcbp.js";
|
|
|
893
896
|
import {
|
|
894
897
|
flushIgnoredMessages2,
|
|
895
898
|
sendStatusNotification2
|
|
896
|
-
} from "./server-
|
|
899
|
+
} from "./server-qc915kw2.js";
|
|
897
900
|
import {
|
|
898
901
|
renderSingleStoreMigrationRequiredRefusal,
|
|
899
902
|
SingleStoreMigrationRequiredError,
|
|
@@ -913,14 +916,14 @@ import {
|
|
|
913
916
|
resolveMemoriesByIdsForSearch2,
|
|
914
917
|
unifiedSearch2,
|
|
915
918
|
formatSearchResults2
|
|
916
|
-
} from "./server-
|
|
919
|
+
} from "./server-976dxaxh.js";
|
|
917
920
|
import {
|
|
918
921
|
resolvePromptContext2
|
|
919
922
|
} from "./server-fmsr7v69.js";
|
|
920
923
|
import"./server-kaqs6h31.js";
|
|
921
924
|
import {
|
|
922
925
|
renderSearchArchiveOffThread2
|
|
923
|
-
} from "./server-
|
|
926
|
+
} from "./server-w79f8ejn.js";
|
|
924
927
|
import {
|
|
925
928
|
compareSemverCore
|
|
926
929
|
} from "./server-84w6rvvf.js";
|
|
@@ -7520,6 +7523,12 @@ var RECENT_TOOL_SKELETON_WINDOW = 20;
|
|
|
7520
7523
|
function buildReplacementContent(tagId) {
|
|
7521
7524
|
return `[dropped §${tagId}§]`;
|
|
7522
7525
|
}
|
|
7526
|
+
var FROZEN_TEXT_ANNOTATION_SUFFIX = /(?:\n\n(?:<instruction name="deferred_notes">(?:(?!<\/instruction>)[\s\S])*<\/instruction>|<ctx-search-hint>(?:(?!<\/ctx-search-hint>)[\s\S])*<\/ctx-search-hint>))+$/;
|
|
7527
|
+
function renderDroppedText(tagId, renderedText) {
|
|
7528
|
+
const placeholder = buildReplacementContent(tagId);
|
|
7529
|
+
const annotations = renderedText?.match(FROZEN_TEXT_ANNOTATION_SUFFIX)?.[0] ?? "";
|
|
7530
|
+
return placeholder + annotations;
|
|
7531
|
+
}
|
|
7523
7532
|
function applyNewToolDrop(target, options) {
|
|
7524
7533
|
const plan = planNewToolDrop(target, options, !!options.persist);
|
|
7525
7534
|
if (!plan)
|
|
@@ -19284,8 +19293,21 @@ function createTransform(deps) {
|
|
|
19284
19293
|
const temporalReplayIds = temporalCandidates ? messages.flatMap((message) => message.info.id ? [message.info.id] : []) : undefined;
|
|
19285
19294
|
logTransformTiming(sessionId, "findSessionId", tSessionId, `messages=${messages.length}`);
|
|
19286
19295
|
const tLkgEntry = performance.now();
|
|
19287
|
-
const lkgInput = deps.transformMode === "rust" ? [] : projectEntry(sessionId,
|
|
19296
|
+
const lkgInput = deps.transformMode === "rust" ? [] : projectEntry(sessionId, entryOrderForThinkingFit);
|
|
19288
19297
|
const recovery = deps.compactionOff || deps.transformMode === "rust" ? {} : readLkgRecoveryPrefix(sessionId, lkgInput, messages, deps.db);
|
|
19298
|
+
const recoveryTailSources = [];
|
|
19299
|
+
if (recovery.prefix) {
|
|
19300
|
+
const priorIdentities = new Set(recovery.prefix.inputs.map((input) => input.id));
|
|
19301
|
+
lkgInput.forEach((input, index) => {
|
|
19302
|
+
const identity = lkgInputIdentity(input.id, input.role, index);
|
|
19303
|
+
if (!identity || priorIdentities.has(identity))
|
|
19304
|
+
return;
|
|
19305
|
+
recoveryTailSources.push({
|
|
19306
|
+
identity,
|
|
19307
|
+
pristineSystem: input.id === null && input.role === "system" ? structuredClone(entryOrderForThinkingFit[index]) : undefined
|
|
19308
|
+
});
|
|
19309
|
+
});
|
|
19310
|
+
}
|
|
19289
19311
|
const persistedUntaggedInputIds = deps.compactionOff || deps.transformMode === "rust" ? [] : readPersistedLkgUntaggedInputIds(deps.db, sessionId);
|
|
19290
19312
|
const untaggedReplayIds = new Set([
|
|
19291
19313
|
...recovery.prefix?.untaggedInputIds ?? [],
|
|
@@ -20322,9 +20344,15 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
20322
20344
|
});
|
|
20323
20345
|
compactionModeTransitionPending.delete(sessionId);
|
|
20324
20346
|
if (recovery.prefix && !recoveryNormalized) {
|
|
20325
|
-
const
|
|
20326
|
-
|
|
20327
|
-
|
|
20347
|
+
const renderedById = new Map;
|
|
20348
|
+
for (const message of messages) {
|
|
20349
|
+
if (!message.info.id)
|
|
20350
|
+
continue;
|
|
20351
|
+
const group = renderedById.get(message.info.id) ?? [];
|
|
20352
|
+
group.push(message);
|
|
20353
|
+
renderedById.set(message.info.id, group);
|
|
20354
|
+
}
|
|
20355
|
+
const suffix = recoveryTailSources.flatMap(({ identity, pristineSystem }) => pristineSystem ? [pristineSystem] : renderedById.get(identity) ?? []);
|
|
20328
20356
|
messages.splice(0, messages.length, ...JSON.parse(recovery.prefix.json), ...suffix);
|
|
20329
20357
|
}
|
|
20330
20358
|
const recoveryReleaseReason = recovery.rebuildReason ?? (recoveryNormalized ? "recovery_tail_normalized" : undefined);
|
|
@@ -20781,6 +20809,8 @@ function replayCommittedDrops(db, sessionId, messages) {
|
|
|
20781
20809
|
const toolThinking = new Map;
|
|
20782
20810
|
const batch = new ToolMutationBatch(messages);
|
|
20783
20811
|
for (const message of messages) {
|
|
20812
|
+
if (message.info.syntheticHead === true)
|
|
20813
|
+
continue;
|
|
20784
20814
|
if (message.info.role === "user")
|
|
20785
20815
|
precedingThinking = [];
|
|
20786
20816
|
const thinking = message.parts.filter(isThinkingPart);
|
|
@@ -20814,9 +20844,10 @@ function replayCommittedDrops(db, sessionId, messages) {
|
|
|
20814
20844
|
message,
|
|
20815
20845
|
setContent(content) {
|
|
20816
20846
|
if (isTextPart(part)) {
|
|
20817
|
-
|
|
20847
|
+
const rendered = renderDroppedText(tag.tagNumber, part.text);
|
|
20848
|
+
if (part.text === rendered)
|
|
20818
20849
|
return false;
|
|
20819
|
-
part.text =
|
|
20850
|
+
part.text = rendered;
|
|
20820
20851
|
} else
|
|
20821
20852
|
message.parts[p] = { type: "text", text: content };
|
|
20822
20853
|
return true;
|
|
@@ -22349,8 +22380,23 @@ WHERE session_id = ?
|
|
|
22349
22380
|
AND data IS NOT NULL
|
|
22350
22381
|
AND (time_created > ? OR (time_created = ? AND id > ?))
|
|
22351
22382
|
ORDER BY time_created, id`;
|
|
22352
|
-
|
|
22353
|
-
|
|
22383
|
+
var V2_ASSISTANT_USAGE_ROWS_AFTER_SQL = `
|
|
22384
|
+
SELECT
|
|
22385
|
+
json_extract(data, '$.agent') AS agent,
|
|
22386
|
+
seq AS time_created,
|
|
22387
|
+
id AS id,
|
|
22388
|
+
COALESCE(json_extract(data, '$.tokens.input'), 0)
|
|
22389
|
+
+ COALESCE(json_extract(data, '$.tokens.cache.read'), 0)
|
|
22390
|
+
+ COALESCE(json_extract(data, '$.tokens.cache.write'), 0) AS prompt,
|
|
22391
|
+
COALESCE(json_extract(data, '$.tokens.output'), 0) AS output
|
|
22392
|
+
FROM session_message
|
|
22393
|
+
WHERE session_id = ?
|
|
22394
|
+
AND type = 'assistant'
|
|
22395
|
+
AND data IS NOT NULL
|
|
22396
|
+
AND (seq > ? OR (seq = ? AND id > ?))
|
|
22397
|
+
ORDER BY seq, id`;
|
|
22398
|
+
function readAssistantUsageRowsAfter(openCodeDb, sessionId, afterTimeCreated, afterId, generation = "v1") {
|
|
22399
|
+
const rows = openCodeDb.prepare(generation === "v2" ? V2_ASSISTANT_USAGE_ROWS_AFTER_SQL : ASSISTANT_USAGE_ROWS_AFTER_SQL).all(sessionId, afterTimeCreated, afterTimeCreated, afterId);
|
|
22354
22400
|
return rows.map((r) => ({
|
|
22355
22401
|
agent: r.agent ?? null,
|
|
22356
22402
|
timeCreated: Number(r.time_created ?? 0),
|
|
@@ -22359,8 +22405,8 @@ function readAssistantUsageRowsAfter(openCodeDb, sessionId, afterTimeCreated, af
|
|
|
22359
22405
|
output: Number(r.output ?? 0)
|
|
22360
22406
|
}));
|
|
22361
22407
|
}
|
|
22362
|
-
function computeOpenCodeWorkMetricsIncremental(openCodeDb, sessionId, carry) {
|
|
22363
|
-
const rows = readAssistantUsageRowsAfter(openCodeDb, sessionId, carry.lastTimeCreated, carry.lastId);
|
|
22408
|
+
function computeOpenCodeWorkMetricsIncremental(openCodeDb, sessionId, carry, generation = "v1") {
|
|
22409
|
+
const rows = readAssistantUsageRowsAfter(openCodeDb, sessionId, carry.lastTimeCreated, carry.lastId, generation);
|
|
22364
22410
|
if (rows.length === 0) {
|
|
22365
22411
|
return { carry, metrics: metricsFromCarry(carry) };
|
|
22366
22412
|
}
|
|
@@ -22387,28 +22433,28 @@ var EMBEDDING_AFFECTING_KEYS = new Set([
|
|
|
22387
22433
|
"embedding.query_instruction",
|
|
22388
22434
|
"embedding.document_prefix",
|
|
22389
22435
|
"embedding.fallback_provider",
|
|
22390
|
-
"
|
|
22436
|
+
"embedding.local_runtime",
|
|
22437
|
+
"embedding.local_dtype",
|
|
22391
22438
|
"subc.connection_file",
|
|
22392
|
-
"shadow_embedding"
|
|
22439
|
+
"shadow_embedding.enabled",
|
|
22440
|
+
"memory.enabled",
|
|
22441
|
+
"memory.git_commit_indexing.enabled",
|
|
22442
|
+
"allow_home_project"
|
|
22393
22443
|
]);
|
|
22394
22444
|
var LITERAL_CONFIG_TOKEN_RE = /\{(?:env|file):[^}]+\}/;
|
|
22395
|
-
function
|
|
22396
|
-
|
|
22397
|
-
|
|
22398
|
-
|
|
22445
|
+
function affectsEmbeddingRegistration(path) {
|
|
22446
|
+
return [...EMBEDDING_AFFECTING_KEYS].some((field) => field === path || field.startsWith(`${path}.`));
|
|
22447
|
+
}
|
|
22448
|
+
function untrustedConfigFieldPaths(detailed) {
|
|
22449
|
+
const paths = (detailed.recoveredFieldPaths ?? detailed.recoveredTopLevelKeys).filter(affectsEmbeddingRegistration);
|
|
22450
|
+
paths.push(...detailed.substitutionFailures.map((failure) => failure.keyPath).filter(affectsEmbeddingRegistration));
|
|
22451
|
+
for (const [key, value] of Object.entries(detailed.config.embedding)) {
|
|
22399
22452
|
if (typeof value === "string" && LITERAL_CONFIG_TOKEN_RE.test(value)) {
|
|
22400
|
-
|
|
22453
|
+
paths.push(`embedding.${key}`);
|
|
22401
22454
|
}
|
|
22402
22455
|
}
|
|
22403
|
-
return
|
|
22456
|
+
return [...new Set(paths)].sort();
|
|
22404
22457
|
}
|
|
22405
|
-
var EMBEDDING_AFFECTING_TOP_LEVEL_KEYS = new Set([
|
|
22406
|
-
"embedding",
|
|
22407
|
-
"memory",
|
|
22408
|
-
"experimental",
|
|
22409
|
-
"subc",
|
|
22410
|
-
"shadow_embedding"
|
|
22411
|
-
]);
|
|
22412
22458
|
var EMBEDDING_WARNING_TERMS = [
|
|
22413
22459
|
"api_key",
|
|
22414
22460
|
"endpoint",
|
|
@@ -22433,21 +22479,12 @@ function isConfigLoadUntrusted(detailed) {
|
|
|
22433
22479
|
return true;
|
|
22434
22480
|
}
|
|
22435
22481
|
for (const failure of detailed.substitutionFailures) {
|
|
22436
|
-
if (EMBEDDING_AFFECTING_KEYS.has(failure.keyPath)) {
|
|
22437
|
-
return true;
|
|
22438
|
-
}
|
|
22439
22482
|
if (failure.keyPath === "<unknown>" && warningLooksEmbeddingRelated(failure.message)) {
|
|
22440
22483
|
return true;
|
|
22441
22484
|
}
|
|
22442
22485
|
}
|
|
22443
|
-
|
|
22444
|
-
if (EMBEDDING_AFFECTING_TOP_LEVEL_KEYS.has(recoveredKey)) {
|
|
22445
|
-
return true;
|
|
22446
|
-
}
|
|
22447
|
-
}
|
|
22448
|
-
if (embeddingConfigHasLiteralTokens(detailed.config.embedding)) {
|
|
22486
|
+
if (untrustedConfigFieldPaths(detailed).length > 0)
|
|
22449
22487
|
return true;
|
|
22450
|
-
}
|
|
22451
22488
|
return false;
|
|
22452
22489
|
}
|
|
22453
22490
|
function describeFailure(detailed) {
|
|
@@ -22460,8 +22497,9 @@ function describeFailure(detailed) {
|
|
|
22460
22497
|
if (detailed.substitutionFailures.length > 0) {
|
|
22461
22498
|
parts.push(`substitution=${detailed.substitutionFailures.map((failure) => `${failure.source}:${failure.keyPath}`).join(",")}`);
|
|
22462
22499
|
}
|
|
22463
|
-
|
|
22464
|
-
|
|
22500
|
+
const recovered = detailed.recoveredFieldPaths ?? detailed.recoveredTopLevelKeys;
|
|
22501
|
+
if (recovered.length > 0) {
|
|
22502
|
+
parts.push(`recovered=${recovered.join(",")}`);
|
|
22465
22503
|
}
|
|
22466
22504
|
return parts.length > 0 ? parts.join("; ") : detailed.loadOutcome;
|
|
22467
22505
|
}
|
|
@@ -22469,7 +22507,8 @@ function logConfigFailureOnce(projectIdentity, detailed) {
|
|
|
22469
22507
|
const signature = sha256Prefix(JSON.stringify({
|
|
22470
22508
|
outcomes: detailed.sources,
|
|
22471
22509
|
substitutions: detailed.substitutionFailures.map((failure) => `${failure.source}:${failure.keyPath}:${failure.message}`).sort(),
|
|
22472
|
-
recoveredTopLevelKeys: [...detailed.recoveredTopLevelKeys].sort()
|
|
22510
|
+
recoveredTopLevelKeys: [...detailed.recoveredTopLevelKeys].sort(),
|
|
22511
|
+
recoveredFieldPaths: detailed.recoveredFieldPaths?.slice().sort()
|
|
22473
22512
|
}));
|
|
22474
22513
|
const existing = loggedFailureSignatures.get(projectIdentity) ?? new Set;
|
|
22475
22514
|
if (existing.has(signature))
|
|
@@ -22485,9 +22524,14 @@ function handleUntrustedLoad(db, projectIdentity, directory, detailed) {
|
|
|
22485
22524
|
logConfigFailureOnce(projectIdentity, detailed);
|
|
22486
22525
|
return true;
|
|
22487
22526
|
}
|
|
22488
|
-
registerProjectInObservationMode2(db, projectIdentity, directory, detailed.config.embedding, describeFailure(detailed));
|
|
22527
|
+
registerProjectInObservationMode2(db, projectIdentity, directory, detailed.config.embedding, describeFailure(detailed), untrustedConfigMemoryMessage(detailed));
|
|
22489
22528
|
return true;
|
|
22490
22529
|
}
|
|
22530
|
+
function untrustedConfigMemoryMessage(detailed) {
|
|
22531
|
+
const fields = untrustedConfigFieldPaths(detailed);
|
|
22532
|
+
const cause = fields.length > 0 ? `has invalid embedding or project identity settings: ${fields.join(", ")}` : Object.values(detailed.sources).includes("legacy-config-unmigrated") ? "is awaiting config migration" : Object.values(detailed.sources).some((source) => source === "project-file-parse-error" || source === "project-file-io-error") ? "could not be read or parsed" : "has invalid embedding settings";
|
|
22533
|
+
return `Cross-session memory is off for this project because magic-context.jsonc ${cause}.`;
|
|
22534
|
+
}
|
|
22491
22535
|
|
|
22492
22536
|
// src/plugin/embedding-routing.ts
|
|
22493
22537
|
var SYNAPSE_PROBE_TTL_MS = 60000;
|
|
@@ -23034,13 +23078,15 @@ function runnerStatusFromModule(status) {
|
|
|
23034
23078
|
}
|
|
23035
23079
|
var rustStatusInFlight = new Map;
|
|
23036
23080
|
function resolveSidebarWorkMetrics(db, sessionId, persistedNewWork, persistedTotalInput) {
|
|
23037
|
-
|
|
23081
|
+
const generation = getHarness2() === "opencode2" ? "v2" : "v1";
|
|
23082
|
+
if (!openCodeDbExists(generation)) {
|
|
23038
23083
|
return { newWorkTokens: persistedNewWork, totalInputTokens: persistedTotalInput };
|
|
23039
23084
|
}
|
|
23040
23085
|
try {
|
|
23041
|
-
const
|
|
23042
|
-
const
|
|
23043
|
-
|
|
23086
|
+
const carryKey = `${generation}:${sessionId}`;
|
|
23087
|
+
const carry = workMetricsCarryBySession.get(carryKey) ?? emptyWorkMetricsCarry();
|
|
23088
|
+
const { carry: nextCarry, metrics } = withReadOnlySessionDb((openCodeDb) => computeOpenCodeWorkMetricsIncremental(openCodeDb, sessionId, carry, generation), generation);
|
|
23089
|
+
workMetricsCarryBySession.set(carryKey, nextCarry);
|
|
23044
23090
|
try {
|
|
23045
23091
|
setSessionWorkMetrics(db, sessionId, metrics.newWorkTokens, metrics.totalInputTokens);
|
|
23046
23092
|
} catch {}
|
|
@@ -23941,8 +23987,8 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
23941
23987
|
const db = readDatabase();
|
|
23942
23988
|
if (!db)
|
|
23943
23989
|
return { ok: false, error: "db unavailable" };
|
|
23944
|
-
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-
|
|
23945
|
-
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-
|
|
23990
|
+
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-f1df1gb8.js"));
|
|
23991
|
+
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-x5nzy34v.js"));
|
|
23946
23992
|
log2(`[rpc] recomp requested for session ${sessionId}`);
|
|
23947
23993
|
if (!args.client && !args.hiddenCompletionExecutor) {
|
|
23948
23994
|
return {
|
|
@@ -24026,7 +24072,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
24026
24072
|
const db = readDatabase();
|
|
24027
24073
|
if (!db)
|
|
24028
24074
|
return { ok: false, error: "db unavailable" };
|
|
24029
|
-
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-
|
|
24075
|
+
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-jq33fda8.js"));
|
|
24030
24076
|
const model = liveSessionState.liveModelBySession.get(sessionId);
|
|
24031
24077
|
const contextLimit = model ? resolveContextLimit(model.providerID, model.modelID, { db, sessionID: sessionId }) : 128000;
|
|
24032
24078
|
const ctx = {
|
|
@@ -27139,6 +27185,16 @@ function toolResultText(result) {
|
|
|
27139
27185
|
`);
|
|
27140
27186
|
return text.length > 0 ? text : undefined;
|
|
27141
27187
|
}
|
|
27188
|
+
function sumRowUsage(rows) {
|
|
27189
|
+
const count = (value) => typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
27190
|
+
return rows.reduce((total, row) => ({
|
|
27191
|
+
input: total.input + count(row.data.tokens?.input),
|
|
27192
|
+
output: total.output + count(row.data.tokens?.output),
|
|
27193
|
+
cacheRead: total.cacheRead + count(row.data.tokens?.cache?.read),
|
|
27194
|
+
cacheWrite: total.cacheWrite + count(row.data.tokens?.cache?.write),
|
|
27195
|
+
...total.reasoning !== undefined || row.data.tokens?.reasoning !== undefined ? { reasoning: (total.reasoning ?? 0) + count(row.data.tokens?.reasoning) } : {}
|
|
27196
|
+
}), { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 });
|
|
27197
|
+
}
|
|
27142
27198
|
function toolLoopMessages(attempt, rows) {
|
|
27143
27199
|
const messages = attempt.observedMessages ?? [];
|
|
27144
27200
|
const results = new Map;
|
|
@@ -27331,6 +27387,10 @@ function createLateHiddenExecutor(current) {
|
|
|
27331
27387
|
open: (run) => wired().open(run),
|
|
27332
27388
|
attempt: (handle, request) => wired().attempt(handle, request),
|
|
27333
27389
|
collect: (handle, limit) => wired().collect(handle, limit),
|
|
27390
|
+
collectPartial: (handle, limit) => {
|
|
27391
|
+
const executor = wired();
|
|
27392
|
+
return executor.collectPartial?.(handle, limit) ?? executor.collect(handle, limit);
|
|
27393
|
+
},
|
|
27334
27394
|
close: (handle, settlement) => wired().close(handle, settlement)
|
|
27335
27395
|
};
|
|
27336
27396
|
}
|
|
@@ -27420,9 +27480,32 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
27420
27480
|
});
|
|
27421
27481
|
run.child = lifecycle.updateModel(run.child, requested);
|
|
27422
27482
|
};
|
|
27483
|
+
const partialCompletion = (run) => {
|
|
27484
|
+
const attempt = run.attempt;
|
|
27485
|
+
const rows = attempt ? withReader(options.openReader, (reader) => {
|
|
27486
|
+
const latest = reader.latestAssistant(run.child.id);
|
|
27487
|
+
return (reader.assistantSince?.(run.child.id, attempt.baseline) ?? (latest ? [latest] : [])).filter((row) => row.seq > attempt.baseline);
|
|
27488
|
+
}) : [];
|
|
27489
|
+
const usage = sumRowUsage(rows);
|
|
27490
|
+
return {
|
|
27491
|
+
text: rows.map(assistantText).filter(Boolean).join(`
|
|
27492
|
+
`) || null,
|
|
27493
|
+
messages: attempt ? toolLoopMessages(attempt.child, rows) : [],
|
|
27494
|
+
usage,
|
|
27495
|
+
tokenLog: runTokenLog(usage),
|
|
27496
|
+
lengthCapped: false
|
|
27497
|
+
};
|
|
27498
|
+
};
|
|
27423
27499
|
const retire = (run, reason) => {
|
|
27424
27500
|
if (run.retired)
|
|
27425
27501
|
return;
|
|
27502
|
+
if (hiddenToolLoop(run.identity) && !run.completion) {
|
|
27503
|
+
try {
|
|
27504
|
+
run.partialCompletion = partialCompletion(run);
|
|
27505
|
+
} catch (error) {
|
|
27506
|
+
note(`[magic-context] could not read interrupted child output: ${String(error)}`);
|
|
27507
|
+
}
|
|
27508
|
+
}
|
|
27426
27509
|
lifecycle.retire(run.child, reason);
|
|
27427
27510
|
run.retired = true;
|
|
27428
27511
|
};
|
|
@@ -27553,6 +27636,8 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
27553
27636
|
shaped: false,
|
|
27554
27637
|
budget: run.budget
|
|
27555
27638
|
};
|
|
27639
|
+
run.partialCompletion = undefined;
|
|
27640
|
+
run.attempt = { child: attempt, baseline };
|
|
27556
27641
|
options.hook.registerAttempt(marker, attempt);
|
|
27557
27642
|
const deadline = Date.now() + run.identity.timeoutMs;
|
|
27558
27643
|
const budget = run.budget;
|
|
@@ -27688,19 +27773,14 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
27688
27773
|
const tokenNumber = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
27689
27774
|
const steps = withReader(options.openReader, (reader) => reader.assistantSince?.(run.child.id, baseline) ?? [row]).filter((step) => step.seq > baseline && step.seq <= row.seq);
|
|
27690
27775
|
const reportedUsage = steps.some((step) => tokenNumber(step.data.tokens?.input) !== undefined || tokenNumber(step.data.tokens?.output) !== undefined);
|
|
27691
|
-
const usage = steps
|
|
27692
|
-
input: total.input + (tokenNumber(step.data.tokens?.input) ?? 0),
|
|
27693
|
-
output: total.output + (tokenNumber(step.data.tokens?.output) ?? 0),
|
|
27694
|
-
cacheRead: total.cacheRead + (tokenNumber(step.data.tokens?.cache?.read) ?? 0),
|
|
27695
|
-
cacheWrite: total.cacheWrite + (tokenNumber(step.data.tokens?.cache?.write) ?? 0)
|
|
27696
|
-
}), { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 });
|
|
27776
|
+
const usage = sumRowUsage(steps);
|
|
27697
27777
|
if (request.signal?.aborted || run.retired || Date.now() >= deadline) {
|
|
27698
27778
|
await interruptAndRetire(run, "prompt-aborted-or-timeout");
|
|
27699
27779
|
throw new Error(request.signal?.aborted ? "Hidden completion prompt aborted" : "Hidden completion prompt timed out");
|
|
27700
27780
|
}
|
|
27701
27781
|
run.completion = {
|
|
27702
27782
|
text,
|
|
27703
|
-
tokenLog: runTokenLog(tokens, run.identity.maxOutputTokens, row.data.finish),
|
|
27783
|
+
tokenLog: runTokenLog(reportedUsage ? usage : tokens, run.identity.maxOutputTokens, row.data.finish),
|
|
27704
27784
|
...hiddenToolLoop(run.identity) ? { messages: toolLoopMessages(attempt, steps) } : {},
|
|
27705
27785
|
reasoning: text ? null : assistantReasoning(row),
|
|
27706
27786
|
usage: reportedUsage ? usage : meter(system, promptText(request), text ?? ""),
|
|
@@ -27749,6 +27829,12 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
27749
27829
|
throw new Error("Hidden completion has no settled output");
|
|
27750
27830
|
return completion;
|
|
27751
27831
|
},
|
|
27832
|
+
async collectPartial(handle) {
|
|
27833
|
+
const run = runs.get(handle);
|
|
27834
|
+
if (!run)
|
|
27835
|
+
throw new Error("Hidden completion handle is closed");
|
|
27836
|
+
return run.completion ?? run.partialCompletion ?? partialCompletion(run);
|
|
27837
|
+
},
|
|
27752
27838
|
async close(handle, settlement) {
|
|
27753
27839
|
if (!handle)
|
|
27754
27840
|
return;
|
|
@@ -28923,7 +29009,7 @@ async function runHiddenSingleShotPrompt(args) {
|
|
|
28923
29009
|
let timer;
|
|
28924
29010
|
try {
|
|
28925
29011
|
const completion = await Promise.race([
|
|
28926
|
-
args.executor.collect(handle, 200),
|
|
29012
|
+
args.executor.collectPartial?.(handle, 200) ?? args.executor.collect(handle, 200),
|
|
28927
29013
|
new Promise((resolve) => {
|
|
28928
29014
|
timer = setTimeout(() => resolve(null), 5000);
|
|
28929
29015
|
})
|
|
@@ -30756,6 +30842,7 @@ Remember: output only the JSON object described by the system prompt.`;
|
|
|
30756
30842
|
let childSessionId = null;
|
|
30757
30843
|
let promptSettled = false;
|
|
30758
30844
|
let invocationRecorded = false;
|
|
30845
|
+
let completionUsage;
|
|
30759
30846
|
const recordInvocation = (params) => {
|
|
30760
30847
|
if (!args.db || !args.parentSessionId || invocationRecorded)
|
|
30761
30848
|
return;
|
|
@@ -30769,6 +30856,7 @@ Remember: output only the JSON object described by the system prompt.`;
|
|
|
30769
30856
|
startedAt,
|
|
30770
30857
|
status: params.status,
|
|
30771
30858
|
messages: params.messages,
|
|
30859
|
+
tokens: args.hiddenCompletionExecutor?.capabilities.harness === "opencode2" ? completionUsage : undefined,
|
|
30772
30860
|
attemptedModel: args.model,
|
|
30773
30861
|
configuredModels: args.fallbackModels,
|
|
30774
30862
|
error: params.error
|
|
@@ -30793,11 +30881,15 @@ Remember: output only the JSON object described by the system prompt.`;
|
|
|
30793
30881
|
timeoutMs: remainingMs,
|
|
30794
30882
|
signal: args.signal,
|
|
30795
30883
|
metadata: { task: "evaluate-smart-notes" },
|
|
30884
|
+
onFailureOutput: (completion) => {
|
|
30885
|
+
completionUsage = completion.usage;
|
|
30886
|
+
},
|
|
30796
30887
|
parse: parseCompilerOutput
|
|
30797
30888
|
});
|
|
30798
30889
|
promptSettled = true;
|
|
30799
30890
|
response = carried.validated;
|
|
30800
30891
|
outputMessages = carried.completion.messages;
|
|
30892
|
+
completionUsage = carried.completion.usage;
|
|
30801
30893
|
} else {
|
|
30802
30894
|
const client = args.client;
|
|
30803
30895
|
if (!client) {
|
|
@@ -31575,6 +31667,7 @@ async function confirmReadOnly(args, noteId, content, surfaceCondition, leaseSig
|
|
|
31575
31667
|
startedAt,
|
|
31576
31668
|
status: params.status,
|
|
31577
31669
|
messages: params.messages,
|
|
31670
|
+
tokens: args.hiddenCompletionExecutor?.capabilities.harness === "opencode2" ? params.tokens : undefined,
|
|
31578
31671
|
attemptedModel: args.model,
|
|
31579
31672
|
configuredModels: args.fallbackModels,
|
|
31580
31673
|
error: params.error
|
|
@@ -31602,7 +31695,11 @@ async function confirmReadOnly(args, noteId, content, surfaceCondition, leaseSig
|
|
|
31602
31695
|
parse: parseConfirmationVerdict
|
|
31603
31696
|
});
|
|
31604
31697
|
promptSettled = true;
|
|
31605
|
-
recordInvocation({
|
|
31698
|
+
recordInvocation({
|
|
31699
|
+
status: "completed",
|
|
31700
|
+
messages: run.completion.messages,
|
|
31701
|
+
tokens: run.completion.usage
|
|
31702
|
+
});
|
|
31606
31703
|
return run.validated;
|
|
31607
31704
|
} finally {
|
|
31608
31705
|
promptSignal.cleanup();
|
|
@@ -32160,8 +32257,8 @@ async function mapMemories(args) {
|
|
|
32160
32257
|
result.failureStage = outcome.failure.stage;
|
|
32161
32258
|
}
|
|
32162
32259
|
const committed = outcome.mapped + outcome.independent;
|
|
32260
|
+
const committedIds = new Set(outcome.committedIds);
|
|
32163
32261
|
runLeaseGuardedWrite(args.db, args.holderId, args.leaseKey, () => {
|
|
32164
|
-
const committedIds = new Set(outcome.committedIds);
|
|
32165
32262
|
for (const memory of batch.inputs) {
|
|
32166
32263
|
if (committedIds.has(memory.id)) {
|
|
32167
32264
|
delete retries[memory.id];
|
|
@@ -32196,7 +32293,22 @@ async function mapMemories(args) {
|
|
|
32196
32293
|
log2(`[dreamer] map-memories: targeted retry still omitted ${outcome.requeue.length} id(s); leaving them unmapped for the next run`);
|
|
32197
32294
|
}
|
|
32198
32295
|
}
|
|
32199
|
-
if (outcome.failure?.class === "timeout" &&
|
|
32296
|
+
if (outcome.failure?.class === "timeout" && batch.inputs.length > 1) {
|
|
32297
|
+
const unmapped = batch.inputs.filter((memory) => !committedIds.has(memory.id));
|
|
32298
|
+
const splitSize = Math.floor(batch.inputs.length / 2);
|
|
32299
|
+
const splits = [];
|
|
32300
|
+
for (let offset = 0;offset < unmapped.length; offset += splitSize) {
|
|
32301
|
+
splits.push({
|
|
32302
|
+
inputs: unmapped.slice(offset, offset + splitSize),
|
|
32303
|
+
isOmissionRetry: batch.isOmissionRetry
|
|
32304
|
+
});
|
|
32305
|
+
}
|
|
32306
|
+
if (splits.length > 0) {
|
|
32307
|
+
batches.splice(i + 1, 0, ...splits);
|
|
32308
|
+
log2(`[dreamer] map-memories: splitting batch [${batch.inputs.map((memory) => memory.id).join(",")}] into ${splits.map((split) => split.inputs.length).join("+")} after timeout; retrying ${unmapped.length} uncommitted mapping(s)`);
|
|
32309
|
+
}
|
|
32310
|
+
}
|
|
32311
|
+
if (outcome.failure?.class === "timeout" && batch.inputs.length === 1 && committed === 0) {
|
|
32200
32312
|
consecutiveTimeouts += 1;
|
|
32201
32313
|
timeoutStreakElapsedMs.push(outcome.failure.elapsedMs);
|
|
32202
32314
|
if (consecutiveTimeouts >= CONSECUTIVE_TIMEOUT_LIMIT2) {
|
|
@@ -32204,7 +32316,7 @@ async function mapMemories(args) {
|
|
|
32204
32316
|
log2(`[dreamer] map-memories starvation: circuit breaker tripped after ${consecutiveTimeouts} consecutive batch timeouts with no committed mappings (investigation made no durable progress); per-batch elapsed [${timeoutStreakElapsedMs.join("ms, ")}ms] vs ${sliceMs}ms slice; stopping with ${result.remaining} mapping(s) remaining`);
|
|
32205
32317
|
break;
|
|
32206
32318
|
}
|
|
32207
|
-
} else {
|
|
32319
|
+
} else if (committed > 0 || outcome.failure?.class !== "timeout") {
|
|
32208
32320
|
consecutiveTimeouts = 0;
|
|
32209
32321
|
timeoutStreakElapsedMs = [];
|
|
32210
32322
|
}
|
|
@@ -32255,7 +32367,8 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
32255
32367
|
});
|
|
32256
32368
|
recordInvocation2(args, startedAt, {
|
|
32257
32369
|
status: "completed",
|
|
32258
|
-
messages: run.completion.messages ?? []
|
|
32370
|
+
messages: run.completion.messages ?? [],
|
|
32371
|
+
tokens: run.completion.usage
|
|
32259
32372
|
});
|
|
32260
32373
|
stage = "apply";
|
|
32261
32374
|
const outcome = await applyParsedBatchMappings(args, batch, run.validated, budgetFinalized, true);
|
|
@@ -32330,7 +32443,8 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
32330
32443
|
recordInvocation2(args, startedAt, {
|
|
32331
32444
|
status: failedInvocationStatus(error),
|
|
32332
32445
|
error,
|
|
32333
|
-
messages
|
|
32446
|
+
messages,
|
|
32447
|
+
tokens: failedCompletion?.usage
|
|
32334
32448
|
});
|
|
32335
32449
|
if (error instanceof DreamerModuleFailureError)
|
|
32336
32450
|
throw error;
|
|
@@ -32497,6 +32611,7 @@ function recordInvocation2(args, startedAt, params) {
|
|
|
32497
32611
|
startedAt,
|
|
32498
32612
|
status: params.status,
|
|
32499
32613
|
messages: params.messages,
|
|
32614
|
+
tokens: args.hiddenCompletionExecutor?.capabilities.harness === "opencode2" ? params.tokens : undefined,
|
|
32500
32615
|
attemptedModel: args.model,
|
|
32501
32616
|
configuredModels: args.fallbackModels,
|
|
32502
32617
|
error: params.error
|
|
@@ -33775,7 +33890,8 @@ async function git2(root, args) {
|
|
|
33775
33890
|
cwd: root,
|
|
33776
33891
|
timeout: 1e4,
|
|
33777
33892
|
maxBuffer: MAX_DIFF_BYTES,
|
|
33778
|
-
encoding: "utf8"
|
|
33893
|
+
encoding: "utf8",
|
|
33894
|
+
windowsHide: true
|
|
33779
33895
|
});
|
|
33780
33896
|
return stdout;
|
|
33781
33897
|
}
|
|
@@ -34417,7 +34533,8 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
34417
34533
|
});
|
|
34418
34534
|
recordInvocation4(args, startedAt, {
|
|
34419
34535
|
status: "completed",
|
|
34420
|
-
messages: run.completion.messages ?? []
|
|
34536
|
+
messages: run.completion.messages ?? [],
|
|
34537
|
+
tokens: run.completion.usage
|
|
34421
34538
|
});
|
|
34422
34539
|
reportUsage(run.completion.messages ?? [], run.childSessionId, run.completion.usage.input + (run.completion.usage.cacheRead ?? 0) + (run.completion.usage.cacheWrite ?? 0));
|
|
34423
34540
|
return await applyParsedVerifyManifest(args, batch, run.validated, evidence?.head ?? headAtPrompt, budgetFinalized);
|
|
@@ -34491,7 +34608,8 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
34491
34608
|
recordInvocation4(args, startedAt, {
|
|
34492
34609
|
status: failedInvocationStatus(error),
|
|
34493
34610
|
error,
|
|
34494
|
-
messages
|
|
34611
|
+
messages,
|
|
34612
|
+
tokens: failedCompletion?.usage
|
|
34495
34613
|
});
|
|
34496
34614
|
if (error instanceof DreamerModuleFailureError || signal.aborted)
|
|
34497
34615
|
throw error;
|
|
@@ -34750,6 +34868,7 @@ function recordInvocation4(args, startedAt, params) {
|
|
|
34750
34868
|
startedAt,
|
|
34751
34869
|
status: params.status,
|
|
34752
34870
|
messages: params.messages,
|
|
34871
|
+
tokens: args.hiddenCompletionExecutor?.capabilities.harness === "opencode2" ? params.tokens : undefined,
|
|
34753
34872
|
attemptedModel: args.model,
|
|
34754
34873
|
configuredModels: args.fallbackModels,
|
|
34755
34874
|
error: params.error
|
|
@@ -34819,6 +34938,15 @@ function classifyFailure(error) {
|
|
|
34819
34938
|
const transient = explicitTransient || name === "AbortError" || /abort|lease|timeout|timed out|econn|socket|network|rate.?limit|429|503|overloaded|sqlite_busy|database is locked/.test(combined);
|
|
34820
34939
|
return { transient, brief };
|
|
34821
34940
|
}
|
|
34941
|
+
function sumCompletionUsages(usages) {
|
|
34942
|
+
return usages.reduce((total, usage) => ({
|
|
34943
|
+
input: total.input + usage.input,
|
|
34944
|
+
output: total.output + usage.output,
|
|
34945
|
+
cacheRead: total.cacheRead + usage.cacheRead,
|
|
34946
|
+
cacheWrite: total.cacheWrite + usage.cacheWrite,
|
|
34947
|
+
...total.reasoning !== undefined || usage.reasoning !== undefined ? { reasoning: (total.reasoning ?? 0) + (usage.reasoning ?? 0) } : {}
|
|
34948
|
+
}), emptyTokenTotals());
|
|
34949
|
+
}
|
|
34822
34950
|
function newIds(beforeIds, afterIds) {
|
|
34823
34951
|
const before = new Set(beforeIds);
|
|
34824
34952
|
const out = [];
|
|
@@ -35626,6 +35754,7 @@ async function runRetrospectiveTask(config, ctx, helpers) {
|
|
|
35626
35754
|
}, ctx.leaseAcquisition);
|
|
35627
35755
|
let childSessionId = null;
|
|
35628
35756
|
let hiddenHandle = null;
|
|
35757
|
+
const hiddenUsages = [];
|
|
35629
35758
|
let promptSettled = false;
|
|
35630
35759
|
let invocationRecorded = false;
|
|
35631
35760
|
const recordInvocation = (status, messages, error) => {
|
|
@@ -35641,6 +35770,7 @@ async function runRetrospectiveTask(config, ctx, helpers) {
|
|
|
35641
35770
|
startedAt: helpers.invocationStartedAt,
|
|
35642
35771
|
status,
|
|
35643
35772
|
messages,
|
|
35773
|
+
tokens: deps.hiddenCompletionExecutor?.capabilities.harness === "opencode2" && hiddenUsages.length ? sumCompletionUsages(hiddenUsages) : undefined,
|
|
35644
35774
|
attemptedModel: config.model,
|
|
35645
35775
|
configuredModels: config.fallbackModels,
|
|
35646
35776
|
error
|
|
@@ -35726,6 +35856,8 @@ async function runRetrospectiveTask(config, ctx, helpers) {
|
|
|
35726
35856
|
}
|
|
35727
35857
|
});
|
|
35728
35858
|
promptSettled = true;
|
|
35859
|
+
if (hiddenHandle)
|
|
35860
|
+
hiddenUsages.push(run.output.usage);
|
|
35729
35861
|
const output = hiddenHandle ? run.output.messages ?? [] : run.output;
|
|
35730
35862
|
return { ...run, output };
|
|
35731
35863
|
};
|
|
@@ -35896,6 +36028,7 @@ async function runAgenticTask(config, ctx, helpers) {
|
|
|
35896
36028
|
let childSessionId = null;
|
|
35897
36029
|
let promptSettled = false;
|
|
35898
36030
|
let expiredArchived = 0;
|
|
36031
|
+
const hiddenUsages = [];
|
|
35899
36032
|
let invocationRecorded = false;
|
|
35900
36033
|
const recordInvocation = (status, messages, error) => {
|
|
35901
36034
|
if (!parent || !childSessionId || invocationRecorded)
|
|
@@ -35910,6 +36043,7 @@ async function runAgenticTask(config, ctx, helpers) {
|
|
|
35910
36043
|
startedAt: invocationStartedAt,
|
|
35911
36044
|
status,
|
|
35912
36045
|
messages,
|
|
36046
|
+
tokens: deps.hiddenCompletionExecutor?.capabilities.harness === "opencode2" && hiddenUsages.length ? sumCompletionUsages(hiddenUsages) : undefined,
|
|
35913
36047
|
attemptedModel: config.model,
|
|
35914
36048
|
configuredModels: config.fallbackModels,
|
|
35915
36049
|
error
|
|
@@ -36027,6 +36161,7 @@ async function runAgenticTask(config, ctx, helpers) {
|
|
|
36027
36161
|
}
|
|
36028
36162
|
});
|
|
36029
36163
|
childSessionId = hidden.childSessionId;
|
|
36164
|
+
hiddenUsages.push(hidden.completion.usage);
|
|
36030
36165
|
run = { output: hidden.completion.messages ?? [], validated: hidden.validated };
|
|
36031
36166
|
promptSettled = true;
|
|
36032
36167
|
} else {
|
|
@@ -37241,7 +37376,8 @@ async function sweepGitCommits(args) {
|
|
|
37241
37376
|
try {
|
|
37242
37377
|
const result = await indexCommitsForProject(db, projectIdentity, directory, {
|
|
37243
37378
|
sinceDays: gitCommitIndexing.since_days,
|
|
37244
|
-
maxCommits: gitCommitIndexing.max_commits
|
|
37379
|
+
maxCommits: gitCommitIndexing.max_commits,
|
|
37380
|
+
skipRetention: isCommitRetentionPaused(gitCommitIndexing)
|
|
37245
37381
|
});
|
|
37246
37382
|
if (result.nonIndexable) {
|
|
37247
37383
|
if (!parkGitSweepNonIndexable(db, projectIdentity, holderId)) {
|
|
@@ -37326,11 +37462,7 @@ function registerV2DreamScheduleTimer(args) {
|
|
|
37326
37462
|
embeddingConfig: config.embedding,
|
|
37327
37463
|
transformMode: config.transform_mode,
|
|
37328
37464
|
moduleClient: createDreamTimerModuleClient(args.rustModeModuleClient),
|
|
37329
|
-
gitCommitIndexing: gitCommitIndexing?.enabled ?
|
|
37330
|
-
enabled: true,
|
|
37331
|
-
since_days: gitCommitIndexing.since_days,
|
|
37332
|
-
max_commits: gitCommitIndexing.max_commits
|
|
37333
|
-
} : undefined,
|
|
37465
|
+
gitCommitIndexing: gitCommitIndexing?.enabled ? gitCommitIndexing : undefined,
|
|
37334
37466
|
ensureRegistered: args.ensureRegistered ?? ensureProjectRegisteredFromOpenCodeDirectory
|
|
37335
37467
|
}).catch((error) => {
|
|
37336
37468
|
log2(`[magic-context] v2 dream timer registration failed (continuing without it): ${error}`);
|
|
@@ -38399,7 +38531,7 @@ function projectRawMessages(rows, ordinalFor) {
|
|
|
38399
38531
|
const message = {
|
|
38400
38532
|
id: row.id,
|
|
38401
38533
|
ordinal: ordinalFor(row, index),
|
|
38402
|
-
role: row.type === "assistant" ? "assistant" : "user",
|
|
38534
|
+
role: row.type === "assistant" ? "assistant" : row.type === "system" ? "system" : "user",
|
|
38403
38535
|
createdAt: row.time_created ?? row.data.time?.created,
|
|
38404
38536
|
parts: row.type === "assistant" ? (row.data.content ?? []).map((part) => {
|
|
38405
38537
|
if (part.type !== "tool")
|
|
@@ -51087,7 +51219,7 @@ function createCtxMemoryTool(deps) {
|
|
|
51087
51219
|
const memoryOwnedByTool = (memory) => visibility.owned(memory);
|
|
51088
51220
|
const embeddingSnapshot = getProjectEmbeddingSnapshot2(projectPath);
|
|
51089
51221
|
if (embeddingSnapshot ? !embeddingSnapshot.features.memoryEnabled : deps.memoryEnabled === false) {
|
|
51090
|
-
return getDisabledMessage();
|
|
51222
|
+
return embeddingSnapshot?.memoryDisabledReason ?? getDisabledMessage();
|
|
51091
51223
|
}
|
|
51092
51224
|
if (args.action === "write") {
|
|
51093
51225
|
const content = args.content?.trim();
|