@cortexkit/opencode-magic-context 0.49.17 → 0.49.19
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 +6 -2
- package/dist/chunk-embedding-write-worker.js +2 -2
- package/dist/{context-yhetp0kn.js → context-j31m2dv7.js} +27 -14
- package/dist/features/magic-context/dreamer/classify.d.ts +3 -0
- package/dist/features/magic-context/dreamer/classify.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/hidden-single-shot.d.ts +11 -0
- package/dist/features/magic-context/dreamer/hidden-single-shot.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/map-memories.d.ts +3 -0
- package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify.d.ts +3 -0
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/migrations.d.ts.map +1 -1
- package/dist/features/magic-context/storage-clone.d.ts.map +1 -1
- package/dist/features/magic-context/storage-host-instruction-retention.d.ts +11 -0
- package/dist/features/magic-context/storage-host-instruction-retention.d.ts.map +1 -0
- package/dist/features/magic-context/storage-meta-persisted.d.ts +13 -0
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-worker-evaluation.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-worker-evaluation.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/cache-busting-signals.d.ts +22 -1
- package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts +4 -2
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/file-token-coverage.d.ts +11 -0
- package/dist/hooks/magic-context/file-token-coverage.d.ts.map +1 -0
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +9 -0
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/host-served-rows.d.ts +25 -0
- package/dist/hooks/magic-context/host-served-rows.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +7 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts +13 -0
- 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 +1 -1
- package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
- package/dist/hooks/magic-context/pass-outcome.d.ts +2 -0
- package/dist/hooks/magic-context/pass-outcome.d.ts.map +1 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts +2 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- package/dist/hooks/magic-context/signed-thinking-hold.d.ts +59 -0
- package/dist/hooks/magic-context/signed-thinking-hold.d.ts.map +1 -0
- package/dist/hooks/magic-context/system-date-refresh.d.ts +15 -2
- package/dist/hooks/magic-context/system-date-refresh.d.ts.map +1 -1
- package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-content-primitives.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +6 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-context-state.d.ts +19 -0
- package/dist/hooks/magic-context/transform-context-state.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +21 -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-aabzay3h.js → index-3esx8tkf.js} +256 -50
- package/dist/{index-v8awdgvd.js → index-3h4dp9wb.js} +1 -1
- package/dist/{index-5a1ex6x8.js → index-4911rn0b.js} +3 -3
- package/dist/{index-qn7xstt2.js → index-63k48rv9.js} +1 -2
- package/dist/{index-p7m7j0cp.js → index-9zcsy3hh.js} +53 -7
- package/dist/{index-nkpmm9q8.js → index-c1p88z1y.js} +3 -3
- package/dist/{index-hqhm3wke.js → index-cf74k5ak.js} +2 -2
- package/dist/{index-vrzjhftj.js → index-dxmq29t1.js} +4 -4
- package/dist/{index-kmdj7dsq.js → index-edmpdxcw.js} +1 -1
- package/dist/{index-4yt7dtf4.js → index-jhghdnsm.js} +113 -44
- package/dist/{index-fb2qxs2y.js → index-jrr131e0.js} +2 -2
- package/dist/{index-a7c4r5re.js → index-rpxdjkm0.js} +216 -40
- package/dist/{index-cwzfcbtq.js → index-se4m2g6w.js} +10 -1
- package/dist/index.js +21 -17
- package/dist/{message-index-bounded-1633vc7f.js → message-index-bounded-zyc8h32y.js} +3 -3
- package/dist/{message-index-dprebmtt.js → message-index-gtpqnj8w.js} +3 -3
- package/dist/migration-worker.js +2 -2
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/messages-transform.d.ts.map +1 -1
- package/dist/plugin/tool-registry.d.ts.map +1 -1
- package/dist/raw-ordinal-warmup-worker.js +4 -4
- package/dist/{read-session-chunk-4zp09ejb.js → read-session-chunk-jjb48bt9.js} +2 -2
- package/dist/{recomp-orchestrator-z3ecszx6.js → recomp-orchestrator-999jj4bc.js} +8 -8
- package/dist/{search-archive-znyy44ve.js → search-archive-6vm0e2f5.js} +3 -3
- package/dist/{search-6mee3vty.js → search-xsqk1bj4.js} +6 -6
- package/dist/shared/model-suggestion-retry.d.ts +30 -1
- package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
- package/dist/shared/prompt-async-transport.d.ts.map +1 -1
- package/dist/{storage-tags-8qns3012.js → storage-tags-r7k9tjcv.js} +1 -1
- package/dist/tools/ctx-expand/rust-mode-tag.test-support.d.ts +15 -0
- package/dist/tools/ctx-expand/rust-mode-tag.test-support.d.ts.map +1 -0
- package/dist/tools/ctx-expand/tools.d.ts +11 -0
- package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-3ydzxa62.js → transform-postprocess-phase-jj99r7z2.js} +8 -8
- package/dist/v2/auto-search-worker.js +6 -2
- package/dist/v2/chunk-embedding-write-worker.js +2 -2
- package/dist/v2/{context-jn3zpeqh.js → context-y5yamxak.js} +378 -92
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/payload.d.ts.map +1 -1
- package/dist/v2/hooks/tools.d.ts.map +1 -1
- package/dist/v2/{message-index-pxehjpzx.js → message-index-8vz2pq76.js} +3 -3
- package/dist/v2/{message-index-bounded-hpejqyd8.js → message-index-bounded-spd8r7pj.js} +3 -3
- package/dist/v2/migration-worker.js +2 -2
- package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
- package/dist/v2/{read-session-chunk-zdppn4bj.js → read-session-chunk-cwkxrmns.js} +2 -2
- package/dist/v2/{recomp-orchestrator-cmqnfpp3.js → recomp-orchestrator-f6m9jr7p.js} +7 -7
- package/dist/v2/{search-archive-gfh11vs0.js → search-archive-wve3tq1k.js} +3 -3
- package/dist/v2/{search-66842dya.js → search-hwg7jfbj.js} +6 -6
- package/dist/v2/{server-zyzawhdw.js → server-27gq4mfz.js} +2 -2
- package/dist/v2/{server-3rhpvy84.js → server-2ar62dyx.js} +10 -1
- package/dist/v2/{server-ec4ca92p.js → server-45q69hkq.js} +1 -1
- package/dist/v2/{server-fw7wrk01.js → server-6vdzn1td.js} +216 -40
- package/dist/v2/{server-kh7dpa1a.js → server-9hx7g5jp.js} +53 -7
- package/dist/v2/{server-gtfhttbr.js → server-bmymkx73.js} +2 -2
- package/dist/v2/{server-vsw8tmm6.js → server-gsxjv2q2.js} +4 -4
- package/dist/v2/{server-my7k4eds.js → server-hm38q7r0.js} +1 -1
- package/dist/v2/{server-gpvay0xz.js → server-xq7dfjke.js} +1 -2
- package/dist/v2/server.js +2 -2
- package/dist/v2/{storage-tags-1h8k6ra9.js → storage-tags-3wdb8zph.js} +1 -1
- package/dist/v2/store-reader.d.ts +6 -0
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{wrapup-orchestrator-xs8redz9.js → wrapup-orchestrator-embdz8gj.js} +7 -7
- package/dist/{wrapup-orchestrator-j7d7ry5b.js → wrapup-orchestrator-whhbjmaz.js} +9 -9
- package/package.json +1 -1
- package/src/shared/model-suggestion-retry.test.ts +166 -0
- package/src/shared/model-suggestion-retry.ts +165 -14
- package/src/shared/prompt-async-transport.test.ts +107 -0
- package/src/shared/prompt-async-transport.ts +39 -0
|
@@ -89,7 +89,7 @@ import {
|
|
|
89
89
|
toMessageIndexSource2,
|
|
90
90
|
clearIndexedMessagesInTransaction2,
|
|
91
91
|
indexSourcesAfterOrdinal2
|
|
92
|
-
} from "./server-
|
|
92
|
+
} from "./server-2ar62dyx.js";
|
|
93
93
|
import {
|
|
94
94
|
detectOverflow,
|
|
95
95
|
SESSION_META_SELECT_COLUMNS,
|
|
@@ -105,12 +105,15 @@ import {
|
|
|
105
105
|
retreatPastHostUnservedRows,
|
|
106
106
|
snapTerminalCompartmentToServedRow,
|
|
107
107
|
isHostRenderedSystemMessage,
|
|
108
|
+
markCoveredInstructionRow,
|
|
109
|
+
isCoveredInstructionRow,
|
|
108
110
|
completedToolArcCrossesBoundary,
|
|
109
111
|
buildToolArcs,
|
|
110
112
|
fenceBoundaryForCompletedToolArcs,
|
|
111
113
|
fenceBoundaryForToolArcs,
|
|
112
114
|
buildTrueRawTokenIndex,
|
|
113
115
|
computeRawRangeFingerprint,
|
|
116
|
+
isFilePart,
|
|
114
117
|
DreamTokenBudgetExceeded,
|
|
115
118
|
TOKEN_BUDGET_FINALIZE_MESSAGE,
|
|
116
119
|
registerBudgetFinalizeChild,
|
|
@@ -127,6 +130,7 @@ import {
|
|
|
127
130
|
isRustMarkerAdmissionFenced,
|
|
128
131
|
readReplayEnvelope,
|
|
129
132
|
readReplayDocument,
|
|
133
|
+
updateReplayDocument,
|
|
130
134
|
writeReplayDocument,
|
|
131
135
|
describeProtectedTailDrainBudgetSkip,
|
|
132
136
|
loadProtectedTailMeta,
|
|
@@ -157,6 +161,7 @@ import {
|
|
|
157
161
|
serializeStrippedPlaceholderState,
|
|
158
162
|
THINKING_BINDING_RECOVERY_FROZEN_PREFIX,
|
|
159
163
|
THINKING_BINDING_STRIP_ORDER_END_MARKER,
|
|
164
|
+
COMPACTION_OFF_THINKING_FROZEN_PREFIX,
|
|
160
165
|
getMergedReasoningStrippedIds,
|
|
161
166
|
addMergedReasoningStrippedIds,
|
|
162
167
|
parseProcessedImageMarkers,
|
|
@@ -182,7 +187,7 @@ import {
|
|
|
182
187
|
getRawSessionTagKeysThrough2,
|
|
183
188
|
getLegacyProtectedTailStartOrdinal2,
|
|
184
189
|
readSessionChunk2
|
|
185
|
-
} from "./server-
|
|
190
|
+
} from "./server-9hx7g5jp.js";
|
|
186
191
|
import {
|
|
187
192
|
getTableColumnNames
|
|
188
193
|
} from "./server-pwv4ezb0.js";
|
|
@@ -192,7 +197,7 @@ import {
|
|
|
192
197
|
LATEST_SUPPORTED_VERSION,
|
|
193
198
|
getPersistedSchemaVersion,
|
|
194
199
|
openDatabase
|
|
195
|
-
} from "./server-
|
|
200
|
+
} from "./server-bmymkx73.js";
|
|
196
201
|
import {
|
|
197
202
|
providerMass,
|
|
198
203
|
calibrationForModelKey,
|
|
@@ -210,7 +215,7 @@ import {
|
|
|
210
215
|
foldShrunkPartTags2,
|
|
211
216
|
getTagNumberByMessageId2,
|
|
212
217
|
getActiveTagsBySession2
|
|
213
|
-
} from "./server-
|
|
218
|
+
} from "./server-27gq4mfz.js";
|
|
214
219
|
import {
|
|
215
220
|
resolveOpenCodeDbPath,
|
|
216
221
|
assertOpenCodeStoreGeneration,
|
|
@@ -240,7 +245,7 @@ import {
|
|
|
240
245
|
resolveStoredPathWorkspaceIdentity,
|
|
241
246
|
sourceNameForMemory,
|
|
242
247
|
computeWorkspaceEpochFingerprint
|
|
243
|
-
} from "./server-
|
|
248
|
+
} from "./server-xq7dfjke.js";
|
|
244
249
|
import {
|
|
245
250
|
shouldSkipHomeProjectMemory,
|
|
246
251
|
resolveProjectIdentity
|
|
@@ -253,7 +258,7 @@ import {
|
|
|
253
258
|
userFacingFailureCode,
|
|
254
259
|
promoteSessionFactsDurable,
|
|
255
260
|
embedPromotedFacts
|
|
256
|
-
} from "./server-
|
|
261
|
+
} from "./server-hm38q7r0.js";
|
|
257
262
|
import {
|
|
258
263
|
isMarkerCandidateBasisCurrent2,
|
|
259
264
|
invalidateMarkerCandidateBasis2,
|
|
@@ -2121,6 +2126,8 @@ function outputMessageIsPostAnchor(message, inputIndexById, anchorIndex) {
|
|
|
2121
2126
|
}
|
|
2122
2127
|
return false;
|
|
2123
2128
|
}
|
|
2129
|
+
if (isCoveredInstructionRow(message.info))
|
|
2130
|
+
return false;
|
|
2124
2131
|
if (!isSyntheticOutput(message))
|
|
2125
2132
|
return null;
|
|
2126
2133
|
const linked = ["sourceMessageId", "ownerMessageId", "anchorMessageId"].map((key) => recordValue(message.info, key)).find((value) => typeof value === "string");
|
|
@@ -2516,6 +2523,34 @@ function noteLkgCapturedPrefix(sessionId) {
|
|
|
2516
2523
|
if (!sessions.has(sessionId))
|
|
2517
2524
|
sessions.set(sessionId, {});
|
|
2518
2525
|
}
|
|
2526
|
+
function readPersistedLkgUntaggedInputIds(db, sessionId) {
|
|
2527
|
+
try {
|
|
2528
|
+
const saved = readReplayEnvelope(db, sessionId, "read").lkgUntaggedInputIds;
|
|
2529
|
+
return Array.isArray(saved) ? saved.filter((id) => typeof id === "string" && id.length > 0) : [];
|
|
2530
|
+
} catch (error) {
|
|
2531
|
+
sessionLog2(sessionId, "LKG untagged-input record unreadable:", error);
|
|
2532
|
+
return [];
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
function persistLkgUntaggedInputIds(db, sessionId, ids) {
|
|
2536
|
+
const next = [...new Set(ids)].sort();
|
|
2537
|
+
try {
|
|
2538
|
+
return updateReplayDocument(db, sessionId, (doc) => {
|
|
2539
|
+
const saved = Array.isArray(doc.lkgUntaggedInputIds) ? doc.lkgUntaggedInputIds : [];
|
|
2540
|
+
if (JSON.stringify(saved) === JSON.stringify(next))
|
|
2541
|
+
return false;
|
|
2542
|
+
doc.version = 2;
|
|
2543
|
+
if (next.length > 0)
|
|
2544
|
+
doc.lkgUntaggedInputIds = next;
|
|
2545
|
+
else
|
|
2546
|
+
delete doc.lkgUntaggedInputIds;
|
|
2547
|
+
return true;
|
|
2548
|
+
});
|
|
2549
|
+
} catch (error) {
|
|
2550
|
+
sessionLog2(sessionId, "LKG untagged-input record write failed:", error);
|
|
2551
|
+
return false;
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2519
2554
|
function noteLkgRecoveryPrefix(args) {
|
|
2520
2555
|
const digests = [
|
|
2521
2556
|
...args.entry.entryContentDigests,
|
|
@@ -2526,19 +2561,23 @@ function noteLkgRecoveryPrefix(args) {
|
|
|
2526
2561
|
const ids = args.entry.entryInputIds;
|
|
2527
2562
|
if (ids.some((id) => !id) || new Set(ids).size !== ids.length)
|
|
2528
2563
|
return false;
|
|
2564
|
+
const untaggedInputIds = new Set([
|
|
2565
|
+
...sessions.get(args.sessionId)?.prefix?.untaggedInputIds ?? [],
|
|
2566
|
+
...args.db ? readPersistedLkgUntaggedInputIds(args.db, args.sessionId) : [],
|
|
2567
|
+
...ids.slice(args.entry.anchorIndex + 1)
|
|
2568
|
+
]);
|
|
2529
2569
|
sessions.set(args.sessionId, {
|
|
2530
2570
|
fenceRevision: sessions.get(args.sessionId)?.fenceRevision,
|
|
2531
2571
|
prefix: {
|
|
2532
2572
|
inputs: ids.map((id, index) => ({ id, digest: digests[index] })),
|
|
2533
2573
|
json: JSON.stringify(args.messages),
|
|
2534
|
-
untaggedInputIds
|
|
2535
|
-
...sessions.get(args.sessionId)?.prefix?.untaggedInputIds ?? [],
|
|
2536
|
-
...ids.slice(args.entry.anchorIndex + 1)
|
|
2537
|
-
]),
|
|
2574
|
+
untaggedInputIds,
|
|
2538
2575
|
modelKey: args.modelKey,
|
|
2539
2576
|
providerKey: args.providerKey
|
|
2540
2577
|
}
|
|
2541
2578
|
});
|
|
2579
|
+
if (args.db)
|
|
2580
|
+
persistLkgUntaggedInputIds(args.db, args.sessionId, untaggedInputIds);
|
|
2542
2581
|
return true;
|
|
2543
2582
|
}
|
|
2544
2583
|
function readLkgRecoveryPrefix(sessionId, inputs, messages, db) {
|
|
@@ -3073,10 +3112,11 @@ function dropSlot(sessionId, _reason) {
|
|
|
3073
3112
|
if (pass !== undefined)
|
|
3074
3113
|
hydrationAttemptBySession.set(sessionId, pass);
|
|
3075
3114
|
}
|
|
3076
|
-
function noteEntry(sessionId,
|
|
3115
|
+
function noteEntry(sessionId, input) {
|
|
3077
3116
|
const slot = getSlot(sessionId);
|
|
3078
3117
|
if (!slot)
|
|
3079
3118
|
return null;
|
|
3119
|
+
const messages = input.some((message) => isCoveredInstructionRow(message.info)) ? input.filter((message) => !isCoveredInstructionRow(message.info)) : input;
|
|
3080
3120
|
const entryInputIds = messages.map((message) => {
|
|
3081
3121
|
const id = message.info?.id;
|
|
3082
3122
|
return typeof id === "string" ? id : "";
|
|
@@ -3537,11 +3577,15 @@ function clonePiContentDecisions(raw, filter) {
|
|
|
3537
3577
|
])}`);
|
|
3538
3578
|
continue;
|
|
3539
3579
|
}
|
|
3540
|
-
|
|
3541
|
-
|
|
3580
|
+
const thinkingPrefix = [
|
|
3581
|
+
THINKING_BINDING_RECOVERY_FROZEN_PREFIX,
|
|
3582
|
+
COMPACTION_OFF_THINKING_FROZEN_PREFIX
|
|
3583
|
+
].find((prefix) => entry.startsWith(prefix));
|
|
3584
|
+
if (thinkingPrefix) {
|
|
3585
|
+
const messageId = entry.slice(thinkingPrefix.length);
|
|
3542
3586
|
if (messageId.length === 0 || !filter.includeMessageId(messageId))
|
|
3543
3587
|
continue;
|
|
3544
|
-
copied.push(`${
|
|
3588
|
+
copied.push(`${thinkingPrefix}${mapMessageId(filter, messageId) ?? messageId}`);
|
|
3545
3589
|
continue;
|
|
3546
3590
|
}
|
|
3547
3591
|
if (entry.startsWith(MERGED_REASONING_PARTS_PREFIX) || entry.startsWith("pi-content-replay-"))
|
|
@@ -6460,9 +6504,33 @@ var promptFailureDetails = new WeakMap;
|
|
|
6460
6504
|
function isHostTimeoutError(error) {
|
|
6461
6505
|
return error !== null && typeof error === "object" && error.name === "TimeoutError";
|
|
6462
6506
|
}
|
|
6507
|
+
|
|
6508
|
+
class ModelProducedNoOutputError extends Error {
|
|
6509
|
+
waitedMs;
|
|
6510
|
+
constructor(waitedMs) {
|
|
6511
|
+
super(`prompt timed out after ${waitedMs}ms with no model output`);
|
|
6512
|
+
this.waitedMs = waitedMs;
|
|
6513
|
+
this.name = "ModelProducedNoOutputError";
|
|
6514
|
+
}
|
|
6515
|
+
}
|
|
6516
|
+
var modelActivityBySignal = new WeakMap;
|
|
6517
|
+
function noteModelActivityMonitored(signal) {
|
|
6518
|
+
const activity = signal ? modelActivityBySignal.get(signal) : undefined;
|
|
6519
|
+
if (activity)
|
|
6520
|
+
activity.monitored = true;
|
|
6521
|
+
}
|
|
6522
|
+
function noteModelOutputReceived(signal) {
|
|
6523
|
+
const activity = signal ? modelActivityBySignal.get(signal) : undefined;
|
|
6524
|
+
if (activity) {
|
|
6525
|
+
activity.monitored = true;
|
|
6526
|
+
activity.received = true;
|
|
6527
|
+
}
|
|
6528
|
+
}
|
|
6463
6529
|
function isPromptTimeoutError(error) {
|
|
6464
6530
|
if (isHostTimeoutError(error))
|
|
6465
6531
|
return true;
|
|
6532
|
+
if (error instanceof ModelProducedNoOutputError)
|
|
6533
|
+
return true;
|
|
6466
6534
|
return error instanceof Error && /^prompt timed out after \d+ms$/.test(error.message);
|
|
6467
6535
|
}
|
|
6468
6536
|
function getPromptFailureDetail(error) {
|
|
@@ -6540,12 +6608,22 @@ function raceWithSignal(work, signal) {
|
|
|
6540
6608
|
work.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
6541
6609
|
});
|
|
6542
6610
|
}
|
|
6543
|
-
async function promptWithTimeout(client, args, timeoutMs, signal, transport) {
|
|
6611
|
+
async function promptWithTimeout(client, args, timeoutMs, signal, transport, firstOutputTimeoutMs) {
|
|
6544
6612
|
if (signal?.aborted) {
|
|
6545
6613
|
throw new Error(externalAbortMessage(signal));
|
|
6546
6614
|
}
|
|
6547
6615
|
const controller = new AbortController;
|
|
6548
6616
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
6617
|
+
const activity = { monitored: false, received: false };
|
|
6618
|
+
modelActivityBySignal.set(controller.signal, activity);
|
|
6619
|
+
let silent = false;
|
|
6620
|
+
const firstOutputTimer = firstOutputTimeoutMs !== undefined && firstOutputTimeoutMs < timeoutMs ? setTimeout(() => {
|
|
6621
|
+
if (!activity.monitored || activity.received)
|
|
6622
|
+
return;
|
|
6623
|
+
silent = true;
|
|
6624
|
+
controller.abort();
|
|
6625
|
+
}, firstOutputTimeoutMs) : undefined;
|
|
6626
|
+
const timeoutError = () => silent && firstOutputTimeoutMs !== undefined ? new ModelProducedNoOutputError(firstOutputTimeoutMs) : new Error(`prompt timed out after ${timeoutMs}ms`);
|
|
6549
6627
|
const onExternalAbort = () => controller.abort();
|
|
6550
6628
|
signal?.addEventListener("abort", onExternalAbort);
|
|
6551
6629
|
try {
|
|
@@ -6568,7 +6646,7 @@ async function promptWithTimeout(client, args, timeoutMs, signal, transport) {
|
|
|
6568
6646
|
if (!transport || transport.childSessionId) {
|
|
6569
6647
|
await abortChildRun(client, transport?.childSessionId ?? args.path.id);
|
|
6570
6648
|
}
|
|
6571
|
-
throw
|
|
6649
|
+
throw timeoutError();
|
|
6572
6650
|
}
|
|
6573
6651
|
if (isHostTimeoutError(error)) {
|
|
6574
6652
|
if (!transport || transport.childSessionId) {
|
|
@@ -6578,13 +6656,15 @@ async function promptWithTimeout(client, args, timeoutMs, signal, transport) {
|
|
|
6578
6656
|
throw error;
|
|
6579
6657
|
} finally {
|
|
6580
6658
|
clearTimeout(timeout);
|
|
6659
|
+
if (firstOutputTimer)
|
|
6660
|
+
clearTimeout(firstOutputTimer);
|
|
6581
6661
|
signal?.removeEventListener("abort", onExternalAbort);
|
|
6582
6662
|
}
|
|
6583
6663
|
if (signal?.aborted || controller.signal.aborted) {
|
|
6584
6664
|
if (!transport || transport.childSessionId) {
|
|
6585
6665
|
await abortChildRun(client, transport?.childSessionId ?? args.path.id);
|
|
6586
6666
|
}
|
|
6587
|
-
throw
|
|
6667
|
+
throw signal?.aborted ? new Error(externalAbortMessage(signal)) : timeoutError();
|
|
6588
6668
|
}
|
|
6589
6669
|
}
|
|
6590
6670
|
async function abortChildRun(client, sessionId) {
|
|
@@ -6602,6 +6682,8 @@ async function abortChildRun(client, sessionId) {
|
|
|
6602
6682
|
function isNonRetryable(error, externalSignal) {
|
|
6603
6683
|
if (externalSignal?.aborted || error instanceof HiddenCompletionRefusal && error.terminal || error instanceof HiddenAgentStepLimit || error instanceof DreamTokenBudgetExceeded)
|
|
6604
6684
|
return true;
|
|
6685
|
+
if (error instanceof ModelProducedNoOutputError)
|
|
6686
|
+
return false;
|
|
6605
6687
|
if (error instanceof Error) {
|
|
6606
6688
|
if (error.name === "AbortError")
|
|
6607
6689
|
return true;
|
|
@@ -6633,7 +6715,7 @@ function classifyPromptFailure(error, phase, externalSignal) {
|
|
|
6633
6715
|
if (externalSignal?.aborted || message === "prompt aborted by external signal") {
|
|
6634
6716
|
return "child_aborted";
|
|
6635
6717
|
}
|
|
6636
|
-
if (/^prompt timed out after \d+ms$/.test(message) || isHostTimeoutError(error)) {
|
|
6718
|
+
if (error instanceof ModelProducedNoOutputError || /^prompt timed out after \d+ms$/.test(message) || isHostTimeoutError(error)) {
|
|
6637
6719
|
return "provider_timeout";
|
|
6638
6720
|
}
|
|
6639
6721
|
if (phase === "validation") {
|
|
@@ -6668,11 +6750,11 @@ function throwWithPromptFailure(legacyError, failedAttempts, args, timeoutMs, tr
|
|
|
6668
6750
|
});
|
|
6669
6751
|
throw error;
|
|
6670
6752
|
}
|
|
6671
|
-
async function attemptOnce(client, args, timeoutMs, signal, callContext, label, transport, allowModelSuggestions = true) {
|
|
6753
|
+
async function attemptOnce(client, args, timeoutMs, signal, callContext, label, transport, allowModelSuggestions = true, firstOutputTimeoutMs) {
|
|
6672
6754
|
const originalBody = { ...args.body };
|
|
6673
6755
|
const attemptArgs = copyPromptArgs(args, originalBody);
|
|
6674
6756
|
try {
|
|
6675
|
-
await promptWithTimeout(client, attemptArgs, timeoutMs, signal, transport);
|
|
6757
|
+
await promptWithTimeout(client, attemptArgs, timeoutMs, signal, transport, firstOutputTimeoutMs);
|
|
6676
6758
|
return;
|
|
6677
6759
|
} catch (error) {
|
|
6678
6760
|
if (isNonRetryable(error, signal) || !allowModelSuggestions)
|
|
@@ -6691,9 +6773,30 @@ async function attemptOnce(client, args, timeoutMs, signal, callContext, label,
|
|
|
6691
6773
|
providerID: suggestion.providerID,
|
|
6692
6774
|
modelID: suggestion.suggestion
|
|
6693
6775
|
}
|
|
6694
|
-
}), timeoutMs, signal, transport);
|
|
6776
|
+
}), timeoutMs, signal, transport, firstOutputTimeoutMs);
|
|
6695
6777
|
}
|
|
6696
6778
|
}
|
|
6779
|
+
function createChainClock(options, timeoutMs) {
|
|
6780
|
+
const fallbacks = options.fallbackModels ?? [];
|
|
6781
|
+
const hasValidFallbackFrom = (index) => fallbacks.slice(index).some((fallback) => {
|
|
6782
|
+
const entry = toModelEntry(fallback);
|
|
6783
|
+
return entry ? parseProviderModel(entry.model) !== null : false;
|
|
6784
|
+
});
|
|
6785
|
+
let silentSpentMs = 0;
|
|
6786
|
+
return {
|
|
6787
|
+
budget(nextFallbackIndex) {
|
|
6788
|
+
const attemptTimeoutMs = Math.max(1, timeoutMs - silentSpentMs);
|
|
6789
|
+
if (options.firstOutputTimeoutMs === undefined || !hasValidFallbackFrom(nextFallbackIndex))
|
|
6790
|
+
return { timeoutMs: attemptTimeoutMs };
|
|
6791
|
+
const bound = Math.min(options.firstOutputTimeoutMs, Math.floor(attemptTimeoutMs / 2));
|
|
6792
|
+
return bound > 0 ? { timeoutMs: attemptTimeoutMs, firstOutputTimeoutMs: bound } : { timeoutMs: attemptTimeoutMs };
|
|
6793
|
+
},
|
|
6794
|
+
settle(error, startedAt) {
|
|
6795
|
+
if (error instanceof ModelProducedNoOutputError)
|
|
6796
|
+
silentSpentMs += Date.now() - startedAt;
|
|
6797
|
+
}
|
|
6798
|
+
};
|
|
6799
|
+
}
|
|
6697
6800
|
async function promptSyncWithModelSuggestionRetry(client, args, options = {}) {
|
|
6698
6801
|
const timeoutMs = options.timeoutMs ?? 300000;
|
|
6699
6802
|
const callContext = options.callContext ?? "subagent";
|
|
@@ -6702,11 +6805,15 @@ async function promptSyncWithModelSuggestionRetry(client, args, options = {}) {
|
|
|
6702
6805
|
const baseArgs = copyPromptArgs(args, baseBody);
|
|
6703
6806
|
const explicitPrimaryLabel = baseBody.model?.providerID && baseBody.model.modelID ? `${baseBody.model.providerID}/${baseBody.model.modelID}` : "primary";
|
|
6704
6807
|
let lastError = null;
|
|
6808
|
+
const clock = createChainClock(options, timeoutMs);
|
|
6809
|
+
const primaryStartedAt = Date.now();
|
|
6705
6810
|
try {
|
|
6706
|
-
|
|
6811
|
+
const budget = clock.budget(0);
|
|
6812
|
+
await attemptOnce(client, baseArgs, budget.timeoutMs, options.signal, callContext, explicitPrimaryLabel, options.transport, options.allowModelSuggestions, budget.firstOutputTimeoutMs);
|
|
6707
6813
|
return;
|
|
6708
6814
|
} catch (error) {
|
|
6709
6815
|
lastError = error;
|
|
6816
|
+
clock.settle(error, primaryStartedAt);
|
|
6710
6817
|
if (isNonRetryable(error, options.signal))
|
|
6711
6818
|
throw error;
|
|
6712
6819
|
if (fallbacks.length === 0) {
|
|
@@ -6728,12 +6835,15 @@ async function promptSyncWithModelSuggestionRetry(client, args, options = {}) {
|
|
|
6728
6835
|
model: parsed,
|
|
6729
6836
|
...fallback?.qualifier ? { variant: fallback.qualifier } : {}
|
|
6730
6837
|
});
|
|
6838
|
+
const attemptStartedAt = Date.now();
|
|
6731
6839
|
try {
|
|
6732
|
-
|
|
6840
|
+
const budget = clock.budget(i + 1);
|
|
6841
|
+
await attemptOnce(client, attemptArgs, budget.timeoutMs, options.signal, callContext, label, options.transport, options.allowModelSuggestions, budget.firstOutputTimeoutMs);
|
|
6733
6842
|
log2(`[${callContext}] fallback succeeded with ${label} (attempt ${i + 2}/${fallbacks.length + 1})`);
|
|
6734
6843
|
return;
|
|
6735
6844
|
} catch (error) {
|
|
6736
6845
|
lastError = error;
|
|
6846
|
+
clock.settle(error, attemptStartedAt);
|
|
6737
6847
|
if (isNonRetryable(error, options.signal))
|
|
6738
6848
|
throw error;
|
|
6739
6849
|
const remaining = fallbacks.length - i - 1;
|
|
@@ -6745,9 +6855,9 @@ async function promptSyncWithModelSuggestionRetry(client, args, options = {}) {
|
|
|
6745
6855
|
log2(`[${callContext}] all models exhausted; tried: ${[explicitPrimaryLabel, ...fallbacks.map((fallback) => toModelEntry(fallback)?.model ?? String(fallback))].join(", ")}; last error: ${shortErr(lastError)}`);
|
|
6746
6856
|
throw lastError ?? new Error("All fallback models failed");
|
|
6747
6857
|
}
|
|
6748
|
-
async function attemptAndValidate(client, args, timeoutMs, signal, callContext, attempt, options) {
|
|
6858
|
+
async function attemptAndValidate(client, args, timeoutMs, signal, callContext, attempt, options, firstOutputTimeoutMs) {
|
|
6749
6859
|
try {
|
|
6750
|
-
await attemptOnce(client, args, timeoutMs, signal, callContext, attempt.label, options.transport, options.allowModelSuggestions);
|
|
6860
|
+
await attemptOnce(client, args, timeoutMs, signal, callContext, attempt.label, options.transport, options.allowModelSuggestions, firstOutputTimeoutMs);
|
|
6751
6861
|
} catch (error) {
|
|
6752
6862
|
throw {
|
|
6753
6863
|
error,
|
|
@@ -6809,6 +6919,8 @@ async function promptSyncWithValidatedOutputRetry(client, args, options) {
|
|
|
6809
6919
|
let firstError = null;
|
|
6810
6920
|
let lastError = null;
|
|
6811
6921
|
const cooledPrimary = primaryQuotaFailure(explicitPrimaryLabel);
|
|
6922
|
+
const clock = createChainClock(options, timeoutMs);
|
|
6923
|
+
const primaryStartedAt = Date.now();
|
|
6812
6924
|
try {
|
|
6813
6925
|
if (cooledPrimary)
|
|
6814
6926
|
throw {
|
|
@@ -6823,16 +6935,18 @@ async function promptSyncWithValidatedOutputRetry(client, args, options) {
|
|
|
6823
6935
|
skipped: true
|
|
6824
6936
|
}
|
|
6825
6937
|
};
|
|
6826
|
-
|
|
6938
|
+
const budget = clock.budget(0);
|
|
6939
|
+
return await attemptAndValidate(client, baseArgs, budget.timeoutMs, options.signal, callContext, {
|
|
6827
6940
|
label: explicitPrimaryLabel,
|
|
6828
6941
|
attemptIndex: 0,
|
|
6829
6942
|
isFallback: false,
|
|
6830
6943
|
totalAttempts,
|
|
6831
6944
|
model: baseBody.model
|
|
6832
|
-
}, options);
|
|
6945
|
+
}, options, budget.firstOutputTimeoutMs);
|
|
6833
6946
|
} catch (caught) {
|
|
6834
6947
|
const failure = caught;
|
|
6835
6948
|
failedAttempts.push(failure);
|
|
6949
|
+
clock.settle(failure.error, primaryStartedAt);
|
|
6836
6950
|
firstError = failure.error;
|
|
6837
6951
|
lastError = failure.error;
|
|
6838
6952
|
if (failure.error instanceof DreamerProviderOutputFailureError && failure.error.quotaResetAt !== undefined)
|
|
@@ -6870,13 +6984,16 @@ async function promptSyncWithValidatedOutputRetry(client, args, options) {
|
|
|
6870
6984
|
totalAttempts,
|
|
6871
6985
|
model: parsed
|
|
6872
6986
|
};
|
|
6987
|
+
const attemptStartedAt = Date.now();
|
|
6873
6988
|
try {
|
|
6874
|
-
const
|
|
6989
|
+
const budget = clock.budget(i + 1);
|
|
6990
|
+
const result = await attemptAndValidate(client, attemptArgs, budget.timeoutMs, options.signal, callContext, attempt, options, budget.firstOutputTimeoutMs);
|
|
6875
6991
|
log2(`[${callContext}] fallback succeeded with ${label} (attempt ${i + 2}/${fallbacks.length + 1})`);
|
|
6876
6992
|
return result;
|
|
6877
6993
|
} catch (caught) {
|
|
6878
6994
|
const failure = caught;
|
|
6879
6995
|
failedAttempts.push(failure);
|
|
6996
|
+
clock.settle(failure.error, attemptStartedAt);
|
|
6880
6997
|
lastError = failure.error;
|
|
6881
6998
|
if (isNonRetryable(failure.error, options.signal)) {
|
|
6882
6999
|
throwWithPromptFailure(failure.error, failedAttempts, args, timeoutMs, options.transport);
|
|
@@ -7228,6 +7345,24 @@ function isTerminalAssistant(message) {
|
|
|
7228
7345
|
const info = infoOf(message);
|
|
7229
7346
|
return isSettledAssistant(message) && info.finish !== "tool-calls" && info.finish !== "tool_use" && !(message && typeof message === "object" && Array.isArray(message.parts) && message.parts.some((part) => part.type === "tool"));
|
|
7230
7347
|
}
|
|
7348
|
+
function showsModelOutput(message) {
|
|
7349
|
+
if (infoOf(message).role !== "assistant")
|
|
7350
|
+
return false;
|
|
7351
|
+
const tokens = sumTokensFromChildMessages([message]);
|
|
7352
|
+
if (tokens.input + tokens.output + tokens.cacheRead + tokens.cacheWrite > 0)
|
|
7353
|
+
return true;
|
|
7354
|
+
const parts = message?.parts;
|
|
7355
|
+
if (!Array.isArray(parts))
|
|
7356
|
+
return false;
|
|
7357
|
+
return parts.some((part) => {
|
|
7358
|
+
if (!part || typeof part !== "object")
|
|
7359
|
+
return false;
|
|
7360
|
+
const { type, text } = part;
|
|
7361
|
+
if (type === "tool")
|
|
7362
|
+
return true;
|
|
7363
|
+
return (type === "text" || type === "reasoning") && typeof text === "string" && text.trim().length > 0;
|
|
7364
|
+
});
|
|
7365
|
+
}
|
|
7231
7366
|
function unwrapData(response) {
|
|
7232
7367
|
if (response && typeof response === "object" && "data" in response) {
|
|
7233
7368
|
return response.data;
|
|
@@ -7325,6 +7460,8 @@ async function promptAsyncAndWaitForIdle(client, request, options = {}) {
|
|
|
7325
7460
|
}
|
|
7326
7461
|
let sentAt = Date.now();
|
|
7327
7462
|
let sawBusy = false;
|
|
7463
|
+
noteModelActivityMonitored(signal);
|
|
7464
|
+
let sawOutput = false;
|
|
7328
7465
|
for (;; ) {
|
|
7329
7466
|
await sleep(pollIntervalMs, signal);
|
|
7330
7467
|
const hostError = activeSessionErrors.get(sessionId);
|
|
@@ -7339,6 +7476,13 @@ async function promptAsyncAndWaitForIdle(client, request, options = {}) {
|
|
|
7339
7476
|
}
|
|
7340
7477
|
const status = await readStatus(session, sessionId, dir, signal);
|
|
7341
7478
|
const messages = await readMessages(session, sessionId, dir, signal);
|
|
7479
|
+
if (!sawOutput && messages.some((message) => {
|
|
7480
|
+
const id = messageId2(message);
|
|
7481
|
+
return id !== null && !initialBaseline.has(id) && showsModelOutput(message);
|
|
7482
|
+
})) {
|
|
7483
|
+
sawOutput = true;
|
|
7484
|
+
noteModelOutputReceived(signal);
|
|
7485
|
+
}
|
|
7342
7486
|
if (budget) {
|
|
7343
7487
|
const latest = messages.at(-1);
|
|
7344
7488
|
const latestId = messageId2(latest);
|
|
@@ -10730,7 +10874,16 @@ function selectHiddenMessagesAtCompactionSeam(messagesBeforeTrim, skippedVisible
|
|
|
10730
10874
|
}
|
|
10731
10875
|
return markerBoundaryIndex < 0 ? [] : trimmed.slice(markerBoundaryIndex + 1);
|
|
10732
10876
|
}
|
|
10733
|
-
function
|
|
10877
|
+
function cutCoveredPrefix(messages, count, coveredInstructions) {
|
|
10878
|
+
const removed = messages.splice(0, count);
|
|
10879
|
+
for (const message of removed) {
|
|
10880
|
+
if (!isHostRenderedSystemMessage(message))
|
|
10881
|
+
continue;
|
|
10882
|
+
markCoveredInstructionRow(message.info);
|
|
10883
|
+
coveredInstructions.push(message);
|
|
10884
|
+
}
|
|
10885
|
+
}
|
|
10886
|
+
function prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, coveredInstructions, projectPath, injectionBudgetTokens, temporalAwareness) {
|
|
10734
10887
|
const cached = injectionCache.get(sessionId);
|
|
10735
10888
|
if (cached && cached.db !== db) {
|
|
10736
10889
|
clearInjectionCache(sessionId);
|
|
@@ -10747,8 +10900,7 @@ function prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, pr
|
|
|
10747
10900
|
if (prepared.compartmentEndMessageId.length > 0) {
|
|
10748
10901
|
const cutoffIndex = findBoundaryIndex(sessionId, messages, prepared.compartmentEndMessageId);
|
|
10749
10902
|
if (cutoffIndex >= 0) {
|
|
10750
|
-
|
|
10751
|
-
messages.splice(0, messages.length, ...remaining);
|
|
10903
|
+
cutCoveredPrefix(messages, cutoffIndex + (isPartialCompartmentEnd(db, sessionId, prepared.compartmentEndMessageId) ? 0 : 1), coveredInstructions);
|
|
10752
10904
|
} else {
|
|
10753
10905
|
sessionLog2(sessionId, `compartment injection: cached boundary ${prepared.compartmentEndMessageId} not in messages (already trimmed), reusing cache`);
|
|
10754
10906
|
}
|
|
@@ -10870,8 +11022,7 @@ function prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, pr
|
|
|
10870
11022
|
if (cutoffIndex >= 0) {
|
|
10871
11023
|
clearDegradedRebuild(sessionId);
|
|
10872
11024
|
skippedVisibleMessages = cutoffIndex + (isPartialCompartmentEnd(db, sessionId, trimEndMessageId) ? 0 : 1);
|
|
10873
|
-
|
|
10874
|
-
messages.splice(0, messages.length, ...remaining);
|
|
11025
|
+
cutCoveredPrefix(messages, skippedVisibleMessages, coveredInstructions);
|
|
10875
11026
|
resultEndMessageId = trimEndMessageId;
|
|
10876
11027
|
} else {
|
|
10877
11028
|
const degradedCount = noteDegradedRebuild(sessionId);
|
|
@@ -10891,8 +11042,7 @@ function prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, pr
|
|
|
10891
11042
|
const reAnchorCutoff = findBoundaryIndex(sessionId, messages, reAnchorCompartment.endMessageId);
|
|
10892
11043
|
if (reAnchorCutoff >= 0) {
|
|
10893
11044
|
skippedVisibleMessages = reAnchorCutoff + (isPartialCompartmentEnd(db, sessionId, reAnchorCompartment.endMessageId) ? 0 : 1);
|
|
10894
|
-
|
|
10895
|
-
messages.splice(0, messages.length, ...remaining);
|
|
11045
|
+
cutCoveredPrefix(messages, skippedVisibleMessages, coveredInstructions);
|
|
10896
11046
|
resultEndMessage = reAnchorCompartment.endMessage;
|
|
10897
11047
|
resultEndMessageId = reAnchorCompartment.endMessageId;
|
|
10898
11048
|
reAnchored = true;
|
|
@@ -15944,6 +16094,31 @@ function persistFilteredNoise(db, sessionId, chunk, eligibleEnd) {
|
|
|
15944
16094
|
return saved;
|
|
15945
16095
|
}
|
|
15946
16096
|
|
|
16097
|
+
// src/hooks/magic-context/file-token-coverage.ts
|
|
16098
|
+
function omitIncompleteFileTokenTotals(db, sessionId, messages, totals) {
|
|
16099
|
+
const filesByMessage = new Map;
|
|
16100
|
+
for (const message of messages) {
|
|
16101
|
+
const count = message.parts.filter(isFilePart).length;
|
|
16102
|
+
if (count > 0 && totals.has(message.id))
|
|
16103
|
+
filesByMessage.set(message.id, count);
|
|
16104
|
+
}
|
|
16105
|
+
if (filesByMessage.size === 0)
|
|
16106
|
+
return totals;
|
|
16107
|
+
const rows = db.prepare(`
|
|
16108
|
+
SELECT o.value AS owner, COUNT(t.id) AS count
|
|
16109
|
+
FROM json_each(?) o LEFT JOIN tags t
|
|
16110
|
+
ON t.session_id = ? AND t.type = 'file'
|
|
16111
|
+
AND t.message_id >= o.value || ':file'
|
|
16112
|
+
AND t.message_id < o.value || ':file;'
|
|
16113
|
+
GROUP BY o.value
|
|
16114
|
+
`).all(JSON.stringify([...filesByMessage.keys()]), sessionId);
|
|
16115
|
+
for (const row of rows) {
|
|
16116
|
+
if (row.count < (filesByMessage.get(row.owner) ?? 0))
|
|
16117
|
+
totals.delete(row.owner);
|
|
16118
|
+
}
|
|
16119
|
+
return totals;
|
|
16120
|
+
}
|
|
16121
|
+
|
|
15947
16122
|
// src/hooks/magic-context/protected-tail-boundary.ts
|
|
15948
16123
|
function describeBoundaryDiagnostics(snapshot) {
|
|
15949
16124
|
return `boundaryDiagnostics=${JSON.stringify(snapshot.diagnostics ?? { unavailable: true, boundaryReason: snapshot.boundaryReason })}`;
|
|
@@ -16169,7 +16344,7 @@ function resolveProtectedTailBoundary(ctx) {
|
|
|
16169
16344
|
const offset = Math.max(1, ctx.lastCompartmentEndOrdinal + 1);
|
|
16170
16345
|
const absoluteMessageCount = getCachedAbsoluteMessageCount2(ctx.sessionId) ?? getRawSessionMessageOrdinalCount2(ctx.sessionId);
|
|
16171
16346
|
const messages = readRawSessionMessageRange2(ctx.sessionId, Math.max(1, offset - 1), absoluteMessageCount);
|
|
16172
|
-
const storedTotals = ctx.storedTokenTotalsForMessages?.(messages.map((m) => m.id)) ?? ctx.storedTokenTotals;
|
|
16347
|
+
const storedTotals = ctx.storedTokenTotalsForMessages?.(messages.map((m) => m.id), messages) ?? ctx.storedTokenTotals;
|
|
16173
16348
|
const index = buildTrueRawTokenIndex(ctx.sessionId, messages, {
|
|
16174
16349
|
providerShapeVersion: ctx.providerShapeVersion,
|
|
16175
16350
|
cacheNamespace: ctx.cacheNamespace,
|
|
@@ -16412,9 +16587,10 @@ function resolveBoundaryContext(args) {
|
|
|
16412
16587
|
migrationFloorActive = seedResult.seeded;
|
|
16413
16588
|
}
|
|
16414
16589
|
const calibration = sessionDecisionCalibration(args.db, args.sessionId);
|
|
16415
|
-
const storedTokenTotalsForMessages = (messageIds) => {
|
|
16590
|
+
const storedTokenTotalsForMessages = (messageIds, messages = []) => {
|
|
16416
16591
|
try {
|
|
16417
|
-
|
|
16592
|
+
const totals = getAllStatusTagTokenTotalsFlat2(args.db, args.sessionId, args.taggerFloor ?? 0, calibration, messageIds).totals;
|
|
16593
|
+
return omitIncompleteFileTokenTotals(args.db, args.sessionId, messages, totals);
|
|
16418
16594
|
} catch (error) {
|
|
16419
16595
|
sessionLog2(args.sessionId, "protected-tail stored-token map unavailable (live fallback):", error);
|
|
16420
16596
|
return;
|
|
@@ -16449,7 +16625,7 @@ function resolveWrapupProtectedTailBoundary(args) {
|
|
|
16449
16625
|
const offset = Math.max(1, ctx.lastCompartmentEndOrdinal + 1);
|
|
16450
16626
|
const absoluteMessageCount = getCachedAbsoluteMessageCount2(ctx.sessionId) ?? getRawSessionMessageOrdinalCount2(ctx.sessionId);
|
|
16451
16627
|
const messages = readRawSessionMessageRange2(ctx.sessionId, Math.max(1, offset - 1), absoluteMessageCount);
|
|
16452
|
-
const storedTotals = ctx.storedTokenTotalsForMessages?.(messages.map((m) => m.id)) ?? ctx.storedTokenTotals;
|
|
16628
|
+
const storedTotals = ctx.storedTokenTotalsForMessages?.(messages.map((m) => m.id), messages) ?? ctx.storedTokenTotals;
|
|
16453
16629
|
const index = buildTrueRawTokenIndex(ctx.sessionId, messages, {
|
|
16454
16630
|
providerShapeVersion: ctx.providerShapeVersion,
|
|
16455
16631
|
cacheNamespace: ctx.cacheNamespace,
|
|
@@ -18620,4 +18796,4 @@ ${failure}`;
|
|
|
18620
18796
|
}
|
|
18621
18797
|
}
|
|
18622
18798
|
|
|
18623
|
-
export { historianRunConfig, dreamerRunConfig, pluginConfigReader, currentPluginConfigReader, withLiveDreamerOutputCap, COMPARTMENT_LEASE_RENEWAL_MS, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLeaseBestEffort, isCompartmentLeaseHeld, queueM0Mutation, getMaxM0MutationId, getCompartments, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, getUncoveredCompartmentEndsThrough, providerResponseFailed, isSuccessfulProviderCompletion, rememberUnpublishedAutoSearchNoHint, getUnpublishedAutoSearchNoHint, forgetUnpublishedAutoSearchNoHint, registerAutoSearchWork, getOrCreateSessionMeta, updateSessionMeta, advanceToolReclaimWatermark, markSessionCleanupPending, retryPendingSessionCleanups, retryPendingRustSessionCleanupsForProject, clearSession, requestPendingMaterialization, pendingMaterializationOrigin, hasPendingMaterializationOrigin, clearPendingMaterialization, recordSystemPromptForRequest, recordHeldHeadForRequest, bindSystemPromptResponse, isHeldHeadForRequest, deferDeliveredSystemRefresh, retirePendingSystemPromptDelivery, lkgProviderInputTotal, beginV2LkgRequest, claimLkgRequestIdentity, currentLkgRequestIdentity, noteCapturedLkgRequest, noteLkgProviderResponse, measuredLkgPrefix, clearLkgMeasuredRequest, saveLkgSlotToDb, clearPersistedLkgSlotStrict, loadPersistedLkgSlot, drainStaleLkgSlots, resolveLkgModelKeys, createLkgEntryProjector, captureLkgSlot, validateAnthropicReasoningRuns, validateLkgSeam, replayLkg, coldStartRawServedIndex, coldStartUncapturedReplay, noteUncertifiedNormalLkg, hasProcessLocalLkgProof, lkgDirtyRevision, rememberLkgDirtyRevision, noteLkgRecoveryPrefix, readLkgRecoveryPrefix, noteLkgHealthyPrefix, lkgRecoveryReplayUnproven, lkgRecoveryEntryUnproven, beginLkgPass, visitMessageContentFields, contentSnapshotValue, messageContentFields, signatureForFields, exactReusablePrefix, incrementalLkgContentDigests, lkgSlotRejection, captureSlot, getInMemorySlot, getSlot, forgetInMemorySlot, dropSlot, noteEntry, getLkgSlotHeapStats, TOOL_SWEEP_SCOPED_MARKER, useScopedToolSweep, createPreAdoptionToolSweepResolver, copySessionStateForClone, queueMemoryMutation, getMaxMemoryMutationIdForProjects, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectUserProfileVersion, saveSourceContent, replaceSourceContent, getSourceContents, readCoordinateGeneration, rebaseSessionCoordinatesAsync, HiddenCompletionRefusal, getOpenCodeDbPath, compareOpenCodeMessagesByCanonicalOrder, prepareCompactionMarkerCandidates, removeMcOwnedCompactionMarkers, getCompartmentEvents, USER_MEMORY_CANDIDATE_TTL_MS, insertUserMemoryCandidates, getUserMemoryCandidates, deleteUserMemoryCandidates, pruneExpiredUserMemoryCandidates, insertUserMemory, getActiveUserMemories, updateUserMemoryContent, dismissUserMemory, DreamerProviderOutputFailureError, withDreamerModelCooldown, providerOutputFailureFromInvalidManifest, DREAMER_AGENT, DREAMER_RETROSPECTIVE_AGENT, DREAMER_PRIMER_INVESTIGATOR_AGENT, DREAMER_MEMORY_MAPPER_AGENT, DREAMER_CLASSIFIER_AGENT, DREAMER_DOCS_AGENT, DREAMER_REVIEWER_AGENT, HIDDEN_HISTORIAN_AGENT, HIDDEN_DREAMER_AGENT, HIDDEN_CURATE_AGENT, hiddenAgentFor, hiddenToolLoop, HIDDEN_RUN_DISPOSED_REASON, noteChildOfDisposedInstance, hiddenChildPermissions, registerHiddenChildAgents, hiddenToolCallRefusal, HiddenAgentStepLimit, HiddenChildHook, extractLatestAssistantText, hasLengthCappedOutput, parseProviderModel, modelBodyField, toModelEntry, isPromptTimeoutError, getPromptFailureDetail, raceWithSignal, promptSyncWithValidatedOutputRetry, normalizeSDKResponse, failedInvocationStatus, sumTokensFromChildMessages, recordChildInvocation, createPromptAsyncTransport, CTX_NOTE_LIGHT_DESCRIPTION, ACTIVE_TOOL_IDS, systemPromptFingerprint, createPromptSurfaceRuntime, createPromptSurfaceGuidanceEpochCache, MARKER_SUMMARY_TEXT, markerUpdateDefinitelyDidNotCut, applyDeferredCompactionMarker, teardownChildSession, runTokenLog, formatRunTokenLog, createChildSessionWithFence, buildMagicContextSection, getMuralIdentity, getMural, modelKeyAcceptsImages, resolveMuralWire, extractM0Block, formatDate, TEMPORAL_MARKER_REPLAY_PATTERN, collectTemporalCandidates, injectTemporalMarkers, clearInjectionCache, getVisibleMemoryIds, selectHiddenMessagesAtCompactionSeam, prepareCompartmentInjection, renderCompartmentInjection, MaterializeContentionError, mustMaterialize, trimMemoriesToBudgetV2, renderMemoryBlockV2, materializeM0, hydrateCachedM0Mural, resetPrefixTrimFallbackState, findHostCompactionWindow, capturePrefixTrimSourceOrder, prepareCachedM0M1Replay, hasCompleteCachedM0M1, injectM0M1, clampProducerAtomChars, producerInputTokenLimit, historianProducerReserve, producerPromptFailureReason, resolveHiddenCompletionExecutor, createV1HiddenCompletionExecutor, EMPTY_READ_REPLY, noteTouchedAt, renderGlance, renderNotesById, formatWriteReply, observeNoteNudgeServe, onNoteTrigger, peekNoteNudgeText, markNoteNudgeDelivered, clearNoteNudgeTriggerAndCooldown, describeBoundaryDiagnostics, RECOVERY_NO_HEAD_LIMIT, deriveProtectedTailTokenTarget, selectPerRunCap, resolveOpenCodeProtectedTailBoundary, resolveWrapupProtectedTailBoundary, getRawHistoryEligibility, hasRunnableCompartmentWindow, recordHighPressureNoEligibleHead, noteTransformPassForExactOrdinalReads, runCompartmentAgent, getActiveCompartmentRun, markActiveCompartmentRunPublished, registerActiveCompartmentRun, startCompartmentAgent, isRecompFailure2, isRecompSkip2, extractRecompReason2, setRecompStarting2, setRecompNote2, setRecompTerminal2, buildRecompDeps2, runManagedRecomp2 };
|
|
18799
|
+
export { historianRunConfig, dreamerRunConfig, pluginConfigReader, currentPluginConfigReader, withLiveDreamerOutputCap, COMPARTMENT_LEASE_RENEWAL_MS, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLeaseBestEffort, isCompartmentLeaseHeld, queueM0Mutation, getMaxM0MutationId, getCompartments, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, getUncoveredCompartmentEndsThrough, providerResponseFailed, isSuccessfulProviderCompletion, rememberUnpublishedAutoSearchNoHint, getUnpublishedAutoSearchNoHint, forgetUnpublishedAutoSearchNoHint, registerAutoSearchWork, getOrCreateSessionMeta, updateSessionMeta, advanceToolReclaimWatermark, markSessionCleanupPending, retryPendingSessionCleanups, retryPendingRustSessionCleanupsForProject, clearSession, requestPendingMaterialization, pendingMaterializationOrigin, hasPendingMaterializationOrigin, clearPendingMaterialization, recordSystemPromptForRequest, recordHeldHeadForRequest, bindSystemPromptResponse, isHeldHeadForRequest, deferDeliveredSystemRefresh, retirePendingSystemPromptDelivery, lkgProviderInputTotal, beginV2LkgRequest, claimLkgRequestIdentity, currentLkgRequestIdentity, noteCapturedLkgRequest, noteLkgProviderResponse, measuredLkgPrefix, clearLkgMeasuredRequest, saveLkgSlotToDb, clearPersistedLkgSlotStrict, loadPersistedLkgSlot, drainStaleLkgSlots, resolveLkgModelKeys, createLkgEntryProjector, captureLkgSlot, validateAnthropicReasoningRuns, validateLkgSeam, replayLkg, coldStartRawServedIndex, coldStartUncapturedReplay, noteUncertifiedNormalLkg, hasProcessLocalLkgProof, lkgDirtyRevision, rememberLkgDirtyRevision, readPersistedLkgUntaggedInputIds, persistLkgUntaggedInputIds, noteLkgRecoveryPrefix, readLkgRecoveryPrefix, noteLkgHealthyPrefix, lkgRecoveryReplayUnproven, lkgRecoveryEntryUnproven, beginLkgPass, visitMessageContentFields, contentSnapshotValue, messageContentFields, signatureForFields, exactReusablePrefix, incrementalLkgContentDigests, lkgSlotRejection, captureSlot, getInMemorySlot, getSlot, forgetInMemorySlot, dropSlot, noteEntry, getLkgSlotHeapStats, TOOL_SWEEP_SCOPED_MARKER, useScopedToolSweep, createPreAdoptionToolSweepResolver, copySessionStateForClone, queueMemoryMutation, getMaxMemoryMutationIdForProjects, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectUserProfileVersion, saveSourceContent, replaceSourceContent, getSourceContents, readCoordinateGeneration, rebaseSessionCoordinatesAsync, HiddenCompletionRefusal, getOpenCodeDbPath, compareOpenCodeMessagesByCanonicalOrder, prepareCompactionMarkerCandidates, removeMcOwnedCompactionMarkers, getCompartmentEvents, USER_MEMORY_CANDIDATE_TTL_MS, insertUserMemoryCandidates, getUserMemoryCandidates, deleteUserMemoryCandidates, pruneExpiredUserMemoryCandidates, insertUserMemory, getActiveUserMemories, updateUserMemoryContent, dismissUserMemory, DreamerProviderOutputFailureError, withDreamerModelCooldown, providerOutputFailureFromInvalidManifest, DREAMER_AGENT, DREAMER_RETROSPECTIVE_AGENT, DREAMER_PRIMER_INVESTIGATOR_AGENT, DREAMER_MEMORY_MAPPER_AGENT, DREAMER_CLASSIFIER_AGENT, DREAMER_DOCS_AGENT, DREAMER_REVIEWER_AGENT, HIDDEN_HISTORIAN_AGENT, HIDDEN_DREAMER_AGENT, HIDDEN_CURATE_AGENT, hiddenAgentFor, hiddenToolLoop, HIDDEN_RUN_DISPOSED_REASON, noteChildOfDisposedInstance, hiddenChildPermissions, registerHiddenChildAgents, hiddenToolCallRefusal, HiddenAgentStepLimit, HiddenChildHook, extractLatestAssistantText, hasLengthCappedOutput, parseProviderModel, modelBodyField, toModelEntry, isPromptTimeoutError, getPromptFailureDetail, raceWithSignal, promptSyncWithValidatedOutputRetry, normalizeSDKResponse, failedInvocationStatus, sumTokensFromChildMessages, recordChildInvocation, createPromptAsyncTransport, CTX_NOTE_LIGHT_DESCRIPTION, ACTIVE_TOOL_IDS, systemPromptFingerprint, createPromptSurfaceRuntime, createPromptSurfaceGuidanceEpochCache, MARKER_SUMMARY_TEXT, markerUpdateDefinitelyDidNotCut, applyDeferredCompactionMarker, teardownChildSession, runTokenLog, formatRunTokenLog, createChildSessionWithFence, buildMagicContextSection, getMuralIdentity, getMural, modelKeyAcceptsImages, resolveMuralWire, extractM0Block, formatDate, TEMPORAL_MARKER_REPLAY_PATTERN, collectTemporalCandidates, injectTemporalMarkers, clearInjectionCache, getVisibleMemoryIds, selectHiddenMessagesAtCompactionSeam, prepareCompartmentInjection, renderCompartmentInjection, MaterializeContentionError, mustMaterialize, trimMemoriesToBudgetV2, renderMemoryBlockV2, materializeM0, hydrateCachedM0Mural, resetPrefixTrimFallbackState, findHostCompactionWindow, capturePrefixTrimSourceOrder, prepareCachedM0M1Replay, hasCompleteCachedM0M1, injectM0M1, clampProducerAtomChars, producerInputTokenLimit, historianProducerReserve, producerPromptFailureReason, resolveHiddenCompletionExecutor, createV1HiddenCompletionExecutor, EMPTY_READ_REPLY, noteTouchedAt, renderGlance, renderNotesById, formatWriteReply, observeNoteNudgeServe, onNoteTrigger, peekNoteNudgeText, markNoteNudgeDelivered, clearNoteNudgeTriggerAndCooldown, omitIncompleteFileTokenTotals, describeBoundaryDiagnostics, RECOVERY_NO_HEAD_LIMIT, deriveProtectedTailTokenTarget, selectPerRunCap, resolveOpenCodeProtectedTailBoundary, resolveWrapupProtectedTailBoundary, getRawHistoryEligibility, hasRunnableCompartmentWindow, recordHighPressureNoEligibleHead, noteTransformPassForExactOrdinalReads, runCompartmentAgent, getActiveCompartmentRun, markActiveCompartmentRunPublished, registerActiveCompartmentRun, startCompartmentAgent, isRecompFailure2, isRecompSkip2, extractRecompReason2, setRecompStarting2, setRecompNote2, setRecompTerminal2, buildRecompDeps2, runManagedRecomp2 };
|