@cortexkit/opencode-magic-context 0.49.11 → 0.49.13
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/agents/smart-notes-dreamer-gate.fixture.d.ts +28 -0
- package/dist/agents/smart-notes-dreamer-gate.fixture.d.ts.map +1 -0
- package/dist/{announcement-hdbkt8v5.js → announcement-g789dmt6.js} +2 -2
- package/dist/auto-search-worker.js +4 -4
- package/dist/chunk-embedding-write-worker.js +89 -0
- package/dist/{compaction-marker-candidates-xxz35vwp.js → compaction-marker-candidates-v5c6997n.js} +3 -3
- package/dist/compaction-marker-candidates-worker.js +1 -1
- package/dist/config/agent-disable.d.ts +14 -0
- package/dist/config/agent-disable.d.ts.map +1 -1
- package/dist/config/dependency-notes.d.ts +34 -0
- package/dist/config/dependency-notes.d.ts.map +1 -0
- package/dist/config/schema/agent-overrides.d.ts +12 -12
- package/dist/config/schema/magic-context.d.ts +88 -88
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-xwkfncav.js → conflict-warning-hook-mgq17yr3.js} +8 -8
- package/dist/{context-twz3s0cg.js → context-azqk0vfd.js} +121 -145
- package/dist/{derive-budgets-3nbxsyss.js → derive-budgets-zn7yzd2d.js} +3 -3
- package/dist/embedding-backfill-5e1t5wha.js +22 -0
- package/dist/embedding-worker-process.js +2 -2
- package/dist/embedding-worker.js +6 -6
- package/dist/features/magic-context/chunk-embedding-write-worker.d.ts +2 -0
- package/dist/features/magic-context/chunk-embedding-write-worker.d.ts.map +1 -0
- package/dist/features/magic-context/chunk-embedding-writer.d.ts +48 -0
- package/dist/features/magic-context/chunk-embedding-writer.d.ts.map +1 -0
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts +1 -1
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/hidden-single-shot.d.ts +3 -2
- package/dist/features/magic-context/dreamer/hidden-single-shot.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/map-memories.d.ts +8 -1
- package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts +2 -0
- package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts +5 -0
- package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-config.d.ts +22 -4
- package/dist/features/magic-context/dreamer/task-config.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-registry.d.ts +22 -0
- package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts +4 -1
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify-prompt.d.ts +6 -1
- package/dist/features/magic-context/dreamer/verify-prompt.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify.d.ts +25 -11
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-openai.d.ts +32 -0
- package/dist/features/magic-context/memory/embedding-openai.d.ts.map +1 -1
- package/dist/features/magic-context/memory/project-identity.d.ts +1 -0
- package/dist/features/magic-context/memory/project-identity.d.ts.map +1 -1
- package/dist/features/magic-context/memory/unborn-head.d.ts +34 -0
- package/dist/features/magic-context/memory/unborn-head.d.ts.map +1 -0
- package/dist/features/magic-context/mural/compress-cues.d.ts +3 -0
- package/dist/features/magic-context/mural/compress-cues.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts +5 -0
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tags.d.ts +2 -0
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/{history-owner-ty29fz0f.js → history-owner-xp3pngv7.js} +3 -3
- package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-embed-session.d.ts +10 -0
- package/dist/hooks/magic-context/auto-embed-session.d.ts.map +1 -0
- package/dist/hooks/magic-context/compartment-prompt.d.ts +6 -0
- package/dist/hooks/magic-context/compartment-prompt.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts +3 -0
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger-error.d.ts +12 -0
- package/dist/hooks/magic-context/compartment-trigger-error.d.ts.map +1 -0
- package/dist/hooks/magic-context/embed-session-state.d.ts +8 -1
- package/dist/hooks/magic-context/embed-session-state.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-prompt-fit.d.ts +2 -0
- package/dist/hooks/magic-context/historian-prompt-fit.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +3 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/pending-materialization.d.ts +2 -0
- package/dist/hooks/magic-context/pending-materialization.d.ts.map +1 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts +12 -0
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- package/dist/hooks/magic-context/raw-exact-ordinal-read.d.ts +58 -0
- package/dist/hooks/magic-context/raw-exact-ordinal-read.d.ts.map +1 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts +7 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-raw.d.ts +19 -0
- package/dist/hooks/magic-context/read-session-raw.d.ts.map +1 -1
- package/dist/hooks/magic-context/recomp-orchestrator.d.ts +2 -0
- package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +2 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +4 -0
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/wrapup-orchestrator.d.ts.map +1 -1
- package/dist/{index-bzp9s8z2.js → index-1d289pq2.js} +2 -2
- package/dist/{index-w28y7d0z.js → index-1sarmj9z.js} +15 -15
- package/dist/{index-z7avx6rw.js → index-2jr1smmh.js} +280 -160
- package/dist/{index-4ccdr7yw.js → index-3kdm78zp.js} +5 -5
- package/dist/{index-9159kk15.js → index-3kx0kg0f.js} +64 -7
- package/dist/{index-0jz47061.js → index-a8bvhwqs.js} +190 -30
- package/dist/{index-84j7jq8a.js → index-aw1bh90w.js} +10 -10
- package/dist/{index-qr1mkc2y.js → index-b16gpywn.js} +9 -9
- package/dist/{index-g7jkrz0x.js → index-bp5083x2.js} +1 -1
- package/dist/{index-yhrrx7qa.js → index-bxdg2nbt.js} +3 -3
- package/dist/{index-0abg88h2.js → index-dgs16axy.js} +4 -4
- package/dist/{index-mp2kghkv.js → index-dyvbsvga.js} +1 -1
- package/dist/{index-bmwfzz28.js → index-e20m7284.js} +4 -4
- package/dist/{index-4jkhhpn1.js → index-e4dsjj1p.js} +3 -3
- package/dist/{index-s178h9z8.js → index-f71thw8j.js} +1 -1
- package/dist/{index-kvw6xew3.js → index-fkx2qnvw.js} +2 -2
- package/dist/{index-f8cn4xqa.js → index-fwefky9w.js} +18 -5
- package/dist/{index-0sahzkwr.js → index-g2q4htwp.js} +46 -2
- package/dist/{index-mw7c950g.js → index-gp3kcpc4.js} +1 -1
- package/dist/{index-g40wgxxt.js → index-hnm8raee.js} +4 -4
- package/dist/{index-gjvjh960.js → index-hqkczed7.js} +1 -1
- package/dist/{index-mvvephtj.js → index-j75v2476.js} +1 -1
- package/dist/{index-150zz6fh.js → index-k29z4aqh.js} +1 -1
- package/dist/{index-b64n4d0h.js → index-kee4kn5j.js} +1 -1
- package/dist/index-ksdyrrav.js +52 -0
- package/dist/{index-angx1s0k.js → index-mmfa86mt.js} +16 -6
- package/dist/{index-9jvab89d.js → index-n6m03s3n.js} +2 -2
- package/dist/{index-q28hsbpg.js → index-nj7yykkx.js} +1 -1
- package/dist/{index-ghc9f0n7.js → index-p5y3k4g7.js} +29 -1
- package/dist/{index-xztdf9t7.js → index-qkd9zz0p.js} +17 -17
- package/dist/index-saews2s3.js +229 -0
- package/dist/{index-kkvxnbt8.js → index-sj89f3b0.js} +62 -33
- package/dist/{index-jw4gbfkv.js → index-v10f1rjv.js} +5 -5
- package/dist/{index-0j6crjgh.js → index-v13skev1.js} +13 -13
- package/dist/{index-hqnggmxn.js → index-wj6ht7nm.js} +547 -179
- package/dist/{index-a865mj02.js → index-wk0n1cgt.js} +4 -4
- package/dist/{index-q3qck7j2.js → index-wz6mzzb1.js} +6 -5
- package/dist/{index-se1w3v2m.js → index-y1qysm3q.js} +332 -256
- package/dist/{index-a4b0gbyg.js → index-y9f76s3f.js} +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +119 -129
- package/dist/{logger-wn328tfg.js → logger-jm3sqqzr.js} +2 -2
- package/dist/{message-index-bounded-0rbbg9rd.js → message-index-bounded-vm64mqpq.js} +16 -16
- package/dist/{message-index-ct5x2kwa.js → message-index-seaqpb7c.js} +16 -16
- package/dist/{message-time-backfill-nb5hhnrt.js → message-time-backfill-qjge9044.js} +3 -3
- package/dist/migration-worker.js +11 -11
- package/dist/plugin/dream-timer.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/tool-registry.d.ts.map +1 -1
- package/dist/{project-embedding-registry-ft9gh2e2.js → project-embedding-registry-x45bv3qr.js} +12 -11
- package/dist/raw-ordinal-warmup-worker.js +12 -7
- package/dist/{read-session-chunk-y3hhsbzw.js → read-session-chunk-ax05f7gr.js} +11 -11
- package/dist/{read-session-raw-gm6xj30v.js → read-session-raw-m56hc7v2.js} +7 -3
- package/dist/recomp-orchestrator-dmbeadwt.js +61 -0
- package/dist/{safe-notification-target-jdynm677.js → safe-notification-target-1szv1k5k.js} +3 -3
- package/dist/{search-jd8xh721.js → search-5yd5ytzs.js} +25 -24
- package/dist/{send-session-notification-vzhj8bsg.js → send-session-notification-24r4esbh.js} +6 -6
- package/dist/shared/data-path.d.ts +4 -0
- package/dist/shared/data-path.d.ts.map +1 -1
- package/dist/shared/model-suggestion-retry.d.ts +2 -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/{storage-tags-35m4gms2.js → storage-tags-yygfb9c8.js} +7 -5
- package/dist/{task-config-cgpg0nvh.js → task-config-x3qmayd2.js} +6 -2
- package/dist/tools/ctx-note/tools.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-pmqxfq4q.js → transform-postprocess-phase-72v86syx.js} +32 -31
- package/dist/v2/auto-search-worker.js +4 -4
- package/dist/v2/chunk-embedding-write-worker.js +88 -0
- package/dist/v2/{compaction-marker-candidates-a15w3mqh.js → compaction-marker-candidates-1vqwr3s5.js} +2 -2
- package/dist/v2/compaction-marker-candidates-worker.js +1 -1
- package/dist/v2/{context-p1zfcw41.js → context-w055w17c.js} +628 -255
- package/dist/v2/{derive-budgets-0rmpmxjw.js → derive-budgets-2zh4gm2c.js} +3 -3
- package/dist/v2/embedding-backfill-jmaf8zrr.js +21 -0
- package/dist/v2/embedding-worker-process.js +1 -1
- package/dist/v2/embedding-worker.js +5 -5
- package/dist/v2/{history-owner-2cr9py37.js → history-owner-42e16w0n.js} +2 -2
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/dream-manual.d.ts.map +1 -1
- package/dist/v2/hooks/dream-trigger.d.ts +1 -1
- package/dist/v2/hooks/dream-trigger.d.ts.map +1 -1
- package/dist/v2/hooks/hidden-child.d.ts.map +1 -1
- package/dist/v2/hooks/transform-features.d.ts +3 -2
- package/dist/v2/hooks/transform-features.d.ts.map +1 -1
- package/dist/v2/{logger-te6e1j72.js → logger-7qt02bnb.js} +1 -1
- package/dist/v2/{message-index-bounded-7wcbp975.js → message-index-bounded-wepg5723.js} +15 -15
- package/dist/v2/{message-index-cjhv92m2.js → message-index-gcmd0ng0.js} +15 -15
- package/dist/v2/{message-time-backfill-rz1pnpaj.js → message-time-backfill-bsteyc4d.js} +2 -2
- package/dist/v2/migration-worker.js +10 -10
- package/dist/v2/{project-embedding-registry-g34gcf74.js → project-embedding-registry-0msp56p8.js} +11 -10
- package/dist/v2/raw-ordinal-warmup-worker.js +12 -7
- package/dist/v2/{read-session-chunk-8d3v87vr.js → read-session-chunk-hr3w5bjk.js} +10 -10
- package/dist/v2/{read-session-raw-h4azh85b.js → read-session-raw-b3tf6ra1.js} +6 -2
- package/dist/v2/recomp-orchestrator-ca7qt75a.js +60 -0
- package/dist/v2/retrospective-raw-provider.d.ts.map +1 -1
- package/dist/v2/{safe-notification-target-936374xx.js → safe-notification-target-qg7n2s77.js} +2 -2
- package/dist/v2/{search-a1acjwf8.js → search-c86dcv14.js} +24 -23
- package/dist/v2/{send-session-notification-z5mcjdea.js → send-session-notification-8ghn9tnv.js} +5 -5
- package/dist/v2/{server-npm52h2q.js → server-05xjtq6c.js} +1 -1
- package/dist/v2/{server-s6jqh8bj.js → server-0ppsweh6.js} +1 -1
- package/dist/v2/server-0s95v3en.js +49 -0
- package/dist/v2/{server-hn9fb3v0.js → server-34kwfsr4.js} +2 -2
- package/dist/v2/server-4gn3z5an.js +229 -0
- package/dist/v2/{server-kn7skz9r.js → server-6cdy4rc0.js} +3 -3
- package/dist/v2/{server-7dv9wt9r.js → server-6pmqg9m4.js} +1 -1
- package/dist/v2/{server-7fvmt15t.js → server-b81w6sw3.js} +273 -107
- package/dist/v2/{server-kmapq3v0.js → server-bxpwy6fy.js} +18 -5
- package/dist/v2/{server-d6t16r89.js → server-d8tj10db.js} +1 -1
- package/dist/v2/{server-cxsr0ng6.js → server-da07v4xp.js} +1 -1
- package/dist/v2/{server-rxcq4t50.js → server-ef89gdsx.js} +5 -5
- package/dist/v2/{server-9e5r8y60.js → server-f2xf5gcb.js} +46 -2
- package/dist/v2/{server-83d71zab.js → server-g10mdym6.js} +3 -3
- package/dist/v2/{server-njnx39q2.js → server-gvkm8xaj.js} +189 -29
- package/dist/v2/{server-ckrb5rm8.js → server-h0410h0v.js} +1 -1
- package/dist/v2/{server-sg68np13.js → server-hek6z3w6.js} +330 -254
- package/dist/v2/{server-f27he3j1.js → server-k2bzedxk.js} +4 -4
- package/dist/v2/{server-wkhfyzpg.js → server-m97brnat.js} +9 -9
- package/dist/v2/{server-erfp0xb6.js → server-n8ch9683.js} +16 -16
- package/dist/v2/{server-bx59ezg6.js → server-prg55b7k.js} +16 -6
- package/dist/v2/{server-89fcbe37.js → server-pwv4ezb0.js} +1 -1
- package/dist/v2/{server-r5p3b1wy.js → server-qd11g795.js} +29 -1
- package/dist/v2/{server-ewqshbs8.js → server-qhfvvfxj.js} +64 -7
- package/dist/v2/{server-988cqjme.js → server-rrqpvwqd.js} +2 -2
- package/dist/v2/{server-d3f4g62c.js → server-t4prcjc1.js} +13 -13
- package/dist/v2/{server-nveratm5.js → server-tbe1femw.js} +4 -4
- package/dist/v2/{server-jc8v585p.js → server-th4y11y7.js} +15 -15
- package/dist/v2/{server-h3wc20sv.js → server-vbe4se57.js} +4 -4
- package/dist/v2/{server-pbpp8r8h.js → server-xh7jar6k.js} +9 -9
- package/dist/v2/{server-63ha7f0f.js → server-yrvqaswb.js} +1 -1
- package/dist/v2/{server-5x7kmyz8.js → server-zc3e54vy.js} +10 -51
- package/dist/v2/{server-xqf2d2mg.js → server-zs8d0s3b.js} +2 -2
- package/dist/v2/server.d.ts.map +1 -1
- package/dist/v2/server.js +18 -10
- package/dist/v2/{storage-tags-c4zfcxv4.js → storage-tags-a2gq6dw7.js} +6 -4
- package/dist/v2/store-reader.d.ts +1 -0
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{task-config-x0hq3qfd.js → task-config-nvz8mapa.js} +6 -2
- package/dist/v2/{wrapup-orchestrator-87q9d5e2.js → wrapup-orchestrator-e1a2w6jh.js} +31 -29
- package/dist/wrapup-orchestrator-2051r6qm.js +48 -0
- package/package.json +6 -5
- package/src/agents/smart-notes-dreamer-gate.fixture.ts +171 -0
- package/src/agents/smart-notes-dreamer-gate.golden.json +245 -0
- package/src/agents/smart-notes-dreamer-gate.test.ts +161 -0
- package/src/config/agent-disable.ts +13 -0
- package/src/config/dependency-notes.test.ts +114 -0
- package/src/config/dependency-notes.ts +80 -0
- package/src/config/schema/magic-context.ts +23 -14
- package/src/features/magic-context/dreamer/task-registry.ts +40 -0
- package/src/shared/data-path.test.ts +35 -1
- package/src/shared/data-path.ts +57 -1
- package/src/shared/model-suggestion-retry.test.ts +34 -0
- package/src/shared/model-suggestion-retry.ts +23 -3
- package/src/shared/prompt-async-transport.test.ts +1 -1
- package/src/shared/prompt-async-transport.ts +16 -3
- package/dist/embedding-backfill-fjbfh1dt.js +0 -21
- package/dist/recomp-orchestrator-67k45s0b.js +0 -60
- package/dist/v2/embedding-backfill-xcw3t6hp.js +0 -20
- package/dist/v2/recomp-orchestrator-n0pq36f0.js +0 -59
- package/dist/wrapup-orchestrator-jqapepw0.js +0 -47
- /package/dist/{index-e6xnpach.js → index-b7p25tm0.js} +0 -0
- /package/dist/v2/{index-e6xnpach.js → index-b7p25tm0.js} +0 -0
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CANONICAL_DREAM_TASKS,
|
|
3
|
+
DREAM_TASK_CAPABILITIES,
|
|
4
|
+
toolLoopDreamTasks,
|
|
5
|
+
formatDreamTaskBacklogs,
|
|
6
|
+
formatDreamTaskFailures,
|
|
7
|
+
processedDreamTaskItems,
|
|
8
|
+
PROJECT_MEMORY_DREAM_TASKS,
|
|
9
|
+
dreamTaskAllowedBySettings,
|
|
10
|
+
leaseKindFor,
|
|
11
|
+
leaseKeyFor,
|
|
12
|
+
isCanonicalDreamTask,
|
|
13
|
+
compareTaskOrder,
|
|
14
|
+
buildDreamTaskRuntimeConfigs2,
|
|
15
|
+
userMemoryCollectionEnabled2
|
|
16
|
+
} from "./index-p5y3k4g7.js";
|
|
1
17
|
import {
|
|
2
18
|
getHarness2,
|
|
3
19
|
harnessOwnsOpenCodeStore2
|
|
@@ -6,7 +22,7 @@ import {
|
|
|
6
22
|
getDataDir,
|
|
7
23
|
getMagicContextStorageResolution,
|
|
8
24
|
getMagicContextStorageDir
|
|
9
|
-
} from "./index-
|
|
25
|
+
} from "./index-g2q4htwp.js";
|
|
10
26
|
import {
|
|
11
27
|
sanitizeDiagnosticText,
|
|
12
28
|
hasShareabilitySensitiveText,
|
|
@@ -15,7 +31,7 @@ import {
|
|
|
15
31
|
log2,
|
|
16
32
|
sessionLog2,
|
|
17
33
|
getLoggerDiagnostics2
|
|
18
|
-
} from "./index-
|
|
34
|
+
} from "./index-j75v2476.js";
|
|
19
35
|
import {
|
|
20
36
|
resolveOpenCodeDbPath,
|
|
21
37
|
assertOpenCodeStoreGeneration,
|
|
@@ -54,7 +70,7 @@ import {
|
|
|
54
70
|
storedPathBelongsToIdentity,
|
|
55
71
|
beginBootQuietPeriod,
|
|
56
72
|
scheduleAfterBootQuiet
|
|
57
|
-
} from "./index-
|
|
73
|
+
} from "./index-a8bvhwqs.js";
|
|
58
74
|
import {
|
|
59
75
|
recordSessionProjectIdentity,
|
|
60
76
|
hasRecordedSessionProjectIdentity,
|
|
@@ -63,25 +79,8 @@ import {
|
|
|
63
79
|
renewGitSweepLease,
|
|
64
80
|
markGitSweepSuccessAndRelease,
|
|
65
81
|
parkGitSweepNonIndexable,
|
|
66
|
-
releaseGitSweepLease
|
|
67
|
-
|
|
68
|
-
markProjectLoadUntrusted2,
|
|
69
|
-
drainProjectEmbeddingIdentityMaintenance2,
|
|
70
|
-
drainStaleEmbeddingIdentitiesForProject2,
|
|
71
|
-
registerProjectEmbedding2,
|
|
72
|
-
registerProjectShadowEmbedding2,
|
|
73
|
-
enqueueShadowEmbeddingItems2,
|
|
74
|
-
registerProjectInObservationMode2,
|
|
75
|
-
unregisterProjectShadowEmbedding2,
|
|
76
|
-
getProjectEmbeddingSnapshot2,
|
|
77
|
-
embedTextForProject2,
|
|
78
|
-
embedBatchForProject2,
|
|
79
|
-
embedUnembeddedMemoriesForProject2,
|
|
80
|
-
embedUnembeddedMemoriesForProjectOutcome2,
|
|
81
|
-
drainCommitBacklogForProject2,
|
|
82
|
-
embedSessionCompartmentChunks2,
|
|
83
|
-
getEmbeddingCoverageStatus2
|
|
84
|
-
} from "./index-se1w3v2m.js";
|
|
82
|
+
releaseGitSweepLease
|
|
83
|
+
} from "./index-saews2s3.js";
|
|
85
84
|
import {
|
|
86
85
|
hasTrustedAbsoluteWall,
|
|
87
86
|
applyProvenInputFloor,
|
|
@@ -93,7 +92,7 @@ import {
|
|
|
93
92
|
deriveTriggerBudget2,
|
|
94
93
|
resolveKnownHistorianContextLimit2,
|
|
95
94
|
resolveHistorianProducerLimits2
|
|
96
|
-
} from "./index-
|
|
95
|
+
} from "./index-v10f1rjv.js";
|
|
97
96
|
import {
|
|
98
97
|
resolveModelCalibration,
|
|
99
98
|
calibrateBuckets,
|
|
@@ -107,7 +106,7 @@ import {
|
|
|
107
106
|
estimateTokens,
|
|
108
107
|
estimateFixedPromptTokens,
|
|
109
108
|
normalizeText
|
|
110
|
-
} from "./index-
|
|
109
|
+
} from "./index-hqkczed7.js";
|
|
111
110
|
import {
|
|
112
111
|
protectedToolTokenCount,
|
|
113
112
|
peelLeadingMcTagNotation,
|
|
@@ -144,11 +143,11 @@ import {
|
|
|
144
143
|
getDroppedTagsByNumbers2,
|
|
145
144
|
getMaxDroppedTagNumber2,
|
|
146
145
|
getTagById2
|
|
147
|
-
} from "./index-
|
|
146
|
+
} from "./index-fwefky9w.js";
|
|
148
147
|
import {
|
|
149
148
|
observeTemporalDecisions,
|
|
150
149
|
stableStringify
|
|
151
|
-
} from "./index-
|
|
150
|
+
} from "./index-bp5083x2.js";
|
|
152
151
|
import {
|
|
153
152
|
withContentLanguageDirective,
|
|
154
153
|
parseCron,
|
|
@@ -161,13 +160,14 @@ import {
|
|
|
161
160
|
DEFAULT_HISTORIAN_TIMEOUT_MS,
|
|
162
161
|
DEFAULT_LOCAL_EMBEDDING_MODEL,
|
|
163
162
|
DREAM_TASK_PROMOTION_DEFAULTS
|
|
164
|
-
} from "./index-
|
|
163
|
+
} from "./index-1sarmj9z.js";
|
|
165
164
|
import {
|
|
166
165
|
isRawCompactionSummaryInfo2,
|
|
167
166
|
extractInMemoryMessageViews2,
|
|
168
167
|
buildInMemoryTailRawMessages2,
|
|
168
|
+
RawOrdinalsNotReady2,
|
|
169
169
|
runSessionWarmupWorker
|
|
170
|
-
} from "./index-
|
|
170
|
+
} from "./index-mmfa86mt.js";
|
|
171
171
|
import {
|
|
172
172
|
openCodeDbExists,
|
|
173
173
|
withReadOnlySessionDb,
|
|
@@ -175,7 +175,7 @@ import {
|
|
|
175
175
|
latestPersistedMessageForRecovery,
|
|
176
176
|
latestRealUserTurnIdFromOpenCodeDb,
|
|
177
177
|
findLastAssistantModelFromOpenCodeDb
|
|
178
|
-
} from "./index-
|
|
178
|
+
} from "./index-1d289pq2.js";
|
|
179
179
|
import {
|
|
180
180
|
expandToolPart,
|
|
181
181
|
estimateTrueRawMessageTokens,
|
|
@@ -296,24 +296,10 @@ import {
|
|
|
296
296
|
readRawSessionMessageById2,
|
|
297
297
|
readSessionChunk2,
|
|
298
298
|
readRawSessionSeedTail2
|
|
299
|
-
} from "./index-
|
|
299
|
+
} from "./index-b16gpywn.js";
|
|
300
300
|
import {
|
|
301
301
|
getMeasuredToolDefinitionTokens
|
|
302
|
-
} from "./index-
|
|
303
|
-
import {
|
|
304
|
-
CANONICAL_DREAM_TASKS,
|
|
305
|
-
DREAM_TASK_CAPABILITIES,
|
|
306
|
-
toolLoopDreamTasks,
|
|
307
|
-
formatDreamTaskBacklogs,
|
|
308
|
-
formatDreamTaskFailures,
|
|
309
|
-
processedDreamTaskItems,
|
|
310
|
-
leaseKindFor,
|
|
311
|
-
leaseKeyFor,
|
|
312
|
-
isCanonicalDreamTask,
|
|
313
|
-
compareTaskOrder,
|
|
314
|
-
buildDreamTaskRuntimeConfigs2,
|
|
315
|
-
userMemoryCollectionEnabled2
|
|
316
|
-
} from "./index-ghc9f0n7.js";
|
|
302
|
+
} from "./index-n6m03s3n.js";
|
|
317
303
|
import {
|
|
318
304
|
isFailClosedBlockingError,
|
|
319
305
|
shouldBypassFailClosedBlock,
|
|
@@ -327,14 +313,14 @@ import {
|
|
|
327
313
|
runSqliteOptimize,
|
|
328
314
|
openDatabase,
|
|
329
315
|
openCurrentDatabase
|
|
330
|
-
} from "./index-
|
|
316
|
+
} from "./index-qkd9zz0p.js";
|
|
331
317
|
import {
|
|
332
318
|
registerOwnRpcServerInstance,
|
|
333
319
|
rpcPortDir,
|
|
334
320
|
rpcPortFilePath,
|
|
335
321
|
parseRpcPortFile,
|
|
336
322
|
inspectProcessesAsync
|
|
337
|
-
} from "./index-
|
|
323
|
+
} from "./index-nj7yykkx.js";
|
|
338
324
|
import {
|
|
339
325
|
configureContextDatabasePragmas2
|
|
340
326
|
} from "./index-fb3zxn06.js";
|
|
@@ -346,7 +332,7 @@ import {
|
|
|
346
332
|
resolveStoredPathWorkspaceIdentity,
|
|
347
333
|
storedPathBelongsToWorkspace,
|
|
348
334
|
computeWorkspaceEpochFingerprint
|
|
349
|
-
} from "./index-
|
|
335
|
+
} from "./index-wk0n1cgt.js";
|
|
350
336
|
import {
|
|
351
337
|
V2_MEMORY_CATEGORIES,
|
|
352
338
|
CATEGORY_PRIORITY
|
|
@@ -354,15 +340,12 @@ import {
|
|
|
354
340
|
import {
|
|
355
341
|
getMagicContextBuiltinCommands,
|
|
356
342
|
formatConfigParseStatusLine,
|
|
357
|
-
COMPACTION_ENABLED_PATH,
|
|
358
|
-
isCompactionEnabled,
|
|
359
343
|
cortexKitUserConfigBasePath,
|
|
360
344
|
cortexKitProjectConfigBasePath,
|
|
361
345
|
resolveLegacyConfigSources,
|
|
362
346
|
loadPluginConfigDetailed,
|
|
363
347
|
historianRunConfig,
|
|
364
348
|
currentPluginConfigReader,
|
|
365
|
-
isProjectMemoryEnabled,
|
|
366
349
|
clampProducerAtomChars,
|
|
367
350
|
producerInputTokenLimit,
|
|
368
351
|
historianProducerReserve,
|
|
@@ -374,10 +357,6 @@ import {
|
|
|
374
357
|
DREAMER_CLASSIFIER_AGENT,
|
|
375
358
|
DREAMER_DOCS_AGENT,
|
|
376
359
|
DREAMER_REVIEWER_AGENT,
|
|
377
|
-
embedPauseBySession,
|
|
378
|
-
embedRunStateBySession,
|
|
379
|
-
invalidateAutoEmbedSession,
|
|
380
|
-
getEmbedDrainUiStatus,
|
|
381
360
|
getCompartments,
|
|
382
361
|
getLastCompartmentEndMessage,
|
|
383
362
|
getLastCompartmentEndMessageId,
|
|
@@ -453,9 +432,11 @@ import {
|
|
|
453
432
|
toModelEntry,
|
|
454
433
|
isPromptTimeoutError,
|
|
455
434
|
getPromptFailureDetail,
|
|
435
|
+
raceWithSignal,
|
|
456
436
|
promptSyncWithValidatedOutputRetry,
|
|
457
437
|
normalizeSDKResponse,
|
|
458
438
|
failedInvocationStatus,
|
|
439
|
+
sumTokensFromChildMessages,
|
|
459
440
|
recordChildInvocation,
|
|
460
441
|
createPromptAsyncTransport,
|
|
461
442
|
systemPromptFingerprint,
|
|
@@ -518,10 +499,39 @@ import {
|
|
|
518
499
|
getRawHistoryEligibility,
|
|
519
500
|
hasRunnableCompartmentWindow,
|
|
520
501
|
recordHighPressureNoEligibleHead,
|
|
502
|
+
noteTransformPassForExactOrdinalReads,
|
|
521
503
|
snapRangeToCompartments,
|
|
522
504
|
getActiveCompartmentRun,
|
|
523
505
|
startCompartmentAgent
|
|
524
|
-
} from "./index-
|
|
506
|
+
} from "./index-2jr1smmh.js";
|
|
507
|
+
import {
|
|
508
|
+
embedPauseBySession,
|
|
509
|
+
embedRunStateBySession,
|
|
510
|
+
activeEmbeddingSessions,
|
|
511
|
+
autoEmbedAttemptedBySession,
|
|
512
|
+
autoEmbedIdentityBySession,
|
|
513
|
+
autoEmbedRetryAfterBySession,
|
|
514
|
+
invalidateAutoEmbedSession,
|
|
515
|
+
getEmbedDrainUiStatus,
|
|
516
|
+
describeShadowBackfillWriteRefusal2,
|
|
517
|
+
markProjectLoadUntrusted2,
|
|
518
|
+
drainProjectEmbeddingIdentityMaintenance2,
|
|
519
|
+
drainStaleEmbeddingIdentitiesForProject2,
|
|
520
|
+
registerProjectEmbedding2,
|
|
521
|
+
registerProjectShadowEmbedding2,
|
|
522
|
+
enqueueShadowEmbeddingItems2,
|
|
523
|
+
registerProjectInObservationMode2,
|
|
524
|
+
unregisterProjectShadowEmbedding2,
|
|
525
|
+
getProjectEmbeddingSnapshot2,
|
|
526
|
+
embedTextForProject2,
|
|
527
|
+
embedBatchForProject2,
|
|
528
|
+
embedUnembeddedMemoriesForProject2,
|
|
529
|
+
embedUnembeddedMemoriesForProjectOutcome2,
|
|
530
|
+
drainCommitBacklogForProject2,
|
|
531
|
+
embedSessionCompartmentChunks2,
|
|
532
|
+
getEmbeddingCoverageStatus2,
|
|
533
|
+
getAutoEmbeddingSessionCoverage2
|
|
534
|
+
} from "./index-y1qysm3q.js";
|
|
525
535
|
import {
|
|
526
536
|
SubcClient,
|
|
527
537
|
connectionFileExists,
|
|
@@ -529,7 +539,7 @@ import {
|
|
|
529
539
|
toSynapseLaneDescriptor,
|
|
530
540
|
formatSynapseLaneDescriptor,
|
|
531
541
|
SynapseEmbeddingProvider
|
|
532
|
-
} from "./index-
|
|
542
|
+
} from "./index-fkx2qnvw.js";
|
|
533
543
|
import {
|
|
534
544
|
BoundedSessionMap,
|
|
535
545
|
LkgRecoveryFenceError,
|
|
@@ -550,7 +560,7 @@ import {
|
|
|
550
560
|
indexSingleMessage2,
|
|
551
561
|
indexMessagesAfterOrdinal2,
|
|
552
562
|
sweepOrphanedOpenCodeMessageIndexes2
|
|
553
|
-
} from "./index-
|
|
563
|
+
} from "./index-v13skev1.js";
|
|
554
564
|
import {
|
|
555
565
|
renderUserFacingFailure,
|
|
556
566
|
userFacingFailureCode,
|
|
@@ -594,7 +604,7 @@ import {
|
|
|
594
604
|
readGitFileChangeTimesSince,
|
|
595
605
|
verificationFileExists,
|
|
596
606
|
normalizeVerificationFiles
|
|
597
|
-
} from "./index-
|
|
607
|
+
} from "./index-bxdg2nbt.js";
|
|
598
608
|
import {
|
|
599
609
|
registerNotificationSink2,
|
|
600
610
|
pushNotification2,
|
|
@@ -604,7 +614,7 @@ import {
|
|
|
604
614
|
} from "./index-x8a7jmkh.js";
|
|
605
615
|
import {
|
|
606
616
|
getLocalEmbeddingNativeMemoryStats
|
|
607
|
-
} from "./index-
|
|
617
|
+
} from "./index-e20m7284.js";
|
|
608
618
|
import {
|
|
609
619
|
saveEmbeddingIfHashMatches,
|
|
610
620
|
invalidateProject2,
|
|
@@ -612,7 +622,7 @@ import {
|
|
|
612
622
|
} from "./index-4dhv7mqz.js";
|
|
613
623
|
import {
|
|
614
624
|
cosineSimilarity
|
|
615
|
-
} from "./index-
|
|
625
|
+
} from "./index-3kdm78zp.js";
|
|
616
626
|
import {
|
|
617
627
|
computeCueContentHash,
|
|
618
628
|
hasMuralCueColumns,
|
|
@@ -659,17 +669,17 @@ import {
|
|
|
659
669
|
resolveMemoriesByIdsForSearch2,
|
|
660
670
|
unifiedSearch2,
|
|
661
671
|
formatSearchResults2
|
|
662
|
-
} from "./index-
|
|
672
|
+
} from "./index-aw1bh90w.js";
|
|
663
673
|
import {
|
|
664
674
|
flushIgnoredMessages2,
|
|
665
675
|
clearIgnoredMessages2,
|
|
666
676
|
observeIgnoredNotificationEvent2,
|
|
667
677
|
sendStatusNotification2
|
|
668
|
-
} from "./index-
|
|
678
|
+
} from "./index-dgs16axy.js";
|
|
669
679
|
import {
|
|
670
680
|
setRecompStarting2,
|
|
671
681
|
setRecompTerminal2
|
|
672
|
-
} from "./index-
|
|
682
|
+
} from "./index-hnm8raee.js";
|
|
673
683
|
import {
|
|
674
684
|
makeToolCompositeKey,
|
|
675
685
|
searchMessageHistoryOffThread,
|
|
@@ -720,23 +730,33 @@ import {
|
|
|
720
730
|
abortSessionFailClosed2,
|
|
721
731
|
evaluateEmergencyFailClosed2,
|
|
722
732
|
runPostTransformPhase2
|
|
723
|
-
} from "./index-
|
|
733
|
+
} from "./index-sj89f3b0.js";
|
|
724
734
|
import {
|
|
725
735
|
ANNOUNCEMENT_VERSION2,
|
|
726
736
|
ANNOUNCEMENT_FEATURES2,
|
|
727
737
|
ANNOUNCEMENT_FOOTER2,
|
|
728
738
|
markAnnouncementSeen2,
|
|
729
739
|
shouldShowAnnouncement2
|
|
730
|
-
} from "./index-
|
|
740
|
+
} from "./index-gp3kcpc4.js";
|
|
731
741
|
import {
|
|
732
742
|
resolvePromptContext2
|
|
733
743
|
} from "./index-fmsr7v69.js";
|
|
744
|
+
import {
|
|
745
|
+
COMPACTION_ENABLED_PATH,
|
|
746
|
+
isDreamerRunnable,
|
|
747
|
+
isCompactionEnabled
|
|
748
|
+
} from "./index-ksdyrrav.js";
|
|
734
749
|
import {
|
|
735
750
|
__toESM
|
|
736
751
|
} from "./index-22jkk6wg.js";
|
|
737
752
|
import {
|
|
738
753
|
computeNormalizedHash
|
|
739
754
|
} from "./index-2bvekkfy.js";
|
|
755
|
+
import {
|
|
756
|
+
canonicalModelIdentity,
|
|
757
|
+
piModelRefToCanonical,
|
|
758
|
+
modelRefLookupOrder
|
|
759
|
+
} from "./index-avwt563y.js";
|
|
740
760
|
import {
|
|
741
761
|
canonicalProjectDirectory
|
|
742
762
|
} from "./index-knvkbfvh.js";
|
|
@@ -744,6 +764,13 @@ import {
|
|
|
744
764
|
getErrorMessage,
|
|
745
765
|
describeError
|
|
746
766
|
} from "./index-y8v6yerm.js";
|
|
767
|
+
import {
|
|
768
|
+
closeQuietly,
|
|
769
|
+
isKnownAutocommit
|
|
770
|
+
} from "./index-8ajstryz.js";
|
|
771
|
+
import {
|
|
772
|
+
logSlowWriteTransaction
|
|
773
|
+
} from "./index-k29z4aqh.js";
|
|
747
774
|
import {
|
|
748
775
|
shouldEnforcePrivateStoragePermissions,
|
|
749
776
|
ensureStorageDirectorySync,
|
|
@@ -751,18 +778,39 @@ import {
|
|
|
751
778
|
writeStorageFileAsync,
|
|
752
779
|
createStorageWriteStream
|
|
753
780
|
} from "./index-fvnzcnww.js";
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
781
|
+
|
|
782
|
+
// src/config/dependency-notes.ts
|
|
783
|
+
function scheduledTasks(config) {
|
|
784
|
+
const tasks = config.dreamer?.tasks ?? {};
|
|
785
|
+
return Object.entries(tasks).filter(([, task]) => typeof task?.schedule === "string" && task.schedule.trim() !== "").map(([name]) => name);
|
|
786
|
+
}
|
|
787
|
+
function configDependencyNotes(config) {
|
|
788
|
+
const notes = [];
|
|
789
|
+
const dreamerRunnable = isDreamerRunnable(config);
|
|
790
|
+
const dreamerDisabled = config.dreamer?.disable === true;
|
|
791
|
+
const memoryOff = config.memory?.enabled === false;
|
|
792
|
+
const memoryTasks = scheduledTasks(config).filter((task) => PROJECT_MEMORY_DREAM_TASKS.includes(task));
|
|
793
|
+
if (dreamerRunnable && memoryOff && memoryTasks.length > 0) {
|
|
794
|
+
notes.push(`memory.enabled is false, so these scheduled dreamer tasks do not run for this project, on schedule or through /ctx-dream: ${memoryTasks.join(", ")}. maintain-docs, evaluate-smart-notes and review-user-memories still run.`);
|
|
795
|
+
}
|
|
796
|
+
if (dreamerDisabled && config.smart_notes?.enabled !== false) {
|
|
797
|
+
notes.push("dreamer.disable is true, so smart_notes.enabled has no effect: ctx_note does not offer surface_condition and pending smart notes are not evaluated.");
|
|
798
|
+
}
|
|
799
|
+
const reviewSchedule = config.dreamer?.tasks?.["review-user-memories"]?.schedule;
|
|
800
|
+
if (dreamerDisabled && typeof reviewSchedule === "string" && reviewSchedule.trim() !== "") {
|
|
801
|
+
notes.push("dreamer.disable is true, so dreamer.tasks.review-user-memories.schedule has no effect: the historian does not collect user observations and the <user-profile> block gets no new entries.");
|
|
802
|
+
}
|
|
803
|
+
return notes;
|
|
804
|
+
}
|
|
805
|
+
var loggedNotes = new Set;
|
|
806
|
+
function logConfigDependencyNotesOnce(config, log) {
|
|
807
|
+
const fresh = configDependencyNotes(config).filter((note) => !loggedNotes.has(note));
|
|
808
|
+
for (const note of fresh) {
|
|
809
|
+
loggedNotes.add(note);
|
|
810
|
+
log(`[magic-context] config note: ${note}`);
|
|
811
|
+
}
|
|
812
|
+
return fresh;
|
|
813
|
+
}
|
|
766
814
|
|
|
767
815
|
// src/features/magic-context/dreamer/open-opencode-db.ts
|
|
768
816
|
function openOpenCodeDb() {
|
|
@@ -1945,10 +1993,28 @@ async function readRetrospectiveScanWindow(provider, projectIdentity, watermarkM
|
|
|
1945
1993
|
}
|
|
1946
1994
|
function readOpenCodeMessagesSince(db, sessionId, sinceMs, capPerSession) {
|
|
1947
1995
|
const limit = Math.max(1, Math.floor(capPerSession));
|
|
1948
|
-
const rows = db.prepare(`SELECT id, data, time_created
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1996
|
+
const rows = db.prepare(`SELECT current.id, current.data, current.time_created,
|
|
1997
|
+
EXISTS (
|
|
1998
|
+
SELECT 1 FROM message assistant_reply
|
|
1999
|
+
WHERE assistant_reply.session_id = current.session_id
|
|
2000
|
+
AND json_valid(assistant_reply.data)
|
|
2001
|
+
AND json_extract(assistant_reply.data, '$.role') = 'assistant'
|
|
2002
|
+
AND (assistant_reply.time_created < current.time_created
|
|
2003
|
+
OR (assistant_reply.time_created = current.time_created
|
|
2004
|
+
AND assistant_reply.id < current.id))
|
|
2005
|
+
AND EXISTS (
|
|
2006
|
+
SELECT 1 FROM message prior_user
|
|
2007
|
+
WHERE prior_user.session_id = current.session_id
|
|
2008
|
+
AND json_valid(prior_user.data)
|
|
2009
|
+
AND json_extract(prior_user.data, '$.role') = 'user'
|
|
2010
|
+
AND (prior_user.time_created < assistant_reply.time_created
|
|
2011
|
+
OR (prior_user.time_created = assistant_reply.time_created
|
|
2012
|
+
AND prior_user.id < assistant_reply.id))
|
|
2013
|
+
)
|
|
2014
|
+
) AS has_prior_assistant_reply
|
|
2015
|
+
FROM message current
|
|
2016
|
+
WHERE current.session_id = ? AND current.time_created > ?
|
|
2017
|
+
ORDER BY current.time_created ASC, current.id ASC
|
|
1952
2018
|
LIMIT ?`).all(sessionId, sinceMs, limit + 1);
|
|
1953
2019
|
const truncated = rows.length > limit;
|
|
1954
2020
|
const kept = truncated ? rows.slice(0, limit) : rows;
|
|
@@ -2052,7 +2118,8 @@ function normalizeOpenCodeRows(db, sessionId, rows) {
|
|
|
2052
2118
|
ordinal,
|
|
2053
2119
|
role,
|
|
2054
2120
|
parts,
|
|
2055
|
-
ts: row.time_created
|
|
2121
|
+
ts: row.time_created,
|
|
2122
|
+
followsAssistantReply: row.has_prior_assistant_reply === 1
|
|
2056
2123
|
});
|
|
2057
2124
|
});
|
|
2058
2125
|
}
|
|
@@ -2066,7 +2133,8 @@ function normalizeOpenCodeMessage(args) {
|
|
|
2066
2133
|
ordinal: args.ordinal,
|
|
2067
2134
|
role: "user",
|
|
2068
2135
|
text,
|
|
2069
|
-
ts: args.ts
|
|
2136
|
+
ts: args.ts,
|
|
2137
|
+
...args.followsAssistantReply ? { followsAssistantReply: true } : {}
|
|
2070
2138
|
});
|
|
2071
2139
|
}
|
|
2072
2140
|
}
|
|
@@ -2491,9 +2559,12 @@ async function runCompressCues(args) {
|
|
|
2491
2559
|
let timeoutStreakElapsedMs = [];
|
|
2492
2560
|
for (let i = 0;i < chunks.length; i += 1) {
|
|
2493
2561
|
const remainingMs = Math.max(0, args.deadline - Date.now());
|
|
2494
|
-
if (remainingMs <= 0)
|
|
2562
|
+
if (remainingMs <= 0) {
|
|
2563
|
+
result.stopReason = "deadline";
|
|
2495
2564
|
break;
|
|
2565
|
+
}
|
|
2496
2566
|
if (remainingMs < CHUNK_TIMEOUT_FLOOR_MS) {
|
|
2567
|
+
result.stopReason = "deadline";
|
|
2497
2568
|
log2(`[dreamer] compress-cues: stopping before chunk ${i + 1}/${chunks.length} — remaining budget ${remainingMs}ms is below the ${CHUNK_TIMEOUT_FLOOR_MS}ms chunk floor; banking ${result.compressed} compressed cue(s)`);
|
|
2498
2569
|
break;
|
|
2499
2570
|
}
|
|
@@ -2502,6 +2573,10 @@ async function runCompressCues(args) {
|
|
|
2502
2573
|
if (!chunk)
|
|
2503
2574
|
break;
|
|
2504
2575
|
const outcome = await compressOneChunk(args, chunk, sliceMs, abortController.signal);
|
|
2576
|
+
if (outcome.failure) {
|
|
2577
|
+
result.failure = outcome.failure.error;
|
|
2578
|
+
result.failureStage = outcome.failure.stage;
|
|
2579
|
+
}
|
|
2505
2580
|
result.compressed += outcome.compressed;
|
|
2506
2581
|
result.skipped += outcome.skipped;
|
|
2507
2582
|
result.remaining -= outcome.compressed;
|
|
@@ -2511,6 +2586,7 @@ async function runCompressCues(args) {
|
|
|
2511
2586
|
consecutiveTimeouts += 1;
|
|
2512
2587
|
timeoutStreakElapsedMs.push(outcome.failure.elapsedMs);
|
|
2513
2588
|
if (consecutiveTimeouts >= CONSECUTIVE_TIMEOUT_LIMIT) {
|
|
2589
|
+
result.stopReason = "timeout-circuit-breaker";
|
|
2514
2590
|
log2(`[dreamer] compress-cues: circuit breaker tripped — ${consecutiveTimeouts} consecutive chunk timeouts (model too slow for its time slice); per-chunk elapsed [${timeoutStreakElapsedMs.join("ms, ")}ms] vs ${sliceMs}ms slice; stopping run incomplete with ${chunks.length - i - 1} chunk(s) unattempted`);
|
|
2515
2591
|
break;
|
|
2516
2592
|
}
|
|
@@ -2527,7 +2603,7 @@ async function runCompressCues(args) {
|
|
|
2527
2603
|
}
|
|
2528
2604
|
}
|
|
2529
2605
|
function isTimeoutClassError(error) {
|
|
2530
|
-
return error
|
|
2606
|
+
return isPromptTimeoutError(error) || getPromptFailureDetail(error)?.failureClass === "provider_timeout";
|
|
2531
2607
|
}
|
|
2532
2608
|
async function compressOneChunk(args, chunk, sliceMs, signal) {
|
|
2533
2609
|
let agentSessionId = null;
|
|
@@ -2535,6 +2611,7 @@ async function compressOneChunk(args, chunk, sliceMs, signal) {
|
|
|
2535
2611
|
const executor = resolveHiddenCompletionExecutor(args.hiddenCompletionExecutor, args.client, args.db, args.sessionDirectory, "compress-cues");
|
|
2536
2612
|
let promptSettled = false;
|
|
2537
2613
|
const startedAt = Date.now();
|
|
2614
|
+
let stage = "child-start";
|
|
2538
2615
|
try {
|
|
2539
2616
|
const prompt = buildCompressCuesPrompt({
|
|
2540
2617
|
projectPath: args.projectIdentity,
|
|
@@ -2555,6 +2632,7 @@ async function compressOneChunk(args, chunk, sliceMs, signal) {
|
|
|
2555
2632
|
agentSessionId = handle.id || null;
|
|
2556
2633
|
if (!agentSessionId)
|
|
2557
2634
|
throw new Error("Could not create compress-cues session.");
|
|
2635
|
+
stage = "prompt";
|
|
2558
2636
|
const opened = handle;
|
|
2559
2637
|
const run = await promptSyncWithValidatedOutputRetry(args.client, {
|
|
2560
2638
|
path: { id: agentSessionId },
|
|
@@ -2606,16 +2684,19 @@ async function compressOneChunk(args, chunk, sliceMs, signal) {
|
|
|
2606
2684
|
modelId: run.output.modelId
|
|
2607
2685
|
});
|
|
2608
2686
|
}
|
|
2687
|
+
stage = "apply";
|
|
2609
2688
|
return args.moduleRoute ? await applyCuesThroughModule(args, chunk, run.validated, signal) : applyCues(args, chunk, run.validated);
|
|
2610
2689
|
} catch (error) {
|
|
2611
2690
|
const desc = describeError(error);
|
|
2612
2691
|
log2(`[dreamer] compress-cues chunk failed: ${desc.brief}`, desc.stackHead ? { stackHead: desc.stackHead } : undefined);
|
|
2613
|
-
if (signal.aborted || error instanceof HiddenCompletionRefusal || error instanceof DreamerProviderOutputFailureError)
|
|
2692
|
+
if (signal.aborted || error instanceof DreamerModuleFailureError || error instanceof HiddenCompletionRefusal || error instanceof DreamerProviderOutputFailureError)
|
|
2614
2693
|
throw error;
|
|
2615
2694
|
return {
|
|
2616
2695
|
compressed: 0,
|
|
2617
2696
|
skipped: 0,
|
|
2618
2697
|
failure: {
|
|
2698
|
+
error,
|
|
2699
|
+
stage,
|
|
2619
2700
|
class: isTimeoutClassError(error) ? "timeout" : "other",
|
|
2620
2701
|
brief: desc.brief,
|
|
2621
2702
|
elapsedMs: Date.now() - startedAt
|
|
@@ -2769,7 +2850,7 @@ async function applyCuesThroughModule(args, chunk, manifestText, signal) {
|
|
|
2769
2850
|
// src/features/magic-context/dreamer/hidden-single-shot.ts
|
|
2770
2851
|
async function runHiddenSingleShotPrompt(args) {
|
|
2771
2852
|
const system = withContentLanguageDirective(args.system, args.language);
|
|
2772
|
-
const
|
|
2853
|
+
const opening = args.executor.open({
|
|
2773
2854
|
parentSessionId: args.parentSessionId,
|
|
2774
2855
|
agent: args.agent,
|
|
2775
2856
|
kind: "dreamer-task",
|
|
@@ -2781,6 +2862,17 @@ async function runHiddenSingleShotPrompt(args) {
|
|
|
2781
2862
|
directory: args.sessionDirectory,
|
|
2782
2863
|
...args.metadata ? { metadata: args.metadata } : {}
|
|
2783
2864
|
});
|
|
2865
|
+
opening.then((handle) => {
|
|
2866
|
+
if (args.signal?.aborted)
|
|
2867
|
+
return args.executor.close(handle, {
|
|
2868
|
+
promptSettled: false,
|
|
2869
|
+
privacySensitive: args.privacySensitive ?? true,
|
|
2870
|
+
context: `[dreamer] ${args.callContext}`,
|
|
2871
|
+
log: log2
|
|
2872
|
+
});
|
|
2873
|
+
}).catch(() => {});
|
|
2874
|
+
const handle = await raceWithSignal(opening, args.signal);
|
|
2875
|
+
args.onOpened?.(handle.id);
|
|
2784
2876
|
let promptSettled = false;
|
|
2785
2877
|
try {
|
|
2786
2878
|
if (!handle.id)
|
|
@@ -2835,12 +2927,16 @@ async function runHiddenSingleShotPrompt(args) {
|
|
|
2835
2927
|
}
|
|
2836
2928
|
throw error;
|
|
2837
2929
|
} finally {
|
|
2838
|
-
|
|
2930
|
+
const close = args.executor.close(handle, {
|
|
2839
2931
|
promptSettled,
|
|
2840
2932
|
privacySensitive: args.privacySensitive ?? true,
|
|
2841
2933
|
context: `[dreamer] ${args.callContext}`,
|
|
2842
2934
|
log: log2
|
|
2843
2935
|
});
|
|
2936
|
+
if (args.signal?.aborted)
|
|
2937
|
+
close.catch(() => {});
|
|
2938
|
+
else
|
|
2939
|
+
await raceWithSignal(close, args.signal);
|
|
2844
2940
|
}
|
|
2845
2941
|
}
|
|
2846
2942
|
|
|
@@ -5005,7 +5101,7 @@ function getAsyncModule() {
|
|
|
5005
5101
|
await beforeModuleLoad();
|
|
5006
5102
|
const [{ default: singlefileAsyncifyVariant }, { newQuickJSAsyncWASMModuleFromVariant }] = await importPluginModule(() => Promise.all([
|
|
5007
5103
|
import("./index-e7vx3byk.js").then((m)=>__toESM(m.default,1)),
|
|
5008
|
-
import("./index-
|
|
5104
|
+
import("./index-b7p25tm0.js")
|
|
5009
5105
|
]));
|
|
5010
5106
|
const module = await newQuickJSAsyncWASMModuleFromVariant(singlefileAsyncifyVariant);
|
|
5011
5107
|
return module;
|
|
@@ -6910,14 +7006,28 @@ function isDeferred(memory, retries) {
|
|
|
6910
7006
|
return !!retry && retry.content === contentKey(memory) && retry.deferUntil > Date.now();
|
|
6911
7007
|
}
|
|
6912
7008
|
function assistantText(messages) {
|
|
6913
|
-
|
|
7009
|
+
const joined = messages.filter((message) => isRecord(message) && (message.role === "assistant" || isRecord(message.info) && message.info.role === "assistant")).map((message) => extractLatestAssistantText([message]) ?? (isRecord(message) && Array.isArray(message.content) ? message.content.filter(isRecord).filter((part) => part.type === "text" && typeof part.text === "string").map((part) => part.text).join(`
|
|
6914
7010
|
`) : "")).join(`
|
|
6915
7011
|
`);
|
|
7012
|
+
return joined.trim() ? joined : null;
|
|
6916
7013
|
}
|
|
6917
7014
|
function currentManifest(text) {
|
|
6918
7015
|
const start = text.lastIndexOf("<mappings>");
|
|
6919
7016
|
return start < 0 ? text : text.slice(start);
|
|
6920
7017
|
}
|
|
7018
|
+
function parseMapMemoriesCompletion(text, completion, expectedIds) {
|
|
7019
|
+
return validateMapMemoriesManifest(currentManifest(assistantText(completion.messages ?? []) || text), expectedIds);
|
|
7020
|
+
}
|
|
7021
|
+
function validateClientMapMemories(messages, expectedIds) {
|
|
7022
|
+
if (hasLengthCappedOutput(messages)) {
|
|
7023
|
+
throw new Error("map-memories returned length-capped output");
|
|
7024
|
+
}
|
|
7025
|
+
const raw = assistantText(messages);
|
|
7026
|
+
if (raw == null) {
|
|
7027
|
+
throw new Error("map-memories returned no output");
|
|
7028
|
+
}
|
|
7029
|
+
return validateMapMemoriesManifest(currentManifest(raw), expectedIds);
|
|
7030
|
+
}
|
|
6921
7031
|
function logBatchUsage(messages, committed, startedAt) {
|
|
6922
7032
|
const steps = messages.filter((message) => isRecord(message) && (message.role === "assistant" || isRecord(message.info) && message.info.role === "assistant")).length;
|
|
6923
7033
|
log2(`[dreamer] map-memories batch: steps=${steps} committed=${committed} steps_per_memory=${committed ? (steps / committed).toFixed(2) : "n/a"} elapsed_ms=${Date.now() - startedAt}`);
|
|
@@ -6982,8 +7092,11 @@ async function mapMemories(args) {
|
|
|
6982
7092
|
const inputs = allInputs.filter((memory) => !isDeferred(memory, retries));
|
|
6983
7093
|
result.remaining = allInputs.length;
|
|
6984
7094
|
result.complete = result.remaining === 0;
|
|
6985
|
-
if (inputs.length === 0)
|
|
7095
|
+
if (inputs.length === 0) {
|
|
7096
|
+
if (allInputs.length > 0)
|
|
7097
|
+
result.deferred = true;
|
|
6986
7098
|
return result;
|
|
7099
|
+
}
|
|
6987
7100
|
const batches = [];
|
|
6988
7101
|
for (let i = 0;i < inputs.length; i += MAP_BATCH_SIZE) {
|
|
6989
7102
|
batches.push({ inputs: inputs.slice(i, i + MAP_BATCH_SIZE), isOmissionRetry: false });
|
|
@@ -7009,6 +7122,10 @@ async function mapMemories(args) {
|
|
|
7009
7122
|
if (!batch)
|
|
7010
7123
|
break;
|
|
7011
7124
|
const outcome = await mapOneBatch(args, batch.inputs, sliceMs, abortController.signal);
|
|
7125
|
+
if (outcome.failure) {
|
|
7126
|
+
result.failure = outcome.failure.error;
|
|
7127
|
+
result.failureStage = outcome.failure.stage;
|
|
7128
|
+
}
|
|
7012
7129
|
const committed = outcome.mapped + outcome.independent;
|
|
7013
7130
|
runLeaseGuardedWrite(args.db, args.holderId, args.leaseKey, () => {
|
|
7014
7131
|
const committedIds = new Set(outcome.committedIds);
|
|
@@ -7072,6 +7189,7 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
7072
7189
|
const startedAt = Date.now();
|
|
7073
7190
|
let budgetFinalized = false;
|
|
7074
7191
|
let failedCompletion;
|
|
7192
|
+
let stage = "child-start";
|
|
7075
7193
|
const onBudgetUpdate = (state) => {
|
|
7076
7194
|
budgetFinalized ||= state.finalizeFired;
|
|
7077
7195
|
args.onBudgetUpdate?.(state);
|
|
@@ -7093,15 +7211,19 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
7093
7211
|
fallbackModels: args.fallbackModels,
|
|
7094
7212
|
timeoutMs: sliceMs,
|
|
7095
7213
|
signal,
|
|
7214
|
+
onOpened: () => {
|
|
7215
|
+
stage = "prompt";
|
|
7216
|
+
},
|
|
7096
7217
|
onFailureOutput: (completion) => {
|
|
7097
7218
|
failedCompletion = completion;
|
|
7098
7219
|
},
|
|
7099
|
-
parse: (text, completion) =>
|
|
7220
|
+
parse: (text, completion) => parseMapMemoriesCompletion(text, completion, new Set(batch.map((memory) => memory.id)))
|
|
7100
7221
|
});
|
|
7101
7222
|
recordInvocation2(args, startedAt, {
|
|
7102
7223
|
status: "completed",
|
|
7103
7224
|
messages: run.completion.messages ?? []
|
|
7104
7225
|
});
|
|
7226
|
+
stage = "apply";
|
|
7105
7227
|
const outcome = await applyParsedBatchMappings(args, batch, run.validated, budgetFinalized, true);
|
|
7106
7228
|
logBatchUsage(run.completion.messages ?? [], outcome.mapped + outcome.independent, startedAt);
|
|
7107
7229
|
const returnedIds = new Set(outcome.committedIds);
|
|
@@ -7126,6 +7248,7 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
7126
7248
|
agentSessionId = typeof created?.id === "string" ? created.id : null;
|
|
7127
7249
|
if (!agentSessionId)
|
|
7128
7250
|
throw new Error("Could not create map-memories session.");
|
|
7251
|
+
stage = "prompt";
|
|
7129
7252
|
const run = await promptSyncWithValidatedOutputRetry(client, {
|
|
7130
7253
|
path: { id: agentSessionId },
|
|
7131
7254
|
query: { directory: args.sessionDirectory },
|
|
@@ -7153,18 +7276,11 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
7153
7276
|
preferResponseOnMissingData: true
|
|
7154
7277
|
});
|
|
7155
7278
|
},
|
|
7156
|
-
validateOutput: (messages) =>
|
|
7157
|
-
if (hasLengthCappedOutput(messages)) {
|
|
7158
|
-
throw new Error("map-memories returned length-capped output");
|
|
7159
|
-
}
|
|
7160
|
-
const text = currentManifest(assistantText(messages));
|
|
7161
|
-
if (!text)
|
|
7162
|
-
throw new Error("map-memories returned no output");
|
|
7163
|
-
return validateMapMemoriesManifest(text, new Set(batch.map((memory) => memory.id)));
|
|
7164
|
-
}
|
|
7279
|
+
validateOutput: (messages) => validateClientMapMemories(messages, new Set(batch.map((memory) => memory.id)))
|
|
7165
7280
|
});
|
|
7166
7281
|
promptSettled = true;
|
|
7167
7282
|
recordInvocation2(args, startedAt, { status: "completed", messages: run.output });
|
|
7283
|
+
stage = "apply";
|
|
7168
7284
|
const outcome = await applyParsedBatchMappings(args, batch, run.validated, budgetFinalized, true);
|
|
7169
7285
|
logBatchUsage(run.output, outcome.mapped + outcome.independent, startedAt);
|
|
7170
7286
|
const returnedIds = new Set(outcome.committedIds);
|
|
@@ -7193,6 +7309,8 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
7193
7309
|
return {
|
|
7194
7310
|
...outcome,
|
|
7195
7311
|
failure: {
|
|
7312
|
+
error,
|
|
7313
|
+
stage,
|
|
7196
7314
|
class: isTimeoutClassError2(error) ? "timeout" : "other",
|
|
7197
7315
|
elapsedMs: Date.now() - startedAt
|
|
7198
7316
|
}
|
|
@@ -8712,7 +8830,7 @@ var VERIFY_SYSTEM_PROMPT = `You are a memory verifier for the magic-context syst
|
|
|
8712
8830
|
|
|
8713
8831
|
Each memory below comes with its backing file(s) — the code it makes a claim about. For EACH memory: use the provided git diff as evidence when present. If no diff is supplied, read its backing files (you may read more if needed) and decide whether the memory is still accurate.
|
|
8714
8832
|
|
|
8715
|
-
Tools (read-only): read, grep, glob. Request line ranges
|
|
8833
|
+
Tools (read-only): read, grep, glob, plus any available AFT navigation tools. Use at most 3 tool calls per memory, including searches and reads. Start with the backing files and likely identifier matches. Never read the same file twice in a batch; reuse evidence. Request short useful line ranges unless the claim concerns the file as a whole. If evidence is insufficient when the call budget runs out, SKIP that memory; uncertainty never justifies archival. You change nothing.
|
|
8716
8834
|
|
|
8717
8835
|
Decide ONE of four outcomes per memory:
|
|
8718
8836
|
- VERIFIED — still accurate. Keep it as-is.
|
|
@@ -8724,7 +8842,7 @@ UPDATE and ARCHIVE are ONLY for claims a repository file can falsify, such as an
|
|
|
8724
8842
|
|
|
8725
8843
|
BE CONSERVATIVE ABOUT ARCHIVING. Wrong archival of a TRUE memory is the worst possible outcome — far worse than leaving a slightly-stale memory. If you cannot find the code, or you are unsure, or it might still be true somewhere you didn't look: mark it VERIFIED or SKIPPED, never archived. Archive ONLY when you have positive evidence the code contradicts a code fact.
|
|
8726
8844
|
|
|
8727
|
-
Output ONE XML manifest
|
|
8845
|
+
Output ONE XML manifest and NOTHING else — no narration or reasoning. Open <verify> before investigating and emit each complete verdict immediately before investigating the next memory, so interruption preserves finished work. Close </verify> when done:
|
|
8728
8846
|
<verify>
|
|
8729
8847
|
<verified id="N" files="path/a.ts,path/b.ts"/>
|
|
8730
8848
|
<update id="M" files="path/c.ts">corrected present-tense content</update>
|
|
@@ -8737,17 +8855,24 @@ Rules:
|
|
|
8737
8855
|
- Every input memory id MUST appear exactly once, in exactly one of verified/update/archive/skip.
|
|
8738
8856
|
- files = the COMPLETE current backing set (repo-relative, comma-separated). It may differ from the given mapping if a file moved — record what you actually verified against.
|
|
8739
8857
|
- Default to VERIFIED. skip when code cannot decide the claim. update and archive are the exceptions, not the norm.`;
|
|
8858
|
+
async function seedVerifyCandidates(memories, directory) {
|
|
8859
|
+
const seeded = await seedIdentifierCandidates(memories.map((m) => ({ ...m, candidates: [] })), directory);
|
|
8860
|
+
return memories.map((m, i) => ({ ...m, candidates: seeded[i].candidates }));
|
|
8861
|
+
}
|
|
8740
8862
|
function buildVerifyPrompt(projectPath, memories, evidence) {
|
|
8741
8863
|
const list = memories.map((m) => `[${m.id}] ${m.category}
|
|
8742
8864
|
Content: ${m.content}
|
|
8743
|
-
Backing files: ${m.mappedFiles.join(", ")}
|
|
8865
|
+
Backing files: ${m.mappedFiles.join(", ")}${m.candidates?.length ? `
|
|
8866
|
+
Likely files (identifier matches, confirm before using): ${m.candidates.join(", ")}` : ""}`).join(`
|
|
8744
8867
|
|
|
8745
8868
|
`);
|
|
8746
8869
|
return `## Verify these memories against the code
|
|
8747
8870
|
|
|
8748
8871
|
Project: ${projectPath}
|
|
8749
8872
|
|
|
8750
|
-
|
|
8873
|
+
When available in this session, use aft_outline to outline the backing file and aft_zoom on the claimed symbol (or aft_search to locate it), instead of paging through whole files. Read a whole file only when the claim is about the file as a whole. Otherwise use the available read-only tools.
|
|
8874
|
+
|
|
8875
|
+
${evidence ? "The git diff below is the evidence. If changed hunks do not touch a claim, mark it verified without opening files. Open files only when a diff suggests the claim may have changed. A rename or deletion requires an update or archive when positively supported; do not archive on uncertainty." : "Check each memory's claim against its backing files."} Decide verified / update / archive / skip (default verified; behavioral directives only permit verified or skip), then output ONE <verify> manifest covering every id.
|
|
8751
8876
|
|
|
8752
8877
|
<memories>
|
|
8753
8878
|
${list}
|
|
@@ -8824,13 +8949,57 @@ function validateVerifyManifest(text, expectedIds) {
|
|
|
8824
8949
|
assertNoDuplicateManifestIds(ids.filter((id) => expectedIds.has(id)), "verify");
|
|
8825
8950
|
return parsed;
|
|
8826
8951
|
}
|
|
8952
|
+
function parsePartialVerifyManifest(text, expectedIds) {
|
|
8953
|
+
const out = { verified: [], updated: [], archived: [], skipped: [] };
|
|
8954
|
+
const start = text.lastIndexOf("<verify>");
|
|
8955
|
+
if (start < 0)
|
|
8956
|
+
return out;
|
|
8957
|
+
const entries = new Map;
|
|
8958
|
+
const conflicts = new Set;
|
|
8959
|
+
for (const match of text.slice(start).matchAll(/<(?:verified|archive|skip)\b[^<>]*\/>|<update\b[^<>]*>[\s\S]*?<\/update>/g)) {
|
|
8960
|
+
try {
|
|
8961
|
+
const parsed = parseVerifyManifest(`<verify>${match[0]}</verify>`);
|
|
8962
|
+
const id = verifyIds(parsed)[0];
|
|
8963
|
+
if (!expectedIds.has(id) || conflicts.has(id))
|
|
8964
|
+
continue;
|
|
8965
|
+
const previous = entries.get(id);
|
|
8966
|
+
if (previous && JSON.stringify(previous) !== JSON.stringify(parsed)) {
|
|
8967
|
+
entries.delete(id);
|
|
8968
|
+
conflicts.add(id);
|
|
8969
|
+
} else
|
|
8970
|
+
entries.set(id, parsed);
|
|
8971
|
+
} catch {}
|
|
8972
|
+
}
|
|
8973
|
+
for (const parsed of entries.values()) {
|
|
8974
|
+
out.verified.push(...parsed.verified);
|
|
8975
|
+
out.updated.push(...parsed.updated);
|
|
8976
|
+
out.archived.push(...parsed.archived);
|
|
8977
|
+
out.skipped.push(...parsed.skipped);
|
|
8978
|
+
}
|
|
8979
|
+
return out;
|
|
8980
|
+
}
|
|
8827
8981
|
|
|
8828
8982
|
// src/features/magic-context/dreamer/verify.ts
|
|
8829
|
-
var VERIFY_BATCH_SIZE =
|
|
8983
|
+
var VERIFY_BATCH_SIZE = 5;
|
|
8984
|
+
var VERIFY_TOKENS_PER_MEMORY = 1e5;
|
|
8985
|
+
var VERIFY_RUN_TOKEN_BUDGET = 2500000;
|
|
8986
|
+
var VERIFY_RUN_SLICE_MS = 240000;
|
|
8987
|
+
function verifyBatchTokenBudget(size, configured) {
|
|
8988
|
+
return Math.min(configured ?? Number.MAX_SAFE_INTEGER, size * VERIFY_TOKENS_PER_MEMORY);
|
|
8989
|
+
}
|
|
8990
|
+
function verifyAssistantText(messages) {
|
|
8991
|
+
const text = messages.filter((m) => isRecord(m) && (m.role === "assistant" || isRecord(m.info) && m.info.role === "assistant")).map((m) => extractLatestAssistantText([m]) || (isRecord(m) && Array.isArray(m.content) ? m.content.filter(isRecord).filter((p) => p.type === "text").map((p) => p.text).join(`
|
|
8992
|
+
`) : "")).join(`
|
|
8993
|
+
`);
|
|
8994
|
+
if (!text.trim())
|
|
8995
|
+
return null;
|
|
8996
|
+
const start = text.lastIndexOf("<verify>");
|
|
8997
|
+
return start >= 0 ? text.slice(start) : text;
|
|
8998
|
+
}
|
|
8830
8999
|
var IDENTICAL_PROVIDER_FAILURE_BATCH_LIMIT = 2;
|
|
8831
|
-
var VERIFY_BATCH_FLOOR_MS =
|
|
8832
|
-
function computeVerifyBatchSliceMs(remainingMs,
|
|
8833
|
-
return Math.min(remainingMs,
|
|
9000
|
+
var VERIFY_BATCH_FLOOR_MS = 30000;
|
|
9001
|
+
function computeVerifyBatchSliceMs(remainingMs, _batchesRemaining) {
|
|
9002
|
+
return Math.min(remainingMs, VERIFY_RUN_SLICE_MS);
|
|
8834
9003
|
}
|
|
8835
9004
|
function closeBroadCycle(args, cycleStartAt) {
|
|
8836
9005
|
if (!args.forceBroad || cycleStartAt === undefined)
|
|
@@ -8854,6 +9023,7 @@ async function runVerify(args) {
|
|
|
8854
9023
|
}
|
|
8855
9024
|
async function runVerifyWithCooldown(args) {
|
|
8856
9025
|
const runStartedAt = Date.now();
|
|
9026
|
+
const sliceDeadline = runStartedAt + VERIFY_RUN_SLICE_MS;
|
|
8857
9027
|
const result = {
|
|
8858
9028
|
verified: 0,
|
|
8859
9029
|
updated: 0,
|
|
@@ -8896,16 +9066,31 @@ async function runVerifyWithCooldown(args) {
|
|
|
8896
9066
|
let consecutiveProviderFailures = 0;
|
|
8897
9067
|
let priorProviderFailureFingerprint = null;
|
|
8898
9068
|
let lastProviderFailure = null;
|
|
9069
|
+
let runSpent = 0;
|
|
9070
|
+
const runTokenBudget = Math.min(args.tokenBudget ?? VERIFY_RUN_TOKEN_BUDGET, VERIFY_RUN_TOKEN_BUDGET);
|
|
8899
9071
|
try {
|
|
8900
9072
|
for (let i = 0;i < batches.length; i += 1) {
|
|
8901
|
-
const remainingMs = Math.max(0, args.deadline - Date.now());
|
|
9073
|
+
const remainingMs = Math.max(0, Math.min(args.deadline, sliceDeadline) - Date.now());
|
|
8902
9074
|
if (remainingMs < VERIFY_BATCH_FLOOR_MS) {
|
|
8903
9075
|
result.stopReason = "deadline";
|
|
8904
9076
|
log2(`[dreamer] ${args.forceBroad ? "verify-broad" : "verify"}: stopping before batch ${i + 1}/${batches.length} — remaining budget ${remainingMs}ms is below the ${VERIFY_BATCH_FLOOR_MS}ms batch floor`);
|
|
8905
9077
|
break;
|
|
8906
9078
|
}
|
|
8907
9079
|
const sliceMs = computeVerifyBatchSliceMs(remainingMs, batches.length - i);
|
|
8908
|
-
|
|
9080
|
+
if (runSpent >= runTokenBudget) {
|
|
9081
|
+
result.stopReason = "token-budget";
|
|
9082
|
+
break;
|
|
9083
|
+
}
|
|
9084
|
+
let batchSpent = 0;
|
|
9085
|
+
const counts = await verifyOneBatch({
|
|
9086
|
+
...args,
|
|
9087
|
+
tokenBudget: runTokenBudget - runSpent,
|
|
9088
|
+
onBudgetUpdate: (state) => {
|
|
9089
|
+
runSpent += Math.max(0, state.spent - batchSpent);
|
|
9090
|
+
batchSpent = Math.max(batchSpent, state.spent);
|
|
9091
|
+
args.onBudgetUpdate?.(state);
|
|
9092
|
+
}
|
|
9093
|
+
}, batches[i], sliceMs, abortController.signal);
|
|
8909
9094
|
result.verified += counts.verified;
|
|
8910
9095
|
result.updated += counts.updated;
|
|
8911
9096
|
result.archived += counts.archived;
|
|
@@ -8915,6 +9100,10 @@ async function runVerifyWithCooldown(args) {
|
|
|
8915
9100
|
result.remaining -= batchProcessed;
|
|
8916
9101
|
result.batches += 1;
|
|
8917
9102
|
args.onProgress?.(result.verified + result.updated + result.archived + result.skipped + result.refused, result.refused);
|
|
9103
|
+
if (counts.tokenLimited) {
|
|
9104
|
+
result.stopReason = "token-budget";
|
|
9105
|
+
break;
|
|
9106
|
+
}
|
|
8918
9107
|
if (counts.timedOut) {
|
|
8919
9108
|
result.stopReason = "batch-timeout";
|
|
8920
9109
|
log2(`[dreamer] ${args.forceBroad ? "verify-broad" : "verify"}: batch ${i + 1}/${batches.length} timed out after its ${sliceMs}ms slice; stopping with ${result.remaining} remaining`);
|
|
@@ -8949,18 +9138,41 @@ async function runVerifyWithCooldown(args) {
|
|
|
8949
9138
|
}
|
|
8950
9139
|
}
|
|
8951
9140
|
async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
9141
|
+
const batchController = new AbortController;
|
|
9142
|
+
const abort = () => batchController.abort(signal.reason);
|
|
9143
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
9144
|
+
if (signal.aborted)
|
|
9145
|
+
abort();
|
|
9146
|
+
const timer = setTimeout(() => batchController.abort(new Error(`verify slice timed out after ${sliceMs}ms`)), sliceMs);
|
|
9147
|
+
const batchSignal = batchController.signal;
|
|
9148
|
+
const tokenBudget = verifyBatchTokenBudget(batch.length, args.tokenBudget);
|
|
8952
9149
|
let agentSessionId = null;
|
|
9150
|
+
let hiddenSessionId = null;
|
|
8953
9151
|
let promptSettled = false;
|
|
8954
9152
|
const startedAt = Date.now();
|
|
8955
9153
|
let budgetFinalized = false;
|
|
9154
|
+
let failedCompletion;
|
|
9155
|
+
let headAtPrompt = null;
|
|
8956
9156
|
const onBudgetUpdate = (state) => {
|
|
8957
9157
|
budgetFinalized ||= state.finalizeFired;
|
|
8958
|
-
args.onBudgetUpdate?.(
|
|
9158
|
+
args.onBudgetUpdate?.({
|
|
9159
|
+
...state,
|
|
9160
|
+
...hiddenSessionId ? { sessionId: hiddenSessionId } : {}
|
|
9161
|
+
});
|
|
9162
|
+
};
|
|
9163
|
+
const reportUsage = (messages, sessionId, fallbackSpent = 0) => {
|
|
9164
|
+
const usage = sumTokensFromChildMessages(messages);
|
|
9165
|
+
onBudgetUpdate({
|
|
9166
|
+
spent: Math.max(fallbackSpent, usage.input + usage.cacheRead + usage.cacheWrite),
|
|
9167
|
+
finalizeFired: budgetFinalized,
|
|
9168
|
+
...sessionId ? { sessionId } : {}
|
|
9169
|
+
});
|
|
8959
9170
|
};
|
|
8960
9171
|
try {
|
|
8961
|
-
|
|
8962
|
-
const evidence = !args.forceBroad && batch.every((m) => m.verifiedAt) ? await buildVerifyDiffEvidence(args.sessionDirectory, batch) : null;
|
|
8963
|
-
const prompt = buildVerifyPrompt(args.projectIdentity, batch, evidence);
|
|
9172
|
+
headAtPrompt = await raceWithSignal(readGitHead(args.sessionDirectory), batchSignal);
|
|
9173
|
+
const evidence = !args.forceBroad && batch.every((m) => m.verifiedAt) ? await raceWithSignal(buildVerifyDiffEvidence(args.sessionDirectory, batch), batchSignal) : null;
|
|
9174
|
+
const prompt = buildVerifyPrompt(args.projectIdentity, await raceWithSignal(seedVerifyCandidates(batch, args.sessionDirectory), batchSignal), evidence);
|
|
9175
|
+
batchSignal.throwIfAborted();
|
|
8964
9176
|
if (args.hiddenCompletionExecutor) {
|
|
8965
9177
|
const run = await runHiddenSingleShotPrompt({
|
|
8966
9178
|
executor: args.hiddenCompletionExecutor,
|
|
@@ -8971,41 +9183,53 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
8971
9183
|
prompt,
|
|
8972
9184
|
title: "magic-context-dream-verify",
|
|
8973
9185
|
callContext: "dreamer:verify",
|
|
8974
|
-
metadata: { tokenBudget
|
|
9186
|
+
metadata: { tokenBudget, onBudgetUpdate },
|
|
8975
9187
|
model: args.model,
|
|
8976
9188
|
fallbackModels: args.fallbackModels,
|
|
8977
9189
|
language: args.language,
|
|
8978
9190
|
timeoutMs: sliceMs,
|
|
8979
|
-
signal,
|
|
9191
|
+
signal: batchSignal,
|
|
9192
|
+
onFailureOutput: (completion) => {
|
|
9193
|
+
failedCompletion = completion;
|
|
9194
|
+
},
|
|
9195
|
+
onOpened: (sessionId) => {
|
|
9196
|
+
hiddenSessionId = sessionId;
|
|
9197
|
+
onBudgetUpdate({ spent: 0, finalizeFired: false, sessionId });
|
|
9198
|
+
},
|
|
8980
9199
|
parse: (text, completion) => {
|
|
8981
9200
|
const providerFailure = providerOutputFailureFromInvalidManifest(completion.messages ?? [], text);
|
|
8982
9201
|
if (providerFailure)
|
|
8983
9202
|
throw providerFailure;
|
|
8984
|
-
|
|
9203
|
+
const manifest = verifyAssistantText(completion.messages ?? []) ?? (text.trim() ? text : null);
|
|
9204
|
+
if (!manifest)
|
|
9205
|
+
throw new Error("verify returned no output");
|
|
9206
|
+
return validateVerifyManifest(manifest, new Set(batch.map((memory) => memory.id)));
|
|
8985
9207
|
}
|
|
8986
9208
|
});
|
|
8987
9209
|
recordInvocation4(args, startedAt, {
|
|
8988
9210
|
status: "completed",
|
|
8989
9211
|
messages: run.completion.messages ?? []
|
|
8990
9212
|
});
|
|
8991
|
-
|
|
9213
|
+
reportUsage(run.completion.messages ?? [], run.childSessionId, run.completion.usage.input + (run.completion.usage.cacheRead ?? 0) + (run.completion.usage.cacheWrite ?? 0));
|
|
9214
|
+
return await applyParsedVerifyManifest(args, batch, run.validated, evidence?.head ?? headAtPrompt, budgetFinalized);
|
|
8992
9215
|
}
|
|
8993
9216
|
const client = args.client;
|
|
8994
9217
|
if (!client)
|
|
8995
9218
|
throw new Error("verify requires a client or hidden completion executor");
|
|
8996
|
-
const createResponse = await createChildSessionWithFence({
|
|
9219
|
+
const createResponse = await raceWithSignal(createChildSessionWithFence({
|
|
8997
9220
|
client,
|
|
8998
9221
|
db: args.db,
|
|
8999
9222
|
parentSessionId: args.parentSessionId,
|
|
9000
9223
|
title: args.forceBroad ? "magic-context-dream-verify-broad" : "magic-context-dream-verify",
|
|
9001
9224
|
directory: args.sessionDirectory
|
|
9002
|
-
});
|
|
9225
|
+
}), batchSignal);
|
|
9003
9226
|
const created = normalizeSDKResponse(createResponse, null, {
|
|
9004
9227
|
preferResponseOnMissingData: true
|
|
9005
9228
|
});
|
|
9006
9229
|
agentSessionId = typeof created?.id === "string" ? created.id : null;
|
|
9007
9230
|
if (!agentSessionId)
|
|
9008
9231
|
throw new Error("Could not create verify session.");
|
|
9232
|
+
onBudgetUpdate({ spent: 0, finalizeFired: false, sessionId: agentSessionId });
|
|
9009
9233
|
const run = await promptSyncWithValidatedOutputRetry(client, {
|
|
9010
9234
|
path: { id: agentSessionId },
|
|
9011
9235
|
query: { directory: args.sessionDirectory },
|
|
@@ -9017,11 +9241,11 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
9017
9241
|
}
|
|
9018
9242
|
}, {
|
|
9019
9243
|
transport: createPromptAsyncTransport(client, agentSessionId, {
|
|
9020
|
-
tokenBudget
|
|
9244
|
+
tokenBudget,
|
|
9021
9245
|
onBudgetUpdate
|
|
9022
9246
|
}),
|
|
9023
9247
|
timeoutMs: sliceMs,
|
|
9024
|
-
signal,
|
|
9248
|
+
signal: batchSignal,
|
|
9025
9249
|
fallbackModels: args.fallbackModels,
|
|
9026
9250
|
callContext: "dreamer:verify",
|
|
9027
9251
|
fetchOutput: async () => {
|
|
@@ -9037,7 +9261,7 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
9037
9261
|
if (hasLengthCappedOutput(messages)) {
|
|
9038
9262
|
throw new Error("verify returned length-capped output");
|
|
9039
9263
|
}
|
|
9040
|
-
const text =
|
|
9264
|
+
const text = verifyAssistantText(messages);
|
|
9041
9265
|
if (!text)
|
|
9042
9266
|
throw new Error("verify returned no output");
|
|
9043
9267
|
const providerFailure = providerOutputFailureFromInvalidManifest(messages, text);
|
|
@@ -9048,27 +9272,31 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
9048
9272
|
});
|
|
9049
9273
|
promptSettled = true;
|
|
9050
9274
|
recordInvocation4(args, startedAt, { status: "completed", messages: run.output });
|
|
9275
|
+
reportUsage(run.output, agentSessionId);
|
|
9051
9276
|
return await applyParsedVerifyManifest(args, batch, run.validated, evidence?.head ?? headAtPrompt, budgetFinalized);
|
|
9052
9277
|
} catch (error) {
|
|
9053
9278
|
const desc = describeError(error);
|
|
9054
9279
|
const providerFailure = error instanceof DreamerProviderOutputFailureError ? error : undefined;
|
|
9055
9280
|
const promptFailure = getPromptFailureDetail(error);
|
|
9056
9281
|
log2(`[dreamer] verify batch ${providerFailure ? "provider failure" : "failed"}: ${desc.brief}`, desc.stackHead ? { stackHead: desc.stackHead } : undefined);
|
|
9282
|
+
const messages = failedCompletion?.messages ?? await readFailedChildMessages(args.client, agentSessionId, args.sessionDirectory) ?? [];
|
|
9283
|
+
reportUsage(messages, hiddenSessionId ?? agentSessionId, failedCompletion?.usage.input ?? 0);
|
|
9057
9284
|
recordInvocation4(args, startedAt, {
|
|
9058
9285
|
status: failedInvocationStatus(error),
|
|
9059
9286
|
error,
|
|
9060
|
-
messages
|
|
9287
|
+
messages
|
|
9061
9288
|
});
|
|
9062
|
-
if (error instanceof DreamerModuleFailureError ||
|
|
9289
|
+
if (error instanceof DreamerModuleFailureError || signal.aborted)
|
|
9063
9290
|
throw error;
|
|
9064
|
-
|
|
9291
|
+
const interrupted = batchSignal.aborted || error instanceof DreamTokenBudgetExceeded || promptFailure?.failureClass === "provider_timeout" || isPromptTimeoutError(error);
|
|
9292
|
+
if (interrupted) {
|
|
9293
|
+
const text = verifyAssistantText(messages) ?? failedCompletion?.text ?? "";
|
|
9294
|
+
const recovered = parsePartialVerifyManifest(text, new Set(batch.map((m) => m.id)));
|
|
9295
|
+
const counts = await applyParsedVerifyManifest(args, batch, recovered, headAtPrompt, true);
|
|
9065
9296
|
return {
|
|
9066
|
-
|
|
9067
|
-
|
|
9068
|
-
|
|
9069
|
-
skipped: 0,
|
|
9070
|
-
refused: 0,
|
|
9071
|
-
timedOut: true
|
|
9297
|
+
...counts,
|
|
9298
|
+
timedOut: !(error instanceof DreamTokenBudgetExceeded),
|
|
9299
|
+
tokenLimited: error instanceof DreamTokenBudgetExceeded
|
|
9072
9300
|
};
|
|
9073
9301
|
}
|
|
9074
9302
|
if (promptFailure !== null && promptFailure.failureClass !== "parse_failed" && !providerFailure)
|
|
@@ -9083,7 +9311,7 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
9083
9311
|
};
|
|
9084
9312
|
} finally {
|
|
9085
9313
|
if (agentSessionId && args.client)
|
|
9086
|
-
await teardownChildSession({
|
|
9314
|
+
await raceWithSignal(teardownChildSession({
|
|
9087
9315
|
client: args.client,
|
|
9088
9316
|
sessionId: agentSessionId,
|
|
9089
9317
|
sessionDirectory: args.sessionDirectory,
|
|
@@ -9091,7 +9319,9 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
9091
9319
|
privacySensitive: true,
|
|
9092
9320
|
context: "[dreamer] verify",
|
|
9093
9321
|
log: log2
|
|
9094
|
-
});
|
|
9322
|
+
}), batchSignal).catch(() => {});
|
|
9323
|
+
clearTimeout(timer);
|
|
9324
|
+
signal.removeEventListener("abort", abort);
|
|
9095
9325
|
}
|
|
9096
9326
|
}
|
|
9097
9327
|
async function applyParsedVerifyManifest(args, batch, parsed, headAtPrompt, budgetFinalized = false) {
|
|
@@ -9118,7 +9348,7 @@ async function applyParsedVerifyManifest(args, batch, parsed, headAtPrompt, budg
|
|
|
9118
9348
|
throw new Error(`verify manifest covers ${validIds.length}/${batch.length} batch ids after filtering unknown entries; rejecting mostly-wrong manifest`);
|
|
9119
9349
|
}
|
|
9120
9350
|
if (budgetFinalized && validIds.length < batch.length) {
|
|
9121
|
-
log2(`[dreamer] verify: accepted partial manifest after
|
|
9351
|
+
log2(`[dreamer] verify: accepted partial manifest after investigation stop: ${validIds.length}/${batch.length}`);
|
|
9122
9352
|
}
|
|
9123
9353
|
if (validIds.length === 0) {
|
|
9124
9354
|
return { verified: 0, updated: 0, archived: 0, skipped: 0, refused: 0 };
|
|
@@ -9353,10 +9583,10 @@ function dreamRunFailureDetail(error) {
|
|
|
9353
9583
|
child_session_id: null
|
|
9354
9584
|
};
|
|
9355
9585
|
}
|
|
9356
|
-
const localRefusal = error instanceof HiddenCompletionRefusal;
|
|
9586
|
+
const localRefusal = error instanceof HiddenCompletionRefusal || error instanceof DreamerModuleFailureError;
|
|
9357
9587
|
const providerFailure = error instanceof Error && error.name === "DreamerProviderOutputFailureError";
|
|
9358
9588
|
return {
|
|
9359
|
-
failure_class: localRefusal ? "local_refusal" : providerFailure ? "provider_error" : /no models?|model chain is empty/i.test(message) ? "no_models" : "unknown",
|
|
9589
|
+
failure_class: localRefusal ? "local_refusal" : providerFailure ? "provider_error" : /lease_(?:lost|expired)|Dream lease (?:lost|unavailable)/i.test(message) ? "child_aborted" : /no models?|model chain is empty/i.test(message) ? "no_models" : "unknown",
|
|
9360
9590
|
model_attempted: null,
|
|
9361
9591
|
models_tried: [],
|
|
9362
9592
|
provider_error: providerFailure ? sanitizeDiagnosticText(message).slice(0, 500) : null,
|
|
@@ -9367,6 +9597,10 @@ function dreamRunFailureDetail(error) {
|
|
|
9367
9597
|
} : {}
|
|
9368
9598
|
};
|
|
9369
9599
|
}
|
|
9600
|
+
function incompleteFailure(error, fallback = "parse_failed") {
|
|
9601
|
+
const detail = dreamRunFailureDetail(error);
|
|
9602
|
+
return detail.failure_class === "unknown" ? { ...detail, failure_class: fallback } : detail;
|
|
9603
|
+
}
|
|
9370
9604
|
function classifyFailure(error) {
|
|
9371
9605
|
const described = describeError(error);
|
|
9372
9606
|
const brief = described.brief;
|
|
@@ -9526,6 +9760,7 @@ function createDreamTaskExecutor(deps) {
|
|
|
9526
9760
|
const { db, projectIdentity, holderId, leaseKey } = ctx;
|
|
9527
9761
|
deps.client?.resetDreamTokenBudget?.(config.task);
|
|
9528
9762
|
const startedAt = Date.now();
|
|
9763
|
+
const effectiveTokenBudget = config.task === "verify" || config.task === "verify-broad" ? Math.min(config.tokenBudget ?? VERIFY_RUN_TOKEN_BUDGET, VERIFY_RUN_TOKEN_BUDGET) : config.tokenBudget;
|
|
9529
9764
|
const leaseAcquisition = ctx.leaseAcquisition ?? acquireLeaseWithAcquisition(db, holderId, leaseKey) ?? (() => {
|
|
9530
9765
|
throw new Error("Dream lease unavailable during executor setup");
|
|
9531
9766
|
})();
|
|
@@ -9573,7 +9808,7 @@ function createDreamTaskExecutor(deps) {
|
|
|
9573
9808
|
if (state.sessionId) {
|
|
9574
9809
|
const previous = childSpending.get(state.sessionId) ?? 0;
|
|
9575
9810
|
budgetSpent += Math.max(0, state.spent - previous);
|
|
9576
|
-
childSpending.set(state.sessionId, state.spent);
|
|
9811
|
+
childSpending.set(state.sessionId, Math.max(previous, state.spent));
|
|
9577
9812
|
} else
|
|
9578
9813
|
budgetSpent = Math.max(budgetSpent, state.spent);
|
|
9579
9814
|
budgetFinalized ||= state.finalizeFired;
|
|
@@ -9600,9 +9835,15 @@ function createDreamTaskExecutor(deps) {
|
|
|
9600
9835
|
failure: extra?.failure ?? dreamRunFailureDetail(error ?? "unknown dreamer failure")
|
|
9601
9836
|
} : {},
|
|
9602
9837
|
...extra?.progress ? { progress: extra.progress } : {},
|
|
9603
|
-
...
|
|
9838
|
+
...childSpending.size ? {
|
|
9839
|
+
children: [...childSpending].map(([sessionId, promptTokens]) => ({
|
|
9840
|
+
sessionId,
|
|
9841
|
+
promptTokens
|
|
9842
|
+
}))
|
|
9843
|
+
} : {},
|
|
9844
|
+
...effectiveTokenBudget ? {
|
|
9604
9845
|
tokenBudget: {
|
|
9605
|
-
budget:
|
|
9846
|
+
budget: effectiveTokenBudget,
|
|
9606
9847
|
spent: budgetSpent,
|
|
9607
9848
|
finalizeFired: budgetFinalized,
|
|
9608
9849
|
banked: extra?.banked ?? processedDreamTaskItems(backlogAtStart.pending, (extra?.backlogAfter ?? getDreamTaskBacklog(db, projectIdentity, config.task)).pending)
|
|
@@ -9691,8 +9932,13 @@ function createDreamTaskExecutor(deps) {
|
|
|
9691
9932
|
});
|
|
9692
9933
|
log2(`[dreamer] compress-cues: compressed=${result.compressed} skipped=${result.skipped} chunks=${result.chunks} remaining=${result.remaining}`);
|
|
9693
9934
|
if (!result.complete) {
|
|
9694
|
-
|
|
9695
|
-
|
|
9935
|
+
if (result.stopReason === "deadline" && result.chunks === 0)
|
|
9936
|
+
return skip("compress-cues: insufficient time to start a chunk");
|
|
9937
|
+
const error = `${incompleteMessage(result.remaining)}; ${result.failureStage ? `${result.failureStage}: ` : ""}${result.failure ? describeError(result.failure).brief : `${result.skipped} cues rejected by validation`}`;
|
|
9938
|
+
recordRun("failed", error, {
|
|
9939
|
+
banked: result.compressed,
|
|
9940
|
+
failure: incompleteFailure(result.failure, result.failureStage === "child-start" ? "local_refusal" : result.stopReason === "timeout-circuit-breaker" ? "provider_timeout" : "parse_failed")
|
|
9941
|
+
});
|
|
9696
9942
|
return { status: "failed", transient: true, error };
|
|
9697
9943
|
}
|
|
9698
9944
|
recordRun("completed", null);
|
|
@@ -9738,9 +9984,15 @@ function createDreamTaskExecutor(deps) {
|
|
|
9738
9984
|
});
|
|
9739
9985
|
log2(`[dreamer] map-memories: committed=${result.mapped + result.independent} mapped=${result.mapped} independent=${result.independent} batches=${result.batches} remaining=${result.remaining} complete=${result.complete}${result.stopReason ? ` stop_reason=${result.stopReason}` : ""}`);
|
|
9740
9986
|
if (!result.complete) {
|
|
9987
|
+
if (result.deferred)
|
|
9988
|
+
return skip("map-memories: all pending mappings are in content-keyed retry backoff; no child started");
|
|
9989
|
+
if (result.stopReason === "deadline" && result.batches === 0 && !result.failure)
|
|
9990
|
+
return skip("map-memories: insufficient time to start a batch");
|
|
9741
9991
|
if (result.stopReason === "timeout-circuit-breaker") {
|
|
9742
9992
|
const error = `map-memories starvation: timeout circuit breaker stopped the run with ${result.remaining} remain`;
|
|
9743
|
-
recordRun("failed", error
|
|
9993
|
+
recordRun("failed", error, {
|
|
9994
|
+
failure: incompleteFailure(result.failure, "provider_timeout")
|
|
9995
|
+
});
|
|
9744
9996
|
return { status: "failed", transient: true, error };
|
|
9745
9997
|
}
|
|
9746
9998
|
const processed = result.mapped + result.independent;
|
|
@@ -9749,8 +10001,10 @@ function createDreamTaskExecutor(deps) {
|
|
|
9749
10001
|
recordRun("completed", null, { progress });
|
|
9750
10002
|
return { status: "completed" };
|
|
9751
10003
|
}
|
|
9752
|
-
const error = incompleteMessage(result.remaining);
|
|
9753
|
-
recordRun("failed", error
|
|
10004
|
+
const error = `${incompleteMessage(result.remaining)}; ${result.failureStage ? `${result.failureStage}: ` : ""}${result.failure ? describeError(result.failure).brief : "manifest returned no accepted mapping decisions"}`;
|
|
10005
|
+
recordRun("failed", error, {
|
|
10006
|
+
failure: incompleteFailure(result.failure, result.failureStage === "child-start" ? "local_refusal" : "parse_failed")
|
|
10007
|
+
});
|
|
9754
10008
|
return { status: "failed", transient: true, error };
|
|
9755
10009
|
}
|
|
9756
10010
|
recordRun("completed", null);
|
|
@@ -9780,25 +10034,27 @@ function createDreamTaskExecutor(deps) {
|
|
|
9780
10034
|
});
|
|
9781
10035
|
const processed = result.verified + result.updated + result.archived + result.skipped + result.refused;
|
|
9782
10036
|
const verificationProgress = `${config.task}${config.task === "verify-broad" ? ` cycle ${result.broadCycleStartAt ?? "open"}` : ""}: processed ${processed} (verified ${result.verified}, updated ${result.updated}, archived ${result.archived}, skipped ${result.skipped}, refused ${result.refused}); ${result.remaining} remain`;
|
|
9783
|
-
const broadProgress = config.task === "verify-broad" ? verificationProgress : null;
|
|
9784
10037
|
const backlogAfter = config.task === "verify-broad" ? { pending: result.remaining, total: backlogAtStart.total } : undefined;
|
|
9785
10038
|
if (!result.complete) {
|
|
9786
|
-
if (
|
|
10039
|
+
if (processed > 0) {
|
|
9787
10040
|
recordRun("completed", null, {
|
|
9788
|
-
progress:
|
|
10041
|
+
progress: verificationProgress,
|
|
9789
10042
|
memoryChanges: computeMemoryDelta(memoryBefore),
|
|
9790
10043
|
backlogAfter,
|
|
9791
10044
|
banked: result.verified + result.updated + result.archived
|
|
9792
10045
|
});
|
|
9793
10046
|
return { status: "completed" };
|
|
9794
10047
|
}
|
|
10048
|
+
if (result.stopReason === "deadline")
|
|
10049
|
+
return skip(`${config.task}: insufficient time to start a batch`);
|
|
9795
10050
|
const batchTimedOut = result.stopReason === "batch-timeout";
|
|
9796
10051
|
const error = batchTimedOut ? `${config.task}: a batch timed out within its time slice; ${result.remaining} remain` : incompleteMessage(result.remaining);
|
|
9797
10052
|
recordRun("failed", error, {
|
|
9798
10053
|
progress: verificationProgress,
|
|
9799
10054
|
memoryChanges: computeMemoryDelta(memoryBefore),
|
|
9800
10055
|
backlogAfter,
|
|
9801
|
-
banked: result.verified + result.updated + result.archived
|
|
10056
|
+
banked: result.verified + result.updated + result.archived,
|
|
10057
|
+
failure: incompleteFailure(error, batchTimedOut ? "provider_timeout" : result.stopReason === "token-budget" ? "token_budget" : "parse_failed")
|
|
9802
10058
|
});
|
|
9803
10059
|
return { status: "failed", transient: !batchTimedOut, error };
|
|
9804
10060
|
}
|
|
@@ -9922,6 +10178,7 @@ function createDreamTaskExecutor(deps) {
|
|
|
9922
10178
|
if (retro.skipReason)
|
|
9923
10179
|
return skip(retro.skipReason);
|
|
9924
10180
|
recordRun("completed", null, {
|
|
10181
|
+
progress: retro.noOpReason,
|
|
9925
10182
|
memoryChanges: computeMemoryDelta(memoryBefore),
|
|
9926
10183
|
backlogAfter: retro.retrospectiveWatermarkMs == null ? undefined : getDreamTaskBacklog(db, projectIdentity, "retrospective", {
|
|
9927
10184
|
retrospectiveWatermarkMs: retro.retrospectiveWatermarkMs
|
|
@@ -9929,6 +10186,7 @@ function createDreamTaskExecutor(deps) {
|
|
|
9929
10186
|
});
|
|
9930
10187
|
return {
|
|
9931
10188
|
status: "completed",
|
|
10189
|
+
...retro.noOpReason ? { detail: retro.noOpReason } : {},
|
|
9932
10190
|
schedulePatch: retro.retrospectiveWatermarkMs != null || retro.taskStateJson !== undefined ? {
|
|
9933
10191
|
...retro.retrospectiveWatermarkMs != null ? {
|
|
9934
10192
|
retrospectiveWatermarkMs: retro.retrospectiveWatermarkMs
|
|
@@ -10128,20 +10386,28 @@ async function runRetrospectiveTask(config, ctx, helpers) {
|
|
|
10128
10386
|
const recencyCutoffMs = helpers.invocationStartedAt - recencyDays * RETROSPECTIVE_DAY_MS;
|
|
10129
10387
|
const scan = await readRetrospectiveScanWindow(provider, projectIdentity, watermarkMs, RETROSPECTIVE_OVERLAP_USER_LINES, { usableInputTokens, recencyCutoffMs });
|
|
10130
10388
|
const clearedTaskStateJson = activeOverflow ? writeRetrospectiveOverflowState(taskState.root, null) : undefined;
|
|
10131
|
-
const completedWindow = (retrospectiveWatermarkMs) => ({
|
|
10389
|
+
const completedWindow = (retrospectiveWatermarkMs, noOpReason) => ({
|
|
10132
10390
|
retrospectiveWatermarkMs,
|
|
10133
|
-
...clearedTaskStateJson ? { taskStateJson: clearedTaskStateJson } : {}
|
|
10391
|
+
...clearedTaskStateJson ? { taskStateJson: clearedTaskStateJson } : {},
|
|
10392
|
+
...noOpReason ? { noOpReason } : {}
|
|
10134
10393
|
});
|
|
10135
10394
|
const messages = withGlobalOrdinals(scan.messages);
|
|
10136
10395
|
const userMessages = messages.filter((message) => message.role === "user" && message.text.trim().length > 0);
|
|
10137
10396
|
if (userMessages.length === 0) {
|
|
10138
|
-
|
|
10139
|
-
|
|
10397
|
+
const noOpReason = "no reply-following user lines";
|
|
10398
|
+
log2(`[dreamer] retrospective: ${noOpReason}`);
|
|
10399
|
+
return completedWindow(scan.maxScannedTs, noOpReason);
|
|
10140
10400
|
}
|
|
10141
|
-
const
|
|
10142
|
-
if (
|
|
10401
|
+
const newUserOrdinals = new Set(userMessages.filter((message) => message.ts > watermarkMs).map((message) => message.ordinal));
|
|
10402
|
+
if (newUserOrdinals.size === 0) {
|
|
10143
10403
|
log2("[dreamer] retrospective: only overlap lines, nothing new");
|
|
10144
|
-
return completedWindow(scan.maxScannedTs);
|
|
10404
|
+
return completedWindow(scan.maxScannedTs, "only overlap lines, nothing new");
|
|
10405
|
+
}
|
|
10406
|
+
const postWatermarkOrdinals = new Set(userMessages.filter((message) => message.ts > watermarkMs && message.followsAssistantReply === true).map((message) => message.ordinal));
|
|
10407
|
+
if (postWatermarkOrdinals.size === 0) {
|
|
10408
|
+
const noOpReason = "no reply-following user lines";
|
|
10409
|
+
log2(`[dreamer] retrospective: ${noOpReason}`);
|
|
10410
|
+
return completedWindow(scan.maxScannedTs, noOpReason);
|
|
10145
10411
|
}
|
|
10146
10412
|
const abortController = new AbortController;
|
|
10147
10413
|
let leaseLost = false;
|
|
@@ -10722,6 +10988,12 @@ function pruneIdleScheduleIdentities(db, now) {
|
|
|
10722
10988
|
|
|
10723
10989
|
// src/features/magic-context/dreamer/task-scheduler.ts
|
|
10724
10990
|
var MAX_TASK_RETRIES = 3;
|
|
10991
|
+
function tasksAllowedBySettings(deps) {
|
|
10992
|
+
return deps.tasks.filter((config) => dreamTaskAllowedBySettings(config.task, {
|
|
10993
|
+
projectMemoryEnabled: deps.projectMemoryEnabled,
|
|
10994
|
+
smartNotesEnabled: deps.smartNotesEnabled
|
|
10995
|
+
}));
|
|
10996
|
+
}
|
|
10725
10997
|
function ensureSeeded(db, projectIdentity, config, now) {
|
|
10726
10998
|
if (getTaskScheduleState(db, projectIdentity, config.task))
|
|
10727
10999
|
return;
|
|
@@ -10940,19 +11212,18 @@ async function runManualDream(deps) {
|
|
|
10940
11212
|
};
|
|
10941
11213
|
if (!isUsableProjectIdentity(deps.projectIdentity))
|
|
10942
11214
|
return result;
|
|
11215
|
+
const allowed = tasksAllowedBySettings(deps);
|
|
10943
11216
|
let selected;
|
|
10944
11217
|
let forceGate = false;
|
|
10945
11218
|
if (deps.task) {
|
|
10946
|
-
const cfg =
|
|
11219
|
+
const cfg = allowed.find((t) => t.task === deps.task);
|
|
10947
11220
|
if (!cfg)
|
|
10948
11221
|
return result;
|
|
10949
11222
|
selected = [cfg];
|
|
10950
11223
|
forceGate = true;
|
|
10951
11224
|
} else {
|
|
10952
|
-
selected =
|
|
11225
|
+
selected = allowed.filter((t) => t.schedule.trim() !== "");
|
|
10953
11226
|
}
|
|
10954
|
-
if (!isProjectMemoryEnabled(deps.projectMemoryEnabled))
|
|
10955
|
-
selected = selected.filter((config) => config.task === "evaluate-smart-notes");
|
|
10956
11227
|
if (selected.length === 0)
|
|
10957
11228
|
return result;
|
|
10958
11229
|
const selectedTaskNames = selected.map((config) => config.task);
|
|
@@ -11018,10 +11289,11 @@ async function runManualDream(deps) {
|
|
|
11018
11289
|
async function runDueTasksForProject(deps) {
|
|
11019
11290
|
if (!isUsableProjectIdentity(deps.projectIdentity))
|
|
11020
11291
|
return 0;
|
|
11021
|
-
|
|
11292
|
+
const tasks = tasksAllowedBySettings(deps);
|
|
11293
|
+
if (tasks.length === 0)
|
|
11022
11294
|
return 0;
|
|
11023
11295
|
const now = deps.now ?? Date.now();
|
|
11024
|
-
const due = planDueTasks(deps.db, deps.projectIdentity,
|
|
11296
|
+
const due = planDueTasks(deps.db, deps.projectIdentity, tasks, now);
|
|
11025
11297
|
if (due.length === 0)
|
|
11026
11298
|
return 0;
|
|
11027
11299
|
const gated = [];
|
|
@@ -11743,7 +12015,8 @@ async function sweepProject(reg, origin, db, gitCommitEnabled) {
|
|
|
11743
12015
|
projectIdentity: reg.projectIdentity,
|
|
11744
12016
|
tasks: runtimeConfigs,
|
|
11745
12017
|
executor,
|
|
11746
|
-
projectMemoryEnabled: reg.memoryEnabled !== false
|
|
12018
|
+
projectMemoryEnabled: reg.memoryEnabled !== false,
|
|
12019
|
+
smartNotesEnabled: reg.smartNotesEnabled
|
|
11747
12020
|
});
|
|
11748
12021
|
if (ran > 0) {
|
|
11749
12022
|
log2(`[dreamer] timer tick (${origin}) ${reg.projectIdentity} — ran ${ran} task(s)`);
|
|
@@ -15933,9 +16206,9 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
15933
16206
|
return { count: buildCompartmentCount(db, sessionId, moduleStatus) };
|
|
15934
16207
|
});
|
|
15935
16208
|
const buildManagedCtx = async (db) => {
|
|
15936
|
-
const { deriveHistorianChunkTokens, resolveHistorianContextLimit } = await importPluginModule(() => import("./derive-budgets-
|
|
16209
|
+
const { deriveHistorianChunkTokens, resolveHistorianContextLimit } = await importPluginModule(() => import("./derive-budgets-zn7yzd2d.js"));
|
|
15937
16210
|
const { resolveHistorianModel } = await importPluginModule(() => import("./model-resolution-nx97z3x7.js"));
|
|
15938
|
-
const {
|
|
16211
|
+
const { userObservationCollectionEnabled, userObservationsRequested } = await importPluginModule(() => import("./task-config-x3qmayd2.js"));
|
|
15939
16212
|
const DEFAULT_HISTORIAN_TIMEOUT_MS = 10 * 60 * 1000;
|
|
15940
16213
|
const runConfig = historianRunConfig(config, currentPluginConfigReader(directory)?.poll().effective ?? config);
|
|
15941
16214
|
const historianModel = resolveHistorianModel(runConfig, "opencode");
|
|
@@ -15953,7 +16226,8 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
15953
16226
|
autoPromote: runConfig.memory?.auto_promote ?? true,
|
|
15954
16227
|
historianModel: historianModel.primary,
|
|
15955
16228
|
fallbackModels: historianModel.fallbacks,
|
|
15956
|
-
userMemoriesEnabled:
|
|
16229
|
+
userMemoriesEnabled: userObservationCollectionEnabled(runConfig.dreamer),
|
|
16230
|
+
userObservationsRequested: userObservationsRequested(runConfig.dreamer),
|
|
15957
16231
|
historianTwoPass: runConfig.historian?.two_pass === true,
|
|
15958
16232
|
historianExpandTools: runConfig.historian?.expand_tools,
|
|
15959
16233
|
getNotificationParams: (sessionId) => getLiveNotificationParams(sessionId, liveSessionState.liveModelBySession, liveSessionState.variantBySession, liveSessionState.agentBySession, runConfig.toast_duration_ms)
|
|
@@ -15965,7 +16239,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
15965
16239
|
return { ok: false, error: "no session" };
|
|
15966
16240
|
const readDirectory = args.readSessionDirectory;
|
|
15967
16241
|
if (readDirectory) {
|
|
15968
|
-
const { handoffHistoryWork } = await import("./history-owner-
|
|
16242
|
+
const { handoffHistoryWork } = await import("./history-owner-xp3pngv7.js");
|
|
15969
16243
|
const handed = await handoffHistoryWork({
|
|
15970
16244
|
storageDir: args.storageDir ?? getMagicContextStorageDir(),
|
|
15971
16245
|
directory,
|
|
@@ -15984,8 +16258,8 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
15984
16258
|
const db = readDatabase();
|
|
15985
16259
|
if (!db)
|
|
15986
16260
|
return { ok: false, error: "db unavailable" };
|
|
15987
|
-
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-
|
|
15988
|
-
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-
|
|
16261
|
+
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-dmbeadwt.js"));
|
|
16262
|
+
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-24r4esbh.js"));
|
|
15989
16263
|
log2(`[rpc] recomp requested for session ${sessionId}`);
|
|
15990
16264
|
if (!args.client && !args.hiddenCompletionExecutor) {
|
|
15991
16265
|
return {
|
|
@@ -16043,7 +16317,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16043
16317
|
rpcServer.handle("wrapup", async (params) => {
|
|
16044
16318
|
const readDirectory = args.readSessionDirectory;
|
|
16045
16319
|
if (readDirectory && params.sessionId) {
|
|
16046
|
-
const { handoffHistoryWork } = await import("./history-owner-
|
|
16320
|
+
const { handoffHistoryWork } = await import("./history-owner-xp3pngv7.js");
|
|
16047
16321
|
const sessionId = String(params.sessionId);
|
|
16048
16322
|
const handed = await handoffHistoryWork({
|
|
16049
16323
|
storageDir: args.storageDir ?? getMagicContextStorageDir(),
|
|
@@ -16069,7 +16343,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16069
16343
|
const db = readDatabase();
|
|
16070
16344
|
if (!db)
|
|
16071
16345
|
return { ok: false, error: "db unavailable" };
|
|
16072
|
-
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-
|
|
16346
|
+
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-2051r6qm.js"));
|
|
16073
16347
|
const model = liveSessionState.liveModelBySession.get(sessionId);
|
|
16074
16348
|
const contextLimit = model ? resolveContextLimit(model.providerID, model.modelID, { db, sessionID: sessionId }) : 128000;
|
|
16075
16349
|
const ctx = {
|
|
@@ -16143,6 +16417,85 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16143
16417
|
});
|
|
16144
16418
|
}
|
|
16145
16419
|
|
|
16420
|
+
// src/hooks/magic-context/auto-embed-session.ts
|
|
16421
|
+
function embeddingIdentity(projectIdentity) {
|
|
16422
|
+
const snapshot = getProjectEmbeddingSnapshot2(projectIdentity);
|
|
16423
|
+
return JSON.stringify([
|
|
16424
|
+
projectIdentity,
|
|
16425
|
+
snapshot?.providerIdentity,
|
|
16426
|
+
snapshot?.chunkModelId,
|
|
16427
|
+
snapshot?.runtimeFingerprint
|
|
16428
|
+
]);
|
|
16429
|
+
}
|
|
16430
|
+
function maybeAutoEmbedSessionBackfill(deps, sessionId) {
|
|
16431
|
+
const markActive = () => activeEmbeddingSessions.set(sessionId, {
|
|
16432
|
+
project: deps.projectIdentity,
|
|
16433
|
+
model: getProjectEmbeddingSnapshot2(deps.projectIdentity)?.chunkModelId ?? "off"
|
|
16434
|
+
});
|
|
16435
|
+
markActive();
|
|
16436
|
+
const identity = embeddingIdentity(deps.projectIdentity);
|
|
16437
|
+
if (autoEmbedIdentityBySession.get(sessionId) !== identity) {
|
|
16438
|
+
invalidateAutoEmbedSession(sessionId);
|
|
16439
|
+
autoEmbedIdentityBySession.set(sessionId, identity);
|
|
16440
|
+
}
|
|
16441
|
+
if (autoEmbedAttemptedBySession.has(sessionId) || embedPauseBySession.has(sessionId) || embedRunStateBySession.has(sessionId) || Date.now() < (autoEmbedRetryAfterBySession.get(sessionId) ?? 0))
|
|
16442
|
+
return;
|
|
16443
|
+
const controller = new AbortController;
|
|
16444
|
+
embedRunStateBySession.set(sessionId, controller);
|
|
16445
|
+
(async () => {
|
|
16446
|
+
let complete = false;
|
|
16447
|
+
let retryDelay = 1000;
|
|
16448
|
+
let started = false;
|
|
16449
|
+
let reason = "error";
|
|
16450
|
+
let registeredIdentity = identity;
|
|
16451
|
+
try {
|
|
16452
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
16453
|
+
if (controller.signal.aborted)
|
|
16454
|
+
return;
|
|
16455
|
+
await deps.ensureRegistered();
|
|
16456
|
+
if (controller.signal.aborted)
|
|
16457
|
+
return;
|
|
16458
|
+
markActive();
|
|
16459
|
+
registeredIdentity = embeddingIdentity(deps.projectIdentity);
|
|
16460
|
+
autoEmbedIdentityBySession.set(sessionId, registeredIdentity);
|
|
16461
|
+
const coverage = await getAutoEmbeddingSessionCoverage2(deps.db, deps.projectIdentity, sessionId);
|
|
16462
|
+
if (controller.signal.aborted || !coverage.enabled)
|
|
16463
|
+
return;
|
|
16464
|
+
if (coverage.embedded === coverage.total) {
|
|
16465
|
+
complete = true;
|
|
16466
|
+
return;
|
|
16467
|
+
}
|
|
16468
|
+
const model = getProjectEmbeddingSnapshot2(deps.projectIdentity)?.model;
|
|
16469
|
+
log2(`[magic-context] session backfill start session=${sessionId} missing=${coverage.total - coverage.embedded} model=${model}`);
|
|
16470
|
+
started = true;
|
|
16471
|
+
const outcome = await embedSessionCompartmentChunks2(deps.db, deps.projectIdentity, sessionId, { signal: controller.signal, automatic: true });
|
|
16472
|
+
reason = outcome.status;
|
|
16473
|
+
const after = await getAutoEmbeddingSessionCoverage2(deps.db, deps.projectIdentity, sessionId);
|
|
16474
|
+
complete = after.enabled && after.embedded === after.total;
|
|
16475
|
+
if (!complete && outcome.status !== "busy" && outcome.status !== "aborted") {
|
|
16476
|
+
retryDelay = 60000;
|
|
16477
|
+
if (outcome.status === "nothing" || outcome.status === "done")
|
|
16478
|
+
reason = "deferred";
|
|
16479
|
+
}
|
|
16480
|
+
} catch (error) {
|
|
16481
|
+
log2("[magic-context] auto-embed drain failed:", error);
|
|
16482
|
+
retryDelay = 60000;
|
|
16483
|
+
} finally {
|
|
16484
|
+
if (started)
|
|
16485
|
+
log2(`[magic-context] session backfill ${complete ? "complete" : "stop"} session=${sessionId} reason=${reason}`);
|
|
16486
|
+
if (embedRunStateBySession.get(sessionId) === controller) {
|
|
16487
|
+
embedRunStateBySession.delete(sessionId);
|
|
16488
|
+
}
|
|
16489
|
+
if (!controller.signal.aborted && autoEmbedIdentityBySession.get(sessionId) === registeredIdentity && embeddingIdentity(deps.projectIdentity) === registeredIdentity) {
|
|
16490
|
+
if (complete)
|
|
16491
|
+
autoEmbedAttemptedBySession.add(sessionId);
|
|
16492
|
+
else
|
|
16493
|
+
autoEmbedRetryAfterBySession.set(sessionId, Date.now() + retryDelay);
|
|
16494
|
+
}
|
|
16495
|
+
}
|
|
16496
|
+
})();
|
|
16497
|
+
}
|
|
16498
|
+
|
|
16146
16499
|
// src/features/magic-context/transform-decision-log.ts
|
|
16147
16500
|
var TRANSFORM_DECISIONS_RETENTION = 2000;
|
|
16148
16501
|
var canonicalReasons = new Set([
|
|
@@ -16872,6 +17225,16 @@ function commitCompactionModeRecord(db, sessionId, record) {
|
|
|
16872
17225
|
setCompactionModeRecord(db, sessionId, record);
|
|
16873
17226
|
}
|
|
16874
17227
|
|
|
17228
|
+
// src/hooks/magic-context/compartment-trigger-error.ts
|
|
17229
|
+
function recordCompartmentTriggerError(passOutcome, sessionId, error, log = sessionLog2) {
|
|
17230
|
+
passOutcome.record("compartment-trigger-failure");
|
|
17231
|
+
if (error instanceof RawOrdinalsNotReady2) {
|
|
17232
|
+
log(sessionId, "compartment trigger deferred: raw ordinals not ready; the next pass evaluates it again");
|
|
17233
|
+
return;
|
|
17234
|
+
}
|
|
17235
|
+
log(sessionId, "compartment trigger failed (non-fatal):", error);
|
|
17236
|
+
}
|
|
17237
|
+
|
|
16875
17238
|
// src/hooks/magic-context/pass-outcome.ts
|
|
16876
17239
|
var PASS_DEGRADATION_EFFECTS = {
|
|
16877
17240
|
"store-generation-rebase-failure": "changes-request",
|
|
@@ -23384,6 +23747,7 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
23384
23747
|
ensureProjectRegistered: args.ensureProjectRegistered,
|
|
23385
23748
|
getNotificationParams: args.getNotificationParams,
|
|
23386
23749
|
experimentalUserMemories: args.experimentalUserMemories,
|
|
23750
|
+
userObservationsRequested: args.userObservationsRequested,
|
|
23387
23751
|
historianTwoPass: args.historianTwoPass,
|
|
23388
23752
|
historianExpandTools: args.historianExpandTools,
|
|
23389
23753
|
memoryEnabled: args.memoryEnabled,
|
|
@@ -23425,6 +23789,7 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
23425
23789
|
ensureProjectRegistered: args.ensureProjectRegistered,
|
|
23426
23790
|
getNotificationParams: args.getNotificationParams,
|
|
23427
23791
|
experimentalUserMemories: args.experimentalUserMemories,
|
|
23792
|
+
userObservationsRequested: args.userObservationsRequested,
|
|
23428
23793
|
historianTwoPass: args.historianTwoPass,
|
|
23429
23794
|
historianExpandTools: args.historianExpandTools,
|
|
23430
23795
|
memoryEnabled: args.memoryEnabled,
|
|
@@ -24129,6 +24494,7 @@ function createTransform(deps) {
|
|
|
24129
24494
|
fallbackModelId,
|
|
24130
24495
|
getNotificationParams: () => notificationParams,
|
|
24131
24496
|
experimentalUserMemories: historianRun?.userMemoriesEnabled ?? deps.experimentalUserMemories,
|
|
24497
|
+
userObservationsRequested: historianRun?.userObservationsRequested ?? deps.userObservationsRequested,
|
|
24132
24498
|
experimentalTemporalAwareness: deps.experimentalTemporalAwareness,
|
|
24133
24499
|
historianTwoPass: historianRun?.twoPass ?? deps.historianTwoPass,
|
|
24134
24500
|
historianExpandTools: historianRun?.expandTools ?? deps.historianExpandTools,
|
|
@@ -24184,6 +24550,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24184
24550
|
sessionLog2(sessionId, `tag floor: 0 (full-scan fallback) — no leading wire message resolved a tag across ${messages.length} msgs`);
|
|
24185
24551
|
}
|
|
24186
24552
|
const ownerRatio = sessionDecisionCalibration(db, sessionId).proseRatio;
|
|
24553
|
+
noteTransformPassForExactOrdinalReads(sessionId);
|
|
24187
24554
|
prewarmTagOwners(db, sessionId, ownerRatio);
|
|
24188
24555
|
const tagOwnersReady = isTagOwnerSummaryReady2(db, sessionId, ownerRatio);
|
|
24189
24556
|
let triggerBoundarySnapshot;
|
|
@@ -24207,8 +24574,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24207
24574
|
triggerBoundarySnapshot = triggerResult.boundarySnapshot;
|
|
24208
24575
|
}
|
|
24209
24576
|
} catch (error) {
|
|
24210
|
-
passOutcome
|
|
24211
|
-
sessionLog2(sessionId, "compartment trigger failed (non-fatal):", error);
|
|
24577
|
+
recordCompartmentTriggerError(passOutcome, sessionId, error);
|
|
24212
24578
|
}
|
|
24213
24579
|
logTransformTiming(sessionId, "compartmentTrigger", tTrigger);
|
|
24214
24580
|
}
|
|
@@ -24399,6 +24765,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24399
24765
|
safeForBackgroundCompression: historianRunnable && (isCacheBusting || schedulerDecision === "execute"),
|
|
24400
24766
|
deferredHistoryRefreshSessions,
|
|
24401
24767
|
experimentalUserMemories: historianRun?.userMemoriesEnabled ?? deps.experimentalUserMemories,
|
|
24768
|
+
userObservationsRequested: historianRun?.userObservationsRequested ?? deps.userObservationsRequested,
|
|
24402
24769
|
experimentalTemporalAwareness: deps.experimentalTemporalAwareness,
|
|
24403
24770
|
historianTwoPass: historianRun?.twoPass ?? deps.historianTwoPass,
|
|
24404
24771
|
historianExpandTools: historianRun?.expandTools ?? deps.historianExpandTools,
|
|
@@ -27752,12 +28119,13 @@ function parseNoteIds(action, value) {
|
|
|
27752
28119
|
}
|
|
27753
28120
|
function createCtxNoteTool(deps) {
|
|
27754
28121
|
const { surface_condition: _condition, ...plainArgs } = ctxNoteArgsShape;
|
|
28122
|
+
const smartNoteSurface = deps.smartNotesEnabled !== false && deps.dreamerEnabled !== false;
|
|
27755
28123
|
return tool3({
|
|
27756
|
-
description:
|
|
27757
|
-
args:
|
|
28124
|
+
description: smartNoteSurface ? CTX_NOTE_DESCRIPTION : withoutSmartNoteText(CTX_NOTE_DESCRIPTION),
|
|
28125
|
+
args: smartNoteSurface ? ctxNoteArgsShape : {
|
|
27758
28126
|
...plainArgs,
|
|
27759
28127
|
filter: ctxNoteArgsShape.filter.describe(NOTES_FILTER_DESCRIPTION)
|
|
27760
|
-
}
|
|
28128
|
+
},
|
|
27761
28129
|
async execute(rawArgs, toolContext) {
|
|
27762
28130
|
const parsedArgs = ctxNoteArgsSchema.safeParse(rawArgs);
|
|
27763
28131
|
let args = parsedArgs.success ? parsedArgs.data : rawArgs;
|
|
@@ -28783,4 +29151,4 @@ function applyHiddenSubagentTemperature(input, output, log) {
|
|
|
28783
29151
|
output.temperature = temperature;
|
|
28784
29152
|
}
|
|
28785
29153
|
|
|
28786
|
-
export { openOpenCodeDb, DREAMER_SYSTEM_PROMPT, runSessionProjectBackfill, SMART_NOTE_COMPILER_SYSTEM_PROMPT, createLiveSessionState, RETROSPECTIVE_MAX_USER_MESSAGE_CHARS, RETROSPECTIVE_MESSAGE_TRUNCATION_MARKER, OpenCodeRetrospectiveRawProvider, createDreamTaskExecutor, runManualDream, runDueTasksForProject, scheduleClearAndReindex, startDreamScheduleTimer, createDreamTimerModuleClient, ensureProjectRegisteredFromOpenCodeDirectory, recordOpenCodeProvenInputFloor, resolveOpenCodeProvenInputFloor, resolveContextWindowGeometry, resolveContextLimit, resolveExecuteThresholdDetail, resolveModelKey, resolveSessionId, createScheduler, describeStorageUnavailability, resolveSessionCacheTtl, runEmbedHistoryDrain, pauseEmbedHistoryDrain, formatEmbedStatusText, getSessionProperties, getSessionCreatedInfo, getMessageUpdatedAssistantInfo, getMessageUpdatedInfo, getSessionErrorInfo, getMessageRemovedInfo, summarizeManualDream, createMagicContextCommandHandler, getLiveNotificationParams, createChatMessageHook, createEventHook, createCommandExecuteBeforeHook, createToolExecuteAfterHook, recordHiddenVariantWarning, buildStatusDetail, isDebugRpcEnabled, registerRpcHandlers, clearTransformDecisionSession, scheduleOpenCodeTransformDecisionWrite, stageOpenCodeV2TransformDecision, bindOpenCodeV2TransformDecision, maybeDeliverChannel2, armLatestThinkingRecovery, armBindingRecoverySafely, armLatestThinkingRecoveryFromError, createM0RenderOptions, lkgReplayLimit, measureLkgReplay, STORAGE_BUSY_MESSAGE, StorageBusyRefusalError, bindSystemDateRequestIdentity, bindSystemDateOutput, registerSystemDateRefresh, rustWrapupHistorianFields, UnmanagedOverWindowError, UnresolvedHistoryBoundaryError, clearMessageTokensCache, createTransform, createSubcModuleClient, createModuleToolBackends, createRustRefusalRecovery, createSystemPromptHashHandler, tryMessagesTransformLkgReplay, createMessagesTransformHandler, primaryOnlyToolIds, subagentToolRefusal, guardSubagentTools, hideSubagentTools, createCtxExpandTools, CTX_MEMORY_LIST_TOOL_NAME, CTX_MEMORY_ACTIONS, createCtxMemoryTools, createCtxMemoryListTools, CTX_NOTE_DESCRIPTION, withoutSmartNoteText, createCtxNoteTools, createCtxReduceTools, createCtxSearchTools, parameterDescriptionsFor, applyJsonSchemaParameterDescriptions, MagicContextRpcServer, subagentTemperature, applyHiddenSubagentTemperature };
|
|
29154
|
+
export { logConfigDependencyNotesOnce, openOpenCodeDb, DREAMER_SYSTEM_PROMPT, runSessionProjectBackfill, SMART_NOTE_COMPILER_SYSTEM_PROMPT, createLiveSessionState, RETROSPECTIVE_MAX_USER_MESSAGE_CHARS, RETROSPECTIVE_MESSAGE_TRUNCATION_MARKER, OpenCodeRetrospectiveRawProvider, createDreamTaskExecutor, runManualDream, runDueTasksForProject, scheduleClearAndReindex, startDreamScheduleTimer, createDreamTimerModuleClient, ensureProjectRegisteredFromOpenCodeDirectory, recordOpenCodeProvenInputFloor, resolveOpenCodeProvenInputFloor, resolveContextWindowGeometry, resolveContextLimit, resolveExecuteThresholdDetail, resolveModelKey, resolveSessionId, createScheduler, describeStorageUnavailability, resolveSessionCacheTtl, runEmbedHistoryDrain, pauseEmbedHistoryDrain, formatEmbedStatusText, getSessionProperties, getSessionCreatedInfo, getMessageUpdatedAssistantInfo, getMessageUpdatedInfo, getSessionErrorInfo, getMessageRemovedInfo, summarizeManualDream, createMagicContextCommandHandler, getLiveNotificationParams, createChatMessageHook, createEventHook, createCommandExecuteBeforeHook, createToolExecuteAfterHook, recordHiddenVariantWarning, buildStatusDetail, isDebugRpcEnabled, registerRpcHandlers, maybeAutoEmbedSessionBackfill, clearTransformDecisionSession, scheduleOpenCodeTransformDecisionWrite, stageOpenCodeV2TransformDecision, bindOpenCodeV2TransformDecision, maybeDeliverChannel2, armLatestThinkingRecovery, armBindingRecoverySafely, armLatestThinkingRecoveryFromError, createM0RenderOptions, lkgReplayLimit, measureLkgReplay, STORAGE_BUSY_MESSAGE, StorageBusyRefusalError, bindSystemDateRequestIdentity, bindSystemDateOutput, registerSystemDateRefresh, rustWrapupHistorianFields, UnmanagedOverWindowError, UnresolvedHistoryBoundaryError, clearMessageTokensCache, createTransform, createSubcModuleClient, createModuleToolBackends, createRustRefusalRecovery, createSystemPromptHashHandler, tryMessagesTransformLkgReplay, createMessagesTransformHandler, primaryOnlyToolIds, subagentToolRefusal, guardSubagentTools, hideSubagentTools, createCtxExpandTools, CTX_MEMORY_LIST_TOOL_NAME, CTX_MEMORY_ACTIONS, createCtxMemoryTools, createCtxMemoryListTools, CTX_NOTE_DESCRIPTION, withoutSmartNoteText, createCtxNoteTools, createCtxReduceTools, createCtxSearchTools, parameterDescriptionsFor, applyJsonSchemaParameterDescriptions, MagicContextRpcServer, subagentTemperature, applyHiddenSubagentTemperature };
|