@cortexkit/opencode-magic-context 0.49.45 → 0.49.47
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 +1 -1
- package/dist/chunk-embedding-write-worker.js +1 -1
- package/dist/{context-y85dvs6j.js → context-hvkjxqhs.js} +416 -106
- package/dist/{derive-budgets-htj16n4x.js → derive-budgets-nkw09vq7.js} +1 -1
- package/dist/features/magic-context/request-tool-definitions.d.ts +57 -0
- package/dist/features/magic-context/request-tool-definitions.d.ts.map +1 -1
- package/dist/hooks/magic-context/cache-busting-signals.d.ts +6 -3
- package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/host-checkpoint-ride.d.ts +80 -0
- package/dist/hooks/magic-context/host-checkpoint-ride.d.ts.map +1 -0
- package/dist/hooks/magic-context/inject-compartments.d.ts +21 -0
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/latest-thinking-recovery.d.ts +19 -0
- package/dist/hooks/magic-context/latest-thinking-recovery.d.ts.map +1 -1
- package/dist/hooks/magic-context/pending-materialization.d.ts +3 -0
- package/dist/hooks/magic-context/pending-materialization.d.ts.map +1 -1
- package/dist/hooks/magic-context/priced-pass-sizing.d.ts +132 -0
- package/dist/hooks/magic-context/priced-pass-sizing.d.ts.map +1 -0
- package/dist/hooks/magic-context/reasoning-budget.d.ts.map +1 -1
- package/dist/hooks/magic-context/recovery-fit.d.ts +51 -0
- package/dist/hooks/magic-context/recovery-fit.d.ts.map +1 -0
- package/dist/hooks/magic-context/request-tools-release.d.ts +26 -0
- package/dist/hooks/magic-context/request-tools-release.d.ts.map +1 -0
- package/dist/hooks/magic-context/routine-cleanup-decision.d.ts +109 -0
- package/dist/hooks/magic-context/routine-cleanup-decision.d.ts.map +1 -0
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +24 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-context-state.d.ts +2 -1
- package/dist/hooks/magic-context/transform-context-state.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +22 -2
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +19 -2
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-jwa5t1s4.js → index-1qmv26ga.js} +17 -4
- package/dist/{index-0a79y98x.js → index-2x3kd999.js} +301 -90
- package/dist/{index-qdx8dq60.js → index-37a9bfta.js} +4 -4
- package/dist/{index-tvd2j34s.js → index-44pp3vrj.js} +1 -1
- package/dist/{index-980brvjr.js → index-5jk4h64j.js} +3 -3
- package/dist/{index-66a50f3e.js → index-6athgjba.js} +66 -14
- package/dist/{index-dnqqqc5f.js → index-8cfnaagj.js} +10 -2
- package/dist/{index-z8dacvkt.js → index-b0xt5qz9.js} +1 -1
- package/dist/{index-xejh7cqv.js → index-bqhjzhv4.js} +173 -9
- package/dist/{index-fs3zfby1.js → index-c99tqfge.js} +724 -98
- package/dist/{index-dcdvyaeh.js → index-eej9kwad.js} +3 -3
- package/dist/{index-rk5hyc41.js → index-esr8qcc4.js} +2 -2
- package/dist/{index-bzq05g00.js → index-etn2hmb5.js} +1 -1
- package/dist/{index-gf1vx3bn.js → index-kw7azjmy.js} +2 -2
- package/dist/{index-29gd1zcx.js → index-w6fh4v87.js} +1 -1
- package/dist/{index-gxqr0sbd.js → index-x53gnmce.js} +10 -10
- package/dist/{index-7na94cjf.js → index-xgczbhyx.js} +5 -5
- package/dist/{index-wwg1je98.js → index-xgnh498s.js} +3 -2
- package/dist/index.js +20 -20
- package/dist/{message-index-bounded-d8xt6q5c.js → message-index-bounded-3qpg8dq5.js} +3 -3
- package/dist/migration-worker.js +1 -1
- package/dist/raw-ordinal-warmup-worker.js +4 -4
- package/dist/{read-session-chunk-k3fqshw8.js → read-session-chunk-7h9f32sz.js} +2 -2
- package/dist/{recomp-orchestrator-y75thsc3.js → recomp-orchestrator-43g9tjya.js} +9 -9
- package/dist/{render-3psbedzk.js → render-4m7x9cq4.js} +7 -7
- package/dist/{search-hd16c8gq.js → search-0a3hh5x6.js} +5 -5
- package/dist/{search-archive-rvr7j5gx.js → search-archive-f6kwv02s.js} +4 -4
- package/dist/shared/window-geometry.d.ts +5 -0
- package/dist/shared/window-geometry.d.ts.map +1 -1
- package/dist/{storage-tags-ye9aqrqy.js → storage-tags-q8erkn48.js} +3 -1
- package/dist/{store-pd1e9hnr.js → store-h20ny8b8.js} +2 -2
- package/dist/{store-reader-yh19h38c.js → store-reader-3eh1s1m8.js} +1 -1
- package/dist/tools/parameter-descriptions.d.ts +6 -6
- package/dist/tools/parameter-descriptions.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-1rzxmkhb.js → transform-postprocess-phase-5746a5b6.js} +10 -10
- package/dist/v2/auto-search-worker.js +1 -1
- package/dist/v2/chunk-embedding-write-worker.js +1 -1
- package/dist/v2/{context-0e946t63.js → context-e9n2mxax.js} +1424 -295
- package/dist/v2/{derive-budgets-sa0v7bz0.js → derive-budgets-b5cgrtp8.js} +2 -2
- package/dist/v2/fold/code-mode-catalog.d.ts +11 -3
- package/dist/v2/fold/code-mode-catalog.d.ts.map +1 -1
- package/dist/v2/fold/instruction-supersession.d.ts +13 -2
- package/dist/v2/fold/instruction-supersession.d.ts.map +1 -1
- package/dist/v2/fold/manual-baseline.d.ts +7 -0
- package/dist/v2/fold/manual-baseline.d.ts.map +1 -1
- package/dist/v2/fold/native-replay.d.ts +5 -0
- package/dist/v2/fold/native-replay.d.ts.map +1 -1
- package/dist/v2/fold/owner.d.ts +14 -0
- package/dist/v2/fold/owner.d.ts.map +1 -1
- package/dist/v2/fold/summary.d.ts +35 -0
- package/dist/v2/fold/summary.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts +10 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/lkg-system.d.ts +3 -0
- package/dist/v2/hooks/lkg-system.d.ts.map +1 -1
- package/dist/v2/{message-index-bounded-wt64v2rn.js → message-index-bounded-na8debr6.js} +3 -3
- package/dist/v2/migration-worker.js +1 -1
- package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
- package/dist/v2/{read-session-chunk-4b31z6bz.js → read-session-chunk-x33xeg2g.js} +2 -2
- package/dist/v2/{recomp-orchestrator-6qrm2nea.js → recomp-orchestrator-jyjpn5jm.js} +10 -10
- package/dist/v2/{render-f8mw16pp.js → render-mp82ns36.js} +7 -7
- package/dist/v2/{search-archive-7d0xdp54.js → search-archive-d0fcqch9.js} +4 -4
- package/dist/v2/{search-ecjd7e50.js → search-ebd0yr40.js} +4 -4
- package/dist/v2/{server-wbxbk3za.js → server-1f03b92k.js} +2 -2
- package/dist/v2/{server-ymn9w46x.js → server-5zzt9rah.js} +1 -1
- package/dist/v2/{server-sd8hvzte.js → server-af1rmkyn.js} +1 -1
- package/dist/v2/{server-vnpnmrsv.js → server-c43zxc9k.js} +27 -3
- package/dist/v2/{server-hq7fdqfm.js → server-epvj1cey.js} +2 -2
- package/dist/v2/{server-39kzpp8q.js → server-fhxe5jgm.js} +2 -2
- package/dist/v2/{server-0ymsgh0j.js → server-gy26cwvw.js} +1 -1
- package/dist/v2/{server-zqzh2ybj.js → server-rg92e592.js} +175 -11
- package/dist/v2/{server-ef1mskas.js → server-rthnpmbp.js} +66 -14
- package/dist/v2/{server-gwqfwtzq.js → server-t4hk02v1.js} +10 -10
- package/dist/v2/{server-vjhk8v41.js → server-wa4qhryh.js} +1 -1
- package/dist/v2/{server-an1ff8d8.js → server-wwmaqtxy.js} +5 -5
- package/dist/v2/{server-2qyfev3b.js → server-xsrykjkj.js} +17 -4
- package/dist/v2/{server-qxzbmtqt.js → server-zt1m5rwj.js} +10 -2
- package/dist/v2/{server-ftyc8awt.js → server-zypeavf0.js} +1 -1
- package/dist/v2/server.js +4 -4
- package/dist/v2/{storage-tags-8nttt1sk.js → storage-tags-ztar1k0g.js} +3 -1
- package/dist/v2/{store-reader-cgx47zkp.js → store-reader-yaxtdy6f.js} +1 -1
- package/dist/v2/store-reader.d.ts +22 -1
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{store-pebs9m52.js → store-skkhh3rd.js} +2 -2
- package/dist/v2/{v2-archive-reader-53kp5mme.js → v2-archive-reader-gm6mygag.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-bng0dfxy.js → wrapup-orchestrator-y9a02xpd.js} +10 -10
- package/dist/{v2-archive-reader-0fcxs5e9.js → v2-archive-reader-yp9956t8.js} +1 -1
- package/dist/{wrapup-orchestrator-r5cqgyrg.js → wrapup-orchestrator-ese0epyk.js} +10 -10
- package/package.json +1 -1
- package/src/agents/smart-notes-dreamer-gate.golden.json +169 -169
- package/src/shared/prompt-surface-a1-golden.md +4 -4
- package/src/shared/window-geometry.test.ts +85 -0
- package/src/shared/window-geometry.ts +29 -2
|
@@ -74,7 +74,7 @@ import {
|
|
|
74
74
|
adoptNullOwnerToolTag2,
|
|
75
75
|
getCandidateToolOwners2,
|
|
76
76
|
pickNearestPriorOwner2
|
|
77
|
-
} from "./index-
|
|
77
|
+
} from "./index-x53gnmce.js";
|
|
78
78
|
import {
|
|
79
79
|
textMentionsRecentCommit,
|
|
80
80
|
hasMeaningfulUserText2,
|
|
@@ -117,14 +117,15 @@ import {
|
|
|
117
117
|
pendingMaterializationOrigin,
|
|
118
118
|
hasPendingMaterializationOrigin,
|
|
119
119
|
clearPendingMaterialization,
|
|
120
|
+
clearPendingMaterializationOrigin,
|
|
120
121
|
saveSourceContent,
|
|
121
122
|
replaceSourceContent,
|
|
122
123
|
getSourceContents
|
|
123
|
-
} from "./index-
|
|
124
|
+
} from "./index-1qmv26ga.js";
|
|
124
125
|
import {
|
|
125
126
|
cleanSearchText,
|
|
126
127
|
matchedSearchSnippet
|
|
127
|
-
} from "./index-
|
|
128
|
+
} from "./index-etn2hmb5.js";
|
|
128
129
|
import {
|
|
129
130
|
stripSystemInjection,
|
|
130
131
|
isTextPart,
|
|
@@ -222,7 +223,7 @@ import {
|
|
|
222
223
|
extractToolCallObservation,
|
|
223
224
|
ToolMutationBatch,
|
|
224
225
|
createToolDropTarget
|
|
225
|
-
} from "./index-
|
|
226
|
+
} from "./index-xgnh498s.js";
|
|
226
227
|
import {
|
|
227
228
|
isValidLanguageCode
|
|
228
229
|
} from "./index-4dpvnp8k.js";
|
|
@@ -238,7 +239,7 @@ import {
|
|
|
238
239
|
getMessageIndexEpoch,
|
|
239
240
|
isMessageIndexSearchable,
|
|
240
241
|
createAutoSearchDiagnostics
|
|
241
|
-
} from "./index-
|
|
242
|
+
} from "./index-44pp3vrj.js";
|
|
242
243
|
import {
|
|
243
244
|
openCodeDbExists,
|
|
244
245
|
withReadOnlySessionDb,
|
|
@@ -258,6 +259,7 @@ import {
|
|
|
258
259
|
renderCompartmentInjection,
|
|
259
260
|
MaterializeContentionError,
|
|
260
261
|
mustMaterialize,
|
|
262
|
+
stripMemoryMuralBlock,
|
|
261
263
|
hydrateCachedM0Mural,
|
|
262
264
|
prepareCachedM0M1Replay,
|
|
263
265
|
hasCompleteCachedM0M1,
|
|
@@ -266,7 +268,7 @@ import {
|
|
|
266
268
|
peekNoteNudgeText,
|
|
267
269
|
markNoteNudgeDelivered,
|
|
268
270
|
getActiveCompartmentRun
|
|
269
|
-
} from "./index-
|
|
271
|
+
} from "./index-bqhjzhv4.js";
|
|
270
272
|
import {
|
|
271
273
|
userFacingFailureCode
|
|
272
274
|
} from "./index-sd2s4t4p.js";
|
|
@@ -2496,7 +2498,7 @@ function hasReclaimRide(signals) {
|
|
|
2496
2498
|
return signals.hardFold || signals.force || signals.explicitFlush || signals.publishedHistory || signals.subagentExecute === true || signals.executeReclaim === true || signals.servedShapeRepair === true;
|
|
2497
2499
|
}
|
|
2498
2500
|
function prefixMutationPermitted(gate) {
|
|
2499
|
-
return !gate.signedThinkingHold || gate.firstRender || gate.emergency;
|
|
2501
|
+
return !gate.signedThinkingHold || gate.firstRender || gate.hostCheckpointHead === true || gate.emergency;
|
|
2500
2502
|
}
|
|
2501
2503
|
function reclaimRidePermitted(signals, gate) {
|
|
2502
2504
|
return prefixMutationPermitted(gate) && hasReclaimRide(signals);
|
|
@@ -3367,6 +3369,166 @@ function degradedPassError(site, error) {
|
|
|
3367
3369
|
return new DegradedPassRefusalError(site, { cause: error });
|
|
3368
3370
|
}
|
|
3369
3371
|
|
|
3372
|
+
// src/hooks/magic-context/host-checkpoint-ride.ts
|
|
3373
|
+
import { createHash } from "node:crypto";
|
|
3374
|
+
var SESSIONS_MAX = 100;
|
|
3375
|
+
var servedHeads = new BoundedSessionMap(SESSIONS_MAX);
|
|
3376
|
+
var commits = new BoundedSessionMap(SESSIONS_MAX);
|
|
3377
|
+
var passes = new BoundedSessionMap(SESSIONS_MAX);
|
|
3378
|
+
function servedHeadDigest(head) {
|
|
3379
|
+
if (head.m0Text == null || head.m1Text == null)
|
|
3380
|
+
return null;
|
|
3381
|
+
const mural = head.muralDataUrl ?? null;
|
|
3382
|
+
const m0 = mural ? head.m0Text : stripMemoryMuralBlock(head.m0Text);
|
|
3383
|
+
return createHash("sha256").update(JSON.stringify([m0, head.m1Text, mural])).digest("hex");
|
|
3384
|
+
}
|
|
3385
|
+
function servedHeadChanged(before, after) {
|
|
3386
|
+
const a = servedHeadDigest(before);
|
|
3387
|
+
return a === null || a !== servedHeadDigest(after);
|
|
3388
|
+
}
|
|
3389
|
+
function noteHostCheckpointCommit(sessionId, commit) {
|
|
3390
|
+
commits.set(sessionId, commit);
|
|
3391
|
+
}
|
|
3392
|
+
function hostCheckpointHeadChange(sessionId, head) {
|
|
3393
|
+
const commit = commits.peek(sessionId);
|
|
3394
|
+
if (commit)
|
|
3395
|
+
return {
|
|
3396
|
+
changed: commit.changed,
|
|
3397
|
+
source: "commit",
|
|
3398
|
+
previousCoverage: commit.previousCoverage
|
|
3399
|
+
};
|
|
3400
|
+
const served = servedHeads.peek(sessionId);
|
|
3401
|
+
const digest = served ? servedHeadDigest(head()) : null;
|
|
3402
|
+
if (!served || digest === null)
|
|
3403
|
+
return { changed: false, source: "none", previousCoverage: null };
|
|
3404
|
+
return {
|
|
3405
|
+
changed: served.digest !== digest,
|
|
3406
|
+
source: "served_head",
|
|
3407
|
+
previousCoverage: served.coverage
|
|
3408
|
+
};
|
|
3409
|
+
}
|
|
3410
|
+
function beginHostCheckpointPass(sessionId, pending) {
|
|
3411
|
+
passes.set(sessionId, {
|
|
3412
|
+
requested: hasPendingMaterializationOrigin(pending, sessionId, "host_compaction"),
|
|
3413
|
+
commit: commits.peek(sessionId),
|
|
3414
|
+
previousRecord: servedHeads.peek(sessionId)
|
|
3415
|
+
});
|
|
3416
|
+
}
|
|
3417
|
+
function stageServedHead(sessionId, head, coverage) {
|
|
3418
|
+
const state = passes.peek(sessionId);
|
|
3419
|
+
if (!state)
|
|
3420
|
+
return;
|
|
3421
|
+
const digest = servedHeadDigest(head);
|
|
3422
|
+
state.staged = digest === null ? null : { digest, coverage };
|
|
3423
|
+
}
|
|
3424
|
+
function completeHostCheckpointPass(sessionId, pending, withdraw) {
|
|
3425
|
+
const state = passes.peek(sessionId);
|
|
3426
|
+
if (!state)
|
|
3427
|
+
return;
|
|
3428
|
+
if (state.staged !== undefined) {
|
|
3429
|
+
if (state.staged)
|
|
3430
|
+
servedHeads.set(sessionId, state.staged);
|
|
3431
|
+
else
|
|
3432
|
+
servedHeads.delete(sessionId);
|
|
3433
|
+
}
|
|
3434
|
+
if (withdraw)
|
|
3435
|
+
clearPendingMaterializationOrigin(pending, sessionId, "host_compaction");
|
|
3436
|
+
if (!hasPendingMaterializationOrigin(pending, sessionId, "host_compaction"))
|
|
3437
|
+
commits.delete(sessionId);
|
|
3438
|
+
}
|
|
3439
|
+
function revertHostCheckpointPass(sessionId, pending) {
|
|
3440
|
+
const state = passes.peek(sessionId);
|
|
3441
|
+
passes.delete(sessionId);
|
|
3442
|
+
if (!state)
|
|
3443
|
+
return;
|
|
3444
|
+
if (state.previousRecord)
|
|
3445
|
+
servedHeads.set(sessionId, state.previousRecord);
|
|
3446
|
+
else
|
|
3447
|
+
servedHeads.delete(sessionId);
|
|
3448
|
+
if (!state.requested)
|
|
3449
|
+
return;
|
|
3450
|
+
if (state.commit)
|
|
3451
|
+
commits.set(sessionId, state.commit);
|
|
3452
|
+
if (!hasPendingMaterializationOrigin(pending, sessionId, "host_compaction"))
|
|
3453
|
+
requestPendingMaterialization(pending, sessionId, "host_compaction");
|
|
3454
|
+
}
|
|
3455
|
+
function forgetHostCheckpointPass(sessionId) {
|
|
3456
|
+
passes.delete(sessionId);
|
|
3457
|
+
}
|
|
3458
|
+
|
|
3459
|
+
// src/features/magic-context/storage-host-instruction-retention.ts
|
|
3460
|
+
var NAMESPACE3 = "hostInstructionRetention";
|
|
3461
|
+
var enabled = true;
|
|
3462
|
+
function hostInstructionRetentionEnabled() {
|
|
3463
|
+
return enabled;
|
|
3464
|
+
}
|
|
3465
|
+
function isHostInstructionRetentionOn(db, sessionId) {
|
|
3466
|
+
const lane = readReplayEnvelope(db, sessionId)[NAMESPACE3];
|
|
3467
|
+
return typeof lane === "object" && lane !== null && lane.on === true;
|
|
3468
|
+
}
|
|
3469
|
+
function markHostInstructionRetention(db, sessionId) {
|
|
3470
|
+
return updateReplayDocument(db, sessionId, (doc) => {
|
|
3471
|
+
const lane = doc[NAMESPACE3];
|
|
3472
|
+
if (typeof lane === "object" && lane !== null && lane.on === true)
|
|
3473
|
+
return false;
|
|
3474
|
+
doc.version = 2;
|
|
3475
|
+
doc[NAMESPACE3] = { on: true };
|
|
3476
|
+
return true;
|
|
3477
|
+
});
|
|
3478
|
+
}
|
|
3479
|
+
|
|
3480
|
+
// src/hooks/magic-context/routine-cleanup-decision.ts
|
|
3481
|
+
function pressureBands(args) {
|
|
3482
|
+
const emergencyDropEligible = !args.compactionOff && args.percentage >= args.forceMaterializationPercentage;
|
|
3483
|
+
const forceRideWaitsOnLocalCount = args.fromEstimate && args.percentage < 95;
|
|
3484
|
+
return {
|
|
3485
|
+
forceMaterialization: args.fullFeatureMode && emergencyDropEligible,
|
|
3486
|
+
emergencyDropEligible,
|
|
3487
|
+
forceRideWaitsOnLocalCount,
|
|
3488
|
+
forceBandConfirmed: emergencyDropEligible && !forceRideWaitsOnLocalCount,
|
|
3489
|
+
executePressureEligible: args.schedulerDecision === "execute" || emergencyDropEligible
|
|
3490
|
+
};
|
|
3491
|
+
}
|
|
3492
|
+
function forceRide(args) {
|
|
3493
|
+
return args.bands.emergencyDropEligible && (args.percentage >= 95 || !args.fromEstimate && args.emergencySample() === 0);
|
|
3494
|
+
}
|
|
3495
|
+
function heuristicsRunOnPass(args) {
|
|
3496
|
+
return !args.compactionOff && args.drainAllowed && (args.rides.publishedHistory || args.rides.executeReclaim === true || args.rides.servedShapeRepair === true || args.materializationRequested || args.bands.forceMaterialization || args.foldBustsServedPrefix || args.firstRender || args.bands.emergencyDropEligible || args.schedulerDecision === "execute" && (!args.alreadyRanThisTurn || !args.fullFeatureMode));
|
|
3497
|
+
}
|
|
3498
|
+
function routineCleanupRunsOnPass(args) {
|
|
3499
|
+
return (args.bands.forceBandConfirmed ? args.percentage >= 95 || args.emergencySample() === 0 : !args.fullFeatureMode || !args.routinePressureAlreadyApplied) || args.materializationRequested || args.rewriteAlreadyPriced;
|
|
3500
|
+
}
|
|
3501
|
+
var routinePressureAppliedBySession = new BoundedSessionMap(100);
|
|
3502
|
+
function heuristicsAlreadyRanThisTurn(lastHeuristicsTurnId, sessionId, currentTurnId) {
|
|
3503
|
+
return currentTurnId !== null && lastHeuristicsTurnId.get(sessionId) === currentTurnId;
|
|
3504
|
+
}
|
|
3505
|
+
function routinePressureAlreadyApplied(sessionId, args) {
|
|
3506
|
+
return args.fullFeatureMode && args.executePressureEligible && (args.alreadyRanThisTurn || routinePressureAppliedBySession.get(sessionId) === true);
|
|
3507
|
+
}
|
|
3508
|
+
function updateRoutinePressureEpisode(sessionId, args) {
|
|
3509
|
+
if (!args.executePressureEligible)
|
|
3510
|
+
routinePressureAppliedBySession.delete(sessionId);
|
|
3511
|
+
else if (args.fullFeatureMode && args.alreadyRanThisTurn)
|
|
3512
|
+
routinePressureAppliedBySession.set(sessionId, true);
|
|
3513
|
+
}
|
|
3514
|
+
function markRoutinePressureApplied(sessionId) {
|
|
3515
|
+
routinePressureAppliedBySession.set(sessionId, true);
|
|
3516
|
+
}
|
|
3517
|
+
function forgetRoutinePressureEpisode(sessionId) {
|
|
3518
|
+
routinePressureAppliedBySession.delete(sessionId);
|
|
3519
|
+
}
|
|
3520
|
+
function safeReasoningCutoff(messageTagNumbers, protectedThinkingMessages) {
|
|
3521
|
+
let cutoff = 0;
|
|
3522
|
+
for (const tag of messageTagNumbers.values())
|
|
3523
|
+
cutoff = Math.max(cutoff, tag);
|
|
3524
|
+
for (const message of protectedThinkingMessages) {
|
|
3525
|
+
const tag = messageTagNumbers.get(message);
|
|
3526
|
+
if (tag && tag > 0)
|
|
3527
|
+
cutoff = Math.min(cutoff, tag - 1);
|
|
3528
|
+
}
|
|
3529
|
+
return cutoff;
|
|
3530
|
+
}
|
|
3531
|
+
|
|
3370
3532
|
// src/hooks/magic-context/strip-structural-noise.ts
|
|
3371
3533
|
var STRUCTURAL_PART_TYPES = new Set(["meta", "step-start", "step-finish", "reasoning"]);
|
|
3372
3534
|
var structuralSentinels = new WeakSet;
|
|
@@ -3491,27 +3653,6 @@ function projectStructuralSentinels(args) {
|
|
|
3491
3653
|
return removed;
|
|
3492
3654
|
}
|
|
3493
3655
|
|
|
3494
|
-
// src/features/magic-context/storage-host-instruction-retention.ts
|
|
3495
|
-
var NAMESPACE3 = "hostInstructionRetention";
|
|
3496
|
-
var enabled = true;
|
|
3497
|
-
function hostInstructionRetentionEnabled() {
|
|
3498
|
-
return enabled;
|
|
3499
|
-
}
|
|
3500
|
-
function isHostInstructionRetentionOn(db, sessionId) {
|
|
3501
|
-
const lane = readReplayEnvelope(db, sessionId)[NAMESPACE3];
|
|
3502
|
-
return typeof lane === "object" && lane !== null && lane.on === true;
|
|
3503
|
-
}
|
|
3504
|
-
function markHostInstructionRetention(db, sessionId) {
|
|
3505
|
-
return updateReplayDocument(db, sessionId, (doc) => {
|
|
3506
|
-
const lane = doc[NAMESPACE3];
|
|
3507
|
-
if (typeof lane === "object" && lane !== null && lane.on === true)
|
|
3508
|
-
return false;
|
|
3509
|
-
doc.version = 2;
|
|
3510
|
-
doc[NAMESPACE3] = { on: true };
|
|
3511
|
-
return true;
|
|
3512
|
-
});
|
|
3513
|
-
}
|
|
3514
|
-
|
|
3515
3656
|
// src/hooks/magic-context/apply-operations.ts
|
|
3516
3657
|
var RECENT_TOOL_SKELETON_WINDOW = 20;
|
|
3517
3658
|
function buildReplacementContent(tagId) {
|
|
@@ -4891,7 +5032,7 @@ function createExistingTagResolver(sessionId, tagger, db) {
|
|
|
4891
5032
|
// src/hooks/magic-context/transform-stage-logger.ts
|
|
4892
5033
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4893
5034
|
var SLOW_STAGE_MS = 100;
|
|
4894
|
-
var
|
|
5035
|
+
var passes2 = new AsyncLocalStorage;
|
|
4895
5036
|
async function withTransformTimingSummary(run) {
|
|
4896
5037
|
const pass = {
|
|
4897
5038
|
stages: [],
|
|
@@ -4899,7 +5040,7 @@ async function withTransformTimingSummary(run) {
|
|
|
4899
5040
|
closed: false,
|
|
4900
5041
|
sessionId: undefined
|
|
4901
5042
|
};
|
|
4902
|
-
return
|
|
5043
|
+
return passes2.run(pass, async () => {
|
|
4903
5044
|
try {
|
|
4904
5045
|
return await run();
|
|
4905
5046
|
} finally {
|
|
@@ -4912,7 +5053,7 @@ async function withTransformTimingSummary(run) {
|
|
|
4912
5053
|
function logTransformElapsed(sessionId, stage, elapsedMs, extra) {
|
|
4913
5054
|
const elapsed = elapsedMs.toFixed(1);
|
|
4914
5055
|
const suffix = extra ? ` ${extra}` : "";
|
|
4915
|
-
const pass =
|
|
5056
|
+
const pass = passes2.getStore();
|
|
4916
5057
|
if (pass && !pass.closed) {
|
|
4917
5058
|
pass.sessionId = sessionId;
|
|
4918
5059
|
pass.stages.push(`${stage}=${elapsed}ms${extra ? `(${extra})` : ""}`);
|
|
@@ -5542,10 +5683,9 @@ function tagMessages(sessionId, messages, tagger, db, options = {}) {
|
|
|
5542
5683
|
var DEGRADE_CACHE_WARNING_THRESHOLD = 10;
|
|
5543
5684
|
var SYSTEM_INJECTION_ACTIONABLE_TAIL_MESSAGES = 40;
|
|
5544
5685
|
var degradedCacheCountBySession = new BoundedSessionMap(100);
|
|
5545
|
-
var routinePressureAppliedBySession = new BoundedSessionMap(100);
|
|
5546
5686
|
function resetDegradedCacheCount2(sessionId) {
|
|
5547
5687
|
degradedCacheCountBySession.delete(sessionId);
|
|
5548
|
-
|
|
5688
|
+
forgetRoutinePressureEpisode(sessionId);
|
|
5549
5689
|
}
|
|
5550
5690
|
function isSyntheticHeadMessage2(message) {
|
|
5551
5691
|
if (message.info.id !== undefined)
|
|
@@ -6203,11 +6343,15 @@ function evaluateEmergencyFailClosed2(input) {
|
|
|
6203
6343
|
if (input.usagePercentage < 95) {
|
|
6204
6344
|
return { shouldAbort: false, reason: "below-emergency-band" };
|
|
6205
6345
|
}
|
|
6206
|
-
const
|
|
6207
|
-
|
|
6208
|
-
shouldAbort,
|
|
6209
|
-
|
|
6210
|
-
|
|
6346
|
+
const recoveryOrigin = input.emergencyRecoveryArmed ? input.emergencyRecoveryOrigin : null;
|
|
6347
|
+
if (recoveryOrigin === "provider_overflow" && !input.foldMaterializedThisPass) {
|
|
6348
|
+
return { shouldAbort: true, reason: "provider-overflow-abort" };
|
|
6349
|
+
}
|
|
6350
|
+
const served = input.recoveryServedRequest;
|
|
6351
|
+
if (recoveryOrigin !== null && served !== undefined && served.lineTokens > 0 && (!Number.isFinite(served.tokens) || served.tokens > served.lineTokens)) {
|
|
6352
|
+
return { shouldAbort: true, reason: "recovery-request-over-limit" };
|
|
6353
|
+
}
|
|
6354
|
+
return { shouldAbort: false, reason: "proceed" };
|
|
6211
6355
|
}
|
|
6212
6356
|
function finalizeMessageRepresentation2(messages, resolvedProviderID, options) {
|
|
6213
6357
|
const protectedMessages = options?.protectedThinkingMessages ?? new Set;
|
|
@@ -6290,22 +6434,34 @@ async function runPostTransformPhase2(args) {
|
|
|
6290
6434
|
}
|
|
6291
6435
|
const reasoningMutationExemptMessage = findLatestAssistantReasoningMutationExemptMessage(args.messages);
|
|
6292
6436
|
const pendingMaterializationAtPassStart = args.pendingMaterializationSessions.has(args.sessionId);
|
|
6437
|
+
beginHostCheckpointPass(args.sessionId, args.pendingMaterializationSessions);
|
|
6293
6438
|
const pendingOrigin = pendingMaterializationOrigin(args.pendingMaterializationSessions, args.sessionId);
|
|
6294
6439
|
const deferredMaterializationAtPassStart = args.deferredMaterializationSessions.has(args.sessionId);
|
|
6295
6440
|
let isExplicitFlush = pendingMaterializationAtPassStart;
|
|
6296
6441
|
const deferredMaterializationWasPending = deferredMaterializationAtPassStart;
|
|
6297
|
-
const alreadyRanThisTurn = args.
|
|
6298
|
-
const
|
|
6299
|
-
|
|
6300
|
-
|
|
6301
|
-
|
|
6302
|
-
|
|
6303
|
-
|
|
6304
|
-
|
|
6305
|
-
}
|
|
6306
|
-
|
|
6307
|
-
|
|
6308
|
-
|
|
6442
|
+
const alreadyRanThisTurn = heuristicsAlreadyRanThisTurn(args.lastHeuristicsTurnId, args.sessionId, args.currentTurnId);
|
|
6443
|
+
const bands = pressureBands({
|
|
6444
|
+
percentage: args.contextUsage.percentage,
|
|
6445
|
+
fromEstimate: args.contextUsageFromEstimate === true,
|
|
6446
|
+
forceMaterializationPercentage: args.forceMaterializationPercentage,
|
|
6447
|
+
compactionOff,
|
|
6448
|
+
fullFeatureMode: args.fullFeatureMode,
|
|
6449
|
+
schedulerDecision: args.schedulerDecision
|
|
6450
|
+
});
|
|
6451
|
+
const {
|
|
6452
|
+
forceMaterialization,
|
|
6453
|
+
emergencyDropEligible,
|
|
6454
|
+
forceRideWaitsOnLocalCount,
|
|
6455
|
+
forceBandConfirmed,
|
|
6456
|
+
executePressureEligible
|
|
6457
|
+
} = bands;
|
|
6458
|
+
const episode = {
|
|
6459
|
+
fullFeatureMode: args.fullFeatureMode,
|
|
6460
|
+
executePressureEligible,
|
|
6461
|
+
alreadyRanThisTurn
|
|
6462
|
+
};
|
|
6463
|
+
updateRoutinePressureEpisode(args.sessionId, episode);
|
|
6464
|
+
const routinePressureApplied = routinePressureAlreadyApplied(args.sessionId, episode);
|
|
6309
6465
|
if (args.contextUsageFromEstimate !== true && args.contextUsage.percentage > 0 && args.contextUsage.percentage < args.forceMaterializationPercentage - 5 && getEmergencyInputSample(args.db, args.sessionId) > 0) {
|
|
6310
6466
|
clearEmergencyDropSample(args.db, args.sessionId);
|
|
6311
6467
|
}
|
|
@@ -6328,15 +6484,7 @@ async function runPostTransformPhase2(args) {
|
|
|
6328
6484
|
let activeThinkingTurn = retainedThinking.size > 0;
|
|
6329
6485
|
const protectedThinkingMessages = new Set(args.messages.filter((message) => message.parts.some((part) => retainedThinking.has(part))));
|
|
6330
6486
|
let newTargets = protectNewTagMutations(args.messages, args.targets, retainedThinking, args.thinkingBindingRecoveryEnabledForModel === true);
|
|
6331
|
-
|
|
6332
|
-
for (const tag of args.messageTagNumbers.values())
|
|
6333
|
-
maxReasoningTag = Math.max(maxReasoningTag, tag);
|
|
6334
|
-
let safeReasoningCutoff = maxReasoningTag;
|
|
6335
|
-
for (const message of protectedThinkingMessages) {
|
|
6336
|
-
const tag = args.messageTagNumbers.get(message);
|
|
6337
|
-
if (tag && tag > 0)
|
|
6338
|
-
safeReasoningCutoff = Math.min(safeReasoningCutoff, tag - 1);
|
|
6339
|
-
}
|
|
6487
|
+
const safeReasoningCutoff2 = safeReasoningCutoff(args.messageTagNumbers, protectedThinkingMessages);
|
|
6340
6488
|
let activeThinkingPrefixHold = args.activeThinkingPrefixHold === true;
|
|
6341
6489
|
let freezeM0M1 = args.freezeM0M1 === true || activeThinkingPrefixHold;
|
|
6342
6490
|
let rewritingSignedPrefix = false;
|
|
@@ -6375,6 +6523,26 @@ async function runPostTransformPhase2(args) {
|
|
|
6375
6523
|
sessionLog2(args.sessionId, "compaction mode switch: stripping signed thinking");
|
|
6376
6524
|
releaseThinkingForRewrite(false, true);
|
|
6377
6525
|
}
|
|
6526
|
+
const hostCheckpointRequested = hasPendingMaterializationOrigin(args.pendingMaterializationSessions, args.sessionId, "host_compaction");
|
|
6527
|
+
const hostCheckpointProof = hostCheckpointRequested && m0M1EnabledForFold ? hostCheckpointHeadChange(args.sessionId, () => {
|
|
6528
|
+
hydrateCachedM0Mural(args.db, args.sessionId, args.sessionMeta);
|
|
6529
|
+
return {
|
|
6530
|
+
m0Text: args.sessionMeta.cachedM0Bytes?.toString("utf8"),
|
|
6531
|
+
m1Text: args.sessionMeta.cachedM1Bytes?.toString("utf8"),
|
|
6532
|
+
muralDataUrl: args.sessionMeta.cachedM0MuralDataUrl ?? null
|
|
6533
|
+
};
|
|
6534
|
+
}) : undefined;
|
|
6535
|
+
const hostCheckpointRide = hostCheckpointProof?.changed === true;
|
|
6536
|
+
if (hostCheckpointRequested) {
|
|
6537
|
+
sessionLog2(args.sessionId, `host checkpoint head: changed=${hostCheckpointRide} proof=${hostCheckpointProof?.source ?? "none"}`);
|
|
6538
|
+
}
|
|
6539
|
+
if (hostCheckpointRide && activeThinkingPrefixHold) {
|
|
6540
|
+
sessionLog2(args.sessionId, "host checkpoint head changed under a signed-thinking hold: stripping signed thinking");
|
|
6541
|
+
releaseThinkingForRewrite(false, true);
|
|
6542
|
+
}
|
|
6543
|
+
if (args.requestToolsChange && args.thinkingBindingRecoveryEnabledForModel === true) {
|
|
6544
|
+
releaseThinkingForRewrite(false, true);
|
|
6545
|
+
}
|
|
6378
6546
|
const foldDueDecision = m0M1EnabledForFold && args.m0M1 && !freezeM0M1 ? mustMaterialize({
|
|
6379
6547
|
db: args.db,
|
|
6380
6548
|
sessionId: args.sessionId,
|
|
@@ -6542,8 +6710,13 @@ async function runPostTransformPhase2(args) {
|
|
|
6542
6710
|
servedShapeRepair: servedShapeRepair.needsRebuild,
|
|
6543
6711
|
executeReclaim: false,
|
|
6544
6712
|
subagentExecute: !args.fullFeatureMode && args.schedulerDecision === "execute",
|
|
6545
|
-
hardFold: rewritingSignedPrefix || foldBustsServedPrefixThisPass || firstRenderBust,
|
|
6546
|
-
force:
|
|
6713
|
+
hardFold: rewritingSignedPrefix || foldBustsServedPrefixThisPass || firstRenderBust || hostCheckpointRide,
|
|
6714
|
+
force: forceRide({
|
|
6715
|
+
bands,
|
|
6716
|
+
percentage: args.contextUsage.percentage,
|
|
6717
|
+
fromEstimate: args.contextUsageFromEstimate === true,
|
|
6718
|
+
emergencySample: () => getEmergencyInputSample(args.db, args.sessionId)
|
|
6719
|
+
}),
|
|
6547
6720
|
explicitFlush: isExplicitFlush && hasPendingMaterializationOrigin(args.pendingMaterializationSessions, args.sessionId, "user_flush"),
|
|
6548
6721
|
publishedHistory: !prefixPreflightFailed && (publishedM1RefreshedThisPass || !m0M1EnabledForFold && (args.pendingCompartmentInjection?.compartmentCount ?? 0) > 0 && legacyPublishedHeadChanged(args))
|
|
6549
6722
|
};
|
|
@@ -6567,17 +6740,29 @@ async function runPostTransformPhase2(args) {
|
|
|
6567
6740
|
const publishedWorkDrainAllowed = (!compactionOff || servedShapeRepair.needsRebuild) && reclaimRidePermitted(rideSignals, {
|
|
6568
6741
|
signedThinkingHold: activeThinkingPrefixHold,
|
|
6569
6742
|
firstRender: firstRenderBust,
|
|
6743
|
+
hostCheckpointHead: hostCheckpointRide,
|
|
6570
6744
|
emergency: forceBandConfirmed
|
|
6571
6745
|
});
|
|
6572
6746
|
const shouldApplyPendingOps = !compactionOff && publishedWorkDrainAllowed;
|
|
6573
|
-
const shouldRunHeuristics =
|
|
6747
|
+
const shouldRunHeuristics = heuristicsRunOnPass({
|
|
6748
|
+
compactionOff,
|
|
6749
|
+
drainAllowed: publishedWorkDrainAllowed,
|
|
6750
|
+
rides: rideSignals,
|
|
6751
|
+
materializationRequested,
|
|
6752
|
+
bands,
|
|
6753
|
+
foldBustsServedPrefix: foldBustsServedPrefixThisPass,
|
|
6754
|
+
firstRender: firstRenderBust,
|
|
6755
|
+
schedulerDecision: args.schedulerDecision,
|
|
6756
|
+
alreadyRanThisTurn,
|
|
6757
|
+
fullFeatureMode: args.fullFeatureMode
|
|
6758
|
+
});
|
|
6574
6759
|
const isCacheBustingPass = publishedWorkDrainAllowed;
|
|
6575
6760
|
if (servedShapeRepair.needsRebuild && !isCacheBustingPass)
|
|
6576
6761
|
throw new Error("Served-shape repair requires a rebuilding pass");
|
|
6577
6762
|
servedShapeRepair.apply(isCacheBustingPass);
|
|
6578
6763
|
let unheldSignedTurnBust = false;
|
|
6579
6764
|
if (isCacheBustingPass && !activeThinkingPrefixHold && activeThinkingTurn && args.thinkingBindingRecoveryEnabledForModel === true) {
|
|
6580
|
-
if (foldBustsServedPrefixThisPass || firstRenderBust || publishedM1RefreshedThisPass)
|
|
6765
|
+
if (foldBustsServedPrefixThisPass || firstRenderBust || publishedM1RefreshedThisPass || hostCheckpointRide)
|
|
6581
6766
|
releaseThinkingForRewrite();
|
|
6582
6767
|
else {
|
|
6583
6768
|
unheldSignedTurnBust = true;
|
|
@@ -6587,7 +6772,7 @@ async function runPostTransformPhase2(args) {
|
|
|
6587
6772
|
}
|
|
6588
6773
|
}
|
|
6589
6774
|
const recoveryHasHistoryHead = m0M1EnabledForFold || (args.pendingCompartmentInjection?.compartmentCount ?? 0) > 0;
|
|
6590
|
-
const recoveryHeadChangedThisPass = !prefixPreflightFailed && (foldChangesHeadThisPass || !firstRenderBust && publishedM1RefreshedThisPass || !m0M1EnabledForFold && legacyPublishedHeadChanged(args));
|
|
6775
|
+
const recoveryHeadChangedThisPass = !prefixPreflightFailed && (foldChangesHeadThisPass || hostCheckpointRide || !firstRenderBust && publishedM1RefreshedThisPass || !m0M1EnabledForFold && legacyPublishedHeadChanged(args));
|
|
6591
6776
|
const recoveryHeadlessRebuild = !recoveryHasHistoryHead && (args.schedulerDecision === "execute" || isExplicitFlush || forceMaterialization || emergencyDropEligible);
|
|
6592
6777
|
const recoveredShapeRewriteProof = recoveryHeadChangedThisPass ? "head_bytes" : recoveryExternalFoldCause ?? (recoveryHeadlessRebuild ? "headless_rebuild" : null);
|
|
6593
6778
|
const canNormalizeRecoveredShape = isCacheBustingPass && !activeThinkingPrefixHold && recoveredShapeRewriteProof !== null;
|
|
@@ -6715,7 +6900,18 @@ async function runPostTransformPhase2(args) {
|
|
|
6715
6900
|
recordFirstApplicationWireEdit(false);
|
|
6716
6901
|
firstApplicationLocations.set(message, Math.min(firstApplicationLocations.get(message) ?? Infinity, partIndex));
|
|
6717
6902
|
};
|
|
6718
|
-
const
|
|
6903
|
+
const coveredHostInstructions = args.coveredHostInstructions ?? [];
|
|
6904
|
+
let coveredRetentionOn = false;
|
|
6905
|
+
let retainCoveredInstructions = false;
|
|
6906
|
+
if (m0M1EnabledForFold && args.m0M1 && !compactionOff && args.opencode2 && (coveredHostInstructions.length > 0 || canEditWholePrefix) && hostInstructionRetentionEnabled()) {
|
|
6907
|
+
try {
|
|
6908
|
+
coveredRetentionOn = isHostInstructionRetentionOn(args.db, args.sessionId);
|
|
6909
|
+
} catch (error) {
|
|
6910
|
+
failPass("host-instruction-retention-read-failure", error);
|
|
6911
|
+
}
|
|
6912
|
+
retainCoveredInstructions = coveredRetentionOn || canEditWholePrefix;
|
|
6913
|
+
}
|
|
6914
|
+
const hostRowReclaim = args.reclaimHostRows?.(args.sessionId, args.messages, !compactionOff && canEditWholePrefix, retainCoveredInstructions ? coveredHostInstructions : []);
|
|
6719
6915
|
for (const message of hostRowReclaim?.edits ?? []) {
|
|
6720
6916
|
const index = args.messages.indexOf(message);
|
|
6721
6917
|
recordFirstApplicationWireEdit(index < 0 || servesThinkingBlock2(args.messages.slice(index + 1), args.resolvedProviderID, args.resolvedModelID));
|
|
@@ -6780,11 +6976,19 @@ async function runPostTransformPhase2(args) {
|
|
|
6780
6976
|
wordRules: args.cavemanTextCompression.wordRules
|
|
6781
6977
|
} : undefined;
|
|
6782
6978
|
const heuristicTags = shouldApplyPendingOps ? getActiveTagsBySession2(args.db, args.sessionId) : args.tags;
|
|
6783
|
-
const emergencyRewriteAlreadyPriced = pendingOpsDidMutate || foldBustsServedPrefixThisPass || firstRenderBust || args.historyRebuiltThisPass || args.compartmentInjectionRebuiltFromDb || args.rebuiltHistoryFromInitialPrepare;
|
|
6979
|
+
const emergencyRewriteAlreadyPriced = pendingOpsDidMutate || foldBustsServedPrefixThisPass || firstRenderBust || hostCheckpointRide || args.historyRebuiltThisPass || args.compartmentInjectionRebuiltFromDb || args.rebuiltHistoryFromInitialPrepare;
|
|
6784
6980
|
if (forceBandConfirmed && emergencyRewriteAlreadyPriced && getEmergencyInputSample(args.db, args.sessionId) > 0) {
|
|
6785
6981
|
clearEmergencyDropSample(args.db, args.sessionId);
|
|
6786
6982
|
}
|
|
6787
|
-
let routineCleanupApplied = (
|
|
6983
|
+
let routineCleanupApplied = routineCleanupRunsOnPass({
|
|
6984
|
+
bands,
|
|
6985
|
+
percentage: args.contextUsage.percentage,
|
|
6986
|
+
emergencySample: () => getEmergencyInputSample(args.db, args.sessionId),
|
|
6987
|
+
fullFeatureMode: args.fullFeatureMode,
|
|
6988
|
+
routinePressureAlreadyApplied: routinePressureApplied,
|
|
6989
|
+
materializationRequested,
|
|
6990
|
+
rewriteAlreadyPriced: emergencyRewriteAlreadyPriced
|
|
6991
|
+
});
|
|
6788
6992
|
let cleanup = applyHeuristicCleanup(args.sessionId, args.db, newTargets, args.messageTagNumbers, {
|
|
6789
6993
|
protectedTagNumbers: args.protectedTagNumbers,
|
|
6790
6994
|
protectedCutoff: args.protectedCutoff,
|
|
@@ -6822,7 +7026,7 @@ async function runPostTransformPhase2(args) {
|
|
|
6822
7026
|
routineCleanupApplied = true;
|
|
6823
7027
|
}
|
|
6824
7028
|
if (routineCleanupApplied && args.fullFeatureMode && executePressureEligible) {
|
|
6825
|
-
|
|
7029
|
+
markRoutinePressureApplied(args.sessionId);
|
|
6826
7030
|
}
|
|
6827
7031
|
logTransformTiming(args.sessionId, "applyHeuristicCleanup", t5, `droppedTools=${cleanup.droppedTools} deduplicatedTools=${cleanup.deduplicatedTools} droppedInjections=${cleanup.droppedInjections} compressedTextTags=${cleanup.compressedTextTags} mutatedTextTags=${cleanup.mutatedTextTags}`);
|
|
6828
7032
|
const heuristicMutationCount = cleanup.droppedTools + cleanup.deduplicatedTools + cleanup.droppedInjections + cleanup.mutatedTextTags;
|
|
@@ -6841,7 +7045,7 @@ async function runPostTransformPhase2(args) {
|
|
|
6841
7045
|
}
|
|
6842
7046
|
}
|
|
6843
7047
|
const reasoningEstimates = tryGetReasoningTokenEstimatesByMessage2(args.db, args.sessionId, sessionDecisionCalibration(args.db, args.sessionId).proseRatio);
|
|
6844
|
-
const budgetCutoff = routineCleanupApplied && !activeThinkingPrefixHold && reasoningEstimates ? Math.min(
|
|
7048
|
+
const budgetCutoff = routineCleanupApplied && !activeThinkingPrefixHold && reasoningEstimates ? Math.min(safeReasoningCutoff2, opencodeReasoningBudgetCutoff({
|
|
6845
7049
|
messages: args.messages,
|
|
6846
7050
|
messageTagNumbers: args.messageTagNumbers,
|
|
6847
7051
|
budget: args.keepReasoningTokens ?? DEFAULT_KEEP_REASONING_TOKENS,
|
|
@@ -7098,25 +7302,10 @@ async function runPostTransformPhase2(args) {
|
|
|
7098
7302
|
}
|
|
7099
7303
|
}
|
|
7100
7304
|
const m0M1Enabled = m0M1EnabledForFold;
|
|
7101
|
-
if (
|
|
7102
|
-
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
if (hostInstructionRetentionEnabled()) {
|
|
7106
|
-
try {
|
|
7107
|
-
retain = isHostInstructionRetentionOn(args.db, args.sessionId);
|
|
7108
|
-
} catch (error) {
|
|
7109
|
-
failPass("host-instruction-retention-read-failure", error);
|
|
7110
|
-
}
|
|
7111
|
-
if (!retain && canEditWholePrefix) {
|
|
7112
|
-
if (!markHostInstructionRetention(args.db, args.sessionId))
|
|
7113
|
-
failPass("host-instruction-retention-persistence-failure");
|
|
7114
|
-
retain = true;
|
|
7115
|
-
}
|
|
7116
|
-
}
|
|
7117
|
-
if (retain && covered.length > 0)
|
|
7118
|
-
args.messages.unshift(...covered);
|
|
7119
|
-
}
|
|
7305
|
+
if (retainCoveredInstructions && coveredHostInstructions.length > 0) {
|
|
7306
|
+
if (!coveredRetentionOn && coveredHostInstructions.some((m) => m.parts.length > 0))
|
|
7307
|
+
recordFirstApplicationWireEdit(true);
|
|
7308
|
+
args.messages.unshift(...coveredHostInstructions);
|
|
7120
7309
|
}
|
|
7121
7310
|
if (m0M1Enabled && args.m0M1) {
|
|
7122
7311
|
if (freezeM0M1 && !preparedPrefix) {
|
|
@@ -7163,6 +7352,11 @@ async function runPostTransformPhase2(args) {
|
|
|
7163
7352
|
if (result.m0RematerializedThisPass) {
|
|
7164
7353
|
m0ComparisonDecision = result.decision;
|
|
7165
7354
|
}
|
|
7355
|
+
stageServedHead(args.sessionId, {
|
|
7356
|
+
m0Text: args.sessionMeta.cachedM0Bytes?.toString("utf8"),
|
|
7357
|
+
m1Text: args.sessionMeta.cachedM1Bytes?.toString("utf8"),
|
|
7358
|
+
muralDataUrl: args.sessionMeta.cachedM0MuralDataUrl ?? null
|
|
7359
|
+
}, args.sessionMeta.cachedM0Bytes == null ? -1 : args.sessionMeta.cachedM0MaxCompartmentSeq);
|
|
7166
7360
|
sessionLog2(args.sessionId, `transform: injected m[0]/m[1] (rematerialized=${result.m0RematerializedThisPass}, reason=${result.decision.reason ?? "cache_hit"})`);
|
|
7167
7361
|
}
|
|
7168
7362
|
} catch (error) {
|
|
@@ -7451,7 +7645,7 @@ async function runPostTransformPhase2(args) {
|
|
|
7451
7645
|
}
|
|
7452
7646
|
const materializeReason = m0MaterializeReason ?? (explicitMaterializedSuccessfully ? pendingOrigin : null);
|
|
7453
7647
|
const materialized = m0RematerializedThisPass || explicitMaterializedSuccessfully || deferredMaterializedSuccessfully;
|
|
7454
|
-
let bustedThisPass = firstApplicationEdits.any || firstRenderBust || pendingOpsDidMutate || heuristicOrReasoningDidMutate || autoReclaimDidMutateThisPass || convertedToolSkeletonsDidMutate || m0RematerializedThisPass || m0M1InjectedThisPass && historyWasConsumedThisPass || historyWasConsumedThisPass;
|
|
7648
|
+
let bustedThisPass = firstApplicationEdits.any || firstRenderBust || hostCheckpointRide || pendingOpsDidMutate || heuristicOrReasoningDidMutate || autoReclaimDidMutateThisPass || convertedToolSkeletonsDidMutate || m0RematerializedThisPass || m0M1InjectedThisPass && historyWasConsumedThisPass || historyWasConsumedThisPass;
|
|
7455
7649
|
const proactiveThinkingStripPermitted = isCacheBustingPass && !activeThinkingPrefixHold;
|
|
7456
7650
|
const tFrozenDecisions = performance.now();
|
|
7457
7651
|
if (reasoningMutationTargetUnknown) {
|
|
@@ -7683,6 +7877,8 @@ async function runPostTransformPhase2(args) {
|
|
|
7683
7877
|
}
|
|
7684
7878
|
}
|
|
7685
7879
|
hostRowReclaim?.commit();
|
|
7880
|
+
if (retainCoveredInstructions && !coveredRetentionOn && !markHostInstructionRetention(args.db, args.sessionId))
|
|
7881
|
+
failPass("host-instruction-retention-persistence-failure");
|
|
7686
7882
|
let settledDroppedReasoning = 0;
|
|
7687
7883
|
if (!canUseEmptySentinels) {
|
|
7688
7884
|
let mode = "legacy";
|
|
@@ -7833,6 +8029,21 @@ async function runPostTransformPhase2(args) {
|
|
|
7833
8029
|
logTransformTiming(args.sessionId, "pp.tailGuard", tTailGuard);
|
|
7834
8030
|
if (bustedThisPass)
|
|
7835
8031
|
clearExecuteReclaimState(args.db, args.sessionId);
|
|
8032
|
+
if (hostCheckpointRide && isCacheBustingPass) {
|
|
8033
|
+
try {
|
|
8034
|
+
rearmChannel2AfterCoverageAdvancingHardFold({
|
|
8035
|
+
db: args.db,
|
|
8036
|
+
sessionId: args.sessionId,
|
|
8037
|
+
foldExecuted: true,
|
|
8038
|
+
compactionOff,
|
|
8039
|
+
previousCoverage: hostCheckpointProof?.previousCoverage ?? null,
|
|
8040
|
+
currentCoverage: args.sessionMeta.cachedM0Bytes == null ? null : args.sessionMeta.cachedM0MaxCompartmentSeq
|
|
8041
|
+
});
|
|
8042
|
+
} catch (error) {
|
|
8043
|
+
sessionLog2(args.sessionId, "channel2 host-checkpoint reset failed (ignored):", error);
|
|
8044
|
+
}
|
|
8045
|
+
}
|
|
8046
|
+
completeHostCheckpointPass(args.sessionId, args.pendingMaterializationSessions, hostCheckpointRequested && (!hostCheckpointRide || isCacheBustingPass || compactionOff));
|
|
7836
8047
|
return {
|
|
7837
8048
|
explicitMaterializedSuccessfully,
|
|
7838
8049
|
deferredMaterializedSuccessfully,
|
|
@@ -7869,4 +8080,4 @@ function checkM0MutationDriftAndSignal2(args) {
|
|
|
7869
8080
|
return false;
|
|
7870
8081
|
}
|
|
7871
8082
|
|
|
7872
|
-
export { makeToolCompositeKey, createTagger, cavemanWordRulesForLanguage, searchMessageHistoryOffThread, findSessionId, findLastUserMessageId, clearAutoSearchForSession, setCtxReduceRegisteredGlobally, resolveCtxReduceAvailabilityFromMessages, resolveCtxReduceAvailability, primeCtxReduceSpawnPermission, ctxReduceSpawnPermissionReadNeeded, spawnAgentFromMessages, spawnAgentFromOpenCodeDb, todowritePermissionDenied, cachedToolPermissionDenied, clearToolPermissionDenied, resolveTodowriteAvailabilityFromMessages, resolveTodowriteAvailability, diagnosticStateChanged, clearDiagnosticLogState, canConsumeDeferredOnThisPass, hasReclaimRide, reclaimRidePermitted, reclaimRideLabel, pendingDropEligibilityKey, createPendingDropEligibilityCache, readExecuteReclaimState, writeExecuteReclaimState, maintainExecuteFloorMark, captureOpencodeReasoningBudgetStatus, reasoningBudgetStatusLine, ENGINE_RECONNECTING_USER_MESSAGE, ENGINE_BUSY_USER_MESSAGE, SIGNED_THINKING_RESET_FENCE_FAILED, contextRefusalError, protectedToolRefusal, outgoingContextRefusal, signedTurnContextRefusal, EmergencyFailClosedError, latestAssistantTurnStart, latestAssistantTurnMessages, hasActiveAnthropicThinkingTurn, replayCavemanCompression, DegradedPassRefusalError, degradedPassError, isStructuralNoiseSentinel, stripStructuralNoise, prepareStructuralSentinelChoices, renderDroppedText, applyFlushedStatuses, prewarmTagOwners, waitForTagOwners, collectForeignTextParts, isLegacyForeignTextTag, withTransformTimingSummary, logTransformTiming, hasRecentAssistantCommit, tagMessages, resetDegradedCacheCount2, isSyntheticHeadMessage2, applyTodoSynthesis2, freezeReasoningOnBustingPass2, servesThinkingBlock2, firstServedDivergenceIndex2, rustModeServedKeyAfterPersistedStrips2, replayRustModeBindingMismatchStrips2, RUST_MARKER_LOCK_SKIP_LOG2, applyRustModeDeferredCompactionMarker2, clearRustModeBoundaryRecord2, runRustModePostprocess2, reconcileMarkerRepresentation2, clearPendingCompactionMarkerAfterSuccessfulDrain2, defaultCompactionMarkerStrategy2, abortSessionFailClosed2, evaluateEmergencyFailClosed2, finalizeMessageRepresentation2, runPostTransformPhase2, checkM0MutationDriftAndSignal2 };
|
|
8083
|
+
export { makeToolCompositeKey, createTagger, cavemanWordRulesForLanguage, searchMessageHistoryOffThread, findSessionId, findLastUserMessageId, clearAutoSearchForSession, setCtxReduceRegisteredGlobally, resolveCtxReduceAvailabilityFromMessages, resolveCtxReduceAvailability, primeCtxReduceSpawnPermission, ctxReduceSpawnPermissionReadNeeded, spawnAgentFromMessages, spawnAgentFromOpenCodeDb, todowritePermissionDenied, cachedToolPermissionDenied, clearToolPermissionDenied, resolveTodowriteAvailabilityFromMessages, resolveTodowriteAvailability, diagnosticStateChanged, clearDiagnosticLogState, canConsumeDeferredOnThisPass, hasReclaimRide, reclaimRidePermitted, reclaimRideLabel, pendingDropEligibilityKey, createPendingDropEligibilityCache, readExecuteReclaimState, writeExecuteReclaimState, maintainExecuteFloorMark, captureOpencodeReasoningBudgetStatus, reasoningBudgetStatusLine, ENGINE_RECONNECTING_USER_MESSAGE, ENGINE_BUSY_USER_MESSAGE, SIGNED_THINKING_RESET_FENCE_FAILED, contextRefusalError, protectedToolRefusal, outgoingContextRefusal, signedTurnContextRefusal, EmergencyFailClosedError, removeReasoningParts, latestAssistantTurnStart, latestAssistantTurnMessages, hasActiveAnthropicThinkingTurn, retainedActiveThinkingParts, replayCavemanCompression, DegradedPassRefusalError, degradedPassError, servedHeadChanged, noteHostCheckpointCommit, revertHostCheckpointPass, forgetHostCheckpointPass, hostInstructionRetentionEnabled, isHostInstructionRetentionOn, pressureBands, forceRide, heuristicsRunOnPass, routineCleanupRunsOnPass, heuristicsAlreadyRanThisTurn, routinePressureAlreadyApplied, safeReasoningCutoff, isStructuralNoiseSentinel, stripStructuralNoise, prepareStructuralSentinelChoices, renderDroppedText, applyFlushedStatuses, prewarmTagOwners, waitForTagOwners, collectForeignTextParts, isLegacyForeignTextTag, withTransformTimingSummary, logTransformTiming, hasRecentAssistantCommit, tagMessages, resetDegradedCacheCount2, isSyntheticHeadMessage2, applyTodoSynthesis2, freezeReasoningOnBustingPass2, servesThinkingBlock2, firstServedDivergenceIndex2, rustModeServedKeyAfterPersistedStrips2, replayRustModeBindingMismatchStrips2, RUST_MARKER_LOCK_SKIP_LOG2, applyRustModeDeferredCompactionMarker2, clearRustModeBoundaryRecord2, runRustModePostprocess2, reconcileMarkerRepresentation2, clearPendingCompactionMarkerAfterSuccessfulDrain2, defaultCompactionMarkerStrategy2, abortSessionFailClosed2, evaluateEmergencyFailClosed2, finalizeMessageRepresentation2, runPostTransformPhase2, checkM0MutationDriftAndSignal2 };
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
releaseCompartmentLeaseBestEffort,
|
|
9
9
|
getCompartments,
|
|
10
10
|
getLastCompartmentEndMessage
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-1qmv26ga.js";
|
|
12
12
|
import {
|
|
13
13
|
inRootAsyncContext2
|
|
14
14
|
} from "./index-gzy5w8ya.js";
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
getHistorianFailureState,
|
|
21
21
|
clearEmergencyRecovery,
|
|
22
22
|
prepareRawSessionOrdinals2
|
|
23
|
-
} from "./index-
|
|
23
|
+
} from "./index-xgnh498s.js";
|
|
24
24
|
import {
|
|
25
25
|
pushNotification2
|
|
26
26
|
} from "./index-x8a7jmkh.js";
|
|
@@ -32,14 +32,14 @@ import {
|
|
|
32
32
|
getActiveCompartmentRun,
|
|
33
33
|
markActiveCompartmentRunPublished,
|
|
34
34
|
registerActiveCompartmentRun
|
|
35
|
-
} from "./index-
|
|
35
|
+
} from "./index-bqhjzhv4.js";
|
|
36
36
|
import {
|
|
37
37
|
sendStatusNotification2
|
|
38
38
|
} from "./index-25ka1jza.js";
|
|
39
39
|
import {
|
|
40
40
|
setRecompStarting2,
|
|
41
41
|
setRecompTerminal2
|
|
42
|
-
} from "./index-
|
|
42
|
+
} from "./index-eej9kwad.js";
|
|
43
43
|
|
|
44
44
|
// src/hooks/magic-context/wrapup-orchestrator.ts
|
|
45
45
|
import * as crypto from "node:crypto";
|