@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
@@ -415,7 +415,7 @@ var init_agent_config = __esm({
415
415
  init_secure_files();
416
416
  AGENT_CONFIG_PATH = path2.join(EXE_AI_DIR, "agent-config.json");
417
417
  KNOWN_RUNTIMES = {
418
- claude: ["claude-opus-4", "claude-sonnet-4", "claude-haiku-4.5"],
418
+ claude: ["claude-opus-4.6", "claude-opus-4", "claude-sonnet-4.6", "claude-sonnet-4", "claude-haiku-4.5"],
419
419
  codex: ["gpt-5.4", "gpt-5.5", "gpt-5.3-codex-spark", "o3", "o4-mini"],
420
420
  opencode: ["anthropic/claude-sonnet-4-6", "openai/gpt-5.4", "google/gemini-2.5-pro", "deepseek/deepseek-r3", "minimax/minimax-m2.5"]
421
421
  };
@@ -425,7 +425,7 @@ var init_agent_config = __esm({
425
425
  opencode: "OpenCode (open source)"
426
426
  };
427
427
  DEFAULT_MODELS = {
428
- claude: "claude-opus-4",
428
+ claude: "claude-opus-4.6",
429
429
  codex: RUNTIME_TABLE.codex?.defaultModel ?? "gpt-5.4",
430
430
  opencode: RUNTIME_TABLE.opencode?.defaultModel ?? "anthropic/claude-sonnet-4-6"
431
431
  };
@@ -908,9 +908,9 @@ var MAX_RETRIES, BASE_DELAY_MS, MAX_JITTER_MS;
908
908
  var init_db_retry = __esm({
909
909
  "src/lib/db-retry.ts"() {
910
910
  "use strict";
911
- MAX_RETRIES = 3;
912
- BASE_DELAY_MS = 200;
913
- MAX_JITTER_MS = 300;
911
+ MAX_RETRIES = 5;
912
+ BASE_DELAY_MS = 250;
913
+ MAX_JITTER_MS = 400;
914
914
  }
915
915
  });
916
916
 
@@ -1498,6 +1498,15 @@ var init_database_adapter = __esm({
1498
1498
  }
1499
1499
  });
1500
1500
 
1501
+ // src/types/memory.ts
1502
+ var EMBEDDING_DIM;
1503
+ var init_memory = __esm({
1504
+ "src/types/memory.ts"() {
1505
+ "use strict";
1506
+ EMBEDDING_DIM = 1024;
1507
+ }
1508
+ });
1509
+
1501
1510
  // src/lib/daemon-auth.ts
1502
1511
  import crypto from "crypto";
1503
1512
  import path8 from "path";
@@ -1536,6 +1545,17 @@ var init_daemon_auth = __esm({
1536
1545
  });
1537
1546
 
1538
1547
  // src/lib/exe-daemon-client.ts
1548
+ var exe_daemon_client_exports = {};
1549
+ __export(exe_daemon_client_exports, {
1550
+ connectEmbedDaemon: () => connectEmbedDaemon,
1551
+ disconnectClient: () => disconnectClient,
1552
+ embedBatchViaClient: () => embedBatchViaClient,
1553
+ embedViaClient: () => embedViaClient,
1554
+ isClientConnected: () => isClientConnected,
1555
+ pingDaemon: () => pingDaemon,
1556
+ sendDaemonRequest: () => sendDaemonRequest,
1557
+ sendIngestRequest: () => sendIngestRequest
1558
+ });
1539
1559
  import net from "net";
1540
1560
  import os6 from "os";
1541
1561
  import { spawn } from "child_process";
@@ -1772,6 +1792,9 @@ async function connectEmbedDaemon() {
1772
1792
  }
1773
1793
  return false;
1774
1794
  }
1795
+ function sendRequest(texts, priority) {
1796
+ return sendDaemonRequest({ texts, priority });
1797
+ }
1775
1798
  function sendDaemonRequest(payload, timeoutMs = REQUEST_TIMEOUT_MS) {
1776
1799
  return new Promise((resolve) => {
1777
1800
  if (!_socket || !_connected) {
@@ -1794,10 +1817,170 @@ function sendDaemonRequest(payload, timeoutMs = REQUEST_TIMEOUT_MS) {
1794
1817
  }
1795
1818
  });
1796
1819
  }
1820
+ async function pingDaemon() {
1821
+ if (!_socket || !_connected) return null;
1822
+ const response = await sendDaemonRequest({ type: "health" }, 5e3);
1823
+ if (response.health) {
1824
+ return response.health;
1825
+ }
1826
+ return null;
1827
+ }
1828
+ function killAndRespawnDaemon() {
1829
+ if (!acquireSpawnLock()) {
1830
+ process.stderr.write("[exed-client] Another process is already restarting daemon \u2014 skipping\n");
1831
+ if (_socket) {
1832
+ _socket.destroy();
1833
+ _socket = null;
1834
+ }
1835
+ _connected = false;
1836
+ _buffer = "";
1837
+ return;
1838
+ }
1839
+ try {
1840
+ process.stderr.write("[exed-client] Killing daemon for restart...\n");
1841
+ if (existsSync7(PID_PATH)) {
1842
+ try {
1843
+ const pid = parseInt(readFileSync7(PID_PATH, "utf8").trim(), 10);
1844
+ if (pid > 0) {
1845
+ try {
1846
+ process.kill(pid, "SIGKILL");
1847
+ } catch {
1848
+ }
1849
+ }
1850
+ } catch {
1851
+ }
1852
+ }
1853
+ if (_socket) {
1854
+ _socket.destroy();
1855
+ _socket = null;
1856
+ }
1857
+ _connected = false;
1858
+ _buffer = "";
1859
+ try {
1860
+ unlinkSync3(PID_PATH);
1861
+ } catch {
1862
+ }
1863
+ try {
1864
+ unlinkSync3(SOCKET_PATH);
1865
+ } catch {
1866
+ }
1867
+ spawnDaemon();
1868
+ } finally {
1869
+ releaseSpawnLock();
1870
+ }
1871
+ }
1872
+ function isDaemonTooYoung() {
1873
+ try {
1874
+ const stat = statSync(PID_PATH);
1875
+ return Date.now() - stat.mtimeMs < MIN_DAEMON_AGE_MS;
1876
+ } catch {
1877
+ return false;
1878
+ }
1879
+ }
1880
+ async function retryThenRestart(doRequest, label) {
1881
+ const result = await doRequest();
1882
+ if (!result.error) {
1883
+ _consecutiveFailures = 0;
1884
+ return result;
1885
+ }
1886
+ _consecutiveFailures++;
1887
+ for (let i = 0; i < MAX_RETRIES_BEFORE_RESTART; i++) {
1888
+ const delayMs = RETRY_DELAYS_MS[i] ?? 5e3;
1889
+ process.stderr.write(`[exed-client] ${label} failed (${result.error}), retry ${i + 1}/${MAX_RETRIES_BEFORE_RESTART} in ${delayMs}ms
1890
+ `);
1891
+ await new Promise((r) => setTimeout(r, delayMs));
1892
+ if (!_connected) {
1893
+ if (!await connectToSocket()) continue;
1894
+ }
1895
+ const retry = await doRequest();
1896
+ if (!retry.error) {
1897
+ _consecutiveFailures = 0;
1898
+ return retry;
1899
+ }
1900
+ _consecutiveFailures++;
1901
+ }
1902
+ if (isDaemonTooYoung()) {
1903
+ process.stderr.write(`[exed-client] ${label}: daemon too young (< ${MIN_DAEMON_AGE_MS / 1e3}s) \u2014 skipping restart
1904
+ `);
1905
+ return { error: result.error };
1906
+ }
1907
+ process.stderr.write(`[exed-client] ${label}: ${_consecutiveFailures} consecutive failures \u2014 restarting daemon
1908
+ `);
1909
+ killAndRespawnDaemon();
1910
+ const start = Date.now();
1911
+ let delay2 = 200;
1912
+ while (Date.now() - start < CONNECT_TIMEOUT_MS) {
1913
+ await new Promise((r) => setTimeout(r, delay2));
1914
+ if (await connectToSocket()) break;
1915
+ delay2 = Math.min(delay2 * 2, 3e3);
1916
+ }
1917
+ if (!_connected) return { error: "Daemon restart failed" };
1918
+ const final = await doRequest();
1919
+ if (!final.error) _consecutiveFailures = 0;
1920
+ return final;
1921
+ }
1922
+ async function embedViaClient(text, priority = "high") {
1923
+ if (!_connected && !await connectEmbedDaemon()) return null;
1924
+ _requestCount++;
1925
+ if (_requestCount % HEALTH_CHECK_INTERVAL === 0) {
1926
+ const health = await pingDaemon();
1927
+ if (!health && !isDaemonTooYoung()) {
1928
+ process.stderr.write(`[exed-client] Periodic health check failed at request ${_requestCount} \u2014 restarting daemon
1929
+ `);
1930
+ killAndRespawnDaemon();
1931
+ const start = Date.now();
1932
+ let d = 200;
1933
+ while (Date.now() - start < CONNECT_TIMEOUT_MS) {
1934
+ await new Promise((r) => setTimeout(r, d));
1935
+ if (await connectToSocket()) break;
1936
+ d = Math.min(d * 2, 3e3);
1937
+ }
1938
+ if (!_connected) return null;
1939
+ }
1940
+ }
1941
+ const result = await retryThenRestart(
1942
+ () => sendRequest([text], priority),
1943
+ "Embed"
1944
+ );
1945
+ return !result.error && result.vectors?.[0] ? result.vectors[0] : null;
1946
+ }
1947
+ async function embedBatchViaClient(texts, priority = "high") {
1948
+ if (!_connected && !await connectEmbedDaemon()) return null;
1949
+ _requestCount++;
1950
+ const result = await retryThenRestart(
1951
+ () => sendRequest(texts, priority),
1952
+ "Batch embed"
1953
+ );
1954
+ return !result.error && result.vectors ? result.vectors : null;
1955
+ }
1956
+ function disconnectClient() {
1957
+ if (_socket) {
1958
+ _socket.destroy();
1959
+ _socket = null;
1960
+ }
1961
+ _connected = false;
1962
+ _buffer = "";
1963
+ for (const [id, entry] of _pending) {
1964
+ clearTimeout(entry.timer);
1965
+ _pending.delete(id);
1966
+ entry.resolve({ error: "Client disconnected" });
1967
+ }
1968
+ }
1797
1969
  function isClientConnected() {
1798
1970
  return _connected;
1799
1971
  }
1800
- 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;
1972
+ function sendIngestRequest(payload) {
1973
+ if (!_socket || !_connected) return false;
1974
+ try {
1975
+ const id = randomUUID();
1976
+ const token = process.env[DAEMON_TOKEN_ENV] ?? readDaemonToken();
1977
+ _socket.write(JSON.stringify({ id, token, type: "ingest", ...payload }) + "\n");
1978
+ return true;
1979
+ } catch {
1980
+ return false;
1981
+ }
1982
+ }
1983
+ 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;
1801
1984
  var init_exe_daemon_client = __esm({
1802
1985
  "src/lib/exe-daemon-client.ts"() {
1803
1986
  "use strict";
@@ -1813,12 +1996,27 @@ var init_exe_daemon_client = __esm({
1813
1996
  _socket = null;
1814
1997
  _connected = false;
1815
1998
  _buffer = "";
1999
+ _requestCount = 0;
2000
+ _consecutiveFailures = 0;
2001
+ HEALTH_CHECK_INTERVAL = 100;
2002
+ MAX_RETRIES_BEFORE_RESTART = 3;
2003
+ RETRY_DELAYS_MS = [1e3, 3e3, 5e3];
2004
+ MIN_DAEMON_AGE_MS = 3e4;
1816
2005
  _pending = /* @__PURE__ */ new Map();
1817
2006
  MAX_BUFFER = 1e7;
1818
2007
  }
1819
2008
  });
1820
2009
 
1821
2010
  // src/lib/daemon-protocol.ts
2011
+ var daemon_protocol_exports = {};
2012
+ __export(daemon_protocol_exports, {
2013
+ deserializeArgs: () => deserializeArgs,
2014
+ deserializeResultSet: () => deserializeResultSet,
2015
+ deserializeValue: () => deserializeValue,
2016
+ serializeArgs: () => serializeArgs,
2017
+ serializeResultSet: () => serializeResultSet,
2018
+ serializeValue: () => serializeValue
2019
+ });
1822
2020
  function serializeValue(v) {
1823
2021
  if (v === null || v === void 0) return null;
1824
2022
  if (typeof v === "bigint") return Number(v);
@@ -1843,6 +2041,32 @@ function deserializeValue(v) {
1843
2041
  }
1844
2042
  return v;
1845
2043
  }
2044
+ function serializeArgs(args) {
2045
+ return args.map(serializeValue);
2046
+ }
2047
+ function deserializeArgs(args) {
2048
+ return args.map(deserializeValue);
2049
+ }
2050
+ function serializeResultSet(rs) {
2051
+ const rows = [];
2052
+ for (const row of rs.rows) {
2053
+ const obj = {};
2054
+ for (let i = 0; i < rs.columns.length; i++) {
2055
+ const col = rs.columns[i];
2056
+ if (col !== void 0) {
2057
+ obj[col] = serializeValue(row[i]);
2058
+ }
2059
+ }
2060
+ rows.push(obj);
2061
+ }
2062
+ return {
2063
+ columns: [...rs.columns],
2064
+ columnTypes: [...rs.columnTypes ?? []],
2065
+ rows,
2066
+ rowsAffected: typeof rs.rowsAffected === "bigint" ? Number(rs.rowsAffected) : rs.rowsAffected ?? 0,
2067
+ lastInsertRowid: rs.lastInsertRowid != null ? typeof rs.lastInsertRowid === "bigint" ? Number(rs.lastInsertRowid) : rs.lastInsertRowid : null
2068
+ };
2069
+ }
1846
2070
  function deserializeResultSet(srs) {
1847
2071
  const rows = srs.rows.map((obj) => {
1848
2072
  const values = srs.columns.map(
@@ -1920,7 +2144,7 @@ function createDaemonDbClient(fallbackClient) {
1920
2144
  });
1921
2145
  if (response.error) {
1922
2146
  const errMsg = String(response.error);
1923
- if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed") {
2147
+ if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed" || errMsg === "DB not initialized") {
1924
2148
  process.stderr.write(`[db-daemon] Transport error (${errMsg}), falling back to direct
1925
2149
  `);
1926
2150
  return fallbackClient.execute(stmt);
@@ -1945,7 +2169,7 @@ function createDaemonDbClient(fallbackClient) {
1945
2169
  });
1946
2170
  if (response.error) {
1947
2171
  const errMsg = String(response.error);
1948
- if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed") {
2172
+ if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed" || errMsg === "DB not initialized") {
1949
2173
  process.stderr.write(`[db-daemon] Batch transport error (${errMsg}), falling back to direct
1950
2174
  `);
1951
2175
  return fallbackClient.batch(stmts, mode);
@@ -2068,7 +2292,7 @@ async function initDatabase(config) {
2068
2292
  });
2069
2293
  }, 3e4);
2070
2294
  _walCheckpointTimer.unref();
2071
- if (process.env.DATABASE_URL) {
2295
+ if (process.env.DATABASE_URL && process.env.EXE_USE_POSTGRES === "1") {
2072
2296
  _adapterClient = await createPrismaDbAdapter(_resilientClient);
2073
2297
  }
2074
2298
  }
@@ -2079,7 +2303,7 @@ function getClient() {
2079
2303
  if (!_adapterClient) {
2080
2304
  throw new Error("Database client not initialized. Call initDatabase() first.");
2081
2305
  }
2082
- if (process.env.DATABASE_URL) {
2306
+ if (process.env.DATABASE_URL && process.env.EXE_USE_POSTGRES === "1") {
2083
2307
  return _adapterClient;
2084
2308
  }
2085
2309
  if (process.env.EXE_IS_DAEMON === "1") {
@@ -2091,9 +2315,11 @@ function getClient() {
2091
2315
  return _resilientClient;
2092
2316
  }
2093
2317
  async function initDaemonClient() {
2094
- if (process.env.DATABASE_URL) return;
2318
+ if (process.env.DATABASE_URL && process.env.EXE_USE_POSTGRES === "1") return;
2095
2319
  if (process.env.EXE_IS_DAEMON === "1") return;
2320
+ if (process.env.VITEST) return;
2096
2321
  if (!_resilientClient) return;
2322
+ if (_daemonClient) return;
2097
2323
  try {
2098
2324
  const { initDaemonDbClient: initDaemonDbClient2 } = await Promise.resolve().then(() => (init_db_daemon_client(), db_daemon_client_exports));
2099
2325
  _daemonClient = await initDaemonDbClient2(_resilientClient);
@@ -2242,6 +2468,13 @@ async function ensureSchema() {
2242
2468
  });
2243
2469
  } catch {
2244
2470
  }
2471
+ try {
2472
+ await client.execute({
2473
+ sql: `ALTER TABLE behaviors ADD COLUMN vector F32_BLOB(${EMBEDDING_DIM})`,
2474
+ args: []
2475
+ });
2476
+ } catch {
2477
+ }
2245
2478
  try {
2246
2479
  await client.execute({
2247
2480
  sql: `ALTER TABLE tasks ADD COLUMN blocked_by TEXT`,
@@ -3112,6 +3345,7 @@ var init_database = __esm({
3112
3345
  init_db_retry();
3113
3346
  init_employees();
3114
3347
  init_database_adapter();
3348
+ init_memory();
3115
3349
  _client = null;
3116
3350
  _resilientClient = null;
3117
3351
  _walCheckpointTimer = null;
@@ -3428,15 +3662,6 @@ var init_cto_delegation_gate = __esm({
3428
3662
  }
3429
3663
  });
3430
3664
 
3431
- // src/types/memory.ts
3432
- var EMBEDDING_DIM;
3433
- var init_memory = __esm({
3434
- "src/types/memory.ts"() {
3435
- "use strict";
3436
- EMBEDDING_DIM = 1024;
3437
- }
3438
- });
3439
-
3440
3665
  // src/lib/keychain.ts
3441
3666
  import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
3442
3667
  import { existsSync as existsSync12 } from "fs";
@@ -3979,6 +4204,68 @@ var init_platform_procedures = __esm({
3979
4204
  domain: "architecture",
3980
4205
  priority: "p0",
3981
4206
  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."
4207
+ },
4208
+ // --- MCP is the ONLY data interface ---
4209
+ {
4210
+ title: "MCP disconnect \u2014 ask the user, never work around it",
4211
+ domain: "workflow",
4212
+ priority: "p0",
4213
+ 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."
4214
+ },
4215
+ // --- MCP Tool Catalog (Layer 0 — every agent knows what tools exist) ---
4216
+ {
4217
+ title: "MCP tools \u2014 memory and search",
4218
+ domain: "tool-use",
4219
+ priority: "p1",
4220
+ 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)."
4221
+ },
4222
+ {
4223
+ title: "MCP tools \u2014 task orchestration",
4224
+ domain: "tool-use",
4225
+ priority: "p1",
4226
+ 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."
4227
+ },
4228
+ {
4229
+ title: "MCP tools \u2014 knowledge graph (GraphRAG)",
4230
+ domain: "tool-use",
4231
+ priority: "p1",
4232
+ 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."
4233
+ },
4234
+ {
4235
+ title: "MCP tools \u2014 identity, behavior, and decisions",
4236
+ domain: "tool-use",
4237
+ priority: "p1",
4238
+ 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."
4239
+ },
4240
+ {
4241
+ title: "MCP tools \u2014 communication and messaging",
4242
+ domain: "tool-use",
4243
+ priority: "p1",
4244
+ 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.)."
4245
+ },
4246
+ {
4247
+ title: "MCP tools \u2014 wiki, documents, and content",
4248
+ domain: "tool-use",
4249
+ priority: "p1",
4250
+ 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."
4251
+ },
4252
+ {
4253
+ title: "MCP tools \u2014 system, operations, and admin",
4254
+ domain: "tool-use",
4255
+ priority: "p1",
4256
+ 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."
4257
+ },
4258
+ {
4259
+ title: "MCP tools \u2014 config, licensing, and team",
4260
+ domain: "tool-use",
4261
+ priority: "p1",
4262
+ 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."
4263
+ },
4264
+ {
4265
+ title: "MCP tools \u2014 advanced (triggers, skills, orchestration)",
4266
+ domain: "tool-use",
4267
+ priority: "p1",
4268
+ 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."
3982
4269
  }
3983
4270
  ];
3984
4271
  PLATFORM_PROCEDURE_TITLES = new Set(
@@ -4128,6 +4415,11 @@ async function initStore(options) {
4128
4415
  encryptionKey: hexKey
4129
4416
  });
4130
4417
  await retryOnBusy2(() => ensureSchema(), "ensureSchema");
4418
+ try {
4419
+ const { initDaemonClient: initDaemonClient2 } = await Promise.resolve().then(() => (init_database(), database_exports));
4420
+ await initDaemonClient2();
4421
+ } catch {
4422
+ }
4131
4423
  if (!options?.lightweight) {
4132
4424
  try {
4133
4425
  const { initShardManager: initShardManager2 } = await Promise.resolve().then(() => (init_shard_manager(), shard_manager_exports));
@@ -4641,6 +4933,77 @@ var init_store = __esm({
4641
4933
  }
4642
4934
  });
4643
4935
 
4936
+ // src/bin/fast-db-init.ts
4937
+ var fast_db_init_exports = {};
4938
+ __export(fast_db_init_exports, {
4939
+ fastDbInit: () => fastDbInit
4940
+ });
4941
+ async function fastDbInit() {
4942
+ const { isInitialized: isInitialized2, getClient: getClient2 } = await Promise.resolve().then(() => (init_database(), database_exports));
4943
+ if (isInitialized2()) {
4944
+ return getClient2();
4945
+ }
4946
+ try {
4947
+ const { connectEmbedDaemon: connectEmbedDaemon2, sendDaemonRequest: sendDaemonRequest2, isClientConnected: isClientConnected2 } = await Promise.resolve().then(() => (init_exe_daemon_client(), exe_daemon_client_exports));
4948
+ const { deserializeResultSet: deserializeResultSet2 } = await Promise.resolve().then(() => (init_daemon_protocol(), daemon_protocol_exports));
4949
+ await connectEmbedDaemon2();
4950
+ if (isClientConnected2()) {
4951
+ const daemonClient = {
4952
+ async execute(stmt) {
4953
+ const sql = typeof stmt === "string" ? stmt : stmt.sql;
4954
+ const args = typeof stmt === "string" ? [] : Array.isArray(stmt.args) ? stmt.args : [];
4955
+ const resp = await sendDaemonRequest2({ type: "db-execute", sql, args });
4956
+ if (resp.error) throw new Error(String(resp.error));
4957
+ if (resp.db) return deserializeResultSet2(resp.db);
4958
+ throw new Error("Unexpected daemon response");
4959
+ },
4960
+ async batch(stmts, mode) {
4961
+ const statements = stmts.map((s) => {
4962
+ const sql = typeof s === "string" ? s : s.sql;
4963
+ const args = typeof s === "string" ? [] : Array.isArray(s.args) ? s.args : [];
4964
+ return { sql, args };
4965
+ });
4966
+ const resp = await sendDaemonRequest2({ type: "db-batch", statements, mode: mode ?? "deferred" });
4967
+ if (resp.error) throw new Error(String(resp.error));
4968
+ const batchResults = resp["db-batch"];
4969
+ if (batchResults) return batchResults.map(deserializeResultSet2);
4970
+ throw new Error("Unexpected daemon batch response");
4971
+ },
4972
+ async transaction(_mode) {
4973
+ throw new Error("Transactions not supported via daemon socket");
4974
+ },
4975
+ async executeMultiple(_sql) {
4976
+ throw new Error("executeMultiple not supported via daemon socket");
4977
+ },
4978
+ async migrate(_stmts) {
4979
+ throw new Error("migrate not supported via daemon socket");
4980
+ },
4981
+ sync() {
4982
+ return Promise.resolve(void 0);
4983
+ },
4984
+ close() {
4985
+ },
4986
+ get closed() {
4987
+ return false;
4988
+ },
4989
+ get protocol() {
4990
+ return "file";
4991
+ }
4992
+ };
4993
+ return daemonClient;
4994
+ }
4995
+ } catch {
4996
+ }
4997
+ const { initStore: initStore2 } = await Promise.resolve().then(() => (init_store(), store_exports));
4998
+ await initStore2({ lightweight: true });
4999
+ return getClient2();
5000
+ }
5001
+ var init_fast_db_init = __esm({
5002
+ "src/bin/fast-db-init.ts"() {
5003
+ "use strict";
5004
+ }
5005
+ });
5006
+
4644
5007
  // src/lib/review-gate.ts
4645
5008
  var review_gate_exports = {};
4646
5009
  __export(review_gate_exports, {
@@ -4961,8 +5324,8 @@ This write was prevented. Do NOT retry.`
4961
5324
  const filePath = data.tool_input?.file_path ?? "";
4962
5325
  if (filePath) {
4963
5326
  try {
4964
- const { initStore: initStore2 } = await Promise.resolve().then(() => (init_store(), store_exports));
4965
- await initStore2();
5327
+ const { fastDbInit: fastDbInit2 } = await Promise.resolve().then(() => (init_fast_db_init(), fast_db_init_exports));
5328
+ await fastDbInit2();
4966
5329
  const { evaluateDelegationGate: evaluateDelegationGate2, GATE_BLOCK_MESSAGE: GATE_BLOCK_MESSAGE2 } = await Promise.resolve().then(() => (init_cto_delegation_gate(), cto_delegation_gate_exports));
4967
5330
  const decision = await evaluateDelegationGate2({
4968
5331
  agentId: agent.agentId,