@cortexkit/magic-context 0.49.8 → 0.49.10

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 (2) hide show
  1. package/dist/index.js +161 -15
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -30175,32 +30175,32 @@ var init_read_session_formatting = __esm(() => {
30175
30175
  // ../plugin/src/shared/stable-json.ts
30176
30176
  function stableStringify(value, seen = new WeakSet) {
30177
30177
  const pieces = [];
30178
- writeStable(value, seen, pieces);
30178
+ writeStable(value, seen, (piece) => pieces.push(piece));
30179
30179
  return pieces.join("");
30180
30180
  }
30181
- function writeStable(value, seen, pieces) {
30181
+ function writeStable(value, seen, write) {
30182
30182
  if (value === undefined) {
30183
- pieces.push("undefined");
30183
+ write("undefined");
30184
30184
  return;
30185
30185
  }
30186
30186
  if (value === null || typeof value !== "object") {
30187
- pieces.push(JSON.stringify(value) ?? String(value));
30187
+ write(JSON.stringify(value) ?? String(value));
30188
30188
  return;
30189
30189
  }
30190
30190
  if (seen.has(value)) {
30191
- pieces.push('"[Circular]"');
30191
+ write('"[Circular]"');
30192
30192
  return;
30193
30193
  }
30194
30194
  seen.add(value);
30195
30195
  if (Array.isArray(value)) {
30196
- pieces.push("[");
30196
+ write("[");
30197
30197
  for (let index = 0;index < value.length; index += 1) {
30198
30198
  if (index > 0)
30199
- pieces.push(",");
30199
+ write(",");
30200
30200
  if (index in value)
30201
- writeStable(value[index], seen, pieces);
30201
+ writeStable(value[index], seen, write);
30202
30202
  }
30203
- pieces.push("]");
30203
+ write("]");
30204
30204
  return;
30205
30205
  }
30206
30206
  const entries = Object.entries(value).sort(([a], [b]) => {
@@ -30210,14 +30210,19 @@ function writeStable(value, seen, pieces) {
30210
30210
  return 1;
30211
30211
  return 0;
30212
30212
  });
30213
- pieces.push("{");
30213
+ if (entries.length > 0 && entries.length <= 16 && entries.every(([key, child]) => key.length <= 4096 && !/^(0|[1-9]\d*)$/.test(key) && (child === null || typeof child === "number" || typeof child === "boolean" || typeof child === "string" && child.length <= 4096))) {
30214
+ write(JSON.stringify(Object.fromEntries(entries)));
30215
+ return;
30216
+ }
30217
+ write("{");
30214
30218
  entries.forEach(([key, child], index) => {
30215
30219
  if (index > 0)
30216
- pieces.push(",");
30217
- pieces.push(JSON.stringify(key), ":");
30218
- writeStable(child, seen, pieces);
30220
+ write(",");
30221
+ write(JSON.stringify(key));
30222
+ write(":");
30223
+ writeStable(child, seen, write);
30219
30224
  });
30220
- pieces.push("}");
30225
+ write("}");
30221
30226
  }
30222
30227
 
30223
30228
  // ../plugin/src/features/magic-context/tool-definition-tokens.ts
@@ -30889,6 +30894,12 @@ var init_tag_content_primitives = __esm(() => {
30889
30894
  encoder = new TextEncoder;
30890
30895
  });
30891
30896
 
30897
+ // ../plugin/src/hooks/magic-context/tail-hygiene-output-count.ts
30898
+ var CURRENT_OUTPUT_COUNT;
30899
+ var init_tail_hygiene_output_count = __esm(() => {
30900
+ CURRENT_OUTPUT_COUNT = Symbol.for("magic-context.current-reclaimable-tool-output-count");
30901
+ });
30902
+
30892
30903
  // ../plugin/src/shared/record-type-guard.ts
30893
30904
  function isRecord2(value) {
30894
30905
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -30900,6 +30911,128 @@ var init_tag_owner_id = __esm(() => {
30900
30911
  PI_FALLBACK_PREFIXES_JSON = JSON.stringify([..."pi-msg-"].reduce((prefixes, char) => prefixes.flatMap((prefix) => /[a-z]/.test(char) ? [prefix + char, prefix + char.toUpperCase()] : [prefix + char]), [""]));
30901
30912
  });
30902
30913
 
30914
+ // ../plugin/src/shared/tail-hygiene-json.ts
30915
+ class TailHygieneJsonMemo {
30916
+ entries = new Map;
30917
+ bytes = 0;
30918
+ passText = new WeakMap;
30919
+ passHash = new WeakMap;
30920
+ beginPass() {
30921
+ this.passText = new WeakMap;
30922
+ this.passHash = new WeakMap;
30923
+ }
30924
+ get(key, value, compute, fingerprint = false) {
30925
+ const pass = fingerprint ? this.passHash : this.passText;
30926
+ const object = value !== null && typeof value === "object" ? value : undefined;
30927
+ const local = object ? pass.get(object) : undefined;
30928
+ if (local !== undefined)
30929
+ return local;
30930
+ const previous = this.entries.get(key);
30931
+ if (previous && sameJson(previous.snapshot, value)) {
30932
+ if (object)
30933
+ pass.set(object, previous.result);
30934
+ return previous.result;
30935
+ }
30936
+ const result = compute();
30937
+ if (previous) {
30938
+ this.bytes -= previous.bytes;
30939
+ this.entries.delete(key);
30940
+ }
30941
+ try {
30942
+ const copy = copyJson(value);
30943
+ const bytes = copy.bytes + (key.length + result.length) * 2;
30944
+ if (bytes <= MAX_MEMO_BYTES) {
30945
+ this.entries.set(key, { snapshot: copy.value, result, bytes });
30946
+ this.bytes += bytes;
30947
+ if (object)
30948
+ pass.set(object, result);
30949
+ }
30950
+ } catch {}
30951
+ while (this.bytes > MAX_MEMO_BYTES || this.entries.size > MAX_MEMO_ENTRIES) {
30952
+ const oldest = this.entries.entries().next().value;
30953
+ if (!oldest)
30954
+ break;
30955
+ this.bytes -= oldest[1].bytes;
30956
+ this.entries.delete(oldest[0]);
30957
+ }
30958
+ return result;
30959
+ }
30960
+ }
30961
+ function copyJson(value) {
30962
+ const seen = new Map;
30963
+ let bytes = 0;
30964
+ const copy = (current) => {
30965
+ bytes += 16;
30966
+ if (typeof current === "string")
30967
+ bytes += current.length * 2;
30968
+ if (bytes > MAX_MEMO_BYTES)
30969
+ throw new Error("memo capacity");
30970
+ if (current === null || typeof current !== "object") {
30971
+ if (["function", "symbol", "bigint"].includes(typeof current))
30972
+ throw new Error("exotic");
30973
+ return current;
30974
+ }
30975
+ if (seen.has(current))
30976
+ return seen.get(current);
30977
+ const prototype = Object.getPrototypeOf(current);
30978
+ if (!Array.isArray(current) && prototype !== Object.prototype && prototype !== null)
30979
+ throw new Error("exotic");
30980
+ const result = Array.isArray(current) ? new Array(current.length) : Object.create(prototype);
30981
+ seen.set(current, result);
30982
+ for (const key of Object.keys(current)) {
30983
+ const descriptor = Object.getOwnPropertyDescriptor(current, key);
30984
+ if (!descriptor || !("value" in descriptor))
30985
+ throw new Error("accessor");
30986
+ bytes += key.length * 2 + 16;
30987
+ if (key === "__proto__") {
30988
+ Object.defineProperty(result, key, {
30989
+ value: copy(descriptor.value),
30990
+ enumerable: true,
30991
+ writable: true,
30992
+ configurable: true
30993
+ });
30994
+ } else
30995
+ result[key] = copy(descriptor.value);
30996
+ }
30997
+ return result;
30998
+ };
30999
+ return { value: copy(value), bytes };
31000
+ }
31001
+ function sameJson(before, after) {
31002
+ const forward = new Map;
31003
+ const reverse = new Set;
31004
+ const same = (left, right) => {
31005
+ if (left === null || right === null || typeof left !== "object" || typeof right !== "object")
31006
+ return Object.is(left, right);
31007
+ if (forward.has(left))
31008
+ return forward.get(left) === right;
31009
+ if (reverse.has(right) || Object.getPrototypeOf(left) !== Object.getPrototypeOf(right))
31010
+ return false;
31011
+ forward.set(left, right);
31012
+ reverse.add(right);
31013
+ if (Array.isArray(left) && (!Array.isArray(right) || left.length !== right.length))
31014
+ return false;
31015
+ const keys = Object.keys(left);
31016
+ const otherKeys = Object.keys(right);
31017
+ if (keys.length !== otherKeys.length)
31018
+ return false;
31019
+ for (let index = 0;index < keys.length; index++) {
31020
+ const key = keys[index];
31021
+ if (key !== otherKeys[index])
31022
+ return false;
31023
+ const descriptor = Object.getOwnPropertyDescriptor(right, key);
31024
+ if (!descriptor || !("value" in descriptor) || !same(left[key], descriptor.value))
31025
+ return false;
31026
+ }
31027
+ return true;
31028
+ };
31029
+ return same(before, after);
31030
+ }
31031
+ var MAX_MEMO_BYTES, MAX_MEMO_ENTRIES = 1e4;
31032
+ var init_tail_hygiene_json = __esm(() => {
31033
+ MAX_MEMO_BYTES = 64 * 1024 * 1024;
31034
+ });
31035
+
30903
31036
  // ../plugin/src/hooks/magic-context/image-token-estimate.ts
30904
31037
  var JPEG_SCAN_LIMIT_BYTES;
30905
31038
  var init_image_token_estimate = __esm(() => {
@@ -30943,18 +31076,21 @@ var init_todo_view = __esm(() => {
30943
31076
  });
30944
31077
 
30945
31078
  // ../plugin/src/hooks/magic-context/tail-hygiene-walk.ts
30946
- var MAX_CONTENT_MEMO_BYTES, contentMemo, contentMemoOrder, baselineMeasurementMemo, MAX_BASELINE_MEMO_SIZE;
31079
+ var MAX_CONTENT_MEMO_BYTES, contentMemo, contentMemoOrder, partJsonMemo, baselineMeasurementMemo, MAX_BASELINE_MEMO_SIZE;
30947
31080
  var init_tail_hygiene_walk = __esm(() => {
30948
31081
  init_reclaim_protection();
30949
31082
  init_tag_owner_id();
31083
+ init_tail_hygiene_json();
30950
31084
  init_image_token_estimate();
30951
31085
  init_provider_visible_parts();
30952
31086
  init_read_session_formatting();
31087
+ init_tail_hygiene_output_count();
30953
31088
  init_todo_view();
30954
31089
  init_reclaim_protection();
30955
31090
  MAX_CONTENT_MEMO_BYTES = 256 * 1024 * 1024;
30956
31091
  contentMemo = new Map;
30957
31092
  contentMemoOrder = new Set;
31093
+ partJsonMemo = new TailHygieneJsonMemo;
30958
31094
  baselineMeasurementMemo = new Map;
30959
31095
  MAX_BASELINE_MEMO_SIZE = 128 * 1024 * 1024;
30960
31096
  });
@@ -30963,7 +31099,9 @@ var init_tail_hygiene_walk = __esm(() => {
30963
31099
  var init_ctx_reduce_nudge = __esm(() => {
30964
31100
  init_read_session_formatting();
30965
31101
  init_tag_content_primitives();
31102
+ init_tail_hygiene_output_count();
30966
31103
  init_tail_hygiene_walk();
31104
+ init_tail_hygiene_output_count();
30967
31105
  });
30968
31106
 
30969
31107
  // ../plugin/src/hooks/magic-context/emergency-drop.ts
@@ -32633,10 +32771,18 @@ var init_token_budget = __esm(() => {
32633
32771
  finalizingChildren = new Map;
32634
32772
  });
32635
32773
 
32774
+ // ../plugin/src/shared/hidden-zen-read.ts
32775
+ var blockedSessions, v1Runs;
32776
+ var init_hidden_zen_read = __esm(() => {
32777
+ blockedSessions = new Set;
32778
+ v1Runs = new Map;
32779
+ });
32780
+
32636
32781
  // ../plugin/src/hooks/magic-context/dropped-input-guard.ts
32637
32782
  var recordedToolParameters;
32638
32783
  var init_dropped_input_guard = __esm(() => {
32639
32784
  init_token_budget();
32785
+ init_hidden_zen_read();
32640
32786
  init_logger();
32641
32787
  recordedToolParameters = new Map;
32642
32788
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/magic-context",
3
- "version": "0.49.8",
3
+ "version": "0.49.10",
4
4
  "description": "Unified CLI for Magic Context — setup, doctor, and migration across OpenCode, Pi, and OMP",
5
5
  "keywords": [
6
6
  "opencode",