@askexenow/exe-os 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +178 -79
  2. package/package.json +1 -1
  3. package/dist/bin/backfill-responses.js +0 -1912
  4. package/dist/bin/backfill-vectors.js +0 -1642
  5. package/dist/bin/cleanup-stale-review-tasks.js +0 -1339
  6. package/dist/bin/cli.js +0 -18800
  7. package/dist/bin/exe-agent.js +0 -1858
  8. package/dist/bin/exe-assign.js +0 -1957
  9. package/dist/bin/exe-boot.js +0 -6460
  10. package/dist/bin/exe-call.js +0 -197
  11. package/dist/bin/exe-cloud.js +0 -850
  12. package/dist/bin/exe-dispatch.js +0 -1146
  13. package/dist/bin/exe-doctor.js +0 -1657
  14. package/dist/bin/exe-export-behaviors.js +0 -1494
  15. package/dist/bin/exe-forget.js +0 -1627
  16. package/dist/bin/exe-gateway.js +0 -7732
  17. package/dist/bin/exe-healthcheck.js +0 -207
  18. package/dist/bin/exe-heartbeat.js +0 -1647
  19. package/dist/bin/exe-kill.js +0 -1479
  20. package/dist/bin/exe-launch-agent.js +0 -1704
  21. package/dist/bin/exe-link.js +0 -192
  22. package/dist/bin/exe-new-employee.js +0 -852
  23. package/dist/bin/exe-pending-messages.js +0 -1446
  24. package/dist/bin/exe-pending-notifications.js +0 -1321
  25. package/dist/bin/exe-pending-reviews.js +0 -1468
  26. package/dist/bin/exe-repo-drift.js +0 -95
  27. package/dist/bin/exe-review.js +0 -1590
  28. package/dist/bin/exe-search.js +0 -2651
  29. package/dist/bin/exe-session-cleanup.js +0 -3173
  30. package/dist/bin/exe-settings.js +0 -354
  31. package/dist/bin/exe-status.js +0 -1532
  32. package/dist/bin/exe-team.js +0 -1324
  33. package/dist/bin/git-sweep.js +0 -2185
  34. package/dist/bin/graph-backfill.js +0 -1968
  35. package/dist/bin/graph-export.js +0 -1604
  36. package/dist/bin/install.js +0 -656
  37. package/dist/bin/list-providers.js +0 -140
  38. package/dist/bin/scan-tasks.js +0 -1820
  39. package/dist/bin/setup.js +0 -951
  40. package/dist/bin/shard-migrate.js +0 -1494
  41. package/dist/bin/update.js +0 -95
  42. package/dist/bin/wiki-sync.js +0 -1514
  43. package/dist/gateway/index.js +0 -8848
  44. package/dist/hooks/bug-report-worker.js +0 -2743
  45. package/dist/hooks/commit-complete.js +0 -2108
  46. package/dist/hooks/error-recall.js +0 -2861
  47. package/dist/hooks/exe-heartbeat-hook.js +0 -232
  48. package/dist/hooks/ingest-worker.js +0 -4793
  49. package/dist/hooks/ingest.js +0 -684
  50. package/dist/hooks/instructions-loaded.js +0 -1880
  51. package/dist/hooks/notification.js +0 -1726
  52. package/dist/hooks/post-compact.js +0 -1751
  53. package/dist/hooks/pre-compact.js +0 -1746
  54. package/dist/hooks/pre-tool-use.js +0 -2191
  55. package/dist/hooks/prompt-ingest-worker.js +0 -2126
  56. package/dist/hooks/prompt-submit.js +0 -4693
  57. package/dist/hooks/response-ingest-worker.js +0 -1936
  58. package/dist/hooks/session-end.js +0 -1752
  59. package/dist/hooks/session-start.js +0 -2795
  60. package/dist/hooks/stop.js +0 -1835
  61. package/dist/hooks/subagent-stop.js +0 -1726
  62. package/dist/hooks/summary-worker.js +0 -2661
  63. package/dist/index.js +0 -11834
  64. package/dist/lib/cloud-sync.js +0 -495
  65. package/dist/lib/config.js +0 -222
  66. package/dist/lib/consolidation.js +0 -476
  67. package/dist/lib/crypto.js +0 -51
  68. package/dist/lib/database.js +0 -730
  69. package/dist/lib/device-registry.js +0 -900
  70. package/dist/lib/embedder.js +0 -632
  71. package/dist/lib/employee-templates.js +0 -543
  72. package/dist/lib/employees.js +0 -177
  73. package/dist/lib/error-detector.js +0 -156
  74. package/dist/lib/exe-daemon-client.js +0 -451
  75. package/dist/lib/exe-daemon.js +0 -8285
  76. package/dist/lib/file-grep.js +0 -199
  77. package/dist/lib/hybrid-search.js +0 -1819
  78. package/dist/lib/identity-templates.js +0 -320
  79. package/dist/lib/identity.js +0 -223
  80. package/dist/lib/keychain.js +0 -145
  81. package/dist/lib/license.js +0 -377
  82. package/dist/lib/messaging.js +0 -1376
  83. package/dist/lib/reminders.js +0 -63
  84. package/dist/lib/schedules.js +0 -1396
  85. package/dist/lib/session-registry.js +0 -52
  86. package/dist/lib/skill-learning.js +0 -477
  87. package/dist/lib/status-brief.js +0 -235
  88. package/dist/lib/store.js +0 -1551
  89. package/dist/lib/task-router.js +0 -62
  90. package/dist/lib/tasks.js +0 -2456
  91. package/dist/lib/tmux-routing.js +0 -2836
  92. package/dist/lib/tmux-status.js +0 -261
  93. package/dist/lib/tmux-transport.js +0 -83
  94. package/dist/lib/transport.js +0 -128
  95. package/dist/lib/ws-auth.js +0 -19
  96. package/dist/lib/ws-client.js +0 -160
  97. package/dist/mcp/server.js +0 -10538
  98. package/dist/mcp/tools/complete-reminder.js +0 -67
  99. package/dist/mcp/tools/create-reminder.js +0 -52
  100. package/dist/mcp/tools/create-task.js +0 -1853
  101. package/dist/mcp/tools/deactivate-behavior.js +0 -263
  102. package/dist/mcp/tools/list-reminders.js +0 -62
  103. package/dist/mcp/tools/list-tasks.js +0 -463
  104. package/dist/mcp/tools/send-message.js +0 -1382
  105. package/dist/mcp/tools/update-task.js +0 -1692
  106. package/dist/runtime/index.js +0 -6809
  107. package/dist/tui/App.js +0 -17479
