@cortexkit/opencode-magic-context 0.49.35 → 0.49.37
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/README.md +1 -1
- package/dist/auto-search-worker.js +163 -160
- package/dist/chunk-embedding-write-worker.js +58 -56
- package/dist/{compaction-marker-candidates-g0p67ced.js → compaction-marker-candidates-5p1qkve9.js} +3 -1
- package/dist/compaction-marker-candidates-worker.js +24 -23
- package/dist/{compartment-chunk-embedding-y4136are.js → compartment-chunk-embedding-ypktm0tk.js} +5 -4
- package/dist/{conflict-warning-hook-hhw8z5ak.js → conflict-warning-hook-b75jn458.js} +6 -5
- package/dist/{context-fk8e3h9p.js → context-ngk2jz60.js} +501 -97
- package/dist/{embedding-backfill-q6n72sy0.js → embedding-backfill-rma0v2ct.js} +9 -8
- package/dist/embedding-worker.js +2 -2
- package/dist/features/magic-context/compaction-marker-candidates.d.ts.map +1 -1
- package/dist/features/magic-context/compaction-marker.d.ts +5 -3
- package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify-gate.d.ts +2 -0
- package/dist/features/magic-context/dreamer/verify-gate.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify-state.d.ts +9 -0
- package/dist/features/magic-context/dreamer/verify-state.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/verify.d.ts +2 -1
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/migration-worker-client.d.ts +3 -0
- package/dist/features/magic-context/migration-worker-client.d.ts.map +1 -1
- package/dist/features/magic-context/migration-worker.d.ts +15 -0
- package/dist/features/magic-context/migration-worker.d.ts.map +1 -1
- package/dist/features/magic-context/overflow-detection.d.ts +2 -2
- package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
- package/dist/features/magic-context/search-rerank.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +1 -0
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tags.d.ts +4 -0
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/features/magic-context/work-metrics-carry-storage.d.ts +10 -0
- package/dist/features/magic-context/work-metrics-carry-storage.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts +5 -1
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
- package/dist/hooks/magic-context/compaction-marker-publication.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
- package/dist/hooks/magic-context/issue-423-fixture.d.ts +1 -1
- package/dist/hooks/magic-context/issue-423-fixture.d.ts.map +1 -1
- package/dist/hooks/magic-context/issue-424-fixture.d.ts +1 -1
- package/dist/hooks/magic-context/issue-424-fixture.d.ts.map +1 -1
- package/dist/hooks/magic-context/project-structural-sentinels.d.ts +25 -0
- package/dist/hooks/magic-context/project-structural-sentinels.d.ts.map +1 -0
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts +8 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts +2 -0
- package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
- package/dist/hooks/magic-context/release-recovery-prefix.d.ts +9 -0
- package/dist/hooks/magic-context/release-recovery-prefix.d.ts.map +1 -0
- package/dist/hooks/magic-context/strip-structural-noise.d.ts +6 -3
- package/dist/hooks/magic-context/strip-structural-noise.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-context-state.d.ts +3 -0
- package/dist/hooks/magic-context/transform-context-state.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +3 -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-cpjk5jd2.js → index-1d042x6w.js} +16 -14
- package/dist/{index-jn0ddrhp.js → index-21fgrfrf.js} +8 -6
- package/dist/{index-pq0dpwrc.js → index-2rs7912w.js} +2 -2
- package/dist/{index-ezv6dz3y.js → index-4ks89h5a.js} +4 -4
- package/dist/{index-vzhhr1ht.js → index-4y35msh5.js} +1 -2
- package/dist/{index-f297z1n8.js → index-72czy45z.js} +5 -5
- package/dist/index-7v05d9b7.js +58 -0
- package/dist/{index-f9b3vtt1.js → index-850vthn3.js} +8 -2
- package/dist/{index-ksv0a31x.js → index-8jjjmhab.js} +12 -1
- package/dist/index-96ztjvkn.js +204 -0
- package/dist/{index-gyaa159j.js → index-9fgmkfaf.js} +6 -3
- package/dist/{index-4bgk5ztz.js → index-9tdvbdv1.js} +187 -90
- package/dist/{index-2v6nvy3k.js → index-ae1ar4v1.js} +1 -1
- package/dist/{index-faxb7mck.js → index-b1ydbp95.js} +1 -1
- package/dist/{index-nxrsns5x.js → index-c5dzns43.js} +75 -75
- package/dist/{index-zhqwda72.js → index-dcjkw41m.js} +1 -1
- package/dist/{index-x2mrq5xv.js → index-dfdg2cgg.js} +179 -49
- package/dist/{index-87ctnzz9.js → index-dz48h1wx.js} +2 -2
- package/dist/{index-b6xz3qbe.js → index-gnmhbyyc.js} +366 -83
- package/dist/{index-qx8j6kds.js → index-j105mf16.js} +2 -2
- package/dist/{index-p56dszfp.js → index-jggt5gf2.js} +1 -1
- package/dist/{index-xwwsbsd3.js → index-pp8vdn01.js} +5 -5
- package/dist/{index-dy7w6wm4.js → index-prw8apnc.js} +5 -5
- package/dist/{index-qncw9hey.js → index-r2epb000.js} +33 -3
- package/dist/{index-brg2w6qc.js → index-tn9drm1a.js} +16 -14
- package/dist/{index-pswsyf1w.js → index-ty4vhe4n.js} +3 -3
- package/dist/{index-pztqab6k.js → index-vd2ywmfe.js} +1 -1
- package/dist/{index-3j9t1v4n.js → index-wcwhhtdh.js} +10 -9
- package/dist/{index-1rhgxqs8.js → index-xd2p95m7.js} +1 -1
- package/dist/{index-0c7p8mq5.js → index-xnm0wq1r.js} +1 -1
- package/dist/{index-3d3872c6.js → index-ys7j6679.js} +4 -4
- package/dist/index.js +38 -37
- package/dist/{message-fts-rowid-map-xg7hr0mk.js → message-fts-rowid-map-t6qsyg9s.js} +4 -3
- package/dist/{message-index-bounded-narw7bnz.js → message-index-bounded-wfk6aqxk.js} +9 -8
- package/dist/migration-worker.js +45 -40
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/{project-embedding-registry-tdz7985n.js → project-embedding-registry-3yyegjma.js} +8 -7
- package/dist/raw-ordinal-warmup-worker.js +114 -118
- package/dist/{read-session-chunk-vmg1zjg0.js → read-session-chunk-26yrrhyz.js} +7 -6
- package/dist/{read-session-raw-mncmzbm9.js → read-session-raw-j7c9w57v.js} +3 -2
- package/dist/{recomp-orchestrator-qyyhnc9b.js → recomp-orchestrator-wk509qkp.js} +20 -19
- package/dist/{render-c5p0k846.js → render-h1qarr8a.js} +13 -12
- package/dist/{search-f6hwvcxk.js → search-5h9fydyq.js} +16 -15
- package/dist/{search-archive-0ny7p3bw.js → search-archive-q79hyqxs.js} +9 -8
- package/dist/{send-session-notification-0gwcz3fw.js → send-session-notification-14p3yje4.js} +5 -4
- package/dist/shared/model-suggestion-retry.d.ts +7 -0
- package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
- package/dist/shared/prompt-async-transport.d.ts.map +1 -1
- package/dist/shared/reusable-worker-entry.d.ts +4 -0
- package/dist/shared/reusable-worker-entry.d.ts.map +1 -0
- package/dist/shared/reusable-worker.d.ts +6 -0
- package/dist/shared/reusable-worker.d.ts.map +1 -0
- package/dist/shared/reusable-worker.fixture.d.ts +2 -0
- package/dist/shared/reusable-worker.fixture.d.ts.map +1 -0
- package/dist/shared/worker-shutdown.d.ts +1 -1
- package/dist/shared/worker-shutdown.d.ts.map +1 -1
- package/dist/{storage-tags-zx1023km.js → storage-tags-vj0yj7ed.js} +1 -1
- package/dist/{store-620rjzt9.js → store-s3eykdjt.js} +1 -1
- package/dist/{transform-postprocess-phase-807ff6t2.js → transform-postprocess-phase-4gj0mtcg.js} +21 -20
- package/dist/v2/auto-search-worker.js +163 -160
- package/dist/v2/chunk-embedding-write-worker.js +59 -57
- package/dist/v2/compaction-marker-candidates-worker.js +24 -23
- package/dist/v2/{compaction-marker-candidates-t1aq6gsj.js → compaction-marker-candidates-yeb2ky46.js} +4 -2
- package/dist/v2/{compartment-chunk-embedding-ncsk0r9e.js → compartment-chunk-embedding-qfk791bd.js} +6 -5
- package/dist/v2/{context-znqfkap4.js → context-05x7kr7f.js} +1027 -215
- package/dist/v2/{embedding-backfill-11j425e0.js → embedding-backfill-00tw59rx.js} +10 -9
- package/dist/v2/embedding-worker.js +2 -2
- package/dist/v2/fold/code-mode-catalog.d.ts +3 -0
- package/dist/v2/fold/code-mode-catalog.d.ts.map +1 -0
- package/dist/v2/fold/host-media.d.ts +7 -3
- package/dist/v2/fold/host-media.d.ts.map +1 -1
- package/dist/v2/fold/idle.d.ts +1 -0
- package/dist/v2/fold/idle.d.ts.map +1 -1
- package/dist/v2/fold/manual-baseline.d.ts +8 -0
- package/dist/v2/fold/manual-baseline.d.ts.map +1 -0
- package/dist/v2/fold/native-replay-v3.d.ts +7 -0
- package/dist/v2/fold/native-replay-v3.d.ts.map +1 -1
- package/dist/v2/fold/native-replay.d.ts +24 -7
- package/dist/v2/fold/native-replay.d.ts.map +1 -1
- package/dist/v2/fold/restore.d.ts.map +1 -1
- package/dist/v2/fold/summary.d.ts +4 -0
- package/dist/v2/fold/summary.d.ts.map +1 -0
- package/dist/v2/hidden-completion.d.ts.map +1 -1
- package/dist/v2/hooks/channel2.d.ts +6 -0
- package/dist/v2/hooks/channel2.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/restore-rows.d.ts +12 -2
- package/dist/v2/hooks/restore-rows.d.ts.map +1 -1
- package/dist/v2/hooks/synthetic-admission.d.ts +7 -0
- package/dist/v2/hooks/synthetic-admission.d.ts.map +1 -0
- package/dist/v2/hooks/usage-persist.d.ts.map +1 -1
- package/dist/v2/{message-fts-rowid-map-rmk571mb.js → message-fts-rowid-map-z86avy0n.js} +5 -4
- package/dist/v2/{message-index-bounded-620bppw7.js → message-index-bounded-w14496s9.js} +9 -8
- package/dist/v2/migration-worker.js +46 -41
- package/dist/v2/{project-embedding-registry-bm5fe1a8.js → project-embedding-registry-jqq2qeqb.js} +9 -8
- package/dist/v2/raw-ordinal-warmup-worker.js +114 -118
- package/dist/v2/{read-session-chunk-qfwv1k71.js → read-session-chunk-tqnh1ret.js} +7 -6
- package/dist/v2/{read-session-raw-q294t8xs.js → read-session-raw-qpp6x9kg.js} +4 -3
- package/dist/v2/{recomp-orchestrator-fcnjref7.js → recomp-orchestrator-9cjk6aej.js} +19 -18
- package/dist/v2/{render-98a1qv0b.js → render-5dz1knf2.js} +13 -12
- package/dist/v2/{search-z1zqzsmh.js → search-8yfet25y.js} +15 -14
- package/dist/v2/{search-archive-r0y1bafr.js → search-archive-z6z9jqwf.js} +9 -8
- package/dist/v2/{send-session-notification-fst6hkg7.js → send-session-notification-kxp47tsw.js} +4 -3
- package/dist/v2/{server-cpjk5jd2.js → server-1d042x6w.js} +16 -14
- package/dist/v2/{server-fqj6ddpr.js → server-5by3vdzs.js} +186 -89
- package/dist/v2/{server-5jp38p98.js → server-6emy0v9a.js} +1 -2
- package/dist/v2/{server-rktnzs89.js → server-6vzh6wej.js} +1 -1
- package/dist/v2/{server-qa74bj91.js → server-7094pk3w.js} +9 -8
- package/dist/v2/{server-bxpz2dcn.js → server-7acq7815.js} +8 -6
- package/dist/v2/server-7v05d9b7.js +58 -0
- package/dist/v2/{server-24g8r2d0.js → server-7zacmty5.js} +75 -75
- package/dist/v2/server-96ztjvkn.js +204 -0
- package/dist/v2/{server-hnknwaz8.js → server-a9w5f0yw.js} +3 -3
- package/dist/v2/{server-9k0mjef7.js → server-avdveykk.js} +1 -1
- package/dist/v2/{server-hsf0qsn5.js → server-cp1a03vc.js} +1 -1
- package/dist/v2/{server-r3chnxs5.js → server-dfq5vb8j.js} +2 -2
- package/dist/v2/{server-x4m6xcn4.js → server-e51xmr4d.js} +6 -6
- package/dist/v2/{server-7ccxt4nq.js → server-g3gqq4ac.js} +6 -3
- package/dist/v2/{server-kkxzwa6w.js → server-gkse1wyz.js} +3 -3
- package/dist/v2/{server-1xesqm5h.js → server-jd7vzwn4.js} +15 -13
- package/dist/v2/{server-ws5exe6q.js → server-nmyganc8.js} +1 -1
- package/dist/v2/{server-q0z2q2dx.js → server-nq3cb7be.js} +1 -1
- package/dist/v2/{server-55v5hpth.js → server-qjyp27vf.js} +2 -2
- package/dist/v2/{server-xbtw0p9t.js → server-r4430x9m.js} +9 -3
- package/dist/v2/{server-qf2kzsh2.js → server-t8y64xj7.js} +4 -4
- package/dist/v2/{server-s9xgyyj9.js → server-tnzbk64q.js} +34 -4
- package/dist/v2/{server-51779zs2.js → server-v0p37hm2.js} +4 -1
- package/dist/v2/{server-bpvsvtph.js → server-xfjjbrkt.js} +12 -1
- package/dist/v2/server.js +4 -4
- package/dist/v2/{storage-tags-19s0ebf0.js → storage-tags-cw07ky67.js} +1 -1
- package/dist/v2/{store-vdm8v3jd.js → store-z3qe67cg.js} +1 -1
- package/dist/v2/{v2-archive-reader-t2c0eypn.js → v2-archive-reader-z7wr42ry.js} +3 -3
- package/dist/v2/{wrapup-orchestrator-aqpqsveg.js → wrapup-orchestrator-j1v62bkj.js} +19 -18
- package/dist/{v2-archive-reader-tm2eayp2.js → v2-archive-reader-028z6kck.js} +2 -2
- package/dist/{wrapup-orchestrator-k5yp19a6.js → wrapup-orchestrator-xg9avt2p.js} +21 -20
- package/package.json +1 -1
- package/src/shared/model-suggestion-retry.ts +1 -1
- package/src/shared/prompt-async-transport.test.ts +64 -3
- package/src/shared/prompt-async-transport.ts +61 -16
- package/src/shared/reusable-worker-entry.ts +58 -0
- package/src/shared/reusable-worker-reset.test.ts +108 -0
- package/src/shared/reusable-worker.fixture.ts +35 -0
- package/src/shared/reusable-worker.test.ts +253 -0
- package/src/shared/reusable-worker.ts +240 -0
- package/src/shared/worker-shutdown.ts +21 -17
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
resolveLegacyConfigSources,
|
|
8
8
|
getProtectedTokensTierOverrides,
|
|
9
9
|
loadPluginConfigDetailed
|
|
10
|
-
} from "./server-
|
|
10
|
+
} from "./server-avdveykk.js";
|
|
11
11
|
import {
|
|
12
12
|
getHarness2,
|
|
13
13
|
harnessOwnsOpenCodeStore2
|
|
@@ -38,6 +38,13 @@ import {
|
|
|
38
38
|
getModelsDevCacheState
|
|
39
39
|
} from "./server-qxzbmtqt.js";
|
|
40
40
|
import {
|
|
41
|
+
string,
|
|
42
|
+
number,
|
|
43
|
+
boolean,
|
|
44
|
+
array,
|
|
45
|
+
object,
|
|
46
|
+
tuple,
|
|
47
|
+
literal,
|
|
41
48
|
isValidLanguageCode,
|
|
42
49
|
withContentLanguageDirective,
|
|
43
50
|
parseCron,
|
|
@@ -49,7 +56,7 @@ import {
|
|
|
49
56
|
DEFAULT_HISTORIAN_TIMEOUT_MS,
|
|
50
57
|
DEFAULT_LOCAL_EMBEDDING_MODEL,
|
|
51
58
|
DREAM_TASK_PROMOTION_DEFAULTS
|
|
52
|
-
} from "./server-
|
|
59
|
+
} from "./server-7zacmty5.js";
|
|
53
60
|
import {
|
|
54
61
|
CANONICAL_DREAM_TASKS,
|
|
55
62
|
DREAM_TASK_CAPABILITIES,
|
|
@@ -202,7 +209,7 @@ import {
|
|
|
202
209
|
startCompartmentAgent,
|
|
203
210
|
setRecompStarting2,
|
|
204
211
|
setRecompTerminal2
|
|
205
|
-
} from "./server-
|
|
212
|
+
} from "./server-5by3vdzs.js";
|
|
206
213
|
import {
|
|
207
214
|
resolveHistorianModel2
|
|
208
215
|
} from "./server-5kym00ag.js";
|
|
@@ -231,7 +238,7 @@ import {
|
|
|
231
238
|
beginBootQuietPeriod,
|
|
232
239
|
scheduleAfterBootQuiet
|
|
233
240
|
} from "./server-69m30b21.js";
|
|
234
|
-
import"./server-
|
|
241
|
+
import"./server-v0p37hm2.js";
|
|
235
242
|
import {
|
|
236
243
|
inRootAsyncContext2,
|
|
237
244
|
getTagIdentityWriteGeneration2,
|
|
@@ -246,9 +253,12 @@ import {
|
|
|
246
253
|
SqliteAcquisitionBusyError2,
|
|
247
254
|
withAsyncPrivilegedWriter2
|
|
248
255
|
} from "./server-gzy5w8ya.js";
|
|
256
|
+
import {
|
|
257
|
+
reuseWorker
|
|
258
|
+
} from "./server-96ztjvkn.js";
|
|
249
259
|
import {
|
|
250
260
|
createWorkerShutdown
|
|
251
|
-
} from "./server-
|
|
261
|
+
} from "./server-1d042x6w.js";
|
|
252
262
|
import {
|
|
253
263
|
areRustHistorianSyntheticParts2,
|
|
254
264
|
isRawCompactionSummaryInfo2,
|
|
@@ -256,7 +266,7 @@ import {
|
|
|
256
266
|
buildInMemoryTailRawMessages2,
|
|
257
267
|
RawOrdinalsNotReady2,
|
|
258
268
|
runSessionWarmupWorker
|
|
259
|
-
} from "./server-
|
|
269
|
+
} from "./server-tnzbk64q.js";
|
|
260
270
|
import {
|
|
261
271
|
resolveModelCalibration,
|
|
262
272
|
calibrateBuckets,
|
|
@@ -351,7 +361,7 @@ import {
|
|
|
351
361
|
adoptNullOwnerToolTag2,
|
|
352
362
|
getCandidateToolOwners2,
|
|
353
363
|
pickNearestPriorOwner2
|
|
354
|
-
} from "./server-
|
|
364
|
+
} from "./server-xfjjbrkt.js";
|
|
355
365
|
import {
|
|
356
366
|
textMentionsRecentCommit,
|
|
357
367
|
hasMeaningfulUserText2,
|
|
@@ -499,7 +509,6 @@ import {
|
|
|
499
509
|
getPendingPiCompactionMarkerState,
|
|
500
510
|
clearPendingPiCompactionMarkerStateIf,
|
|
501
511
|
logPiCompactionMarkerClear,
|
|
502
|
-
setSessionWorkMetrics,
|
|
503
512
|
getObservedEpochFloor,
|
|
504
513
|
resolveEpochFloorForPass,
|
|
505
514
|
getReasoningRemovalState,
|
|
@@ -581,7 +590,7 @@ import {
|
|
|
581
590
|
readRawSessionMessageOrdinalById2,
|
|
582
591
|
readSessionChunk2,
|
|
583
592
|
readRawSessionSeedTail2
|
|
584
|
-
} from "./server-
|
|
593
|
+
} from "./server-jd7vzwn4.js";
|
|
585
594
|
import {
|
|
586
595
|
BoundedSessionMap,
|
|
587
596
|
recordToolDefinitionSet,
|
|
@@ -592,8 +601,8 @@ import {
|
|
|
592
601
|
cleanSearchText,
|
|
593
602
|
matchedSearchSnippet,
|
|
594
603
|
getLastIndexedOrdinal
|
|
595
|
-
} from "./server-
|
|
596
|
-
import"./server-
|
|
604
|
+
} from "./server-dfq5vb8j.js";
|
|
605
|
+
import"./server-nmyganc8.js";
|
|
597
606
|
import {
|
|
598
607
|
getMessageIndexEpoch,
|
|
599
608
|
isMessageIndexSearchable,
|
|
@@ -619,7 +628,7 @@ import {
|
|
|
619
628
|
resolveMemoriesByIdsForSearch2,
|
|
620
629
|
unifiedSearch2,
|
|
621
630
|
formatSearchResults2
|
|
622
|
-
} from "./server-
|
|
631
|
+
} from "./server-7094pk3w.js";
|
|
623
632
|
import {
|
|
624
633
|
embedPauseBySession,
|
|
625
634
|
embedRunStateBySession,
|
|
@@ -641,7 +650,7 @@ import {
|
|
|
641
650
|
} from "./server-zzgtgqmd.js";
|
|
642
651
|
import {
|
|
643
652
|
deleteChunkEmbedBackoffForSession2
|
|
644
|
-
} from "./server-
|
|
653
|
+
} from "./server-cp1a03vc.js";
|
|
645
654
|
import {
|
|
646
655
|
registerOwnRpcServerInstance,
|
|
647
656
|
rpcPortDir,
|
|
@@ -752,7 +761,7 @@ import {
|
|
|
752
761
|
saveSourceContent,
|
|
753
762
|
replaceSourceContent,
|
|
754
763
|
getSourceContents
|
|
755
|
-
} from "./server-
|
|
764
|
+
} from "./server-t8y64xj7.js";
|
|
756
765
|
import {
|
|
757
766
|
startBootDeadline,
|
|
758
767
|
getUnconfirmedMigrationHolders,
|
|
@@ -768,7 +777,7 @@ import {
|
|
|
768
777
|
openDatabaseAsync,
|
|
769
778
|
isDatabasePersisted,
|
|
770
779
|
getDatabasePersistenceError
|
|
771
|
-
} from "./server-
|
|
780
|
+
} from "./server-g3gqq4ac.js";
|
|
772
781
|
import {
|
|
773
782
|
V2_MEMORY_CATEGORIES,
|
|
774
783
|
CATEGORY_PRIORITY
|
|
@@ -824,7 +833,7 @@ import {
|
|
|
824
833
|
resolveHistorianProducerLimits2,
|
|
825
834
|
resolveHistorianContextLimit2
|
|
826
835
|
} from "./server-sd8hvzte.js";
|
|
827
|
-
import"./server-
|
|
836
|
+
import"./server-r4430x9m.js";
|
|
828
837
|
import {
|
|
829
838
|
isEmbeddingHostBusy2
|
|
830
839
|
} from "./server-qt1qqasc.js";
|
|
@@ -848,7 +857,7 @@ import {
|
|
|
848
857
|
embedSessionCompartmentChunks2,
|
|
849
858
|
getEmbeddingCoverageStatus2,
|
|
850
859
|
getAutoEmbeddingSessionCoverage2
|
|
851
|
-
} from "./server-
|
|
860
|
+
} from "./server-7acq7815.js";
|
|
852
861
|
import {
|
|
853
862
|
GIT_SWEEP_LEASE_RENEWAL_MS,
|
|
854
863
|
acquireGitSweepLease,
|
|
@@ -868,10 +877,10 @@ import {
|
|
|
868
877
|
getCachedLocalEmbeddingPooling,
|
|
869
878
|
preflightLocalEmbeddingPooling,
|
|
870
879
|
getLocalEmbeddingNativeMemoryStats
|
|
871
|
-
} from "./server-
|
|
880
|
+
} from "./server-6vzh6wej.js";
|
|
872
881
|
import {
|
|
873
882
|
cosineSimilarity
|
|
874
|
-
} from "./server-
|
|
883
|
+
} from "./server-gkse1wyz.js";
|
|
875
884
|
import {
|
|
876
885
|
computeCueContentHash,
|
|
877
886
|
hasMuralCueColumns,
|
|
@@ -891,6 +900,7 @@ import {
|
|
|
891
900
|
getMemoryById2,
|
|
892
901
|
getMemoriesByIds2,
|
|
893
902
|
updateMemorySeenCount2,
|
|
903
|
+
updateMemoryVerification2,
|
|
894
904
|
setMemoryClassification2,
|
|
895
905
|
supersededMemory2,
|
|
896
906
|
mergeMemoryStats2,
|
|
@@ -915,7 +925,7 @@ import {
|
|
|
915
925
|
readGitFileChangeTimesSince,
|
|
916
926
|
verificationFileExists,
|
|
917
927
|
normalizeVerificationFiles
|
|
918
|
-
} from "./server-
|
|
928
|
+
} from "./server-nq3cb7be.js";
|
|
919
929
|
import {
|
|
920
930
|
registerNotificationSink2,
|
|
921
931
|
pushNotification2,
|
|
@@ -944,7 +954,7 @@ import {
|
|
|
944
954
|
readV2RawMessagePagesForConversion2,
|
|
945
955
|
createV2RawMessageReader2,
|
|
946
956
|
createV2RawMessageProvider2
|
|
947
|
-
} from "./server-
|
|
957
|
+
} from "./server-6emy0v9a.js";
|
|
948
958
|
import {
|
|
949
959
|
resolvePromptContext2
|
|
950
960
|
} from "./server-fmsr7v69.js";
|
|
@@ -952,14 +962,14 @@ import {
|
|
|
952
962
|
renderMessageByOrdinal2,
|
|
953
963
|
renderVerboseRangeForTool2,
|
|
954
964
|
renderItemByTag2
|
|
955
|
-
} from "./server-
|
|
965
|
+
} from "./server-qjyp27vf.js";
|
|
956
966
|
import"./server-kaqs6h31.js";
|
|
957
967
|
import {
|
|
958
968
|
readV2ArchiveOffThread2
|
|
959
|
-
} from "./server-
|
|
969
|
+
} from "./server-e51xmr4d.js";
|
|
960
970
|
import {
|
|
961
971
|
renderSearchArchiveOffThread2
|
|
962
|
-
} from "./server-
|
|
972
|
+
} from "./server-a9w5f0yw.js";
|
|
963
973
|
import {
|
|
964
974
|
markCoveredInstructionRow,
|
|
965
975
|
isCoveredInstructionRow,
|
|
@@ -1099,11 +1109,11 @@ __export(exports_external, {
|
|
|
1099
1109
|
_default: () => _default2,
|
|
1100
1110
|
_function: () => _function,
|
|
1101
1111
|
any: () => any,
|
|
1102
|
-
array: () =>
|
|
1112
|
+
array: () => array2,
|
|
1103
1113
|
base64: () => base642,
|
|
1104
1114
|
base64url: () => base64url2,
|
|
1105
1115
|
bigint: () => bigint2,
|
|
1106
|
-
boolean: () =>
|
|
1116
|
+
boolean: () => boolean3,
|
|
1107
1117
|
catch: () => _catch2,
|
|
1108
1118
|
check: () => check,
|
|
1109
1119
|
cidrv4: () => cidrv42,
|
|
@@ -1157,7 +1167,7 @@ __export(exports_external, {
|
|
|
1157
1167
|
ksuid: () => ksuid2,
|
|
1158
1168
|
lazy: () => lazy,
|
|
1159
1169
|
length: () => _length,
|
|
1160
|
-
literal: () =>
|
|
1170
|
+
literal: () => literal2,
|
|
1161
1171
|
locales: () => exports_locales,
|
|
1162
1172
|
looseObject: () => looseObject,
|
|
1163
1173
|
lowercase: () => _lowercase,
|
|
@@ -1182,8 +1192,8 @@ __export(exports_external, {
|
|
|
1182
1192
|
null: () => _null3,
|
|
1183
1193
|
nullable: () => nullable,
|
|
1184
1194
|
nullish: () => nullish2,
|
|
1185
|
-
number: () =>
|
|
1186
|
-
object: () =>
|
|
1195
|
+
number: () => number3,
|
|
1196
|
+
object: () => object3,
|
|
1187
1197
|
optional: () => optional,
|
|
1188
1198
|
overwrite: () => _overwrite,
|
|
1189
1199
|
parse: () => parse3,
|
|
@@ -1213,7 +1223,7 @@ __export(exports_external, {
|
|
|
1213
1223
|
size: () => _size,
|
|
1214
1224
|
startsWith: () => _startsWith,
|
|
1215
1225
|
strictObject: () => strictObject,
|
|
1216
|
-
string: () =>
|
|
1226
|
+
string: () => string3,
|
|
1217
1227
|
stringFormat: () => stringFormat,
|
|
1218
1228
|
stringbool: () => stringbool,
|
|
1219
1229
|
success: () => success,
|
|
@@ -1226,7 +1236,7 @@ __export(exports_external, {
|
|
|
1226
1236
|
transform: () => transform,
|
|
1227
1237
|
treeifyError: () => treeifyError,
|
|
1228
1238
|
trim: () => _trim,
|
|
1229
|
-
tuple: () =>
|
|
1239
|
+
tuple: () => tuple2,
|
|
1230
1240
|
uint32: () => uint32,
|
|
1231
1241
|
uint64: () => uint64,
|
|
1232
1242
|
ulid: () => ulid2,
|
|
@@ -1579,7 +1589,7 @@ __export(exports_regexes, {
|
|
|
1579
1589
|
base64: () => base64,
|
|
1580
1590
|
base64url: () => base64url,
|
|
1581
1591
|
bigint: () => bigint,
|
|
1582
|
-
boolean: () =>
|
|
1592
|
+
boolean: () => boolean2,
|
|
1583
1593
|
browserEmail: () => browserEmail,
|
|
1584
1594
|
cidrv4: () => cidrv4,
|
|
1585
1595
|
cidrv6: () => cidrv6,
|
|
@@ -1608,7 +1618,7 @@ __export(exports_regexes, {
|
|
|
1608
1618
|
md5_hex: () => md5_hex,
|
|
1609
1619
|
nanoid: () => nanoid,
|
|
1610
1620
|
null: () => _null,
|
|
1611
|
-
number: () =>
|
|
1621
|
+
number: () => number2,
|
|
1612
1622
|
rfc5322Email: () => rfc5322Email,
|
|
1613
1623
|
sha1_base64: () => sha1_base64,
|
|
1614
1624
|
sha1_base64url: () => sha1_base64url,
|
|
@@ -1622,7 +1632,7 @@ __export(exports_regexes, {
|
|
|
1622
1632
|
sha512_base64: () => sha512_base64,
|
|
1623
1633
|
sha512_base64url: () => sha512_base64url,
|
|
1624
1634
|
sha512_hex: () => sha512_hex,
|
|
1625
|
-
string: () =>
|
|
1635
|
+
string: () => string2,
|
|
1626
1636
|
time: () => time,
|
|
1627
1637
|
ulid: () => ulid,
|
|
1628
1638
|
undefined: () => _undefined,
|
|
@@ -1706,10 +1716,10 @@ __export(exports_iso, {
|
|
|
1706
1716
|
var exports_coerce = {};
|
|
1707
1717
|
__export(exports_coerce, {
|
|
1708
1718
|
bigint: () => bigint3,
|
|
1709
|
-
boolean: () =>
|
|
1719
|
+
boolean: () => boolean4,
|
|
1710
1720
|
date: () => date4,
|
|
1711
|
-
number: () =>
|
|
1712
|
-
string: () =>
|
|
1721
|
+
number: () => number4,
|
|
1722
|
+
string: () => string4
|
|
1713
1723
|
});
|
|
1714
1724
|
|
|
1715
1725
|
// src/v2/hooks/context.ts
|
|
@@ -4222,7 +4232,7 @@ async function acquireSearchWorker(db, key, entry, input, signal) {
|
|
|
4222
4232
|
}
|
|
4223
4233
|
const fresh = !slot;
|
|
4224
4234
|
if (!slot) {
|
|
4225
|
-
const worker = inRootAsyncContext2(() => new Worker(entry, { workerData: { ...input, persistent: true } }));
|
|
4235
|
+
const worker = inRootAsyncContext2(() => input.job === "backfill" && entry.href === defaultAutoSearchWorkerEntry().href ? reuseWorker(entry, { workerData: input }) : new Worker(entry, { workerData: { ...input, persistent: true } }));
|
|
4226
4236
|
const shutdown = createWorkerShutdown(worker, "auto-search", AUTO_SEARCH_WORKER_CLOSE_DEADLINE_MS);
|
|
4227
4237
|
slot = {
|
|
4228
4238
|
worker,
|
|
@@ -4300,6 +4310,7 @@ function queueAutoSearchBackfill(db, sessionId, projectPath, query) {
|
|
|
4300
4310
|
pending.set(key, work);
|
|
4301
4311
|
return work;
|
|
4302
4312
|
}
|
|
4313
|
+
var nextSearchJobId = 0;
|
|
4303
4314
|
async function executeAutoSearchWorker(db, sessionId, projectPath, query, options, entry, job) {
|
|
4304
4315
|
if (options.signal?.aborted)
|
|
4305
4316
|
return [];
|
|
@@ -4320,6 +4331,7 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4320
4331
|
const signal = deadlineSignal ? AbortSignal.any([deadlineSignal, lifecycle.signal]) : lifecycle.signal;
|
|
4321
4332
|
const snapshot = getProjectEmbeddingSnapshot2(projectPath);
|
|
4322
4333
|
const input = {
|
|
4334
|
+
jobId: ++nextSearchJobId,
|
|
4323
4335
|
job,
|
|
4324
4336
|
path,
|
|
4325
4337
|
harness: getHarness2(),
|
|
@@ -4439,6 +4451,8 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4439
4451
|
const onMessage = async (reply) => {
|
|
4440
4452
|
if (released)
|
|
4441
4453
|
return;
|
|
4454
|
+
if (entry.href === defaultAutoSearchWorkerEntry().href && reply.jobId !== input.jobId)
|
|
4455
|
+
return;
|
|
4442
4456
|
if (reply.kind === "diagnostics") {
|
|
4443
4457
|
if (!settled && options.autoSearchDiagnostics) {
|
|
4444
4458
|
const workerStarted = options.autoSearchDiagnostics.workerStarted;
|
|
@@ -4466,7 +4480,7 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4466
4480
|
}
|
|
4467
4481
|
if (reply.kind === "messages" || reply.kind === "accepted")
|
|
4468
4482
|
return;
|
|
4469
|
-
const response = { id: reply.id };
|
|
4483
|
+
const response = { id: reply.id, jobId: input.jobId };
|
|
4470
4484
|
if (!signal.aborted) {
|
|
4471
4485
|
const requestedAt = performance.now();
|
|
4472
4486
|
try {
|
|
@@ -4595,7 +4609,7 @@ function searchMessageHistoryOffThread(db, request, entry = defaultAutoSearchWor
|
|
|
4595
4609
|
deadline.unref?.();
|
|
4596
4610
|
};
|
|
4597
4611
|
try {
|
|
4598
|
-
worker = inRootAsyncContext2(() => new Worker(entry, { workerData: input }));
|
|
4612
|
+
worker = inRootAsyncContext2(() => entry.href === defaultAutoSearchWorkerEntry().href ? reuseWorker(entry, { workerData: input }) : new Worker(entry, { workerData: input }));
|
|
4599
4613
|
shutdown = createWorkerShutdown(worker, "message-search", MESSAGE_SEARCH_WORKER_CLOSE_DEADLINE_MS);
|
|
4600
4614
|
} catch (error) {
|
|
4601
4615
|
finish(null, "start-failed", error);
|
|
@@ -5484,12 +5498,17 @@ function countCompartmentsSince(db, projectPath, since) {
|
|
|
5484
5498
|
return row?.cnt ?? 0;
|
|
5485
5499
|
}
|
|
5486
5500
|
function countProjectSessionsSince(db, projectPath, since) {
|
|
5487
|
-
const
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5501
|
+
const scope = `FROM session_projects sp
|
|
5502
|
+
LEFT JOIN session_meta m ON m.session_id = sp.session_id
|
|
5503
|
+
WHERE sp.project_path = ? AND sp.harness = ?
|
|
5504
|
+
AND COALESCE(m.is_subagent, 0) = 0`;
|
|
5505
|
+
const row = since === null ? db.prepare(`SELECT COUNT(*) AS cnt ${scope}`).get(projectPath, getHarness2()) : db.prepare(`SELECT COUNT(*) AS cnt ${scope}
|
|
5506
|
+
AND COALESCE(
|
|
5507
|
+
(SELECT CAST(value AS INTEGER) FROM schema_migrations_meta
|
|
5508
|
+
WHERE key = 'retrospective_activity:' || sp.session_id),
|
|
5509
|
+
(SELECT updated_at FROM message_history_index
|
|
5510
|
+
WHERE session_id = sp.session_id AND harness = sp.harness)
|
|
5511
|
+
) > ?`).get(projectPath, getHarness2(), since);
|
|
5493
5512
|
return row?.cnt ?? 0;
|
|
5494
5513
|
}
|
|
5495
5514
|
function countMappedMemories(db, projectPath) {
|
|
@@ -5502,6 +5521,10 @@ function countMappedMemories(db, projectPath) {
|
|
|
5502
5521
|
AND v.file_path <> ''`).get(projectPath, Date.now());
|
|
5503
5522
|
return row?.cnt ?? 0;
|
|
5504
5523
|
}
|
|
5524
|
+
var CURRENT_VERIFY_SKIP_SQL = `COALESCE(CASE WHEN json_valid(m.metadata_json) THEN
|
|
5525
|
+
json_extract(m.metadata_json, '$.dreamerVerifySkip.contentHash') = m.normalized_hash
|
|
5526
|
+
AND json_type(m.metadata_json, '$.dreamerVerifySkip.fingerprint') = 'text'
|
|
5527
|
+
ELSE 0 END, 0)`;
|
|
5505
5528
|
function countUnverifiedMappedMemories(db, projectPath) {
|
|
5506
5529
|
const row = db.prepare(`SELECT COUNT(DISTINCT m.id) AS cnt
|
|
5507
5530
|
FROM memories m
|
|
@@ -5510,7 +5533,8 @@ function countUnverifiedMappedMemories(db, projectPath) {
|
|
|
5510
5533
|
AND m.status IN ('active','permanent')
|
|
5511
5534
|
AND (m.expires_at IS NULL OR m.expires_at > ?)
|
|
5512
5535
|
AND v.file_path <> ''
|
|
5513
|
-
AND v.verified_at = 0
|
|
5536
|
+
AND v.verified_at = 0
|
|
5537
|
+
AND NOT (${CURRENT_VERIFY_SKIP_SQL})`).get(projectPath, Date.now());
|
|
5514
5538
|
return row?.cnt ?? 0;
|
|
5515
5539
|
}
|
|
5516
5540
|
function countBroadCycleCandidates(db, projectPath, cycleStartAt) {
|
|
@@ -5519,6 +5543,7 @@ function countBroadCycleCandidates(db, projectPath, cycleStartAt) {
|
|
|
5519
5543
|
WHERE m.project_path = ?
|
|
5520
5544
|
AND m.status IN ('active','permanent')
|
|
5521
5545
|
AND (m.expires_at IS NULL OR m.expires_at > ?)
|
|
5546
|
+
AND NOT (${CURRENT_VERIFY_SKIP_SQL})
|
|
5522
5547
|
AND (
|
|
5523
5548
|
SELECT MAX(v.verified_at)
|
|
5524
5549
|
FROM memory_verifications v
|
|
@@ -5627,7 +5652,7 @@ function getDreamTaskBacklog(db, projectPath, task, options = {}) {
|
|
|
5627
5652
|
case "verify-broad": {
|
|
5628
5653
|
const total = countMappedMemories(db, projectPath);
|
|
5629
5654
|
const cycleStartAt = getTaskScheduleState(db, projectPath, "verify-broad")?.lastBroadRunAt;
|
|
5630
|
-
const pending =
|
|
5655
|
+
const pending = countBroadCycleCandidates(db, projectPath, cycleStartAt ?? Number.MAX_SAFE_INTEGER);
|
|
5631
5656
|
return { pending, total };
|
|
5632
5657
|
}
|
|
5633
5658
|
case "curate": {
|
|
@@ -5754,6 +5779,7 @@ function getDreamTaskBacklogs(db, projectPath, tasks = CANONICAL_DREAM_TASKS, op
|
|
|
5754
5779
|
}
|
|
5755
5780
|
const optionKey = (value) => value === undefined ? "omitted" : value === null ? "null" : `number:${value}`;
|
|
5756
5781
|
const key = JSON.stringify([
|
|
5782
|
+
getHarness2(),
|
|
5757
5783
|
projectPath,
|
|
5758
5784
|
tasks,
|
|
5759
5785
|
optionKey(options.lastRunAt),
|
|
@@ -8584,6 +8610,130 @@ function isVisibleNoteReadPart(part) {
|
|
|
8584
8610
|
return false;
|
|
8585
8611
|
}
|
|
8586
8612
|
|
|
8613
|
+
// src/hooks/magic-context/strip-structural-noise.ts
|
|
8614
|
+
var STRUCTURAL_PART_TYPES = new Set(["meta", "step-start", "step-finish", "reasoning"]);
|
|
8615
|
+
var structuralSentinels = new WeakSet;
|
|
8616
|
+
function isStructuralNoiseSentinel(part) {
|
|
8617
|
+
return isRecord(part) && structuralSentinels.has(part);
|
|
8618
|
+
}
|
|
8619
|
+
function isStructuralNoisePart(part) {
|
|
8620
|
+
if (!isRecord(part) || typeof part.type !== "string") {
|
|
8621
|
+
return false;
|
|
8622
|
+
}
|
|
8623
|
+
if (!STRUCTURAL_PART_TYPES.has(part.type)) {
|
|
8624
|
+
return false;
|
|
8625
|
+
}
|
|
8626
|
+
if (part.type === "reasoning" && typeof part.text === "string" && part.text !== "[cleared]") {
|
|
8627
|
+
return false;
|
|
8628
|
+
}
|
|
8629
|
+
return true;
|
|
8630
|
+
}
|
|
8631
|
+
function stripStructuralNoise(messages) {
|
|
8632
|
+
let strippedParts = 0;
|
|
8633
|
+
for (const message of messages) {
|
|
8634
|
+
if (!Array.isArray(message.parts)) {
|
|
8635
|
+
continue;
|
|
8636
|
+
}
|
|
8637
|
+
for (let i = 0;i < message.parts.length; i++) {
|
|
8638
|
+
const part = message.parts[i];
|
|
8639
|
+
if (isSentinel(part))
|
|
8640
|
+
continue;
|
|
8641
|
+
if (!isStructuralNoisePart(part))
|
|
8642
|
+
continue;
|
|
8643
|
+
message.parts[i] = makeSentinel(part);
|
|
8644
|
+
if (isRecord(part) && part.type !== "reasoning") {
|
|
8645
|
+
structuralSentinels.add(message.parts[i]);
|
|
8646
|
+
}
|
|
8647
|
+
strippedParts++;
|
|
8648
|
+
}
|
|
8649
|
+
}
|
|
8650
|
+
return strippedParts;
|
|
8651
|
+
}
|
|
8652
|
+
|
|
8653
|
+
// src/hooks/magic-context/project-structural-sentinels.ts
|
|
8654
|
+
function readOmissions(value) {
|
|
8655
|
+
if (value === undefined)
|
|
8656
|
+
return new Set;
|
|
8657
|
+
if (!Array.isArray(value) || value.some((id) => typeof id !== "string" || !id))
|
|
8658
|
+
throw new Error("Invalid structural-sentinel replay decisions");
|
|
8659
|
+
return new Set(value);
|
|
8660
|
+
}
|
|
8661
|
+
function hasSignedReasoning(message) {
|
|
8662
|
+
return message.info.role === "assistant" && message.parts.some((part) => {
|
|
8663
|
+
if (!isRecord(part) || part.type !== "reasoning" || !isRecord(part.metadata))
|
|
8664
|
+
return false;
|
|
8665
|
+
const anthropic = part.metadata.anthropic;
|
|
8666
|
+
return isRecord(anthropic) && typeof anthropic.signature === "string";
|
|
8667
|
+
});
|
|
8668
|
+
}
|
|
8669
|
+
function readKeepIds(document) {
|
|
8670
|
+
const value = document.structuralSentinelUpgrade;
|
|
8671
|
+
if (value === undefined)
|
|
8672
|
+
return;
|
|
8673
|
+
if (!isRecord(value) || !Array.isArray(value.keep) || value.keep.some((id) => typeof id !== "string" || !id))
|
|
8674
|
+
throw new Error("Invalid structural-sentinel upgrade");
|
|
8675
|
+
return new Set(value.keep);
|
|
8676
|
+
}
|
|
8677
|
+
function prepareStructuralSentinelChoices(args) {
|
|
8678
|
+
const document = readReplayEnvelope(args.db, args.sessionId);
|
|
8679
|
+
if (readKeepIds(document))
|
|
8680
|
+
return document;
|
|
8681
|
+
const prior = !!args.db.prepare(`SELECT 1 WHERE
|
|
8682
|
+
EXISTS (SELECT 1 FROM session_meta WHERE session_id = ? AND trailing_blank_decisions <> '')
|
|
8683
|
+
OR EXISTS (SELECT 1 FROM session_replay_decisions WHERE session_id = ?)
|
|
8684
|
+
OR EXISTS (SELECT 1 FROM tags WHERE session_id = ?)
|
|
8685
|
+
OR EXISTS (SELECT 1 FROM lkg_slots WHERE session_id = ?)`).get(args.sessionId, args.sessionId, args.sessionId, args.sessionId);
|
|
8686
|
+
try {
|
|
8687
|
+
const persisted = updateReplayDocument(args.db, args.sessionId, (current) => {
|
|
8688
|
+
if (readKeepIds(current))
|
|
8689
|
+
return false;
|
|
8690
|
+
current.version = 2;
|
|
8691
|
+
current.structuralSentinelUpgrade = {
|
|
8692
|
+
keep: prior ? args.messages.flatMap((message) => message.info.id && hasSignedReasoning(message) ? [message.info.id] : []) : []
|
|
8693
|
+
};
|
|
8694
|
+
return true;
|
|
8695
|
+
});
|
|
8696
|
+
if (!persisted)
|
|
8697
|
+
throw new Error("Cannot persist structural-sentinel upgrade");
|
|
8698
|
+
} catch (error) {
|
|
8699
|
+
sessionLog2(args.sessionId, `structural-sentinel upgrade deferred: ${String(error)}`);
|
|
8700
|
+
return document;
|
|
8701
|
+
}
|
|
8702
|
+
return readReplayEnvelope(args.db, args.sessionId);
|
|
8703
|
+
}
|
|
8704
|
+
function projectStructuralSentinels(args) {
|
|
8705
|
+
const structuralMessages = args.messages.filter((message) => message.parts.some(isStructuralNoiseSentinel));
|
|
8706
|
+
if (structuralMessages.length === 0)
|
|
8707
|
+
return 0;
|
|
8708
|
+
const document = args.deferUpgrade ? readReplayEnvelope(args.db, args.sessionId) : prepareStructuralSentinelChoices(args);
|
|
8709
|
+
const keepIds = args.deferUpgrade ? undefined : readKeepIds(document);
|
|
8710
|
+
let omittedIds = readOmissions(document.structuralSentinelOmissions);
|
|
8711
|
+
const candidates = structuralMessages.filter((message) => typeof message.info.id === "string" && message.info.id !== "" && hasSignedReasoning(message));
|
|
8712
|
+
const selected = keepIds && args.rebuilding ? candidates.filter((message) => keepIds.has(message.info.id ?? "") && !omittedIds.has(message.info.id ?? "")) : [];
|
|
8713
|
+
if (selected.length) {
|
|
8714
|
+
if (!updateReplayDocument(args.db, args.sessionId, (document) => {
|
|
8715
|
+
const ids = readOmissions(document.structuralSentinelOmissions);
|
|
8716
|
+
for (const message of selected) {
|
|
8717
|
+
ids.add(message.info.id);
|
|
8718
|
+
}
|
|
8719
|
+
document.version = 2;
|
|
8720
|
+
document.structuralSentinelOmissions = [...ids];
|
|
8721
|
+
return true;
|
|
8722
|
+
}))
|
|
8723
|
+
throw new Error("Cannot persist structural-sentinel omissions");
|
|
8724
|
+
omittedIds = readOmissions(readReplayEnvelope(args.db, args.sessionId).structuralSentinelOmissions);
|
|
8725
|
+
}
|
|
8726
|
+
let removed = 0;
|
|
8727
|
+
for (const message of candidates) {
|
|
8728
|
+
if (!omittedIds.has(message.info.id ?? "") && (!keepIds || keepIds.has(message.info.id ?? "")))
|
|
8729
|
+
continue;
|
|
8730
|
+
const parts = message.parts.filter((part) => !isStructuralNoiseSentinel(part));
|
|
8731
|
+
removed += message.parts.length - parts.length;
|
|
8732
|
+
message.parts = parts;
|
|
8733
|
+
}
|
|
8734
|
+
return removed;
|
|
8735
|
+
}
|
|
8736
|
+
|
|
8587
8737
|
// src/hooks/magic-context/strict-thinking-prefix.ts
|
|
8588
8738
|
function servedPrefixMatches(args) {
|
|
8589
8739
|
const heads = args.messages?.slice(0, 2);
|
|
@@ -8930,38 +9080,6 @@ ${typeof state?.output === "string" ? state.output : JSON.stringify(state?.outpu
|
|
|
8930
9080
|
text: typeof part.text === "string" ? part.text : typeof part.thinking === "string" ? part.thinking : undefined
|
|
8931
9081
|
};
|
|
8932
9082
|
}
|
|
8933
|
-
// src/hooks/magic-context/strip-structural-noise.ts
|
|
8934
|
-
var STRUCTURAL_PART_TYPES = new Set(["meta", "step-start", "step-finish", "reasoning"]);
|
|
8935
|
-
function isStructuralNoisePart(part) {
|
|
8936
|
-
if (!isRecord(part) || typeof part.type !== "string") {
|
|
8937
|
-
return false;
|
|
8938
|
-
}
|
|
8939
|
-
if (!STRUCTURAL_PART_TYPES.has(part.type)) {
|
|
8940
|
-
return false;
|
|
8941
|
-
}
|
|
8942
|
-
if (part.type === "reasoning" && typeof part.text === "string" && part.text !== "[cleared]") {
|
|
8943
|
-
return false;
|
|
8944
|
-
}
|
|
8945
|
-
return true;
|
|
8946
|
-
}
|
|
8947
|
-
function stripStructuralNoise(messages) {
|
|
8948
|
-
let strippedParts = 0;
|
|
8949
|
-
for (const message of messages) {
|
|
8950
|
-
if (!Array.isArray(message.parts)) {
|
|
8951
|
-
continue;
|
|
8952
|
-
}
|
|
8953
|
-
for (let i = 0;i < message.parts.length; i++) {
|
|
8954
|
-
const part = message.parts[i];
|
|
8955
|
-
if (isSentinel(part))
|
|
8956
|
-
continue;
|
|
8957
|
-
if (!isStructuralNoisePart(part))
|
|
8958
|
-
continue;
|
|
8959
|
-
message.parts[i] = makeSentinel(part);
|
|
8960
|
-
strippedParts++;
|
|
8961
|
-
}
|
|
8962
|
-
}
|
|
8963
|
-
return strippedParts;
|
|
8964
|
-
}
|
|
8965
9083
|
// src/hooks/magic-context/foreign-text-parts.ts
|
|
8966
9084
|
function hasStringId(part) {
|
|
8967
9085
|
return part !== null && typeof part === "object" && typeof part.id === "string";
|
|
@@ -10432,6 +10550,9 @@ async function runPostTransformPhase(args) {
|
|
|
10432
10550
|
}
|
|
10433
10551
|
};
|
|
10434
10552
|
const trailingBlankSourceDecisions = args.trailingBlankSourceDecisions ?? snapshotTrailingBlankSourceDecisions(args.messages);
|
|
10553
|
+
let structuralSentinelUpgradeFailed = args.structuralSentinelUpgradeFailed ?? false;
|
|
10554
|
+
if (!structuralSentinelUpgradeFailed && args.opencode1 && !compactionOff && modelAcceptsEmptyContent(args.resolvedProviderID))
|
|
10555
|
+
structuralSentinelUpgradeFailed = prepareStructuralSentinelChoices(args).structuralSentinelUpgrade === undefined;
|
|
10435
10556
|
if (!modelAcceptsEmptyContent(args.resolvedProviderID) && !compactionOff)
|
|
10436
10557
|
captureInlineThinkingRepairs(args.messages, args.messageTagNumbers, args.sessionMeta?.clearedReasoningThroughTag ?? 0);
|
|
10437
10558
|
const servedShapeRepair = prepareServedShapeRepair(args.db, args.sessionId, args.messages, args.readLastServedMessages, compactionOff ? undefined : postprocessReplaySnapshot(args.db, args.sessionId));
|
|
@@ -10550,6 +10671,8 @@ async function runPostTransformPhase(args) {
|
|
|
10550
10671
|
const servedBeforeFirstRender = firstRenderBust ? args.readLastServedMessages?.() : null;
|
|
10551
10672
|
let foldExecutedThisPass = false;
|
|
10552
10673
|
let foldBustsServedPrefixThisPass = false;
|
|
10674
|
+
let foldChangesHeadThisPass = false;
|
|
10675
|
+
let recoveryExternalFoldCause = null;
|
|
10553
10676
|
let publishedM1RefreshedThisPass = false;
|
|
10554
10677
|
let prefixPreflightFailed = false;
|
|
10555
10678
|
const softRefreshOpportunity = !freezeM0M1 && (args.schedulerDecision === "execute" || deferredMaterialize || servedShapeRepair.needsRebuild);
|
|
@@ -10628,9 +10751,16 @@ async function runPostTransformPhase(args) {
|
|
|
10628
10751
|
prefixPreflightFailed = foldResult.materializationContentionRetryExhausted === true;
|
|
10629
10752
|
foldExecutedThisPass = foldExecutesThisPass(foldDueDecision.value || softRefreshOpportunity, foldResult.m0RematerializedThisPass);
|
|
10630
10753
|
foldBustsServedPrefixThisPass = foldExecutedThisPass && (committedFoldBustsServedPrefix ?? true);
|
|
10754
|
+
foldChangesHeadThisPass = foldExecutedThisPass && committedFoldChangesHead === true;
|
|
10631
10755
|
publishedM1RefreshedThisPass = !foldResult.materializationContentionRetryExhausted && previousM1 !== args.sessionMeta.cachedM1Bytes?.toString("utf8");
|
|
10632
10756
|
m0RematerializedThisPass = foldResult.m0RematerializedThisPass;
|
|
10633
10757
|
m0MaterializeReason = foldResult.decision.reason;
|
|
10758
|
+
if (!prefixPreflightFailed && foldExecutedThisPass) {
|
|
10759
|
+
const decision = foldResult.decision;
|
|
10760
|
+
if (decision.reason === "system_hash" && decision.systemHashPrev && decision.systemHashPrev !== "0" || decision.reason === "model_change" && decision.m0ModelKeyPrev || decision.reason === "tool_definitions") {
|
|
10761
|
+
recoveryExternalFoldCause = decision.reason;
|
|
10762
|
+
}
|
|
10763
|
+
}
|
|
10634
10764
|
if (foldResult.m0RematerializedThisPass && convertedToolSkeletons.size > 0) {
|
|
10635
10765
|
convertedToolSkeletonsDidMutate = renderConvertedToolSkeletons(args.targets, convertedToolSkeletons);
|
|
10636
10766
|
sessionLog2(args.sessionId, `HARD fold converted ${convertedToolSkeletons.size} legacy dropped-tool skeleton(s) to real-or-absent`);
|
|
@@ -10733,8 +10863,14 @@ async function runPostTransformPhase(args) {
|
|
|
10733
10863
|
newTargets = args.targets;
|
|
10734
10864
|
}
|
|
10735
10865
|
}
|
|
10866
|
+
const recoveryHasHistoryHead = m0M1EnabledForFold || (args.pendingCompartmentInjection?.compartmentCount ?? 0) > 0;
|
|
10867
|
+
const recoveryHeadChangedThisPass = !prefixPreflightFailed && (foldChangesHeadThisPass || !firstRenderBust && publishedM1RefreshedThisPass || !m0M1EnabledForFold && legacyPublishedHeadChanged(args));
|
|
10868
|
+
const recoveryHeadlessRebuild = !recoveryHasHistoryHead && (args.schedulerDecision === "execute" || isExplicitFlush || forceMaterialization || emergencyDropEligible);
|
|
10869
|
+
const recoveredShapeRewriteProof = recoveryHeadChangedThisPass ? "head_bytes" : recoveryExternalFoldCause ?? (recoveryHeadlessRebuild ? "headless_rebuild" : null);
|
|
10870
|
+
const canNormalizeRecoveredShape = isCacheBustingPass && !activeThinkingPrefixHold && recoveredShapeRewriteProof !== null;
|
|
10871
|
+
sessionLog2(args.sessionId, `rewrite permission: allowed=${isCacheBustingPass} ${reclaimRideLabel(rideSignals)} served_shape_repair=${servedShapeRepair.needsRebuild} signed_prefix_release=${rewritingSignedPrefix} fold_prefix_loss=${foldBustsServedPrefixThisPass} first_render=${firstRenderBust} idle_expiry=${idleExpiryRebuild} thinking_hold=${activeThinkingPrefixHold} recovery_has_head=${recoveryHasHistoryHead} recovery_head_changed=${recoveryHeadChangedThisPass} recovery_headless_rebuild=${recoveryHeadlessRebuild} proven_external_fold=${recoveryExternalFoldCause ?? "none"} recovered_shape_proof=${recoveredShapeRewriteProof ?? "none"}`);
|
|
10736
10872
|
let recoveryTailNormalizedThisPass = false;
|
|
10737
|
-
if (args.normalizeRecoveryTail &&
|
|
10873
|
+
if (args.normalizeRecoveryTail && canNormalizeRecoveredShape) {
|
|
10738
10874
|
args.normalizeRecoveryTail();
|
|
10739
10875
|
recoveryTailNormalizedThisPass = true;
|
|
10740
10876
|
args.tags = getTagsBySession2(args.db, args.sessionId);
|
|
@@ -11852,6 +11988,19 @@ async function runPostTransformPhase(args) {
|
|
|
11852
11988
|
if (reasoningRemovalEnabled)
|
|
11853
11989
|
removeReasoningParts(args.messages, removedReasoningIds, args.resolvedProviderID);
|
|
11854
11990
|
}
|
|
11991
|
+
const releaseRecoveryThisPass = canEditWholePrefix;
|
|
11992
|
+
if (releaseRecoveryThisPass)
|
|
11993
|
+
args.releaseRecoveryPrefix?.();
|
|
11994
|
+
sessionLog2(args.sessionId, `recovery projection: case=${canNormalizeRecoveredShape ? recoveredShapeRewriteProof : releaseRecoveryThisPass ? "conversation_only" : "defer"} released=${releaseRecoveryThisPass} normalized=${recoveryTailNormalizedThisPass}`);
|
|
11995
|
+
if (canUseEmptySentinels && args.opencode1) {
|
|
11996
|
+
projectStructuralSentinels({
|
|
11997
|
+
db: args.db,
|
|
11998
|
+
sessionId: args.sessionId,
|
|
11999
|
+
messages: args.messages,
|
|
12000
|
+
rebuilding: canNormalizeRecoveredShape && bustedThisPass,
|
|
12001
|
+
deferUpgrade: structuralSentinelUpgradeFailed
|
|
12002
|
+
});
|
|
12003
|
+
}
|
|
11855
12004
|
sessionLog2(args.sessionId, `final representation: clearedParts=${finalRepresentation.clearedParts} mergedReasoningParts=${finalRepresentation.mergedReasoningParts} removedReasoningParts=${removedReasoningParts} settledDroppedReasoning=${settledDroppedReasoning}`);
|
|
11856
12005
|
logTransformTiming(args.sessionId, "finalizeMessageRepresentation", tFinalRepresentation, `clearedParts=${finalRepresentation.clearedParts} mergedReasoningParts=${finalRepresentation.mergedReasoningParts}`);
|
|
11857
12006
|
const tTailBaseline = performance.now();
|
|
@@ -12715,6 +12864,44 @@ function createPassOutcome() {
|
|
|
12715
12864
|
};
|
|
12716
12865
|
}
|
|
12717
12866
|
|
|
12867
|
+
// src/hooks/magic-context/release-recovery-prefix.ts
|
|
12868
|
+
function groups(messages) {
|
|
12869
|
+
const result = new Map;
|
|
12870
|
+
for (const message of messages) {
|
|
12871
|
+
if (!message.info.id)
|
|
12872
|
+
continue;
|
|
12873
|
+
const group = result.get(message.info.id) ?? [];
|
|
12874
|
+
group.push(message);
|
|
12875
|
+
result.set(message.info.id, group);
|
|
12876
|
+
}
|
|
12877
|
+
return result;
|
|
12878
|
+
}
|
|
12879
|
+
function visibleGroup(group) {
|
|
12880
|
+
return JSON.stringify(group.map((message) => ({
|
|
12881
|
+
role: message.info.role,
|
|
12882
|
+
parts: message.parts.filter((part) => !isStructuralNoiseSentinel(part) && !(isRecord(part) && (part.type === "step-start" || part.type === "step-finish" || part.type === "meta"))).map(providerVisiblePart)
|
|
12883
|
+
})));
|
|
12884
|
+
}
|
|
12885
|
+
function snapshotRecoveryMessages(messages) {
|
|
12886
|
+
return new Map([...groups(messages)].map(([id, group]) => [id, visibleGroup(group)]));
|
|
12887
|
+
}
|
|
12888
|
+
function releaseRecoveryPrefix(args) {
|
|
12889
|
+
const frozen = groups(args.frozen);
|
|
12890
|
+
const rendered = groups(args.after);
|
|
12891
|
+
const emitted = new Set;
|
|
12892
|
+
return args.after.flatMap((message) => {
|
|
12893
|
+
const id = message.info.id;
|
|
12894
|
+
if (!id)
|
|
12895
|
+
return [message];
|
|
12896
|
+
if (emitted.has(id))
|
|
12897
|
+
return [];
|
|
12898
|
+
emitted.add(id);
|
|
12899
|
+
const group = rendered.get(id) ?? [message];
|
|
12900
|
+
const previous = frozen.get(id);
|
|
12901
|
+
return previous && args.before.get(id) === visibleGroup(group) ? previous : group;
|
|
12902
|
+
});
|
|
12903
|
+
}
|
|
12904
|
+
|
|
12718
12905
|
// src/hooks/magic-context/rust-mode-transform.ts
|
|
12719
12906
|
import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
|
|
12720
12907
|
|
|
@@ -15394,6 +15581,32 @@ function releaseRustServedRaw(db, sessionId, output, rebuiltIdentity) {
|
|
|
15394
15581
|
}
|
|
15395
15582
|
|
|
15396
15583
|
// src/hooks/magic-context/transform-context-state.ts
|
|
15584
|
+
var usageRefusals = new WeakMap;
|
|
15585
|
+
function recordUsageRefusal(db, sessionId, refusedAt = Date.now()) {
|
|
15586
|
+
let sessions = usageRefusals.get(db);
|
|
15587
|
+
if (!sessions) {
|
|
15588
|
+
sessions = new Map;
|
|
15589
|
+
usageRefusals.set(db, sessions);
|
|
15590
|
+
}
|
|
15591
|
+
if (!sessions.has(sessionId))
|
|
15592
|
+
sessions.set(sessionId, refusedAt);
|
|
15593
|
+
}
|
|
15594
|
+
function shouldResetRefusedUsage(db, sessionId, meta, liveReading) {
|
|
15595
|
+
const refusals = usageRefusals.get(db);
|
|
15596
|
+
const refusedAt = refusals?.get(sessionId);
|
|
15597
|
+
if (refusedAt === undefined)
|
|
15598
|
+
return false;
|
|
15599
|
+
const readingAt = liveReading?.hasUsageTokens ? liveReading.updatedAt : meta.lastResponseTime;
|
|
15600
|
+
if (readingAt > refusedAt) {
|
|
15601
|
+
refusals?.delete(sessionId);
|
|
15602
|
+
return false;
|
|
15603
|
+
}
|
|
15604
|
+
const now = Date.now();
|
|
15605
|
+
const foldedAt = meta.cachedM0MaterializedAt ?? 0;
|
|
15606
|
+
if (foldedAt > refusedAt && foldedAt <= now)
|
|
15607
|
+
return true;
|
|
15608
|
+
return !!db.prepare("SELECT 1 FROM compartments WHERE session_id = ? AND harness = ? AND created_at > ? AND created_at <= ? LIMIT 1").get(sessionId, getHarness2(), refusedAt, now);
|
|
15609
|
+
}
|
|
15397
15610
|
function loadPersistedUsageWatermark(db, sessionId) {
|
|
15398
15611
|
const result = db.prepare("SELECT last_response_time FROM session_meta WHERE session_id = ?").get(sessionId);
|
|
15399
15612
|
if (result === null || typeof result !== "object")
|
|
@@ -19335,6 +19548,7 @@ function createTransform(deps) {
|
|
|
19335
19548
|
return;
|
|
19336
19549
|
throw degradedPassError(site, error);
|
|
19337
19550
|
};
|
|
19551
|
+
const structuralSentinelUpgradeFailed = deps.storeGeneration === "v1" && !deps.compactionOff && deps.transformMode !== "rust" && prepareStructuralSentinelChoices({ db, sessionId, messages }).structuralSentinelUpgrade === undefined;
|
|
19338
19552
|
if (deps.storeGeneration !== undefined) {
|
|
19339
19553
|
try {
|
|
19340
19554
|
if (rustModeTransform && readCoordinateGeneration(db, sessionId) !== deps.storeGeneration) {
|
|
@@ -19556,10 +19770,13 @@ function createTransform(deps) {
|
|
|
19556
19770
|
loadedSessions.add(sessionId);
|
|
19557
19771
|
const earlyStateSnapshot = loadTransformPassStateSnapshot(db, sessionId);
|
|
19558
19772
|
const historianFailureState = earlyStateSnapshot.historianFailure;
|
|
19559
|
-
|
|
19773
|
+
const liveUsageBeforeReset = deps.contextUsageMap.get(sessionId);
|
|
19774
|
+
const usageResetAfterRefusal = shouldResetRefusedUsage(db, sessionId, sessionMeta, liveUsageBeforeReset);
|
|
19775
|
+
if ((isFirstTransformPassForSession || usageResetAfterRefusal) && sessionMeta) {
|
|
19560
19776
|
const persistedPct = sessionMeta.lastContextPercentage ?? 0;
|
|
19561
|
-
if (persistedPct > 0) {
|
|
19562
|
-
|
|
19777
|
+
if (persistedPct > 0 || usageResetAfterRefusal && (sessionMeta.lastInputTokens > 0 || deps.contextUsageMap.has(sessionId))) {
|
|
19778
|
+
const resetPct = persistedPct || liveUsageBeforeReset?.usage.percentage || 0;
|
|
19779
|
+
sessionLog2(sessionId, `transform: ${isFirstTransformPassForSession ? "first pass" : "refused turn recovery"} reset — percentage=${resetPct.toFixed(1)}% — clearing stale usage state`);
|
|
19563
19780
|
updateSessionMeta(db, sessionId, {
|
|
19564
19781
|
lastContextPercentage: 0,
|
|
19565
19782
|
lastInputTokens: 0
|
|
@@ -19968,10 +20185,15 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
19968
20185
|
let taggingSucceeded = false;
|
|
19969
20186
|
let recoveryBatch = null;
|
|
19970
20187
|
let recoveryNormalized = false;
|
|
20188
|
+
let recoveryReleased = false;
|
|
19971
20189
|
const untaggedReplayTailServed = !!recovery.prefix || untaggedReplayIds.size > 0 && messages.some((message) => untaggedReplayIds.has(message.info.id ?? ""));
|
|
20190
|
+
const releaseRecoveryReplay = untaggedReplayTailServed ? () => {
|
|
20191
|
+
recoveryReleased = true;
|
|
20192
|
+
} : undefined;
|
|
19972
20193
|
const normalizeRecoveryTail = untaggedReplayTailServed ? () => {
|
|
19973
20194
|
if (recoveryNormalized)
|
|
19974
20195
|
return;
|
|
20196
|
+
recoveryReleased = true;
|
|
19975
20197
|
const tail = messages.filter((message) => untaggedReplayIds.has(message.info.id ?? ""));
|
|
19976
20198
|
const tagged = tagMessages(sessionId, tail, deps.tagger, db, {
|
|
19977
20199
|
skipPrefixInjection: !ctxReduceCallable,
|
|
@@ -20047,6 +20269,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
20047
20269
|
const targetTagNumbers = [...targets.keys()];
|
|
20048
20270
|
const targetsSliceTags = compactionOff ? [] : getDroppedTagsByNumbers2(db, sessionId, targetTagNumbers);
|
|
20049
20271
|
logTransformTiming(sessionId, "getDroppedTagsByNumbers", t1b, `targets=${targetTagNumbers.length} fetched=${targetsSliceTags.length}`);
|
|
20272
|
+
const recoveryBeforePostprocess = recovery.prefix ? snapshotRecoveryMessages(messages) : undefined;
|
|
20050
20273
|
let didMutateFromFlushedStatuses = false;
|
|
20051
20274
|
if (taggingSucceeded) {
|
|
20052
20275
|
try {
|
|
@@ -20191,7 +20414,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
20191
20414
|
let contextUsageFromEstimate = hostOverWindow;
|
|
20192
20415
|
if (contextUsage.inputTokens <= 0 && protectionCacheBustingPass) {
|
|
20193
20416
|
const overflowRecoveryPass = usagePercentageSynthetic || emergencyRecoveryArmed;
|
|
20194
|
-
const savedProviderReading = overflowRecoveryPass ? null : savedProviderReadingForPass({
|
|
20417
|
+
const savedProviderReading = overflowRecoveryPass || usageResetAfterRefusal ? null : savedProviderReadingForPass({
|
|
20195
20418
|
persisted: persistedUsageBeforeResets,
|
|
20196
20419
|
currentModelKey: currentModelKeyForBoundary ?? (hardModelKey || undefined),
|
|
20197
20420
|
contextLimit: resolvedContextLimit,
|
|
@@ -20258,7 +20481,10 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
20258
20481
|
const tPostProcess = performance.now();
|
|
20259
20482
|
dropProjectionEmergency = contextUsage.percentage >= 95;
|
|
20260
20483
|
const postTransformResult = await runPostTransformPhase({
|
|
20484
|
+
opencode1: deps.storeGeneration === "v1",
|
|
20261
20485
|
opencode2: deps.storeGeneration === "v2",
|
|
20486
|
+
structuralSentinelUpgradeFailed,
|
|
20487
|
+
releaseRecoveryPrefix: releaseRecoveryReplay,
|
|
20262
20488
|
normalizeRecoveryTail,
|
|
20263
20489
|
compactionMarkerStrategy: deps.compactionMarkerStrategy ?? defaultCompactionMarkerStrategy,
|
|
20264
20490
|
sessionId,
|
|
@@ -20353,7 +20579,17 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
20353
20579
|
}
|
|
20354
20580
|
});
|
|
20355
20581
|
compactionModeTransitionPending.delete(sessionId);
|
|
20356
|
-
if (recovery.prefix && !recoveryNormalized) {
|
|
20582
|
+
if (recovery.prefix && recoveryReleased && !recoveryNormalized) {
|
|
20583
|
+
if (!recoveryBeforePostprocess)
|
|
20584
|
+
throw new Error("Cannot release recovery without its pre-edit snapshot");
|
|
20585
|
+
const released = releaseRecoveryPrefix({
|
|
20586
|
+
frozen: JSON.parse(recovery.prefix.json),
|
|
20587
|
+
before: recoveryBeforePostprocess,
|
|
20588
|
+
after: messages
|
|
20589
|
+
});
|
|
20590
|
+
messages.splice(0, messages.length, ...released);
|
|
20591
|
+
}
|
|
20592
|
+
if (recovery.prefix && !recoveryReleased) {
|
|
20357
20593
|
const renderedById = new Map;
|
|
20358
20594
|
for (const message of messages) {
|
|
20359
20595
|
if (!message.info.id)
|
|
@@ -20365,7 +20601,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
20365
20601
|
const suffix = recoveryTailSources.flatMap(({ identity, pristineSystem }) => pristineSystem ? [pristineSystem] : renderedById.get(identity) ?? []);
|
|
20366
20602
|
messages.splice(0, messages.length, ...JSON.parse(recovery.prefix.json), ...suffix);
|
|
20367
20603
|
}
|
|
20368
|
-
const recoveryReleaseReason = recovery.rebuildReason ?? (recoveryNormalized ? "recovery_tail_normalized" : undefined);
|
|
20604
|
+
const recoveryReleaseReason = recovery.rebuildReason ?? (recoveryNormalized ? "recovery_tail_normalized" : recoveryReleased ? "recovery_prefix_released" : undefined);
|
|
20369
20605
|
if (recoveryReleaseReason)
|
|
20370
20606
|
postTransformResult.bustedThisPass = true;
|
|
20371
20607
|
passOutcome.markFinalized();
|
|
@@ -20500,6 +20736,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
20500
20736
|
}
|
|
20501
20737
|
try {
|
|
20502
20738
|
await host.hostRefuse(deps.client, sessionId);
|
|
20739
|
+
recordUsageRefusal(db, sessionId);
|
|
20503
20740
|
} catch (error) {
|
|
20504
20741
|
sessionLog2(sessionId, "transform: emergency fail-closed abort failed; refusing to return a sendable prompt:", getErrorMessage(error));
|
|
20505
20742
|
throw new EmergencyFailClosedError("Emergency recovery abort failed", {
|
|
@@ -20747,7 +20984,16 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
20747
20984
|
});
|
|
20748
20985
|
deps.onPassPermission?.(sessionId, postTransformResult.prefixMutationPermitted);
|
|
20749
20986
|
};
|
|
20750
|
-
const timedTransform = (input, output) => withTransformTimingSummary(() =>
|
|
20987
|
+
const timedTransform = (input, output) => withTransformTimingSummary(async () => {
|
|
20988
|
+
const sessionId = findSessionId(output.messages);
|
|
20989
|
+
try {
|
|
20990
|
+
await transform(input, output);
|
|
20991
|
+
} catch (error) {
|
|
20992
|
+
if (sessionId && !deps.compactionOff && error instanceof EmergencyFailClosedError)
|
|
20993
|
+
recordUsageRefusal(deps.db, sessionId);
|
|
20994
|
+
throw error;
|
|
20995
|
+
}
|
|
20996
|
+
});
|
|
20751
20997
|
return Object.assign(timedTransform, {
|
|
20752
20998
|
clearSessionLogState,
|
|
20753
20999
|
invalidateRustWireState(sessionId) {
|
|
@@ -22433,6 +22679,78 @@ function computeOpenCodeWorkMetricsIncremental(openCodeDb, sessionId, carry, gen
|
|
|
22433
22679
|
return { carry, metrics: metricsFromCarry(view) };
|
|
22434
22680
|
}
|
|
22435
22681
|
|
|
22682
|
+
// src/features/magic-context/work-metrics-carry-storage.ts
|
|
22683
|
+
var STATE_KEY = "magicContextWorkMetrics";
|
|
22684
|
+
var storedCarry = object({
|
|
22685
|
+
version: literal(1),
|
|
22686
|
+
source: string(),
|
|
22687
|
+
newWorkSum: number(),
|
|
22688
|
+
lastTimeCreated: number(),
|
|
22689
|
+
lastId: string(),
|
|
22690
|
+
perAgent: array(tuple([
|
|
22691
|
+
string(),
|
|
22692
|
+
object({
|
|
22693
|
+
prevPrompt: number(),
|
|
22694
|
+
phaseId: number(),
|
|
22695
|
+
phasePeak: number(),
|
|
22696
|
+
phaseHasQualifying: boolean(),
|
|
22697
|
+
closedPhaseSum: number(),
|
|
22698
|
+
lastOutput: number(),
|
|
22699
|
+
seen: boolean()
|
|
22700
|
+
})
|
|
22701
|
+
]))
|
|
22702
|
+
});
|
|
22703
|
+
function readState2(db, sessionId) {
|
|
22704
|
+
const row = db.prepare("SELECT deferred_execute_state, new_work_tokens, total_input_tokens FROM session_meta WHERE session_id = ?").get(sessionId);
|
|
22705
|
+
let root = {};
|
|
22706
|
+
try {
|
|
22707
|
+
const value = JSON.parse(row?.deferred_execute_state ?? "null");
|
|
22708
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value))
|
|
22709
|
+
root = value;
|
|
22710
|
+
} catch {}
|
|
22711
|
+
return { root, newWorkTokens: row?.new_work_tokens, totalInputTokens: row?.total_input_tokens };
|
|
22712
|
+
}
|
|
22713
|
+
function matchesStoredState(state, source, carry, metrics) {
|
|
22714
|
+
const parsed = storedCarry.safeParse(state.root[STATE_KEY]);
|
|
22715
|
+
if (!parsed.success)
|
|
22716
|
+
return false;
|
|
22717
|
+
const previous = parsed.data;
|
|
22718
|
+
if (previous.source !== source || previous.newWorkSum !== carry.newWorkSum || previous.lastTimeCreated !== carry.lastTimeCreated || previous.lastId !== carry.lastId || previous.perAgent.length !== carry.perAgent.size || state.newWorkTokens !== metrics.newWorkTokens || state.totalInputTokens !== metrics.totalInputTokens)
|
|
22719
|
+
return false;
|
|
22720
|
+
return previous.perAgent.every(([key, agent]) => {
|
|
22721
|
+
const current = carry.perAgent.get(key);
|
|
22722
|
+
return current !== undefined && agent.prevPrompt === current.prevPrompt && agent.phaseId === current.phaseId && agent.phasePeak === current.phasePeak && agent.phaseHasQualifying === current.phaseHasQualifying && agent.closedPhaseSum === current.closedPhaseSum && agent.lastOutput === current.lastOutput && agent.seen === current.seen;
|
|
22723
|
+
});
|
|
22724
|
+
}
|
|
22725
|
+
function readSessionWorkMetricsCarry(db, sessionId, source) {
|
|
22726
|
+
const parsed = storedCarry.safeParse(readState2(db, sessionId).root[STATE_KEY]);
|
|
22727
|
+
if (!parsed.success || parsed.data.source !== source)
|
|
22728
|
+
return;
|
|
22729
|
+
return {
|
|
22730
|
+
perAgent: new Map(parsed.data.perAgent),
|
|
22731
|
+
newWorkSum: parsed.data.newWorkSum,
|
|
22732
|
+
lastTimeCreated: parsed.data.lastTimeCreated,
|
|
22733
|
+
lastId: parsed.data.lastId
|
|
22734
|
+
};
|
|
22735
|
+
}
|
|
22736
|
+
function setSessionWorkMetricsCarry(db, sessionId, source, carry, metrics) {
|
|
22737
|
+
const normalized = {
|
|
22738
|
+
newWorkTokens: Math.max(0, Math.floor(metrics.newWorkTokens)),
|
|
22739
|
+
totalInputTokens: Math.max(0, Math.floor(metrics.totalInputTokens))
|
|
22740
|
+
};
|
|
22741
|
+
if (matchesStoredState(readState2(db, sessionId), source, carry, normalized))
|
|
22742
|
+
return;
|
|
22743
|
+
db.transaction(() => {
|
|
22744
|
+
const state = readState2(db, sessionId);
|
|
22745
|
+
if (matchesStoredState(state, source, carry, normalized))
|
|
22746
|
+
return;
|
|
22747
|
+
ensureSessionMetaRow(db, sessionId);
|
|
22748
|
+
const { root } = state;
|
|
22749
|
+
root[STATE_KEY] = { ...carry, version: 1, source, perAgent: [...carry.perAgent] };
|
|
22750
|
+
db.prepare("UPDATE session_meta SET deferred_execute_state = ?, new_work_tokens = ?, total_input_tokens = ? WHERE session_id = ?").run(JSON.stringify(root), normalized.newWorkTokens, normalized.totalInputTokens, sessionId);
|
|
22751
|
+
}).immediate();
|
|
22752
|
+
}
|
|
22753
|
+
|
|
22436
22754
|
// src/plugin/embedding-bootstrap.ts
|
|
22437
22755
|
import { readFileSync, statSync } from "node:fs";
|
|
22438
22756
|
|
|
@@ -23060,7 +23378,6 @@ function pluginPackageVersion(moduleUrl = import.meta.url) {
|
|
|
23060
23378
|
}
|
|
23061
23379
|
|
|
23062
23380
|
// src/plugin/rpc-handlers.ts
|
|
23063
|
-
var workMetricsCarryBySession = new Map;
|
|
23064
23381
|
async function executeRustRecompRpc(moduleClient, sessionId, projectRoot) {
|
|
23065
23382
|
if (!moduleClient)
|
|
23066
23383
|
return { ok: false, error: "Rust module client is unavailable" };
|
|
@@ -23100,12 +23417,11 @@ function resolveSidebarWorkMetrics(db, sessionId, persistedNewWork, persistedTot
|
|
|
23100
23417
|
return { newWorkTokens: persistedNewWork, totalInputTokens: persistedTotalInput };
|
|
23101
23418
|
}
|
|
23102
23419
|
try {
|
|
23103
|
-
const
|
|
23104
|
-
const carry =
|
|
23420
|
+
const source = `${generation}:${resolveOpenCodeDbPath(generation).path}`;
|
|
23421
|
+
const carry = readSessionWorkMetricsCarry(db, sessionId, source) ?? emptyWorkMetricsCarry();
|
|
23105
23422
|
const { carry: nextCarry, metrics } = withReadOnlySessionDb((openCodeDb) => computeOpenCodeWorkMetricsIncremental(openCodeDb, sessionId, carry, generation), generation);
|
|
23106
|
-
workMetricsCarryBySession.set(carryKey, nextCarry);
|
|
23107
23423
|
try {
|
|
23108
|
-
|
|
23424
|
+
setSessionWorkMetricsCarry(db, sessionId, source, nextCarry, metrics);
|
|
23109
23425
|
} catch {}
|
|
23110
23426
|
return metrics;
|
|
23111
23427
|
} catch {
|
|
@@ -24004,8 +24320,8 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
24004
24320
|
const db = readDatabase();
|
|
24005
24321
|
if (!db)
|
|
24006
24322
|
return { ok: false, error: "db unavailable" };
|
|
24007
|
-
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-
|
|
24008
|
-
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-
|
|
24323
|
+
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-9cjk6aej.js"));
|
|
24324
|
+
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-kxp47tsw.js"));
|
|
24009
24325
|
log2(`[rpc] recomp requested for session ${sessionId}`);
|
|
24010
24326
|
if (!args.client && !args.hiddenCompletionExecutor) {
|
|
24011
24327
|
return {
|
|
@@ -24089,7 +24405,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
24089
24405
|
const db = readDatabase();
|
|
24090
24406
|
if (!db)
|
|
24091
24407
|
return { ok: false, error: "db unavailable" };
|
|
24092
|
-
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-
|
|
24408
|
+
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-j1v62bkj.js"));
|
|
24093
24409
|
const model = liveSessionState.liveModelBySession.get(sessionId);
|
|
24094
24410
|
const contextLimit = model ? resolveContextLimit(model.providerID, model.modelID, { db, sessionID: sessionId }) : 128000;
|
|
24095
24411
|
const ctx = {
|
|
@@ -25108,12 +25424,22 @@ function decodeThroughHostSchema(encoded) {
|
|
|
25108
25424
|
const assetSchema = mediaPart?.fields?.media;
|
|
25109
25425
|
const encoding = assetSchema?.ast?.encoding;
|
|
25110
25426
|
const decode = Array.isArray(encoding) ? encoding[0]?.transformation?.decode : undefined;
|
|
25111
|
-
const
|
|
25112
|
-
|
|
25113
|
-
|
|
25114
|
-
|
|
25115
|
-
|
|
25116
|
-
|
|
25427
|
+
const getter = decode;
|
|
25428
|
+
let asset;
|
|
25429
|
+
if (getter?._tag === "Transform") {
|
|
25430
|
+
if (typeof getter.transform !== "function")
|
|
25431
|
+
return "host media schema has no decode transformation";
|
|
25432
|
+
asset = getter.transform(encoded);
|
|
25433
|
+
} else {
|
|
25434
|
+
if (getter?._tag !== undefined)
|
|
25435
|
+
return `host media schema has unsupported decode transformation: ${String(getter._tag)}`;
|
|
25436
|
+
const run = getter?.run;
|
|
25437
|
+
if (typeof run !== "function")
|
|
25438
|
+
return "host media schema has no decode transformation";
|
|
25439
|
+
const result = run.call(decode, { _tag: "Some", value: encoded }, {});
|
|
25440
|
+
const option = result?._tag === "Success" ? result.value : undefined;
|
|
25441
|
+
asset = option?._tag === "Some" ? option.value : undefined;
|
|
25442
|
+
}
|
|
25117
25443
|
if (!isClassInstance(asset) || asset.source !== source)
|
|
25118
25444
|
return "host media schema decode did not return an asset";
|
|
25119
25445
|
return asset;
|
|
@@ -25158,6 +25484,7 @@ class HostFoldIdle {
|
|
|
25158
25484
|
now;
|
|
25159
25485
|
timers;
|
|
25160
25486
|
windows = new Map;
|
|
25487
|
+
attempted = new Map;
|
|
25161
25488
|
constructor(fold, now = Date.now, timers = { setTimeout, clearTimeout }) {
|
|
25162
25489
|
this.fold = fold;
|
|
25163
25490
|
this.now = now;
|
|
@@ -25179,6 +25506,9 @@ class HostFoldIdle {
|
|
|
25179
25506
|
}
|
|
25180
25507
|
if (!Number.isFinite(ttl) || lastResponseTime <= 0)
|
|
25181
25508
|
return;
|
|
25509
|
+
const attempted = this.attempted.get(sessionID);
|
|
25510
|
+
if (attempted?.cacheTtl === cacheTtl && attempted.lastResponseTime === lastResponseTime)
|
|
25511
|
+
return;
|
|
25182
25512
|
const window = { cacheTtl, lastResponseTime };
|
|
25183
25513
|
this.windows.set(sessionID, window);
|
|
25184
25514
|
const eligible = () => this.windows.get(sessionID) === window && computeHardCacheExpired(window.cacheTtl, window.lastResponseTime, this.now());
|
|
@@ -25187,6 +25517,7 @@ class HostFoldIdle {
|
|
|
25187
25517
|
return;
|
|
25188
25518
|
if (eligible()) {
|
|
25189
25519
|
window.timer = undefined;
|
|
25520
|
+
this.attempted.set(sessionID, { cacheTtl, lastResponseTime });
|
|
25190
25521
|
const release = () => {
|
|
25191
25522
|
if (this.windows.get(sessionID) === window)
|
|
25192
25523
|
this.windows.delete(sessionID);
|
|
@@ -25203,9 +25534,37 @@ class HostFoldIdle {
|
|
|
25203
25534
|
dispose() {
|
|
25204
25535
|
for (const sessionID of this.windows.keys())
|
|
25205
25536
|
this.active(sessionID);
|
|
25537
|
+
this.attempted.clear();
|
|
25206
25538
|
}
|
|
25207
25539
|
}
|
|
25208
25540
|
|
|
25541
|
+
// src/v2/fold/manual-baseline.ts
|
|
25542
|
+
function stageManualBaseline(db, sessionID, render) {
|
|
25543
|
+
const read = () => db.prepare("SELECT * FROM session_meta WHERE session_id = ?").get(sessionID);
|
|
25544
|
+
const before = read();
|
|
25545
|
+
const columns = Object.keys(before).filter((key) => key.startsWith("cached_m0_") || key.startsWith("cached_m1_") || key === "memory_block_count" || key === "memory_block_ids");
|
|
25546
|
+
const update = db.prepare(`UPDATE session_meta SET ${columns.map((key) => `${key} = ?`).join(", ")} WHERE session_id = ?`);
|
|
25547
|
+
const restore = (row) => update.run(...columns.map((key) => row[key] ?? null), sessionID);
|
|
25548
|
+
let summary;
|
|
25549
|
+
let staged;
|
|
25550
|
+
try {
|
|
25551
|
+
summary = render();
|
|
25552
|
+
staged = read();
|
|
25553
|
+
} finally {
|
|
25554
|
+
restore(before);
|
|
25555
|
+
}
|
|
25556
|
+
const commit = db.prepare(`UPDATE session_meta SET ${columns.map((key) => `${key} = ?`).join(", ")} WHERE session_id = ? AND ${columns.map((key) => `${key} IS ?`).join(" AND ")}`);
|
|
25557
|
+
return {
|
|
25558
|
+
summary,
|
|
25559
|
+
boundaryID: staged.cached_m0_last_baseline_end_message_id,
|
|
25560
|
+
commit() {
|
|
25561
|
+
const result = commit.run(...columns.map((key) => staged[key] ?? null), sessionID, ...columns.map((key) => before[key] ?? null));
|
|
25562
|
+
if (result.changes !== 1)
|
|
25563
|
+
throw new Error("Manual compaction baseline changed during admission");
|
|
25564
|
+
}
|
|
25565
|
+
};
|
|
25566
|
+
}
|
|
25567
|
+
|
|
25209
25568
|
// src/v2/fold/memory-cache.ts
|
|
25210
25569
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
25211
25570
|
|
|
@@ -25992,6 +26351,30 @@ function adaptPayload(draft, admittedIDs = new Set, messageTimes = new Map, hidd
|
|
|
25992
26351
|
};
|
|
25993
26352
|
}
|
|
25994
26353
|
|
|
26354
|
+
// src/v2/fold/code-mode-catalog.ts
|
|
26355
|
+
var changed = "The Code Mode tool catalog has changed.";
|
|
26356
|
+
var replacement = `${changed} This catalog supersedes the previous Code Mode tool catalog.`;
|
|
26357
|
+
function codeModeCatalogKind(data) {
|
|
26358
|
+
const text = data.text ?? "";
|
|
26359
|
+
const metadata = data.metadata;
|
|
26360
|
+
const keyed = typeof metadata === "object" && metadata !== null && "instructionSources" in metadata;
|
|
26361
|
+
if (keyed) {
|
|
26362
|
+
const sources = metadata.instructionSources;
|
|
26363
|
+
if (!Array.isArray(sources) || !sources.includes("core/codemode"))
|
|
26364
|
+
return;
|
|
26365
|
+
if (sources.length !== 1)
|
|
26366
|
+
return text.startsWith(replacement) ? "combined-replacement" : undefined;
|
|
26367
|
+
}
|
|
26368
|
+
if (text.startsWith(replacement))
|
|
26369
|
+
return "replacement";
|
|
26370
|
+
if (text.startsWith(changed))
|
|
26371
|
+
return "incremental";
|
|
26372
|
+
if (keyed || text.startsWith(`# Code Mode
|
|
26373
|
+
`) || text.startsWith("No Code Mode tools are currently available."))
|
|
26374
|
+
return "initial";
|
|
26375
|
+
return;
|
|
26376
|
+
}
|
|
26377
|
+
|
|
25995
26378
|
// src/v2/fold/native-codec.ts
|
|
25996
26379
|
class NativeReplayUnavailable extends Error {
|
|
25997
26380
|
}
|
|
@@ -26040,19 +26423,32 @@ var efforts = new Set(["none", "minimal", "low", "medium", "high", "xhigh", "max
|
|
|
26040
26423
|
|
|
26041
26424
|
class ControlMetadataUnavailable extends Error {
|
|
26042
26425
|
}
|
|
26043
|
-
var
|
|
26426
|
+
var object2 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
26044
26427
|
var keys = (value, allowed) => Object.keys(value).every((key) => allowed.includes(key));
|
|
26045
26428
|
var identity = (value) => typeof value === "string" && value.length > 0 && Buffer.byteLength(value) <= 1024;
|
|
26046
26429
|
var digest = (value) => typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
|
|
26047
26430
|
function validReplayState(value) {
|
|
26048
|
-
if (!
|
|
26431
|
+
if (!object2(value) || !keys(value, [
|
|
26432
|
+
"floor",
|
|
26433
|
+
"controls",
|
|
26434
|
+
"blocked",
|
|
26435
|
+
"upgrade",
|
|
26436
|
+
"withoutRecentContext",
|
|
26437
|
+
"retiredInstructionThrough",
|
|
26438
|
+
"retiredInstructionIDs"
|
|
26439
|
+
]))
|
|
26049
26440
|
return false;
|
|
26050
26441
|
const floor = value.floor;
|
|
26051
26442
|
const upgrade = value.upgrade;
|
|
26052
|
-
return
|
|
26443
|
+
return object2(floor) && keys(floor, ["kind", "id", "seq", "after", "digest"]) && ["start", "summary", "checkpoint", "host-checkpoint"].includes(floor.kind) && identity(floor.id) && typeof floor.seq === "number" && typeof floor.after === "number" && Number.isSafeInteger(floor.seq) && Number.isSafeInteger(floor.after) && floor.after === (floor.kind === "start" || floor.kind === "host-checkpoint" ? floor.seq - 1 : floor.seq) && digest(floor.digest) && validControls(value.controls) && (value.blocked === undefined || typeof value.blocked === "boolean") && (value.withoutRecentContext === undefined || typeof value.withoutRecentContext === "boolean") && (value.retiredInstructionThrough === undefined || Number.isSafeInteger(value.retiredInstructionThrough) && value.retiredInstructionThrough >= 0) && (value.retiredInstructionIDs === undefined || Array.isArray(value.retiredInstructionIDs) && value.retiredInstructionIDs.every(identity)) && (upgrade === undefined || object2(upgrade) && keys(upgrade, ["admissionID", "mode"]) && identity(upgrade.admissionID) && ["bounded", "host-checkpoint", "source-repair"].includes(upgrade.mode));
|
|
26444
|
+
}
|
|
26445
|
+
function instructionRetirement(replay) {
|
|
26446
|
+
const ids = new Set(replay?.retiredInstructionIDs);
|
|
26447
|
+
const through = replay?.retiredInstructionThrough ?? -1;
|
|
26448
|
+
return (row) => row.type === "system" && (row.seq <= through || ids.has(row.id));
|
|
26053
26449
|
}
|
|
26054
26450
|
function validAdmissionV3(value) {
|
|
26055
|
-
if (!
|
|
26451
|
+
if (!object2(value) || !keys(value, ["version", "proof", "replay"]) || value.version !== 3 || !object2(value.proof))
|
|
26056
26452
|
return false;
|
|
26057
26453
|
const proof = value.proof;
|
|
26058
26454
|
return keys(proof, [
|
|
@@ -26069,7 +26465,7 @@ function encodeAdmissionV3(value) {
|
|
|
26069
26465
|
return JSON.stringify(value);
|
|
26070
26466
|
}
|
|
26071
26467
|
function validCapturedReplayV3(value) {
|
|
26072
|
-
return
|
|
26468
|
+
return object2(value) && keys(value, ["version", "sessionID", "sourceDigest", "through", "replay"]) && value.version === 3 && identity(value.sessionID) && digest(value.sourceDigest) && Number.isSafeInteger(value.through) && validReplayState(value.replay);
|
|
26073
26469
|
}
|
|
26074
26470
|
function floorFor(row, kind) {
|
|
26075
26471
|
return {
|
|
@@ -26208,11 +26604,17 @@ function controlsThrough(controls, reader, sessionID, through) {
|
|
|
26208
26604
|
|
|
26209
26605
|
// src/v2/fold/native-replay.ts
|
|
26210
26606
|
var coordinates = new WeakMap;
|
|
26607
|
+
var sequences = new WeakMap;
|
|
26608
|
+
function nativeRowSequence(message) {
|
|
26609
|
+
return sequences.get(message);
|
|
26610
|
+
}
|
|
26211
26611
|
function nativeRowID(message) {
|
|
26212
26612
|
return coordinates.get(message) ?? message.id;
|
|
26213
26613
|
}
|
|
26214
|
-
function bindNativeRowID(message, id) {
|
|
26614
|
+
function bindNativeRowID(message, id, seq) {
|
|
26215
26615
|
coordinates.set(message, id);
|
|
26616
|
+
if (seq !== undefined)
|
|
26617
|
+
sequences.set(message, seq);
|
|
26216
26618
|
}
|
|
26217
26619
|
function copyNativeInput(messages) {
|
|
26218
26620
|
const copies = reviveNative(encodeNative(messages));
|
|
@@ -26221,6 +26623,9 @@ function copyNativeInput(messages) {
|
|
|
26221
26623
|
const id = original && nativeRowID(original);
|
|
26222
26624
|
if (id !== undefined)
|
|
26223
26625
|
coordinates.set(copy, id);
|
|
26626
|
+
const seq = original && sequences.get(original);
|
|
26627
|
+
if (seq !== undefined)
|
|
26628
|
+
sequences.set(copy, seq);
|
|
26224
26629
|
});
|
|
26225
26630
|
return copies;
|
|
26226
26631
|
}
|
|
@@ -26332,6 +26737,48 @@ class NativeFoldReplay {
|
|
|
26332
26737
|
async baseline(sessionID) {
|
|
26333
26738
|
return this.tail(sessionID)?.baseline;
|
|
26334
26739
|
}
|
|
26740
|
+
async retiredInstructionThrough(sessionID, reader) {
|
|
26741
|
+
if (!reader.latestCompaction(sessionID))
|
|
26742
|
+
return -1;
|
|
26743
|
+
return (await this.floorState(sessionID, reader))?.retiredInstructionThrough ?? -1;
|
|
26744
|
+
}
|
|
26745
|
+
async instructionRetirement(sessionID, reader) {
|
|
26746
|
+
if (!reader.latestCompaction(sessionID))
|
|
26747
|
+
return instructionRetirement();
|
|
26748
|
+
return instructionRetirement(await this.floorState(sessionID, reader));
|
|
26749
|
+
}
|
|
26750
|
+
async prepareManualFold(sessionID, reader, boundaryID, summary) {
|
|
26751
|
+
const running = reader.latestRunningCompaction(sessionID);
|
|
26752
|
+
if (!running || this.options.protocol !== 3)
|
|
26753
|
+
throw new NativeReplayUnavailable("Manual compaction has no running host checkpoint");
|
|
26754
|
+
const previous = await this.floorState(sessionID, reader);
|
|
26755
|
+
if (this.unprovenControls.has(sessionID) || previous?.blocked)
|
|
26756
|
+
throw new NativeReplayUnavailable("Manual compaction controls have not been captured");
|
|
26757
|
+
const seq = boundaryID ? reader.sequenceForId(sessionID, boundaryID) : undefined;
|
|
26758
|
+
const row = seq === undefined ? undefined : reader.range(sessionID, seq - 1, seq)[0];
|
|
26759
|
+
const first = reader.page(sessionID, { limit: 1 }).rows[0];
|
|
26760
|
+
let floor = row ? floorFor(row, "summary") : undefined;
|
|
26761
|
+
floor ??= first ? floorFor(first, "start") : undefined;
|
|
26762
|
+
if (!floor)
|
|
26763
|
+
throw new NativeReplayUnavailable("Manual compaction has no history boundary");
|
|
26764
|
+
const instructions = reader.instructionRowsThrough(sessionID, running.seq - 1);
|
|
26765
|
+
const retiredInstructionIDs = [];
|
|
26766
|
+
let newerFullCatalog = false;
|
|
26767
|
+
for (const instruction of [...instructions].reverse()) {
|
|
26768
|
+
const text = instruction.data.text ?? "";
|
|
26769
|
+
const catalog = codeModeCatalogKind(instruction.data);
|
|
26770
|
+
if (instruction.seq > floor.after && (catalog && catalog !== "combined-replacement" && newerFullCatalog || text.length > 0 && summary.includes(text)))
|
|
26771
|
+
retiredInstructionIDs.push(instruction.id);
|
|
26772
|
+
if (catalog === "replacement" || catalog === "combined-replacement")
|
|
26773
|
+
newerFullCatalog = true;
|
|
26774
|
+
}
|
|
26775
|
+
return {
|
|
26776
|
+
floor,
|
|
26777
|
+
controls: previous?.controls ?? [],
|
|
26778
|
+
...floor.after >= 0 ? { retiredInstructionThrough: floor.after } : {},
|
|
26779
|
+
retiredInstructionIDs
|
|
26780
|
+
};
|
|
26781
|
+
}
|
|
26335
26782
|
admissionKey(sessionID) {
|
|
26336
26783
|
return this.options.protocol === 3 ? `native-fold/v3/${encodeURIComponent(sessionID)}` : admissionKey(sessionID);
|
|
26337
26784
|
}
|
|
@@ -26551,7 +26998,7 @@ ${cached}
|
|
|
26551
26998
|
return pending.rows.filter((row) => row.seq > pending.value.replay.floor.after).flatMap((row) => {
|
|
26552
26999
|
const messages = this.rendered(structuredClone(row), model);
|
|
26553
27000
|
for (const message of messages)
|
|
26554
|
-
|
|
27001
|
+
bindNativeRowID(message, row.id, row.seq);
|
|
26555
27002
|
return messages;
|
|
26556
27003
|
});
|
|
26557
27004
|
}
|
|
@@ -26778,6 +27225,7 @@ ${cached}
|
|
|
26778
27225
|
if (!isLocalCheckpoint(cut) || cut.session_id !== sessionID)
|
|
26779
27226
|
return;
|
|
26780
27227
|
let after = -1;
|
|
27228
|
+
const retired = instructionRetirement(replayOverride ?? this.tail(sessionID)?.replay);
|
|
26781
27229
|
if (this.options.protocol === 3) {
|
|
26782
27230
|
const replay = replayOverride ?? this.tail(sessionID)?.replay;
|
|
26783
27231
|
if (!replay || !validFloor(reader, sessionID, replay.floor))
|
|
@@ -26792,7 +27240,7 @@ ${cached}
|
|
|
26792
27240
|
}
|
|
26793
27241
|
const through = cut.seq - 1;
|
|
26794
27242
|
const metadata = (this.metadataThrough.get(sessionID) ?? -1) >= through ? this.metadata.get(sessionID) : undefined;
|
|
26795
|
-
const required = (metadata ?? reader.rowStampsThrough(sessionID, through, this.options.protocol === 3 ? after : undefined)).filter(conversational).filter((row) => row.seq > after && row.seq <= through);
|
|
27243
|
+
const required = (metadata ?? reader.rowStampsThrough(sessionID, through, this.options.protocol === 3 ? after : undefined)).filter(conversational).filter((row) => !retired(row)).filter((row) => row.seq > after && row.seq <= through);
|
|
26796
27244
|
const tail = this.tail(sessionID);
|
|
26797
27245
|
let records;
|
|
26798
27246
|
if (!this.dirty.has(sessionID) && tail?.model === `${model.providerID}/${model.id}` && this.storage.containsRows(sessionID, required.map((row) => row.id))) {
|
|
@@ -26803,10 +27251,10 @@ ${cached}
|
|
|
26803
27251
|
if (required.some((row) => !restored.has(row.id)))
|
|
26804
27252
|
return;
|
|
26805
27253
|
}
|
|
26806
|
-
const projected = records.flatMap((row) => {
|
|
27254
|
+
const projected = records.filter((row) => !retired(row)).flatMap((row) => {
|
|
26807
27255
|
const messages = reviveNative(JSON.parse(row.data));
|
|
26808
27256
|
for (const message of messages)
|
|
26809
|
-
|
|
27257
|
+
bindNativeRowID(message, row.id, row.seq);
|
|
26810
27258
|
return messages;
|
|
26811
27259
|
});
|
|
26812
27260
|
return this.options.protocol === 3 ? insertControls(projected, controlsThrough((replayOverride ?? this.tail(sessionID)?.replay)?.controls ?? [], reader, sessionID, through), nativeRowID) : projected;
|
|
@@ -26888,7 +27336,7 @@ ${cached}
|
|
|
26888
27336
|
if (!row)
|
|
26889
27337
|
throw new NativeReplayUnavailable("Native carrier has no source row coordinate");
|
|
26890
27338
|
cursor = row.seq;
|
|
26891
|
-
|
|
27339
|
+
bindNativeRowID(message, row.id, row.seq);
|
|
26892
27340
|
if (message.role !== "tool")
|
|
26893
27341
|
owner = row.id;
|
|
26894
27342
|
const messages = grouped.get(row) ?? [];
|
|
@@ -26913,13 +27361,13 @@ ${cached}
|
|
|
26913
27361
|
replay = { ...replay, blocked: false };
|
|
26914
27362
|
const replayAfter = replay.floor.after;
|
|
26915
27363
|
const replayStart = replay.floor.kind === "start";
|
|
27364
|
+
const baseline = this.servedBaseline(draft);
|
|
26916
27365
|
captured = native.filter((message) => {
|
|
26917
27366
|
if (effortPart(message))
|
|
26918
27367
|
return false;
|
|
26919
27368
|
const id = nativeRowID(message);
|
|
26920
27369
|
if (HEAD_IDS.some((head) => head === id))
|
|
26921
27370
|
return false;
|
|
26922
|
-
const baseline = this.servedBaseline(draft);
|
|
26923
27371
|
if (!id)
|
|
26924
27372
|
return !(baseline && message.role === "user" && message.content.some((part) => part.type === "text" && part.text === baseline));
|
|
26925
27373
|
if (replayStart)
|
|
@@ -27033,21 +27481,23 @@ ${cached}
|
|
|
27033
27481
|
if (await this.admissions?.get(admissionKey(draft.sessionID)) && !await this.readV3(draft.sessionID))
|
|
27034
27482
|
return false;
|
|
27035
27483
|
const running = reader.latestRunningCompaction(draft.sessionID);
|
|
27036
|
-
const replay = await this.floorState(draft.sessionID, reader, undefined, undefined, true);
|
|
27484
|
+
const replay = args.manual?.replay ?? await this.floorState(draft.sessionID, reader, undefined, undefined, true);
|
|
27037
27485
|
if (!running || !replay || replay.blocked) {
|
|
27038
27486
|
this.report(draft.sessionID, "fold refused: no usable host checkpoint boundary");
|
|
27039
27487
|
return false;
|
|
27040
27488
|
}
|
|
27041
27489
|
const model = `${draft.model.providerID}/${draft.model.id}`;
|
|
27042
|
-
if (this.tail(draft.sessionID)?.model !== model)
|
|
27490
|
+
if (!args.manual && this.tail(draft.sessionID)?.model !== model)
|
|
27043
27491
|
this.storage.replaceRows(draft.sessionID, reader.latestSequence(draft.sessionID), []);
|
|
27044
|
-
|
|
27045
|
-
|
|
27046
|
-
|
|
27047
|
-
|
|
27048
|
-
|
|
27049
|
-
|
|
27050
|
-
|
|
27492
|
+
if (!args.manual)
|
|
27493
|
+
await this.retainReplay(draft.sessionID, replay, model, reader.latestSequence(draft.sessionID));
|
|
27494
|
+
if (!args.manual)
|
|
27495
|
+
await this.storage.supply(draft.sessionID, running.id, JSON.stringify({
|
|
27496
|
+
source: this.storage.sourceID,
|
|
27497
|
+
sessionID: draft.sessionID,
|
|
27498
|
+
admissionID: running.id,
|
|
27499
|
+
summary
|
|
27500
|
+
}));
|
|
27051
27501
|
const value = {
|
|
27052
27502
|
version: 3,
|
|
27053
27503
|
replay,
|
|
@@ -27060,6 +27510,57 @@ ${cached}
|
|
|
27060
27510
|
}
|
|
27061
27511
|
};
|
|
27062
27512
|
const payload = encodeAdmissionV3(value);
|
|
27513
|
+
if (args.manual) {
|
|
27514
|
+
const keys = [
|
|
27515
|
+
capturedReplayKey(draft.sessionID),
|
|
27516
|
+
this.admissionKey(draft.sessionID)
|
|
27517
|
+
];
|
|
27518
|
+
const old = await Promise.all(keys.map((key) => this.admissions?.get(key)));
|
|
27519
|
+
const capture = {
|
|
27520
|
+
version: 3,
|
|
27521
|
+
sessionID: draft.sessionID,
|
|
27522
|
+
sourceDigest: foldDigest(reader.hostIdentity()),
|
|
27523
|
+
through: reader.latestSequence(draft.sessionID),
|
|
27524
|
+
replay
|
|
27525
|
+
};
|
|
27526
|
+
const capturedPayload = JSON.stringify(capture);
|
|
27527
|
+
let written = 0;
|
|
27528
|
+
try {
|
|
27529
|
+
for (const [index, key] of keys.entries()) {
|
|
27530
|
+
const data = index === 0 ? capturedPayload : payload;
|
|
27531
|
+
await this.admissions?.set(key, {
|
|
27532
|
+
payload: data,
|
|
27533
|
+
digest: foldDigest(data)
|
|
27534
|
+
});
|
|
27535
|
+
written++;
|
|
27536
|
+
}
|
|
27537
|
+
args.manual.commit();
|
|
27538
|
+
} catch (error) {
|
|
27539
|
+
for (let index = written - 1;index >= 0; index--) {
|
|
27540
|
+
const key = keys[index];
|
|
27541
|
+
if (!key)
|
|
27542
|
+
continue;
|
|
27543
|
+
if (old[index] !== undefined)
|
|
27544
|
+
await this.admissions?.set(key, old[index]);
|
|
27545
|
+
else if (this.admissions?.remove)
|
|
27546
|
+
await this.admissions.remove(key);
|
|
27547
|
+
else
|
|
27548
|
+
await this.admissions?.set(key, null);
|
|
27549
|
+
}
|
|
27550
|
+
throw error;
|
|
27551
|
+
}
|
|
27552
|
+
this.invalidate(draft.sessionID);
|
|
27553
|
+
this.cancelLegacyUpgrade(draft.sessionID);
|
|
27554
|
+
this.cancelEditedAdmission(draft.sessionID);
|
|
27555
|
+
await this.retainReplay(draft.sessionID, replay, model, running.seq - 1);
|
|
27556
|
+
await this.storage.supply(draft.sessionID, running.id, JSON.stringify({
|
|
27557
|
+
source: this.storage.sourceID,
|
|
27558
|
+
sessionID: draft.sessionID,
|
|
27559
|
+
admissionID: running.id,
|
|
27560
|
+
summary
|
|
27561
|
+
}));
|
|
27562
|
+
return true;
|
|
27563
|
+
}
|
|
27063
27564
|
await this.admissions?.set(this.admissionKey(draft.sessionID), {
|
|
27064
27565
|
payload,
|
|
27065
27566
|
digest: foldDigest(payload)
|
|
@@ -27128,7 +27629,13 @@ ${cached}
|
|
|
27128
27629
|
this.report(sessionID, "replay refused: missing usable checkpoint boundary");
|
|
27129
27630
|
throw new NativeReplayUnavailable("Host checkpoint replay boundary is unavailable");
|
|
27130
27631
|
}
|
|
27131
|
-
options = {
|
|
27632
|
+
options = {
|
|
27633
|
+
...options,
|
|
27634
|
+
bounded: false,
|
|
27635
|
+
after: replay.floor.after,
|
|
27636
|
+
retiredInstructionThrough: replay.retiredInstructionThrough,
|
|
27637
|
+
retiredInstructionIDs: replay.retiredInstructionIDs
|
|
27638
|
+
};
|
|
27132
27639
|
}
|
|
27133
27640
|
const release = this.storage.hold(sessionID);
|
|
27134
27641
|
let result;
|
|
@@ -27194,10 +27701,13 @@ ${cached}
|
|
|
27194
27701
|
reader?.close();
|
|
27195
27702
|
}
|
|
27196
27703
|
const messages = [];
|
|
27704
|
+
const retired = instructionRetirement(options);
|
|
27197
27705
|
for (const row of this.storage.rows(sessionID, after, cut.seq - 1)) {
|
|
27706
|
+
if (retired(row))
|
|
27707
|
+
continue;
|
|
27198
27708
|
const revived = reviveNative(JSON.parse(row.data));
|
|
27199
27709
|
for (const message of revived)
|
|
27200
|
-
|
|
27710
|
+
bindNativeRowID(message, row.id, row.seq);
|
|
27201
27711
|
messages.push(...revived);
|
|
27202
27712
|
}
|
|
27203
27713
|
return messages;
|
|
@@ -27210,10 +27720,11 @@ ${cached}
|
|
|
27210
27720
|
this.report(sessionID, "replay refused: missing usable checkpoint boundary");
|
|
27211
27721
|
throw new NativeReplayUnavailable("Host checkpoint replay boundary is unavailable");
|
|
27212
27722
|
}
|
|
27213
|
-
const
|
|
27723
|
+
const retired = instructionRetirement(replay);
|
|
27724
|
+
const messages = reader.range(sessionID, replay?.floor.after ?? -1, cut.seq - 1).filter(conversational).filter((row) => !retired(row)).flatMap((row) => {
|
|
27214
27725
|
const messages = this.rendered(row, model);
|
|
27215
27726
|
for (const message of messages)
|
|
27216
|
-
|
|
27727
|
+
bindNativeRowID(message, row.id, row.seq);
|
|
27217
27728
|
return messages;
|
|
27218
27729
|
});
|
|
27219
27730
|
return replay ? insertControls(messages, controlsThrough(replay.controls, reader, sessionID, cut.seq - 1), nativeRowID) : messages;
|
|
@@ -27348,6 +27859,12 @@ class HostFoldPolicy {
|
|
|
27348
27859
|
}
|
|
27349
27860
|
}
|
|
27350
27861
|
|
|
27862
|
+
// src/v2/fold/summary.ts
|
|
27863
|
+
var RAW_HISTORY_ACCOUNT = "Magic Context retains the conversation as raw messages; no summarized history is available yet.";
|
|
27864
|
+
function hasFoldSummary(summary) {
|
|
27865
|
+
return typeof summary === "string" && summary.replace(/<[^>]*>/g, "").trim().length > 0;
|
|
27866
|
+
}
|
|
27867
|
+
|
|
27351
27868
|
// src/v2/fork-inheritance.ts
|
|
27352
27869
|
var RAW_TYPES = new Set(RAW_MESSAGE_TYPES2);
|
|
27353
27870
|
function forkBoundarySeq(origin, sequenceForId) {
|
|
@@ -28342,6 +28859,26 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
28342
28859
|
const budgetStopped = new Promise((_resolve, reject) => {
|
|
28343
28860
|
budgetReject = reject;
|
|
28344
28861
|
});
|
|
28862
|
+
const chargeBudgetRows = (rows) => {
|
|
28863
|
+
if (!budget)
|
|
28864
|
+
return;
|
|
28865
|
+
for (const row of rows) {
|
|
28866
|
+
if (row.seq <= usageSeq)
|
|
28867
|
+
continue;
|
|
28868
|
+
if (!row.data.finish)
|
|
28869
|
+
break;
|
|
28870
|
+
usageSeq = row.seq;
|
|
28871
|
+
const tokens = row.data.tokens;
|
|
28872
|
+
const decision = budget.charge(Math.max(0, tokens?.input ?? 0), Math.max(0, tokens?.cache?.read ?? 0), Math.max(0, tokens?.cache?.write ?? 0), row.data.finish === "stop" && !(row.data.content ?? []).some((part) => part.type === "tool-call"), false);
|
|
28873
|
+
const onBudgetUpdate = run.identity.metadata?.onBudgetUpdate;
|
|
28874
|
+
if (typeof onBudgetUpdate === "function")
|
|
28875
|
+
onBudgetUpdate({ ...budget.snapshot(), sessionId: run.child.id });
|
|
28876
|
+
if (decision !== "continue") {
|
|
28877
|
+
attempt.budgetExceeded = new DreamTokenBudgetExceeded(run.child.id, budget.snapshot().spent);
|
|
28878
|
+
return attempt.budgetExceeded;
|
|
28879
|
+
}
|
|
28880
|
+
}
|
|
28881
|
+
};
|
|
28345
28882
|
if (budget) {
|
|
28346
28883
|
budgetPoll = inRootAsyncContext2(() => setInterval(() => {
|
|
28347
28884
|
try {
|
|
@@ -28349,25 +28886,12 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
28349
28886
|
const latest = reader.latestAssistant(run.child.id);
|
|
28350
28887
|
return latest ? [latest] : [];
|
|
28351
28888
|
})());
|
|
28352
|
-
|
|
28353
|
-
|
|
28354
|
-
|
|
28355
|
-
|
|
28356
|
-
|
|
28357
|
-
|
|
28358
|
-
const onBudgetUpdate = run.identity.metadata?.onBudgetUpdate;
|
|
28359
|
-
if (typeof onBudgetUpdate === "function")
|
|
28360
|
-
onBudgetUpdate({
|
|
28361
|
-
...budget.snapshot(),
|
|
28362
|
-
sessionId: run.child.id
|
|
28363
|
-
});
|
|
28364
|
-
if (decision !== "continue") {
|
|
28365
|
-
if (budgetPoll)
|
|
28366
|
-
clearInterval(budgetPoll);
|
|
28367
|
-
attempt.budgetExceeded = new DreamTokenBudgetExceeded(run.child.id, budget.snapshot().spent);
|
|
28368
|
-
interruptAndRetire(run, "token-budget").finally(() => budgetReject(attempt.budgetExceeded));
|
|
28369
|
-
return;
|
|
28370
|
-
}
|
|
28889
|
+
const exceeded = chargeBudgetRows(fresh);
|
|
28890
|
+
if (exceeded) {
|
|
28891
|
+
if (budgetPoll)
|
|
28892
|
+
clearInterval(budgetPoll);
|
|
28893
|
+
interruptAndRetire(run, "token-budget").finally(() => budgetReject(exceeded));
|
|
28894
|
+
return;
|
|
28371
28895
|
}
|
|
28372
28896
|
} catch (error) {
|
|
28373
28897
|
if (budgetPoll)
|
|
@@ -28464,6 +28988,11 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
28464
28988
|
const tokens = row.data.tokens;
|
|
28465
28989
|
const tokenNumber = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
28466
28990
|
const steps = withReader(options.openReader, (reader) => reader.assistantSince?.(run.child.id, baseline) ?? [row]).filter((step) => step.seq > baseline && step.seq <= row.seq);
|
|
28991
|
+
const exceeded = chargeBudgetRows(steps);
|
|
28992
|
+
if (exceeded) {
|
|
28993
|
+
await interruptAndRetire(run, "token-budget");
|
|
28994
|
+
throw exceeded;
|
|
28995
|
+
}
|
|
28467
28996
|
const reportedUsage = steps.some((step) => tokenNumber(step.data.tokens?.input) !== undefined || tokenNumber(step.data.tokens?.output) !== undefined);
|
|
28468
28997
|
const usage = sumRowUsage(steps);
|
|
28469
28998
|
if (request.signal?.aborted || run.retired || Date.now() >= deadline) {
|
|
@@ -28683,6 +29212,100 @@ class V2MessageTimesCache {
|
|
|
28683
29212
|
|
|
28684
29213
|
// src/v2/hooks/channel2.ts
|
|
28685
29214
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
29215
|
+
|
|
29216
|
+
// src/v2/hooks/synthetic-admission.ts
|
|
29217
|
+
var memos = new WeakMap;
|
|
29218
|
+
var MAX_SESSIONS = 64;
|
|
29219
|
+
var MAX_IDS = 50000;
|
|
29220
|
+
function admissionSession(key) {
|
|
29221
|
+
if (!key.startsWith("synthetic/"))
|
|
29222
|
+
return;
|
|
29223
|
+
const end = key.indexOf("/", "synthetic/".length);
|
|
29224
|
+
return end < 0 ? undefined : key.slice("synthetic/".length, end);
|
|
29225
|
+
}
|
|
29226
|
+
function memoFor(storage) {
|
|
29227
|
+
const prior = memos.get(storage);
|
|
29228
|
+
if (prior)
|
|
29229
|
+
return prior;
|
|
29230
|
+
const sessions = new Map;
|
|
29231
|
+
const set = storage.set;
|
|
29232
|
+
const remove = storage.remove;
|
|
29233
|
+
const invalidate = (key) => {
|
|
29234
|
+
const sessionID = admissionSession(key);
|
|
29235
|
+
if (sessionID !== undefined) {
|
|
29236
|
+
sessions.delete(sessionID);
|
|
29237
|
+
const current = memos.get(storage);
|
|
29238
|
+
if (current) {
|
|
29239
|
+
current.sessions.delete(sessionID);
|
|
29240
|
+
current.revision++;
|
|
29241
|
+
}
|
|
29242
|
+
}
|
|
29243
|
+
};
|
|
29244
|
+
const wrappedSet = async (key, value) => {
|
|
29245
|
+
invalidate(key);
|
|
29246
|
+
try {
|
|
29247
|
+
await set.call(storage, key, value);
|
|
29248
|
+
} finally {
|
|
29249
|
+
invalidate(key);
|
|
29250
|
+
}
|
|
29251
|
+
};
|
|
29252
|
+
const wrappedRemove = remove && (async (key) => {
|
|
29253
|
+
invalidate(key);
|
|
29254
|
+
try {
|
|
29255
|
+
await remove.call(storage, key);
|
|
29256
|
+
} finally {
|
|
29257
|
+
invalidate(key);
|
|
29258
|
+
}
|
|
29259
|
+
});
|
|
29260
|
+
const memo = { sessions, revision: 0, set, remove, wrappedSet, wrappedRemove };
|
|
29261
|
+
storage.set = wrappedSet;
|
|
29262
|
+
if (wrappedRemove)
|
|
29263
|
+
storage.remove = wrappedRemove;
|
|
29264
|
+
memos.set(storage, memo);
|
|
29265
|
+
return memo;
|
|
29266
|
+
}
|
|
29267
|
+
function forgetSyntheticAdmission(storage, sessionID) {
|
|
29268
|
+
const memo = memoFor(storage);
|
|
29269
|
+
memo.sessions.delete(sessionID);
|
|
29270
|
+
memo.revision++;
|
|
29271
|
+
}
|
|
29272
|
+
function clearSyntheticAdmissions(storage) {
|
|
29273
|
+
const memo = memos.get(storage);
|
|
29274
|
+
if (!memo)
|
|
29275
|
+
return;
|
|
29276
|
+
memo.sessions.clear();
|
|
29277
|
+
if (storage.set === memo.wrappedSet)
|
|
29278
|
+
storage.set = memo.set;
|
|
29279
|
+
if (storage.remove === memo.wrappedRemove)
|
|
29280
|
+
storage.remove = memo.remove;
|
|
29281
|
+
memos.delete(storage);
|
|
29282
|
+
}
|
|
29283
|
+
async function admittedSynthetic(storage, sessionID, id) {
|
|
29284
|
+
for (;; ) {
|
|
29285
|
+
const memo = memoFor(storage);
|
|
29286
|
+
const session = memo.sessions.get(sessionID) ?? new Map;
|
|
29287
|
+
memo.sessions.delete(sessionID);
|
|
29288
|
+
memo.sessions.set(sessionID, session);
|
|
29289
|
+
if (memo.sessions.size > MAX_SESSIONS)
|
|
29290
|
+
memo.sessions.delete(memo.sessions.keys().next().value);
|
|
29291
|
+
const known = session.get(id);
|
|
29292
|
+
if (known !== undefined)
|
|
29293
|
+
return known;
|
|
29294
|
+
const revision = memo.revision;
|
|
29295
|
+
const record = await storage.get(`synthetic/${sessionID}/${id}`);
|
|
29296
|
+
if (memos.get(storage) !== memo || memo.revision !== revision)
|
|
29297
|
+
continue;
|
|
29298
|
+
const admitted = record !== null && typeof record === "object" && "id" in record && record.id === id;
|
|
29299
|
+
if (memo.sessions.get(sessionID) !== session)
|
|
29300
|
+
return admitted;
|
|
29301
|
+
if (session.size >= MAX_IDS)
|
|
29302
|
+
session.delete(session.keys().next().value);
|
|
29303
|
+
session.set(id, admitted);
|
|
29304
|
+
return admitted;
|
|
29305
|
+
}
|
|
29306
|
+
}
|
|
29307
|
+
|
|
29308
|
+
// src/v2/hooks/channel2.ts
|
|
28686
29309
|
var pendingCandidates = new WeakMap;
|
|
28687
29310
|
function syntheticCandidates(context, sessionID, stored) {
|
|
28688
29311
|
const pending = pendingCandidates.get(context.storage);
|
|
@@ -28698,9 +29321,17 @@ function syntheticCandidates(context, sessionID, stored) {
|
|
|
28698
29321
|
}
|
|
28699
29322
|
function clearSyntheticCandidates(context) {
|
|
28700
29323
|
pendingCandidates.delete(context.storage);
|
|
29324
|
+
clearSyntheticAdmissions(context.storage);
|
|
29325
|
+
}
|
|
29326
|
+
function observeSyntheticAdmissionEvent(context, event) {
|
|
29327
|
+
const sessionID = event.data?.sessionID;
|
|
29328
|
+
if (!sessionID || !(event.type === "session.deleted" || event.type?.startsWith("session.revert.")))
|
|
29329
|
+
return;
|
|
29330
|
+
forgetSyntheticAdmission(context.storage, sessionID);
|
|
28701
29331
|
}
|
|
28702
29332
|
async function deliverSynthetic(context, sessionID, text) {
|
|
28703
29333
|
const id = `msg_${randomBytes2(12).toString("hex")}`;
|
|
29334
|
+
forgetSyntheticAdmission(context.storage, sessionID);
|
|
28704
29335
|
await context.storage.set(`synthetic/${sessionID}/${id}`, { id });
|
|
28705
29336
|
let candidates = pendingCandidates.get(context.storage);
|
|
28706
29337
|
if (!candidates) {
|
|
@@ -28712,8 +29343,7 @@ async function deliverSynthetic(context, sessionID, text) {
|
|
|
28712
29343
|
return id;
|
|
28713
29344
|
}
|
|
28714
29345
|
async function isAdmittedSynthetic(context, sessionID, id) {
|
|
28715
|
-
|
|
28716
|
-
return record !== null && typeof record === "object" && "id" in record && record.id === id;
|
|
29346
|
+
return admittedSynthetic(context.storage, sessionID, id);
|
|
28717
29347
|
}
|
|
28718
29348
|
async function deliverPendingChannel2(context, db, sessionID, baseline) {
|
|
28719
29349
|
if (getChannel2NudgeState(db, sessionID) !== "pending")
|
|
@@ -28915,7 +29545,7 @@ class DeletedSessionTombstones {
|
|
|
28915
29545
|
}
|
|
28916
29546
|
|
|
28917
29547
|
// src/features/magic-context/dreamer/task-executor.ts
|
|
28918
|
-
import { createHash as
|
|
29548
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
28919
29549
|
import { existsSync as existsSync7, readFileSync as readFileSync8 } from "node:fs";
|
|
28920
29550
|
|
|
28921
29551
|
// src/features/magic-context/mural/compress-cues.ts
|
|
@@ -34658,7 +35288,7 @@ function insertDreamRun(db, run) {
|
|
|
34658
35288
|
}
|
|
34659
35289
|
|
|
34660
35290
|
// src/features/magic-context/dreamer/verify.ts
|
|
34661
|
-
import { createHash as
|
|
35291
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
34662
35292
|
|
|
34663
35293
|
// src/features/magic-context/dreamer/verify-diff.ts
|
|
34664
35294
|
import { execFile as execFile3 } from "node:child_process";
|
|
@@ -34779,7 +35409,56 @@ Read only these changed line ranges if they may affect the claim.`
|
|
|
34779
35409
|
}
|
|
34780
35410
|
|
|
34781
35411
|
// src/features/magic-context/dreamer/verify-gate.ts
|
|
35412
|
+
import path6 from "node:path";
|
|
35413
|
+
|
|
35414
|
+
// src/features/magic-context/dreamer/verify-state.ts
|
|
35415
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
35416
|
+
import { readFile, realpath as realpath2 } from "node:fs/promises";
|
|
34782
35417
|
import path5 from "node:path";
|
|
35418
|
+
function verificationMetadata(memory) {
|
|
35419
|
+
try {
|
|
35420
|
+
const parsed = JSON.parse(memory.metadataJson ?? "{}");
|
|
35421
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
|
|
35422
|
+
return parsed;
|
|
35423
|
+
} catch {}
|
|
35424
|
+
return {};
|
|
35425
|
+
}
|
|
35426
|
+
async function verificationFilesFingerprint(directory, files) {
|
|
35427
|
+
const root = await resolveGitTopLevel(directory) ?? path5.resolve(directory);
|
|
35428
|
+
const hash = createHash13("sha256");
|
|
35429
|
+
for (const file of [...new Set(files)].sort()) {
|
|
35430
|
+
const absolute = path5.resolve(root, file);
|
|
35431
|
+
const withinRoot = (candidate) => {
|
|
35432
|
+
const relative = path5.relative(root, candidate);
|
|
35433
|
+
return relative !== ".." && !relative.startsWith(`..${path5.sep}`) && !path5.isAbsolute(relative);
|
|
35434
|
+
};
|
|
35435
|
+
if (!withinRoot(absolute))
|
|
35436
|
+
return null;
|
|
35437
|
+
hash.update(JSON.stringify(file));
|
|
35438
|
+
try {
|
|
35439
|
+
if (!withinRoot(await realpath2(absolute)))
|
|
35440
|
+
return null;
|
|
35441
|
+
hash.update(createHash13("sha256").update(await readFile(absolute)).digest("hex"));
|
|
35442
|
+
} catch (error) {
|
|
35443
|
+
if (error.code !== "ENOENT")
|
|
35444
|
+
return null;
|
|
35445
|
+
hash.update("missing");
|
|
35446
|
+
}
|
|
35447
|
+
}
|
|
35448
|
+
return hash.digest("hex");
|
|
35449
|
+
}
|
|
35450
|
+
function recordVerificationVerdict(db, memory, verdict, at, fingerprint = null) {
|
|
35451
|
+
const metadata = verificationMetadata(memory);
|
|
35452
|
+
delete metadata.dreamerVerifySkip;
|
|
35453
|
+
if (verdict === "skip" && fingerprint) {
|
|
35454
|
+
metadata.dreamerVerifySkip = { contentHash: memory.normalizedHash, fingerprint, at };
|
|
35455
|
+
}
|
|
35456
|
+
metadata.dreamerVerifyVerdict = verdict;
|
|
35457
|
+
metadata.dreamerVerifyAttemptedAt = at;
|
|
35458
|
+
db.prepare("UPDATE memories SET metadata_json = ? WHERE id = ?").run(JSON.stringify(metadata), memory.id);
|
|
35459
|
+
}
|
|
35460
|
+
|
|
35461
|
+
// src/features/magic-context/dreamer/verify-gate.ts
|
|
34783
35462
|
function minOf(values) {
|
|
34784
35463
|
return values.reduce((acc, v) => v < acc ? v : acc, Number.POSITIVE_INFINITY);
|
|
34785
35464
|
}
|
|
@@ -34811,7 +35490,22 @@ async function partitionVerifyScope(args) {
|
|
|
34811
35490
|
const runStartedAt = args.now ?? Date.now();
|
|
34812
35491
|
const active = getMemoriesByProject2(args.db, args.projectIdentity);
|
|
34813
35492
|
const verById = getMemoryVerifications(args.db, active.map((m) => m.id));
|
|
34814
|
-
const candidates =
|
|
35493
|
+
const candidates = [];
|
|
35494
|
+
const unchangedSkippedIds = [];
|
|
35495
|
+
const changedSkippedIds = new Set;
|
|
35496
|
+
for (const memory of active) {
|
|
35497
|
+
const files = verById.get(memory.id)?.files ?? [];
|
|
35498
|
+
if (!files.length)
|
|
35499
|
+
continue;
|
|
35500
|
+
const skip = verificationMetadata(memory).dreamerVerifySkip;
|
|
35501
|
+
if (skip && skip.contentHash === memory.normalizedHash && typeof skip.fingerprint === "string" && skip.fingerprint === await verificationFilesFingerprint(args.projectDirectory, files)) {
|
|
35502
|
+
unchangedSkippedIds.push(memory.id);
|
|
35503
|
+
} else {
|
|
35504
|
+
candidates.push(memory);
|
|
35505
|
+
if (skip)
|
|
35506
|
+
changedSkippedIds.add(memory.id);
|
|
35507
|
+
}
|
|
35508
|
+
}
|
|
34815
35509
|
const toPrompt = (m) => {
|
|
34816
35510
|
const verifiedAt = verById.get(m.id)?.verifiedAt ?? 0;
|
|
34817
35511
|
let verifiedCommit = null;
|
|
@@ -34838,7 +35532,7 @@ async function partitionVerifyScope(args) {
|
|
|
34838
35532
|
leaseKey: args.leaseKey,
|
|
34839
35533
|
runStartedAt
|
|
34840
35534
|
});
|
|
34841
|
-
const broadCandidates = candidates.filter((m) => (verById.get(m.id)?.verifiedAt ?? 0) < broadCycleStartAt).sort((a, b) => {
|
|
35535
|
+
const broadCandidates = candidates.filter((m) => changedSkippedIds.has(m.id) || (verById.get(m.id)?.verifiedAt ?? 0) < broadCycleStartAt).sort((a, b) => {
|
|
34842
35536
|
const verifiedAtA = verById.get(a.id)?.verifiedAt ?? 0;
|
|
34843
35537
|
const verifiedAtB = verById.get(b.id)?.verifiedAt ?? 0;
|
|
34844
35538
|
return verifiedAtA - verifiedAtB || a.id - b.id;
|
|
@@ -34849,7 +35543,10 @@ async function partitionVerifyScope(args) {
|
|
|
34849
35543
|
mode: "broad",
|
|
34850
35544
|
inScope: broadCandidates.map(toPrompt),
|
|
34851
35545
|
inScopeIds: broadCandidates.map((m) => m.id),
|
|
34852
|
-
skippedIds:
|
|
35546
|
+
skippedIds: [
|
|
35547
|
+
...unchangedSkippedIds,
|
|
35548
|
+
...candidates.filter((m) => !broadIds.has(m.id)).map((m) => m.id)
|
|
35549
|
+
],
|
|
34853
35550
|
broadCycleStartAt,
|
|
34854
35551
|
reason: `broad cycle (${broadCandidates.length} remain; started ${broadCycleStartAt})`
|
|
34855
35552
|
};
|
|
@@ -34860,7 +35557,7 @@ async function partitionVerifyScope(args) {
|
|
|
34860
35557
|
mode: "incremental",
|
|
34861
35558
|
inScope: [],
|
|
34862
35559
|
inScopeIds: [],
|
|
34863
|
-
skippedIds:
|
|
35560
|
+
skippedIds: unchangedSkippedIds,
|
|
34864
35561
|
reason: "no file-mapped memories in scope"
|
|
34865
35562
|
};
|
|
34866
35563
|
}
|
|
@@ -34869,11 +35566,11 @@ async function partitionVerifyScope(args) {
|
|
|
34869
35566
|
mode,
|
|
34870
35567
|
inScope: candidates.map(toPrompt),
|
|
34871
35568
|
inScopeIds: candidates.map((m) => m.id),
|
|
34872
|
-
skippedIds:
|
|
35569
|
+
skippedIds: unchangedSkippedIds,
|
|
34873
35570
|
reason
|
|
34874
35571
|
});
|
|
34875
35572
|
const resolvedGitRoot = await resolveGitTopLevel(args.projectDirectory);
|
|
34876
|
-
const gitRoot = resolvedGitRoot ??
|
|
35573
|
+
const gitRoot = resolvedGitRoot ?? path6.resolve(args.projectDirectory);
|
|
34877
35574
|
const verifiedTimes = candidates.map((m) => verById.get(m.id)?.verifiedAt ?? 0).filter((t) => t > 0);
|
|
34878
35575
|
const sinceMs = verifiedTimes.length > 0 ? minOf(verifiedTimes) : runStartedAt;
|
|
34879
35576
|
const changeTimes = await readGitFileChangeTimesSince(args.projectDirectory, sinceMs, resolvedGitRoot ?? undefined);
|
|
@@ -34883,11 +35580,11 @@ async function partitionVerifyScope(args) {
|
|
|
34883
35580
|
const head = await readGitHead(args.projectDirectory);
|
|
34884
35581
|
const uncommitted = head ? await readGitChangedFilesSince(args.projectDirectory, head, resolvedGitRoot ?? undefined) ?? new Set : new Set;
|
|
34885
35582
|
const inScope = [];
|
|
34886
|
-
const skippedIds = [];
|
|
35583
|
+
const skippedIds = [...unchangedSkippedIds];
|
|
34887
35584
|
for (const m of candidates) {
|
|
34888
35585
|
const v = verById.get(m.id);
|
|
34889
35586
|
const verifiedAt = v?.verifiedAt ?? 0;
|
|
34890
|
-
if (verifiedAt === 0) {
|
|
35587
|
+
if (verifiedAt === 0 || changedSkippedIds.has(m.id)) {
|
|
34891
35588
|
inScope.push(toPrompt(m));
|
|
34892
35589
|
continue;
|
|
34893
35590
|
}
|
|
@@ -35257,6 +35954,7 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
35257
35954
|
let budgetFinalized = false;
|
|
35258
35955
|
let failedCompletion;
|
|
35259
35956
|
let headAtPrompt = null;
|
|
35957
|
+
const skipSnapshots = new Map;
|
|
35260
35958
|
const onBudgetUpdate = (state) => {
|
|
35261
35959
|
budgetFinalized ||= state.finalizeFired;
|
|
35262
35960
|
args.onBudgetUpdate?.({
|
|
@@ -35273,6 +35971,11 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
35273
35971
|
});
|
|
35274
35972
|
};
|
|
35275
35973
|
try {
|
|
35974
|
+
if (!args.moduleRoute) {
|
|
35975
|
+
for (const memory of batch) {
|
|
35976
|
+
skipSnapshots.set(memory.id, await raceWithSignal(verificationFilesFingerprint(args.sessionDirectory, memory.mappedFiles), batchSignal));
|
|
35977
|
+
}
|
|
35978
|
+
}
|
|
35276
35979
|
headAtPrompt = await raceWithSignal(readGitHead(args.sessionDirectory), batchSignal);
|
|
35277
35980
|
const evidence = !args.forceBroad && batch.every((m) => m.verifiedAt) ? await raceWithSignal(buildVerifyDiffEvidence(args.sessionDirectory, batch), batchSignal) : null;
|
|
35278
35981
|
const prompt = buildVerifyPrompt(args.projectIdentity, await raceWithSignal(seedVerifyCandidates(batch, args.sessionDirectory), batchSignal), evidence);
|
|
@@ -35314,7 +36017,7 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
35314
36017
|
tokens: run.completion.usage
|
|
35315
36018
|
});
|
|
35316
36019
|
reportUsage(run.completion.messages ?? [], run.childSessionId, run.completion.usage.input + (run.completion.usage.cacheRead ?? 0) + (run.completion.usage.cacheWrite ?? 0));
|
|
35317
|
-
return await applyParsedVerifyManifest(args, batch, run.validated, evidence?.head ?? headAtPrompt, budgetFinalized);
|
|
36020
|
+
return await applyParsedVerifyManifest(args, batch, run.validated, evidence?.head ?? headAtPrompt, budgetFinalized, skipSnapshots);
|
|
35318
36021
|
}
|
|
35319
36022
|
const client = args.client;
|
|
35320
36023
|
if (!client)
|
|
@@ -35374,7 +36077,7 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
35374
36077
|
promptSettled = true;
|
|
35375
36078
|
recordInvocation4(args, startedAt, { status: "completed", messages: run.output });
|
|
35376
36079
|
reportUsage(run.output, agentSessionId);
|
|
35377
|
-
return await applyParsedVerifyManifest(args, batch, run.validated, evidence?.head ?? headAtPrompt, budgetFinalized);
|
|
36080
|
+
return await applyParsedVerifyManifest(args, batch, run.validated, evidence?.head ?? headAtPrompt, budgetFinalized, skipSnapshots);
|
|
35378
36081
|
} catch (error) {
|
|
35379
36082
|
const desc = describeError(error);
|
|
35380
36083
|
const providerFailure = error instanceof DreamerProviderOutputFailureError ? error : undefined;
|
|
@@ -35394,7 +36097,7 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
35394
36097
|
if (interrupted) {
|
|
35395
36098
|
const text = verifyAssistantText(messages) ?? failedCompletion?.text ?? "";
|
|
35396
36099
|
const recovered = parsePartialVerifyManifest(text, new Set(batch.map((m) => m.id)));
|
|
35397
|
-
const counts = await applyParsedVerifyManifest(args, batch, recovered, headAtPrompt, true);
|
|
36100
|
+
const counts = await applyParsedVerifyManifest(args, batch, recovered, headAtPrompt, true, skipSnapshots);
|
|
35398
36101
|
return {
|
|
35399
36102
|
...counts,
|
|
35400
36103
|
timedOut: !(error instanceof DreamTokenBudgetExceeded),
|
|
@@ -35426,7 +36129,7 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
35426
36129
|
signal.removeEventListener("abort", abort);
|
|
35427
36130
|
}
|
|
35428
36131
|
}
|
|
35429
|
-
async function applyParsedVerifyManifest(args, batch, parsed, headAtPrompt, budgetFinalized = false) {
|
|
36132
|
+
async function applyParsedVerifyManifest(args, batch, parsed, headAtPrompt, budgetFinalized = false, skipSnapshots) {
|
|
35430
36133
|
const batchIds = new Set(batch.map((m) => m.id));
|
|
35431
36134
|
const batchById = new Map(batch.map((memory) => [memory.id, memory]));
|
|
35432
36135
|
const valid = {
|
|
@@ -35505,6 +36208,15 @@ async function applyParsedVerifyManifest(args, batch, parsed, headAtPrompt, budg
|
|
|
35505
36208
|
}
|
|
35506
36209
|
writes.push({ kind: "archive", id: a.id, reason: a.reason });
|
|
35507
36210
|
}
|
|
36211
|
+
if (!args.moduleRoute) {
|
|
36212
|
+
for (const entry of valid.skipped) {
|
|
36213
|
+
const original = batchById.get(entry.id);
|
|
36214
|
+
if (!original)
|
|
36215
|
+
continue;
|
|
36216
|
+
const fingerprint = skipSnapshots ? skipSnapshots.get(entry.id) ?? null : await verificationFilesFingerprint(args.sessionDirectory, original.mappedFiles);
|
|
36217
|
+
writes.push({ kind: "skip", id: entry.id, fingerprint });
|
|
36218
|
+
}
|
|
36219
|
+
}
|
|
35508
36220
|
let verified = 0;
|
|
35509
36221
|
let updated = 0;
|
|
35510
36222
|
let archived = 0;
|
|
@@ -35534,7 +36246,7 @@ async function applyParsedVerifyManifest(args, batch, parsed, headAtPrompt, budg
|
|
|
35534
36246
|
name: "memory.set_verification",
|
|
35535
36247
|
arguments: {
|
|
35536
36248
|
memory_project: args.projectIdentity,
|
|
35537
|
-
command_id: `${args.moduleRoute.moduleCommandId}:${
|
|
36249
|
+
command_id: `${args.moduleRoute.moduleCommandId}:${createHash14("sha256").update(rows.map((row) => row.memory_id).join(",")).digest("hex").slice(0, 16)}`,
|
|
35538
36250
|
rows
|
|
35539
36251
|
}
|
|
35540
36252
|
}
|
|
@@ -35566,9 +36278,17 @@ async function applyParsedVerifyManifest(args, batch, parsed, headAtPrompt, budg
|
|
|
35566
36278
|
continue;
|
|
35567
36279
|
if (w.kind === "verify") {
|
|
35568
36280
|
recordMemoryVerifications(args.db, w.id, w.files, now);
|
|
35569
|
-
|
|
35570
|
-
|
|
36281
|
+
updateMemoryVerification2(args.db, w.id, "verified");
|
|
36282
|
+
recordVerificationVerdict(args.db, memory, "verified", now);
|
|
36283
|
+
const verifiedMemory = getMemoryById2(args.db, w.id);
|
|
36284
|
+
if (verifiedHead && verifiedMemory)
|
|
36285
|
+
recordVerifiedCommit(args.db, verifiedMemory, now, verifiedHead);
|
|
35571
36286
|
verified += 1;
|
|
36287
|
+
} else if (w.kind === "skip") {
|
|
36288
|
+
if (memory.content !== batchById.get(w.id)?.content)
|
|
36289
|
+
continue;
|
|
36290
|
+
updateMemoryVerification2(args.db, w.id, "unverified");
|
|
36291
|
+
recordVerificationVerdict(args.db, memory, "skip", now, w.fingerprint);
|
|
35572
36292
|
} else if (w.kind === "update") {
|
|
35573
36293
|
const duplicate = getMemoryByHash2(args.db, memory.projectPath, memory.category, w.hash);
|
|
35574
36294
|
if (duplicate && duplicate.id !== memory.id) {
|
|
@@ -35577,6 +36297,8 @@ async function applyParsedVerifyManifest(args, batch, parsed, headAtPrompt, budg
|
|
|
35577
36297
|
continue;
|
|
35578
36298
|
}
|
|
35579
36299
|
rewriteMemoryContent(args.db, memory, w.content, w.hash);
|
|
36300
|
+
updateMemoryVerification2(args.db, w.id, "unverified");
|
|
36301
|
+
recordVerificationVerdict(args.db, memory, "update", now);
|
|
35580
36302
|
queueMemoryMutation(args.db, {
|
|
35581
36303
|
projectPath: args.projectIdentity,
|
|
35582
36304
|
mutationType: "update",
|
|
@@ -35587,6 +36309,8 @@ async function applyParsedVerifyManifest(args, batch, parsed, headAtPrompt, budg
|
|
|
35587
36309
|
updated += 1;
|
|
35588
36310
|
} else {
|
|
35589
36311
|
archiveMemory2(args.db, w.id, w.reason);
|
|
36312
|
+
updateMemoryVerification2(args.db, w.id, "stale");
|
|
36313
|
+
recordVerificationVerdict(args.db, memory, "archive", now);
|
|
35590
36314
|
queueMemoryMutation(args.db, {
|
|
35591
36315
|
projectPath: args.projectIdentity,
|
|
35592
36316
|
mutationType: "archive",
|
|
@@ -36380,7 +37104,7 @@ function parseFrictionGateVerdict(verdict) {
|
|
|
36380
37104
|
}
|
|
36381
37105
|
function computeRetrospectiveWindowKey(flagged) {
|
|
36382
37106
|
const anchors = flagged.map((message) => `${message.sessionId}:${message.ts}`).sort().join("|");
|
|
36383
|
-
return
|
|
37107
|
+
return createHash15("sha256").update(anchors).digest("hex").slice(0, 32);
|
|
36384
37108
|
}
|
|
36385
37109
|
function renderFrictionWindow(messages, flaggedOrdinals, radius = 2) {
|
|
36386
37110
|
const flagged = new Set(flaggedOrdinals);
|
|
@@ -38485,9 +39209,9 @@ function hiddenTerminalError(event) {
|
|
|
38485
39209
|
}
|
|
38486
39210
|
|
|
38487
39211
|
// src/v2/hooks/lkg-system.ts
|
|
38488
|
-
import { createHash as
|
|
39212
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
38489
39213
|
function identity2(slot) {
|
|
38490
|
-
return
|
|
39214
|
+
return createHash16("sha256").update(JSON.stringify({
|
|
38491
39215
|
capturedAt: slot.capturedAt,
|
|
38492
39216
|
captureSequence: slot.captureSequence,
|
|
38493
39217
|
rowVersion: slot.rowVersion,
|
|
@@ -38704,16 +39428,31 @@ async function interruptBeforeProvider(session, sessionID, timers = systemTimers
|
|
|
38704
39428
|
}
|
|
38705
39429
|
|
|
38706
39430
|
// src/v2/hooks/restore-rows.ts
|
|
39431
|
+
var DEFAULT_LIMITS = {
|
|
39432
|
+
maxSessions: 16,
|
|
39433
|
+
sessionRows: 40000,
|
|
39434
|
+
totalRows: 80000,
|
|
39435
|
+
sessionBytes: 192 * 1024 * 1024,
|
|
39436
|
+
totalBytes: 256 * 1024 * 1024
|
|
39437
|
+
};
|
|
39438
|
+
|
|
38707
39439
|
class RestoredRowCache {
|
|
38708
|
-
capacity;
|
|
38709
39440
|
sessions = new Map;
|
|
38710
|
-
|
|
38711
|
-
|
|
39441
|
+
limits;
|
|
39442
|
+
totalRows = 0;
|
|
39443
|
+
totalBytes = 0;
|
|
39444
|
+
constructor(limits = {}) {
|
|
39445
|
+
this.limits = {
|
|
39446
|
+
...DEFAULT_LIMITS,
|
|
39447
|
+
...typeof limits === "number" ? { maxSessions: limits } : limits
|
|
39448
|
+
};
|
|
38712
39449
|
}
|
|
38713
39450
|
rows(reader, sessionID, after, through) {
|
|
38714
|
-
if (through <= after)
|
|
39451
|
+
if (through <= after) {
|
|
39452
|
+
this.forget(sessionID);
|
|
38715
39453
|
return [];
|
|
38716
|
-
|
|
39454
|
+
}
|
|
39455
|
+
const kept = this.sessions.get(sessionID)?.rows ?? new Map;
|
|
38717
39456
|
const stamps = reader.spanRowStamps(sessionID, after, through);
|
|
38718
39457
|
const runs = [];
|
|
38719
39458
|
let previous = after;
|
|
@@ -38735,28 +39474,44 @@ class RestoredRowCache {
|
|
|
38735
39474
|
fresh.set(row.seq, row);
|
|
38736
39475
|
const next = new Map;
|
|
38737
39476
|
const rows = [];
|
|
39477
|
+
let bytes = 0;
|
|
38738
39478
|
for (const [seq, stamp] of stamps) {
|
|
38739
39479
|
const row = fresh.get(seq) ?? kept.get(seq)?.row;
|
|
38740
39480
|
if (!row)
|
|
38741
39481
|
continue;
|
|
38742
|
-
next.set(seq, { stamp, row });
|
|
38743
39482
|
rows.push(row);
|
|
39483
|
+
const rowBytes = Number(stamp.slice(stamp.lastIndexOf("\x00") + 1));
|
|
39484
|
+
if (!Number.isSafeInteger(rowBytes) || rowBytes < 0 || next.size >= Math.min(this.limits.sessionRows, this.limits.totalRows) || bytes + rowBytes > Math.min(this.limits.sessionBytes, this.limits.totalBytes))
|
|
39485
|
+
continue;
|
|
39486
|
+
next.set(seq, { stamp, row });
|
|
39487
|
+
bytes += rowBytes;
|
|
38744
39488
|
}
|
|
38745
|
-
this.
|
|
38746
|
-
|
|
38747
|
-
|
|
39489
|
+
this.forget(sessionID);
|
|
39490
|
+
if (next.size) {
|
|
39491
|
+
this.sessions.set(sessionID, { rows: next, bytes });
|
|
39492
|
+
this.totalRows += next.size;
|
|
39493
|
+
this.totalBytes += bytes;
|
|
39494
|
+
}
|
|
39495
|
+
while (this.sessions.size > this.limits.maxSessions || this.totalRows > this.limits.totalRows || this.totalBytes > this.limits.totalBytes) {
|
|
38748
39496
|
const oldest = this.sessions.keys().next().value;
|
|
38749
39497
|
if (oldest === undefined)
|
|
38750
39498
|
break;
|
|
38751
|
-
this.
|
|
39499
|
+
this.forget(oldest);
|
|
38752
39500
|
}
|
|
38753
39501
|
return structuredClone(rows);
|
|
38754
39502
|
}
|
|
38755
39503
|
forget(sessionID) {
|
|
39504
|
+
const prior = this.sessions.get(sessionID);
|
|
39505
|
+
if (prior) {
|
|
39506
|
+
this.totalRows -= prior.rows.size;
|
|
39507
|
+
this.totalBytes -= prior.bytes;
|
|
39508
|
+
}
|
|
38756
39509
|
this.sessions.delete(sessionID);
|
|
38757
39510
|
}
|
|
38758
39511
|
clear() {
|
|
38759
39512
|
this.sessions.clear();
|
|
39513
|
+
this.totalRows = 0;
|
|
39514
|
+
this.totalBytes = 0;
|
|
38760
39515
|
}
|
|
38761
39516
|
}
|
|
38762
39517
|
function readPages(reader, sessionID, after, through) {
|
|
@@ -40340,14 +41095,14 @@ function datetime(args) {
|
|
|
40340
41095
|
const timeRegex = `${time2}(?:${opts.join("|")})`;
|
|
40341
41096
|
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
|
40342
41097
|
}
|
|
40343
|
-
var
|
|
41098
|
+
var string2 = (params) => {
|
|
40344
41099
|
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
|
40345
41100
|
return new RegExp(`^${regex}$`);
|
|
40346
41101
|
};
|
|
40347
41102
|
var bigint = /^-?\d+n?$/;
|
|
40348
41103
|
var integer = /^-?\d+$/;
|
|
40349
|
-
var
|
|
40350
|
-
var
|
|
41104
|
+
var number2 = /^-?\d+(?:\.\d+)?/;
|
|
41105
|
+
var boolean2 = /^(?:true|false)$/i;
|
|
40351
41106
|
var _null = /^null$/i;
|
|
40352
41107
|
var _undefined = /^undefined$/i;
|
|
40353
41108
|
var lowercase = /^[^A-Z]*$/;
|
|
@@ -41073,7 +41828,7 @@ var $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
|
41073
41828
|
});
|
|
41074
41829
|
var $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
|
|
41075
41830
|
$ZodType.init(inst, def);
|
|
41076
|
-
inst._zod.pattern = [...inst?._zod.bag?.patterns ?? []].pop() ??
|
|
41831
|
+
inst._zod.pattern = [...inst?._zod.bag?.patterns ?? []].pop() ?? string2(inst._zod.bag);
|
|
41077
41832
|
inst._zod.parse = (payload, _) => {
|
|
41078
41833
|
if (def.coerce)
|
|
41079
41834
|
try {
|
|
@@ -41387,7 +42142,7 @@ var $ZodCustomStringFormat = /* @__PURE__ */ $constructor("$ZodCustomStringForma
|
|
|
41387
42142
|
});
|
|
41388
42143
|
var $ZodNumber = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
|
|
41389
42144
|
$ZodType.init(inst, def);
|
|
41390
|
-
inst._zod.pattern = inst._zod.bag.pattern ??
|
|
42145
|
+
inst._zod.pattern = inst._zod.bag.pattern ?? number2;
|
|
41391
42146
|
inst._zod.parse = (payload, _ctx) => {
|
|
41392
42147
|
if (def.coerce)
|
|
41393
42148
|
try {
|
|
@@ -41414,7 +42169,7 @@ var $ZodNumberFormat = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) =>
|
|
|
41414
42169
|
});
|
|
41415
42170
|
var $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
|
|
41416
42171
|
$ZodType.init(inst, def);
|
|
41417
|
-
inst._zod.pattern =
|
|
42172
|
+
inst._zod.pattern = boolean2;
|
|
41418
42173
|
inst._zod.parse = (payload, _ctx) => {
|
|
41419
42174
|
if (def.coerce)
|
|
41420
42175
|
try {
|
|
@@ -50069,7 +50824,7 @@ var ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
|
|
|
50069
50824
|
inst.nullable = () => nullable(inst);
|
|
50070
50825
|
inst.nullish = () => optional(nullable(inst));
|
|
50071
50826
|
inst.nonoptional = (params) => nonoptional(inst, params);
|
|
50072
|
-
inst.array = () =>
|
|
50827
|
+
inst.array = () => array2(inst);
|
|
50073
50828
|
inst.or = (arg) => union([inst, arg]);
|
|
50074
50829
|
inst.and = (arg) => intersection(inst, arg);
|
|
50075
50830
|
inst.transform = (tx) => pipe(inst, transform(tx));
|
|
@@ -50154,7 +50909,7 @@ var ZodString = /* @__PURE__ */ $constructor("ZodString", (inst, def) => {
|
|
|
50154
50909
|
inst.time = (params) => inst.check(time2(params));
|
|
50155
50910
|
inst.duration = (params) => inst.check(duration2(params));
|
|
50156
50911
|
});
|
|
50157
|
-
function
|
|
50912
|
+
function string3(params) {
|
|
50158
50913
|
return _string(ZodString, params);
|
|
50159
50914
|
}
|
|
50160
50915
|
var ZodStringFormat = /* @__PURE__ */ $constructor("ZodStringFormat", (inst, def) => {
|
|
@@ -50356,7 +51111,7 @@ var ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
|
|
|
50356
51111
|
inst.isFinite = true;
|
|
50357
51112
|
inst.format = bag.format ?? null;
|
|
50358
51113
|
});
|
|
50359
|
-
function
|
|
51114
|
+
function number3(params) {
|
|
50360
51115
|
return _number(ZodNumber, params);
|
|
50361
51116
|
}
|
|
50362
51117
|
var ZodNumberFormat = /* @__PURE__ */ $constructor("ZodNumberFormat", (inst, def) => {
|
|
@@ -50382,7 +51137,7 @@ var ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
|
|
|
50382
51137
|
$ZodBoolean.init(inst, def);
|
|
50383
51138
|
ZodType.init(inst, def);
|
|
50384
51139
|
});
|
|
50385
|
-
function
|
|
51140
|
+
function boolean3(params) {
|
|
50386
51141
|
return _boolean(ZodBoolean, params);
|
|
50387
51142
|
}
|
|
50388
51143
|
var ZodBigInt = /* @__PURE__ */ $constructor("ZodBigInt", (inst, def) => {
|
|
@@ -50490,7 +51245,7 @@ var ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
|
|
|
50490
51245
|
inst.length = (len, params) => inst.check(_length(len, params));
|
|
50491
51246
|
inst.unwrap = () => inst.element;
|
|
50492
51247
|
});
|
|
50493
|
-
function
|
|
51248
|
+
function array2(element, params) {
|
|
50494
51249
|
return _array(ZodArray, element, params);
|
|
50495
51250
|
}
|
|
50496
51251
|
function keyof(schema) {
|
|
@@ -50519,7 +51274,7 @@ var ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
|
|
|
50519
51274
|
inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
|
|
50520
51275
|
inst.required = (...args) => required(ZodNonOptional, inst, args[0]);
|
|
50521
51276
|
});
|
|
50522
|
-
function
|
|
51277
|
+
function object3(shape, params) {
|
|
50523
51278
|
const def = {
|
|
50524
51279
|
type: "object",
|
|
50525
51280
|
get shape() {
|
|
@@ -50595,7 +51350,7 @@ var ZodTuple = /* @__PURE__ */ $constructor("ZodTuple", (inst, def) => {
|
|
|
50595
51350
|
rest
|
|
50596
51351
|
});
|
|
50597
51352
|
});
|
|
50598
|
-
function
|
|
51353
|
+
function tuple2(items, _paramsOrRest, _params) {
|
|
50599
51354
|
const hasRest = _paramsOrRest instanceof $ZodType;
|
|
50600
51355
|
const params = hasRest ? _params : _paramsOrRest;
|
|
50601
51356
|
const rest = hasRest ? _paramsOrRest : null;
|
|
@@ -50724,7 +51479,7 @@ var ZodLiteral = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
|
|
|
50724
51479
|
}
|
|
50725
51480
|
});
|
|
50726
51481
|
});
|
|
50727
|
-
function
|
|
51482
|
+
function literal2(value, params) {
|
|
50728
51483
|
return new ZodLiteral({
|
|
50729
51484
|
type: "literal",
|
|
50730
51485
|
values: Array.isArray(value) ? value : [value],
|
|
@@ -50952,7 +51707,7 @@ var ZodFunction = /* @__PURE__ */ $constructor("ZodFunction", (inst, def) => {
|
|
|
50952
51707
|
function _function(params) {
|
|
50953
51708
|
return new ZodFunction({
|
|
50954
51709
|
type: "function",
|
|
50955
|
-
input: Array.isArray(params?.input) ?
|
|
51710
|
+
input: Array.isArray(params?.input) ? tuple2(params?.input) : params?.input ?? array2(unknown()),
|
|
50956
51711
|
output: params?.output ?? unknown()
|
|
50957
51712
|
});
|
|
50958
51713
|
}
|
|
@@ -50996,7 +51751,7 @@ var stringbool = (...args) => _stringbool({
|
|
|
50996
51751
|
}, ...args);
|
|
50997
51752
|
function json2(params) {
|
|
50998
51753
|
const jsonSchema = lazy(() => {
|
|
50999
|
-
return union([
|
|
51754
|
+
return union([string3(params), number3(), boolean3(), _null3(), array2(jsonSchema), record(string3(), jsonSchema)]);
|
|
51000
51755
|
});
|
|
51001
51756
|
return jsonSchema;
|
|
51002
51757
|
}
|
|
@@ -51028,13 +51783,13 @@ function getErrorMap() {
|
|
|
51028
51783
|
var ZodFirstPartyTypeKind;
|
|
51029
51784
|
(function(ZodFirstPartyTypeKind) {})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
51030
51785
|
// ../../node_modules/.bun/zod@4.1.8/node_modules/zod/v4/classic/coerce.js
|
|
51031
|
-
function
|
|
51786
|
+
function string4(params) {
|
|
51032
51787
|
return _coercedString(ZodString, params);
|
|
51033
51788
|
}
|
|
51034
|
-
function
|
|
51789
|
+
function number4(params) {
|
|
51035
51790
|
return _coercedNumber(ZodNumber, params);
|
|
51036
51791
|
}
|
|
51037
|
-
function
|
|
51792
|
+
function boolean4(params) {
|
|
51038
51793
|
return _coercedBoolean(ZodBoolean, params);
|
|
51039
51794
|
}
|
|
51040
51795
|
function bigint3(params) {
|
|
@@ -51967,7 +52722,7 @@ import { existsSync as existsSync9 } from "node:fs";
|
|
|
51967
52722
|
import { isAbsolute as isAbsolute2 } from "node:path";
|
|
51968
52723
|
|
|
51969
52724
|
// ../retina-local-fs/src/path-fence.ts
|
|
51970
|
-
import { lstat as lstat2, realpath as
|
|
52725
|
+
import { lstat as lstat2, realpath as realpath3 } from "node:fs/promises";
|
|
51971
52726
|
import { homedir as homedir4 } from "node:os";
|
|
51972
52727
|
import { basename, dirname as dirname2, isAbsolute, join as join11, relative, resolve as resolve2, sep } from "node:path";
|
|
51973
52728
|
|
|
@@ -51997,7 +52752,7 @@ async function resolveFenceRoots(options) {
|
|
|
51997
52752
|
const configuredHomePath = resolve2(options.homeDirectory ?? process.env.HOME ?? homedir4());
|
|
51998
52753
|
let home;
|
|
51999
52754
|
try {
|
|
52000
|
-
home = await
|
|
52755
|
+
home = await realpath3(configuredHomePath);
|
|
52001
52756
|
} catch (error) {
|
|
52002
52757
|
throw fsError(configuredHomePath, error);
|
|
52003
52758
|
}
|
|
@@ -52027,7 +52782,7 @@ function fenceCandidates(canonical, aliases) {
|
|
|
52027
52782
|
}
|
|
52028
52783
|
async function canonicalPath(path, allowMissing) {
|
|
52029
52784
|
try {
|
|
52030
|
-
return await
|
|
52785
|
+
return await realpath3(path);
|
|
52031
52786
|
} catch (error) {
|
|
52032
52787
|
if (!allowMissing || !isMissingError(error)) {
|
|
52033
52788
|
throw fsError(path, error);
|
|
@@ -52052,7 +52807,7 @@ async function canonicalPath(path, allowMissing) {
|
|
|
52052
52807
|
suffix.unshift(basename(candidate));
|
|
52053
52808
|
candidate = parent;
|
|
52054
52809
|
try {
|
|
52055
|
-
return join11(await
|
|
52810
|
+
return join11(await realpath3(candidate), ...suffix);
|
|
52056
52811
|
} catch (parentError) {
|
|
52057
52812
|
if (!isMissingError(parentError)) {
|
|
52058
52813
|
throw fsError(path, parentError);
|
|
@@ -52742,7 +53497,7 @@ function formatCtxReduceReply(stampedCount, selfStampCount = 0) {
|
|
|
52742
53497
|
return parts.join(" ");
|
|
52743
53498
|
}
|
|
52744
53499
|
// src/tools/ctx-reduce/tools.ts
|
|
52745
|
-
import { createHash as
|
|
53500
|
+
import { createHash as createHash17 } from "node:crypto";
|
|
52746
53501
|
|
|
52747
53502
|
// src/features/magic-context/range-parser.ts
|
|
52748
53503
|
function parseRangeString(input) {
|
|
@@ -52805,11 +53560,11 @@ function createCtxReduceTool(deps) {
|
|
|
52805
53560
|
const stableId = `oc-${sessionId}-${callId}`;
|
|
52806
53561
|
if (Buffer.byteLength(stableId) <= 128)
|
|
52807
53562
|
return stableId;
|
|
52808
|
-
return `oc-${
|
|
53563
|
+
return `oc-${createHash17("sha256").update(stableId).digest("hex")}`;
|
|
52809
53564
|
}
|
|
52810
53565
|
fallbackCommandSequence += 1;
|
|
52811
53566
|
const monotonicId = `oc-${sessionId}-${fallbackCommandSequence}`;
|
|
52812
|
-
return Buffer.byteLength(monotonicId) <= 128 ? monotonicId : `oc-${
|
|
53567
|
+
return Buffer.byteLength(monotonicId) <= 128 ? monotonicId : `oc-${createHash17("sha256").update(monotonicId).digest("hex")}`;
|
|
52813
53568
|
};
|
|
52814
53569
|
return tool({
|
|
52815
53570
|
description: CTX_REDUCE_DESCRIPTION,
|
|
@@ -53452,7 +54207,7 @@ function persistV2UsageReading(args) {
|
|
|
53452
54207
|
args.contextUsageMap.set(sessionID, {
|
|
53453
54208
|
usage: { inputTokens: reading.inputTokens, percentage },
|
|
53454
54209
|
hasUsageTokens: true,
|
|
53455
|
-
updatedAt: Date.now()
|
|
54210
|
+
updatedAt: reading.completed || Date.now()
|
|
53456
54211
|
});
|
|
53457
54212
|
} else {
|
|
53458
54213
|
args.contextUsageMap.delete(sessionID);
|
|
@@ -53500,7 +54255,7 @@ function bindKeptInstructionCoordinates(messages, incoming, reader, sessionID) {
|
|
|
53500
54255
|
selected.forEach((row, index) => {
|
|
53501
54256
|
const message = pending[index];
|
|
53502
54257
|
if (message)
|
|
53503
|
-
bindNativeRowID(message, row.id);
|
|
54258
|
+
bindNativeRowID(message, row.id, row.seq);
|
|
53504
54259
|
});
|
|
53505
54260
|
}
|
|
53506
54261
|
pending = [];
|
|
@@ -53794,10 +54549,10 @@ async function applyV2SystemPrompt(systemPrompt, draft) {
|
|
|
53794
54549
|
text
|
|
53795
54550
|
})));
|
|
53796
54551
|
}
|
|
53797
|
-
function coveredInstructionRows(reader, sessionID, throughSeq, model) {
|
|
54552
|
+
function coveredInstructionRows(reader, sessionID, throughSeq, model, retired = () => false) {
|
|
53798
54553
|
if (throughSeq < 0)
|
|
53799
54554
|
return [];
|
|
53800
|
-
return reader.instructionRowsThrough(sessionID, throughSeq).flatMap((row) => restoreRow(row, model)).map((message) => markCoveredInstructionRow(message));
|
|
54555
|
+
return reader.instructionRowsThrough(sessionID, throughSeq).filter((row) => !retired(row)).flatMap((row) => restoreRow(row, model)).map((message) => markCoveredInstructionRow(message));
|
|
53801
54556
|
}
|
|
53802
54557
|
async function registerContext(context) {
|
|
53803
54558
|
const directory = context.location.directory;
|
|
@@ -54276,7 +55031,15 @@ async function registerContext(context) {
|
|
|
54276
55031
|
storage: nativeFoldMemory,
|
|
54277
55032
|
openReader: openStoreReader,
|
|
54278
55033
|
canReplay: (sessionID, reader) => nativeFoldReplay.canReplay(sessionID, reader),
|
|
54279
|
-
canFold: (sessionID, reader) =>
|
|
55034
|
+
canFold: async (sessionID, reader) => {
|
|
55035
|
+
const meta = getOrCreateSessionMeta(storage.require(), sessionID);
|
|
55036
|
+
const summary = [
|
|
55037
|
+
servedModuleM0Text(sessionID),
|
|
55038
|
+
await nativeFoldReplay.baseline(sessionID),
|
|
55039
|
+
meta.cachedM0Bytes?.toString("utf8")
|
|
55040
|
+
].find((value) => value !== RAW_HISTORY_ACCOUNT && hasFoldSummary(value));
|
|
55041
|
+
return !meta.isSubagent && summary !== RAW_HISTORY_ACCOUNT && hasFoldSummary(summary) && nativeFoldReplay.canFold(sessionID, reader);
|
|
55042
|
+
},
|
|
54280
55043
|
threshold: Number(process.env.MC_OC2_HOST_FOLD_ROWS ?? 1000),
|
|
54281
55044
|
log: sessionLog2
|
|
54282
55045
|
}) : undefined;
|
|
@@ -54302,6 +55065,7 @@ async function registerContext(context) {
|
|
|
54302
55065
|
if (!event.data?.sessionID)
|
|
54303
55066
|
continue;
|
|
54304
55067
|
const sessionID = event.data.sessionID;
|
|
55068
|
+
observeSyntheticAdmissionEvent(context, event);
|
|
54305
55069
|
overflowRecovery.observeTerminal(event, (id, messageID) => {
|
|
54306
55070
|
const reader = openStoreReader();
|
|
54307
55071
|
try {
|
|
@@ -54483,22 +55247,46 @@ async function registerContext(context) {
|
|
|
54483
55247
|
await storage.probe();
|
|
54484
55248
|
const watermark = reader.latestSequenceForIds(draft.sessionID, draft.messages.flatMap((message) => message.id ? [message.id] : []));
|
|
54485
55249
|
const running = reader.latestRunningCompaction(draft.sessionID);
|
|
55250
|
+
const attempt = running && nativeFoldMemory?.admission(draft.sessionID, running.id);
|
|
55251
|
+
const manual = running?.data.reason === "manual" && !(attempt?.status === "pending" && attempt.owner_token);
|
|
54486
55252
|
const moduleBaseline = rustModeModuleClient ? servedModuleM0Text(draft.sessionID) : undefined;
|
|
54487
55253
|
const source = !rustModeModuleClient ? "typescript" : moduleBaseline === null ? "typescript_fallback" : "module";
|
|
54488
55254
|
if (nativeFoldReplay) {
|
|
54489
55255
|
try {
|
|
54490
55256
|
const state = getOrCreateSessionMeta(storage.require(), draft.sessionID);
|
|
54491
|
-
const
|
|
54492
|
-
|
|
55257
|
+
const staged = manual && moduleBaseline == null ? stageManualBaseline(storage.require(), draft.sessionID, () => materialize(draft)) : undefined;
|
|
55258
|
+
const publishedHistory = Boolean(storage.require().prepare("SELECT 1 FROM compartments WHERE session_id = ? LIMIT 1").get(draft.sessionID));
|
|
55259
|
+
const candidate = [
|
|
55260
|
+
moduleBaseline,
|
|
55261
|
+
await nativeFoldReplay.baseline(draft.sessionID),
|
|
55262
|
+
state.cachedM0Bytes?.toString("utf8"),
|
|
55263
|
+
(await folds.read(draft.sessionID))?.submitted
|
|
55264
|
+
].find((value) => value !== RAW_HISTORY_ACCOUNT && (publishedHistory && value?.includes("<session-history>") || hasFoldSummary(value)));
|
|
55265
|
+
const manualHistory = manual && hasFoldSummary(staged?.summary ?? moduleBaseline);
|
|
55266
|
+
const summary = manualHistory ? staged?.summary ?? candidate ?? RAW_HISTORY_ACCOUNT : candidate ?? RAW_HISTORY_ACCOUNT;
|
|
55267
|
+
const manualReplay = manualHistory && summary ? await nativeFoldReplay.prepareManualFold(draft.sessionID, reader, staged ? staged.boundaryID : storage.require().prepare("SELECT cached_m0_last_baseline_end_message_id AS id FROM session_meta WHERE session_id = ?").get(draft.sessionID).id, summary) : undefined;
|
|
55268
|
+
if ((hasFoldSummary(summary) || publishedHistory) && await nativeFoldReplay.supply({
|
|
54493
55269
|
draft,
|
|
54494
55270
|
reader,
|
|
54495
55271
|
previousCut: reader.latestCompaction(draft.sessionID),
|
|
54496
|
-
summary
|
|
55272
|
+
summary,
|
|
55273
|
+
manual: manualReplay ? { replay: manualReplay, commit: () => staged?.commit() } : undefined
|
|
54497
55274
|
})) {
|
|
55275
|
+
if (manualHistory) {
|
|
55276
|
+
dropSlot(draft.sessionID, "manual host compaction");
|
|
55277
|
+
generateReplay.forget(draft.sessionID);
|
|
55278
|
+
restoredRows.forget(draft.sessionID);
|
|
55279
|
+
historyRefreshSessions.add(draft.sessionID);
|
|
55280
|
+
requestPendingMaterialization(pendingMaterializationSessions, draft.sessionID, "host_compaction");
|
|
55281
|
+
}
|
|
54498
55282
|
draft.result = { summary, metadata: { keepID: undefined } };
|
|
54499
55283
|
return;
|
|
54500
55284
|
}
|
|
55285
|
+
if (manual)
|
|
55286
|
+
throw new V2ContextRefusal("Magic Context could not admit the manual fold.");
|
|
54501
55287
|
} catch (error) {
|
|
55288
|
+
if (error instanceof V2ContextRefusal || manual)
|
|
55289
|
+
throw error;
|
|
54502
55290
|
nativeFoldReplay.invalidate(draft.sessionID, true);
|
|
54503
55291
|
sessionLog2(draft.sessionID, `v2 host fold: legacy compaction reason=${JSON.stringify(String(error))}`);
|
|
54504
55292
|
}
|
|
@@ -54507,7 +55295,10 @@ async function registerContext(context) {
|
|
|
54507
55295
|
sessionID: draft.sessionID,
|
|
54508
55296
|
watermark,
|
|
54509
55297
|
runningCut: running?.seq,
|
|
54510
|
-
materialize: () =>
|
|
55298
|
+
materialize: () => {
|
|
55299
|
+
const summary = moduleBaseline ?? materialize(draft);
|
|
55300
|
+
return hasFoldSummary(summary) ? summary : RAW_HISTORY_ACCOUNT;
|
|
55301
|
+
}
|
|
54511
55302
|
});
|
|
54512
55303
|
sessionLog2(draft.sessionID, `v2 compaction hook: fired answered=true source=${source}`);
|
|
54513
55304
|
draft.result = { summary: fold.submitted, metadata: { keepID: undefined } };
|
|
@@ -54522,6 +55313,19 @@ async function registerContext(context) {
|
|
|
54522
55313
|
});
|
|
54523
55314
|
const temporalTimes = config.temporal_awareness === true;
|
|
54524
55315
|
const anchorTimesOnly = !temporalTimes && !rustModeModuleClient;
|
|
55316
|
+
const retireInstructionMessages = async (sessionID, reader, messages) => {
|
|
55317
|
+
const retired = await nativeFoldReplay?.instructionRetirement(sessionID, reader);
|
|
55318
|
+
if (!retired)
|
|
55319
|
+
return messages;
|
|
55320
|
+
return messages.filter((message) => {
|
|
55321
|
+
const id = nativeRowID(message);
|
|
55322
|
+
return message.role !== "system" || !id || !retired({
|
|
55323
|
+
type: "system",
|
|
55324
|
+
id,
|
|
55325
|
+
seq: nativeRowSequence(message) ?? reader.sequenceForId(sessionID, id) ?? Infinity
|
|
55326
|
+
});
|
|
55327
|
+
});
|
|
55328
|
+
};
|
|
54525
55329
|
const timeIds = (messages) => {
|
|
54526
55330
|
if (temporalTimes)
|
|
54527
55331
|
return messages.flatMap((message) => message.id ? [message.id] : []);
|
|
@@ -54543,16 +55347,17 @@ async function registerContext(context) {
|
|
|
54543
55347
|
const boundaryID = db.prepare("SELECT cached_m0_last_baseline_end_message_id AS id FROM session_meta WHERE session_id = ?").get(draft.sessionID)?.id ?? (boundaryRepair?.kind === "repaired" || boundaryRepair?.kind === "baseline-reset" ? boundaryRepair.anchorEndMessageId : null);
|
|
54544
55348
|
const servedBoundary = boundaryID ? servedBoundaryRow2(reader, draft.sessionID, boundaryID) : null;
|
|
54545
55349
|
const nativeFloor = await nativeFoldReplay?.restorationFloor(draft.sessionID, cut, reader);
|
|
55350
|
+
const retiredInstructions = await nativeFoldReplay?.instructionRetirement(draft.sessionID, reader) ?? (() => false);
|
|
54546
55351
|
const boundary = Math.max(nativeFloor ?? -Infinity, (nativeFoldReplay?.sourceChanged(draft.sessionID) && !rustModeModuleClient ? (reader.earliestSequence(draft.sessionID) ?? 0) - 1 : undefined) ?? (moduleBoundarySeq !== undefined ? moduleBoundarySeq - 1 : undefined) ?? servedBoundary?.seq ?? reader.sequenceForId(draft.sessionID, boundaryID) ?? (reader.earliestSequence(draft.sessionID) ?? 0) - 1);
|
|
54547
55352
|
if (moduleBoundarySeq !== undefined)
|
|
54548
55353
|
sessionLog2(draft.sessionID, `v2 restore: from the module boundary ${moduleBoundaryID} to the host checkpoint`);
|
|
54549
55354
|
const present = new Set(args.messages.map((message) => message.id));
|
|
54550
|
-
const restored = restoredRows.rows(reader, draft.sessionID, boundary, cut.seq).filter((row) => !present.has(row.id)).flatMap((row) => restoreRow(row, draft.model, hostUsesMediaAssets() ? {
|
|
55355
|
+
const restored = restoredRows.rows(reader, draft.sessionID, boundary, cut.seq).filter((row) => !retiredInstructions(row)).filter((row) => !present.has(row.id)).flatMap((row) => restoreRow(row, draft.model, hostUsesMediaAssets() ? {
|
|
54551
55356
|
asset: hostMediaAsset,
|
|
54552
55357
|
unavailable: (detail) => sessionLog2(draft.sessionID, `v2 restore: attachment replaced by a note row=${detail.rowID} name=${JSON.stringify(detail.name ?? null)} mediaType=${detail.mediaType} reason=${JSON.stringify(detail.reason)}`)
|
|
54553
55358
|
} : undefined));
|
|
54554
55359
|
return [
|
|
54555
|
-
...rustModeModuleClient ? [] : coveredInstructionRows(reader, draft.sessionID, Math.min(boundary, cut.seq), draft.model),
|
|
55360
|
+
...rustModeModuleClient ? [] : coveredInstructionRows(reader, draft.sessionID, Math.min(boundary, cut.seq), draft.model, retiredInstructions),
|
|
54556
55361
|
...restored,
|
|
54557
55362
|
...args.messages.filter((message) => message !== args.incoming)
|
|
54558
55363
|
];
|
|
@@ -54785,6 +55590,7 @@ async function registerContext(context) {
|
|
|
54785
55590
|
}
|
|
54786
55591
|
} else if (localCut)
|
|
54787
55592
|
return;
|
|
55593
|
+
messages = await retireInstructionMessages(draft.sessionID, reader, messages);
|
|
54788
55594
|
times = readTimes(reader, messages);
|
|
54789
55595
|
}
|
|
54790
55596
|
} finally {
|
|
@@ -55014,6 +55820,7 @@ async function registerContext(context) {
|
|
|
55014
55820
|
boundaryRepair
|
|
55015
55821
|
}));
|
|
55016
55822
|
}
|
|
55823
|
+
draft.messages = await retireInstructionMessages(draft.sessionID, reader, draft.messages);
|
|
55017
55824
|
messageTimes = readTimes(reader, draft.messages);
|
|
55018
55825
|
} finally {
|
|
55019
55826
|
reader.close();
|
|
@@ -55194,6 +56001,11 @@ async function registerContext(context) {
|
|
|
55194
56001
|
if (!deletedSessions.has(draft.sessionID) && admissionRebuildPasses.has(draft.sessionID)) {
|
|
55195
56002
|
await nativeFoldReplay?.commitLegacyUpgrade(draft.sessionID, true);
|
|
55196
56003
|
await nativeFoldReplay?.commitEditedAdmission(draft.sessionID);
|
|
56004
|
+
if (db && hostFoldIdle) {
|
|
56005
|
+
const meta = getOrCreateSessionMeta(db, draft.sessionID);
|
|
56006
|
+
if (computeHardCacheExpired(meta.cacheTtl, meta.lastResponseTime, Date.now()))
|
|
56007
|
+
hostFoldIdle.idle(draft.sessionID, meta.cacheTtl, meta.lastResponseTime);
|
|
56008
|
+
}
|
|
55197
56009
|
}
|
|
55198
56010
|
} finally {
|
|
55199
56011
|
admissionRebuildPasses.delete(draft.sessionID);
|