@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 {
@@ -1222,6 +1249,7 @@ async function ensureSchema() {
1222
1249
  project TEXT NOT NULL,
1223
1250
  summary TEXT NOT NULL,
1224
1251
  task_file TEXT,
1252
+ session_scope TEXT,
1225
1253
  read INTEGER NOT NULL DEFAULT 0,
1226
1254
  created_at TEXT NOT NULL
1227
1255
  );
@@ -1230,7 +1258,7 @@ async function ensureSchema() {
1230
1258
  ON notifications(read);
1231
1259
 
1232
1260
  CREATE INDEX IF NOT EXISTS idx_notifications_agent
1233
- ON notifications(agent_id);
1261
+ ON notifications(agent_id, session_scope);
1234
1262
 
1235
1263
  CREATE INDEX IF NOT EXISTS idx_notifications_task_file
1236
1264
  ON notifications(task_file);
@@ -1268,6 +1296,7 @@ async function ensureSchema() {
1268
1296
  target_agent TEXT NOT NULL,
1269
1297
  target_project TEXT,
1270
1298
  target_device TEXT NOT NULL DEFAULT 'local',
1299
+ session_scope TEXT,
1271
1300
  content TEXT NOT NULL,
1272
1301
  priority TEXT DEFAULT 'normal',
1273
1302
  status TEXT DEFAULT 'pending',
@@ -1281,10 +1310,31 @@ async function ensureSchema() {
1281
1310
  );
1282
1311
 
1283
1312
  CREATE INDEX IF NOT EXISTS idx_messages_target
1284
- ON messages(target_agent, status);
1313
+ ON messages(target_agent, session_scope, status);
1285
1314
 
1286
1315
  CREATE INDEX IF NOT EXISTS idx_messages_conversation_order
1287
- ON messages(target_agent, from_agent, server_seq);
1316
+ ON messages(target_agent, session_scope, from_agent, server_seq);
1317
+ `);
1318
+ try {
1319
+ await client.execute({
1320
+ sql: `ALTER TABLE notifications ADD COLUMN session_scope TEXT`,
1321
+ args: []
1322
+ });
1323
+ } catch {
1324
+ }
1325
+ try {
1326
+ await client.execute({
1327
+ sql: `ALTER TABLE messages ADD COLUMN session_scope TEXT`,
1328
+ args: []
1329
+ });
1330
+ } catch {
1331
+ }
1332
+ await client.executeMultiple(`
1333
+ CREATE INDEX IF NOT EXISTS idx_notifications_agent_scope_read
1334
+ ON notifications(agent_id, session_scope, read, created_at);
1335
+
1336
+ CREATE INDEX IF NOT EXISTS idx_messages_target_scope_status
1337
+ ON messages(target_agent, session_scope, status, created_at);
1288
1338
  `);
1289
1339
  try {
1290
1340
  await client.execute({
@@ -1868,6 +1918,13 @@ async function ensureSchema() {
1868
1918
  } catch {
1869
1919
  }
1870
1920
  }
1921
+ try {
1922
+ await client.execute({
1923
+ sql: `UPDATE tasks SET status = 'closed' WHERE status = 'done' AND result IS NOT NULL`,
1924
+ args: []
1925
+ });
1926
+ } catch {
1927
+ }
1871
1928
  }
1872
1929
  var _client, _resilientClient, _walCheckpointTimer, _daemonClient, _adapterClient, initTurso;
1873
1930
  var init_database = __esm({
@@ -1890,6 +1947,7 @@ var shard_manager_exports = {};
1890
1947
  __export(shard_manager_exports, {
1891
1948
  disposeShards: () => disposeShards,
1892
1949
  ensureShardSchema: () => ensureShardSchema,
1950
+ getOpenShardCount: () => getOpenShardCount,
1893
1951
  getReadyShardClient: () => getReadyShardClient,
1894
1952
  getShardClient: () => getShardClient,
1895
1953
  getShardsDir: () => getShardsDir,
@@ -1899,14 +1957,17 @@ __export(shard_manager_exports, {
1899
1957
  shardExists: () => shardExists
1900
1958
  });
1901
1959
  import path5 from "path";
1902
- import { existsSync as existsSync4, mkdirSync, readdirSync } from "fs";
1960
+ import { existsSync as existsSync5, mkdirSync as mkdirSync2, readdirSync } from "fs";
1903
1961
  import { createClient as createClient2 } from "@libsql/client";
1904
1962
  function initShardManager(encryptionKey) {
1905
1963
  _encryptionKey = encryptionKey;
1906
- if (!existsSync4(SHARDS_DIR)) {
1907
- mkdirSync(SHARDS_DIR, { recursive: true });
1964
+ if (!existsSync5(SHARDS_DIR)) {
1965
+ mkdirSync2(SHARDS_DIR, { recursive: true });
1908
1966
  }
1909
1967
  _shardingEnabled = true;
1968
+ if (_evictionTimer) clearInterval(_evictionTimer);
1969
+ _evictionTimer = setInterval(evictIdleShards, EVICTION_INTERVAL_MS);
1970
+ _evictionTimer.unref();
1910
1971
  }
1911
1972
  function isShardingEnabled() {
1912
1973
  return _shardingEnabled;
@@ -1923,21 +1984,28 @@ function getShardClient(projectName) {
1923
1984
  throw new Error(`Invalid project name for shard: "${projectName}"`);
1924
1985
  }
1925
1986
  const cached = _shards.get(safeName);
1926
- if (cached) return cached;
1987
+ if (cached) {
1988
+ _shardLastAccess.set(safeName, Date.now());
1989
+ return cached;
1990
+ }
1991
+ while (_shards.size >= MAX_OPEN_SHARDS) {
1992
+ evictLRU();
1993
+ }
1927
1994
  const dbPath = path5.join(SHARDS_DIR, `${safeName}.db`);
1928
1995
  const client = createClient2({
1929
1996
  url: `file:${dbPath}`,
1930
1997
  encryptionKey: _encryptionKey
1931
1998
  });
1932
1999
  _shards.set(safeName, client);
2000
+ _shardLastAccess.set(safeName, Date.now());
1933
2001
  return client;
1934
2002
  }
1935
2003
  function shardExists(projectName) {
1936
2004
  const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
1937
- return existsSync4(path5.join(SHARDS_DIR, `${safeName}.db`));
2005
+ return existsSync5(path5.join(SHARDS_DIR, `${safeName}.db`));
1938
2006
  }
1939
2007
  function listShards() {
1940
- if (!existsSync4(SHARDS_DIR)) return [];
2008
+ if (!existsSync5(SHARDS_DIR)) return [];
1941
2009
  return readdirSync(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
1942
2010
  }
1943
2011
  async function ensureShardSchema(client) {
@@ -1989,6 +2057,8 @@ async function ensureShardSchema(client) {
1989
2057
  for (const col of [
1990
2058
  "ALTER TABLE memories ADD COLUMN task_id TEXT",
1991
2059
  "ALTER TABLE memories ADD COLUMN consolidated INTEGER NOT NULL DEFAULT 0",
2060
+ "ALTER TABLE memories ADD COLUMN author_device_id TEXT",
2061
+ "ALTER TABLE memories ADD COLUMN scope TEXT NOT NULL DEFAULT 'business'",
1992
2062
  "ALTER TABLE memories ADD COLUMN importance INTEGER DEFAULT 5",
1993
2063
  "ALTER TABLE memories ADD COLUMN status TEXT DEFAULT 'active'",
1994
2064
  "ALTER TABLE memories ADD COLUMN wiki_synced INTEGER DEFAULT 0",
@@ -2126,21 +2196,69 @@ async function getReadyShardClient(projectName) {
2126
2196
  await ensureShardSchema(client);
2127
2197
  return client;
2128
2198
  }
2199
+ function evictLRU() {
2200
+ let oldest = null;
2201
+ let oldestTime = Infinity;
2202
+ for (const [name, time] of _shardLastAccess) {
2203
+ if (time < oldestTime) {
2204
+ oldestTime = time;
2205
+ oldest = name;
2206
+ }
2207
+ }
2208
+ if (oldest) {
2209
+ const client = _shards.get(oldest);
2210
+ if (client) {
2211
+ client.close();
2212
+ }
2213
+ _shards.delete(oldest);
2214
+ _shardLastAccess.delete(oldest);
2215
+ }
2216
+ }
2217
+ function evictIdleShards() {
2218
+ const now = Date.now();
2219
+ const toEvict = [];
2220
+ for (const [name, lastAccess] of _shardLastAccess) {
2221
+ if (now - lastAccess > SHARD_IDLE_MS) {
2222
+ toEvict.push(name);
2223
+ }
2224
+ }
2225
+ for (const name of toEvict) {
2226
+ const client = _shards.get(name);
2227
+ if (client) {
2228
+ client.close();
2229
+ }
2230
+ _shards.delete(name);
2231
+ _shardLastAccess.delete(name);
2232
+ }
2233
+ }
2234
+ function getOpenShardCount() {
2235
+ return _shards.size;
2236
+ }
2129
2237
  function disposeShards() {
2238
+ if (_evictionTimer) {
2239
+ clearInterval(_evictionTimer);
2240
+ _evictionTimer = null;
2241
+ }
2130
2242
  for (const [, client] of _shards) {
2131
2243
  client.close();
2132
2244
  }
2133
2245
  _shards.clear();
2246
+ _shardLastAccess.clear();
2134
2247
  _shardingEnabled = false;
2135
2248
  _encryptionKey = null;
2136
2249
  }
2137
- var SHARDS_DIR, _shards, _encryptionKey, _shardingEnabled;
2250
+ var SHARDS_DIR, SHARD_IDLE_MS, MAX_OPEN_SHARDS, EVICTION_INTERVAL_MS, _shards, _shardLastAccess, _evictionTimer, _encryptionKey, _shardingEnabled;
2138
2251
  var init_shard_manager = __esm({
2139
2252
  "src/lib/shard-manager.ts"() {
2140
2253
  "use strict";
2141
2254
  init_config();
2142
2255
  SHARDS_DIR = path5.join(EXE_AI_DIR, "shards");
2256
+ SHARD_IDLE_MS = 5 * 60 * 1e3;
2257
+ MAX_OPEN_SHARDS = 10;
2258
+ EVICTION_INTERVAL_MS = 60 * 1e3;
2143
2259
  _shards = /* @__PURE__ */ new Map();
2260
+ _shardLastAccess = /* @__PURE__ */ new Map();
2261
+ _evictionTimer = null;
2144
2262
  _encryptionKey = null;
2145
2263
  _shardingEnabled = false;
2146
2264
  }
@@ -2342,7 +2460,7 @@ init_database();
2342
2460
 
2343
2461
  // src/lib/keychain.ts
2344
2462
  import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
2345
- import { existsSync as existsSync3 } from "fs";
2463
+ import { existsSync as existsSync4 } from "fs";
2346
2464
  import path4 from "path";
2347
2465
  import os4 from "os";
2348
2466
  var SERVICE = "exe-mem";
@@ -2372,7 +2490,7 @@ async function getMasterKey() {
2372
2490
  }
2373
2491
  }
2374
2492
  const keyPath = getKeyPath();
2375
- if (!existsSync3(keyPath)) {
2493
+ if (!existsSync4(keyPath)) {
2376
2494
  process.stderr.write(
2377
2495
  `[keychain] Key not found at ${keyPath} (HOME=${os4.homedir()}, EXE_OS_DIR=${process.env.EXE_OS_DIR ?? "unset"})
2378
2496
  `