@cortexkit/opencode-magic-context 0.49.84 → 0.49.86
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/{announcement-p41dde4h.js → announcement-fnyxaahs.js} +3 -1
- package/dist/auto-search-worker.js +3 -3
- package/dist/chunk-embedding-write-worker.js +5 -4
- package/dist/{context-3sajdysh.js → context-xesm7rj3.js} +27 -26
- package/dist/{derive-budgets-0kcek5ex.js → derive-budgets-90869322.js} +3 -1
- package/dist/{embedding-backfill-k994xdas.js → embedding-backfill-v6sw58m8.js} +7 -5
- package/dist/embedding-worker.js +15 -27
- package/dist/features/magic-context/memory/embedding-worker-boundary.test-support.d.ts +24 -0
- package/dist/features/magic-context/memory/embedding-worker-boundary.test-support.d.ts.map +1 -0
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts +35 -1
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-worker-loop.d.ts +57 -0
- package/dist/features/magic-context/memory/embedding-worker-loop.d.ts.map +1 -0
- package/dist/features/magic-context/memory/verification-paths.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts +6 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -1
- package/dist/{index-xjfan0za.js → index-022w6314.js} +37 -37
- package/dist/{index-tvbkemec.js → index-08jfpny9.js} +1 -1
- package/dist/{index-fgy6hnr3.js → index-1bqkqde0.js} +5 -4
- package/dist/{index-0wehkw71.js → index-1pf5qrx4.js} +4 -4
- package/dist/{index-tqnvn9pa.js → index-25nktq8n.js} +3 -3
- package/dist/{index-98qy103c.js → index-2kf73btc.js} +1 -1
- package/dist/{index-vpw46557.js → index-3dtzyred.js} +1 -1
- package/dist/{index-bd34njzg.js → index-4ntnt8ee.js} +1 -1
- package/dist/{index-w2wpx7t5.js → index-4w5rx7de.js} +1 -1
- package/dist/{index-xd0ww0ns.js → index-798s7c8s.js} +1 -1
- package/dist/{index-fpqdbb67.js → index-7svecf3m.js} +3 -3
- package/dist/{v2/server-fvnzcnww.js → index-c5tmzym6.js} +192 -11
- package/dist/{index-k0jnsjcp.js → index-d0rtbv0f.js} +6 -6
- package/dist/{index-qybp04ff.js → index-e32b3x4n.js} +3 -3
- package/dist/{index-cfy5k1pa.js → index-gxdc95cp.js} +5 -5
- package/dist/{index-w8dcjt7f.js → index-k0tb2z28.js} +1 -1
- package/dist/{index-zb4h9nrk.js → index-k50xhjw1.js} +202 -14
- package/dist/{index-szwrpyac.js → index-nny4gm06.js} +1 -1
- package/dist/{index-shpyv8gq.js → index-s8ks5nz4.js} +16 -9
- package/dist/{index-d028gmgp.js → index-ttk3trse.js} +14 -14
- package/dist/{index-skwwbcnv.js → index-w6v4dw5f.js} +24 -24
- package/dist/{index-5wjv4c41.js → index-xccywqdj.js} +15 -15
- package/dist/{index-kthfyf45.js → index-zmqx48vt.js} +3 -3
- package/dist/index.js +33 -33
- package/dist/migration-worker.js +4 -3
- package/dist/{project-embedding-registry-y3z36mjy.js → project-embedding-registry-q80scexh.js} +6 -4
- package/dist/raw-ordinal-warmup-worker.js +2 -2
- package/dist/{recomp-orchestrator-m2s3jpvj.js → recomp-orchestrator-7ecg8ryx.js} +16 -15
- package/dist/{render-p2j7rn9a.js → render-yqp7q79f.js} +8 -7
- package/dist/{search-archive-hz9xh7nh.js → search-archive-r4h96j2z.js} +2 -2
- package/dist/{search-ksx0f1qd.js → search-bw22d7zc.js} +12 -10
- package/dist/shared/storage-file-mutex.d.ts.map +1 -1
- package/dist/shared/storage-permissions.d.ts +5 -3
- package/dist/shared/storage-permissions.d.ts.map +1 -1
- package/dist/{store-x0swqb5c.js → store-n4yz3n66.js} +2 -2
- package/dist/{store-reader-tsv1w4vt.js → store-reader-nf8z86n9.js} +1 -1
- package/dist/{transform-postprocess-phase-1wb2rrr1.js → transform-postprocess-phase-t99yj9vt.js} +17 -16
- package/dist/v2/auto-search-worker.js +3 -3
- package/dist/v2/chunk-embedding-write-worker.js +5 -4
- package/dist/v2/{context-at9nje0j.js → context-k8sx1nyy.js} +39 -39
- package/dist/v2/{derive-budgets-xbwcap8k.js → derive-budgets-ecjy1aqh.js} +4 -2
- package/dist/v2/{embedding-backfill-hjvjxp7d.js → embedding-backfill-k8kqnwfq.js} +7 -5
- package/dist/v2/embedding-worker.js +15 -27
- package/dist/v2/migration-worker.js +4 -3
- package/dist/v2/{project-embedding-registry-mzsvyads.js → project-embedding-registry-2jp1antr.js} +6 -4
- package/dist/v2/raw-ordinal-warmup-worker.js +2 -2
- package/dist/v2/{recomp-orchestrator-nhef90gc.js → recomp-orchestrator-ssde9ft1.js} +17 -16
- package/dist/v2/{render-c9r2g2jv.js → render-fezgh7pa.js} +8 -7
- package/dist/v2/{search-archive-80ckv9kq.js → search-archive-zz1kza50.js} +2 -2
- package/dist/v2/{search-t06js5dc.js → search-m251amra.js} +11 -9
- package/dist/v2/{server-4z964n1c.js → server-3p6b0qya.js} +1 -1
- package/dist/v2/{server-3cndh146.js → server-4wwwm2ya.js} +24 -24
- package/dist/v2/{server-mr9rqn0y.js → server-97w51d8n.js} +4 -4
- package/dist/v2/{server-d706s5xn.js → server-b93f0bqh.js} +205 -17
- package/dist/v2/{server-dfesqfv1.js → server-brgandk4.js} +1 -1
- package/dist/v2/{server-w1jfaxas.js → server-cwtehwbb.js} +1 -1
- package/dist/v2/{server-y4favn4d.js → server-e2k9mt86.js} +1 -1
- package/dist/v2/{server-3hhakg5a.js → server-fsw8kbng.js} +13 -13
- package/dist/v2/{server-68q80y27.js → server-hn8b7sfe.js} +16 -9
- package/dist/v2/{server-pejjj0nv.js → server-mbkwcwgw.js} +1 -1
- package/dist/v2/{server-ry6rpspz.js → server-n5zr7190.js} +15 -15
- package/dist/v2/{server-210rc0z9.js → server-ps6rz88g.js} +1 -1
- package/dist/{index-fvnzcnww.js → v2/server-r2es6zt7.js} +192 -11
- package/dist/v2/{server-bt546axy.js → server-rz4snd3x.js} +3 -3
- package/dist/v2/{server-863bwkga.js → server-ssg29wjg.js} +6 -6
- package/dist/v2/{server-hhw6rzsn.js → server-w7mpvkpj.js} +1 -1
- package/dist/v2/{server-sy98vksf.js → server-xa8fefhw.js} +3 -3
- package/dist/v2/{server-gx1s06dx.js → server-y31y6gws.js} +5 -4
- package/dist/v2/{server-cce6m31c.js → server-ytqps2xa.js} +1 -1
- package/dist/v2/server.js +6 -4
- package/dist/v2/{store-reader-paamf0ac.js → store-reader-2vhx33n6.js} +1 -1
- package/dist/v2/{store-h3s95ywe.js → store-y56y034s.js} +2 -2
- package/dist/v2/{v2-archive-reader-1zzteaa5.js → v2-archive-reader-e2w39c3p.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-9y98qcqz.js → wrapup-orchestrator-eg5b1p89.js} +16 -15
- package/dist/{v2-archive-reader-3yjxaj5z.js → v2-archive-reader-8dsngf2j.js} +1 -1
- package/dist/{wrapup-orchestrator-sa3a075a.js → wrapup-orchestrator-nmk6yf7f.js} +17 -16
- package/package.json +1 -1
- package/src/shared/storage-file-mutex-review.test.ts +125 -2
- package/src/shared/storage-file-mutex.ts +17 -8
- package/src/shared/storage-permissions-creators.test.ts +194 -0
- package/src/shared/storage-permissions-startup.test.ts +476 -0
- package/src/shared/storage-permissions.ts +227 -12
- package/src/tui/compaction-off.ts +2 -2
- package/src/tui/slots/sidebar-content-render.test.ts +309 -0
- package/src/tui/slots/sidebar-content.tsx +134 -99
- package/src/tui-compiled/compaction-off.ts +2 -2
- package/src/tui-compiled/slots/sidebar-content.tsx +321 -247
- /package/dist/{index-rdh63md0.js → index-1y4y98r1.js} +0 -0
- /package/dist/v2/{server-9nk5h6w6.js → server-qyazxy92.js} +0 -0
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
enqueueShadowEmbeddingItems2,
|
|
39
39
|
getProjectEmbeddingSnapshot2,
|
|
40
40
|
embedItemsForProject2
|
|
41
|
-
} from "./index-
|
|
41
|
+
} from "./index-s8ks5nz4.js";
|
|
42
42
|
import {
|
|
43
43
|
recordEmbeddingMeasurement
|
|
44
44
|
} from "./index-2amn2s73.js";
|
|
@@ -54,7 +54,7 @@ import {
|
|
|
54
54
|
sanitizeFtsQuery,
|
|
55
55
|
searchMemoriesFTS,
|
|
56
56
|
searchMemoriesFTSUnion
|
|
57
|
-
} from "./index-
|
|
57
|
+
} from "./index-1bqkqde0.js";
|
|
58
58
|
import {
|
|
59
59
|
ModuleMemoryAuthorityError2,
|
|
60
60
|
getMemoriesByProject2,
|
|
@@ -71,10 +71,10 @@ import {
|
|
|
71
71
|
withMemoryHintContent,
|
|
72
72
|
autoSearchRelevance,
|
|
73
73
|
recordAutoSearchLane
|
|
74
|
-
} from "./index-
|
|
74
|
+
} from "./index-798s7c8s.js";
|
|
75
75
|
import {
|
|
76
76
|
ensureMemoryEmbeddings2
|
|
77
|
-
} from "./index-
|
|
77
|
+
} from "./index-k0tb2z28.js";
|
|
78
78
|
import {
|
|
79
79
|
MESSAGE_FTS_SESSION_FILTER_SQL,
|
|
80
80
|
withMessageFtsSessionFilter
|
|
@@ -88,11 +88,11 @@ import {
|
|
|
88
88
|
expandWorkspaceIdentitySetWithAliases,
|
|
89
89
|
resolveStoredPathWorkspaceIdentity,
|
|
90
90
|
sourceNameForMemory
|
|
91
|
-
} from "./index-
|
|
91
|
+
} from "./index-4w5rx7de.js";
|
|
92
92
|
import {
|
|
93
93
|
getNotes,
|
|
94
94
|
getActivePrimers
|
|
95
|
-
} from "./index-
|
|
95
|
+
} from "./index-4ntnt8ee.js";
|
|
96
96
|
import {
|
|
97
97
|
isKnownAutocommit
|
|
98
98
|
} from "./index-8ajstryz.js";
|
|
@@ -7,14 +7,14 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
requestPendingMaterialization,
|
|
9
9
|
dropSlot
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-w6v4dw5f.js";
|
|
11
11
|
import {
|
|
12
12
|
executeContextRecomp
|
|
13
|
-
} from "./index-
|
|
13
|
+
} from "./index-ttk3trse.js";
|
|
14
14
|
import {
|
|
15
15
|
renderUserFacingFailure,
|
|
16
16
|
userFacingFailureCode
|
|
17
|
-
} from "./index-
|
|
17
|
+
} from "./index-1bqkqde0.js";
|
|
18
18
|
|
|
19
19
|
// src/hooks/magic-context/recomp-orchestrator.ts
|
|
20
20
|
function resolveLiveModelKey(liveSessionState, sessionId) {
|
|
@@ -225,7 +225,7 @@ import {
|
|
|
225
225
|
saveSourceContent,
|
|
226
226
|
replaceSourceContent,
|
|
227
227
|
getSourceContents
|
|
228
|
-
} from "./index-
|
|
228
|
+
} from "./index-w6v4dw5f.js";
|
|
229
229
|
import {
|
|
230
230
|
cleanSearchText,
|
|
231
231
|
matchedSearchSnippet
|
|
@@ -234,18 +234,18 @@ import {
|
|
|
234
234
|
getProjectEmbeddingSnapshot2,
|
|
235
235
|
embedTextForProject2,
|
|
236
236
|
embedBatchForProject2
|
|
237
|
-
} from "./index-
|
|
237
|
+
} from "./index-s8ks5nz4.js";
|
|
238
238
|
import {
|
|
239
239
|
isEmbeddingHostBusy2
|
|
240
240
|
} from "./index-qt1qqasc.js";
|
|
241
241
|
import {
|
|
242
242
|
userFacingFailureCode
|
|
243
|
-
} from "./index-
|
|
243
|
+
} from "./index-1bqkqde0.js";
|
|
244
244
|
import {
|
|
245
245
|
getMessageIndexEpoch,
|
|
246
246
|
isMessageIndexSearchable,
|
|
247
247
|
createAutoSearchDiagnostics
|
|
248
|
-
} from "./index-
|
|
248
|
+
} from "./index-798s7c8s.js";
|
|
249
249
|
import {
|
|
250
250
|
openCodeDbExists,
|
|
251
251
|
withReadOnlySessionDb,
|
|
@@ -285,7 +285,7 @@ import {
|
|
|
285
285
|
peekNoteNudgeText,
|
|
286
286
|
markNoteNudgeDelivered,
|
|
287
287
|
getActiveCompartmentRun
|
|
288
|
-
} from "./index-
|
|
288
|
+
} from "./index-ttk3trse.js";
|
|
289
289
|
import {
|
|
290
290
|
getErrorMessage
|
|
291
291
|
} from "./index-y8v6yerm.js";
|
|
@@ -10,21 +10,22 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
getMagicContextStorageDir,
|
|
12
12
|
importPluginModule,
|
|
13
|
-
log2
|
|
13
|
+
log2,
|
|
14
|
+
flushLogger2
|
|
14
15
|
} from "./index-ywrz4wy2.js";
|
|
15
16
|
import {
|
|
16
17
|
inRootAsyncContext2
|
|
17
18
|
} from "./index-gzy5w8ya.js";
|
|
18
|
-
import {
|
|
19
|
-
computeNormalizedHash
|
|
20
|
-
} from "./index-2bvekkfy.js";
|
|
21
19
|
import {
|
|
22
20
|
shouldEnforcePrivateStoragePermissions,
|
|
23
21
|
ensureStorageDirectorySync,
|
|
24
22
|
writeStorageFileAsync,
|
|
25
23
|
writeStorageFileHandleAsync,
|
|
26
24
|
createStorageFileHandleAsync
|
|
27
|
-
} from "./index-
|
|
25
|
+
} from "./index-c5tmzym6.js";
|
|
26
|
+
import {
|
|
27
|
+
computeNormalizedHash
|
|
28
|
+
} from "./index-2bvekkfy.js";
|
|
28
29
|
|
|
29
30
|
// src/features/magic-context/memory/embedding-model-match.ts
|
|
30
31
|
function parseEmbeddingModel(model) {
|
|
@@ -675,6 +676,80 @@ function dominantEmbeddingFailure(failures) {
|
|
|
675
676
|
import { fork } from "node:child_process";
|
|
676
677
|
import { Worker } from "node:worker_threads";
|
|
677
678
|
|
|
679
|
+
// src/features/magic-context/memory/embedding-worker-loop.ts
|
|
680
|
+
var EMBEDDING_WORKER_STOPPING_ERROR = "embedding worker stopping";
|
|
681
|
+
function isEmbeddingWorkerStopNotice(message) {
|
|
682
|
+
return typeof message === "object" && message !== null && "control" in message && (message.control === "stopping" || message.control === "stopped");
|
|
683
|
+
}
|
|
684
|
+
function serveEmbeddingWorker(port, model, options) {
|
|
685
|
+
const now = options.now ?? (() => performance.now());
|
|
686
|
+
let queue = Promise.resolve();
|
|
687
|
+
let stopping = false;
|
|
688
|
+
let busySince = null;
|
|
689
|
+
const refuse = (id) => port.postMessage({ id, loaded: false, error: EMBEDDING_WORKER_STOPPING_ERROR });
|
|
690
|
+
const handle = async (request) => {
|
|
691
|
+
if (stopping)
|
|
692
|
+
return refuse(request.id);
|
|
693
|
+
busySince = now();
|
|
694
|
+
try {
|
|
695
|
+
const loaded = await model.initialize();
|
|
696
|
+
let vectors;
|
|
697
|
+
if (loaded && request.texts) {
|
|
698
|
+
vectors = [];
|
|
699
|
+
for (let offset = 0;offset < request.texts.length; offset += options.batchSize) {
|
|
700
|
+
if (offset > 0)
|
|
701
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
702
|
+
if (stopping)
|
|
703
|
+
throw new Error(EMBEDDING_WORKER_STOPPING_ERROR);
|
|
704
|
+
vectors.push(...await model.embedBatch(request.texts.slice(offset, offset + options.batchSize)));
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
port.postMessage({
|
|
708
|
+
id: request.id,
|
|
709
|
+
loaded,
|
|
710
|
+
vectors,
|
|
711
|
+
failure: model.getLastFailureReason(),
|
|
712
|
+
stats: options.stats?.()
|
|
713
|
+
}, vectors?.flatMap((vector) => vector ? [vector.buffer] : []) ?? []);
|
|
714
|
+
} catch (error) {
|
|
715
|
+
port.postMessage({ id: request.id, loaded: false, error: String(error) });
|
|
716
|
+
} finally {
|
|
717
|
+
busySince = null;
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
const stop = async () => {
|
|
721
|
+
stopping = true;
|
|
722
|
+
const requestedAt = now();
|
|
723
|
+
const busy = busySince !== null;
|
|
724
|
+
port.postMessage({
|
|
725
|
+
control: "stopping",
|
|
726
|
+
busy,
|
|
727
|
+
busyMs: busySince === null ? 0 : requestedAt - busySince
|
|
728
|
+
});
|
|
729
|
+
await queue;
|
|
730
|
+
try {
|
|
731
|
+
await model.dispose();
|
|
732
|
+
} catch {}
|
|
733
|
+
port.postMessage({
|
|
734
|
+
control: "stopped",
|
|
735
|
+
busy,
|
|
736
|
+
waitedMs: now() - requestedAt
|
|
737
|
+
});
|
|
738
|
+
options.exit();
|
|
739
|
+
};
|
|
740
|
+
port.on("message", (message) => {
|
|
741
|
+
if (message?.stop === true) {
|
|
742
|
+
if (!stopping)
|
|
743
|
+
stop();
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
const request = message;
|
|
747
|
+
if (stopping)
|
|
748
|
+
return refuse(request.id);
|
|
749
|
+
queue = queue.then(() => handle(request));
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
|
|
678
753
|
// src/features/magic-context/memory/onnx-telemetry.ts
|
|
679
754
|
import { isMainThread } from "node:worker_threads";
|
|
680
755
|
var FFI_SPECIFIER = "bun:ffi";
|
|
@@ -721,6 +796,41 @@ async function prepareNativeOnnxTelemetry() {
|
|
|
721
796
|
|
|
722
797
|
// src/features/magic-context/memory/embedding-worker-client.ts
|
|
723
798
|
var warnedWindowsTelemetry = false;
|
|
799
|
+
var EMBEDDING_WORKER_STOP_GRACE_MS = 5000;
|
|
800
|
+
var EMBEDDING_WORKER_FORCED_EXIT_WAIT_MS = 2000;
|
|
801
|
+
var EMBEDDING_WORKER_SIGKILL_WAIT_MS = 200;
|
|
802
|
+
var EMBEDDING_WORKER_STOP_MAX_MS = EMBEDDING_WORKER_STOP_GRACE_MS + EMBEDDING_WORKER_FORCED_EXIT_WAIT_MS + EMBEDDING_WORKER_SIGKILL_WAIT_MS;
|
|
803
|
+
function busySince(state) {
|
|
804
|
+
let oldest = null;
|
|
805
|
+
for (const sentAt of state.dispatched.values()) {
|
|
806
|
+
if (oldest === null || sentAt < oldest)
|
|
807
|
+
oldest = sentAt;
|
|
808
|
+
}
|
|
809
|
+
return oldest;
|
|
810
|
+
}
|
|
811
|
+
async function exitsWithin(exit, ms) {
|
|
812
|
+
let timer;
|
|
813
|
+
try {
|
|
814
|
+
return await Promise.race([
|
|
815
|
+
exit.then(() => true),
|
|
816
|
+
new Promise((resolve) => {
|
|
817
|
+
timer = setTimeout(() => resolve(false), ms);
|
|
818
|
+
})
|
|
819
|
+
]);
|
|
820
|
+
} finally {
|
|
821
|
+
clearTimeout(timer);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
function describeRunning(since, at) {
|
|
825
|
+
return since === null ? "no" : `yes (for ${Math.max(0, Math.round(at - since))}ms)`;
|
|
826
|
+
}
|
|
827
|
+
function describeStuckWorker(state, stopSince) {
|
|
828
|
+
const notice = state.stopNotice;
|
|
829
|
+
const at = performance.now();
|
|
830
|
+
if (notice)
|
|
831
|
+
return describeRunning(notice.busy ? notice.receivedAt - notice.busyMs : null, at);
|
|
832
|
+
return `${describeRunning(stopSince, at)}, no answer to the stop request`;
|
|
833
|
+
}
|
|
724
834
|
|
|
725
835
|
class EmbeddingWorkerClient {
|
|
726
836
|
data;
|
|
@@ -728,19 +838,23 @@ class EmbeddingWorkerClient {
|
|
|
728
838
|
timeoutMs;
|
|
729
839
|
prepareTelemetry;
|
|
730
840
|
idleMs;
|
|
841
|
+
options;
|
|
731
842
|
worker = null;
|
|
732
843
|
startPromise = null;
|
|
844
|
+
states = new WeakMap;
|
|
845
|
+
stopping = new Set;
|
|
733
846
|
nextId = 1;
|
|
734
847
|
pending = new Map;
|
|
735
848
|
disposed = false;
|
|
736
849
|
activeRequests = 0;
|
|
737
850
|
idleTimer = null;
|
|
738
|
-
constructor(data, entry = new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./embedding-worker.ts" : "./embedding-worker.js", import.meta.url), timeoutMs = 5 * 60000, prepareTelemetry = prepareNativeOnnxTelemetry, idleMs = 10 * 60000) {
|
|
851
|
+
constructor(data, entry = new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./embedding-worker.ts" : "./embedding-worker.js", import.meta.url), timeoutMs = 5 * 60000, prepareTelemetry = prepareNativeOnnxTelemetry, idleMs = 10 * 60000, options = {}) {
|
|
739
852
|
this.data = data;
|
|
740
853
|
this.entry = entry;
|
|
741
854
|
this.timeoutMs = timeoutMs;
|
|
742
855
|
this.prepareTelemetry = prepareTelemetry;
|
|
743
856
|
this.idleMs = idleMs;
|
|
857
|
+
this.options = options;
|
|
744
858
|
}
|
|
745
859
|
start() {
|
|
746
860
|
if (this.startPromise)
|
|
@@ -778,14 +892,38 @@ class EmbeddingWorkerClient {
|
|
|
778
892
|
}
|
|
779
893
|
}
|
|
780
894
|
this.worker = worker;
|
|
895
|
+
let markExited;
|
|
896
|
+
const state = {
|
|
897
|
+
dispatched: new Map,
|
|
898
|
+
stopNotice: null,
|
|
899
|
+
exited: false,
|
|
900
|
+
exit: new Promise((resolve) => {
|
|
901
|
+
markExited = resolve;
|
|
902
|
+
})
|
|
903
|
+
};
|
|
904
|
+
this.states.set(worker, state);
|
|
905
|
+
worker.once("exit", () => {
|
|
906
|
+
state.exited = true;
|
|
907
|
+
markExited();
|
|
908
|
+
});
|
|
781
909
|
worker.unref();
|
|
782
910
|
if (!(worker instanceof Worker))
|
|
783
911
|
worker.channel?.unref?.();
|
|
784
912
|
worker.on("message", (wire) => {
|
|
913
|
+
if (isEmbeddingWorkerStopNotice(wire)) {
|
|
914
|
+
if (wire.control === "stopping")
|
|
915
|
+
state.stopNotice = {
|
|
916
|
+
busy: wire.busy,
|
|
917
|
+
busyMs: wire.busyMs,
|
|
918
|
+
receivedAt: performance.now()
|
|
919
|
+
};
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
785
922
|
const reply = worker instanceof Worker ? wire : {
|
|
786
923
|
...wire,
|
|
787
924
|
vectors: wire.vectors?.map((vector) => vector === null ? null : new Float32Array(Uint8Array.from(Buffer.from(vector, "base64")).buffer))
|
|
788
925
|
};
|
|
926
|
+
state.dispatched.delete(reply.id);
|
|
789
927
|
if (this.worker !== worker)
|
|
790
928
|
return;
|
|
791
929
|
const request = this.pending.get(reply.id);
|
|
@@ -893,6 +1031,7 @@ class EmbeddingWorkerClient {
|
|
|
893
1031
|
worker.ref();
|
|
894
1032
|
if (!(worker instanceof Worker))
|
|
895
1033
|
worker.channel?.ref?.();
|
|
1034
|
+
this.states.get(worker)?.dispatched.set(id, performance.now());
|
|
896
1035
|
try {
|
|
897
1036
|
if (worker instanceof Worker)
|
|
898
1037
|
worker.postMessage({ id, texts });
|
|
@@ -915,21 +1054,70 @@ class EmbeddingWorkerClient {
|
|
|
915
1054
|
request.reject(error);
|
|
916
1055
|
}
|
|
917
1056
|
this.pending.clear();
|
|
918
|
-
if (worker
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
1057
|
+
if (!worker)
|
|
1058
|
+
return;
|
|
1059
|
+
const stopped = this.stopWorker(worker, error.message);
|
|
1060
|
+
this.stopping.add(stopped);
|
|
1061
|
+
try {
|
|
1062
|
+
await stopped;
|
|
1063
|
+
} finally {
|
|
1064
|
+
this.stopping.delete(stopped);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
async stopWorker(worker, reason) {
|
|
1068
|
+
const state = this.states.get(worker);
|
|
1069
|
+
if (!state || state.exited)
|
|
1070
|
+
return;
|
|
1071
|
+
const writeLog = this.options.log ?? log2;
|
|
1072
|
+
const graceMs = this.options.stopGraceMs ?? EMBEDDING_WORKER_STOP_GRACE_MS;
|
|
1073
|
+
const forcedExitWaitMs = this.options.forcedExitWaitMs ?? EMBEDDING_WORKER_FORCED_EXIT_WAIT_MS;
|
|
1074
|
+
const owner = worker instanceof Worker ? `pid ${process.pid}` : `pid ${process.pid}, worker pid ${worker.pid ?? "unknown"}`;
|
|
1075
|
+
const startedAt = performance.now();
|
|
1076
|
+
const stopSince = busySince(state);
|
|
1077
|
+
worker.ref();
|
|
1078
|
+
if (!(worker instanceof Worker))
|
|
922
1079
|
worker.channel?.ref?.();
|
|
923
|
-
|
|
924
|
-
|
|
1080
|
+
const request = { stop: true };
|
|
1081
|
+
try {
|
|
1082
|
+
if (worker instanceof Worker)
|
|
1083
|
+
worker.postMessage(request);
|
|
1084
|
+
else if (worker.connected)
|
|
1085
|
+
worker.send(request, () => {});
|
|
1086
|
+
} catch {}
|
|
1087
|
+
if (await exitsWithin(state.exit, graceMs)) {
|
|
1088
|
+
writeLog(`[magic-context] embedding worker stopped (${reason}; ${owner}; inference running: ${describeRunning(stopSince, startedAt)}; stop took ${Math.round(performance.now() - startedAt)}ms)`);
|
|
1089
|
+
flushLogger2();
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
writeLog(`[magic-context] embedding worker did not stop within ${graceMs}ms; terminating it (${reason}; ${owner}; inference running: ${describeStuckWorker(state, stopSince)})`);
|
|
1093
|
+
flushLogger2();
|
|
1094
|
+
try {
|
|
1095
|
+
if (worker instanceof Worker)
|
|
1096
|
+
worker.terminate().catch(() => {});
|
|
1097
|
+
else
|
|
925
1098
|
worker.kill();
|
|
926
|
-
|
|
1099
|
+
} catch {}
|
|
1100
|
+
if (await exitsWithin(state.exit, forcedExitWaitMs))
|
|
1101
|
+
return;
|
|
1102
|
+
let killed = false;
|
|
1103
|
+
if (!(worker instanceof Worker) && process.platform !== "win32") {
|
|
1104
|
+
try {
|
|
1105
|
+
killed = worker.kill("SIGKILL");
|
|
1106
|
+
} catch {}
|
|
1107
|
+
if (await exitsWithin(state.exit, EMBEDDING_WORKER_SIGKILL_WAIT_MS))
|
|
1108
|
+
return;
|
|
927
1109
|
}
|
|
1110
|
+
writeLog(`[magic-context] embedding worker has not exited ${forcedExitWaitMs}ms after it was terminated${killed ? " and sent SIGKILL" : ""}; no longer waiting for it (${reason}; ${owner})`);
|
|
1111
|
+
flushLogger2();
|
|
1112
|
+
worker.unref();
|
|
1113
|
+
if (!(worker instanceof Worker))
|
|
1114
|
+
worker.channel?.unref?.();
|
|
928
1115
|
}
|
|
929
1116
|
async dispose() {
|
|
930
1117
|
this.disposed = true;
|
|
931
1118
|
await this.startPromise?.catch(() => {});
|
|
932
1119
|
await this.stop(new Error("embedding worker disposed"));
|
|
1120
|
+
await Promise.all([...this.stopping]);
|
|
933
1121
|
}
|
|
934
1122
|
}
|
|
935
1123
|
|
|
@@ -1651,4 +1839,4 @@ class LocalEmbeddingProvider {
|
|
|
1651
1839
|
}
|
|
1652
1840
|
}
|
|
1653
1841
|
|
|
1654
|
-
export { embeddingModelsMatch, resolveEmbeddingTextPrefixes, getCachedLocalEmbeddingPooling, logLocalEmbeddingPoolingDecisionOnce, preflightLocalEmbeddingPooling, logLocalEmbeddingPoolingUnavailableOnce, getEmbeddingProviderIdentity, dominantEmbeddingFailure, resolveLocalEmbeddingWorkerRuntime, getLocalEmbeddingNativeMemoryStats, LocalEmbeddingProvider };
|
|
1842
|
+
export { embeddingModelsMatch, resolveEmbeddingTextPrefixes, getCachedLocalEmbeddingPooling, logLocalEmbeddingPoolingDecisionOnce, preflightLocalEmbeddingPooling, logLocalEmbeddingPoolingUnavailableOnce, getEmbeddingProviderIdentity, dominantEmbeddingFailure, serveEmbeddingWorker, resolveLocalEmbeddingWorkerRuntime, getLocalEmbeddingNativeMemoryStats, LocalEmbeddingProvider };
|
|
@@ -56,7 +56,7 @@ import {
|
|
|
56
56
|
getEmbeddingProviderIdentity,
|
|
57
57
|
dominantEmbeddingFailure,
|
|
58
58
|
LocalEmbeddingProvider
|
|
59
|
-
} from "./index-
|
|
59
|
+
} from "./index-k50xhjw1.js";
|
|
60
60
|
import {
|
|
61
61
|
embedPauseBySession,
|
|
62
62
|
activeEmbeddingSessions,
|
|
@@ -67,7 +67,7 @@ import {
|
|
|
67
67
|
} from "./index-2amn2s73.js";
|
|
68
68
|
import {
|
|
69
69
|
setBootQuietPeriodForTests
|
|
70
|
-
} from "./index-
|
|
70
|
+
} from "./index-7svecf3m.js";
|
|
71
71
|
import {
|
|
72
72
|
isEmbeddingHostBusy2
|
|
73
73
|
} from "./index-qt1qqasc.js";
|
|
@@ -78,7 +78,7 @@ import {
|
|
|
78
78
|
acquireGitSweepLease,
|
|
79
79
|
renewGitSweepLease,
|
|
80
80
|
releaseGitSweepLease
|
|
81
|
-
} from "./index-
|
|
81
|
+
} from "./index-3dtzyred.js";
|
|
82
82
|
import {
|
|
83
83
|
saveEmbeddingIfHashMatches,
|
|
84
84
|
getMemoryEmbedCoverage,
|
|
@@ -1407,12 +1407,17 @@ function snapshotFor(registration) {
|
|
|
1407
1407
|
...synapseDescriptor ? { synapseDescriptor } : {}
|
|
1408
1408
|
};
|
|
1409
1409
|
}
|
|
1410
|
+
var pendingProviderDisposals = new Set;
|
|
1410
1411
|
function disposeProvider(provider) {
|
|
1411
1412
|
if (!provider)
|
|
1412
|
-
return;
|
|
1413
|
-
provider.dispose().catch((error) => {
|
|
1413
|
+
return Promise.resolve();
|
|
1414
|
+
const disposal = provider.dispose().catch((error) => {
|
|
1414
1415
|
log2("[magic-context] embedding provider dispose failed:", error);
|
|
1416
|
+
}).finally(() => {
|
|
1417
|
+
pendingProviderDisposals.delete(disposal);
|
|
1415
1418
|
});
|
|
1419
|
+
pendingProviderDisposals.add(disposal);
|
|
1420
|
+
return disposal;
|
|
1416
1421
|
}
|
|
1417
1422
|
function getUpsertActiveIdentityStatement(db) {
|
|
1418
1423
|
let stmt = upsertActiveIdentityStatements.get(db);
|
|
@@ -1775,7 +1780,7 @@ function registerProjectShadowEmbedding2(db, projectIdentity, config, sourceDire
|
|
|
1775
1780
|
return null;
|
|
1776
1781
|
const prior = shadowRegistrations.get(projectIdentity);
|
|
1777
1782
|
if (prior && prior.providerIdentity === providerIdentity) {
|
|
1778
|
-
provider
|
|
1783
|
+
disposeProvider(provider);
|
|
1779
1784
|
dbForShadowQueue.set(projectIdentity, db);
|
|
1780
1785
|
persistShadowDescriptor(db, prior);
|
|
1781
1786
|
const backfillAlreadyArmed = hasPendingShadowBackfill(projectIdentity) || shadowQueue.some((item) => item.projectIdentity === projectIdentity);
|
|
@@ -2428,13 +2433,15 @@ function unregisterProjectEmbedding2(projectIdentity) {
|
|
|
2428
2433
|
const prior = projectRegistrations.get(projectIdentity);
|
|
2429
2434
|
const shadow = shadowRegistrations.get(projectIdentity);
|
|
2430
2435
|
if (!prior && !shadow)
|
|
2431
|
-
return;
|
|
2436
|
+
return Promise.resolve();
|
|
2432
2437
|
projectRegistrations.delete(projectIdentity);
|
|
2433
2438
|
shadowRegistrations.delete(projectIdentity);
|
|
2434
2439
|
dbForShadowQueue.delete(projectIdentity);
|
|
2435
2440
|
globalRegistrationGeneration += 1;
|
|
2436
|
-
|
|
2437
|
-
|
|
2441
|
+
return Promise.all([
|
|
2442
|
+
disposeProvider(prior?.provider ?? null),
|
|
2443
|
+
disposeProvider(shadow?.provider ?? null)
|
|
2444
|
+
]).then(() => {});
|
|
2438
2445
|
}
|
|
2439
2446
|
function getProjectEmbeddingSnapshot2(projectIdentity) {
|
|
2440
2447
|
const registration = projectRegistrations.get(projectIdentity);
|
|
@@ -61,6 +61,10 @@ import {
|
|
|
61
61
|
parseJsonc,
|
|
62
62
|
detectConfigFile
|
|
63
63
|
} from "./index-sd3egckz.js";
|
|
64
|
+
import {
|
|
65
|
+
ensureStorageDirectorySync,
|
|
66
|
+
writeStorageFileAtomicSync
|
|
67
|
+
} from "./index-c5tmzym6.js";
|
|
64
68
|
import {
|
|
65
69
|
catalogOutputReserve,
|
|
66
70
|
setOutputReserveConfig,
|
|
@@ -70,7 +74,7 @@ import {
|
|
|
70
74
|
deriveTriggerBudget2,
|
|
71
75
|
resolveHistorianProducerLimits2,
|
|
72
76
|
producerSourceLocalBudget2
|
|
73
|
-
} from "./index-
|
|
77
|
+
} from "./index-zmqx48vt.js";
|
|
74
78
|
import {
|
|
75
79
|
withContentLanguageDirective,
|
|
76
80
|
buildPrimaryLanguageDirective,
|
|
@@ -107,13 +111,13 @@ import {
|
|
|
107
111
|
import {
|
|
108
112
|
shouldSkipHomeProjectMemory,
|
|
109
113
|
resolveProjectIdentity
|
|
110
|
-
} from "./index-
|
|
114
|
+
} from "./index-7svecf3m.js";
|
|
111
115
|
import {
|
|
112
116
|
getSchemaFenceRejection,
|
|
113
117
|
LATEST_SUPPORTED_VERSION,
|
|
114
118
|
getPersistedSchemaVersion,
|
|
115
119
|
openDatabase
|
|
116
|
-
} from "./index-
|
|
120
|
+
} from "./index-xccywqdj.js";
|
|
117
121
|
import {
|
|
118
122
|
areRustHistorianSyntheticParts2,
|
|
119
123
|
isStrictGapHealingMessage2,
|
|
@@ -130,7 +134,7 @@ import {
|
|
|
130
134
|
resolveStoredPathWorkspaceIdentity,
|
|
131
135
|
sourceNameForMemory,
|
|
132
136
|
computeWorkspaceEpochFingerprint
|
|
133
|
-
} from "./index-
|
|
137
|
+
} from "./index-4w5rx7de.js";
|
|
134
138
|
import {
|
|
135
139
|
BoundedSessionMap
|
|
136
140
|
} from "./index-jrj95cce.js";
|
|
@@ -202,7 +206,7 @@ import {
|
|
|
202
206
|
getProjectState,
|
|
203
207
|
recordSubagentInvocation,
|
|
204
208
|
getLatestHistorianInvocationId
|
|
205
|
-
} from "./index-
|
|
209
|
+
} from "./index-w6v4dw5f.js";
|
|
206
210
|
import {
|
|
207
211
|
clearCompressionDepth,
|
|
208
212
|
clearCompressionDepthRange,
|
|
@@ -269,7 +273,7 @@ import {
|
|
|
269
273
|
getSessionNotes,
|
|
270
274
|
getReadySmartNotes,
|
|
271
275
|
insertPrimerCandidates
|
|
272
|
-
} from "./index-
|
|
276
|
+
} from "./index-4ntnt8ee.js";
|
|
273
277
|
import {
|
|
274
278
|
pushNotification2
|
|
275
279
|
} from "./index-fzgyvsb1.js";
|
|
@@ -287,13 +291,13 @@ import {
|
|
|
287
291
|
getProjectChunkEmbeddingModelId2,
|
|
288
292
|
getProjectEmbeddingMaxInputTokens2,
|
|
289
293
|
embedItemsWindowBounded2
|
|
290
|
-
} from "./index-
|
|
294
|
+
} from "./index-s8ks5nz4.js";
|
|
291
295
|
import {
|
|
292
296
|
renderUserFacingFailure,
|
|
293
297
|
userFacingFailureCode,
|
|
294
298
|
promoteSessionFactsDurable,
|
|
295
299
|
embedPromotedFacts
|
|
296
|
-
} from "./index-
|
|
300
|
+
} from "./index-1bqkqde0.js";
|
|
297
301
|
import {
|
|
298
302
|
isMarkerCandidateBasisCurrent2,
|
|
299
303
|
invalidateMarkerCandidateBasis2,
|
|
@@ -321,9 +325,6 @@ import {
|
|
|
321
325
|
import {
|
|
322
326
|
piModelRefToCanonical
|
|
323
327
|
} from "./index-avwt563y.js";
|
|
324
|
-
import {
|
|
325
|
-
sameProjectDirectory
|
|
326
|
-
} from "./index-knvkbfvh.js";
|
|
327
328
|
import {
|
|
328
329
|
getErrorMessage,
|
|
329
330
|
describeError
|
|
@@ -336,9 +337,8 @@ import {
|
|
|
336
337
|
WriteTransactionSteps
|
|
337
338
|
} from "./index-m0pwswv9.js";
|
|
338
339
|
import {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
} from "./index-fvnzcnww.js";
|
|
340
|
+
sameProjectDirectory
|
|
341
|
+
} from "./index-knvkbfvh.js";
|
|
342
342
|
|
|
343
343
|
// src/agents/permissions.ts
|
|
344
344
|
function buildAllowOnlyPermission(allowedTools, agentLabel) {
|