@cortexkit/pi-magic-context 0.47.0 → 0.48.0

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 (60) hide show
  1. package/dist/auto-search-worker.js +27 -22
  2. package/dist/embedding-activity-ew6dshfd.js +10 -0
  3. package/dist/embedding-backfill-bnnytehy.js +20 -0
  4. package/dist/embedding-cache-7rp4gqzr.js +16 -0
  5. package/dist/embedding-worker.js +11 -8
  6. package/dist/harness-9872e0ym.js +10 -0
  7. package/dist/historian-calibration-extension.js +3 -2
  8. package/dist/index-0am8a7k1.js +152 -0
  9. package/dist/index-0h2mkab2.js +17 -0
  10. package/dist/index-135e8hvg.js +43 -0
  11. package/dist/{index-0qejsd7f.js → index-3cgbv47m.js} +289 -45
  12. package/dist/index-419bndtm.js +2309 -0
  13. package/dist/index-544c0e0x.js +3026 -0
  14. package/dist/index-5hd7h4rr.js +3098 -0
  15. package/dist/index-5jp1h0bz.js +750 -0
  16. package/dist/index-603mt6nm.js +171 -0
  17. package/dist/index-674f6qs2.js +16 -0
  18. package/dist/{index-vgcemg0n.js → index-6pgq5ns2.js} +151 -2452
  19. package/dist/{index-xpbh1ypk.js → index-72bdc1bd.js} +38 -741
  20. package/dist/index-8976mezv.js +209 -0
  21. package/dist/{index-td885aah.js → index-8y5knskr.js} +98 -231
  22. package/dist/{index-k3ezsjng.js → index-98z1c1r0.js} +14574 -13942
  23. package/dist/index-9p40dgkm.js +22 -0
  24. package/dist/index-9x1f96r8.js +11 -0
  25. package/dist/{index-266qrgss.js → index-9xb0axhc.js} +301 -27
  26. package/dist/{index-spk5vrhy.js → index-bgmv2kaf.js} +1 -16
  27. package/dist/index-dkx0b1kt.js +514 -0
  28. package/dist/{index-7n8gb6j3.js → index-f956htf3.js} +28 -31
  29. package/dist/index-fapenpch.js +13 -0
  30. package/dist/index-fm3ksh5e.js +1060 -0
  31. package/dist/{index-2p1e8706.js → index-fp37he9a.js} +3 -3
  32. package/dist/index-hrf13mn3.js +2388 -0
  33. package/dist/index-pvm4pd5d.js +3069 -0
  34. package/dist/{index-kztsbkqq.js → index-r7xg4hvw.js} +171 -168
  35. package/dist/index-rt5jgzp1.js +1127 -0
  36. package/dist/{index-n3g5mwa8.js → index-wrm4nbj7.js} +3 -3
  37. package/dist/index-xjqheg7a.js +931 -0
  38. package/dist/index-yhzhdp3m.js +143 -0
  39. package/dist/{index-w76x3af7.js → index-zrr5t5a7.js} +1 -3
  40. package/dist/index.js +4203 -2183
  41. package/dist/logger-v3dsxdnm.js +19 -0
  42. package/dist/message-index-bounded-t7vvty76.js +120 -0
  43. package/dist/{message-time-backfill-d3db2etr.js → message-time-backfill-4ndf7hrq.js} +7 -6
  44. package/dist/migration-worker.js +20 -14
  45. package/dist/project-embedding-registry-jy2hmq28.js +85 -0
  46. package/dist/raw-ordinal-warmup-worker.js +60 -0
  47. package/dist/{read-session-chunk-atxsyfqv.js → read-session-chunk-47pjn7fz.js} +12 -6
  48. package/dist/read-session-raw-yn8nawav.js +55 -0
  49. package/dist/{safe-notification-target-6cn3z99t.js → safe-notification-target-3c1ns931.js} +3 -2
  50. package/dist/search-42szfhwp.js +40 -0
  51. package/dist/sqlite-3yye76ht.js +44 -0
  52. package/dist/sqlite-context-pragmas-gcgch6qz.js +6 -0
  53. package/dist/storage-memory-1z20y55x.js +71 -0
  54. package/dist/storage-tags-jym5z6yk.js +127 -0
  55. package/dist/subagent-entry.js +34 -17
  56. package/dist/transformers-node-wasm.js +18415 -18415
  57. package/package.json +3 -3
  58. package/dist/index-7s8vw2y0.js +0 -5207
  59. package/dist/index-qaa5j277.js +0 -8544
  60. /package/dist/{index-en1k8h8m.js → index-5prbx026.js} +0 -0
