@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.
- package/dist/bin/backfill-conversations.js +222 -49
- package/dist/bin/backfill-responses.js +221 -48
- package/dist/bin/backfill-vectors.js +225 -52
- package/dist/bin/cleanup-stale-review-tasks.js +150 -28
- package/dist/bin/cli.js +1295 -856
- package/dist/bin/exe-agent-config.js +36 -8
- package/dist/bin/exe-agent.js +14 -4
- package/dist/bin/exe-assign.js +221 -48
- package/dist/bin/exe-boot.js +778 -427
- package/dist/bin/exe-call.js +41 -13
- package/dist/bin/exe-cloud.js +163 -58
- package/dist/bin/exe-dispatch.js +276 -139
- package/dist/bin/exe-doctor.js +145 -27
- package/dist/bin/exe-export-behaviors.js +141 -23
- package/dist/bin/exe-forget.js +137 -19
- package/dist/bin/exe-gateway.js +677 -388
- package/dist/bin/exe-heartbeat.js +227 -108
- package/dist/bin/exe-kill.js +138 -20
- package/dist/bin/exe-launch-agent.js +172 -39
- package/dist/bin/exe-link.js +291 -100
- package/dist/bin/exe-new-employee.js +214 -106
- package/dist/bin/exe-pending-messages.js +395 -33
- package/dist/bin/exe-pending-notifications.js +684 -99
- package/dist/bin/exe-pending-reviews.js +420 -74
- package/dist/bin/exe-rename.js +147 -49
- package/dist/bin/exe-review.js +138 -20
- package/dist/bin/exe-search.js +240 -69
- package/dist/bin/exe-session-cleanup.js +440 -250
- package/dist/bin/exe-settings.js +61 -17
- package/dist/bin/exe-start-codex.js +158 -39
- package/dist/bin/exe-start-opencode.js +157 -38
- package/dist/bin/exe-status.js +151 -29
- package/dist/bin/exe-team.js +138 -20
- package/dist/bin/git-sweep.js +404 -212
- package/dist/bin/graph-backfill.js +137 -19
- package/dist/bin/graph-export.js +140 -22
- package/dist/bin/install.js +90 -61
- package/dist/bin/scan-tasks.js +412 -220
- package/dist/bin/setup.js +564 -293
- package/dist/bin/shard-migrate.js +139 -21
- package/dist/bin/update.js +138 -49
- package/dist/bin/wiki-sync.js +137 -19
- package/dist/gateway/index.js +533 -320
- package/dist/hooks/bug-report-worker.js +344 -193
- package/dist/hooks/codex-stop-task-finalizer.js +4678 -0
- package/dist/hooks/commit-complete.js +402 -210
- package/dist/hooks/error-recall.js +245 -74
- package/dist/hooks/exe-heartbeat-hook.js +16 -6
- package/dist/hooks/ingest-worker.js +3423 -3157
- package/dist/hooks/ingest.js +832 -97
- package/dist/hooks/instructions-loaded.js +227 -54
- package/dist/hooks/notification.js +216 -43
- package/dist/hooks/post-compact.js +239 -62
- package/dist/hooks/pre-compact.js +408 -216
- package/dist/hooks/pre-tool-use.js +268 -90
- package/dist/hooks/prompt-ingest-worker.js +352 -102
- package/dist/hooks/prompt-submit.js +541 -328
- package/dist/hooks/response-ingest-worker.js +372 -122
- package/dist/hooks/session-end.js +443 -240
- package/dist/hooks/session-start.js +313 -127
- package/dist/hooks/stop.js +293 -98
- package/dist/hooks/subagent-stop.js +239 -62
- package/dist/hooks/summary-worker.js +568 -236
- package/dist/index.js +538 -324
- package/dist/lib/agent-config.js +28 -6
- package/dist/lib/cloud-sync.js +284 -105
- package/dist/lib/config.js +30 -10
- package/dist/lib/consolidation.js +16 -6
- package/dist/lib/database.js +123 -25
- package/dist/lib/db-daemon-client.js +73 -19
- package/dist/lib/db.js +123 -25
- package/dist/lib/device-registry.js +133 -35
- package/dist/lib/embedder.js +107 -32
- package/dist/lib/employee-templates.js +14 -4
- package/dist/lib/employees.js +41 -13
- package/dist/lib/exe-daemon-client.js +88 -22
- package/dist/lib/exe-daemon.js +935 -587
- package/dist/lib/hybrid-search.js +240 -69
- package/dist/lib/identity.js +18 -8
- package/dist/lib/license.js +133 -48
- package/dist/lib/messaging.js +116 -56
- package/dist/lib/reminders.js +14 -4
- package/dist/lib/schedules.js +137 -19
- package/dist/lib/skill-learning.js +33 -6
- package/dist/lib/store.js +137 -19
- package/dist/lib/task-router.js +14 -4
- package/dist/lib/tasks.js +280 -234
- package/dist/lib/tmux-routing.js +172 -125
- package/dist/lib/token-spend.js +26 -8
- package/dist/mcp/server.js +1326 -609
- package/dist/mcp/tools/complete-reminder.js +14 -4
- package/dist/mcp/tools/create-reminder.js +14 -4
- package/dist/mcp/tools/create-task.js +306 -248
- package/dist/mcp/tools/deactivate-behavior.js +16 -6
- package/dist/mcp/tools/list-reminders.js +14 -4
- package/dist/mcp/tools/list-tasks.js +123 -107
- package/dist/mcp/tools/send-message.js +75 -29
- package/dist/mcp/tools/update-task.js +1848 -199
- package/dist/runtime/index.js +441 -248
- package/dist/tui/App.js +761 -424
- package/package.json +1 -1
|
@@ -8,9 +8,47 @@ var __export = (target, all) => {
|
|
|
8
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
// src/lib/secure-files.ts
|
|
12
|
+
import { chmodSync, existsSync, mkdirSync } from "fs";
|
|
13
|
+
import { chmod, mkdir } from "fs/promises";
|
|
14
|
+
async function ensurePrivateDir(dirPath) {
|
|
15
|
+
await mkdir(dirPath, { recursive: true, mode: PRIVATE_DIR_MODE });
|
|
16
|
+
try {
|
|
17
|
+
await chmod(dirPath, PRIVATE_DIR_MODE);
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function ensurePrivateDirSync(dirPath) {
|
|
22
|
+
mkdirSync(dirPath, { recursive: true, mode: PRIVATE_DIR_MODE });
|
|
23
|
+
try {
|
|
24
|
+
chmodSync(dirPath, PRIVATE_DIR_MODE);
|
|
25
|
+
} catch {
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async function enforcePrivateFile(filePath) {
|
|
29
|
+
try {
|
|
30
|
+
await chmod(filePath, PRIVATE_FILE_MODE);
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function enforcePrivateFileSync(filePath) {
|
|
35
|
+
try {
|
|
36
|
+
if (existsSync(filePath)) chmodSync(filePath, PRIVATE_FILE_MODE);
|
|
37
|
+
} catch {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
var PRIVATE_DIR_MODE, PRIVATE_FILE_MODE;
|
|
41
|
+
var init_secure_files = __esm({
|
|
42
|
+
"src/lib/secure-files.ts"() {
|
|
43
|
+
"use strict";
|
|
44
|
+
PRIVATE_DIR_MODE = 448;
|
|
45
|
+
PRIVATE_FILE_MODE = 384;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
11
49
|
// src/lib/config.ts
|
|
12
|
-
import { readFile, writeFile
|
|
13
|
-
import { readFileSync, existsSync, renameSync } from "fs";
|
|
50
|
+
import { readFile, writeFile } from "fs/promises";
|
|
51
|
+
import { readFileSync, existsSync as existsSync2, renameSync } from "fs";
|
|
14
52
|
import path from "path";
|
|
15
53
|
import os from "os";
|
|
16
54
|
function resolveDataDir() {
|
|
@@ -18,7 +56,7 @@ function resolveDataDir() {
|
|
|
18
56
|
if (process.env.EXE_MEM_DIR) return process.env.EXE_MEM_DIR;
|
|
19
57
|
const newDir = path.join(os.homedir(), ".exe-os");
|
|
20
58
|
const legacyDir = path.join(os.homedir(), ".exe-mem");
|
|
21
|
-
if (!
|
|
59
|
+
if (!existsSync2(newDir) && existsSync2(legacyDir)) {
|
|
22
60
|
try {
|
|
23
61
|
renameSync(legacyDir, newDir);
|
|
24
62
|
process.stderr.write(`[exe-os] Migrated data directory: ~/.exe-mem \u2192 ~/.exe-os
|
|
@@ -81,9 +119,9 @@ function normalizeAutoUpdate(raw) {
|
|
|
81
119
|
}
|
|
82
120
|
async function loadConfig() {
|
|
83
121
|
const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
|
|
84
|
-
await
|
|
122
|
+
await ensurePrivateDir(dir);
|
|
85
123
|
const configPath = path.join(dir, "config.json");
|
|
86
|
-
if (!
|
|
124
|
+
if (!existsSync2(configPath)) {
|
|
87
125
|
return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
|
|
88
126
|
}
|
|
89
127
|
const raw = await readFile(configPath, "utf-8");
|
|
@@ -96,6 +134,7 @@ async function loadConfig() {
|
|
|
96
134
|
`);
|
|
97
135
|
try {
|
|
98
136
|
await writeFile(configPath, JSON.stringify(migratedCfg, null, 2) + "\n");
|
|
137
|
+
await enforcePrivateFile(configPath);
|
|
99
138
|
} catch {
|
|
100
139
|
}
|
|
101
140
|
}
|
|
@@ -115,6 +154,7 @@ var EXE_AI_DIR, DB_PATH, MODELS_DIR, CONFIG_PATH, LEGACY_LANCE_PATH, CURRENT_CON
|
|
|
115
154
|
var init_config = __esm({
|
|
116
155
|
"src/lib/config.ts"() {
|
|
117
156
|
"use strict";
|
|
157
|
+
init_secure_files();
|
|
118
158
|
EXE_AI_DIR = resolveDataDir();
|
|
119
159
|
DB_PATH = path.join(EXE_AI_DIR, "memories.db");
|
|
120
160
|
MODELS_DIR = path.join(EXE_AI_DIR, "models");
|
|
@@ -193,7 +233,7 @@ var init_config = __esm({
|
|
|
193
233
|
|
|
194
234
|
// src/lib/employees.ts
|
|
195
235
|
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
196
|
-
import { existsSync as
|
|
236
|
+
import { existsSync as existsSync3, symlinkSync, readlinkSync, readFileSync as readFileSync2, renameSync as renameSync2, unlinkSync, writeFileSync } from "fs";
|
|
197
237
|
import { execSync as execSync2 } from "child_process";
|
|
198
238
|
import path2 from "path";
|
|
199
239
|
import os2 from "os";
|
|
@@ -210,7 +250,7 @@ function getCoordinatorName(employees = loadEmployeesSync()) {
|
|
|
210
250
|
return getCoordinatorEmployee(employees)?.name ?? DEFAULT_COORDINATOR_TEMPLATE_NAME;
|
|
211
251
|
}
|
|
212
252
|
function loadEmployeesSync(employeesPath = EMPLOYEES_PATH) {
|
|
213
|
-
if (!
|
|
253
|
+
if (!existsSync3(employeesPath)) return [];
|
|
214
254
|
try {
|
|
215
255
|
return JSON.parse(readFileSync2(employeesPath, "utf-8"));
|
|
216
256
|
} catch {
|
|
@@ -880,13 +920,50 @@ var init_database_adapter = __esm({
|
|
|
880
920
|
}
|
|
881
921
|
});
|
|
882
922
|
|
|
923
|
+
// src/lib/daemon-auth.ts
|
|
924
|
+
import crypto from "crypto";
|
|
925
|
+
import path5 from "path";
|
|
926
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "fs";
|
|
927
|
+
function normalizeToken(token) {
|
|
928
|
+
if (!token) return null;
|
|
929
|
+
const trimmed = token.trim();
|
|
930
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
931
|
+
}
|
|
932
|
+
function readDaemonToken() {
|
|
933
|
+
try {
|
|
934
|
+
if (!existsSync4(DAEMON_TOKEN_PATH)) return null;
|
|
935
|
+
return normalizeToken(readFileSync4(DAEMON_TOKEN_PATH, "utf8"));
|
|
936
|
+
} catch {
|
|
937
|
+
return null;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
function ensureDaemonToken(seed) {
|
|
941
|
+
const existing = readDaemonToken();
|
|
942
|
+
if (existing) return existing;
|
|
943
|
+
const token = normalizeToken(seed) ?? crypto.randomBytes(32).toString("hex");
|
|
944
|
+
ensurePrivateDirSync(EXE_AI_DIR);
|
|
945
|
+
writeFileSync3(DAEMON_TOKEN_PATH, `${token}
|
|
946
|
+
`, "utf8");
|
|
947
|
+
enforcePrivateFileSync(DAEMON_TOKEN_PATH);
|
|
948
|
+
return token;
|
|
949
|
+
}
|
|
950
|
+
var DAEMON_TOKEN_PATH;
|
|
951
|
+
var init_daemon_auth = __esm({
|
|
952
|
+
"src/lib/daemon-auth.ts"() {
|
|
953
|
+
"use strict";
|
|
954
|
+
init_config();
|
|
955
|
+
init_secure_files();
|
|
956
|
+
DAEMON_TOKEN_PATH = path5.join(EXE_AI_DIR, "exed.token");
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
|
|
883
960
|
// src/lib/exe-daemon-client.ts
|
|
884
961
|
import net from "net";
|
|
885
962
|
import os4 from "os";
|
|
886
963
|
import { spawn } from "child_process";
|
|
887
964
|
import { randomUUID } from "crypto";
|
|
888
|
-
import { existsSync as
|
|
889
|
-
import
|
|
965
|
+
import { existsSync as existsSync5, unlinkSync as unlinkSync3, readFileSync as readFileSync5, openSync, closeSync, statSync } from "fs";
|
|
966
|
+
import path6 from "path";
|
|
890
967
|
import { fileURLToPath } from "url";
|
|
891
968
|
function handleData(chunk) {
|
|
892
969
|
_buffer += chunk.toString();
|
|
@@ -914,9 +991,9 @@ function handleData(chunk) {
|
|
|
914
991
|
}
|
|
915
992
|
}
|
|
916
993
|
function cleanupStaleFiles() {
|
|
917
|
-
if (
|
|
994
|
+
if (existsSync5(PID_PATH)) {
|
|
918
995
|
try {
|
|
919
|
-
const pid = parseInt(
|
|
996
|
+
const pid = parseInt(readFileSync5(PID_PATH, "utf8").trim(), 10);
|
|
920
997
|
if (pid > 0) {
|
|
921
998
|
try {
|
|
922
999
|
process.kill(pid, 0);
|
|
@@ -937,11 +1014,11 @@ function cleanupStaleFiles() {
|
|
|
937
1014
|
}
|
|
938
1015
|
}
|
|
939
1016
|
function findPackageRoot() {
|
|
940
|
-
let dir =
|
|
941
|
-
const { root } =
|
|
1017
|
+
let dir = path6.dirname(fileURLToPath(import.meta.url));
|
|
1018
|
+
const { root } = path6.parse(dir);
|
|
942
1019
|
while (dir !== root) {
|
|
943
|
-
if (
|
|
944
|
-
dir =
|
|
1020
|
+
if (existsSync5(path6.join(dir, "package.json"))) return dir;
|
|
1021
|
+
dir = path6.dirname(dir);
|
|
945
1022
|
}
|
|
946
1023
|
return null;
|
|
947
1024
|
}
|
|
@@ -967,16 +1044,17 @@ function spawnDaemon() {
|
|
|
967
1044
|
process.stderr.write("[exed-client] WARN: cannot find package root\n");
|
|
968
1045
|
return;
|
|
969
1046
|
}
|
|
970
|
-
const daemonPath =
|
|
971
|
-
if (!
|
|
1047
|
+
const daemonPath = path6.join(pkgRoot, "dist", "lib", "exe-daemon.js");
|
|
1048
|
+
if (!existsSync5(daemonPath)) {
|
|
972
1049
|
process.stderr.write(`[exed-client] WARN: daemon script not found at ${daemonPath}
|
|
973
1050
|
`);
|
|
974
1051
|
return;
|
|
975
1052
|
}
|
|
976
1053
|
const resolvedPath = daemonPath;
|
|
1054
|
+
const daemonToken = ensureDaemonToken(process.env[DAEMON_TOKEN_ENV] ?? null);
|
|
977
1055
|
process.stderr.write(`[exed-client] Spawning daemon: ${resolvedPath}
|
|
978
1056
|
`);
|
|
979
|
-
const logPath =
|
|
1057
|
+
const logPath = path6.join(path6.dirname(SOCKET_PATH), "exed.log");
|
|
980
1058
|
let stderrFd = "ignore";
|
|
981
1059
|
try {
|
|
982
1060
|
stderrFd = openSync(logPath, "a");
|
|
@@ -994,7 +1072,8 @@ function spawnDaemon() {
|
|
|
994
1072
|
TMUX_PANE: void 0,
|
|
995
1073
|
// Prevents resolveExeSession() from scoping to one session
|
|
996
1074
|
EXE_DAEMON_SOCK: SOCKET_PATH,
|
|
997
|
-
EXE_DAEMON_PID: PID_PATH
|
|
1075
|
+
EXE_DAEMON_PID: PID_PATH,
|
|
1076
|
+
[DAEMON_TOKEN_ENV]: daemonToken
|
|
998
1077
|
}
|
|
999
1078
|
});
|
|
1000
1079
|
child.unref();
|
|
@@ -1101,13 +1180,14 @@ function sendDaemonRequest(payload, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
|
1101
1180
|
return;
|
|
1102
1181
|
}
|
|
1103
1182
|
const id = randomUUID();
|
|
1183
|
+
const token = process.env[DAEMON_TOKEN_ENV] ?? readDaemonToken();
|
|
1104
1184
|
const timer = setTimeout(() => {
|
|
1105
1185
|
_pending.delete(id);
|
|
1106
1186
|
resolve({ error: "Request timeout" });
|
|
1107
1187
|
}, timeoutMs);
|
|
1108
1188
|
_pending.set(id, { resolve, timer });
|
|
1109
1189
|
try {
|
|
1110
|
-
_socket.write(JSON.stringify({ id, ...payload }) + "\n");
|
|
1190
|
+
_socket.write(JSON.stringify({ id, token, ...payload }) + "\n");
|
|
1111
1191
|
} catch {
|
|
1112
1192
|
clearTimeout(timer);
|
|
1113
1193
|
_pending.delete(id);
|
|
@@ -1118,17 +1198,19 @@ function sendDaemonRequest(payload, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
|
1118
1198
|
function isClientConnected() {
|
|
1119
1199
|
return _connected;
|
|
1120
1200
|
}
|
|
1121
|
-
var SOCKET_PATH, PID_PATH, SPAWN_LOCK_PATH, SPAWN_LOCK_STALE_MS, CONNECT_TIMEOUT_MS, REQUEST_TIMEOUT_MS, _socket, _connected, _buffer, _pending, MAX_BUFFER;
|
|
1201
|
+
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;
|
|
1122
1202
|
var init_exe_daemon_client = __esm({
|
|
1123
1203
|
"src/lib/exe-daemon-client.ts"() {
|
|
1124
1204
|
"use strict";
|
|
1125
1205
|
init_config();
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1206
|
+
init_daemon_auth();
|
|
1207
|
+
SOCKET_PATH = process.env.EXE_DAEMON_SOCK ?? process.env.EXE_EMBED_SOCK ?? path6.join(EXE_AI_DIR, "exed.sock");
|
|
1208
|
+
PID_PATH = process.env.EXE_DAEMON_PID ?? process.env.EXE_EMBED_PID ?? path6.join(EXE_AI_DIR, "exed.pid");
|
|
1209
|
+
SPAWN_LOCK_PATH = path6.join(EXE_AI_DIR, "exed-spawn.lock");
|
|
1129
1210
|
SPAWN_LOCK_STALE_MS = 3e4;
|
|
1130
1211
|
CONNECT_TIMEOUT_MS = 15e3;
|
|
1131
1212
|
REQUEST_TIMEOUT_MS = 3e4;
|
|
1213
|
+
DAEMON_TOKEN_ENV = "EXE_DAEMON_TOKEN";
|
|
1132
1214
|
_socket = null;
|
|
1133
1215
|
_connected = false;
|
|
1134
1216
|
_buffer = "";
|
|
@@ -1707,6 +1789,7 @@ async function ensureSchema() {
|
|
|
1707
1789
|
project TEXT NOT NULL,
|
|
1708
1790
|
summary TEXT NOT NULL,
|
|
1709
1791
|
task_file TEXT,
|
|
1792
|
+
session_scope TEXT,
|
|
1710
1793
|
read INTEGER NOT NULL DEFAULT 0,
|
|
1711
1794
|
created_at TEXT NOT NULL
|
|
1712
1795
|
);
|
|
@@ -1715,7 +1798,7 @@ async function ensureSchema() {
|
|
|
1715
1798
|
ON notifications(read);
|
|
1716
1799
|
|
|
1717
1800
|
CREATE INDEX IF NOT EXISTS idx_notifications_agent
|
|
1718
|
-
ON notifications(agent_id);
|
|
1801
|
+
ON notifications(agent_id, session_scope);
|
|
1719
1802
|
|
|
1720
1803
|
CREATE INDEX IF NOT EXISTS idx_notifications_task_file
|
|
1721
1804
|
ON notifications(task_file);
|
|
@@ -1753,6 +1836,7 @@ async function ensureSchema() {
|
|
|
1753
1836
|
target_agent TEXT NOT NULL,
|
|
1754
1837
|
target_project TEXT,
|
|
1755
1838
|
target_device TEXT NOT NULL DEFAULT 'local',
|
|
1839
|
+
session_scope TEXT,
|
|
1756
1840
|
content TEXT NOT NULL,
|
|
1757
1841
|
priority TEXT DEFAULT 'normal',
|
|
1758
1842
|
status TEXT DEFAULT 'pending',
|
|
@@ -1766,10 +1850,31 @@ async function ensureSchema() {
|
|
|
1766
1850
|
);
|
|
1767
1851
|
|
|
1768
1852
|
CREATE INDEX IF NOT EXISTS idx_messages_target
|
|
1769
|
-
ON messages(target_agent, status);
|
|
1853
|
+
ON messages(target_agent, session_scope, status);
|
|
1770
1854
|
|
|
1771
1855
|
CREATE INDEX IF NOT EXISTS idx_messages_conversation_order
|
|
1772
|
-
ON messages(target_agent, from_agent, server_seq);
|
|
1856
|
+
ON messages(target_agent, session_scope, from_agent, server_seq);
|
|
1857
|
+
`);
|
|
1858
|
+
try {
|
|
1859
|
+
await client.execute({
|
|
1860
|
+
sql: `ALTER TABLE notifications ADD COLUMN session_scope TEXT`,
|
|
1861
|
+
args: []
|
|
1862
|
+
});
|
|
1863
|
+
} catch {
|
|
1864
|
+
}
|
|
1865
|
+
try {
|
|
1866
|
+
await client.execute({
|
|
1867
|
+
sql: `ALTER TABLE messages ADD COLUMN session_scope TEXT`,
|
|
1868
|
+
args: []
|
|
1869
|
+
});
|
|
1870
|
+
} catch {
|
|
1871
|
+
}
|
|
1872
|
+
await client.executeMultiple(`
|
|
1873
|
+
CREATE INDEX IF NOT EXISTS idx_notifications_agent_scope_read
|
|
1874
|
+
ON notifications(agent_id, session_scope, read, created_at);
|
|
1875
|
+
|
|
1876
|
+
CREATE INDEX IF NOT EXISTS idx_messages_target_scope_status
|
|
1877
|
+
ON messages(target_agent, session_scope, status, created_at);
|
|
1773
1878
|
`);
|
|
1774
1879
|
try {
|
|
1775
1880
|
await client.execute({
|
|
@@ -2353,6 +2458,13 @@ async function ensureSchema() {
|
|
|
2353
2458
|
} catch {
|
|
2354
2459
|
}
|
|
2355
2460
|
}
|
|
2461
|
+
try {
|
|
2462
|
+
await client.execute({
|
|
2463
|
+
sql: `UPDATE tasks SET status = 'closed' WHERE status = 'done' AND result IS NOT NULL`,
|
|
2464
|
+
args: []
|
|
2465
|
+
});
|
|
2466
|
+
} catch {
|
|
2467
|
+
}
|
|
2356
2468
|
}
|
|
2357
2469
|
async function disposeDatabase() {
|
|
2358
2470
|
if (_walCheckpointTimer) {
|
|
@@ -2392,14 +2504,14 @@ var init_database = __esm({
|
|
|
2392
2504
|
|
|
2393
2505
|
// src/lib/keychain.ts
|
|
2394
2506
|
import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
|
|
2395
|
-
import { existsSync as
|
|
2396
|
-
import
|
|
2507
|
+
import { existsSync as existsSync6 } from "fs";
|
|
2508
|
+
import path7 from "path";
|
|
2397
2509
|
import os5 from "os";
|
|
2398
2510
|
function getKeyDir() {
|
|
2399
|
-
return process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ??
|
|
2511
|
+
return process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? path7.join(os5.homedir(), ".exe-os");
|
|
2400
2512
|
}
|
|
2401
2513
|
function getKeyPath() {
|
|
2402
|
-
return
|
|
2514
|
+
return path7.join(getKeyDir(), "master.key");
|
|
2403
2515
|
}
|
|
2404
2516
|
async function tryKeytar() {
|
|
2405
2517
|
try {
|
|
@@ -2420,7 +2532,7 @@ async function getMasterKey() {
|
|
|
2420
2532
|
}
|
|
2421
2533
|
}
|
|
2422
2534
|
const keyPath = getKeyPath();
|
|
2423
|
-
if (!
|
|
2535
|
+
if (!existsSync6(keyPath)) {
|
|
2424
2536
|
process.stderr.write(
|
|
2425
2537
|
`[keychain] Key not found at ${keyPath} (HOME=${os5.homedir()}, EXE_OS_DIR=${process.env.EXE_OS_DIR ?? "unset"})
|
|
2426
2538
|
`
|
|
@@ -2507,6 +2619,7 @@ var shard_manager_exports = {};
|
|
|
2507
2619
|
__export(shard_manager_exports, {
|
|
2508
2620
|
disposeShards: () => disposeShards,
|
|
2509
2621
|
ensureShardSchema: () => ensureShardSchema,
|
|
2622
|
+
getOpenShardCount: () => getOpenShardCount,
|
|
2510
2623
|
getReadyShardClient: () => getReadyShardClient,
|
|
2511
2624
|
getShardClient: () => getShardClient,
|
|
2512
2625
|
getShardsDir: () => getShardsDir,
|
|
@@ -2515,15 +2628,18 @@ __export(shard_manager_exports, {
|
|
|
2515
2628
|
listShards: () => listShards,
|
|
2516
2629
|
shardExists: () => shardExists
|
|
2517
2630
|
});
|
|
2518
|
-
import
|
|
2519
|
-
import { existsSync as
|
|
2631
|
+
import path8 from "path";
|
|
2632
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync3, readdirSync as readdirSync2 } from "fs";
|
|
2520
2633
|
import { createClient as createClient2 } from "@libsql/client";
|
|
2521
2634
|
function initShardManager(encryptionKey) {
|
|
2522
2635
|
_encryptionKey = encryptionKey;
|
|
2523
|
-
if (!
|
|
2524
|
-
|
|
2636
|
+
if (!existsSync7(SHARDS_DIR)) {
|
|
2637
|
+
mkdirSync3(SHARDS_DIR, { recursive: true });
|
|
2525
2638
|
}
|
|
2526
2639
|
_shardingEnabled = true;
|
|
2640
|
+
if (_evictionTimer) clearInterval(_evictionTimer);
|
|
2641
|
+
_evictionTimer = setInterval(evictIdleShards, EVICTION_INTERVAL_MS);
|
|
2642
|
+
_evictionTimer.unref();
|
|
2527
2643
|
}
|
|
2528
2644
|
function isShardingEnabled() {
|
|
2529
2645
|
return _shardingEnabled;
|
|
@@ -2540,21 +2656,28 @@ function getShardClient(projectName) {
|
|
|
2540
2656
|
throw new Error(`Invalid project name for shard: "${projectName}"`);
|
|
2541
2657
|
}
|
|
2542
2658
|
const cached = _shards.get(safeName);
|
|
2543
|
-
if (cached)
|
|
2544
|
-
|
|
2659
|
+
if (cached) {
|
|
2660
|
+
_shardLastAccess.set(safeName, Date.now());
|
|
2661
|
+
return cached;
|
|
2662
|
+
}
|
|
2663
|
+
while (_shards.size >= MAX_OPEN_SHARDS) {
|
|
2664
|
+
evictLRU();
|
|
2665
|
+
}
|
|
2666
|
+
const dbPath = path8.join(SHARDS_DIR, `${safeName}.db`);
|
|
2545
2667
|
const client = createClient2({
|
|
2546
2668
|
url: `file:${dbPath}`,
|
|
2547
2669
|
encryptionKey: _encryptionKey
|
|
2548
2670
|
});
|
|
2549
2671
|
_shards.set(safeName, client);
|
|
2672
|
+
_shardLastAccess.set(safeName, Date.now());
|
|
2550
2673
|
return client;
|
|
2551
2674
|
}
|
|
2552
2675
|
function shardExists(projectName) {
|
|
2553
2676
|
const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
2554
|
-
return
|
|
2677
|
+
return existsSync7(path8.join(SHARDS_DIR, `${safeName}.db`));
|
|
2555
2678
|
}
|
|
2556
2679
|
function listShards() {
|
|
2557
|
-
if (!
|
|
2680
|
+
if (!existsSync7(SHARDS_DIR)) return [];
|
|
2558
2681
|
return readdirSync2(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
|
|
2559
2682
|
}
|
|
2560
2683
|
async function ensureShardSchema(client) {
|
|
@@ -2606,6 +2729,8 @@ async function ensureShardSchema(client) {
|
|
|
2606
2729
|
for (const col of [
|
|
2607
2730
|
"ALTER TABLE memories ADD COLUMN task_id TEXT",
|
|
2608
2731
|
"ALTER TABLE memories ADD COLUMN consolidated INTEGER NOT NULL DEFAULT 0",
|
|
2732
|
+
"ALTER TABLE memories ADD COLUMN author_device_id TEXT",
|
|
2733
|
+
"ALTER TABLE memories ADD COLUMN scope TEXT NOT NULL DEFAULT 'business'",
|
|
2609
2734
|
"ALTER TABLE memories ADD COLUMN importance INTEGER DEFAULT 5",
|
|
2610
2735
|
"ALTER TABLE memories ADD COLUMN status TEXT DEFAULT 'active'",
|
|
2611
2736
|
"ALTER TABLE memories ADD COLUMN wiki_synced INTEGER DEFAULT 0",
|
|
@@ -2743,21 +2868,69 @@ async function getReadyShardClient(projectName) {
|
|
|
2743
2868
|
await ensureShardSchema(client);
|
|
2744
2869
|
return client;
|
|
2745
2870
|
}
|
|
2871
|
+
function evictLRU() {
|
|
2872
|
+
let oldest = null;
|
|
2873
|
+
let oldestTime = Infinity;
|
|
2874
|
+
for (const [name, time] of _shardLastAccess) {
|
|
2875
|
+
if (time < oldestTime) {
|
|
2876
|
+
oldestTime = time;
|
|
2877
|
+
oldest = name;
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
if (oldest) {
|
|
2881
|
+
const client = _shards.get(oldest);
|
|
2882
|
+
if (client) {
|
|
2883
|
+
client.close();
|
|
2884
|
+
}
|
|
2885
|
+
_shards.delete(oldest);
|
|
2886
|
+
_shardLastAccess.delete(oldest);
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
function evictIdleShards() {
|
|
2890
|
+
const now = Date.now();
|
|
2891
|
+
const toEvict = [];
|
|
2892
|
+
for (const [name, lastAccess] of _shardLastAccess) {
|
|
2893
|
+
if (now - lastAccess > SHARD_IDLE_MS) {
|
|
2894
|
+
toEvict.push(name);
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
for (const name of toEvict) {
|
|
2898
|
+
const client = _shards.get(name);
|
|
2899
|
+
if (client) {
|
|
2900
|
+
client.close();
|
|
2901
|
+
}
|
|
2902
|
+
_shards.delete(name);
|
|
2903
|
+
_shardLastAccess.delete(name);
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
function getOpenShardCount() {
|
|
2907
|
+
return _shards.size;
|
|
2908
|
+
}
|
|
2746
2909
|
function disposeShards() {
|
|
2910
|
+
if (_evictionTimer) {
|
|
2911
|
+
clearInterval(_evictionTimer);
|
|
2912
|
+
_evictionTimer = null;
|
|
2913
|
+
}
|
|
2747
2914
|
for (const [, client] of _shards) {
|
|
2748
2915
|
client.close();
|
|
2749
2916
|
}
|
|
2750
2917
|
_shards.clear();
|
|
2918
|
+
_shardLastAccess.clear();
|
|
2751
2919
|
_shardingEnabled = false;
|
|
2752
2920
|
_encryptionKey = null;
|
|
2753
2921
|
}
|
|
2754
|
-
var SHARDS_DIR, _shards, _encryptionKey, _shardingEnabled;
|
|
2922
|
+
var SHARDS_DIR, SHARD_IDLE_MS, MAX_OPEN_SHARDS, EVICTION_INTERVAL_MS, _shards, _shardLastAccess, _evictionTimer, _encryptionKey, _shardingEnabled;
|
|
2755
2923
|
var init_shard_manager = __esm({
|
|
2756
2924
|
"src/lib/shard-manager.ts"() {
|
|
2757
2925
|
"use strict";
|
|
2758
2926
|
init_config();
|
|
2759
|
-
SHARDS_DIR =
|
|
2927
|
+
SHARDS_DIR = path8.join(EXE_AI_DIR, "shards");
|
|
2928
|
+
SHARD_IDLE_MS = 5 * 60 * 1e3;
|
|
2929
|
+
MAX_OPEN_SHARDS = 10;
|
|
2930
|
+
EVICTION_INTERVAL_MS = 60 * 1e3;
|
|
2760
2931
|
_shards = /* @__PURE__ */ new Map();
|
|
2932
|
+
_shardLastAccess = /* @__PURE__ */ new Map();
|
|
2933
|
+
_evictionTimer = null;
|
|
2761
2934
|
_encryptionKey = null;
|
|
2762
2935
|
_shardingEnabled = false;
|
|
2763
2936
|
}
|
|
@@ -3522,7 +3695,7 @@ var init_store = __esm({
|
|
|
3522
3695
|
|
|
3523
3696
|
// src/lib/active-agent.ts
|
|
3524
3697
|
init_config();
|
|
3525
|
-
import { readFileSync as readFileSync3, writeFileSync as writeFileSync2, mkdirSync, unlinkSync as unlinkSync2, readdirSync } from "fs";
|
|
3698
|
+
import { readFileSync as readFileSync3, writeFileSync as writeFileSync2, mkdirSync as mkdirSync2, unlinkSync as unlinkSync2, readdirSync } from "fs";
|
|
3526
3699
|
import { execSync as execSync3 } from "child_process";
|
|
3527
3700
|
import path3 from "path";
|
|
3528
3701
|
|