@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"() {
@@ -669,7 +724,7 @@ var init_agent_config = __esm({
669
724
  init_secure_files();
670
725
  AGENT_CONFIG_PATH = path6.join(EXE_AI_DIR, "agent-config.json");
671
726
  DEFAULT_MODELS = {
672
- claude: "claude-opus-4",
727
+ claude: "claude-opus-4.6",
673
728
  codex: RUNTIME_TABLE.codex?.defaultModel ?? "gpt-5.4",
674
729
  opencode: RUNTIME_TABLE.opencode?.defaultModel ?? "anthropic/claude-sonnet-4-6"
675
730
  };
@@ -786,8 +841,8 @@ function logQueue(msg) {
786
841
  process.stderr.write(`[intercom-queue] ${msg}
787
842
  `);
788
843
  try {
789
- const { appendFileSync: appendFileSync2 } = __require("fs");
790
- appendFileSync2(INTERCOM_LOG, line);
844
+ const { appendFileSync: appendFileSync3 } = __require("fs");
845
+ appendFileSync3(INTERCOM_LOG, line);
791
846
  } catch {
792
847
  }
793
848
  }
@@ -851,9 +906,9 @@ var MAX_RETRIES2, BASE_DELAY_MS, MAX_JITTER_MS;
851
906
  var init_db_retry = __esm({
852
907
  "src/lib/db-retry.ts"() {
853
908
  "use strict";
854
- MAX_RETRIES2 = 3;
855
- BASE_DELAY_MS = 200;
856
- MAX_JITTER_MS = 300;
909
+ MAX_RETRIES2 = 5;
910
+ BASE_DELAY_MS = 250;
911
+ MAX_JITTER_MS = 400;
857
912
  }
858
913
  });
859
914
 
@@ -1441,6 +1496,15 @@ var init_database_adapter = __esm({
1441
1496
  }
1442
1497
  });
1443
1498
 
1499
+ // src/types/memory.ts
1500
+ var EMBEDDING_DIM;
1501
+ var init_memory = __esm({
1502
+ "src/types/memory.ts"() {
1503
+ "use strict";
1504
+ EMBEDDING_DIM = 1024;
1505
+ }
1506
+ });
1507
+
1444
1508
  // src/lib/daemon-auth.ts
1445
1509
  import crypto from "crypto";
1446
1510
  import path9 from "path";
@@ -1715,6 +1779,9 @@ async function connectEmbedDaemon() {
1715
1779
  }
1716
1780
  return false;
1717
1781
  }
