@cortexkit/opencode-magic-context 0.49.29 → 0.49.31

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.
Files changed (82) hide show
  1. package/dist/auto-search-worker.js +1 -1
  2. package/dist/chunk-embedding-write-worker.js +1 -1
  3. package/dist/{context-836j3vte.js → context-9a0f8mzh.js} +294 -41
  4. package/dist/features/magic-context/dreamer/map-memories-prompt.d.ts +3 -3
  5. package/dist/features/magic-context/dreamer/map-memories-prompt.d.ts.map +1 -1
  6. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  7. package/dist/features/magic-context/dreamer/verify.d.ts +13 -17
  8. package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
  9. package/dist/features/magic-context/storage-native-replay.d.ts +2 -0
  10. package/dist/features/magic-context/storage-native-replay.d.ts.map +1 -1
  11. package/dist/features/magic-context/work-metrics.d.ts.map +1 -1
  12. package/dist/hooks/magic-context/apply-operations.d.ts +11 -1
  13. package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
  14. package/dist/hooks/magic-context/history-boundary-repair.d.ts +1 -1
  15. package/dist/hooks/magic-context/history-boundary-repair.d.ts.map +1 -1
  16. package/dist/hooks/magic-context/strip-content.d.ts +1 -1
  17. package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
  18. package/dist/hooks/magic-context/tag-messages.d.ts +2 -0
  19. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  20. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +2 -0
  21. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  22. package/dist/hooks/magic-context/transform.d.ts +11 -0
  23. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  24. package/dist/{index-wyt5m81v.js → index-0bjktrjt.js} +3 -3
  25. package/dist/{index-zhgqgxtt.js → index-0fe4q77z.js} +7 -5
  26. package/dist/{index-wpcdk76y.js → index-22e7khnr.js} +37 -29
  27. package/dist/{index-a1h316s9.js → index-3jmx3fae.js} +1 -1
  28. package/dist/{index-tx68g9nc.js → index-4s4zq97n.js} +1 -1
  29. package/dist/{index-h4s5jk7f.js → index-hbt0sbv2.js} +1 -1
  30. package/dist/{index-q9zvphbq.js → index-kmayq4kq.js} +39 -7
  31. package/dist/{index-bps8vn9r.js → index-qathsvz2.js} +5 -3
  32. package/dist/{index-wvffze8y.js → index-vtz789ex.js} +1 -1
  33. package/dist/{index-093c4g1c.js → index-y6ynjghv.js} +2 -2
  34. package/dist/index.js +13 -13
  35. package/dist/{message-index-bounded-7qsn4fd3.js → message-index-bounded-zq7a5nm6.js} +2 -2
  36. package/dist/migration-worker.js +1 -1
  37. package/dist/raw-ordinal-warmup-worker.js +2 -2
  38. package/dist/{read-session-chunk-a5d0q3m0.js → read-session-chunk-1ndphmb8.js} +1 -1
  39. package/dist/{recomp-orchestrator-na34m4c5.js → recomp-orchestrator-ynehxbya.js} +5 -5
  40. package/dist/{search-archive-66pm17gm.js → search-archive-sr07c6aj.js} +2 -2
  41. package/dist/{search-0cd6hx7a.js → search-fbaz1m8r.js} +3 -3
  42. package/dist/shared/marker-only-text.d.ts +2 -0
  43. package/dist/shared/marker-only-text.d.ts.map +1 -0
  44. package/dist/shared/tag-transcript.d.ts +4 -1
  45. package/dist/shared/tag-transcript.d.ts.map +1 -1
  46. package/dist/shared/transcript.d.ts +3 -1
  47. package/dist/shared/transcript.d.ts.map +1 -1
  48. package/dist/{transform-postprocess-phase-27we33af.js → transform-postprocess-phase-50h70ft8.js} +5 -5
  49. package/dist/v2/auto-search-worker.js +1 -1
  50. package/dist/v2/chunk-embedding-write-worker.js +1 -1
  51. package/dist/v2/{context-g4ptae4x.js → context-cdqw9jex.js} +320 -58
  52. package/dist/v2/fold/owner.d.ts +4 -0
  53. package/dist/v2/fold/owner.d.ts.map +1 -1
  54. package/dist/v2/hidden-child-cleanup.d.ts.map +1 -1
  55. package/dist/v2/hidden-child-native.d.ts.map +1 -1
  56. package/dist/v2/hooks/context.d.ts.map +1 -1
  57. package/dist/v2/hooks/types.d.ts +3 -0
  58. package/dist/v2/hooks/types.d.ts.map +1 -1
  59. package/dist/v2/{message-index-bounded-7363502m.js → message-index-bounded-jvgz7vk9.js} +2 -2
  60. package/dist/v2/message-times.d.ts +17 -0
  61. package/dist/v2/message-times.d.ts.map +1 -0
  62. package/dist/v2/migration-worker.js +1 -1
  63. package/dist/v2/raw-ordinal-warmup-worker.js +2 -2
  64. package/dist/v2/{read-session-chunk-kkppfhft.js → read-session-chunk-djzgm4jg.js} +1 -1
  65. package/dist/v2/{recomp-orchestrator-f1df1gb8.js → recomp-orchestrator-kdxr4tx8.js} +4 -4
  66. package/dist/v2/{search-archive-v07jpw25.js → search-archive-n3dhns4r.js} +2 -2
  67. package/dist/v2/{search-2v3xyzse.js → search-q3jjw6zp.js} +3 -3
  68. package/dist/v2/{server-976dxaxh.js → server-42nebt63.js} +1 -1
  69. package/dist/v2/{server-77gznpmf.js → server-d01pe8q5.js} +1 -1
  70. package/dist/v2/{server-k9je35ev.js → server-hwag0khr.js} +1 -1
  71. package/dist/v2/{server-mxzj3r0y.js → server-rb8m4vry.js} +7 -5
  72. package/dist/v2/{server-q50ttc2g.js → server-rdjgz95f.js} +39 -7
  73. package/dist/v2/{server-w79f8ejn.js → server-rr4cbkr0.js} +1 -1
  74. package/dist/v2/server.js +2 -2
  75. package/dist/v2/store-reader.d.ts +14 -2
  76. package/dist/v2/store-reader.d.ts.map +1 -1
  77. package/dist/v2/{wrapup-orchestrator-jq33fda8.js → wrapup-orchestrator-prfvyqbb.js} +4 -4
  78. package/dist/{wrapup-orchestrator-f0xr7pft.js → wrapup-orchestrator-4zhkcsz0.js} +6 -6
  79. package/package.json +1 -1
  80. package/src/shared/marker-only-text.ts +8 -0
  81. package/src/shared/tag-transcript.ts +34 -5
  82. package/src/shared/transcript.ts +1 -1
