@askexenow/exe-os 0.8.0 → 0.8.2

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 (107) hide show
  1. package/README.md +178 -79
  2. package/package.json +1 -1
  3. package/dist/bin/backfill-responses.js +0 -1912
  4. package/dist/bin/backfill-vectors.js +0 -1642
  5. package/dist/bin/cleanup-stale-review-tasks.js +0 -1339
  6. package/dist/bin/cli.js +0 -18800
  7. package/dist/bin/exe-agent.js +0 -1858
  8. package/dist/bin/exe-assign.js +0 -1957
  9. package/dist/bin/exe-boot.js +0 -6460
  10. package/dist/bin/exe-call.js +0 -197
  11. package/dist/bin/exe-cloud.js +0 -850
  12. package/dist/bin/exe-dispatch.js +0 -1146
  13. package/dist/bin/exe-doctor.js +0 -1657
  14. package/dist/bin/exe-export-behaviors.js +0 -1494
  15. package/dist/bin/exe-forget.js +0 -1627
  16. package/dist/bin/exe-gateway.js +0 -7732
  17. package/dist/bin/exe-healthcheck.js +0 -207
  18. package/dist/bin/exe-heartbeat.js +0 -1647
  19. package/dist/bin/exe-kill.js +0 -1479
  20. package/dist/bin/exe-launch-agent.js +0 -1704
  21. package/dist/bin/exe-link.js +0 -192
  22. package/dist/bin/exe-new-employee.js +0 -852
  23. package/dist/bin/exe-pending-messages.js +0 -1446
  24. package/dist/bin/exe-pending-notifications.js +0 -1321
  25. package/dist/bin/exe-pending-reviews.js +0 -1468
  26. package/dist/bin/exe-repo-drift.js +0 -95
  27. package/dist/bin/exe-review.js +0 -1590
  28. package/dist/bin/exe-search.js +0 -2651
  29. package/dist/bin/exe-session-cleanup.js +0 -3173
  30. package/dist/bin/exe-settings.js +0 -354
  31. package/dist/bin/exe-status.js +0 -1532
  32. package/dist/bin/exe-team.js +0 -1324
  33. package/dist/bin/git-sweep.js +0 -2185
  34. package/dist/bin/graph-backfill.js +0 -1968
  35. package/dist/bin/graph-export.js +0 -1604
  36. package/dist/bin/install.js +0 -656
  37. package/dist/bin/list-providers.js +0 -140
  38. package/dist/bin/scan-tasks.js +0 -1820
  39. package/dist/bin/setup.js +0 -951
  40. package/dist/bin/shard-migrate.js +0 -1494
  41. package/dist/bin/update.js +0 -95
  42. package/dist/bin/wiki-sync.js +0 -1514
  43. package/dist/gateway/index.js +0 -8848
  44. package/dist/hooks/bug-report-worker.js +0 -2743
  45. package/dist/hooks/commit-complete.js +0 -2108
  46. package/dist/hooks/error-recall.js +0 -2861
  47. package/dist/hooks/exe-heartbeat-hook.js +0 -232
  48. package/dist/hooks/ingest-worker.js +0 -4793
  49. package/dist/hooks/ingest.js +0 -684
  50. package/dist/hooks/instructions-loaded.js +0 -1880
  51. package/dist/hooks/notification.js +0 -1726
  52. package/dist/hooks/post-compact.js +0 -1751
  53. package/dist/hooks/pre-compact.js +0 -1746
  54. package/dist/hooks/pre-tool-use.js +0 -2191
  55. package/dist/hooks/prompt-ingest-worker.js +0 -2126
  56. package/dist/hooks/prompt-submit.js +0 -4693
  57. package/dist/hooks/response-ingest-worker.js +0 -1936
  58. package/dist/hooks/session-end.js +0 -1752
  59. package/dist/hooks/session-start.js +0 -2795
  60. package/dist/hooks/stop.js +0 -1835
  61. package/dist/hooks/subagent-stop.js +0 -1726
  62. package/dist/hooks/summary-worker.js +0 -2661
  63. package/dist/index.js +0 -11834
  64. package/dist/lib/cloud-sync.js +0 -495
  65. package/dist/lib/config.js +0 -222
  66. package/dist/lib/consolidation.js +0 -476
  67. package/dist/lib/crypto.js +0 -51
  68. package/dist/lib/database.js +0 -730
  69. package/dist/lib/device-registry.js +0 -900
  70. package/dist/lib/embedder.js +0 -632
  71. package/dist/lib/employee-templates.js +0 -543
  72. package/dist/lib/employees.js +0 -177
  73. package/dist/lib/error-detector.js +0 -156
  74. package/dist/lib/exe-daemon-client.js +0 -451
  75. package/dist/lib/exe-daemon.js +0 -8285
  76. package/dist/lib/file-grep.js +0 -199
  77. package/dist/lib/hybrid-search.js +0 -1819
  78. package/dist/lib/identity-templates.js +0 -320
  79. package/dist/lib/identity.js +0 -223
  80. package/dist/lib/keychain.js +0 -145
  81. package/dist/lib/license.js +0 -377
  82. package/dist/lib/messaging.js +0 -1376
  83. package/dist/lib/reminders.js +0 -63
  84. package/dist/lib/schedules.js +0 -1396
  85. package/dist/lib/session-registry.js +0 -52
  86. package/dist/lib/skill-learning.js +0 -477
  87. package/dist/lib/status-brief.js +0 -235
  88. package/dist/lib/store.js +0 -1551
  89. package/dist/lib/task-router.js +0 -62
  90. package/dist/lib/tasks.js +0 -2456
  91. package/dist/lib/tmux-routing.js +0 -2836
  92. package/dist/lib/tmux-status.js +0 -261
  93. package/dist/lib/tmux-transport.js +0 -83
  94. package/dist/lib/transport.js +0 -128
  95. package/dist/lib/ws-auth.js +0 -19
  96. package/dist/lib/ws-client.js +0 -160
  97. package/dist/mcp/server.js +0 -10538
  98. package/dist/mcp/tools/complete-reminder.js +0 -67
  99. package/dist/mcp/tools/create-reminder.js +0 -52
  100. package/dist/mcp/tools/create-task.js +0 -1853
  101. package/dist/mcp/tools/deactivate-behavior.js +0 -263
  102. package/dist/mcp/tools/list-reminders.js +0 -62
  103. package/dist/mcp/tools/list-tasks.js +0 -463
  104. package/dist/mcp/tools/send-message.js +0 -1382
  105. package/dist/mcp/tools/update-task.js +0 -1692
  106. package/dist/runtime/index.js +0 -6809
  107. package/dist/tui/App.js +0 -17479
