@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
@@ -64,6 +64,21 @@ var init_secure_files = __esm({
64
64
  });
65
65
 
66
66
  // src/lib/config.ts
67
+ var config_exports = {};
68
+ __export(config_exports, {
69
+ CONFIG_MIGRATIONS: () => CONFIG_MIGRATIONS,
70
+ CONFIG_PATH: () => CONFIG_PATH,
71
+ CURRENT_CONFIG_VERSION: () => CURRENT_CONFIG_VERSION,
72
+ DB_PATH: () => DB_PATH,
73
+ EXE_AI_DIR: () => EXE_AI_DIR,
74
+ LEGACY_LANCE_PATH: () => LEGACY_LANCE_PATH,
75
+ MODELS_DIR: () => MODELS_DIR,
76
+ loadConfig: () => loadConfig,
77
+ loadConfigFrom: () => loadConfigFrom,
78
+ loadConfigSync: () => loadConfigSync,
79
+ migrateConfig: () => migrateConfig,
80
+ saveConfig: () => saveConfig
81
+ });
67
82
  import { readFile, writeFile } from "fs/promises";
68
83
  import { readFileSync, existsSync as existsSync2, renameSync } from "fs";
69
84
  import path from "path";
@@ -167,6 +182,46 @@ async function loadConfig() {
167
182
  return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
168
183
  }
169
184
  }
185
+ function loadConfigSync() {
186
+ const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
187
+ const configPath = path.join(dir, "config.json");
188
+ if (!existsSync2(configPath)) {
189
+ return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
190
+ }
191
+ try {
192
+ const raw = readFileSync(configPath, "utf-8");
193
+ let parsed = JSON.parse(raw);
194
+ parsed = migrateLegacyConfig(parsed);
195
+ const { config: migratedCfg } = migrateConfig(parsed);
196
+ normalizeScalingRoadmap(migratedCfg);
197
+ normalizeSessionLifecycle(migratedCfg);
198
+ normalizeAutoUpdate(migratedCfg);
199
+ return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db"), ...migratedCfg };
200
+ } catch {
201
+ return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
202
+ }
203
+ }
204
+ async function saveConfig(config) {
205
+ const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
206
+ await ensurePrivateDir(dir);
207
+ const configPath = path.join(dir, "config.json");
208
+ await writeFile(configPath, JSON.stringify(config, null, 2) + "\n");
209
+ await enforcePrivateFile(configPath);
210
+ }
211
+ async function loadConfigFrom(configPath) {
212
+ const raw = await readFile(configPath, "utf-8");
213
+ try {
214
+ let parsed = JSON.parse(raw);
215
+ parsed = migrateLegacyConfig(parsed);
216
+ const { config: migratedCfg } = migrateConfig(parsed);
217
+ normalizeScalingRoadmap(migratedCfg);
218
+ normalizeSessionLifecycle(migratedCfg);
219
+ normalizeAutoUpdate(migratedCfg);
220
+ return { ...DEFAULT_CONFIG, ...migratedCfg };
221
+ } catch {
222
+ return { ...DEFAULT_CONFIG };
223
+ }
224
+ }
170
225
  var EXE_AI_DIR, DB_PATH, MODELS_DIR, CONFIG_PATH, LEGACY_LANCE_PATH, CURRENT_CONFIG_VERSION, DEFAULT_CONFIG, CONFIG_MIGRATIONS;
