@cortexkit/pi-magic-context 0.49.33 → 0.49.35
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 +11 -6
- package/dist/chunk-embedding-write-worker.js +16 -13
- package/dist/{compaction-marker-candidates-p1kqkqhq.js → compaction-marker-candidates-hk2frhac.js} +3 -2
- package/dist/compaction-marker-candidates-worker.js +1 -1
- package/dist/{compartment-chunk-embedding-8c85ebce.js → compartment-chunk-embedding-5j1d1e3v.js} +8 -7
- package/dist/embedding-backfill-jt459ady.js +26 -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-drmr22ac.js → index-0rvn6vhq.js} +3 -3
- package/dist/{index-hqw0rt9k.js → index-0wtm7g7f.js} +1 -1
- package/dist/{index-r9y6tbbm.js → index-11knwv2h.js} +20 -240
- package/dist/{index-0gymvr5j.js → index-2p691ayw.js} +19 -8
- 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-6y6v2wvn.js +194 -0
- package/dist/{index-wpazxe9x.js → index-8m82cez2.js} +4 -4
- package/dist/{index-xn5yh0pn.js → index-a11nmw5t.js} +29 -128
- package/dist/index-by1bzjcd.js +24 -0
- package/dist/index-c6wbq66z.js +168 -0
- package/dist/{index-jn44h81p.js → index-cq71g4dk.js} +1 -1
- package/dist/{index-6wdwv3a6.js → index-d0w84hy5.js} +1 -1
- package/dist/{index-pb3ea2tq.js → index-d107f484.js} +5 -5
- package/dist/index-d21rhpbd.js +4171 -0
- package/dist/index-dnp1jjar.js +222 -0
- package/dist/index-ea37qn4x.js +777 -0
- package/dist/{index-k5ya5k8r.js → index-fzm8fm4z.js} +469 -4976
- package/dist/{index-fgs78jyd.js → index-gymgz20n.js} +5 -222
- package/dist/index-hgd00nas.js +113 -0
- package/dist/{index-d5q1q700.js → index-m68qfjte.js} +2 -2
- package/dist/{index-6981g1xv.js → index-mkh1cm5k.js} +1 -1
- package/dist/{index-4zemngt7.js → index-mp0gh04g.js} +2 -2
- package/dist/{index-23t8ryqw.js → index-n0zjvs3h.js} +1 -168
- package/dist/{index-bvpar0bg.js → index-rgvqh5x7.js} +2 -2
- package/dist/{index-gwxaz0z5.js → index-rzfr7wdv.js} +2 -2
- package/dist/{index-87xkw8xm.js → index-svqk0701.js} +70 -35
- package/dist/{index-9xd7qveg.js → index-vgfk2xa5.js} +4 -4
- package/dist/index-w26zvs1q.js +528 -0
- package/dist/index-wrr9rp9a.js +16 -0
- package/dist/{index-my0dn413.js → index-wt7vmyj4.js} +1 -1
- package/dist/{index-c474g0gj.js → index-yacs388s.js} +1 -1
- package/dist/{index-e59j3yq5.js → index-yg42q9bc.js} +95 -550
- package/dist/{index-eqw9t2ty.js → index-yhsmjvqa.js} +3 -3
- package/dist/index.js +523 -236
- package/dist/{logger-shetp43v.js → logger-2j70hhz4.js} +2 -1
- package/dist/{message-fts-rowid-map-3mbvdgn9.js → message-fts-rowid-map-aw4xa05a.js} +5 -4
- package/dist/{message-index-bounded-n30vk21s.js → message-index-bounded-da34vhs4.js} +12 -10
- package/dist/{message-time-backfill-e3r8ddh1.js → message-time-backfill-x45573rs.js} +3 -2
- package/dist/migration-worker.js +13 -10
- package/dist/{project-embedding-registry-acqb6be4.js → project-embedding-registry-davzvsz9.js} +13 -11
- package/dist/raw-ordinal-warmup-worker.js +12 -7
- package/dist/{read-session-chunk-ka6dhc77.js → read-session-chunk-nbcznexm.js} +14 -8
- package/dist/{read-session-raw-g9b1zdn5.js → read-session-raw-zb8kpa2y.js} +3 -2
- package/dist/render-d931g2vv.js +41 -0
- package/dist/{safe-notification-target-zcpchea6.js → safe-notification-target-jk69jxwp.js} +3 -2
- package/dist/search-archive-a76pp30g.js +24 -0
- package/dist/{search-qbxrnnjb.js → search-atp7g95j.js} +24 -20
- package/dist/{storage-tags-6409qq18.js → storage-tags-jy8b0xsy.js} +5 -4
- package/dist/store-kabezr25.js +453 -0
- package/dist/store-reader-2m80zs5z.js +14 -0
- package/dist/subagent-entry.js +31 -23
- package/dist/tag-snapshot-worker-pi.js +15 -12
- package/dist/v2-archive-reader-wcjcfdzq.js +11 -0
- package/package.json +1 -1
- package/dist/embedding-backfill-rwfmyvze.js +0 -24
- package/dist/search-archive-msy2bczx.js +0 -21
|
@@ -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-svqk0701.js";
|
|
13
13
|
import {
|
|
14
14
|
recordMessageFtsRowid2,
|
|
15
15
|
recordIndexedMessageTime2,
|
|
16
16
|
messageFtsOrdinalRangeIsMapped2,
|
|
17
17
|
deleteUnmappedMessageFtsRows2
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-rgvqh5x7.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;
|
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
inRootAsyncContext2,
|
|
3
|
-
getSqliteDatabasePath2,
|
|
4
|
-
withSqliteBackgroundWriter2,
|
|
5
|
-
withoutSqliteTransformPass2,
|
|
6
|
-
isTransientSqliteError2
|
|
7
|
-
} from "./index-2qtx0q6h.js";
|
|
8
1
|
import {
|
|
9
2
|
estimateTokens
|
|
10
|
-
} from "./index-
|
|
3
|
+
} from "./index-wt7vmyj4.js";
|
|
11
4
|
import {
|
|
12
5
|
getHarness2
|
|
13
6
|
} from "./index-0h2mkab2.js";
|
|
14
7
|
import {
|
|
15
|
-
sanitizeDiagnosticText,
|
|
16
8
|
log2
|
|
17
|
-
} from "./index-
|
|
9
|
+
} from "./index-gymgz20n.js";
|
|
10
|
+
import {
|
|
11
|
+
sanitizeDiagnosticText
|
|
12
|
+
} from "./index-dnp1jjar.js";
|
|
18
13
|
import {
|
|
19
14
|
SYNAPSE_DEFAULT_MODEL,
|
|
20
15
|
isSynapseEmbeddingTruncated,
|
|
21
16
|
getSynapseBatchRequestKey,
|
|
22
17
|
SynapseEmbeddingProvider
|
|
23
|
-
} from "./index-
|
|
18
|
+
} from "./index-rzfr7wdv.js";
|
|
19
|
+
import {
|
|
20
|
+
inRootAsyncContext2,
|
|
21
|
+
getSqliteDatabasePath2
|
|
22
|
+
} from "./index-2qtx0q6h.js";
|
|
24
23
|
import {
|
|
25
24
|
createWorkerShutdown
|
|
26
25
|
} from "./index-54wmg4rj.js";
|
|
@@ -41,7 +40,7 @@ import {
|
|
|
41
40
|
countSessionCompartmentEmbedCoverage2,
|
|
42
41
|
countSessionCompartmentEmbedCoveragePolite2,
|
|
43
42
|
countUnembeddedSessionCompartmentsPolite2
|
|
44
|
-
} from "./index-
|
|
43
|
+
} from "./index-2p691ayw.js";
|
|
45
44
|
import {
|
|
46
45
|
DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
47
46
|
} from "./index-ccanzg8p.js";
|
|
@@ -54,10 +53,18 @@ import {
|
|
|
54
53
|
getEmbeddingProviderIdentity,
|
|
55
54
|
dominantEmbeddingFailure,
|
|
56
55
|
LocalEmbeddingProvider
|
|
57
|
-
} from "./index-
|
|
56
|
+
} from "./index-2qqsnh1b.js";
|
|
57
|
+
import {
|
|
58
|
+
embedPauseBySession,
|
|
59
|
+
activeEmbeddingSessions,
|
|
60
|
+
drainBackgroundBatches,
|
|
61
|
+
beginSynapseBatchLedger,
|
|
62
|
+
finishSynapseBatchLedger,
|
|
63
|
+
pruneSynapseBatchLedgerForProject
|
|
64
|
+
} from "./index-hgd00nas.js";
|
|
58
65
|
import {
|
|
59
66
|
setBootQuietPeriodForTests
|
|
60
|
-
} from "./index-
|
|
67
|
+
} from "./index-6pk49fc3.js";
|
|
61
68
|
import {
|
|
62
69
|
isEmbeddingHostBusy2
|
|
63
70
|
} from "./index-9p40dgkm.js";
|
|
@@ -68,7 +75,7 @@ import {
|
|
|
68
75
|
acquireGitSweepLease,
|
|
69
76
|
renewGitSweepLease,
|
|
70
77
|
releaseGitSweepLease
|
|
71
|
-
} from "./index-
|
|
78
|
+
} from "./index-mp0gh04g.js";
|
|
72
79
|
import {
|
|
73
80
|
saveEmbeddingIfHashMatches,
|
|
74
81
|
getMemoryEmbedCoverage,
|
|
@@ -79,116 +86,10 @@ import {
|
|
|
79
86
|
} from "./index-nrzkqte4.js";
|
|
80
87
|
import {
|
|
81
88
|
logSlowWriteTransaction
|
|
82
|
-
} from "./index-
|
|
83
|
-
|
|
84
|
-
// ../plugin/src/hooks/magic-context/embed-session-state.ts
|
|
85
|
-
var embedPauseBySession = new Set;
|
|
86
|
-
var embedRunStateBySession = new Map;
|
|
87
|
-
var activeEmbeddingSessions = new Map;
|
|
88
|
-
var autoEmbedAttemptedBySession = new Set;
|
|
89
|
-
var autoEmbedIdentityBySession = new Map;
|
|
90
|
-
var autoEmbedRetryAfterBySession = new Map;
|
|
91
|
-
function invalidateAutoEmbedSession(sessionId) {
|
|
92
|
-
autoEmbedAttemptedBySession.delete(sessionId);
|
|
93
|
-
autoEmbedIdentityBySession.delete(sessionId);
|
|
94
|
-
autoEmbedRetryAfterBySession.delete(sessionId);
|
|
95
|
-
}
|
|
96
|
-
function getEmbedDrainUiStatus(sessionId, progress) {
|
|
97
|
-
if (embedPauseBySession.has(sessionId)) {
|
|
98
|
-
return { status: "paused" };
|
|
99
|
-
}
|
|
100
|
-
const activeRun = embedRunStateBySession.get(sessionId);
|
|
101
|
-
if (activeRun && !activeRun.signal.aborted || progress?.kind === "embed" && progress.phase === "recomp") {
|
|
102
|
-
return { status: "running" };
|
|
103
|
-
}
|
|
104
|
-
if (progress?.kind === "embed" && (progress.phase === "failed" || progress.phase === "skipped") && progress.message) {
|
|
105
|
-
if (/provider/i.test(progress.message)) {
|
|
106
|
-
return { status: "stopped", detail: progress.message };
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return { status: "idle" };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ../plugin/src/shared/background-batch-drain.ts
|
|
113
|
-
async function drainBackgroundBatches(step, options = {}) {
|
|
114
|
-
const now = options.now ?? (() => performance.now());
|
|
115
|
-
const deadline = now() + (options.budgetMs ?? 2000);
|
|
116
|
-
const yieldFn = options.yieldFn ?? (() => new Promise((resolve) => setTimeout(resolve, 0)));
|
|
117
|
-
let batches = 0;
|
|
118
|
-
while (now() < deadline) {
|
|
119
|
-
try {
|
|
120
|
-
if (!withoutSqliteTransformPass2(() => withSqliteBackgroundWriter2(step)))
|
|
121
|
-
break;
|
|
122
|
-
} catch (error) {
|
|
123
|
-
if (isTransientSqliteError2(error))
|
|
124
|
-
break;
|
|
125
|
-
throw error;
|
|
126
|
-
}
|
|
127
|
-
batches++;
|
|
128
|
-
await yieldFn();
|
|
129
|
-
}
|
|
130
|
-
return batches;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// ../plugin/src/features/magic-context/storage-embedding-measurements.ts
|
|
134
|
-
import { createHash } from "node:crypto";
|
|
135
|
-
function normalizedQueryHash(query) {
|
|
136
|
-
const normalized = query.trim().replace(/\s+/g, " ").toLowerCase();
|
|
137
|
-
return createHash("sha256").update(normalized).digest("hex");
|
|
138
|
-
}
|
|
139
|
-
var MEASUREMENT_CORPUS_SESSION_ROW_CAP = 2000;
|
|
140
|
-
function recordEmbeddingMeasurement(db, input, cap = MEASUREMENT_CORPUS_SESSION_ROW_CAP) {
|
|
141
|
-
const queryTextHash = normalizedQueryHash(input.queryText);
|
|
142
|
-
const dedupKey = queryTextHash;
|
|
143
|
-
const result = db.prepare(`INSERT OR IGNORE INTO embedding_measurement_corpus
|
|
144
|
-
(session_id, project_path, dedup_key, cohort_key, query_text_hash,
|
|
145
|
-
primary_result_ids_json, shadow_result_ids_json, primary_latency_ms, shadow_latency_ms,
|
|
146
|
-
primary_failed, shadow_failed, primary_model_id, shadow_model_id,
|
|
147
|
-
primary_fingerprint, shadow_fingerprint, primary_epoch, shadow_epoch,
|
|
148
|
-
corpus_hash, coverage_json, created_at)
|
|
149
|
-
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());
|
|
150
|
-
if (result.changes > 0) {
|
|
151
|
-
const rowCount = db.prepare("SELECT COUNT(*) AS count FROM embedding_measurement_corpus WHERE session_id = ?").get(input.sessionId).count;
|
|
152
|
-
const overflow = rowCount - cap;
|
|
153
|
-
if (overflow > 0) {
|
|
154
|
-
db.prepare(`DELETE FROM embedding_measurement_corpus
|
|
155
|
-
WHERE session_id = ?
|
|
156
|
-
AND id IN (
|
|
157
|
-
SELECT id FROM embedding_measurement_corpus
|
|
158
|
-
WHERE session_id = ?
|
|
159
|
-
ORDER BY id ASC
|
|
160
|
-
LIMIT ?
|
|
161
|
-
)`).run(input.sessionId, input.sessionId, overflow);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return result.changes > 0;
|
|
165
|
-
}
|
|
166
|
-
function beginSynapseBatchLedger(db, input, now = Date.now()) {
|
|
167
|
-
db.prepare(`INSERT INTO synapse_batch_ledger
|
|
168
|
-
(session_id, project_path, scope, manifest_json, request_key, status, created_at, updated_at)
|
|
169
|
-
VALUES (?, ?, ?, ?, ?, 'pending', ?, ?)
|
|
170
|
-
ON CONFLICT(session_id, request_key) DO UPDATE SET
|
|
171
|
-
manifest_json = excluded.manifest_json,
|
|
172
|
-
updated_at = excluded.updated_at`).run(input.sessionId, input.projectPath, input.scope, JSON.stringify(input.manifest), input.requestKey, now, now);
|
|
173
|
-
}
|
|
174
|
-
function finishSynapseBatchLedger(db, sessionId, requestKey, status, now = Date.now()) {
|
|
175
|
-
db.prepare("UPDATE synapse_batch_ledger SET status = ?, updated_at = ? WHERE session_id = ? AND request_key = ?").run(status, now, sessionId, requestKey);
|
|
176
|
-
}
|
|
177
|
-
var SYNAPSE_BATCH_LEDGER_TTL_MS = 14 * 24 * 60 * 60 * 1000;
|
|
178
|
-
function pruneSynapseBatchLedgerForProject(db, projectIdentity, ttlMs = SYNAPSE_BATCH_LEDGER_TTL_MS) {
|
|
179
|
-
const ledgerTable = db.prepare("SELECT 1 AS present FROM sqlite_master WHERE type = 'table' AND name = 'synapse_batch_ledger'").get();
|
|
180
|
-
if (!ledgerTable)
|
|
181
|
-
return 0;
|
|
182
|
-
const shadow = `shadow:${projectIdentity}`;
|
|
183
|
-
const cutoff = Date.now() - ttlMs;
|
|
184
|
-
const predicate = "session_id IN (?, ?) AND updated_at < ?";
|
|
185
|
-
if (!db.prepare(`SELECT 1 FROM synapse_batch_ledger WHERE ${predicate} LIMIT 1`).get(projectIdentity, shadow, cutoff))
|
|
186
|
-
return 0;
|
|
187
|
-
return db.prepare(`DELETE FROM synapse_batch_ledger WHERE ${predicate}`).run(projectIdentity, shadow, cutoff).changes;
|
|
188
|
-
}
|
|
89
|
+
} from "./index-0wtm7g7f.js";
|
|
189
90
|
|
|
190
91
|
// ../plugin/src/features/magic-context/memory/embedding-openai.ts
|
|
191
|
-
import { createHash
|
|
92
|
+
import { createHash } from "node:crypto";
|
|
192
93
|
|
|
193
94
|
// ../plugin/src/features/magic-context/memory/embedding-ssrf.ts
|
|
194
95
|
var METADATA_HOSTNAMES = new Set(["metadata.google.internal", "metadata.goog"]);
|
|
@@ -295,7 +196,7 @@ var RATE_LIMIT_BACKOFF_CAP_MS = 30000;
|
|
|
295
196
|
var RATE_LIMIT_BACKOFF_JITTER = 0.25;
|
|
296
197
|
var rateLimitStates = new Map;
|
|
297
198
|
function rateLimitStateKey(endpoint, apiKey) {
|
|
298
|
-
const keyHash = apiKey ?
|
|
199
|
+
const keyHash = apiKey ? createHash("sha256").update(apiKey).digest("hex").slice(0, 16) : "";
|
|
299
200
|
return `${endpoint}\x00${keyHash}`;
|
|
300
201
|
}
|
|
301
202
|
function parseRetryAfterMs(value, nowMs) {
|
|
@@ -707,7 +608,7 @@ class OpenAICompatibleEmbeddingProvider {
|
|
|
707
608
|
}
|
|
708
609
|
|
|
709
610
|
// ../plugin/src/features/magic-context/project-embedding-registry.ts
|
|
710
|
-
import { createHash as
|
|
611
|
+
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
711
612
|
|
|
712
613
|
// ../plugin/src/features/magic-context/chunk-embedding-writer.ts
|
|
713
614
|
import { Worker } from "node:worker_threads";
|
|
@@ -1379,10 +1280,10 @@ function stableStringify(value) {
|
|
|
1379
1280
|
return JSON.stringify(value);
|
|
1380
1281
|
}
|
|
1381
1282
|
function sha256Prefix(value, length = 16) {
|
|
1382
|
-
return
|
|
1283
|
+
return createHash2("sha256").update(value).digest("hex").slice(0, length);
|
|
1383
1284
|
}
|
|
1384
1285
|
function contentSha2562(value) {
|
|
1385
|
-
return
|
|
1286
|
+
return createHash2("sha256").update(value).digest("hex");
|
|
1386
1287
|
}
|
|
1387
1288
|
function getRuntimeFingerprint(config) {
|
|
1388
1289
|
if (config.provider === "off") {
|
|
@@ -3183,4 +3084,4 @@ function _resetProjectEmbeddingRegistryForTests2() {
|
|
|
3183
3084
|
setBootQuietPeriodForTests(null);
|
|
3184
3085
|
}
|
|
3185
3086
|
|
|
3186
|
-
export {
|
|
3087
|
+
export { OpenAICompatibleEmbeddingProvider, saveCommitEmbedding, loadProjectCommitEmbeddings, loadUnembeddedCommits, countEmbeddedCommits, upsertCommits, getLatestIndexedCommitSha, enforceProjectCap, describeShadowBackfillWriteRefusal2, listShadowBackfillStalls2, getShadowBackfillStopReason2, markProjectLoadUntrusted2, contentSha2562, drainProjectEmbeddingIdentityMaintenance2, drainStaleEmbeddingIdentitiesForProject2, registerProjectEmbedding2, registerProjectShadowEmbedding2, getShadowEmbeddingMeasurementCohort2, getPrimaryEmbeddingMeasurementCohort2, embedShadowTextForProject2, enqueueShadowEmbeddingItems2, getShadowBackfillRemaining2, flushShadowEmbeddingBacklog2, registerProjectInObservationMode2, unregisterProjectShadowEmbedding2, unregisterProjectEmbedding2, getProjectEmbeddingSnapshot2, installProjectEmbeddingSearchBridge2, getProjectChunkEmbeddingModelId2, getProjectEmbeddingMaxInputTokens2, embedTextForProject2, embedBatchForProject2, embedItemsForProject2, embedUnembeddedMemoriesForProject2, drainCommitBacklogForProject2, embedUnembeddedCompartmentChunksForProject2, embedSessionCompartmentChunks2, getEmbeddingCoverageStatus2, getAutoEmbeddingSessionCoverage2, sweepAllRegisteredProjects2, _setTestProviderFactoryForProject2, _resetProjectEmbeddingRegistryForTests2 };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// ../plugin/src/hooks/magic-context/host-served-rows.ts
|
|
2
|
+
var HOST_UNSERVED_ROW = "hostUnservedRow";
|
|
3
|
+
function markHostUnservedRow(target) {
|
|
4
|
+
Object.defineProperty(target, HOST_UNSERVED_ROW, {
|
|
5
|
+
value: true,
|
|
6
|
+
enumerable: false,
|
|
7
|
+
configurable: true
|
|
8
|
+
});
|
|
9
|
+
return target;
|
|
10
|
+
}
|
|
11
|
+
function isHostUnservedRow(value) {
|
|
12
|
+
return typeof value === "object" && value !== null && value[HOST_UNSERVED_ROW] === true;
|
|
13
|
+
}
|
|
14
|
+
function retreatPastHostUnservedRows(messages, exclusiveEnd, floor) {
|
|
15
|
+
if (!messages.some(isHostUnservedRow))
|
|
16
|
+
return exclusiveEnd;
|
|
17
|
+
const byOrdinal = new Map(messages.map((message) => [message.ordinal, message]));
|
|
18
|
+
let end = exclusiveEnd;
|
|
19
|
+
while (end - 1 >= floor && isHostUnservedRow(byOrdinal.get(end - 1)))
|
|
20
|
+
end -= 1;
|
|
21
|
+
return end;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { markHostUnservedRow, isHostUnservedRow, retreatPastHostUnservedRows };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// ../plugin/src/shared/bounded-session-map.ts
|
|
2
|
+
class BoundedSessionMap {
|
|
3
|
+
maxEntries;
|
|
4
|
+
store = new Map;
|
|
5
|
+
constructor(maxEntries) {
|
|
6
|
+
if (!Number.isFinite(maxEntries) || maxEntries < 1) {
|
|
7
|
+
throw new Error(`BoundedSessionMap: maxEntries must be >= 1, got ${maxEntries}`);
|
|
8
|
+
}
|
|
9
|
+
this.maxEntries = maxEntries;
|
|
10
|
+
}
|
|
11
|
+
get(sessionId) {
|
|
12
|
+
const value = this.store.get(sessionId);
|
|
13
|
+
if (value === undefined)
|
|
14
|
+
return;
|
|
15
|
+
this.store.delete(sessionId);
|
|
16
|
+
this.store.set(sessionId, value);
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
peek(sessionId) {
|
|
20
|
+
return this.store.get(sessionId);
|
|
21
|
+
}
|
|
22
|
+
has(sessionId) {
|
|
23
|
+
return this.store.has(sessionId);
|
|
24
|
+
}
|
|
25
|
+
set(sessionId, value) {
|
|
26
|
+
if (this.store.has(sessionId)) {
|
|
27
|
+
this.store.delete(sessionId);
|
|
28
|
+
} else if (this.store.size >= this.maxEntries) {
|
|
29
|
+
const oldest = this.store.keys().next().value;
|
|
30
|
+
if (oldest !== undefined)
|
|
31
|
+
this.store.delete(oldest);
|
|
32
|
+
}
|
|
33
|
+
this.store.set(sessionId, value);
|
|
34
|
+
}
|
|
35
|
+
delete(sessionId) {
|
|
36
|
+
return this.store.delete(sessionId);
|
|
37
|
+
}
|
|
38
|
+
clear() {
|
|
39
|
+
this.store.clear();
|
|
40
|
+
}
|
|
41
|
+
get size() {
|
|
42
|
+
return this.store.size;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ../plugin/src/features/magic-context/tool-definition-tokens.ts
|
|
47
|
+
var ACTIVITY_WINDOW_MS = 10 * 60000;
|
|
48
|
+
var MAX_ACTIVITY_GAP_MS = 60000;
|
|
49
|
+
var WINDOWED_SINCE_KEY = "tool_definition_measurements:windowed_since";
|
|
50
|
+
var routes = new Map;
|
|
51
|
+
var sessionFlights = new BoundedSessionMap(1000);
|
|
52
|
+
var persistenceDb = null;
|
|
53
|
+
var windowedSince;
|
|
54
|
+
var boundAt = 0;
|
|
55
|
+
var cachedInsertStmt = null;
|
|
56
|
+
var cachedDeleteStmt = null;
|
|
57
|
+
function agentKey(agentName) {
|
|
58
|
+
return agentName && agentName.length > 0 ? agentName : "default";
|
|
59
|
+
}
|
|
60
|
+
function keyFor(providerID, modelID, agentName) {
|
|
61
|
+
return `${providerID}/${modelID}/${agentKey(agentName)}`;
|
|
62
|
+
}
|
|
63
|
+
function routeFor(providerID, modelID, agentName) {
|
|
64
|
+
const key = keyFor(providerID, modelID, agentName);
|
|
65
|
+
let route = routes.get(key);
|
|
66
|
+
if (!route) {
|
|
67
|
+
route = {
|
|
68
|
+
providerID,
|
|
69
|
+
modelID,
|
|
70
|
+
agentName: agentKey(agentName),
|
|
71
|
+
tools: new Map,
|
|
72
|
+
live: false,
|
|
73
|
+
clock: 0,
|
|
74
|
+
lastWallAt: Date.now(),
|
|
75
|
+
oldestFireAt: Number.POSITIVE_INFINITY,
|
|
76
|
+
retired: new Map,
|
|
77
|
+
legacyRows: new Set
|
|
78
|
+
};
|
|
79
|
+
routes.set(key, route);
|
|
80
|
+
}
|
|
81
|
+
return { key, route };
|
|
82
|
+
}
|
|
83
|
+
function advanceClock(route) {
|
|
84
|
+
const now = Date.now();
|
|
85
|
+
const gap = Math.min(Math.max(now - route.lastWallAt, 0), MAX_ACTIVITY_GAP_MS);
|
|
86
|
+
route.clock += gap;
|
|
87
|
+
route.lastWallAt = Math.max(route.lastWallAt, now);
|
|
88
|
+
return route.clock;
|
|
89
|
+
}
|
|
90
|
+
function readWindowedSince(db) {
|
|
91
|
+
try {
|
|
92
|
+
const row = db.prepare("SELECT value FROM schema_migrations_meta WHERE key = ?").get(WINDOWED_SINCE_KEY);
|
|
93
|
+
if (!row)
|
|
94
|
+
return;
|
|
95
|
+
const value = Number(row.value);
|
|
96
|
+
return Number.isFinite(value) ? value : undefined;
|
|
97
|
+
} catch {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function markWindowed() {
|
|
102
|
+
if (windowedSince !== undefined || !persistenceDb)
|
|
103
|
+
return;
|
|
104
|
+
try {
|
|
105
|
+
persistenceDb.prepare("INSERT OR IGNORE INTO schema_migrations_meta (key, value) VALUES (?, ?)").run(WINDOWED_SINCE_KEY, String(boundAt));
|
|
106
|
+
windowedSince = readWindowedSince(persistenceDb);
|
|
107
|
+
} catch {}
|
|
108
|
+
}
|
|
109
|
+
function setDatabase(db) {
|
|
110
|
+
const rebound = persistenceDb !== null && persistenceDb !== db;
|
|
111
|
+
persistenceDb = db;
|
|
112
|
+
boundAt = Date.now();
|
|
113
|
+
cachedInsertStmt = null;
|
|
114
|
+
cachedDeleteStmt = null;
|
|
115
|
+
if (rebound) {
|
|
116
|
+
for (const route of routes.values()) {
|
|
117
|
+
for (const slot of route.tools.values()) {
|
|
118
|
+
slot.persisted = false;
|
|
119
|
+
slot.writeFailedAt = undefined;
|
|
120
|
+
}
|
|
121
|
+
for (const retired of route.retired.values())
|
|
122
|
+
retired.rowKept = false;
|
|
123
|
+
route.legacyRows.clear();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
windowedSince = readWindowedSince(db);
|
|
127
|
+
if (windowedSince !== undefined)
|
|
128
|
+
return;
|
|
129
|
+
try {
|
|
130
|
+
if (!db.prepare("SELECT 1 FROM tool_definition_measurements LIMIT 1").get())
|
|
131
|
+
markWindowed();
|
|
132
|
+
} catch {}
|
|
133
|
+
}
|
|
134
|
+
function loadToolDefinitionMeasurements(db) {
|
|
135
|
+
let rows = [];
|
|
136
|
+
try {
|
|
137
|
+
rows = db.prepare("SELECT provider_id, model_id, agent_name, tool_id, token_count, recorded_at FROM tool_definition_measurements").all();
|
|
138
|
+
} catch {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const since = readWindowedSince(db);
|
|
142
|
+
const loadedAt = new Map;
|
|
143
|
+
for (const row of rows) {
|
|
144
|
+
const { route } = routeFor(row.provider_id, row.model_id, row.agent_name);
|
|
145
|
+
if (route.live)
|
|
146
|
+
continue;
|
|
147
|
+
let now = loadedAt.get(route);
|
|
148
|
+
if (now === undefined) {
|
|
149
|
+
now = advanceClock(route);
|
|
150
|
+
loadedAt.set(route, now);
|
|
151
|
+
}
|
|
152
|
+
const legacy = since === undefined || !(Number(row.recorded_at) >= since);
|
|
153
|
+
route.tools.set(row.tool_id, {
|
|
154
|
+
tokens: row.token_count,
|
|
155
|
+
fingerprint: undefined,
|
|
156
|
+
lastFireAt: now,
|
|
157
|
+
legacy,
|
|
158
|
+
persisted: !legacy
|
|
159
|
+
});
|
|
160
|
+
route.oldestFireAt = Math.min(route.oldestFireAt, now);
|
|
161
|
+
if (legacy)
|
|
162
|
+
route.legacyRows.add(row.tool_id);
|
|
163
|
+
else
|
|
164
|
+
route.legacyRows.delete(row.tool_id);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export { BoundedSessionMap, setDatabase, loadToolDefinitionMeasurements };
|
|
@@ -3,27 +3,27 @@ import {
|
|
|
3
3
|
} from "./index-135e8hvg.js";
|
|
4
4
|
import {
|
|
5
5
|
log2
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-gymgz20n.js";
|
|
7
7
|
import {
|
|
8
8
|
ensureColumn,
|
|
9
9
|
healAllNullColumns,
|
|
10
10
|
installV95PerfSchema
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-yacs388s.js";
|
|
12
12
|
import {
|
|
13
13
|
resolveOpenCodeDbPath,
|
|
14
14
|
openCodeDbPathExists,
|
|
15
15
|
getOpenCodeDbProbeDescriptions
|
|
16
|
-
} from "./index-
|
|
16
|
+
} from "./index-n0zjvs3h.js";
|
|
17
17
|
import {
|
|
18
18
|
Database2
|
|
19
19
|
} from "./index-2qtx0q6h.js";
|
|
20
20
|
import {
|
|
21
21
|
normalizeStoredProjectPath,
|
|
22
22
|
storedPathBelongsToIdentity
|
|
23
|
-
} from "./index-
|
|
23
|
+
} from "./index-6pk49fc3.js";
|
|
24
24
|
import {
|
|
25
25
|
logSlowWriteTransaction
|
|
26
|
-
} from "./index-
|
|
26
|
+
} from "./index-0wtm7g7f.js";
|
|
27
27
|
|
|
28
28
|
// ../plugin/src/features/magic-context/migrations.ts
|
|
29
29
|
import { isMainThread } from "node:worker_threads";
|