@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.
Files changed (106) hide show
  1. package/package.json +1 -1
  2. package/dist/bin/backfill-responses.js +0 -2064
  3. package/dist/bin/backfill-vectors.js +0 -1771
  4. package/dist/bin/cleanup-stale-review-tasks.js +0 -1468
  5. package/dist/bin/cli.js +0 -21371
  6. package/dist/bin/exe-agent.js +0 -2016
  7. package/dist/bin/exe-assign.js +0 -2176
  8. package/dist/bin/exe-boot.js +0 -6332
  9. package/dist/bin/exe-call.js +0 -341
  10. package/dist/bin/exe-cloud.js +0 -861
  11. package/dist/bin/exe-dispatch.js +0 -1159
  12. package/dist/bin/exe-doctor.js +0 -1786
  13. package/dist/bin/exe-export-behaviors.js +0 -1637
  14. package/dist/bin/exe-forget.js +0 -1784
  15. package/dist/bin/exe-gateway.js +0 -8140
  16. package/dist/bin/exe-healthcheck.js +0 -207
  17. package/dist/bin/exe-heartbeat.js +0 -1778
  18. package/dist/bin/exe-kill.js +0 -1622
  19. package/dist/bin/exe-launch-agent.js +0 -1847
  20. package/dist/bin/exe-link.js +0 -192
  21. package/dist/bin/exe-new-employee.js +0 -1384
  22. package/dist/bin/exe-pending-messages.js +0 -1576
  23. package/dist/bin/exe-pending-notifications.js +0 -1450
  24. package/dist/bin/exe-pending-reviews.js +0 -1598
  25. package/dist/bin/exe-repo-drift.js +0 -95
  26. package/dist/bin/exe-review.js +0 -1742
  27. package/dist/bin/exe-search.js +0 -3116
  28. package/dist/bin/exe-session-cleanup.js +0 -3360
  29. package/dist/bin/exe-settings.js +0 -365
  30. package/dist/bin/exe-status.js +0 -1661
  31. package/dist/bin/exe-team.js +0 -1453
  32. package/dist/bin/git-sweep.js +0 -2441
  33. package/dist/bin/graph-backfill.js +0 -2111
  34. package/dist/bin/graph-export.js +0 -1747
  35. package/dist/bin/install.js +0 -661
  36. package/dist/bin/list-providers.js +0 -140
  37. package/dist/bin/scan-tasks.js +0 -2039
  38. package/dist/bin/setup.js +0 -2717
  39. package/dist/bin/shard-migrate.js +0 -1637
  40. package/dist/bin/update.js +0 -98
  41. package/dist/bin/wiki-sync.js +0 -1657
  42. package/dist/gateway/index.js +0 -9256
  43. package/dist/hooks/bug-report-worker.js +0 -2903
  44. package/dist/hooks/commit-complete.js +0 -2364
  45. package/dist/hooks/error-recall.js +0 -3327
  46. package/dist/hooks/exe-heartbeat-hook.js +0 -237
  47. package/dist/hooks/ingest-worker.js +0 -5065
  48. package/dist/hooks/ingest.js +0 -695
  49. package/dist/hooks/instructions-loaded.js +0 -2069
  50. package/dist/hooks/notification.js +0 -1915
  51. package/dist/hooks/post-compact.js +0 -1940
  52. package/dist/hooks/pre-compact.js +0 -1935
  53. package/dist/hooks/pre-tool-use.js +0 -2380
  54. package/dist/hooks/prompt-ingest-worker.js +0 -2291
  55. package/dist/hooks/prompt-submit.js +0 -5189
  56. package/dist/hooks/response-ingest-worker.js +0 -2431
  57. package/dist/hooks/session-end.js +0 -2196
  58. package/dist/hooks/session-start.js +0 -3259
  59. package/dist/hooks/stop.js +0 -2025
  60. package/dist/hooks/subagent-stop.js +0 -1915
  61. package/dist/hooks/summary-worker.js +0 -2931
  62. package/dist/index.js +0 -12327
  63. package/dist/lib/cloud-sync.js +0 -500
  64. package/dist/lib/config.js +0 -235
  65. package/dist/lib/consolidation.js +0 -481
  66. package/dist/lib/crypto.js +0 -51
  67. package/dist/lib/database.js +0 -834
  68. package/dist/lib/device-registry.js +0 -1009
  69. package/dist/lib/embedder.js +0 -645
  70. package/dist/lib/employee-templates.js +0 -570
  71. package/dist/lib/employees.js +0 -182
  72. package/dist/lib/error-detector.js +0 -156
  73. package/dist/lib/exe-daemon-client.js +0 -456
  74. package/dist/lib/exe-daemon.js +0 -8699
  75. package/dist/lib/file-grep.js +0 -215
  76. package/dist/lib/hybrid-search.js +0 -3064
  77. package/dist/lib/identity-templates.js +0 -441
  78. package/dist/lib/identity.js +0 -228
  79. package/dist/lib/keychain.js +0 -145
  80. package/dist/lib/license.js +0 -382
  81. package/dist/lib/messaging.js +0 -1389
  82. package/dist/lib/reminders.js +0 -63
  83. package/dist/lib/schedules.js +0 -1525
  84. package/dist/lib/session-registry.js +0 -52
  85. package/dist/lib/skill-learning.js +0 -488
  86. package/dist/lib/status-brief.js +0 -240
  87. package/dist/lib/store.js +0 -1740
  88. package/dist/lib/task-router.js +0 -128
  89. package/dist/lib/tasks.js +0 -2585
  90. package/dist/lib/tmux-routing.js +0 -2969
  91. package/dist/lib/tmux-status.js +0 -261
  92. package/dist/lib/tmux-transport.js +0 -83
  93. package/dist/lib/transport.js +0 -128
  94. package/dist/lib/ws-auth.js +0 -19
  95. package/dist/lib/ws-client.js +0 -160
  96. package/dist/mcp/server.js +0 -10812
  97. package/dist/mcp/tools/complete-reminder.js +0 -67
  98. package/dist/mcp/tools/create-reminder.js +0 -52
  99. package/dist/mcp/tools/create-task.js +0 -1903
  100. package/dist/mcp/tools/deactivate-behavior.js +0 -268
  101. package/dist/mcp/tools/list-reminders.js +0 -62
  102. package/dist/mcp/tools/list-tasks.js +0 -491
  103. package/dist/mcp/tools/send-message.js +0 -1395
  104. package/dist/mcp/tools/update-task.js +0 -1807
  105. package/dist/runtime/index.js +0 -7201
  106. package/dist/tui/App.js +0 -17874
