@cortexkit/opencode-magic-context 0.49.63 → 0.49.64
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-v1apxpct.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/{index-tq20edcs.js → index-0ab398z2.js} +2 -2
- package/dist/{index-qdver0af.js → index-5fbeycst.js} +6 -6
- 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-bqd5dmm4.js → index-aq4yfcq6.js} +15 -15
- 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-s2qsd3w9.js → index-hs9xxmmy.js} +5 -5
- package/dist/{index-8sc7vqt7.js → index-kvfrse61.js} +75 -43
- package/dist/{index-3wq9btxt.js → index-m568xww6.js} +3 -3
- package/dist/{index-0cz8bsyx.js → index-qn27gh4e.js} +1 -1
- package/dist/{index-4yjn3er4.js → index-zdd01nhc.js} +5 -5
- package/dist/index.js +18 -18
- package/dist/{message-index-bounded-f6yz4xq8.js → message-index-bounded-zs7ah2te.js} +3 -3
- package/dist/migration-worker.js +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-6vxnrh2w.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-jjc9jcer.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-nfkhb5sv.js} +12 -12
- 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-krccyz0a.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-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-8hcxmt1w.js → server-xse5jngy.js} +5 -5
- 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-v2rgtczc.js} +6 -6
- package/dist/{v2-archive-reader-wec0a8fx.js → v2-archive-reader-cv6veqnz.js} +1 -1
- package/dist/{wrapup-orchestrator-560v99mk.js → wrapup-orchestrator-qbtg1dhm.js} +8 -8
- package/package.json +1 -1
- package/src/shared/tag-transcript.ts +105 -1
package/dist/v2/server.js
CHANGED
|
@@ -7875,7 +7875,7 @@ var require_src2 = __commonJS(function(exports, module) {
|
|
|
7875
7875
|
// package.json
|
|
7876
7876
|
var package_default = {
|
|
7877
7877
|
name: "@cortexkit/opencode-magic-context",
|
|
7878
|
-
version: "0.49.
|
|
7878
|
+
version: "0.49.64",
|
|
7879
7879
|
type: "module",
|
|
7880
7880
|
description: "OpenCode plugin for Magic Context — cross-session memory and context management",
|
|
7881
7881
|
main: "dist/index.js",
|
|
@@ -8196,7 +8196,7 @@ async function setup(context) {
|
|
|
8196
8196
|
if (claimStorageBackupWarningCheck() && isMagicContextStorageOutsideEngram(storageDir)) {
|
|
8197
8197
|
log2(`[magic-context] Magic Context storage is at ${storageDir}, outside the folder Engram backs up (~/.local/share/cortexkit/magic-context). It is not included in CortexKit backups.`);
|
|
8198
8198
|
}
|
|
8199
|
-
const { registerContext } = await import("./context-
|
|
8199
|
+
const { registerContext } = await import("./context-nfkhb5sv.js");
|
|
8200
8200
|
setHarness2("opencode2");
|
|
8201
8201
|
bindStaleBuildNotice({}, import.meta.url, "opencode2");
|
|
8202
8202
|
const duties = await registerContext(context);
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
releaseCompartmentLeaseBestEffort,
|
|
12
12
|
getCompartments,
|
|
13
13
|
getLastCompartmentEndMessage
|
|
14
|
-
} from "./server-
|
|
14
|
+
} from "./server-yxw43z2w.js";
|
|
15
15
|
import"./server-2amn2s73.js";
|
|
16
16
|
import"./server-y8xjr8rx.js";
|
|
17
17
|
import"./server-x6fn9x8q.js";
|
|
@@ -24,7 +24,7 @@ import"./server-1d042x6w.js";
|
|
|
24
24
|
import"./server-6ash6z8z.js";
|
|
25
25
|
import"./server-ds8vpfkr.js";
|
|
26
26
|
import"./server-8pdfmc27.js";
|
|
27
|
-
import"./server-
|
|
27
|
+
import"./server-8w9b5exq.js";
|
|
28
28
|
import {
|
|
29
29
|
getWrapupInProgressState,
|
|
30
30
|
acquireWrapupInProgress,
|
|
@@ -32,16 +32,16 @@ import {
|
|
|
32
32
|
releaseWrapupInProgress,
|
|
33
33
|
getHistorianFailureState,
|
|
34
34
|
clearEmergencyRecovery
|
|
35
|
-
} from "./server-
|
|
35
|
+
} from "./server-hb5zm7yh.js";
|
|
36
36
|
import"./server-xepx8t43.js";
|
|
37
|
-
import"./server-
|
|
37
|
+
import"./server-hcgqsdrh.js";
|
|
38
38
|
import"./server-1zx87sdm.js";
|
|
39
39
|
import"./server-rz6g5xne.js";
|
|
40
40
|
import"./server-2ra6pwf3.js";
|
|
41
41
|
import"./server-3ap5dmhc.js";
|
|
42
42
|
import {
|
|
43
43
|
prepareRawSessionOrdinals2
|
|
44
|
-
} from "./server-
|
|
44
|
+
} from "./server-cdddk5d1.js";
|
|
45
45
|
import"./server-fr0wbhdn.js";
|
|
46
46
|
import"./server-jn4pktdk.js";
|
|
47
47
|
import"./server-afsz3cmx.js";
|
|
@@ -63,7 +63,7 @@ import {
|
|
|
63
63
|
registerActiveCompartmentRun,
|
|
64
64
|
setRecompStarting2,
|
|
65
65
|
setRecompTerminal2
|
|
66
|
-
} from "./server-
|
|
66
|
+
} from "./server-xse5jngy.js";
|
|
67
67
|
import"./server-qt1qqasc.js";
|
|
68
68
|
import"./server-z5255w05.js";
|
|
69
69
|
import"./server-jtq03rkb.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runManagedWrapup2
|
|
3
|
-
} from "./index-
|
|
4
|
-
import"./index-
|
|
5
|
-
import"./index-
|
|
3
|
+
} from "./index-hs9xxmmy.js";
|
|
4
|
+
import"./index-m568xww6.js";
|
|
5
|
+
import"./index-zdd01nhc.js";
|
|
6
6
|
import"./index-832w615x.js";
|
|
7
7
|
import"./index-sd3egckz.js";
|
|
8
8
|
import"./index-n6aye6ny.js";
|
|
@@ -10,16 +10,16 @@ import"./index-zxj39ba2.js";
|
|
|
10
10
|
import"./index-jjvbk92s.js";
|
|
11
11
|
import"./index-gq1g9a3a.js";
|
|
12
12
|
import"./index-4dhv7mqz.js";
|
|
13
|
-
import"./index-
|
|
13
|
+
import"./index-ezr8mr1c.js";
|
|
14
14
|
import"./index-tebcx987.js";
|
|
15
|
-
import"./index-
|
|
15
|
+
import"./index-7dj3s7qq.js";
|
|
16
16
|
import"./index-2amn2s73.js";
|
|
17
17
|
import"./index-6athgjba.js";
|
|
18
18
|
import"./index-ngwmx6nt.js";
|
|
19
19
|
import"./index-1sq1krqw.js";
|
|
20
20
|
import"./index-qt1qqasc.js";
|
|
21
|
-
import"./index-
|
|
22
|
-
import"./index-
|
|
21
|
+
import"./index-6kgsfb81.js";
|
|
22
|
+
import"./index-kvfrse61.js";
|
|
23
23
|
import"./index-1zx87sdm.js";
|
|
24
24
|
import"./index-x40zr813.js";
|
|
25
25
|
import"./index-x8a7jmkh.js";
|
|
@@ -29,7 +29,7 @@ import"./index-6nqz8hsz.js";
|
|
|
29
29
|
import"./index-jg7sbt3v.js";
|
|
30
30
|
import"./index-snbpdpa3.js";
|
|
31
31
|
import"./index-pxnzyvjc.js";
|
|
32
|
-
import"./index-
|
|
32
|
+
import"./index-qn27gh4e.js";
|
|
33
33
|
import"./index-fb3zxn06.js";
|
|
34
34
|
import"./index-xx05vta0.js";
|
|
35
35
|
import"./index-fr0wbhdn.js";
|
package/package.json
CHANGED
|
@@ -49,6 +49,7 @@ import { createHash } from "node:crypto";
|
|
|
49
49
|
import type { ContextDatabase } from "../features/magic-context/storage";
|
|
50
50
|
import { saveSourceContent } from "../features/magic-context/storage-source";
|
|
51
51
|
import {
|
|
52
|
+
setTagTokenCount,
|
|
52
53
|
updateTagByteSize,
|
|
53
54
|
updateTagInputByteSize,
|
|
54
55
|
updateTagInputTokenCount,
|
|
@@ -296,6 +297,12 @@ interface ToolOccurrence {
|
|
|
296
297
|
originalInput?: Record<string, unknown>;
|
|
297
298
|
}
|
|
298
299
|
|
|
300
|
+
interface ResultTextBlock {
|
|
301
|
+
part: TranscriptPart;
|
|
302
|
+
text: string;
|
|
303
|
+
tokenCacheKey: string;
|
|
304
|
+
}
|
|
305
|
+
|
|
299
306
|
interface TagTranscriptTiming {
|
|
300
307
|
identity: number;
|
|
301
308
|
prefix: number;
|
|
@@ -310,8 +317,18 @@ interface ToolAggregate {
|
|
|
310
317
|
occurrences: ToolOccurrence[];
|
|
311
318
|
/** Largest byteSize seen across occurrences — used as the tag size. */
|
|
312
319
|
maxByteSize: number;
|
|
313
|
-
/**
|
|
320
|
+
/**
|
|
321
|
+
* Token count paired with maxByteSize (the same output occurrence). A result
|
|
322
|
+
* that carries images instead counts its largest text block plus every image
|
|
323
|
+
* at the host's per-image cost (see applyImageResultAccounting).
|
|
324
|
+
*/
|
|
314
325
|
maxTokenCount: number;
|
|
326
|
+
/** Per-image token cost of the image blocks in this pass's result occurrences. */
|
|
327
|
+
resultImageTokens: number;
|
|
328
|
+
/** This pass's result text blocks, before the tag prefix, for applyImageResultAccounting. */
|
|
329
|
+
resultTexts: ResultTextBlock[];
|
|
330
|
+
/** Set when applyGrownToolResultAccounting wrote this pass (its write keeps the larger count). */
|
|
331
|
+
tokenCountGrewThisPass?: boolean;
|
|
315
332
|
/** Tool name from the first occurrence we see one on. */
|
|
316
333
|
toolName: string | null;
|
|
317
334
|
/** Input byte size from the invocation occurrence (for storage projection). */
|
|
@@ -572,6 +589,9 @@ export function tagTranscript(
|
|
|
572
589
|
if (timing) timing.identity += performance.now() - identityStart;
|
|
573
590
|
}
|
|
574
591
|
existing.identityReusable &&= reuseIdentity;
|
|
592
|
+
if (part.kind === "tool_result") {
|
|
593
|
+
noteResultBlock(existing, part, text, tokenCacheKey);
|
|
594
|
+
}
|
|
575
595
|
applyToolPrefixAndTarget({
|
|
576
596
|
skipPrefixInjection,
|
|
577
597
|
part,
|
|
@@ -612,6 +632,8 @@ export function tagTranscript(
|
|
|
612
632
|
// genuinely larger folded result can still bump accounting.
|
|
613
633
|
maxByteSize: reusableAccounting.byteSize,
|
|
614
634
|
maxTokenCount: reusableAccounting.tokenCount ?? 0,
|
|
635
|
+
resultImageTokens: 0,
|
|
636
|
+
resultTexts: [],
|
|
615
637
|
toolName: null,
|
|
616
638
|
inputByteSize: reusableAccounting.inputByteSize,
|
|
617
639
|
inputTokenCount: reusableAccounting.inputTokenCount,
|
|
@@ -674,6 +696,8 @@ export function tagTranscript(
|
|
|
674
696
|
occurrences: [{ message, part, kind: part.kind }],
|
|
675
697
|
maxByteSize: persistedAccounting?.byteSize ?? outputByteSize,
|
|
676
698
|
maxTokenCount: persistedAccounting?.tokenCount ?? outputTokenCount,
|
|
699
|
+
resultImageTokens: 0,
|
|
700
|
+
resultTexts: [],
|
|
677
701
|
toolName: accounting.toolName,
|
|
678
702
|
inputByteSize:
|
|
679
703
|
persistedAccounting?.inputByteSize ??
|
|
@@ -703,6 +727,8 @@ export function tagTranscript(
|
|
|
703
727
|
toolAggregates.set(aggregateKey, aggregate);
|
|
704
728
|
if (part.kind === "tool_use") {
|
|
705
729
|
openToolAggregateKeysByCallId.set(callId, [...pendingKeys, aggregateKey]);
|
|
730
|
+
} else {
|
|
731
|
+
noteResultBlock(aggregate, part, text, tokenCacheKey);
|
|
706
732
|
}
|
|
707
733
|
applyToolPrefixAndTarget({
|
|
708
734
|
skipPrefixInjection,
|
|
@@ -723,6 +749,17 @@ export function tagTranscript(
|
|
|
723
749
|
}
|
|
724
750
|
}
|
|
725
751
|
|
|
752
|
+
for (const aggregate of toolAggregates.values()) {
|
|
753
|
+
applyImageResultAccounting({
|
|
754
|
+
db,
|
|
755
|
+
sessionId,
|
|
756
|
+
tagger,
|
|
757
|
+
aggregate,
|
|
758
|
+
timing,
|
|
759
|
+
tokenCache: options.toolTokenCache,
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
|
|
726
763
|
if (timing && options.onTiming) {
|
|
727
764
|
options.onTiming("identity", timing.identity);
|
|
728
765
|
options.onTiming("prefix", timing.prefix);
|
|
@@ -787,11 +824,74 @@ function applyGrownToolResultAccounting(args: GrownToolResultAccountingArgs): vo
|
|
|
787
824
|
}
|
|
788
825
|
args.aggregate.maxByteSize = args.byteSize;
|
|
789
826
|
args.aggregate.maxTokenCount = tokenCount;
|
|
827
|
+
args.aggregate.tokenCountGrewThisPass = true;
|
|
790
828
|
updateTagByteSize(args.db, args.sessionId, args.aggregate.tagId, args.byteSize);
|
|
791
829
|
updateTagTokenCount(args.db, args.sessionId, args.aggregate.tagId, tokenCount);
|
|
792
830
|
syncToolAggregateAccounting(args.tagger, args.sessionId, args.aggregate);
|
|
793
831
|
}
|
|
794
832
|
|
|
833
|
+
/** Record one result block of this pass; `text` must be read before the tag prefix is added. */
|
|
834
|
+
function noteResultBlock(
|
|
835
|
+
aggregate: ToolAggregate,
|
|
836
|
+
part: TranscriptPart,
|
|
837
|
+
text: string,
|
|
838
|
+
tokenCacheKey: string,
|
|
839
|
+
): void {
|
|
840
|
+
const imageTokens = part.imageTokens?.() ?? 0;
|
|
841
|
+
if (imageTokens > 0) aggregate.resultImageTokens += imageTokens;
|
|
842
|
+
else if (text.length > 0) aggregate.resultTexts.push({ part, text, tokenCacheKey });
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* A tool result that carries images (Pi's `read` of a picture, an image
|
|
847
|
+
* generator) is sized as its largest text block plus each image at what the
|
|
848
|
+
* request carries for it: the host's per-image token cost while the image is
|
|
849
|
+
* sent, or the cost of the text placeholder sent in its place (the
|
|
850
|
+
* processed-image strip's marker, or the host's note for a model without image
|
|
851
|
+
* input; see the Pi transcript's `imageTokens`). Byte-growth accounting alone
|
|
852
|
+
* would leave it at the count of its largest block, an image whose bytes are
|
|
853
|
+
* base64, so the protected tail, the drop planners and status would see a few
|
|
854
|
+
* dozen tokens for an output the provider bills as an image. Runs once per
|
|
855
|
+
* pass after the walk, so block order does not matter. The stored count follows
|
|
856
|
+
* the request both ways: it rises when a row stored before images were counted
|
|
857
|
+
* is seen again, and falls once an image leaves the request, so a queued drop
|
|
858
|
+
* of an already-stripped result is not valued at the images it no longer
|
|
859
|
+
* removes. Replaying the same request writes nothing. Results without images
|
|
860
|
+
* are left untouched.
|
|
861
|
+
*/
|
|
862
|
+
function applyImageResultAccounting(args: {
|
|
863
|
+
db: ContextDatabase;
|
|
864
|
+
sessionId: string;
|
|
865
|
+
tagger: Tagger;
|
|
866
|
+
aggregate: ToolAggregate & { tagId: number };
|
|
867
|
+
timing: TagTranscriptTiming | undefined;
|
|
868
|
+
tokenCache?: Map<string, { text: string; tokenCount: number }>;
|
|
869
|
+
}): void {
|
|
870
|
+
const { aggregate } = args;
|
|
871
|
+
if (aggregate.resultImageTokens === 0) return;
|
|
872
|
+
const tokenStart = args.timing ? performance.now() : 0;
|
|
873
|
+
let textTokens = 0;
|
|
874
|
+
for (const block of aggregate.resultTexts) {
|
|
875
|
+
textTokens = Math.max(
|
|
876
|
+
textTokens,
|
|
877
|
+
getCachedToolPartTokenCount(
|
|
878
|
+
block.part,
|
|
879
|
+
block.text,
|
|
880
|
+
args.tokenCache,
|
|
881
|
+
block.tokenCacheKey,
|
|
882
|
+
),
|
|
883
|
+
);
|
|
884
|
+
}
|
|
885
|
+
if (args.timing) args.timing.tokenCounting += performance.now() - tokenStart;
|
|
886
|
+
const tokenCount = textTokens + aggregate.resultImageTokens;
|
|
887
|
+
// A growth write this pass keeps the larger of the stored and new counts, so
|
|
888
|
+
// the in-memory count may not be what the row holds; write the exact count.
|
|
889
|
+
if (tokenCount === aggregate.maxTokenCount && !aggregate.tokenCountGrewThisPass) return;
|
|
890
|
+
aggregate.maxTokenCount = tokenCount;
|
|
891
|
+
setTagTokenCount(args.db, args.sessionId, aggregate.tagId, tokenCount);
|
|
892
|
+
syncToolAggregateAccounting(args.tagger, args.sessionId, aggregate);
|
|
893
|
+
}
|
|
894
|
+
|
|
795
895
|
function readAggregateToolAccounting(
|
|
796
896
|
part: TranscriptPart,
|
|
797
897
|
timing: TagTranscriptTiming | undefined,
|
|
@@ -960,9 +1060,13 @@ function getToolPartByteSize(part: TranscriptPart, text: string): number {
|
|
|
960
1060
|
* Real-tokenizer mirror of {@link getToolPartByteSize}: token count of a tool
|
|
961
1061
|
* part's output text (falling back to the raw payload for non-text results,
|
|
962
1062
|
* matching the byte path so token_count stays consistent with byte_size).
|
|
1063
|
+
* An image block is the exception: it counts at the host's per-image cost, since
|
|
1064
|
+
* the provider bills the image, not the length of its base64 encoding.
|
|
963
1065
|
*/
|
|
964
1066
|
function getToolPartTokenCount(part: TranscriptPart, text: string): number {
|
|
965
1067
|
if (text.length > 0 || part.kind !== "tool_result") return estimateTokens(text);
|
|
1068
|
+
const imageTokens = part.imageTokens?.() ?? 0;
|
|
1069
|
+
if (imageTokens > 0) return imageTokens;
|
|
966
1070
|
const raw = part.rawByteSize?.();
|
|
967
1071
|
if (typeof raw === "number" && raw > 0) {
|
|
968
1072
|
const record = isRecord(part) ? part : undefined;
|