@askexenow/exe-os 0.9.16 → 0.9.18

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.
Files changed (97) hide show
  1. package/dist/bin/backfill-conversations.js +1242 -909
  2. package/dist/bin/backfill-responses.js +1245 -912
  3. package/dist/bin/backfill-vectors.js +1244 -906
  4. package/dist/bin/cleanup-stale-review-tasks.js +1870 -417
  5. package/dist/bin/cli.js +217 -107
  6. package/dist/bin/exe-agent-config.js +2 -2
  7. package/dist/bin/exe-agent.js +62 -0
  8. package/dist/bin/exe-assign.js +346 -10
  9. package/dist/bin/exe-boot.js +387 -32
  10. package/dist/bin/exe-call.js +72 -2
  11. package/dist/bin/exe-cloud.js +8 -0
  12. package/dist/bin/exe-dispatch.js +1821 -225
  13. package/dist/bin/exe-doctor.js +720 -52
  14. package/dist/bin/exe-export-behaviors.js +1429 -148
  15. package/dist/bin/exe-forget.js +1408 -34
  16. package/dist/bin/exe-gateway.js +1629 -1295
  17. package/dist/bin/exe-heartbeat.js +1899 -448
  18. package/dist/bin/exe-kill.js +1624 -346
  19. package/dist/bin/exe-launch-agent.js +726 -90
  20. package/dist/bin/exe-link.js +27 -8
  21. package/dist/bin/exe-new-employee.js +75 -9
  22. package/dist/bin/exe-pending-messages.js +2769 -1316
  23. package/dist/bin/exe-pending-notifications.js +2829 -1376
  24. package/dist/bin/exe-pending-reviews.js +2847 -1392
  25. package/dist/bin/exe-rename.js +89 -8
  26. package/dist/bin/exe-review.js +1494 -312
  27. package/dist/bin/exe-search.js +1608 -1300
  28. package/dist/bin/exe-session-cleanup.js +194 -91
  29. package/dist/bin/exe-settings.js +10 -2
  30. package/dist/bin/exe-start-codex.js +769 -120
  31. package/dist/bin/exe-start-opencode.js +763 -108
  32. package/dist/bin/exe-status.js +1887 -434
  33. package/dist/bin/exe-team.js +1782 -324
  34. package/dist/bin/git-sweep.js +408 -33
  35. package/dist/bin/graph-backfill.js +681 -27
  36. package/dist/bin/graph-export.js +1419 -141
  37. package/dist/bin/install.js +4 -8
  38. package/dist/bin/intercom-check.js +8641 -0
  39. package/dist/bin/scan-tasks.js +553 -38
  40. package/dist/bin/setup.js +82 -10
  41. package/dist/bin/shard-migrate.js +682 -28
  42. package/dist/gateway/index.js +1629 -1295
  43. package/dist/hooks/bug-report-worker.js +1136 -183
  44. package/dist/hooks/codex-stop-task-finalizer.js +1060 -107
  45. package/dist/hooks/commit-complete.js +408 -33
  46. package/dist/hooks/error-recall.js +1608 -1300
  47. package/dist/hooks/ingest-worker.js +250 -7966
  48. package/dist/hooks/ingest.js +707 -119
  49. package/dist/hooks/instructions-loaded.js +383 -20
  50. package/dist/hooks/notification.js +383 -20
  51. package/dist/hooks/post-compact.js +384 -21
  52. package/dist/hooks/{response-ingest-worker.js → post-tool-combined.js} +4157 -1716
  53. package/dist/hooks/pre-compact.js +486 -45
  54. package/dist/hooks/pre-tool-use.js +385 -22
  55. package/dist/hooks/prompt-submit.js +291 -96
  56. package/dist/hooks/session-end.js +490 -48
  57. package/dist/hooks/session-start.js +236 -22
  58. package/dist/hooks/stop.js +192 -50
  59. package/dist/hooks/subagent-stop.js +95 -18
  60. package/dist/hooks/summary-worker.js +205 -361
  61. package/dist/index.js +221 -105
  62. package/dist/lib/agent-config.js +2 -2
  63. package/dist/lib/cloud-sync.js +27 -8
  64. package/dist/lib/consolidation.js +437 -41
  65. package/dist/lib/database.js +20 -8
  66. package/dist/lib/db-daemon-client.js +2 -2
  67. package/dist/lib/db.js +20 -8
  68. package/dist/lib/device-registry.js +27 -8
  69. package/dist/lib/employee-templates.js +62 -0
  70. package/dist/lib/employees.js +2 -2
  71. package/dist/lib/exe-daemon.js +6703 -6259
  72. package/dist/lib/hybrid-search.js +1608 -1300
  73. package/dist/lib/identity.js +1 -1
  74. package/dist/lib/messaging.js +11 -3
  75. package/dist/lib/reminders.js +1 -1
  76. package/dist/lib/schedules.js +718 -26
  77. package/dist/lib/session-registry.js +11 -0
  78. package/dist/lib/skill-learning.js +639 -9
  79. package/dist/lib/store.js +676 -27
  80. package/dist/lib/tasks.js +665 -27
  81. package/dist/lib/tmux-routing.js +732 -94
  82. package/dist/lib/token-spend.js +1 -1
  83. package/dist/mcp/server.js +856 -383
  84. package/dist/mcp/tools/complete-reminder.js +1 -1
  85. package/dist/mcp/tools/create-reminder.js +1 -1
  86. package/dist/mcp/tools/create-task.js +616 -46
  87. package/dist/mcp/tools/deactivate-behavior.js +9 -1
  88. package/dist/mcp/tools/list-reminders.js +1 -1
  89. package/dist/mcp/tools/list-tasks.js +10 -2
  90. package/dist/mcp/tools/send-message.js +11 -3
  91. package/dist/mcp/tools/update-task.js +677 -39
  92. package/dist/runtime/index.js +425 -37
  93. package/dist/tui/App.js +365 -34
  94. package/package.json +5 -2
  95. package/src/commands/exe/intercom.md +6 -17
  96. package/dist/bin/wiki-sync.js +0 -2991
  97. package/dist/hooks/prompt-ingest-worker.js +0 -3979
