@cortexkit/pi-magic-context 0.46.1 → 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.
- package/dist/auto-search-worker.js +112 -0
- package/dist/embedding-activity-ew6dshfd.js +10 -0
- package/dist/embedding-backfill-bnnytehy.js +20 -0
- package/dist/embedding-cache-7rp4gqzr.js +16 -0
- package/dist/embedding-worker.js +11 -8
- package/dist/harness-9872e0ym.js +10 -0
- package/dist/historian-calibration-extension.js +3 -2
- package/dist/index-0am8a7k1.js +152 -0
- package/dist/index-0h2mkab2.js +17 -0
- package/dist/index-135e8hvg.js +43 -0
- package/dist/{index-wv28nczk.js → index-3cgbv47m.js} +354 -38
- package/dist/index-419bndtm.js +2309 -0
- package/dist/index-544c0e0x.js +3026 -0
- package/dist/index-5hd7h4rr.js +3098 -0
- package/dist/index-5jp1h0bz.js +750 -0
- package/dist/index-603mt6nm.js +171 -0
- package/dist/index-674f6qs2.js +16 -0
- package/dist/{index-r01b1b78.js → index-6pgq5ns2.js} +157 -2454
- package/dist/index-72bdc1bd.js +3591 -0
- package/dist/index-8976mezv.js +209 -0
- package/dist/{index-td885aah.js → index-8y5knskr.js} +98 -231
- package/dist/{index-ykb8kkm3.js → index-98z1c1r0.js} +14599 -22287
- package/dist/index-9p40dgkm.js +22 -0
- package/dist/index-9x1f96r8.js +11 -0
- package/dist/{index-266qrgss.js → index-9xb0axhc.js} +301 -27
- package/dist/{index-phh7e055.js → index-bgmv2kaf.js} +28 -28
- package/dist/index-dkx0b1kt.js +514 -0
- package/dist/{index-7n8gb6j3.js → index-f956htf3.js} +28 -31
- package/dist/index-fapenpch.js +13 -0
- package/dist/index-fm3ksh5e.js +1060 -0
- package/dist/{index-2p1e8706.js → index-fp37he9a.js} +3 -3
- package/dist/index-hrf13mn3.js +2388 -0
- package/dist/index-pvm4pd5d.js +3069 -0
- package/dist/index-r7xg4hvw.js +3480 -0
- package/dist/index-rt5jgzp1.js +1127 -0
- package/dist/{index-n3g5mwa8.js → index-wrm4nbj7.js} +3 -3
- package/dist/index-xjqheg7a.js +931 -0
- package/dist/index-yhzhdp3m.js +143 -0
- package/dist/{index-w76x3af7.js → index-zrr5t5a7.js} +1 -3
- package/dist/index.js +6345 -2585
- package/dist/logger-v3dsxdnm.js +19 -0
- package/dist/message-index-bounded-t7vvty76.js +120 -0
- package/dist/{message-time-backfill-4688z1k2.js → message-time-backfill-4ndf7hrq.js} +7 -6
- package/dist/migration-worker.js +24 -16
- package/dist/project-embedding-registry-jy2hmq28.js +85 -0
- package/dist/raw-ordinal-warmup-worker.js +60 -0
- package/dist/{read-session-chunk-tc6yn2pe.js → read-session-chunk-47pjn7fz.js} +12 -6
- package/dist/read-session-raw-yn8nawav.js +55 -0
- package/dist/{safe-notification-target-6cn3z99t.js → safe-notification-target-3c1ns931.js} +3 -2
- package/dist/search-42szfhwp.js +40 -0
- package/dist/sqlite-3yye76ht.js +44 -0
- package/dist/sqlite-context-pragmas-gcgch6qz.js +6 -0
- package/dist/storage-memory-1z20y55x.js +71 -0
- package/dist/storage-tags-jym5z6yk.js +127 -0
- package/dist/subagent-entry.js +36 -16
- package/dist/transformers-node-wasm.js +18415 -18415
- package/package.json +3 -3
- package/dist/index-4vfrjwf6.js +0 -7737
- package/dist/index-xvw8zptx.js +0 -5123
- /package/dist/{index-901ekbga.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
|
-
|
|
3
|
-
} from "./index-
|
|
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
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
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
|
|
574
|
+
return countTokensExactly(activeTokenizer, text);
|
|
301
575
|
} catch (error) {
|
|
302
576
|
tokenizer = undefined;
|
|
303
577
|
tokenizerLoadAttempted = true;
|
|
@@ -138,7 +138,7 @@ class Parser {
|
|
|
138
138
|
} else
|
|
139
139
|
break;
|
|
140
140
|
}
|
|
141
|
-
const expression = { steps
|
|
141
|
+
const expression = { steps };
|
|
142
142
|
if (this.take(".each(")) {
|
|
143
143
|
if (relative)
|
|
144
144
|
return this.error();
|
|
@@ -205,9 +205,23 @@ function compiled(source) {
|
|
|
205
205
|
function oneLine(value) {
|
|
206
206
|
return value.replace(/[\r\n\u2028\u2029]+/g, " ");
|
|
207
207
|
}
|
|
208
|
-
function truncate(value, cap) {
|
|
208
|
+
function truncate(value, cap, legacyPreview = false) {
|
|
209
209
|
const chars = Array.from(oneLine(value));
|
|
210
|
-
|
|
210
|
+
if (cap === undefined || chars.length <= cap)
|
|
211
|
+
return chars.join("");
|
|
212
|
+
if (legacyPreview)
|
|
213
|
+
return `${chars.slice(0, cap).join("")}…`;
|
|
214
|
+
let end = 0;
|
|
215
|
+
for (let i = 0;i < Math.min(cap, chars.length); i++) {
|
|
216
|
+
if (!".!?。!?".includes(chars[i]))
|
|
217
|
+
continue;
|
|
218
|
+
let next = i + 1;
|
|
219
|
+
while (next < chars.length && `"'”’)]`.includes(chars[next]))
|
|
220
|
+
next++;
|
|
221
|
+
if (next <= cap && ("。!?".includes(chars[i]) || next === chars.length || /[ \t]/.test(chars[next])))
|
|
222
|
+
end = next;
|
|
223
|
+
}
|
|
224
|
+
return `${end ? `${chars.slice(0, end).join("")} ` : ""}[… ${chars.length - end} more characters]`;
|
|
211
225
|
}
|
|
212
226
|
function scalar(value) {
|
|
213
227
|
if (value === undefined)
|
|
@@ -224,10 +238,11 @@ function compactJson(value) {
|
|
|
224
238
|
function field(value, key) {
|
|
225
239
|
return value !== null && typeof value === "object" && !Array.isArray(value) && Object.hasOwn(value, key) ? value[key] : undefined;
|
|
226
240
|
}
|
|
227
|
-
function render(nodes, root) {
|
|
241
|
+
function render(nodes, root, legacyPreview) {
|
|
228
242
|
return nodes.map((node) => {
|
|
229
243
|
if (typeof node === "string")
|
|
230
244
|
return node;
|
|
245
|
+
const cap = node.cap ?? (legacyPreview ? 300 : undefined);
|
|
231
246
|
let value = root;
|
|
232
247
|
let list = false;
|
|
233
248
|
for (const step of node.steps) {
|
|
@@ -241,19 +256,19 @@ function render(nodes, root) {
|
|
|
241
256
|
}
|
|
242
257
|
}
|
|
243
258
|
if (node.count)
|
|
244
|
-
return truncate(Array.isArray(value) ? String(value.length) : "",
|
|
259
|
+
return truncate(Array.isArray(value) ? String(value.length) : "", cap, legacyPreview);
|
|
245
260
|
if (node.each || list || node.join !== undefined) {
|
|
246
261
|
if (!Array.isArray(value))
|
|
247
262
|
return "";
|
|
248
|
-
const elements = value.slice(0, 10).map((item) => truncate(node.each ? render(node.each, item) : scalar(item), 300));
|
|
249
|
-
if (value.length > 10)
|
|
263
|
+
const elements = value.slice(0, legacyPreview ? 10 : undefined).map((item) => truncate(node.each ? render(node.each, item, legacyPreview) : scalar(item), legacyPreview ? 300 : undefined, legacyPreview));
|
|
264
|
+
if (legacyPreview && value.length > 10)
|
|
250
265
|
elements.push(`… +${value.length - 10} more`);
|
|
251
|
-
return truncate(elements.join(node.join ?? (node.each ? "; " : ", ")),
|
|
266
|
+
return truncate(elements.join(node.join ?? (node.each ? "; " : ", ")), cap, legacyPreview);
|
|
252
267
|
}
|
|
253
|
-
return truncate(scalar(value),
|
|
268
|
+
return truncate(scalar(value), cap, legacyPreview);
|
|
254
269
|
}).join("");
|
|
255
270
|
}
|
|
256
|
-
function renderToolTemplate(source, input, output) {
|
|
271
|
+
function renderToolTemplate(source, input, output, legacyPreview = false) {
|
|
257
272
|
const nodes = compiled(source);
|
|
258
273
|
if (!nodes)
|
|
259
274
|
return null;
|
|
@@ -268,23 +283,8 @@ function renderToolTemplate(source, input, output) {
|
|
|
268
283
|
}
|
|
269
284
|
}
|
|
270
285
|
const root = { input, output: structured };
|
|
271
|
-
const bareOutputNodes = nodes.map((node) => typeof node !== "string" && node.steps.length === 1 && ("field" in node.steps[0]) && node.steps[0].field === "output" && !node.each && !node.count && node.join === undefined ? truncate(text ?? "", node.cap) : node);
|
|
272
|
-
return truncate(render(bareOutputNodes, root), 1000);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// ../plugin/src/shared/protected-tools-policy.ts
|
|
276
|
-
var DEFAULT_PROTECTED_TOOLS = {
|
|
277
|
-
todowrite: 1,
|
|
278
|
-
ctx_reduce: 3
|
|
279
|
-
};
|
|
280
|
-
function normalizeProtectedToolName(name) {
|
|
281
|
-
return (name ?? "").toLowerCase().replace(/^mcp_/, "");
|
|
282
|
-
}
|
|
283
|
-
function mergeProtectedTools(...maps) {
|
|
284
|
-
return Object.fromEntries([DEFAULT_PROTECTED_TOOLS, ...maps].flatMap((map) => Object.entries(map ?? {}).map(([name, count]) => [
|
|
285
|
-
normalizeProtectedToolName(name),
|
|
286
|
-
count
|
|
287
|
-
])));
|
|
286
|
+
const bareOutputNodes = nodes.map((node) => typeof node !== "string" && node.steps.length === 1 && ("field" in node.steps[0]) && node.steps[0].field === "output" && !node.each && !node.count && node.join === undefined ? truncate(text ?? "", node.cap ?? (legacyPreview ? 300 : undefined), legacyPreview) : node);
|
|
287
|
+
return truncate(render(bareOutputNodes, root, legacyPreview), legacyPreview ? 1000 : undefined, legacyPreview);
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
export { canonicalModelIdentity, piModelRefToCanonical, resolveModelRefForPi, modelRefLookupOrder, ompModelRefToCanonical, resolveModelRefForOmp, toolTemplateError, renderToolTemplate
|
|
290
|
+
export { canonicalModelIdentity, piModelRefToCanonical, resolveModelRefForPi, modelRefLookupOrder, ompModelRefToCanonical, resolveModelRefForOmp, toolTemplateError, renderToolTemplate };
|