@cortexkit/pi-magic-context 0.49.34 → 0.49.36
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 +163 -155
- package/dist/chunk-embedding-write-worker.js +71 -66
- package/dist/{compaction-marker-candidates-p1kqkqhq.js → compaction-marker-candidates-9fzqg6y0.js} +6 -3
- package/dist/compaction-marker-candidates-worker.js +24 -23
- package/dist/{compartment-chunk-embedding-8c85ebce.js → compartment-chunk-embedding-jpcme6tz.js} +11 -9
- package/dist/embedding-backfill-002vyexq.js +27 -0
- package/dist/embedding-worker-process.js +2 -1
- package/dist/embedding-worker.js +5 -4
- package/dist/expand-attachments-8sxeyj26.js +21 -0
- package/dist/historian-calibration-extension.js +2 -1
- package/dist/{index-hqw0rt9k.js → index-0wtm7g7f.js} +1 -1
- package/dist/{index-wqpjhx1p.js → index-2qqsnh1b.js} +2 -2
- package/dist/index-3bb24eb6.js +229 -0
- package/dist/{index-48twbev2.js → index-6pk49fc3.js} +37 -51
- package/dist/{index-399p688g.js → index-8sqebjzk.js} +4 -1
- package/dist/{index-np9ryr8y.js → index-a7sj2bam.js} +24 -241
- package/dist/index-by1bzjcd.js +24 -0
- package/dist/{index-6981g1xv.js → index-c1dqxr10.js} +35 -5
- package/dist/index-c6wbq66z.js +168 -0
- package/dist/{index-bvpar0bg.js → index-ck8wj35v.js} +2 -2
- package/dist/{index-jn44h81p.js → index-cq71g4dk.js} +1 -1
- package/dist/{index-pb3ea2tq.js → index-d107f484.js} +5 -5
- package/dist/{index-f4fz95fy.js → index-dgqjq8sg.js} +398 -4996
- package/dist/index-dnp1jjar.js +222 -0
- package/dist/index-ea37qn4x.js +777 -0
- package/dist/{index-g2tfayfc.js → index-f6y7mdq9.js} +98 -552
- package/dist/{index-0gymvr5j.js → index-f9qet7y8.js} +19 -8
- package/dist/index-gxqmh9hq.js +194 -0
- package/dist/{index-fgs78jyd.js → index-gymgz20n.js} +5 -222
- package/dist/index-hgd00nas.js +113 -0
- package/dist/{index-9xd7qveg.js → index-jbkwszd5.js} +4 -4
- package/dist/{index-e61zxfts.js → index-kj49vs41.js} +4 -4
- package/dist/{index-4zemngt7.js → index-mp0gh04g.js} +2 -2
- package/dist/{index-eenxm3t3.js → index-mx757f3g.js} +51 -32
- package/dist/{index-23t8ryqw.js → index-n0zjvs3h.js} +1 -168
- package/dist/index-nypgv96r.js +58 -0
- package/dist/index-p9jfa33t.js +4171 -0
- package/dist/{index-eqw9t2ty.js → index-pwp6zyx3.js} +15 -4
- package/dist/{index-cj3bkd16.js → index-ry84c8dr.js} +2 -2
- package/dist/{index-gwxaz0z5.js → index-rzfr7wdv.js} +2 -2
- package/dist/index-w26zvs1q.js +528 -0
- package/dist/index-wfqysrwq.js +204 -0
- package/dist/index-wrr9rp9a.js +16 -0
- package/dist/{index-my0dn413.js → index-wt7vmyj4.js} +1 -1
- package/dist/{index-0mc0vv97.js → index-wwsfevck.js} +8 -5
- package/dist/{index-54wmg4rj.js → index-x2n261wp.js} +16 -14
- package/dist/{index-6wdwv3a6.js → index-y90fxz4t.js} +10 -4
- package/dist/{index-c474g0gj.js → index-yacs388s.js} +1 -1
- package/dist/{index-xn5yh0pn.js → index-z7dktknj.js} +34 -131
- package/dist/index.js +1316 -488
- package/dist/{logger-shetp43v.js → logger-2j70hhz4.js} +2 -1
- package/dist/{message-fts-rowid-map-3mbvdgn9.js → message-fts-rowid-map-hmgyfxxa.js} +8 -6
- package/dist/{message-index-bounded-a6na71rg.js → message-index-bounded-82sergz7.js} +15 -12
- package/dist/{message-time-backfill-e3r8ddh1.js → message-time-backfill-x45573rs.js} +3 -2
- package/dist/migration-worker.js +56 -48
- package/dist/{project-embedding-registry-acqb6be4.js → project-embedding-registry-16pj4vyf.js} +16 -13
- package/dist/raw-ordinal-warmup-worker.js +114 -113
- package/dist/{read-session-chunk-2xcp6f40.js → read-session-chunk-jxq427v6.js} +17 -10
- package/dist/{read-session-raw-g9b1zdn5.js → read-session-raw-a9ntjqap.js} +6 -4
- package/dist/render-2wan3bfh.js +42 -0
- package/dist/{safe-notification-target-zcpchea6.js → safe-notification-target-jk69jxwp.js} +3 -2
- package/dist/search-3p18trsb.js +50 -0
- package/dist/search-archive-pgrv04gv.js +25 -0
- package/dist/{storage-tags-6409qq18.js → storage-tags-p9y3bnw7.js} +5 -4
- package/dist/store-reader-2m80zs5z.js +14 -0
- package/dist/store-v60q7dje.js +452 -0
- package/dist/subagent-entry.js +34 -25
- package/dist/tag-snapshot-worker-pi.js +218 -209
- package/dist/v2-archive-reader-5zpj8hrg.js +11 -0
- package/package.json +1 -1
- package/dist/embedding-backfill-rwfmyvze.js +0 -24
- package/dist/search-archive-jate39w5.js +0 -21
- package/dist/search-b6hp64hc.js +0 -45
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getTokenEstimatorFingerprint,
|
|
3
3
|
estimateTokens
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-wt7vmyj4.js";
|
|
5
5
|
import {
|
|
6
6
|
getHarness2
|
|
7
7
|
} from "./index-0h2mkab2.js";
|
|
8
8
|
import {
|
|
9
9
|
log2
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-gymgz20n.js";
|
|
11
11
|
import {
|
|
12
12
|
isSynapseEmbeddingTruncated
|
|
13
|
-
} from "./index-
|
|
13
|
+
} from "./index-rzfr7wdv.js";
|
|
14
14
|
import {
|
|
15
15
|
messageFtsOrdinalRangeIsMapped2
|
|
16
|
-
} from "./index-
|
|
16
|
+
} from "./index-ck8wj35v.js";
|
|
17
17
|
import {
|
|
18
18
|
isKnownAutocommit
|
|
19
19
|
} from "./index-nrzkqte4.js";
|
|
@@ -975,15 +975,26 @@ var unretainedSearchPools = new WeakMap;
|
|
|
975
975
|
function getLastCompartmentChunkPoolWarm2() {
|
|
976
976
|
return lastChunkPoolWarm;
|
|
977
977
|
}
|
|
978
|
-
function peekCompartmentChunkSearchPool2(db, sessionId, projectPath, modelId, dateRange = null) {
|
|
979
|
-
if (!modelId)
|
|
978
|
+
function peekCompartmentChunkSearchPool2(db, sessionId, projectPath, modelId, dateRange = null, diagnostic) {
|
|
979
|
+
if (!modelId) {
|
|
980
|
+
if (diagnostic)
|
|
981
|
+
diagnostic.peek = "no-model";
|
|
980
982
|
return null;
|
|
983
|
+
}
|
|
981
984
|
trackSearchPool(db, sessionId, projectPath, modelId);
|
|
982
985
|
const entry = getDecodedSearchPool(db).get(searchPoolKey(sessionId, projectPath, modelId));
|
|
983
|
-
if (!entry || searchPoolInTransaction(db))
|
|
986
|
+
if (!entry || searchPoolInTransaction(db)) {
|
|
987
|
+
if (diagnostic)
|
|
988
|
+
diagnostic.peek = entry ? "transaction" : "missing";
|
|
984
989
|
return null;
|
|
985
|
-
|
|
990
|
+
}
|
|
991
|
+
if (!sameSessionSignature(readSessionChunkSignature(db, sessionId), entry.sessionSignature)) {
|
|
992
|
+
if (diagnostic)
|
|
993
|
+
diagnostic.peek = "signature-changed";
|
|
986
994
|
return null;
|
|
995
|
+
}
|
|
996
|
+
if (diagnostic)
|
|
997
|
+
diagnostic.peek = "hit";
|
|
987
998
|
touchDecodedSearchPoolEntry(entry);
|
|
988
999
|
return filterSearchPoolDates(entry.rows, dateRange);
|
|
989
1000
|
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import {
|
|
2
|
+
registerExitAbort
|
|
3
|
+
} from "./index-8sqebjzk.js";
|
|
4
|
+
import {
|
|
5
|
+
inRootAsyncContext2
|
|
6
|
+
} from "./index-2qtx0q6h.js";
|
|
7
|
+
import {
|
|
8
|
+
createWorkerShutdown
|
|
9
|
+
} from "./index-x2n261wp.js";
|
|
10
|
+
|
|
11
|
+
// ../plugin/src/tools/ctx-expand/v2-archive-reader.ts
|
|
12
|
+
import { Worker } from "node:worker_threads";
|
|
13
|
+
var worker;
|
|
14
|
+
var shutdown;
|
|
15
|
+
var ready;
|
|
16
|
+
var idle;
|
|
17
|
+
var startingTimer;
|
|
18
|
+
var rejectStart;
|
|
19
|
+
var nextId = 0;
|
|
20
|
+
var exitRegistered = false;
|
|
21
|
+
var pending = new Map;
|
|
22
|
+
async function stopV2ArchiveReader() {
|
|
23
|
+
const closing = shutdown;
|
|
24
|
+
worker = undefined;
|
|
25
|
+
shutdown = undefined;
|
|
26
|
+
ready = undefined;
|
|
27
|
+
clearTimeout(idle);
|
|
28
|
+
clearTimeout(startingTimer);
|
|
29
|
+
rejectStart?.(new Error("Search archive worker unavailable: reader stopped"));
|
|
30
|
+
rejectStart = undefined;
|
|
31
|
+
for (const item of pending.values()) {
|
|
32
|
+
clearTimeout(item.timer);
|
|
33
|
+
item.reject(new Error("Search archive worker unavailable: reader stopped"));
|
|
34
|
+
}
|
|
35
|
+
pending.clear();
|
|
36
|
+
await closing?.close();
|
|
37
|
+
}
|
|
38
|
+
function start() {
|
|
39
|
+
if (ready)
|
|
40
|
+
return ready;
|
|
41
|
+
if (!exitRegistered) {
|
|
42
|
+
exitRegistered = true;
|
|
43
|
+
const controller = new AbortController;
|
|
44
|
+
controller.signal.addEventListener("abort", () => {
|
|
45
|
+
stopV2ArchiveReader();
|
|
46
|
+
}, { once: true });
|
|
47
|
+
registerExitAbort(controller);
|
|
48
|
+
}
|
|
49
|
+
ready = new Promise((resolve, reject) => {
|
|
50
|
+
rejectStart = reject;
|
|
51
|
+
const entry = new URL(import.meta.url.endsWith(".ts") ? "../../hooks/magic-context/raw-ordinal-warmup-worker.ts" : "./raw-ordinal-warmup-worker.js", import.meta.url);
|
|
52
|
+
const current = inRootAsyncContext2(() => new Worker(entry, { workerData: { v2ArchiveReader: true } }));
|
|
53
|
+
worker = current;
|
|
54
|
+
shutdown = createWorkerShutdown(current, "v2-archive-reader", 2000);
|
|
55
|
+
current.unref();
|
|
56
|
+
const fail = (detail) => {
|
|
57
|
+
if (worker !== current)
|
|
58
|
+
return;
|
|
59
|
+
clearTimeout(startingTimer);
|
|
60
|
+
reject(new Error(`Search archive worker unavailable: ${detail}`));
|
|
61
|
+
stopV2ArchiveReader();
|
|
62
|
+
};
|
|
63
|
+
startingTimer = setTimeout(() => fail("reader did not start"), 1e4);
|
|
64
|
+
startingTimer.unref?.();
|
|
65
|
+
current.on("error", (error) => fail(String(error)));
|
|
66
|
+
current.on("exit", (code) => fail(`exit code ${code}`));
|
|
67
|
+
current.on("message", (reply) => {
|
|
68
|
+
if (worker !== current)
|
|
69
|
+
return;
|
|
70
|
+
if (reply.kind === "v2-archive-ready") {
|
|
71
|
+
clearTimeout(startingTimer);
|
|
72
|
+
rejectStart = undefined;
|
|
73
|
+
resolve();
|
|
74
|
+
} else if (reply.kind === "v2-archive-result") {
|
|
75
|
+
const item = pending.get(reply.id);
|
|
76
|
+
if (!item)
|
|
77
|
+
return;
|
|
78
|
+
pending.delete(reply.id);
|
|
79
|
+
clearTimeout(item.timer);
|
|
80
|
+
if (reply.error)
|
|
81
|
+
item.reject(new Error(`Search archive worker unavailable: ${reply.error}`));
|
|
82
|
+
else
|
|
83
|
+
item.resolve(reply.text);
|
|
84
|
+
if (pending.size === 0) {
|
|
85
|
+
idle = setTimeout(() => {
|
|
86
|
+
stopV2ArchiveReader();
|
|
87
|
+
}, 60000);
|
|
88
|
+
idle.unref?.();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
return ready;
|
|
94
|
+
}
|
|
95
|
+
async function readV2ArchiveOffThread2(path, rawPath, sessionId, read) {
|
|
96
|
+
try {
|
|
97
|
+
clearTimeout(idle);
|
|
98
|
+
await start();
|
|
99
|
+
const current = worker;
|
|
100
|
+
if (!current)
|
|
101
|
+
throw new Error("Search archive worker unavailable: reader stopped");
|
|
102
|
+
return await new Promise((resolve, reject) => {
|
|
103
|
+
const id = ++nextId;
|
|
104
|
+
const timer = setTimeout(() => {
|
|
105
|
+
stopV2ArchiveReader();
|
|
106
|
+
}, 10 * 60000);
|
|
107
|
+
timer.unref?.();
|
|
108
|
+
pending.set(id, { resolve, reject, timer });
|
|
109
|
+
try {
|
|
110
|
+
current.postMessage({
|
|
111
|
+
kind: "v2-archive-read",
|
|
112
|
+
id,
|
|
113
|
+
path,
|
|
114
|
+
rawPath,
|
|
115
|
+
sessionId,
|
|
116
|
+
read
|
|
117
|
+
});
|
|
118
|
+
} catch {
|
|
119
|
+
stopV2ArchiveReader();
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
} catch (error) {
|
|
123
|
+
await stopV2ArchiveReader();
|
|
124
|
+
if (error instanceof Error && error.message.startsWith("Search archive worker unavailable:"))
|
|
125
|
+
throw error;
|
|
126
|
+
throw new Error(`Search archive worker unavailable: ${String(error)}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async function serveV2ArchiveReads2(port, openConnections) {
|
|
130
|
+
const [
|
|
131
|
+
{ Database },
|
|
132
|
+
{ V2StoreReaderPool },
|
|
133
|
+
{ createV2RawMessageReader, createV2RawMessageProvider },
|
|
134
|
+
{ setBoundedRawMessageProvider },
|
|
135
|
+
{ renderItemByTag, renderMessageByOrdinal, renderVerboseRangeForTool },
|
|
136
|
+
{ renderSearchArchive },
|
|
137
|
+
{ createV2RecoveryAttachments }
|
|
138
|
+
] = await Promise.all([
|
|
139
|
+
import("./sqlite-v89bj0yy.js"),
|
|
140
|
+
import("./store-reader-2m80zs5z.js"),
|
|
141
|
+
import("./store-v60q7dje.js"),
|
|
142
|
+
import("./read-session-chunk-jxq427v6.js"),
|
|
143
|
+
import("./render-2wan3bfh.js"),
|
|
144
|
+
import("./search-archive-pgrv04gv.js"),
|
|
145
|
+
import("./expand-attachments-8sxeyj26.js")
|
|
146
|
+
]);
|
|
147
|
+
const pool = new V2StoreReaderPool;
|
|
148
|
+
openConnections.add(pool);
|
|
149
|
+
port.on("message", (request) => {
|
|
150
|
+
if (request.kind !== "v2-archive-read")
|
|
151
|
+
return;
|
|
152
|
+
let db;
|
|
153
|
+
let unregister;
|
|
154
|
+
let rawReader;
|
|
155
|
+
let reply;
|
|
156
|
+
try {
|
|
157
|
+
db = new Database(request.path, { readonly: true, fileMustExist: true });
|
|
158
|
+
openConnections.add(db);
|
|
159
|
+
db.exec("PRAGMA busy_timeout = 250");
|
|
160
|
+
const raw = pool.open(request.rawPath);
|
|
161
|
+
rawReader = raw;
|
|
162
|
+
const reader = createV2RawMessageReader(() => raw, undefined, () => {});
|
|
163
|
+
const attachments = createV2RecoveryAttachments(raw);
|
|
164
|
+
unregister = setBoundedRawMessageProvider(request.sessionId, createV2RawMessageProvider(reader, request.sessionId));
|
|
165
|
+
const read = request.read;
|
|
166
|
+
let text;
|
|
167
|
+
if (read.kind === "tag") {
|
|
168
|
+
text = renderItemByTag(db, request.sessionId, read.tag, "part", attachments);
|
|
169
|
+
} else {
|
|
170
|
+
const start = read.kind === "message" ? read.message : read.start;
|
|
171
|
+
const end = read.kind === "message" ? read.message : read.end;
|
|
172
|
+
text = renderSearchArchive(db, request.sessionId, start, end, read.tokenBudget, read.kind === "archive" && read.archiveOnly, () => reader.ordinalMapForRange(request.sessionId, start, end));
|
|
173
|
+
if (text === null && read.kind === "message") {
|
|
174
|
+
text = renderMessageByOrdinal(request.sessionId, read.message, attachments);
|
|
175
|
+
} else if (text === null && read.kind === "verbose") {
|
|
176
|
+
text = renderVerboseRangeForTool(request.sessionId, start, end, read.tokenBudget, read.expandTools, attachments);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
reply = { kind: "v2-archive-result", id: request.id, text };
|
|
180
|
+
} catch (error) {
|
|
181
|
+
reply = { kind: "v2-archive-result", id: request.id, text: null, error: String(error) };
|
|
182
|
+
} finally {
|
|
183
|
+
unregister?.();
|
|
184
|
+
rawReader?.close();
|
|
185
|
+
if (db)
|
|
186
|
+
openConnections.delete(db);
|
|
187
|
+
db?.close();
|
|
188
|
+
}
|
|
189
|
+
port.postMessage(reply);
|
|
190
|
+
});
|
|
191
|
+
port.postMessage({ kind: "v2-archive-ready" });
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export { readV2ArchiveOffThread2, serveV2ArchiveReads2 };
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getHarness2
|
|
3
3
|
} from "./index-0h2mkab2.js";
|
|
4
|
+
import {
|
|
5
|
+
sanitizeDiagnosticText,
|
|
6
|
+
sanitizeConfigValue
|
|
7
|
+
} from "./index-dnp1jjar.js";
|
|
4
8
|
|
|
5
9
|
// ../plugin/src/shared/logger.ts
|
|
6
10
|
import * as fs from "node:fs";
|
|
@@ -147,227 +151,6 @@ function getLegacyOpenCodeMagicContextStorageDir() {
|
|
|
147
151
|
return path.join(getOpenCodeStorageDir(), "plugin", "magic-context");
|
|
148
152
|
}
|
|
149
153
|
|
|
150
|
-
// ../plugin/src/shared/redaction.ts
|
|
151
|
-
import { homedir as homedir2, userInfo } from "node:os";
|
|
152
|
-
function escapeRegex(value) {
|
|
153
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
154
|
-
}
|
|
155
|
-
var SECRET_WORDS = [
|
|
156
|
-
"key",
|
|
157
|
-
"token",
|
|
158
|
-
"secret",
|
|
159
|
-
"password",
|
|
160
|
-
"auth",
|
|
161
|
-
"authorization",
|
|
162
|
-
"bearer",
|
|
163
|
-
"credential"
|
|
164
|
-
];
|
|
165
|
-
var SECRET_SEGMENT_PATTERN = new RegExp(`^(?:${SECRET_WORDS.map((w) => `${w}s?`).join("|")})$`, "i");
|
|
166
|
-
var TRAILING_DESCRIPTORS = new Set(["id", "ids", "value", "values", "header", "headers"]);
|
|
167
|
-
function redactionTypeForKey(key) {
|
|
168
|
-
const normalized = key.trim().toLowerCase().replace(/[^a-z0-9_.-]+/g, "_");
|
|
169
|
-
const suffix = normalized.split(".").filter(Boolean).at(-1) ?? normalized;
|
|
170
|
-
return suffix || "secret";
|
|
171
|
-
}
|
|
172
|
-
function isNonSecretScalarValue(value) {
|
|
173
|
-
const v = value.trim();
|
|
174
|
-
if (v === "true" || v === "false" || v === "null" || v === "undefined")
|
|
175
|
-
return true;
|
|
176
|
-
return /^[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?$/.test(v);
|
|
177
|
-
}
|
|
178
|
-
var SECRET_QUALIFIERS = new Set([
|
|
179
|
-
"api",
|
|
180
|
-
"access",
|
|
181
|
-
"private",
|
|
182
|
-
"client",
|
|
183
|
-
"auth",
|
|
184
|
-
"authorization",
|
|
185
|
-
"secret",
|
|
186
|
-
"bearer",
|
|
187
|
-
"session",
|
|
188
|
-
"refresh",
|
|
189
|
-
"service",
|
|
190
|
-
"x",
|
|
191
|
-
"openai",
|
|
192
|
-
"anthropic",
|
|
193
|
-
"google",
|
|
194
|
-
"github",
|
|
195
|
-
"huggingface",
|
|
196
|
-
"aws",
|
|
197
|
-
"azure",
|
|
198
|
-
"id"
|
|
199
|
-
]);
|
|
200
|
-
var UNQUALIFIED_SECRET_SEGMENT_PATTERN = /^(?:password|secret|credential|bearer|authorization)s?$/;
|
|
201
|
-
function isSecretKey(key) {
|
|
202
|
-
const segments = key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase().split(/[._-]+/).filter(Boolean);
|
|
203
|
-
if (segments.length === 0)
|
|
204
|
-
return false;
|
|
205
|
-
if (segments.length === 1) {
|
|
206
|
-
const first = segments[0];
|
|
207
|
-
return Boolean(first && SECRET_SEGMENT_PATTERN.test(first));
|
|
208
|
-
}
|
|
209
|
-
for (let i = 0;i < segments.length; i++) {
|
|
210
|
-
const seg = segments[i];
|
|
211
|
-
if (!seg || !SECRET_SEGMENT_PATTERN.test(seg))
|
|
212
|
-
continue;
|
|
213
|
-
let trailingOk = true;
|
|
214
|
-
for (let j = i + 1;j < segments.length; j++) {
|
|
215
|
-
const tail = segments[j];
|
|
216
|
-
if (!tail)
|
|
217
|
-
continue;
|
|
218
|
-
if (TRAILING_DESCRIPTORS.has(tail))
|
|
219
|
-
continue;
|
|
220
|
-
if (SECRET_SEGMENT_PATTERN.test(tail))
|
|
221
|
-
continue;
|
|
222
|
-
trailingOk = false;
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
if (!trailingOk)
|
|
226
|
-
continue;
|
|
227
|
-
if (UNQUALIFIED_SECRET_SEGMENT_PATTERN.test(seg))
|
|
228
|
-
return true;
|
|
229
|
-
for (let k = i - 1;k >= 0; k--) {
|
|
230
|
-
const lead = segments[k];
|
|
231
|
-
if (lead && SECRET_QUALIFIERS.has(lead))
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
function sanitizePathString(value) {
|
|
238
|
-
const home = process.env.HOME || process.env.USERPROFILE || homedir2();
|
|
239
|
-
const username = userInfo().username;
|
|
240
|
-
let sanitized = value;
|
|
241
|
-
if (home) {
|
|
242
|
-
sanitized = sanitized.replace(new RegExp(escapeRegex(home), "g"), "~");
|
|
243
|
-
}
|
|
244
|
-
sanitized = sanitized.replace(/\/Users\/[^/]+\//g, "/Users/<USER>/");
|
|
245
|
-
sanitized = sanitized.replace(/\/home\/[^/]+\//g, "/home/<USER>/");
|
|
246
|
-
sanitized = sanitized.replace(/C:\\Users\\[^\\]+\\/g, "C:\\Users\\<USER>\\");
|
|
247
|
-
if (username) {
|
|
248
|
-
sanitized = sanitized.replace(new RegExp(escapeRegex(username), "g"), "<USER>");
|
|
249
|
-
}
|
|
250
|
-
return sanitized;
|
|
251
|
-
}
|
|
252
|
-
var SECRET_TEXT_PATTERNS = [
|
|
253
|
-
{
|
|
254
|
-
pattern: /\bsk-ant-(?:api03-)?[A-Za-z0-9_-]{32,}/g,
|
|
255
|
-
replacement: "<ANTHROPIC_API_KEY_REDACTED>"
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
pattern: /\bsk-(?:proj-)?[A-Za-z0-9_-]{12,}/g,
|
|
259
|
-
replacement: "<OPENAI_API_KEY_REDACTED>"
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
pattern: /\bgithub_pat_[A-Za-z0-9_]{20,}/g,
|
|
263
|
-
replacement: "<GITHUB_PAT_REDACTED>"
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
pattern: /\b(?:gh[opsu]|ghr)_[A-Za-z0-9_-]{30,}/g,
|
|
267
|
-
replacement: "<GITHUB_TOKEN_REDACTED>"
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
pattern: /\bhf_[A-Za-z0-9]{30,}/g,
|
|
271
|
-
replacement: "<HUGGINGFACE_TOKEN_REDACTED>"
|
|
272
|
-
},
|
|
273
|
-
{
|
|
274
|
-
pattern: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
|
|
275
|
-
replacement: "<AWS_ACCESS_KEY_ID_REDACTED>"
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
pattern: /\bxox[abprsuvc]-[A-Za-z0-9-]{10,}/g,
|
|
279
|
-
replacement: "<SLACK_TOKEN_REDACTED>"
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
pattern: /\bAIza[A-Za-z0-9_-]{35}\b/g,
|
|
283
|
-
replacement: "<GOOGLE_API_KEY_REDACTED>"
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
pattern: /\b(Authorization\s*:\s*Bearer\s+)([A-Za-z0-9._~+/=-]{8,})/gi,
|
|
287
|
-
replacement: (_full, prefix) => `${prefix}<REDACTED:bearer>`
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
pattern: /\b((?:Proxy-)?Authorization\s*:\s*(?:Basic|Digest|Token|Negotiate|NTLM)\s+)([A-Za-z0-9._~+/=-]{4,})/gi,
|
|
291
|
-
replacement: (_full, prefix) => `${prefix}<REDACTED:authorization>`
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
pattern: /\b((?:x-)?(?:api-?key|api-?token|auth-?token|access-?token)\s*:\s*)([^\s'"`,;<>]{6,})/gi,
|
|
295
|
-
replacement: (full, prefix, value) => isNonSecretScalarValue(value) ? full : `${prefix}<REDACTED:api_key>`
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
pattern: /\b((?:api[_-]?key|client[_-]?secret|access[_-]?token|token|secret|password|passwd|pwd)\s*:\s*)([^\s'"`,;<>]{6,})/gi,
|
|
299
|
-
replacement: (full, prefix, value) => isNonSecretScalarValue(value) ? full : `${prefix}<REDACTED:credential>`
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
pattern: /\b([a-z][a-z0-9+.-]*:\/\/[^\s/:@]+:)([^\s/@]+)(@)/gi,
|
|
303
|
-
replacement: (_full, prefix, _password, at) => `${prefix}<REDACTED:password>${at}`
|
|
304
|
-
},
|
|
305
|
-
{
|
|
306
|
-
pattern: /\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g,
|
|
307
|
-
replacement: "<JWT_REDACTED>"
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
pattern: /(["'])([^"']*(?:key|token|secret|password|auth|bearer|credential)[^"']*)\1(\s*:\s*)(["'])([^"']*)\4/gi,
|
|
311
|
-
replacement: (full, quote, key, separator, valueQuote, value) => isNonSecretScalarValue(value) ? full : `${quote}${key}${quote}${separator}${valueQuote}<REDACTED:${redactionTypeForKey(key)}>${valueQuote}`
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
pattern: /\b([A-Za-z0-9_.-]*(?:key|token|secret|password|auth|bearer|credential)[A-Za-z0-9_.-]*)\s*=\s*([^\s'"`]+)/gi,
|
|
315
|
-
replacement: (full, key, value) => isNonSecretScalarValue(value) ? full : `${key}=<REDACTED:${redactionTypeForKey(key)}>`
|
|
316
|
-
}
|
|
317
|
-
];
|
|
318
|
-
function redactSecretText(value) {
|
|
319
|
-
let redacted = value;
|
|
320
|
-
for (const { pattern, replacement } of SECRET_TEXT_PATTERNS) {
|
|
321
|
-
if (typeof replacement === "string") {
|
|
322
|
-
redacted = redacted.replace(pattern, replacement);
|
|
323
|
-
} else {
|
|
324
|
-
redacted = redacted.replace(pattern, replacement);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
return redacted;
|
|
328
|
-
}
|
|
329
|
-
function sanitizeDiagnosticText(value) {
|
|
330
|
-
return redactSecretText(sanitizePathString(value));
|
|
331
|
-
}
|
|
332
|
-
var SHAREABILITY_SENSITIVE_PATTERNS = [
|
|
333
|
-
/\bC:\/Users\/[^/\s]+/i,
|
|
334
|
-
/(?:^|\s)~\/[^\s]+/,
|
|
335
|
-
/\b(?:api[_-]?key|secret|token|password|passwd|pwd|client[_-]?secret|access[_-]?key)\b\s*[:=]\s*\S+/i,
|
|
336
|
-
/\b(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(?::\d+)?\b/i,
|
|
337
|
-
/\b(?:10|127)\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/,
|
|
338
|
-
/\b192\.168\.\d{1,3}\.\d{1,3}\b/,
|
|
339
|
-
/\b172\.(?:1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}\b/
|
|
340
|
-
];
|
|
341
|
-
function hasShareabilitySensitiveText(text) {
|
|
342
|
-
try {
|
|
343
|
-
if (sanitizeDiagnosticText(text) !== text)
|
|
344
|
-
return true;
|
|
345
|
-
return SHAREABILITY_SENSITIVE_PATTERNS.some((pattern) => pattern.test(text));
|
|
346
|
-
} catch {
|
|
347
|
-
return true;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
function sanitizeConfigValue(value, keyPath = []) {
|
|
351
|
-
if (value === null || typeof value === "number" || typeof value === "boolean")
|
|
352
|
-
return value;
|
|
353
|
-
const key = keyPath.at(-1) ?? "";
|
|
354
|
-
if (key && isSecretKey(key)) {
|
|
355
|
-
return `<REDACTED:${redactionTypeForKey(key)}>`;
|
|
356
|
-
}
|
|
357
|
-
if (typeof value === "string")
|
|
358
|
-
return sanitizeDiagnosticText(value);
|
|
359
|
-
if (Array.isArray(value)) {
|
|
360
|
-
return value.map((entry, index) => sanitizeConfigValue(entry, [...keyPath, String(index)]));
|
|
361
|
-
}
|
|
362
|
-
if (value && typeof value === "object") {
|
|
363
|
-
return Object.fromEntries(Object.entries(value).map(([entryKey, entry]) => [
|
|
364
|
-
entryKey,
|
|
365
|
-
sanitizeConfigValue(entry, [...keyPath, entryKey])
|
|
366
|
-
]));
|
|
367
|
-
}
|
|
368
|
-
return value;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
154
|
// ../plugin/src/shared/stale-plugin-build.ts
|
|
372
155
|
import { posix } from "node:path";
|
|
373
156
|
import { fileURLToPath } from "node:url";
|
|
@@ -696,4 +479,4 @@ if (!isTestEnv) {
|
|
|
696
479
|
process.on("exit", flush);
|
|
697
480
|
}
|
|
698
481
|
|
|
699
|
-
export { getDataDir, ensureCortexKitArtifactGitignore, getProjectMagicContextHistorianDir, getMagicContextStorageDir, isMagicContextStorageOutsideEngram, claimStorageBackupWarningCheck, getLegacyOpenCodeMagicContextStorageDir,
|
|
482
|
+
export { getDataDir, ensureCortexKitArtifactGitignore, getProjectMagicContextHistorianDir, getMagicContextStorageDir, isMagicContextStorageOutsideEngram, claimStorageBackupWarningCheck, getLegacyOpenCodeMagicContextStorageDir, registerStalePluginBuildHost, classifyStalePluginBuild, importPluginModule, setLogLineForwarder2, writeForwardedLogLine2, log2, sessionLog2, getLoggerDiagnostics2, flushLogger2, getLogFilePath2 };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withSqliteBackgroundWriter2,
|
|
3
|
+
withoutSqliteTransformPass2,
|
|
4
|
+
isTransientSqliteError2
|
|
5
|
+
} from "./index-2qtx0q6h.js";
|
|
6
|
+
|
|
7
|
+
// ../plugin/src/hooks/magic-context/embed-session-state.ts
|
|
8
|
+
var embedPauseBySession = new Set;
|
|
9
|
+
var embedRunStateBySession = new Map;
|
|
10
|
+
var activeEmbeddingSessions = new Map;
|
|
11
|
+
var autoEmbedAttemptedBySession = new Set;
|
|
12
|
+
var autoEmbedIdentityBySession = new Map;
|
|
13
|
+
var autoEmbedRetryAfterBySession = new Map;
|
|
14
|
+
function invalidateAutoEmbedSession(sessionId) {
|
|
15
|
+
autoEmbedAttemptedBySession.delete(sessionId);
|
|
16
|
+
autoEmbedIdentityBySession.delete(sessionId);
|
|
17
|
+
autoEmbedRetryAfterBySession.delete(sessionId);
|
|
18
|
+
}
|
|
19
|
+
function getEmbedDrainUiStatus(sessionId, progress) {
|
|
20
|
+
if (embedPauseBySession.has(sessionId)) {
|
|
21
|
+
return { status: "paused" };
|
|
22
|
+
}
|
|
23
|
+
const activeRun = embedRunStateBySession.get(sessionId);
|
|
24
|
+
if (activeRun && !activeRun.signal.aborted || progress?.kind === "embed" && progress.phase === "recomp") {
|
|
25
|
+
return { status: "running" };
|
|
26
|
+
}
|
|
27
|
+
if (progress?.kind === "embed" && (progress.phase === "failed" || progress.phase === "skipped") && progress.message) {
|
|
28
|
+
if (/provider/i.test(progress.message)) {
|
|
29
|
+
return { status: "stopped", detail: progress.message };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return { status: "idle" };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ../plugin/src/shared/background-batch-drain.ts
|
|
36
|
+
async function drainBackgroundBatches(step, options = {}) {
|
|
37
|
+
const now = options.now ?? (() => performance.now());
|
|
38
|
+
const deadline = now() + (options.budgetMs ?? 2000);
|
|
39
|
+
const yieldFn = options.yieldFn ?? (() => new Promise((resolve) => setTimeout(resolve, 0)));
|
|
40
|
+
let batches = 0;
|
|
41
|
+
while (now() < deadline) {
|
|
42
|
+
try {
|
|
43
|
+
if (!withoutSqliteTransformPass2(() => withSqliteBackgroundWriter2(step)))
|
|
44
|
+
break;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
if (isTransientSqliteError2(error))
|
|
47
|
+
break;
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
batches++;
|
|
51
|
+
await yieldFn();
|
|
52
|
+
}
|
|
53
|
+
return batches;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ../plugin/src/features/magic-context/storage-embedding-measurements.ts
|
|
57
|
+
import { createHash } from "node:crypto";
|
|
58
|
+
function normalizedQueryHash(query) {
|
|
59
|
+
const normalized = query.trim().replace(/\s+/g, " ").toLowerCase();
|
|
60
|
+
return createHash("sha256").update(normalized).digest("hex");
|
|
61
|
+
}
|
|
62
|
+
var MEASUREMENT_CORPUS_SESSION_ROW_CAP = 2000;
|
|
63
|
+
function recordEmbeddingMeasurement(db, input, cap = MEASUREMENT_CORPUS_SESSION_ROW_CAP) {
|
|
64
|
+
const queryTextHash = normalizedQueryHash(input.queryText);
|
|
65
|
+
const dedupKey = queryTextHash;
|
|
66
|
+
const result = db.prepare(`INSERT OR IGNORE INTO embedding_measurement_corpus
|
|
67
|
+
(session_id, project_path, dedup_key, cohort_key, query_text_hash,
|
|
68
|
+
primary_result_ids_json, shadow_result_ids_json, primary_latency_ms, shadow_latency_ms,
|
|
69
|
+
primary_failed, shadow_failed, primary_model_id, shadow_model_id,
|
|
70
|
+
primary_fingerprint, shadow_fingerprint, primary_epoch, shadow_epoch,
|
|
71
|
+
corpus_hash, coverage_json, created_at)
|
|
72
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(input.sessionId, input.projectPath, dedupKey, input.cohortKey, queryTextHash, JSON.stringify(input.primaryResultIds.slice(0, 10)), JSON.stringify(input.shadowResultIds.slice(0, 10)), input.primaryLatencyMs, input.shadowLatencyMs, input.primaryFailed ? 1 : 0, input.shadowFailed ? 1 : 0, input.primaryModelId, input.shadowModelId, input.primaryFingerprint, input.shadowFingerprint, input.primaryEpoch, input.shadowEpoch, input.corpusHash, JSON.stringify(input.coverage), Date.now());
|
|
73
|
+
if (result.changes > 0) {
|
|
74
|
+
const rowCount = db.prepare("SELECT COUNT(*) AS count FROM embedding_measurement_corpus WHERE session_id = ?").get(input.sessionId).count;
|
|
75
|
+
const overflow = rowCount - cap;
|
|
76
|
+
if (overflow > 0) {
|
|
77
|
+
db.prepare(`DELETE FROM embedding_measurement_corpus
|
|
78
|
+
WHERE session_id = ?
|
|
79
|
+
AND id IN (
|
|
80
|
+
SELECT id FROM embedding_measurement_corpus
|
|
81
|
+
WHERE session_id = ?
|
|
82
|
+
ORDER BY id ASC
|
|
83
|
+
LIMIT ?
|
|
84
|
+
)`).run(input.sessionId, input.sessionId, overflow);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result.changes > 0;
|
|
88
|
+
}
|
|
89
|
+
function beginSynapseBatchLedger(db, input, now = Date.now()) {
|
|
90
|
+
db.prepare(`INSERT INTO synapse_batch_ledger
|
|
91
|
+
(session_id, project_path, scope, manifest_json, request_key, status, created_at, updated_at)
|
|
92
|
+
VALUES (?, ?, ?, ?, ?, 'pending', ?, ?)
|
|
93
|
+
ON CONFLICT(session_id, request_key) DO UPDATE SET
|
|
94
|
+
manifest_json = excluded.manifest_json,
|
|
95
|
+
updated_at = excluded.updated_at`).run(input.sessionId, input.projectPath, input.scope, JSON.stringify(input.manifest), input.requestKey, now, now);
|
|
96
|
+
}
|
|
97
|
+
function finishSynapseBatchLedger(db, sessionId, requestKey, status, now = Date.now()) {
|
|
98
|
+
db.prepare("UPDATE synapse_batch_ledger SET status = ?, updated_at = ? WHERE session_id = ? AND request_key = ?").run(status, now, sessionId, requestKey);
|
|
99
|
+
}
|
|
100
|
+
var SYNAPSE_BATCH_LEDGER_TTL_MS = 14 * 24 * 60 * 60 * 1000;
|
|
101
|
+
function pruneSynapseBatchLedgerForProject(db, projectIdentity, ttlMs = SYNAPSE_BATCH_LEDGER_TTL_MS) {
|
|
102
|
+
const ledgerTable = db.prepare("SELECT 1 AS present FROM sqlite_master WHERE type = 'table' AND name = 'synapse_batch_ledger'").get();
|
|
103
|
+
if (!ledgerTable)
|
|
104
|
+
return 0;
|
|
105
|
+
const shadow = `shadow:${projectIdentity}`;
|
|
106
|
+
const cutoff = Date.now() - ttlMs;
|
|
107
|
+
const predicate = "session_id IN (?, ?) AND updated_at < ?";
|
|
108
|
+
if (!db.prepare(`SELECT 1 FROM synapse_batch_ledger WHERE ${predicate} LIMIT 1`).get(projectIdentity, shadow, cutoff))
|
|
109
|
+
return 0;
|
|
110
|
+
return db.prepare(`DELETE FROM synapse_batch_ledger WHERE ${predicate}`).run(projectIdentity, shadow, cutoff).changes;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { embedPauseBySession, embedRunStateBySession, activeEmbeddingSessions, autoEmbedAttemptedBySession, autoEmbedIdentityBySession, autoEmbedRetryAfterBySession, invalidateAutoEmbedSession, getEmbedDrainUiStatus, drainBackgroundBatches, recordEmbeddingMeasurement, beginSynapseBatchLedger, finishSynapseBatchLedger, pruneSynapseBatchLedgerForProject };
|
|
@@ -3,19 +3,19 @@ import {
|
|
|
3
3
|
} from "./index-ccanzg8p.js";
|
|
4
4
|
import {
|
|
5
5
|
log2
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-gymgz20n.js";
|
|
7
7
|
import {
|
|
8
8
|
isSynapseEmbeddingTruncated,
|
|
9
9
|
SynapseEmbeddingProvider
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-rzfr7wdv.js";
|
|
11
11
|
import {
|
|
12
12
|
LocalEmbeddingProvider
|
|
13
|
-
} from "./index-
|
|
13
|
+
} from "./index-2qqsnh1b.js";
|
|
14
14
|
import {
|
|
15
15
|
OpenAICompatibleEmbeddingProvider,
|
|
16
16
|
getProjectEmbeddingSnapshot2,
|
|
17
17
|
embedBatchForProject2
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-z7dktknj.js";
|
|
19
19
|
import {
|
|
20
20
|
isEmbeddingHostBusy2
|
|
21
21
|
} from "./index-9p40dgkm.js";
|
|
@@ -6,19 +6,19 @@ import {
|
|
|
6
6
|
removeNestedBlocks,
|
|
7
7
|
hasMeaningfulUserText2,
|
|
8
8
|
extractTexts2
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-wt7vmyj4.js";
|
|
10
10
|
import {
|
|
11
11
|
cleanUserText2
|
|
12
|
-
} from "./index-
|
|
12
|
+
} from "./index-mx757f3g.js";
|
|
13
13
|
import {
|
|
14
14
|
recordMessageFtsRowid2,
|
|
15
15
|
recordIndexedMessageTime2,
|
|
16
16
|
messageFtsOrdinalRangeIsMapped2,
|
|
17
17
|
deleteUnmappedMessageFtsRows2
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-ck8wj35v.js";
|
|
19
19
|
import {
|
|
20
20
|
logSlowWriteTransaction
|
|
21
|
-
} from "./index-
|
|
21
|
+
} from "./index-0wtm7g7f.js";
|
|
22
22
|
|
|
23
23
|
// ../plugin/src/features/magic-context/compression-depth-storage.ts
|
|
24
24
|
var incrementDepthStatements = new WeakMap;
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
} from "./index-0h2mkab2.js";
|
|
4
4
|
import {
|
|
5
5
|
isUserHomeDirectory
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-6pk49fc3.js";
|
|
7
7
|
import {
|
|
8
8
|
logSlowWriteTransaction
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-0wtm7g7f.js";
|
|
10
10
|
|
|
11
11
|
// ../plugin/src/features/magic-context/session-project-storage.ts
|
|
12
12
|
var SESSION_CHUNK_REPAIR_BATCH_SIZE = 100;
|