@askexenow/exe-os 0.8.1 → 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.
- package/package.json +1 -1
- package/dist/bin/backfill-responses.js +0 -2064
- package/dist/bin/backfill-vectors.js +0 -1771
- package/dist/bin/cleanup-stale-review-tasks.js +0 -1468
- package/dist/bin/cli.js +0 -21371
- package/dist/bin/exe-agent.js +0 -2016
- package/dist/bin/exe-assign.js +0 -2176
- package/dist/bin/exe-boot.js +0 -6332
- package/dist/bin/exe-call.js +0 -341
- package/dist/bin/exe-cloud.js +0 -861
- package/dist/bin/exe-dispatch.js +0 -1159
- package/dist/bin/exe-doctor.js +0 -1786
- package/dist/bin/exe-export-behaviors.js +0 -1637
- package/dist/bin/exe-forget.js +0 -1784
- package/dist/bin/exe-gateway.js +0 -8140
- package/dist/bin/exe-healthcheck.js +0 -207
- package/dist/bin/exe-heartbeat.js +0 -1778
- package/dist/bin/exe-kill.js +0 -1622
- package/dist/bin/exe-launch-agent.js +0 -1847
- package/dist/bin/exe-link.js +0 -192
- package/dist/bin/exe-new-employee.js +0 -1384
- package/dist/bin/exe-pending-messages.js +0 -1576
- package/dist/bin/exe-pending-notifications.js +0 -1450
- package/dist/bin/exe-pending-reviews.js +0 -1598
- package/dist/bin/exe-repo-drift.js +0 -95
- package/dist/bin/exe-review.js +0 -1742
- package/dist/bin/exe-search.js +0 -3116
- package/dist/bin/exe-session-cleanup.js +0 -3360
- package/dist/bin/exe-settings.js +0 -365
- package/dist/bin/exe-status.js +0 -1661
- package/dist/bin/exe-team.js +0 -1453
- package/dist/bin/git-sweep.js +0 -2441
- package/dist/bin/graph-backfill.js +0 -2111
- package/dist/bin/graph-export.js +0 -1747
- package/dist/bin/install.js +0 -661
- package/dist/bin/list-providers.js +0 -140
- package/dist/bin/scan-tasks.js +0 -2039
- package/dist/bin/setup.js +0 -2717
- package/dist/bin/shard-migrate.js +0 -1637
- package/dist/bin/update.js +0 -98
- package/dist/bin/wiki-sync.js +0 -1657
- package/dist/gateway/index.js +0 -9256
- package/dist/hooks/bug-report-worker.js +0 -2903
- package/dist/hooks/commit-complete.js +0 -2364
- package/dist/hooks/error-recall.js +0 -3327
- package/dist/hooks/exe-heartbeat-hook.js +0 -237
- package/dist/hooks/ingest-worker.js +0 -5065
- package/dist/hooks/ingest.js +0 -695
- package/dist/hooks/instructions-loaded.js +0 -2069
- package/dist/hooks/notification.js +0 -1915
- package/dist/hooks/post-compact.js +0 -1940
- package/dist/hooks/pre-compact.js +0 -1935
- package/dist/hooks/pre-tool-use.js +0 -2380
- package/dist/hooks/prompt-ingest-worker.js +0 -2291
- package/dist/hooks/prompt-submit.js +0 -5189
- package/dist/hooks/response-ingest-worker.js +0 -2431
- package/dist/hooks/session-end.js +0 -2196
- package/dist/hooks/session-start.js +0 -3259
- package/dist/hooks/stop.js +0 -2025
- package/dist/hooks/subagent-stop.js +0 -1915
- package/dist/hooks/summary-worker.js +0 -2931
- package/dist/index.js +0 -12327
- package/dist/lib/cloud-sync.js +0 -500
- package/dist/lib/config.js +0 -235
- package/dist/lib/consolidation.js +0 -481
- package/dist/lib/crypto.js +0 -51
- package/dist/lib/database.js +0 -834
- package/dist/lib/device-registry.js +0 -1009
- package/dist/lib/embedder.js +0 -645
- package/dist/lib/employee-templates.js +0 -570
- package/dist/lib/employees.js +0 -182
- package/dist/lib/error-detector.js +0 -156
- package/dist/lib/exe-daemon-client.js +0 -456
- package/dist/lib/exe-daemon.js +0 -8699
- package/dist/lib/file-grep.js +0 -215
- package/dist/lib/hybrid-search.js +0 -3064
- package/dist/lib/identity-templates.js +0 -441
- package/dist/lib/identity.js +0 -228
- package/dist/lib/keychain.js +0 -145
- package/dist/lib/license.js +0 -382
- package/dist/lib/messaging.js +0 -1389
- package/dist/lib/reminders.js +0 -63
- package/dist/lib/schedules.js +0 -1525
- package/dist/lib/session-registry.js +0 -52
- package/dist/lib/skill-learning.js +0 -488
- package/dist/lib/status-brief.js +0 -240
- package/dist/lib/store.js +0 -1740
- package/dist/lib/task-router.js +0 -128
- package/dist/lib/tasks.js +0 -2585
- package/dist/lib/tmux-routing.js +0 -2969
- package/dist/lib/tmux-status.js +0 -261
- package/dist/lib/tmux-transport.js +0 -83
- package/dist/lib/transport.js +0 -128
- package/dist/lib/ws-auth.js +0 -19
- package/dist/lib/ws-client.js +0 -160
- package/dist/mcp/server.js +0 -10812
- package/dist/mcp/tools/complete-reminder.js +0 -67
- package/dist/mcp/tools/create-reminder.js +0 -52
- package/dist/mcp/tools/create-task.js +0 -1903
- package/dist/mcp/tools/deactivate-behavior.js +0 -268
- package/dist/mcp/tools/list-reminders.js +0 -62
- package/dist/mcp/tools/list-tasks.js +0 -491
- package/dist/mcp/tools/send-message.js +0 -1395
- package/dist/mcp/tools/update-task.js +0 -1807
- package/dist/runtime/index.js +0 -7201
- package/dist/tui/App.js +0 -17874
|
@@ -1,1395 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __esm = (fn, res) => function __init() {
|
|
6
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
7
|
-
};
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
-
|
|
22
|
-
// src/lib/database.ts
|
|
23
|
-
import { createClient } from "@libsql/client";
|
|
24
|
-
function getClient() {
|
|
25
|
-
if (!_client) {
|
|
26
|
-
throw new Error("Database client not initialized. Call initDatabase() first.");
|
|
27
|
-
}
|
|
28
|
-
return _client;
|
|
29
|
-
}
|
|
30
|
-
var _client;
|
|
31
|
-
var init_database = __esm({
|
|
32
|
-
"src/lib/database.ts"() {
|
|
33
|
-
"use strict";
|
|
34
|
-
_client = null;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// src/lib/session-registry.ts
|
|
39
|
-
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
|
|
40
|
-
import path from "path";
|
|
41
|
-
import os from "os";
|
|
42
|
-
function registerSession(entry) {
|
|
43
|
-
const dir = path.dirname(REGISTRY_PATH);
|
|
44
|
-
if (!existsSync(dir)) {
|
|
45
|
-
mkdirSync(dir, { recursive: true });
|
|
46
|
-
}
|
|
47
|
-
const sessions = listSessions();
|
|
48
|
-
const idx = sessions.findIndex((s) => s.windowName === entry.windowName);
|
|
49
|
-
if (idx >= 0) {
|
|
50
|
-
sessions[idx] = entry;
|
|
51
|
-
} else {
|
|
52
|
-
sessions.push(entry);
|
|
53
|
-
}
|
|
54
|
-
writeFileSync(REGISTRY_PATH, JSON.stringify(sessions, null, 2));
|
|
55
|
-
}
|
|
56
|
-
function listSessions() {
|
|
57
|
-
try {
|
|
58
|
-
const raw = readFileSync(REGISTRY_PATH, "utf8");
|
|
59
|
-
return JSON.parse(raw);
|
|
60
|
-
} catch {
|
|
61
|
-
return [];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
var REGISTRY_PATH;
|
|
65
|
-
var init_session_registry = __esm({
|
|
66
|
-
"src/lib/session-registry.ts"() {
|
|
67
|
-
"use strict";
|
|
68
|
-
REGISTRY_PATH = path.join(os.homedir(), ".exe-os", "session-registry.json");
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// src/lib/session-key.ts
|
|
73
|
-
import { execSync } from "child_process";
|
|
74
|
-
function getSessionKey() {
|
|
75
|
-
if (_cached) return _cached;
|
|
76
|
-
let pid = process.ppid;
|
|
77
|
-
for (let i = 0; i < 10; i++) {
|
|
78
|
-
try {
|
|
79
|
-
const info = execSync(`ps -p ${pid} -o ppid=,comm=`, {
|
|
80
|
-
encoding: "utf8",
|
|
81
|
-
timeout: 2e3
|
|
82
|
-
}).trim();
|
|
83
|
-
const match = info.match(/^\s*(\d+)\s+(.+)$/);
|
|
84
|
-
if (!match) break;
|
|
85
|
-
const [, ppid, cmd] = match;
|
|
86
|
-
if (cmd === "claude" || cmd.endsWith("/claude")) {
|
|
87
|
-
_cached = String(pid);
|
|
88
|
-
return _cached;
|
|
89
|
-
}
|
|
90
|
-
pid = parseInt(ppid, 10);
|
|
91
|
-
if (pid <= 1) break;
|
|
92
|
-
} catch {
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
_cached = process.env.CLAUDE_CODE_SSE_PORT ?? String(process.ppid);
|
|
97
|
-
return _cached;
|
|
98
|
-
}
|
|
99
|
-
var _cached;
|
|
100
|
-
var init_session_key = __esm({
|
|
101
|
-
"src/lib/session-key.ts"() {
|
|
102
|
-
"use strict";
|
|
103
|
-
_cached = null;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// src/lib/tmux-transport.ts
|
|
108
|
-
var tmux_transport_exports = {};
|
|
109
|
-
__export(tmux_transport_exports, {
|
|
110
|
-
TmuxTransport: () => TmuxTransport
|
|
111
|
-
});
|
|
112
|
-
import { execFileSync } from "child_process";
|
|
113
|
-
var QUIET, TmuxTransport;
|
|
114
|
-
var init_tmux_transport = __esm({
|
|
115
|
-
"src/lib/tmux-transport.ts"() {
|
|
116
|
-
"use strict";
|
|
117
|
-
QUIET = {
|
|
118
|
-
encoding: "utf8",
|
|
119
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
120
|
-
};
|
|
121
|
-
TmuxTransport = class {
|
|
122
|
-
getMySession() {
|
|
123
|
-
try {
|
|
124
|
-
return execFileSync("tmux", ["display-message", "-p", "#{session_name}"], QUIET).trim() || null;
|
|
125
|
-
} catch {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
listSessions() {
|
|
130
|
-
try {
|
|
131
|
-
return execFileSync("tmux", ["list-sessions", "-F", "#{session_name}"], QUIET).trim().split("\n").filter(Boolean);
|
|
132
|
-
} catch {
|
|
133
|
-
return [];
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
isAlive(target) {
|
|
137
|
-
try {
|
|
138
|
-
const sessions = this.listSessions();
|
|
139
|
-
if (!sessions.includes(target)) return false;
|
|
140
|
-
const paneStatus = execFileSync(
|
|
141
|
-
"tmux",
|
|
142
|
-
["list-panes", "-t", target, "-F", "#{pane_dead}"],
|
|
143
|
-
QUIET
|
|
144
|
-
).trim();
|
|
145
|
-
return paneStatus !== "1";
|
|
146
|
-
} catch {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
sendKeys(target, keys) {
|
|
151
|
-
execFileSync("tmux", ["send-keys", "-t", target, keys, "Enter"], QUIET);
|
|
152
|
-
}
|
|
153
|
-
capturePane(target, lines) {
|
|
154
|
-
const args = ["capture-pane", "-t", target, "-p"];
|
|
155
|
-
if (lines) args.push("-S", `-${lines}`);
|
|
156
|
-
return execFileSync("tmux", args, { ...QUIET, timeout: 3e3 });
|
|
157
|
-
}
|
|
158
|
-
isPaneInCopyMode(target) {
|
|
159
|
-
try {
|
|
160
|
-
const result = execFileSync(
|
|
161
|
-
"tmux",
|
|
162
|
-
["display-message", "-p", "-t", target, "#{pane_in_mode}"],
|
|
163
|
-
{ ...QUIET, timeout: 3e3 }
|
|
164
|
-
).trim();
|
|
165
|
-
return result === "1";
|
|
166
|
-
} catch {
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
spawn(name, config) {
|
|
171
|
-
try {
|
|
172
|
-
const args = ["new-session", "-d", "-s", name];
|
|
173
|
-
if (config.cwd) args.push("-c", config.cwd);
|
|
174
|
-
args.push(config.command);
|
|
175
|
-
execFileSync("tmux", args);
|
|
176
|
-
return { sessionName: name };
|
|
177
|
-
} catch (e) {
|
|
178
|
-
return { sessionName: name, error: `spawn failed: ${e}` };
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
kill(target) {
|
|
182
|
-
try {
|
|
183
|
-
execFileSync("tmux", ["kill-session", "-t", target], QUIET);
|
|
184
|
-
} catch {
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
pipeLog(target, logFile) {
|
|
188
|
-
try {
|
|
189
|
-
const safePath = logFile.replace(/'/g, "'\\''");
|
|
190
|
-
execFileSync("tmux", ["pipe-pane", "-t", target, `cat >> '${safePath}'`], QUIET);
|
|
191
|
-
} catch {
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
// src/lib/transport.ts
|
|
199
|
-
function getTransport() {
|
|
200
|
-
if (!_transport) {
|
|
201
|
-
const { TmuxTransport: TmuxTransport2 } = (init_tmux_transport(), __toCommonJS(tmux_transport_exports));
|
|
202
|
-
_transport = new TmuxTransport2();
|
|
203
|
-
}
|
|
204
|
-
return _transport;
|
|
205
|
-
}
|
|
206
|
-
var _transport;
|
|
207
|
-
var init_transport = __esm({
|
|
208
|
-
"src/lib/transport.ts"() {
|
|
209
|
-
"use strict";
|
|
210
|
-
_transport = null;
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
// src/lib/cc-agent-support.ts
|
|
215
|
-
import { execSync as execSync2 } from "child_process";
|
|
216
|
-
function _resetCcAgentSupportCache() {
|
|
217
|
-
_cachedSupport = null;
|
|
218
|
-
}
|
|
219
|
-
function claudeSupportsAgentFlag() {
|
|
220
|
-
if (_cachedSupport !== null) return _cachedSupport;
|
|
221
|
-
try {
|
|
222
|
-
const helpOutput = execSync2("claude --help 2>&1", {
|
|
223
|
-
encoding: "utf-8",
|
|
224
|
-
timeout: 5e3
|
|
225
|
-
});
|
|
226
|
-
_cachedSupport = /(^|\s)--agent(\b|=)/.test(helpOutput);
|
|
227
|
-
} catch {
|
|
228
|
-
_cachedSupport = false;
|
|
229
|
-
}
|
|
230
|
-
return _cachedSupport;
|
|
231
|
-
}
|
|
232
|
-
var _cachedSupport;
|
|
233
|
-
var init_cc_agent_support = __esm({
|
|
234
|
-
"src/lib/cc-agent-support.ts"() {
|
|
235
|
-
"use strict";
|
|
236
|
-
_cachedSupport = null;
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
// src/lib/mcp-prefix.ts
|
|
241
|
-
function expandDualPrefixTools(shortNames) {
|
|
242
|
-
const out = [];
|
|
243
|
-
for (const name of shortNames) {
|
|
244
|
-
for (const prefix of MCP_TOOL_PREFIXES) {
|
|
245
|
-
out.push(prefix + name);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return out;
|
|
249
|
-
}
|
|
250
|
-
var MCP_PRIMARY_KEY, MCP_LEGACY_KEY, MCP_TOOL_PREFIXES;
|
|
251
|
-
var init_mcp_prefix = __esm({
|
|
252
|
-
"src/lib/mcp-prefix.ts"() {
|
|
253
|
-
"use strict";
|
|
254
|
-
MCP_PRIMARY_KEY = "exe-os";
|
|
255
|
-
MCP_LEGACY_KEY = "exe-mem";
|
|
256
|
-
MCP_TOOL_PREFIXES = [
|
|
257
|
-
`mcp__${MCP_PRIMARY_KEY}__`,
|
|
258
|
-
`mcp__${MCP_LEGACY_KEY}__`
|
|
259
|
-
];
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
// src/lib/provider-table.ts
|
|
264
|
-
function detectActiveProvider(env = process.env) {
|
|
265
|
-
const baseUrl = env.ANTHROPIC_BASE_URL;
|
|
266
|
-
if (!baseUrl) return DEFAULT_PROVIDER;
|
|
267
|
-
for (const [name, cfg] of Object.entries(PROVIDER_TABLE)) {
|
|
268
|
-
if (cfg.baseUrl === baseUrl) return name;
|
|
269
|
-
}
|
|
270
|
-
return DEFAULT_PROVIDER;
|
|
271
|
-
}
|
|
272
|
-
var PROVIDER_TABLE, DEFAULT_PROVIDER;
|
|
273
|
-
var init_provider_table = __esm({
|
|
274
|
-
"src/lib/provider-table.ts"() {
|
|
275
|
-
"use strict";
|
|
276
|
-
PROVIDER_TABLE = {
|
|
277
|
-
opencode: {
|
|
278
|
-
baseUrl: "https://opencode.ai/zen/go",
|
|
279
|
-
apiKeyEnv: "OPENCODE_API_KEY",
|
|
280
|
-
defaultModel: "minimax-m2.7"
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
DEFAULT_PROVIDER = "default";
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
// src/lib/intercom-queue.ts
|
|
288
|
-
import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, renameSync, existsSync as existsSync2, mkdirSync as mkdirSync2 } from "fs";
|
|
289
|
-
import path2 from "path";
|
|
290
|
-
import os2 from "os";
|
|
291
|
-
function ensureDir() {
|
|
292
|
-
const dir = path2.dirname(QUEUE_PATH);
|
|
293
|
-
if (!existsSync2(dir)) mkdirSync2(dir, { recursive: true });
|
|
294
|
-
}
|
|
295
|
-
function readQueue() {
|
|
296
|
-
try {
|
|
297
|
-
if (!existsSync2(QUEUE_PATH)) return [];
|
|
298
|
-
return JSON.parse(readFileSync2(QUEUE_PATH, "utf8"));
|
|
299
|
-
} catch {
|
|
300
|
-
return [];
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
function writeQueue(queue) {
|
|
304
|
-
ensureDir();
|
|
305
|
-
const tmp = `${QUEUE_PATH}.tmp`;
|
|
306
|
-
writeFileSync2(tmp, JSON.stringify(queue, null, 2));
|
|
307
|
-
renameSync(tmp, QUEUE_PATH);
|
|
308
|
-
}
|
|
309
|
-
function queueIntercom(targetSession, reason) {
|
|
310
|
-
const queue = readQueue();
|
|
311
|
-
const existing = queue.find((q) => q.targetSession === targetSession);
|
|
312
|
-
if (existing) {
|
|
313
|
-
existing.attempts++;
|
|
314
|
-
existing.queuedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
315
|
-
existing.reason = reason;
|
|
316
|
-
} else {
|
|
317
|
-
queue.push({
|
|
318
|
-
targetSession,
|
|
319
|
-
queuedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
320
|
-
attempts: 0,
|
|
321
|
-
reason
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
writeQueue(queue);
|
|
325
|
-
}
|
|
326
|
-
var QUEUE_PATH, TTL_MS, INTERCOM_LOG;
|
|
327
|
-
var init_intercom_queue = __esm({
|
|
328
|
-
"src/lib/intercom-queue.ts"() {
|
|
329
|
-
"use strict";
|
|
330
|
-
QUEUE_PATH = path2.join(os2.homedir(), ".exe-os", "intercom-queue.json");
|
|
331
|
-
TTL_MS = 60 * 60 * 1e3;
|
|
332
|
-
INTERCOM_LOG = path2.join(os2.homedir(), ".exe-os", "intercom.log");
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
// src/lib/config.ts
|
|
337
|
-
import { readFile, writeFile, mkdir } from "fs/promises";
|
|
338
|
-
import { readFileSync as readFileSync3, existsSync as existsSync3, renameSync as renameSync2 } from "fs";
|
|
339
|
-
import path3 from "path";
|
|
340
|
-
import os3 from "os";
|
|
341
|
-
function resolveDataDir() {
|
|
342
|
-
if (process.env.EXE_OS_DIR) return process.env.EXE_OS_DIR;
|
|
343
|
-
if (process.env.EXE_MEM_DIR) return process.env.EXE_MEM_DIR;
|
|
344
|
-
const newDir = path3.join(os3.homedir(), ".exe-os");
|
|
345
|
-
const legacyDir = path3.join(os3.homedir(), ".exe-mem");
|
|
346
|
-
if (!existsSync3(newDir) && existsSync3(legacyDir)) {
|
|
347
|
-
try {
|
|
348
|
-
renameSync2(legacyDir, newDir);
|
|
349
|
-
process.stderr.write(`[exe-os] Migrated data directory: ~/.exe-mem \u2192 ~/.exe-os
|
|
350
|
-
`);
|
|
351
|
-
} catch {
|
|
352
|
-
return legacyDir;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return newDir;
|
|
356
|
-
}
|
|
357
|
-
var EXE_AI_DIR, DB_PATH, MODELS_DIR, CONFIG_PATH, LEGACY_LANCE_PATH, CURRENT_CONFIG_VERSION, DEFAULT_CONFIG;
|
|
358
|
-
var init_config = __esm({
|
|
359
|
-
"src/lib/config.ts"() {
|
|
360
|
-
"use strict";
|
|
361
|
-
EXE_AI_DIR = resolveDataDir();
|
|
362
|
-
DB_PATH = path3.join(EXE_AI_DIR, "memories.db");
|
|
363
|
-
MODELS_DIR = path3.join(EXE_AI_DIR, "models");
|
|
364
|
-
CONFIG_PATH = path3.join(EXE_AI_DIR, "config.json");
|
|
365
|
-
LEGACY_LANCE_PATH = path3.join(EXE_AI_DIR, "local.lance");
|
|
366
|
-
CURRENT_CONFIG_VERSION = 1;
|
|
367
|
-
DEFAULT_CONFIG = {
|
|
368
|
-
config_version: CURRENT_CONFIG_VERSION,
|
|
369
|
-
dbPath: DB_PATH,
|
|
370
|
-
modelFile: "jina-embeddings-v5-small-q4_k_m.gguf",
|
|
371
|
-
embeddingDim: 1024,
|
|
372
|
-
batchSize: 20,
|
|
373
|
-
flushIntervalMs: 1e4,
|
|
374
|
-
autoIngestion: true,
|
|
375
|
-
autoRetrieval: true,
|
|
376
|
-
searchMode: "hybrid",
|
|
377
|
-
hookSearchMode: "hybrid",
|
|
378
|
-
fileGrepEnabled: true,
|
|
379
|
-
splashEffect: true,
|
|
380
|
-
consolidationEnabled: true,
|
|
381
|
-
consolidationIntervalMs: 6 * 60 * 60 * 1e3,
|
|
382
|
-
consolidationModel: "claude-haiku-4-5-20251001",
|
|
383
|
-
consolidationMaxCallsPerRun: 20,
|
|
384
|
-
selfQueryRouter: true,
|
|
385
|
-
selfQueryModel: "claude-haiku-4-5-20251001",
|
|
386
|
-
rerankerEnabled: true,
|
|
387
|
-
scalingRoadmap: {
|
|
388
|
-
rerankerAutoTrigger: {
|
|
389
|
-
enabled: true,
|
|
390
|
-
broadQueryMinCardinality: 5e4,
|
|
391
|
-
fetchTopK: 150,
|
|
392
|
-
returnTopK: 5
|
|
393
|
-
}
|
|
394
|
-
},
|
|
395
|
-
graphRagEnabled: true,
|
|
396
|
-
wikiEnabled: false,
|
|
397
|
-
wikiUrl: "",
|
|
398
|
-
wikiApiKey: "",
|
|
399
|
-
wikiSyncIntervalMs: 30 * 60 * 1e3,
|
|
400
|
-
wikiWorkspaceMapping: {
|
|
401
|
-
exe: "Executive",
|
|
402
|
-
yoshi: "Engineering",
|
|
403
|
-
mari: "Marketing",
|
|
404
|
-
tom: "Engineering",
|
|
405
|
-
sasha: "Production"
|
|
406
|
-
},
|
|
407
|
-
wikiAutoUpdate: true,
|
|
408
|
-
wikiAutoUpdateThreshold: 0.5,
|
|
409
|
-
wikiAutoUpdateCreateNew: true,
|
|
410
|
-
skillLearning: true,
|
|
411
|
-
skillThreshold: 3,
|
|
412
|
-
skillModel: "claude-haiku-4-5-20251001",
|
|
413
|
-
exeHeartbeat: {
|
|
414
|
-
enabled: true,
|
|
415
|
-
intervalSeconds: 60,
|
|
416
|
-
staleInProgressThresholdHours: 2
|
|
417
|
-
},
|
|
418
|
-
sessionLifecycle: {
|
|
419
|
-
idleKillEnabled: true,
|
|
420
|
-
idleKillTicksRequired: 3,
|
|
421
|
-
idleKillIntercomAckWindowMs: 1e4,
|
|
422
|
-
maxAutoInstances: 10
|
|
423
|
-
},
|
|
424
|
-
autoUpdate: {
|
|
425
|
-
checkOnBoot: true,
|
|
426
|
-
autoInstall: false,
|
|
427
|
-
checkIntervalMs: 24 * 60 * 60 * 1e3
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
// src/lib/employees.ts
|
|
434
|
-
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
435
|
-
import { existsSync as existsSync4, symlinkSync, readlinkSync } from "fs";
|
|
436
|
-
import { execSync as execSync3 } from "child_process";
|
|
437
|
-
import path4 from "path";
|
|
438
|
-
var EMPLOYEES_PATH;
|
|
439
|
-
var init_employees = __esm({
|
|
440
|
-
"src/lib/employees.ts"() {
|
|
441
|
-
"use strict";
|
|
442
|
-
init_config();
|
|
443
|
-
EMPLOYEES_PATH = path4.join(EXE_AI_DIR, "exe-employees.json");
|
|
444
|
-
}
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
// src/lib/license.ts
|
|
448
|
-
import { readFileSync as readFileSync4, writeFileSync as writeFileSync3, existsSync as existsSync5, mkdirSync as mkdirSync3 } from "fs";
|
|
449
|
-
import { randomUUID } from "crypto";
|
|
450
|
-
import path5 from "path";
|
|
451
|
-
import { jwtVerify, importSPKI } from "jose";
|
|
452
|
-
var LICENSE_PATH, CACHE_PATH, DEVICE_ID_PATH, PLAN_LIMITS;
|
|
453
|
-
var init_license = __esm({
|
|
454
|
-
"src/lib/license.ts"() {
|
|
455
|
-
"use strict";
|
|
456
|
-
init_config();
|
|
457
|
-
LICENSE_PATH = path5.join(EXE_AI_DIR, "license.key");
|
|
458
|
-
CACHE_PATH = path5.join(EXE_AI_DIR, "license-cache.json");
|
|
459
|
-
DEVICE_ID_PATH = path5.join(EXE_AI_DIR, "device-id");
|
|
460
|
-
PLAN_LIMITS = {
|
|
461
|
-
free: { devices: 1, employees: 1, memories: 5e3 },
|
|
462
|
-
pro: { devices: 2, employees: 5, memories: 1e5 },
|
|
463
|
-
team: { devices: 10, employees: 20, memories: 1e6 },
|
|
464
|
-
agency: { devices: 50, employees: 100, memories: 1e7 },
|
|
465
|
-
enterprise: { devices: -1, employees: -1, memories: -1 }
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
|
|
470
|
-
// src/lib/plan-limits.ts
|
|
471
|
-
import { readFileSync as readFileSync5, existsSync as existsSync6 } from "fs";
|
|
472
|
-
import path6 from "path";
|
|
473
|
-
function getLicenseSync() {
|
|
474
|
-
try {
|
|
475
|
-
if (!existsSync6(CACHE_PATH2)) return freeLicense();
|
|
476
|
-
const raw = JSON.parse(readFileSync5(CACHE_PATH2, "utf8"));
|
|
477
|
-
if (!raw.token || typeof raw.token !== "string") return freeLicense();
|
|
478
|
-
const parts = raw.token.split(".");
|
|
479
|
-
if (parts.length !== 3) return freeLicense();
|
|
480
|
-
const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString());
|
|
481
|
-
const plan = payload.plan ?? "free";
|
|
482
|
-
const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
|
|
483
|
-
return {
|
|
484
|
-
valid: true,
|
|
485
|
-
plan,
|
|
486
|
-
email: payload.sub ?? "",
|
|
487
|
-
expiresAt: payload.exp ? new Date(payload.exp * 1e3).toISOString() : null,
|
|
488
|
-
deviceLimit: limits.devices,
|
|
489
|
-
employeeLimit: limits.employees,
|
|
490
|
-
memoryLimit: limits.memories
|
|
491
|
-
};
|
|
492
|
-
} catch {
|
|
493
|
-
return freeLicense();
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
function freeLicense() {
|
|
497
|
-
const limits = PLAN_LIMITS.free;
|
|
498
|
-
return {
|
|
499
|
-
valid: true,
|
|
500
|
-
plan: "free",
|
|
501
|
-
email: "",
|
|
502
|
-
expiresAt: null,
|
|
503
|
-
deviceLimit: limits.devices,
|
|
504
|
-
employeeLimit: limits.employees,
|
|
505
|
-
memoryLimit: limits.memories
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
function assertEmployeeLimitSync(rosterPath) {
|
|
509
|
-
const license = getLicenseSync();
|
|
510
|
-
if (license.employeeLimit < 0) return;
|
|
511
|
-
const filePath = rosterPath ?? EMPLOYEES_PATH;
|
|
512
|
-
let count = 0;
|
|
513
|
-
try {
|
|
514
|
-
if (existsSync6(filePath)) {
|
|
515
|
-
const raw = readFileSync5(filePath, "utf8");
|
|
516
|
-
const employees = JSON.parse(raw);
|
|
517
|
-
count = Array.isArray(employees) ? employees.length : 0;
|
|
518
|
-
}
|
|
519
|
-
} catch {
|
|
520
|
-
throw new PlanLimitError(
|
|
521
|
-
`Cannot verify employee count: roster unreadable at ${filePath}. Refusing to proceed. Check file permissions or upgrade plan.`
|
|
522
|
-
);
|
|
523
|
-
}
|
|
524
|
-
if (count >= license.employeeLimit) {
|
|
525
|
-
throw new PlanLimitError(
|
|
526
|
-
`Employee limit reached: ${count}/${license.employeeLimit} employees on the ${license.plan} plan. Upgrade at https://askexe.com to add more.`
|
|
527
|
-
);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
var PlanLimitError, CACHE_PATH2;
|
|
531
|
-
var init_plan_limits = __esm({
|
|
532
|
-
"src/lib/plan-limits.ts"() {
|
|
533
|
-
"use strict";
|
|
534
|
-
init_database();
|
|
535
|
-
init_employees();
|
|
536
|
-
init_license();
|
|
537
|
-
init_config();
|
|
538
|
-
PlanLimitError = class extends Error {
|
|
539
|
-
constructor(message) {
|
|
540
|
-
super(message);
|
|
541
|
-
this.name = "PlanLimitError";
|
|
542
|
-
}
|
|
543
|
-
};
|
|
544
|
-
CACHE_PATH2 = path6.join(EXE_AI_DIR, "license-cache.json");
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
|
|
548
|
-
// src/lib/worktree.ts
|
|
549
|
-
import { execSync as execSync4 } from "child_process";
|
|
550
|
-
import { existsSync as existsSync7, readFileSync as readFileSync6, appendFileSync, mkdirSync as mkdirSync4, realpathSync } from "fs";
|
|
551
|
-
import path7 from "path";
|
|
552
|
-
function getGitRoot(dir) {
|
|
553
|
-
try {
|
|
554
|
-
const root = execSync4("git rev-parse --show-toplevel", {
|
|
555
|
-
cwd: dir,
|
|
556
|
-
encoding: "utf-8",
|
|
557
|
-
timeout: GIT_TIMEOUT_MS,
|
|
558
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
559
|
-
}).trim();
|
|
560
|
-
return realpath(root);
|
|
561
|
-
} catch {
|
|
562
|
-
return null;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
function getMainRepoRoot(dir) {
|
|
566
|
-
try {
|
|
567
|
-
const commonDir = execSync4(
|
|
568
|
-
"git rev-parse --path-format=absolute --git-common-dir",
|
|
569
|
-
{ cwd: dir, encoding: "utf-8", timeout: GIT_TIMEOUT_MS, stdio: ["pipe", "pipe", "pipe"] }
|
|
570
|
-
).trim();
|
|
571
|
-
return realpath(path7.dirname(commonDir));
|
|
572
|
-
} catch {
|
|
573
|
-
return null;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
function worktreePath(repoRoot, employeeName, instance) {
|
|
577
|
-
const label = instanceLabel(employeeName, instance);
|
|
578
|
-
return path7.join(repoRoot, ".worktrees", label);
|
|
579
|
-
}
|
|
580
|
-
function worktreeBranch(employeeName, instance) {
|
|
581
|
-
return `${instanceLabel(employeeName, instance)}-work`;
|
|
582
|
-
}
|
|
583
|
-
function instanceLabel(name, instance) {
|
|
584
|
-
return instance != null && instance > 0 ? `${name}${instance}` : name;
|
|
585
|
-
}
|
|
586
|
-
function ensureWorktree(projectDir, employeeName, instance) {
|
|
587
|
-
const repoRoot = getGitRoot(projectDir);
|
|
588
|
-
if (!repoRoot) return null;
|
|
589
|
-
const wtPath = worktreePath(repoRoot, employeeName, instance);
|
|
590
|
-
const branch = worktreeBranch(employeeName, instance);
|
|
591
|
-
if (existsSync7(path7.join(wtPath, ".git"))) {
|
|
592
|
-
return wtPath;
|
|
593
|
-
}
|
|
594
|
-
const worktreesDir = path7.join(repoRoot, ".worktrees");
|
|
595
|
-
mkdirSync4(worktreesDir, { recursive: true });
|
|
596
|
-
ensureGitignoreEntry(repoRoot, "/.worktrees/");
|
|
597
|
-
try {
|
|
598
|
-
execSync4("git worktree prune", {
|
|
599
|
-
cwd: repoRoot,
|
|
600
|
-
encoding: "utf-8",
|
|
601
|
-
timeout: GIT_TIMEOUT_MS,
|
|
602
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
603
|
-
});
|
|
604
|
-
} catch {
|
|
605
|
-
}
|
|
606
|
-
const branchExists = branchExistsLocally(repoRoot, branch);
|
|
607
|
-
try {
|
|
608
|
-
if (branchExists) {
|
|
609
|
-
execSync4(`git worktree add "${wtPath}" "${branch}"`, {
|
|
610
|
-
cwd: repoRoot,
|
|
611
|
-
encoding: "utf-8",
|
|
612
|
-
timeout: GIT_TIMEOUT_MS,
|
|
613
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
614
|
-
});
|
|
615
|
-
} else {
|
|
616
|
-
execSync4(`git worktree add "${wtPath}" -b "${branch}" HEAD`, {
|
|
617
|
-
cwd: repoRoot,
|
|
618
|
-
encoding: "utf-8",
|
|
619
|
-
timeout: GIT_TIMEOUT_MS,
|
|
620
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
621
|
-
});
|
|
622
|
-
}
|
|
623
|
-
return wtPath;
|
|
624
|
-
} catch (err) {
|
|
625
|
-
process.stderr.write(
|
|
626
|
-
`[worktree] Failed to create worktree for ${employeeName}: ${err instanceof Error ? err.message : String(err)}
|
|
627
|
-
`
|
|
628
|
-
);
|
|
629
|
-
return null;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
function branchExistsLocally(repoRoot, branch) {
|
|
633
|
-
try {
|
|
634
|
-
execSync4(`git rev-parse --verify "refs/heads/${branch}"`, {
|
|
635
|
-
cwd: repoRoot,
|
|
636
|
-
encoding: "utf-8",
|
|
637
|
-
timeout: GIT_TIMEOUT_MS,
|
|
638
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
639
|
-
});
|
|
640
|
-
return true;
|
|
641
|
-
} catch {
|
|
642
|
-
return false;
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
function realpath(p) {
|
|
646
|
-
try {
|
|
647
|
-
return realpathSync(p);
|
|
648
|
-
} catch {
|
|
649
|
-
return p;
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
function ensureGitignoreEntry(repoRoot, entry) {
|
|
653
|
-
try {
|
|
654
|
-
const gitignorePath = path7.join(repoRoot, ".gitignore");
|
|
655
|
-
if (existsSync7(gitignorePath)) {
|
|
656
|
-
const content = readFileSync6(gitignorePath, "utf-8");
|
|
657
|
-
if (content.includes(entry)) return;
|
|
658
|
-
appendFileSync(gitignorePath, `
|
|
659
|
-
# Agent worktrees (exe-os)
|
|
660
|
-
${entry}
|
|
661
|
-
`);
|
|
662
|
-
} else {
|
|
663
|
-
}
|
|
664
|
-
} catch {
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
var GIT_TIMEOUT_MS;
|
|
668
|
-
var init_worktree = __esm({
|
|
669
|
-
"src/lib/worktree.ts"() {
|
|
670
|
-
"use strict";
|
|
671
|
-
GIT_TIMEOUT_MS = 1e4;
|
|
672
|
-
}
|
|
673
|
-
});
|
|
674
|
-
|
|
675
|
-
// src/lib/tmux-routing.ts
|
|
676
|
-
import { execFileSync as execFileSync2, execSync as execSync5 } from "child_process";
|
|
677
|
-
import { readFileSync as readFileSync7, writeFileSync as writeFileSync4, mkdirSync as mkdirSync5, existsSync as existsSync8, appendFileSync as appendFileSync2 } from "fs";
|
|
678
|
-
import path8 from "path";
|
|
679
|
-
import os4 from "os";
|
|
680
|
-
import { fileURLToPath } from "url";
|
|
681
|
-
function resolveBehaviorsExporterScript() {
|
|
682
|
-
try {
|
|
683
|
-
const thisFile = fileURLToPath(import.meta.url);
|
|
684
|
-
const scriptPath = path8.join(
|
|
685
|
-
path8.dirname(thisFile),
|
|
686
|
-
"..",
|
|
687
|
-
"bin",
|
|
688
|
-
"exe-export-behaviors.js"
|
|
689
|
-
);
|
|
690
|
-
return existsSync8(scriptPath) ? scriptPath : null;
|
|
691
|
-
} catch {
|
|
692
|
-
return null;
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
function exportBehaviorsSync(agentId, projectName, sessionKey) {
|
|
696
|
-
const script = resolveBehaviorsExporterScript();
|
|
697
|
-
if (!script) return null;
|
|
698
|
-
try {
|
|
699
|
-
const output = execFileSync2(
|
|
700
|
-
process.execPath,
|
|
701
|
-
[script, agentId, projectName, sessionKey],
|
|
702
|
-
{ encoding: "utf-8", timeout: BEHAVIORS_EXPORT_TIMEOUT_MS }
|
|
703
|
-
).trim();
|
|
704
|
-
return output.length > 0 ? output : null;
|
|
705
|
-
} catch (err) {
|
|
706
|
-
process.stderr.write(
|
|
707
|
-
`[tmux-routing] behaviors export failed for ${agentId}: ${err instanceof Error ? err.message : String(err)}
|
|
708
|
-
`
|
|
709
|
-
);
|
|
710
|
-
return null;
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
function getMySession() {
|
|
714
|
-
return getTransport().getMySession();
|
|
715
|
-
}
|
|
716
|
-
function employeeSessionName(employee, exeSession, instance) {
|
|
717
|
-
const suffix = instance != null && instance > 0 ? String(instance) : "";
|
|
718
|
-
return `${employee}${suffix}-${exeSession}`;
|
|
719
|
-
}
|
|
720
|
-
function extractRootExe(name) {
|
|
721
|
-
const match = name.match(/(exe\d+)$/);
|
|
722
|
-
return match?.[1] ?? null;
|
|
723
|
-
}
|
|
724
|
-
function getParentExe(sessionKey) {
|
|
725
|
-
try {
|
|
726
|
-
const data = JSON.parse(readFileSync7(path8.join(SESSION_CACHE, `parent-exe-${sessionKey}.json`), "utf8"));
|
|
727
|
-
return data.parentExe || null;
|
|
728
|
-
} catch {
|
|
729
|
-
return null;
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
function resolveExeSession() {
|
|
733
|
-
const mySession = getMySession();
|
|
734
|
-
if (!mySession) return null;
|
|
735
|
-
try {
|
|
736
|
-
const key = getSessionKey();
|
|
737
|
-
const parentExe = getParentExe(key);
|
|
738
|
-
if (parentExe) {
|
|
739
|
-
return extractRootExe(parentExe) ?? parentExe;
|
|
740
|
-
}
|
|
741
|
-
} catch {
|
|
742
|
-
}
|
|
743
|
-
return extractRootExe(mySession) ?? mySession;
|
|
744
|
-
}
|
|
745
|
-
function isEmployeeAlive(sessionName) {
|
|
746
|
-
return getTransport().isAlive(sessionName);
|
|
747
|
-
}
|
|
748
|
-
function findFreeInstance(employeeName, exeSession, maxInstances = 10, isAlive = isEmployeeAlive) {
|
|
749
|
-
const base = employeeSessionName(employeeName, exeSession);
|
|
750
|
-
if (!isAlive(base)) return 0;
|
|
751
|
-
for (let i = 2; i <= maxInstances; i++) {
|
|
752
|
-
const candidate = employeeSessionName(employeeName, exeSession, i);
|
|
753
|
-
if (!isAlive(candidate)) return i;
|
|
754
|
-
}
|
|
755
|
-
return null;
|
|
756
|
-
}
|
|
757
|
-
function readDebounceState() {
|
|
758
|
-
try {
|
|
759
|
-
if (!existsSync8(DEBOUNCE_FILE)) return {};
|
|
760
|
-
return JSON.parse(readFileSync7(DEBOUNCE_FILE, "utf8"));
|
|
761
|
-
} catch {
|
|
762
|
-
return {};
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
function writeDebounceState(state) {
|
|
766
|
-
try {
|
|
767
|
-
if (!existsSync8(SESSION_CACHE)) mkdirSync5(SESSION_CACHE, { recursive: true });
|
|
768
|
-
writeFileSync4(DEBOUNCE_FILE, JSON.stringify(state));
|
|
769
|
-
} catch {
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
function isDebounced(targetSession) {
|
|
773
|
-
const state = readDebounceState();
|
|
774
|
-
const lastSent = state[targetSession] ?? 0;
|
|
775
|
-
return Date.now() - lastSent < INTERCOM_DEBOUNCE_MS;
|
|
776
|
-
}
|
|
777
|
-
function recordDebounce(targetSession) {
|
|
778
|
-
const state = readDebounceState();
|
|
779
|
-
state[targetSession] = Date.now();
|
|
780
|
-
const cutoff = Date.now() - DEBOUNCE_CLEANUP_AGE_MS;
|
|
781
|
-
for (const key of Object.keys(state)) {
|
|
782
|
-
if ((state[key] ?? 0) < cutoff) delete state[key];
|
|
783
|
-
}
|
|
784
|
-
writeDebounceState(state);
|
|
785
|
-
}
|
|
786
|
-
function logIntercom(msg) {
|
|
787
|
-
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${msg}
|
|
788
|
-
`;
|
|
789
|
-
process.stderr.write(`[intercom] ${msg}
|
|
790
|
-
`);
|
|
791
|
-
try {
|
|
792
|
-
appendFileSync2(INTERCOM_LOG2, line);
|
|
793
|
-
} catch {
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
function getSessionState(sessionName) {
|
|
797
|
-
const transport = getTransport();
|
|
798
|
-
if (!transport.isAlive(sessionName)) return "offline";
|
|
799
|
-
try {
|
|
800
|
-
const pane = transport.capturePane(sessionName, 5);
|
|
801
|
-
if (!pane.includes("\u276F") && !pane.includes("Claude Code") && !BUSY_PATTERN.test(pane) && !/Running…/.test(pane)) {
|
|
802
|
-
if (/\$\s*$/.test(pane) || /% $/.test(pane.trimEnd())) {
|
|
803
|
-
return "no_claude";
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
if (/Running…/.test(pane)) return "tool";
|
|
807
|
-
if (BUSY_PATTERN.test(pane)) return "thinking";
|
|
808
|
-
return "idle";
|
|
809
|
-
} catch {
|
|
810
|
-
return "offline";
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
function isExeSession(sessionName) {
|
|
814
|
-
return /^exe\d*$/.test(sessionName);
|
|
815
|
-
}
|
|
816
|
-
function sendIntercom(targetSession) {
|
|
817
|
-
const transport = getTransport();
|
|
818
|
-
if (isExeSession(targetSession)) {
|
|
819
|
-
logIntercom(`SKIP_EXE \u2192 ${targetSession} (exe sessions use prompt-submit hook)`);
|
|
820
|
-
return "skipped_exe";
|
|
821
|
-
}
|
|
822
|
-
if (isDebounced(targetSession)) {
|
|
823
|
-
logIntercom(`DEBOUNCE \u2192 ${targetSession} (cross-process file debounce)`);
|
|
824
|
-
return "debounced";
|
|
825
|
-
}
|
|
826
|
-
try {
|
|
827
|
-
const sessions = transport.listSessions();
|
|
828
|
-
if (!sessions.includes(targetSession)) {
|
|
829
|
-
logIntercom(`SKIP \u2192 ${targetSession} (session not found)`);
|
|
830
|
-
return "failed";
|
|
831
|
-
}
|
|
832
|
-
const sessionState = getSessionState(targetSession);
|
|
833
|
-
if (sessionState === "no_claude") {
|
|
834
|
-
queueIntercom(targetSession, "claude not running in session");
|
|
835
|
-
recordDebounce(targetSession);
|
|
836
|
-
logIntercom(`QUEUED \u2192 ${targetSession} (no claude process \u2014 raw shell detected)`);
|
|
837
|
-
return "queued";
|
|
838
|
-
}
|
|
839
|
-
if (sessionState === "thinking" || sessionState === "tool") {
|
|
840
|
-
queueIntercom(targetSession, "session busy at send time");
|
|
841
|
-
recordDebounce(targetSession);
|
|
842
|
-
logIntercom(`QUEUED \u2192 ${targetSession} (session busy, will retry from queue)`);
|
|
843
|
-
return "queued";
|
|
844
|
-
}
|
|
845
|
-
if (transport.isPaneInCopyMode(targetSession)) {
|
|
846
|
-
logIntercom(`COPY_MODE \u2192 ${targetSession} (exiting copy mode first)`);
|
|
847
|
-
transport.sendKeys(targetSession, "q");
|
|
848
|
-
}
|
|
849
|
-
transport.sendKeys(targetSession, "/exe-intercom");
|
|
850
|
-
recordDebounce(targetSession);
|
|
851
|
-
logIntercom(`DELIVERED \u2192 ${targetSession} (fire-and-forget)`);
|
|
852
|
-
return "delivered";
|
|
853
|
-
} catch {
|
|
854
|
-
logIntercom(`FAIL \u2192 ${targetSession}`);
|
|
855
|
-
return "failed";
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
function ensureEmployee(employeeName, exeSession, projectDir, opts) {
|
|
859
|
-
if (employeeName === "exe") {
|
|
860
|
-
return { status: "failed", sessionName: "", error: "exe is the COO, not a dispatchable employee" };
|
|
861
|
-
}
|
|
862
|
-
try {
|
|
863
|
-
assertEmployeeLimitSync();
|
|
864
|
-
} catch (err) {
|
|
865
|
-
if (err instanceof PlanLimitError) {
|
|
866
|
-
return { status: "failed", sessionName: "", error: err.message };
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
if (/-exe\d*$/.test(employeeName)) {
|
|
870
|
-
const bare = employeeName.replace(/-exe\d*$/, "").replace(/\d+$/, "");
|
|
871
|
-
return {
|
|
872
|
-
status: "failed",
|
|
873
|
-
sessionName: "",
|
|
874
|
-
error: `Error: pass employee name ('${bare}'), not session name ('${employeeName}')`
|
|
875
|
-
};
|
|
876
|
-
}
|
|
877
|
-
let effectiveInstance = opts?.instance;
|
|
878
|
-
if (effectiveInstance === void 0 && opts?.autoInstance) {
|
|
879
|
-
const free = findFreeInstance(
|
|
880
|
-
employeeName,
|
|
881
|
-
exeSession,
|
|
882
|
-
opts.maxAutoInstances ?? 10
|
|
883
|
-
);
|
|
884
|
-
if (free === null) {
|
|
885
|
-
return {
|
|
886
|
-
status: "failed",
|
|
887
|
-
sessionName: employeeSessionName(employeeName, exeSession),
|
|
888
|
-
error: `All ${opts.maxAutoInstances ?? 10} instances of ${employeeName} are alive \u2014 cap reached`
|
|
889
|
-
};
|
|
890
|
-
}
|
|
891
|
-
effectiveInstance = free === 0 ? void 0 : free;
|
|
892
|
-
}
|
|
893
|
-
const sessionName = employeeSessionName(employeeName, exeSession, effectiveInstance);
|
|
894
|
-
if (isEmployeeAlive(sessionName)) {
|
|
895
|
-
const result2 = sendIntercom(sessionName);
|
|
896
|
-
if (result2 === "acknowledged" || result2 === "skipped_exe" || result2 === "debounced" || result2 === "queued") {
|
|
897
|
-
return { status: "intercom_sent", sessionName };
|
|
898
|
-
}
|
|
899
|
-
if (result2 === "delivered") {
|
|
900
|
-
return { status: "intercom_unprocessed", sessionName };
|
|
901
|
-
}
|
|
902
|
-
return { status: "failed", sessionName, error: "intercom delivery failed" };
|
|
903
|
-
}
|
|
904
|
-
const spawnOpts = { ...opts, instance: effectiveInstance };
|
|
905
|
-
const mainRoot = getMainRepoRoot(projectDir) ?? projectDir;
|
|
906
|
-
const wtPath = ensureWorktree(mainRoot, employeeName, effectiveInstance);
|
|
907
|
-
if (wtPath) {
|
|
908
|
-
spawnOpts.cwd = wtPath;
|
|
909
|
-
}
|
|
910
|
-
const result = spawnEmployee(employeeName, exeSession, projectDir, spawnOpts);
|
|
911
|
-
if (result.error) {
|
|
912
|
-
return { status: "failed", sessionName, error: result.error };
|
|
913
|
-
}
|
|
914
|
-
return { status: "spawned", sessionName };
|
|
915
|
-
}
|
|
916
|
-
function spawnEmployee(employeeName, exeSession, projectDir, opts) {
|
|
917
|
-
const transport = getTransport();
|
|
918
|
-
const sessionName = employeeSessionName(employeeName, exeSession, opts?.instance);
|
|
919
|
-
const instanceLabel2 = opts?.instance != null && opts.instance > 0 ? `${employeeName}${opts.instance}` : employeeName;
|
|
920
|
-
const logDir = path8.join(os4.homedir(), ".exe-os", "session-logs");
|
|
921
|
-
const logFile = path8.join(logDir, `${instanceLabel2}-${Date.now()}.log`);
|
|
922
|
-
if (!existsSync8(logDir)) {
|
|
923
|
-
mkdirSync5(logDir, { recursive: true });
|
|
924
|
-
}
|
|
925
|
-
transport.kill(sessionName);
|
|
926
|
-
let cleanupSuffix = "";
|
|
927
|
-
try {
|
|
928
|
-
const thisFile = fileURLToPath(import.meta.url);
|
|
929
|
-
const cleanupScript = path8.join(path8.dirname(thisFile), "..", "bin", "exe-session-cleanup.js");
|
|
930
|
-
if (existsSync8(cleanupScript)) {
|
|
931
|
-
cleanupSuffix = `; ${process.execPath} "${cleanupScript}" "${employeeName}" "${exeSession}"`;
|
|
932
|
-
}
|
|
933
|
-
} catch {
|
|
934
|
-
}
|
|
935
|
-
try {
|
|
936
|
-
const claudeJsonPath = path8.join(os4.homedir(), ".claude.json");
|
|
937
|
-
let claudeJson = {};
|
|
938
|
-
try {
|
|
939
|
-
claudeJson = JSON.parse(readFileSync7(claudeJsonPath, "utf8"));
|
|
940
|
-
} catch {
|
|
941
|
-
}
|
|
942
|
-
if (!claudeJson.projects) claudeJson.projects = {};
|
|
943
|
-
const projects = claudeJson.projects;
|
|
944
|
-
const trustDir = opts?.cwd ?? projectDir;
|
|
945
|
-
if (!projects[trustDir]) projects[trustDir] = {};
|
|
946
|
-
projects[trustDir].hasTrustDialogAccepted = true;
|
|
947
|
-
writeFileSync4(claudeJsonPath, JSON.stringify(claudeJson, null, 2) + "\n");
|
|
948
|
-
} catch {
|
|
949
|
-
}
|
|
950
|
-
try {
|
|
951
|
-
const settingsDir = path8.join(os4.homedir(), ".claude", "projects");
|
|
952
|
-
const normalizedKey = (opts?.cwd ?? projectDir).replace(/\//g, "-").replace(/^-/, "");
|
|
953
|
-
const projSettingsDir = path8.join(settingsDir, normalizedKey);
|
|
954
|
-
const settingsPath = path8.join(projSettingsDir, "settings.json");
|
|
955
|
-
let settings = {};
|
|
956
|
-
try {
|
|
957
|
-
settings = JSON.parse(readFileSync7(settingsPath, "utf8"));
|
|
958
|
-
} catch {
|
|
959
|
-
}
|
|
960
|
-
const perms = settings.permissions ?? {};
|
|
961
|
-
const allow = perms.allow ?? [];
|
|
962
|
-
const toolNames = [
|
|
963
|
-
"recall_my_memory",
|
|
964
|
-
"store_memory",
|
|
965
|
-
"create_task",
|
|
966
|
-
"update_task",
|
|
967
|
-
"list_tasks",
|
|
968
|
-
"get_task",
|
|
969
|
-
"ask_team_memory",
|
|
970
|
-
"store_behavior",
|
|
971
|
-
"get_identity",
|
|
972
|
-
"send_message"
|
|
973
|
-
];
|
|
974
|
-
const requiredTools = expandDualPrefixTools(toolNames);
|
|
975
|
-
let changed = false;
|
|
976
|
-
for (const tool of requiredTools) {
|
|
977
|
-
if (!allow.includes(tool)) {
|
|
978
|
-
allow.push(tool);
|
|
979
|
-
changed = true;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
if (changed) {
|
|
983
|
-
perms.allow = allow;
|
|
984
|
-
settings.permissions = perms;
|
|
985
|
-
mkdirSync5(projSettingsDir, { recursive: true });
|
|
986
|
-
writeFileSync4(settingsPath, JSON.stringify(settings, null, 2) + "\n");
|
|
987
|
-
}
|
|
988
|
-
} catch {
|
|
989
|
-
}
|
|
990
|
-
const spawnCwd = opts?.cwd ?? projectDir;
|
|
991
|
-
const useExeAgent = !!(opts?.model && opts?.provider);
|
|
992
|
-
const ccProvider = useExeAgent ? DEFAULT_PROVIDER : detectActiveProvider();
|
|
993
|
-
const useBinSymlink = ccProvider !== DEFAULT_PROVIDER;
|
|
994
|
-
let identityFlag = "";
|
|
995
|
-
let behaviorsFlag = "";
|
|
996
|
-
let legacyFallbackWarned = false;
|
|
997
|
-
if (!useExeAgent && !useBinSymlink) {
|
|
998
|
-
const identityPath = path8.join(
|
|
999
|
-
os4.homedir(),
|
|
1000
|
-
".exe-os",
|
|
1001
|
-
"identity",
|
|
1002
|
-
`${employeeName}.md`
|
|
1003
|
-
);
|
|
1004
|
-
_resetCcAgentSupportCache();
|
|
1005
|
-
const hasAgentFlag = claudeSupportsAgentFlag();
|
|
1006
|
-
if (hasAgentFlag) {
|
|
1007
|
-
identityFlag = ` --agent ${employeeName}`;
|
|
1008
|
-
} else if (existsSync8(identityPath)) {
|
|
1009
|
-
identityFlag = ` --append-system-prompt-file ${identityPath}`;
|
|
1010
|
-
legacyFallbackWarned = true;
|
|
1011
|
-
}
|
|
1012
|
-
const behaviorsFile = exportBehaviorsSync(
|
|
1013
|
-
employeeName,
|
|
1014
|
-
path8.basename(spawnCwd),
|
|
1015
|
-
sessionName
|
|
1016
|
-
);
|
|
1017
|
-
if (behaviorsFile) {
|
|
1018
|
-
behaviorsFlag = ` --append-system-prompt-file ${behaviorsFile}`;
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
if (legacyFallbackWarned) {
|
|
1022
|
-
process.stderr.write(
|
|
1023
|
-
`[tmux-routing] claude --agent not supported by installed CC. Falling back to --append-system-prompt-file for ${employeeName}. Upgrade Claude Code to enable native --agent launch.
|
|
1024
|
-
`
|
|
1025
|
-
);
|
|
1026
|
-
}
|
|
1027
|
-
let sessionContextFlag = "";
|
|
1028
|
-
try {
|
|
1029
|
-
const ctxDir = path8.join(os4.homedir(), ".exe-os", "session-cache");
|
|
1030
|
-
mkdirSync5(ctxDir, { recursive: true });
|
|
1031
|
-
const ctxFile = path8.join(ctxDir, `session-context-${sessionName}.md`);
|
|
1032
|
-
const ctxContent = [
|
|
1033
|
-
`## Session Context`,
|
|
1034
|
-
`You are running in tmux session: ${sessionName}.`,
|
|
1035
|
-
`Your parent exe session is ${exeSession}.`,
|
|
1036
|
-
`Your employees (if any) use the -${exeSession} suffix (e.g., tom-${exeSession}).`
|
|
1037
|
-
].join("\n");
|
|
1038
|
-
writeFileSync4(ctxFile, ctxContent);
|
|
1039
|
-
sessionContextFlag = ` --append-system-prompt-file ${ctxFile}`;
|
|
1040
|
-
} catch {
|
|
1041
|
-
}
|
|
1042
|
-
let envPrefix = `EXE_SESSION=${exeSession} EXE_SESSION_NAME=${sessionName}`;
|
|
1043
|
-
if (ccProvider !== DEFAULT_PROVIDER) {
|
|
1044
|
-
const cfg = PROVIDER_TABLE[ccProvider];
|
|
1045
|
-
if (cfg?.apiKeyEnv) {
|
|
1046
|
-
const keyVal = process.env[cfg.apiKeyEnv];
|
|
1047
|
-
if (keyVal) {
|
|
1048
|
-
envPrefix = `${envPrefix} ${cfg.apiKeyEnv}=${keyVal}`;
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
let spawnCommand;
|
|
1053
|
-
if (useExeAgent) {
|
|
1054
|
-
spawnCommand = `${envPrefix} exe-agent --employee ${employeeName} --model ${opts.model} --provider ${opts.provider}${cleanupSuffix}`;
|
|
1055
|
-
} else if (useBinSymlink) {
|
|
1056
|
-
const binName = `${employeeName}-${ccProvider}`;
|
|
1057
|
-
process.stderr.write(
|
|
1058
|
-
`[tmux-routing] provider cascade: ${ccProvider} \u2192 spawning ${binName}
|
|
1059
|
-
`
|
|
1060
|
-
);
|
|
1061
|
-
spawnCommand = `${envPrefix} ${binName}${cleanupSuffix}`;
|
|
1062
|
-
} else {
|
|
1063
|
-
spawnCommand = `${envPrefix} claude --dangerously-skip-permissions${identityFlag}${behaviorsFlag}${sessionContextFlag}${cleanupSuffix}`;
|
|
1064
|
-
}
|
|
1065
|
-
const spawnResult = transport.spawn(sessionName, {
|
|
1066
|
-
cwd: spawnCwd,
|
|
1067
|
-
command: spawnCommand
|
|
1068
|
-
});
|
|
1069
|
-
if (spawnResult.error) {
|
|
1070
|
-
return { sessionName, error: `tmux new-session failed: ${spawnResult.error}` };
|
|
1071
|
-
}
|
|
1072
|
-
transport.pipeLog(sessionName, logFile);
|
|
1073
|
-
try {
|
|
1074
|
-
const mySession = getMySession();
|
|
1075
|
-
const dispatchInfo = path8.join(SESSION_CACHE, `dispatch-info-${sessionName}.json`);
|
|
1076
|
-
writeFileSync4(dispatchInfo, JSON.stringify({
|
|
1077
|
-
dispatchedBy: mySession,
|
|
1078
|
-
rootExe: exeSession,
|
|
1079
|
-
provider: useBinSymlink ? ccProvider : useExeAgent ? opts.provider : "anthropic",
|
|
1080
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1081
|
-
}));
|
|
1082
|
-
} catch {
|
|
1083
|
-
}
|
|
1084
|
-
let booted = false;
|
|
1085
|
-
for (let i = 0; i < 30; i++) {
|
|
1086
|
-
try {
|
|
1087
|
-
execSync5("sleep 0.5");
|
|
1088
|
-
} catch {
|
|
1089
|
-
}
|
|
1090
|
-
try {
|
|
1091
|
-
const pane = transport.capturePane(sessionName);
|
|
1092
|
-
if (useExeAgent) {
|
|
1093
|
-
if (pane.includes("[exe-agent]") || pane.includes("online")) {
|
|
1094
|
-
booted = true;
|
|
1095
|
-
break;
|
|
1096
|
-
}
|
|
1097
|
-
} else {
|
|
1098
|
-
if (pane.includes("Claude Code") || pane.includes("\u276F")) {
|
|
1099
|
-
booted = true;
|
|
1100
|
-
break;
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
} catch {
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
if (!booted) {
|
|
1107
|
-
return { sessionName, error: `${useExeAgent ? "exe-agent" : "claude"} did not boot within 15s` };
|
|
1108
|
-
}
|
|
1109
|
-
if (!useExeAgent) {
|
|
1110
|
-
try {
|
|
1111
|
-
transport.sendKeys(sessionName, `/exe-call ${employeeName}`);
|
|
1112
|
-
} catch {
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
registerSession({
|
|
1116
|
-
windowName: sessionName,
|
|
1117
|
-
agentId: employeeName,
|
|
1118
|
-
projectDir: spawnCwd,
|
|
1119
|
-
parentExe: exeSession,
|
|
1120
|
-
pid: 0,
|
|
1121
|
-
registeredAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1122
|
-
});
|
|
1123
|
-
return { sessionName };
|
|
1124
|
-
}
|
|
1125
|
-
var SESSION_CACHE, BEHAVIORS_EXPORT_TIMEOUT_MS, INTERCOM_DEBOUNCE_MS, INTERCOM_LOG2, DEBOUNCE_FILE, DEBOUNCE_CLEANUP_AGE_MS, BUSY_PATTERN;
|
|
1126
|
-
var init_tmux_routing = __esm({
|
|
1127
|
-
"src/lib/tmux-routing.ts"() {
|
|
1128
|
-
"use strict";
|
|
1129
|
-
init_session_registry();
|
|
1130
|
-
init_session_key();
|
|
1131
|
-
init_transport();
|
|
1132
|
-
init_cc_agent_support();
|
|
1133
|
-
init_mcp_prefix();
|
|
1134
|
-
init_provider_table();
|
|
1135
|
-
init_intercom_queue();
|
|
1136
|
-
init_plan_limits();
|
|
1137
|
-
init_worktree();
|
|
1138
|
-
SESSION_CACHE = path8.join(os4.homedir(), ".exe-os", "session-cache");
|
|
1139
|
-
BEHAVIORS_EXPORT_TIMEOUT_MS = 1e4;
|
|
1140
|
-
INTERCOM_DEBOUNCE_MS = 3e4;
|
|
1141
|
-
INTERCOM_LOG2 = path8.join(os4.homedir(), ".exe-os", "intercom.log");
|
|
1142
|
-
DEBOUNCE_FILE = path8.join(SESSION_CACHE, "intercom-debounce.json");
|
|
1143
|
-
DEBOUNCE_CLEANUP_AGE_MS = 5 * 60 * 1e3;
|
|
1144
|
-
BUSY_PATTERN = /[✻✽✶✳·].*…|Running…/;
|
|
1145
|
-
}
|
|
1146
|
-
});
|
|
1147
|
-
|
|
1148
|
-
// src/mcp/tools/send-message.ts
|
|
1149
|
-
import { z } from "zod";
|
|
1150
|
-
|
|
1151
|
-
// src/lib/messaging.ts
|
|
1152
|
-
init_database();
|
|
1153
|
-
init_tmux_routing();
|
|
1154
|
-
import crypto from "crypto";
|
|
1155
|
-
function generateUlid() {
|
|
1156
|
-
const timestamp = Date.now().toString(36).padStart(10, "0");
|
|
1157
|
-
const random = crypto.randomBytes(10).toString("hex").slice(0, 16);
|
|
1158
|
-
return (timestamp + random).toUpperCase();
|
|
1159
|
-
}
|
|
1160
|
-
function rowToMessage(row) {
|
|
1161
|
-
return {
|
|
1162
|
-
id: row.id,
|
|
1163
|
-
fromAgent: row.from_agent,
|
|
1164
|
-
fromDevice: row.from_device,
|
|
1165
|
-
targetAgent: row.target_agent,
|
|
1166
|
-
targetProject: row.target_project ?? null,
|
|
1167
|
-
targetDevice: row.target_device,
|
|
1168
|
-
content: row.content,
|
|
1169
|
-
priority: row.priority ?? "normal",
|
|
1170
|
-
status: row.status ?? "pending",
|
|
1171
|
-
serverSeq: row.server_seq != null ? Number(row.server_seq) : null,
|
|
1172
|
-
retryCount: Number(row.retry_count ?? 0),
|
|
1173
|
-
createdAt: row.created_at,
|
|
1174
|
-
deliveredAt: row.delivered_at ?? null,
|
|
1175
|
-
processedAt: row.processed_at ?? null,
|
|
1176
|
-
failedAt: row.failed_at ?? null,
|
|
1177
|
-
failureReason: row.failure_reason ?? null
|
|
1178
|
-
};
|
|
1179
|
-
}
|
|
1180
|
-
var MAX_RETRIES = 10;
|
|
1181
|
-
async function sendMessage(input) {
|
|
1182
|
-
const client = getClient();
|
|
1183
|
-
const id = generateUlid();
|
|
1184
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1185
|
-
const targetDevice = input.targetDevice ?? "local";
|
|
1186
|
-
await client.execute({
|
|
1187
|
-
sql: `INSERT INTO messages (id, from_agent, from_device, target_agent, target_project, target_device, content, priority, status, created_at)
|
|
1188
|
-
VALUES (?, ?, 'local', ?, ?, ?, ?, ?, 'pending', ?)`,
|
|
1189
|
-
args: [
|
|
1190
|
-
id,
|
|
1191
|
-
input.fromAgent,
|
|
1192
|
-
input.targetAgent,
|
|
1193
|
-
input.targetProject ?? null,
|
|
1194
|
-
targetDevice,
|
|
1195
|
-
input.content,
|
|
1196
|
-
input.priority ?? "normal",
|
|
1197
|
-
now
|
|
1198
|
-
]
|
|
1199
|
-
});
|
|
1200
|
-
try {
|
|
1201
|
-
if (targetDevice !== "local") {
|
|
1202
|
-
await deliverCrossMachineMessage(id, targetDevice);
|
|
1203
|
-
} else {
|
|
1204
|
-
await deliverLocalMessage(id);
|
|
1205
|
-
}
|
|
1206
|
-
} catch {
|
|
1207
|
-
}
|
|
1208
|
-
const result = await client.execute({
|
|
1209
|
-
sql: "SELECT * FROM messages WHERE id = ?",
|
|
1210
|
-
args: [id]
|
|
1211
|
-
});
|
|
1212
|
-
return rowToMessage(result.rows[0]);
|
|
1213
|
-
}
|
|
1214
|
-
var _wsClientSend = null;
|
|
1215
|
-
async function deliverCrossMachineMessage(messageId, targetDevice) {
|
|
1216
|
-
const client = getClient();
|
|
1217
|
-
const result = await client.execute({
|
|
1218
|
-
sql: "SELECT * FROM messages WHERE id = ?",
|
|
1219
|
-
args: [messageId]
|
|
1220
|
-
});
|
|
1221
|
-
if (result.rows.length === 0) return false;
|
|
1222
|
-
const msg = rowToMessage(result.rows[0]);
|
|
1223
|
-
if (msg.status !== "pending") return false;
|
|
1224
|
-
if (!_wsClientSend) {
|
|
1225
|
-
return false;
|
|
1226
|
-
}
|
|
1227
|
-
const payload = JSON.stringify({
|
|
1228
|
-
id: msg.id,
|
|
1229
|
-
fromAgent: msg.fromAgent,
|
|
1230
|
-
targetAgent: msg.targetAgent,
|
|
1231
|
-
targetProject: msg.targetProject,
|
|
1232
|
-
content: msg.content,
|
|
1233
|
-
priority: msg.priority,
|
|
1234
|
-
createdAt: msg.createdAt
|
|
1235
|
-
});
|
|
1236
|
-
const sent = _wsClientSend(targetDevice, payload);
|
|
1237
|
-
if (sent) {
|
|
1238
|
-
await client.execute({
|
|
1239
|
-
sql: "UPDATE messages SET status = 'synced' WHERE id = ?",
|
|
1240
|
-
args: [messageId]
|
|
1241
|
-
});
|
|
1242
|
-
return true;
|
|
1243
|
-
}
|
|
1244
|
-
return false;
|
|
1245
|
-
}
|
|
1246
|
-
async function deliverLocalMessage(messageId) {
|
|
1247
|
-
const client = getClient();
|
|
1248
|
-
const result = await client.execute({
|
|
1249
|
-
sql: "SELECT * FROM messages WHERE id = ?",
|
|
1250
|
-
args: [messageId]
|
|
1251
|
-
});
|
|
1252
|
-
if (result.rows.length === 0) return false;
|
|
1253
|
-
const msg = rowToMessage(result.rows[0]);
|
|
1254
|
-
if (msg.status !== "pending") return false;
|
|
1255
|
-
const targetAgent = msg.targetAgent;
|
|
1256
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1257
|
-
try {
|
|
1258
|
-
const exeSession = resolveExeSession();
|
|
1259
|
-
if (!exeSession) {
|
|
1260
|
-
throw new Error("No exe session found");
|
|
1261
|
-
}
|
|
1262
|
-
const ensureResult = ensureEmployee(targetAgent, exeSession, process.cwd());
|
|
1263
|
-
if (ensureResult.status === "failed") {
|
|
1264
|
-
throw new Error(ensureResult.error ?? "ensureEmployee failed");
|
|
1265
|
-
}
|
|
1266
|
-
await client.execute({
|
|
1267
|
-
sql: "UPDATE messages SET status = 'delivered', delivered_at = ? WHERE id = ?",
|
|
1268
|
-
args: [now, messageId]
|
|
1269
|
-
});
|
|
1270
|
-
return true;
|
|
1271
|
-
} catch {
|
|
1272
|
-
const newRetryCount = msg.retryCount + 1;
|
|
1273
|
-
if (newRetryCount >= MAX_RETRIES) {
|
|
1274
|
-
await markFailed(messageId, "session unavailable after 10 retries");
|
|
1275
|
-
} else {
|
|
1276
|
-
await client.execute({
|
|
1277
|
-
sql: "UPDATE messages SET retry_count = ? WHERE id = ?",
|
|
1278
|
-
args: [newRetryCount, messageId]
|
|
1279
|
-
});
|
|
1280
|
-
}
|
|
1281
|
-
return false;
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
async function markFailed(messageId, reason) {
|
|
1285
|
-
const client = getClient();
|
|
1286
|
-
await client.execute({
|
|
1287
|
-
sql: "UPDATE messages SET status = 'failed', failed_at = ?, failure_reason = ? WHERE id = ?",
|
|
1288
|
-
args: [(/* @__PURE__ */ new Date()).toISOString(), reason, messageId]
|
|
1289
|
-
});
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
// src/adapters/claude/active-agent.ts
|
|
1293
|
-
init_config();
|
|
1294
|
-
import { readFileSync as readFileSync8, writeFileSync as writeFileSync5, mkdirSync as mkdirSync6, unlinkSync, readdirSync } from "fs";
|
|
1295
|
-
import { execSync as execSync6 } from "child_process";
|
|
1296
|
-
import path9 from "path";
|
|
1297
|
-
|
|
1298
|
-
// src/adapters/claude/session-key.ts
|
|
1299
|
-
init_session_key();
|
|
1300
|
-
|
|
1301
|
-
// src/adapters/claude/active-agent.ts
|
|
1302
|
-
var CACHE_DIR = path9.join(EXE_AI_DIR, "session-cache");
|
|
1303
|
-
var STALE_MS = 24 * 60 * 60 * 1e3;
|
|
1304
|
-
function getMarkerPath() {
|
|
1305
|
-
return path9.join(CACHE_DIR, `active-agent-${getSessionKey()}.json`);
|
|
1306
|
-
}
|
|
1307
|
-
function getActiveAgent() {
|
|
1308
|
-
try {
|
|
1309
|
-
const markerPath = getMarkerPath();
|
|
1310
|
-
const raw = readFileSync8(markerPath, "utf8");
|
|
1311
|
-
const data = JSON.parse(raw);
|
|
1312
|
-
if (data.agentId) {
|
|
1313
|
-
if (data.startedAt) {
|
|
1314
|
-
const age = Date.now() - new Date(data.startedAt).getTime();
|
|
1315
|
-
if (age > STALE_MS) {
|
|
1316
|
-
try {
|
|
1317
|
-
unlinkSync(markerPath);
|
|
1318
|
-
} catch {
|
|
1319
|
-
}
|
|
1320
|
-
} else {
|
|
1321
|
-
return {
|
|
1322
|
-
agentId: data.agentId,
|
|
1323
|
-
agentRole: data.agentRole || "employee"
|
|
1324
|
-
};
|
|
1325
|
-
}
|
|
1326
|
-
} else {
|
|
1327
|
-
return {
|
|
1328
|
-
agentId: data.agentId,
|
|
1329
|
-
agentRole: data.agentRole || "employee"
|
|
1330
|
-
};
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
} catch {
|
|
1334
|
-
}
|
|
1335
|
-
try {
|
|
1336
|
-
const sessionName = execSync6(
|
|
1337
|
-
"tmux display-message -p '#{session_name}' 2>/dev/null",
|
|
1338
|
-
{ encoding: "utf8", timeout: 2e3 }
|
|
1339
|
-
).trim();
|
|
1340
|
-
const empMatch = sessionName.match(/^(\w+)-exe\d+$/);
|
|
1341
|
-
if (empMatch && empMatch[1] !== "exe") {
|
|
1342
|
-
return { agentId: empMatch[1], agentRole: "employee" };
|
|
1343
|
-
}
|
|
1344
|
-
if (/^exe\d+$/.test(sessionName)) {
|
|
1345
|
-
return { agentId: "exe", agentRole: "COO" };
|
|
1346
|
-
}
|
|
1347
|
-
} catch {
|
|
1348
|
-
}
|
|
1349
|
-
return {
|
|
1350
|
-
agentId: process.env.AGENT_ID || "default",
|
|
1351
|
-
agentRole: process.env.AGENT_ROLE || "employee"
|
|
1352
|
-
};
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
// src/mcp/tools/send-message.ts
|
|
1356
|
-
function registerSendMessage(server) {
|
|
1357
|
-
server.registerTool(
|
|
1358
|
-
"send_message",
|
|
1359
|
-
{
|
|
1360
|
-
title: "Send Message",
|
|
1361
|
-
description: "Send a structured message to another agent. Messages are queued and delivered via intercom.",
|
|
1362
|
-
inputSchema: {
|
|
1363
|
-
target_agent: z.string().describe("Recipient agent name (e.g., 'yoshi', 'tom', 'exe')"),
|
|
1364
|
-
content: z.string().describe("Message content"),
|
|
1365
|
-
target_project: z.string().optional().describe("Project context (optional)"),
|
|
1366
|
-
priority: z.enum(["normal", "urgent"]).default("normal").describe("Message priority (default: normal)"),
|
|
1367
|
-
target_device: z.string().optional().describe("Target device ID for cross-machine delivery (default: local)")
|
|
1368
|
-
}
|
|
1369
|
-
},
|
|
1370
|
-
async ({ target_agent, content, target_project, priority, target_device }) => {
|
|
1371
|
-
const { agentId } = getActiveAgent();
|
|
1372
|
-
const msg = await sendMessage({
|
|
1373
|
-
fromAgent: agentId,
|
|
1374
|
-
targetAgent: target_agent,
|
|
1375
|
-
targetProject: target_project,
|
|
1376
|
-
targetDevice: target_device,
|
|
1377
|
-
content,
|
|
1378
|
-
priority
|
|
1379
|
-
});
|
|
1380
|
-
const statusText = msg.status === "delivered" ? "delivered" : msg.status === "failed" ? `failed: ${msg.failureReason}` : "queued (pending delivery)";
|
|
1381
|
-
return {
|
|
1382
|
-
content: [
|
|
1383
|
-
{
|
|
1384
|
-
type: "text",
|
|
1385
|
-
text: `Message sent to ${target_agent}: ${statusText}
|
|
1386
|
-
ID: ${msg.id}`
|
|
1387
|
-
}
|
|
1388
|
-
]
|
|
1389
|
-
};
|
|
1390
|
-
}
|
|
1391
|
-
);
|
|
1392
|
-
}
|
|
1393
|
-
export {
|
|
1394
|
-
registerSendMessage
|
|
1395
|
-
};
|