@@ -0,0 +1,22 @@
1
+ // ../plugin/src/shared/embedding-activity.ts
2
+ var busySessions = new Set;
3
+ function setEmbeddingSessionBusy2(sessionId, busy) {
4
+ if (busy)
5
+ busySessions.add(sessionId);
6
+ else
7
+ busySessions.delete(sessionId);
8
+ }
9
+ function observeEmbeddingActivity2(event) {
10
+ const props = event.properties;
11
+ if (!props || typeof props.sessionID !== "string")
12
+ return;
13
+ if (event.type === "session.idle" || event.type === "session.deleted" || event.type === "session.status" && props.status?.type === "idle") {
14
+ setEmbeddingSessionBusy2(props.sessionID, false);
15
+ } else if (event.type === "session.status" && props.status?.type) {
16
+ setEmbeddingSessionBusy2(props.sessionID, true);
17
+ }
18
+ }
19
+ function isEmbeddingHostBusy2() {
20
+ return busySessions.size > 0;
21
+ }
22
+ export { setEmbeddingSessionBusy2, observeEmbeddingActivity2, isEmbeddingHostBusy2 };
@@ -0,0 +1,11 @@
1
+ // ../plugin/src/features/magic-context/memory/normalize-hash.ts
2
+ import { createHash } from "node:crypto";
3
+ function normalizeMemoryContent(content) {
4
+ return content.toLowerCase().replace(/\s+/g, " ").trim();
5
+ }
6
+ function computeNormalizedHash(content) {
7
+ const normalized = normalizeMemoryContent(content);
8
+ return createHash("md5").update(normalized).digest("hex");
9
+ }
10
+
11
+ export { computeNormalizedHash };
@@ -1,25 +1,13 @@
1
1
  import {
2
- log
3
- } from "./index-7n8gb6j3.js";
4
-
5
- // ../plugin/src/shared/internal-initiator-marker.ts
6
- var OMO_INTERNAL_INITIATOR_MARKER = "<!-- OMO_INTERNAL_INITIATOR -->";
7
-
8
- // ../plugin/src/shared/system-directive.ts
9
- var SYSTEM_DIRECTIVE_PREFIX = "[SYSTEM DIRECTIVE: MAGIC-CONTEXT";
10
- function isSystemDirective(text) {
11
- return text.trimStart().startsWith(SYSTEM_DIRECTIVE_PREFIX);
12
- }
13
- function removeSystemReminders(text) {
14
- return text.replace(/<system-reminder>[\s\S]*?<\/system-reminder>/gi, "").trim();
15
- }
2
+ log2
3
+ } from "./index-f956htf3.js";
16
4
 
17
5
  // ../plugin/src/hooks/magic-context/read-session-formatting.ts
18
6
  import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
19
7
  import { createRequire } from "node:module";
20
8
  import { homedir } from "node:os";
21
9
  import { dirname, join, resolve } from "node:path";
22
- import { pathToFileURL } from "node:url";
10
+ import { fileURLToPath, pathToFileURL } from "node:url";
23
11
 
24
12
  // ../plugin/src/shared/commit-detection.ts
25
13
  var HASH_HEX = "[0-9a-f]{7,12}";
@@ -32,6 +20,284 @@ function createCommitHashExtractPattern() {
32
20
  return new RegExp(`\`?\\b(${HASH_HEX})\\b\`?`, "gi");
33
21
  }
34
22
 