1782
+ function sendRequest(texts, priority) {
1783
+ return sendDaemonRequest({ texts, priority });
1784
+ }
1718
1785
  function sendDaemonRequest(payload, timeoutMs = REQUEST_TIMEOUT_MS) {
1719
1786
  return new Promise((resolve) => {
1720
1787
  if (!_socket || !_connected) {
@@ -1737,10 +1804,150 @@ function sendDaemonRequest(payload, timeoutMs = REQUEST_TIMEOUT_MS) {
1737
1804
  }
1738
1805
  });
1739
1806
  }
1807
+ async function pingDaemon() {
1808
+ if (!_socket || !_connected) return null;
1809
+ const response = await sendDaemonRequest({ type: "health" }, 5e3);
1810
+ if (response.health) {
1811
+ return response.health;
1812
+ }
1813
+ return null;
1814
+ }
1815
+ function killAndRespawnDaemon() {
1816
+ if (!acquireSpawnLock()) {
1817
+ process.stderr.write("[exed-client] Another process is already restarting daemon \u2014 skipping\n");
1818
+ if (_socket) {
1819
+ _socket.destroy();
1820
+ _socket = null;
1821
+ }
1822
+ _connected = false;
1823
+ _buffer = "";
1824
+ return;
1825
+ }
1826
+ try {
1827
+ process.stderr.write("[exed-client] Killing daemon for restart...\n");
1828
+ if (existsSync9(PID_PATH)) {
1829
+ try {
1830
+ const pid = parseInt(readFileSync9(PID_PATH, "utf8").trim(), 10);
1831
+ if (pid > 0) {
1832
+ try {
1833
+ process.kill(pid, "SIGKILL");
1834
+ } catch {
1835
+ }
1836
+ }
1837
+ } catch {
1838
+ }
1839
+ }
1840
+ if (_socket) {
1841
+ _socket.destroy();
1842
+ _socket = null;
1843
+ }
1844
+ _connected = false;
1845
+ _buffer = "";
1846
+ try {
1847
+ unlinkSync4(PID_PATH);
1848
+ } catch {
1849
+ }
1850
+ try {
1851
+ unlinkSync4(SOCKET_PATH);
1852
+ } catch {
1853
+ }
1854
+ spawnDaemon();
1855
+ } finally {
1856
+ releaseSpawnLock();
1857
+ }
1858
+ }
1859
+ function isDaemonTooYoung() {
1860
+ try {
1861
+ const stat = statSync(PID_PATH);
1862
+ return Date.now() - stat.mtimeMs < MIN_DAEMON_AGE_MS;
1863
+ } catch {
1864
+ return false;
1865
+ }
1866
+ }
1867
+ async function retryThenRestart(doRequest, label) {
1868
+ const result = await doRequest();
1869
+ if (!result.error) {
1870
+ _consecutiveFailures = 0;
1871
+ return result;
1872
+ }
1873
+ _consecutiveFailures++;
1874
+ for (let i = 0; i < MAX_RETRIES_BEFORE_RESTART; i++) {
1875
+ const delayMs = RETRY_DELAYS_MS[i] ?? 5e3;
1876
+ process.stderr.write(`[exed-client] ${label} failed (${result.error}), retry ${i + 1}/${MAX_RETRIES_BEFORE_RESTART} in ${delayMs}ms
1877
+ `);
1878
+ await new Promise((r) => setTimeout(r, delayMs));
1879
+ if (!_connected) {
1880
+ if (!await connectToSocket()) continue;
1881
+ }
1882
+ const retry = await doRequest();
1883
+ if (!retry.error) {
1884
+ _consecutiveFailures = 0;
1885
+ return retry;
1886
+ }
1887
+ _consecutiveFailures++;
1888
+ }
1889
+ if (isDaemonTooYoung()) {
1890
+ process.stderr.write(`[exed-client] ${label}: daemon too young (< ${MIN_DAEMON_AGE_MS / 1e3}s) \u2014 skipping restart
1891
+ `);
1892
+ return { error: result.error };
1893
+ }
1894
+ process.stderr.write(`[exed-client] ${label}: ${_consecutiveFailures} consecutive failures \u2014 restarting daemon
1895
+ `);
1896
+ killAndRespawnDaemon();
1897
+ const start = Date.now();
1898
+ let delay2 = 200;
1899
+ while (Date.now() - start < CONNECT_TIMEOUT_MS) {
1900
+ await new Promise((r) => setTimeout(r, delay2));
1901
+ if (await connectToSocket()) break;
1902
+ delay2 = Math.min(delay2 * 2, 3e3);
1903
+ }
1904
+ if (!_connected) return { error: "Daemon restart failed" };
1905
+ const final = await doRequest();
1906
+ if (!final.error) _consecutiveFailures = 0;
1907
+ return final;
1908
+ }
1909
+ async function embedViaClient(text, priority = "high") {
1910
+ if (!_connected && !await connectEmbedDaemon()) return null;
1911
+ _requestCount++;
1912
+ if (_requestCount % HEALTH_CHECK_INTERVAL === 0) {
1913
+ const health = await pingDaemon();
1914
+ if (!health && !isDaemonTooYoung()) {
1915
+ process.stderr.write(`[exed-client] Periodic health check failed at request ${_requestCount} \u2014 restarting daemon
1916
+ `);
1917
+ killAndRespawnDaemon();
1918
+ const start = Date.now();
1919
+ let d = 200;
1920
+ while (Date.now() - start < CONNECT_TIMEOUT_MS) {
1921
+ await new Promise((r) => setTimeout(r, d));
1922
+ if (await connectToSocket()) break;
1923
+ d = Math.min(d * 2, 3e3);
1924
+ }
1925
+ if (!_connected) return null;
1926
+ }
1927
+ }
1928
+ const result = await retryThenRestart(
1929
+ () => sendRequest([text], priority),
1930
+ "Embed"
1931
+ );
1932
+ return !result.error && result.vectors?.[0] ? result.vectors[0] : null;
1933
+ }
1934
+ function disconnectClient() {
1935
+ if (_socket) {
1936
+ _socket.destroy();
1937
+ _socket = null;
1938
+ }
1939
+ _connected = false;
1940
+ _buffer = "";
1941
+ for (const [id, entry] of _pending) {
1942
+ clearTimeout(entry.timer);
1943
+ _pending.delete(id);
1944
+ entry.resolve({ error: "Client disconnected" });
1945
+ }
1946
+ }
1740
1947
  function isClientConnected() {
1741
1948
  return _connected;
1742
1949
  }
1743
- 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;
1950
+ 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;
1744
1951
  var init_exe_daemon_client = __esm({
1745
1952
  "src/lib/exe-daemon-client.ts"() {
1746
1953
  "use strict";
@@ -1756,6 +1963,12 @@ var init_exe_daemon_client = __esm({
1756
1963
  _socket = null;
1757
1964
  _connected = false;
1758
1965
  _buffer = "";
1966
+ _requestCount = 0;
1967
+ _consecutiveFailures = 0;
1968
+ HEALTH_CHECK_INTERVAL = 100;
1969
+ MAX_RETRIES_BEFORE_RESTART = 3;
1970
+ RETRY_DELAYS_MS = [1e3, 3e3, 5e3];
1971
+ MIN_DAEMON_AGE_MS = 3e4;
1759
1972
  _pending = /* @__PURE__ */ new Map();
1760
1973
  MAX_BUFFER = 1e7;
1761
1974
  }
@@ -1863,7 +2076,7 @@ function createDaemonDbClient(fallbackClient) {
1863
2076
  });
1864
2077
  if (response.error) {
1865
2078
  const errMsg = String(response.error);
1866
- if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed") {
2079
+ if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed" || errMsg === "DB not initialized") {
1867
2080
  process.stderr.write(`[db-daemon] Transport error (${errMsg}), falling back to direct
1868
2081
  `);
1869
2082
  return fallbackClient.execute(stmt);
@@ -1888,7 +2101,7 @@ function createDaemonDbClient(fallbackClient) {
1888
2101
  });
1889
2102
  if (response.error) {
1890
2103
  const errMsg = String(response.error);
1891
- if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed") {
2104
+ if (errMsg === "Not connected" || errMsg === "Request timeout" || errMsg === "Write failed" || errMsg === "DB not initialized") {
1892
2105
  process.stderr.write(`[db-daemon] Batch transport error (${errMsg}), falling back to direct
1893
2106
  `);
1894
2107
  return fallbackClient.batch(stmts, mode);
@@ -2011,7 +2224,7 @@ async function initDatabase(config) {
2011
2224
  });
2012
2225
  }, 3e4);
2013
2226
  _walCheckpointTimer.unref();
2014
- if (process.env.DATABASE_URL) {
2227
+ if (process.env.DATABASE_URL && process.env.EXE_USE_POSTGRES === "1") {
2015
2228
  _adapterClient = await createPrismaDbAdapter(_resilientClient);
2016
2229
  }
2017
2230
  }
@@ -2022,7 +2235,7 @@ function getClient() {
2022
2235
  if (!_adapterClient) {
2023
2236
  throw new Error("Database client not initialized. Call initDatabase() first.");
2024
2237
  }
2025
- if (process.env.DATABASE_URL) {
2238
+ if (process.env.DATABASE_URL && process.env.EXE_USE_POSTGRES === "1") {
2026
2239
  return _adapterClient;
2027
2240
  }
2028
2241
  if (process.env.EXE_IS_DAEMON === "1") {
@@ -2034,9 +2247,11 @@ function getClient() {
2034
2247
  return _resilientClient;
2035
2248
  }
2036
2249
  async function initDaemonClient() {
2037
- if (process.env.DATABASE_URL) return;
2250
+ if (process.env.DATABASE_URL && process.env.EXE_USE_POSTGRES === "1") return;
2038
2251
  if (process.env.EXE_IS_DAEMON === "1") return;
2252
+ if (process.env.VITEST) return;
2039
2253
  if (!_resilientClient) return;
2254
+ if (_daemonClient) return;
2040
2255
  try {
2041
2256
  const { initDaemonDbClient: initDaemonDbClient2 } = await Promise.resolve().then(() => (init_db_daemon_client(), db_daemon_client_exports));
2042
2257
  _daemonClient = await initDaemonDbClient2(_resilientClient);
@@ -2185,6 +2400,13 @@ async function ensureSchema() {
2185
2400
  });
2186
2401
  } catch {
2187
2402
  }
2403
+ try {
2404
+ await client.execute({
2405
+ sql: `ALTER TABLE behaviors ADD COLUMN vector F32_BLOB(${EMBEDDING_DIM})`,
2406
+ args: []
2407
+ });
2408
+ } catch {
2409
+ }
2188
2410
  try {
2189
2411
  await client.execute({
2190
2412
  sql: `ALTER TABLE tasks ADD COLUMN blocked_by TEXT`,
@@ -3055,6 +3277,7 @@ var init_database = __esm({
3055
3277
  init_db_retry();
3056
3278
  init_employees();
3057
3279
  init_database_adapter();
3280
+ init_memory();
3058
3281
  _client = null;
3059
3282
  _resilientClient = null;
3060
3283
  _walCheckpointTimer = null;
@@ -3756,15 +3979,20 @@ async function createTaskCore(input2) {
3756
3979
  const { resolveExeSession: resolveExeSession2 } = await Promise.resolve().then(() => (init_tmux_routing(), tmux_routing_exports));
3757
3980
  const resolved = resolveExeSession2();
3758
3981
  if (resolved && input2.projectName) {
3759
- const { getSessionProject: getSessionProject2 } = await Promise.resolve().then(() => (init_session_scope(), session_scope_exports));
3760
- const sessionProject = getSessionProject2(resolved);
3761
- if (sessionProject && sessionProject !== input2.projectName) {
3762
- scopeMismatchWarning = `session/project mismatch: session "${resolved}" owns "${sessionProject}" but task targets "${input2.projectName}". Routed to default scope.`;
3763
- process.stderr.write(`[create_task] ${scopeMismatchWarning}
3764
- `);
3765
- earlySessionScope = null;
3766
- } else {
3982
+ const isCoordinatorSession = !resolved.includes("-");
3983
+ if (isCoordinatorSession) {
3767
3984
  earlySessionScope = resolved;
3985
+ } else {
3986
+ const { getSessionProject: getSessionProject2 } = await Promise.resolve().then(() => (init_session_scope(), session_scope_exports));
3987
+ const sessionProject = getSessionProject2(resolved);
3988
+ if (sessionProject && sessionProject !== input2.projectName) {
3989
+ scopeMismatchWarning = `session/project mismatch: session "${resolved}" owns "${sessionProject}" but task targets "${input2.projectName}". Routed to default scope.`;
3990
+ process.stderr.write(`[create_task] ${scopeMismatchWarning}
3991
+ `);
3992
+ earlySessionScope = null;
3993
+ } else {
3994
+ earlySessionScope = resolved;
3995
+ }
3768
3996
  }
3769
3997
  } else {
3770
3998
  earlySessionScope = resolved;
@@ -4649,6 +4877,10 @@ async function dispatchTaskToEmployee(input2) {
4649
4877
  if (transport.isAlive(sessionName)) {
4650
4878
  const result = sendIntercom(sessionName);
4651
4879
  const dispatched = result === "acknowledged" || result === "debounced" || result === "queued" ? "verified" : result === "delivered" ? "sent_unverified" : "session_dead";
4880
+ process.stderr.write(
4881
+ `[dispatch-audit] intercom \u2192 ${sessionName} | task="${input2.title}" [${input2.priority}] | result=${dispatched} (sendIntercom=${result})
4882
+ `
4883
+ );
4652
4884
  return { dispatched, session: sessionName, crossProject };
4653
4885
  } else {
4654
4886
  const projectDir = input2.projectDir ?? process.cwd();
@@ -4657,11 +4889,15 @@ async function dispatchTaskToEmployee(input2) {
4657
4889
  });
4658
4890
  if (result.status === "failed") {
4659
4891
  process.stderr.write(
4660
- `[dispatch] Failed to spawn ${input2.assignedTo}: ${result.error}
4892
+ `[dispatch-audit] SPAWN FAILED \u2192 ${input2.assignedTo} | task="${input2.title}" [${input2.priority}] | error=${result.error}
4661
4893
  `
4662
4894
  );
4663
4895
  return { dispatched: "session_missing" };
4664
4896
  }
4897
+ process.stderr.write(
4898
+ `[dispatch-audit] SPAWNED \u2192 ${result.sessionName} | task="${input2.title}" [${input2.priority}]
4899
+ `
4900
+ );
4665
4901
  return { dispatched: "spawned", session: result.sessionName, crossProject };
4666
4902
  }
4667
4903
  } catch {
@@ -4671,7 +4907,13 @@ async function dispatchTaskToEmployee(input2) {
4671
4907
  function notifyTaskDone() {
4672
4908
  try {
4673
4909
  const key = getSessionKey();
4674
- if (key && !process.env.VITEST) notifyParentExe(key);
4910
+ if (key && !process.env.VITEST) {
4911
+ notifyParentExe(key);
4912
+ process.stderr.write(
4913
+ `[dispatch-audit] notifyTaskDone \u2192 parent coordinator (session=${key})
4914
+ `
4915
+ );
4916
+ }
4675
4917
  } catch {
4676
4918
  }
4677
4919
  }
@@ -4692,16 +4934,91 @@ var init_tasks_notify = __esm({
4692
4934
  }
4693
4935
  });
4694
4936
 
4937
+ // src/lib/embedder.ts
4938
+ var embedder_exports = {};
4939
+ __export(embedder_exports, {
4940
+ disposeEmbedder: () => disposeEmbedder,
4941
+ embed: () => embed,
4942
+ embedDirect: () => embedDirect,
4943
+ getEmbedder: () => getEmbedder
4944
+ });
4945
+ async function getEmbedder() {
4946
+ const ok = await connectEmbedDaemon();
4947
+ if (!ok) {
4948
+ throw new Error(
4949
+ "Could not connect to embedding daemon. Ensure the model is installed (run /exe-setup)."
4950
+ );
4951
+ }
4952
+ }
4953
+ async function embed(text) {
4954
+ const priority = process.env.EXE_EMBED_PRIORITY === "low" ? "low" : "high";
4955
+ const vector = await embedViaClient(text, priority);
4956
+ if (!vector) {
4957
+ throw new Error(
4958
+ "Embedding failed: daemon unavailable. Run /exe-setup to verify model installation."
4959
+ );
4960
+ }
4961
+ if (vector.length !== EMBEDDING_DIM) {
4962
+ throw new Error(
4963
+ `Embedding dimension mismatch: expected ${EMBEDDING_DIM}, got ${vector.length}. Ensure the correct Jina v5-small Q4_K_M GGUF model is installed.`
4964
+ );
4965
+ }
4966
+ return vector;
4967
+ }
4968
+ async function disposeEmbedder() {
4969
+ disconnectClient();
4970
+ }
4971
+ async function embedDirect(text) {
4972
+ const llamaCpp = await import("node-llama-cpp");
4973
+ const { MODELS_DIR: MODELS_DIR2 } = await Promise.resolve().then(() => (init_config(), config_exports));
4974
+ const { existsSync: existsSync19 } = await import("fs");
4975
+ const path24 = await import("path");
4976
+ const modelPath = path24.join(MODELS_DIR2, "jina-embeddings-v5-small-q4_k_m.gguf");
4977
+ if (!existsSync19(modelPath)) {
4978
+ throw new Error(`Embedding model not found at ${modelPath}. Run '/exe-setup' to download it.`);
4979
+ }
4980
+ const llama = await llamaCpp.getLlama();
4981
+ const model = await llama.loadModel({ modelPath });
4982
+ const context = await model.createEmbeddingContext();
4983
+ try {
4984
+ const embedding = await context.getEmbeddingFor(text);
4985
+ const vector = Array.from(embedding.vector);
4986
+ if (vector.length !== EMBEDDING_DIM) {
4987
+ throw new Error(
4988
+ `Embedding dimension mismatch: expected ${EMBEDDING_DIM}, got ${vector.length}.`
4989
+ );
4990
+ }
4991
+ return vector;
4992
+ } finally {
4993
+ await context.dispose();
4994
+ await model.dispose();
4995
+ }
4996
+ }
4997
+ var init_embedder = __esm({
4998
+ "src/lib/embedder.ts"() {
4999
+ "use strict";
5000
+ init_memory();
5001
+ init_exe_daemon_client();
5002
+ }
5003
+ });
5004
+
4695
5005
  // src/lib/behaviors.ts
4696
5006
  import crypto5 from "crypto";
4697
5007
  async function storeBehavior(opts) {
4698
5008
  const client = getClient();
4699
5009
  const id = crypto5.randomUUID();
4700
5010
  const now = (/* @__PURE__ */ new Date()).toISOString();
5011
+ let vector = null;
5012
+ try {
5013
+ const { embed: embed2 } = await Promise.resolve().then(() => (init_embedder(), embedder_exports));
5014
+ const vec = await embed2(opts.content);
5015
+ vector = new Float32Array(vec);
5016
+ } catch {
5017
+ }
4701
5018
  await client.execute({
4702
- sql: `INSERT INTO behaviors (id, agent_id, project_name, domain, priority, content, active, created_at, updated_at)
4703
- VALUES (?, ?, ?, ?, ?, ?, 1, ?, ?)`,
4704
- args: [id, opts.agentId, opts.projectName ?? null, opts.domain ?? null, opts.priority ?? "p1", opts.content, now, now]
5019
+ sql: `INSERT INTO behaviors (id, agent_id, project_name, domain, priority, content, active, created_at, updated_at, vector)
5020
+ VALUES (?, ?, ?, ?, ?, ?, 1, ?, ?, ?)`,
5021
+ args: [id, opts.agentId, opts.projectName ?? null, opts.domain ?? null, opts.priority ?? "p1", opts.content, now, now, vector ? vector.buffer : null]
4705
5022
  });
4706
5023
  return id;
4707
5024
  }
@@ -5804,7 +6121,7 @@ function isSessionBusy(sessionName) {
5804
6121
  function isExeSession(sessionName) {
5805
6122
  const matchesBaseWithInstance = (baseName) => sessionName === baseName || sessionName.startsWith(baseName) && /^\d+$/.test(sessionName.slice(baseName.length));
5806
6123
  const coordinatorName = getCoordinatorName();
5807
- return matchesBaseWithInstance(coordinatorName) || matchesBaseWithInstance("exe");
6124
+ return matchesBaseWithInstance(coordinatorName);
5808
6125
  }
5809
6126
  function sendIntercom(targetSession) {
5810
6127
  const transport = getTransport();
@@ -6341,15 +6658,6 @@ var init_task_scope = __esm({
6341
6658
  }
6342
6659
  });
6343
6660
 
6344
- // src/types/memory.ts
6345
- var EMBEDDING_DIM;
6346
- var init_memory = __esm({
6347
- "src/types/memory.ts"() {
6348
- "use strict";
6349
- EMBEDDING_DIM = 1024;
6350
- }
6351
- });
6352
-
6353
6661
  // src/lib/keychain.ts
6354
6662
  import { readFile as readFile4, writeFile as writeFile5, unlink, mkdir as mkdir4, chmod as chmod2 } from "fs/promises";
6355
6663
  import { existsSync as existsSync16 } from "fs";
@@ -6837,6 +7145,68 @@ var init_platform_procedures = __esm({
6837
7145
  domain: "architecture",
6838
7146
  priority: "p0",
6839
7147
  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."
7148
+ },
7149
+ // --- MCP is the ONLY data interface ---
7150
+ {
7151
+ title: "MCP disconnect \u2014 ask the user, never work around it",
7152
+ domain: "workflow",
7153
+ priority: "p0",
7154
+ 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."
7155
+ },
7156
+ // --- MCP Tool Catalog (Layer 0 — every agent knows what tools exist) ---
7157
+ {
7158
+ title: "MCP tools \u2014 memory and search",
7159
+ domain: "tool-use",
7160
+ priority: "p1",
7161
+ 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)."
7162
+ },
7163
+ {
7164
+ title: "MCP tools \u2014 task orchestration",
7165
+ domain: "tool-use",
7166
+ priority: "p1",
7167
+ 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."
7168
+ },
7169
+ {
7170
+ title: "MCP tools \u2014 knowledge graph (GraphRAG)",
7171
+ domain: "tool-use",
7172
+ priority: "p1",
7173
+ 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."
7174
+ },
7175
+ {
7176
+ title: "MCP tools \u2014 identity, behavior, and decisions",
7177
+ domain: "tool-use",
7178
+ priority: "p1",
7179
+ 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."
7180
+ },
7181
+ {
7182
+ title: "MCP tools \u2014 communication and messaging",
7183
+ domain: "tool-use",
7184
+ priority: "p1",
7185
+ 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.)."
7186
+ },
7187
+ {
7188
+ title: "MCP tools \u2014 wiki, documents, and content",
7189
+ domain: "tool-use",
7190
+ priority: "p1",
7191
+ 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."
7192
+ },
7193
+ {
7194
+ title: "MCP tools \u2014 system, operations, and admin",
7195
+ domain: "tool-use",
7196
+ priority: "p1",
7197
+ 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."
7198
+ },
7199
+ {
7200
+ title: "MCP tools \u2014 config, licensing, and team",
7201
+ domain: "tool-use",
7202
+ priority: "p1",
7203
+ 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."
7204
+ },
7205
+ {
7206
+ title: "MCP tools \u2014 advanced (triggers, skills, orchestration)",
7207
+ domain: "tool-use",
7208
+ priority: "p1",
7209
+ 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."
6840
7210
  }
6841
7211
  ];
6842
7212
  PLATFORM_PROCEDURE_TITLES = new Set(
@@ -6986,6 +7356,11 @@ async function initStore(options) {
6986
7356
  encryptionKey: hexKey
6987
7357
  });
6988
7358
  await retryOnBusy2(() => ensureSchema(), "ensureSchema");
7359
+ try {
7360
+ const { initDaemonClient: initDaemonClient2 } = await Promise.resolve().then(() => (init_database(), database_exports));
7361
+ await initDaemonClient2();
7362
+ } catch {
7363
+ }
6989
7364
  if (!options?.lightweight) {
6990
7365
  try {
6991
7366
  const { initShardManager: initShardManager2 } = await Promise.resolve().then(() => (init_shard_manager(), shard_manager_exports));
@@ -7499,6 +7874,78 @@ var init_store = __esm({
7499
7874
  }
7500
7875
  });
7501
7876
 
7877
+ // src/lib/memory-queue.ts
7878
+ import { appendFileSync as appendFileSync2, readFileSync as readFileSync15, renameSync as renameSync4, unlinkSync as unlinkSync9, existsSync as existsSync18, statSync as statSync2 } from "fs";
7879
+ import path22 from "path";
7880
+ function enqueueMemory(entry) {
7881
+ appendFileSync2(QUEUE_PATH2, JSON.stringify(entry) + "\n");
7882
+ }
7883
+ var QUEUE_PATH2, PROCESSING_PATH, TTL_MS2;
7884
+ var init_memory_queue = __esm({
7885
+ "src/lib/memory-queue.ts"() {
7886
+ "use strict";
7887
+ init_config();
7888
+ QUEUE_PATH2 = path22.join(EXE_AI_DIR, "memory-queue.jsonl");
7889
+ PROCESSING_PATH = QUEUE_PATH2 + ".processing";
7890
+ TTL_MS2 = 24 * 60 * 60 * 1e3;
7891
+ }
7892
+ });
7893
+
7894
+ // src/lib/memory-queue-client.ts
7895
+ var memory_queue_client_exports = {};
7896
+ __export(memory_queue_client_exports, {
7897
+ batchWriteMemoryViaDaemon: () => batchWriteMemoryViaDaemon,
7898
+ writeMemoryViaDaemon: () => writeMemoryViaDaemon
7899
+ });
7900
+ async function writeMemoryViaDaemon(entry) {
7901
+ if (process.env.EXE_IS_DAEMON === "1") {
7902
+ enqueueMemory(entry);
7903
+ return false;
7904
+ }
7905
+ if (!isClientConnected()) {
7906
+ enqueueMemory(entry);
7907
+ return false;
7908
+ }
7909
+ try {
7910
+ const response = await sendDaemonRequest({
7911
+ type: "write-memory",
7912
+ entry
7913
+ });
7914
+ if (response.ok) return true;
7915
+ enqueueMemory(entry);
7916
+ return false;
7917
+ } catch {
7918
+ enqueueMemory(entry);
7919
+ return false;
7920
+ }
7921
+ }
7922
+ async function batchWriteMemoryViaDaemon(entries) {
7923
+ if (entries.length === 0) return 0;
7924
+ if (process.env.EXE_IS_DAEMON === "1" || !isClientConnected()) {
7925
+ for (const entry of entries) enqueueMemory(entry);
7926
+ return 0;
7927
+ }
7928
+ try {
7929
+ const response = await sendDaemonRequest({
7930
+ type: "batch-write-memory",
7931
+ entries
7932
+ });
7933
+ if (response.ok) return response.count ?? entries.length;
7934
+ for (const entry of entries) enqueueMemory(entry);
7935
+ return 0;
7936
+ } catch {
7937
+ for (const entry of entries) enqueueMemory(entry);
7938
+ return 0;
7939
+ }
7940
+ }
7941
+ var init_memory_queue_client = __esm({
7942
+ "src/lib/memory-queue-client.ts"() {
7943
+ "use strict";
7944
+ init_exe_daemon_client();
7945
+ init_memory_queue();
7946
+ }
7947
+ });
7948
+
7502
7949
  // src/lib/git-staleness.ts
7503
7950
  var git_staleness_exports = {};
7504
7951
  __export(git_staleness_exports, {
@@ -7507,7 +7954,7 @@ __export(git_staleness_exports, {
7507
7954
  recordFileRead: () => recordFileRead
7508
7955
  });
7509
7956
  import { execSync as execSync8 } from "child_process";
7510
- import path22 from "path";
7957
+ import path23 from "path";
7511
7958
  function getHeadCommit(cwd) {
7512
7959
  try {
7513
7960
  return execSync8("git rev-parse --short HEAD", {
@@ -7520,9 +7967,9 @@ function getHeadCommit(cwd) {
7520
7967
  }
7521
7968
  }
7522
7969
  function normalizeTrackedPath(cwd, filePath) {
7523
- const resolved = path22.resolve(cwd, filePath);
7524
- const relative = path22.relative(cwd, resolved);
7525
- if (!relative || relative.startsWith("..") || path22.isAbsolute(relative)) {
7970
+ const resolved = path23.resolve(cwd, filePath);
7971
+ const relative = path23.relative(cwd, resolved);
7972
+ if (!relative || relative.startsWith("..") || path23.isAbsolute(relative)) {
7526
7973
  return null;
7527
7974
  }
7528
7975
  return relative;
@@ -7979,9 +8426,7 @@ process.stdin.on("end", async () => {
7979
8426
  try {
7980
8427
  const { initStore: initStore2 } = await Promise.resolve().then(() => (init_store(), store_exports));
7981
8428
  await initStore2();
7982
- const { writeMemory: writeMemory2, flushBatch: flushBatch2 } = await Promise.resolve().then(() => (init_store(), store_exports));
7983
8429
  const { getClient: getClient2 } = await Promise.resolve().then(() => (init_database(), database_exports));
7984
- const { randomUUID: randomUUID4 } = await import("crypto");
7985
8430
  const client = getClient2();
7986
8431
  const seScope = strictSessionScopeFilter();
7987
8432
  const orphanResult = await client.execute({
@@ -7990,19 +8435,16 @@ process.stdin.on("end", async () => {
7990
8435
  });
7991
8436
  const orphanInfo = orphanResult.rows.length > 0 ? `
7992
8437
  Orphaned tasks at session end: ${orphanResult.rows.map((r) => `"${String(r.title)}" (${String(r.status)})`).join(", ")}` : "";
7993
- await writeMemory2({
7994
- id: randomUUID4(),
8438
+ const { writeMemoryViaDaemon: writeMemoryViaDaemon2 } = await Promise.resolve().then(() => (init_memory_queue_client(), memory_queue_client_exports));
8439
+ await writeMemoryViaDaemon2({
8440
+ raw_text: `Session ended for ${agent.agentId}.${orphanInfo}`,
7995
8441
  agent_id: agent.agentId,
7996
8442
  agent_role: agent.agentRole,
7997
8443
  session_id: data.session_id,
7998
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
7999
8444
  tool_name: "SessionEnd",
8000
8445
  project_name: process.env.EXE_PROJECT_NAME ?? process.cwd().split("/").pop() ?? "unknown",
8001
- has_error: false,
8002
- raw_text: `Session ended for ${agent.agentId}.${orphanInfo}`,
8003
- vector: null
8446
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
8004
8447
  });
8005
- await flushBatch2();
8006
8448
  try {
8007
8449
  const { clearSessionFileReads: clearSessionFileReads2 } = await Promise.resolve().then(() => (init_git_staleness(), git_staleness_exports));
8008
8450
  await clearSessionFileReads2(data.session_id);