@@ -468,9 +468,9 @@ var MAX_RETRIES, BASE_DELAY_MS, MAX_JITTER_MS;
468
468
  var init_db_retry = __esm({
469
469
  "src/lib/db-retry.ts"() {
470
470
  "use strict";
471
- MAX_RETRIES = 3;
472
- BASE_DELAY_MS = 200;
473
- MAX_JITTER_MS = 300;
471
+ MAX_RETRIES = 5;
472
+ BASE_DELAY_MS = 250;
473
+ MAX_JITTER_MS = 400;
474
474
  }
475
475
  });
476
476
 
@@ -1058,6 +1058,15 @@ var init_database_adapter = __esm({
1058
1058
  }
1059
1059
  });
1060
1060
 
1061
+ // src/types/memory.ts
1062
+ var EMBEDDING_DIM;
1063
+ var init_memory = __esm({
1064
+ "src/types/memory.ts"() {
1065
+ "use strict";
1066
+ EMBEDDING_DIM = 1024;
1067
+ }
1068
+ });
1069
+
1061
1070
  // src/lib/daemon-auth.ts
1062
1071
  import crypto from "crypto";
1063
1072
  import path4 from "path";
@@ -1332,6 +1341,9 @@ async function connectEmbedDaemon() {
1332
1341
  }
1333
1342
  return false;
1334
1343
  }