23
+ // ../plugin/src/shared/internal-initiator-marker.ts
24
+ var OMO_INTERNAL_INITIATOR_MARKER = "<!-- OMO_INTERNAL_INITIATOR -->";
25
+
26
+ // ../plugin/src/shared/system-directive.ts
27
+ var SYSTEM_DIRECTIVE_PREFIX = "[SYSTEM DIRECTIVE: MAGIC-CONTEXT";
28
+ function isSystemDirective(text) {
29
+ return text.trimStart().startsWith(SYSTEM_DIRECTIVE_PREFIX);
30
+ }
31
+ function removeSystemReminders(text) {
32
+ return text.replace(/<system-reminder>[\s\S]*?<\/system-reminder>/gi, "").trim();
33
+ }
34
+
35
+ // ../plugin/src/hooks/magic-context/token-count-exact.ts
36
+ var NO_RANK = 4294967295;
37
+ var LONG_PIECE_BYTES = 256;
38
+ var MERGE_CACHE_GENERATION = 50000;
39
+ function hasInternals(tokenizer) {
40
+ const value = tokenizer;
41
+ return !!value && value.patternRegex instanceof RegExp && value.patternRegex.global && typeof value.stringRankEncoder === "object" && value.stringRankEncoder !== null && Array.isArray(value.binaryFirstByteIndex);
42
+ }
43
+ var textEncoder = new TextEncoder;
44
+ var textDecoder = new TextDecoder("utf-8");
45
+ function isValidUtf8(bytes) {
46
+ let index = 0;
47
+ while (index < bytes.length) {
48
+ const first = bytes[index];
49
+ let size = 0;
50
+ let codePoint = 0;
51
+ if (first <= 127) {
52
+ size = 1;
53
+ codePoint = first;
54
+ } else if ((first & 224) === 192) {
55
+ size = 2;
56
+ codePoint = first & 31;
57
+ if (first <= 193)
58
+ return false;
59
+ } else if ((first & 240) === 224) {
60
+ size = 3;
61
+ codePoint = first & 15;
62
+ } else if ((first & 248) === 240) {
63
+ size = 4;
64
+ codePoint = first & 7;
65
+ if (first > 244)
66
+ return false;
67
+ } else
68
+ return false;
69
+ if (index + size > bytes.length)
70
+ return false;
71
+ for (let offset = 1;offset < size; offset += 1) {
72
+ const byte = bytes[index + offset];
73
+ if ((byte & 192) !== 128)
74
+ return false;
75
+ codePoint = codePoint << 6 | byte & 63;
76
+ }
77
+ if (size === 2 && codePoint < 128)
78
+ return false;
79
+ if (size === 3 && codePoint < 2048)
80
+ return false;
81
+ if (size === 4 && codePoint < 65536)
82
+ return false;
83
+ if (codePoint >= 55296 && codePoint <= 57343)
84
+ return false;
85
+ if (codePoint > 1114111)
86
+ return false;
87
+ index += size;
88
+ }
89
+ return true;
90
+ }
91
+ function binarySearchBytes(sorted, key) {
92
+ let low = 0;
93
+ let high = sorted.length - 1;
94
+ while (low <= high) {
95
+ const mid = low + high >>> 1;
96
+ const midKey = sorted[mid][0];
97
+ let compare = 0;
98
+ const shared = Math.min(midKey.length, key.length);
99
+ for (let index = 0;index < shared; index += 1) {
100
+ compare = midKey[index] - key[index];
101
+ if (compare !== 0)
102
+ break;
103
+ }
104
+ if (compare === 0)
105
+ compare = midKey.length - key.length;
106
+ if (compare === 0)
107
+ return sorted[mid][1];
108
+ if (compare < 0)
109
+ low = mid + 1;
110
+ else
111
+ high = mid - 1;
112
+ }
113
+ return -1;
114
+ }
115
+ function rankOf(tokenizer, slice) {
116
+ if (isValidUtf8(slice)) {
117
+ const rank = tokenizer.stringRankEncoder[textDecoder.decode(slice)];
118
+ if (rank !== undefined)
119
+ return rank;
120
+ }
121
+ const bucket = tokenizer.binaryFirstByteIndex[slice[0]];
122
+ if (bucket !== null && bucket !== undefined) {
123
+ const rank = binarySearchBytes(bucket, slice);
124
+ if (rank !== -1)
125
+ return rank;
126
+ }
127
+ return NO_RANK;
128
+ }
129
+ function mergeByScanning(tokenizer, bytes) {
130
+ const starts = [];
131
+ const ranks = [];
132
+ const pairRank = (index) => {
133
+ const end = starts[index + 2];
134
+ return end === undefined ? NO_RANK : rankOf(tokenizer, bytes.subarray(starts[index], end));
135
+ };
136
+ for (let index = 0;index <= bytes.length; index += 1)
137
+ starts.push(index);
138
+ for (let index = 0;index < starts.length; index += 1)
139
+ ranks.push(pairRank(index));
140
+ while (starts.length > 1) {
141
+ let minRank = NO_RANK;
142
+ let minIndex = -1;
143
+ for (let index = 0;index < ranks.length - 1; index += 1) {
144
+ if (ranks[index] < minRank) {
145
+ minRank = ranks[index];
146
+ minIndex = index;
147
+ }
148
+ }
149
+ if (minIndex === -1)
150
+ break;
151
+ starts.splice(minIndex + 1, 1);
152
+ ranks.splice(minIndex, 1);
153
+ ranks[minIndex] = pairRank(minIndex);
154
+ if (minIndex > 0)
155
+ ranks[minIndex - 1] = pairRank(minIndex - 1);
156
+ }
157
+ const tokens = [];
158
+ for (let index = 0;index < starts.length - 1; index += 1) {
159
+ const rank = rankOf(tokenizer, bytes.subarray(starts[index], starts[index + 1]));
160
+ if (rank !== NO_RANK)
161
+ tokens.push(rank);
162
+ }
163
+ return tokens;
164
+ }
165
+ function mergeWithHeap(tokenizer, bytes) {
166
+ const length = bytes.length;
167
+ const next = new Int32Array(length + 1);
168
+ const prev = new Int32Array(length + 1);
169
+ const alive = new Uint8Array(length + 1).fill(1);
170
+ const rank = new Float64Array(length + 1).fill(NO_RANK);
171
+ for (let index = 0;index <= length; index += 1) {
172
+ next[index] = index + 1;
173
+ prev[index] = index - 1;
174
+ }
175
+ const heapRank = [];
176
+ const heapAt = [];
177
+ const less = (a, b) => heapRank[a] < heapRank[b] || heapRank[a] === heapRank[b] && heapAt[a] < heapAt[b];
178
+ const swap = (a, b) => {
179
+ [heapRank[a], heapRank[b]] = [heapRank[b], heapRank[a]];
180
+ [heapAt[a], heapAt[b]] = [heapAt[b], heapAt[a]];
181
+ };
182
+ const push = (value, at) => {
183
+ heapRank.push(value);
184
+ heapAt.push(at);
185
+ let child = heapRank.length - 1;
186
+ while (child > 0) {
187
+ const parent = child - 1 >> 1;
188
+ if (!less(child, parent))
189
+ break;
190
+ swap(child, parent);
191
+ child = parent;
192
+ }
193
+ };
194
+ const pop = () => {
195
+ const last = heapRank.length - 1;
196
+ swap(0, last);
197
+ heapRank.pop();
198
+ heapAt.pop();
199
+ let parent = 0;
200
+ for (;; ) {
201
+ const left = parent * 2 + 1;
202
+ const right = left + 1;
203
+ let smallest = parent;
204
+ if (left < heapRank.length && less(left, smallest))
205
+ smallest = left;
206
+ if (right < heapRank.length && less(right, smallest))
207
+ smallest = right;
208
+ if (smallest === parent)
209
+ break;
210
+ swap(parent, smallest);
211
+ parent = smallest;
212
+ }
213
+ };
214
+ const pairRank = (at) => {
215
+ const middle = next[at];
216
+ if (middle >= length)
217
+ return NO_RANK;
218
+ return rankOf(tokenizer, bytes.subarray(at, next[middle]));
219
+ };
220
+ const update = (at) => {
221
+ rank[at] = pairRank(at);
222
+ if (rank[at] !== NO_RANK)
223
+ push(rank[at], at);
224
+ };
225
+ for (let at = 0;at < length; at += 1)
226
+ update(at);
227
+ while (heapRank.length > 0) {
228
+ const value = heapRank[0];
229
+ const at = heapAt[0];
230
+ pop();
231
+ if (!alive[at] || rank[at] !== value)
232
+ continue;
233
+ const removed = next[at];
234
+ alive[removed] = 0;
235
+ next[at] = next[removed];
236
+ prev[next[removed]] = at;
237
+ update(at);
238
+ if (at > 0)
239
+ update(prev[at]);
240
+ }
241
+ const tokens = [];
242
+ for (let at = 0;at < length; at = next[at]) {
243
+ const value = rankOf(tokenizer, bytes.subarray(at, next[at]));
244
+ if (value !== NO_RANK)
245
+ tokens.push(value);
246
+ }
247
+ return tokens;
248
+ }
249
+ var mergeCaches = new WeakMap;
250
+ var mergedPieces = 0;
251
+ function mergePiece(tokenizer, piece) {
252
+ let cache = mergeCaches.get(tokenizer);
253
+ if (!cache) {
254
+ cache = { current: new Map, previous: new Map };
255
+ mergeCaches.set(tokenizer, cache);
256
+ }
257
+ let tokens = cache.current.get(piece);
258
+ if (tokens)
259
+ return tokens;
260
+ tokens = cache.previous.get(piece);
261
+ if (!tokens) {
262
+ const bytes = textEncoder.encode(piece);
263
+ mergedPieces += 1;
264
+ tokens = bytes.length > LONG_PIECE_BYTES ? mergeWithHeap(tokenizer, bytes) : mergeByScanning(tokenizer, bytes);
265
+ }
266
+ if (cache.current.size >= MERGE_CACHE_GENERATION) {
267
+ cache.previous = cache.current;
268
+ cache.current = new Map;
269
+ }
270
+ cache.current.set(piece, tokens);
271
+ return tokens;
272
+ }
273
+ function encodeTokensExactly(tokenizer, text) {
274
+ if (!hasInternals(tokenizer)) {
275
+ return tokenizer.encode(text, "all");
276
+ }
277
+ if (text.length < 10) {
278
+ const direct = tokenizer.stringRankEncoder[text];
279
+ if (direct !== undefined)
280
+ return [direct];
281
+ }
282
+ const tokens = [];
283
+ const regex = tokenizer.patternRegex;
284
+ regex.lastIndex = 0;
285
+ for (let match = regex.exec(text);match !== null; match = regex.exec(text)) {
286
+ const piece = match[0];
287
+ const direct = tokenizer.stringRankEncoder[piece];
288
+ if (direct !== undefined) {
289
+ tokens.push(direct);
290
+ continue;
291
+ }
292
+ for (const token of mergePiece(tokenizer, piece))
293
+ tokens.push(token);
294
+ }
295
+ return tokens;
296
+ }
297
+ function countTokensExactly(tokenizer, text) {
298
+ return encodeTokensExactly(tokenizer, text).length;
299
+ }
300
+
35
301
  // ../plugin/src/hooks/magic-context/read-session-formatting.ts
