@cortexkit/pi-magic-context 0.45.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/embedding-worker.js +4 -4
- package/dist/{index-j0mbc5vj.js → index-266qrgss.js} +59 -1
- package/dist/index-2p1e8706.js +30 -0
- package/dist/{index-k0yd1ph9.js → index-4vfrjwf6.js} +129 -166
- package/dist/{index-g0xfx1c2.js → index-phh7e055.js} +16 -1
- package/dist/{index-ttf0cqq8.js → index-sg8zbjs0.js} +23 -24
- package/dist/index-td885aah.js +576 -0
- package/dist/index-vf38qhee.js +150 -0
- package/dist/{index-2bw9k8nx.js → index-vhzmjpsk.js} +1308 -1019
- package/dist/{index-2pbbk3en.js → index-wv28nczk.js} +55 -1
- package/dist/{index-vxjgsr9m.js → index-xvw8zptx.js} +3565 -3349
- package/dist/index.js +3136 -1449
- package/dist/{message-time-backfill-g83dkh8m.js → message-time-backfill-4688z1k2.js} +2 -2
- package/dist/migration-worker.js +11 -6
- package/dist/{read-session-chunk-kmt7a6zj.js → read-session-chunk-tc6yn2pe.js} +5 -5
- package/dist/subagent-entry.js +10 -10
- package/package.json +4 -3
- package/dist/index-4d3cba70.js +0 -10
- package/dist/index-7s5yk3za.js +0 -16
- package/dist/index-e16q5sd7.js +0 -240
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
withSqliteBackgroundWriter,
|
|
3
3
|
withoutSqliteTransformPass
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-wv28nczk.js";
|
|
5
5
|
import"./index-7n8gb6j3.js";
|
|
6
6
|
import {
|
|
7
7
|
logSlowWriteTransaction
|
|
8
|
-
} from "./index-
|
|
8
|
+
} from "./index-2p1e8706.js";
|
|
9
9
|
|
|
10
10
|
// ../plugin/src/features/magic-context/message-time-backfill.ts
|
|
11
11
|
var MESSAGE_TIME_BACKFILL_BATCH_SIZE = 500;
|
package/dist/migration-worker.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
setLogLineForwarder
|
|
2
|
+
setLogLineForwarder,
|
|
3
|
+
log
|
|
3
4
|
} from "./index-7n8gb6j3.js";
|
|
4
5
|
import {
|
|
5
6
|
Database
|
|
6
|
-
} from "./index-
|
|
7
|
+
} from "./index-wv28nczk.js";
|
|
7
8
|
import {
|
|
8
9
|
runMigrationsWithRetry,
|
|
9
10
|
setSqlitePragmaConfig,
|
|
10
11
|
initializeDatabase
|
|
11
|
-
} from "./index-
|
|
12
|
+
} from "./index-4vfrjwf6.js";
|
|
12
13
|
import {
|
|
13
14
|
closeQuietly
|
|
14
|
-
} from "./index-
|
|
15
|
-
import"./index-
|
|
16
|
-
import"./index-
|
|
15
|
+
} from "./index-td885aah.js";
|
|
16
|
+
import"./index-266qrgss.js";
|
|
17
|
+
import"./index-2p1e8706.js";
|
|
17
18
|
|
|
18
19
|
// ../plugin/src/features/magic-context/migration-worker.ts
|
|
19
20
|
import { parentPort, workerData } from "node:worker_threads";
|
|
@@ -36,6 +37,10 @@ async function main() {
|
|
|
36
37
|
post({ type: "lock-wait", waiting: false });
|
|
37
38
|
}
|
|
38
39
|
});
|
|
40
|
+
const finished = db;
|
|
41
|
+
db = undefined;
|
|
42
|
+
finished.close();
|
|
43
|
+
log(`[migrations] migration worker connection closed: ${data.dbPath}`);
|
|
39
44
|
post({ type: "done" });
|
|
40
45
|
} catch (error) {
|
|
41
46
|
post({
|
|
@@ -32,14 +32,14 @@ import {
|
|
|
32
32
|
readSessionChunk2,
|
|
33
33
|
getRawSessionMessageIdsThrough2,
|
|
34
34
|
readRawSessionSeedTail2
|
|
35
|
-
} from "./index-
|
|
36
|
-
import"./index-
|
|
37
|
-
import"./index-
|
|
35
|
+
} from "./index-xvw8zptx.js";
|
|
36
|
+
import"./index-phh7e055.js";
|
|
37
|
+
import"./index-td885aah.js";
|
|
38
38
|
import {
|
|
39
39
|
hasMeaningfulUserText2,
|
|
40
40
|
extractTexts2
|
|
41
|
-
} from "./index-
|
|
42
|
-
import"./index-
|
|
41
|
+
} from "./index-266qrgss.js";
|
|
42
|
+
import"./index-wv28nczk.js";
|
|
43
43
|
import"./index-7n8gb6j3.js";
|
|
44
44
|
export {
|
|
45
45
|
RAW_MESSAGE_VISIT_PAGE_SIZE2 as RAW_MESSAGE_VISIT_PAGE_SIZE,
|
package/dist/subagent-entry.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TOKEN_BUDGET_TOOL_REFUSAL
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-xvw8zptx.js";
|
|
4
4
|
import {
|
|
5
5
|
setHarness,
|
|
6
6
|
log
|
|
@@ -8,22 +8,22 @@ import {
|
|
|
8
8
|
import {
|
|
9
9
|
resolveProjectIdentityForSession,
|
|
10
10
|
openDatabase
|
|
11
|
-
} from "./index-
|
|
12
|
-
import"./index-
|
|
13
|
-
import"./index-
|
|
14
|
-
import"./index-
|
|
11
|
+
} from "./index-4vfrjwf6.js";
|
|
12
|
+
import"./index-wv28nczk.js";
|
|
13
|
+
import"./index-td885aah.js";
|
|
14
|
+
import"./index-266qrgss.js";
|
|
15
15
|
import {
|
|
16
16
|
loadPiConfig,
|
|
17
17
|
ensureProjectRegisteredFromPiDirectory,
|
|
18
18
|
resolvePiHarnessKind,
|
|
19
19
|
registerMagicContextTools
|
|
20
|
-
} from "./index-
|
|
21
|
-
import"./index-
|
|
22
|
-
import"./index-
|
|
20
|
+
} from "./index-vhzmjpsk.js";
|
|
21
|
+
import"./index-sg8zbjs0.js";
|
|
22
|
+
import"./index-phh7e055.js";
|
|
23
23
|
import {
|
|
24
24
|
setStoragePrivatePermissionEnforcement
|
|
25
|
-
} from "./index-
|
|
26
|
-
import"./index-
|
|
25
|
+
} from "./index-vf38qhee.js";
|
|
26
|
+
import"./index-2p1e8706.js";
|
|
27
27
|
|
|
28
28
|
// src/subagent-entry.ts
|
|
29
29
|
import { readFileSync } from "node:fs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/pi-magic-context",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"build": "bun ../../scripts/check-bun.mjs && tsc -p ../retina-local-fs/tsconfig.build.json && bun ../../scripts/clean-dist-chunks.mjs dist index.js subagent-entry.js historian-calibration-extension.js transformers-web.js transformers-node-wasm.js && bun build ../plugin/src/features/magic-context/memory/transformers-web-entry.ts --outfile dist/transformers-web.js --target browser --format esm --external onnxruntime-web && bun ../plugin/scripts/build-transformers-node-wasm.ts dist && bun build src/index.ts src/subagent-entry.ts src/historian-calibration-extension.ts ../plugin/src/features/magic-context/memory/embedding-worker.ts ../plugin/src/features/magic-context/migration-worker.ts --outdir dist --entry-naming '[name].[ext]' --target node --format esm --splitting --external @earendil-works/pi-coding-agent --external @earendil-works/pi-tui --external onnxruntime-node --external onnxruntime-web --external sharp --external node:sqlite",
|
|
33
33
|
"build:e2e-argv": "bun ../../scripts/clean-dist-chunks.mjs ../../tests/docker/.generated subagent-runner-e2e.mjs && bun build src/subagent-runner.ts --outdir ../../tests/docker/.generated --entry-naming 'subagent-runner-e2e.mjs' --splitting --target node --format esm --external node:sqlite && node --input-type=module -e 'const { __test } = await import(\"../../tests/docker/.generated/subagent-runner-e2e.mjs\"); if (typeof __test.buildArgs !== \"function\" || typeof __test.resolvePiInvocation !== \"function\") throw new Error(\"argv renderer exports missing\"); console.log(\"Node argv renderer: 2 exports loaded\")'",
|
|
34
34
|
"typecheck": "tsc -p ../retina-local-fs/tsconfig.build.json && tsc --noEmit",
|
|
35
|
-
"test": "bun ../../scripts/check-bun.mjs && bun install --frozen-lockfile && bun test --parallel --timeout 30000",
|
|
36
|
-
"test:serial": "bun install --frozen-lockfile && bun test --timeout 30000",
|
|
35
|
+
"test": "bun ../../scripts/check-bun.mjs && bun install --frozen-lockfile && BUN_JSC_useOMGJIT=0 bun test --parallel --timeout 30000",
|
|
36
|
+
"test:serial": "bun install --frozen-lockfile && BUN_JSC_useOMGJIT=0 bun test --timeout 30000",
|
|
37
37
|
"lint": "bun ../../scripts/check-bun.mjs && biome check src",
|
|
38
38
|
"lint:fix": "biome check --write src",
|
|
39
39
|
"format": "biome format --write src",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"clean": "bun ../../scripts/clean-dist-chunks.mjs dist index.js subagent-entry.js historian-calibration-extension.js embedding-worker.js migration-worker.js transformers-web.js transformers-node-wasm.js",
|
|
42
42
|
"prepublishOnly": "bun run build"
|
|
43
43
|
},
|
|
44
|
+
"//test": "Only test runs disable JSC's optimizing WebAssembly tier so per-file isolation does not pay its compilation cost on every file. This is not a production setting and does not change host process engine options.",
|
|
44
45
|
"dependencies": {
|
|
45
46
|
"@cortexkit/subc-client": "0.11.1",
|
|
46
47
|
"@jitl/quickjs-singlefile-cjs-release-asyncify": "0.32.0",
|
package/dist/index-4d3cba70.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// ../plugin/src/shared/storage-permissions.ts
|
|
2
|
-
var enforcePrivateStoragePermissions = true;
|
|
3
|
-
function setStoragePrivatePermissionEnforcement(enforce) {
|
|
4
|
-
enforcePrivateStoragePermissions = enforce;
|
|
5
|
-
}
|
|
6
|
-
function shouldEnforcePrivateStoragePermissions() {
|
|
7
|
-
return enforcePrivateStoragePermissions;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export { setStoragePrivatePermissionEnforcement, shouldEnforcePrivateStoragePermissions };
|
package/dist/index-7s5yk3za.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
log
|
|
3
|
-
} from "./index-7n8gb6j3.js";
|
|
4
|
-
|
|
5
|
-
// ../plugin/src/shared/write-transaction-timing.ts
|
|
6
|
-
var SLOW_WRITE_TRANSACTION_THRESHOLD_MS = 1000;
|
|
7
|
-
function logSlowWriteTransaction(site, startedAt, thresholdMs = SLOW_WRITE_TRANSACTION_THRESHOLD_MS, completedAtMs = performance.now()) {
|
|
8
|
-
try {
|
|
9
|
-
const durationMs = completedAtMs - startedAt;
|
|
10
|
-
if (durationMs < thresholdMs)
|
|
11
|
-
return;
|
|
12
|
-
log(`[magic-context] slow write transaction: site=${site} held=${durationMs.toFixed(1)}ms`);
|
|
13
|
-
} catch {}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export { logSlowWriteTransaction };
|
package/dist/index-e16q5sd7.js
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
// ../plugin/src/shared/sqlite-helpers.ts
|
|
2
|
-
function closeQuietly(db) {
|
|
3
|
-
if (!db)
|
|
4
|
-
return;
|
|
5
|
-
try {
|
|
6
|
-
db.close();
|
|
7
|
-
} catch {}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// ../plugin/src/shared/stable-json.ts
|
|
11
|
-
function stableStringify(value, seen = new WeakSet) {
|
|
12
|
-
if (value === undefined)
|
|
13
|
-
return "undefined";
|
|
14
|
-
if (value === null || typeof value !== "object")
|
|
15
|
-
return JSON.stringify(value) ?? String(value);
|
|
16
|
-
if (seen.has(value))
|
|
17
|
-
return '"[Circular]"';
|
|
18
|
-
seen.add(value);
|
|
19
|
-
if (Array.isArray(value)) {
|
|
20
|
-
return `[${value.map((item) => stableStringify(item, seen)).join(",")}]`;
|
|
21
|
-
}
|
|
22
|
-
const entries = Object.entries(value).sort(([a], [b]) => {
|
|
23
|
-
if (a < b)
|
|
24
|
-
return -1;
|
|
25
|
-
if (a > b)
|
|
26
|
-
return 1;
|
|
27
|
-
return 0;
|
|
28
|
-
});
|
|
29
|
-
return `{${entries.map(([key, child]) => `${JSON.stringify(key)}:${stableStringify(child, seen)}`).join(",")}}`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// ../plugin/src/shared/opencode-db-path.ts
|
|
33
|
-
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
34
|
-
import { homedir } from "node:os";
|
|
35
|
-
import { isAbsolute, join, resolve } from "node:path";
|
|
36
|
-
var cachedResolution = null;
|
|
37
|
-
var lastReadFailure = null;
|
|
38
|
-
var claimedDiagnostics = new Set;
|
|
39
|
-
function openCodeDataDir(env = process.env, dataHome) {
|
|
40
|
-
return join(dataHome ?? env.XDG_DATA_HOME ?? join(homedir(), ".local", "share"), "opencode");
|
|
41
|
-
}
|
|
42
|
-
function environmentKey(dataDir, hostGeneration, channel, env) {
|
|
43
|
-
return [
|
|
44
|
-
hostGeneration,
|
|
45
|
-
dataDir,
|
|
46
|
-
env.OPENCODE_DB ?? "",
|
|
47
|
-
env.OPENCODE_DISABLE_CHANNEL_DB ?? "",
|
|
48
|
-
channel ?? env.OPENCODE_CHANNEL ?? ""
|
|
49
|
-
].join("\x00");
|
|
50
|
-
}
|
|
51
|
-
function channelPath(dataDir, channel) {
|
|
52
|
-
return ["latest", "beta", "prod"].includes(channel) ? join(dataDir, "opencode.db") : join(dataDir, `opencode-${channel}.db`);
|
|
53
|
-
}
|
|
54
|
-
function discoveredCandidateNames(dataDir) {
|
|
55
|
-
const names = ["opencode.db", "opencode-local.db", "opencode-dev.db"];
|
|
56
|
-
try {
|
|
57
|
-
const discovered = readdirSync(dataDir, { withFileTypes: true }).filter((entry) => /^opencode-.+\.db$/.test(entry.name) && !names.includes(entry.name)).map((entry) => entry.name).sort();
|
|
58
|
-
names.push(...discovered);
|
|
59
|
-
} catch {}
|
|
60
|
-
return names;
|
|
61
|
-
}
|
|
62
|
-
function discoverOpenCodeDb(dataDir) {
|
|
63
|
-
const candidates = discoveredCandidateNames(dataDir).map((name, order) => {
|
|
64
|
-
const path = join(dataDir, name);
|
|
65
|
-
try {
|
|
66
|
-
const metadata = statSync(path);
|
|
67
|
-
return metadata.isFile() ? { path, order, mtimeMs: metadata.mtimeMs } : null;
|
|
68
|
-
} catch {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
const existing = candidates.filter((candidate) => candidate !== null).sort((left, right) => right.mtimeMs - left.mtimeMs || left.order - right.order)[0];
|
|
73
|
-
if (!existing) {
|
|
74
|
-
return { path: join(dataDir, "opencode.db"), source: "default", channel: null };
|
|
75
|
-
}
|
|
76
|
-
const name = existing.path.slice(dataDir.length + 1);
|
|
77
|
-
const channel = name === "opencode.db" ? null : name.slice("opencode-".length, -".db".length) || null;
|
|
78
|
-
return { path: existing.path, source: "discovered", channel };
|
|
79
|
-
}
|
|
80
|
-
function resolveV1Fresh(dataDir, env = process.env) {
|
|
81
|
-
const explicit = env.OPENCODE_DB;
|
|
82
|
-
if (explicit !== undefined && explicit.length > 0) {
|
|
83
|
-
if (explicit === ":memory:") {
|
|
84
|
-
return { path: explicit, source: "OPENCODE_DB", channel: null };
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
path: isAbsolute(explicit) ? explicit : join(dataDir, explicit),
|
|
88
|
-
source: "OPENCODE_DB",
|
|
89
|
-
channel: null
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
const disableChannelDb = env.OPENCODE_DISABLE_CHANNEL_DB;
|
|
93
|
-
if (disableChannelDb === "1" || disableChannelDb === "true") {
|
|
94
|
-
return { path: join(dataDir, "opencode.db"), source: "default", channel: null };
|
|
95
|
-
}
|
|
96
|
-
const channel = env.OPENCODE_CHANNEL;
|
|
97
|
-
if (channel !== undefined && channel.length > 0) {
|
|
98
|
-
return { path: channelPath(dataDir, channel), source: "channel", channel };
|
|
99
|
-
}
|
|
100
|
-
return discoverOpenCodeDb(dataDir);
|
|
101
|
-
}
|
|
102
|
-
function sourceOpenCodeDatabaseFilename(hostGeneration, channel, env = process.env) {
|
|
103
|
-
if (hostGeneration === "v1") {
|
|
104
|
-
const explicit = env.OPENCODE_DB;
|
|
105
|
-
if (explicit !== undefined && explicit.length > 0)
|
|
106
|
-
return explicit;
|
|
107
|
-
if (env.OPENCODE_DISABLE_CHANNEL_DB === "1" || env.OPENCODE_DISABLE_CHANNEL_DB === "true") {
|
|
108
|
-
return "opencode.db";
|
|
109
|
-
}
|
|
110
|
-
return ["latest", "beta", "prod"].includes(channel) ? "opencode.db" : `opencode-${channel}.db`;
|
|
111
|
-
}
|
|
112
|
-
return env.OPENCODE_DB ?? (["latest", "dev", "beta", "next", "prod"].includes(channel) || env.OPENCODE_DISABLE_CHANNEL_DB === "1" || env.OPENCODE_DISABLE_CHANNEL_DB === "true" ? "opencode.db" : `opencode-${channel.replace(/[^a-zA-Z0-9._-]/g, "")}.db`);
|
|
113
|
-
}
|
|
114
|
-
function resolveV2Fresh(dataDir, channel, env) {
|
|
115
|
-
const filename = sourceOpenCodeDatabaseFilename("v2", channel, env);
|
|
116
|
-
const explicit = env.OPENCODE_DB !== undefined;
|
|
117
|
-
return {
|
|
118
|
-
path: filename === ":memory:" ? filename : resolve(dataDir, filename),
|
|
119
|
-
source: explicit ? "OPENCODE_DB" : env.OPENCODE_CHANNEL ? "channel" : "default",
|
|
120
|
-
channel: explicit ? null : channel
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
function resolveOpenCodeDbPath(hostGeneration = "v1", options = {}) {
|
|
124
|
-
const env = options.env ?? process.env;
|
|
125
|
-
const dataDir = openCodeDataDir(env, options.dataHome);
|
|
126
|
-
const channel = options.channel ?? env.OPENCODE_CHANNEL;
|
|
127
|
-
const key = environmentKey(dataDir, hostGeneration, channel, env);
|
|
128
|
-
if (cachedResolution?.key === key && (!cachedResolution.existed || existsSync(cachedResolution.resolution.path))) {
|
|
129
|
-
if (cachedResolution.existed)
|
|
130
|
-
return cachedResolution.resolution;
|
|
131
|
-
}
|
|
132
|
-
const resolution = hostGeneration === "v2" ? resolveV2Fresh(dataDir, channel ?? "latest", env) : resolveV1Fresh(dataDir, env);
|
|
133
|
-
cachedResolution = {
|
|
134
|
-
key,
|
|
135
|
-
resolution,
|
|
136
|
-
existed: resolution.path !== ":memory:" && existsSync(resolution.path)
|
|
137
|
-
};
|
|
138
|
-
return resolution;
|
|
139
|
-
}
|
|
140
|
-
function schemaTableNames(db, schema = "main") {
|
|
141
|
-
const rows = db.prepare(`SELECT name FROM ${schema}.sqlite_master WHERE type = 'table' AND name IN ('message', 'part', 'session', 'project', 'session_message', 'session_v2')`).all();
|
|
142
|
-
return new Set(rows.flatMap((row) => typeof row.name === "string" ? [row.name] : []));
|
|
143
|
-
}
|
|
144
|
-
function hasV1MessageTables(db, schema = "main") {
|
|
145
|
-
const tables = schemaTableNames(db, schema);
|
|
146
|
-
return tables.has("message") && tables.has("part");
|
|
147
|
-
}
|
|
148
|
-
function detectOpenCodeStoreGeneration(db, schema = "main") {
|
|
149
|
-
const tables = schemaTableNames(db, schema);
|
|
150
|
-
const hasV1Messages = tables.has("message") && tables.has("part");
|
|
151
|
-
if (hasV1Messages)
|
|
152
|
-
return "v1";
|
|
153
|
-
if (tables.has("session_message"))
|
|
154
|
-
return "v2";
|
|
155
|
-
if (tables.has("session") || tables.has("project"))
|
|
156
|
-
return "v1";
|
|
157
|
-
return "unknown";
|
|
158
|
-
}
|
|
159
|
-
function hasMigratedV2Schema(tables) {
|
|
160
|
-
return tables.has("session_message") && tables.has("session_v2");
|
|
161
|
-
}
|
|
162
|
-
function isOpenCodeV2Store(db, schema = "main") {
|
|
163
|
-
return detectOpenCodeStoreGeneration(db, schema) === "v2" || hasMigratedV2Schema(schemaTableNames(db, schema));
|
|
164
|
-
}
|
|
165
|
-
function assertOpenCodeStoreGeneration(db, expected, path, schema = "main") {
|
|
166
|
-
const actual = detectOpenCodeStoreGeneration(db, schema);
|
|
167
|
-
if (actual === expected)
|
|
168
|
-
return;
|
|
169
|
-
if (expected === "v2" && isOpenCodeV2Store(db, schema))
|
|
170
|
-
return;
|
|
171
|
-
if (actual === "unknown")
|
|
172
|
-
return;
|
|
173
|
-
throw new Error(`OpenCode store generation mismatch at ${path}: expected ${expected}, found ${actual}; refusing generation-specific database access`);
|
|
174
|
-
}
|
|
175
|
-
function openCodeDbPathExists(resolution = resolveOpenCodeDbPath()) {
|
|
176
|
-
return resolution.path !== ":memory:" && existsSync(resolution.path);
|
|
177
|
-
}
|
|
178
|
-
function getOpenCodeDbProbeDescriptions(resolution = resolveOpenCodeDbPath()) {
|
|
179
|
-
if (resolution.source === "OPENCODE_DB")
|
|
180
|
-
return [resolution.path];
|
|
181
|
-
if (resolution.source === "channel" || process.env.OPENCODE_DISABLE_CHANNEL_DB === "1" || process.env.OPENCODE_DISABLE_CHANNEL_DB === "true") {
|
|
182
|
-
return [resolution.path];
|
|
183
|
-
}
|
|
184
|
-
const dataDir = openCodeDataDir();
|
|
185
|
-
return [
|
|
186
|
-
join(dataDir, "opencode.db"),
|
|
187
|
-
join(dataDir, "opencode-local.db"),
|
|
188
|
-
join(dataDir, "opencode-dev.db"),
|
|
189
|
-
join(dataDir, "opencode-<channel>.db")
|
|
190
|
-
];
|
|
191
|
-
}
|
|
192
|
-
function recordOpenCodeDbReadFailure(resolution, error) {
|
|
193
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
194
|
-
lastReadFailure = { ...resolution, message };
|
|
195
|
-
return lastReadFailure;
|
|
196
|
-
}
|
|
197
|
-
function clearOpenCodeDbReadFailure(path) {
|
|
198
|
-
if (path === undefined || lastReadFailure?.path === path)
|
|
199
|
-
lastReadFailure = null;
|
|
200
|
-
}
|
|
201
|
-
function claimOpenCodeDbDiagnosticOnce(surface, resolution) {
|
|
202
|
-
const key = `${surface}\x00${resolution.path}\x00${resolution.source}`;
|
|
203
|
-
if (claimedDiagnostics.has(key))
|
|
204
|
-
return false;
|
|
205
|
-
claimedDiagnostics.add(key);
|
|
206
|
-
return true;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// ../plugin/src/features/magic-context/tool-definition-tokens.ts
|
|
210
|
-
var measurements = new Map;
|
|
211
|
-
var fingerprints = new Map;
|
|
212
|
-
var persistenceDb = null;
|
|
213
|
-
var cachedInsertStmt = null;
|
|
214
|
-
function keyFor(providerID, modelID, agentName) {
|
|
215
|
-
const agent = agentName && agentName.length > 0 ? agentName : "default";
|
|
216
|
-
return `${providerID}/${modelID}/${agent}`;
|
|
217
|
-
}
|
|
218
|
-
function setDatabase(db) {
|
|
219
|
-
persistenceDb = db;
|
|
220
|
-
cachedInsertStmt = null;
|
|
221
|
-
}
|
|
222
|
-
function loadToolDefinitionMeasurements(db) {
|
|
223
|
-
let rows = [];
|
|
224
|
-
try {
|
|
225
|
-
rows = db.prepare("SELECT provider_id, model_id, agent_name, tool_id, token_count FROM tool_definition_measurements").all();
|
|
226
|
-
} catch {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
for (const row of rows) {
|
|
230
|
-
const key = keyFor(row.provider_id, row.model_id, row.agent_name);
|
|
231
|
-
let inner = measurements.get(key);
|
|
232
|
-
if (!inner) {
|
|
233
|
-
inner = new Map;
|
|
234
|
-
measurements.set(key, inner);
|
|
235
|
-
}
|
|
236
|
-
inner.set(row.tool_id, row.token_count);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export { stableStringify, resolveOpenCodeDbPath, hasV1MessageTables, assertOpenCodeStoreGeneration, openCodeDbPathExists, getOpenCodeDbProbeDescriptions, recordOpenCodeDbReadFailure, clearOpenCodeDbReadFailure, claimOpenCodeDbDiagnosticOnce, closeQuietly, setDatabase, loadToolDefinitionMeasurements };
|