@cortexkit/opencode-magic-context 0.49.63 → 0.49.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-search-worker.js +1 -1
- package/dist/chunk-embedding-write-worker.js +1 -1
- package/dist/{context-aaht09yh.js → context-3mfsdp1v.js} +14 -14
- package/dist/features/magic-context/overflow-detection.d.ts +0 -20
- package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tags.d.ts +7 -0
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-prompt.d.ts +8 -1
- package/dist/hooks/magic-context/compartment-prompt.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-historian.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 +5 -0
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-prompt-fit.d.ts +10 -3
- package/dist/hooks/magic-context/historian-prompt-fit.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +11 -0
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/reference-retrieval.d.ts +3 -2
- package/dist/hooks/magic-context/reference-retrieval.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/wrapup-orchestrator.d.ts +1 -0
- package/dist/hooks/magic-context/wrapup-orchestrator.d.ts.map +1 -1
- package/dist/{index-tq20edcs.js → index-0ab398z2.js} +2 -2
- package/dist/{index-d0feqcs5.js → index-6kgsfb81.js} +1 -1
- package/dist/{index-3hk445am.js → index-71h616be.js} +1 -1
- package/dist/{index-ev2rrjfc.js → index-7dj3s7qq.js} +1 -1
- package/dist/{index-s2qsd3w9.js → index-8596jbnw.js} +6 -5
- package/dist/{index-3yyfftqq.js → index-c0k54yhd.js} +3 -3
- package/dist/{index-ywxvdwmj.js → index-ezr8mr1c.js} +1 -1
- package/dist/{index-s2jdky2x.js → index-g59gpt1j.js} +3 -3
- package/dist/{index-kv4ntrr6.js → index-gwb2wpz7.js} +2 -2
- package/dist/{index-8sc7vqt7.js → index-kvfrse61.js} +75 -43
- package/dist/{index-0cz8bsyx.js → index-qn27gh4e.js} +1 -1
- package/dist/{index-qdver0af.js → index-san8daqa.js} +6 -6
- package/dist/{index-bqd5dmm4.js → index-stqmv1mt.js} +65 -37
- package/dist/{index-3wq9btxt.js → index-wz0t5e5s.js} +3 -3
- package/dist/{index-4yjn3er4.js → index-x2hwwzk1.js} +65 -11
- package/dist/index.js +19 -18
- package/dist/{message-index-bounded-f6yz4xq8.js → message-index-bounded-zs7ah2te.js} +3 -3
- package/dist/migration-worker.js +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/raw-ordinal-warmup-worker.js +4 -4
- package/dist/{read-session-chunk-8b1g06nz.js → read-session-chunk-jf2f8jz8.js} +2 -2
- package/dist/{recomp-orchestrator-7s8nyzhy.js → recomp-orchestrator-nyj8ca0y.js} +7 -7
- package/dist/{render-nrfbtkkw.js → render-n46wpv2n.js} +6 -6
- package/dist/{search-archive-1ppdjfm9.js → search-archive-9k6vsp44.js} +4 -4
- package/dist/{search-xha0r30f.js → search-s386bwwh.js} +5 -5
- package/dist/shared/tag-transcript.d.ts.map +1 -1
- package/dist/{storage-tags-spet01yb.js → storage-tags-2r952wqy.js} +1 -1
- package/dist/{transform-postprocess-phase-fxp1atm1.js → transform-postprocess-phase-8yjcca9t.js} +8 -8
- package/dist/v2/auto-search-worker.js +1 -1
- package/dist/v2/chunk-embedding-write-worker.js +1 -1
- package/dist/v2/{context-hk9x7ngz.js → context-34sr5ner.js} +62 -34
- package/dist/v2/{message-index-bounded-0w8eh8fc.js → message-index-bounded-axbs1s97.js} +3 -3
- package/dist/v2/migration-worker.js +1 -1
- package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
- package/dist/v2/{read-session-chunk-dxs1tgt9.js → read-session-chunk-41cm522x.js} +2 -2
- package/dist/v2/{recomp-orchestrator-zc1wdv9q.js → recomp-orchestrator-r4gqhhaw.js} +6 -6
- package/dist/v2/{render-9knrdrjs.js → render-7v7yx9xb.js} +6 -6
- package/dist/v2/{search-archive-2jmyvj69.js → search-archive-1yc8bh6y.js} +4 -4
- package/dist/v2/{search-a2a0qs3t.js → search-mabwkzw2.js} +4 -4
- package/dist/v2/{server-svx20ra2.js → server-8w9b5exq.js} +1 -1
- package/dist/v2/{server-8hcxmt1w.js → server-9rwm2z2h.js} +65 -11
- package/dist/v2/{server-9m5r04ws.js → server-anh8gf0w.js} +2 -2
- package/dist/v2/{server-ja6swvmb.js → server-bh9yzxpz.js} +2 -2
- package/dist/v2/{server-9ab9jnpq.js → server-bnka2vf2.js} +3 -3
- package/dist/v2/{server-8ycacd59.js → server-cdddk5d1.js} +1 -1
- package/dist/v2/{server-88n85n60.js → server-hb5zm7yh.js} +75 -43
- package/dist/v2/{server-tzh55x6d.js → server-hcgqsdrh.js} +1 -1
- package/dist/v2/{server-4r86tcs2.js → server-k97r77x3.js} +2 -2
- package/dist/v2/{server-t8tmrtcg.js → server-yxw43z2w.js} +1 -1
- package/dist/v2/server.js +2 -2
- package/dist/v2/{storage-tags-50wsqg3t.js → storage-tags-9zs0gc7w.js} +1 -1
- package/dist/v2/{v2-archive-reader-ycjh6a2d.js → v2-archive-reader-pgk140pb.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-fyyb28jf.js → wrapup-orchestrator-p0ysz3s9.js} +7 -6
- package/dist/{v2-archive-reader-wec0a8fx.js → v2-archive-reader-cv6veqnz.js} +1 -1
- package/dist/{wrapup-orchestrator-560v99mk.js → wrapup-orchestrator-dxda1svq.js} +8 -8
- package/package.json +1 -1
- package/src/shared/tag-transcript.ts +105 -1
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
yieldIndexChunk2
|
|
5
5
|
} from "./server-gzy5w8ya.js";
|
|
6
6
|
import"./server-1zx87sdm.js";
|
|
7
|
-
import"./server-
|
|
7
|
+
import"./server-hb5zm7yh.js";
|
|
8
8
|
import"./server-y8xjr8rx.js";
|
|
9
9
|
import"./server-pavzsdc6.js";
|
|
10
10
|
import"./server-j8376q08.js";
|
|
@@ -17,7 +17,7 @@ import"./server-1d042x6w.js";
|
|
|
17
17
|
import"./server-6ash6z8z.js";
|
|
18
18
|
import"./server-2ra6pwf3.js";
|
|
19
19
|
import"./server-3ap5dmhc.js";
|
|
20
|
-
import"./server-
|
|
20
|
+
import"./server-cdddk5d1.js";
|
|
21
21
|
import {
|
|
22
22
|
MESSAGE_INDEX_MAX_FTS_BYTES,
|
|
23
23
|
messageIndexSkipKey,
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
markMessageIndexDirty,
|
|
26
26
|
getIndexableContent,
|
|
27
27
|
indexSingleMessage
|
|
28
|
-
} from "./server-
|
|
28
|
+
} from "./server-8w9b5exq.js";
|
|
29
29
|
import"./server-ds8vpfkr.js";
|
|
30
30
|
import"./server-5sbsnpkn.js";
|
|
31
31
|
|
|
@@ -19,7 +19,7 @@ serveWorkerJobs(async (input, port) => {
|
|
|
19
19
|
await main();
|
|
20
20
|
async function main() {
|
|
21
21
|
if (input.v2ArchiveReader) {
|
|
22
|
-
const { serveV2ArchiveReads } = await import("./v2-archive-reader-
|
|
22
|
+
const { serveV2ArchiveReads } = await import("./v2-archive-reader-pgk140pb.js");
|
|
23
23
|
await serveV2ArchiveReads(port, openConnections);
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
@@ -51,7 +51,7 @@ serveWorkerJobs(async (input, port) => {
|
|
|
51
51
|
await runMessageFtsRowidMapBackfill(db);
|
|
52
52
|
reply = { kind: "fts-rowid-backfill" };
|
|
53
53
|
} else if (input.searchArchive) {
|
|
54
|
-
const { renderSearchArchive } = await import("./search-archive-
|
|
54
|
+
const { renderSearchArchive } = await import("./search-archive-1yc8bh6y.js");
|
|
55
55
|
const { readRawSessionMessageIdOrdinalsForRangeFromDb } = await import("./read-session-raw-wg5zc29f.js");
|
|
56
56
|
const archive = input.searchArchive;
|
|
57
57
|
let raw;
|
|
@@ -81,7 +81,7 @@ serveWorkerJobs(async (input, port) => {
|
|
|
81
81
|
const { setHarness } = await import("./harness-e4avh192.js");
|
|
82
82
|
setHarness(input.harness ?? "opencode");
|
|
83
83
|
const [{ indexMessageInShortChunks }, { configureContextDatabasePragmas }] = await Promise.all([
|
|
84
|
-
import("./message-index-bounded-
|
|
84
|
+
import("./message-index-bounded-axbs1s97.js"),
|
|
85
85
|
import("./sqlite-context-pragmas-mv9jqwjh.js")
|
|
86
86
|
]);
|
|
87
87
|
configureContextDatabasePragmas(db);
|
|
@@ -95,7 +95,7 @@ serveWorkerJobs(async (input, port) => {
|
|
|
95
95
|
measurements: result.measurements
|
|
96
96
|
};
|
|
97
97
|
} else if (input.tagRatio !== undefined) {
|
|
98
|
-
const { scanTagOwnerSummary, scanTagOwnerDelta } = await import("./storage-tags-
|
|
98
|
+
const { scanTagOwnerSummary, scanTagOwnerDelta } = await import("./storage-tags-9zs0gc7w.js");
|
|
99
99
|
const delta = input.tagState ? scanTagOwnerDelta(db, input.sessionId, input.tagState) : null;
|
|
100
100
|
if (delta)
|
|
101
101
|
reply = { kind: "tag-delta", delta };
|
|
@@ -38,8 +38,8 @@ import {
|
|
|
38
38
|
readSessionChunk2,
|
|
39
39
|
getRawSessionMessageIdsThrough2,
|
|
40
40
|
readRawSessionSeedTail2
|
|
41
|
-
} from "./server-
|
|
42
|
-
import"./server-
|
|
41
|
+
} from "./server-cdddk5d1.js";
|
|
42
|
+
import"./server-hb5zm7yh.js";
|
|
43
43
|
import"./server-1zx87sdm.js";
|
|
44
44
|
import"./server-3ap5dmhc.js";
|
|
45
45
|
import"./server-rz6g5xne.js";
|
|
@@ -7,23 +7,23 @@ import {
|
|
|
7
7
|
setRecompTerminal2,
|
|
8
8
|
buildRecompDeps2,
|
|
9
9
|
runManagedRecomp2
|
|
10
|
-
} from "./server-
|
|
10
|
+
} from "./server-9rwm2z2h.js";
|
|
11
11
|
import"./server-at0v0z4t.js";
|
|
12
12
|
import"./server-d07yxksx.js";
|
|
13
13
|
import"./server-d9aayyxk.js";
|
|
14
14
|
import"./server-jjvbk92s.js";
|
|
15
15
|
import"./server-z5255w05.js";
|
|
16
16
|
import"./server-4dhv7mqz.js";
|
|
17
|
-
import"./server-
|
|
17
|
+
import"./server-yxw43z2w.js";
|
|
18
18
|
import"./server-rbtx6q5v.js";
|
|
19
|
-
import"./server-
|
|
19
|
+
import"./server-8w9b5exq.js";
|
|
20
20
|
import"./server-2amn2s73.js";
|
|
21
21
|
import"./server-rthnpmbp.js";
|
|
22
22
|
import"./server-aewxmvnf.js";
|
|
23
23
|
import"./server-qjff96a6.js";
|
|
24
24
|
import"./server-qt1qqasc.js";
|
|
25
|
-
import"./server-
|
|
26
|
-
import"./server-
|
|
25
|
+
import"./server-cdddk5d1.js";
|
|
26
|
+
import"./server-hb5zm7yh.js";
|
|
27
27
|
import"./server-1zx87sdm.js";
|
|
28
28
|
import"./server-3ap5dmhc.js";
|
|
29
29
|
import"./server-npdey91q.js";
|
|
@@ -35,7 +35,7 @@ import"./server-rz6g5xne.js";
|
|
|
35
35
|
import"./server-jtq03rkb.js";
|
|
36
36
|
import"./server-8pdfmc27.js";
|
|
37
37
|
import"./server-x6fn9x8q.js";
|
|
38
|
-
import"./server-
|
|
38
|
+
import"./server-hcgqsdrh.js";
|
|
39
39
|
import"./server-fb3zxn06.js";
|
|
40
40
|
import"./server-jn4pktdk.js";
|
|
41
41
|
import"./server-fr0wbhdn.js";
|
|
@@ -2,20 +2,20 @@ import {
|
|
|
2
2
|
renderMessageByOrdinal2,
|
|
3
3
|
renderVerboseRangeForTool2,
|
|
4
4
|
renderItemByTag2
|
|
5
|
-
} from "./server-
|
|
6
|
-
import"./server-
|
|
5
|
+
} from "./server-k97r77x3.js";
|
|
6
|
+
import"./server-yxw43z2w.js";
|
|
7
7
|
import"./server-rbtx6q5v.js";
|
|
8
|
-
import"./server-
|
|
8
|
+
import"./server-8w9b5exq.js";
|
|
9
9
|
import"./server-2amn2s73.js";
|
|
10
10
|
import"./server-rthnpmbp.js";
|
|
11
|
-
import"./server-
|
|
12
|
-
import"./server-
|
|
11
|
+
import"./server-cdddk5d1.js";
|
|
12
|
+
import"./server-hb5zm7yh.js";
|
|
13
13
|
import"./server-1zx87sdm.js";
|
|
14
14
|
import"./server-3ap5dmhc.js";
|
|
15
15
|
import"./server-rz6g5xne.js";
|
|
16
16
|
import"./server-8pdfmc27.js";
|
|
17
17
|
import"./server-x6fn9x8q.js";
|
|
18
|
-
import"./server-
|
|
18
|
+
import"./server-hcgqsdrh.js";
|
|
19
19
|
import"./server-fb3zxn06.js";
|
|
20
20
|
import"./server-jn4pktdk.js";
|
|
21
21
|
import"./server-fr0wbhdn.js";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
renderSearchArchive2,
|
|
3
3
|
renderSearchArchiveOffThread2
|
|
4
|
-
} from "./server-
|
|
5
|
-
import"./server-
|
|
4
|
+
} from "./server-anh8gf0w.js";
|
|
5
|
+
import"./server-bnka2vf2.js";
|
|
6
6
|
import"./server-52x68mj4.js";
|
|
7
|
-
import"./server-
|
|
8
|
-
import"./server-
|
|
7
|
+
import"./server-cdddk5d1.js";
|
|
8
|
+
import"./server-hb5zm7yh.js";
|
|
9
9
|
import"./server-1zx87sdm.js";
|
|
10
10
|
import"./server-3ap5dmhc.js";
|
|
11
11
|
import"./server-rz6g5xne.js";
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
resolveMemoriesByIdsForSearch2,
|
|
6
6
|
unifiedSearch2,
|
|
7
7
|
formatSearchResults2
|
|
8
|
-
} from "./server-
|
|
8
|
+
} from "./server-bh9yzxpz.js";
|
|
9
9
|
import"./server-52x68mj4.js";
|
|
10
10
|
import"./server-d07yxksx.js";
|
|
11
11
|
import"./server-d9aayyxk.js";
|
|
@@ -13,11 +13,11 @@ import"./server-jjvbk92s.js";
|
|
|
13
13
|
import"./server-z5255w05.js";
|
|
14
14
|
import"./server-4dhv7mqz.js";
|
|
15
15
|
import"./server-rbtx6q5v.js";
|
|
16
|
-
import"./server-
|
|
16
|
+
import"./server-8w9b5exq.js";
|
|
17
17
|
import"./server-2amn2s73.js";
|
|
18
18
|
import"./server-qt1qqasc.js";
|
|
19
|
-
import"./server-
|
|
20
|
-
import"./server-
|
|
19
|
+
import"./server-cdddk5d1.js";
|
|
20
|
+
import"./server-hb5zm7yh.js";
|
|
21
21
|
import"./server-1zx87sdm.js";
|
|
22
22
|
import"./server-3ap5dmhc.js";
|
|
23
23
|
import"./server-d706s5xn.js";
|
|
@@ -100,7 +100,7 @@ import {
|
|
|
100
100
|
foldShrunkPartTags2,
|
|
101
101
|
getTagNumberByMessageId2,
|
|
102
102
|
getActiveTagsBySession2
|
|
103
|
-
} from "./server-
|
|
103
|
+
} from "./server-hb5zm7yh.js";
|
|
104
104
|
import {
|
|
105
105
|
hasMeaningfulUserText2,
|
|
106
106
|
estimateTokens,
|
|
@@ -155,14 +155,14 @@ import {
|
|
|
155
155
|
getRawSessionTagKeysThrough2,
|
|
156
156
|
getLegacyProtectedTailStartOrdinal2,
|
|
157
157
|
readSessionChunk2
|
|
158
|
-
} from "./server-
|
|
158
|
+
} from "./server-cdddk5d1.js";
|
|
159
159
|
import {
|
|
160
160
|
clearCompressionDepth,
|
|
161
161
|
clearCompressionDepthRange,
|
|
162
162
|
toMessageIndexSource,
|
|
163
163
|
clearIndexedMessagesInTransaction,
|
|
164
164
|
indexSourcesAfterOrdinal
|
|
165
|
-
} from "./server-
|
|
165
|
+
} from "./server-8w9b5exq.js";
|
|
166
166
|
import {
|
|
167
167
|
COMPARTMENT_LEASE_RENEWAL_MS,
|
|
168
168
|
getCompartmentLeaseBlocker,
|
|
@@ -207,7 +207,7 @@ import {
|
|
|
207
207
|
getProjectState,
|
|
208
208
|
recordSubagentInvocation,
|
|
209
209
|
getLatestHistorianInvocationId
|
|
210
|
-
} from "./server-
|
|
210
|
+
} from "./server-yxw43z2w.js";
|
|
211
211
|
import {
|
|
212
212
|
invalidateAutoEmbedSession
|
|
213
213
|
} from "./server-2amn2s73.js";
|
|
@@ -267,7 +267,7 @@ import {
|
|
|
267
267
|
LATEST_SUPPORTED_VERSION,
|
|
268
268
|
getPersistedSchemaVersion,
|
|
269
269
|
openDatabase
|
|
270
|
-
} from "./server-
|
|
270
|
+
} from "./server-hcgqsdrh.js";
|
|
271
271
|
import {
|
|
272
272
|
parseCompartmentOutput,
|
|
273
273
|
resolveWorkspaceShareCategories,
|
|
@@ -6016,11 +6016,11 @@ var USER_OBSERVATIONS_DISABLED_TOGGLE = `<user_observation_extraction>disabled</
|
|
|
6016
6016
|
User-memory review is not running (the dreamer is disabled): do NOT emit a <user_observations> block.`;
|
|
6017
6017
|
function buildCompartmentAgentPrompt(inputs) {
|
|
6018
6018
|
const parts = [];
|
|
6019
|
+
parts.push(...readEnabledProjectMemories(inputs.memoryEnabled, () => inputs.projectMemory ? [inputs.projectMemory] : []));
|
|
6019
6020
|
if (inputs.seedExamples)
|
|
6020
6021
|
parts.push(inputs.seedExamples);
|
|
6021
6022
|
if (inputs.sessionReferences)
|
|
6022
6023
|
parts.push(inputs.sessionReferences);
|
|
6023
|
-
parts.push(...readEnabledProjectMemories(inputs.memoryEnabled, () => inputs.projectMemory ? [inputs.projectMemory] : []));
|
|
6024
6024
|
if (inputs.extractionFree) {
|
|
6025
6025
|
parts.push(`<extraction>disabled</extraction>
|
|
6026
6026
|
Structural recomp mode: emit compartments and <meta> only. Do NOT emit <facts>, <events>, <user_observations>, or <primer_candidates>.`);
|
|
@@ -6040,6 +6040,34 @@ Memory is disabled for this project: do NOT emit a <facts> block. Produce compar
|
|
|
6040
6040
|
|
|
6041
6041
|
`);
|
|
6042
6042
|
}
|
|
6043
|
+
function logHistorianPromptSizes(sessionId, system, prompt) {
|
|
6044
|
+
const sourceStart = prompt.indexOf(`<new_messages>
|
|
6045
|
+
|
|
6046
|
+
`);
|
|
6047
|
+
const sourceEnd = prompt.lastIndexOf(`
|
|
6048
|
+
|
|
6049
|
+
</new_messages>
|
|
6050
|
+
|
|
6051
|
+
${HISTORIAN_TRANSCRIPT_GUARD}`);
|
|
6052
|
+
const hasSource = sourceStart !== -1 && sourceEnd > sourceStart;
|
|
6053
|
+
const blockBytes = (tag) => {
|
|
6054
|
+
if (!hasSource)
|
|
6055
|
+
return 0;
|
|
6056
|
+
const start = prompt.indexOf(`<${tag}>`);
|
|
6057
|
+
const close = `</${tag}>`;
|
|
6058
|
+
const end = prompt.indexOf(close, start + 1);
|
|
6059
|
+
return start >= 0 && end > start && end < sourceStart ? Buffer.byteLength(prompt.slice(start, end + close.length)) : 0;
|
|
6060
|
+
};
|
|
6061
|
+
const memoryBytes = blockBytes("project-memory");
|
|
6062
|
+
const seedBytes = blockBytes("compartment_examples_from_other_projects");
|
|
6063
|
+
const referenceBytes = blockBytes("session_references");
|
|
6064
|
+
const newMessageBytes = hasSource ? Buffer.byteLength(prompt.slice(sourceStart, sourceEnd + `
|
|
6065
|
+
|
|
6066
|
+
</new_messages>`.length)) : 0;
|
|
6067
|
+
const systemBytes = Buffer.byteLength(system);
|
|
6068
|
+
const userBytes = Buffer.byteLength(prompt);
|
|
6069
|
+
sessionLog2(sessionId, `historian request sizes: systemBytes=${systemBytes} userBytes=${userBytes} memoryBytes=${memoryBytes} seedBytes=${seedBytes} referenceBytes=${referenceBytes} newMessageBytes=${newMessageBytes}`);
|
|
6070
|
+
}
|
|
6043
6071
|
|
|
6044
6072
|
// src/hooks/magic-context/compartment-runner-drop-queue.ts
|
|
6045
6073
|
function prepareCompartmentDrops(db, sessionId, upToMessageIndex, observedKeys, fromMessageIndex = 1) {
|
|
@@ -8522,6 +8550,9 @@ function sourceNamesForMemories(args) {
|
|
|
8522
8550
|
}
|
|
8523
8551
|
return names.size > 0 ? names : undefined;
|
|
8524
8552
|
}
|
|
8553
|
+
function readM0ProjectMemories(db, projectPath, workspace, at = Date.now()) {
|
|
8554
|
+
return workspace.isWorkspaced ? getMemoriesByProjects2(db, workspace.expandedIdentities, ["active", "permanent"], at, workspace.ownIdentities, workspace.shareCategories) : getMemoriesByProject2(db, projectPath, ["active", "permanent"], at);
|
|
8555
|
+
}
|
|
8525
8556
|
function memoryCanonicalIdentity(memory, workspace) {
|
|
8526
8557
|
return resolveStoredPathWorkspaceIdentity(memory.projectPath, workspace.identities, workspace.canonicalIdentityByStoredPath);
|
|
8527
8558
|
}
|
|
@@ -9298,7 +9329,7 @@ function materializeM0(options) {
|
|
|
9298
9329
|
snapshotMarkers.projectDocsHash = docs.canonicalHash;
|
|
9299
9330
|
compartments = options.compactionOff ? [] : readM0Compartments(options.db, options.sessionId);
|
|
9300
9331
|
facts = [];
|
|
9301
|
-
memories = projectPath ?
|
|
9332
|
+
memories = projectPath ? readM0ProjectMemories(options.db, projectPath, workspace, foldMaterializedAt) : [];
|
|
9302
9333
|
userMemories = options.memoryEnabled === false ? [] : safeGetActiveUserMemories(options.db);
|
|
9303
9334
|
options.db.exec("COMMIT");
|
|
9304
9335
|
} catch (error) {
|
|
@@ -12253,9 +12284,9 @@ function fnv1a(input) {
|
|
|
12253
12284
|
}
|
|
12254
12285
|
return h >>> 0;
|
|
12255
12286
|
}
|
|
12256
|
-
function selectSeeds(sessionId,
|
|
12287
|
+
function selectSeeds(sessionId, _chunkStart, count = SEED_FLOOR) {
|
|
12257
12288
|
const bands = seedsByBand();
|
|
12258
|
-
const seed = fnv1a(
|
|
12289
|
+
const seed = fnv1a(sessionId);
|
|
12259
12290
|
const picks = [];
|
|
12260
12291
|
const bandOrder = [];
|
|
12261
12292
|
for (let i = 0;i < SEED_BANDS.length; i++) {
|
|
@@ -12402,7 +12433,22 @@ function fitHistorianPrompt(args) {
|
|
|
12402
12433
|
const requested = Math.max(0, Math.floor(args.requestedChunkTokens));
|
|
12403
12434
|
const seeds = selectSeeds(args.sessionId, args.chunkStart);
|
|
12404
12435
|
const references = selectSessionReferences(args.sessionCompartments, seeds, args.sessionId, args.chunkStart);
|
|
12405
|
-
const memories =
|
|
12436
|
+
const memories = readEnabledProjectMemories(args.memoryEnabled, () => {
|
|
12437
|
+
const project = args.memoryProject;
|
|
12438
|
+
const projectPath = project?.projectPath;
|
|
12439
|
+
const workspace = project && resolveWorkspaceRenderContext(project);
|
|
12440
|
+
const rows = project ? projectPath && workspace ? readM0ProjectMemories(project.db, projectPath, workspace) : [] : (typeof args.memories === "function" ? args.memories() : args.memories) ?? [];
|
|
12441
|
+
const budget = args.memoryInjectionBudgetTokens ?? DEFAULT_MEMORY_BUDGET_TOKENS;
|
|
12442
|
+
const { selected } = workspace?.isWorkspaced ? trimWorkspaceMemoriesToBudgetV2(args.sessionId, rows, budget, workspace, {
|
|
12443
|
+
sourceNameByMemoryId: sourceNamesForMemories({
|
|
12444
|
+
memories: rows,
|
|
12445
|
+
projectPath,
|
|
12446
|
+
workspace
|
|
12447
|
+
})
|
|
12448
|
+
}) : trimMemoriesToBudgetV2(args.sessionId, rows, budget);
|
|
12449
|
+
const selectedIds = new Set(selected.map((memory) => memory.id));
|
|
12450
|
+
return orderHistorianMemories(rows.filter((memory) => selectedIds.has(memory.id)));
|
|
12451
|
+
});
|
|
12406
12452
|
const render = (refs, memoryCount, seedCount) => ({
|
|
12407
12453
|
seedExamples: renderSeedExamplesBlock(seeds.slice(0, seedCount)),
|
|
12408
12454
|
sessionReferences: renderSessionReferencesBlock(references, refs),
|
|
@@ -12964,6 +13010,7 @@ async function runHistorianPrompt(args) {
|
|
|
12964
13010
|
});
|
|
12965
13011
|
if (failure)
|
|
12966
13012
|
throw new Error(failure);
|
|
13013
|
+
logHistorianPromptSizes(parentSessionId, system, prompt);
|
|
12967
13014
|
return executor.attempt(opened, request);
|
|
12968
13015
|
}, { childSessionId: opened.childSessionId }),
|
|
12969
13016
|
timeoutMs: timeoutMs ?? DEFAULT_HISTORIAN_TIMEOUT_MS,
|
|
@@ -14983,7 +15030,11 @@ async function runCompartmentAgent(deps) {
|
|
|
14983
15030
|
chunkStart: Math.max(1, offset),
|
|
14984
15031
|
lastOrdinal: eligibleEndOrdinal - 1,
|
|
14985
15032
|
sessionCompartments: priorCompartments,
|
|
14986
|
-
|
|
15033
|
+
memoryProject: {
|
|
15034
|
+
db,
|
|
15035
|
+
projectPath: deps.memoryProjectPath === undefined ? projectPath : deps.memoryProjectPath ?? undefined
|
|
15036
|
+
},
|
|
15037
|
+
memoryInjectionBudgetTokens: deps.memoryInjectionBudgetTokens,
|
|
14987
15038
|
memoryEnabled: deps.memoryEnabled !== false,
|
|
14988
15039
|
userObservationsRequested: deps.userObservationsRequested
|
|
14989
15040
|
});
|
|
@@ -15104,6 +15155,9 @@ async function runCompartmentAgent(deps) {
|
|
|
15104
15155
|
}
|
|
15105
15156
|
historianRunStarted = true;
|
|
15106
15157
|
deps.onHistorianRunStarted?.();
|
|
15158
|
+
if (deps.recoveryTriggerReason) {
|
|
15159
|
+
sessionLog2(sessionId, `historian recovery fire: admittedBy=${deps.recoveryTriggerReason} trueRawTokens=${boundarySnapshot.trueRawEligibleTokens} formattedChunkTokens=${chunk.tokenEstimate}`);
|
|
15160
|
+
}
|
|
15107
15161
|
const prompt = buildCompartmentAgentPrompt({
|
|
15108
15162
|
seedExamples: promptFit.seedExamples,
|
|
15109
15163
|
sessionReferences: promptFit.sessionReferences,
|
|
@@ -19,10 +19,10 @@ import {
|
|
|
19
19
|
rawMessageWorkerSource2,
|
|
20
20
|
rawMessageOffThreadRangeReader2,
|
|
21
21
|
readRawSessionMessageIdOrdinalsForRange2
|
|
22
|
-
} from "./server-
|
|
22
|
+
} from "./server-cdddk5d1.js";
|
|
23
23
|
import {
|
|
24
24
|
readV2ArchiveOffThread2
|
|
25
|
-
} from "./server-
|
|
25
|
+
} from "./server-bnka2vf2.js";
|
|
26
26
|
|
|
27
27
|
// src/tools/ctx-expand/search-archive.ts
|
|
28
28
|
var archiveReadsOnThisThread = 0;
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
} from "./server-afsz3cmx.js";
|
|
16
16
|
import {
|
|
17
17
|
isRecord
|
|
18
|
-
} from "./server-
|
|
18
|
+
} from "./server-hb5zm7yh.js";
|
|
19
19
|
import {
|
|
20
20
|
cleanSearchText,
|
|
21
21
|
hintKeywordRelevance,
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
isMessageIndexReconciledThrough,
|
|
26
26
|
clearIndexedMessages,
|
|
27
27
|
indexMessagesAfterOrdinal
|
|
28
|
-
} from "./server-
|
|
28
|
+
} from "./server-8w9b5exq.js";
|
|
29
29
|
import {
|
|
30
30
|
Priority,
|
|
31
31
|
AdmissionClass,
|
|
@@ -139,9 +139,9 @@ async function serveV2ArchiveReads2(port, openConnections) {
|
|
|
139
139
|
import("./sqlite-zdgm52sv.js"),
|
|
140
140
|
import("./store-reader-yaxtdy6f.js"),
|
|
141
141
|
import("./store-skkhh3rd.js"),
|
|
142
|
-
import("./read-session-chunk-
|
|
143
|
-
import("./render-
|
|
144
|
-
import("./search-archive-
|
|
142
|
+
import("./read-session-chunk-41cm522x.js"),
|
|
143
|
+
import("./render-7v7yx9xb.js"),
|
|
144
|
+
import("./search-archive-1yc8bh6y.js"),
|
|
145
145
|
import("./expand-attachments-h33jbgyz.js")
|
|
146
146
|
]);
|
|
147
147
|
const pool = new V2StoreReaderPool;
|
|
@@ -4981,6 +4981,11 @@ function markDropLeavesReasoning(db, sessionId) {
|
|
|
4981
4981
|
}
|
|
4982
4982
|
|
|
4983
4983
|
// src/features/magic-context/overflow-detection.ts
|
|
4984
|
+
var TOKEN_COUNT = String.raw`(?<![\d+_-])(?:\d+(?:[,_ .\u202f]+\d+)*(?=\s*tokens?\b)|\d+(?:[,_ \u202f]+\d+)*)(?!\w|[,_\s.]+\d)`;
|
|
4985
|
+
var ESTIMATED_REQUEST = String.raw`\bthis request has an estimated\b`;
|
|
4986
|
+
function overflowPattern(strings, ...fragments) {
|
|
4987
|
+
return new RegExp(String.raw(strings, ...fragments), "i");
|
|
4988
|
+
}
|
|
4984
4989
|
var OVERFLOW_PATTERNS = [
|
|
4985
4990
|
/prompt is too long/i,
|
|
4986
4991
|
/input is too long for requested model/i,
|
|
@@ -4988,7 +4993,7 @@ var OVERFLOW_PATTERNS = [
|
|
|
4988
4993
|
/input token count.*exceeds the maximum/i,
|
|
4989
4994
|
/maximum prompt length is \d+/i,
|
|
4990
4995
|
/reduce the length of the messages/i,
|
|
4991
|
-
|
|
4996
|
+
overflowPattern`maximum context length is ${TOKEN_COUNT} tokens?\b`,
|
|
4992
4997
|
/maximum model length is \d+/i,
|
|
4993
4998
|
/exceeds the limit of \d+/i,
|
|
4994
4999
|
/exceeds the available context size/i,
|
|
@@ -4997,48 +5002,84 @@ var OVERFLOW_PATTERNS = [
|
|
|
4997
5002
|
/exceeded model token limit/i,
|
|
4998
5003
|
/context[_ ]length[_ ]exceeded/i,
|
|
4999
5004
|
/request entity too large/i,
|
|
5000
|
-
|
|
5005
|
+
overflowPattern`context length is only ${TOKEN_COUNT} tokens?\b`,
|
|
5001
5006
|
/input length.*exceeds.*context length/i,
|
|
5002
5007
|
/\bContextWindowExceededError\b/i,
|
|
5003
|
-
|
|
5008
|
+
overflowPattern`\bthe input \(${TOKEN_COUNT} tokens?\) is longer than the model's context length \(${TOKEN_COUNT} tokens?\)`,
|
|
5004
5009
|
/prompt too long; exceeded (?:max )?context length/i,
|
|
5005
|
-
|
|
5010
|
+
overflowPattern`too large for model with ${TOKEN_COUNT} maximum context length`,
|
|
5006
5011
|
/model_context_window_exceeded/i,
|
|
5007
5012
|
/context size has been exceeded/i,
|
|
5008
5013
|
/prepared prompt exceeds engine max_context/i,
|
|
5009
5014
|
/prompt exceeds (?:the )?.{0,32}\bmax_context\b/i
|
|
5010
5015
|
];
|
|
5011
5016
|
var LIMIT_EXTRACTION_PATTERNS = [
|
|
5012
|
-
{ pattern: /maximum prompt length is (\d+)/i, provenance: "prompt_only" },
|
|
5013
5017
|
{
|
|
5014
|
-
pattern:
|
|
5018
|
+
pattern: overflowPattern`maximum prompt length is (${TOKEN_COUNT})`,
|
|
5019
|
+
provenance: "prompt_only"
|
|
5020
|
+
},
|
|
5021
|
+
{
|
|
5022
|
+
pattern: overflowPattern`maximum context length is (${TOKEN_COUNT}) tokens?\b`,
|
|
5015
5023
|
provenance: "combined"
|
|
5016
5024
|
},
|
|
5017
|
-
{ pattern:
|
|
5018
|
-
{ pattern: /context length is only (\d+) tokens?/i, provenance: "combined" },
|
|
5019
|
-
{ pattern: /exceeds the limit of (\d+)/i, provenance: "unknown" },
|
|
5025
|
+
{ pattern: overflowPattern`maximum model length is (${TOKEN_COUNT})`, provenance: "combined" },
|
|
5020
5026
|
{
|
|
5021
|
-
pattern:
|
|
5027
|
+
pattern: overflowPattern`context length is only (${TOKEN_COUNT}) tokens?\b`,
|
|
5022
5028
|
provenance: "combined"
|
|
5023
5029
|
},
|
|
5024
|
-
{ pattern:
|
|
5025
|
-
{ pattern: /exceeds? the context length of (\d+)/i, provenance: "combined" },
|
|
5030
|
+
{ pattern: overflowPattern`exceeds the limit of (${TOKEN_COUNT})`, provenance: "unknown" },
|
|
5026
5031
|
{
|
|
5027
|
-
pattern:
|
|
5032
|
+
pattern: overflowPattern`too large for model with (${TOKEN_COUNT}) maximum context length`,
|
|
5028
5033
|
provenance: "combined"
|
|
5029
5034
|
},
|
|
5030
5035
|
{
|
|
5031
|
-
pattern:
|
|
5036
|
+
pattern: overflowPattern`context size[^0-9]{0,40}(${TOKEN_COUNT})\s*tokens?\b`,
|
|
5037
|
+
provenance: "combined"
|
|
5038
|
+
},
|
|
5039
|
+
{
|
|
5040
|
+
pattern: overflowPattern`exceeds? the context length of (${TOKEN_COUNT})`,
|
|
5041
|
+
provenance: "combined"
|
|
5042
|
+
},
|
|
5043
|
+
{
|
|
5044
|
+
pattern: overflowPattern`\bthe input \(${TOKEN_COUNT} tokens?\) is longer than the model's context length \((${TOKEN_COUNT}) tokens?\)`,
|
|
5045
|
+
provenance: "combined"
|
|
5046
|
+
},
|
|
5047
|
+
{
|
|
5048
|
+
pattern: overflowPattern`>\s*(${TOKEN_COUNT})\s*(?:tokens?\s*)?(?:maximum|max|limit)\b`,
|
|
5032
5049
|
provenance: "prompt_only"
|
|
5033
5050
|
},
|
|
5034
5051
|
{
|
|
5035
|
-
pattern:
|
|
5052
|
+
pattern: overflowPattern`maximum number of tokens allowed\s*\(?\s*(${TOKEN_COUNT})`,
|
|
5036
5053
|
provenance: "prompt_only"
|
|
5037
5054
|
},
|
|
5038
|
-
{
|
|
5039
|
-
|
|
5040
|
-
|
|
5055
|
+
{
|
|
5056
|
+
pattern: overflowPattern`prepared prompt exceeds engine max_context\s+(${TOKEN_COUNT})`,
|
|
5057
|
+
provenance: "unknown"
|
|
5058
|
+
},
|
|
5059
|
+
{
|
|
5060
|
+
pattern: overflowPattern`prompt exceeds (?:the )?.{0,32}\bmax_context\s+(${TOKEN_COUNT})`,
|
|
5061
|
+
provenance: "unknown"
|
|
5062
|
+
},
|
|
5063
|
+
{
|
|
5064
|
+
pattern: overflowPattern`\ballows a context of up to (${TOKEN_COUNT}) tokens?\b`,
|
|
5065
|
+
provenance: "combined"
|
|
5066
|
+
},
|
|
5067
|
+
{
|
|
5068
|
+
pattern: overflowPattern`(?<!${ESTIMATED_REQUEST}\s+)\bup to (${TOKEN_COUNT}) tokens?\b`,
|
|
5069
|
+
provenance: "unknown"
|
|
5070
|
+
},
|
|
5071
|
+
{
|
|
5072
|
+
pattern: overflowPattern`max(?:imum)?.*context(?:(?!${ESTIMATED_REQUEST})[^\d\r\n])*(${TOKEN_COUNT})`,
|
|
5073
|
+
provenance: "unknown"
|
|
5074
|
+
}
|
|
5041
5075
|
];
|
|
5076
|
+
function parseTokenCount(raw) {
|
|
5077
|
+
if (raw === undefined || !/^(?:\d+|\d{1,3}([,_ .\u202f])\d{3}(?:\1\d{3})*)$/.test(raw)) {
|
|
5078
|
+
return null;
|
|
5079
|
+
}
|
|
5080
|
+
const value = Number(raw.replace(/[,_ .\u202f]/g, ""));
|
|
5081
|
+
return Number.isSafeInteger(value) ? value : null;
|
|
5082
|
+
}
|
|
5042
5083
|
var MIN_PLAUSIBLE_LIMIT = 1024;
|
|
5043
5084
|
var MAX_PLAUSIBLE_LIMIT = 1e7;
|
|
5044
5085
|
var THINKING_BINDING_MISMATCH_PATTERN = /bound to a different conversation/i;
|
|
@@ -5160,24 +5201,22 @@ function detectOverflow(error) {
|
|
|
5160
5201
|
matchedPattern: matched?.source
|
|
5161
5202
|
};
|
|
5162
5203
|
}
|
|
5204
|
+
var INPUT_EXTRACTION_PATTERNS = [
|
|
5205
|
+
overflowPattern`prompt is too long:\s*(${TOKEN_COUNT})`,
|
|
5206
|
+
overflowPattern`input token count\s*\(?\s*(${TOKEN_COUNT})`,
|
|
5207
|
+
overflowPattern`input length\s*(${TOKEN_COUNT})`,
|
|
5208
|
+
overflowPattern`prompt was\s*(${TOKEN_COUNT})`,
|
|
5209
|
+
overflowPattern`messages resulted in\s*(${TOKEN_COUNT})\s*tokens?\b`,
|
|
5210
|
+
overflowPattern`\bthe input \((${TOKEN_COUNT}) tokens?\) is longer than the model's context length \(${TOKEN_COUNT} tokens?\)`,
|
|
5211
|
+
overflowPattern`\(\s*(${TOKEN_COUNT})\s+in the messages,\s*${TOKEN_COUNT}\s+in the completion\s*\)`,
|
|
5212
|
+
overflowPattern`${ESTIMATED_REQUEST}\s+(${TOKEN_COUNT})`
|
|
5213
|
+
];
|
|
5163
5214
|
function parseReportedInputTokens(message) {
|
|
5164
5215
|
if (!message)
|
|
5165
5216
|
return;
|
|
5166
|
-
const
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
/input length\s*(\d+)/i,
|
|
5170
|
-
/prompt was\s*(\d+)/i,
|
|
5171
|
-
/messages resulted in\s*(\d+)\s*tokens?/i,
|
|
5172
|
-
/\bthe input \((\d+) tokens?\) is longer than the model's context length \(\d+ tokens?\)/i,
|
|
5173
|
-
/\(\s*(\d+)\s+in the messages,\s*\d+\s+in the completion\s*\)/i
|
|
5174
|
-
];
|
|
5175
|
-
for (const pattern of patterns) {
|
|
5176
|
-
const raw = message.match(pattern)?.[1];
|
|
5177
|
-
if (!raw)
|
|
5178
|
-
continue;
|
|
5179
|
-
const value = Number.parseInt(raw, 10);
|
|
5180
|
-
if (Number.isFinite(value) && value > 0)
|
|
5217
|
+
for (const pattern of INPUT_EXTRACTION_PATTERNS) {
|
|
5218
|
+
const value = parseTokenCount(message.match(pattern)?.[1]);
|
|
5219
|
+
if (value !== null && value > 0)
|
|
5181
5220
|
return value;
|
|
5182
5221
|
}
|
|
5183
5222
|
return;
|
|
@@ -5186,16 +5225,8 @@ function parseReportedLimit(message) {
|
|
|
5186
5225
|
if (!message)
|
|
5187
5226
|
return;
|
|
5188
5227
|
for (const { pattern, provenance } of LIMIT_EXTRACTION_PATTERNS) {
|
|
5189
|
-
const
|
|
5190
|
-
if (
|
|
5191
|
-
continue;
|
|
5192
|
-
const raw = match[1];
|
|
5193
|
-
if (!raw)
|
|
5194
|
-
continue;
|
|
5195
|
-
const value = Number.parseInt(raw, 10);
|
|
5196
|
-
if (!Number.isFinite(value))
|
|
5197
|
-
continue;
|
|
5198
|
-
if (value < MIN_PLAUSIBLE_LIMIT || value > MAX_PLAUSIBLE_LIMIT)
|
|
5228
|
+
const value = parseTokenCount(message.match(pattern)?.[1]);
|
|
5229
|
+
if (value === null || value < MIN_PLAUSIBLE_LIMIT || value > MAX_PLAUSIBLE_LIMIT)
|
|
5199
5230
|
continue;
|
|
5200
5231
|
return { value, provenance };
|
|
5201
5232
|
}
|
|
@@ -7380,6 +7411,7 @@ function getActiveTagTokenTotalsByMessage2(db, sessionId, messageIds) {
|
|
|
7380
7411
|
return out;
|
|
7381
7412
|
}
|
|
7382
7413
|
var updateTagTokenCountStatements = new WeakMap;
|
|
7414
|
+
var setTagTokenCountStatements = new WeakMap;
|
|
7383
7415
|
var updateTagInputTokenCountStatements = new WeakMap;
|
|
7384
7416
|
function getUpdateTagTokenCountStatement(db) {
|
|
7385
7417
|
let stmt = updateTagTokenCountStatements.get(db);
|
|
@@ -1021,7 +1021,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
|
|
|
1021
1021
|
state.running = startMessageFtsRowidMapBackfill2(db, signal).then(async () => {
|
|
1022
1022
|
if (signal.aborted || !readsOpenCodeStore)
|
|
1023
1023
|
return;
|
|
1024
|
-
const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-
|
|
1024
|
+
const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-41cm522x.js"));
|
|
1025
1025
|
const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-ynb3vg6r.js"));
|
|
1026
1026
|
if (signal.aborted)
|
|
1027
1027
|
return;
|
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
} from "./server-y8xjr8rx.js";
|
|
4
4
|
import {
|
|
5
5
|
getTagById2
|
|
6
|
-
} from "./server-
|
|
6
|
+
} from "./server-hb5zm7yh.js";
|
|
7
7
|
import {
|
|
8
8
|
expandToolPart,
|
|
9
9
|
visitRawSessionMessages2,
|
|
10
10
|
readRawSessionMessageById2
|
|
11
|
-
} from "./server-
|
|
11
|
+
} from "./server-cdddk5d1.js";
|
|
12
12
|
|
|
13
13
|
// src/tools/ctx-expand/render.ts
|
|
14
14
|
import { createHash } from "node:crypto";
|