1344
+ function sendRequest(texts, priority) {
1345
+ return sendDaemonRequest({ texts, priority });
1346
+ }
1335
1347
  function sendDaemonRequest(payload, timeoutMs = REQUEST_TIMEOUT_MS) {
1336
1348
  return new Promise((resolve) => {
1337
1349
  if (!_socket || !_connected) {
@@ -1354,10 +1366,150 @@ function sendDaemonRequest(payload, timeoutMs = REQUEST_TIMEOUT_MS) {
1354
1366
  }
1355
1367
  });
1356
1368
  }
1369
+ async function pingDaemon() {
1370
+ if (!_socket || !_connected) return null;
1371
+ const response = await sendDaemonRequest({ type: "health" }, 5e3);
1372
+ if (response.health) {
1373
+ return response.health;
1374
+ }
1375
+ return null;
1376
+ }
1377
+ function killAndRespawnDaemon() {
1378
+ if (!acquireSpawnLock()) {
1379
+ process.stderr.write("[exed-client] Another process is already restarting daemon \u2014 skipping\n");
1380
+ if (_socket) {
1381
+ _socket.destroy();
1382
+ _socket = null;
1383
+ }
1384
+ _connected = false;
1385
+ _buffer = "";
1386
+ return;
1387
+ }
1388
+ try {
1389
+ process.stderr.write("[exed-client] Killing daemon for restart...\n");
1390
+ if (existsSync5(PID_PATH)) {
1391
+ try {
1392
+ const pid = parseInt(readFileSync4(PID_PATH, "utf8").trim(), 10);
1393
+ if (pid > 0) {
1394
+ try {
1395
+ process.kill(pid, "SIGKILL");
1396
+ } catch {
1397
+ }
1398
+ }
1399
+ } catch {
1400
+ }
1401
+ }
1402
+ if (_socket) {
1403
+ _socket.destroy();
1404
+ _socket = null;
1405
+ }
1406
+ _connected = false;
1407
+ _buffer = "";
1408
+ try {
1409
+ unlinkSync2(PID_PATH);
1410
+ } catch {
1411
+ }
1412
+ try {
1413
+ unlinkSync2(SOCKET_PATH);
1414
+ } catch {
1415
+ }
1416
+ spawnDaemon();
1417
+ } finally {
1418
+ releaseSpawnLock();
1419
+ }
1420
+ }
1421
+ function isDaemonTooYoung() {
1422
+ try {
1423
+ const stat = statSync(PID_PATH);
1424
+ return Date.now() - stat.mtimeMs < MIN_DAEMON_AGE_MS;
1425
+ } catch {
1426
+ return false;
1427
+ }
1428
+ }
1429
+ async function retryThenRestart(doRequest, label) {
1430
+ const result = await doRequest();
1431
+ if (!result.error) {
1432
+ _consecutiveFailures = 0;
1433
+ return result;
1434
+ }
1435
+ _consecutiveFailures++;
1436
+ for (let i = 0; i < MAX_RETRIES_BEFORE_RESTART; i++) {
1437
+ const delayMs = RETRY_DELAYS_MS[i] ?? 5e3;
1438
+ process.stderr.write(`[exed-client] ${label} failed (${result.error}), retry ${i + 1}/${MAX_RETRIES_BEFORE_RESTART} in ${delayMs}ms
1439
+ `);
1440
+ await new Promise((r) => setTimeout(r, delayMs));
1441
+ if (!_connected) {
1442
+ if (!await connectToSocket()) continue;
1443
+ }
1444
+ const retry = await doRequest();
1445
+ if (!retry.error) {
1446
+ _consecutiveFailures = 0;
1447
+ return retry;
1448
+ }
1449
+ _consecutiveFailures++;
1450
+ }
1451
+ if (isDaemonTooYoung()) {
1452
+ process.stderr.write(`[exed-client] ${label}: daemon too young (< ${MIN_DAEMON_AGE_MS / 1e3}s) \u2014 skipping restart
1453
+ `);
1454
+ return { error: result.error };
1455
+ }
1456
+ process.stderr.write(`[exed-client] ${label}: ${_consecutiveFailures} consecutive failures \u2014 restarting daemon
1457
+ `);
1458
+ killAndRespawnDaemon();
1459
+ const start = Date.now();
1460
+ let delay2 = 200;
1461
+ while (Date.now() - start < CONNECT_TIMEOUT_MS) {
1462
+ await new Promise((r) => setTimeout(r, delay2));
1463
+ if (await connectToSocket()) break;
1464
+ delay2 = Math.min(delay2 * 2, 3e3);
1465
+ }
1466
+ if (!_connected) return { error: "Daemon restart failed" };
1467
+ const final = await doRequest();
1468
+ if (!final.error) _consecutiveFailures = 0;
1469
+ return final;
1470
+ }
1471
+ async function embedViaClient(text, priority = "high") {
1472
+ if (!_connected && !await connectEmbedDaemon()) return null;
1473
+ _requestCount++;
1474
+ if (_requestCount % HEALTH_CHECK_INTERVAL === 0) {
1475
+ const health = await pingDaemon();
1476
+ if (!health && !isDaemonTooYoung()) {
1477
+ process.stderr.write(`[exed-client] Periodic health check failed at request ${_requestCount} \u2014 restarting daemon
1478
+ `);
1479
+ killAndRespawnDaemon();
1480
+ const start = Date.now();
1481
+ let d = 200;
1482
+ while (Date.now() - start < CONNECT_TIMEOUT_MS) {
1483
+ await new Promise((r) => setTimeout(r, d));
1484
+ if (await connectToSocket()) break;
1485
+ d = Math.min(d * 2, 3e3);
1486
+ }
1487
+ if (!_connected) return null;
1488
+ }
1489
+ }
1490
+ const result = await retryThenRestart(
1491
+ () => sendRequest([text], priority),
1492
+ "Embed"
1493
+ );
1494
+ return !result.error && result.vectors?.[0] ? result.vectors[0] : null;
1495
+ }
1496
+ function disconnectClient() {
1497
+ if (_socket) {
1498
+ _socket.destroy();
1499
+ _socket = null;
1500
+ }
1501
+ _connected = false;
1502
+ _buffer = "";
1503
+ for (const [id, entry] of _pending) {
1504
+ clearTimeout(entry.timer);
1505
+ _pending.delete(id);
1506
+ entry.resolve({ error: "Client disconnected" });
1507
+ }
1508
+ }
1357
1509
  function isClientConnected() {
1358
1510
  return _connected;
1359
1511
  }
1360
- var SOCKET_PATH, PID_PATH, SPAWN_LOCK_PATH, SPAWN_LOCK_STALE_MS, CONNECT_TIMEOUT_MS, REQUEST_TIMEOUT_MS, DAEMON_TOKEN_ENV, _socket, _connected, _buffer, _pending, MAX_BUFFER;
1512
+ var SOCKET_PATH, PID_PATH, SPAWN_LOCK_PATH, SPAWN_LOCK_STALE_MS, CONNECT_TIMEOUT_MS, REQUEST_TIMEOUT_MS, DAEMON_TOKEN_ENV, _socket, _connected, _buffer, _requestCount, _consecutiveFailures, HEALTH_CHECK_INTERVAL, MAX_RETRIES_BEFORE_RESTART, RETRY_DELAYS_MS, MIN_DAEMON_AGE_MS, _pending, MAX_BUFFER;
1361
1513
  var init_exe_daemon_client = __esm({
1362
1514
  "src/lib/exe-daemon-client.ts"() {
1363
1515
  "use strict";
@@ -1373,6 +1525,12 @@ var init_exe_daemon_client = __esm({
1373
1525
  _socket = null;
1374
1526
  _connected = false;
1375
1527
  _buffer = "";
1528
+ _requestCount = 0;
1529
+ _consecutiveFailures = 0;
1530
+ HEALTH_CHECK_INTERVAL = 100;
1531
+ MAX_RETRIES_BEFORE_RESTART = 3;
1532
+ RETRY_DELAYS_MS = [1e3, 3e3, 5e3];
1533
+ MIN_DAEMON_AGE_MS = 3e4;
1376
1534
  _pending = /* @__PURE__ */ new Map();
1377
1535
  MAX_BUFFER = 1e7;
1378
1536
  }
@@ -1480,7 +1638,7 @@ function createDaemonDbClient(fallbackClient) {
1480
1638
  });
1481
1639
  if (response.error) {
1482
1640
  const errMsg = String(response.error);
1483
- if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed") {
1641
+ if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed" || errMsg === "DB not initialized") {
1484
1642
  process.stderr.write(`[db-daemon] Transport error (${errMsg}), falling back to direct
1485
1643
  `);
1486
1644
  return fallbackClient.execute(stmt);
@@ -1505,7 +1663,7 @@ function createDaemonDbClient(fallbackClient) {
1505
1663
  });
1506
1664
  if (response.error) {
1507
1665
  const errMsg = String(response.error);
1508
- if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed") {
1666
+ if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed" || errMsg === "DB not initialized") {
1509
1667
  process.stderr.write(`[db-daemon] Batch transport error (${errMsg}), falling back to direct
1510
1668
  `);
1511
1669
  return fallbackClient.batch(stmts, mode);
@@ -1628,7 +1786,7 @@ async function initDatabase(config) {
1628
1786
  });
1629
1787
  }, 3e4);
1630
1788
  _walCheckpointTimer.unref();
1631
- if (process.env.DATABASE_URL) {
1789
+ if (process.env.DATABASE_URL && process.env.EXE_USE_POSTGRES === "1") {
1632
1790
  _adapterClient = await createPrismaDbAdapter(_resilientClient);
1633
1791
  }
1634
1792
  }
@@ -1639,7 +1797,7 @@ function getClient() {
1639
1797
  if (!_adapterClient) {
1640
1798
  throw new Error("Database client not initialized. Call initDatabase() first.");
1641
1799
  }
1642
- if (process.env.DATABASE_URL) {
1800
+ if (process.env.DATABASE_URL && process.env.EXE_USE_POSTGRES === "1") {
1643
1801
  return _adapterClient;
1644
1802
  }
1645
1803
  if (process.env.EXE_IS_DAEMON === "1") {
@@ -1651,9 +1809,11 @@ function getClient() {
1651
1809
  return _resilientClient;
1652
1810
  }
1653
1811
  async function initDaemonClient() {
1654
- if (process.env.DATABASE_URL) return;
1812
+ if (process.env.DATABASE_URL && process.env.EXE_USE_POSTGRES === "1") return;
1655
1813
  if (process.env.EXE_IS_DAEMON === "1") return;
1814
+ if (process.env.VITEST) return;
1656
1815
  if (!_resilientClient) return;
1816
+ if (_daemonClient) return;
1657
1817
  try {
1658
1818
  const { initDaemonDbClient: initDaemonDbClient2 } = await Promise.resolve().then(() => (init_db_daemon_client(), db_daemon_client_exports));
1659
1819
  _daemonClient = await initDaemonDbClient2(_resilientClient);
@@ -1802,6 +1962,13 @@ async function ensureSchema() {
1802
1962
  });
1803
1963
  } catch {
1804
1964
  }
1965
+ try {
1966
+ await client.execute({
1967
+ sql: `ALTER TABLE behaviors ADD COLUMN vector F32_BLOB(${EMBEDDING_DIM})`,
1968
+ args: []
1969
+ });
1970
+ } catch {
1971
+ }
1805
1972
  try {
1806
1973
  await client.execute({
1807
1974
  sql: `ALTER TABLE tasks ADD COLUMN blocked_by TEXT`,
@@ -2672,6 +2839,7 @@ var init_database = __esm({
2672
2839
  init_db_retry();
2673
2840
  init_employees();
2674
2841
  init_database_adapter();
2842
+ init_memory();
2675
2843
  _client = null;
2676
2844
  _resilientClient = null;
2677
2845
  _walCheckpointTimer = null;
@@ -2790,6 +2958,68 @@ var init_platform_procedures = __esm({
2790
2958
  domain: "architecture",
2791
2959
  priority: "p0",
2792
2960
  content: "Tasks live in the DB. Intercom (tmux send-keys) is fire-and-forget \u2014 it may fail, get garbled, or arrive mid-work. Never rely on intercom for task delivery. The UserPromptSubmit hook checks the DB for new tasks on every prompt. Your operating procedures step 7 says check for next work. The daemon nudges idle agents as a speedup. If you have no tasks, you found them all."
2961
+ },
2962
+ // --- MCP is the ONLY data interface ---
2963
+ {
2964
+ title: "MCP disconnect \u2014 ask the user, never work around it",
2965
+ domain: "workflow",
2966
+ priority: "p0",
2967
+ content: "If MCP tools are unavailable, disconnected, or returning connection errors: STOP. Tell the user clearly: 'MCP server is disconnected. Please run /mcp to reconnect.' Do NOT attempt workarounds \u2014 no raw Node imports, no direct DB access, no CLI hacks, no daemon socket calls. MCP is the ONLY data interface. Working around it wastes time, hits bundling issues, and bypasses the contract boundary. Ask once, wait, proceed when reconnected."
2968
+ },
2969
+ // --- MCP Tool Catalog (Layer 0 — every agent knows what tools exist) ---
2970
+ {
2971
+ title: "MCP tools \u2014 memory and search",
2972
+ domain: "tool-use",
2973
+ priority: "p1",
2974
+ content: "recall_my_memory: search your own memories (semantic + FTS). ask_team_memory: search a colleague's memories by agent name. store_memory: persist a memory (decisions, summaries, context). commit_memory: high-importance memory that survives consolidation. search_everything: unified search across memories, tasks, entities, conversations. get_session_context: temporal window of memories around a timestamp. consolidate_memories: merge duplicate/related memories into insights. get_memory_cardinality: count memories per agent (health check)."
2975
+ },
2976
+ {
2977
+ title: "MCP tools \u2014 task orchestration",
2978
+ domain: "tool-use",
2979
+ priority: "p1",
2980
+ content: "create_task: dispatch work to an employee (auto-spawns session). The ONLY dispatch path. list_tasks: query tasks by status, assignee, project. get_task: fetch full task details by ID. update_task: change status (in_progress, done, blocked, cancelled) + add result summary. close_task: finalize a reviewed task (COO only). checkpoint_task: save progress state for crash recovery. resume_employee: re-spawn an employee session for an existing task."
2981
+ },
2982
+ {
2983
+ title: "MCP tools \u2014 knowledge graph (GraphRAG)",
2984
+ domain: "tool-use",
2985
+ priority: "p1",
2986
+ content: "query_relationships: find connections between entities in the knowledge graph. get_entity_neighbors: explore an entity's direct connections. get_hot_entities: find most-referenced entities (trending topics). get_graph_stats: graph health \u2014 entity/relationship counts, density. export_graph: export graph data for visualization. merge_entities: deduplicate entities (alias resolution). find_similar_trajectories: match tool-call patterns to past task solutions."
2987
+ },
2988
+ {
2989
+ title: "MCP tools \u2014 identity, behavior, and decisions",
2990
+ domain: "tool-use",
2991
+ priority: "p1",
2992
+ content: "get_identity: read an agent's exe.md (Layer 1 identity). update_identity: write an agent's exe.md. Identity > behavior \u2014 use for permanent rules. store_behavior: record a correction or pattern for an agent (Layer 2 expertise). list_behaviors: view an agent's active behaviors. deactivate_behavior: soft-delete a stale or conflicting behavior. store_decision: record an ADR (architectural decision record). get_decision: retrieve a past decision by query."
2993
+ },
2994
+ {
2995
+ title: "MCP tools \u2014 communication and messaging",
2996
+ domain: "tool-use",
2997
+ priority: "p1",
2998
+ content: "send_message: send supplementary context to another agent (NOT for actionable work \u2014 use create_task). acknowledge_messages: mark messages as read. send_whatsapp: send WhatsApp message via gateway (customer-facing alerts). query_conversations: search ingested conversations across all channels (WhatsApp, email, etc.)."
2999
+ },
3000
+ {
3001
+ title: "MCP tools \u2014 wiki, documents, and content",
3002
+ domain: "tool-use",
3003
+ priority: "p1",
3004
+ content: "create_wiki_page: create a wiki page in exe-wiki. list_wiki_pages: browse wiki pages. get_wiki_page: read a wiki page. update_wiki_page: edit a wiki page. ingest_document: import a file (PDF, MD, etc.) into memory as chunks. list_documents: browse ingested documents by workspace. purge_document: remove a document and its memory chunks. set_document_importance: adjust chunk importance scores. rerank_documents: re-score document relevance for a query."
3005
+ },
3006
+ {
3007
+ title: "MCP tools \u2014 system, operations, and admin",
3008
+ domain: "tool-use",
3009
+ priority: "p1",
3010
+ content: "get_agent_spend: token usage per agent/session (cost tracking). list_agent_sessions: view agent session history. get_session_kills: audit log of killed sessions. get_daemon_health: check exed daemon status. get_auto_wake_status: daemon auto-wake configuration. get_worker_gate: check worker deployment gates. run_memory_audit: health check \u2014 duplicates, null vectors, orphaned rows. run_consolidation: trigger sleep-time memory consolidation. cloud_sync: force a cloud sync cycle. backup_vps: trigger VPS backup."
3011
+ },
3012
+ {
3013
+ title: "MCP tools \u2014 config, licensing, and team",
3014
+ domain: "tool-use",
3015
+ priority: "p1",
3016
+ content: "set_agent_config: view/change per-agent runtime and model settings. list_employees: view the employee roster. add_person: add a person to the CRM contacts roster. list_people: browse CRM contacts. get_person: fetch contact details. get_license_status: check license validity. create_license: generate a new license key (admin). list_licenses: view all issued licenses. activate_license: activate a license on a device."
3017
+ },
3018
+ {
3019
+ title: "MCP tools \u2014 advanced (triggers, skills, orchestration)",
3020
+ domain: "tool-use",
3021
+ priority: "p1",
3022
+ content: "create_trigger: set up a scheduled recurring agent job (cron). list_triggers: view active triggers. load_skill: load a slash-command skill dynamically. apply_starter_pack: import a pre-built behavior + identity pack for a role. export_orchestration: export full org state (tasks, behaviors, identities) as portable JSON. import_orchestration: import org state into a new instance. deploy_client: deploy a customer client instance. query_company_brain: unified RAG query across all company knowledge. create_reminder: set a text reminder (shown in boot brief). list_reminders: view pending reminders. complete_reminder: mark a reminder done. global_procedure: manage Layer 0 procedures (actions: store, list, deactivate). Legacy aliases: store_global_procedure, list_global_procedures, deactivate_global_procedure."
2793
3023
  }
2794
3024
  ];
2795
3025
  PLATFORM_PROCEDURE_TITLES = new Set(
@@ -2869,13 +3099,6 @@ ${p.content}`).join("\n\n");
2869
3099
  }
2870
3100
  });
2871
3101
 
2872
- // src/types/memory.ts
2873
- var init_memory = __esm({
2874
- "src/types/memory.ts"() {
2875
- "use strict";
2876
- }
2877
- });
2878
-
2879
3102
  // src/lib/keychain.ts
2880
3103
  var keychain_exports = {};
2881
3104
  __export(keychain_exports, {
@@ -3429,6 +3652,11 @@ async function initStore(options) {
3429
3652
  encryptionKey: hexKey
3430
3653
  });
3431
3654
  await retryOnBusy2(() => ensureSchema(), "ensureSchema");
3655
+ try {
3656
+ const { initDaemonClient: initDaemonClient2 } = await Promise.resolve().then(() => (init_database(), database_exports));
3657
+ await initDaemonClient2();
3658
+ } catch {
3659
+ }
3432
3660
  if (!options?.lightweight) {
3433
3661
  try {
3434
3662
  const { initShardManager: initShardManager2 } = await Promise.resolve().then(() => (init_shard_manager(), shard_manager_exports));
@@ -3473,6 +3701,7 @@ var session_registry_exports = {};
3473
3701
  __export(session_registry_exports, {
3474
3702
  listSessions: () => listSessions,
3475
3703
  pruneStaleSessions: () => pruneStaleSessions,
3704
+ refreshSessionProject: () => refreshSessionProject,
3476
3705
  registerSession: () => registerSession
3477
3706
  });
3478
3707
  import { readFileSync as readFileSync5, writeFileSync as writeFileSync3, mkdirSync as mkdirSync3, existsSync as existsSync8 } from "fs";
@@ -3493,6 +3722,16 @@ function registerSession(entry) {
3493
3722
  }
3494
3723
  writeFileSync3(REGISTRY_PATH, JSON.stringify(sessions, null, 2));
3495
3724
  }
3725
+ function refreshSessionProject(windowName, projectDir) {
3726
+ const sessions = listSessions();
3727
+ const entry = sessions.find((s) => s.windowName === windowName);
3728
+ if (!entry || entry.projectDir === projectDir) return;
3729
+ entry.projectDir = projectDir;
3730
+ try {
3731
+ writeFileSync3(REGISTRY_PATH, JSON.stringify(sessions, null, 2));
3732
+ } catch {
3733
+ }
3734
+ }
3496
3735
  function listSessions() {
3497
3736
  try {
3498
3737
  const raw = readFileSync5(REGISTRY_PATH, "utf8");
@@ -3841,7 +4080,7 @@ var init_agent_config = __esm({
3841
4080
  init_secure_files();
3842
4081
  AGENT_CONFIG_PATH = path9.join(EXE_AI_DIR, "agent-config.json");
3843
4082
  DEFAULT_MODELS = {
3844
- claude: "claude-opus-4",
4083
+ claude: "claude-opus-4.6",
3845
4084
  codex: RUNTIME_TABLE.codex?.defaultModel ?? "gpt-5.4",
3846
4085
  opencode: RUNTIME_TABLE.opencode?.defaultModel ?? "anthropic/claude-sonnet-4-6"
3847
4086
  };
@@ -5051,15 +5290,20 @@ async function createTaskCore(input) {
5051
5290
  const { resolveExeSession: resolveExeSession2 } = await Promise.resolve().then(() => (init_tmux_routing(), tmux_routing_exports));
5052
5291
  const resolved = resolveExeSession2();
5053
5292
  if (resolved && input.projectName) {
5054
- const { getSessionProject: getSessionProject2 } = await Promise.resolve().then(() => (init_session_scope(), session_scope_exports));
5055
- const sessionProject = getSessionProject2(resolved);
5056
- if (sessionProject && sessionProject !== input.projectName) {
5057
- scopeMismatchWarning = `session/project mismatch: session "${resolved}" owns "${sessionProject}" but task targets "${input.projectName}". Routed to default scope.`;
5058
- process.stderr.write(`[create_task] ${scopeMismatchWarning}
5059
- `);
5060
- earlySessionScope = null;
5061
- } else {
5293
+ const isCoordinatorSession = !resolved.includes("-");
5294
+ if (isCoordinatorSession) {
5062
5295
  earlySessionScope = resolved;
5296
+ } else {
5297
+ const { getSessionProject: getSessionProject2 } = await Promise.resolve().then(() => (init_session_scope(), session_scope_exports));
5298
+ const sessionProject = getSessionProject2(resolved);
5299
+ if (sessionProject && sessionProject !== input.projectName) {
5300
+ scopeMismatchWarning = `session/project mismatch: session "${resolved}" owns "${sessionProject}" but task targets "${input.projectName}". Routed to default scope.`;
5301
+ process.stderr.write(`[create_task] ${scopeMismatchWarning}
5302
+ `);
5303
+ earlySessionScope = null;
5304
+ } else {
5305
+ earlySessionScope = resolved;
5306
+ }
5063
5307
  }
5064
5308
  } else {
5065
5309
  earlySessionScope = resolved;
@@ -5944,6 +6188,10 @@ async function dispatchTaskToEmployee(input) {
5944
6188
  if (transport.isAlive(sessionName)) {
5945
6189
  const result = sendIntercom(sessionName);
5946
6190
  const dispatched = result === "acknowledged" || result === "debounced" || result === "queued" ? "verified" : result === "delivered" ? "sent_unverified" : "session_dead";
6191
+ process.stderr.write(
6192
+ `[dispatch-audit] intercom \u2192 ${sessionName} | task="${input.title}" [${input.priority}] | result=${dispatched} (sendIntercom=${result})
6193
+ `
6194
+ );
5947
6195
  return { dispatched, session: sessionName, crossProject };
5948
6196
  } else {
5949
6197
  const projectDir = input.projectDir ?? process.cwd();
@@ -5952,11 +6200,15 @@ async function dispatchTaskToEmployee(input) {
5952
6200
  });
5953
6201
  if (result.status === "failed") {
5954
6202
  process.stderr.write(
5955
- `[dispatch] Failed to spawn ${input.assignedTo}: ${result.error}
6203
+ `[dispatch-audit] SPAWN FAILED \u2192 ${input.assignedTo} | task="${input.title}" [${input.priority}] | error=${result.error}
5956
6204
  `
5957
6205
  );
5958
6206
  return { dispatched: "session_missing" };
5959
6207
  }
6208
+ process.stderr.write(
6209
+ `[dispatch-audit] SPAWNED \u2192 ${result.sessionName} | task="${input.title}" [${input.priority}]
6210
+ `
6211
+ );
5960
6212
  return { dispatched: "spawned", session: result.sessionName, crossProject };
5961
6213
  }
5962
6214
  } catch {
@@ -5966,7 +6218,13 @@ async function dispatchTaskToEmployee(input) {
5966
6218
  function notifyTaskDone() {
5967
6219
  try {
5968
6220
  const key = getSessionKey();
5969
- if (key && !process.env.VITEST) notifyParentExe(key);
6221
+ if (key && !process.env.VITEST) {
6222
+ notifyParentExe(key);
6223
+ process.stderr.write(
6224
+ `[dispatch-audit] notifyTaskDone \u2192 parent coordinator (session=${key})
6225
+ `
6226
+ );
6227
+ }
5970
6228
  } catch {
5971
6229
  }
5972
6230
  }
@@ -5987,16 +6245,91 @@ var init_tasks_notify = __esm({
5987
6245
  }
5988
6246
  });
5989
6247
 
6248
+ // src/lib/embedder.ts
6249
+ var embedder_exports = {};
6250
+ __export(embedder_exports, {
6251
+ disposeEmbedder: () => disposeEmbedder,
6252
+ embed: () => embed,
6253
+ embedDirect: () => embedDirect,
6254
+ getEmbedder: () => getEmbedder
6255
+ });
6256
+ async function getEmbedder() {
6257
+ const ok = await connectEmbedDaemon();
6258
+ if (!ok) {
6259
+ throw new Error(
6260
+ "Could not connect to embedding daemon. Ensure the model is installed (run /exe-setup)."
6261
+ );
6262
+ }
6263
+ }
6264
+ async function embed(text) {
6265
+ const priority = process.env.EXE_EMBED_PRIORITY === "low" ? "low" : "high";
6266
+ const vector = await embedViaClient(text, priority);
6267
+ if (!vector) {
6268
+ throw new Error(
6269
+ "Embedding failed: daemon unavailable. Run /exe-setup to verify model installation."
6270
+ );
6271
+ }
6272
+ if (vector.length !== EMBEDDING_DIM) {
6273
+ throw new Error(
6274
+ `Embedding dimension mismatch: expected ${EMBEDDING_DIM}, got ${vector.length}. Ensure the correct Jina v5-small Q4_K_M GGUF model is installed.`
6275
+ );
6276
+ }
6277
+ return vector;
6278
+ }
6279
+ async function disposeEmbedder() {
6280
+ disconnectClient();
6281
+ }
6282
+ async function embedDirect(text) {
6283
+ const llamaCpp = await import("node-llama-cpp");
6284
+ const { MODELS_DIR: MODELS_DIR2 } = await Promise.resolve().then(() => (init_config(), config_exports));
6285
+ const { existsSync: existsSync21 } = await import("fs");
6286
+ const path25 = await import("path");
6287
+ const modelPath = path25.join(MODELS_DIR2, "jina-embeddings-v5-small-q4_k_m.gguf");
6288
+ if (!existsSync21(modelPath)) {
6289
+ throw new Error(`Embedding model not found at ${modelPath}. Run '/exe-setup' to download it.`);
6290
+ }
6291
+ const llama = await llamaCpp.getLlama();
6292
+ const model = await llama.loadModel({ modelPath });
6293
+ const context = await model.createEmbeddingContext();
6294
+ try {
6295
+ const embedding = await context.getEmbeddingFor(text);
6296
+ const vector = Array.from(embedding.vector);
6297
+ if (vector.length !== EMBEDDING_DIM) {
6298
+ throw new Error(
6299
+ `Embedding dimension mismatch: expected ${EMBEDDING_DIM}, got ${vector.length}.`
6300
+ );
6301
+ }
6302
+ return vector;
6303
+ } finally {
6304
+ await context.dispose();
6305
+ await model.dispose();
6306
+ }
6307
+ }
6308
+ var init_embedder = __esm({
6309
+ "src/lib/embedder.ts"() {
6310
+ "use strict";
6311
+ init_memory();
6312
+ init_exe_daemon_client();
6313
+ }
6314
+ });
6315
+
5990
6316
  // src/lib/behaviors.ts
5991
6317
  import crypto5 from "crypto";
5992
6318
  async function storeBehavior(opts) {
5993
6319
  const client = getClient();
5994
6320
  const id = crypto5.randomUUID();
5995
6321
  const now = (/* @__PURE__ */ new Date()).toISOString();
6322
+ let vector = null;
6323
+ try {
6324
+ const { embed: embed2 } = await Promise.resolve().then(() => (init_embedder(), embedder_exports));
6325
+ const vec = await embed2(opts.content);
6326
+ vector = new Float32Array(vec);
6327
+ } catch {
6328
+ }
5996
6329
  await client.execute({
5997
- sql: `INSERT INTO behaviors (id, agent_id, project_name, domain, priority, content, active, created_at, updated_at)
5998
- VALUES (?, ?, ?, ?, ?, ?, 1, ?, ?)`,
5999
- args: [id, opts.agentId, opts.projectName ?? null, opts.domain ?? null, opts.priority ?? "p1", opts.content, now, now]
6330
+ sql: `INSERT INTO behaviors (id, agent_id, project_name, domain, priority, content, active, created_at, updated_at, vector)
6331
+ VALUES (?, ?, ?, ?, ?, ?, 1, ?, ?, ?)`,
6332
+ args: [id, opts.agentId, opts.projectName ?? null, opts.domain ?? null, opts.priority ?? "p1", opts.content, now, now, vector ? vector.buffer : null]
6000
6333
  });
6001
6334
  return id;
6002
6335
  }
@@ -7099,7 +7432,7 @@ function isSessionBusy(sessionName) {
7099
7432
  function isExeSession(sessionName) {
7100
7433
  const matchesBaseWithInstance = (baseName) => sessionName === baseName || sessionName.startsWith(baseName) && /^\d+$/.test(sessionName.slice(baseName.length));
7101
7434
  const coordinatorName = getCoordinatorName();
7102
- return matchesBaseWithInstance(coordinatorName) || matchesBaseWithInstance("exe");
7435
+ return matchesBaseWithInstance(coordinatorName);
7103
7436
  }
7104
7437
  function sendIntercom(targetSession) {
7105
7438
  const transport = getTransport();
@@ -9265,6 +9598,14 @@ __export(schedules_exports, {
9265
9598
  });
9266
9599
  import crypto9 from "crypto";
9267
9600
  import { execSync as execSync9 } from "child_process";
9601
+ function isValidCron(cron) {
9602
+ const fields = cron.trim().split(/\s+/);
9603
+ if (fields.length !== 5) return false;
9604
+ return fields.every((f) => CRON_FIELD.test(f));
9605
+ }
9606
+ function isValidScheduleId(id) {
9607
+ return SAFE_ID.test(id) && id.length <= 128;
9608
+ }
9268
9609
  async function ensureDb() {
9269
9610
  if (!isInitialized()) {
9270
9611
  await initStore();
@@ -9330,6 +9671,9 @@ function parseHumanCron(input) {
9330
9671
  return `${minute} ${hour} * * ${dow}`;
9331
9672
  }
9332
9673
  async function createSchedule(input) {
9674
+ if (!isValidCron(input.cron)) {
9675
+ throw new Error(`Invalid cron expression: ${input.cron}. Must be 5 fields with only digits, *, /, -, comma.`);
9676
+ }
9333
9677
  await ensureDb();
9334
9678
  const client = getClient();
9335
9679
  const id = crypto9.randomUUID().slice(0, 8);
@@ -9403,6 +9747,12 @@ async function deleteSchedule(id) {
9403
9747
  return true;
9404
9748
  }
9405
9749
  function addToCrontab(id, cron, prompt, projectDir) {
9750
+ if (!isValidCron(cron)) {
9751
+ throw new Error(`Invalid cron expression: ${cron}`);
9752
+ }
9753
+ if (!isValidScheduleId(id)) {
9754
+ throw new Error(`Invalid schedule ID: ${id}`);
9755
+ }
9406
9756
  try {
9407
9757
  const cwd = projectDir ? `cd ${JSON.stringify(projectDir)} && ` : "";
9408
9758
  const escapedPrompt = prompt.replace(/"/g, '\\"');
@@ -9411,10 +9761,12 @@ function addToCrontab(id, cron, prompt, projectDir) {
9411
9761
  `(crontab -l 2>/dev/null; echo ${JSON.stringify(entry)}) | crontab -`,
9412
9762
  { timeout: 5e3, stdio: "ignore" }
9413
9763
  );
9414
- } catch {
9764
+ } catch (err) {
9765
+ if (err instanceof Error && err.message.startsWith("Invalid")) throw err;
9415
9766
  }
9416
9767
  }
9417
9768
  function removeFromCrontab(id) {
9769
+ if (!isValidScheduleId(id)) return;
9418
9770
  try {
9419
9771
  execSync9(
9420
9772
  `crontab -l 2>/dev/null | grep -v "exe-schedule:${id}" | crontab -`,
@@ -9423,11 +9775,14 @@ function removeFromCrontab(id) {
9423
9775
  } catch {
9424
9776
  }
9425
9777
  }
9778
+ var CRON_FIELD, SAFE_ID;
9426
9779
  var init_schedules = __esm({
9427
9780
  "src/lib/schedules.ts"() {
9428
9781
  "use strict";
9429
9782
  init_database();
9430
9783
  init_store();
9784
+ CRON_FIELD = /^[\d*/,\-]+$/;
9785
+ SAFE_ID = /^[a-zA-Z0-9_\-]+$/;
9431
9786
  }
9432
9787
  });
9433
9788