@askexenow/exe-os 0.9.8 → 0.9.9

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 (101) hide show
  1. package/dist/bin/backfill-conversations.js +222 -49
  2. package/dist/bin/backfill-responses.js +221 -48
  3. package/dist/bin/backfill-vectors.js +225 -52
  4. package/dist/bin/cleanup-stale-review-tasks.js +150 -28
  5. package/dist/bin/cli.js +1295 -856
  6. package/dist/bin/exe-agent-config.js +36 -8
  7. package/dist/bin/exe-agent.js +14 -4
  8. package/dist/bin/exe-assign.js +221 -48
  9. package/dist/bin/exe-boot.js +778 -427
  10. package/dist/bin/exe-call.js +41 -13
  11. package/dist/bin/exe-cloud.js +163 -58
  12. package/dist/bin/exe-dispatch.js +276 -139
  13. package/dist/bin/exe-doctor.js +145 -27
  14. package/dist/bin/exe-export-behaviors.js +141 -23
  15. package/dist/bin/exe-forget.js +137 -19
  16. package/dist/bin/exe-gateway.js +677 -388
  17. package/dist/bin/exe-heartbeat.js +227 -108
  18. package/dist/bin/exe-kill.js +138 -20
  19. package/dist/bin/exe-launch-agent.js +172 -39
  20. package/dist/bin/exe-link.js +291 -100
  21. package/dist/bin/exe-new-employee.js +214 -106
  22. package/dist/bin/exe-pending-messages.js +395 -33
  23. package/dist/bin/exe-pending-notifications.js +684 -99
  24. package/dist/bin/exe-pending-reviews.js +420 -74
  25. package/dist/bin/exe-rename.js +147 -49
  26. package/dist/bin/exe-review.js +138 -20
  27. package/dist/bin/exe-search.js +240 -69
  28. package/dist/bin/exe-session-cleanup.js +440 -250
  29. package/dist/bin/exe-settings.js +61 -17
  30. package/dist/bin/exe-start-codex.js +158 -39
  31. package/dist/bin/exe-start-opencode.js +157 -38
  32. package/dist/bin/exe-status.js +151 -29
  33. package/dist/bin/exe-team.js +138 -20
  34. package/dist/bin/git-sweep.js +404 -212
  35. package/dist/bin/graph-backfill.js +137 -19
  36. package/dist/bin/graph-export.js +140 -22
  37. package/dist/bin/install.js +90 -61
  38. package/dist/bin/scan-tasks.js +412 -220
  39. package/dist/bin/setup.js +564 -293
  40. package/dist/bin/shard-migrate.js +139 -21
  41. package/dist/bin/update.js +138 -49
  42. package/dist/bin/wiki-sync.js +137 -19
  43. package/dist/gateway/index.js +533 -320
  44. package/dist/hooks/bug-report-worker.js +344 -193
  45. package/dist/hooks/codex-stop-task-finalizer.js +4678 -0
  46. package/dist/hooks/commit-complete.js +402 -210
  47. package/dist/hooks/error-recall.js +245 -74
  48. package/dist/hooks/exe-heartbeat-hook.js +16 -6
  49. package/dist/hooks/ingest-worker.js +3423 -3157
  50. package/dist/hooks/ingest.js +832 -97
  51. package/dist/hooks/instructions-loaded.js +227 -54
  52. package/dist/hooks/notification.js +216 -43
  53. package/dist/hooks/post-compact.js +239 -62
  54. package/dist/hooks/pre-compact.js +408 -216
  55. package/dist/hooks/pre-tool-use.js +268 -90
  56. package/dist/hooks/prompt-ingest-worker.js +352 -102
  57. package/dist/hooks/prompt-submit.js +541 -328
  58. package/dist/hooks/response-ingest-worker.js +372 -122
  59. package/dist/hooks/session-end.js +443 -240
  60. package/dist/hooks/session-start.js +313 -127
  61. package/dist/hooks/stop.js +293 -98
  62. package/dist/hooks/subagent-stop.js +239 -62
  63. package/dist/hooks/summary-worker.js +568 -236
  64. package/dist/index.js +538 -324
  65. package/dist/lib/agent-config.js +28 -6
  66. package/dist/lib/cloud-sync.js +284 -105
  67. package/dist/lib/config.js +30 -10
  68. package/dist/lib/consolidation.js +16 -6
  69. package/dist/lib/database.js +123 -25
  70. package/dist/lib/db-daemon-client.js +73 -19
  71. package/dist/lib/db.js +123 -25
  72. package/dist/lib/device-registry.js +133 -35
  73. package/dist/lib/embedder.js +107 -32
  74. package/dist/lib/employee-templates.js +14 -4
  75. package/dist/lib/employees.js +41 -13
  76. package/dist/lib/exe-daemon-client.js +88 -22
  77. package/dist/lib/exe-daemon.js +935 -587
  78. package/dist/lib/hybrid-search.js +240 -69
  79. package/dist/lib/identity.js +18 -8
  80. package/dist/lib/license.js +133 -48
  81. package/dist/lib/messaging.js +116 -56
  82. package/dist/lib/reminders.js +14 -4
  83. package/dist/lib/schedules.js +137 -19
  84. package/dist/lib/skill-learning.js +33 -6
  85. package/dist/lib/store.js +137 -19
  86. package/dist/lib/task-router.js +14 -4
  87. package/dist/lib/tasks.js +280 -234
  88. package/dist/lib/tmux-routing.js +172 -125
  89. package/dist/lib/token-spend.js +26 -8
  90. package/dist/mcp/server.js +1326 -609
  91. package/dist/mcp/tools/complete-reminder.js +14 -4
  92. package/dist/mcp/tools/create-reminder.js +14 -4
  93. package/dist/mcp/tools/create-task.js +306 -248
  94. package/dist/mcp/tools/deactivate-behavior.js +16 -6
  95. package/dist/mcp/tools/list-reminders.js +14 -4
  96. package/dist/mcp/tools/list-tasks.js +123 -107
  97. package/dist/mcp/tools/send-message.js +75 -29
  98. package/dist/mcp/tools/update-task.js +1848 -199
  99. package/dist/runtime/index.js +441 -248
  100. package/dist/tui/App.js +761 -424
  101. package/package.json +1 -1
