@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-team.js
CHANGED
|
@@ -198,273 +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/lib/employees.ts
|
|
443
|
-
init_config();
|
|
444
|
-
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
445
|
-
import { existsSync as existsSync2, symlinkSync, readlinkSync, readFileSync as readFileSync2 } from "fs";
|
|
446
|
-
import { execSync } from "child_process";
|
|
447
|
-
import path2 from "path";
|
|
448
|
-
var EMPLOYEES_PATH = path2.join(EXE_AI_DIR, "exe-employees.json");
|
|
449
|
-
async function loadEmployees(employeesPath = EMPLOYEES_PATH) {
|
|
450
|
-
if (!existsSync2(employeesPath)) {
|
|
451
|
-
return [];
|
|
452
|
-
}
|
|
453
|
-
const raw = await readFile2(employeesPath, "utf-8");
|
|
454
|
-
try {
|
|
455
|
-
return JSON.parse(raw);
|
|
456
|
-
} catch {
|
|
457
|
-
return [];
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
// src/lib/database.ts
|
|
462
|
-
import { createClient } from "@libsql/client";
|
|
463
|
-
|
|
464
201
|
// src/lib/db-retry.ts
|
|
465
|
-
var MAX_RETRIES = 3;
|
|
466
|
-
var BASE_DELAY_MS = 200;
|
|
467
|
-
var MAX_JITTER_MS = 300;
|
|
468
202
|
function isBusyError(err) {
|
|
469
203
|
if (err instanceof Error) {
|
|
470
204
|
const msg = err.message.toLowerCase();
|
|
@@ -509,11 +243,18 @@ function wrapWithRetry(client) {
|
|
|
509
243
|
}
|
|
510
244
|
});
|
|
511
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
|
+
});
|
|
512
255
|
|
|
513
256
|
// src/lib/database.ts
|
|
514
|
-
|
|
515
|
-
var _resilientClient = null;
|
|
516
|
-
var initTurso = initDatabase;
|
|
257
|
+
import { createClient } from "@libsql/client";
|
|
517
258
|
async function initDatabase(config) {
|
|
518
259
|
if (_client) {
|
|
519
260
|
_client.close();
|
|
@@ -750,6 +491,13 @@ async function ensureSchema() {
|
|
|
750
491
|
});
|
|
751
492
|
} catch {
|
|
752
493
|
}
|
|
494
|
+
try {
|
|
495
|
+
await client.execute({
|
|
496
|
+
sql: `ALTER TABLE tasks ADD COLUMN session_scope TEXT`,
|
|
497
|
+
args: []
|
|
498
|
+
});
|
|
499
|
+
} catch {
|
|
500
|
+
}
|
|
753
501
|
try {
|
|
754
502
|
await client.execute({
|
|
755
503
|
sql: `ALTER TABLE memories ADD COLUMN task_id TEXT`,
|
|
@@ -1196,6 +944,18 @@ async function ensureSchema() {
|
|
|
1196
944
|
CREATE INDEX IF NOT EXISTS idx_session_kills_agent
|
|
1197
945
|
ON session_kills(agent_id);
|
|
1198
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
|
+
`);
|
|
1199
959
|
await client.executeMultiple(`
|
|
1200
960
|
CREATE TABLE IF NOT EXISTS conversations (
|
|
1201
961
|
id TEXT PRIMARY KEY,
|
|
@@ -1262,71 +1022,298 @@ async function ensureSchema() {
|
|
|
1262
1022
|
} catch {
|
|
1263
1023
|
}
|
|
1264
1024
|
await client.executeMultiple(`
|
|
1265
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS conversations_fts USING fts5(
|
|
1266
|
-
content_text,
|
|
1267
|
-
sender_name,
|
|
1268
|
-
agent_response,
|
|
1269
|
-
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',
|
|
1270
1193
|
content_rowid='rowid'
|
|
1271
1194
|
);
|
|
1272
1195
|
|
|
1273
|
-
CREATE TRIGGER IF NOT EXISTS
|
|
1274
|
-
INSERT INTO
|
|
1275
|
-
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);
|
|
1276
1198
|
END;
|
|
1277
1199
|
|
|
1278
|
-
CREATE TRIGGER IF NOT EXISTS
|
|
1279
|
-
INSERT INTO
|
|
1280
|
-
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);
|
|
1281
1202
|
END;
|
|
1282
1203
|
|
|
1283
|
-
CREATE TRIGGER IF NOT EXISTS
|
|
1284
|
-
INSERT INTO
|
|
1285
|
-
|
|
1286
|
-
INSERT INTO conversations_fts(rowid, content_text, sender_name, agent_response)
|
|
1287
|
-
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);
|
|
1288
1207
|
END;
|
|
1289
1208
|
`);
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
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
|
+
}
|
|
1296
1236
|
}
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
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
|
+
}
|
|
1302
1245
|
}
|
|
1303
1246
|
try {
|
|
1304
|
-
await client.execute(
|
|
1305
|
-
sql: `UPDATE memories SET tier = 1 WHERE tool_name = 'commit_to_long_term_memory' AND importance >= 8 AND tier = 3`,
|
|
1306
|
-
args: []
|
|
1307
|
-
});
|
|
1308
|
-
await client.execute({
|
|
1309
|
-
sql: `UPDATE memories SET tier = 2 WHERE tool_name IN ('store_memory', 'manual') AND importance >= 5 AND tier = 3`,
|
|
1310
|
-
args: []
|
|
1311
|
-
});
|
|
1247
|
+
await client.execute("CREATE INDEX IF NOT EXISTS idx_memories_status ON memories(status)");
|
|
1312
1248
|
} catch {
|
|
1313
1249
|
}
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
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
|
+
}
|
|
1320
1259
|
}
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
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)
|
|
1324
1269
|
);
|
|
1325
|
-
|
|
1326
|
-
|
|
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
|
+
`);
|
|
1327
1314
|
for (const col of [
|
|
1328
|
-
"ALTER TABLE
|
|
1329
|
-
"ALTER TABLE
|
|
1315
|
+
"ALTER TABLE relationships ADD COLUMN confidence REAL DEFAULT 1.0",
|
|
1316
|
+
"ALTER TABLE relationships ADD COLUMN confidence_label TEXT DEFAULT 'extracted'"
|
|
1330
1317
|
]) {
|
|
1331
1318
|
try {
|
|
1332
1319
|
await client.execute(col);
|
|
@@ -1334,6 +1321,117 @@ async function ensureSchema() {
|
|
|
1334
1321
|
}
|
|
1335
1322
|
}
|
|
1336
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/lib/employees.ts
|
|
1415
|
+
init_config();
|
|
1416
|
+
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
1417
|
+
import { existsSync as existsSync2, symlinkSync, readlinkSync, readFileSync as readFileSync2 } from "fs";
|
|
1418
|
+
import { execSync } from "child_process";
|
|
1419
|
+
import path2 from "path";
|
|
1420
|
+
var EMPLOYEES_PATH = path2.join(EXE_AI_DIR, "exe-employees.json");
|
|
1421
|
+
async function loadEmployees(employeesPath = EMPLOYEES_PATH) {
|
|
1422
|
+
if (!existsSync2(employeesPath)) {
|
|
1423
|
+
return [];
|
|
1424
|
+
}
|
|
1425
|
+
const raw = await readFile2(employeesPath, "utf-8");
|
|
1426
|
+
try {
|
|
1427
|
+
return JSON.parse(raw);
|
|
1428
|
+
} catch {
|
|
1429
|
+
return [];
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
// src/lib/store.ts
|
|
1434
|
+
init_database();
|
|
1337
1435
|
|
|
1338
1436
|
// src/lib/keychain.ts
|
|
1339
1437
|
import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
|
|
@@ -1381,6 +1479,57 @@ async function getMasterKey() {
|
|
|
1381
1479
|
|
|
1382
1480
|
// src/lib/store.ts
|
|
1383
1481
|
init_config();
|
|
1482
|
+
|
|
1483
|
+
// src/lib/state-bus.ts
|
|
1484
|
+
var StateBus = class {
|
|
1485
|
+
handlers = /* @__PURE__ */ new Map();
|
|
1486
|
+
globalHandlers = /* @__PURE__ */ new Set();
|
|
1487
|
+
/** Emit an event to all subscribers */
|
|
1488
|
+
emit(event) {
|
|
1489
|
+
const typeHandlers = this.handlers.get(event.type);
|
|
1490
|
+
if (typeHandlers) {
|
|
1491
|
+
for (const handler of typeHandlers) {
|
|
1492
|
+
try {
|
|
1493
|
+
handler(event);
|
|
1494
|
+
} catch {
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
for (const handler of this.globalHandlers) {
|
|
1499
|
+
try {
|
|
1500
|
+
handler(event);
|
|
1501
|
+
} catch {
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
/** Subscribe to a specific event type */
|
|
1506
|
+
on(type, handler) {
|
|
1507
|
+
if (!this.handlers.has(type)) {
|
|
1508
|
+
this.handlers.set(type, /* @__PURE__ */ new Set());
|
|
1509
|
+
}
|
|
1510
|
+
this.handlers.get(type).add(handler);
|
|
1511
|
+
}
|
|
1512
|
+
/** Subscribe to ALL events */
|
|
1513
|
+
onAny(handler) {
|
|
1514
|
+
this.globalHandlers.add(handler);
|
|
1515
|
+
}
|
|
1516
|
+
/** Unsubscribe from a specific event type */
|
|
1517
|
+
off(type, handler) {
|
|
1518
|
+
this.handlers.get(type)?.delete(handler);
|
|
1519
|
+
}
|
|
1520
|
+
/** Unsubscribe from ALL events */
|
|
1521
|
+
offAny(handler) {
|
|
1522
|
+
this.globalHandlers.delete(handler);
|
|
1523
|
+
}
|
|
1524
|
+
/** Remove all listeners */
|
|
1525
|
+
clear() {
|
|
1526
|
+
this.handlers.clear();
|
|
1527
|
+
this.globalHandlers.clear();
|
|
1528
|
+
}
|
|
1529
|
+
};
|
|
1530
|
+
var orgBus = new StateBus();
|
|
1531
|
+
|
|
1532
|
+
// src/lib/store.ts
|
|
1384
1533
|
var INIT_MAX_RETRIES = 3;
|
|
1385
1534
|
var INIT_RETRY_DELAY_MS = 1e3;
|
|
1386
1535
|
function isBusyError2(err) {
|
|
@@ -1451,8 +1600,16 @@ async function initStore(options) {
|
|
|
1451
1600
|
"version-query"
|
|
1452
1601
|
);
|
|
1453
1602
|
_nextVersion = (Number(vResult.rows[0]?.max_v) || 0) + 1;
|
|
1603
|
+
try {
|
|
1604
|
+
const { loadGlobalProcedures: loadGlobalProcedures2 } = await Promise.resolve().then(() => (init_global_procedures(), global_procedures_exports));
|
|
1605
|
+
await loadGlobalProcedures2();
|
|
1606
|
+
} catch {
|
|
1607
|
+
}
|
|
1454
1608
|
}
|
|
1455
1609
|
|
|
1610
|
+
// src/bin/exe-team.ts
|
|
1611
|
+
init_database();
|
|
1612
|
+
|
|
1456
1613
|
// src/lib/is-main.ts
|
|
1457
1614
|
import { realpathSync } from "fs";
|
|
1458
1615
|
import { fileURLToPath } from "url";
|