@@ -1,1159 +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, TTL_MS, 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
- TTL_MS = 60 * 60 * 1e3;
317
- INTERCOM_LOG = path2.join(os2.homedir(), ".exe-os", "intercom.log");
318
- }
319
- });
320
-
321
- // src/lib/database.ts
322
- import { createClient } from "@libsql/client";
323
- var init_database = __esm({
324
- "src/lib/database.ts"() {
325
- "use strict";
326
- }
327
- });
328
-
329
- // src/lib/config.ts
330
- import { readFile, writeFile, mkdir } from "fs/promises";
331
- import { readFileSync as readFileSync3, existsSync as existsSync3, renameSync as renameSync2 } from "fs";
332
- import path3 from "path";
333
- import os3 from "os";
334
- function resolveDataDir() {
335
- if (process.env.EXE_OS_DIR) return process.env.EXE_OS_DIR;
336
- if (process.env.EXE_MEM_DIR) return process.env.EXE_MEM_DIR;
337
- const newDir = path3.join(os3.homedir(), ".exe-os");
338
- const legacyDir = path3.join(os3.homedir(), ".exe-mem");
339
- if (!existsSync3(newDir) && existsSync3(legacyDir)) {
340
- try {
341
- renameSync2(legacyDir, newDir);
342
- process.stderr.write(`[exe-os] Migrated data directory: ~/.exe-mem \u2192 ~/.exe-os
343
- `);
344
- } catch {
345
- return legacyDir;
346
- }
347
- }
348
- return newDir;
349
- }
350
- var EXE_AI_DIR, DB_PATH, MODELS_DIR, CONFIG_PATH, LEGACY_LANCE_PATH, CURRENT_CONFIG_VERSION, DEFAULT_CONFIG;
351
- var init_config = __esm({
352
- "src/lib/config.ts"() {
353
- "use strict";
354
- EXE_AI_DIR = resolveDataDir();
355
- DB_PATH = path3.join(EXE_AI_DIR, "memories.db");
356
- MODELS_DIR = path3.join(EXE_AI_DIR, "models");
357
- CONFIG_PATH = path3.join(EXE_AI_DIR, "config.json");
358
- LEGACY_LANCE_PATH = path3.join(EXE_AI_DIR, "local.lance");
359
- CURRENT_CONFIG_VERSION = 1;
360
- DEFAULT_CONFIG = {
361
- config_version: CURRENT_CONFIG_VERSION,
362
- dbPath: DB_PATH,
363
- modelFile: "jina-embeddings-v5-small-q4_k_m.gguf",
364
- embeddingDim: 1024,
365
- batchSize: 20,
366
- flushIntervalMs: 1e4,
367
- autoIngestion: true,
368
- autoRetrieval: true,
369
- searchMode: "hybrid",
370
- hookSearchMode: "hybrid",
371
- fileGrepEnabled: true,
372
- splashEffect: true,
373
- consolidationEnabled: true,
374
- consolidationIntervalMs: 6 * 60 * 60 * 1e3,
375
- consolidationModel: "claude-haiku-4-5-20251001",
376
- consolidationMaxCallsPerRun: 20,
377
- selfQueryRouter: true,
378
- selfQueryModel: "claude-haiku-4-5-20251001",
379
- rerankerEnabled: true,
380
- scalingRoadmap: {
381
- rerankerAutoTrigger: {
382
- enabled: true,
383
- broadQueryMinCardinality: 5e4,
384
- fetchTopK: 150,
385
- returnTopK: 5
386
- }
387
- },
388
- graphRagEnabled: true,
389
- wikiEnabled: false,
390
- wikiUrl: "",
391
- wikiApiKey: "",
392
- wikiSyncIntervalMs: 30 * 60 * 1e3,
393
- wikiWorkspaceMapping: {
394
- exe: "Executive",
395
- yoshi: "Engineering",
396
- mari: "Marketing",
397
- tom: "Engineering",
398
- sasha: "Production"
399
- },
400
- wikiAutoUpdate: true,
401
- wikiAutoUpdateThreshold: 0.5,
402
- wikiAutoUpdateCreateNew: true,
403
- skillLearning: true,
404
- skillThreshold: 3,
405
- skillModel: "claude-haiku-4-5-20251001",
406
- exeHeartbeat: {
407
- enabled: true,
408
- intervalSeconds: 60,
409
- staleInProgressThresholdHours: 2
410
- },
411
- sessionLifecycle: {
412
- idleKillEnabled: true,
413
- idleKillTicksRequired: 3,
414
- idleKillIntercomAckWindowMs: 1e4,
415
- maxAutoInstances: 10
416
- },
417
- autoUpdate: {
418
- checkOnBoot: true,
419
- autoInstall: false,
420
- checkIntervalMs: 24 * 60 * 60 * 1e3
421
- }
422
- };
423
- }
424
- });
425
-
426
- // src/lib/employees.ts
427
- import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
428
- import { existsSync as existsSync4, symlinkSync, readlinkSync } from "fs";
429
- import { execSync as execSync3 } from "child_process";
430
- import path4 from "path";
431
- var EMPLOYEES_PATH;
432
- var init_employees = __esm({
433
- "src/lib/employees.ts"() {
434
- "use strict";
435
- init_config();
436
- EMPLOYEES_PATH = path4.join(EXE_AI_DIR, "exe-employees.json");
437
- }
438
- });
439
-
440
- // src/lib/license.ts
441
- import { readFileSync as readFileSync4, writeFileSync as writeFileSync3, existsSync as existsSync5, mkdirSync as mkdirSync3 } from "fs";
442
- import { randomUUID } from "crypto";
443
- import path5 from "path";
444
- import { jwtVerify, importSPKI } from "jose";
445
- var LICENSE_PATH, CACHE_PATH, DEVICE_ID_PATH, PLAN_LIMITS;
446
- var init_license = __esm({
447
- "src/lib/license.ts"() {
448
- "use strict";
449
- init_config();
450
- LICENSE_PATH = path5.join(EXE_AI_DIR, "license.key");
451
- CACHE_PATH = path5.join(EXE_AI_DIR, "license-cache.json");
452
- DEVICE_ID_PATH = path5.join(EXE_AI_DIR, "device-id");
453
- PLAN_LIMITS = {
454
- free: { devices: 1, employees: 1, memories: 5e3 },
455
- pro: { devices: 2, employees: 5, memories: 1e5 },
456
- team: { devices: 10, employees: 20, memories: 1e6 },
457
- agency: { devices: 50, employees: 100, memories: 1e7 },
458
- enterprise: { devices: -1, employees: -1, memories: -1 }
459
- };
460
- }
461
- });
462
-
463
- // src/lib/plan-limits.ts
464
- import { readFileSync as readFileSync5, existsSync as existsSync6 } from "fs";
465
- import path6 from "path";
466
- function getLicenseSync() {
467
- try {
468
- if (!existsSync6(CACHE_PATH2)) return freeLicense();
469
- const raw = JSON.parse(readFileSync5(CACHE_PATH2, "utf8"));
470
- if (!raw.token || typeof raw.token !== "string") return freeLicense();
471
- const parts = raw.token.split(".");
472
- if (parts.length !== 3) return freeLicense();
473
- const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString());
474
- const plan = payload.plan ?? "free";
475
- const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
476
- return {
477
- valid: true,
478
- plan,
479
- email: payload.sub ?? "",
480
- expiresAt: payload.exp ? new Date(payload.exp * 1e3).toISOString() : null,
481
- deviceLimit: limits.devices,
482
- employeeLimit: limits.employees,
483
- memoryLimit: limits.memories
484
- };
485
- } catch {
486
- return freeLicense();
487
- }
488
- }
489
- function freeLicense() {
490
- const limits = PLAN_LIMITS.free;
491
- return {
492
- valid: true,
493
- plan: "free",
494
- email: "",
495
- expiresAt: null,
496
- deviceLimit: limits.devices,
497
- employeeLimit: limits.employees,
498
- memoryLimit: limits.memories
499
- };
500
- }
501
- function assertEmployeeLimitSync(rosterPath) {
502
- const license = getLicenseSync();
503
- if (license.employeeLimit < 0) return;
504
- const filePath = rosterPath ?? EMPLOYEES_PATH;
505
- let count = 0;
506
- try {
507
- if (existsSync6(filePath)) {
508
- const raw = readFileSync5(filePath, "utf8");
509
- const employees = JSON.parse(raw);
510
- count = Array.isArray(employees) ? employees.length : 0;
511
- }
512
- } catch {
513
- throw new PlanLimitError(
514
- `Cannot verify employee count: roster unreadable at ${filePath}. Refusing to proceed. Check file permissions or upgrade plan.`
515
- );
516
- }
517
- if (count >= license.employeeLimit) {
518
- throw new PlanLimitError(
519
- `Employee limit reached: ${count}/${license.employeeLimit} employees on the ${license.plan} plan. Upgrade at https://askexe.com to add more.`
520
- );
521
- }
522
- }
523
- var PlanLimitError, CACHE_PATH2;
524
- var init_plan_limits = __esm({
525
- "src/lib/plan-limits.ts"() {
526
- "use strict";
527
- init_database();
528
- init_employees();
529
- init_license();
530
- init_config();
531
- PlanLimitError = class extends Error {
532
- constructor(message) {
533
- super(message);
534
- this.name = "PlanLimitError";
535
- }
536
- };
537
- CACHE_PATH2 = path6.join(EXE_AI_DIR, "license-cache.json");
538
- }
539
- });
540
-
541
- // src/lib/worktree.ts
542
- import { execSync as execSync4 } from "child_process";
543
- import { existsSync as existsSync7, readFileSync as readFileSync6, appendFileSync, mkdirSync as mkdirSync4, realpathSync } from "fs";
544
- import path7 from "path";
545
- function getGitRoot(dir) {
546
- try {
547
- const root = execSync4("git rev-parse --show-toplevel", {
548
- cwd: dir,
549
- encoding: "utf-8",
550
- timeout: GIT_TIMEOUT_MS,
551
- stdio: ["pipe", "pipe", "pipe"]
552
- }).trim();
553
- return realpath(root);
554
- } catch {
555
- return null;
556
- }
557
- }
558
- function getMainRepoRoot(dir) {
559
- try {
560
- const commonDir = execSync4(
561
- "git rev-parse --path-format=absolute --git-common-dir",
562
- { cwd: dir, encoding: "utf-8", timeout: GIT_TIMEOUT_MS, stdio: ["pipe", "pipe", "pipe"] }
563
- ).trim();
564
- return realpath(path7.dirname(commonDir));
565
- } catch {
566
- return null;
567
- }
568
- }
569
- function worktreePath(repoRoot, employeeName2, instance) {
570
- const label = instanceLabel(employeeName2, instance);
571
- return path7.join(repoRoot, ".worktrees", label);
572
- }
573
- function worktreeBranch(employeeName2, instance) {
574
- return `${instanceLabel(employeeName2, instance)}-work`;
575
- }
576
- function instanceLabel(name, instance) {
577
- return instance != null && instance > 0 ? `${name}${instance}` : name;
578
- }
579
- function ensureWorktree(projectDir2, employeeName2, instance) {
580
- const repoRoot = getGitRoot(projectDir2);
581
- if (!repoRoot) return null;
582
- const wtPath = worktreePath(repoRoot, employeeName2, instance);
583
- const branch = worktreeBranch(employeeName2, instance);
584
- if (existsSync7(path7.join(wtPath, ".git"))) {
585
- return wtPath;
586
- }
587
- const worktreesDir = path7.join(repoRoot, ".worktrees");
588
- mkdirSync4(worktreesDir, { recursive: true });
589
- ensureGitignoreEntry(repoRoot, "/.worktrees/");
590
- try {
591
- execSync4("git worktree prune", {
592
- cwd: repoRoot,
593
- encoding: "utf-8",
594
- timeout: GIT_TIMEOUT_MS,
595
- stdio: ["pipe", "pipe", "pipe"]
596
- });
597
- } catch {
598
- }
599
- const branchExists = branchExistsLocally(repoRoot, branch);
600
- try {
601
- if (branchExists) {
602
- execSync4(`git worktree add "${wtPath}" "${branch}"`, {
603
- cwd: repoRoot,
604
- encoding: "utf-8",
605
- timeout: GIT_TIMEOUT_MS,
606
- stdio: ["pipe", "pipe", "pipe"]
607
- });
608
- } else {
609
- execSync4(`git worktree add "${wtPath}" -b "${branch}" HEAD`, {
610
- cwd: repoRoot,
611
- encoding: "utf-8",
612
- timeout: GIT_TIMEOUT_MS,
613
- stdio: ["pipe", "pipe", "pipe"]
614
- });
615
- }
616
- return wtPath;
617
- } catch (err) {
618
- process.stderr.write(
619
- `[worktree] Failed to create worktree for ${employeeName2}: ${err instanceof Error ? err.message : String(err)}
620
- `
621
- );
622
- return null;
623
- }
624
- }
625
- function branchExistsLocally(repoRoot, branch) {
626
- try {
627
- execSync4(`git rev-parse --verify "refs/heads/${branch}"`, {
628
- cwd: repoRoot,
629
- encoding: "utf-8",
630
- timeout: GIT_TIMEOUT_MS,
631
- stdio: ["pipe", "pipe", "pipe"]
632
- });
633
- return true;
634
- } catch {
635
- return false;
636
- }
637
- }
638
- function realpath(p) {
639
- try {
640
- return realpathSync(p);
641
- } catch {
642
- return p;
643
- }
644
- }
645
- function ensureGitignoreEntry(repoRoot, entry) {
646
- try {
647
- const gitignorePath = path7.join(repoRoot, ".gitignore");
648
- if (existsSync7(gitignorePath)) {
649
- const content = readFileSync6(gitignorePath, "utf-8");
650
- if (content.includes(entry)) return;
651
- appendFileSync(gitignorePath, `
652
- # Agent worktrees (exe-os)
653
- ${entry}
654
- `);
655
- } else {
656
- }
657
- } catch {
658
- }
659
- }
660
- var GIT_TIMEOUT_MS;
661
- var init_worktree = __esm({
662
- "src/lib/worktree.ts"() {
663
- "use strict";
664
- GIT_TIMEOUT_MS = 1e4;
665
- }
666
- });
667
-
668
- // src/lib/tmux-routing.ts
669
- import { execFileSync as execFileSync2, execSync as execSync5 } from "child_process";
670
- import { readFileSync as readFileSync7, writeFileSync as writeFileSync4, mkdirSync as mkdirSync5, existsSync as existsSync8, appendFileSync as appendFileSync2 } from "fs";
671
- import path8 from "path";
672
- import os4 from "os";
673
- import { fileURLToPath } from "url";
674
- function resolveBehaviorsExporterScript() {
675
- try {
676
- const thisFile = fileURLToPath(import.meta.url);
677
- const scriptPath = path8.join(
678
- path8.dirname(thisFile),
679
- "..",
680
- "bin",
681
- "exe-export-behaviors.js"
682
- );
683
- return existsSync8(scriptPath) ? scriptPath : null;
684
- } catch {
685
- return null;
686
- }
687
- }
688
- function exportBehaviorsSync(agentId, projectName, sessionKey) {
689
- const script = resolveBehaviorsExporterScript();
690
- if (!script) return null;
691
- try {
692
- const output = execFileSync2(
693
- process.execPath,
694
- [script, agentId, projectName, sessionKey],
695
- { encoding: "utf-8", timeout: BEHAVIORS_EXPORT_TIMEOUT_MS }
696
- ).trim();
697
- return output.length > 0 ? output : null;
698
- } catch (err) {
699
- process.stderr.write(
700
- `[tmux-routing] behaviors export failed for ${agentId}: ${err instanceof Error ? err.message : String(err)}
701
- `
702
- );
703
- return null;
704
- }
705
- }
706
- function getMySession() {
707
- return getTransport().getMySession();
708
- }
709
- function employeeSessionName(employee, exeSession2, instance) {
710
- const suffix = instance != null && instance > 0 ? String(instance) : "";
711
- return `${employee}${suffix}-${exeSession2}`;
712
- }
713
- function extractRootExe(name) {
714
- const match = name.match(/(exe\d+)$/);
715
- return match?.[1] ?? null;
716
- }
717
- function getParentExe(sessionKey) {
718
- try {
719
- const data = JSON.parse(readFileSync7(path8.join(SESSION_CACHE, `parent-exe-${sessionKey}.json`), "utf8"));
720
- return data.parentExe || null;
721
- } catch {
722
- return null;
723
- }
724
- }
725
- function resolveExeSession() {
726
- const mySession = getMySession();
727
- if (!mySession) return null;
728
- try {
729
- const key = getSessionKey();
730
- const parentExe = getParentExe(key);
731
- if (parentExe) {
732
- return extractRootExe(parentExe) ?? parentExe;
733
- }
734
- } catch {
735
- }
736
- return extractRootExe(mySession) ?? mySession;
737
- }
738
- function isEmployeeAlive(sessionName) {
739
- return getTransport().isAlive(sessionName);
740
- }
741
- function findFreeInstance(employeeName2, exeSession2, maxInstances = 10, isAlive = isEmployeeAlive) {
742
- const base = employeeSessionName(employeeName2, exeSession2);
743
- if (!isAlive(base)) return 0;
744
- for (let i = 2; i <= maxInstances; i++) {
745
- const candidate = employeeSessionName(employeeName2, exeSession2, i);
746
- if (!isAlive(candidate)) return i;
747
- }
748
- return null;
749
- }
750
- function readDebounceState() {
751
- try {
752
- if (!existsSync8(DEBOUNCE_FILE)) return {};
753
- return JSON.parse(readFileSync7(DEBOUNCE_FILE, "utf8"));
754
- } catch {
755
- return {};
756
- }
757
- }
758
- function writeDebounceState(state) {
759
- try {
760
- if (!existsSync8(SESSION_CACHE)) mkdirSync5(SESSION_CACHE, { recursive: true });
761
- writeFileSync4(DEBOUNCE_FILE, JSON.stringify(state));
762
- } catch {
763
- }
764
- }
765
- function isDebounced(targetSession) {
766
- const state = readDebounceState();
767
- const lastSent = state[targetSession] ?? 0;
768
- return Date.now() - lastSent < INTERCOM_DEBOUNCE_MS;
769
- }
770
- function recordDebounce(targetSession) {
771
- const state = readDebounceState();
772
- state[targetSession] = Date.now();
773
- const cutoff = Date.now() - DEBOUNCE_CLEANUP_AGE_MS;
774
- for (const key of Object.keys(state)) {
775
- if ((state[key] ?? 0) < cutoff) delete state[key];
776
- }
777
- writeDebounceState(state);
778
- }
779
- function logIntercom(msg) {
780
- const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${msg}
781
- `;
782
- process.stderr.write(`[intercom] ${msg}
783
- `);
784
- try {
785
- appendFileSync2(INTERCOM_LOG2, line);
786
- } catch {
787
- }
788
- }
789
- function getSessionState(sessionName) {
790
- const transport = getTransport();
791
- if (!transport.isAlive(sessionName)) return "offline";
792
- try {
793
- const pane = transport.capturePane(sessionName, 5);
794
- if (!pane.includes("\u276F") && !pane.includes("Claude Code") && !BUSY_PATTERN.test(pane) && !/Running…/.test(pane)) {
795
- if (/\$\s*$/.test(pane) || /% $/.test(pane.trimEnd())) {
796
- return "no_claude";
797
- }
798
- }
799
- if (/Running…/.test(pane)) return "tool";
800
- if (BUSY_PATTERN.test(pane)) return "thinking";
801
- return "idle";
802
- } catch {
803
- return "offline";
804
- }
805
- }
806
- function isExeSession(sessionName) {
807
- return /^exe\d*$/.test(sessionName);
808
- }
809
- function sendIntercom(targetSession) {
810
- const transport = getTransport();
811
- if (isExeSession(targetSession)) {
812
- logIntercom(`SKIP_EXE \u2192 ${targetSession} (exe sessions use prompt-submit hook)`);
813
- return "skipped_exe";
814
- }
815
- if (isDebounced(targetSession)) {
816
- logIntercom(`DEBOUNCE \u2192 ${targetSession} (cross-process file debounce)`);
817
- return "debounced";
818
- }
819
- try {
820
- const sessions = transport.listSessions();
821
- if (!sessions.includes(targetSession)) {
822
- logIntercom(`SKIP \u2192 ${targetSession} (session not found)`);
823
- return "failed";
824
- }
825
- const sessionState = getSessionState(targetSession);
826
- if (sessionState === "no_claude") {
827
- queueIntercom(targetSession, "claude not running in session");
828
- recordDebounce(targetSession);
829
- logIntercom(`QUEUED \u2192 ${targetSession} (no claude process \u2014 raw shell detected)`);
830
- return "queued";
831
- }
832
- if (sessionState === "thinking" || sessionState === "tool") {
833
- queueIntercom(targetSession, "session busy at send time");
834
- recordDebounce(targetSession);
835
- logIntercom(`QUEUED \u2192 ${targetSession} (session busy, will retry from queue)`);
836
- return "queued";
837
- }
838
- if (transport.isPaneInCopyMode(targetSession)) {
839
- logIntercom(`COPY_MODE \u2192 ${targetSession} (exiting copy mode first)`);
840
- transport.sendKeys(targetSession, "q");
841
- }
842
- transport.sendKeys(targetSession, "/exe-intercom");
843
- recordDebounce(targetSession);
844
- logIntercom(`DELIVERED \u2192 ${targetSession} (fire-and-forget)`);
845
- return "delivered";
846
- } catch {
847
- logIntercom(`FAIL \u2192 ${targetSession}`);
848
- return "failed";
849
- }
850
- }
851
- function ensureEmployee(employeeName2, exeSession2, projectDir2, opts) {
852
- if (employeeName2 === "exe") {
853
- return { status: "failed", sessionName: "", error: "exe is the COO, not a dispatchable employee" };
854
- }
855
- try {
856
- assertEmployeeLimitSync();
857
- } catch (err) {
858
- if (err instanceof PlanLimitError) {
859
- return { status: "failed", sessionName: "", error: err.message };
860
- }
861
- }
862
- if (/-exe\d*$/.test(employeeName2)) {
863
- const bare = employeeName2.replace(/-exe\d*$/, "").replace(/\d+$/, "");
864
- return {
865
- status: "failed",
866
- sessionName: "",
867
- error: `Error: pass employee name ('${bare}'), not session name ('${employeeName2}')`
868
- };
869
- }
870
- let effectiveInstance = opts?.instance;
871
- if (effectiveInstance === void 0 && opts?.autoInstance) {
872
- const free = findFreeInstance(
873
- employeeName2,
874
- exeSession2,
875
- opts.maxAutoInstances ?? 10
876
- );
877
- if (free === null) {
878
- return {
879
- status: "failed",
880
- sessionName: employeeSessionName(employeeName2, exeSession2),
881
- error: `All ${opts.maxAutoInstances ?? 10} instances of ${employeeName2} are alive \u2014 cap reached`
882
- };
883
- }
884
- effectiveInstance = free === 0 ? void 0 : free;
885
- }
886
- const sessionName = employeeSessionName(employeeName2, exeSession2, effectiveInstance);
887
- if (isEmployeeAlive(sessionName)) {
888
- const result3 = sendIntercom(sessionName);
889
- if (result3 === "acknowledged" || result3 === "skipped_exe" || result3 === "debounced" || result3 === "queued") {
890
- return { status: "intercom_sent", sessionName };
891
- }
892
- if (result3 === "delivered") {
893
- return { status: "intercom_unprocessed", sessionName };
894
- }
895
- return { status: "failed", sessionName, error: "intercom delivery failed" };
896
- }
897
- const spawnOpts = { ...opts, instance: effectiveInstance };
898
- const mainRoot = getMainRepoRoot(projectDir2) ?? projectDir2;
899
- const wtPath = ensureWorktree(mainRoot, employeeName2, effectiveInstance);
900
- if (wtPath) {
901
- spawnOpts.cwd = wtPath;
902
- }
903
- const result2 = spawnEmployee(employeeName2, exeSession2, projectDir2, spawnOpts);
904
- if (result2.error) {
905
- return { status: "failed", sessionName, error: result2.error };
906
- }
907
- return { status: "spawned", sessionName };
908
- }
909
- function spawnEmployee(employeeName2, exeSession2, projectDir2, opts) {
910
- const transport = getTransport();
911
- const sessionName = employeeSessionName(employeeName2, exeSession2, opts?.instance);
912
- const instanceLabel2 = opts?.instance != null && opts.instance > 0 ? `${employeeName2}${opts.instance}` : employeeName2;
913
- const logDir = path8.join(os4.homedir(), ".exe-os", "session-logs");
914
- const logFile = path8.join(logDir, `${instanceLabel2}-${Date.now()}.log`);
915
- if (!existsSync8(logDir)) {
916
- mkdirSync5(logDir, { recursive: true });
917
- }
918
- transport.kill(sessionName);
919
- let cleanupSuffix = "";
920
- try {
921
- const thisFile = fileURLToPath(import.meta.url);
922
- const cleanupScript = path8.join(path8.dirname(thisFile), "..", "bin", "exe-session-cleanup.js");
923
- if (existsSync8(cleanupScript)) {
924
- cleanupSuffix = `; ${process.execPath} "${cleanupScript}" "${employeeName2}" "${exeSession2}"`;
925
- }
926
- } catch {
927
- }
928
- try {
929
- const claudeJsonPath = path8.join(os4.homedir(), ".claude.json");
930
- let claudeJson = {};
931
- try {
932
- claudeJson = JSON.parse(readFileSync7(claudeJsonPath, "utf8"));
933
- } catch {
934
- }
935
- if (!claudeJson.projects) claudeJson.projects = {};
936
- const projects = claudeJson.projects;
937
- const trustDir = opts?.cwd ?? projectDir2;
938
- if (!projects[trustDir]) projects[trustDir] = {};
939
- projects[trustDir].hasTrustDialogAccepted = true;
940
- writeFileSync4(claudeJsonPath, JSON.stringify(claudeJson, null, 2) + "\n");
941
- } catch {
942
- }
943
- try {
944
- const settingsDir = path8.join(os4.homedir(), ".claude", "projects");
945
- const normalizedKey = (opts?.cwd ?? projectDir2).replace(/\//g, "-").replace(/^-/, "");
946
- const projSettingsDir = path8.join(settingsDir, normalizedKey);
947
- const settingsPath = path8.join(projSettingsDir, "settings.json");
948
- let settings = {};
949
- try {
950
- settings = JSON.parse(readFileSync7(settingsPath, "utf8"));
951
- } catch {
952
- }
953
- const perms = settings.permissions ?? {};
954
- const allow = perms.allow ?? [];
955
- const toolNames = [
956
- "recall_my_memory",
957
- "store_memory",
958
- "create_task",
959
- "update_task",
960
- "list_tasks",
961
- "get_task",
962
- "ask_team_memory",
963
- "store_behavior",
964
- "get_identity",
965
- "send_message"
966
- ];
967
- const requiredTools = expandDualPrefixTools(toolNames);
968
- let changed = false;
969
- for (const tool of requiredTools) {
970
- if (!allow.includes(tool)) {
971
- allow.push(tool);
972
- changed = true;
973
- }
974
- }
975
- if (changed) {
976
- perms.allow = allow;
977
- settings.permissions = perms;
978
- mkdirSync5(projSettingsDir, { recursive: true });
979
- writeFileSync4(settingsPath, JSON.stringify(settings, null, 2) + "\n");
980
- }
981
- } catch {
982
- }
983
- const spawnCwd = opts?.cwd ?? projectDir2;
984
- const useExeAgent = !!(opts?.model && opts?.provider);
985
- const ccProvider = useExeAgent ? DEFAULT_PROVIDER : detectActiveProvider();
986
- const useBinSymlink = ccProvider !== DEFAULT_PROVIDER;
987
- let identityFlag = "";
988
- let behaviorsFlag = "";
989
- let legacyFallbackWarned = false;
990
- if (!useExeAgent && !useBinSymlink) {
991
- const identityPath = path8.join(
992
- os4.homedir(),
993
- ".exe-os",
994
- "identity",
995
- `${employeeName2}.md`
996
- );
997
- _resetCcAgentSupportCache();
998
- const hasAgentFlag = claudeSupportsAgentFlag();
999
- if (hasAgentFlag) {
1000
- identityFlag = ` --agent ${employeeName2}`;
1001
- } else if (existsSync8(identityPath)) {
1002
- identityFlag = ` --append-system-prompt-file ${identityPath}`;
1003
- legacyFallbackWarned = true;
1004
- }
1005
- const behaviorsFile = exportBehaviorsSync(
1006
- employeeName2,
1007
- path8.basename(spawnCwd),
1008
- sessionName
1009
- );
1010
- if (behaviorsFile) {
1011
- behaviorsFlag = ` --append-system-prompt-file ${behaviorsFile}`;
1012
- }
1013
- }
1014
- if (legacyFallbackWarned) {
1015
- process.stderr.write(
1016
- `[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.
1017
- `
1018
- );
1019
- }
1020
- let sessionContextFlag = "";
1021
- try {
1022
- const ctxDir = path8.join(os4.homedir(), ".exe-os", "session-cache");
1023
- mkdirSync5(ctxDir, { recursive: true });
1024
- const ctxFile = path8.join(ctxDir, `session-context-${sessionName}.md`);
1025
- const ctxContent = [
1026
- `## Session Context`,
1027
- `You are running in tmux session: ${sessionName}.`,
1028
- `Your parent exe session is ${exeSession2}.`,
1029
- `Your employees (if any) use the -${exeSession2} suffix (e.g., tom-${exeSession2}).`
1030
- ].join("\n");
1031
- writeFileSync4(ctxFile, ctxContent);
1032
- sessionContextFlag = ` --append-system-prompt-file ${ctxFile}`;
1033
- } catch {
1034
- }
1035
- let envPrefix = `EXE_SESSION=${exeSession2} EXE_SESSION_NAME=${sessionName}`;
1036
- if (ccProvider !== DEFAULT_PROVIDER) {
1037
- const cfg = PROVIDER_TABLE[ccProvider];
1038
- if (cfg?.apiKeyEnv) {
1039
- const keyVal = process.env[cfg.apiKeyEnv];
1040
- if (keyVal) {
1041
- envPrefix = `${envPrefix} ${cfg.apiKeyEnv}=${keyVal}`;
1042
- }
1043
- }
1044
- }
1045
- let spawnCommand;
1046
- if (useExeAgent) {
1047
- spawnCommand = `${envPrefix} exe-agent --employee ${employeeName2} --model ${opts.model} --provider ${opts.provider}${cleanupSuffix}`;
1048
- } else if (useBinSymlink) {
1049
- const binName = `${employeeName2}-${ccProvider}`;
1050
- process.stderr.write(
1051
- `[tmux-routing] provider cascade: ${ccProvider} \u2192 spawning ${binName}
1052
- `
1053
- );
1054
- spawnCommand = `${envPrefix} ${binName}${cleanupSuffix}`;
1055
- } else {
1056
- spawnCommand = `${envPrefix} claude --dangerously-skip-permissions${identityFlag}${behaviorsFlag}${sessionContextFlag}${cleanupSuffix}`;
1057
- }
1058
- const spawnResult = transport.spawn(sessionName, {
1059
- cwd: spawnCwd,
1060
- command: spawnCommand
1061
- });
1062
- if (spawnResult.error) {
1063
- return { sessionName, error: `tmux new-session failed: ${spawnResult.error}` };
1064
- }
1065
- transport.pipeLog(sessionName, logFile);
1066
- try {
1067
- const mySession = getMySession();
1068
- const dispatchInfo = path8.join(SESSION_CACHE, `dispatch-info-${sessionName}.json`);
1069
- writeFileSync4(dispatchInfo, JSON.stringify({
1070
- dispatchedBy: mySession,
1071
- rootExe: exeSession2,
1072
- provider: useBinSymlink ? ccProvider : useExeAgent ? opts.provider : "anthropic",
1073
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
1074
- }));
1075
- } catch {
1076
- }
1077
- let booted = false;
1078
- for (let i = 0; i < 30; i++) {
1079
- try {
1080
- execSync5("sleep 0.5");
1081
- } catch {
1082
- }
1083
- try {
1084
- const pane = transport.capturePane(sessionName);
1085
- if (useExeAgent) {
1086
- if (pane.includes("[exe-agent]") || pane.includes("online")) {
1087
- booted = true;
1088
- break;
1089
- }
1090
- } else {
1091
- if (pane.includes("Claude Code") || pane.includes("\u276F")) {
1092
- booted = true;
1093
- break;
1094
- }
1095
- }
1096
- } catch {
1097
- }
1098
- }
1099
- if (!booted) {
1100
- return { sessionName, error: `${useExeAgent ? "exe-agent" : "claude"} did not boot within 15s` };
1101
- }
1102
- if (!useExeAgent) {
1103
- try {
1104
- transport.sendKeys(sessionName, `/exe-call ${employeeName2}`);
1105
- } catch {
1106
- }
1107
- }
1108
- registerSession({
1109
- windowName: sessionName,
1110
- agentId: employeeName2,
1111
- projectDir: spawnCwd,
1112
- parentExe: exeSession2,
1113
- pid: 0,
1114
- registeredAt: (/* @__PURE__ */ new Date()).toISOString()
1115
- });
1116
- return { sessionName };
1117
- }
1118
- var SESSION_CACHE, BEHAVIORS_EXPORT_TIMEOUT_MS, INTERCOM_DEBOUNCE_MS, INTERCOM_LOG2, DEBOUNCE_FILE, DEBOUNCE_CLEANUP_AGE_MS, BUSY_PATTERN;
1119
- var init_tmux_routing = __esm({
1120
- "src/lib/tmux-routing.ts"() {
1121
- "use strict";
1122
- init_session_registry();
1123
- init_session_key();
1124
- init_transport();
1125
- init_cc_agent_support();
1126
- init_mcp_prefix();
1127
- init_provider_table();
1128
- init_intercom_queue();
1129
- init_plan_limits();
1130
- init_worktree();
1131
- SESSION_CACHE = path8.join(os4.homedir(), ".exe-os", "session-cache");
1132
- BEHAVIORS_EXPORT_TIMEOUT_MS = 1e4;
1133
- INTERCOM_DEBOUNCE_MS = 3e4;
1134
- INTERCOM_LOG2 = path8.join(os4.homedir(), ".exe-os", "intercom.log");
1135
- DEBOUNCE_FILE = path8.join(SESSION_CACHE, "intercom-debounce.json");
1136
- DEBOUNCE_CLEANUP_AGE_MS = 5 * 60 * 1e3;
1137
- BUSY_PATTERN = /[✻✽✶✳·].*…|Running…/;
1138
- }
1139
- });
1140
-
1141
- // src/bin/exe-dispatch.ts
1142
- init_tmux_routing();
1143
- var employeeName = process.argv[2];
1144
- if (!employeeName) {
1145
- console.error("Usage: exe-dispatch <employeeName> [projectDir]");
1146
- process.exit(1);
1147
- }
1148
- var projectDir = process.argv[3] || process.cwd();
1149
- var exeSession = resolveExeSession();
1150
- if (!exeSession) {
1151
- console.log(JSON.stringify({
1152
- status: "failed",
1153
- sessionName: "",
1154
- error: "Not in tmux \u2014 cannot resolve exe session"
1155
- }));
1156
- process.exit(1);
1157
- }
1158
- var result = ensureEmployee(employeeName, exeSession, projectDir);
1159
- console.log(JSON.stringify(result));