@@ -1,495 +0,0 @@
1
- // src/lib/database.ts
2
- import { createClient } from "@libsql/client";
3
- var _client = null;
4
- function getClient() {
5
- if (!_client) {
6
- throw new Error("Database client not initialized. Call initDatabase() first.");
7
- }
8
- return _client;
9
- }
10
-
11
- // src/lib/crypto.ts
12
- import crypto from "crypto";
13
- var ALGORITHM = "aes-256-gcm";
14
- var IV_LENGTH = 12;
15
- var TAG_LENGTH = 16;
16
- var _syncKey = null;
17
- function requireSyncKey() {
18
- if (!_syncKey) {
19
- throw new Error("Sync crypto not initialized. Call initSyncCrypto(masterKey) first.");
20
- }
21
- return _syncKey;
22
- }
23
- function encryptSyncBlob(data) {
24
- const key = requireSyncKey();
25
- const iv = crypto.randomBytes(IV_LENGTH);
26
- const cipher = crypto.createCipheriv(ALGORITHM, key, iv);
27
- const encrypted = Buffer.concat([cipher.update(data), cipher.final()]);
28
- const tag = cipher.getAuthTag();
29
- return Buffer.concat([iv, encrypted, tag]).toString("base64");
30
- }
31
- function decryptSyncBlob(ciphertext) {
32
- const key = requireSyncKey();
33
- const combined = Buffer.from(ciphertext, "base64");
34
- if (combined.length < IV_LENGTH + TAG_LENGTH) {
35
- throw new Error("Sync blob too short to contain IV + tag");
36
- }
37
- const iv = combined.subarray(0, IV_LENGTH);
38
- const tag = combined.subarray(combined.length - TAG_LENGTH);
39
- const encrypted = combined.subarray(IV_LENGTH, combined.length - TAG_LENGTH);
40
- const decipher = crypto.createDecipheriv(ALGORITHM, key, iv);
41
- decipher.setAuthTag(tag);
42
- return Buffer.concat([decipher.update(encrypted), decipher.final()]);
43
- }
44
-
45
- // src/lib/compress.ts
46
- import { brotliCompressSync, brotliDecompressSync, constants } from "zlib";
47
- function compress(input) {
48
- if (input.length === 0) return Buffer.alloc(0);
49
- return brotliCompressSync(input, {
50
- params: {
51
- [constants.BROTLI_PARAM_QUALITY]: 4
52
- }
53
- });
54
- }
55
- function decompress(input) {
56
- if (input.length === 0) return Buffer.alloc(0);
57
- return brotliDecompressSync(input);
58
- }
59
-
60
- // src/lib/plan-limits.ts
61
- import { readFileSync as readFileSync3, existsSync as existsSync4 } from "fs";
62
- import path4 from "path";
63
-
64
- // src/lib/employees.ts
65
- import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
66
- import { existsSync as existsSync2, symlinkSync, readlinkSync } from "fs";
67
- import { execSync } from "child_process";
68
- import path2 from "path";
69
-
70
- // src/lib/config.ts
71
- import { readFile, writeFile, mkdir } from "fs/promises";
72
- import { readFileSync, existsSync, renameSync } from "fs";
73
- import path from "path";
74
- import os from "os";
75
- function resolveDataDir() {
76
- if (process.env.EXE_OS_DIR) return process.env.EXE_OS_DIR;
77
- if (process.env.EXE_MEM_DIR) return process.env.EXE_MEM_DIR;
78
- const newDir = path.join(os.homedir(), ".exe-os");
79
- const legacyDir = path.join(os.homedir(), ".exe-mem");
80
- if (!existsSync(newDir) && existsSync(legacyDir)) {
81
- try {
82
- renameSync(legacyDir, newDir);
83
- process.stderr.write(`[exe-os] Migrated data directory: ~/.exe-mem \u2192 ~/.exe-os
84
- `);
85
- } catch {
86
- return legacyDir;
87
- }
88
- }
89
- return newDir;
90
- }
91
- var EXE_AI_DIR = resolveDataDir();
92
- var DB_PATH = path.join(EXE_AI_DIR, "memories.db");
93
- var MODELS_DIR = path.join(EXE_AI_DIR, "models");
94
- var CONFIG_PATH = path.join(EXE_AI_DIR, "config.json");
95
- var LEGACY_LANCE_PATH = path.join(EXE_AI_DIR, "local.lance");
96
- var CURRENT_CONFIG_VERSION = 1;
97
- var DEFAULT_CONFIG = {
98
- config_version: CURRENT_CONFIG_VERSION,
99
- dbPath: DB_PATH,
100
- modelFile: "jina-embeddings-v5-small-q4_k_m.gguf",
101
- embeddingDim: 1024,
102
- batchSize: 20,
103
- flushIntervalMs: 1e4,
104
- autoIngestion: true,
105
- autoRetrieval: true,
106
- searchMode: "hybrid",
107
- hookSearchMode: "hybrid",
108
- fileGrepEnabled: true,
109
- splashEffect: true,
110
- consolidationEnabled: true,
111
- consolidationIntervalMs: 6 * 60 * 60 * 1e3,
112
- consolidationModel: "claude-haiku-4-5-20251001",
113
- consolidationMaxCallsPerRun: 20,
114
- selfQueryRouter: true,
115
- selfQueryModel: "claude-haiku-4-5-20251001",
116
- rerankerEnabled: true,
117
- scalingRoadmap: {
118
- rerankerAutoTrigger: {
119
- enabled: true,
120
- broadQueryMinCardinality: 5e4,
121
- fetchTopK: 150,
122
- returnTopK: 5
123
- }
124
- },
125
- graphRagEnabled: true,
126
- wikiEnabled: false,
127
- wikiUrl: "",
128
- wikiApiKey: "",
129
- wikiSyncIntervalMs: 30 * 60 * 1e3,
130
- wikiWorkspaceMapping: {
131
- exe: "Executive",
132
- yoshi: "Engineering",
133
- mari: "Marketing",
134
- tom: "Engineering",
135
- sasha: "Production"
136
- },
137
- wikiAutoUpdate: true,
138
- wikiAutoUpdateThreshold: 0.5,
139
- wikiAutoUpdateCreateNew: true,
140
- skillLearning: true,
141
- skillThreshold: 3,
142
- skillModel: "claude-haiku-4-5-20251001",
143
- exeHeartbeat: {
144
- enabled: true,
145
- intervalSeconds: 60,
146
- staleInProgressThresholdHours: 2
147
- },
148
- sessionLifecycle: {
149
- idleKillEnabled: true,
150
- idleKillTicksRequired: 3,
151
- idleKillIntercomAckWindowMs: 1e4,
152
- maxAutoInstances: 10
153
- }
154
- };
155
-
156
- // src/lib/employees.ts
157
- var EMPLOYEES_PATH = path2.join(EXE_AI_DIR, "exe-employees.json");
158
-
159
- // src/lib/license.ts
160
- import { readFileSync as readFileSync2, writeFileSync, existsSync as existsSync3, mkdirSync } from "fs";
161
- import { randomUUID } from "crypto";
162
- import path3 from "path";
163
- import { jwtVerify, importSPKI } from "jose";
164
- var LICENSE_PATH = path3.join(EXE_AI_DIR, "license.key");
165
- var CACHE_PATH = path3.join(EXE_AI_DIR, "license-cache.json");
166
- var DEVICE_ID_PATH = path3.join(EXE_AI_DIR, "device-id");
167
- var API_BASE = "https://askexe.com/cloud";
168
- var LICENSE_PUBLIC_KEY_PEM = `-----BEGIN PUBLIC KEY-----
169
- MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEeHztAMOpR/ZMh+rWuOASjEZ54CGY
170
- 4uj+UqeKCcvtgNHKmOK278HJaJcANe9xAeji8AFYu27q3WtzCi04pHudow==
171
- -----END PUBLIC KEY-----`;
172
- var LICENSE_JWT_ALG = "ES256";
173
- var PLAN_LIMITS = {
174
- free: { devices: 1, employees: 1, memories: 5e3 },
175
- pro: { devices: 2, employees: 5, memories: 1e5 },
176
- team: { devices: 10, employees: 20, memories: 1e6 },
177
- agency: { devices: 50, employees: 100, memories: 1e7 },
178
- enterprise: { devices: -1, employees: -1, memories: -1 }
179
- };
180
- var FREE_LICENSE = {
181
- valid: true,
182
- plan: "free",
183
- email: "",
184
- expiresAt: null,
185
- deviceLimit: 1,
186
- employeeLimit: 1,
187
- memoryLimit: 5e3
188
- };
189
- function loadDeviceId() {
190
- const deviceJsonPath = path3.join(EXE_AI_DIR, "device.json");
191
- try {
192
- if (existsSync3(deviceJsonPath)) {
193
- const data = JSON.parse(readFileSync2(deviceJsonPath, "utf8"));
194
- if (data.deviceId) return data.deviceId;
195
- }
196
- } catch {
197
- }
198
- try {
199
- if (existsSync3(DEVICE_ID_PATH)) {
200
- const id2 = readFileSync2(DEVICE_ID_PATH, "utf8").trim();
201
- if (id2) return id2;
202
- }
203
- } catch {
204
- }
205
- const id = randomUUID();
206
- mkdirSync(EXE_AI_DIR, { recursive: true });
207
- writeFileSync(DEVICE_ID_PATH, id, "utf8");
208
- return id;
209
- }
210
- function loadLicense() {
211
- try {
212
- if (!existsSync3(LICENSE_PATH)) return null;
213
- return readFileSync2(LICENSE_PATH, "utf8").trim();
214
- } catch {
215
- return null;
216
- }
217
- }
218
- async function verifyLicenseJwt(token) {
219
- try {
220
- const key = await importSPKI(LICENSE_PUBLIC_KEY_PEM, LICENSE_JWT_ALG);
221
- const { payload } = await jwtVerify(token, key, {
222
- algorithms: [LICENSE_JWT_ALG]
223
- });
224
- const plan = payload.plan ?? "free";
225
- const email = payload.sub ?? "";
226
- const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
227
- return {
228
- valid: true,
229
- plan,
230
- email,
231
- expiresAt: payload.exp ? new Date(payload.exp * 1e3).toISOString() : null,
232
- deviceLimit: limits.devices,
233
- employeeLimit: limits.employees,
234
- memoryLimit: limits.memories
235
- };
236
- } catch {
237
- return null;
238
- }
239
- }
240
- async function getCachedLicense() {
241
- try {
242
- if (!existsSync3(CACHE_PATH)) return null;
243
- const raw = JSON.parse(readFileSync2(CACHE_PATH, "utf8"));
244
- if (!raw.token || typeof raw.token !== "string") return null;
245
- return await verifyLicenseJwt(raw.token);
246
- } catch {
247
- return null;
248
- }
249
- }
250
- function cacheResponse(token) {
251
- try {
252
- writeFileSync(CACHE_PATH, JSON.stringify({ token }), "utf8");
253
- } catch {
254
- }
255
- }
256
- async function validateLicense(apiKey, deviceId) {
257
- const did = deviceId ?? loadDeviceId();
258
- try {
259
- const res = await fetch(`${API_BASE}/auth/activate`, {
260
- method: "POST",
261
- headers: { "Content-Type": "application/json" },
262
- body: JSON.stringify({ apiKey, deviceId: did }),
263
- signal: AbortSignal.timeout(1e4)
264
- });
265
- if (res.ok) {
266
- const data = await res.json();
267
- if (data.error === "device_limit_exceeded") {
268
- const cached2 = await getCachedLicense();
269
- if (cached2) return cached2;
270
- return { ...FREE_LICENSE, valid: false, plan: "free" };
271
- }
272
- if (data.token) {
273
- cacheResponse(data.token);
274
- const verified = await verifyLicenseJwt(data.token);
275
- if (verified) return verified;
276
- }
277
- const limits = PLAN_LIMITS[data.plan] ?? PLAN_LIMITS.free;
278
- return {
279
- valid: data.valid,
280
- plan: data.plan,
281
- email: data.email,
282
- expiresAt: data.expiresAt,
283
- deviceLimit: limits.devices,
284
- employeeLimit: limits.employees,
285
- memoryLimit: limits.memories
286
- };
287
- }
288
- const cached = await getCachedLicense();
289
- if (cached) return cached;
290
- return { ...FREE_LICENSE, valid: false, plan: "free" };
291
- } catch {
292
- const cached = await getCachedLicense();
293
- if (cached) return cached;
294
- return FREE_LICENSE;
295
- }
296
- }
297
- async function checkLicense() {
298
- const key = loadLicense();
299
- if (!key) return FREE_LICENSE;
300
- const cached = await getCachedLicense();
301
- if (cached) return cached;
302
- const deviceId = loadDeviceId();
303
- return validateLicense(key, deviceId);
304
- }
305
- function isFeatureAllowed(license, feature) {
306
- switch (feature) {
307
- case "cloud_sync":
308
- case "external_agents":
309
- case "wiki":
310
- return license.plan !== "free";
311
- case "unlimited_employees":
312
- return license.plan === "team" || license.plan === "agency" || license.plan === "enterprise";
313
- }
314
- }
315
-
316
- // src/lib/plan-limits.ts
317
- var PlanLimitError = class extends Error {
318
- constructor(message) {
319
- super(message);
320
- this.name = "PlanLimitError";
321
- }
322
- };
323
- var CACHE_PATH2 = path4.join(EXE_AI_DIR, "license-cache.json");
324
- async function assertFeature(feature) {
325
- const license = await checkLicense();
326
- if (!isFeatureAllowed(license, feature)) {
327
- throw new PlanLimitError(
328
- `Feature "${feature}" requires a paid plan. Current plan: ${license.plan}. Upgrade at https://askexe.com.`
329
- );
330
- }
331
- }
332
-
333
- // src/lib/cloud-sync.ts
334
- var LOCALHOST_PATTERNS = /^(localhost|127\.0\.0\.1|\[::1\])$/i;
335
- function assertSecureEndpoint(endpoint) {
336
- if (endpoint.startsWith("https://")) return;
337
- if (endpoint.startsWith("http://")) {
338
- try {
339
- const parsed = new URL(endpoint);
340
- if (LOCALHOST_PATTERNS.test(parsed.hostname)) return;
341
- } catch {
342
- return;
343
- }
344
- throw new Error(
345
- `Insecure cloud endpoint rejected: "${endpoint}". Use https:// for remote hosts. Plain http:// is only allowed for localhost.`
346
- );
347
- }
348
- }
349
- async function cloudPush(records, maxVersion, config) {
350
- if (records.length === 0) return true;
351
- assertSecureEndpoint(config.endpoint);
352
- try {
353
- const json = JSON.stringify(records);
354
- const compressed = compress(Buffer.from(json, "utf8"));
355
- const blob = encryptSyncBlob(compressed);
356
- const resp = await fetch(`${config.endpoint}/sync/push`, {
357
- method: "POST",
358
- headers: {
359
- Authorization: `Bearer ${config.apiKey}`,
360
- "Content-Type": "application/json",
361
- "X-Device-Id": loadDeviceId()
362
- },
363
- body: JSON.stringify({ version: maxVersion, blob })
364
- });
365
- return resp.ok;
366
- } catch (err) {
367
- process.stderr.write(`[cloud-sync] PUSH FAILED: ${err instanceof Error ? err.message : String(err)}
368
- `);
369
- return false;
370
- }
371
- }
372
- async function cloudPull(sinceVersion, config) {
373
- assertSecureEndpoint(config.endpoint);
374
- try {
375
- const response = await fetch(`${config.endpoint}/sync/pull`, {
376
- method: "POST",
377
- headers: {
378
- Authorization: `Bearer ${config.apiKey}`,
379
- "Content-Type": "application/json",
380
- "X-Device-Id": loadDeviceId()
381
- },
382
- body: JSON.stringify({ since_version: sinceVersion })
383
- });
384
- if (!response.ok) return { records: [], maxVersion: sinceVersion };
385
- const data = await response.json();
386
- const allRecords = [];
387
- for (const { blob } of data.blobs ?? []) {
388
- try {
389
- const compressed = decryptSyncBlob(blob);
390
- const json = decompress(compressed).toString("utf8");
391
- const records = JSON.parse(json);
392
- allRecords.push(...records);
393
- } catch {
394
- continue;
395
- }
396
- }
397
- return { records: allRecords, maxVersion: data.max_version ?? sinceVersion };
398
- } catch (err) {
399
- process.stderr.write(`[cloud-sync] PULL FAILED: ${err instanceof Error ? err.message : String(err)}
400
- `);
401
- return { records: [], maxVersion: sinceVersion };
402
- }
403
- }
404
- async function cloudSync(config) {
405
- await assertFeature("cloud_sync");
406
- let client;
407
- try {
408
- client = getClient();
409
- } catch {
410
- throw new Error("[cloud-sync] Database not initialized. Call initStore() before cloudSync().");
411
- }
412
- const pullMeta = await client.execute(
413
- "SELECT value FROM sync_meta WHERE key = 'last_cloud_pull_version'"
414
- );
415
- const lastPullVersion = pullMeta.rows.length > 0 ? Number(pullMeta.rows[0].value) : 0;
416
- const pullResult = await cloudPull(lastPullVersion, config);
417
- let pulled = 0;
418
- if (pullResult.records.length > 0) {
419
- const stmts = pullResult.records.map((rec) => ({
420
- sql: `INSERT OR REPLACE INTO memories
421
- (id, agent_id, agent_role, session_id, timestamp,
422
- tool_name, project_name, has_error, raw_text, version,
423
- author_device_id, scope)
424
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
425
- args: [
426
- rec.id,
427
- rec.agent_id,
428
- rec.agent_role,
429
- rec.session_id,
430
- rec.timestamp,
431
- rec.tool_name,
432
- rec.project_name,
433
- rec.has_error,
434
- rec.raw_text,
435
- rec.version,
436
- rec.author_device_id ?? null,
437
- rec.scope ?? "business"
438
- ]
439
- }));
440
- await client.batch(stmts, "write");
441
- pulled = pullResult.records.length;
442
- }
443
- if (pullResult.maxVersion > lastPullVersion) {
444
- await client.execute({
445
- sql: "INSERT OR REPLACE INTO sync_meta (key, value) VALUES ('last_cloud_pull_version', ?)",
446
- args: [String(pullResult.maxVersion)]
447
- });
448
- }
449
- const pushMeta = await client.execute(
450
- "SELECT value FROM sync_meta WHERE key = 'last_cloud_push_version'"
451
- );
452
- const lastPushVersion = pushMeta.rows.length > 0 ? Number(pushMeta.rows[0].value) : 0;
453
- const recordsResult = await client.execute({
454
- sql: `SELECT id, agent_id, agent_role, session_id, timestamp,
455
- tool_name, project_name, has_error, raw_text, version,
456
- author_device_id, scope
457
- FROM memories
458
- WHERE version > ?
459
- AND (scope IS NULL OR scope != 'personal')
460
- ORDER BY version ASC`,
461
- args: [lastPushVersion]
462
- });
463
- let pushed = 0;
464
- if (recordsResult.rows.length > 0) {
465
- const records = recordsResult.rows.map((row) => ({
466
- id: row.id,
467
- agent_id: row.agent_id,
468
- agent_role: row.agent_role,
469
- session_id: row.session_id,
470
- timestamp: row.timestamp,
471
- tool_name: row.tool_name,
472
- project_name: row.project_name,
473
- has_error: row.has_error,
474
- raw_text: row.raw_text,
475
- version: row.version,
476
- author_device_id: row.author_device_id,
477
- scope: row.scope
478
- }));
479
- const maxVersion = Number(records[records.length - 1].version);
480
- const pushOk = await cloudPush(records, maxVersion, config);
481
- if (pushOk) {
482
- await client.execute({
483
- sql: "INSERT OR REPLACE INTO sync_meta (key, value) VALUES ('last_cloud_push_version', ?)",
484
- args: [String(maxVersion)]
485
- });
486
- pushed = records.length;
487
- }
488
- }
489
- return { pushed, pulled };
490
- }
491
- export {
492
- cloudPull,
493
- cloudPush,
494
- cloudSync
495
- };
@@ -1,222 +0,0 @@
1
- // src/lib/config.ts
2
- import { readFile, writeFile, mkdir } from "fs/promises";
3
- import { readFileSync, existsSync, renameSync } from "fs";
4
- import path from "path";
5
- import os from "os";
6
- function resolveDataDir() {
7
- if (process.env.EXE_OS_DIR) return process.env.EXE_OS_DIR;
8
- if (process.env.EXE_MEM_DIR) return process.env.EXE_MEM_DIR;
9
- const newDir = path.join(os.homedir(), ".exe-os");
10
- const legacyDir = path.join(os.homedir(), ".exe-mem");
11
- if (!existsSync(newDir) && existsSync(legacyDir)) {
12
- try {
13
- renameSync(legacyDir, newDir);
14
- process.stderr.write(`[exe-os] Migrated data directory: ~/.exe-mem \u2192 ~/.exe-os
15
- `);
16
- } catch {
17
- return legacyDir;
18
- }
19
- }
20
- return newDir;
21
- }
22
- var EXE_AI_DIR = resolveDataDir();
23
- var DB_PATH = path.join(EXE_AI_DIR, "memories.db");
24
- var MODELS_DIR = path.join(EXE_AI_DIR, "models");
25
- var CONFIG_PATH = path.join(EXE_AI_DIR, "config.json");
26
- var LEGACY_LANCE_PATH = path.join(EXE_AI_DIR, "local.lance");
27
- var CURRENT_CONFIG_VERSION = 1;
28
- var DEFAULT_CONFIG = {
29
- config_version: CURRENT_CONFIG_VERSION,
30
- dbPath: DB_PATH,
31
- modelFile: "jina-embeddings-v5-small-q4_k_m.gguf",
32
- embeddingDim: 1024,
33
- batchSize: 20,
34
- flushIntervalMs: 1e4,
35
- autoIngestion: true,
36
- autoRetrieval: true,
37
- searchMode: "hybrid",
38
- hookSearchMode: "hybrid",
39
- fileGrepEnabled: true,
40
- splashEffect: true,
41
- consolidationEnabled: true,
42
- consolidationIntervalMs: 6 * 60 * 60 * 1e3,
43
- consolidationModel: "claude-haiku-4-5-20251001",
44
- consolidationMaxCallsPerRun: 20,
45
- selfQueryRouter: true,
46
- selfQueryModel: "claude-haiku-4-5-20251001",
47
- rerankerEnabled: true,
48
- scalingRoadmap: {
49
- rerankerAutoTrigger: {
50
- enabled: true,
51
- broadQueryMinCardinality: 5e4,
52
- fetchTopK: 150,
53
- returnTopK: 5
54
- }
55
- },
56
- graphRagEnabled: true,
57
- wikiEnabled: false,
58
- wikiUrl: "",
59
- wikiApiKey: "",
60
- wikiSyncIntervalMs: 30 * 60 * 1e3,
61
- wikiWorkspaceMapping: {
62
- exe: "Executive",
63
- yoshi: "Engineering",
64
- mari: "Marketing",
65
- tom: "Engineering",
66
- sasha: "Production"
67
- },
68
- wikiAutoUpdate: true,
69
- wikiAutoUpdateThreshold: 0.5,
70
- wikiAutoUpdateCreateNew: true,
71
- skillLearning: true,
72
- skillThreshold: 3,
73
- skillModel: "claude-haiku-4-5-20251001",
74
- exeHeartbeat: {
75
- enabled: true,
76
- intervalSeconds: 60,
77
- staleInProgressThresholdHours: 2
78
- },
79
- sessionLifecycle: {
80
- idleKillEnabled: true,
81
- idleKillTicksRequired: 3,
82
- idleKillIntercomAckWindowMs: 1e4,
83
- maxAutoInstances: 10
84
- }
85
- };
86
- function migrateLegacyConfig(raw) {
87
- if ("r2" in raw) {
88
- process.stderr.write(
89
- "[exe-os] Warning: config.json contains deprecated 'r2' field from v1.0. R2 sync has been replaced in v1.1. The 'r2' field will be ignored.\n"
90
- );
91
- delete raw.r2;
92
- }
93
- if ("syncIntervalMs" in raw) {
94
- delete raw.syncIntervalMs;
95
- }
96
- return raw;
97
- }
98
- var CONFIG_MIGRATIONS = [
99
- {
100
- from: 0,
101
- to: 1,
102
- migrate: (cfg) => {
103
- cfg.config_version = 1;
104
- return cfg;
105
- }
106
- }
107
- ];
108
- function migrateConfig(raw) {
109
- const fromVersion = typeof raw.config_version === "number" ? raw.config_version : 0;
110
- let currentVersion = fromVersion;
111
- let migrated = false;
112
- if (currentVersion > CURRENT_CONFIG_VERSION) {
113
- return { config: raw, migrated: false, fromVersion };
114
- }
115
- for (const migration of CONFIG_MIGRATIONS) {
116
- if (currentVersion === migration.from && migration.to <= CURRENT_CONFIG_VERSION) {
117
- raw = migration.migrate(raw);
118
- currentVersion = migration.to;
119
- migrated = true;
120
- }
121
- }
122
- return { config: raw, migrated, fromVersion };
123
- }
124
- function normalizeScalingRoadmap(raw) {
125
- const defaultAuto = DEFAULT_CONFIG.scalingRoadmap.rerankerAutoTrigger;
126
- const userRoadmap = raw.scalingRoadmap ?? {};
127
- const userAuto = userRoadmap.rerankerAutoTrigger ?? {};
128
- if (userAuto.enabled === void 0 && raw.rerankerEnabled !== void 0) {
129
- userAuto.enabled = raw.rerankerEnabled;
130
- }
131
- raw.scalingRoadmap = {
132
- ...userRoadmap,
133
- rerankerAutoTrigger: { ...defaultAuto, ...userAuto }
134
- };
135
- }
136
- function normalizeSessionLifecycle(raw) {
137
- const defaultSL = DEFAULT_CONFIG.sessionLifecycle;
138
- const userSL = raw.sessionLifecycle ?? {};
139
- raw.sessionLifecycle = { ...defaultSL, ...userSL };
140
- }
141
- async function loadConfig() {
142
- const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
143
- await mkdir(dir, { recursive: true });
144
- const configPath = path.join(dir, "config.json");
145
- if (!existsSync(configPath)) {
146
- return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
147
- }
148
- const raw = await readFile(configPath, "utf-8");
149
- try {
150
- let parsed = JSON.parse(raw);
151
- parsed = migrateLegacyConfig(parsed);
152
- const { config: migratedCfg, migrated, fromVersion } = migrateConfig(parsed);
153
- if (migrated) {
154
- process.stderr.write(`[exe-os] Config migrated from v${fromVersion} to v${migratedCfg.config_version}
155
- `);
156
- try {
157
- await writeFile(configPath, JSON.stringify(migratedCfg, null, 2) + "\n");
158
- } catch {
159
- }
160
- }
161
- normalizeScalingRoadmap(migratedCfg);
162
- normalizeSessionLifecycle(migratedCfg);
163
- const config = { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db"), ...migratedCfg };
164
- if (config.dbPath.startsWith("~")) {
165
- config.dbPath = config.dbPath.replace(/^~/, os.homedir());
166
- }
167
- return config;
168
- } catch {
169
- return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
170
- }
171
- }
172
- function loadConfigSync() {
173
- const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
174
- const configPath = path.join(dir, "config.json");
175
- if (!existsSync(configPath)) {
176
- return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
177
- }
178
- try {
179
- const raw = readFileSync(configPath, "utf-8");
180
- let parsed = JSON.parse(raw);
181
- parsed = migrateLegacyConfig(parsed);
182
- const { config: migratedCfg } = migrateConfig(parsed);
183
- normalizeScalingRoadmap(migratedCfg);
184
- normalizeSessionLifecycle(migratedCfg);
185
- return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db"), ...migratedCfg };
186
- } catch {
187
- return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
188
- }
189
- }
190
- async function saveConfig(config) {
191
- const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
192
- await mkdir(dir, { recursive: true });
193
- const configPath = path.join(dir, "config.json");
194
- await writeFile(configPath, JSON.stringify(config, null, 2) + "\n");
195
- }
196
- async function loadConfigFrom(configPath) {
197
- const raw = await readFile(configPath, "utf-8");
198
- try {
199
- let parsed = JSON.parse(raw);
200
- parsed = migrateLegacyConfig(parsed);
201
- const { config: migratedCfg } = migrateConfig(parsed);
202
- normalizeScalingRoadmap(migratedCfg);
203
- normalizeSessionLifecycle(migratedCfg);
204
- return { ...DEFAULT_CONFIG, ...migratedCfg };
205
- } catch {
206
- return { ...DEFAULT_CONFIG };
207
- }
208
- }
209
- export {
210
- CONFIG_MIGRATIONS,
211
- CONFIG_PATH,
212
- CURRENT_CONFIG_VERSION,
213
- DB_PATH,
214
- EXE_AI_DIR,
215
- LEGACY_LANCE_PATH,
216
- MODELS_DIR,
217
- loadConfig,
218
- loadConfigFrom,
219
- loadConfigSync,
220
- migrateConfig,
221
- saveConfig
222
- };