@askexenow/exe-os 0.8.41 → 0.8.43
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/bin/backfill-conversations.js +805 -642
- package/dist/bin/backfill-responses.js +804 -641
- package/dist/bin/backfill-vectors.js +791 -634
- package/dist/bin/cleanup-stale-review-tasks.js +788 -631
- package/dist/bin/cli.js +1345 -660
- package/dist/bin/exe-agent.js +20 -1
- package/dist/bin/exe-assign.js +1503 -1343
- package/dist/bin/exe-boot.js +2518 -1798
- package/dist/bin/exe-call.js +39 -1
- package/dist/bin/exe-cloud.js +15 -1
- package/dist/bin/exe-dispatch.js +39 -2
- package/dist/bin/exe-doctor.js +790 -633
- package/dist/bin/exe-export-behaviors.js +792 -637
- package/dist/bin/exe-forget.js +145 -0
- package/dist/bin/exe-gateway.js +2500 -1877
- package/dist/bin/exe-heartbeat.js +147 -1
- package/dist/bin/exe-kill.js +795 -640
- package/dist/bin/exe-launch-agent.js +2168 -2008
- package/dist/bin/exe-link.js +28 -2
- package/dist/bin/exe-new-employee.js +25 -3
- package/dist/bin/exe-pending-messages.js +146 -1
- package/dist/bin/exe-pending-notifications.js +788 -631
- package/dist/bin/exe-pending-reviews.js +147 -1
- package/dist/bin/exe-rename.js +23 -0
- package/dist/bin/exe-review.js +490 -327
- package/dist/bin/exe-search.js +154 -3
- package/dist/bin/exe-session-cleanup.js +2466 -413
- package/dist/bin/exe-status.js +474 -317
- package/dist/bin/exe-team.js +474 -317
- package/dist/bin/git-sweep.js +2690 -150
- package/dist/bin/graph-backfill.js +794 -637
- package/dist/bin/graph-export.js +798 -641
- package/dist/bin/scan-tasks.js +2951 -44
- package/dist/bin/setup.js +62 -26
- package/dist/bin/shard-migrate.js +792 -637
- package/dist/bin/wiki-sync.js +794 -637
- package/dist/gateway/index.js +2504 -1895
- package/dist/hooks/bug-report-worker.js +2118 -576
- package/dist/hooks/commit-complete.js +2689 -149
- package/dist/hooks/error-recall.js +154 -3
- package/dist/hooks/ingest-worker.js +1439 -815
- package/dist/hooks/instructions-loaded.js +151 -0
- package/dist/hooks/notification.js +153 -2
- package/dist/hooks/post-compact.js +164 -0
- package/dist/hooks/pre-compact.js +3073 -101
- package/dist/hooks/pre-tool-use.js +151 -0
- package/dist/hooks/prompt-ingest-worker.js +1714 -1537
- package/dist/hooks/prompt-submit.js +2658 -1113
- package/dist/hooks/response-ingest-worker.js +170 -6
- package/dist/hooks/session-end.js +153 -2
- package/dist/hooks/session-start.js +154 -3
- package/dist/hooks/stop.js +151 -0
- package/dist/hooks/subagent-stop.js +151 -0
- package/dist/hooks/summary-worker.js +179 -7
- package/dist/index.js +278 -100
- package/dist/lib/cloud-sync.js +28 -2
- package/dist/lib/consolidation.js +69 -2
- package/dist/lib/database.js +19 -0
- package/dist/lib/device-registry.js +19 -0
- package/dist/lib/employee-templates.js +20 -1
- package/dist/lib/exe-daemon.js +236 -16
- package/dist/lib/hybrid-search.js +154 -3
- package/dist/lib/license.js +15 -1
- package/dist/lib/messaging.js +39 -2
- package/dist/lib/schedules.js +792 -637
- package/dist/lib/store.js +796 -636
- package/dist/lib/tasks.js +1614 -1091
- package/dist/lib/tmux-routing.js +149 -9
- package/dist/mcp/server.js +1825 -1138
- package/dist/mcp/tools/create-task.js +2280 -828
- package/dist/mcp/tools/list-tasks.js +2788 -159
- package/dist/mcp/tools/send-message.js +39 -2
- package/dist/mcp/tools/update-task.js +64 -0
- package/dist/runtime/index.js +235 -67
- package/dist/tui/App.js +1452 -644
- package/package.json +3 -2
package/dist/bin/exe-review.js
CHANGED
|
@@ -198,282 +198,7 @@ var init_config = __esm({
|
|
|
198
198
|
}
|
|
199
199
|
});
|
|
200
200
|
|
|
201
|
-
// src/lib/shard-manager.ts
|
|
202
|
-
var shard_manager_exports = {};
|
|
203
|
-
__export(shard_manager_exports, {
|
|
204
|
-
disposeShards: () => disposeShards,
|
|
205
|
-
ensureShardSchema: () => ensureShardSchema,
|
|
206
|
-
getReadyShardClient: () => getReadyShardClient,
|
|
207
|
-
getShardClient: () => getShardClient,
|
|
208
|
-
getShardsDir: () => getShardsDir,
|
|
209
|
-
initShardManager: () => initShardManager,
|
|
210
|
-
isShardingEnabled: () => isShardingEnabled,
|
|
211
|
-
listShards: () => listShards,
|
|
212
|
-
shardExists: () => shardExists
|
|
213
|
-
});
|
|
214
|
-
import path4 from "path";
|
|
215
|
-
import { existsSync as existsSync4, mkdirSync, readdirSync } from "fs";
|
|
216
|
-
import { createClient as createClient2 } from "@libsql/client";
|
|
217
|
-
function initShardManager(encryptionKey) {
|
|
218
|
-
_encryptionKey = encryptionKey;
|
|
219
|
-
if (!existsSync4(SHARDS_DIR)) {
|
|
220
|
-
mkdirSync(SHARDS_DIR, { recursive: true });
|
|
221
|
-
}
|
|
222
|
-
_shardingEnabled = true;
|
|
223
|
-
}
|
|
224
|
-
function isShardingEnabled() {
|
|
225
|
-
return _shardingEnabled;
|
|
226
|
-
}
|
|
227
|
-
function getShardsDir() {
|
|
228
|
-
return SHARDS_DIR;
|
|
229
|
-
}
|
|
230
|
-
function getShardClient(projectName) {
|
|
231
|
-
if (!_encryptionKey) {
|
|
232
|
-
throw new Error("Shard manager not initialized. Call initShardManager() first.");
|
|
233
|
-
}
|
|
234
|
-
const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
235
|
-
if (!safeName) {
|
|
236
|
-
throw new Error(`Invalid project name for shard: "${projectName}"`);
|
|
237
|
-
}
|
|
238
|
-
const cached = _shards.get(safeName);
|
|
239
|
-
if (cached) return cached;
|
|
240
|
-
const dbPath = path4.join(SHARDS_DIR, `${safeName}.db`);
|
|
241
|
-
const client = createClient2({
|
|
242
|
-
url: `file:${dbPath}`,
|
|
243
|
-
encryptionKey: _encryptionKey
|
|
244
|
-
});
|
|
245
|
-
_shards.set(safeName, client);
|
|
246
|
-
return client;
|
|
247
|
-
}
|
|
248
|
-
function shardExists(projectName) {
|
|
249
|
-
const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
250
|
-
return existsSync4(path4.join(SHARDS_DIR, `${safeName}.db`));
|
|
251
|
-
}
|
|
252
|
-
function listShards() {
|
|
253
|
-
if (!existsSync4(SHARDS_DIR)) return [];
|
|
254
|
-
return readdirSync(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
|
|
255
|
-
}
|
|
256
|
-
async function ensureShardSchema(client) {
|
|
257
|
-
await client.execute("PRAGMA journal_mode = WAL");
|
|
258
|
-
await client.execute("PRAGMA busy_timeout = 30000");
|
|
259
|
-
try {
|
|
260
|
-
await client.execute("PRAGMA libsql_vector_search_ef = 128");
|
|
261
|
-
} catch {
|
|
262
|
-
}
|
|
263
|
-
await client.executeMultiple(`
|
|
264
|
-
CREATE TABLE IF NOT EXISTS memories (
|
|
265
|
-
id TEXT PRIMARY KEY,
|
|
266
|
-
agent_id TEXT NOT NULL,
|
|
267
|
-
agent_role TEXT NOT NULL,
|
|
268
|
-
session_id TEXT NOT NULL,
|
|
269
|
-
timestamp TEXT NOT NULL,
|
|
270
|
-
tool_name TEXT NOT NULL,
|
|
271
|
-
project_name TEXT NOT NULL,
|
|
272
|
-
has_error INTEGER NOT NULL DEFAULT 0,
|
|
273
|
-
raw_text TEXT NOT NULL,
|
|
274
|
-
vector F32_BLOB(1024),
|
|
275
|
-
version INTEGER NOT NULL DEFAULT 0
|
|
276
|
-
);
|
|
277
|
-
|
|
278
|
-
CREATE INDEX IF NOT EXISTS idx_memories_agent ON memories(agent_id);
|
|
279
|
-
CREATE INDEX IF NOT EXISTS idx_memories_timestamp ON memories(timestamp);
|
|
280
|
-
CREATE INDEX IF NOT EXISTS idx_memories_agent_project ON memories(agent_id, project_name);
|
|
281
|
-
`);
|
|
282
|
-
await client.executeMultiple(`
|
|
283
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts USING fts5(
|
|
284
|
-
raw_text,
|
|
285
|
-
content='memories',
|
|
286
|
-
content_rowid='rowid'
|
|
287
|
-
);
|
|
288
|
-
|
|
289
|
-
CREATE TRIGGER IF NOT EXISTS memories_fts_ai AFTER INSERT ON memories BEGIN
|
|
290
|
-
INSERT INTO memories_fts(rowid, raw_text) VALUES (new.rowid, new.raw_text);
|
|
291
|
-
END;
|
|
292
|
-
|
|
293
|
-
CREATE TRIGGER IF NOT EXISTS memories_fts_ad AFTER DELETE ON memories BEGIN
|
|
294
|
-
INSERT INTO memories_fts(memories_fts, rowid, raw_text) VALUES('delete', old.rowid, old.raw_text);
|
|
295
|
-
END;
|
|
296
|
-
|
|
297
|
-
CREATE TRIGGER IF NOT EXISTS memories_fts_au AFTER UPDATE ON memories BEGIN
|
|
298
|
-
INSERT INTO memories_fts(memories_fts, rowid, raw_text) VALUES('delete', old.rowid, old.raw_text);
|
|
299
|
-
INSERT INTO memories_fts(rowid, raw_text) VALUES (new.rowid, new.raw_text);
|
|
300
|
-
END;
|
|
301
|
-
`);
|
|
302
|
-
for (const col of [
|
|
303
|
-
"ALTER TABLE memories ADD COLUMN task_id TEXT",
|
|
304
|
-
"ALTER TABLE memories ADD COLUMN consolidated INTEGER NOT NULL DEFAULT 0",
|
|
305
|
-
"ALTER TABLE memories ADD COLUMN importance INTEGER DEFAULT 5",
|
|
306
|
-
"ALTER TABLE memories ADD COLUMN status TEXT DEFAULT 'active'",
|
|
307
|
-
"ALTER TABLE memories ADD COLUMN wiki_synced INTEGER DEFAULT 0",
|
|
308
|
-
"ALTER TABLE memories ADD COLUMN graph_extracted INTEGER DEFAULT 0",
|
|
309
|
-
"ALTER TABLE memories ADD COLUMN content_hash TEXT",
|
|
310
|
-
"ALTER TABLE memories ADD COLUMN graph_extracted_hash TEXT",
|
|
311
|
-
"ALTER TABLE memories ADD COLUMN confidence REAL DEFAULT 0.7",
|
|
312
|
-
"ALTER TABLE memories ADD COLUMN last_accessed TEXT",
|
|
313
|
-
// Wiki linkage columns (must match database.ts)
|
|
314
|
-
"ALTER TABLE memories ADD COLUMN workspace_id TEXT",
|
|
315
|
-
"ALTER TABLE memories ADD COLUMN document_id TEXT",
|
|
316
|
-
"ALTER TABLE memories ADD COLUMN user_id TEXT",
|
|
317
|
-
"ALTER TABLE memories ADD COLUMN char_offset INTEGER",
|
|
318
|
-
"ALTER TABLE memories ADD COLUMN page_number INTEGER",
|
|
319
|
-
// Source provenance columns (must match database.ts)
|
|
320
|
-
"ALTER TABLE memories ADD COLUMN source_path TEXT",
|
|
321
|
-
"ALTER TABLE memories ADD COLUMN source_type TEXT DEFAULT 'text'",
|
|
322
|
-
"ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3",
|
|
323
|
-
"ALTER TABLE memories ADD COLUMN supersedes_id TEXT"
|
|
324
|
-
]) {
|
|
325
|
-
try {
|
|
326
|
-
await client.execute(col);
|
|
327
|
-
} catch {
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
for (const idx of [
|
|
331
|
-
"CREATE INDEX IF NOT EXISTS idx_memories_tier ON memories(tier)",
|
|
332
|
-
"CREATE INDEX IF NOT EXISTS idx_memories_supersedes ON memories(supersedes_id) WHERE supersedes_id IS NOT NULL"
|
|
333
|
-
]) {
|
|
334
|
-
try {
|
|
335
|
-
await client.execute(idx);
|
|
336
|
-
} catch {
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
try {
|
|
340
|
-
await client.execute("CREATE INDEX IF NOT EXISTS idx_memories_status ON memories(status)");
|
|
341
|
-
} catch {
|
|
342
|
-
}
|
|
343
|
-
for (const idx of [
|
|
344
|
-
"CREATE INDEX IF NOT EXISTS idx_memories_workspace ON memories(workspace_id)",
|
|
345
|
-
"CREATE INDEX IF NOT EXISTS idx_memories_document ON memories(document_id)",
|
|
346
|
-
"CREATE INDEX IF NOT EXISTS idx_memories_user ON memories(user_id)"
|
|
347
|
-
]) {
|
|
348
|
-
try {
|
|
349
|
-
await client.execute(idx);
|
|
350
|
-
} catch {
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
await client.executeMultiple(`
|
|
354
|
-
CREATE TABLE IF NOT EXISTS entities (
|
|
355
|
-
id TEXT PRIMARY KEY,
|
|
356
|
-
name TEXT NOT NULL,
|
|
357
|
-
type TEXT NOT NULL,
|
|
358
|
-
first_seen TEXT NOT NULL,
|
|
359
|
-
last_seen TEXT NOT NULL,
|
|
360
|
-
properties TEXT DEFAULT '{}',
|
|
361
|
-
UNIQUE(name, type)
|
|
362
|
-
);
|
|
363
|
-
|
|
364
|
-
CREATE TABLE IF NOT EXISTS relationships (
|
|
365
|
-
id TEXT PRIMARY KEY,
|
|
366
|
-
source_entity_id TEXT NOT NULL,
|
|
367
|
-
target_entity_id TEXT NOT NULL,
|
|
368
|
-
type TEXT NOT NULL,
|
|
369
|
-
weight REAL DEFAULT 1.0,
|
|
370
|
-
timestamp TEXT NOT NULL,
|
|
371
|
-
properties TEXT DEFAULT '{}',
|
|
372
|
-
UNIQUE(source_entity_id, target_entity_id, type)
|
|
373
|
-
);
|
|
374
|
-
|
|
375
|
-
CREATE TABLE IF NOT EXISTS entity_memories (
|
|
376
|
-
entity_id TEXT NOT NULL,
|
|
377
|
-
memory_id TEXT NOT NULL,
|
|
378
|
-
PRIMARY KEY (entity_id, memory_id)
|
|
379
|
-
);
|
|
380
|
-
|
|
381
|
-
CREATE TABLE IF NOT EXISTS relationship_memories (
|
|
382
|
-
relationship_id TEXT NOT NULL,
|
|
383
|
-
memory_id TEXT NOT NULL,
|
|
384
|
-
PRIMARY KEY (relationship_id, memory_id)
|
|
385
|
-
);
|
|
386
|
-
|
|
387
|
-
CREATE INDEX IF NOT EXISTS idx_entities_name ON entities(name);
|
|
388
|
-
CREATE INDEX IF NOT EXISTS idx_entities_type ON entities(type);
|
|
389
|
-
CREATE INDEX IF NOT EXISTS idx_relationships_source ON relationships(source_entity_id);
|
|
390
|
-
CREATE INDEX IF NOT EXISTS idx_relationships_target ON relationships(target_entity_id);
|
|
391
|
-
CREATE INDEX IF NOT EXISTS idx_relationships_type ON relationships(type);
|
|
392
|
-
|
|
393
|
-
CREATE TABLE IF NOT EXISTS hyperedges (
|
|
394
|
-
id TEXT PRIMARY KEY,
|
|
395
|
-
label TEXT NOT NULL,
|
|
396
|
-
relation TEXT NOT NULL,
|
|
397
|
-
confidence REAL DEFAULT 1.0,
|
|
398
|
-
timestamp TEXT NOT NULL
|
|
399
|
-
);
|
|
400
|
-
|
|
401
|
-
CREATE TABLE IF NOT EXISTS hyperedge_nodes (
|
|
402
|
-
hyperedge_id TEXT NOT NULL,
|
|
403
|
-
entity_id TEXT NOT NULL,
|
|
404
|
-
PRIMARY KEY (hyperedge_id, entity_id)
|
|
405
|
-
);
|
|
406
|
-
`);
|
|
407
|
-
for (const col of [
|
|
408
|
-
"ALTER TABLE relationships ADD COLUMN confidence REAL DEFAULT 1.0",
|
|
409
|
-
"ALTER TABLE relationships ADD COLUMN confidence_label TEXT DEFAULT 'extracted'"
|
|
410
|
-
]) {
|
|
411
|
-
try {
|
|
412
|
-
await client.execute(col);
|
|
413
|
-
} catch {
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
async function getReadyShardClient(projectName) {
|
|
418
|
-
const client = getShardClient(projectName);
|
|
419
|
-
await ensureShardSchema(client);
|
|
420
|
-
return client;
|
|
421
|
-
}
|
|
422
|
-
function disposeShards() {
|
|
423
|
-
for (const [, client] of _shards) {
|
|
424
|
-
client.close();
|
|
425
|
-
}
|
|
426
|
-
_shards.clear();
|
|
427
|
-
_shardingEnabled = false;
|
|
428
|
-
_encryptionKey = null;
|
|
429
|
-
}
|
|
430
|
-
var SHARDS_DIR, _shards, _encryptionKey, _shardingEnabled;
|
|
431
|
-
var init_shard_manager = __esm({
|
|
432
|
-
"src/lib/shard-manager.ts"() {
|
|
433
|
-
"use strict";
|
|
434
|
-
init_config();
|
|
435
|
-
SHARDS_DIR = path4.join(EXE_AI_DIR, "shards");
|
|
436
|
-
_shards = /* @__PURE__ */ new Map();
|
|
437
|
-
_encryptionKey = null;
|
|
438
|
-
_shardingEnabled = false;
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
// src/bin/exe-review.ts
|
|
443
|
-
import { randomUUID } from "crypto";
|
|
444
|
-
|
|
445
|
-
// src/lib/employees.ts
|
|
446
|
-
init_config();
|
|
447
|
-
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
448
|
-
import { existsSync as existsSync2, symlinkSync, readlinkSync, readFileSync as readFileSync2 } from "fs";
|
|
449
|
-
import { execSync } from "child_process";
|
|
450
|
-
import path2 from "path";
|
|
451
|
-
var EMPLOYEES_PATH = path2.join(EXE_AI_DIR, "exe-employees.json");
|
|
452
|
-
async function loadEmployees(employeesPath = EMPLOYEES_PATH) {
|
|
453
|
-
if (!existsSync2(employeesPath)) {
|
|
454
|
-
return [];
|
|
455
|
-
}
|
|
456
|
-
const raw = await readFile2(employeesPath, "utf-8");
|
|
457
|
-
try {
|
|
458
|
-
return JSON.parse(raw);
|
|
459
|
-
} catch {
|
|
460
|
-
return [];
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
function getEmployee(employees, name) {
|
|
464
|
-
return employees.find((e) => e.name.toLowerCase() === name.toLowerCase());
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
// src/types/memory.ts
|
|
468
|
-
var EMBEDDING_DIM = 1024;
|
|
469
|
-
|
|
470
|
-
// src/lib/database.ts
|
|
471
|
-
import { createClient } from "@libsql/client";
|
|
472
|
-
|
|
473
201
|
// src/lib/db-retry.ts
|
|
474
|
-
var MAX_RETRIES = 3;
|
|
475
|
-
var BASE_DELAY_MS = 200;
|
|
476
|
-
var MAX_JITTER_MS = 300;
|
|
477
202
|
function isBusyError(err) {
|
|
478
203
|
if (err instanceof Error) {
|
|
479
204
|
const msg = err.message.toLowerCase();
|
|
@@ -518,11 +243,18 @@ function wrapWithRetry(client) {
|
|
|
518
243
|
}
|
|
519
244
|
});
|
|
520
245
|
}
|
|
246
|
+
var MAX_RETRIES, BASE_DELAY_MS, MAX_JITTER_MS;
|
|
247
|
+
var init_db_retry = __esm({
|
|
248
|
+
"src/lib/db-retry.ts"() {
|
|
249
|
+
"use strict";
|
|
250
|
+
MAX_RETRIES = 3;
|
|
251
|
+
BASE_DELAY_MS = 200;
|
|
252
|
+
MAX_JITTER_MS = 300;
|
|
253
|
+
}
|
|
254
|
+
});
|
|
521
255
|
|
|
522
256
|
// src/lib/database.ts
|
|
523
|
-
|
|
524
|
-
var _resilientClient = null;
|
|
525
|
-
var initTurso = initDatabase;
|
|
257
|
+
import { createClient } from "@libsql/client";
|
|
526
258
|
async function initDatabase(config) {
|
|
527
259
|
if (_client) {
|
|
528
260
|
_client.close();
|
|
@@ -759,6 +491,13 @@ async function ensureSchema() {
|
|
|
759
491
|
});
|
|
760
492
|
} catch {
|
|
761
493
|
}
|
|
494
|
+
try {
|
|
495
|
+
await client.execute({
|
|
496
|
+
sql: `ALTER TABLE tasks ADD COLUMN session_scope TEXT`,
|
|
497
|
+
args: []
|
|
498
|
+
});
|
|
499
|
+
} catch {
|
|
500
|
+
}
|
|
762
501
|
try {
|
|
763
502
|
await client.execute({
|
|
764
503
|
sql: `ALTER TABLE memories ADD COLUMN task_id TEXT`,
|
|
@@ -1205,6 +944,18 @@ async function ensureSchema() {
|
|
|
1205
944
|
CREATE INDEX IF NOT EXISTS idx_session_kills_agent
|
|
1206
945
|
ON session_kills(agent_id);
|
|
1207
946
|
`);
|
|
947
|
+
await client.execute(`
|
|
948
|
+
CREATE TABLE IF NOT EXISTS global_procedures (
|
|
949
|
+
id TEXT PRIMARY KEY,
|
|
950
|
+
title TEXT NOT NULL,
|
|
951
|
+
content TEXT NOT NULL,
|
|
952
|
+
priority TEXT NOT NULL DEFAULT 'p0',
|
|
953
|
+
domain TEXT,
|
|
954
|
+
active INTEGER NOT NULL DEFAULT 1,
|
|
955
|
+
created_at TEXT NOT NULL,
|
|
956
|
+
updated_at TEXT NOT NULL
|
|
957
|
+
)
|
|
958
|
+
`);
|
|
1208
959
|
await client.executeMultiple(`
|
|
1209
960
|
CREATE TABLE IF NOT EXISTS conversations (
|
|
1210
961
|
id TEXT PRIMARY KEY,
|
|
@@ -1271,71 +1022,298 @@ async function ensureSchema() {
|
|
|
1271
1022
|
} catch {
|
|
1272
1023
|
}
|
|
1273
1024
|
await client.executeMultiple(`
|
|
1274
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS conversations_fts USING fts5(
|
|
1275
|
-
content_text,
|
|
1276
|
-
sender_name,
|
|
1277
|
-
agent_response,
|
|
1278
|
-
content='conversations',
|
|
1025
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS conversations_fts USING fts5(
|
|
1026
|
+
content_text,
|
|
1027
|
+
sender_name,
|
|
1028
|
+
agent_response,
|
|
1029
|
+
content='conversations',
|
|
1030
|
+
content_rowid='rowid'
|
|
1031
|
+
);
|
|
1032
|
+
|
|
1033
|
+
CREATE TRIGGER IF NOT EXISTS conversations_fts_ai AFTER INSERT ON conversations BEGIN
|
|
1034
|
+
INSERT INTO conversations_fts(rowid, content_text, sender_name, agent_response)
|
|
1035
|
+
VALUES (new.rowid, new.content_text, new.sender_name, new.agent_response);
|
|
1036
|
+
END;
|
|
1037
|
+
|
|
1038
|
+
CREATE TRIGGER IF NOT EXISTS conversations_fts_ad AFTER DELETE ON conversations BEGIN
|
|
1039
|
+
INSERT INTO conversations_fts(conversations_fts, rowid, content_text, sender_name, agent_response)
|
|
1040
|
+
VALUES('delete', old.rowid, old.content_text, old.sender_name, old.agent_response);
|
|
1041
|
+
END;
|
|
1042
|
+
|
|
1043
|
+
CREATE TRIGGER IF NOT EXISTS conversations_fts_au AFTER UPDATE ON conversations BEGIN
|
|
1044
|
+
INSERT INTO conversations_fts(conversations_fts, rowid, content_text, sender_name, agent_response)
|
|
1045
|
+
VALUES('delete', old.rowid, old.content_text, old.sender_name, old.agent_response);
|
|
1046
|
+
INSERT INTO conversations_fts(rowid, content_text, sender_name, agent_response)
|
|
1047
|
+
VALUES (new.rowid, new.content_text, new.sender_name, new.agent_response);
|
|
1048
|
+
END;
|
|
1049
|
+
`);
|
|
1050
|
+
try {
|
|
1051
|
+
await client.execute({
|
|
1052
|
+
sql: `ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3`,
|
|
1053
|
+
args: []
|
|
1054
|
+
});
|
|
1055
|
+
} catch {
|
|
1056
|
+
}
|
|
1057
|
+
try {
|
|
1058
|
+
await client.execute(
|
|
1059
|
+
`CREATE INDEX IF NOT EXISTS idx_memories_tier ON memories(tier)`
|
|
1060
|
+
);
|
|
1061
|
+
} catch {
|
|
1062
|
+
}
|
|
1063
|
+
try {
|
|
1064
|
+
await client.execute({
|
|
1065
|
+
sql: `UPDATE memories SET tier = 1 WHERE tool_name = 'commit_to_long_term_memory' AND importance >= 8 AND tier = 3`,
|
|
1066
|
+
args: []
|
|
1067
|
+
});
|
|
1068
|
+
await client.execute({
|
|
1069
|
+
sql: `UPDATE memories SET tier = 2 WHERE tool_name IN ('store_memory', 'manual') AND importance >= 5 AND tier = 3`,
|
|
1070
|
+
args: []
|
|
1071
|
+
});
|
|
1072
|
+
} catch {
|
|
1073
|
+
}
|
|
1074
|
+
try {
|
|
1075
|
+
await client.execute({
|
|
1076
|
+
sql: `ALTER TABLE memories ADD COLUMN supersedes_id TEXT`,
|
|
1077
|
+
args: []
|
|
1078
|
+
});
|
|
1079
|
+
} catch {
|
|
1080
|
+
}
|
|
1081
|
+
try {
|
|
1082
|
+
await client.execute(
|
|
1083
|
+
`CREATE INDEX IF NOT EXISTS idx_memories_supersedes ON memories(supersedes_id) WHERE supersedes_id IS NOT NULL`
|
|
1084
|
+
);
|
|
1085
|
+
} catch {
|
|
1086
|
+
}
|
|
1087
|
+
for (const col of [
|
|
1088
|
+
"ALTER TABLE tasks ADD COLUMN checkpoint TEXT",
|
|
1089
|
+
"ALTER TABLE tasks ADD COLUMN checkpoint_count INTEGER DEFAULT 0"
|
|
1090
|
+
]) {
|
|
1091
|
+
try {
|
|
1092
|
+
await client.execute(col);
|
|
1093
|
+
} catch {
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
var _client, _resilientClient, initTurso;
|
|
1098
|
+
var init_database = __esm({
|
|
1099
|
+
"src/lib/database.ts"() {
|
|
1100
|
+
"use strict";
|
|
1101
|
+
init_db_retry();
|
|
1102
|
+
_client = null;
|
|
1103
|
+
_resilientClient = null;
|
|
1104
|
+
initTurso = initDatabase;
|
|
1105
|
+
}
|
|
1106
|
+
});
|
|
1107
|
+
|
|
1108
|
+
// src/lib/shard-manager.ts
|
|
1109
|
+
var shard_manager_exports = {};
|
|
1110
|
+
__export(shard_manager_exports, {
|
|
1111
|
+
disposeShards: () => disposeShards,
|
|
1112
|
+
ensureShardSchema: () => ensureShardSchema,
|
|
1113
|
+
getReadyShardClient: () => getReadyShardClient,
|
|
1114
|
+
getShardClient: () => getShardClient,
|
|
1115
|
+
getShardsDir: () => getShardsDir,
|
|
1116
|
+
initShardManager: () => initShardManager,
|
|
1117
|
+
isShardingEnabled: () => isShardingEnabled,
|
|
1118
|
+
listShards: () => listShards,
|
|
1119
|
+
shardExists: () => shardExists
|
|
1120
|
+
});
|
|
1121
|
+
import path4 from "path";
|
|
1122
|
+
import { existsSync as existsSync4, mkdirSync, readdirSync } from "fs";
|
|
1123
|
+
import { createClient as createClient2 } from "@libsql/client";
|
|
1124
|
+
function initShardManager(encryptionKey) {
|
|
1125
|
+
_encryptionKey = encryptionKey;
|
|
1126
|
+
if (!existsSync4(SHARDS_DIR)) {
|
|
1127
|
+
mkdirSync(SHARDS_DIR, { recursive: true });
|
|
1128
|
+
}
|
|
1129
|
+
_shardingEnabled = true;
|
|
1130
|
+
}
|
|
1131
|
+
function isShardingEnabled() {
|
|
1132
|
+
return _shardingEnabled;
|
|
1133
|
+
}
|
|
1134
|
+
function getShardsDir() {
|
|
1135
|
+
return SHARDS_DIR;
|
|
1136
|
+
}
|
|
1137
|
+
function getShardClient(projectName) {
|
|
1138
|
+
if (!_encryptionKey) {
|
|
1139
|
+
throw new Error("Shard manager not initialized. Call initShardManager() first.");
|
|
1140
|
+
}
|
|
1141
|
+
const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1142
|
+
if (!safeName) {
|
|
1143
|
+
throw new Error(`Invalid project name for shard: "${projectName}"`);
|
|
1144
|
+
}
|
|
1145
|
+
const cached = _shards.get(safeName);
|
|
1146
|
+
if (cached) return cached;
|
|
1147
|
+
const dbPath = path4.join(SHARDS_DIR, `${safeName}.db`);
|
|
1148
|
+
const client = createClient2({
|
|
1149
|
+
url: `file:${dbPath}`,
|
|
1150
|
+
encryptionKey: _encryptionKey
|
|
1151
|
+
});
|
|
1152
|
+
_shards.set(safeName, client);
|
|
1153
|
+
return client;
|
|
1154
|
+
}
|
|
1155
|
+
function shardExists(projectName) {
|
|
1156
|
+
const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1157
|
+
return existsSync4(path4.join(SHARDS_DIR, `${safeName}.db`));
|
|
1158
|
+
}
|
|
1159
|
+
function listShards() {
|
|
1160
|
+
if (!existsSync4(SHARDS_DIR)) return [];
|
|
1161
|
+
return readdirSync(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
|
|
1162
|
+
}
|
|
1163
|
+
async function ensureShardSchema(client) {
|
|
1164
|
+
await client.execute("PRAGMA journal_mode = WAL");
|
|
1165
|
+
await client.execute("PRAGMA busy_timeout = 30000");
|
|
1166
|
+
try {
|
|
1167
|
+
await client.execute("PRAGMA libsql_vector_search_ef = 128");
|
|
1168
|
+
} catch {
|
|
1169
|
+
}
|
|
1170
|
+
await client.executeMultiple(`
|
|
1171
|
+
CREATE TABLE IF NOT EXISTS memories (
|
|
1172
|
+
id TEXT PRIMARY KEY,
|
|
1173
|
+
agent_id TEXT NOT NULL,
|
|
1174
|
+
agent_role TEXT NOT NULL,
|
|
1175
|
+
session_id TEXT NOT NULL,
|
|
1176
|
+
timestamp TEXT NOT NULL,
|
|
1177
|
+
tool_name TEXT NOT NULL,
|
|
1178
|
+
project_name TEXT NOT NULL,
|
|
1179
|
+
has_error INTEGER NOT NULL DEFAULT 0,
|
|
1180
|
+
raw_text TEXT NOT NULL,
|
|
1181
|
+
vector F32_BLOB(1024),
|
|
1182
|
+
version INTEGER NOT NULL DEFAULT 0
|
|
1183
|
+
);
|
|
1184
|
+
|
|
1185
|
+
CREATE INDEX IF NOT EXISTS idx_memories_agent ON memories(agent_id);
|
|
1186
|
+
CREATE INDEX IF NOT EXISTS idx_memories_timestamp ON memories(timestamp);
|
|
1187
|
+
CREATE INDEX IF NOT EXISTS idx_memories_agent_project ON memories(agent_id, project_name);
|
|
1188
|
+
`);
|
|
1189
|
+
await client.executeMultiple(`
|
|
1190
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts USING fts5(
|
|
1191
|
+
raw_text,
|
|
1192
|
+
content='memories',
|
|
1279
1193
|
content_rowid='rowid'
|
|
1280
1194
|
);
|
|
1281
1195
|
|
|
1282
|
-
CREATE TRIGGER IF NOT EXISTS
|
|
1283
|
-
INSERT INTO
|
|
1284
|
-
VALUES (new.rowid, new.content_text, new.sender_name, new.agent_response);
|
|
1196
|
+
CREATE TRIGGER IF NOT EXISTS memories_fts_ai AFTER INSERT ON memories BEGIN
|
|
1197
|
+
INSERT INTO memories_fts(rowid, raw_text) VALUES (new.rowid, new.raw_text);
|
|
1285
1198
|
END;
|
|
1286
1199
|
|
|
1287
|
-
CREATE TRIGGER IF NOT EXISTS
|
|
1288
|
-
INSERT INTO
|
|
1289
|
-
VALUES('delete', old.rowid, old.content_text, old.sender_name, old.agent_response);
|
|
1200
|
+
CREATE TRIGGER IF NOT EXISTS memories_fts_ad AFTER DELETE ON memories BEGIN
|
|
1201
|
+
INSERT INTO memories_fts(memories_fts, rowid, raw_text) VALUES('delete', old.rowid, old.raw_text);
|
|
1290
1202
|
END;
|
|
1291
1203
|
|
|
1292
|
-
CREATE TRIGGER IF NOT EXISTS
|
|
1293
|
-
INSERT INTO
|
|
1294
|
-
|
|
1295
|
-
INSERT INTO conversations_fts(rowid, content_text, sender_name, agent_response)
|
|
1296
|
-
VALUES (new.rowid, new.content_text, new.sender_name, new.agent_response);
|
|
1204
|
+
CREATE TRIGGER IF NOT EXISTS memories_fts_au AFTER UPDATE ON memories BEGIN
|
|
1205
|
+
INSERT INTO memories_fts(memories_fts, rowid, raw_text) VALUES('delete', old.rowid, old.raw_text);
|
|
1206
|
+
INSERT INTO memories_fts(rowid, raw_text) VALUES (new.rowid, new.raw_text);
|
|
1297
1207
|
END;
|
|
1298
1208
|
`);
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1209
|
+
for (const col of [
|
|
1210
|
+
"ALTER TABLE memories ADD COLUMN task_id TEXT",
|
|
1211
|
+
"ALTER TABLE memories ADD COLUMN consolidated INTEGER NOT NULL DEFAULT 0",
|
|
1212
|
+
"ALTER TABLE memories ADD COLUMN importance INTEGER DEFAULT 5",
|
|
1213
|
+
"ALTER TABLE memories ADD COLUMN status TEXT DEFAULT 'active'",
|
|
1214
|
+
"ALTER TABLE memories ADD COLUMN wiki_synced INTEGER DEFAULT 0",
|
|
1215
|
+
"ALTER TABLE memories ADD COLUMN graph_extracted INTEGER DEFAULT 0",
|
|
1216
|
+
"ALTER TABLE memories ADD COLUMN content_hash TEXT",
|
|
1217
|
+
"ALTER TABLE memories ADD COLUMN graph_extracted_hash TEXT",
|
|
1218
|
+
"ALTER TABLE memories ADD COLUMN confidence REAL DEFAULT 0.7",
|
|
1219
|
+
"ALTER TABLE memories ADD COLUMN last_accessed TEXT",
|
|
1220
|
+
// Wiki linkage columns (must match database.ts)
|
|
1221
|
+
"ALTER TABLE memories ADD COLUMN workspace_id TEXT",
|
|
1222
|
+
"ALTER TABLE memories ADD COLUMN document_id TEXT",
|
|
1223
|
+
"ALTER TABLE memories ADD COLUMN user_id TEXT",
|
|
1224
|
+
"ALTER TABLE memories ADD COLUMN char_offset INTEGER",
|
|
1225
|
+
"ALTER TABLE memories ADD COLUMN page_number INTEGER",
|
|
1226
|
+
// Source provenance columns (must match database.ts)
|
|
1227
|
+
"ALTER TABLE memories ADD COLUMN source_path TEXT",
|
|
1228
|
+
"ALTER TABLE memories ADD COLUMN source_type TEXT DEFAULT 'text'",
|
|
1229
|
+
"ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3",
|
|
1230
|
+
"ALTER TABLE memories ADD COLUMN supersedes_id TEXT"
|
|
1231
|
+
]) {
|
|
1232
|
+
try {
|
|
1233
|
+
await client.execute(col);
|
|
1234
|
+
} catch {
|
|
1235
|
+
}
|
|
1305
1236
|
}
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1237
|
+
for (const idx of [
|
|
1238
|
+
"CREATE INDEX IF NOT EXISTS idx_memories_tier ON memories(tier)",
|
|
1239
|
+
"CREATE INDEX IF NOT EXISTS idx_memories_supersedes ON memories(supersedes_id) WHERE supersedes_id IS NOT NULL"
|
|
1240
|
+
]) {
|
|
1241
|
+
try {
|
|
1242
|
+
await client.execute(idx);
|
|
1243
|
+
} catch {
|
|
1244
|
+
}
|
|
1311
1245
|
}
|
|
1312
1246
|
try {
|
|
1313
|
-
await client.execute(
|
|
1314
|
-
sql: `UPDATE memories SET tier = 1 WHERE tool_name = 'commit_to_long_term_memory' AND importance >= 8 AND tier = 3`,
|
|
1315
|
-
args: []
|
|
1316
|
-
});
|
|
1317
|
-
await client.execute({
|
|
1318
|
-
sql: `UPDATE memories SET tier = 2 WHERE tool_name IN ('store_memory', 'manual') AND importance >= 5 AND tier = 3`,
|
|
1319
|
-
args: []
|
|
1320
|
-
});
|
|
1247
|
+
await client.execute("CREATE INDEX IF NOT EXISTS idx_memories_status ON memories(status)");
|
|
1321
1248
|
} catch {
|
|
1322
1249
|
}
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1250
|
+
for (const idx of [
|
|
1251
|
+
"CREATE INDEX IF NOT EXISTS idx_memories_workspace ON memories(workspace_id)",
|
|
1252
|
+
"CREATE INDEX IF NOT EXISTS idx_memories_document ON memories(document_id)",
|
|
1253
|
+
"CREATE INDEX IF NOT EXISTS idx_memories_user ON memories(user_id)"
|
|
1254
|
+
]) {
|
|
1255
|
+
try {
|
|
1256
|
+
await client.execute(idx);
|
|
1257
|
+
} catch {
|
|
1258
|
+
}
|
|
1329
1259
|
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1260
|
+
await client.executeMultiple(`
|
|
1261
|
+
CREATE TABLE IF NOT EXISTS entities (
|
|
1262
|
+
id TEXT PRIMARY KEY,
|
|
1263
|
+
name TEXT NOT NULL,
|
|
1264
|
+
type TEXT NOT NULL,
|
|
1265
|
+
first_seen TEXT NOT NULL,
|
|
1266
|
+
last_seen TEXT NOT NULL,
|
|
1267
|
+
properties TEXT DEFAULT '{}',
|
|
1268
|
+
UNIQUE(name, type)
|
|
1333
1269
|
);
|
|
1334
|
-
|
|
1335
|
-
|
|
1270
|
+
|
|
1271
|
+
CREATE TABLE IF NOT EXISTS relationships (
|
|
1272
|
+
id TEXT PRIMARY KEY,
|
|
1273
|
+
source_entity_id TEXT NOT NULL,
|
|
1274
|
+
target_entity_id TEXT NOT NULL,
|
|
1275
|
+
type TEXT NOT NULL,
|
|
1276
|
+
weight REAL DEFAULT 1.0,
|
|
1277
|
+
timestamp TEXT NOT NULL,
|
|
1278
|
+
properties TEXT DEFAULT '{}',
|
|
1279
|
+
UNIQUE(source_entity_id, target_entity_id, type)
|
|
1280
|
+
);
|
|
1281
|
+
|
|
1282
|
+
CREATE TABLE IF NOT EXISTS entity_memories (
|
|
1283
|
+
entity_id TEXT NOT NULL,
|
|
1284
|
+
memory_id TEXT NOT NULL,
|
|
1285
|
+
PRIMARY KEY (entity_id, memory_id)
|
|
1286
|
+
);
|
|
1287
|
+
|
|
1288
|
+
CREATE TABLE IF NOT EXISTS relationship_memories (
|
|
1289
|
+
relationship_id TEXT NOT NULL,
|
|
1290
|
+
memory_id TEXT NOT NULL,
|
|
1291
|
+
PRIMARY KEY (relationship_id, memory_id)
|
|
1292
|
+
);
|
|
1293
|
+
|
|
1294
|
+
CREATE INDEX IF NOT EXISTS idx_entities_name ON entities(name);
|
|
1295
|
+
CREATE INDEX IF NOT EXISTS idx_entities_type ON entities(type);
|
|
1296
|
+
CREATE INDEX IF NOT EXISTS idx_relationships_source ON relationships(source_entity_id);
|
|
1297
|
+
CREATE INDEX IF NOT EXISTS idx_relationships_target ON relationships(target_entity_id);
|
|
1298
|
+
CREATE INDEX IF NOT EXISTS idx_relationships_type ON relationships(type);
|
|
1299
|
+
|
|
1300
|
+
CREATE TABLE IF NOT EXISTS hyperedges (
|
|
1301
|
+
id TEXT PRIMARY KEY,
|
|
1302
|
+
label TEXT NOT NULL,
|
|
1303
|
+
relation TEXT NOT NULL,
|
|
1304
|
+
confidence REAL DEFAULT 1.0,
|
|
1305
|
+
timestamp TEXT NOT NULL
|
|
1306
|
+
);
|
|
1307
|
+
|
|
1308
|
+
CREATE TABLE IF NOT EXISTS hyperedge_nodes (
|
|
1309
|
+
hyperedge_id TEXT NOT NULL,
|
|
1310
|
+
entity_id TEXT NOT NULL,
|
|
1311
|
+
PRIMARY KEY (hyperedge_id, entity_id)
|
|
1312
|
+
);
|
|
1313
|
+
`);
|
|
1336
1314
|
for (const col of [
|
|
1337
|
-
"ALTER TABLE
|
|
1338
|
-
"ALTER TABLE
|
|
1315
|
+
"ALTER TABLE relationships ADD COLUMN confidence REAL DEFAULT 1.0",
|
|
1316
|
+
"ALTER TABLE relationships ADD COLUMN confidence_label TEXT DEFAULT 'extracted'"
|
|
1339
1317
|
]) {
|
|
1340
1318
|
try {
|
|
1341
1319
|
await client.execute(col);
|
|
@@ -1343,6 +1321,126 @@ async function ensureSchema() {
|
|
|
1343
1321
|
}
|
|
1344
1322
|
}
|
|
1345
1323
|
}
|
|
1324
|
+
async function getReadyShardClient(projectName) {
|
|
1325
|
+
const client = getShardClient(projectName);
|
|
1326
|
+
await ensureShardSchema(client);
|
|
1327
|
+
return client;
|
|
1328
|
+
}
|
|
1329
|
+
function disposeShards() {
|
|
1330
|
+
for (const [, client] of _shards) {
|
|
1331
|
+
client.close();
|
|
1332
|
+
}
|
|
1333
|
+
_shards.clear();
|
|
1334
|
+
_shardingEnabled = false;
|
|
1335
|
+
_encryptionKey = null;
|
|
1336
|
+
}
|
|
1337
|
+
var SHARDS_DIR, _shards, _encryptionKey, _shardingEnabled;
|
|
1338
|
+
var init_shard_manager = __esm({
|
|
1339
|
+
"src/lib/shard-manager.ts"() {
|
|
1340
|
+
"use strict";
|
|
1341
|
+
init_config();
|
|
1342
|
+
SHARDS_DIR = path4.join(EXE_AI_DIR, "shards");
|
|
1343
|
+
_shards = /* @__PURE__ */ new Map();
|
|
1344
|
+
_encryptionKey = null;
|
|
1345
|
+
_shardingEnabled = false;
|
|
1346
|
+
}
|
|
1347
|
+
});
|
|
1348
|
+
|
|
1349
|
+
// src/lib/global-procedures.ts
|
|
1350
|
+
var global_procedures_exports = {};
|
|
1351
|
+
__export(global_procedures_exports, {
|
|
1352
|
+
deactivateGlobalProcedure: () => deactivateGlobalProcedure,
|
|
1353
|
+
getGlobalProceduresBlock: () => getGlobalProceduresBlock,
|
|
1354
|
+
loadGlobalProcedures: () => loadGlobalProcedures,
|
|
1355
|
+
storeGlobalProcedure: () => storeGlobalProcedure
|
|
1356
|
+
});
|
|
1357
|
+
import { randomUUID } from "crypto";
|
|
1358
|
+
async function loadGlobalProcedures() {
|
|
1359
|
+
const client = getClient();
|
|
1360
|
+
const result = await client.execute({
|
|
1361
|
+
sql: "SELECT * FROM global_procedures WHERE active = 1 ORDER BY priority ASC, created_at ASC",
|
|
1362
|
+
args: []
|
|
1363
|
+
});
|
|
1364
|
+
const procedures = result.rows;
|
|
1365
|
+
if (procedures.length > 0) {
|
|
1366
|
+
_cache = procedures.map((p) => `### ${p.title}
|
|
1367
|
+
${p.content}`).join("\n\n");
|
|
1368
|
+
} else {
|
|
1369
|
+
_cache = "";
|
|
1370
|
+
}
|
|
1371
|
+
_cacheLoaded = true;
|
|
1372
|
+
return procedures;
|
|
1373
|
+
}
|
|
1374
|
+
function getGlobalProceduresBlock() {
|
|
1375
|
+
if (!_cacheLoaded) return "";
|
|
1376
|
+
if (!_cache) return "";
|
|
1377
|
+
return `## Organization-Wide Procedures (MANDATORY \u2014 supersedes all other rules)
|
|
1378
|
+
|
|
1379
|
+
${_cache}
|
|
1380
|
+
`;
|
|
1381
|
+
}
|
|
1382
|
+
async function storeGlobalProcedure(input) {
|
|
1383
|
+
const id = randomUUID();
|
|
1384
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1385
|
+
const client = getClient();
|
|
1386
|
+
await client.execute({
|
|
1387
|
+
sql: `INSERT INTO global_procedures (id, title, content, priority, domain, active, created_at, updated_at)
|
|
1388
|
+
VALUES (?, ?, ?, ?, ?, 1, ?, ?)`,
|
|
1389
|
+
args: [id, input.title, input.content, input.priority ?? "p0", input.domain ?? null, now, now]
|
|
1390
|
+
});
|
|
1391
|
+
await loadGlobalProcedures();
|
|
1392
|
+
return id;
|
|
1393
|
+
}
|
|
1394
|
+
async function deactivateGlobalProcedure(id) {
|
|
1395
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1396
|
+
const client = getClient();
|
|
1397
|
+
const result = await client.execute({
|
|
1398
|
+
sql: "UPDATE global_procedures SET active = 0, updated_at = ? WHERE id = ?",
|
|
1399
|
+
args: [now, id]
|
|
1400
|
+
});
|
|
1401
|
+
await loadGlobalProcedures();
|
|
1402
|
+
return result.rowsAffected > 0;
|
|
1403
|
+
}
|
|
1404
|
+
var _cache, _cacheLoaded;
|
|
1405
|
+
var init_global_procedures = __esm({
|
|
1406
|
+
"src/lib/global-procedures.ts"() {
|
|
1407
|
+
"use strict";
|
|
1408
|
+
init_database();
|
|
1409
|
+
_cache = "";
|
|
1410
|
+
_cacheLoaded = false;
|
|
1411
|
+
}
|
|
1412
|
+
});
|
|
1413
|
+
|
|
1414
|
+
// src/bin/exe-review.ts
|
|
1415
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
1416
|
+
|
|
1417
|
+
// src/lib/employees.ts
|
|
1418
|
+
init_config();
|
|
1419
|
+
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
1420
|
+
import { existsSync as existsSync2, symlinkSync, readlinkSync, readFileSync as readFileSync2 } from "fs";
|
|
1421
|
+
import { execSync } from "child_process";
|
|
1422
|
+
import path2 from "path";
|
|
1423
|
+
var EMPLOYEES_PATH = path2.join(EXE_AI_DIR, "exe-employees.json");
|
|
1424
|
+
async function loadEmployees(employeesPath = EMPLOYEES_PATH) {
|
|
1425
|
+
if (!existsSync2(employeesPath)) {
|
|
1426
|
+
return [];
|
|
1427
|
+
}
|
|
1428
|
+
const raw = await readFile2(employeesPath, "utf-8");
|
|
1429
|
+
try {
|
|
1430
|
+
return JSON.parse(raw);
|
|
1431
|
+
} catch {
|
|
1432
|
+
return [];
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
function getEmployee(employees, name) {
|
|
1436
|
+
return employees.find((e) => e.name.toLowerCase() === name.toLowerCase());
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
// src/types/memory.ts
|
|
1440
|
+
var EMBEDDING_DIM = 1024;
|
|
1441
|
+
|
|
1442
|
+
// src/lib/store.ts
|
|
1443
|
+
init_database();
|
|
1346
1444
|
|
|
1347
1445
|
// src/lib/keychain.ts
|
|
1348
1446
|
import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
|
|
@@ -1390,6 +1488,57 @@ async function getMasterKey() {
|
|
|
1390
1488
|
|
|
1391
1489
|
// src/lib/store.ts
|
|
1392
1490
|
init_config();
|
|
1491
|
+
|
|
1492
|
+
// src/lib/state-bus.ts
|
|
1493
|
+
var StateBus = class {
|
|
1494
|
+
handlers = /* @__PURE__ */ new Map();
|
|
1495
|
+
globalHandlers = /* @__PURE__ */ new Set();
|
|
1496
|
+
/** Emit an event to all subscribers */
|
|
1497
|
+
emit(event) {
|
|
1498
|
+
const typeHandlers = this.handlers.get(event.type);
|
|
1499
|
+
if (typeHandlers) {
|
|
1500
|
+
for (const handler of typeHandlers) {
|
|
1501
|
+
try {
|
|
1502
|
+
handler(event);
|
|
1503
|
+
} catch {
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
for (const handler of this.globalHandlers) {
|
|
1508
|
+
try {
|
|
1509
|
+
handler(event);
|
|
1510
|
+
} catch {
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
/** Subscribe to a specific event type */
|
|
1515
|
+
on(type, handler) {
|
|
1516
|
+
if (!this.handlers.has(type)) {
|
|
1517
|
+
this.handlers.set(type, /* @__PURE__ */ new Set());
|
|
1518
|
+
}
|
|
1519
|
+
this.handlers.get(type).add(handler);
|
|
1520
|
+
}
|
|
1521
|
+
/** Subscribe to ALL events */
|
|
1522
|
+
onAny(handler) {
|
|
1523
|
+
this.globalHandlers.add(handler);
|
|
1524
|
+
}
|
|
1525
|
+
/** Unsubscribe from a specific event type */
|
|
1526
|
+
off(type, handler) {
|
|
1527
|
+
this.handlers.get(type)?.delete(handler);
|
|
1528
|
+
}
|
|
1529
|
+
/** Unsubscribe from ALL events */
|
|
1530
|
+
offAny(handler) {
|
|
1531
|
+
this.globalHandlers.delete(handler);
|
|
1532
|
+
}
|
|
1533
|
+
/** Remove all listeners */
|
|
1534
|
+
clear() {
|
|
1535
|
+
this.handlers.clear();
|
|
1536
|
+
this.globalHandlers.clear();
|
|
1537
|
+
}
|
|
1538
|
+
};
|
|
1539
|
+
var orgBus = new StateBus();
|
|
1540
|
+
|
|
1541
|
+
// src/lib/store.ts
|
|
1393
1542
|
var INIT_MAX_RETRIES = 3;
|
|
1394
1543
|
var INIT_RETRY_DELAY_MS = 1e3;
|
|
1395
1544
|
function isBusyError2(err) {
|
|
@@ -1460,6 +1609,11 @@ async function initStore(options) {
|
|
|
1460
1609
|
"version-query"
|
|
1461
1610
|
);
|
|
1462
1611
|
_nextVersion = (Number(vResult.rows[0]?.max_v) || 0) + 1;
|
|
1612
|
+
try {
|
|
1613
|
+
const { loadGlobalProcedures: loadGlobalProcedures2 } = await Promise.resolve().then(() => (init_global_procedures(), global_procedures_exports));
|
|
1614
|
+
await loadGlobalProcedures2();
|
|
1615
|
+
} catch {
|
|
1616
|
+
}
|
|
1463
1617
|
}
|
|
1464
1618
|
function classifyTier(record) {
|
|
1465
1619
|
if (record.tool_name === "commit_to_long_term_memory" && (record.importance ?? 0) >= 8) return 1;
|
|
@@ -1501,6 +1655,12 @@ async function writeMemory(record) {
|
|
|
1501
1655
|
supersedes_id: record.supersedes_id ?? null
|
|
1502
1656
|
};
|
|
1503
1657
|
_pendingRecords.push(dbRow);
|
|
1658
|
+
orgBus.emit({
|
|
1659
|
+
type: "memory_stored",
|
|
1660
|
+
agentId: record.agent_id,
|
|
1661
|
+
project: record.project_name,
|
|
1662
|
+
timestamp: record.timestamp
|
|
1663
|
+
});
|
|
1504
1664
|
const MAX_PENDING = 1e3;
|
|
1505
1665
|
if (_pendingRecords.length > MAX_PENDING) {
|
|
1506
1666
|
const dropped = _pendingRecords.length - MAX_PENDING;
|
|
@@ -1655,6 +1815,9 @@ function vectorToBlob(vector) {
|
|
|
1655
1815
|
return JSON.stringify(Array.from(f32));
|
|
1656
1816
|
}
|
|
1657
1817
|
|
|
1818
|
+
// src/bin/exe-review.ts
|
|
1819
|
+
init_database();
|
|
1820
|
+
|
|
1658
1821
|
// src/lib/is-main.ts
|
|
1659
1822
|
import { realpathSync } from "fs";
|
|
1660
1823
|
import { fileURLToPath } from "url";
|
|
@@ -1747,7 +1910,7 @@ function generateReviewReport(employeeName, analysis, memories) {
|
|
|
1747
1910
|
}
|
|
1748
1911
|
function createReviewMemory(employeeName, report) {
|
|
1749
1912
|
return {
|
|
1750
|
-
id:
|
|
1913
|
+
id: randomUUID2(),
|
|
1751
1914
|
agent_id: "exe",
|
|
1752
1915
|
agent_role: "COO",
|
|
1753
1916
|
session_id: `review-${employeeName}-${Date.now()}`,
|