171
226
  var init_config = __esm({
172
227
  "src/lib/config.ts"() {
@@ -666,7 +721,7 @@ var init_agent_config = __esm({
666
721
  init_secure_files();
667
722
  AGENT_CONFIG_PATH = path5.join(EXE_AI_DIR, "agent-config.json");
668
723
  DEFAULT_MODELS = {
669
- claude: "claude-opus-4",
724
+ claude: "claude-opus-4.6",
670
725
  codex: RUNTIME_TABLE.codex?.defaultModel ?? "gpt-5.4",
671
726
  opencode: RUNTIME_TABLE.opencode?.defaultModel ?? "anthropic/claude-sonnet-4-6"
672
727
  };
@@ -783,8 +838,8 @@ function logQueue(msg) {
783
838
  process.stderr.write(`[intercom-queue] ${msg}
784
839
  `);
785
840
  try {
786
- const { appendFileSync: appendFileSync2 } = __require("fs");
787
- appendFileSync2(INTERCOM_LOG, line);
841
+ const { appendFileSync: appendFileSync3 } = __require("fs");
842
+ appendFileSync3(INTERCOM_LOG, line);
788
843
  } catch {
789
844
  }
790
845
  }
@@ -848,9 +903,9 @@ var MAX_RETRIES2, BASE_DELAY_MS, MAX_JITTER_MS;
848
903
  var init_db_retry = __esm({
849
904
  "src/lib/db-retry.ts"() {
850
905
  "use strict";
851
- MAX_RETRIES2 = 3;
852
- BASE_DELAY_MS = 200;
853
- MAX_JITTER_MS = 300;
906
+ MAX_RETRIES2 = 5;
907
+ BASE_DELAY_MS = 250;
908
+ MAX_JITTER_MS = 400;
854
909
  }
855
910
  });
856
911
 
@@ -1438,6 +1493,15 @@ var init_database_adapter = __esm({
1438
1493
  }
1439
1494
  });
1440
1495
 
1496
+ // src/types/memory.ts
1497
+ var EMBEDDING_DIM;
1498
+ var init_memory = __esm({
1499
+ "src/types/memory.ts"() {
1500
+ "use strict";
1501
+ EMBEDDING_DIM = 1024;
1502
+ }
1503
+ });
1504
+
1441
1505
  // src/lib/daemon-auth.ts
1442
1506
  import crypto from "crypto";
1443
1507
  import path8 from "path";
@@ -1712,6 +1776,9 @@ async function connectEmbedDaemon() {
1712
1776
  }
1713
1777
  return false;
1714
1778
  }
1779
+ function sendRequest(texts, priority) {
1780
+ return sendDaemonRequest({ texts, priority });
1781
+ }
1715
1782
  function sendDaemonRequest(payload, timeoutMs = REQUEST_TIMEOUT_MS) {
1716
1783
  return new Promise((resolve) => {
1717
1784
  if (!_socket || !_connected) {
@@ -1734,10 +1801,150 @@ function sendDaemonRequest(payload, timeoutMs = REQUEST_TIMEOUT_MS) {
1734
1801
  }
1735
1802
  });
1736
1803
  }
1804
+ async function pingDaemon() {
1805
+ if (!_socket || !_connected) return null;
1806
+ const response = await sendDaemonRequest({ type: "health" }, 5e3);
1807
+ if (response.health) {
1808
+ return response.health;
1809
+ }
1810
+ return null;
1811
+ }
1812
+ function killAndRespawnDaemon() {
1813
+ if (!acquireSpawnLock()) {
1814
+ process.stderr.write("[exed-client] Another process is already restarting daemon \u2014 skipping\n");
1815
+ if (_socket) {
1816
+ _socket.destroy();
1817
+ _socket = null;
1818
+ }
1819
+ _connected = false;
1820
+ _buffer = "";
1821
+ return;
1822
+ }
1823
+ try {
1824
+ process.stderr.write("[exed-client] Killing daemon for restart...\n");
1825
+ if (existsSync8(PID_PATH)) {
1826
+ try {
1827
+ const pid = parseInt(readFileSync8(PID_PATH, "utf8").trim(), 10);
1828
+ if (pid > 0) {
1829
+ try {
1830
+ process.kill(pid, "SIGKILL");
1831
+ } catch {
1832
+ }
1833
+ }
1834
+ } catch {
1835
+ }
1836
+ }
1837
+ if (_socket) {
1838
+ _socket.destroy();
1839
+ _socket = null;
1840
+ }
1841
+ _connected = false;
1842
+ _buffer = "";
1843
+ try {
1844
+ unlinkSync3(PID_PATH);
1845
+ } catch {
1846
+ }
1847
+ try {
1848
+ unlinkSync3(SOCKET_PATH);
1849
+ } catch {
1850
+ }
1851
+ spawnDaemon();
1852
+ } finally {
1853
+ releaseSpawnLock();
1854
+ }
1855
+ }
1856
+ function isDaemonTooYoung() {
1857
+ try {
1858
+ const stat = statSync(PID_PATH);
1859
+ return Date.now() - stat.mtimeMs < MIN_DAEMON_AGE_MS;
1860
+ } catch {
1861
+ return false;
1862
+ }
1863
+ }
1864
+ async function retryThenRestart(doRequest, label) {
1865
+ const result = await doRequest();
1866
+ if (!result.error) {
1867
+ _consecutiveFailures = 0;
1868
+ return result;
1869
+ }
1870
+ _consecutiveFailures++;
1871
+ for (let i = 0; i < MAX_RETRIES_BEFORE_RESTART; i++) {
1872
+ const delayMs = RETRY_DELAYS_MS[i] ?? 5e3;
1873
+ process.stderr.write(`[exed-client] ${label} failed (${result.error}), retry ${i + 1}/${MAX_RETRIES_BEFORE_RESTART} in ${delayMs}ms
1874
+ `);
1875
+ await new Promise((r) => setTimeout(r, delayMs));
1876
+ if (!_connected) {
1877
+ if (!await connectToSocket()) continue;
1878
+ }
1879
+ const retry = await doRequest();
1880
+ if (!retry.error) {
1881
+ _consecutiveFailures = 0;
1882
+ return retry;
1883
+ }
1884
+ _consecutiveFailures++;
1885
+ }
1886
+ if (isDaemonTooYoung()) {
1887
+ process.stderr.write(`[exed-client] ${label}: daemon too young (< ${MIN_DAEMON_AGE_MS / 1e3}s) \u2014 skipping restart
1888
+ `);
1889
+ return { error: result.error };
1890
+ }
1891
+ process.stderr.write(`[exed-client] ${label}: ${_consecutiveFailures} consecutive failures \u2014 restarting daemon
1892
+ `);
1893
+ killAndRespawnDaemon();
1894
+ const start = Date.now();
1895
+ let delay2 = 200;
1896
+ while (Date.now() - start < CONNECT_TIMEOUT_MS) {
1897
+ await new Promise((r) => setTimeout(r, delay2));
1898
+ if (await connectToSocket()) break;
1899
+ delay2 = Math.min(delay2 * 2, 3e3);
1900
+ }
1901
+ if (!_connected) return { error: "Daemon restart failed" };
1902
+ const final = await doRequest();
1903
+ if (!final.error) _consecutiveFailures = 0;
1904
+ return final;
1905
+ }
1906
+ async function embedViaClient(text, priority = "high") {
1907
+ if (!_connected && !await connectEmbedDaemon()) return null;
1908
+ _requestCount++;
1909
+ if (_requestCount % HEALTH_CHECK_INTERVAL === 0) {
1910
+ const health = await pingDaemon();
1911
+ if (!health && !isDaemonTooYoung()) {
1912
+ process.stderr.write(`[exed-client] Periodic health check failed at request ${_requestCount} \u2014 restarting daemon
1913
+ `);
1914
+ killAndRespawnDaemon();
1915
+ const start = Date.now();
1916
+ let d = 200;
1917
+ while (Date.now() - start < CONNECT_TIMEOUT_MS) {
1918
+ await new Promise((r) => setTimeout(r, d));
1919
+ if (await connectToSocket()) break;
1920
+ d = Math.min(d * 2, 3e3);
1921
+ }
1922
+ if (!_connected) return null;
1923
+ }
1924
+ }
1925
+ const result = await retryThenRestart(
1926
+ () => sendRequest([text], priority),
1927
+ "Embed"
1928
+ );
1929
+ return !result.error && result.vectors?.[0] ? result.vectors[0] : null;
1930
+ }
1931
+ function disconnectClient() {
1932
+ if (_socket) {
1933
+ _socket.destroy();
1934
+ _socket = null;
1935
+ }
1936
+ _connected = false;
1937
+ _buffer = "";
1938
+ for (const [id, entry] of _pending) {
1939
+ clearTimeout(entry.timer);
1940
+ _pending.delete(id);
1941
+ entry.resolve({ error: "Client disconnected" });
1942
+ }
1943
+ }
1737
1944
  function isClientConnected() {
1738
1945
  return _connected;
1739
1946
  }
1740
- 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;
1947
+ 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;
1741
1948
  var init_exe_daemon_client = __esm({
1742
1949
  "src/lib/exe-daemon-client.ts"() {
1743
1950
  "use strict";
@@ -1753,6 +1960,12 @@ var init_exe_daemon_client = __esm({
1753
1960
  _socket = null;
1754
1961
  _connected = false;
1755
1962
  _buffer = "";
1963
+ _requestCount = 0;
1964
+ _consecutiveFailures = 0;
1965
+ HEALTH_CHECK_INTERVAL = 100;
1966
+ MAX_RETRIES_BEFORE_RESTART = 3;
1967
+ RETRY_DELAYS_MS = [1e3, 3e3, 5e3];
1968
+ MIN_DAEMON_AGE_MS = 3e4;
1756
1969
  _pending = /* @__PURE__ */ new Map();
1757
1970
  MAX_BUFFER = 1e7;
1758
1971
  }
@@ -1860,7 +2073,7 @@ function createDaemonDbClient(fallbackClient) {
1860
2073
  });
1861
2074
  if (response.error) {
1862
2075
  const errMsg = String(response.error);
1863
- if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed") {
2076
+ if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed" || errMsg === "DB not initialized") {
1864
2077
  process.stderr.write(`[db-daemon] Transport error (${errMsg}), falling back to direct
1865
2078
  `);
1866
2079
  return fallbackClient.execute(stmt);
@@ -1885,7 +2098,7 @@ function createDaemonDbClient(fallbackClient) {
1885
2098
  });
1886
2099
  if (response.error) {
1887
2100
  const errMsg = String(response.error);
1888
- if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed") {
2101
+ if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed" || errMsg === "DB not initialized") {
1889
2102
  process.stderr.write(`[db-daemon] Batch transport error (${errMsg}), falling back to direct
1890
2103
  `);
1891
2104
  return fallbackClient.batch(stmts, mode);
@@ -2008,7 +2221,7 @@ async function initDatabase(config) {
2008
2221
  });
2009
2222
  }, 3e4);
2010
2223
  _walCheckpointTimer.unref();
2011
- if (process.env.DATABASE_URL) {
2224
+ if (process.env.DATABASE_URL && process.env.EXE_USE_POSTGRES === "1") {
2012
2225
  _adapterClient = await createPrismaDbAdapter(_resilientClient);
2013
2226
  }
2014
2227
  }
@@ -2019,7 +2232,7 @@ function getClient() {
2019
2232
  if (!_adapterClient) {
2020
2233
  throw new Error("Database client not initialized. Call initDatabase() first.");
2021
2234
  }
2022
- if (process.env.DATABASE_URL) {
2235
+ if (process.env.DATABASE_URL && process.env.EXE_USE_POSTGRES === "1") {
2023
2236
  return _adapterClient;
2024
2237
  }
2025
2238
  if (process.env.EXE_IS_DAEMON === "1") {
@@ -2031,9 +2244,11 @@ function getClient() {
2031
2244
  return _resilientClient;
2032
2245
  }
2033
2246
  async function initDaemonClient() {
2034
- if (process.env.DATABASE_URL) return;
2247
+ if (process.env.DATABASE_URL && process.env.EXE_USE_POSTGRES === "1") return;
2035
2248
  if (process.env.EXE_IS_DAEMON === "1") return;
2249
+ if (process.env.VITEST) return;
2036
2250
  if (!_resilientClient) return;
2251
+ if (_daemonClient) return;
2037
2252
  try {
2038
2253
  const { initDaemonDbClient: initDaemonDbClient2 } = await Promise.resolve().then(() => (init_db_daemon_client(), db_daemon_client_exports));
2039
2254
  _daemonClient = await initDaemonDbClient2(_resilientClient);
@@ -2182,6 +2397,13 @@ async function ensureSchema() {
2182
2397
  });
2183
2398
  } catch {
2184
2399
  }
2400
+ try {
2401
+ await client.execute({
2402
+ sql: `ALTER TABLE behaviors ADD COLUMN vector F32_BLOB(${EMBEDDING_DIM})`,
2403
+ args: []
2404
+ });
2405
+ } catch {
2406
+ }
2185
2407
  try {
2186
2408
  await client.execute({
2187
2409
  sql: `ALTER TABLE tasks ADD COLUMN blocked_by TEXT`,
@@ -3052,6 +3274,7 @@ var init_database = __esm({
3052
3274
  init_db_retry();
3053
3275
  init_employees();
3054
3276
  init_database_adapter();
3277
+ init_memory();
3055
3278
  _client = null;
3056
3279
  _resilientClient = null;
3057
3280
  _walCheckpointTimer = null;
@@ -3547,15 +3770,20 @@ async function createTaskCore(input2) {
3547
3770
  const { resolveExeSession: resolveExeSession2 } = await Promise.resolve().then(() => (init_tmux_routing(), tmux_routing_exports));
3548
3771
  const resolved = resolveExeSession2();
3549
3772
  if (resolved && input2.projectName) {
3550
- const { getSessionProject: getSessionProject2 } = await Promise.resolve().then(() => (init_session_scope(), session_scope_exports));
3551
- const sessionProject = getSessionProject2(resolved);
3552
- if (sessionProject && sessionProject !== input2.projectName) {
3553
- scopeMismatchWarning = `session/project mismatch: session "${resolved}" owns "${sessionProject}" but task targets "${input2.projectName}". Routed to default scope.`;
3554
- process.stderr.write(`[create_task] ${scopeMismatchWarning}
3555
- `);
3556
- earlySessionScope = null;
3557
- } else {
3773
+ const isCoordinatorSession = !resolved.includes("-");
3774
+ if (isCoordinatorSession) {
3558
3775
  earlySessionScope = resolved;
3776
+ } else {
3777
+ const { getSessionProject: getSessionProject2 } = await Promise.resolve().then(() => (init_session_scope(), session_scope_exports));
3778
+ const sessionProject = getSessionProject2(resolved);
3779
+ if (sessionProject && sessionProject !== input2.projectName) {
3780
+ scopeMismatchWarning = `session/project mismatch: session "${resolved}" owns "${sessionProject}" but task targets "${input2.projectName}". Routed to default scope.`;
3781
+ process.stderr.write(`[create_task] ${scopeMismatchWarning}
3782
+ `);
3783
+ earlySessionScope = null;
3784
+ } else {
3785
+ earlySessionScope = resolved;
3786
+ }
3559
3787
  }
3560
3788
  } else {
3561
3789
  earlySessionScope = resolved;
@@ -4440,6 +4668,10 @@ async function dispatchTaskToEmployee(input2) {
4440
4668
  if (transport.isAlive(sessionName)) {
4441
4669
  const result = sendIntercom(sessionName);
4442
4670
  const dispatched = result === "acknowledged" || result === "debounced" || result === "queued" ? "verified" : result === "delivered" ? "sent_unverified" : "session_dead";
4671
+ process.stderr.write(
4672
+ `[dispatch-audit] intercom \u2192 ${sessionName} | task="${input2.title}" [${input2.priority}] | result=${dispatched} (sendIntercom=${result})
4673
+ `
4674
+ );
4443
4675
  return { dispatched, session: sessionName, crossProject };
4444
4676
  } else {
4445
4677
  const projectDir = input2.projectDir ?? process.cwd();
@@ -4448,11 +4680,15 @@ async function dispatchTaskToEmployee(input2) {
4448
4680
  });
4449
4681
  if (result.status === "failed") {
4450
4682
  process.stderr.write(
4451
- `[dispatch] Failed to spawn ${input2.assignedTo}: ${result.error}
4683
+ `[dispatch-audit] SPAWN FAILED \u2192 ${input2.assignedTo} | task="${input2.title}" [${input2.priority}] | error=${result.error}
4452
4684
  `
4453
4685
  );
4454
4686
  return { dispatched: "session_missing" };
4455
4687
  }
4688
+ process.stderr.write(
4689
+ `[dispatch-audit] SPAWNED \u2192 ${result.sessionName} | task="${input2.title}" [${input2.priority}]
4690
+ `
4691
+ );
4456
4692
  return { dispatched: "spawned", session: result.sessionName, crossProject };
4457
4693
  }
4458
4694
  } catch {
@@ -4462,7 +4698,13 @@ async function dispatchTaskToEmployee(input2) {
4462
4698
  function notifyTaskDone() {
4463
4699
  try {
4464
4700
  const key = getSessionKey();
4465
- if (key && !process.env.VITEST) notifyParentExe(key);
4701
+ if (key && !process.env.VITEST) {
4702
+ notifyParentExe(key);
4703
+ process.stderr.write(
4704
+ `[dispatch-audit] notifyTaskDone \u2192 parent coordinator (session=${key})
4705
+ `
4706
+ );
4707
+ }
4466
4708
  } catch {
4467
4709
  }
4468
4710
  }
@@ -4483,16 +4725,91 @@ var init_tasks_notify = __esm({
4483
4725
  }
4484
4726
  });
4485
4727
 
4728
+ // src/lib/embedder.ts
4729
+ var embedder_exports = {};
4730
+ __export(embedder_exports, {
4731
+ disposeEmbedder: () => disposeEmbedder,
4732
+ embed: () => embed,
4733
+ embedDirect: () => embedDirect,
4734
+ getEmbedder: () => getEmbedder
4735
+ });
4736
+ async function getEmbedder() {
4737
+ const ok = await connectEmbedDaemon();
4738
+ if (!ok) {
4739
+ throw new Error(
4740
+ "Could not connect to embedding daemon. Ensure the model is installed (run /exe-setup)."
4741
+ );
4742
+ }
4743
+ }
4744
+ async function embed(text) {
4745
+ const priority = process.env.EXE_EMBED_PRIORITY === "low" ? "low" : "high";
4746
+ const vector = await embedViaClient(text, priority);
4747
+ if (!vector) {
4748
+ throw new Error(
4749
+ "Embedding failed: daemon unavailable. Run /exe-setup to verify model installation."
4750
+ );
4751
+ }
4752
+ if (vector.length !== EMBEDDING_DIM) {
4753
+ throw new Error(
4754
+ `Embedding dimension mismatch: expected ${EMBEDDING_DIM}, got ${vector.length}. Ensure the correct Jina v5-small Q4_K_M GGUF model is installed.`
4755
+ );
4756
+ }
4757
+ return vector;
4758
+ }
4759
+ async function disposeEmbedder() {
4760
+ disconnectClient();
4761
+ }
4762
+ async function embedDirect(text) {
4763
+ const llamaCpp = await import("node-llama-cpp");
4764
+ const { MODELS_DIR: MODELS_DIR2 } = await Promise.resolve().then(() => (init_config(), config_exports));
4765
+ const { existsSync: existsSync18 } = await import("fs");
4766
+ const path22 = await import("path");
4767
+ const modelPath = path22.join(MODELS_DIR2, "jina-embeddings-v5-small-q4_k_m.gguf");
4768
+ if (!existsSync18(modelPath)) {
4769
+ throw new Error(`Embedding model not found at ${modelPath}. Run '/exe-setup' to download it.`);
4770
+ }
4771
+ const llama = await llamaCpp.getLlama();
4772
+ const model = await llama.loadModel({ modelPath });
4773
+ const context = await model.createEmbeddingContext();
4774
+ try {
4775
+ const embedding = await context.getEmbeddingFor(text);
4776
+ const vector = Array.from(embedding.vector);
4777
+ if (vector.length !== EMBEDDING_DIM) {
4778
+ throw new Error(
4779
+ `Embedding dimension mismatch: expected ${EMBEDDING_DIM}, got ${vector.length}.`
4780
+ );
4781
+ }
4782
+ return vector;
4783
+ } finally {
4784
+ await context.dispose();
4785
+ await model.dispose();
4786
+ }
4787
+ }
4788
+ var init_embedder = __esm({
4789
+ "src/lib/embedder.ts"() {
4790
+ "use strict";
4791
+ init_memory();
4792
+ init_exe_daemon_client();
4793
+ }
4794
+ });
4795
+
4486
4796
  // src/lib/behaviors.ts
4487
4797
  import crypto5 from "crypto";
4488
4798
  async function storeBehavior(opts) {
4489
4799
  const client = getClient();
4490
4800
  const id = crypto5.randomUUID();
4491
4801
  const now = (/* @__PURE__ */ new Date()).toISOString();
4802
+ let vector = null;
4803
+ try {
4804
+ const { embed: embed2 } = await Promise.resolve().then(() => (init_embedder(), embedder_exports));
4805
+ const vec = await embed2(opts.content);
4806
+ vector = new Float32Array(vec);
4807
+ } catch {
4808
+ }
4492
4809
  await client.execute({
4493
- sql: `INSERT INTO behaviors (id, agent_id, project_name, domain, priority, content, active, created_at, updated_at)
4494
- VALUES (?, ?, ?, ?, ?, ?, 1, ?, ?)`,
4495
- args: [id, opts.agentId, opts.projectName ?? null, opts.domain ?? null, opts.priority ?? "p1", opts.content, now, now]
4810
+ sql: `INSERT INTO behaviors (id, agent_id, project_name, domain, priority, content, active, created_at, updated_at, vector)
4811
+ VALUES (?, ?, ?, ?, ?, ?, 1, ?, ?, ?)`,
4812
+ args: [id, opts.agentId, opts.projectName ?? null, opts.domain ?? null, opts.priority ?? "p1", opts.content, now, now, vector ? vector.buffer : null]
4496
4813
  });
4497
4814
  return id;
4498
4815
  }
@@ -5595,7 +5912,7 @@ function isSessionBusy(sessionName) {
5595
5912
  function isExeSession(sessionName) {
5596
5913
  const matchesBaseWithInstance = (baseName) => sessionName === baseName || sessionName.startsWith(baseName) && /^\d+$/.test(sessionName.slice(baseName.length));
5597
5914
  const coordinatorName = getCoordinatorName();
5598
- return matchesBaseWithInstance(coordinatorName) || matchesBaseWithInstance("exe");
5915
+ return matchesBaseWithInstance(coordinatorName);
5599
5916
  }
5600
5917
  function sendIntercom(targetSession) {
5601
5918
  const transport = getTransport();
@@ -6132,15 +6449,6 @@ var init_task_scope = __esm({
6132
6449
  }
6133
6450
  });
6134
6451
 
6135
- // src/types/memory.ts
6136
- var EMBEDDING_DIM;
6137
- var init_memory = __esm({
6138
- "src/types/memory.ts"() {
6139
- "use strict";
6140
- EMBEDDING_DIM = 1024;
6141
- }
6142
- });
6143
-
6144
6452
  // src/lib/keychain.ts
6145
6453
  import { readFile as readFile4, writeFile as writeFile5, unlink, mkdir as mkdir4, chmod as chmod2 } from "fs/promises";
6146
6454
  import { existsSync as existsSync15 } from "fs";
@@ -6628,6 +6936,68 @@ var init_platform_procedures = __esm({
6628
6936
  domain: "architecture",
6629
6937
  priority: "p0",
6630
6938
  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."
6939
+ },
6940
+ // --- MCP is the ONLY data interface ---
6941
+ {
6942
+ title: "MCP disconnect \u2014 ask the user, never work around it",
6943
+ domain: "workflow",
6944
+ priority: "p0",
6945
+ 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."
6946
+ },
6947
+ // --- MCP Tool Catalog (Layer 0 — every agent knows what tools exist) ---
6948
+ {
6949
+ title: "MCP tools \u2014 memory and search",
6950
+ domain: "tool-use",
6951
+ priority: "p1",
6952
+ 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)."
6953
+ },
6954
+ {
6955
+ title: "MCP tools \u2014 task orchestration",
6956
+ domain: "tool-use",
6957
+ priority: "p1",
6958
+ 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."
6959
+ },
6960
+ {
6961
+ title: "MCP tools \u2014 knowledge graph (GraphRAG)",
6962
+ domain: "tool-use",
6963
+ priority: "p1",
6964
+ 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."
6965
+ },
6966
+ {
6967
+ title: "MCP tools \u2014 identity, behavior, and decisions",
6968
+ domain: "tool-use",
6969
+ priority: "p1",
6970
+ 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."
6971
+ },
6972
+ {
6973
+ title: "MCP tools \u2014 communication and messaging",
6974
+ domain: "tool-use",
6975
+ priority: "p1",
6976
+ 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.)."
6977
+ },
6978
+ {
6979
+ title: "MCP tools \u2014 wiki, documents, and content",
6980
+ domain: "tool-use",
6981
+ priority: "p1",
6982
+ 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."
6983
+ },
6984
+ {
6985
+ title: "MCP tools \u2014 system, operations, and admin",
6986
+ domain: "tool-use",
6987
+ priority: "p1",
6988
+ 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."
6989
+ },
6990
+ {
6991
+ title: "MCP tools \u2014 config, licensing, and team",
6992
+ domain: "tool-use",
6993
+ priority: "p1",
6994
+ 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."
6995
+ },
6996
+ {
6997
+ title: "MCP tools \u2014 advanced (triggers, skills, orchestration)",
6998
+ domain: "tool-use",
6999
+ priority: "p1",
7000
+ 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."
6631
7001
  }
6632
7002
  ];
6633
7003
  PLATFORM_PROCEDURE_TITLES = new Set(
@@ -6777,6 +7147,11 @@ async function initStore(options) {
6777
7147
  encryptionKey: hexKey
6778
7148
  });
6779
7149
  await retryOnBusy2(() => ensureSchema(), "ensureSchema");
7150
+ try {
7151
+ const { initDaemonClient: initDaemonClient2 } = await Promise.resolve().then(() => (init_database(), database_exports));
7152
+ await initDaemonClient2();
7153
+ } catch {
7154
+ }
6780
7155
  if (!options?.lightweight) {
6781
7156
  try {
6782
7157
  const { initShardManager: initShardManager2 } = await Promise.resolve().then(() => (init_shard_manager(), shard_manager_exports));
@@ -7290,8 +7665,77 @@ var init_store = __esm({
7290
7665
  }
7291
7666
  });
7292
7667
 
7293
- // src/adapters/claude/hooks/pre-compact.ts
7294
- import crypto7 from "crypto";
7668
+ // src/lib/memory-queue.ts
7669
+ import { appendFileSync as appendFileSync2, readFileSync as readFileSync14, renameSync as renameSync4, unlinkSync as unlinkSync8, existsSync as existsSync17, statSync as statSync2 } from "fs";
7670
+ import path21 from "path";
7671
+ function enqueueMemory(entry) {
7672
+ appendFileSync2(QUEUE_PATH2, JSON.stringify(entry) + "\n");
7673
+ }
7674
+ var QUEUE_PATH2, PROCESSING_PATH, TTL_MS2;
7675
+ var init_memory_queue = __esm({
7676
+ "src/lib/memory-queue.ts"() {
7677
+ "use strict";
7678
+ init_config();
7679
+ QUEUE_PATH2 = path21.join(EXE_AI_DIR, "memory-queue.jsonl");
7680
+ PROCESSING_PATH = QUEUE_PATH2 + ".processing";
7681
+ TTL_MS2 = 24 * 60 * 60 * 1e3;
7682
+ }
7683
+ });
7684
+
7685
+ // src/lib/memory-queue-client.ts
7686
+ var memory_queue_client_exports = {};
7687
+ __export(memory_queue_client_exports, {
7688
+ batchWriteMemoryViaDaemon: () => batchWriteMemoryViaDaemon,
7689
+ writeMemoryViaDaemon: () => writeMemoryViaDaemon
7690
+ });
7691
+ async function writeMemoryViaDaemon(entry) {
7692
+ if (process.env.EXE_IS_DAEMON === "1") {
7693
+ enqueueMemory(entry);
7694
+ return false;
7695
+ }
7696
+ if (!isClientConnected()) {
7697
+ enqueueMemory(entry);
7698
+ return false;
7699
+ }
7700
+ try {
7701
+ const response = await sendDaemonRequest({
7702
+ type: "write-memory",
7703
+ entry
7704
+ });
7705
+ if (response.ok) return true;
7706
+ enqueueMemory(entry);
7707
+ return false;
7708
+ } catch {
7709
+ enqueueMemory(entry);
7710
+ return false;
7711
+ }
7712
+ }
7713
+ async function batchWriteMemoryViaDaemon(entries) {
7714
+ if (entries.length === 0) return 0;
7715
+ if (process.env.EXE_IS_DAEMON === "1" || !isClientConnected()) {
7716
+ for (const entry of entries) enqueueMemory(entry);
7717
+ return 0;
7718
+ }
7719
+ try {
7720
+ const response = await sendDaemonRequest({
7721
+ type: "batch-write-memory",
7722
+ entries
7723
+ });
7724
+ if (response.ok) return response.count ?? entries.length;
7725
+ for (const entry of entries) enqueueMemory(entry);
7726
+ return 0;
7727
+ } catch {
7728
+ for (const entry of entries) enqueueMemory(entry);
7729
+ return 0;
7730
+ }
7731
+ }
7732
+ var init_memory_queue_client = __esm({
7733
+ "src/lib/memory-queue-client.ts"() {
7734
+ "use strict";
7735
+ init_exe_daemon_client();
7736
+ init_memory_queue();
7737
+ }
7738
+ });
7295
7739
 
7296
7740
  // src/lib/active-agent.ts
7297
7741
  init_config();
@@ -7411,7 +7855,7 @@ process.stdin.on("end", async () => {
7411
7855
  const agent = getActiveAgent();
7412
7856
  const sections = [];
7413
7857
  try {
7414
- const { initStore: initStore2, writeMemory: writeMemory2, flushBatch: flushBatch2 } = await Promise.resolve().then(() => (init_store(), store_exports));
7858
+ const { initStore: initStore2 } = await Promise.resolve().then(() => (init_store(), store_exports));
7415
7859
  await initStore2();
7416
7860
  const { getClient: getClient2 } = await Promise.resolve().then(() => (init_database(), database_exports));
7417
7861
  const client = getClient2();
@@ -7463,21 +7907,18 @@ ${taskLines}`);
7463
7907
  if (lastCheckpoint?.files_touched?.length) {
7464
7908
  recoveryLines.push(`Files: ${lastCheckpoint.files_touched.join(", ")}`);
7465
7909
  }
7466
- await writeMemory2({
7467
- id: crypto7.randomUUID(),
7910
+ const { writeMemoryViaDaemon: writeMemoryViaDaemon2 } = await Promise.resolve().then(() => (init_memory_queue_client(), memory_queue_client_exports));
7911
+ await writeMemoryViaDaemon2({
7912
+ raw_text: recoveryLines.join("\n"),
7468
7913
  agent_id: agent.agentId,
7469
7914
  agent_role: agent.agentRole,
7470
7915
  session_id: payload.session_id,
7471
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
7472
7916
  tool_name: "pre-compact-hook",
7473
7917
  project_name: projectName,
7474
- has_error: false,
7475
- raw_text: recoveryLines.join("\n"),
7476
- vector: null,
7918
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
7477
7919
  importance: 8,
7478
7920
  task_id: taskId
7479
7921
  });
7480
- await flushBatch2();
7481
7922
  } catch {
7482
7923
  }
7483
7924
  }