@@ -76,6 +76,8 @@ import type { Transcript, TranscriptMessage, TranscriptPart } from "./transcript
76
76
  export { TEXT_TAG_IDENTITY_MARKER };
77
77
 
78
78
  export interface TagTranscriptOptions {
79
+ /** Independently validated text sources; does not authorize tool accounting reuse. */
80
+ reuseTextMessageIds?: ReadonlySet<string>;
79
81
  /** Keep tag-only assistant slots inert when their original text must survive stripping. */
80
82
  preserveTagOnlyAssistantText?: boolean;
81
83
  /**
@@ -125,6 +127,8 @@ export interface TagTranscriptResult {
125
127
  targets: Map<number, TagTarget>;
126
128
  }
127
129
 
130
+ type PersistedDropTag = Pick<TagEntry, "tagNumber" | "messageId" | "type" | "toolOwnerMessageId">;
131
+
128
132
  /**
129
133
  * Bind durable drops to a saved request without tagging it again. Recovery must
130
134
  * not allocate identities, inject prefixes, or write accounting while the store
@@ -132,7 +136,7 @@ export interface TagTranscriptResult {
132
136
  */
133
137
  export function buildPersistedDropTargets(
134
138
  transcript: Transcript,
135
- tags: readonly TagEntry[],
139
+ tags: readonly PersistedDropTag[],
136
140
  options: { allowReasoningPrefixRewrite?: boolean } = {},
137
141
  ): Map<number, TagTarget> {
138
142
  const targets = new Map<number, TagTarget>();
@@ -147,7 +151,7 @@ export function buildPersistedDropTargets(
147
151
  const byNumber = new Map(tags.map((tag) => [tag.tagNumber, tag]));
148
152
  const aggregates = new Map<
149
153
  string,
150
- { tag?: TagEntry; occurrences: ToolOccurrence[]; reasoning: boolean }
154
+ { tag?: PersistedDropTag; occurrences: ToolOccurrence[]; reasoning: boolean }
151
155
  >();
152
156
  const pending = new Map<string, string[]>();
153
157
  const resolved = new Map<string, string>();
@@ -421,7 +425,10 @@ export function tagTranscript(
421
425
  skipPrefixInjection,
422
426
  preserveTagOnlyAssistantText: options.preserveTagOnlyAssistantText,
423
427
  entryFingerprint: options.entryFingerprintByMessageId?.get(messageId) ?? null,
424
- reuseIdentity: reuseIdentity || contentDerivedTextIds !== undefined,
428
+ reuseIdentity:
429
+ reuseIdentity ||
430
+ options.reuseTextMessageIds?.has(messageId) === true ||
431
+ contentDerivedTextIds !== undefined,
425
432
  timing,
426
433
  textIdentitySourceCache: options.textIdentitySourceCache,
427
434
  textTokenCache: options.textTokenCache,
@@ -512,6 +519,11 @@ export function tagTranscript(
512
519
  timing,
513
520
  options.toolTokenCache,
514
521
  tokenCacheKey,
522
+ {
523
+ byteSize: existing.maxByteSize,
524
+ tokenCount: existing.maxTokenCount,
525
+ inputTokenCount: existing.inputTokenCount,
526
+ },
515
527
  );
516
528
  text = accounting.text;
517
529
  if (part.kind === "tool_result") {
@@ -627,6 +639,7 @@ export function tagTranscript(
627
639
  timing,
628
640
  options.toolTokenCache,
629
641
  tokenCacheKey,
642
+ tagger.getToolTagAccounting(sessionId, callId, messageId),
630
643
  );
631
644
  text = accounting.text;
632
645
  const outputByteSize = part.kind === "tool_result" ? accounting.byteSize : 0;
@@ -784,12 +797,23 @@ function readAggregateToolAccounting(
784
797
  timing: TagTranscriptTiming | undefined,
785
798
  tokenCache?: Map<string, { text: string; tokenCount: number }>,
786
799
  tokenCacheKey?: string,
800
+ persisted?: { byteSize: number; tokenCount: number | null; inputTokenCount: number | null },
787
801
  ): AggregateToolAccounting {
788
802
  const text = part.getText() ?? "";
789
803
  const byteSize = getToolPartByteSize(part, text);
790
- const metadata = part.getToolMetadata();
804
+ // Persisted tool-result accounting tracks the largest byte size seen. Skip
805
+ // output tokenization when that size has not grown and a count is stored;
806
+ // known input counts also need no tokenization. Growth and missing counts still
807
+ // use the counting path, even if the owning message ID was not eligible for
808
+ // tag reuse through options.reuseMessageIds.
809
+ const metadata = part.getToolMetadata({
810
+ skipInputTokenCount: persisted?.inputTokenCount != null,
811
+ });
791
812
  let tokenCount = 0;
792
- if (part.kind === "tool_result") {
813
+ if (
814
+ part.kind === "tool_result" &&
815
+ (!persisted || persisted.tokenCount === null || byteSize > persisted.byteSize)
816
+ ) {
793
817
  const tokenStart = timing ? performance.now() : 0;
794
818
  tokenCount = getCachedToolPartTokenCount(part, text, tokenCache, tokenCacheKey);
795
819
  if (timing) timing.tokenCounting += performance.now() - tokenStart;
@@ -1423,6 +1447,11 @@ function buildAggregateTarget(
1423
1447
  },
1424
1448
  // Open invocations still belong to the current turn; only complete arcs reclaim.
1425
1449
  prepareDrop: () => !occurrences.some((occ) => occ.part.canRemove?.() === "defer"),
1450
+ prepareReplayDrop: () => {
1451
+ if (complete() && !requiresToolArcSkeleton) {
1452
+ for (const occ of occurrences) occ.part.canRemove?.();
1453
+ }
1454
+ },
1426
1455
  canDrop: () => complete() && !occurrences.some((occ) => occ.part.hasUserAnswer?.()),
1427
1456
  requiresToolArcSkeleton,
1428
1457
  // Non-mutating read of the invocation input (the tool_use occurrence
@@ -139,7 +139,7 @@ export interface TranscriptPart {
139
139
  *
140
140
  * For non-tool parts both byte fields are undefined/0.
141
141
  */
142
- getToolMetadata(): {
142
+ getToolMetadata(options?: { skipInputTokenCount?: boolean }): {
143
143
  toolName: string | undefined;
144
144
  inputByteSize: number;
145
145
  inputTokenCount: number;