36
302
  var MAX_COMMITS_PER_BLOCK = 5;
37
303
  function hasMeaningfulUserText2(parts) {
@@ -144,22 +410,30 @@ var tokenizerSerializedTableBytes;
144
410
  function tokenizerPackageRoots() {
145
411
  const cwd = process.cwd();
146
412
  const openCodeCache = join(process.env.XDG_CACHE_HOME ?? join(homedir(), ".cache"), "opencode");
147
- const roots = [cwd, openCodeCache];
148
413
  const candidates = [];
149
- for (const root of roots) {
414
+ const probeRoot = (root) => {
150
415
  for (const packageDir of TOKENIZER_PACKAGE_DIRS) {
151
416
  candidates.push(join(root, "node_modules", ...packageDir, "node_modules", "ai-tokenizer"));
152
417
  }
153
418
  candidates.push(join(root, "node_modules", "ai-tokenizer"));
419
+ };
420
+ for (const root of [cwd, openCodeCache]) {
421
+ probeRoot(root);
154
422
  }
155
- let ancestor = process.argv[1] ? dirname(resolve(process.argv[1])) : cwd;
156
- while (true) {
157
- candidates.push(join(ancestor, "node_modules", "ai-tokenizer"));
158
- const parent = dirname(ancestor);
159
- if (parent === ancestor)
160
- break;
161
- ancestor = parent;
162
- }
423
+ const pushAncestors = (startDir) => {
424
+ let ancestor = startDir;
425
+ while (true) {
426
+ candidates.push(join(ancestor, "node_modules", "ai-tokenizer"));
427
+ const parent = dirname(ancestor);
428
+ if (parent === ancestor)
429
+ break;
430
+ ancestor = parent;
431
+ }
432
+ };
433
+ pushAncestors(process.argv[1] ? dirname(resolve(process.argv[1])) : cwd);
434
+ const ownDir = dirname(fileURLToPath(new URL(import.meta.url)));
435
+ pushAncestors(ownDir);
436
+ probeRoot(join(homedir(), ".omp", "plugins"));
163
437
  return [...new Set(candidates)];
164
438
  }
165
439
  function packageImportTarget(value) {
@@ -222,7 +496,7 @@ function warnTokenizerFallback(error) {
222
496
  return;
223
497
  tokenizerWarningSent = true;
224
498
  const reason = error instanceof Error ? error.message : String(error);
225
- log("[magic-context] ai-tokenizer is unavailable; using approximate character-based token counts for this process. Token budgets, persisted per-message counts, and protected-tail/compartment boundaries may be less accurate until restart:", reason);
499
+ log2("[magic-context] ai-tokenizer is unavailable; using approximate character-based token counts for this process. Token budgets, persisted per-message counts, and protected-tail/compartment boundaries may be less accurate until restart:", reason);
226
500
  }
227
501
  async function preloadTokenizer() {
228
502
  if (tokenizer)
@@ -297,7 +571,7 @@ function estimateTokens(text) {
297
571
  if (!activeTokenizer)
298
572
  return estimateTokensHeuristically(text);
299
573
  try {
300
- return activeTokenizer.encode(text, "all").length;
574
+ return countTokensExactly(activeTokenizer, text);
301
575
  } catch (error) {
302
576
  tokenizer = undefined;
303
577
  tokenizerLoadAttempted = true;
@@ -287,19 +287,4 @@ function renderToolTemplate(source, input, output, legacyPreview = false) {
287
287
  return truncate(render(bareOutputNodes, root, legacyPreview), legacyPreview ? 1000 : undefined, legacyPreview);
288
288
  }
289
289
 
290
- // ../plugin/src/shared/protected-tools-policy.ts
291
- var DEFAULT_PROTECTED_TOOLS = {
292
- todowrite: 1,
293
- ctx_reduce: 3
294
- };
295
- function normalizeProtectedToolName(name) {
296
- return (name ?? "").toLowerCase().replace(/^mcp_/, "");
297
- }
298
- function mergeProtectedTools(...maps) {
299
- return Object.fromEntries([DEFAULT_PROTECTED_TOOLS, ...maps].flatMap((map) => Object.entries(map ?? {}).map(([name, count]) => [
300
- normalizeProtectedToolName(name),
301
- count
302
- ])));
303
- }
304
-
305
- export { canonicalModelIdentity, piModelRefToCanonical, resolveModelRefForPi, modelRefLookupOrder, ompModelRefToCanonical, resolveModelRefForOmp, toolTemplateError, renderToolTemplate, DEFAULT_PROTECTED_TOOLS, normalizeProtectedToolName, mergeProtectedTools };
290
+ export { canonicalModelIdentity, piModelRefToCanonical, resolveModelRefForPi, modelRefLookupOrder, ompModelRefToCanonical, resolveModelRefForOmp, toolTemplateError, renderToolTemplate };