@@ -9,9 +9,34 @@ var __export = (target, all) => {
9
9
  __defProp(target, name, { get: all[name], enumerable: true });
10
10
  };
11
11
 
12
+ // src/lib/secure-files.ts
13
+ import { chmodSync, existsSync, mkdirSync } from "fs";
14
+ import { chmod, mkdir } from "fs/promises";
15
+ async function ensurePrivateDir(dirPath) {
16
+ await mkdir(dirPath, { recursive: true, mode: PRIVATE_DIR_MODE });
17
+ try {
18
+ await chmod(dirPath, PRIVATE_DIR_MODE);
19
+ } catch {
20
+ }
21
+ }
22
+ async function enforcePrivateFile(filePath) {
23
+ try {
24
+ await chmod(filePath, PRIVATE_FILE_MODE);
25
+ } catch {
26
+ }
27
+ }
28
+ var PRIVATE_DIR_MODE, PRIVATE_FILE_MODE;
29
+ var init_secure_files = __esm({
30
+ "src/lib/secure-files.ts"() {
31
+ "use strict";
32
+ PRIVATE_DIR_MODE = 448;
33
+ PRIVATE_FILE_MODE = 384;
34
+ }
35
+ });
36
+
12
37
  // src/lib/config.ts
13
- import { readFile, writeFile, mkdir, chmod } from "fs/promises";
14
- import { readFileSync, existsSync, renameSync } from "fs";
38
+ import { readFile, writeFile } from "fs/promises";
39
+ import { readFileSync, existsSync as existsSync2, renameSync } from "fs";
15
40
  import path from "path";
