@cortexkit/opencode-magic-context 0.49.81 → 0.49.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-search-worker.js +3 -3
- package/dist/chunk-embedding-write-worker.js +4 -4
- package/dist/{conflict-warning-hook-8s8r0c0v.js → conflict-warning-hook-a0wrnzch.js} +2 -2
- package/dist/{context-359s1ncq.js → context-xmyke353.js} +258 -31
- package/dist/{embedding-backfill-0tvprmrn.js → embedding-backfill-k994xdas.js} +4 -4
- package/dist/features/magic-context/dreamer/map-memories-retry.d.ts +18 -0
- package/dist/features/magic-context/dreamer/map-memories-retry.d.ts.map +1 -0
- 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/task-gates.d.ts +1 -1
- package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-registry.d.ts +7 -0
- package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts +9 -0
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
- package/dist/features/magic-context/memory/identity-merge-command.d.ts +4 -0
- package/dist/features/magic-context/memory/identity-merge-command.d.ts.map +1 -0
- package/dist/features/magic-context/memory/project-binding-notice.d.ts +5 -0
- package/dist/features/magic-context/memory/project-binding-notice.d.ts.map +1 -0
- 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/storage-clone.d.ts +17 -0
- package/dist/features/magic-context/storage-clone.d.ts.map +1 -1
- package/dist/features/magic-context/store-generation-rebase.d.ts +13 -0
- package/dist/features/magic-context/store-generation-rebase.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts +1 -7
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/execute-status.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/stored-compartment-gaps.d.ts +16 -0
- package/dist/hooks/magic-context/stored-compartment-gaps.d.ts.map +1 -0
- package/dist/hooks/magic-context/transform.d.ts +1 -0
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-m4q6ptgz.js → index-2xhzmwf6.js} +4 -4
- package/dist/{index-jhhkb4jv.js → index-2ygw6q5s.js} +1 -1
- package/dist/{index-v0epndb8.js → index-93rezfvc.js} +22 -2
- package/dist/{index-1rx9bfrk.js → index-b2787fk6.js} +111 -40
- package/dist/{index-tebcx987.js → index-bd34njzg.js} +1 -1
- package/dist/{index-zpd4pxnp.js → index-dg5jvh9r.js} +6 -6
- package/dist/{index-6athgjba.js → index-e21n48yd.js} +34 -2
- package/dist/{index-726b5jh5.js → index-eptthgkw.js} +5 -5
- package/dist/{index-6sckwxjj.js → index-eyk7msgw.js} +344 -159
- package/dist/{index-9554nr2q.js → index-fgy6hnr3.js} +6 -1
- package/dist/{index-tzy5h4x6.js → index-fpqdbb67.js} +1 -1
- package/dist/{index-x8a7jmkh.js → index-fzgyvsb1.js} +15 -4
- package/dist/{index-1sq1krqw.js → index-g6hfh4h4.js} +4 -4
- package/dist/{index-wwzamy3j.js → index-hz1xdb15.js} +3 -3
- package/dist/{index-nda0zgna.js → index-kknjvmpx.js} +2 -1
- package/dist/{index-m6rkq3t4.js → index-rnyaa7cj.js} +1 -1
- package/dist/{index-yfn52pb6.js → index-shpyv8gq.js} +2 -2
- package/dist/{index-7jefmy0g.js → index-stx8zd81.js} +2 -2
- package/dist/{index-jg7sbt3v.js → index-vpw46557.js} +1 -1
- package/dist/{index-xx05vta0.js → index-w2wpx7t5.js} +1 -1
- package/dist/{index-177yv84k.js → index-w8dcjt7f.js} +1 -1
- package/dist/{index-ma258g0g.js → index-wxxcfpxh.js} +5 -5
- package/dist/{index-xsdaz3mq.js → index-x8qgqnym.js} +30 -11
- package/dist/{index-aawwdt26.js → index-zvane1rq.js} +2 -2
- package/dist/index.js +32 -32
- package/dist/migration-worker.js +3 -3
- package/dist/plugin/rpc-handlers.d.ts +2 -0
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/{project-embedding-registry-sw4z2ptg.js → project-embedding-registry-y3z36mjy.js} +3 -3
- package/dist/raw-ordinal-warmup-worker.js +2 -2
- package/dist/{recomp-orchestrator-ar3xw3f4.js → recomp-orchestrator-fjdp3t1d.js} +14 -14
- package/dist/{render-bjxgkrk6.js → render-c9fjwrad.js} +6 -6
- package/dist/{rpc-notifications-3hed126v.js → rpc-notifications-t9q0ynq7.js} +3 -1
- package/dist/{search-z56487n8.js → search-1jejx5cx.js} +9 -9
- package/dist/{search-archive-p3jhx9wc.js → search-archive-s2jas2jb.js} +2 -2
- package/dist/{send-session-notification-ykvt5k2s.js → send-session-notification-7x518gew.js} +1 -1
- package/dist/shared/prompt-surface-runtime.d.ts +1 -1
- package/dist/shared/rpc-notifications.d.ts +8 -3
- package/dist/shared/rpc-notifications.d.ts.map +1 -1
- package/dist/shared/rpc-types.d.ts +4 -0
- package/dist/shared/rpc-types.d.ts.map +1 -1
- package/dist/shared/status-summary.d.ts +2 -0
- package/dist/shared/status-summary.d.ts.map +1 -1
- package/dist/shared/status-view-check.d.ts.map +1 -1
- package/dist/shared/status-view.d.ts +1 -0
- package/dist/shared/status-view.d.ts.map +1 -1
- package/dist/shared/user-facing-codes.d.ts +5 -0
- package/dist/shared/user-facing-codes.d.ts.map +1 -1
- package/dist/{store-8trkpmtx.js → store-ggrq9e14.js} +6 -2
- package/dist/{store-reader-3eh1s1m8.js → store-reader-tr64nxyy.js} +1 -1
- package/dist/{task-config-t6bpyka7.js → task-config-qt6n4bxm.js} +1 -1
- package/dist/tools/ctx-memory/constants.d.ts +1 -1
- package/dist/tools/ctx-memory/constants.d.ts.map +1 -1
- package/dist/tools/light-descriptions.d.ts +1 -1
- package/dist/tools/light-descriptions.d.ts.map +1 -1
- package/dist/tools/parameter-descriptions.d.ts +6 -6
- package/dist/tools/parameter-descriptions.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-6kyqctnq.js → transform-postprocess-phase-p2egg02g.js} +15 -15
- package/dist/v2/auto-search-worker.js +3 -3
- package/dist/v2/chunk-embedding-write-worker.js +4 -4
- package/dist/v2/{context-dpe94zcx.js → context-zn18k0yk.js} +648 -245
- package/dist/v2/{embedding-backfill-qnaswpmb.js → embedding-backfill-hjvjxp7d.js} +4 -4
- package/dist/v2/fork-inheritance.d.ts +25 -17
- package/dist/v2/fork-inheritance.d.ts.map +1 -1
- package/dist/v2/hidden-child-native.d.ts +6 -6
- package/dist/v2/hidden-child-native.d.ts.map +1 -1
- package/dist/v2/hidden-child-record.d.ts +21 -3
- package/dist/v2/hidden-child-record.d.ts.map +1 -1
- package/dist/v2/hidden-child-sweep.d.ts +1 -1
- package/dist/v2/hidden-child-sweep.d.ts.map +1 -1
- package/dist/v2/hidden-completion.d.ts +1 -0
- package/dist/v2/hidden-completion.d.ts.map +1 -1
- package/dist/v2/hidden-run-holder.d.ts +16 -0
- package/dist/v2/hidden-run-holder.d.ts.map +1 -0
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/dream-timer.d.ts +5 -7
- package/dist/v2/hooks/dream-timer.d.ts.map +1 -1
- package/dist/v2/hooks/fork-history-status.d.ts +10 -0
- package/dist/v2/hooks/fork-history-status.d.ts.map +1 -0
- package/dist/v2/hooks/hidden-child.d.ts.map +1 -1
- package/dist/v2/hooks/store.d.ts +4 -0
- package/dist/v2/hooks/store.d.ts.map +1 -1
- package/dist/v2/hooks/types.d.ts +5 -26
- package/dist/v2/hooks/types.d.ts.map +1 -1
- package/dist/v2/migration-worker.js +3 -3
- package/dist/v2/{project-embedding-registry-52f2jept.js → project-embedding-registry-mzsvyads.js} +3 -3
- package/dist/v2/raw-ordinal-warmup-worker.js +2 -2
- package/dist/v2/{recomp-orchestrator-7t6fkpbb.js → recomp-orchestrator-jn39mxh0.js} +13 -13
- package/dist/v2/{render-hwqk0d8t.js → render-q2aj9bgy.js} +6 -6
- package/dist/v2/retrospective-raw-provider.d.ts.map +1 -1
- package/dist/v2/{rpc-notifications-3hed126v.js → rpc-notifications-t9q0ynq7.js} +3 -1
- package/dist/v2/{search-eftsvbg7.js → search-9xn6ds9x.js} +8 -8
- package/dist/v2/{search-archive-mdxzvgpm.js → search-archive-fj59gjv1.js} +2 -2
- package/dist/v2/{send-session-notification-8g4r97bp.js → send-session-notification-p52rhjzy.js} +1 -1
- package/dist/v2/{server-ma9jwnas.js → server-1cn3kryt.js} +4 -4
- package/dist/v2/{server-34pvhvxt.js → server-1efjj215.js} +22 -2
- package/dist/v2/{server-92g7d776.js → server-2kswss3d.js} +2 -1
- package/dist/v2/{server-jn4pktdk.js → server-2ktxmtbd.js} +1 -1
- package/dist/v2/{server-zw1e3wq5.js → server-2w1rdttn.js} +1 -1
- package/dist/v2/{server-jtq03rkb.js → server-4z964n1c.js} +1 -1
- package/dist/v2/{server-pxdpwycq.js → server-53n8hv5q.js} +6 -6
- package/dist/v2/{server-rbtx6q5v.js → server-569he5mh.js} +1 -1
- package/dist/v2/{server-rthnpmbp.js → server-5yfq912a.js} +34 -2
- package/dist/v2/{server-mhrgymcs.js → server-68q80y27.js} +2 -2
- package/dist/v2/{server-afsz3cmx.js → server-bt546axy.js} +1 -1
- package/dist/v2/{server-dhdn8mwq.js → server-c8mqs0v5.js} +30 -11
- package/dist/v2/{server-x8a7jmkh.js → server-fzgyvsb1.js} +15 -4
- package/dist/v2/{server-76v5y7zm.js → server-g1a0nhtk.js} +2 -2
- package/dist/v2/{server-25qtxt4d.js → server-gx1s06dx.js} +6 -1
- package/dist/v2/{server-x8ksqcw7.js → server-pejjj0nv.js} +1 -1
- package/dist/v2/{server-a1zp7exh.js → server-vt6nj2hn.js} +106 -35
- package/dist/v2/{server-qjff96a6.js → server-wdq85mxj.js} +4 -4
- package/dist/v2/server.js +3 -3
- package/dist/v2/{store-m3zny7q2.js → store-qdgzd38f.js} +6 -2
- package/dist/v2/{store-reader-yaxtdy6f.js → store-reader-83tka051.js} +1 -1
- package/dist/v2/store-reader.d.ts +15 -8
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{task-config-7md27rx8.js → task-config-ex2vajr2.js} +1 -1
- package/dist/v2/tui/index.d.ts +1 -1
- package/dist/v2/tui/index.d.ts.map +1 -1
- package/dist/v2/{v2-archive-reader-p89x05hj.js → v2-archive-reader-9z8z97db.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-c0bwb0wa.js → wrapup-orchestrator-vd5zfp3v.js} +13 -13
- package/dist/{v2-archive-reader-vzmzb245.js → v2-archive-reader-r0xpxsb1.js} +1 -1
- package/dist/{wrapup-orchestrator-548q5y55.js → wrapup-orchestrator-k29zqfp9.js} +15 -15
- package/package.json +1 -1
- package/src/agents/smart-notes-dreamer-gate.golden.json +169 -169
- package/src/features/magic-context/dreamer/task-registry.ts +8 -0
- package/src/shared/prompt-surface-a1-golden.md +8 -7
- package/src/shared/rpc-notifications.test.ts +29 -0
- package/src/shared/rpc-notifications.ts +24 -5
- package/src/shared/rpc-types.ts +4 -0
- package/src/shared/status-summary.ts +9 -1
- package/src/shared/status-view-check.ts +2 -0
- package/src/shared/status-view.test.ts +9 -0
- package/src/shared/status-view.ts +4 -0
- package/src/shared/user-facing-codes.ts +5 -0
- package/src/tui/slots/sidebar-content.tsx +11 -5
- package/src/tui-compiled/slots/sidebar-content.tsx +191 -176
- package/src/v2/tui/index.ts +7 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CANONICAL_DREAM_TASKS,
|
|
3
|
+
MIN_POOL_TO_CLASSIFY,
|
|
3
4
|
DREAM_TASK_CAPABILITIES,
|
|
4
5
|
toolLoopDreamTasks,
|
|
5
6
|
formatDreamTaskBacklogs,
|
|
@@ -13,7 +14,7 @@ import {
|
|
|
13
14
|
compareTaskOrder,
|
|
14
15
|
buildDreamTaskRuntimeConfigs2,
|
|
15
16
|
userMemoryCollectionEnabled2
|
|
16
|
-
} from "./index-
|
|
17
|
+
} from "./index-kknjvmpx.js";
|
|
17
18
|
import {
|
|
18
19
|
getHarness2,
|
|
19
20
|
harnessOwnsOpenCodeStore2
|
|
@@ -60,6 +61,7 @@ import {
|
|
|
60
61
|
pruneMissingProjectIdentities,
|
|
61
62
|
shouldSkipHomeProjectMemory,
|
|
62
63
|
ProjectIdentityError,
|
|
64
|
+
directoryFallback,
|
|
63
65
|
takeDubiousOwnershipProjectIdentityWarning,
|
|
64
66
|
isUserHomeDirectory,
|
|
65
67
|
resolveProjectIdentity,
|
|
@@ -71,7 +73,7 @@ import {
|
|
|
71
73
|
storedPathBelongsToIdentity,
|
|
72
74
|
beginBootQuietPeriod,
|
|
73
75
|
scheduleAfterBootQuiet
|
|
74
|
-
} from "./index-
|
|
76
|
+
} from "./index-fpqdbb67.js";
|
|
75
77
|
import {
|
|
76
78
|
recordSessionProjectIdentity,
|
|
77
79
|
hasRecordedSessionProjectIdentity,
|
|
@@ -81,7 +83,7 @@ import {
|
|
|
81
83
|
markGitSweepSuccessAndRelease,
|
|
82
84
|
parkGitSweepNonIndexable,
|
|
83
85
|
releaseGitSweepLease
|
|
84
|
-
} from "./index-
|
|
86
|
+
} from "./index-vpw46557.js";
|
|
85
87
|
import {
|
|
86
88
|
getMagicContextBuiltinCommands,
|
|
87
89
|
formatConfigParseStatusLine,
|
|
@@ -196,7 +198,7 @@ import {
|
|
|
196
198
|
snapRangeToCompartments,
|
|
197
199
|
getActiveCompartmentRun,
|
|
198
200
|
startCompartmentAgent
|
|
199
|
-
} from "./index-
|
|
201
|
+
} from "./index-b2787fk6.js";
|
|
200
202
|
import {
|
|
201
203
|
hasTrustedAbsoluteWall,
|
|
202
204
|
applyProvenInputFloor,
|
|
@@ -453,7 +455,7 @@ import {
|
|
|
453
455
|
runSqliteOptimize,
|
|
454
456
|
openDatabase,
|
|
455
457
|
openCurrentDatabase
|
|
456
|
-
} from "./index-
|
|
458
|
+
} from "./index-zvane1rq.js";
|
|
457
459
|
import {
|
|
458
460
|
unescapeXml,
|
|
459
461
|
resolveWorkspaceShareCategories,
|
|
@@ -462,7 +464,7 @@ import {
|
|
|
462
464
|
resolveStoredPathWorkspaceIdentity,
|
|
463
465
|
storedPathBelongsToWorkspace,
|
|
464
466
|
computeWorkspaceEpochFingerprint
|
|
465
|
-
} from "./index-
|
|
467
|
+
} from "./index-w2wpx7t5.js";
|
|
466
468
|
import {
|
|
467
469
|
V2_MEMORY_CATEGORIES,
|
|
468
470
|
CATEGORY_PRIORITY
|
|
@@ -569,7 +571,7 @@ import {
|
|
|
569
571
|
GLOBAL_USER_PROFILE_PROJECT_PATH,
|
|
570
572
|
getProjectState,
|
|
571
573
|
bumpProjectUserProfileVersion
|
|
572
|
-
} from "./index-
|
|
574
|
+
} from "./index-x8qgqnym.js";
|
|
573
575
|
import {
|
|
574
576
|
getLastIndexedOrdinal
|
|
575
577
|
} from "./index-zzvd4a9z.js";
|
|
@@ -598,14 +600,14 @@ import {
|
|
|
598
600
|
createPrimer,
|
|
599
601
|
updatePrimerSupport,
|
|
600
602
|
updatePrimerAnswer
|
|
601
|
-
} from "./index-
|
|
603
|
+
} from "./index-bd34njzg.js";
|
|
602
604
|
import {
|
|
603
605
|
registerNotificationSink2,
|
|
604
606
|
pushNotification2,
|
|
605
607
|
acknowledgeNotifications2,
|
|
606
608
|
drainNotifications2,
|
|
607
609
|
isTuiConnected2
|
|
608
|
-
} from "./index-
|
|
610
|
+
} from "./index-fzgyvsb1.js";
|
|
609
611
|
import {
|
|
610
612
|
getCachedLocalEmbeddingPooling,
|
|
611
613
|
preflightLocalEmbeddingPooling,
|
|
@@ -631,7 +633,7 @@ import {
|
|
|
631
633
|
embedSessionCompartmentChunks2,
|
|
632
634
|
getEmbeddingCoverageStatus2,
|
|
633
635
|
getAutoEmbeddingSessionCoverage2
|
|
634
|
-
} from "./index-
|
|
636
|
+
} from "./index-shpyv8gq.js";
|
|
635
637
|
import {
|
|
636
638
|
saveEmbeddingIfHashMatches,
|
|
637
639
|
invalidateProject2,
|
|
@@ -657,7 +659,7 @@ import {
|
|
|
657
659
|
readGitFileChangeTimesSince,
|
|
658
660
|
verificationFileExists,
|
|
659
661
|
normalizeVerificationFiles
|
|
660
|
-
} from "./index-
|
|
662
|
+
} from "./index-fgy6hnr3.js";
|
|
661
663
|
import {
|
|
662
664
|
computeCueContentHash,
|
|
663
665
|
hasMuralCueColumns,
|
|
@@ -682,6 +684,7 @@ import {
|
|
|
682
684
|
supersededMemory2,
|
|
683
685
|
mergeMemoryStats2,
|
|
684
686
|
archiveMemory2,
|
|
687
|
+
getMemoryCount2,
|
|
685
688
|
getMemoryCountsByStatus2
|
|
686
689
|
} from "./index-jjvbk92s.js";
|
|
687
690
|
import {
|
|
@@ -704,23 +707,23 @@ import {
|
|
|
704
707
|
resolveMemoriesByIdsForSearch2,
|
|
705
708
|
unifiedSearch2,
|
|
706
709
|
formatSearchResults2
|
|
707
|
-
} from "./index-
|
|
710
|
+
} from "./index-dg5jvh9r.js";
|
|
708
711
|
import {
|
|
709
712
|
scheduleReconciliation,
|
|
710
713
|
scheduleIncrementalIndex,
|
|
711
714
|
getMessageIndexQueueHeapStats,
|
|
712
715
|
clearSessionTracking
|
|
713
|
-
} from "./index-
|
|
716
|
+
} from "./index-rnyaa7cj.js";
|
|
714
717
|
import {
|
|
715
718
|
flushIgnoredMessages2,
|
|
716
719
|
clearIgnoredMessages2,
|
|
717
720
|
observeIgnoredNotificationEvent2,
|
|
718
721
|
sendStatusNotification2
|
|
719
|
-
} from "./index-
|
|
722
|
+
} from "./index-g6hfh4h4.js";
|
|
720
723
|
import {
|
|
721
724
|
setRecompStarting2,
|
|
722
725
|
setRecompTerminal2
|
|
723
|
-
} from "./index-
|
|
726
|
+
} from "./index-hz1xdb15.js";
|
|
724
727
|
import {
|
|
725
728
|
makeToolCompositeKey,
|
|
726
729
|
searchMessageHistoryOffThread,
|
|
@@ -805,7 +808,7 @@ import {
|
|
|
805
808
|
abortSessionFailClosed2,
|
|
806
809
|
evaluateEmergencyFailClosed2,
|
|
807
810
|
runPostTransformPhase2
|
|
808
|
-
} from "./index-
|
|
811
|
+
} from "./index-wxxcfpxh.js";
|
|
809
812
|
import {
|
|
810
813
|
ANNOUNCEMENT_VERSION2,
|
|
811
814
|
ANNOUNCEMENT_FEATURES2,
|
|
@@ -823,10 +826,10 @@ import {
|
|
|
823
826
|
} from "./index-twmeey4h.js";
|
|
824
827
|
import {
|
|
825
828
|
readV2ArchiveOffThread2
|
|
826
|
-
} from "./index-
|
|
829
|
+
} from "./index-2xhzmwf6.js";
|
|
827
830
|
import {
|
|
828
831
|
renderSearchArchiveOffThread2
|
|
829
|
-
} from "./index-
|
|
832
|
+
} from "./index-2ygw6q5s.js";
|
|
830
833
|
import {
|
|
831
834
|
COMPACTION_ENABLED_PATH,
|
|
832
835
|
isDreamerRunnable,
|
|
@@ -1963,6 +1966,33 @@ ${buildFrictionGatePrompt({ userLines })}`;
|
|
|
1963
1966
|
function retrospectiveGatePromptTokens(messages) {
|
|
1964
1967
|
return estimateTokens(retrospectiveGatePrompt(messages));
|
|
1965
1968
|
}
|
|
1969
|
+
function admitRetrospectiveCohorts(rows, firstUnreadTs, maxMessages, promptInputLimitTokens) {
|
|
1970
|
+
const kept = [];
|
|
1971
|
+
let start = 0;
|
|
1972
|
+
for (let first = rows[start];first && first.ts < firstUnreadTs; first = rows[start]) {
|
|
1973
|
+
const ts = first.ts;
|
|
1974
|
+
let end = start + 1;
|
|
1975
|
+
while (end < rows.length && rows[end]?.ts === ts)
|
|
1976
|
+
end += 1;
|
|
1977
|
+
const cohort = rows.slice(start, end);
|
|
1978
|
+
const tooManyRows = end > maxMessages;
|
|
1979
|
+
const tooManyTokens = !tooManyRows && promptInputLimitTokens !== undefined && retrospectiveGatePromptTokens([...kept, ...cohort]) > promptInputLimitTokens;
|
|
1980
|
+
if (tooManyRows || tooManyTokens) {
|
|
1981
|
+
return {
|
|
1982
|
+
kept,
|
|
1983
|
+
budgetTruncated: tooManyTokens,
|
|
1984
|
+
...kept.length === 0 ? { oversized: { ts, rows: cohort } } : {}
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1987
|
+
kept.push(...cohort);
|
|
1988
|
+
start = end;
|
|
1989
|
+
}
|
|
1990
|
+
return { kept, budgetTruncated: false };
|
|
1991
|
+
}
|
|
1992
|
+
function logSkippedRetrospectiveCohort(sessionIds, ts, count, lowerBound) {
|
|
1993
|
+
const sessions = [...new Set(sessionIds)].join(",");
|
|
1994
|
+
log2(`[dreamer] retrospective: oversized timestamp cohort sessionIds=${sessions} timestamp=${ts} ${lowerBound ? "skippedAtLeast" : "skipped"}=${count}`);
|
|
1995
|
+
}
|
|
1966
1996
|
async function readRetrospectiveScanWindow(provider, projectIdentity, watermarkMs, overlapUserCount, options) {
|
|
1967
1997
|
const maxMessages = options?.maxMessagesPerRun ?? RETROSPECTIVE_MAX_MESSAGES_PER_RUN;
|
|
1968
1998
|
const capPerSession = options?.capPerSession ?? RETROSPECTIVE_MAX_MESSAGES_PER_SESSION;
|
|
@@ -1992,59 +2022,57 @@ async function readRetrospectiveScanWindow(provider, projectIdentity, watermarkM
|
|
|
1992
2022
|
if (sessionsToRead.length > 0) {
|
|
1993
2023
|
sinceReads.push(...await Promise.all(sessionsToRead.map((session) => provider.readUserMessagesSince(session.sessionId, scanSinceMs, capPerSession))));
|
|
1994
2024
|
}
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
if (!row)
|
|
2012
|
-
continue;
|
|
2013
|
-
const candidate = [...keptSince, row];
|
|
2014
|
-
if (retrospectiveGatePromptTokens(candidate) <= promptInputLimitTokens) {
|
|
2015
|
-
keptSince.push(row);
|
|
2016
|
-
continue;
|
|
2017
|
-
}
|
|
2018
|
-
budgetDropped = countCandidates.slice(index);
|
|
2019
|
-
break;
|
|
2025
|
+
const allSince = sinceReads.flatMap((read) => read.messages).filter((message) => message.ts > scanSinceMs).map(clampRetrospectiveMessage).sort((a, b) => a.ts - b.ts || a.ordinal - b.ordinal);
|
|
2026
|
+
let unknownBoundary = !!firstExcludedSession && firstExcludedPendingTs === undefined;
|
|
2027
|
+
let firstUnreadTs = firstExcludedPendingTs ?? Number.POSITIVE_INFINITY;
|
|
2028
|
+
const oversizedSessions = new Map;
|
|
2029
|
+
for (const [index, read] of sinceReads.entries()) {
|
|
2030
|
+
if (!read.truncated)
|
|
2031
|
+
continue;
|
|
2032
|
+
const unreadTs = read.firstOmittedTs ?? read.messages.at(-1)?.ts;
|
|
2033
|
+
if (unreadTs === undefined) {
|
|
2034
|
+
unknownBoundary = true;
|
|
2035
|
+
continue;
|
|
2036
|
+
}
|
|
2037
|
+
firstUnreadTs = Math.min(firstUnreadTs, unreadTs);
|
|
2038
|
+
const sessionId = sessionsToRead[index]?.sessionId;
|
|
2039
|
+
if (sessionId !== undefined && read.firstOmittedTs !== undefined && read.firstOmittedTs === oldestBySession?.get(sessionId)) {
|
|
2040
|
+
oversizedSessions.set(sessionId, read.firstOmittedTs);
|
|
2020
2041
|
}
|
|
2021
2042
|
}
|
|
2022
|
-
const
|
|
2043
|
+
const {
|
|
2044
|
+
kept: keptSince,
|
|
2045
|
+
budgetTruncated,
|
|
2046
|
+
oversized
|
|
2047
|
+
} = admitRetrospectiveCohorts(allSince, unknownBoundary ? scanSinceMs : firstUnreadTs, maxMessages, promptInputLimitTokens);
|
|
2048
|
+
const lastKept = keptSince.at(-1);
|
|
2023
2049
|
let maxScannedTs = scanSinceMs;
|
|
2024
|
-
if (
|
|
2025
|
-
|
|
2026
|
-
maxScannedTs =
|
|
2050
|
+
if (!unknownBoundary) {
|
|
2051
|
+
if (oversized) {
|
|
2052
|
+
maxScannedTs = oversized.ts;
|
|
2053
|
+
logSkippedRetrospectiveCohort(oversized.rows.map(({ sessionId }) => sessionId), maxScannedTs, oversized.rows.length, false);
|
|
2054
|
+
} else if (lastKept) {
|
|
2055
|
+
maxScannedTs = lastKept.ts;
|
|
2056
|
+
} else if (Number.isFinite(firstUnreadTs)) {
|
|
2057
|
+
const blockedSessions = sessions.filter(({ session }) => oldestBySession?.get(session.sessionId) === firstUnreadTs);
|
|
2058
|
+
const hitSessionReadCap = blockedSessions.some(({ session }) => oversizedSessions.get(session.sessionId) === firstUnreadTs);
|
|
2059
|
+
if (hitSessionReadCap || blockedSessions.length > sessionLimit) {
|
|
2060
|
+
maxScannedTs = firstUnreadTs;
|
|
2061
|
+
logSkippedRetrospectiveCohort(blockedSessions.map(({ session }) => session.sessionId), maxScannedTs, Math.max(blockedSessions.length, hitSessionReadCap ? capPerSession + 1 : 0), true);
|
|
2062
|
+
} else {
|
|
2063
|
+
maxScannedTs = Math.max(scanSinceMs, firstUnreadTs - 1);
|
|
2064
|
+
}
|
|
2065
|
+
} else if (oldestBySession && allSince.length === 0) {
|
|
2066
|
+
for (const { session } of eligibleSessions) {
|
|
2067
|
+
maxScannedTs = Math.max(maxScannedTs, session.updatedAt ?? scanSinceMs);
|
|
2068
|
+
}
|
|
2027
2069
|
}
|
|
2028
2070
|
}
|
|
2029
|
-
for (const row of keptSince) {
|
|
2030
|
-
if (row.ts > maxScannedTs)
|
|
2031
|
-
maxScannedTs = row.ts;
|
|
2032
|
-
}
|
|
2033
|
-
let frontier = saturatedFrontier;
|
|
2034
|
-
const firstDropped = droppedSince[0];
|
|
2035
|
-
if (firstDropped)
|
|
2036
|
-
frontier = Math.min(frontier, firstDropped.ts - 1);
|
|
2037
|
-
if (typeof firstExcludedPendingTs === "number") {
|
|
2038
|
-
frontier = Math.min(frontier, firstExcludedPendingTs - 1);
|
|
2039
|
-
} else if (typeof firstExcludedSession?.updatedAt === "number") {
|
|
2040
|
-
frontier = Math.min(frontier, firstExcludedSession.updatedAt - 1);
|
|
2041
|
-
}
|
|
2042
|
-
maxScannedTs = Math.max(scanSinceMs, Math.min(maxScannedTs, frontier));
|
|
2043
2071
|
const keptSessionIds = new Set(keptSince.map((message) => message.sessionId));
|
|
2044
2072
|
const overlapSessions = sessionsToRead.filter((session) => keptSessionIds.has(session.sessionId));
|
|
2045
2073
|
const overlapBatches = overlapUserCount > 0 && watermarkMs > 0 && watermarkMs >= recencyCutoffMs ? await Promise.all(overlapSessions.map((session) => provider.readUserMessagesBefore(session.sessionId, watermarkMs, overlapUserCount))) : [];
|
|
2046
2074
|
const seen = new Set;
|
|
2047
|
-
const merged = [];
|
|
2075
|
+
const merged = [...keptSince];
|
|
2048
2076
|
const appendUnique = (row) => {
|
|
2049
2077
|
const key = `${row.sessionId}\x00${row.ts}\x00${row.role}\x00${row.toolName ?? ""}`;
|
|
2050
2078
|
if (seen.has(key))
|
|
@@ -2053,9 +2081,7 @@ async function readRetrospectiveScanWindow(provider, projectIdentity, watermarkM
|
|
|
2053
2081
|
merged.push(row);
|
|
2054
2082
|
return true;
|
|
2055
2083
|
};
|
|
2056
|
-
|
|
2057
|
-
appendUnique(row);
|
|
2058
|
-
const overlapRows = overlapBatches.flat().filter((message) => message.ts >= recencyCutoffMs).map(clampRetrospectiveMessage).sort((a, b) => a.ts - b.ts || a.ordinal - b.ordinal);
|
|
2084
|
+
const overlapRows = overlapBatches.flat().filter((message) => message.ts >= recencyCutoffMs && message.ts <= watermarkMs).map(clampRetrospectiveMessage).sort((a, b) => a.ts - b.ts || a.ordinal - b.ordinal);
|
|
2059
2085
|
for (const row of overlapRows) {
|
|
2060
2086
|
const beforeLength = merged.length;
|
|
2061
2087
|
if (!appendUnique(row))
|
|
@@ -2075,7 +2101,7 @@ async function readRetrospectiveScanWindow(provider, projectIdentity, watermarkM
|
|
|
2075
2101
|
maxScannedTs,
|
|
2076
2102
|
promptTokens,
|
|
2077
2103
|
...promptInputLimitTokens === undefined ? {} : { promptInputLimitTokens },
|
|
2078
|
-
budgetTruncated
|
|
2104
|
+
budgetTruncated
|
|
2079
2105
|
};
|
|
2080
2106
|
} finally {
|
|
2081
2107
|
provider.dispose?.();
|
|
@@ -2108,7 +2134,12 @@ function readOpenCodeMessagesSince(db, sessionId, sinceMs, capPerSession) {
|
|
|
2108
2134
|
LIMIT ?`).all(sessionId, sinceMs, limit + 1);
|
|
2109
2135
|
const truncated = rows.length > limit;
|
|
2110
2136
|
const kept = truncated ? rows.slice(0, limit) : rows;
|
|
2111
|
-
|
|
2137
|
+
const firstOmitted = rows[limit];
|
|
2138
|
+
return {
|
|
2139
|
+
messages: normalizeOpenCodeRows(db, sessionId, kept),
|
|
2140
|
+
truncated,
|
|
2141
|
+
...firstOmitted ? { firstOmittedTs: firstOmitted.time_created } : {}
|
|
2142
|
+
};
|
|
2112
2143
|
}
|
|
2113
2144
|
function readOpenCodeOldestMessageTimesSince(db, sessionIds, sinceMs) {
|
|
2114
2145
|
const result = new Map;
|
|
@@ -2404,7 +2435,7 @@ function recordRetrospectiveWindowProcessed(db, projectPath, windowKey) {
|
|
|
2404
2435
|
}
|
|
2405
2436
|
|
|
2406
2437
|
// src/features/magic-context/dreamer/task-executor.ts
|
|
2407
|
-
import { createHash as
|
|
2438
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
2408
2439
|
import { existsSync as existsSync5, readFileSync as readFileSync3 } from "node:fs";
|
|
2409
2440
|
|
|
2410
2441
|
// src/features/magic-context/mural/compress-cues.ts
|
|
@@ -3480,7 +3511,6 @@ async function readFailedChildMessages(client, sessionId, directory) {
|
|
|
3480
3511
|
}
|
|
3481
3512
|
|
|
3482
3513
|
// src/features/magic-context/dreamer/classify.ts
|
|
3483
|
-
var MIN_POOL_TO_CLASSIFY = 10;
|
|
3484
3514
|
var FULL_POOL_CEILING = 100;
|
|
3485
3515
|
var STAGE3_ANCHOR_COUNT = 30;
|
|
3486
3516
|
var CLASSIFY_CHUNK_SIZE = 100;
|
|
@@ -6987,7 +7017,7 @@ function snapshotMaintainDocsFiles(docsDir) {
|
|
|
6987
7017
|
}
|
|
6988
7018
|
|
|
6989
7019
|
// src/features/magic-context/dreamer/map-memories.ts
|
|
6990
|
-
import { createHash as
|
|
7020
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
6991
7021
|
|
|
6992
7022
|
// src/features/magic-context/dreamer/map-memories-prompt.ts
|
|
6993
7023
|
import { execFile as execFile2 } from "node:child_process";
|
|
@@ -7192,17 +7222,14 @@ function parsePartialMapMemoriesManifest(text, expectedIds) {
|
|
|
7192
7222
|
return [...entries.values()];
|
|
7193
7223
|
}
|
|
7194
7224
|
|
|
7195
|
-
// src/features/magic-context/dreamer/map-memories.ts
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
var CONSECUTIVE_TIMEOUT_LIMIT2 = 2;
|
|
7199
|
-
var MAX_INDEPENDENT_REQUEUE_PER_RUN = MAP_BATCH_SIZE;
|
|
7200
|
-
function retryKey(project) {
|
|
7225
|
+
// src/features/magic-context/dreamer/map-memories-retry.ts
|
|
7226
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
7227
|
+
function mapMemoryRetryKey(project) {
|
|
7201
7228
|
return `map-memories:retry:${project}`;
|
|
7202
7229
|
}
|
|
7203
|
-
function
|
|
7230
|
+
function readMapMemoryRetries(db, project) {
|
|
7204
7231
|
try {
|
|
7205
|
-
const parsed = JSON.parse(getDreamState(db,
|
|
7232
|
+
const parsed = JSON.parse(getDreamState(db, mapMemoryRetryKey(project)) ?? "{}");
|
|
7206
7233
|
if (!isRecord(parsed))
|
|
7207
7234
|
return {};
|
|
7208
7235
|
const retries = {};
|
|
@@ -7224,10 +7251,26 @@ function contentKey(memory) {
|
|
|
7224
7251
|
return createHash5("sha256").update(`${memory.category}
|
|
7225
7252
|
${memory.content}`).digest("hex");
|
|
7226
7253
|
}
|
|
7227
|
-
function
|
|
7254
|
+
function isMapMemoryDeferred(memory, retries, now = Date.now()) {
|
|
7228
7255
|
const retry = retries[memory.id];
|
|
7229
|
-
return !!retry && retry.
|
|
7256
|
+
return !!retry && retry.deferUntil > now && retry.content === contentKey(memory);
|
|
7257
|
+
}
|
|
7258
|
+
function nextMapMemoryRetry(memory, prior) {
|
|
7259
|
+
const content = contentKey(memory);
|
|
7260
|
+
const failures = (prior?.content === content ? prior.failures : 0) + 1;
|
|
7261
|
+
const maxWaitHours = 7 * 24;
|
|
7262
|
+
return {
|
|
7263
|
+
content,
|
|
7264
|
+
failures,
|
|
7265
|
+
deferUntil: failures < 2 ? 0 : Date.now() + Math.min(maxWaitHours, 2 ** (failures - 2)) * 3600000
|
|
7266
|
+
};
|
|
7230
7267
|
}
|
|
7268
|
+
|
|
7269
|
+
// src/features/magic-context/dreamer/map-memories.ts
|
|
7270
|
+
var MAP_BATCH_SIZE = 5;
|
|
7271
|
+
var MAP_BATCH_FLOOR_MS = 240000;
|
|
7272
|
+
var CONSECUTIVE_TIMEOUT_LIMIT2 = 2;
|
|
7273
|
+
var MAX_INDEPENDENT_REQUEUE_PER_RUN = MAP_BATCH_SIZE;
|
|
7231
7274
|
function assistantText(messages) {
|
|
7232
7275
|
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(`
|
|
7233
7276
|
`) : "")).join(`
|
|
@@ -7296,8 +7339,8 @@ function selectMapMemoryInputs(db, projectIdentity, repoDir, includeDeferred = f
|
|
|
7296
7339
|
if (requeue.length >= MAX_INDEPENDENT_REQUEUE_PER_RUN)
|
|
7297
7340
|
break;
|
|
7298
7341
|
}
|
|
7299
|
-
const retries =
|
|
7300
|
-
return [...unmappedInputs, ...requeue].filter((memory) => includeDeferred || !
|
|
7342
|
+
const retries = readMapMemoryRetries(db, projectIdentity);
|
|
7343
|
+
return [...unmappedInputs, ...requeue].filter((memory) => includeDeferred || !isMapMemoryDeferred(memory, retries));
|
|
7301
7344
|
}
|
|
7302
7345
|
async function mapMemories(args) {
|
|
7303
7346
|
const result = {
|
|
@@ -7308,12 +7351,12 @@ async function mapMemories(args) {
|
|
|
7308
7351
|
complete: true
|
|
7309
7352
|
};
|
|
7310
7353
|
const allInputs = selectMapMemoryInputs(args.db, args.projectIdentity, args.sessionDirectory, true);
|
|
7311
|
-
const retries =
|
|
7354
|
+
const retries = readMapMemoryRetries(args.db, args.projectIdentity);
|
|
7312
7355
|
const activeIds = new Set(allInputs.map((memory) => String(memory.id)));
|
|
7313
7356
|
for (const id of Object.keys(retries))
|
|
7314
7357
|
if (!activeIds.has(id))
|
|
7315
7358
|
delete retries[id];
|
|
7316
|
-
const inputs = allInputs.filter((memory) => !
|
|
7359
|
+
const inputs = allInputs.filter((memory) => !isMapMemoryDeferred(memory, retries));
|
|
7317
7360
|
result.remaining = allInputs.length;
|
|
7318
7361
|
result.complete = result.remaining === 0;
|
|
7319
7362
|
if (inputs.length === 0) {
|
|
@@ -7330,6 +7373,7 @@ async function mapMemories(args) {
|
|
|
7330
7373
|
try {
|
|
7331
7374
|
let consecutiveTimeouts = 0;
|
|
7332
7375
|
let timeoutStreakElapsedMs = [];
|
|
7376
|
+
const countedMisses = new Set;
|
|
7333
7377
|
for (let i = 0;i < batches.length; i += 1) {
|
|
7334
7378
|
const remainingMs = Math.max(0, args.deadline - Date.now());
|
|
7335
7379
|
if (remainingMs <= 0) {
|
|
@@ -7352,22 +7396,19 @@ async function mapMemories(args) {
|
|
|
7352
7396
|
}
|
|
7353
7397
|
const committed = outcome.mapped + outcome.independent;
|
|
7354
7398
|
const committedIds = new Set(outcome.committedIds);
|
|
7399
|
+
const missedIds = new Set(outcome.missedIds);
|
|
7355
7400
|
runLeaseGuardedWrite(args.db, args.holderId, args.leaseKey, () => {
|
|
7356
7401
|
for (const memory of batch.inputs) {
|
|
7357
7402
|
if (committedIds.has(memory.id)) {
|
|
7358
7403
|
delete retries[memory.id];
|
|
7359
7404
|
continue;
|
|
7360
7405
|
}
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
content,
|
|
7366
|
-
failures,
|
|
7367
|
-
deferUntil: failures < 2 ? 0 : Date.now() + Math.min(24, 2 ** (failures - 2)) * 3600000
|
|
7368
|
-
};
|
|
7406
|
+
if (missedIds.has(memory.id) && !countedMisses.has(memory.id)) {
|
|
7407
|
+
countedMisses.add(memory.id);
|
|
7408
|
+
retries[memory.id] = nextMapMemoryRetry(memory, retries[memory.id]);
|
|
7409
|
+
}
|
|
7369
7410
|
}
|
|
7370
|
-
setDreamState(args.db,
|
|
7411
|
+
setDreamState(args.db, mapMemoryRetryKey(args.projectIdentity), JSON.stringify(retries));
|
|
7371
7412
|
});
|
|
7372
7413
|
result.mapped += outcome.mapped;
|
|
7373
7414
|
result.independent += outcome.independent;
|
|
@@ -7379,7 +7420,7 @@ async function mapMemories(args) {
|
|
|
7379
7420
|
if (outcome.requeue?.length) {
|
|
7380
7421
|
if (!batch.isOmissionRetry) {
|
|
7381
7422
|
batches.push({
|
|
7382
|
-
inputs: outcome.requeue.filter((memory) => !
|
|
7423
|
+
inputs: outcome.requeue.filter((memory) => !isMapMemoryDeferred(memory, retries)),
|
|
7383
7424
|
isOmissionRetry: true
|
|
7384
7425
|
});
|
|
7385
7426
|
log2(`[dreamer] map-memories: committed ${committed}/${batch.inputs.length} mapping(s); requeueing ${outcome.requeue.length} omitted id(s) in a targeted retry`);
|
|
@@ -7467,11 +7508,7 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
7467
7508
|
stage = "apply";
|
|
7468
7509
|
const outcome = await applyParsedBatchMappings(args, batch, run.validated, budgetFinalized, true);
|
|
7469
7510
|
logBatchUsage(run.completion.messages ?? [], outcome.mapped + outcome.independent, startedAt);
|
|
7470
|
-
|
|
7471
|
-
return {
|
|
7472
|
-
...outcome,
|
|
7473
|
-
requeue: budgetFinalized ? [] : batch.filter((memory) => !returnedIds.has(memory.id))
|
|
7474
|
-
};
|
|
7511
|
+
return completedMapBatch(outcome, batch, run.validated, budgetFinalized);
|
|
7475
7512
|
}
|
|
7476
7513
|
const client = args.client;
|
|
7477
7514
|
if (!client)
|
|
@@ -7525,11 +7562,7 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
7525
7562
|
stage = "apply";
|
|
7526
7563
|
const outcome = await applyParsedBatchMappings(args, batch, run.validated, budgetFinalized, true);
|
|
7527
7564
|
logBatchUsage(run.output, outcome.mapped + outcome.independent, startedAt);
|
|
7528
|
-
|
|
7529
|
-
return {
|
|
7530
|
-
...outcome,
|
|
7531
|
-
requeue: budgetFinalized ? [] : batch.filter((memory) => !returnedIds.has(memory.id))
|
|
7532
|
-
};
|
|
7565
|
+
return completedMapBatch(outcome, batch, run.validated, budgetFinalized);
|
|
7533
7566
|
} catch (error) {
|
|
7534
7567
|
const desc = describeError(error);
|
|
7535
7568
|
log2(`[dreamer] map-memories batch failed: ${desc.brief}`, desc.stackHead ? { stackHead: desc.stackHead } : undefined);
|
|
@@ -7571,6 +7604,17 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
7571
7604
|
});
|
|
7572
7605
|
}
|
|
7573
7606
|
}
|
|
7607
|
+
function completedMapBatch(outcome, batch, parsed, budgetFinalized) {
|
|
7608
|
+
if (budgetFinalized)
|
|
7609
|
+
return outcome;
|
|
7610
|
+
const decided = new Set(parsed.map(({ id }) => id));
|
|
7611
|
+
const committed = new Set(outcome.committedIds);
|
|
7612
|
+
return {
|
|
7613
|
+
...outcome,
|
|
7614
|
+
missedIds: batch.filter(({ id }) => !decided.has(id)).map(({ id }) => id),
|
|
7615
|
+
requeue: batch.filter(({ id }) => !committed.has(id))
|
|
7616
|
+
};
|
|
7617
|
+
}
|
|
7574
7618
|
async function applyParsedBatchMappings(args, batch, parsed, budgetFinalized = false, allowPartial = false) {
|
|
7575
7619
|
const batchIds = new Set(batch.map((memory) => memory.id));
|
|
7576
7620
|
const valid = parsed.filter((entry) => batchIds.has(entry.id));
|
|
@@ -7662,7 +7706,7 @@ async function applyParsedBatchMappings(args, batch, parsed, budgetFinalized = f
|
|
|
7662
7706
|
name: "memory.set_mapping",
|
|
7663
7707
|
arguments: {
|
|
7664
7708
|
memory_project: args.projectIdentity,
|
|
7665
|
-
command_id: `${args.moduleRoute.moduleCommandId}:${
|
|
7709
|
+
command_id: `${args.moduleRoute.moduleCommandId}:${createHash6("sha256").update(rows.map((row) => row.memory_id).join(",")).digest("hex").slice(0, 16)}`,
|
|
7666
7710
|
rows
|
|
7667
7711
|
}
|
|
7668
7712
|
}
|
|
@@ -8516,16 +8560,24 @@ function countLiveMemories(db, projectPath, options = {}) {
|
|
|
8516
8560
|
const row = options.category ? db.prepare(`${sql} AND category = ?`).get(projectPath, Date.now(), options.category) : db.prepare(sql).get(projectPath, Date.now());
|
|
8517
8561
|
return row?.cnt ?? 0;
|
|
8518
8562
|
}
|
|
8563
|
+
var UNMAPPED_LIVE_MEMORIES_SQL = `FROM memories m
|
|
8564
|
+
WHERE m.project_path = ?
|
|
8565
|
+
AND m.status IN ('active','permanent')
|
|
8566
|
+
AND (m.expires_at IS NULL OR m.expires_at > ?)
|
|
8567
|
+
AND NOT EXISTS (SELECT 1 FROM memory_verifications v WHERE v.memory_id = m.id)`;
|
|
8519
8568
|
function countUnmappedActiveMemories(db, projectPath) {
|
|
8520
|
-
const
|
|
8521
|
-
|
|
8522
|
-
|
|
8523
|
-
|
|
8524
|
-
|
|
8525
|
-
|
|
8526
|
-
|
|
8527
|
-
|
|
8528
|
-
|
|
8569
|
+
const now = Date.now();
|
|
8570
|
+
const row = db.prepare(`SELECT COUNT(*) AS cnt ${UNMAPPED_LIVE_MEMORIES_SQL}`).get(projectPath, now);
|
|
8571
|
+
const total = row?.cnt ?? 0;
|
|
8572
|
+
if (total === 0)
|
|
8573
|
+
return 0;
|
|
8574
|
+
const retries = readMapMemoryRetries(db, projectPath);
|
|
8575
|
+
const waitingIds = Object.entries(retries).filter(([, retry]) => retry.deferUntil > now).map(([id]) => id);
|
|
8576
|
+
if (waitingIds.length === 0)
|
|
8577
|
+
return total;
|
|
8578
|
+
const waiting = db.prepare(`SELECT m.id, m.category, m.content ${UNMAPPED_LIVE_MEMORIES_SQL}
|
|
8579
|
+
AND m.id IN (SELECT CAST(value AS INTEGER) FROM json_each(?))`).all(projectPath, now, JSON.stringify(waitingIds));
|
|
8580
|
+
return total - waiting.filter((memory) => isMapMemoryDeferred(memory, retries, now)).length;
|
|
8529
8581
|
}
|
|
8530
8582
|
function countCompartmentsSince(db, projectPath, since) {
|
|
8531
8583
|
const row = db.prepare(`SELECT COUNT(*) AS cnt
|
|
@@ -8708,7 +8760,7 @@ function getDreamTaskBacklog(db, projectPath, task, options = {}) {
|
|
|
8708
8760
|
case "classify-memories": {
|
|
8709
8761
|
const total = countLiveMemories(db, projectPath);
|
|
8710
8762
|
return {
|
|
8711
|
-
pending: countLiveMemories(db, projectPath, { unclassifiedOnly: true }),
|
|
8763
|
+
pending: total >= MIN_POOL_TO_CLASSIFY ? countLiveMemories(db, projectPath, { unclassifiedOnly: true }) : 0,
|
|
8712
8764
|
total
|
|
8713
8765
|
};
|
|
8714
8766
|
}
|
|
@@ -8814,6 +8866,9 @@ function getDreamTaskBacklogs(db, projectPath, tasks = CANONICAL_DREAM_TASKS, op
|
|
|
8814
8866
|
cache.eligibleProjects.clear();
|
|
8815
8867
|
cache.eligibleProjects.set(projectPath, eligible);
|
|
8816
8868
|
}
|
|
8869
|
+
if (eligible && tasks.includes("map-memories")) {
|
|
8870
|
+
eligible = !Object.values(readMapMemoryRetries(db, projectPath)).some(({ deferUntil }) => deferUntil > 0);
|
|
8871
|
+
}
|
|
8817
8872
|
const optionKey = (value) => value === undefined ? "omitted" : value === null ? "null" : `number:${value}`;
|
|
8818
8873
|
const key = JSON.stringify([
|
|
8819
8874
|
getHarness2(),
|
|
@@ -8849,7 +8904,7 @@ function evaluateTaskGate(task, ctx) {
|
|
|
8849
8904
|
case "compress-cues":
|
|
8850
8905
|
return countLiveMemories(db, project) > 0;
|
|
8851
8906
|
case "classify-memories":
|
|
8852
|
-
return countLiveMemories(db, project)
|
|
8907
|
+
return countLiveMemories(db, project) >= MIN_POOL_TO_CLASSIFY;
|
|
8853
8908
|
case "retrospective":
|
|
8854
8909
|
return countProjectSessionsSince(db, project, ctx.retrospectiveWatermarkMs ?? null) > 0;
|
|
8855
8910
|
case "maintain-docs":
|
|
@@ -8870,7 +8925,7 @@ function evaluateTaskGate(task, ctx) {
|
|
|
8870
8925
|
}
|
|
8871
8926
|
|
|
8872
8927
|
// src/features/magic-context/dreamer/verify.ts
|
|
8873
|
-
import { createHash as
|
|
8928
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
8874
8929
|
|
|
8875
8930
|
// src/features/magic-context/dreamer/verify-diff.ts
|
|
8876
8931
|
import { execFile as execFile3 } from "node:child_process";
|
|
@@ -8994,7 +9049,7 @@ Read only these changed line ranges if they may affect the claim.`
|
|
|
8994
9049
|
import path5 from "node:path";
|
|
8995
9050
|
|
|
8996
9051
|
// src/features/magic-context/dreamer/verify-state.ts
|
|
8997
|
-
import { createHash as
|
|
9052
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
8998
9053
|
import { readFile, realpath as realpath2 } from "node:fs/promises";
|
|
8999
9054
|
import path4 from "node:path";
|
|
9000
9055
|
function verificationMetadata(memory) {
|
|
@@ -9007,7 +9062,7 @@ function verificationMetadata(memory) {
|
|
|
9007
9062
|
}
|
|
9008
9063
|
async function verificationFilesFingerprint(directory, files) {
|
|
9009
9064
|
const root = await resolveGitTopLevel(directory) ?? path4.resolve(directory);
|
|
9010
|
-
const hash =
|
|
9065
|
+
const hash = createHash7("sha256");
|
|
9011
9066
|
for (const file of [...new Set(files)].sort()) {
|
|
9012
9067
|
const absolute = path4.resolve(root, file);
|
|
9013
9068
|
const withinRoot = (candidate) => {
|
|
@@ -9020,7 +9075,7 @@ async function verificationFilesFingerprint(directory, files) {
|
|
|
9020
9075
|
try {
|
|
9021
9076
|
if (!withinRoot(await realpath2(absolute)))
|
|
9022
9077
|
return null;
|
|
9023
|
-
hash.update(
|
|
9078
|
+
hash.update(createHash7("sha256").update(await readFile(absolute)).digest("hex"));
|
|
9024
9079
|
} catch (error) {
|
|
9025
9080
|
if (error.code !== "ENOENT")
|
|
9026
9081
|
return null;
|
|
@@ -9825,7 +9880,7 @@ async function applyParsedVerifyManifest(args, batch, parsed, headAtPrompt, budg
|
|
|
9825
9880
|
name: "memory.set_verification",
|
|
9826
9881
|
arguments: {
|
|
9827
9882
|
memory_project: args.projectIdentity,
|
|
9828
|
-
command_id: `${args.moduleRoute.moduleCommandId}:${
|
|
9883
|
+
command_id: `${args.moduleRoute.moduleCommandId}:${createHash8("sha256").update(rows.map((row) => row.memory_id).join(",")).digest("hex").slice(0, 16)}`,
|
|
9829
9884
|
rows
|
|
9830
9885
|
}
|
|
9831
9886
|
}
|
|
@@ -10739,7 +10794,7 @@ function parseFrictionGateVerdict(verdict) {
|
|
|
10739
10794
|
}
|
|
10740
10795
|
function computeRetrospectiveWindowKey(flagged) {
|
|
10741
10796
|
const anchors = flagged.map((message) => `${message.sessionId}:${message.ts}`).sort().join("|");
|
|
10742
|
-
return
|
|
10797
|
+
return createHash9("sha256").update(anchors).digest("hex").slice(0, 32);
|
|
10743
10798
|
}
|
|
10744
10799
|
function renderFrictionWindow(messages, flaggedOrdinals, radius = 2) {
|
|
10745
10800
|
const flagged = new Set(flaggedOrdinals);
|
|
@@ -10858,6 +10913,13 @@ async function runRetrospectiveTask(config, ctx, helpers) {
|
|
|
10858
10913
|
const recencyDays = Math.max(1, Math.floor(config.retrospectiveRecencyDays ?? 30));
|
|
10859
10914
|
const recencyCutoffMs = helpers.invocationStartedAt - recencyDays * RETROSPECTIVE_DAY_MS;
|
|
10860
10915
|
const scan = await readRetrospectiveScanWindow(provider, projectIdentity, watermarkMs, RETROSPECTIVE_OVERLAP_USER_LINES, { usableInputTokens, recencyCutoffMs });
|
|
10916
|
+
ctx.onRetrospectiveScan?.({
|
|
10917
|
+
watermarkMs,
|
|
10918
|
+
maxScannedTs: scan.maxScannedTs,
|
|
10919
|
+
usableInputTokens,
|
|
10920
|
+
recencyCutoffMs,
|
|
10921
|
+
budgetTruncated: scan.budgetTruncated
|
|
10922
|
+
});
|
|
10861
10923
|
const clearedTaskStateJson = activeOverflow ? writeRetrospectiveOverflowState(taskState.root, null) : undefined;
|
|
10862
10924
|
const completedWindow = (retrospectiveWatermarkMs, noOpReason) => ({
|
|
10863
10925
|
retrospectiveWatermarkMs,
|
|
@@ -11645,6 +11707,7 @@ async function runDomainGroup(deps, group, cb) {
|
|
|
11645
11707
|
}
|
|
11646
11708
|
}
|
|
11647
11709
|
let outcome;
|
|
11710
|
+
const diagnostics = {};
|
|
11648
11711
|
const startedAt = Date.now();
|
|
11649
11712
|
try {
|
|
11650
11713
|
outcome = await executor(due.config, {
|
|
@@ -11652,7 +11715,12 @@ async function runDomainGroup(deps, group, cb) {
|
|
|
11652
11715
|
projectIdentity,
|
|
11653
11716
|
holderId,
|
|
11654
11717
|
leaseKey,
|
|
11655
|
-
leaseAcquisition: acquisition
|
|
11718
|
+
leaseAcquisition: acquisition,
|
|
11719
|
+
...due.config.task === "retrospective" ? {
|
|
11720
|
+
onRetrospectiveScan: (scan) => {
|
|
11721
|
+
diagnostics.retrospectiveScan = scan;
|
|
11722
|
+
}
|
|
11723
|
+
} : {}
|
|
11656
11724
|
});
|
|
11657
11725
|
} catch (error) {
|
|
11658
11726
|
outcome = { status: "failed", transient: true, error: String(error) };
|
|
@@ -11663,6 +11731,11 @@ async function runDomainGroup(deps, group, cb) {
|
|
|
11663
11731
|
cb?.onSkipped?.(due.config.task, outcome.detail);
|
|
11664
11732
|
} else if (outcome.status === "completed") {
|
|
11665
11733
|
advanceAfterRun(db, projectIdentity, due, finishedAt, "completed", null, outcome.schedulePatch, startedAt);
|
|
11734
|
+
const scan = diagnostics.retrospectiveScan;
|
|
11735
|
+
if (scan) {
|
|
11736
|
+
const stored = readRetrospectiveWatermark(db, projectIdentity, due.config.task);
|
|
11737
|
+
log2(`[dreamer] retrospective: watermark start=${scan.watermarkMs} maxScannedTs=${scan.maxScannedTs} patch=${outcome.schedulePatch?.retrospectiveWatermarkMs ?? "none"} stored=${stored ?? "none"} usableInputTokens=${scan.usableInputTokens} recencyCutoffMs=${scan.recencyCutoffMs} budgetTruncated=${scan.budgetTruncated}`, { projectIdentity });
|
|
11738
|
+
}
|
|
11666
11739
|
cb?.onRan?.(due.config.task, outcome.detail, outcome.backlog);
|
|
11667
11740
|
} else if (outcome.transient) {
|
|
11668
11741
|
recordTransientFailure(db, projectIdentity, due, finishedAt, outcome.error ?? null, outcome.schedulePatch);
|
|
@@ -12307,7 +12380,7 @@ function createDreamTimerModuleClient(moduleClient) {
|
|
|
12307
12380
|
import { readFileSync as readFileSync4, statSync as statSync3 } from "node:fs";
|
|
12308
12381
|
|
|
12309
12382
|
// src/plugin/embedding-bootstrap-helpers.ts
|
|
12310
|
-
import { createHash as
|
|
12383
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
12311
12384
|
var EMBEDDING_AFFECTING_KEYS = new Set([
|
|
12312
12385
|
"embedding.api_key",
|
|
12313
12386
|
"embedding.endpoint",
|
|
@@ -12356,7 +12429,7 @@ var EMBEDDING_WARNING_TERMS = [
|
|
|
12356
12429
|
];
|
|
12357
12430
|
var loggedFailureSignatures = new Map;
|
|
12358
12431
|
function sha256Prefix(value, length = 16) {
|
|
12359
|
-
return
|
|
12432
|
+
return createHash10("sha256").update(value).digest("hex").slice(0, length);
|
|
12360
12433
|
}
|
|
12361
12434
|
function warningLooksEmbeddingRelated(message) {
|
|
12362
12435
|
const lower = message.toLowerCase();
|
|
@@ -13140,6 +13213,79 @@ function getActiveMemoryImportanceHistogram(db, projectPath) {
|
|
|
13140
13213
|
};
|
|
13141
13214
|
}
|
|
13142
13215
|
|
|
13216
|
+
// src/features/magic-context/memory/identity-merge-command.ts
|
|
13217
|
+
var IDENTITY_MERGE_COMMAND = "npx @cortexkit/magic-context@latest doctor merge-identities";
|
|
13218
|
+
var IDENTITY_MERGE_PREVIEW_HINT = "It shows what would move. Add --apply to move them.";
|
|
13219
|
+
function shellArg(value, platform) {
|
|
13220
|
+
if (/^[\w.:/-]+$/.test(value))
|
|
13221
|
+
return value;
|
|
13222
|
+
return platform === "win32" ? `"${value}"` : `'${value.replaceAll("'", "'\\''")}'`;
|
|
13223
|
+
}
|
|
13224
|
+
function identityMergeCommand(from, to, platform = process.platform) {
|
|
13225
|
+
return `${IDENTITY_MERGE_COMMAND} --from ${shellArg(from, platform)} --to ${to ? shellArg(to, platform) : '"DESTINATION_IDENTITY"'}`;
|
|
13226
|
+
}
|
|
13227
|
+
|
|
13228
|
+
// src/features/magic-context/memory/project-binding-notice.ts
|
|
13229
|
+
var observedBindings = new WeakMap;
|
|
13230
|
+
function bindingLog(harness, directory, old, identity, memories) {
|
|
13231
|
+
return `project binding changed harness=${harness} cwd=${directory || "unknown"} old=${old ?? "none"} new=${identity} memories=${memories}`;
|
|
13232
|
+
}
|
|
13233
|
+
function observeSessionProjectBinding(db, sessionId, identity, directory, notify) {
|
|
13234
|
+
const change = recordSessionProjectIdentity(db, sessionId, identity);
|
|
13235
|
+
const harness = getHarness2();
|
|
13236
|
+
let observations = observedBindings.get(db);
|
|
13237
|
+
if (!observations) {
|
|
13238
|
+
observations = new BoundedSessionMap(1000);
|
|
13239
|
+
observedBindings.set(db, observations);
|
|
13240
|
+
}
|
|
13241
|
+
const key = `${harness}\x00${sessionId}`;
|
|
13242
|
+
const last = observations.get(key);
|
|
13243
|
+
const noticed = last?.noticed ?? new Set;
|
|
13244
|
+
const observation = {
|
|
13245
|
+
directory,
|
|
13246
|
+
noticed,
|
|
13247
|
+
warning: change ? undefined : last?.warning
|
|
13248
|
+
};
|
|
13249
|
+
observations.set(key, observation);
|
|
13250
|
+
const old = change?.previousProjectPath;
|
|
13251
|
+
if (!change || !old && harness !== "pi" && harness !== "omp")
|
|
13252
|
+
return;
|
|
13253
|
+
const memories = old ? getMemoryCount2(db, old) : 0;
|
|
13254
|
+
const binding = bindingLog(harness, directory, old, identity, memories);
|
|
13255
|
+
if (!old || !memories) {
|
|
13256
|
+
sessionLog2(sessionId, binding);
|
|
13257
|
+
return;
|
|
13258
|
+
}
|
|
13259
|
+
const oldDirectory = [last?.directory, directory].find((path) => path && directoryFallback(path) === old);
|
|
13260
|
+
const location = oldDirectory ? `the old folder (${oldDirectory})` : `the old project (${old})`;
|
|
13261
|
+
let guidance;
|
|
13262
|
+
if (old.startsWith("dir:") && /^(dir|git):/.test(identity)) {
|
|
13263
|
+
guidance = `Review the merge first:
|
|
13264
|
+
${identityMergeCommand(oldDirectory ?? old, identity)}
|
|
13265
|
+
${IDENTITY_MERGE_PREVIEW_HINT}`;
|
|
13266
|
+
} else if (old.startsWith("git:") && identity.startsWith("dir:")) {
|
|
13267
|
+
guidance = "A repository's memories cannot be merged into a folder project.";
|
|
13268
|
+
} else {
|
|
13269
|
+
guidance = "Run `npx @cortexkit/magic-context@latest doctor` to see how these memories can be merged.";
|
|
13270
|
+
}
|
|
13271
|
+
const count = `${memories} ${memories === 1 ? "memory" : "memories"}`;
|
|
13272
|
+
observation.warning = `${count} stayed under this session's previous project. Nothing was moved.
|
|
13273
|
+
${guidance}`;
|
|
13274
|
+
if (noticed.has(old)) {
|
|
13275
|
+
sessionLog2(sessionId, binding);
|
|
13276
|
+
return;
|
|
13277
|
+
}
|
|
13278
|
+
noticed.add(old);
|
|
13279
|
+
const notice = `This session changed projects. ${count} stayed with ${location}; nothing moved. ${guidance}`;
|
|
13280
|
+
sessionLog2(sessionId, `${binding} notice=${JSON.stringify(notice)}`);
|
|
13281
|
+
try {
|
|
13282
|
+
notify?.(notice);
|
|
13283
|
+
} catch {}
|
|
13284
|
+
}
|
|
13285
|
+
function getProjectBindingWarning(db, sessionId) {
|
|
13286
|
+
return observedBindings.get(db)?.peek(`${getHarness2()}\x00${sessionId}`)?.warning;
|
|
13287
|
+
}
|
|
13288
|
+
|
|
13143
13289
|
// src/features/magic-context/session-cache-ttl.ts
|
|
13144
13290
|
function readSessionCacheTtl(db, sessionId) {
|
|
13145
13291
|
const saved = readReplayEnvelope(db, sessionId).cacheTtlPolicy;
|
|
@@ -13807,7 +13953,9 @@ function statusWarningsFromDetail(detail) {
|
|
|
13807
13953
|
const warnings = [];
|
|
13808
13954
|
if (detail.lastTransformError)
|
|
13809
13955
|
warnings.push("transform_update_failed");
|
|
13810
|
-
if (
|
|
13956
|
+
if (detail.forkHistoryGap)
|
|
13957
|
+
warnings.push("fork_history_gap");
|
|
13958
|
+
else if ((detail.historianFailureCount ?? 0) > 0)
|
|
13811
13959
|
warnings.push("historian_unavailable");
|
|
13812
13960
|
if ((detail.configParseFailures?.length ?? 0) > 0)
|
|
13813
13961
|
warnings.push("configuration_warning");
|
|
@@ -13862,6 +14010,7 @@ function statusSummaryFromDetail(detail) {
|
|
|
13862
14010
|
compactionMarker: detail.compactionMarker,
|
|
13863
14011
|
warnings: statusWarningsFromDetail(detail),
|
|
13864
14012
|
hiddenVariantWarnings: detail.hiddenVariantWarnings ?? [],
|
|
14013
|
+
projectBindingWarning: detail.projectBindingWarning,
|
|
13865
14014
|
dreamerSkipped: detail.dreamerSkipped,
|
|
13866
14015
|
hiddenModelSkips: detail.hiddenModelSkips,
|
|
13867
14016
|
dreamerQuotas: [
|
|
@@ -13966,6 +14115,10 @@ function renderUserStatusSummary(summary, style) {
|
|
|
13966
14115
|
for (const warning of summary.hiddenVariantWarnings ?? []) {
|
|
13967
14116
|
lines.push(style === "markdown" ? `- **Warning:** ${warning}` : `Warning: ${warning}`);
|
|
13968
14117
|
}
|
|
14118
|
+
if (summary.projectBindingWarning) {
|
|
14119
|
+
const label = style === "markdown" ? "- **Warning:**" : "Warning:";
|
|
14120
|
+
lines.push(`${label} ${summary.projectBindingWarning}`);
|
|
14121
|
+
}
|
|
13969
14122
|
for (const warning of summary.warnings) {
|
|
13970
14123
|
lines.push(style === "markdown" ? `- **Warning:** ${renderUserFacingFailure(warning)}` : `Warning: ${renderUserFacingFailure(warning)}`);
|
|
13971
14124
|
}
|
|
@@ -14616,7 +14769,11 @@ ${c.content}
|
|
|
14616
14769
|
const rebaseNotice = readCoordinateRebaseNotice(db, sessionId);
|
|
14617
14770
|
const rebaseNoticeLine = rebaseNotice ? formatCoordinateRebaseNotice(rebaseNotice) : null;
|
|
14618
14771
|
if (rebaseNotice && rebaseNoticeLine) {
|
|
14619
|
-
|
|
14772
|
+
if (rebaseNotice.inheritedGaps !== undefined) {
|
|
14773
|
+
lines.push("", "### Saved History Recovery", `- ${rebaseNoticeLine}.`);
|
|
14774
|
+
} else {
|
|
14775
|
+
lines.push("", "### Store Conversion", `- The host changed how it stores this conversation (${rebaseNotice.previousGeneration ?? "unrecorded"} → ${rebaseNotice.generation}); saved positions were re-derived from message ids.`, `- ${rebaseNoticeLine}.`);
|
|
14776
|
+
}
|
|
14620
14777
|
}
|
|
14621
14778
|
lines.push("", "### History Compression", `- Compartments: ${compartments.length}`, ...rebaseNotice && rebaseNotice.unresolvedCompartments > 0 ? [
|
|
14622
14779
|
`- Excluded from range recovery: ${rebaseNotice.unresolvedCompartments} (endpoint message no longer in this host's history)`
|
|
@@ -15962,6 +16119,7 @@ function buildSidebarSnapshot(db, sessionId, directory, liveSessionState, inject
|
|
|
15962
16119
|
readySmartNoteCount,
|
|
15963
16120
|
cacheTtl,
|
|
15964
16121
|
lastTransformError: meta?.last_transform_error ? String(meta.last_transform_error) : null,
|
|
16122
|
+
projectBindingWarning: getProjectBindingWarning(db, sessionId),
|
|
15965
16123
|
lastDreamerRunAt,
|
|
15966
16124
|
projectIdentity,
|
|
15967
16125
|
dreamerBacklog,
|
|
@@ -16466,6 +16624,15 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16466
16624
|
const rawConfig = config;
|
|
16467
16625
|
const getNotificationParams = (sessionId) => getLiveNotificationParams(sessionId, liveSessionState.liveModelBySession, liveSessionState.variantBySession, liveSessionState.agentBySession, currentPluginConfigReader(directory)?.poll().effective.toast_duration_ms ?? config.toast_duration_ms);
|
|
16468
16626
|
const injectionBudgetTokens = config.memory?.injection_budget_tokens;
|
|
16627
|
+
const showForkHistoryGap = (db, sessionId) => {
|
|
16628
|
+
if (!compactionEnabled || config.transform_mode === "rust")
|
|
16629
|
+
return false;
|
|
16630
|
+
try {
|
|
16631
|
+
return args.readForkHistoryGap?.(db, sessionId) === true;
|
|
16632
|
+
} catch {
|
|
16633
|
+
return false;
|
|
16634
|
+
}
|
|
16635
|
+
};
|
|
16469
16636
|
if (isDebugRpcEnabled(config)) {
|
|
16470
16637
|
const readMemory = () => buildDebugMemoryUsage(args.getDebugMemoryHolders?.());
|
|
16471
16638
|
rpcServer.handle("debug.memoryUsage", async () => ({ ...readMemory() }));
|
|
@@ -16486,7 +16653,10 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16486
16653
|
error: "Rust module status unavailable; canonical session state was not read"
|
|
16487
16654
|
};
|
|
16488
16655
|
}
|
|
16489
|
-
|
|
16656
|
+
const snapshot = buildSidebarSnapshotRpcResponse(db, sessionId, dir, liveSessionState, injectionBudgetTokens, rawConfig, moduleStatus, compactionEnabled);
|
|
16657
|
+
if (!snapshot.error && snapshot.disabled !== true && showForkHistoryGap(db, sessionId))
|
|
16658
|
+
snapshot.forkHistoryGap = true;
|
|
16659
|
+
return snapshot;
|
|
16490
16660
|
});
|
|
16491
16661
|
rpcServer.handle("session-owner", async (params) => {
|
|
16492
16662
|
const sessionId = String(params.sessionId ?? "");
|
|
@@ -16520,6 +16690,8 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16520
16690
|
};
|
|
16521
16691
|
}
|
|
16522
16692
|
const detail = buildStatusDetail(db, sessionId, dir, modelKey, rawConfig, liveSessionState, injectionBudgetTokens, moduleStatus, compactionEnabled);
|
|
16693
|
+
if (showForkHistoryGap(db, sessionId))
|
|
16694
|
+
detail.forkHistoryGap = true;
|
|
16523
16695
|
if (args.hiddenCompletionExecutor?.capabilities.tools === false) {
|
|
16524
16696
|
detail.dreamerUnsupportedTasks = toolLoopDreamTasks();
|
|
16525
16697
|
}
|
|
@@ -16565,7 +16737,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16565
16737
|
const buildManagedCtx = async (db) => {
|
|
16566
16738
|
const { deriveHistorianChunkTokens, resolveHistorianContextLimit } = await importPluginModule(() => import("./derive-budgets-2z6xxm7e.js"));
|
|
16567
16739
|
const { resolveHistorianModel } = await importPluginModule(() => import("./model-resolution-280gmqvd.js"));
|
|
16568
|
-
const { userObservationCollectionEnabled, userObservationsRequested } = await importPluginModule(() => import("./task-config-
|
|
16740
|
+
const { userObservationCollectionEnabled, userObservationsRequested } = await importPluginModule(() => import("./task-config-qt6n4bxm.js"));
|
|
16569
16741
|
const DEFAULT_HISTORIAN_TIMEOUT_MS = 10 * 60 * 1000;
|
|
16570
16742
|
const runConfig = historianRunConfig(config, currentPluginConfigReader(directory)?.poll().effective ?? config);
|
|
16571
16743
|
const historianModel = resolveHistorianModel(runConfig, "opencode");
|
|
@@ -16615,8 +16787,8 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16615
16787
|
const db = readDatabase();
|
|
16616
16788
|
if (!db)
|
|
16617
16789
|
return { ok: false, error: "db unavailable" };
|
|
16618
|
-
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-
|
|
16619
|
-
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-
|
|
16790
|
+
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-fjdp3t1d.js"));
|
|
16791
|
+
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-7x518gew.js"));
|
|
16620
16792
|
log2(`[rpc] recomp requested for session ${sessionId}`);
|
|
16621
16793
|
if (!args.client && !args.hiddenCompletionExecutor) {
|
|
16622
16794
|
return {
|
|
@@ -16700,7 +16872,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16700
16872
|
const db = readDatabase();
|
|
16701
16873
|
if (!db)
|
|
16702
16874
|
return { ok: false, error: "db unavailable" };
|
|
16703
|
-
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-
|
|
16875
|
+
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-k29zqfp9.js"));
|
|
16704
16876
|
const model = await args.readSelectedSessionModel?.(sessionId) ?? liveSessionState.liveModelBySession.get(sessionId);
|
|
16705
16877
|
const window = resolveOpenCodeWrapupWindow(db, sessionId, model);
|
|
16706
16878
|
if (!window)
|
|
@@ -18080,7 +18252,7 @@ function evaluateRequestToolsRelease(args) {
|
|
|
18080
18252
|
}
|
|
18081
18253
|
|
|
18082
18254
|
// src/hooks/magic-context/rust-mode-transform.ts
|
|
18083
|
-
import { createHash as
|
|
18255
|
+
import { createHash as createHash14, randomUUID as randomUUID6 } from "node:crypto";
|
|
18084
18256
|
|
|
18085
18257
|
// src/features/magic-context/memory/single-store-embedding-drain.ts
|
|
18086
18258
|
function isWatermarkRow(row) {
|
|
@@ -18144,7 +18316,7 @@ function advanceEmbeddedWatermark(db, projectPath, upTo) {
|
|
|
18144
18316
|
}
|
|
18145
18317
|
|
|
18146
18318
|
// src/features/magic-context/mural/source-revision.ts
|
|
18147
|
-
import { createHash as
|
|
18319
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
18148
18320
|
var statements = new WeakMap;
|
|
18149
18321
|
function muralSourceRevision(db, projectPath) {
|
|
18150
18322
|
let statement = statements.get(db);
|
|
@@ -18161,7 +18333,7 @@ function muralSourceRevision(db, projectPath) {
|
|
|
18161
18333
|
statements.set(db, statement);
|
|
18162
18334
|
}
|
|
18163
18335
|
const row = statement.get(projectPath, Date.now());
|
|
18164
|
-
return
|
|
18336
|
+
return createHash11("sha256").update(row.revision).digest("hex");
|
|
18165
18337
|
}
|
|
18166
18338
|
|
|
18167
18339
|
// src/features/magic-context/install-instance-id.ts
|
|
@@ -20622,7 +20794,7 @@ function noteExternalLkgReplay(participant, sessionId, inputMessages, servedMess
|
|
|
20622
20794
|
}
|
|
20623
20795
|
|
|
20624
20796
|
// src/hooks/magic-context/rust-served-raw.ts
|
|
20625
|
-
import { createHash as
|
|
20797
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
20626
20798
|
class RustServedRawConflict extends EmergencyFailClosedError {
|
|
20627
20799
|
reason;
|
|
20628
20800
|
messageIds;
|
|
@@ -20636,7 +20808,7 @@ class RustServedRawConflict extends EmergencyFailClosedError {
|
|
|
20636
20808
|
}
|
|
20637
20809
|
function partDigest(part) {
|
|
20638
20810
|
const serialized = JSON.stringify(part);
|
|
20639
|
-
return
|
|
20811
|
+
return createHash13("sha256").update(stableStringify(serialized === undefined ? undefined : JSON.parse(serialized))).digest("hex");
|
|
20640
20812
|
}
|
|
20641
20813
|
function records(doc) {
|
|
20642
20814
|
if (doc.rustServedRaw === undefined)
|
|
@@ -21355,10 +21527,10 @@ function messageCacheSignature(message) {
|
|
|
21355
21527
|
const parts = Array.isArray(message.parts) ? message.parts : [];
|
|
21356
21528
|
const serializedParts = JSON.stringify(parts) ?? "null";
|
|
21357
21529
|
const serializedMessage = JSON.stringify(message) ?? "null";
|
|
21358
|
-
return `${messageIdOf(message) ?? ""}:${parts.length}:${Buffer.byteLength(serializedParts)}:${
|
|
21530
|
+
return `${messageIdOf(message) ?? ""}:${parts.length}:${Buffer.byteLength(serializedParts)}:${createHash14("sha256").update(serializedMessage).digest("hex")}`;
|
|
21359
21531
|
}
|
|
21360
21532
|
function advanceWireFingerprint(previous, encoded) {
|
|
21361
|
-
return
|
|
21533
|
+
return createHash14("sha256").update(previous).update("\\0").update(JSON.stringify(encoded) ?? "null").digest("hex");
|
|
21362
21534
|
}
|
|
21363
21535
|
function buildWireFingerprint(encoded) {
|
|
21364
21536
|
let fingerprint = "rust-wire-v1";
|
|
@@ -22935,7 +23107,11 @@ function createRustModeTransform(deps, options) {
|
|
|
22935
23107
|
const sessionProjectIdentity = (options.sessionProjectIdentityResolverForTests ?? resolveProjectIdentityForSession)(directory, deps.allowHomeProject);
|
|
22936
23108
|
if (sessionProjectIdentity) {
|
|
22937
23109
|
if (state.recordedSessionProjectIdentity !== sessionProjectIdentity) {
|
|
22938
|
-
|
|
23110
|
+
observeSessionProjectBinding(deps.db, sessionId, sessionProjectIdentity, directory, (notice) => {
|
|
23111
|
+
withoutSqliteTransformPass2(() => sendStatusNotification2(deps.client, sessionId, `## Project memory warning
|
|
23112
|
+
|
|
23113
|
+
${notice}`, {}));
|
|
23114
|
+
});
|
|
22939
23115
|
}
|
|
22940
23116
|
state.recordedSessionProjectIdentity = sessionProjectIdentity;
|
|
22941
23117
|
state.recordedSessionDirectory = directory;
|
|
@@ -23153,7 +23329,7 @@ function createRustModeTransform(deps, options) {
|
|
|
23153
23329
|
const id = messageIdOf(message) ?? `index:${todoStart + offset}`;
|
|
23154
23330
|
const parts = message.parts?.filter((part) => isRecord3(part) && part.type === "tool" && part.tool === "todowrite");
|
|
23155
23331
|
if (parts?.length) {
|
|
23156
|
-
todoCalls.set(id,
|
|
23332
|
+
todoCalls.set(id, createHash14("sha256").update(JSON.stringify(parts)).digest("hex"));
|
|
23157
23333
|
} else {
|
|
23158
23334
|
todoCalls.delete(id);
|
|
23159
23335
|
}
|
|
@@ -25743,7 +25919,15 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25743
25919
|
const authorityProjectPath = (deps.memoryConfig?.enabled ? projectIdentity : undefined) ?? deps.projectPath ?? sessionProjectIdentity;
|
|
25744
25920
|
if (authorityProjectPath) {}
|
|
25745
25921
|
if (sessionIdentityForBinding && sessionDirectoryResolvedFromHost && recordedSessionProjectIdentity.get(sessionId) !== sessionIdentityForBinding) {
|
|
25746
|
-
|
|
25922
|
+
observeSessionProjectBinding(db, sessionId, sessionIdentityForBinding, sessionDirectory, (notice) => {
|
|
25923
|
+
if (deps.hostProjectBindingNotice)
|
|
25924
|
+
deps.hostProjectBindingNotice(sessionId, notice);
|
|
25925
|
+
else {
|
|
25926
|
+
withoutSqliteTransformPass2(() => sendStatusNotification2(deps.client, sessionId, `## Project memory warning
|
|
25927
|
+
|
|
25928
|
+
${notice}`, notificationParams));
|
|
25929
|
+
}
|
|
25930
|
+
});
|
|
25747
25931
|
recordedSessionProjectIdentity.set(sessionId, sessionIdentityForBinding);
|
|
25748
25932
|
}
|
|
25749
25933
|
const taggerFloor = compactionOff ? 0 : deriveTaggerLoadFloor(messages, sessionId, db);
|
|
@@ -27212,12 +27396,12 @@ function systemPromptDates(prompt, sticky) {
|
|
|
27212
27396
|
}
|
|
27213
27397
|
|
|
27214
27398
|
// src/hooks/magic-context/system-prompt-diagnostics.ts
|
|
27215
|
-
import { createHash as
|
|
27399
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
27216
27400
|
function snapshotSystemPrompt(system, preset) {
|
|
27217
27401
|
return { elements: system.map((element) => Buffer.from(element)), preset };
|
|
27218
27402
|
}
|
|
27219
27403
|
function describeSystemPromptChange(previous, current) {
|
|
27220
|
-
const metadata = (element) => element === undefined ? "absent" : `bytes=${element.length},md5=${
|
|
27404
|
+
const metadata = (element) => element === undefined ? "absent" : `bytes=${element.length},md5=${createHash15("md5").update(element).digest("hex")}`;
|
|
27221
27405
|
const elements = [];
|
|
27222
27406
|
for (let index = 0;index < Math.max(previous?.elements.length ?? 0, current.elements.length); index++) {
|
|
27223
27407
|
const before = previous?.elements[index];
|
|
@@ -28405,10 +28589,11 @@ Your active memories are already in <project-memory> as \`#id: fact\` lines. Wri
|
|
|
28405
28589
|
|
|
28406
28590
|
Actions:
|
|
28407
28591
|
- write: new memory (content + category).
|
|
28408
|
-
- update: rewrite one memory whose fact changed (ids: [one], content; category
|
|
28592
|
+
- update: rewrite one memory whose fact changed (ids: [one], content; category: the current one to keep, a new one to recategorize).
|
|
28409
28593
|
- archive: retire wrong or obsolete memories (ids: [one or more], optional reason).
|
|
28410
|
-
- merge: collapse duplicates into one (ids: [two or more], content).
|
|
28594
|
+
- merge: collapse duplicates into one (ids: [two or more distinct ids of memories in the same category], content).
|
|
28411
28595
|
- get: fetch by id (ids: 1–20), readable in every status.
|
|
28596
|
+
The call form that works on every host sends action, content, category and ids every time: argument-dropping providers only emit required fields. For get and archive pass content="" and any valid category; for write pass ids=[].
|
|
28412
28597
|
Examples: category="CONFIG_VALUES", content="OpenCode source is at ~/Work/OSS/opencode" · category="CONSTRAINTS", content="Dashboard Tauri build needs RGBA PNGs, not grayscale"`;
|
|
28413
28598
|
var DEFAULT_SEARCH_LIMIT = 10;
|
|
28414
28599
|
// src/tools/ctx-memory/tools.ts
|
|
@@ -28668,13 +28853,13 @@ function updateMemoryContentInCurrentTransaction(db, memory, content, normalized
|
|
|
28668
28853
|
}
|
|
28669
28854
|
var ctxMemoryArgsShape = {
|
|
28670
28855
|
action: tool2.schema.enum([...CTX_MEMORY_ACTIONS]).describe("write | update | archive | merge | get"),
|
|
28671
|
-
content: tool2.schema.string().describe("
|
|
28672
|
-
category: tool2.schema.enum([...V2_MEMORY_CATEGORIES]).describe("
|
|
28673
|
-
ids: tool2.schema.array(tool2.schema.number()).describe("
|
|
28856
|
+
content: tool2.schema.string().describe("Send on every call — the memory text for write, update and merge; pass an empty string for archive and get."),
|
|
28857
|
+
category: tool2.schema.enum([...V2_MEMORY_CATEGORIES]).describe("Send on every call — the fact's kind for write; on update/merge, the memory's current category to keep it; archive and get ignore it, so pass any valid category."),
|
|
28858
|
+
ids: tool2.schema.array(tool2.schema.number()).describe("Send on every call — one id for update, one or more for archive, two or more distinct ids of memories in the same category for merge, 1–20 for get; write takes an empty list."),
|
|
28674
28859
|
reason: tool2.schema.string().optional().describe("Why it is being archived (optional).")
|
|
28675
28860
|
};
|
|
28676
28861
|
var ctxMemoryListArgsShape = {
|
|
28677
|
-
category: tool2.schema.enum([...V2_MEMORY_CATEGORIES]).optional().describe("
|
|
28862
|
+
category: tool2.schema.enum([...V2_MEMORY_CATEGORIES]).optional().describe("Filter listed memories to this category (optional)."),
|
|
28678
28863
|
limit: tool2.schema.number().optional().describe("Max results for list (default 10).")
|
|
28679
28864
|
};
|
|
28680
28865
|
var ctxMemoryArgsSchema = tool2.schema.object({
|
|
@@ -29865,7 +30050,7 @@ function formatCtxReduceReply(stampedCount, selfStampCount = 0) {
|
|
|
29865
30050
|
return parts.join(" ");
|
|
29866
30051
|
}
|
|
29867
30052
|
// src/tools/ctx-reduce/tools.ts
|
|
29868
|
-
import { createHash as
|
|
30053
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
29869
30054
|
import { tool as tool4 } from "@opencode-ai/plugin";
|
|
29870
30055
|
|
|
29871
30056
|
// src/features/magic-context/range-parser.ts
|
|
@@ -29929,11 +30114,11 @@ function createCtxReduceTool(deps) {
|
|
|
29929
30114
|
const stableId = `oc-${sessionId}-${callId}`;
|
|
29930
30115
|
if (Buffer.byteLength(stableId) <= 128)
|
|
29931
30116
|
return stableId;
|
|
29932
|
-
return `oc-${
|
|
30117
|
+
return `oc-${createHash16("sha256").update(stableId).digest("hex")}`;
|
|
29933
30118
|
}
|
|
29934
30119
|
fallbackCommandSequence += 1;
|
|
29935
30120
|
const monotonicId = `oc-${sessionId}-${fallbackCommandSequence}`;
|
|
29936
|
-
return Buffer.byteLength(monotonicId) <= 128 ? monotonicId : `oc-${
|
|
30121
|
+
return Buffer.byteLength(monotonicId) <= 128 ? monotonicId : `oc-${createHash16("sha256").update(monotonicId).digest("hex")}`;
|
|
29937
30122
|
};
|
|
29938
30123
|
return tool4({
|
|
29939
30124
|
description: CTX_REDUCE_DESCRIPTION,
|
|
@@ -30273,9 +30458,9 @@ var FULL_PARAMETER_DESCRIPTIONS = {
|
|
|
30273
30458
|
},
|
|
30274
30459
|
ctx_memory: {
|
|
30275
30460
|
action: "write | update | archive | merge | get",
|
|
30276
|
-
content: "
|
|
30277
|
-
category: "
|
|
30278
|
-
ids: "
|
|
30461
|
+
content: "Send on every call — the memory text for write, update and merge; pass an empty string for archive and get.",
|
|
30462
|
+
category: "Send on every call — the fact's kind for write; on update/merge, the memory's current category to keep it; archive and get ignore it, so pass any valid category.",
|
|
30463
|
+
ids: "Send on every call — one id for update, one or more for archive, two or more distinct ids of memories in the same category for merge, 1–20 for get; write takes an empty list.",
|
|
30279
30464
|
reason: "Why it is being archived (optional)."
|
|
30280
30465
|
},
|
|
30281
30466
|
ctx_search: {
|
|
@@ -30308,9 +30493,9 @@ var LIGHT_PARAMETER_DESCRIPTIONS = {
|
|
|
30308
30493
|
},
|
|
30309
30494
|
ctx_memory: {
|
|
30310
30495
|
action: "write | update | archive | merge | get",
|
|
30311
|
-
content: "
|
|
30312
|
-
category: "
|
|
30313
|
-
ids: "
|
|
30496
|
+
content: "Send on every call: the fact (write, update, merge); empty string for archive/get.",
|
|
30497
|
+
category: "Send on every call: kind for write; current category for update/merge; any category for archive/get (ignored).",
|
|
30498
|
+
ids: "Send on every call: one id for update, 1+ for archive, 2+ distinct same-category ids for merge, 1–20 for get; write: empty list.",
|
|
30314
30499
|
reason: "Why it is archived (optional)."
|
|
30315
30500
|
},
|
|
30316
30501
|
ctx_search: {
|