@@ -1,1146 +0,0 @@
1
- #!/usr/bin/env node
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __esm = (fn, res) => function __init() {
7
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
- };
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
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);
22
-
23
- // src/lib/session-registry.ts
24
- import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
25
- import path from "path";
26
- import os from "os";
27
- function registerSession(entry) {
28
- const dir = path.dirname(REGISTRY_PATH);
29
- if (!existsSync(dir)) {
30
- mkdirSync(dir, { recursive: true });
31
- }
32
- const sessions = listSessions();
33
- const idx = sessions.findIndex((s) => s.windowName === entry.windowName);
34
- if (idx >= 0) {
35
- sessions[idx] = entry;
36
- } else {
37
- sessions.push(entry);
38
- }
39
- writeFileSync(REGISTRY_PATH, JSON.stringify(sessions, null, 2));
40
- }
41
- function listSessions() {
42
- try {
43
- const raw = readFileSync(REGISTRY_PATH, "utf8");
44
- return JSON.parse(raw);
45
- } catch {
46
- return [];
47
- }
48
- }
49
- var REGISTRY_PATH;
50
- var init_session_registry = __esm({
51
- "src/lib/session-registry.ts"() {
52
- "use strict";
53
- REGISTRY_PATH = path.join(os.homedir(), ".exe-os", "session-registry.json");
54
- }
55
- });
56
-
57
- // src/lib/session-key.ts
58
- import { execSync } from "child_process";
59
- function getSessionKey() {
60
- if (_cached) return _cached;
61
- let pid = process.ppid;
62
- for (let i = 0; i < 10; i++) {
63
- try {
64
- const info = execSync(`ps -p ${pid} -o ppid=,comm=`, {
65
- encoding: "utf8",
66
- timeout: 2e3
67
- }).trim();
68
- const match = info.match(/^\s*(\d+)\s+(.+)$/);
69
- if (!match) break;
70
- const [, ppid, cmd] = match;
71
- if (cmd === "claude" || cmd.endsWith("/claude")) {
72
- _cached = String(pid);
73
- return _cached;
74
- }
75
- pid = parseInt(ppid, 10);
76
- if (pid <= 1) break;
77
- } catch {
78
- break;
79
- }
80
- }
81
- _cached = process.env.CLAUDE_CODE_SSE_PORT ?? String(process.ppid);
82
- return _cached;
83
- }
84
- var _cached;
85
- var init_session_key = __esm({
86
- "src/lib/session-key.ts"() {
87
- "use strict";
88
- _cached = null;
89
- }
90
- });
91
-
92
- // src/lib/tmux-transport.ts
93
- var tmux_transport_exports = {};
94
- __export(tmux_transport_exports, {
95
- TmuxTransport: () => TmuxTransport
96
- });
97
- import { execFileSync } from "child_process";
98
- var QUIET, TmuxTransport;
99
- var init_tmux_transport = __esm({
100
- "src/lib/tmux-transport.ts"() {
101
- "use strict";
102
- QUIET = {
103
- encoding: "utf8",
104
- stdio: ["pipe", "pipe", "pipe"]
105
- };
106
- TmuxTransport = class {
107
- getMySession() {
108
- try {
109
- return execFileSync("tmux", ["display-message", "-p", "#{session_name}"], QUIET).trim() || null;
110
- } catch {
111
- return null;
112
- }
113
- }
114
- listSessions() {
115
- try {
116
- return execFileSync("tmux", ["list-sessions", "-F", "#{session_name}"], QUIET).trim().split("\n").filter(Boolean);
117
- } catch {
118
- return [];
119
- }
120
- }
121
- isAlive(target) {
122
- try {
123
- const sessions = this.listSessions();
124
- if (!sessions.includes(target)) return false;
125
- const paneStatus = execFileSync(
126
- "tmux",
127
- ["list-panes", "-t", target, "-F", "#{pane_dead}"],
128
- QUIET
129
- ).trim();
130
- return paneStatus !== "1";
131
- } catch {
132
- return false;
133
- }
134
- }
135
- sendKeys(target, keys) {
136
- execFileSync("tmux", ["send-keys", "-t", target, keys, "Enter"], QUIET);
137
- }
138
- capturePane(target, lines) {
139
- const args = ["capture-pane", "-t", target, "-p"];
140
- if (lines) args.push("-S", `-${lines}`);
141
- return execFileSync("tmux", args, { ...QUIET, timeout: 3e3 });
142
- }
143
- isPaneInCopyMode(target) {
144
- try {
145
- const result2 = execFileSync(
146
- "tmux",
147
- ["display-message", "-p", "-t", target, "#{pane_in_mode}"],
148
- { ...QUIET, timeout: 3e3 }
149
- ).trim();
150
- return result2 === "1";
151
- } catch {
152
- return false;
153
- }
154
- }
155
- spawn(name, config) {
156
- try {
157
- const args = ["new-session", "-d", "-s", name];
158
- if (config.cwd) args.push("-c", config.cwd);
159
- args.push(config.command);
160
- execFileSync("tmux", args);
161
- return { sessionName: name };
162
- } catch (e) {
163
- return { sessionName: name, error: `spawn failed: ${e}` };
164
- }
165
- }
166
- kill(target) {
167
- try {
168
- execFileSync("tmux", ["kill-session", "-t", target], QUIET);
169
- } catch {
170
- }
171
- }
172
- pipeLog(target, logFile) {
173
- try {
174
- const safePath = logFile.replace(/'/g, "'\\''");
175
- execFileSync("tmux", ["pipe-pane", "-t", target, `cat >> '${safePath}'`], QUIET);
176
- } catch {
177
- }
178
- }
179
- };
180
- }
181
- });
182
-
183
- // src/lib/transport.ts
184
- function getTransport() {
185
- if (!_transport) {
186
- const { TmuxTransport: TmuxTransport2 } = (init_tmux_transport(), __toCommonJS(tmux_transport_exports));
187
- _transport = new TmuxTransport2();
188
- }
189
- return _transport;
190
- }
191
- var _transport;
192
- var init_transport = __esm({
193
- "src/lib/transport.ts"() {
194
- "use strict";
195
- _transport = null;
196
- }
197
- });
198
-
199
- // src/lib/cc-agent-support.ts
200
- import { execSync as execSync2 } from "child_process";
201
- function _resetCcAgentSupportCache() {
202
- _cachedSupport = null;
203
- }
204
- function claudeSupportsAgentFlag() {
205
- if (_cachedSupport !== null) return _cachedSupport;
206
- try {
207
- const helpOutput = execSync2("claude --help 2>&1", {
208
- encoding: "utf-8",
209
- timeout: 5e3
210
- });
211
- _cachedSupport = /(^|\s)--agent(\b|=)/.test(helpOutput);
212
- } catch {
213
- _cachedSupport = false;
214
- }
215
- return _cachedSupport;
216
- }
217
- var _cachedSupport;
218
- var init_cc_agent_support = __esm({
219
- "src/lib/cc-agent-support.ts"() {
220
- "use strict";
221
- _cachedSupport = null;
222
- }
223
- });
224
-
225
- // src/lib/mcp-prefix.ts
226
- function expandDualPrefixTools(shortNames) {
227
- const out = [];
228
- for (const name of shortNames) {
229
- for (const prefix of MCP_TOOL_PREFIXES) {
230
- out.push(prefix + name);
231
- }
232
- }
233
- return out;
234
- }
235
- var MCP_PRIMARY_KEY, MCP_LEGACY_KEY, MCP_TOOL_PREFIXES;
236
- var init_mcp_prefix = __esm({
237
- "src/lib/mcp-prefix.ts"() {
238
- "use strict";
239
- MCP_PRIMARY_KEY = "exe-os";
240
- MCP_LEGACY_KEY = "exe-mem";
241
- MCP_TOOL_PREFIXES = [
242
- `mcp__${MCP_PRIMARY_KEY}__`,
243
- `mcp__${MCP_LEGACY_KEY}__`
244
- ];
245
- }
246
- });
247
-
248
- // src/lib/provider-table.ts
249
- function detectActiveProvider(env = process.env) {
250
- const baseUrl = env.ANTHROPIC_BASE_URL;
251
- if (!baseUrl) return DEFAULT_PROVIDER;
252
- for (const [name, cfg] of Object.entries(PROVIDER_TABLE)) {
253
- if (cfg.baseUrl === baseUrl) return name;
254
- }
255
- return DEFAULT_PROVIDER;
256
- }
257
- var PROVIDER_TABLE, DEFAULT_PROVIDER;
258
- var init_provider_table = __esm({
259
- "src/lib/provider-table.ts"() {
260
- "use strict";
261
- PROVIDER_TABLE = {
262
- opencode: {
263
- baseUrl: "https://opencode.ai/zen/go",
264
- apiKeyEnv: "OPENCODE_API_KEY",
265
- defaultModel: "minimax-m2.7"
266
- }
267
- };
268
- DEFAULT_PROVIDER = "default";
269
- }
270
- });
271
-
272
- // src/lib/intercom-queue.ts
273
- import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, renameSync, existsSync as existsSync2, mkdirSync as mkdirSync2 } from "fs";
274
- import path2 from "path";
275
- import os2 from "os";
276
- function ensureDir() {
277
- const dir = path2.dirname(QUEUE_PATH);
278
- if (!existsSync2(dir)) mkdirSync2(dir, { recursive: true });
279
- }
280
- function readQueue() {
281
- try {
282
- if (!existsSync2(QUEUE_PATH)) return [];
283
- return JSON.parse(readFileSync2(QUEUE_PATH, "utf8"));
284
- } catch {
285
- return [];
286
- }
287
- }
288
- function writeQueue(queue) {
289
- ensureDir();
290
- const tmp = `${QUEUE_PATH}.tmp`;
291
- writeFileSync2(tmp, JSON.stringify(queue, null, 2));
292
- renameSync(tmp, QUEUE_PATH);
293
- }
294
- function queueIntercom(targetSession, reason) {
295
- const queue = readQueue();
296
- const existing = queue.find((q) => q.targetSession === targetSession);
297
- if (existing) {
298
- existing.attempts++;
299
- existing.queuedAt = (/* @__PURE__ */ new Date()).toISOString();
300
- existing.reason = reason;
301
- } else {
302
- queue.push({
303
- targetSession,
304
- queuedAt: (/* @__PURE__ */ new Date()).toISOString(),
305
- attempts: 0,
306
- reason
307
- });
308
- }
309
- writeQueue(queue);
310
- }
311
- var QUEUE_PATH, INTERCOM_LOG;
312
- var init_intercom_queue = __esm({
313
- "src/lib/intercom-queue.ts"() {
314
- "use strict";
315
- QUEUE_PATH = path2.join(os2.homedir(), ".exe-os", "intercom-queue.json");
316
- INTERCOM_LOG = path2.join(os2.homedir(), ".exe-os", "intercom.log");
317
- }
318
- });
319
-
320
- // src/lib/database.ts
321
- import { createClient } from "@libsql/client";
322
- var init_database = __esm({
323
- "src/lib/database.ts"() {
324
- "use strict";
325
- }
326
- });
327
-
328
- // src/lib/config.ts
329
- import { readFile, writeFile, mkdir } from "fs/promises";
330
- import { readFileSync as readFileSync3, existsSync as existsSync3, renameSync as renameSync2 } from "fs";
331
- import path3 from "path";
332
- import os3 from "os";
333
- function resolveDataDir() {
334
- if (process.env.EXE_OS_DIR) return process.env.EXE_OS_DIR;
335
- if (process.env.EXE_MEM_DIR) return process.env.EXE_MEM_DIR;
336
- const newDir = path3.join(os3.homedir(), ".exe-os");
337
- const legacyDir = path3.join(os3.homedir(), ".exe-mem");
338
- if (!existsSync3(newDir) && existsSync3(legacyDir)) {
339
- try {
340
- renameSync2(legacyDir, newDir);
341
- process.stderr.write(`[exe-os] Migrated data directory: ~/.exe-mem \u2192 ~/.exe-os
342
- `);
343
- } catch {
344
- return legacyDir;
345
- }
346
- }
347
- return newDir;
348
- }
349
- var EXE_AI_DIR, DB_PATH, MODELS_DIR, CONFIG_PATH, LEGACY_LANCE_PATH, CURRENT_CONFIG_VERSION, DEFAULT_CONFIG;
350
- var init_config = __esm({
351
- "src/lib/config.ts"() {
352
- "use strict";
353
- EXE_AI_DIR = resolveDataDir();
354
- DB_PATH = path3.join(EXE_AI_DIR, "memories.db");
355
- MODELS_DIR = path3.join(EXE_AI_DIR, "models");
356
- CONFIG_PATH = path3.join(EXE_AI_DIR, "config.json");
357
- LEGACY_LANCE_PATH = path3.join(EXE_AI_DIR, "local.lance");
358
- CURRENT_CONFIG_VERSION = 1;
359
- DEFAULT_CONFIG = {
360
- config_version: CURRENT_CONFIG_VERSION,
361
- dbPath: DB_PATH,
362
- modelFile: "jina-embeddings-v5-small-q4_k_m.gguf",
363
- embeddingDim: 1024,
364
- batchSize: 20,
365
- flushIntervalMs: 1e4,
366
- autoIngestion: true,
367
- autoRetrieval: true,
368
- searchMode: "hybrid",
369
- hookSearchMode: "hybrid",
370
- fileGrepEnabled: true,
371
- splashEffect: true,
372
- consolidationEnabled: true,
373
- consolidationIntervalMs: 6 * 60 * 60 * 1e3,
374
- consolidationModel: "claude-haiku-4-5-20251001",
375
- consolidationMaxCallsPerRun: 20,
376
- selfQueryRouter: true,
377
- selfQueryModel: "claude-haiku-4-5-20251001",
378
- rerankerEnabled: true,
379
- scalingRoadmap: {
380
- rerankerAutoTrigger: {
381
- enabled: true,
382
- broadQueryMinCardinality: 5e4,
383
- fetchTopK: 150,
384
- returnTopK: 5
385
- }
386
- },
387
- graphRagEnabled: true,
388
- wikiEnabled: false,
389
- wikiUrl: "",
390
- wikiApiKey: "",
391
- wikiSyncIntervalMs: 30 * 60 * 1e3,
392
- wikiWorkspaceMapping: {
393
- exe: "Executive",
394
- yoshi: "Engineering",
395
- mari: "Marketing",
396
- tom: "Engineering",
397
- sasha: "Production"
398
- },
399
- wikiAutoUpdate: true,
400
- wikiAutoUpdateThreshold: 0.5,
401
- wikiAutoUpdateCreateNew: true,
402
- skillLearning: true,
403
- skillThreshold: 3,
404
- skillModel: "claude-haiku-4-5-20251001",
405
- exeHeartbeat: {
406
- enabled: true,
407
- intervalSeconds: 60,
408
- staleInProgressThresholdHours: 2
409
- },
410
- sessionLifecycle: {
411
- idleKillEnabled: true,
412
- idleKillTicksRequired: 3,
413
- idleKillIntercomAckWindowMs: 1e4,
414
- maxAutoInstances: 10
415
- }
416
- };
417
- }
418
- });
419
-
420
- // src/lib/employees.ts
421
- import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
422
- import { existsSync as existsSync4, symlinkSync, readlinkSync } from "fs";
423
- import { execSync as execSync3 } from "child_process";
424
- import path4 from "path";
425
- var EMPLOYEES_PATH;
426
- var init_employees = __esm({
427
- "src/lib/employees.ts"() {
428
- "use strict";
429
- init_config();
430
- EMPLOYEES_PATH = path4.join(EXE_AI_DIR, "exe-employees.json");
431
- }
432
- });
433
-
434
- // src/lib/license.ts
435
- import { readFileSync as readFileSync4, writeFileSync as writeFileSync3, existsSync as existsSync5, mkdirSync as mkdirSync3 } from "fs";
436
- import { randomUUID } from "crypto";
437
- import path5 from "path";
438
- import { jwtVerify, importSPKI } from "jose";
439
- var LICENSE_PATH, CACHE_PATH, DEVICE_ID_PATH, PLAN_LIMITS;
440
- var init_license = __esm({
441
- "src/lib/license.ts"() {
442
- "use strict";
443
- init_config();
444
- LICENSE_PATH = path5.join(EXE_AI_DIR, "license.key");
445
- CACHE_PATH = path5.join(EXE_AI_DIR, "license-cache.json");
446
- DEVICE_ID_PATH = path5.join(EXE_AI_DIR, "device-id");
447
- PLAN_LIMITS = {
448
- free: { devices: 1, employees: 1, memories: 5e3 },
449
- pro: { devices: 2, employees: 5, memories: 1e5 },
450
- team: { devices: 10, employees: 20, memories: 1e6 },
451
- agency: { devices: 50, employees: 100, memories: 1e7 },
452
- enterprise: { devices: -1, employees: -1, memories: -1 }
453
- };
454
- }
455
- });
456
-
457
- // src/lib/plan-limits.ts
458
- import { readFileSync as readFileSync5, existsSync as existsSync6 } from "fs";
459
- import path6 from "path";
460
- function getLicenseSync() {
461
- try {
462
- if (!existsSync6(CACHE_PATH2)) return freeLicense();
463
- const raw = JSON.parse(readFileSync5(CACHE_PATH2, "utf8"));
464
- if (!raw.token || typeof raw.token !== "string") return freeLicense();
465
- const parts = raw.token.split(".");
466
- if (parts.length !== 3) return freeLicense();
467
- const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString());
468
- const plan = payload.plan ?? "free";
469
- const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
470
- return {
471
- valid: true,
472
- plan,
473
- email: payload.sub ?? "",
474
- expiresAt: payload.exp ? new Date(payload.exp * 1e3).toISOString() : null,
475
- deviceLimit: limits.devices,
476
- employeeLimit: limits.employees,
477
- memoryLimit: limits.memories
478
- };
479
- } catch {
480
- return freeLicense();
481
- }
482
- }
483
- function freeLicense() {
484
- const limits = PLAN_LIMITS.free;
485
- return {
486
- valid: true,
487
- plan: "free",
488
- email: "",
489
- expiresAt: null,
490
- deviceLimit: limits.devices,
491
- employeeLimit: limits.employees,
492
- memoryLimit: limits.memories
493
- };
494
- }
495
- function assertEmployeeLimitSync(rosterPath) {
496
- const license = getLicenseSync();
497
- if (license.employeeLimit < 0) return;
498
- const filePath = rosterPath ?? EMPLOYEES_PATH;
499
- let count = 0;
500
- try {
501
- if (existsSync6(filePath)) {
502
- const raw = readFileSync5(filePath, "utf8");
503
- const employees = JSON.parse(raw);
504
- count = Array.isArray(employees) ? employees.length : 0;
505
- }
506
- } catch {
507
- throw new PlanLimitError(
508
- `Cannot verify employee count: roster unreadable at ${filePath}. Refusing to proceed. Check file permissions or upgrade plan.`
509
- );
510
- }
511
- if (count >= license.employeeLimit) {
512
- throw new PlanLimitError(
513
- `Employee limit reached: ${count}/${license.employeeLimit} employees on the ${license.plan} plan. Upgrade at https://askexe.com to add more.`
514
- );
515
- }
516
- }
517
- var PlanLimitError, CACHE_PATH2;
518
- var init_plan_limits = __esm({
519
- "src/lib/plan-limits.ts"() {
520
- "use strict";
521
- init_database();
522
- init_employees();
523
- init_license();
524
- init_config();
525
- PlanLimitError = class extends Error {
526
- constructor(message) {
527
- super(message);
528
- this.name = "PlanLimitError";
529
- }
530
- };
531
- CACHE_PATH2 = path6.join(EXE_AI_DIR, "license-cache.json");
532
- }
533
- });
534
-
535
- // src/lib/worktree.ts
536
- import { execSync as execSync4 } from "child_process";
537
- import { existsSync as existsSync7, readFileSync as readFileSync6, appendFileSync, mkdirSync as mkdirSync4, realpathSync } from "fs";
538
- import path7 from "path";
539
- function getGitRoot(dir) {
540
- try {
541
- const root = execSync4("git rev-parse --show-toplevel", {
542
- cwd: dir,
543
- encoding: "utf-8",
544
- timeout: GIT_TIMEOUT_MS,
545
- stdio: ["pipe", "pipe", "pipe"]
546
- }).trim();
547
- return realpath(root);
548
- } catch {
549
- return null;
550
- }
551
- }
552
- function worktreePath(repoRoot, employeeName2, instance) {
553
- const label = instanceLabel(employeeName2, instance);
554
- return path7.join(repoRoot, ".worktrees", label);
555
- }
556
- function worktreeBranch(employeeName2, instance) {
557
- return `${instanceLabel(employeeName2, instance)}-work`;
558
- }
559
- function instanceLabel(name, instance) {
560
- return instance != null && instance > 0 ? `${name}${instance}` : name;
561
- }
562
- function ensureWorktree(projectDir2, employeeName2, instance) {
563
- const repoRoot = getGitRoot(projectDir2);
564
- if (!repoRoot) return null;
565
- const wtPath = worktreePath(repoRoot, employeeName2, instance);
566
- const branch = worktreeBranch(employeeName2, instance);
567
- if (existsSync7(path7.join(wtPath, ".git"))) {
568
- return wtPath;
569
- }
570
- const worktreesDir = path7.join(repoRoot, ".worktrees");
571
- mkdirSync4(worktreesDir, { recursive: true });
572
- ensureGitignoreEntry(repoRoot, "/.worktrees/");
573
- try {
574
- execSync4("git worktree prune", {
575
- cwd: repoRoot,
576
- encoding: "utf-8",
577
- timeout: GIT_TIMEOUT_MS,
578
- stdio: ["pipe", "pipe", "pipe"]
579
- });
580
- } catch {
581
- }
582
- const branchExists = branchExistsLocally(repoRoot, branch);
583
- try {
584
- if (branchExists) {
585
- execSync4(`git worktree add "${wtPath}" "${branch}"`, {
586
- cwd: repoRoot,
587
- encoding: "utf-8",
588
- timeout: GIT_TIMEOUT_MS,
589
- stdio: ["pipe", "pipe", "pipe"]
590
- });
591
- } else {
592
- execSync4(`git worktree add "${wtPath}" -b "${branch}" HEAD`, {
593
- cwd: repoRoot,
594
- encoding: "utf-8",
595
- timeout: GIT_TIMEOUT_MS,
596
- stdio: ["pipe", "pipe", "pipe"]
597
- });
598
- }
599
- return wtPath;
600
- } catch (err) {
601
- process.stderr.write(
602
- `[worktree] Failed to create worktree for ${employeeName2}: ${err instanceof Error ? err.message : String(err)}
603
- `
604
- );
605
- return null;
606
- }
607
- }
608
- function branchExistsLocally(repoRoot, branch) {
609
- try {
610
- execSync4(`git rev-parse --verify "refs/heads/${branch}"`, {
611
- cwd: repoRoot,
612
- encoding: "utf-8",
613
- timeout: GIT_TIMEOUT_MS,
614
- stdio: ["pipe", "pipe", "pipe"]
615
- });
616
- return true;
617
- } catch {
618
- return false;
619
- }
620
- }
621
- function realpath(p) {
622
- try {
623
- return realpathSync(p);
624
- } catch {
625
- return p;
626
- }
627
- }
628
- function ensureGitignoreEntry(repoRoot, entry) {
629
- try {
630
- const gitignorePath = path7.join(repoRoot, ".gitignore");
631
- if (existsSync7(gitignorePath)) {
632
- const content = readFileSync6(gitignorePath, "utf-8");
633
- if (content.includes(entry)) return;
634
- appendFileSync(gitignorePath, `
635
- # Agent worktrees (exe-os)
636
- ${entry}
637
- `);
638
- } else {
639
- }
640
- } catch {
641
- }
642
- }
643
- var GIT_TIMEOUT_MS;
644
- var init_worktree = __esm({
645
- "src/lib/worktree.ts"() {
646
- "use strict";
647
- GIT_TIMEOUT_MS = 1e4;
648
- }
649
- });
650
-
651
- // src/lib/tmux-routing.ts
652
- import { execFileSync as execFileSync2, execSync as execSync5 } from "child_process";
653
- import { readFileSync as readFileSync7, writeFileSync as writeFileSync4, mkdirSync as mkdirSync5, existsSync as existsSync8, appendFileSync as appendFileSync2 } from "fs";
654
- import path8 from "path";
655
- import os4 from "os";
656
- import { fileURLToPath } from "url";
657
- function resolveBehaviorsExporterScript() {
658
- try {
659
- const thisFile = fileURLToPath(import.meta.url);
660
- const scriptPath = path8.join(
661
- path8.dirname(thisFile),
662
- "..",
663
- "bin",
664
- "exe-export-behaviors.js"
665
- );
666
- return existsSync8(scriptPath) ? scriptPath : null;
667
- } catch {
668
- return null;
669
- }
670
- }
671
- function exportBehaviorsSync(agentId, projectName, sessionKey) {
672
- const script = resolveBehaviorsExporterScript();
673
- if (!script) return null;
674
- try {
675
- const output = execFileSync2(
676
- process.execPath,
677
- [script, agentId, projectName, sessionKey],
678
- { encoding: "utf-8", timeout: BEHAVIORS_EXPORT_TIMEOUT_MS }
679
- ).trim();
680
- return output.length > 0 ? output : null;
681
- } catch (err) {
682
- process.stderr.write(
683
- `[tmux-routing] behaviors export failed for ${agentId}: ${err instanceof Error ? err.message : String(err)}
684
- `
685
- );
686
- return null;
687
- }
688
- }
689
- function getMySession() {
690
- return getTransport().getMySession();
691
- }
692
- function employeeSessionName(employee, exeSession2, instance) {
693
- const suffix = instance != null && instance > 0 ? String(instance) : "";
694
- return `${employee}${suffix}-${exeSession2}`;
695
- }
696
- function extractRootExe(name) {
697
- const match = name.match(/(exe\d+)$/);
698
- return match?.[1] ?? null;
699
- }
700
- function getParentExe(sessionKey) {
701
- try {
702
- const data = JSON.parse(readFileSync7(path8.join(SESSION_CACHE, `parent-exe-${sessionKey}.json`), "utf8"));
703
- return data.parentExe || null;
704
- } catch {
705
- return null;
706
- }
707
- }
708
- function resolveExeSession() {
709
- const mySession = getMySession();
710
- if (!mySession) return null;
711
- try {
712
- const key = getSessionKey();
713
- const parentExe = getParentExe(key);
714
- if (parentExe) {
715
- return extractRootExe(parentExe) ?? parentExe;
716
- }
717
- } catch {
718
- }
719
- return extractRootExe(mySession) ?? mySession;
720
- }
721
- function isEmployeeAlive(sessionName) {
722
- return getTransport().isAlive(sessionName);
723
- }
724
- function findFreeInstance(employeeName2, exeSession2, maxInstances = 10, isAlive = isEmployeeAlive) {
725
- const base = employeeSessionName(employeeName2, exeSession2);
726
- if (!isAlive(base)) return 0;
727
- for (let i = 2; i <= maxInstances; i++) {
728
- const candidate = employeeSessionName(employeeName2, exeSession2, i);
729
- if (!isAlive(candidate)) return i;
730
- }
731
- return null;
732
- }
733
- function readDebounceState() {
734
- try {
735
- if (!existsSync8(DEBOUNCE_FILE)) return {};
736
- return JSON.parse(readFileSync7(DEBOUNCE_FILE, "utf8"));
737
- } catch {
738
- return {};
739
- }
740
- }
741
- function writeDebounceState(state) {
742
- try {
743
- if (!existsSync8(SESSION_CACHE)) mkdirSync5(SESSION_CACHE, { recursive: true });
744
- writeFileSync4(DEBOUNCE_FILE, JSON.stringify(state));
745
- } catch {
746
- }
747
- }
748
- function isDebounced(targetSession) {
749
- const state = readDebounceState();
750
- const lastSent = state[targetSession] ?? 0;
751
- return Date.now() - lastSent < INTERCOM_DEBOUNCE_MS;
752
- }
753
- function recordDebounce(targetSession) {
754
- const state = readDebounceState();
755
- state[targetSession] = Date.now();
756
- const cutoff = Date.now() - DEBOUNCE_CLEANUP_AGE_MS;
757
- for (const key of Object.keys(state)) {
758
- if ((state[key] ?? 0) < cutoff) delete state[key];
759
- }
760
- writeDebounceState(state);
761
- }
762
- function logIntercom(msg) {
763
- const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${msg}
764
- `;
765
- process.stderr.write(`[intercom] ${msg}
766
- `);
767
- try {
768
- appendFileSync2(INTERCOM_LOG2, line);
769
- } catch {
770
- }
771
- }
772
- function getSessionState(sessionName) {
773
- const transport = getTransport();
774
- if (!transport.isAlive(sessionName)) return "offline";
775
- try {
776
- const pane = transport.capturePane(sessionName, 5);
777
- if (/Running…/.test(pane)) return "tool";
778
- if (BUSY_PATTERN.test(pane)) return "thinking";
779
- return "idle";
780
- } catch {
781
- return "offline";
782
- }
783
- }
784
- function isSessionBusy(sessionName) {
785
- const state = getSessionState(sessionName);
786
- return state === "thinking" || state === "tool";
787
- }
788
- function isExeSession(sessionName) {
789
- return /^exe\d*$/.test(sessionName);
790
- }
791
- function sendIntercom(targetSession) {
792
- const transport = getTransport();
793
- if (isExeSession(targetSession)) {
794
- logIntercom(`SKIP_EXE \u2192 ${targetSession} (exe sessions use prompt-submit hook)`);
795
- return "skipped_exe";
796
- }
797
- if (isDebounced(targetSession)) {
798
- logIntercom(`DEBOUNCE \u2192 ${targetSession} (cross-process file debounce)`);
799
- return "debounced";
800
- }
801
- try {
802
- const sessions = transport.listSessions();
803
- if (!sessions.includes(targetSession)) {
804
- logIntercom(`SKIP \u2192 ${targetSession} (session not found)`);
805
- return "failed";
806
- }
807
- if (isSessionBusy(targetSession)) {
808
- queueIntercom(targetSession, "session busy at send time");
809
- recordDebounce(targetSession);
810
- logIntercom(`QUEUED \u2192 ${targetSession} (session busy, will retry from queue)`);
811
- return "queued";
812
- }
813
- if (transport.isPaneInCopyMode(targetSession)) {
814
- logIntercom(`COPY_MODE \u2192 ${targetSession} (exiting copy mode first)`);
815
- transport.sendKeys(targetSession, "q");
816
- }
817
- transport.sendKeys(targetSession, "/exe-intercom");
818
- recordDebounce(targetSession);
819
- for (let i = 0; i < INTERCOM_POLL_MAX_ATTEMPTS; i++) {
820
- try {
821
- execSync5(`sleep ${INTERCOM_POLL_INTERVAL_S}`);
822
- } catch {
823
- }
824
- const state = getSessionState(targetSession);
825
- if (state === "thinking" || state === "tool") {
826
- logIntercom(`ACKNOWLEDGED \u2192 ${targetSession} (state=${state}, poll=${i + 1})`);
827
- return "acknowledged";
828
- }
829
- }
830
- logIntercom(`DELIVERED \u2192 ${targetSession} (no state transition after ${INTERCOM_POLL_MAX_ATTEMPTS}s)`);
831
- return "delivered";
832
- } catch {
833
- logIntercom(`FAIL \u2192 ${targetSession}`);
834
- return "failed";
835
- }
836
- }
837
- function ensureEmployee(employeeName2, exeSession2, projectDir2, opts) {
838
- if (employeeName2 === "exe") {
839
- return { status: "failed", sessionName: "", error: "exe is the COO, not a dispatchable employee" };
840
- }
841
- try {
842
- assertEmployeeLimitSync();
843
- } catch (err) {
844
- if (err instanceof PlanLimitError) {
845
- return { status: "failed", sessionName: "", error: err.message };
846
- }
847
- }
848
- if (/-exe\d*$/.test(employeeName2)) {
849
- const bare = employeeName2.replace(/-exe\d*$/, "").replace(/\d+$/, "");
850
- return {
851
- status: "failed",
852
- sessionName: "",
853
- error: `Error: pass employee name ('${bare}'), not session name ('${employeeName2}')`
854
- };
855
- }
856
- let effectiveInstance = opts?.instance;
857
- if (effectiveInstance === void 0 && opts?.autoInstance) {
858
- const free = findFreeInstance(
859
- employeeName2,
860
- exeSession2,
861
- opts.maxAutoInstances ?? 10
862
- );
863
- if (free === null) {
864
- return {
865
- status: "failed",
866
- sessionName: employeeSessionName(employeeName2, exeSession2),
867
- error: `All ${opts.maxAutoInstances ?? 10} instances of ${employeeName2} are alive \u2014 cap reached`
868
- };
869
- }
870
- effectiveInstance = free === 0 ? void 0 : free;
871
- }
872
- const sessionName = employeeSessionName(employeeName2, exeSession2, effectiveInstance);
873
- if (isEmployeeAlive(sessionName)) {
874
- const result3 = sendIntercom(sessionName);
875
- if (result3 === "acknowledged" || result3 === "skipped_exe" || result3 === "debounced" || result3 === "queued") {
876
- return { status: "intercom_sent", sessionName };
877
- }
878
- if (result3 === "delivered") {
879
- return { status: "intercom_unprocessed", sessionName };
880
- }
881
- return { status: "failed", sessionName, error: "intercom delivery failed" };
882
- }
883
- const spawnOpts = { ...opts, instance: effectiveInstance };
884
- const wtPath = ensureWorktree(projectDir2, employeeName2, effectiveInstance);
885
- if (wtPath) {
886
- spawnOpts.cwd = wtPath;
887
- }
888
- const result2 = spawnEmployee(employeeName2, exeSession2, projectDir2, spawnOpts);
889
- if (result2.error) {
890
- return { status: "failed", sessionName, error: result2.error };
891
- }
892
- return { status: "spawned", sessionName };
893
- }
894
- function spawnEmployee(employeeName2, exeSession2, projectDir2, opts) {
895
- const transport = getTransport();
896
- const sessionName = employeeSessionName(employeeName2, exeSession2, opts?.instance);
897
- const instanceLabel2 = opts?.instance != null && opts.instance > 0 ? `${employeeName2}${opts.instance}` : employeeName2;
898
- const logDir = path8.join(os4.homedir(), ".exe-os", "session-logs");
899
- const logFile = path8.join(logDir, `${instanceLabel2}-${Date.now()}.log`);
900
- if (!existsSync8(logDir)) {
901
- mkdirSync5(logDir, { recursive: true });
902
- }
903
- transport.kill(sessionName);
904
- let cleanupSuffix = "";
905
- try {
906
- const thisFile = fileURLToPath(import.meta.url);
907
- const cleanupScript = path8.join(path8.dirname(thisFile), "..", "bin", "exe-session-cleanup.js");
908
- if (existsSync8(cleanupScript)) {
909
- cleanupSuffix = `; ${process.execPath} "${cleanupScript}" "${employeeName2}" "${exeSession2}"`;
910
- }
911
- } catch {
912
- }
913
- try {
914
- const claudeJsonPath = path8.join(os4.homedir(), ".claude.json");
915
- let claudeJson = {};
916
- try {
917
- claudeJson = JSON.parse(readFileSync7(claudeJsonPath, "utf8"));
918
- } catch {
919
- }
920
- if (!claudeJson.projects) claudeJson.projects = {};
921
- const projects = claudeJson.projects;
922
- const trustDir = opts?.cwd ?? projectDir2;
923
- if (!projects[trustDir]) projects[trustDir] = {};
924
- projects[trustDir].hasTrustDialogAccepted = true;
925
- writeFileSync4(claudeJsonPath, JSON.stringify(claudeJson, null, 2) + "\n");
926
- } catch {
927
- }
928
- try {
929
- const settingsDir = path8.join(os4.homedir(), ".claude", "projects");
930
- const normalizedKey = (opts?.cwd ?? projectDir2).replace(/\//g, "-").replace(/^-/, "");
931
- const projSettingsDir = path8.join(settingsDir, normalizedKey);
932
- const settingsPath = path8.join(projSettingsDir, "settings.json");
933
- let settings = {};
934
- try {
935
- settings = JSON.parse(readFileSync7(settingsPath, "utf8"));
936
- } catch {
937
- }
938
- const perms = settings.permissions ?? {};
939
- const allow = perms.allow ?? [];
940
- const toolNames = [
941
- "recall_my_memory",
942
- "store_memory",
943
- "create_task",
944
- "update_task",
945
- "list_tasks",
946
- "get_task",
947
- "ask_team_memory",
948
- "store_behavior",
949
- "get_identity",
950
- "send_message"
951
- ];
952
- const requiredTools = expandDualPrefixTools(toolNames);
953
- let changed = false;
954
- for (const tool of requiredTools) {
955
- if (!allow.includes(tool)) {
956
- allow.push(tool);
957
- changed = true;
958
- }
959
- }
960
- if (changed) {
961
- perms.allow = allow;
962
- settings.permissions = perms;
963
- mkdirSync5(projSettingsDir, { recursive: true });
964
- writeFileSync4(settingsPath, JSON.stringify(settings, null, 2) + "\n");
965
- }
966
- } catch {
967
- }
968
- const spawnCwd = opts?.cwd ?? projectDir2;
969
- const useExeAgent = !!(opts?.model && opts?.provider);
970
- const ccProvider = useExeAgent ? DEFAULT_PROVIDER : detectActiveProvider();
971
- const useBinSymlink = ccProvider !== DEFAULT_PROVIDER;
972
- let identityFlag = "";
973
- let behaviorsFlag = "";
974
- let legacyFallbackWarned = false;
975
- if (!useExeAgent && !useBinSymlink) {
976
- const identityPath = path8.join(
977
- os4.homedir(),
978
- ".exe-os",
979
- "identity",
980
- `${employeeName2}.md`
981
- );
982
- _resetCcAgentSupportCache();
983
- const hasAgentFlag = claudeSupportsAgentFlag();
984
- if (hasAgentFlag) {
985
- identityFlag = ` --agent ${employeeName2}`;
986
- } else if (existsSync8(identityPath)) {
987
- identityFlag = ` --append-system-prompt-file ${identityPath}`;
988
- legacyFallbackWarned = true;
989
- }
990
- const behaviorsFile = exportBehaviorsSync(
991
- employeeName2,
992
- path8.basename(spawnCwd),
993
- sessionName
994
- );
995
- if (behaviorsFile) {
996
- behaviorsFlag = ` --append-system-prompt-file ${behaviorsFile}`;
997
- }
998
- }
999
- if (legacyFallbackWarned) {
1000
- process.stderr.write(
1001
- `[tmux-routing] claude --agent not supported by installed CC. Falling back to --append-system-prompt-file for ${employeeName2}. Upgrade Claude Code to enable native --agent launch.
1002
- `
1003
- );
1004
- }
1005
- let sessionContextFlag = "";
1006
- try {
1007
- const ctxDir = path8.join(os4.homedir(), ".exe-os", "session-cache");
1008
- mkdirSync5(ctxDir, { recursive: true });
1009
- const ctxFile = path8.join(ctxDir, `session-context-${sessionName}.md`);
1010
- const ctxContent = [
1011
- `## Session Context`,
1012
- `You are running in tmux session: ${sessionName}.`,
1013
- `Your parent exe session is ${exeSession2}.`,
1014
- `Your employees (if any) use the -${exeSession2} suffix (e.g., tom-${exeSession2}).`
1015
- ].join("\n");
1016
- writeFileSync4(ctxFile, ctxContent);
1017
- sessionContextFlag = ` --append-system-prompt-file ${ctxFile}`;
1018
- } catch {
1019
- }
1020
- let envPrefix = `EXE_SESSION=${exeSession2} EXE_SESSION_NAME=${sessionName}`;
1021
- if (ccProvider !== DEFAULT_PROVIDER) {
1022
- const cfg = PROVIDER_TABLE[ccProvider];
1023
- if (cfg?.apiKeyEnv) {
1024
- const keyVal = process.env[cfg.apiKeyEnv];
1025
- if (keyVal) {
1026
- envPrefix = `${envPrefix} ${cfg.apiKeyEnv}=${keyVal}`;
1027
- }
1028
- }
1029
- }
1030
- let spawnCommand;
1031
- if (useExeAgent) {
1032
- spawnCommand = `${envPrefix} exe-agent --employee ${employeeName2} --model ${opts.model} --provider ${opts.provider}${cleanupSuffix}`;
1033
- } else if (useBinSymlink) {
1034
- const binName = `${employeeName2}-${ccProvider}`;
1035
- process.stderr.write(
1036
- `[tmux-routing] provider cascade: ${ccProvider} \u2192 spawning ${binName}
1037
- `
1038
- );
1039
- spawnCommand = `${envPrefix} ${binName}${cleanupSuffix}`;
1040
- } else {
1041
- spawnCommand = `${envPrefix} claude --dangerously-skip-permissions${identityFlag}${behaviorsFlag}${sessionContextFlag}${cleanupSuffix}`;
1042
- }
1043
- const spawnResult = transport.spawn(sessionName, {
1044
- cwd: spawnCwd,
1045
- command: spawnCommand
1046
- });
1047
- if (spawnResult.error) {
1048
- return { sessionName, error: `tmux new-session failed: ${spawnResult.error}` };
1049
- }
1050
- transport.pipeLog(sessionName, logFile);
1051
- try {
1052
- const mySession = getMySession();
1053
- const dispatchInfo = path8.join(SESSION_CACHE, `dispatch-info-${sessionName}.json`);
1054
- writeFileSync4(dispatchInfo, JSON.stringify({
1055
- dispatchedBy: mySession,
1056
- rootExe: exeSession2,
1057
- provider: useBinSymlink ? ccProvider : useExeAgent ? opts.provider : "anthropic",
1058
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
1059
- }));
1060
- } catch {
1061
- }
1062
- let booted = false;
1063
- for (let i = 0; i < 30; i++) {
1064
- try {
1065
- execSync5("sleep 1");
1066
- } catch {
1067
- }
1068
- try {
1069
- const pane = transport.capturePane(sessionName);
1070
- if (useExeAgent) {
1071
- if (pane.includes("[exe-agent]") || pane.includes("online")) {
1072
- booted = true;
1073
- break;
1074
- }
1075
- } else {
1076
- if (pane.includes("Claude Code") || pane.includes("\u276F")) {
1077
- booted = true;
1078
- break;
1079
- }
1080
- }
1081
- } catch {
1082
- }
1083
- }
1084
- if (!booted) {
1085
- return { sessionName, error: `${useExeAgent ? "exe-agent" : "claude"} did not boot within 30s` };
1086
- }
1087
- if (!useExeAgent) {
1088
- try {
1089
- transport.sendKeys(sessionName, `/exe-call ${employeeName2}`);
1090
- } catch {
1091
- }
1092
- }
1093
- registerSession({
1094
- windowName: sessionName,
1095
- agentId: employeeName2,
1096
- projectDir: spawnCwd,
1097
- parentExe: exeSession2,
1098
- pid: 0,
1099
- registeredAt: (/* @__PURE__ */ new Date()).toISOString()
1100
- });
1101
- return { sessionName };
1102
- }
1103
- var SESSION_CACHE, BEHAVIORS_EXPORT_TIMEOUT_MS, INTERCOM_DEBOUNCE_MS, INTERCOM_LOG2, DEBOUNCE_FILE, DEBOUNCE_CLEANUP_AGE_MS, BUSY_PATTERN, INTERCOM_POLL_INTERVAL_S, INTERCOM_POLL_MAX_ATTEMPTS;
1104
- var init_tmux_routing = __esm({
1105
- "src/lib/tmux-routing.ts"() {
1106
- "use strict";
1107
- init_session_registry();
1108
- init_session_key();
1109
- init_transport();
1110
- init_cc_agent_support();
1111
- init_mcp_prefix();
1112
- init_provider_table();
1113
- init_intercom_queue();
1114
- init_plan_limits();
1115
- init_worktree();
1116
- SESSION_CACHE = path8.join(os4.homedir(), ".exe-os", "session-cache");
1117
- BEHAVIORS_EXPORT_TIMEOUT_MS = 1e4;
1118
- INTERCOM_DEBOUNCE_MS = 3e4;
1119
- INTERCOM_LOG2 = path8.join(os4.homedir(), ".exe-os", "intercom.log");
1120
- DEBOUNCE_FILE = path8.join(SESSION_CACHE, "intercom-debounce.json");
1121
- DEBOUNCE_CLEANUP_AGE_MS = 5 * 60 * 1e3;
1122
- BUSY_PATTERN = /[✻✽✶✳·].*…|Running…/;
1123
- INTERCOM_POLL_INTERVAL_S = 1;
1124
- INTERCOM_POLL_MAX_ATTEMPTS = 8;
1125
- }
1126
- });
1127
-
1128
- // src/bin/exe-dispatch.ts
1129
- init_tmux_routing();
1130
- var employeeName = process.argv[2];
1131
- if (!employeeName) {
1132
- console.error("Usage: exe-dispatch <employeeName> [projectDir]");
1133
- process.exit(1);
1134
- }
1135
- var projectDir = process.argv[3] || process.cwd();
1136
- var exeSession = resolveExeSession();
1137
- if (!exeSession) {
1138
- console.log(JSON.stringify({
1139
- status: "failed",
1140
- sessionName: "",
1141
- error: "Not in tmux \u2014 cannot resolve exe session"
1142
- }));
1143
- process.exit(1);
1144
- }
1145
- var result = ensureEmployee(employeeName, exeSession, projectDir);
1146
- console.log(JSON.stringify(result));