@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
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __esm = (fn, res) => function __init() {
|
|
5
7
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
8
|
};
|
|
@@ -8,6 +10,15 @@ var __export = (target, all) => {
|
|
|
8
10
|
for (var name in all)
|
|
9
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
12
|
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
11
22
|
|
|
12
23
|
// src/lib/db-retry.ts
|
|
13
24
|
function isBusyError(err) {
|
|
@@ -64,9 +75,34 @@ var init_db_retry = __esm({
|
|
|
64
75
|
}
|
|
65
76
|
});
|
|
66
77
|
|
|
78
|
+
// src/lib/secure-files.ts
|
|
79
|
+
import { chmodSync, existsSync, mkdirSync } from "fs";
|
|
80
|
+
import { chmod, mkdir } from "fs/promises";
|
|
81
|
+
async function ensurePrivateDir(dirPath) {
|
|
82
|
+
await mkdir(dirPath, { recursive: true, mode: PRIVATE_DIR_MODE });
|
|
83
|
+
try {
|
|
84
|
+
await chmod(dirPath, PRIVATE_DIR_MODE);
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function enforcePrivateFile(filePath) {
|
|
89
|
+
try {
|
|
90
|
+
await chmod(filePath, PRIVATE_FILE_MODE);
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
var PRIVATE_DIR_MODE, PRIVATE_FILE_MODE;
|
|
95
|
+
var init_secure_files = __esm({
|
|
96
|
+
"src/lib/secure-files.ts"() {
|
|
97
|
+
"use strict";
|
|
98
|
+
PRIVATE_DIR_MODE = 448;
|
|
99
|
+
PRIVATE_FILE_MODE = 384;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
67
103
|
// src/lib/config.ts
|
|
68
|
-
import { readFile, writeFile
|
|
69
|
-
import { readFileSync, existsSync, renameSync } from "fs";
|
|
104
|
+
import { readFile, writeFile } from "fs/promises";
|
|
105
|
+
import { readFileSync, existsSync as existsSync2, renameSync } from "fs";
|
|
70
106
|
import path from "path";
|
|
71
107
|
import os from "os";
|
|
72
108
|
function resolveDataDir() {
|
|
@@ -74,7 +110,7 @@ function resolveDataDir() {
|
|
|
74
110
|
if (process.env.EXE_MEM_DIR) return process.env.EXE_MEM_DIR;
|
|
75
111
|
const newDir = path.join(os.homedir(), ".exe-os");
|
|
76
112
|
const legacyDir = path.join(os.homedir(), ".exe-mem");
|
|
77
|
-
if (!
|
|
113
|
+
if (!existsSync2(newDir) && existsSync2(legacyDir)) {
|
|
78
114
|
try {
|
|
79
115
|
renameSync(legacyDir, newDir);
|
|
80
116
|
process.stderr.write(`[exe-os] Migrated data directory: ~/.exe-mem \u2192 ~/.exe-os
|
|
@@ -137,9 +173,9 @@ function normalizeAutoUpdate(raw) {
|
|
|
137
173
|
}
|
|
138
174
|
async function loadConfig() {
|
|
139
175
|
const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
|
|
140
|
-
await
|
|
176
|
+
await ensurePrivateDir(dir);
|
|
141
177
|
const configPath = path.join(dir, "config.json");
|
|
142
|
-
if (!
|
|
178
|
+
if (!existsSync2(configPath)) {
|
|
143
179
|
return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
|
|
144
180
|
}
|
|
145
181
|
const raw = await readFile(configPath, "utf-8");
|
|
@@ -152,6 +188,7 @@ async function loadConfig() {
|
|
|
152
188
|
`);
|
|
153
189
|
try {
|
|
154
190
|
await writeFile(configPath, JSON.stringify(migratedCfg, null, 2) + "\n");
|
|
191
|
+
await enforcePrivateFile(configPath);
|
|
155
192
|
} catch {
|
|
156
193
|
}
|
|
157
194
|
}
|
|
@@ -171,6 +208,7 @@ var EXE_AI_DIR, DB_PATH, MODELS_DIR, CONFIG_PATH, LEGACY_LANCE_PATH, CURRENT_CON
|
|
|
171
208
|
var init_config = __esm({
|
|
172
209
|
"src/lib/config.ts"() {
|
|
173
210
|
"use strict";
|
|
211
|
+
init_secure_files();
|
|
174
212
|
EXE_AI_DIR = resolveDataDir();
|
|
175
213
|
DB_PATH = path.join(EXE_AI_DIR, "memories.db");
|
|
176
214
|
MODELS_DIR = path.join(EXE_AI_DIR, "models");
|
|
@@ -249,7 +287,7 @@ var init_config = __esm({
|
|
|
249
287
|
|
|
250
288
|
// src/lib/employees.ts
|
|
251
289
|
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
252
|
-
import { existsSync as
|
|
290
|
+
import { existsSync as existsSync3, symlinkSync, readlinkSync, readFileSync as readFileSync2, renameSync as renameSync2, unlinkSync, writeFileSync } from "fs";
|
|
253
291
|
import { execSync } from "child_process";
|
|
254
292
|
import path2 from "path";
|
|
255
293
|
import os2 from "os";
|
|
@@ -266,7 +304,7 @@ function getCoordinatorName(employees = loadEmployeesSync()) {
|
|
|
266
304
|
return getCoordinatorEmployee(employees)?.name ?? DEFAULT_COORDINATOR_TEMPLATE_NAME;
|
|
267
305
|
}
|
|
268
306
|
function loadEmployeesSync(employeesPath = EMPLOYEES_PATH) {
|
|
269
|
-
if (!
|
|
307
|
+
if (!existsSync3(employeesPath)) return [];
|
|
270
308
|
try {
|
|
271
309
|
return JSON.parse(readFileSync2(employeesPath, "utf-8"));
|
|
272
310
|
} catch {
|
|
@@ -1211,6 +1249,7 @@ async function ensureSchema() {
|
|
|
1211
1249
|
project TEXT NOT NULL,
|
|
1212
1250
|
summary TEXT NOT NULL,
|
|
1213
1251
|
task_file TEXT,
|
|
1252
|
+
session_scope TEXT,
|
|
1214
1253
|
read INTEGER NOT NULL DEFAULT 0,
|
|
1215
1254
|
created_at TEXT NOT NULL
|
|
1216
1255
|
);
|
|
@@ -1219,7 +1258,7 @@ async function ensureSchema() {
|
|
|
1219
1258
|
ON notifications(read);
|
|
1220
1259
|
|
|
1221
1260
|
CREATE INDEX IF NOT EXISTS idx_notifications_agent
|
|
1222
|
-
ON notifications(agent_id);
|
|
1261
|
+
ON notifications(agent_id, session_scope);
|
|
1223
1262
|
|
|
1224
1263
|
CREATE INDEX IF NOT EXISTS idx_notifications_task_file
|
|
1225
1264
|
ON notifications(task_file);
|
|
@@ -1257,6 +1296,7 @@ async function ensureSchema() {
|
|
|
1257
1296
|
target_agent TEXT NOT NULL,
|
|
1258
1297
|
target_project TEXT,
|
|
1259
1298
|
target_device TEXT NOT NULL DEFAULT 'local',
|
|
1299
|
+
session_scope TEXT,
|
|
1260
1300
|
content TEXT NOT NULL,
|
|
1261
1301
|
priority TEXT DEFAULT 'normal',
|
|
1262
1302
|
status TEXT DEFAULT 'pending',
|
|
@@ -1270,10 +1310,31 @@ async function ensureSchema() {
|
|
|
1270
1310
|
);
|
|
1271
1311
|
|
|
1272
1312
|
CREATE INDEX IF NOT EXISTS idx_messages_target
|
|
1273
|
-
ON messages(target_agent, status);
|
|
1313
|
+
ON messages(target_agent, session_scope, status);
|
|
1274
1314
|
|
|
1275
1315
|
CREATE INDEX IF NOT EXISTS idx_messages_conversation_order
|
|
1276
|
-
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);
|
|
1277
1338
|
`);
|
|
1278
1339
|
try {
|
|
1279
1340
|
await client.execute({
|
|
@@ -1857,6 +1918,13 @@ async function ensureSchema() {
|
|
|
1857
1918
|
} catch {
|
|
1858
1919
|
}
|
|
1859
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
|
+
}
|
|
1860
1928
|
}
|
|
1861
1929
|
var _client, _resilientClient, _walCheckpointTimer, _daemonClient, _adapterClient, initTurso;
|
|
1862
1930
|
var init_database = __esm({
|
|
@@ -1874,11 +1942,67 @@ var init_database = __esm({
|
|
|
1874
1942
|
}
|
|
1875
1943
|
});
|
|
1876
1944
|
|
|
1945
|
+
// src/lib/state-bus.ts
|
|
1946
|
+
var StateBus, orgBus;
|
|
1947
|
+
var init_state_bus = __esm({
|
|
1948
|
+
"src/lib/state-bus.ts"() {
|
|
1949
|
+
"use strict";
|
|
1950
|
+
StateBus = class {
|
|
1951
|
+
handlers = /* @__PURE__ */ new Map();
|
|
1952
|
+
globalHandlers = /* @__PURE__ */ new Set();
|
|
1953
|
+
/** Emit an event to all subscribers */
|
|
1954
|
+
emit(event) {
|
|
1955
|
+
const typeHandlers = this.handlers.get(event.type);
|
|
1956
|
+
if (typeHandlers) {
|
|
1957
|
+
for (const handler of typeHandlers) {
|
|
1958
|
+
try {
|
|
1959
|
+
handler(event);
|
|
1960
|
+
} catch {
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
for (const handler of this.globalHandlers) {
|
|
1965
|
+
try {
|
|
1966
|
+
handler(event);
|
|
1967
|
+
} catch {
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
/** Subscribe to a specific event type */
|
|
1972
|
+
on(type, handler) {
|
|
1973
|
+
if (!this.handlers.has(type)) {
|
|
1974
|
+
this.handlers.set(type, /* @__PURE__ */ new Set());
|
|
1975
|
+
}
|
|
1976
|
+
this.handlers.get(type).add(handler);
|
|
1977
|
+
}
|
|
1978
|
+
/** Subscribe to ALL events */
|
|
1979
|
+
onAny(handler) {
|
|
1980
|
+
this.globalHandlers.add(handler);
|
|
1981
|
+
}
|
|
1982
|
+
/** Unsubscribe from a specific event type */
|
|
1983
|
+
off(type, handler) {
|
|
1984
|
+
this.handlers.get(type)?.delete(handler);
|
|
1985
|
+
}
|
|
1986
|
+
/** Unsubscribe from ALL events */
|
|
1987
|
+
offAny(handler) {
|
|
1988
|
+
this.globalHandlers.delete(handler);
|
|
1989
|
+
}
|
|
1990
|
+
/** Remove all listeners */
|
|
1991
|
+
clear() {
|
|
1992
|
+
this.handlers.clear();
|
|
1993
|
+
this.globalHandlers.clear();
|
|
1994
|
+
}
|
|
1995
|
+
};
|
|
1996
|
+
orgBus = new StateBus();
|
|
1997
|
+
}
|
|
1998
|
+
});
|
|
1999
|
+
|
|
1877
2000
|
// src/lib/shard-manager.ts
|
|
1878
2001
|
var shard_manager_exports = {};
|
|
1879
2002
|
__export(shard_manager_exports, {
|
|
1880
2003
|
disposeShards: () => disposeShards,
|
|
1881
2004
|
ensureShardSchema: () => ensureShardSchema,
|
|
2005
|
+
getOpenShardCount: () => getOpenShardCount,
|
|
1882
2006
|
getReadyShardClient: () => getReadyShardClient,
|
|
1883
2007
|
getShardClient: () => getShardClient,
|
|
1884
2008
|
getShardsDir: () => getShardsDir,
|
|
@@ -1888,14 +2012,17 @@ __export(shard_manager_exports, {
|
|
|
1888
2012
|
shardExists: () => shardExists
|
|
1889
2013
|
});
|
|
1890
2014
|
import path5 from "path";
|
|
1891
|
-
import { existsSync as
|
|
2015
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync2, readdirSync } from "fs";
|
|
1892
2016
|
import { createClient as createClient2 } from "@libsql/client";
|
|
1893
2017
|
function initShardManager(encryptionKey) {
|
|
1894
2018
|
_encryptionKey = encryptionKey;
|
|
1895
|
-
if (!
|
|
1896
|
-
|
|
2019
|
+
if (!existsSync5(SHARDS_DIR)) {
|
|
2020
|
+
mkdirSync2(SHARDS_DIR, { recursive: true });
|
|
1897
2021
|
}
|
|
1898
2022
|
_shardingEnabled = true;
|
|
2023
|
+
if (_evictionTimer) clearInterval(_evictionTimer);
|
|
2024
|
+
_evictionTimer = setInterval(evictIdleShards, EVICTION_INTERVAL_MS);
|
|
2025
|
+
_evictionTimer.unref();
|
|
1899
2026
|
}
|
|
1900
2027
|
function isShardingEnabled() {
|
|
1901
2028
|
return _shardingEnabled;
|
|
@@ -1912,21 +2039,28 @@ function getShardClient(projectName) {
|
|
|
1912
2039
|
throw new Error(`Invalid project name for shard: "${projectName}"`);
|
|
1913
2040
|
}
|
|
1914
2041
|
const cached = _shards.get(safeName);
|
|
1915
|
-
if (cached)
|
|
2042
|
+
if (cached) {
|
|
2043
|
+
_shardLastAccess.set(safeName, Date.now());
|
|
2044
|
+
return cached;
|
|
2045
|
+
}
|
|
2046
|
+
while (_shards.size >= MAX_OPEN_SHARDS) {
|
|
2047
|
+
evictLRU();
|
|
2048
|
+
}
|
|
1916
2049
|
const dbPath = path5.join(SHARDS_DIR, `${safeName}.db`);
|
|
1917
2050
|
const client = createClient2({
|
|
1918
2051
|
url: `file:${dbPath}`,
|
|
1919
2052
|
encryptionKey: _encryptionKey
|
|
1920
2053
|
});
|
|
1921
2054
|
_shards.set(safeName, client);
|
|
2055
|
+
_shardLastAccess.set(safeName, Date.now());
|
|
1922
2056
|
return client;
|
|
1923
2057
|
}
|
|
1924
2058
|
function shardExists(projectName) {
|
|
1925
2059
|
const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1926
|
-
return
|
|
2060
|
+
return existsSync5(path5.join(SHARDS_DIR, `${safeName}.db`));
|
|
1927
2061
|
}
|
|
1928
2062
|
function listShards() {
|
|
1929
|
-
if (!
|
|
2063
|
+
if (!existsSync5(SHARDS_DIR)) return [];
|
|
1930
2064
|
return readdirSync(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
|
|
1931
2065
|
}
|
|
1932
2066
|
async function ensureShardSchema(client) {
|
|
@@ -1978,6 +2112,8 @@ async function ensureShardSchema(client) {
|
|
|
1978
2112
|
for (const col of [
|
|
1979
2113
|
"ALTER TABLE memories ADD COLUMN task_id TEXT",
|
|
1980
2114
|
"ALTER TABLE memories ADD COLUMN consolidated INTEGER NOT NULL DEFAULT 0",
|
|
2115
|
+
"ALTER TABLE memories ADD COLUMN author_device_id TEXT",
|
|
2116
|
+
"ALTER TABLE memories ADD COLUMN scope TEXT NOT NULL DEFAULT 'business'",
|
|
1981
2117
|
"ALTER TABLE memories ADD COLUMN importance INTEGER DEFAULT 5",
|
|
1982
2118
|
"ALTER TABLE memories ADD COLUMN status TEXT DEFAULT 'active'",
|
|
1983
2119
|
"ALTER TABLE memories ADD COLUMN wiki_synced INTEGER DEFAULT 0",
|
|
@@ -2115,21 +2251,69 @@ async function getReadyShardClient(projectName) {
|
|
|
2115
2251
|
await ensureShardSchema(client);
|
|
2116
2252
|
return client;
|
|
2117
2253
|
}
|
|
2254
|
+
function evictLRU() {
|
|
2255
|
+
let oldest = null;
|
|
2256
|
+
let oldestTime = Infinity;
|
|
2257
|
+
for (const [name, time] of _shardLastAccess) {
|
|
2258
|
+
if (time < oldestTime) {
|
|
2259
|
+
oldestTime = time;
|
|
2260
|
+
oldest = name;
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
if (oldest) {
|
|
2264
|
+
const client = _shards.get(oldest);
|
|
2265
|
+
if (client) {
|
|
2266
|
+
client.close();
|
|
2267
|
+
}
|
|
2268
|
+
_shards.delete(oldest);
|
|
2269
|
+
_shardLastAccess.delete(oldest);
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
function evictIdleShards() {
|
|
2273
|
+
const now = Date.now();
|
|
2274
|
+
const toEvict = [];
|
|
2275
|
+
for (const [name, lastAccess] of _shardLastAccess) {
|
|
2276
|
+
if (now - lastAccess > SHARD_IDLE_MS) {
|
|
2277
|
+
toEvict.push(name);
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
for (const name of toEvict) {
|
|
2281
|
+
const client = _shards.get(name);
|
|
2282
|
+
if (client) {
|
|
2283
|
+
client.close();
|
|
2284
|
+
}
|
|
2285
|
+
_shards.delete(name);
|
|
2286
|
+
_shardLastAccess.delete(name);
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
function getOpenShardCount() {
|
|
2290
|
+
return _shards.size;
|
|
2291
|
+
}
|
|
2118
2292
|
function disposeShards() {
|
|
2293
|
+
if (_evictionTimer) {
|
|
2294
|
+
clearInterval(_evictionTimer);
|
|
2295
|
+
_evictionTimer = null;
|
|
2296
|
+
}
|
|
2119
2297
|
for (const [, client] of _shards) {
|
|
2120
2298
|
client.close();
|
|
2121
2299
|
}
|
|
2122
2300
|
_shards.clear();
|
|
2301
|
+
_shardLastAccess.clear();
|
|
2123
2302
|
_shardingEnabled = false;
|
|
2124
2303
|
_encryptionKey = null;
|
|
2125
2304
|
}
|
|
2126
|
-
var SHARDS_DIR, _shards, _encryptionKey, _shardingEnabled;
|
|
2305
|
+
var SHARDS_DIR, SHARD_IDLE_MS, MAX_OPEN_SHARDS, EVICTION_INTERVAL_MS, _shards, _shardLastAccess, _evictionTimer, _encryptionKey, _shardingEnabled;
|
|
2127
2306
|
var init_shard_manager = __esm({
|
|
2128
2307
|
"src/lib/shard-manager.ts"() {
|
|
2129
2308
|
"use strict";
|
|
2130
2309
|
init_config();
|
|
2131
2310
|
SHARDS_DIR = path5.join(EXE_AI_DIR, "shards");
|
|
2311
|
+
SHARD_IDLE_MS = 5 * 60 * 1e3;
|
|
2312
|
+
MAX_OPEN_SHARDS = 10;
|
|
2313
|
+
EVICTION_INTERVAL_MS = 60 * 1e3;
|
|
2132
2314
|
_shards = /* @__PURE__ */ new Map();
|
|
2315
|
+
_shardLastAccess = /* @__PURE__ */ new Map();
|
|
2316
|
+
_evictionTimer = null;
|
|
2133
2317
|
_encryptionKey = null;
|
|
2134
2318
|
_shardingEnabled = false;
|
|
2135
2319
|
}
|
|
@@ -2322,13 +2506,477 @@ ${p.content}`).join("\n\n");
|
|
|
2322
2506
|
}
|
|
2323
2507
|
});
|
|
2324
2508
|
|
|
2509
|
+
// src/lib/session-registry.ts
|
|
2510
|
+
import path6 from "path";
|
|
2511
|
+
import os5 from "os";
|
|
2512
|
+
var REGISTRY_PATH;
|
|
2513
|
+
var init_session_registry = __esm({
|
|
2514
|
+
"src/lib/session-registry.ts"() {
|
|
2515
|
+
"use strict";
|
|
2516
|
+
REGISTRY_PATH = path6.join(os5.homedir(), ".exe-os", "session-registry.json");
|
|
2517
|
+
}
|
|
2518
|
+
});
|
|
2519
|
+
|
|
2520
|
+
// src/lib/session-key.ts
|
|
2521
|
+
import { execSync as execSync2 } from "child_process";
|
|
2522
|
+
function normalizeCommand(command) {
|
|
2523
|
+
const trimmed = command.trim().toLowerCase();
|
|
2524
|
+
const parts = trimmed.split(/[\\/]/);
|
|
2525
|
+
return parts[parts.length - 1] ?? trimmed;
|
|
2526
|
+
}
|
|
2527
|
+
function detectRuntimeFromCommand(command) {
|
|
2528
|
+
const normalized = normalizeCommand(command);
|
|
2529
|
+
for (const [runtime, commands] of Object.entries(RUNTIME_COMMANDS)) {
|
|
2530
|
+
if (commands.includes(normalized)) {
|
|
2531
|
+
return runtime;
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
return null;
|
|
2535
|
+
}
|
|
2536
|
+
function resolveRuntimeProcess() {
|
|
2537
|
+
let pid = process.ppid;
|
|
2538
|
+
for (let i = 0; i < 10; i++) {
|
|
2539
|
+
try {
|
|
2540
|
+
const info = execSync2(`ps -p ${pid} -o ppid=,comm=`, {
|
|
2541
|
+
encoding: "utf8",
|
|
2542
|
+
timeout: 2e3
|
|
2543
|
+
}).trim();
|
|
2544
|
+
const match = info.match(/^\s*(\d+)\s+(.+)$/);
|
|
2545
|
+
if (!match) break;
|
|
2546
|
+
const [, ppid, cmd] = match;
|
|
2547
|
+
const runtime = detectRuntimeFromCommand(cmd ?? "");
|
|
2548
|
+
if (runtime) {
|
|
2549
|
+
return { pid: String(pid), runtime };
|
|
2550
|
+
}
|
|
2551
|
+
pid = parseInt(ppid, 10);
|
|
2552
|
+
if (pid <= 1) break;
|
|
2553
|
+
} catch {
|
|
2554
|
+
break;
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
return null;
|
|
2558
|
+
}
|
|
2559
|
+
function getSessionKey() {
|
|
2560
|
+
if (_cached) return _cached;
|
|
2561
|
+
if (process.env.EXE_SESSION_KEY) {
|
|
2562
|
+
_cached = process.env.EXE_SESSION_KEY;
|
|
2563
|
+
return _cached;
|
|
2564
|
+
}
|
|
2565
|
+
const resolved = resolveRuntimeProcess();
|
|
2566
|
+
if (resolved) {
|
|
2567
|
+
_cachedRuntime = resolved.runtime;
|
|
2568
|
+
_cached = resolved.pid;
|
|
2569
|
+
return _cached;
|
|
2570
|
+
}
|
|
2571
|
+
_cached = process.env.CLAUDE_CODE_SSE_PORT ?? String(process.ppid);
|
|
2572
|
+
return _cached;
|
|
2573
|
+
}
|
|
2574
|
+
var _cached, _cachedRuntime, RUNTIME_COMMANDS;
|
|
2575
|
+
var init_session_key = __esm({
|
|
2576
|
+
"src/lib/session-key.ts"() {
|
|
2577
|
+
"use strict";
|
|
2578
|
+
_cached = null;
|
|
2579
|
+
_cachedRuntime = null;
|
|
2580
|
+
RUNTIME_COMMANDS = {
|
|
2581
|
+
claude: ["claude", "claude.exe", "claude-native"],
|
|
2582
|
+
codex: ["codex"],
|
|
2583
|
+
opencode: ["opencode"]
|
|
2584
|
+
};
|
|
2585
|
+
}
|
|
2586
|
+
});
|
|
2587
|
+
|
|
2588
|
+
// src/lib/tmux-transport.ts
|
|
2589
|
+
var tmux_transport_exports = {};
|
|
2590
|
+
__export(tmux_transport_exports, {
|
|
2591
|
+
TmuxTransport: () => TmuxTransport
|
|
2592
|
+
});
|
|
2593
|
+
import { execFileSync } from "child_process";
|
|
2594
|
+
var QUIET, TmuxTransport;
|
|
2595
|
+
var init_tmux_transport = __esm({
|
|
2596
|
+
"src/lib/tmux-transport.ts"() {
|
|
2597
|
+
"use strict";
|
|
2598
|
+
QUIET = {
|
|
2599
|
+
encoding: "utf8",
|
|
2600
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
2601
|
+
};
|
|
2602
|
+
TmuxTransport = class {
|
|
2603
|
+
getMySession() {
|
|
2604
|
+
try {
|
|
2605
|
+
return execFileSync("tmux", ["display-message", "-p", "#{session_name}"], QUIET).trim() || null;
|
|
2606
|
+
} catch {
|
|
2607
|
+
return null;
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
listSessions() {
|
|
2611
|
+
try {
|
|
2612
|
+
return execFileSync("tmux", ["list-sessions", "-F", "#{session_name}"], QUIET).trim().split("\n").filter(Boolean);
|
|
2613
|
+
} catch {
|
|
2614
|
+
return [];
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
isAlive(target) {
|
|
2618
|
+
try {
|
|
2619
|
+
const sessions = this.listSessions();
|
|
2620
|
+
if (!sessions.includes(target)) return false;
|
|
2621
|
+
const paneStatus = execFileSync(
|
|
2622
|
+
"tmux",
|
|
2623
|
+
["list-panes", "-t", target, "-F", "#{pane_dead}"],
|
|
2624
|
+
QUIET
|
|
2625
|
+
).trim();
|
|
2626
|
+
return paneStatus !== "1";
|
|
2627
|
+
} catch {
|
|
2628
|
+
return false;
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
sendKeys(target, keys) {
|
|
2632
|
+
execFileSync("tmux", ["send-keys", "-t", target, keys, "Enter"], QUIET);
|
|
2633
|
+
}
|
|
2634
|
+
capturePane(target, lines) {
|
|
2635
|
+
const args = ["capture-pane", "-t", target, "-p"];
|
|
2636
|
+
if (lines) args.push("-S", `-${lines}`);
|
|
2637
|
+
return execFileSync("tmux", args, { ...QUIET, timeout: 3e3 });
|
|
2638
|
+
}
|
|
2639
|
+
isPaneInCopyMode(target) {
|
|
2640
|
+
try {
|
|
2641
|
+
const result = execFileSync(
|
|
2642
|
+
"tmux",
|
|
2643
|
+
["display-message", "-p", "-t", target, "#{pane_in_mode}"],
|
|
2644
|
+
{ ...QUIET, timeout: 3e3 }
|
|
2645
|
+
).trim();
|
|
2646
|
+
return result === "1";
|
|
2647
|
+
} catch {
|
|
2648
|
+
return false;
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
spawn(name, config) {
|
|
2652
|
+
try {
|
|
2653
|
+
const args = ["new-session", "-d", "-s", name];
|
|
2654
|
+
if (config.cwd) args.push("-c", config.cwd);
|
|
2655
|
+
args.push(config.command);
|
|
2656
|
+
execFileSync("tmux", args);
|
|
2657
|
+
return { sessionName: name };
|
|
2658
|
+
} catch (e) {
|
|
2659
|
+
return { sessionName: name, error: `spawn failed: ${e}` };
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
kill(target) {
|
|
2663
|
+
try {
|
|
2664
|
+
execFileSync("tmux", ["kill-session", "-t", target], QUIET);
|
|
2665
|
+
} catch {
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
pipeLog(target, logFile) {
|
|
2669
|
+
try {
|
|
2670
|
+
const safePath = logFile.replace(/'/g, "'\\''");
|
|
2671
|
+
execFileSync("tmux", ["pipe-pane", "-t", target, `cat >> '${safePath}'`], QUIET);
|
|
2672
|
+
} catch {
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
};
|
|
2676
|
+
}
|
|
2677
|
+
});
|
|
2678
|
+
|
|
2679
|
+
// src/lib/transport.ts
|
|
2680
|
+
function getTransport() {
|
|
2681
|
+
if (!_transport) {
|
|
2682
|
+
const { TmuxTransport: TmuxTransport2 } = (init_tmux_transport(), __toCommonJS(tmux_transport_exports));
|
|
2683
|
+
_transport = new TmuxTransport2();
|
|
2684
|
+
}
|
|
2685
|
+
return _transport;
|
|
2686
|
+
}
|
|
2687
|
+
var _transport;
|
|
2688
|
+
var init_transport = __esm({
|
|
2689
|
+
"src/lib/transport.ts"() {
|
|
2690
|
+
"use strict";
|
|
2691
|
+
_transport = null;
|
|
2692
|
+
}
|
|
2693
|
+
});
|
|
2694
|
+
|
|
2695
|
+
// src/lib/cc-agent-support.ts
|
|
2696
|
+
import { execSync as execSync3 } from "child_process";
|
|
2697
|
+
var init_cc_agent_support = __esm({
|
|
2698
|
+
"src/lib/cc-agent-support.ts"() {
|
|
2699
|
+
"use strict";
|
|
2700
|
+
}
|
|
2701
|
+
});
|
|
2702
|
+
|
|
2703
|
+
// src/lib/mcp-prefix.ts
|
|
2704
|
+
var MCP_PRIMARY_KEY, MCP_LEGACY_KEY, MCP_TOOL_PREFIXES;
|
|
2705
|
+
var init_mcp_prefix = __esm({
|
|
2706
|
+
"src/lib/mcp-prefix.ts"() {
|
|
2707
|
+
"use strict";
|
|
2708
|
+
MCP_PRIMARY_KEY = "exe-os";
|
|
2709
|
+
MCP_LEGACY_KEY = "exe-mem";
|
|
2710
|
+
MCP_TOOL_PREFIXES = [
|
|
2711
|
+
`mcp__${MCP_PRIMARY_KEY}__`,
|
|
2712
|
+
`mcp__${MCP_LEGACY_KEY}__`
|
|
2713
|
+
];
|
|
2714
|
+
}
|
|
2715
|
+
});
|
|
2716
|
+
|
|
2717
|
+
// src/lib/provider-table.ts
|
|
2718
|
+
var init_provider_table = __esm({
|
|
2719
|
+
"src/lib/provider-table.ts"() {
|
|
2720
|
+
"use strict";
|
|
2721
|
+
}
|
|
2722
|
+
});
|
|
2723
|
+
|
|
2724
|
+
// src/lib/runtime-table.ts
|
|
2725
|
+
var RUNTIME_TABLE;
|
|
2726
|
+
var init_runtime_table = __esm({
|
|
2727
|
+
"src/lib/runtime-table.ts"() {
|
|
2728
|
+
"use strict";
|
|
2729
|
+
RUNTIME_TABLE = {
|
|
2730
|
+
codex: {
|
|
2731
|
+
binary: "codex",
|
|
2732
|
+
launchMode: "interactive",
|
|
2733
|
+
autoApproveFlag: "--dangerously-bypass-approvals-and-sandbox",
|
|
2734
|
+
inlineFlag: "--no-alt-screen",
|
|
2735
|
+
apiKeyEnv: "OPENAI_API_KEY",
|
|
2736
|
+
defaultModel: "gpt-5.4"
|
|
2737
|
+
},
|
|
2738
|
+
opencode: {
|
|
2739
|
+
binary: "opencode",
|
|
2740
|
+
launchMode: "exec",
|
|
2741
|
+
autoApproveFlag: "--dangerously-skip-permissions",
|
|
2742
|
+
inlineFlag: "",
|
|
2743
|
+
apiKeyEnv: "ANTHROPIC_API_KEY",
|
|
2744
|
+
defaultModel: "anthropic/claude-sonnet-4-6"
|
|
2745
|
+
}
|
|
2746
|
+
};
|
|
2747
|
+
}
|
|
2748
|
+
});
|
|
2749
|
+
|
|
2750
|
+
// src/lib/agent-config.ts
|
|
2751
|
+
import { readFileSync as readFileSync3, writeFileSync as writeFileSync2, existsSync as existsSync6 } from "fs";
|
|
2752
|
+
import path7 from "path";
|
|
2753
|
+
var AGENT_CONFIG_PATH, DEFAULT_MODELS;
|
|
2754
|
+
var init_agent_config = __esm({
|
|
2755
|
+
"src/lib/agent-config.ts"() {
|
|
2756
|
+
"use strict";
|
|
2757
|
+
init_config();
|
|
2758
|
+
init_runtime_table();
|
|
2759
|
+
init_secure_files();
|
|
2760
|
+
AGENT_CONFIG_PATH = path7.join(EXE_AI_DIR, "agent-config.json");
|
|
2761
|
+
DEFAULT_MODELS = {
|
|
2762
|
+
claude: "claude-opus-4",
|
|
2763
|
+
codex: RUNTIME_TABLE.codex?.defaultModel ?? "gpt-5.4",
|
|
2764
|
+
opencode: RUNTIME_TABLE.opencode?.defaultModel ?? "anthropic/claude-sonnet-4-6"
|
|
2765
|
+
};
|
|
2766
|
+
}
|
|
2767
|
+
});
|
|
2768
|
+
|
|
2769
|
+
// src/lib/intercom-queue.ts
|
|
2770
|
+
import { readFileSync as readFileSync4, writeFileSync as writeFileSync3, renameSync as renameSync3, existsSync as existsSync7, mkdirSync as mkdirSync3 } from "fs";
|
|
2771
|
+
import path8 from "path";
|
|
2772
|
+
import os6 from "os";
|
|
2773
|
+
var QUEUE_PATH, TTL_MS, INTERCOM_LOG;
|
|
2774
|
+
var init_intercom_queue = __esm({
|
|
2775
|
+
"src/lib/intercom-queue.ts"() {
|
|
2776
|
+
"use strict";
|
|
2777
|
+
QUEUE_PATH = path8.join(os6.homedir(), ".exe-os", "intercom-queue.json");
|
|
2778
|
+
TTL_MS = 60 * 60 * 1e3;
|
|
2779
|
+
INTERCOM_LOG = path8.join(os6.homedir(), ".exe-os", "intercom.log");
|
|
2780
|
+
}
|
|
2781
|
+
});
|
|
2782
|
+
|
|
2783
|
+
// src/lib/license.ts
|
|
2784
|
+
import { readFileSync as readFileSync5, writeFileSync as writeFileSync4, existsSync as existsSync8, mkdirSync as mkdirSync4 } from "fs";
|
|
2785
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
2786
|
+
import { createRequire as createRequire2 } from "module";
|
|
2787
|
+
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
2788
|
+
import os7 from "os";
|
|
2789
|
+
import path9 from "path";
|
|
2790
|
+
import { jwtVerify, importSPKI } from "jose";
|
|
2791
|
+
var LICENSE_PATH, CACHE_PATH, DEVICE_ID_PATH;
|
|
2792
|
+
var init_license = __esm({
|
|
2793
|
+
"src/lib/license.ts"() {
|
|
2794
|
+
"use strict";
|
|
2795
|
+
init_config();
|
|
2796
|
+
LICENSE_PATH = path9.join(EXE_AI_DIR, "license.key");
|
|
2797
|
+
CACHE_PATH = path9.join(EXE_AI_DIR, "license-cache.json");
|
|
2798
|
+
DEVICE_ID_PATH = path9.join(EXE_AI_DIR, "device-id");
|
|
2799
|
+
}
|
|
2800
|
+
});
|
|
2801
|
+
|
|
2802
|
+
// src/lib/plan-limits.ts
|
|
2803
|
+
import { readFileSync as readFileSync6, existsSync as existsSync9 } from "fs";
|
|
2804
|
+
import path10 from "path";
|
|
2805
|
+
var CACHE_PATH2;
|
|
2806
|
+
var init_plan_limits = __esm({
|
|
2807
|
+
"src/lib/plan-limits.ts"() {
|
|
2808
|
+
"use strict";
|
|
2809
|
+
init_database();
|
|
2810
|
+
init_employees();
|
|
2811
|
+
init_license();
|
|
2812
|
+
init_config();
|
|
2813
|
+
CACHE_PATH2 = path10.join(EXE_AI_DIR, "license-cache.json");
|
|
2814
|
+
}
|
|
2815
|
+
});
|
|
2816
|
+
|
|
2817
|
+
// src/lib/tmux-routing.ts
|
|
2818
|
+
import { readFileSync as readFileSync7, writeFileSync as writeFileSync5, mkdirSync as mkdirSync5, existsSync as existsSync10, appendFileSync, readdirSync as readdirSync2 } from "fs";
|
|
2819
|
+
import path11 from "path";
|
|
2820
|
+
import os8 from "os";
|
|
2821
|
+
import { fileURLToPath } from "url";
|
|
2822
|
+
function getMySession() {
|
|
2823
|
+
return getTransport().getMySession();
|
|
2824
|
+
}
|
|
2825
|
+
function extractRootExe(name) {
|
|
2826
|
+
if (!name) return null;
|
|
2827
|
+
if (!name.includes("-")) return name;
|
|
2828
|
+
const parts = name.split("-").filter(Boolean);
|
|
2829
|
+
return parts.length > 0 ? parts[parts.length - 1] : null;
|
|
2830
|
+
}
|
|
2831
|
+
function getParentExe(sessionKey) {
|
|
2832
|
+
try {
|
|
2833
|
+
const data = JSON.parse(readFileSync7(path11.join(SESSION_CACHE, `parent-exe-${sessionKey}.json`), "utf8"));
|
|
2834
|
+
return data.parentExe || null;
|
|
2835
|
+
} catch {
|
|
2836
|
+
return null;
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2839
|
+
function resolveExeSession() {
|
|
2840
|
+
const mySession = getMySession();
|
|
2841
|
+
if (!mySession) return null;
|
|
2842
|
+
const fromSessionName = extractRootExe(mySession);
|
|
2843
|
+
try {
|
|
2844
|
+
const key = getSessionKey();
|
|
2845
|
+
const parentExe = getParentExe(key);
|
|
2846
|
+
if (parentExe) {
|
|
2847
|
+
const fromCache = extractRootExe(parentExe) ?? parentExe;
|
|
2848
|
+
if (fromSessionName && fromCache !== fromSessionName) {
|
|
2849
|
+
process.stderr.write(
|
|
2850
|
+
`[tmux-routing] WARN: cache says "${fromCache}" but session name says "${fromSessionName}". Trusting session name.
|
|
2851
|
+
`
|
|
2852
|
+
);
|
|
2853
|
+
return fromSessionName;
|
|
2854
|
+
}
|
|
2855
|
+
return fromCache;
|
|
2856
|
+
}
|
|
2857
|
+
} catch {
|
|
2858
|
+
}
|
|
2859
|
+
return fromSessionName ?? mySession;
|
|
2860
|
+
}
|
|
2861
|
+
var SPAWN_LOCK_DIR, SESSION_CACHE, INTERCOM_LOG2, DEBOUNCE_FILE, DEBOUNCE_CLEANUP_AGE_MS;
|
|
2862
|
+
var init_tmux_routing = __esm({
|
|
2863
|
+
"src/lib/tmux-routing.ts"() {
|
|
2864
|
+
"use strict";
|
|
2865
|
+
init_session_registry();
|
|
2866
|
+
init_session_key();
|
|
2867
|
+
init_transport();
|
|
2868
|
+
init_cc_agent_support();
|
|
2869
|
+
init_mcp_prefix();
|
|
2870
|
+
init_provider_table();
|
|
2871
|
+
init_agent_config();
|
|
2872
|
+
init_runtime_table();
|
|
2873
|
+
init_intercom_queue();
|
|
2874
|
+
init_plan_limits();
|
|
2875
|
+
init_employees();
|
|
2876
|
+
SPAWN_LOCK_DIR = path11.join(os8.homedir(), ".exe-os", "spawn-locks");
|
|
2877
|
+
SESSION_CACHE = path11.join(os8.homedir(), ".exe-os", "session-cache");
|
|
2878
|
+
INTERCOM_LOG2 = path11.join(os8.homedir(), ".exe-os", "intercom.log");
|
|
2879
|
+
DEBOUNCE_FILE = path11.join(SESSION_CACHE, "intercom-debounce.json");
|
|
2880
|
+
DEBOUNCE_CLEANUP_AGE_MS = 5 * 60 * 1e3;
|
|
2881
|
+
}
|
|
2882
|
+
});
|
|
2883
|
+
|
|
2884
|
+
// src/lib/task-scope.ts
|
|
2885
|
+
function getCurrentSessionScope() {
|
|
2886
|
+
try {
|
|
2887
|
+
return resolveExeSession();
|
|
2888
|
+
} catch {
|
|
2889
|
+
return null;
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
2892
|
+
function strictSessionScopeFilter(sessionScope, tableAlias) {
|
|
2893
|
+
const scope = sessionScope !== void 0 ? sessionScope : getCurrentSessionScope();
|
|
2894
|
+
if (!scope) return { sql: "", args: [] };
|
|
2895
|
+
const col = tableAlias ? `${tableAlias}.session_scope` : "session_scope";
|
|
2896
|
+
return {
|
|
2897
|
+
sql: ` AND ${col} = ?`,
|
|
2898
|
+
args: [scope]
|
|
2899
|
+
};
|
|
2900
|
+
}
|
|
2901
|
+
var init_task_scope = __esm({
|
|
2902
|
+
"src/lib/task-scope.ts"() {
|
|
2903
|
+
"use strict";
|
|
2904
|
+
init_tmux_routing();
|
|
2905
|
+
}
|
|
2906
|
+
});
|
|
2907
|
+
|
|
2908
|
+
// src/lib/notifications.ts
|
|
2909
|
+
import crypto from "crypto";
|
|
2910
|
+
import path12 from "path";
|
|
2911
|
+
import os9 from "os";
|
|
2912
|
+
import {
|
|
2913
|
+
readFileSync as readFileSync8,
|
|
2914
|
+
readdirSync as readdirSync3,
|
|
2915
|
+
unlinkSync as unlinkSync2,
|
|
2916
|
+
existsSync as existsSync11,
|
|
2917
|
+
rmdirSync
|
|
2918
|
+
} from "fs";
|
|
2919
|
+
async function readUnreadNotifications(agentFilter, sessionScope) {
|
|
2920
|
+
try {
|
|
2921
|
+
const client = getClient();
|
|
2922
|
+
const conditions = ["read = 0"];
|
|
2923
|
+
const args = [];
|
|
2924
|
+
const scope = strictSessionScopeFilter(sessionScope);
|
|
2925
|
+
if (agentFilter) {
|
|
2926
|
+
conditions.push("agent_id = ?");
|
|
2927
|
+
args.push(agentFilter);
|
|
2928
|
+
}
|
|
2929
|
+
const result = await client.execute({
|
|
2930
|
+
sql: `SELECT id, agent_id, agent_role, event, project, summary, task_file, session_scope, created_at
|
|
2931
|
+
FROM notifications
|
|
2932
|
+
WHERE ${conditions.join(" AND ")}${scope.sql}
|
|
2933
|
+
ORDER BY created_at ASC`,
|
|
2934
|
+
args: [...args, ...scope.args]
|
|
2935
|
+
});
|
|
2936
|
+
return result.rows.map((r) => ({
|
|
2937
|
+
id: String(r.id),
|
|
2938
|
+
agentId: String(r.agent_id),
|
|
2939
|
+
agentRole: String(r.agent_role),
|
|
2940
|
+
event: String(r.event),
|
|
2941
|
+
project: String(r.project),
|
|
2942
|
+
summary: String(r.summary),
|
|
2943
|
+
taskFile: r.task_file ? String(r.task_file) : void 0,
|
|
2944
|
+
sessionScope: r.session_scope == null ? null : String(r.session_scope),
|
|
2945
|
+
timestamp: String(r.created_at),
|
|
2946
|
+
read: false
|
|
2947
|
+
}));
|
|
2948
|
+
} catch {
|
|
2949
|
+
return [];
|
|
2950
|
+
}
|
|
2951
|
+
}
|
|
2952
|
+
async function markAsRead(ids, sessionScope) {
|
|
2953
|
+
if (ids.length === 0) return;
|
|
2954
|
+
try {
|
|
2955
|
+
const client = getClient();
|
|
2956
|
+
const placeholders = ids.map(() => "?").join(", ");
|
|
2957
|
+
const scope = strictSessionScopeFilter(sessionScope);
|
|
2958
|
+
await client.execute({
|
|
2959
|
+
sql: `UPDATE notifications SET read = 1 WHERE id IN (${placeholders})${scope.sql}`,
|
|
2960
|
+
args: [...ids, ...scope.args]
|
|
2961
|
+
});
|
|
2962
|
+
} catch {
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
var init_notifications = __esm({
|
|
2966
|
+
"src/lib/notifications.ts"() {
|
|
2967
|
+
"use strict";
|
|
2968
|
+
init_database();
|
|
2969
|
+
init_task_scope();
|
|
2970
|
+
}
|
|
2971
|
+
});
|
|
2972
|
+
|
|
2325
2973
|
// src/lib/store.ts
|
|
2326
2974
|
import { createHash } from "crypto";
|
|
2327
2975
|
init_database();
|
|
2328
2976
|
|
|
2329
2977
|
// src/lib/keychain.ts
|
|
2330
2978
|
import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
|
|
2331
|
-
import { existsSync as
|
|
2979
|
+
import { existsSync as existsSync4 } from "fs";
|
|
2332
2980
|
import path4 from "path";
|
|
2333
2981
|
import os4 from "os";
|
|
2334
2982
|
var SERVICE = "exe-mem";
|
|
@@ -2358,7 +3006,7 @@ async function getMasterKey() {
|
|
|
2358
3006
|
}
|
|
2359
3007
|
}
|
|
2360
3008
|
const keyPath = getKeyPath();
|
|
2361
|
-
if (!
|
|
3009
|
+
if (!existsSync4(keyPath)) {
|
|
2362
3010
|
process.stderr.write(
|
|
2363
3011
|
`[keychain] Key not found at ${keyPath} (HOME=${os4.homedir()}, EXE_OS_DIR=${process.env.EXE_OS_DIR ?? "unset"})
|
|
2364
3012
|
`
|
|
@@ -2379,57 +3027,7 @@ async function getMasterKey() {
|
|
|
2379
3027
|
|
|
2380
3028
|
// src/lib/store.ts
|
|
2381
3029
|
init_config();
|
|
2382
|
-
|
|
2383
|
-
// src/lib/state-bus.ts
|
|
2384
|
-
var StateBus = class {
|
|
2385
|
-
handlers = /* @__PURE__ */ new Map();
|
|
2386
|
-
globalHandlers = /* @__PURE__ */ new Set();
|
|
2387
|
-
/** Emit an event to all subscribers */
|
|
2388
|
-
emit(event) {
|
|
2389
|
-
const typeHandlers = this.handlers.get(event.type);
|
|
2390
|
-
if (typeHandlers) {
|
|
2391
|
-
for (const handler of typeHandlers) {
|
|
2392
|
-
try {
|
|
2393
|
-
handler(event);
|
|
2394
|
-
} catch {
|
|
2395
|
-
}
|
|
2396
|
-
}
|
|
2397
|
-
}
|
|
2398
|
-
for (const handler of this.globalHandlers) {
|
|
2399
|
-
try {
|
|
2400
|
-
handler(event);
|
|
2401
|
-
} catch {
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2404
|
-
}
|
|
2405
|
-
/** Subscribe to a specific event type */
|
|
2406
|
-
on(type, handler) {
|
|
2407
|
-
if (!this.handlers.has(type)) {
|
|
2408
|
-
this.handlers.set(type, /* @__PURE__ */ new Set());
|
|
2409
|
-
}
|
|
2410
|
-
this.handlers.get(type).add(handler);
|
|
2411
|
-
}
|
|
2412
|
-
/** Subscribe to ALL events */
|
|
2413
|
-
onAny(handler) {
|
|
2414
|
-
this.globalHandlers.add(handler);
|
|
2415
|
-
}
|
|
2416
|
-
/** Unsubscribe from a specific event type */
|
|
2417
|
-
off(type, handler) {
|
|
2418
|
-
this.handlers.get(type)?.delete(handler);
|
|
2419
|
-
}
|
|
2420
|
-
/** Unsubscribe from ALL events */
|
|
2421
|
-
offAny(handler) {
|
|
2422
|
-
this.globalHandlers.delete(handler);
|
|
2423
|
-
}
|
|
2424
|
-
/** Remove all listeners */
|
|
2425
|
-
clear() {
|
|
2426
|
-
this.handlers.clear();
|
|
2427
|
-
this.globalHandlers.clear();
|
|
2428
|
-
}
|
|
2429
|
-
};
|
|
2430
|
-
var orgBus = new StateBus();
|
|
2431
|
-
|
|
2432
|
-
// src/lib/store.ts
|
|
3030
|
+
init_state_bus();
|
|
2433
3031
|
var INIT_MAX_RETRIES = 3;
|
|
2434
3032
|
var INIT_RETRY_DELAY_MS = 1e3;
|
|
2435
3033
|
function isBusyError2(err) {
|
|
@@ -2510,17 +3108,17 @@ async function initStore(options) {
|
|
|
2510
3108
|
}
|
|
2511
3109
|
|
|
2512
3110
|
// src/bin/exe-pending-notifications.ts
|
|
2513
|
-
|
|
3111
|
+
init_notifications();
|
|
2514
3112
|
|
|
2515
3113
|
// src/lib/is-main.ts
|
|
2516
3114
|
import { realpathSync } from "fs";
|
|
2517
|
-
import { fileURLToPath } from "url";
|
|
3115
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
2518
3116
|
function isMainModule(importMetaUrl) {
|
|
2519
3117
|
if (process.argv[1] == null) return false;
|
|
2520
3118
|
if (process.argv[1].includes("mcp/server")) return false;
|
|
2521
3119
|
try {
|
|
2522
3120
|
const scriptPath = realpathSync(process.argv[1]);
|
|
2523
|
-
const modulePath = realpathSync(
|
|
3121
|
+
const modulePath = realpathSync(fileURLToPath2(importMetaUrl));
|
|
2524
3122
|
return scriptPath === modulePath;
|
|
2525
3123
|
} catch {
|
|
2526
3124
|
return importMetaUrl === `file://${process.argv[1]}` || importMetaUrl === new URL(process.argv[1], "file://").href;
|
|
@@ -2528,7 +3126,6 @@ function isMainModule(importMetaUrl) {
|
|
|
2528
3126
|
}
|
|
2529
3127
|
|
|
2530
3128
|
// src/bin/exe-pending-notifications.ts
|
|
2531
|
-
var RECENT_WINDOW = "-24 hours";
|
|
2532
3129
|
function formatLine(row) {
|
|
2533
3130
|
switch (row.event) {
|
|
2534
3131
|
case "subtasks_complete":
|
|
@@ -2563,38 +3160,26 @@ async function main() {
|
|
|
2563
3160
|
process.exit(0);
|
|
2564
3161
|
}
|
|
2565
3162
|
await initStore();
|
|
2566
|
-
const
|
|
2567
|
-
const
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
});
|
|
2576
|
-
if (
|
|
3163
|
+
const notifications = await readUnreadNotifications(agentId);
|
|
3164
|
+
const recentCutoff = Date.now() - 24 * 60 * 60 * 1e3;
|
|
3165
|
+
const pending = notifications.filter((row) => new Date(row.timestamp).getTime() > recentCutoff).map((row) => ({
|
|
3166
|
+
id: row.id,
|
|
3167
|
+
event: row.event,
|
|
3168
|
+
project: row.project,
|
|
3169
|
+
summary: row.summary,
|
|
3170
|
+
task_file: row.taskFile ?? null,
|
|
3171
|
+
created_at: row.timestamp
|
|
3172
|
+
}));
|
|
3173
|
+
if (pending.length === 0) {
|
|
2577
3174
|
process.exit(0);
|
|
2578
3175
|
}
|
|
2579
3176
|
const ids = [];
|
|
2580
|
-
for (const
|
|
2581
|
-
const row = {
|
|
2582
|
-
id: String(raw.id),
|
|
2583
|
-
event: String(raw.event),
|
|
2584
|
-
project: String(raw.project),
|
|
2585
|
-
summary: String(raw.summary),
|
|
2586
|
-
task_file: raw.task_file == null ? null : String(raw.task_file),
|
|
2587
|
-
created_at: String(raw.created_at)
|
|
2588
|
-
};
|
|
3177
|
+
for (const row of pending) {
|
|
2589
3178
|
process.stdout.write(formatLine(row));
|
|
2590
3179
|
ids.push(row.id);
|
|
2591
3180
|
}
|
|
2592
3181
|
if (ids.length > 0) {
|
|
2593
|
-
|
|
2594
|
-
await client.execute({
|
|
2595
|
-
sql: `UPDATE notifications SET read = 1 WHERE id IN (${placeholders})`,
|
|
2596
|
-
args: ids
|
|
2597
|
-
});
|
|
3182
|
+
await markAsRead(ids);
|
|
2598
3183
|
}
|
|
2599
3184
|
}
|
|
2600
3185
|
if (isMainModule(import.meta.url)) {
|