16
41
  import os from "os";
17
42
  function resolveDataDir() {
@@ -19,7 +44,7 @@ function resolveDataDir() {
19
44
  if (process.env.EXE_MEM_DIR) return process.env.EXE_MEM_DIR;
20
45
  const newDir = path.join(os.homedir(), ".exe-os");
21
46
  const legacyDir = path.join(os.homedir(), ".exe-mem");
22
- if (!existsSync(newDir) && existsSync(legacyDir)) {
47
+ if (!existsSync2(newDir) && existsSync2(legacyDir)) {
23
48
  try {
24
49
  renameSync(legacyDir, newDir);
25
50
  process.stderr.write(`[exe-os] Migrated data directory: ~/.exe-mem \u2192 ~/.exe-os
@@ -82,9 +107,9 @@ function normalizeAutoUpdate(raw) {
82
107
  }
83
108
  async function loadConfig() {
84
109
  const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
85
- await mkdir(dir, { recursive: true });
110
+ await ensurePrivateDir(dir);
86
111
  const configPath = path.join(dir, "config.json");
87
- if (!existsSync(configPath)) {
112
+ if (!existsSync2(configPath)) {
88
113
  return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
89
114
  }
90
115
  const raw = await readFile(configPath, "utf-8");
@@ -97,6 +122,7 @@ async function loadConfig() {
97
122
  `);
98
123
  try {
99
124
  await writeFile(configPath, JSON.stringify(migratedCfg, null, 2) + "\n");
125
+ await enforcePrivateFile(configPath);
100
126
  } catch {
101
127
  }
102
128
  }
@@ -116,6 +142,7 @@ var EXE_AI_DIR, DB_PATH, MODELS_DIR, CONFIG_PATH, LEGACY_LANCE_PATH, CURRENT_CON
116
142
  var init_config = __esm({
117
143
  "src/lib/config.ts"() {
118
144
  "use strict";
145
+ init_secure_files();
119
146
  EXE_AI_DIR = resolveDataDir();
120
147
  DB_PATH = path.join(EXE_AI_DIR, "memories.db");
121
148
  MODELS_DIR = path.join(EXE_AI_DIR, "models");
@@ -194,7 +221,7 @@ var init_config = __esm({
194
221
 
195
222
  // src/lib/employees.ts
196
223
  import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
197
- import { existsSync as existsSync2, symlinkSync, readlinkSync, readFileSync as readFileSync2, renameSync as renameSync2, unlinkSync, writeFileSync } from "fs";
224
+ import { existsSync as existsSync3, symlinkSync, readlinkSync, readFileSync as readFileSync2, renameSync as renameSync2, unlinkSync, writeFileSync } from "fs";
198
225
  import { execSync } from "child_process";
199
226
  import path2 from "path";
200
227
  import os2 from "os";
@@ -211,7 +238,7 @@ function getCoordinatorName(employees = loadEmployeesSync()) {
211
238
  return getCoordinatorEmployee(employees)?.name ?? DEFAULT_COORDINATOR_TEMPLATE_NAME;
212
239
  }
213
240
  async function loadEmployees(employeesPath = EMPLOYEES_PATH) {
214
- if (!existsSync2(employeesPath)) {
241
+ if (!existsSync3(employeesPath)) {
215
242
  return [];
216
243
  }
217
244
  const raw = await readFile2(employeesPath, "utf-8");
@@ -222,7 +249,7 @@ async function loadEmployees(employeesPath = EMPLOYEES_PATH) {
222
249
  }
223
250
  }
224
251
  function loadEmployeesSync(employeesPath = EMPLOYEES_PATH) {
225
- if (!existsSync2(employeesPath)) return [];
252
+ if (!existsSync3(employeesPath)) return [];
226
253
  try {
227
254
  return JSON.parse(readFileSync2(employeesPath, "utf-8"));
228
255
  } catch {
@@ -1225,6 +1252,7 @@ async function ensureSchema() {
1225
1252
  project TEXT NOT NULL,
1226
1253
  summary TEXT NOT NULL,
1227
1254
  task_file TEXT,
1255
+ session_scope TEXT,
1228
1256
  read INTEGER NOT NULL DEFAULT 0,
1229
1257
  created_at TEXT NOT NULL
1230
1258
  );
@@ -1233,7 +1261,7 @@ async function ensureSchema() {
1233
1261
  ON notifications(read);
1234
1262
 
1235
1263
  CREATE INDEX IF NOT EXISTS idx_notifications_agent
1236
- ON notifications(agent_id);
1264
+ ON notifications(agent_id, session_scope);
1237
1265
 
1238
1266
  CREATE INDEX IF NOT EXISTS idx_notifications_task_file
1239
1267
  ON notifications(task_file);
@@ -1271,6 +1299,7 @@ async function ensureSchema() {
1271
1299
  target_agent TEXT NOT NULL,
1272
1300
  target_project TEXT,
1273
1301
  target_device TEXT NOT NULL DEFAULT 'local',
1302
+ session_scope TEXT,
1274
1303
  content TEXT NOT NULL,
1275
1304
  priority TEXT DEFAULT 'normal',
1276
1305
  status TEXT DEFAULT 'pending',
@@ -1284,10 +1313,31 @@ async function ensureSchema() {
1284
1313
  );
1285
1314
 
1286
1315
  CREATE INDEX IF NOT EXISTS idx_messages_target
1287
- ON messages(target_agent, status);
1316
+ ON messages(target_agent, session_scope, status);
1288
1317
 
1289
1318
  CREATE INDEX IF NOT EXISTS idx_messages_conversation_order
1290
- ON messages(target_agent, from_agent, server_seq);
1319
+ ON messages(target_agent, session_scope, from_agent, server_seq);
1320
+ `);
1321
+ try {
1322
+ await client.execute({
1323
+ sql: `ALTER TABLE notifications ADD COLUMN session_scope TEXT`,
1324
+ args: []
1325
+ });
1326
+ } catch {
1327
+ }
1328
+ try {
1329
+ await client.execute({
1330
+ sql: `ALTER TABLE messages ADD COLUMN session_scope TEXT`,
1331
+ args: []
1332
+ });
1333
+ } catch {
1334
+ }
1335
+ await client.executeMultiple(`
1336
+ CREATE INDEX IF NOT EXISTS idx_notifications_agent_scope_read
1337
+ ON notifications(agent_id, session_scope, read, created_at);
1338
+
1339
+ CREATE INDEX IF NOT EXISTS idx_messages_target_scope_status
1340
+ ON messages(target_agent, session_scope, status, created_at);
1291
1341
  `);
1292
1342
  try {
1293
1343
  await client.execute({
@@ -1871,6 +1921,13 @@ async function ensureSchema() {
1871
1921
  } catch {
1872
1922
  }
1873
1923
  }
1924
+ try {
1925
+ await client.execute({
1926
+ sql: `UPDATE tasks SET status = 'closed' WHERE status = 'done' AND result IS NOT NULL`,
1927
+ args: []
1928
+ });
1929
+ } catch {
1930
+ }
1874
1931
  }
1875
1932
  var _client, _resilientClient, _walCheckpointTimer, _daemonClient, _adapterClient, initTurso;
1876
1933
  var init_database = __esm({
@@ -1893,6 +1950,7 @@ var shard_manager_exports = {};
1893
1950
  __export(shard_manager_exports, {
1894
1951
  disposeShards: () => disposeShards,
1895
1952
  ensureShardSchema: () => ensureShardSchema,
1953
+ getOpenShardCount: () => getOpenShardCount,
1896
1954
  getReadyShardClient: () => getReadyShardClient,
1897
1955
  getShardClient: () => getShardClient,
1898
1956
  getShardsDir: () => getShardsDir,
@@ -1902,14 +1960,17 @@ __export(shard_manager_exports, {
1902
1960
  shardExists: () => shardExists
1903
1961
  });
1904
1962
  import path5 from "path";
1905
- import { existsSync as existsSync4, mkdirSync, readdirSync } from "fs";
1963
+ import { existsSync as existsSync5, mkdirSync as mkdirSync2, readdirSync } from "fs";
1906
1964
  import { createClient as createClient2 } from "@libsql/client";
1907
1965
  function initShardManager(encryptionKey) {
1908
1966
  _encryptionKey = encryptionKey;
1909
- if (!existsSync4(SHARDS_DIR)) {
1910
- mkdirSync(SHARDS_DIR, { recursive: true });
1967
+ if (!existsSync5(SHARDS_DIR)) {
1968
+ mkdirSync2(SHARDS_DIR, { recursive: true });
1911
1969
  }
1912
1970
  _shardingEnabled = true;
1971
+ if (_evictionTimer) clearInterval(_evictionTimer);
1972
+ _evictionTimer = setInterval(evictIdleShards, EVICTION_INTERVAL_MS);
1973
+ _evictionTimer.unref();
1913
1974
  }
1914
1975
  function isShardingEnabled() {
1915
1976
  return _shardingEnabled;
@@ -1926,21 +1987,28 @@ function getShardClient(projectName) {
1926
1987
  throw new Error(`Invalid project name for shard: "${projectName}"`);
1927
1988
  }
1928
1989
  const cached = _shards.get(safeName);
1929
- if (cached) return cached;
1990
+ if (cached) {
1991
+ _shardLastAccess.set(safeName, Date.now());
1992
+ return cached;
1993
+ }
1994
+ while (_shards.size >= MAX_OPEN_SHARDS) {
1995
+ evictLRU();
1996
+ }
1930
1997
  const dbPath = path5.join(SHARDS_DIR, `${safeName}.db`);
1931
1998
  const client = createClient2({
1932
1999
  url: `file:${dbPath}`,
1933
2000
  encryptionKey: _encryptionKey
1934
2001
  });
1935
2002
  _shards.set(safeName, client);
2003
+ _shardLastAccess.set(safeName, Date.now());
1936
2004
  return client;
1937
2005
  }
1938
2006
  function shardExists(projectName) {
1939
2007
  const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
1940
- return existsSync4(path5.join(SHARDS_DIR, `${safeName}.db`));
2008
+ return existsSync5(path5.join(SHARDS_DIR, `${safeName}.db`));
1941
2009
  }
1942
2010
  function listShards() {
1943
- if (!existsSync4(SHARDS_DIR)) return [];
2011
+ if (!existsSync5(SHARDS_DIR)) return [];
1944
2012
  return readdirSync(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
1945
2013
  }
1946
2014
  async function ensureShardSchema(client) {
@@ -1992,6 +2060,8 @@ async function ensureShardSchema(client) {
1992
2060
  for (const col of [
1993
2061
  "ALTER TABLE memories ADD COLUMN task_id TEXT",
1994
2062
  "ALTER TABLE memories ADD COLUMN consolidated INTEGER NOT NULL DEFAULT 0",
2063
+ "ALTER TABLE memories ADD COLUMN author_device_id TEXT",
2064
+ "ALTER TABLE memories ADD COLUMN scope TEXT NOT NULL DEFAULT 'business'",
1995
2065
  "ALTER TABLE memories ADD COLUMN importance INTEGER DEFAULT 5",
1996
2066
  "ALTER TABLE memories ADD COLUMN status TEXT DEFAULT 'active'",
1997
2067
  "ALTER TABLE memories ADD COLUMN wiki_synced INTEGER DEFAULT 0",
@@ -2129,21 +2199,69 @@ async function getReadyShardClient(projectName) {
2129
2199
  await ensureShardSchema(client);
2130
2200
  return client;
2131
2201
  }
2202
+ function evictLRU() {
2203
+ let oldest = null;
2204
+ let oldestTime = Infinity;
2205
+ for (const [name, time] of _shardLastAccess) {
2206
+ if (time < oldestTime) {
2207
+ oldestTime = time;
2208
+ oldest = name;
2209
+ }
2210
+ }
2211
+ if (oldest) {
2212
+ const client = _shards.get(oldest);
2213
+ if (client) {
2214
+ client.close();
2215
+ }
2216
+ _shards.delete(oldest);
2217
+ _shardLastAccess.delete(oldest);
2218
+ }
2219
+ }
2220
+ function evictIdleShards() {
2221
+ const now = Date.now();
2222
+ const toEvict = [];
2223
+ for (const [name, lastAccess] of _shardLastAccess) {
2224
+ if (now - lastAccess > SHARD_IDLE_MS) {
2225
+ toEvict.push(name);
2226
+ }
2227
+ }
2228
+ for (const name of toEvict) {
2229
+ const client = _shards.get(name);
2230
+ if (client) {
2231
+ client.close();
2232
+ }
2233
+ _shards.delete(name);
2234
+ _shardLastAccess.delete(name);
2235
+ }
2236
+ }
2237
+ function getOpenShardCount() {
2238
+ return _shards.size;
2239
+ }
2132
2240
  function disposeShards() {
2241
+ if (_evictionTimer) {
2242
+ clearInterval(_evictionTimer);
2243
+ _evictionTimer = null;
2244
+ }
2133
2245
  for (const [, client] of _shards) {
2134
2246
  client.close();
2135
2247
  }
2136
2248
  _shards.clear();
2249
+ _shardLastAccess.clear();
2137
2250
  _shardingEnabled = false;
2138
2251
  _encryptionKey = null;
2139
2252
  }
2140
- var SHARDS_DIR, _shards, _encryptionKey, _shardingEnabled;
2253
+ var SHARDS_DIR, SHARD_IDLE_MS, MAX_OPEN_SHARDS, EVICTION_INTERVAL_MS, _shards, _shardLastAccess, _evictionTimer, _encryptionKey, _shardingEnabled;
2141
2254
  var init_shard_manager = __esm({
2142
2255
  "src/lib/shard-manager.ts"() {
2143
2256
  "use strict";
2144
2257
  init_config();
2145
2258
  SHARDS_DIR = path5.join(EXE_AI_DIR, "shards");
2259
+ SHARD_IDLE_MS = 5 * 60 * 1e3;
2260
+ MAX_OPEN_SHARDS = 10;
2261
+ EVICTION_INTERVAL_MS = 60 * 1e3;
2146
2262
  _shards = /* @__PURE__ */ new Map();
2263
+ _shardLastAccess = /* @__PURE__ */ new Map();
2264
+ _evictionTimer = null;
2147
2265
  _encryptionKey = null;
2148
2266
  _shardingEnabled = false;
2149
2267
  }
@@ -2351,7 +2469,7 @@ init_database();
2351
2469
 
2352
2470
  // src/lib/keychain.ts
2353
2471
  import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
2354
- import { existsSync as existsSync3 } from "fs";
2472
+ import { existsSync as existsSync4 } from "fs";
2355
2473
  import path4 from "path";
2356
2474
  import os4 from "os";
2357
2475
  var SERVICE = "exe-mem";
@@ -2381,7 +2499,7 @@ async function getMasterKey() {
2381
2499
  }
2382
2500
  }
2383
2501
  const keyPath = getKeyPath();
2384
- if (!existsSync3(keyPath)) {
2502
+ if (!existsSync4(keyPath)) {
2385
2503
  process.stderr.write(
2386
2504
  `[keychain] Key not found at ${keyPath} (HOME=${os4.homedir()}, EXE_OS_DIR=${process.env.EXE_OS_DIR ?? "unset"})
2387
2505
  `