crosscheck-mcp 0.1.2 → 0.1.3
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/node-stdio.cjs +677 -569
- package/dist/node-stdio.cjs.map +1 -1
- package/dist/node-stdio.d.cts +1 -1
- package/dist/node-stdio.d.ts +1 -1
- package/dist/node-stdio.js +673 -557
- package/dist/node-stdio.js.map +1 -1
- package/package.json +6 -5
package/dist/node-stdio.cjs
CHANGED
|
@@ -6,6 +6,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __esm = (fn, res) => function __init() {
|
|
10
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
|
+
};
|
|
9
12
|
var __export = (target, all) => {
|
|
10
13
|
for (var name in all)
|
|
11
14
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -28,39 +31,28 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
31
|
));
|
|
29
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
33
|
|
|
31
|
-
// src/entrypoints/node-stdio.ts
|
|
32
|
-
var node_stdio_exports = {};
|
|
33
|
-
__export(node_stdio_exports, {
|
|
34
|
-
RecordingEmitter: () => RecordingEmitter,
|
|
35
|
-
SERVER_NAME: () => SERVER_NAME,
|
|
36
|
-
SERVER_VERSION: () => SERVER_VERSION,
|
|
37
|
-
connectAndServe: () => connectAndServe,
|
|
38
|
-
createServer: () => createServer,
|
|
39
|
-
getEventEmitter: () => getEventEmitter,
|
|
40
|
-
setEventEmitter: () => setEventEmitter
|
|
41
|
-
});
|
|
42
|
-
module.exports = __toCommonJS(node_stdio_exports);
|
|
43
|
-
|
|
44
34
|
// node_modules/tsup/assets/cjs_shims.js
|
|
45
|
-
var getImportMetaUrl
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// src/adapters/storage/better-sqlite3.ts
|
|
55
|
-
var import_better_sqlite3 = __toESM(require("better-sqlite3"), 1);
|
|
35
|
+
var getImportMetaUrl, importMetaUrl;
|
|
36
|
+
var init_cjs_shims = __esm({
|
|
37
|
+
"node_modules/tsup/assets/cjs_shims.js"() {
|
|
38
|
+
"use strict";
|
|
39
|
+
getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
40
|
+
importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
56
43
|
|
|
57
44
|
// src/adapters/storage/migrations/0001_init.ts
|
|
58
|
-
var m0001_init
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
45
|
+
var m0001_init;
|
|
46
|
+
var init_init = __esm({
|
|
47
|
+
"src/adapters/storage/migrations/0001_init.ts"() {
|
|
48
|
+
"use strict";
|
|
49
|
+
init_cjs_shims();
|
|
50
|
+
m0001_init = {
|
|
51
|
+
id: "0001_init",
|
|
52
|
+
name: "initial schema (sessions, usage_log, claims, ...)",
|
|
53
|
+
up: [
|
|
54
|
+
// sessions — includes the totals columns that Python adds via ALTER.
|
|
55
|
+
`CREATE TABLE IF NOT EXISTS sessions (
|
|
64
56
|
session_id TEXT PRIMARY KEY,
|
|
65
57
|
started_at INTEGER NOT NULL,
|
|
66
58
|
last_at INTEGER,
|
|
@@ -74,8 +66,8 @@ var m0001_init = {
|
|
|
74
66
|
total_cost_usd REAL NOT NULL DEFAULT 0.0,
|
|
75
67
|
total_cpu_ms INTEGER NOT NULL DEFAULT 0
|
|
76
68
|
)`,
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
// usage_log — per-call ledger.
|
|
70
|
+
`CREATE TABLE IF NOT EXISTS usage_log (
|
|
79
71
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
80
72
|
session_id TEXT NOT NULL,
|
|
81
73
|
ts INTEGER NOT NULL,
|
|
@@ -92,10 +84,10 @@ var m0001_init = {
|
|
|
92
84
|
wall_ms INTEGER NOT NULL DEFAULT 0,
|
|
93
85
|
cpu_ms INTEGER NOT NULL DEFAULT 0
|
|
94
86
|
)`,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
87
|
+
`CREATE INDEX IF NOT EXISTS idx_usage_session ON usage_log(session_id)`,
|
|
88
|
+
`CREATE INDEX IF NOT EXISTS idx_usage_provider ON usage_log(provider)`,
|
|
89
|
+
// claims (FK to sessions, ON DELETE CASCADE).
|
|
90
|
+
`CREATE TABLE IF NOT EXISTS claims (
|
|
99
91
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
100
92
|
session_id TEXT NOT NULL REFERENCES sessions(session_id) ON DELETE CASCADE,
|
|
101
93
|
text TEXT NOT NULL,
|
|
@@ -105,10 +97,10 @@ var m0001_init = {
|
|
|
105
97
|
kind TEXT,
|
|
106
98
|
created_at INTEGER NOT NULL
|
|
107
99
|
)`,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
100
|
+
`CREATE INDEX IF NOT EXISTS idx_claims_session ON claims(session_id)`,
|
|
101
|
+
// claim_links (FK to claims). Kind enum widened in Python's
|
|
102
|
+
// _migrate_claim_links_check; mirrored here as the CHECK clause.
|
|
103
|
+
`CREATE TABLE IF NOT EXISTS claim_links (
|
|
112
104
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
113
105
|
src_id INTEGER NOT NULL REFERENCES claims(id) ON DELETE CASCADE,
|
|
114
106
|
dst_id INTEGER NOT NULL REFERENCES claims(id) ON DELETE CASCADE,
|
|
@@ -116,18 +108,18 @@ var m0001_init = {
|
|
|
116
108
|
created_at INTEGER NOT NULL,
|
|
117
109
|
UNIQUE(src_id, dst_id, kind)
|
|
118
110
|
)`,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
111
|
+
`CREATE INDEX IF NOT EXISTS idx_links_src ON claim_links(src_id)`,
|
|
112
|
+
`CREATE INDEX IF NOT EXISTS idx_links_dst ON claim_links(dst_id)`,
|
|
113
|
+
// provider_stats — ballots accumulator for the smart router.
|
|
114
|
+
`CREATE TABLE IF NOT EXISTS provider_stats (
|
|
123
115
|
provider TEXT PRIMARY KEY,
|
|
124
116
|
wins INTEGER NOT NULL DEFAULT 0,
|
|
125
117
|
losses INTEGER NOT NULL DEFAULT 0,
|
|
126
118
|
abstains INTEGER NOT NULL DEFAULT 0,
|
|
127
119
|
last_at INTEGER
|
|
128
120
|
)`,
|
|
129
|
-
|
|
130
|
-
|
|
121
|
+
// delegations — cross-model handshake ledger.
|
|
122
|
+
`CREATE TABLE IF NOT EXISTS delegations (
|
|
131
123
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
132
124
|
session_id TEXT,
|
|
133
125
|
requester TEXT,
|
|
@@ -136,10 +128,10 @@ var m0001_init = {
|
|
|
136
128
|
accepted INTEGER NOT NULL,
|
|
137
129
|
created_at INTEGER NOT NULL
|
|
138
130
|
)`,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
131
|
+
`CREATE INDEX IF NOT EXISTS idx_deleg_session ON delegations(session_id)`,
|
|
132
|
+
`CREATE INDEX IF NOT EXISTS idx_deleg_req ON delegations(requester)`,
|
|
133
|
+
// session_memory — facts / open_questions / decisions ledger.
|
|
134
|
+
`CREATE TABLE IF NOT EXISTS session_memory (
|
|
143
135
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
144
136
|
session_id TEXT NOT NULL,
|
|
145
137
|
kind TEXT NOT NULL CHECK (kind IN ('fact','open_question','decision')),
|
|
@@ -151,27 +143,37 @@ var m0001_init = {
|
|
|
151
143
|
stale_at INTEGER,
|
|
152
144
|
stale_reason TEXT
|
|
153
145
|
)`,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
146
|
+
`CREATE INDEX IF NOT EXISTS idx_session_memory_session ON session_memory(session_id)`,
|
|
147
|
+
`CREATE INDEX IF NOT EXISTS idx_session_memory_kind ON session_memory(kind)`,
|
|
148
|
+
// fetch_egress — per-session per-host byte ledger.
|
|
149
|
+
`CREATE TABLE IF NOT EXISTS fetch_egress (
|
|
158
150
|
session_id TEXT NOT NULL,
|
|
159
151
|
host TEXT NOT NULL,
|
|
160
152
|
total_bytes INTEGER NOT NULL DEFAULT 0,
|
|
161
153
|
last_at INTEGER NOT NULL,
|
|
162
154
|
PRIMARY KEY (session_id, host)
|
|
163
155
|
)`,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
156
|
+
// transcripts_fts — FTS5 virtual table for the recall tool. Python uses
|
|
157
|
+
// `tokenize='unicode61 remove_diacritics 2'`; mirrored exactly.
|
|
158
|
+
`CREATE VIRTUAL TABLE IF NOT EXISTS transcripts_fts USING fts5(
|
|
167
159
|
session_id, tool, ts UNINDEXED, path UNINDEXED, content,
|
|
168
160
|
tokenize='unicode61 remove_diacritics 2'
|
|
169
161
|
)`
|
|
170
|
-
|
|
171
|
-
};
|
|
162
|
+
]
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
});
|
|
172
166
|
|
|
173
167
|
// src/adapters/storage/migrations/index.ts
|
|
174
|
-
var MIGRATIONS
|
|
168
|
+
var MIGRATIONS;
|
|
169
|
+
var init_migrations = __esm({
|
|
170
|
+
"src/adapters/storage/migrations/index.ts"() {
|
|
171
|
+
"use strict";
|
|
172
|
+
init_cjs_shims();
|
|
173
|
+
init_init();
|
|
174
|
+
MIGRATIONS = [m0001_init];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
175
177
|
|
|
176
178
|
// src/adapters/storage/schema.ts
|
|
177
179
|
function canonicalSchema(reader) {
|
|
@@ -288,19 +290,18 @@ function listFks(reader, table) {
|
|
|
288
290
|
})
|
|
289
291
|
).sort((a, b) => a.id - b.id || a.seq - b.seq);
|
|
290
292
|
}
|
|
293
|
+
var init_schema = __esm({
|
|
294
|
+
"src/adapters/storage/schema.ts"() {
|
|
295
|
+
"use strict";
|
|
296
|
+
init_cjs_shims();
|
|
297
|
+
}
|
|
298
|
+
});
|
|
291
299
|
|
|
292
300
|
// src/adapters/storage/better-sqlite3.ts
|
|
293
|
-
var
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
"merges_with"
|
|
298
|
-
]);
|
|
299
|
-
var ALLOWED_MEMORY_KINDS = /* @__PURE__ */ new Set([
|
|
300
|
-
"fact",
|
|
301
|
-
"open_question",
|
|
302
|
-
"decision"
|
|
303
|
-
]);
|
|
301
|
+
var better_sqlite3_exports = {};
|
|
302
|
+
__export(better_sqlite3_exports, {
|
|
303
|
+
openBetterSqliteStorage: () => openBetterSqliteStorage
|
|
304
|
+
});
|
|
304
305
|
function openBetterSqliteStorage(opts) {
|
|
305
306
|
const db = new import_better_sqlite3.default(opts.path);
|
|
306
307
|
const wantWal = opts.wal ?? opts.path !== ":memory:";
|
|
@@ -310,101 +311,120 @@ function openBetterSqliteStorage(opts) {
|
|
|
310
311
|
db.pragma("foreign_keys = ON");
|
|
311
312
|
return new BetterSqliteStorage(db);
|
|
312
313
|
}
|
|
313
|
-
var
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
"
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
return { applied };
|
|
337
|
-
}
|
|
338
|
-
applyMigration(m) {
|
|
339
|
-
const txn = this.db.transaction(() => {
|
|
340
|
-
for (const stmt of m.up) this.db.exec(stmt);
|
|
341
|
-
this.db.prepare(
|
|
342
|
-
"INSERT INTO schema_migrations(id, applied_at) VALUES (?, ?)"
|
|
343
|
-
).run(m.id, Date.now());
|
|
344
|
-
});
|
|
345
|
-
txn();
|
|
346
|
-
}
|
|
347
|
-
async canonicalSchema() {
|
|
348
|
-
const reader = {
|
|
349
|
-
pragma: (name, arg) => arg === void 0 ? this.db.pragma(name) : this.db.pragma(`${name}('${arg.replace(/'/g, "''")}')`),
|
|
350
|
-
list: (sql) => this.db.prepare(sql).all()
|
|
351
|
-
};
|
|
352
|
-
return canonicalSchema(reader);
|
|
353
|
-
}
|
|
354
|
-
unsafe() {
|
|
355
|
-
return {
|
|
356
|
-
exec: async (sql, params) => {
|
|
357
|
-
const stmt = this.db.prepare(sql);
|
|
358
|
-
const info = stmt.run(...params ?? []);
|
|
359
|
-
return Number(info.changes);
|
|
360
|
-
},
|
|
361
|
-
query: async (sql, params) => this.db.prepare(sql).all(...params ?? [])
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
async close() {
|
|
365
|
-
this.db.close();
|
|
366
|
-
}
|
|
367
|
-
// ------------------------------------------------------------------
|
|
368
|
-
// Transactions. better-sqlite3 supports nested transactions via
|
|
369
|
-
// SAVEPOINTs automatically when the outer caller is already inside
|
|
370
|
-
// db.transaction(). We expose a Txn that mirrors Storage's surface;
|
|
371
|
-
// every method call inside the callback runs inside the open txn.
|
|
372
|
-
// ------------------------------------------------------------------
|
|
373
|
-
async txn(fn) {
|
|
374
|
-
this.db.exec("BEGIN IMMEDIATE");
|
|
375
|
-
try {
|
|
376
|
-
const result = await fn(this);
|
|
377
|
-
this.db.exec("COMMIT");
|
|
378
|
-
return result;
|
|
379
|
-
} catch (e) {
|
|
380
|
-
try {
|
|
381
|
-
this.db.exec("ROLLBACK");
|
|
382
|
-
} catch {
|
|
314
|
+
var import_better_sqlite3, ALLOWED_LINK_KINDS, ALLOWED_MEMORY_KINDS, BetterSqliteStorage;
|
|
315
|
+
var init_better_sqlite3 = __esm({
|
|
316
|
+
"src/adapters/storage/better-sqlite3.ts"() {
|
|
317
|
+
"use strict";
|
|
318
|
+
init_cjs_shims();
|
|
319
|
+
import_better_sqlite3 = __toESM(require("better-sqlite3"), 1);
|
|
320
|
+
init_migrations();
|
|
321
|
+
init_schema();
|
|
322
|
+
ALLOWED_LINK_KINDS = /* @__PURE__ */ new Set([
|
|
323
|
+
"supports",
|
|
324
|
+
"attacks",
|
|
325
|
+
"derives_from",
|
|
326
|
+
"merges_with"
|
|
327
|
+
]);
|
|
328
|
+
ALLOWED_MEMORY_KINDS = /* @__PURE__ */ new Set([
|
|
329
|
+
"fact",
|
|
330
|
+
"open_question",
|
|
331
|
+
"decision"
|
|
332
|
+
]);
|
|
333
|
+
BetterSqliteStorage = class {
|
|
334
|
+
constructor(db) {
|
|
335
|
+
this.db = db;
|
|
383
336
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
337
|
+
db;
|
|
338
|
+
stmts = /* @__PURE__ */ new Map();
|
|
339
|
+
// ------------------------------------------------------------------
|
|
340
|
+
// Lifecycle / lifetime
|
|
341
|
+
// ------------------------------------------------------------------
|
|
342
|
+
async migrate() {
|
|
343
|
+
this.db.exec(
|
|
344
|
+
"CREATE TABLE IF NOT EXISTS schema_migrations (id TEXT PRIMARY KEY, applied_at INTEGER NOT NULL)"
|
|
345
|
+
);
|
|
346
|
+
const existing = new Set(
|
|
347
|
+
this.db.prepare("SELECT id FROM schema_migrations").all().map((r) => r.id)
|
|
348
|
+
);
|
|
349
|
+
const applied = [];
|
|
350
|
+
const ordered = [...MIGRATIONS].sort((a, b) => a.id.localeCompare(b.id));
|
|
351
|
+
for (const m of ordered) {
|
|
352
|
+
if (existing.has(m.id)) continue;
|
|
353
|
+
this.applyMigration(m);
|
|
354
|
+
applied.push(m.id);
|
|
355
|
+
}
|
|
356
|
+
return { applied };
|
|
357
|
+
}
|
|
358
|
+
applyMigration(m) {
|
|
359
|
+
const txn = this.db.transaction(() => {
|
|
360
|
+
for (const stmt of m.up) this.db.exec(stmt);
|
|
361
|
+
this.db.prepare(
|
|
362
|
+
"INSERT INTO schema_migrations(id, applied_at) VALUES (?, ?)"
|
|
363
|
+
).run(m.id, Date.now());
|
|
364
|
+
});
|
|
365
|
+
txn();
|
|
366
|
+
}
|
|
367
|
+
async canonicalSchema() {
|
|
368
|
+
const reader = {
|
|
369
|
+
pragma: (name, arg) => arg === void 0 ? this.db.pragma(name) : this.db.pragma(`${name}('${arg.replace(/'/g, "''")}')`),
|
|
370
|
+
list: (sql) => this.db.prepare(sql).all()
|
|
371
|
+
};
|
|
372
|
+
return canonicalSchema(reader);
|
|
373
|
+
}
|
|
374
|
+
unsafe() {
|
|
375
|
+
return {
|
|
376
|
+
exec: async (sql, params) => {
|
|
377
|
+
const stmt = this.db.prepare(sql);
|
|
378
|
+
const info = stmt.run(...params ?? []);
|
|
379
|
+
return Number(info.changes);
|
|
380
|
+
},
|
|
381
|
+
query: async (sql, params) => this.db.prepare(sql).all(...params ?? [])
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
async close() {
|
|
385
|
+
this.db.close();
|
|
386
|
+
}
|
|
387
|
+
// ------------------------------------------------------------------
|
|
388
|
+
// Transactions. better-sqlite3 supports nested transactions via
|
|
389
|
+
// SAVEPOINTs automatically when the outer caller is already inside
|
|
390
|
+
// db.transaction(). We expose a Txn that mirrors Storage's surface;
|
|
391
|
+
// every method call inside the callback runs inside the open txn.
|
|
392
|
+
// ------------------------------------------------------------------
|
|
393
|
+
async txn(fn) {
|
|
394
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
395
|
+
try {
|
|
396
|
+
const result = await fn(this);
|
|
397
|
+
this.db.exec("COMMIT");
|
|
398
|
+
return result;
|
|
399
|
+
} catch (e) {
|
|
400
|
+
try {
|
|
401
|
+
this.db.exec("ROLLBACK");
|
|
402
|
+
} catch {
|
|
403
|
+
}
|
|
404
|
+
throw e;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
// ==================================================================
|
|
408
|
+
// sessions
|
|
409
|
+
// ==================================================================
|
|
410
|
+
async getSession(sessionId) {
|
|
411
|
+
const row = this.cached(
|
|
412
|
+
"session-get",
|
|
413
|
+
"SELECT * FROM sessions WHERE session_id = ?"
|
|
414
|
+
).get(sessionId);
|
|
415
|
+
return row ?? null;
|
|
416
|
+
}
|
|
417
|
+
async listSessions(opts) {
|
|
418
|
+
const limit = opts?.limit ?? 100;
|
|
419
|
+
return this.cached(
|
|
420
|
+
"session-list",
|
|
421
|
+
"SELECT * FROM sessions ORDER BY last_at DESC LIMIT ?"
|
|
422
|
+
).all(limit);
|
|
423
|
+
}
|
|
424
|
+
async upsertSession(row) {
|
|
425
|
+
this.cached(
|
|
426
|
+
"session-upsert",
|
|
427
|
+
`INSERT INTO sessions
|
|
408
428
|
(session_id, started_at, last_at, calls, wall_ms, cache_hits,
|
|
409
429
|
total_prompt_tokens, total_completion_tokens, total_cached_tokens,
|
|
410
430
|
total_tokens, total_cost_usd, total_cpu_ms)
|
|
@@ -420,31 +440,31 @@ var BetterSqliteStorage = class {
|
|
|
420
440
|
total_tokens = excluded.total_tokens,
|
|
421
441
|
total_cost_usd = excluded.total_cost_usd,
|
|
422
442
|
total_cpu_ms = excluded.total_cpu_ms`
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
443
|
+
).run(
|
|
444
|
+
row.session_id,
|
|
445
|
+
row.started_at,
|
|
446
|
+
row.last_at,
|
|
447
|
+
row.calls,
|
|
448
|
+
row.wall_ms,
|
|
449
|
+
row.cache_hits,
|
|
450
|
+
row.total_prompt_tokens,
|
|
451
|
+
row.total_completion_tokens,
|
|
452
|
+
row.total_cached_tokens,
|
|
453
|
+
row.total_tokens,
|
|
454
|
+
row.total_cost_usd,
|
|
455
|
+
row.total_cpu_ms
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
async accumulateSessionTotals(sessionId, delta) {
|
|
459
|
+
this.cached(
|
|
460
|
+
"session-touch",
|
|
461
|
+
`INSERT OR IGNORE INTO sessions
|
|
442
462
|
(session_id, started_at, last_at, calls, wall_ms, cache_hits)
|
|
443
463
|
VALUES (?, ?, ?, 0, 0, 0)`
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
464
|
+
).run(sessionId, delta.last_at ?? 0, delta.last_at ?? null);
|
|
465
|
+
this.cached(
|
|
466
|
+
"session-acc",
|
|
467
|
+
`UPDATE sessions SET
|
|
448
468
|
calls = calls + ?,
|
|
449
469
|
wall_ms = wall_ms + ?,
|
|
450
470
|
cache_hits = cache_hits + ?,
|
|
@@ -456,75 +476,75 @@ var BetterSqliteStorage = class {
|
|
|
456
476
|
total_cpu_ms = total_cpu_ms + ?,
|
|
457
477
|
last_at = COALESCE(?, last_at)
|
|
458
478
|
WHERE session_id = ?`
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
479
|
+
).run(
|
|
480
|
+
delta.calls ?? 0,
|
|
481
|
+
delta.wall_ms ?? 0,
|
|
482
|
+
delta.cache_hits ?? 0,
|
|
483
|
+
delta.total_prompt_tokens ?? 0,
|
|
484
|
+
delta.total_completion_tokens ?? 0,
|
|
485
|
+
delta.total_cached_tokens ?? 0,
|
|
486
|
+
delta.total_tokens ?? 0,
|
|
487
|
+
delta.total_cost_usd ?? 0,
|
|
488
|
+
delta.total_cpu_ms ?? 0,
|
|
489
|
+
delta.last_at ?? null,
|
|
490
|
+
sessionId
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
// ==================================================================
|
|
494
|
+
// usage_log
|
|
495
|
+
// ==================================================================
|
|
496
|
+
async insertUsage(rows) {
|
|
497
|
+
if (rows.length === 0) return;
|
|
498
|
+
const stmt = this.cached(
|
|
499
|
+
"usage-insert",
|
|
500
|
+
`INSERT INTO usage_log
|
|
481
501
|
(session_id, ts, tool, purpose, provider, model,
|
|
482
502
|
prompt_tokens, completion_tokens, cached_tokens, total_tokens,
|
|
483
503
|
cost_usd, estimated, wall_ms, cpu_ms)
|
|
484
504
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
485
|
-
);
|
|
486
|
-
const tx = this.db.transaction((items) => {
|
|
487
|
-
for (const r of items) {
|
|
488
|
-
stmt.run(
|
|
489
|
-
r.session_id,
|
|
490
|
-
r.ts,
|
|
491
|
-
r.tool,
|
|
492
|
-
r.purpose,
|
|
493
|
-
r.provider,
|
|
494
|
-
r.model,
|
|
495
|
-
r.prompt_tokens ?? 0,
|
|
496
|
-
r.completion_tokens ?? 0,
|
|
497
|
-
r.cached_tokens ?? 0,
|
|
498
|
-
r.total_tokens ?? 0,
|
|
499
|
-
r.cost_usd ?? 0,
|
|
500
|
-
r.estimated ?? 0,
|
|
501
|
-
r.wall_ms ?? 0,
|
|
502
|
-
r.cpu_ms ?? 0
|
|
503
505
|
);
|
|
506
|
+
const tx = this.db.transaction((items) => {
|
|
507
|
+
for (const r of items) {
|
|
508
|
+
stmt.run(
|
|
509
|
+
r.session_id,
|
|
510
|
+
r.ts,
|
|
511
|
+
r.tool,
|
|
512
|
+
r.purpose,
|
|
513
|
+
r.provider,
|
|
514
|
+
r.model,
|
|
515
|
+
r.prompt_tokens ?? 0,
|
|
516
|
+
r.completion_tokens ?? 0,
|
|
517
|
+
r.cached_tokens ?? 0,
|
|
518
|
+
r.total_tokens ?? 0,
|
|
519
|
+
r.cost_usd ?? 0,
|
|
520
|
+
r.estimated ?? 0,
|
|
521
|
+
r.wall_ms ?? 0,
|
|
522
|
+
r.cpu_ms ?? 0
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
tx(rows);
|
|
504
527
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
return this.cached(
|
|
526
|
-
"usage-grp-purpose",
|
|
527
|
-
`SELECT purpose,
|
|
528
|
+
async listUsageForSession(sessionId, opts) {
|
|
529
|
+
const where = ["session_id = ?"];
|
|
530
|
+
const params = [sessionId];
|
|
531
|
+
if (opts?.only_purpose && opts.only_purpose.length > 0) {
|
|
532
|
+
where.push(`purpose IN (${opts.only_purpose.map(() => "?").join(",")})`);
|
|
533
|
+
params.push(...opts.only_purpose);
|
|
534
|
+
}
|
|
535
|
+
if (opts?.only_provider && opts.only_provider.length > 0) {
|
|
536
|
+
where.push(`provider IN (${opts.only_provider.map(() => "?").join(",")})`);
|
|
537
|
+
params.push(...opts.only_provider);
|
|
538
|
+
}
|
|
539
|
+
const limit = opts?.limit ?? 1e3;
|
|
540
|
+
params.push(limit);
|
|
541
|
+
const sql = `SELECT * FROM usage_log WHERE ${where.join(" AND ")} ORDER BY id ASC LIMIT ?`;
|
|
542
|
+
return this.db.prepare(sql).all(...params);
|
|
543
|
+
}
|
|
544
|
+
async listUsageGroupedByPurpose(sessionId) {
|
|
545
|
+
return this.cached(
|
|
546
|
+
"usage-grp-purpose",
|
|
547
|
+
`SELECT purpose,
|
|
528
548
|
COUNT(*) AS calls,
|
|
529
549
|
COALESCE(SUM(prompt_tokens), 0) AS prompt_tokens,
|
|
530
550
|
COALESCE(SUM(completion_tokens), 0) AS completion_tokens,
|
|
@@ -536,13 +556,13 @@ var BetterSqliteStorage = class {
|
|
|
536
556
|
WHERE session_id = ?
|
|
537
557
|
GROUP BY purpose
|
|
538
558
|
ORDER BY purpose`
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
559
|
+
).all(sessionId);
|
|
560
|
+
}
|
|
561
|
+
async listUsageGroupedByProvider(purpose) {
|
|
562
|
+
if (purpose !== void 0) {
|
|
563
|
+
return this.cached(
|
|
564
|
+
"usage-grp-provider-p",
|
|
565
|
+
`SELECT provider,
|
|
546
566
|
COUNT(*) AS calls,
|
|
547
567
|
COALESCE(SUM(total_tokens), 0) AS total_tokens,
|
|
548
568
|
COALESCE(SUM(cost_usd), 0) AS cost_usd,
|
|
@@ -551,11 +571,11 @@ var BetterSqliteStorage = class {
|
|
|
551
571
|
WHERE purpose = ?
|
|
552
572
|
GROUP BY provider
|
|
553
573
|
ORDER BY provider`
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
574
|
+
).all(purpose);
|
|
575
|
+
}
|
|
576
|
+
return this.cached(
|
|
577
|
+
"usage-grp-provider",
|
|
578
|
+
`SELECT provider,
|
|
559
579
|
COUNT(*) AS calls,
|
|
560
580
|
COALESCE(SUM(total_tokens), 0) AS total_tokens,
|
|
561
581
|
COALESCE(SUM(cost_usd), 0) AS cost_usd,
|
|
@@ -563,13 +583,13 @@ var BetterSqliteStorage = class {
|
|
|
563
583
|
FROM usage_log
|
|
564
584
|
GROUP BY provider
|
|
565
585
|
ORDER BY provider`
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
586
|
+
).all();
|
|
587
|
+
}
|
|
588
|
+
async listRouterStatsByPurpose(purpose, sinceMs) {
|
|
589
|
+
if (sinceMs !== void 0) {
|
|
590
|
+
return this.cached(
|
|
591
|
+
"router-stats-purpose-since",
|
|
592
|
+
`SELECT LOWER(provider) AS provider,
|
|
573
593
|
COUNT(*) AS calls,
|
|
574
594
|
COALESCE(SUM(total_tokens), 0) AS tokens_sum,
|
|
575
595
|
COALESCE(AVG(total_tokens), 0) AS avg_total_tokens,
|
|
@@ -579,11 +599,11 @@ var BetterSqliteStorage = class {
|
|
|
579
599
|
WHERE purpose = ? AND ts >= ? AND provider IS NOT NULL
|
|
580
600
|
GROUP BY LOWER(provider)
|
|
581
601
|
ORDER BY provider`
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
602
|
+
).all(purpose, sinceMs);
|
|
603
|
+
}
|
|
604
|
+
return this.cached(
|
|
605
|
+
"router-stats-purpose",
|
|
606
|
+
`SELECT LOWER(provider) AS provider,
|
|
587
607
|
COUNT(*) AS calls,
|
|
588
608
|
COALESCE(SUM(total_tokens), 0) AS tokens_sum,
|
|
589
609
|
COALESCE(AVG(total_tokens), 0) AS avg_total_tokens,
|
|
@@ -593,321 +613,345 @@ var BetterSqliteStorage = class {
|
|
|
593
613
|
WHERE purpose = ? AND provider IS NOT NULL
|
|
594
614
|
GROUP BY LOWER(provider)
|
|
595
615
|
ORDER BY provider`
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
616
|
+
).all(purpose);
|
|
617
|
+
}
|
|
618
|
+
// ==================================================================
|
|
619
|
+
// claims
|
|
620
|
+
// ==================================================================
|
|
621
|
+
async insertClaim(claim) {
|
|
622
|
+
const info = this.cached(
|
|
623
|
+
"claim-insert",
|
|
624
|
+
`INSERT INTO claims
|
|
605
625
|
(session_id, text, provider, confidence, citations_json, kind, created_at)
|
|
606
626
|
VALUES (?, ?, ?, ?, ?, ?, ?)`
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
627
|
+
).run(
|
|
628
|
+
claim.session_id,
|
|
629
|
+
claim.text,
|
|
630
|
+
claim.provider ?? null,
|
|
631
|
+
claim.confidence ?? null,
|
|
632
|
+
claim.citations ? JSON.stringify(claim.citations) : null,
|
|
633
|
+
claim.kind ?? null,
|
|
634
|
+
Date.now()
|
|
635
|
+
);
|
|
636
|
+
return Number(info.lastInsertRowid);
|
|
637
|
+
}
|
|
638
|
+
async insertClaimLink(srcId, dstId, kind) {
|
|
639
|
+
if (!ALLOWED_LINK_KINDS.has(kind)) {
|
|
640
|
+
throw new RangeError(`invalid claim_link kind: ${kind}`);
|
|
641
|
+
}
|
|
642
|
+
this.cached(
|
|
643
|
+
"claim-link-insert",
|
|
644
|
+
`INSERT OR IGNORE INTO claim_links (src_id, dst_id, kind, created_at)
|
|
625
645
|
VALUES (?, ?, ?, ?)`
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
646
|
+
).run(srcId, dstId, kind, Date.now());
|
|
647
|
+
}
|
|
648
|
+
async listClaimsForSession(sessionId) {
|
|
649
|
+
return this.cached(
|
|
650
|
+
"claim-list-session",
|
|
651
|
+
"SELECT * FROM claims WHERE session_id = ? ORDER BY id"
|
|
652
|
+
).all(sessionId);
|
|
653
|
+
}
|
|
654
|
+
async getClaim(claimId) {
|
|
655
|
+
const row = this.cached(
|
|
656
|
+
"claim-get",
|
|
657
|
+
"SELECT * FROM claims WHERE id = ?"
|
|
658
|
+
).get(claimId);
|
|
659
|
+
return row ?? null;
|
|
660
|
+
}
|
|
661
|
+
async listClaimLinksForSession(sessionId) {
|
|
662
|
+
return this.cached(
|
|
663
|
+
"claim-link-list-session",
|
|
664
|
+
`SELECT cl.*
|
|
645
665
|
FROM claim_links cl
|
|
646
666
|
JOIN claims c ON c.id = cl.src_id OR c.id = cl.dst_id
|
|
647
667
|
WHERE c.session_id = ?
|
|
648
668
|
GROUP BY cl.id
|
|
649
669
|
ORDER BY cl.id`
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
670
|
+
).all(sessionId);
|
|
671
|
+
}
|
|
672
|
+
async deleteClaimsForSession(sessionId) {
|
|
673
|
+
const info = this.cached(
|
|
674
|
+
"claim-delete-session",
|
|
675
|
+
"DELETE FROM claims WHERE session_id = ?"
|
|
676
|
+
).run(sessionId);
|
|
677
|
+
return Number(info.changes);
|
|
678
|
+
}
|
|
679
|
+
// ==================================================================
|
|
680
|
+
// provider_stats
|
|
681
|
+
// ==================================================================
|
|
682
|
+
async listProviderStats(opts) {
|
|
683
|
+
const limit = opts?.limit ?? 100;
|
|
684
|
+
return this.cached(
|
|
685
|
+
"provider-stats-list",
|
|
686
|
+
"SELECT * FROM provider_stats ORDER BY (wins + losses + abstains) DESC, provider ASC LIMIT ?"
|
|
687
|
+
).all(limit);
|
|
688
|
+
}
|
|
689
|
+
async getProviderStats(provider) {
|
|
690
|
+
const row = this.cached(
|
|
691
|
+
"provider-stats-get",
|
|
692
|
+
"SELECT * FROM provider_stats WHERE provider = ?"
|
|
693
|
+
).get(provider);
|
|
694
|
+
return row ?? null;
|
|
695
|
+
}
|
|
696
|
+
async bumpProviderBallot(provider, ballot, at) {
|
|
697
|
+
const column = ballot === "agree" ? "wins" : ballot === "disagree" ? "losses" : "abstains";
|
|
698
|
+
this.db.prepare(
|
|
699
|
+
`INSERT INTO provider_stats(provider, wins, losses, abstains, last_at)
|
|
680
700
|
VALUES (?, 0, 0, 0, ?)
|
|
681
701
|
ON CONFLICT(provider) DO NOTHING`
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
702
|
+
).run(provider, at);
|
|
703
|
+
this.db.prepare(
|
|
704
|
+
`UPDATE provider_stats SET ${column} = ${column} + 1, last_at = ? WHERE provider = ?`
|
|
705
|
+
).run(at, provider);
|
|
706
|
+
}
|
|
707
|
+
// ==================================================================
|
|
708
|
+
// delegations
|
|
709
|
+
// ==================================================================
|
|
710
|
+
async insertDelegation(row) {
|
|
711
|
+
this.cached(
|
|
712
|
+
"delegation-insert",
|
|
713
|
+
`INSERT INTO delegations
|
|
694
714
|
(session_id, requester, tool_call, via, accepted, created_at)
|
|
695
715
|
VALUES (?, ?, ?, ?, ?, ?)`
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
}
|
|
705
|
-
async listDelegationsForSession(sessionId) {
|
|
706
|
-
return this.cached(
|
|
707
|
-
"delegation-list-session",
|
|
708
|
-
"SELECT * FROM delegations WHERE session_id = ? ORDER BY id"
|
|
709
|
-
).all(sessionId);
|
|
710
|
-
}
|
|
711
|
-
async countDelegationsByRequester(requester) {
|
|
712
|
-
const r = this.cached(
|
|
713
|
-
"delegation-count-req",
|
|
714
|
-
"SELECT COUNT(*) AS n FROM delegations WHERE requester = ?"
|
|
715
|
-
).get(requester);
|
|
716
|
-
return Number(r.n);
|
|
717
|
-
}
|
|
718
|
-
async countDelegationsBySession(sessionId) {
|
|
719
|
-
const r = this.cached(
|
|
720
|
-
"delegation-count-session",
|
|
721
|
-
"SELECT COUNT(*) AS n FROM delegations WHERE session_id = ?"
|
|
722
|
-
).get(sessionId);
|
|
723
|
-
return Number(r.n);
|
|
724
|
-
}
|
|
725
|
-
async countAcceptedDelegationsBySession(sessionId) {
|
|
726
|
-
const r = this.cached(
|
|
727
|
-
"delegation-count-accepted-session",
|
|
728
|
-
"SELECT COUNT(*) AS n FROM delegations WHERE session_id = ? AND accepted = 1"
|
|
729
|
-
).get(sessionId);
|
|
730
|
-
return Number(r.n);
|
|
731
|
-
}
|
|
732
|
-
async countAcceptedDelegationsByRequester(requester) {
|
|
733
|
-
const r = this.cached(
|
|
734
|
-
"delegation-count-accepted-requester",
|
|
735
|
-
"SELECT COUNT(*) AS n FROM delegations WHERE requester = ? AND accepted = 1"
|
|
736
|
-
).get(requester);
|
|
737
|
-
return Number(r.n);
|
|
738
|
-
}
|
|
739
|
-
async listDelegationAggregatesByRequester() {
|
|
740
|
-
const rows = this.cached(
|
|
741
|
-
"delegation-agg-requester",
|
|
742
|
-
"SELECT requester, accepted, COUNT(*) AS n FROM delegations WHERE requester IS NOT NULL GROUP BY requester, accepted"
|
|
743
|
-
).all();
|
|
744
|
-
return rows.map((r) => ({
|
|
745
|
-
requester: String(r.requester),
|
|
746
|
-
accepted: r.accepted === 1 ? 1 : 0,
|
|
747
|
-
count: Number(r.n)
|
|
748
|
-
}));
|
|
749
|
-
}
|
|
750
|
-
// ==================================================================
|
|
751
|
-
// global counts (scoreboard / observability)
|
|
752
|
-
// ==================================================================
|
|
753
|
-
async countScoreboardTotals() {
|
|
754
|
-
const countOne = (table) => {
|
|
755
|
-
try {
|
|
756
|
-
const r = this.db.prepare(`SELECT COUNT(*) AS n FROM ${table}`).get();
|
|
757
|
-
return r ? Number(r.n) : 0;
|
|
758
|
-
} catch {
|
|
759
|
-
return 0;
|
|
716
|
+
).run(
|
|
717
|
+
row.session_id,
|
|
718
|
+
row.requester,
|
|
719
|
+
row.tool_call,
|
|
720
|
+
row.via,
|
|
721
|
+
row.accepted,
|
|
722
|
+
row.created_at
|
|
723
|
+
);
|
|
760
724
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
725
|
+
async listDelegationsForSession(sessionId) {
|
|
726
|
+
return this.cached(
|
|
727
|
+
"delegation-list-session",
|
|
728
|
+
"SELECT * FROM delegations WHERE session_id = ? ORDER BY id"
|
|
729
|
+
).all(sessionId);
|
|
730
|
+
}
|
|
731
|
+
async countDelegationsByRequester(requester) {
|
|
732
|
+
const r = this.cached(
|
|
733
|
+
"delegation-count-req",
|
|
734
|
+
"SELECT COUNT(*) AS n FROM delegations WHERE requester = ?"
|
|
735
|
+
).get(requester);
|
|
736
|
+
return Number(r.n);
|
|
737
|
+
}
|
|
738
|
+
async countDelegationsBySession(sessionId) {
|
|
739
|
+
const r = this.cached(
|
|
740
|
+
"delegation-count-session",
|
|
741
|
+
"SELECT COUNT(*) AS n FROM delegations WHERE session_id = ?"
|
|
742
|
+
).get(sessionId);
|
|
743
|
+
return Number(r.n);
|
|
744
|
+
}
|
|
745
|
+
async countAcceptedDelegationsBySession(sessionId) {
|
|
746
|
+
const r = this.cached(
|
|
747
|
+
"delegation-count-accepted-session",
|
|
748
|
+
"SELECT COUNT(*) AS n FROM delegations WHERE session_id = ? AND accepted = 1"
|
|
749
|
+
).get(sessionId);
|
|
750
|
+
return Number(r.n);
|
|
751
|
+
}
|
|
752
|
+
async countAcceptedDelegationsByRequester(requester) {
|
|
753
|
+
const r = this.cached(
|
|
754
|
+
"delegation-count-accepted-requester",
|
|
755
|
+
"SELECT COUNT(*) AS n FROM delegations WHERE requester = ? AND accepted = 1"
|
|
756
|
+
).get(requester);
|
|
757
|
+
return Number(r.n);
|
|
758
|
+
}
|
|
759
|
+
async listDelegationAggregatesByRequester() {
|
|
760
|
+
const rows = this.cached(
|
|
761
|
+
"delegation-agg-requester",
|
|
762
|
+
"SELECT requester, accepted, COUNT(*) AS n FROM delegations WHERE requester IS NOT NULL GROUP BY requester, accepted"
|
|
763
|
+
).all();
|
|
764
|
+
return rows.map((r) => ({
|
|
765
|
+
requester: String(r.requester),
|
|
766
|
+
accepted: r.accepted === 1 ? 1 : 0,
|
|
767
|
+
count: Number(r.n)
|
|
768
|
+
}));
|
|
769
|
+
}
|
|
770
|
+
// ==================================================================
|
|
771
|
+
// global counts (scoreboard / observability)
|
|
772
|
+
// ==================================================================
|
|
773
|
+
async countScoreboardTotals() {
|
|
774
|
+
const countOne = (table) => {
|
|
775
|
+
try {
|
|
776
|
+
const r = this.db.prepare(`SELECT COUNT(*) AS n FROM ${table}`).get();
|
|
777
|
+
return r ? Number(r.n) : 0;
|
|
778
|
+
} catch {
|
|
779
|
+
return 0;
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
return {
|
|
783
|
+
sessions: countOne("sessions"),
|
|
784
|
+
claims: countOne("claims"),
|
|
785
|
+
claim_links: countOne("claim_links"),
|
|
786
|
+
delegations: countOne("delegations")
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
// ==================================================================
|
|
790
|
+
// session_memory
|
|
791
|
+
// ==================================================================
|
|
792
|
+
async insertSessionMemory(row) {
|
|
793
|
+
if (!ALLOWED_MEMORY_KINDS.has(row.kind)) {
|
|
794
|
+
throw new RangeError(`invalid session_memory kind: ${row.kind}`);
|
|
795
|
+
}
|
|
796
|
+
const info = this.cached(
|
|
797
|
+
"memory-insert",
|
|
798
|
+
`INSERT INTO session_memory
|
|
779
799
|
(session_id, kind, content, source_tool, source_call_id, confidence, created_at)
|
|
780
800
|
VALUES (?, ?, ?, ?, ?, ?, ?)`
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
801
|
+
).run(
|
|
802
|
+
row.session_id,
|
|
803
|
+
row.kind,
|
|
804
|
+
row.content,
|
|
805
|
+
row.source_tool ?? null,
|
|
806
|
+
row.source_call_id ?? null,
|
|
807
|
+
row.confidence ?? null,
|
|
808
|
+
row.created_at
|
|
809
|
+
);
|
|
810
|
+
return Number(info.lastInsertRowid);
|
|
811
|
+
}
|
|
812
|
+
async listSessionMemory(sessionId, opts) {
|
|
813
|
+
const where = ["session_id = ?"];
|
|
814
|
+
const params = [sessionId];
|
|
815
|
+
if (!opts?.include_stale) where.push("stale_at IS NULL");
|
|
816
|
+
if (opts?.kinds && opts.kinds.length > 0) {
|
|
817
|
+
where.push(`kind IN (${opts.kinds.map(() => "?").join(",")})`);
|
|
818
|
+
params.push(...opts.kinds);
|
|
819
|
+
}
|
|
820
|
+
const limit = opts?.limit ?? 50;
|
|
821
|
+
params.push(limit);
|
|
822
|
+
const sql = `SELECT * FROM session_memory WHERE ${where.join(" AND ")} ORDER BY id DESC LIMIT ?`;
|
|
823
|
+
return this.db.prepare(sql).all(...params);
|
|
824
|
+
}
|
|
825
|
+
async markSessionMemoryStale(sessionId, at, opts) {
|
|
826
|
+
const where = ["session_id = ?", "stale_at IS NULL"];
|
|
827
|
+
const params = [at, opts?.reason ?? "manual", sessionId];
|
|
828
|
+
if (opts?.ids && opts.ids.length > 0) {
|
|
829
|
+
where.push(`id IN (${opts.ids.map(() => "?").join(",")})`);
|
|
830
|
+
params.push(...opts.ids);
|
|
831
|
+
}
|
|
832
|
+
if (opts?.kinds && opts.kinds.length > 0) {
|
|
833
|
+
where.push(`kind IN (${opts.kinds.map(() => "?").join(",")})`);
|
|
834
|
+
params.push(...opts.kinds);
|
|
835
|
+
}
|
|
836
|
+
const sql = `UPDATE session_memory SET stale_at = ?, stale_reason = ? WHERE ${where.join(" AND ")}`;
|
|
837
|
+
const info = this.db.prepare(sql).run(...params);
|
|
838
|
+
return Number(info.changes);
|
|
839
|
+
}
|
|
840
|
+
async clearSessionMemory(sessionId) {
|
|
841
|
+
const info = this.cached(
|
|
842
|
+
"memory-clear",
|
|
843
|
+
"DELETE FROM session_memory WHERE session_id = ?"
|
|
844
|
+
).run(sessionId);
|
|
845
|
+
return Number(info.changes);
|
|
846
|
+
}
|
|
847
|
+
// ==================================================================
|
|
848
|
+
// fetch_egress
|
|
849
|
+
// ==================================================================
|
|
850
|
+
async recordFetchEgress(sessionId, host, bytes, at) {
|
|
851
|
+
this.cached(
|
|
852
|
+
"fetch-egress-upsert",
|
|
853
|
+
`INSERT INTO fetch_egress (session_id, host, total_bytes, last_at)
|
|
834
854
|
VALUES (?, ?, ?, ?)
|
|
835
855
|
ON CONFLICT(session_id, host) DO UPDATE SET
|
|
836
856
|
total_bytes = total_bytes + excluded.total_bytes,
|
|
837
857
|
last_at = excluded.last_at`
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
858
|
+
).run(sessionId, host, bytes, at);
|
|
859
|
+
}
|
|
860
|
+
async getFetchEgressTotals(sessionId) {
|
|
861
|
+
const r = this.cached(
|
|
862
|
+
"fetch-egress-totals",
|
|
863
|
+
"SELECT COALESCE(SUM(total_bytes), 0) AS total_bytes, COUNT(DISTINCT host) AS unique_hosts FROM fetch_egress WHERE session_id = ?"
|
|
864
|
+
).get(sessionId);
|
|
865
|
+
return {
|
|
866
|
+
total_bytes: Number(r.total_bytes ?? 0),
|
|
867
|
+
unique_hosts: Number(r.unique_hosts ?? 0)
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
async hasFetchEgressHost(sessionId, host) {
|
|
871
|
+
const r = this.cached(
|
|
872
|
+
"fetch-egress-has-host",
|
|
873
|
+
"SELECT 1 AS one FROM fetch_egress WHERE session_id = ? AND host = ? LIMIT 1"
|
|
874
|
+
).get(sessionId, host);
|
|
875
|
+
return r !== void 0;
|
|
876
|
+
}
|
|
877
|
+
// ==================================================================
|
|
878
|
+
// transcripts_fts — the encapsulated FTS5 surface.
|
|
879
|
+
// ==================================================================
|
|
880
|
+
async indexTranscript(row) {
|
|
881
|
+
this.cached(
|
|
882
|
+
"fts-insert",
|
|
883
|
+
`INSERT INTO transcripts_fts (session_id, tool, ts, path, content)
|
|
864
884
|
VALUES (?, ?, ?, ?, ?)`
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
885
|
+
).run(row.session_id ?? "", row.tool, String(row.ts), row.path, row.content);
|
|
886
|
+
}
|
|
887
|
+
async recallSearch(query, k, opts) {
|
|
888
|
+
const where = ["transcripts_fts MATCH ?"];
|
|
889
|
+
const params = [query];
|
|
890
|
+
if (opts?.session_id) {
|
|
891
|
+
where.push("session_id = ?");
|
|
892
|
+
params.push(opts.session_id);
|
|
893
|
+
}
|
|
894
|
+
if (opts?.tool) {
|
|
895
|
+
where.push("tool = ?");
|
|
896
|
+
params.push(opts.tool);
|
|
897
|
+
}
|
|
898
|
+
if (opts?.since_ms !== void 0) {
|
|
899
|
+
where.push("CAST(ts AS INTEGER) >= ?");
|
|
900
|
+
params.push(opts.since_ms);
|
|
901
|
+
}
|
|
902
|
+
params.push(k);
|
|
903
|
+
const sql = `SELECT path, session_id, tool, ts, snippet(transcripts_fts, -1, '[[', ']]', '...', 16) AS snippet, bm25(transcripts_fts) AS rank FROM transcripts_fts WHERE ${where.join(" AND ")} ORDER BY rank LIMIT ?`;
|
|
904
|
+
const rows = this.db.prepare(sql).all(...params);
|
|
905
|
+
return rows.map((r) => ({
|
|
906
|
+
path: r.path,
|
|
907
|
+
session_id: r.session_id ?? null,
|
|
908
|
+
tool: r.tool ?? null,
|
|
909
|
+
ts: Number(r.ts),
|
|
910
|
+
snippet: r.snippet,
|
|
911
|
+
score: 1 / (1 + Math.max(0, r.rank ?? 0))
|
|
912
|
+
}));
|
|
913
|
+
}
|
|
914
|
+
// ------------------------------------------------------------------
|
|
915
|
+
// Prepared-statement cache. better-sqlite3 prepares statements lazily
|
|
916
|
+
// and caches them internally, but the JS-side reference still costs
|
|
917
|
+
// a hashmap lookup on every call. Keeping our own map by key lets
|
|
918
|
+
// hot-path queries hit a single Map.get().
|
|
919
|
+
// ------------------------------------------------------------------
|
|
920
|
+
cached(key, sql) {
|
|
921
|
+
let s = this.stmts.get(key);
|
|
922
|
+
if (!s) {
|
|
923
|
+
s = this.db.prepare(sql);
|
|
924
|
+
this.stmts.set(key, s);
|
|
925
|
+
}
|
|
926
|
+
return s;
|
|
927
|
+
}
|
|
928
|
+
};
|
|
907
929
|
}
|
|
908
|
-
};
|
|
930
|
+
});
|
|
931
|
+
|
|
932
|
+
// src/entrypoints/node-stdio.ts
|
|
933
|
+
var node_stdio_exports = {};
|
|
934
|
+
__export(node_stdio_exports, {
|
|
935
|
+
RecordingEmitter: () => RecordingEmitter,
|
|
936
|
+
SERVER_NAME: () => SERVER_NAME,
|
|
937
|
+
SERVER_VERSION: () => SERVER_VERSION,
|
|
938
|
+
connectAndServe: () => connectAndServe,
|
|
939
|
+
createServer: () => createServer,
|
|
940
|
+
getEventEmitter: () => getEventEmitter,
|
|
941
|
+
setEventEmitter: () => setEventEmitter
|
|
942
|
+
});
|
|
943
|
+
module.exports = __toCommonJS(node_stdio_exports);
|
|
944
|
+
init_cjs_shims();
|
|
945
|
+
var import_node_fs11 = require("fs");
|
|
946
|
+
var import_node_path11 = __toESM(require("path"), 1);
|
|
947
|
+
var import_node_url2 = require("url");
|
|
948
|
+
var import_stdio2 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
949
|
+
|
|
950
|
+
// src/bridge/index.ts
|
|
951
|
+
init_cjs_shims();
|
|
909
952
|
|
|
910
953
|
// src/bridge/python-bridge.ts
|
|
954
|
+
init_cjs_shims();
|
|
911
955
|
var import_node_path = __toESM(require("path"), 1);
|
|
912
956
|
var import_node_url = require("url");
|
|
913
957
|
var import_client = require("@modelcontextprotocol/sdk/client/index.js");
|
|
@@ -1007,6 +1051,7 @@ async function fetchToolNames(client, timeoutMs) {
|
|
|
1007
1051
|
}
|
|
1008
1052
|
|
|
1009
1053
|
// src/bridge/proxy-tools.ts
|
|
1054
|
+
init_cjs_shims();
|
|
1010
1055
|
function buildPythonProxies(bridge) {
|
|
1011
1056
|
const proxies = /* @__PURE__ */ new Map();
|
|
1012
1057
|
for (const name of bridge.toolNames) {
|
|
@@ -1047,6 +1092,7 @@ function makeProxy(bridge, name) {
|
|
|
1047
1092
|
}
|
|
1048
1093
|
|
|
1049
1094
|
// src/core/events.ts
|
|
1095
|
+
init_cjs_shims();
|
|
1050
1096
|
var import_node_fs = require("fs");
|
|
1051
1097
|
var import_node_path2 = require("path");
|
|
1052
1098
|
var StderrEmitter = class {
|
|
@@ -1147,6 +1193,7 @@ function envelopeBytes(v) {
|
|
|
1147
1193
|
}
|
|
1148
1194
|
|
|
1149
1195
|
// src/core/pricing.ts
|
|
1196
|
+
init_cjs_shims();
|
|
1150
1197
|
var import_node_fs2 = require("fs");
|
|
1151
1198
|
function loadPricing(path9) {
|
|
1152
1199
|
let raw;
|
|
@@ -1200,7 +1247,14 @@ function roundTo(x, n) {
|
|
|
1200
1247
|
return Number(x.toFixed(n));
|
|
1201
1248
|
}
|
|
1202
1249
|
|
|
1250
|
+
// src/providers/registry.ts
|
|
1251
|
+
init_cjs_shims();
|
|
1252
|
+
|
|
1253
|
+
// src/providers/anthropic.ts
|
|
1254
|
+
init_cjs_shims();
|
|
1255
|
+
|
|
1203
1256
|
// src/core/provider-caps.ts
|
|
1257
|
+
init_cjs_shims();
|
|
1204
1258
|
var PROVIDER_CAPS = {
|
|
1205
1259
|
anthropic: {
|
|
1206
1260
|
family: "anthropic",
|
|
@@ -1243,6 +1297,7 @@ function supportsTemperature(provider, model) {
|
|
|
1243
1297
|
}
|
|
1244
1298
|
|
|
1245
1299
|
// src/providers/types.ts
|
|
1300
|
+
init_cjs_shims();
|
|
1246
1301
|
var ProviderError = class extends Error {
|
|
1247
1302
|
name = "ProviderError";
|
|
1248
1303
|
kind;
|
|
@@ -1424,6 +1479,7 @@ async function sendAnthropic(args) {
|
|
|
1424
1479
|
}
|
|
1425
1480
|
|
|
1426
1481
|
// src/providers/gemini.ts
|
|
1482
|
+
init_cjs_shims();
|
|
1427
1483
|
var GEMINI_API_URL_BASE = "https://generativelanguage.googleapis.com/v1beta/models";
|
|
1428
1484
|
function jsonSchemaToGeminiSchema(schema) {
|
|
1429
1485
|
const out = {};
|
|
@@ -1606,6 +1662,7 @@ async function sendGemini(args) {
|
|
|
1606
1662
|
}
|
|
1607
1663
|
|
|
1608
1664
|
// src/providers/openai-compatible.ts
|
|
1665
|
+
init_cjs_shims();
|
|
1609
1666
|
var OPENAI_COMPAT_DEFAULT_URLS = {
|
|
1610
1667
|
openai: "https://api.openai.com/v1/chat/completions",
|
|
1611
1668
|
xai: "https://api.x.ai/v1/chat/completions",
|
|
@@ -1855,10 +1912,12 @@ function makeGeminiProvider(model, apiKey, opts) {
|
|
|
1855
1912
|
}
|
|
1856
1913
|
|
|
1857
1914
|
// src/server.ts
|
|
1915
|
+
init_cjs_shims();
|
|
1858
1916
|
var import_server2 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
1859
1917
|
var import_types5 = require("@modelcontextprotocol/sdk/types.js");
|
|
1860
1918
|
|
|
1861
1919
|
// src/instructions.ts
|
|
1920
|
+
init_cjs_shims();
|
|
1862
1921
|
var ROUTABLE_TOOLS = [
|
|
1863
1922
|
// Single-shot
|
|
1864
1923
|
"pick",
|
|
@@ -1917,13 +1976,19 @@ This convention is opt-in: a user message without the \`xc\`/\`XC\` prefix shoul
|
|
|
1917
1976
|
}
|
|
1918
1977
|
|
|
1919
1978
|
// src/tools/index.ts
|
|
1979
|
+
init_cjs_shims();
|
|
1920
1980
|
var import_zod = require("zod");
|
|
1921
1981
|
|
|
1922
1982
|
// src/tools/audit.ts
|
|
1983
|
+
init_cjs_shims();
|
|
1923
1984
|
var import_node_fs3 = require("fs");
|
|
1924
1985
|
var import_node_path3 = require("path");
|
|
1925
1986
|
|
|
1987
|
+
// src/core/structured.ts
|
|
1988
|
+
init_cjs_shims();
|
|
1989
|
+
|
|
1926
1990
|
// src/core/extract-json.ts
|
|
1991
|
+
init_cjs_shims();
|
|
1927
1992
|
function extractJson(text) {
|
|
1928
1993
|
if (typeof text !== "string") return null;
|
|
1929
1994
|
const s = text.trim();
|
|
@@ -1978,6 +2043,7 @@ function extractJson(text) {
|
|
|
1978
2043
|
}
|
|
1979
2044
|
|
|
1980
2045
|
// src/core/json-schema.ts
|
|
2046
|
+
init_cjs_shims();
|
|
1981
2047
|
function validateSchema(value, schema, path9 = "") {
|
|
1982
2048
|
const errs = [];
|
|
1983
2049
|
if ("anyOf" in schema) {
|
|
@@ -2141,6 +2207,7 @@ function pyReprType(t) {
|
|
|
2141
2207
|
}
|
|
2142
2208
|
|
|
2143
2209
|
// src/core/usage.ts
|
|
2210
|
+
init_cjs_shims();
|
|
2144
2211
|
function emptyUsage(provider, model, purpose = "worker") {
|
|
2145
2212
|
return {
|
|
2146
2213
|
provider,
|
|
@@ -2274,6 +2341,7 @@ async function askOne(provider, messages, opts) {
|
|
|
2274
2341
|
}
|
|
2275
2342
|
|
|
2276
2343
|
// src/core/retarget.ts
|
|
2344
|
+
init_cjs_shims();
|
|
2277
2345
|
function retargetProvider(p, newModel) {
|
|
2278
2346
|
if (p.model === newModel) return p;
|
|
2279
2347
|
return {
|
|
@@ -2298,7 +2366,11 @@ async function loadProviderWeights(storage, names) {
|
|
|
2298
2366
|
return out;
|
|
2299
2367
|
}
|
|
2300
2368
|
|
|
2369
|
+
// src/core/tiers.ts
|
|
2370
|
+
init_cjs_shims();
|
|
2371
|
+
|
|
2301
2372
|
// src/core/pyrepr.ts
|
|
2373
|
+
init_cjs_shims();
|
|
2302
2374
|
function pyStrRepr(s) {
|
|
2303
2375
|
const hasSingle = s.indexOf("'") >= 0;
|
|
2304
2376
|
const hasDouble = s.indexOf('"') >= 0;
|
|
@@ -3000,13 +3072,19 @@ function boolArg(v, defaultVal) {
|
|
|
3000
3072
|
}
|
|
3001
3073
|
|
|
3002
3074
|
// src/tools/bench.ts
|
|
3075
|
+
init_cjs_shims();
|
|
3003
3076
|
var import_node_fs4 = require("fs");
|
|
3004
3077
|
var import_node_path5 = __toESM(require("path"), 1);
|
|
3005
3078
|
|
|
3079
|
+
// src/tools/confer.ts
|
|
3080
|
+
init_cjs_shims();
|
|
3081
|
+
|
|
3006
3082
|
// src/core/canary.ts
|
|
3083
|
+
init_cjs_shims();
|
|
3007
3084
|
var import_node_crypto = require("crypto");
|
|
3008
3085
|
|
|
3009
3086
|
// src/core/injection.ts
|
|
3087
|
+
init_cjs_shims();
|
|
3010
3088
|
var INJECTION_PHRASES_RE = new RegExp(
|
|
3011
3089
|
"\\b((?:ignore|disregard|forget)\\s+(?:all\\s+)?(?:previous\\s+|prior\\s+|the\\s+(?:above\\s+)?)?(?:instructions|directions|prompts|rules|context)|you are now\\b|act as (?:a |an )?(?:[A-Za-z]+)|pretend (?:to be|you are)|system prompt:?|new instructions:?)",
|
|
3012
3090
|
"gi"
|
|
@@ -3071,6 +3149,7 @@ function countOccurrences(haystack, needle) {
|
|
|
3071
3149
|
}
|
|
3072
3150
|
|
|
3073
3151
|
// src/core/panel-judges.ts
|
|
3152
|
+
init_cjs_shims();
|
|
3074
3153
|
function pickPanelJudge(providers, moderatorName, pricing) {
|
|
3075
3154
|
if (pricing) {
|
|
3076
3155
|
const tiers = tierLadder(pricing);
|
|
@@ -3252,6 +3331,7 @@ var STRUCTURED_SYNTHESIS_SCHEMA = {
|
|
|
3252
3331
|
};
|
|
3253
3332
|
|
|
3254
3333
|
// src/core/router.ts
|
|
3334
|
+
init_cjs_shims();
|
|
3255
3335
|
var ROUTER_DEFAULT_WINDOW_SECONDS = 30 * 24 * 3600;
|
|
3256
3336
|
var ROUTER_COLD_START_THRESHOLD = 5;
|
|
3257
3337
|
function routerScore(stats, minCost, maxCost) {
|
|
@@ -3400,6 +3480,7 @@ async function pickAutoPanel(storage, purpose, n, providers, allowlist) {
|
|
|
3400
3480
|
}
|
|
3401
3481
|
|
|
3402
3482
|
// src/core/session-memory.ts
|
|
3483
|
+
init_cjs_shims();
|
|
3403
3484
|
var SESSION_MEMORY_DEFAULT_LIMIT = 50;
|
|
3404
3485
|
var SESSION_MEMORY_INJECT_BUDGET_CHARS = 4e3;
|
|
3405
3486
|
async function renderSessionMemoryBlock(storage, sessionId) {
|
|
@@ -3447,6 +3528,7 @@ async function renderSessionMemoryBlock(storage, sessionId) {
|
|
|
3447
3528
|
}
|
|
3448
3529
|
|
|
3449
3530
|
// src/core/worker-tools.ts
|
|
3531
|
+
init_cjs_shims();
|
|
3450
3532
|
var WORKER_TOOL_ALLOWLIST = /* @__PURE__ */ new Set(["fetch", "verify"]);
|
|
3451
3533
|
var WORKER_TOOL_HOP_BUDGET = 2;
|
|
3452
3534
|
var WORKER_TOOLS_MAX_RESULT_CHARS = 4e3;
|
|
@@ -4293,6 +4375,7 @@ ${existing.content}`
|
|
|
4293
4375
|
}
|
|
4294
4376
|
|
|
4295
4377
|
// src/tools/review.ts
|
|
4378
|
+
init_cjs_shims();
|
|
4296
4379
|
async function runReview(args, opts) {
|
|
4297
4380
|
const snippet = typeof args["snippet"] === "string" ? args["snippet"] : String(args["snippet"] ?? "");
|
|
4298
4381
|
const intent = typeof args["intent"] === "string" ? args["intent"] : "";
|
|
@@ -4314,9 +4397,11 @@ ${snippet}
|
|
|
4314
4397
|
}
|
|
4315
4398
|
|
|
4316
4399
|
// src/tools/verify.ts
|
|
4400
|
+
init_cjs_shims();
|
|
4317
4401
|
var import_node_perf_hooks = require("perf_hooks");
|
|
4318
4402
|
|
|
4319
4403
|
// src/core/sandbox.ts
|
|
4404
|
+
init_cjs_shims();
|
|
4320
4405
|
var import_node_child_process = require("child_process");
|
|
4321
4406
|
var import_promises = require("fs/promises");
|
|
4322
4407
|
var import_node_os = require("os");
|
|
@@ -4477,6 +4562,7 @@ function tryKill(child, signal, isUnix) {
|
|
|
4477
4562
|
}
|
|
4478
4563
|
|
|
4479
4564
|
// src/core/shlex.ts
|
|
4565
|
+
init_cjs_shims();
|
|
4480
4566
|
function shlexSplit(s) {
|
|
4481
4567
|
const out = [];
|
|
4482
4568
|
let current = "";
|
|
@@ -5119,6 +5205,7 @@ function isObj4(v) {
|
|
|
5119
5205
|
}
|
|
5120
5206
|
|
|
5121
5207
|
// src/tools/config-pin.ts
|
|
5208
|
+
init_cjs_shims();
|
|
5122
5209
|
var import_node_crypto2 = require("crypto");
|
|
5123
5210
|
var import_node_fs5 = require("fs");
|
|
5124
5211
|
var import_node_path6 = __toESM(require("path"), 1);
|
|
@@ -5351,14 +5438,17 @@ function pyRepr2(v) {
|
|
|
5351
5438
|
}
|
|
5352
5439
|
|
|
5353
5440
|
// src/tools/create.ts
|
|
5441
|
+
init_cjs_shims();
|
|
5354
5442
|
var import_node_crypto4 = require("crypto");
|
|
5355
5443
|
var import_node_fs7 = require("fs");
|
|
5356
5444
|
var import_node_path8 = __toESM(require("path"), 1);
|
|
5357
5445
|
|
|
5358
5446
|
// src/tools/orchestrate.ts
|
|
5447
|
+
init_cjs_shims();
|
|
5359
5448
|
var import_node_perf_hooks2 = require("perf_hooks");
|
|
5360
5449
|
|
|
5361
5450
|
// src/core/dead-models.ts
|
|
5451
|
+
init_cjs_shims();
|
|
5362
5452
|
var DEAD_MODELS_TTL_MS = 5 * 60 * 1e3;
|
|
5363
5453
|
var deadModels = /* @__PURE__ */ new Map();
|
|
5364
5454
|
function makeKey(provider, model) {
|
|
@@ -6119,6 +6209,7 @@ function pyRound6(x) {
|
|
|
6119
6209
|
}
|
|
6120
6210
|
|
|
6121
6211
|
// src/tools/fetch.ts
|
|
6212
|
+
init_cjs_shims();
|
|
6122
6213
|
var import_node_crypto3 = require("crypto");
|
|
6123
6214
|
var import_node_fs6 = require("fs");
|
|
6124
6215
|
var import_node_path7 = __toESM(require("path"), 1);
|
|
@@ -6350,6 +6441,7 @@ function errorPayload(code, message, hint, kind = "client") {
|
|
|
6350
6441
|
}
|
|
6351
6442
|
|
|
6352
6443
|
// src/core/call-context.ts
|
|
6444
|
+
init_cjs_shims();
|
|
6353
6445
|
function buildCallContext(args) {
|
|
6354
6446
|
const ctx = {
|
|
6355
6447
|
cheap_mode: args.cheapMode,
|
|
@@ -6771,6 +6863,7 @@ function errorEnvelope6(toolName, code, message, hint) {
|
|
|
6771
6863
|
}
|
|
6772
6864
|
|
|
6773
6865
|
// src/tools/coordinate.ts
|
|
6866
|
+
init_cjs_shims();
|
|
6774
6867
|
var DEFERRED_OPTS3 = [
|
|
6775
6868
|
// empty — every coordinate opt runs natively when its deps
|
|
6776
6869
|
// (storage / innerCallers) are wired. Without them the
|
|
@@ -7170,6 +7263,7 @@ function errorEnvelope7(code, message, hint) {
|
|
|
7170
7263
|
}
|
|
7171
7264
|
|
|
7172
7265
|
// src/tools/critique.ts
|
|
7266
|
+
init_cjs_shims();
|
|
7173
7267
|
var CRITIQUE_MAX_WEAKNESSES = 5;
|
|
7174
7268
|
var SEVERITY_ALIASES2 = {
|
|
7175
7269
|
medium: "med",
|
|
@@ -7390,6 +7484,7 @@ function isObj6(v) {
|
|
|
7390
7484
|
}
|
|
7391
7485
|
|
|
7392
7486
|
// src/tools/debate.ts
|
|
7487
|
+
init_cjs_shims();
|
|
7393
7488
|
var DEFERRED_OPTS4 = [
|
|
7394
7489
|
// empty — every debate opt runs natively when its deps
|
|
7395
7490
|
// (storage / innerCallers) are wired.
|
|
@@ -7746,6 +7841,7 @@ function errorEnvelope9(code, message, hint) {
|
|
|
7746
7841
|
}
|
|
7747
7842
|
|
|
7748
7843
|
// src/tools/delegate.ts
|
|
7844
|
+
init_cjs_shims();
|
|
7749
7845
|
var DELEGABLE_TOOLS = /* @__PURE__ */ new Set(["confer", "review"]);
|
|
7750
7846
|
var DEFAULT_DELEGATION_LIMITS = {
|
|
7751
7847
|
max_per_session: 50,
|
|
@@ -7911,6 +8007,7 @@ function pyListRepr2(xs) {
|
|
|
7911
8007
|
}
|
|
7912
8008
|
|
|
7913
8009
|
// src/tools/explain.ts
|
|
8010
|
+
init_cjs_shims();
|
|
7914
8011
|
var import_node_fs8 = require("fs");
|
|
7915
8012
|
var import_node_path9 = __toESM(require("path"), 1);
|
|
7916
8013
|
async function runExplain(args, opts) {
|
|
@@ -8235,6 +8332,7 @@ function errorEnvelope11(code, message, hint, kind = "client", extra = {}) {
|
|
|
8235
8332
|
}
|
|
8236
8333
|
|
|
8237
8334
|
// src/tools/list-providers.ts
|
|
8335
|
+
init_cjs_shims();
|
|
8238
8336
|
var KNOWN_PROVIDERS6 = [
|
|
8239
8337
|
"anthropic",
|
|
8240
8338
|
"openai",
|
|
@@ -8266,6 +8364,7 @@ function runListProviders(_args, opts) {
|
|
|
8266
8364
|
}
|
|
8267
8365
|
|
|
8268
8366
|
// src/tools/pick.ts
|
|
8367
|
+
init_cjs_shims();
|
|
8269
8368
|
var PICK_SCORES_SCHEMA = {
|
|
8270
8369
|
type: "object",
|
|
8271
8370
|
additionalProperties: false,
|
|
@@ -8582,6 +8681,7 @@ function toArray(v) {
|
|
|
8582
8681
|
}
|
|
8583
8682
|
|
|
8584
8683
|
// src/tools/plan.ts
|
|
8684
|
+
init_cjs_shims();
|
|
8585
8685
|
var PLAN_MODE_PRESETS = {
|
|
8586
8686
|
fast: { max_rounds: 2, early_stop: true, early_stop_threshold: 0.7 },
|
|
8587
8687
|
thorough: { max_rounds: 5, early_stop: false, early_stop_threshold: 0.7 }
|
|
@@ -8621,6 +8721,7 @@ Return: (1) the plan as numbered steps, (2) risks, (3) alternatives considered.`
|
|
|
8621
8721
|
}
|
|
8622
8722
|
|
|
8623
8723
|
// src/tools/recall.ts
|
|
8724
|
+
init_cjs_shims();
|
|
8624
8725
|
async function runRecall(args, opts) {
|
|
8625
8726
|
const queryRaw = args["query"];
|
|
8626
8727
|
const query = typeof queryRaw === "string" ? queryRaw.trim() : "";
|
|
@@ -8718,6 +8819,7 @@ function errorEnvelope12(code, message, hint) {
|
|
|
8718
8819
|
}
|
|
8719
8820
|
|
|
8720
8821
|
// src/tools/recommend-panel.ts
|
|
8822
|
+
init_cjs_shims();
|
|
8721
8823
|
async function runRecommendPanel(args, opts) {
|
|
8722
8824
|
const purpose = typeof args["purpose"] === "string" ? args["purpose"] : "";
|
|
8723
8825
|
if (!purpose) {
|
|
@@ -8834,6 +8936,7 @@ function toStringArray3(v) {
|
|
|
8834
8936
|
}
|
|
8835
8937
|
|
|
8836
8938
|
// src/tools/scoreboard.ts
|
|
8939
|
+
init_cjs_shims();
|
|
8837
8940
|
var import_node_fs9 = require("fs");
|
|
8838
8941
|
async function runScoreboard(args, opts) {
|
|
8839
8942
|
if (!opts.storage) {
|
|
@@ -8969,6 +9072,7 @@ function errorEnvelope14(code, message, hint) {
|
|
|
8969
9072
|
}
|
|
8970
9073
|
|
|
8971
9074
|
// src/tools/session-memory.ts
|
|
9075
|
+
init_cjs_shims();
|
|
8972
9076
|
var VALID_KINDS = /* @__PURE__ */ new Set([
|
|
8973
9077
|
"fact",
|
|
8974
9078
|
"open_question",
|
|
@@ -9145,6 +9249,7 @@ function pyRepr6(v) {
|
|
|
9145
9249
|
}
|
|
9146
9250
|
|
|
9147
9251
|
// src/tools/solve.ts
|
|
9252
|
+
init_cjs_shims();
|
|
9148
9253
|
var import_node_perf_hooks3 = require("perf_hooks");
|
|
9149
9254
|
async function runSolve(args, opts) {
|
|
9150
9255
|
const problem = typeof args["problem"] === "string" ? args["problem"] : String(args["problem"] ?? "");
|
|
@@ -9514,6 +9619,7 @@ function pyRepr7(v) {
|
|
|
9514
9619
|
}
|
|
9515
9620
|
|
|
9516
9621
|
// src/tools/update-crosscheck.ts
|
|
9622
|
+
init_cjs_shims();
|
|
9517
9623
|
var import_node_child_process2 = require("child_process");
|
|
9518
9624
|
var import_node_fs10 = require("fs");
|
|
9519
9625
|
var import_node_path10 = __toESM(require("path"), 1);
|
|
@@ -9732,6 +9838,7 @@ function withTimeout2(promise, ms) {
|
|
|
9732
9838
|
}
|
|
9733
9839
|
|
|
9734
9840
|
// src/tools/triangulate.ts
|
|
9841
|
+
init_cjs_shims();
|
|
9735
9842
|
async function runTriangulate(args, opts) {
|
|
9736
9843
|
const question = typeof args["question"] === "string" ? args["question"] : String(args["question"] ?? "");
|
|
9737
9844
|
const context = typeof args["context"] === "string" ? args["context"] : "";
|
|
@@ -10601,7 +10708,7 @@ function pingTool() {
|
|
|
10601
10708
|
|
|
10602
10709
|
// src/server.ts
|
|
10603
10710
|
var SERVER_NAME = "crosscheck-agent";
|
|
10604
|
-
var SERVER_VERSION = "0.1.0";
|
|
10711
|
+
var SERVER_VERSION = true ? "0.1.3" : "0.0.0-dev";
|
|
10605
10712
|
function createServer(opts = {}) {
|
|
10606
10713
|
const server = new import_server2.Server(
|
|
10607
10714
|
{ name: SERVER_NAME, version: SERVER_VERSION },
|
|
@@ -10756,7 +10863,8 @@ async function main() {
|
|
|
10756
10863
|
if (dbPath) {
|
|
10757
10864
|
try {
|
|
10758
10865
|
(0, import_node_fs11.mkdirSync)(import_node_path11.default.dirname(dbPath), { recursive: true });
|
|
10759
|
-
|
|
10866
|
+
const { openBetterSqliteStorage: openBetterSqliteStorage2 } = await Promise.resolve().then(() => (init_better_sqlite3(), better_sqlite3_exports));
|
|
10867
|
+
storage = openBetterSqliteStorage2({ path: dbPath });
|
|
10760
10868
|
await storage.migrate();
|
|
10761
10869
|
process.stderr.write(
|
|
10762
10870
|
`crosscheck-agent: storage wired at ${dbPath}
|