@cortexkit/pi-magic-context 0.48.0 → 0.49.1
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 +3 -3
- package/dist/embedding-backfill-scywarbn.js +20 -0
- package/dist/embedding-worker-process.js +29 -0
- package/dist/embedding-worker.js +6 -6
- package/dist/historian-calibration-extension.js +30 -5
- package/dist/index-0j0zqb4t.js +712 -0
- package/dist/{index-pvm4pd5d.js → index-0rasmwm8.js} +811 -76
- package/dist/{index-fp37he9a.js → index-0vrkp1jq.js} +1 -1
- package/dist/{index-419bndtm.js → index-21v1kfs7.js} +2 -2
- package/dist/{index-fm3ksh5e.js → index-27jh224p.js} +4 -4
- package/dist/{index-98z1c1r0.js → index-28vnkyy7.js} +1231 -3018
- package/dist/{index-wrm4nbj7.js → index-290tzwp1.js} +1 -1
- package/dist/{index-603mt6nm.js → index-4gfq5t09.js} +17 -2
- package/dist/{index-vf38qhee.js → index-81nthk8j.js} +44 -1
- package/dist/{index-5jp1h0bz.js → index-b2anqqad.js} +467 -14
- package/dist/{index-6pgq5ns2.js → index-cyrnv16r.js} +314 -1072
- package/dist/index-fqb1bddn.js +4947 -0
- package/dist/{index-dkx0b1kt.js → index-g7hndmqm.js} +20 -29
- package/dist/index-gc2749rx.js +1168 -0
- package/dist/{index-5hd7h4rr.js → index-kjd1fj55.js} +39 -31
- package/dist/{index-8y5knskr.js → index-mcgehvgw.js} +93 -9
- package/dist/{index-r7xg4hvw.js → index-p5zesr4e.js} +26 -722
- package/dist/{index-9xb0axhc.js → index-r56xgha8.js} +1 -1
- package/dist/{index-544c0e0x.js → index-r874cgmv.js} +42 -40
- package/dist/{index-72bdc1bd.js → index-rd53pk0h.js} +4 -4
- package/dist/{index-0am8a7k1.js → index-rdtgp48t.js} +8 -6
- package/dist/{index-rt5jgzp1.js → index-vakawmbc.js} +160 -25
- package/dist/{index-f956htf3.js → index-x3dcnxh0.js} +6 -2
- package/dist/{index-zrr5t5a7.js → index-zh1jw8qp.js} +106 -1
- package/dist/index.js +2271 -1769
- package/dist/{logger-v3dsxdnm.js → logger-j6tecd1h.js} +1 -1
- package/dist/{message-index-bounded-t7vvty76.js → message-index-bounded-110sb4fm.js} +13 -12
- package/dist/{message-time-backfill-4ndf7hrq.js → message-time-backfill-05ppypkz.js} +2 -2
- package/dist/migration-worker.js +10 -9
- package/dist/{project-embedding-registry-jy2hmq28.js → project-embedding-registry-64t0mw8y.js} +10 -10
- package/dist/raw-ordinal-warmup-worker.js +4 -4
- package/dist/{read-session-chunk-47pjn7fz.js → read-session-chunk-rvmc25n5.js} +10 -7
- package/dist/{read-session-raw-yn8nawav.js → read-session-raw-npx3920c.js} +5 -3
- package/dist/{safe-notification-target-3c1ns931.js → safe-notification-target-vn9kpmv4.js} +2 -2
- package/dist/{search-42szfhwp.js → search-7z3w8pmz.js} +19 -18
- package/dist/{storage-tags-jym5z6yk.js → storage-tags-kjnsqbdb.js} +6 -6
- package/dist/subagent-entry.js +25 -23
- package/package.json +3 -3
- package/dist/embedding-backfill-bnnytehy.js +0 -20
- package/dist/index-bgmv2kaf.js +0 -290
- package/dist/index-hrf13mn3.js +0 -2388
- /package/dist/{index-5prbx026.js → index-2pp04pmg.js} +0 -0
|
@@ -4,25 +4,25 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
sanitizeDiagnosticText,
|
|
6
6
|
log2
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-x3dcnxh0.js";
|
|
8
8
|
import {
|
|
9
9
|
isUserHomeDirectory,
|
|
10
10
|
setBootQuietPeriodForTests
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-g7hndmqm.js";
|
|
12
|
+
import {
|
|
13
|
+
withSqliteBackgroundWriter2,
|
|
14
|
+
withoutSqliteTransformPass2,
|
|
15
|
+
isTransientSqliteError2
|
|
16
|
+
} from "./index-3cgbv47m.js";
|
|
12
17
|
import {
|
|
13
18
|
estimateTokens
|
|
14
|
-
} from "./index-
|
|
19
|
+
} from "./index-r56xgha8.js";
|
|
15
20
|
import {
|
|
16
21
|
SYNAPSE_DEFAULT_MODEL,
|
|
17
22
|
isSynapseEmbeddingTruncated,
|
|
18
23
|
getSynapseBatchRequestKey,
|
|
19
24
|
SynapseEmbeddingProvider
|
|
20
|
-
} from "./index-
|
|
21
|
-
import {
|
|
22
|
-
withSqliteBackgroundWriter2,
|
|
23
|
-
withoutSqliteTransformPass2,
|
|
24
|
-
isTransientSqliteError2
|
|
25
|
-
} from "./index-3cgbv47m.js";
|
|
25
|
+
} from "./index-21v1kfs7.js";
|
|
26
26
|
import {
|
|
27
27
|
CHUNK_WINDOW_SAFETY_RATIO,
|
|
28
28
|
normalizeCompartmentChunkMaxInputTokens,
|
|
@@ -39,15 +39,10 @@ import {
|
|
|
39
39
|
countSessionCompartmentEmbedCoverage,
|
|
40
40
|
countSessionCompartmentEmbedCoveragePolite,
|
|
41
41
|
countUnembeddedSessionCompartmentsPolite
|
|
42
|
-
} from "./index-
|
|
42
|
+
} from "./index-27jh224p.js";
|
|
43
43
|
import {
|
|
44
|
-
DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
45
|
-
|
|
46
|
-
resolveEmbeddingTextPrefixes,
|
|
47
|
-
getEmbeddingProviderIdentity,
|
|
48
|
-
dominantEmbeddingFailure,
|
|
49
|
-
LocalEmbeddingProvider
|
|
50
|
-
} from "./index-6pgq5ns2.js";
|
|
44
|
+
DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
45
|
+
} from "./index-cyrnv16r.js";
|
|
51
46
|
import {
|
|
52
47
|
isEmbeddingHostBusy2
|
|
53
48
|
} from "./index-9p40dgkm.js";
|
|
@@ -56,9 +51,16 @@ import {
|
|
|
56
51
|
getMemoryEmbedCoverage,
|
|
57
52
|
invalidateProject2
|
|
58
53
|
} from "./index-yhzhdp3m.js";
|
|
54
|
+
import {
|
|
55
|
+
embeddingModelsMatch,
|
|
56
|
+
resolveEmbeddingTextPrefixes,
|
|
57
|
+
getEmbeddingProviderIdentity,
|
|
58
|
+
dominantEmbeddingFailure,
|
|
59
|
+
LocalEmbeddingProvider
|
|
60
|
+
} from "./index-gc2749rx.js";
|
|
59
61
|
import {
|
|
60
62
|
logSlowWriteTransaction
|
|
61
|
-
} from "./index-
|
|
63
|
+
} from "./index-0vrkp1jq.js";
|
|
62
64
|
|
|
63
65
|
// ../plugin/src/features/magic-context/session-project-storage.ts
|
|
64
66
|
var SESSION_CHUNK_REPAIR_BATCH_SIZE = 100;
|
|
@@ -138,6 +140,27 @@ function repairMisScopedCompartmentChunkEmbeddingsForProject(db, projectPath, id
|
|
|
138
140
|
)`).run(...ids, projectPath, projectPath).changes;
|
|
139
141
|
}
|
|
140
142
|
|
|
143
|
+
// ../plugin/src/shared/background-batch-drain.ts
|
|
144
|
+
async function drainBackgroundBatches(step, options = {}) {
|
|
145
|
+
const now = options.now ?? (() => performance.now());
|
|
146
|
+
const deadline = now() + (options.budgetMs ?? 2000);
|
|
147
|
+
const yieldFn = options.yieldFn ?? (() => new Promise((resolve) => setTimeout(resolve, 0)));
|
|
148
|
+
let batches = 0;
|
|
149
|
+
while (now() < deadline) {
|
|
150
|
+
try {
|
|
151
|
+
if (!withoutSqliteTransformPass2(() => withSqliteBackgroundWriter2(step)))
|
|
152
|
+
break;
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (isTransientSqliteError2(error))
|
|
155
|
+
break;
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
batches++;
|
|
159
|
+
await yieldFn();
|
|
160
|
+
}
|
|
161
|
+
return batches;
|
|
162
|
+
}
|
|
163
|
+
|
|
141
164
|
// ../plugin/src/features/magic-context/storage-embedding-measurements.ts
|
|
142
165
|
import { createHash } from "node:crypto";
|
|
143
166
|
function normalizedQueryHash(query) {
|
|
@@ -596,27 +619,6 @@ class OpenAICompatibleEmbeddingProvider {
|
|
|
596
619
|
// ../plugin/src/features/magic-context/project-embedding-registry.ts
|
|
597
620
|
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
598
621
|
|
|
599
|
-
// ../plugin/src/shared/background-batch-drain.ts
|
|
600
|
-
async function drainBackgroundBatches(step, options = {}) {
|
|
601
|
-
const now = options.now ?? (() => performance.now());
|
|
602
|
-
const deadline = now() + (options.budgetMs ?? 2000);
|
|
603
|
-
const yieldFn = options.yieldFn ?? (() => new Promise((resolve) => setTimeout(resolve, 0)));
|
|
604
|
-
let batches = 0;
|
|
605
|
-
while (now() < deadline) {
|
|
606
|
-
try {
|
|
607
|
-
if (!withoutSqliteTransformPass2(() => withSqliteBackgroundWriter2(step)))
|
|
608
|
-
break;
|
|
609
|
-
} catch (error) {
|
|
610
|
-
if (isTransientSqliteError2(error))
|
|
611
|
-
break;
|
|
612
|
-
throw error;
|
|
613
|
-
}
|
|
614
|
-
batches++;
|
|
615
|
-
await yieldFn();
|
|
616
|
-
}
|
|
617
|
-
return batches;
|
|
618
|
-
}
|
|
619
|
-
|
|
620
622
|
// ../plugin/src/features/magic-context/git-commits/storage-git-commit-embeddings.ts
|
|
621
623
|
var saveStatements = new WeakMap;
|
|
622
624
|
var loadProjectStatements = new WeakMap;
|
|
@@ -3023,4 +3025,4 @@ function _resetProjectEmbeddingRegistryForTests2() {
|
|
|
3023
3025
|
setBootQuietPeriodForTests(null);
|
|
3024
3026
|
}
|
|
3025
3027
|
|
|
3026
|
-
export { recordSessionProjectIdentity, recordEmbeddingMeasurement, OpenAICompatibleEmbeddingProvider,
|
|
3028
|
+
export { recordSessionProjectIdentity, drainBackgroundBatches, recordEmbeddingMeasurement, OpenAICompatibleEmbeddingProvider, saveCommitEmbedding, loadProjectCommitEmbeddings, loadUnembeddedCommits, countEmbeddedCommits, upsertCommits, getLatestIndexedCommitSha, enforceProjectCap, GIT_SWEEP_LEASE_RENEWAL_MS, acquireGitSweepLease, renewGitSweepLease, markGitSweepSuccessAndRelease, parkGitSweepNonIndexable, releaseGitSweepLease, 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 };
|
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
} from "./index-135e8hvg.js";
|
|
4
4
|
import {
|
|
5
5
|
log2
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-x3dcnxh0.js";
|
|
7
7
|
import {
|
|
8
8
|
ensureColumn,
|
|
9
9
|
healAllNullColumns,
|
|
10
10
|
installV95PerfSchema
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-mcgehvgw.js";
|
|
12
12
|
import {
|
|
13
13
|
resolveOpenCodeDbPath,
|
|
14
14
|
openCodeDbPathExists,
|
|
@@ -20,10 +20,10 @@ import {
|
|
|
20
20
|
import {
|
|
21
21
|
normalizeStoredProjectPath,
|
|
22
22
|
storedPathBelongsToIdentity
|
|
23
|
-
} from "./index-
|
|
23
|
+
} from "./index-g7hndmqm.js";
|
|
24
24
|
import {
|
|
25
25
|
logSlowWriteTransaction
|
|
26
|
-
} from "./index-
|
|
26
|
+
} from "./index-0vrkp1jq.js";
|
|
27
27
|
|
|
28
28
|
// ../plugin/src/features/magic-context/migrations.ts
|
|
29
29
|
import { isMainThread } from "node:worker_threads";
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
|
-
DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
3
|
-
|
|
4
|
-
} from "./index-6pgq5ns2.js";
|
|
2
|
+
DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
3
|
+
} from "./index-cyrnv16r.js";
|
|
5
4
|
import {
|
|
6
5
|
log2
|
|
7
|
-
} from "./index-
|
|
6
|
+
} from "./index-x3dcnxh0.js";
|
|
8
7
|
import {
|
|
9
8
|
isSynapseEmbeddingTruncated,
|
|
10
9
|
SynapseEmbeddingProvider
|
|
11
|
-
} from "./index-
|
|
10
|
+
} from "./index-21v1kfs7.js";
|
|
11
|
+
import {
|
|
12
|
+
LocalEmbeddingProvider
|
|
13
|
+
} from "./index-gc2749rx.js";
|
|
12
14
|
import {
|
|
13
15
|
OpenAICompatibleEmbeddingProvider,
|
|
14
16
|
getProjectEmbeddingSnapshot2,
|
|
15
17
|
embedBatchForProject2
|
|
16
|
-
} from "./index-
|
|
18
|
+
} from "./index-r874cgmv.js";
|
|
17
19
|
import {
|
|
18
20
|
isEmbeddingHostBusy2
|
|
19
21
|
} from "./index-9p40dgkm.js";
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./index-3cgbv47m.js";
|
|
5
5
|
import {
|
|
6
6
|
log2
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-x3dcnxh0.js";
|
|
8
8
|
|
|
9
9
|
// ../plugin/src/hooks/magic-context/read-session-raw.ts
|
|
10
10
|
import { isMainThread } from "node:worker_threads";
|
|
@@ -312,30 +312,46 @@ function readRawMessagePageRows(db, sessionId, afterOrdinal, limit, finalWaterma
|
|
|
312
312
|
const pageSize = Math.min(Math.max(1, Math.floor(limit)), remaining);
|
|
313
313
|
if (pageSize === 0)
|
|
314
314
|
return [];
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
315
|
+
return withReadSnapshot(db, () => {
|
|
316
|
+
const ordinal = Math.max(0, Math.floor(afterOrdinal));
|
|
317
|
+
const points = currentOrdinalCheckpoints(db, sessionId)?.scan.checkpoints ?? [];
|
|
318
|
+
let low = 0;
|
|
319
|
+
let high = points.length;
|
|
320
|
+
while (low < high) {
|
|
321
|
+
const middle = Math.floor((low + high) / 2);
|
|
322
|
+
if (points[middle].ordinal <= ordinal)
|
|
323
|
+
low = middle + 1;
|
|
324
|
+
else
|
|
325
|
+
high = middle;
|
|
326
|
+
}
|
|
327
|
+
const floor = points[low - 1];
|
|
328
|
+
const useFloor = floor && (!after || compareOrdinalKeys(floor, after) > 0);
|
|
329
|
+
const anchor = useFloor ? floor : after;
|
|
330
|
+
const skip = anchor === after && after ? 0 : ordinal - (floor?.ordinal ?? 0);
|
|
331
|
+
if (skip > ORDINAL_LOOKUP_LIMIT) {
|
|
332
|
+
prewarmRawSessionOrdinalsForDb(db, sessionId);
|
|
333
|
+
throw new RawOrdinalsNotReady;
|
|
334
|
+
}
|
|
335
|
+
const rawLimit = skip + pageSize + ORDINAL_LOOKUP_LIMIT;
|
|
336
|
+
const rows = db.prepare(`SELECT id, data, time_created, time_updated, ${EXCLUDED_ROW_SQL} AS excluded
|
|
337
|
+
FROM message WHERE id IN (
|
|
338
|
+
SELECT id FROM message WHERE session_id = ?
|
|
339
|
+
${anchor ? "AND (time_created, id) > (?, ?)" : ""}
|
|
340
|
+
ORDER BY time_created, id LIMIT ?)
|
|
341
|
+
ORDER BY time_created, id`).all(sessionId, ...anchor ? [anchor.timeCreated, anchor.id] : [], rawLimit);
|
|
342
|
+
rawMessagePageRowsVisited += rows.length;
|
|
343
|
+
const eligible = rows.filter((row) => row.excluded !== 1);
|
|
344
|
+
if (eligible.length <= skip && rows.length === rawLimit) {
|
|
345
|
+
prewarmRawSessionOrdinalsForDb(db, sessionId);
|
|
346
|
+
throw new RawOrdinalsNotReady;
|
|
347
|
+
}
|
|
348
|
+
return eligible.slice(skip, skip + pageSize).filter(isRawMessageRow).map((row, index) => ({
|
|
349
|
+
...row,
|
|
350
|
+
ordinal: ordinal + index + 1
|
|
351
|
+
}));
|
|
352
|
+
});
|
|
338
353
|
}
|
|
354
|
+
var rawMessagePageRowsVisited = 0;
|
|
339
355
|
function assembleRawMessagePage(messageRows, partRows) {
|
|
340
356
|
const partsByMessageId = new Map;
|
|
341
357
|
for (const part of partRows) {
|
|
@@ -1123,5 +1139,124 @@ function readRawSeedTailFromDb2(db, sessionId, boundaryId) {
|
|
|
1123
1139
|
throw new Error("state_sync materialized boundary is missing from raw storage");
|
|
1124
1140
|
return messages;
|
|
1125
1141
|
}
|
|
1142
|
+
var BOUNDARY_ORDINAL_SQL = `
|
|
1143
|
+
SELECT id, ordinal FROM (
|
|
1144
|
+
SELECT id, ROW_NUMBER() OVER (ORDER BY time_created, id) AS ordinal
|
|
1145
|
+
FROM message
|
|
1146
|
+
WHERE session_id = ?
|
|
1147
|
+
AND typeof(id) = 'text' AND typeof(data) = 'text'
|
|
1148
|
+
AND CASE WHEN json_valid(data) THEN NOT (
|
|
1149
|
+
COALESCE(json_type(data, '$.summary'), '') = 'true'
|
|
1150
|
+
AND COALESCE(json_extract(data, '$.finish'), '') = 'stop'
|
|
1151
|
+
) ELSE 1 END
|
|
1152
|
+
)
|
|
1153
|
+
WHERE id IN (SELECT value FROM json_each(?))`;
|
|
1154
|
+
var BOUNDARY_MESSAGE_SQL = `
|
|
1155
|
+
SELECT id, data, time_created FROM message
|
|
1156
|
+
WHERE +session_id = ? AND id IN (SELECT value FROM json_each(?))`;
|
|
1157
|
+
var BOUNDARY_BLOCK_COUNT_SQL = `
|
|
1158
|
+
SELECT message_id AS id, SUM(
|
|
1159
|
+
CASE
|
|
1160
|
+
WHEN NOT json_valid(data) OR json_type(data) <> 'object' THEN 0
|
|
1161
|
+
ELSE CASE (CASE WHEN json_type(data, '$.type') = 'text'
|
|
1162
|
+
THEN json_extract(data, '$.type') ELSE 'unknown' END)
|
|
1163
|
+
WHEN 'text' THEN CASE WHEN json_type(data, '$.ignored') = 'true' THEN 0 ELSE 1 END
|
|
1164
|
+
WHEN 'reasoning' THEN 1
|
|
1165
|
+
WHEN 'thinking' THEN 1
|
|
1166
|
+
WHEN 'redacted_thinking' THEN 1
|
|
1167
|
+
WHEN 'tool' THEN 1 + CASE
|
|
1168
|
+
WHEN json_type(data, '$.state') = 'object'
|
|
1169
|
+
AND json_type(data, '$.state.status') = 'text'
|
|
1170
|
+
AND json_extract(data, '$.state.status') IN ('completed', 'error')
|
|
1171
|
+
THEN 1 ELSE 0 END
|
|
1172
|
+
WHEN 'compaction' THEN 0
|
|
1173
|
+
WHEN 'step-finish' THEN 0
|
|
1174
|
+
WHEN 'snapshot' THEN 0
|
|
1175
|
+
WHEN 'patch' THEN 0
|
|
1176
|
+
WHEN 'agent' THEN 0
|
|
1177
|
+
WHEN 'retry' THEN 0
|
|
1178
|
+
ELSE 1
|
|
1179
|
+
END
|
|
1180
|
+
END) AS blocks
|
|
1181
|
+
FROM part
|
|
1182
|
+
WHERE +session_id = ?
|
|
1183
|
+
AND message_id IN (SELECT value FROM json_each(?))
|
|
1184
|
+
AND typeof(message_id) = 'text' AND typeof(data) = 'text'
|
|
1185
|
+
GROUP BY message_id`;
|
|
1186
|
+
var boundaryEndpointCaches = new WeakMap;
|
|
1187
|
+
var BOUNDARY_ENDPOINT_CACHE_SESSIONS = 16;
|
|
1188
|
+
var boundaryEndpointRowsRead = 0;
|
|
1189
|
+
function readBoundaryEndpointRows(db, sessionId, ids, blockIds, into) {
|
|
1190
|
+
if (ids.length > 0) {
|
|
1191
|
+
boundaryEndpointRowsRead += ids.length;
|
|
1192
|
+
const wanted = JSON.stringify(ids);
|
|
1193
|
+
const ordinals = new Map;
|
|
1194
|
+
for (const row of db.prepare(BOUNDARY_ORDINAL_SQL).all(sessionId, wanted)) {
|
|
1195
|
+
ordinals.set(row.id, row.ordinal);
|
|
1196
|
+
}
|
|
1197
|
+
const rows = db.prepare(BOUNDARY_MESSAGE_SQL).all(sessionId, wanted);
|
|
1198
|
+
for (const id of ids)
|
|
1199
|
+
into.set(id, null);
|
|
1200
|
+
for (const row of rows) {
|
|
1201
|
+
if (!isRawMessageRow(row) || typeof row.time_created !== "number")
|
|
1202
|
+
continue;
|
|
1203
|
+
const info = parseJsonRecord(row.data);
|
|
1204
|
+
if (!info || isRawCompactionSummaryInfo(info))
|
|
1205
|
+
continue;
|
|
1206
|
+
into.set(row.id, {
|
|
1207
|
+
ordinal: ordinals.get(row.id) ?? null,
|
|
1208
|
+
createdAt: row.time_created
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
const servable = blockIds.filter((id) => {
|
|
1213
|
+
const endpoint = into.get(id);
|
|
1214
|
+
return endpoint && endpoint.lastBlockIndex === undefined;
|
|
1215
|
+
});
|
|
1216
|
+
if (servable.length === 0)
|
|
1217
|
+
return;
|
|
1218
|
+
const counts = new Map;
|
|
1219
|
+
for (const row of db.prepare(BOUNDARY_BLOCK_COUNT_SQL).all(sessionId, JSON.stringify(servable))) {
|
|
1220
|
+
counts.set(row.id, row.blocks);
|
|
1221
|
+
}
|
|
1222
|
+
for (const id of servable) {
|
|
1223
|
+
const endpoint = into.get(id);
|
|
1224
|
+
if (!endpoint)
|
|
1225
|
+
continue;
|
|
1226
|
+
const blocks = counts.get(id) ?? 0;
|
|
1227
|
+
into.set(id, { ...endpoint, lastBlockIndex: blocks > 0 ? blocks - 1 : 0 });
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
function readRawSessionBoundaryEndpointsFromDb2(db, sessionId, ids, blockIds = []) {
|
|
1231
|
+
const wanted = [...new Set(ids)];
|
|
1232
|
+
const wantedBlocks = [...new Set(blockIds)];
|
|
1233
|
+
let sessions = boundaryEndpointCaches.get(db);
|
|
1234
|
+
if (!sessions) {
|
|
1235
|
+
sessions = new Map;
|
|
1236
|
+
boundaryEndpointCaches.set(db, sessions);
|
|
1237
|
+
}
|
|
1238
|
+
for (let attempt = 1;; attempt += 1) {
|
|
1239
|
+
const before = readStoreStamp(db);
|
|
1240
|
+
const cached = sessions.get(sessionId);
|
|
1241
|
+
const reuse = attempt === 1 && cached && sameStoreStamp(cached.stamp, before);
|
|
1242
|
+
const endpoints = new Map(reuse ? cached.endpoints : []);
|
|
1243
|
+
const missing = wanted.filter((id) => !endpoints.has(id));
|
|
1244
|
+
withReadSnapshot(db, () => readBoundaryEndpointRows(db, sessionId, missing, wantedBlocks, endpoints));
|
|
1245
|
+
const unchanged = before !== null && sameStoreStamp(before, readStoreStamp(db));
|
|
1246
|
+
if (unchanged) {
|
|
1247
|
+
sessions.delete(sessionId);
|
|
1248
|
+
sessions.set(sessionId, { stamp: before, endpoints });
|
|
1249
|
+
while (sessions.size > BOUNDARY_ENDPOINT_CACHE_SESSIONS) {
|
|
1250
|
+
const oldest = sessions.keys().next().value;
|
|
1251
|
+
if (oldest === undefined)
|
|
1252
|
+
break;
|
|
1253
|
+
sessions.delete(oldest);
|
|
1254
|
+
}
|
|
1255
|
+
} else if (reuse) {
|
|
1256
|
+
continue;
|
|
1257
|
+
}
|
|
1258
|
+
return new Map(wanted.map((id) => [id, endpoints.get(id) ?? null]));
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1126
1261
|
|
|
1127
|
-
export { runSessionWarmupWorker, prewarmRawSessionOrdinalsForDb, isStrictGapHealingMessage2, readRawSessionMessagesFromDb2, readRawSessionMessagePageFromDb2, RAW_SUMMARY_TEXT_MAX_CHARS2, readRawSessionMessageSummaryPageFromDb2, countRawSessionMessageOrdinalsFromDb2, readRawSessionMessageIdOrdinalsForRangeFromDb2, readRawSessionMessageOrdinalPageFromDb2, countStoredRawSessionMessagesFromDb2, readRawSessionTailFromDb2, buildInMemoryTailRawMessages2, readRawSessionMessagePartsByIdFromDb2, forgetRawSessionOrdinalWatermark2, forgetRawSessionSummaryRows2, noteRawSessionSummaryRowWritten2, rawOrdinalSummarySeed2, scanRawSessionSummaryRows2, getRawSessionSummaryEpoch2, installRawSessionSummaryScan2, isRawSessionSummaryWarm2, readRawSessionMessageOrdinalByIdFromDb2, readRawSessionMessageByIdFromDb2, hasRawSessionMessageByIdFromDb2, readRawSeedTailFromDb2 };
|
|
1262
|
+
export { runSessionWarmupWorker, prewarmRawSessionOrdinalsForDb, isStrictGapHealingMessage2, readRawSessionMessagesFromDb2, readRawSessionMessagePageFromDb2, RAW_SUMMARY_TEXT_MAX_CHARS2, readRawSessionMessageSummaryPageFromDb2, countRawSessionMessageOrdinalsFromDb2, readRawSessionMessageIdOrdinalsForRangeFromDb2, readRawSessionMessageOrdinalPageFromDb2, countStoredRawSessionMessagesFromDb2, readRawSessionTailFromDb2, buildInMemoryTailRawMessages2, readRawSessionMessagePartsByIdFromDb2, forgetRawSessionOrdinalWatermark2, forgetRawSessionSummaryRows2, noteRawSessionSummaryRowWritten2, rawOrdinalSummarySeed2, scanRawSessionSummaryRows2, getRawSessionSummaryEpoch2, installRawSessionSummaryScan2, isRawSessionSummaryWarm2, readRawSessionMessageOrdinalByIdFromDb2, readRawSessionMessageByIdFromDb2, hasRawSessionMessageByIdFromDb2, readRawSeedTailFromDb2, readRawSessionBoundaryEndpointsFromDb2 };
|
|
@@ -552,8 +552,12 @@ function flush() {
|
|
|
552
552
|
let currentSize = getCurrentLogSize(logFile);
|
|
553
553
|
const dataSize = Buffer.byteLength(data);
|
|
554
554
|
if (currentSize > 0 && currentSize + dataSize > MAX_LOG_FILE_BYTES) {
|
|
555
|
-
|
|
556
|
-
currentSize =
|
|
555
|
+
flushesSinceSizeCheck = SIZE_CHECK_INTERVAL_FLUSHES;
|
|
556
|
+
currentSize = getCurrentLogSize(logFile);
|
|
557
|
+
if (currentSize > 0 && currentSize + dataSize > MAX_LOG_FILE_BYTES) {
|
|
558
|
+
rotateLogFile(logFile, currentSize);
|
|
559
|
+
currentSize = 0;
|
|
560
|
+
}
|
|
557
561
|
}
|
|
558
562
|
fs.appendFileSync(logFile, data, { encoding: "utf8", mode: 384 });
|
|
559
563
|
buffer = [];
|
|
@@ -134,6 +134,111 @@ function buildHiddenAgentRegistrations(args) {
|
|
|
134
134
|
];
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
+
// ../plugin/src/shared/models-dev-temperature.ts
|
|
138
|
+
import { readFileSync, statSync } from "node:fs";
|
|
139
|
+
import { homedir } from "node:os";
|
|
140
|
+
import { join } from "node:path";
|
|
141
|
+
var CATALOG_PROVIDER_ALIASES = {
|
|
142
|
+
"google-antigravity": "google",
|
|
143
|
+
"opencode-zen": "opencode"
|
|
144
|
+
};
|
|
145
|
+
var ANTIGRAVITY_MODEL_PREFIX = "antigravity-";
|
|
146
|
+
var cached;
|
|
147
|
+
function modelsDevCatalogPath(env = process.env) {
|
|
148
|
+
if (env.OPENCODE_MODELS_PATH)
|
|
149
|
+
return env.OPENCODE_MODELS_PATH;
|
|
150
|
+
return join(env.XDG_CACHE_HOME || join(homedir(), ".cache"), "opencode", "models.json");
|
|
151
|
+
}
|
|
152
|
+
function buildIndex(raw) {
|
|
153
|
+
const index = new Map;
|
|
154
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
155
|
+
return index;
|
|
156
|
+
for (const [providerID, provider] of Object.entries(raw)) {
|
|
157
|
+
const models = provider?.models;
|
|
158
|
+
if (!models || typeof models !== "object")
|
|
159
|
+
continue;
|
|
160
|
+
for (const [modelID, model] of Object.entries(models)) {
|
|
161
|
+
const temperature = model?.temperature;
|
|
162
|
+
if (typeof temperature === "boolean")
|
|
163
|
+
index.set(`${providerID}/${modelID}`, temperature);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return index;
|
|
167
|
+
}
|
|
168
|
+
function loadIndex() {
|
|
169
|
+
const path = modelsDevCatalogPath();
|
|
170
|
+
try {
|
|
171
|
+
const stat = statSync(path);
|
|
172
|
+
if (cached?.path === path && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size)
|
|
173
|
+
return cached.index;
|
|
174
|
+
const index = buildIndex(JSON.parse(readFileSync(path, "utf8")));
|
|
175
|
+
cached = { path, mtimeMs: stat.mtimeMs, size: stat.size, index };
|
|
176
|
+
return index;
|
|
177
|
+
} catch {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function catalogCandidates(providerID, modelID) {
|
|
182
|
+
const provider = Object.hasOwn(CATALOG_PROVIDER_ALIASES, providerID) ? CATALOG_PROVIDER_ALIASES[providerID] : providerID;
|
|
183
|
+
const candidates = [`${provider}/${modelID}`];
|
|
184
|
+
if (provider === "google" && modelID.startsWith(ANTIGRAVITY_MODEL_PREFIX))
|
|
185
|
+
candidates.push(`google/${modelID.slice(ANTIGRAVITY_MODEL_PREFIX.length)}`);
|
|
186
|
+
return candidates;
|
|
187
|
+
}
|
|
188
|
+
function catalogTemperature(model) {
|
|
189
|
+
const slash = model.indexOf("/");
|
|
190
|
+
if (slash <= 0 || slash === model.length - 1)
|
|
191
|
+
return;
|
|
192
|
+
const index = loadIndex();
|
|
193
|
+
if (!index)
|
|
194
|
+
return;
|
|
195
|
+
for (const entry of catalogCandidates(model.slice(0, slash), model.slice(slash + 1))) {
|
|
196
|
+
const temperature = index.get(entry);
|
|
197
|
+
if (temperature !== undefined)
|
|
198
|
+
return { temperature, entry };
|
|
199
|
+
}
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ../plugin/src/shared/subagent-temperature.ts
|
|
204
|
+
var loggedDecisions = new Set;
|
|
205
|
+
function temperatureCapability(metadata) {
|
|
206
|
+
if (!metadata || typeof metadata !== "object")
|
|
207
|
+
return;
|
|
208
|
+
const model = metadata;
|
|
209
|
+
const supported = model.capabilities?.temperature ?? model.temperature ?? model.compat?.supportsTemperature ?? model.compat?.supportsSamplingParams;
|
|
210
|
+
return typeof supported === "boolean" ? supported : undefined;
|
|
211
|
+
}
|
|
212
|
+
function resolveTemperatureCapability(model, metadata) {
|
|
213
|
+
const host = temperatureCapability(metadata);
|
|
214
|
+
if (host !== undefined)
|
|
215
|
+
return { supported: host, source: "host" };
|
|
216
|
+
const catalog = catalogTemperature(model);
|
|
217
|
+
if (catalog)
|
|
218
|
+
return { supported: catalog.temperature, source: "catalog", entry: catalog.entry };
|
|
219
|
+
return { supported: undefined, source: "none" };
|
|
220
|
+
}
|
|
221
|
+
function describeTemperatureDecision(model, decision) {
|
|
222
|
+
const verdict = decision.supported === true ? "sent" : "omitted";
|
|
223
|
+
const answer = decision.supported === true ? "yes" : "no";
|
|
224
|
+
const reason = decision.source === "host" ? `host model metadata says ${answer}` : decision.source === "catalog" ? `models.dev cache entry ${decision.entry ?? "unknown"} says ${answer}` : "no host or models.dev metadata";
|
|
225
|
+
return `Subagent temperature ${verdict} for ${model}: ${reason}`;
|
|
226
|
+
}
|
|
227
|
+
function logTemperatureDecision(model, decision, log) {
|
|
228
|
+
const key = `${model}\x00${decision.source}\x00${decision.supported}\x00${decision.entry ?? ""}`;
|
|
229
|
+
if (loggedDecisions.has(key))
|
|
230
|
+
return;
|
|
231
|
+
loggedDecisions.add(key);
|
|
232
|
+
log(describeTemperatureDecision(model, decision), decision);
|
|
233
|
+
}
|
|
234
|
+
function subagentTemperature(model, metadata, temperature, log) {
|
|
235
|
+
if (temperature === undefined)
|
|
236
|
+
return;
|
|
237
|
+
const decision = resolveTemperatureCapability(model, metadata);
|
|
238
|
+
logTemperatureDecision(model, decision, log);
|
|
239
|
+
return decision.supported === true ? temperature : undefined;
|
|
240
|
+
}
|
|
241
|
+
|
|
137
242
|
// src/subagent-telemetry.ts
|
|
138
243
|
import { createHash } from "node:crypto";
|
|
139
244
|
var stepCaps = new Map(buildHiddenAgentRegistrations({
|
|
@@ -250,4 +355,4 @@ function readHostSystemPrompt(ctx) {
|
|
|
250
355
|
return;
|
|
251
356
|
}
|
|
252
357
|
|
|
253
|
-
export { buildHiddenAgentRegistrations, subagentStepCap, promptFingerprint, SubagentTelemetry, readHostSystemPrompt };
|
|
358
|
+
export { buildHiddenAgentRegistrations, logTemperatureDecision, subagentTemperature, subagentStepCap, promptFingerprint, SubagentTelemetry, readHostSystemPrompt };
|