reevesagents 1.7.2 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -4,21 +4,21 @@ import {
4
4
  runOnboarding,
5
5
  suggestedAgentPrompt,
6
6
  writeTuiOpenToken
7
- } from "./chunk-TUYP7APK.js";
7
+ } from "./chunk-X6EBVSC7.js";
8
8
  import {
9
9
  installSkills,
10
10
  removeSkills,
11
11
  skillsStatus,
12
12
  sweepAgents
13
- } from "./chunk-FL3LI2MU.js";
13
+ } from "./chunk-CFDTC6GY.js";
14
14
  import {
15
15
  MODEL_CATALOG
16
- } from "./chunk-QMRLJAEV.js";
16
+ } from "./chunk-HIJYVPYH.js";
17
17
  import {
18
18
  REEVESAGENTS_VERSION,
19
19
  listRunApprovals,
20
20
  resolveRunApproval
21
- } from "./chunk-NKT6GFCD.js";
21
+ } from "./chunk-UH6K25MG.js";
22
22
  import {
23
23
  ALLOWED_KEYS,
24
24
  CONFIG_FIELDS,
@@ -34,6 +34,7 @@ import {
34
34
  deleteRunHistory,
35
35
  detach,
36
36
  detectAvailable,
37
+ exactSession,
37
38
  hostStatus,
38
39
  interrupt,
39
40
  killAgent,
@@ -54,22 +55,24 @@ import {
54
55
  savePresetFromRun,
55
56
  sendKey,
56
57
  sendText,
58
+ sessionExists,
57
59
  setConfigValues,
58
60
  spawnWorker,
59
61
  startRun,
60
62
  startRunFromPreset,
61
63
  stopRun,
62
- verifyServerLaunch
63
- } from "./chunk-CE6YASBF.js";
64
- import "./chunk-D24DQQ6V.js";
64
+ verifyServerLaunch,
65
+ windowByName,
66
+ windowIds
67
+ } from "./chunk-PDJ2CPVO.js";
68
+ import "./chunk-Q3WWQP2R.js";
65
69
 
66
- // src/cli.ts
70
+ // src/surfaces/cli/index.ts
67
71
  import { Command } from "commander";
68
- import { execFileSync } from "child_process";
69
72
  import { realpathSync } from "fs";
70
73
  import { fileURLToPath } from "url";
71
74
 
72
- // src/utils/color-env.ts
75
+ // src/surfaces/cli/color-env.ts
73
76
  function prepareTuiColorEnv() {
74
77
  if (process.env.REEVES_NO_COLOR === "1") {
75
78
  delete process.env.FORCE_COLOR;
@@ -85,22 +88,50 @@ function prepareTuiColorEnv() {
85
88
  }
86
89
  }
87
90
 
88
- // src/cli.ts
89
- var program = new Command();
90
- program.name("reevesagents").description("local tmux-first workspace manager for AI CLI agents").version(REEVESAGENTS_VERSION).addHelpText("after", `
91
- First steps:
92
- reevesagents doctor check tmux, Node, and which provider CLIs are installed
93
- reevesagents providers list provider ids and aliases you can spawn
94
- reevesagents spawn --help agent spec syntax and a multi-agent example
95
-
96
- Let one agent drive others: "reevesagents attach <cli>" gives that CLI the
97
- agent-control tools (spawn, send, read, stop) over MCP. Full agent guide: AGENTS.md.`);
98
- function age(startedAt) {
99
- const seconds = Math.max(0, Math.floor((Date.now() - new Date(startedAt).getTime()) / 1e3));
100
- if (seconds < 60) return `${seconds}s`;
101
- if (seconds < 3600) return `${Math.floor(seconds / 60)}m`;
102
- return `${Math.floor(seconds / 3600)}h`;
91
+ // src/surfaces/cli/tui-launcher.ts
92
+ import { execFileSync } from "child_process";
93
+ function isTuiCommand(command) {
94
+ return command === "node" || command === "reevesagents";
95
+ }
96
+ function clearTuiSessionExcept(session, keepWindowId) {
97
+ for (const windowId of windowIds(session)) {
98
+ if (windowId === keepWindowId) continue;
99
+ try {
100
+ execFileSync("tmux", ["kill-window", "-t", windowId], { stdio: "ignore" });
101
+ } catch {
102
+ }
103
+ }
103
104
  }
105
+ function tuiNewWindowArgs(session, window, command) {
106
+ return ["new-window", "-d", "-P", "-F", "#{window_id}", "-t", `${exactSession(session)}:`, "-n", window, command];
107
+ }
108
+ function createTuiWindow(session, window, command) {
109
+ return execFileSync("tmux", tuiNewWindowArgs(session, window, command), { encoding: "utf8" }).trim();
110
+ }
111
+ function openTuiSession(command) {
112
+ const session = "reeves";
113
+ const window = "reeves";
114
+ if (!sessionExists(session)) {
115
+ execFileSync("tmux", ["new-session", "-s", session, "-n", window, command], { stdio: "inherit" });
116
+ return;
117
+ }
118
+ const existing = windowByName(session, window);
119
+ if (existing && !isTuiCommand(existing.command)) {
120
+ try {
121
+ execFileSync("tmux", ["kill-window", "-t", existing.id], { stdio: "ignore" });
122
+ } catch {
123
+ }
124
+ }
125
+ const windowId = existing && isTuiCommand(existing.command) ? existing.id : createTuiWindow(session, window, command);
126
+ execFileSync("tmux", ["select-window", "-t", windowId], { stdio: "ignore" });
127
+ clearTuiSessionExcept(session, windowId);
128
+ execFileSync("tmux", ["attach", "-t", exactSession(session)], { stdio: "inherit" });
129
+ }
130
+
131
+ // src/surfaces/cli/run.ts
132
+ import { execFileSync as execFileSync2 } from "child_process";
133
+
134
+ // src/surfaces/cli/helpers.ts
104
135
  function resolveRun(id) {
105
136
  const runs = listRuns();
106
137
  const exact = runs.find((run) => run.id === id || run.name === id);
@@ -119,6 +150,21 @@ function resolveAgent(id) {
119
150
  if (matches.length > 1) throw new Error(`ambiguous agent id: ${matches.map((agent) => agent.id).join(", ")}`);
120
151
  throw new Error(`agent not found: ${id}`);
121
152
  }
153
+ function destructiveAllowed(opts) {
154
+ return opts.yes === true || process.env.ALLOW_DESTRUCTIVE === "1";
155
+ }
156
+ function requireDestructiveConfirmation(opts, command) {
157
+ if (destructiveAllowed(opts)) return;
158
+ throw new Error(`refusing to ${command} without --yes or ALLOW_DESTRUCTIVE=1`);
159
+ }
160
+
161
+ // src/surfaces/cli/run.ts
162
+ function age(startedAt) {
163
+ const seconds = Math.max(0, Math.floor((Date.now() - new Date(startedAt).getTime()) / 1e3));
164
+ if (seconds < 60) return `${seconds}s`;
165
+ if (seconds < 3600) return `${Math.floor(seconds / 60)}m`;
166
+ return `${Math.floor(seconds / 3600)}h`;
167
+ }
122
168
  function resolveOpenTarget(id) {
123
169
  try {
124
170
  const run = resolveRun(id);
@@ -135,103 +181,30 @@ function quoteShell(s) {
135
181
  function tmuxAttachCommand(session, windowId) {
136
182
  return `tmux select-window -t ${quoteShell(`${session}:${windowId}`)} && tmux attach -t ${quoteShell(session)}`;
137
183
  }
138
- function exactSession(session) {
139
- return `=${session}`;
140
- }
141
- function tmuxSessionExists(session) {
142
- try {
143
- execFileSync("tmux", ["has-session", "-t", exactSession(session)], { stdio: "ignore" });
144
- return true;
145
- } catch {
146
- return false;
147
- }
148
- }
149
- function tmuxWindowIds(session) {
150
- try {
151
- return execFileSync("tmux", ["list-windows", "-t", exactSession(session), "-F", "#{window_id}"], { encoding: "utf8" }).split("\n").map((line) => line.trim()).filter(Boolean);
152
- } catch {
153
- return [];
154
- }
155
- }
156
- function tmuxWindowByName(session, name) {
157
- try {
158
- const rows = execFileSync("tmux", ["list-windows", "-t", exactSession(session), "-F", "#{window_id} #{window_name} #{pane_current_command}"], { encoding: "utf8" }).split("\n").map((line) => line.trim()).filter(Boolean);
159
- for (const row of rows) {
160
- const [windowId, windowName, command = ""] = row.split(" ");
161
- if (windowId && windowName === name) return { id: windowId, command };
162
- }
163
- } catch {
164
- }
165
- return null;
166
- }
167
- function isTuiCommand(command) {
168
- return command === "node" || command === "reevesagents";
169
- }
170
- function clearTuiSessionExcept(session, keepWindowId) {
171
- for (const windowId of tmuxWindowIds(session)) {
172
- if (windowId === keepWindowId) continue;
173
- try {
174
- execFileSync("tmux", ["kill-window", "-t", windowId], { stdio: "ignore" });
175
- } catch {
176
- }
177
- }
178
- }
179
- function tuiNewWindowArgs(session, window, command) {
180
- return ["new-window", "-d", "-P", "-F", "#{window_id}", "-t", `${exactSession(session)}:`, "-n", window, command];
181
- }
182
- function createTuiWindow(session, window, command) {
183
- return execFileSync("tmux", tuiNewWindowArgs(session, window, command), { encoding: "utf8" }).trim();
184
- }
185
- function openTuiSession(command) {
186
- const session = "reeves";
187
- const window = "reeves";
188
- if (!tmuxSessionExists(session)) {
189
- execFileSync("tmux", ["new-session", "-s", session, "-n", window, command], { stdio: "inherit" });
190
- return;
191
- }
192
- const existing = tmuxWindowByName(session, window);
193
- if (existing && !isTuiCommand(existing.command)) {
194
- try {
195
- execFileSync("tmux", ["kill-window", "-t", existing.id], { stdio: "ignore" });
196
- } catch {
197
- }
198
- }
199
- const windowId = existing && isTuiCommand(existing.command) ? existing.id : createTuiWindow(session, window, command);
200
- execFileSync("tmux", ["select-window", "-t", windowId], { stdio: "ignore" });
201
- clearTuiSessionExcept(session, windowId);
202
- execFileSync("tmux", ["attach", "-t", exactSession(session)], { stdio: "inherit" });
203
- }
204
184
  function openTarget(id) {
205
185
  const target = resolveOpenTarget(id);
206
- if (!tmuxSessionExists(target.session)) {
186
+ if (!sessionExists(target.session)) {
207
187
  throw new Error(`tmux session not found: ${target.session}`);
208
188
  }
209
- if (target.windowId.startsWith("@") && !tmuxWindowIds(target.session).includes(target.windowId)) {
189
+ if (target.windowId.startsWith("@") && !windowIds(target.session).includes(target.windowId)) {
210
190
  throw new Error("agent window no longer exists (tmux server may have restarted)");
211
191
  }
212
192
  const tmuxTarget = `${target.session}:${target.windowId}`;
213
193
  if (process.env.TMUX) {
214
- execFileSync("tmux", ["switch-client", "-t", tmuxTarget], { stdio: "ignore" });
215
- execFileSync("tmux", ["select-window", "-t", tmuxTarget], { stdio: "ignore" });
194
+ execFileSync2("tmux", ["switch-client", "-t", tmuxTarget], { stdio: "ignore" });
195
+ execFileSync2("tmux", ["select-window", "-t", tmuxTarget], { stdio: "ignore" });
216
196
  return;
217
197
  }
218
198
  try {
219
- execFileSync("tmux", ["select-window", "-t", tmuxTarget], { stdio: "ignore" });
199
+ execFileSync2("tmux", ["select-window", "-t", tmuxTarget], { stdio: "ignore" });
220
200
  } catch {
221
201
  }
222
202
  if (process.stdin.isTTY && process.stdout.isTTY) {
223
- execFileSync("tmux", ["attach", "-t", target.session], { stdio: "inherit" });
203
+ execFileSync2("tmux", ["attach", "-t", target.session], { stdio: "inherit" });
224
204
  return;
225
205
  }
226
206
  console.log(tmuxAttachCommand(target.session, target.windowId));
227
207
  }
228
- function destructiveAllowed(opts) {
229
- return opts.yes === true || process.env.ALLOW_DESTRUCTIVE === "1";
230
- }
231
- function requireDestructiveConfirmation(opts, command) {
232
- if (destructiveAllowed(opts)) return;
233
- throw new Error(`refusing to ${command} without --yes or ALLOW_DESTRUCTIVE=1`);
234
- }
235
208
  function parseAgentSpec(spec) {
236
209
  const [providerRaw = "", nickname, model = ""] = spec.split(":");
237
210
  const provider = normalizeProvider(providerRaw);
@@ -312,56 +285,57 @@ function spawnIntoRun(run, parsed, opts, available) {
312
285
  for (const agent of agents) printSpawnAgentLine(agent);
313
286
  printSpawnHints(run, !!opts.skip);
314
287
  }
315
- program.command("spawn [agent...]").description("start a run with one or more provider agents").option("--name <name>", "run name", "run").option("--cwd <dir>", "working directory", process.cwd()).option("--prompt <text>", "initial prompt pasted into each agent", "").option("--skip", "skip permission prompts for every agent (sets permissions to skip)").option("--run <run-id>", "add the agents to an existing run instead of starting a new one").option("--auth-mode <mode>", "auth mode for every agent: default or api-key").option("--effort <level>", "reasoning effort for every agent: default, low, medium, high, xhigh, max").option("--extra-args <args>", 'extra flags appended to every agent launch, e.g. "--remote-control"').option("--json", "output JSON: the run id and the spawned agent ids").action((agentSpecs, opts) => {
316
- try {
317
- const specs = agentSpecs.length > 0 ? agentSpecs : [defaultSpawnProvider()];
318
- const parsed = specs.map(parseAgentSpec);
319
- const available = preflightAvailability(parsed.map((spec) => spec.provider));
320
- const permissions = opts.skip ? "skip" : void 0;
321
- const auth_mode = parseAuthModeOpt(opts.authMode);
322
- const effort = parseEffortOpt(opts.effort);
323
- const extra_args = coerceExtraArgs(opts.extraArgs);
324
- if (opts.run) {
325
- spawnIntoRun(resolveRun(opts.run), parsed, opts, available);
326
- return;
327
- }
328
- const [first, ...rest] = parsed;
329
- const result = startRun({
330
- name: opts.name,
331
- working_dir: opts.cwd,
332
- root: {
333
- provider: first.provider,
334
- nickname: first.nickname,
335
- model: first.model,
336
- task: opts.prompt,
337
- permissions,
338
- auth_mode,
339
- effort,
340
- extra_args
341
- },
342
- workers: rest.map((spec) => ({
343
- provider: spec.provider,
344
- nickname: spec.nickname,
345
- model: spec.model,
346
- task: opts.prompt,
347
- permissions,
348
- auth_mode,
349
- effort,
350
- extra_args
351
- }))
352
- }, { available });
353
- if (opts.json) {
354
- printSpawnJson(result.run, result.agents);
355
- return;
288
+ function registerSpawn(program2) {
289
+ program2.command("spawn [agent...]").description("start a run with one or more provider agents").option("--name <name>", "run name", "run").option("--cwd <dir>", "working directory", process.cwd()).option("--prompt <text>", "initial prompt pasted into each agent", "").option("--skip", "skip permission prompts for every agent (sets permissions to skip)").option("--run <run-id>", "add the agents to an existing run instead of starting a new one").option("--auth-mode <mode>", "auth mode for every agent: default or api-key").option("--effort <level>", "reasoning effort for every agent: default, low, medium, high, xhigh, max").option("--extra-args <args>", 'extra flags appended to every agent launch, e.g. "--remote-control"').option("--json", "output JSON: the run id and the spawned agent ids").action((agentSpecs, opts) => {
290
+ try {
291
+ const specs = agentSpecs.length > 0 ? agentSpecs : [defaultSpawnProvider()];
292
+ const parsed = specs.map(parseAgentSpec);
293
+ const available = preflightAvailability(parsed.map((spec) => spec.provider));
294
+ const permissions = opts.skip ? "skip" : void 0;
295
+ const auth_mode = parseAuthModeOpt(opts.authMode);
296
+ const effort = parseEffortOpt(opts.effort);
297
+ const extra_args = coerceExtraArgs(opts.extraArgs);
298
+ if (opts.run) {
299
+ spawnIntoRun(resolveRun(opts.run), parsed, opts, available);
300
+ return;
301
+ }
302
+ const [first, ...rest] = parsed;
303
+ const result = startRun({
304
+ name: opts.name,
305
+ working_dir: opts.cwd,
306
+ root: {
307
+ provider: first.provider,
308
+ nickname: first.nickname,
309
+ model: first.model,
310
+ task: opts.prompt,
311
+ permissions,
312
+ auth_mode,
313
+ effort,
314
+ extra_args
315
+ },
316
+ workers: rest.map((spec) => ({
317
+ provider: spec.provider,
318
+ nickname: spec.nickname,
319
+ model: spec.model,
320
+ task: opts.prompt,
321
+ permissions,
322
+ auth_mode,
323
+ effort,
324
+ extra_args
325
+ }))
326
+ }, { available });
327
+ if (opts.json) {
328
+ printSpawnJson(result.run, result.agents);
329
+ return;
330
+ }
331
+ console.log(`started ${result.run.id.slice(0, 8)} ${result.run.name} ${result.agents.length} agents`);
332
+ for (const agent of result.agents) printSpawnAgentLine(agent);
333
+ printSpawnHints(result.run, !!opts.skip);
334
+ } catch (err) {
335
+ console.error(err instanceof Error ? err.message : String(err));
336
+ process.exit(1);
356
337
  }
357
- console.log(`started ${result.run.id.slice(0, 8)} ${result.run.name} ${result.agents.length} agents`);
358
- for (const agent of result.agents) printSpawnAgentLine(agent);
359
- printSpawnHints(result.run, !!opts.skip);
360
- } catch (err) {
361
- console.error(err instanceof Error ? err.message : String(err));
362
- process.exit(1);
363
- }
364
- }).addHelpText("after", `
338
+ }).addHelpText("after", `
365
339
  Agent spec: provider[:nickname[:model]] (nickname and model are optional)
366
340
  The first agent leads the run; the rest join it as workers.
367
341
  Provider ids and aliases come from "reevesagents providers"
@@ -373,23 +347,25 @@ Example: a Claude Code lead with two Codex and one Kimi worker
373
347
 
374
348
  Run "reevesagents doctor" first: it reports tmux, Node, and which provider
375
349
  CLIs are installed and logged in, so a spawn does not fail on a missing CLI.`);
376
- program.command("add [agent...]").description("add agents to the current workspace (the most recent active run)").option("--run <run-id>", "target a specific run instead of the most recent active one").option("--prompt <text>", "initial prompt pasted into each agent", "").option("--skip", "skip permission prompts for every agent (sets permissions to skip)").option("--auth-mode <mode>", "auth mode for every agent: default or api-key").option("--effort <level>", "reasoning effort for every agent: default, low, medium, high, xhigh, max").option("--extra-args <args>", 'extra flags appended to every agent launch, e.g. "--remote-control"').option("--json", "output JSON: the run id and the spawned agent ids").action((agentSpecs, opts) => {
377
- try {
378
- if (agentSpecs.length === 0) {
379
- throw new Error('add needs at least one agent, e.g. "reevesagents add codex"');
380
- }
381
- const parsed = agentSpecs.map(parseAgentSpec);
382
- const available = preflightAvailability(parsed.map((spec) => spec.provider));
383
- const run = opts.run ? resolveRun(opts.run) : latestActiveRun();
384
- if (!run) {
385
- throw new Error('no active workspace to add to. Start one with "reevesagents spawn"');
386
- }
387
- spawnIntoRun(run, parsed, opts, available);
388
- } catch (err) {
389
- console.error(err instanceof Error ? err.message : String(err));
390
- process.exit(1);
391
- }
392
- }).addHelpText("after", `
350
+ }
351
+ function registerAdd(program2) {
352
+ program2.command("add [agent...]").description("add agents to the current workspace (the most recent active run)").option("--run <run-id>", "target a specific run instead of the most recent active one").option("--prompt <text>", "initial prompt pasted into each agent", "").option("--skip", "skip permission prompts for every agent (sets permissions to skip)").option("--auth-mode <mode>", "auth mode for every agent: default or api-key").option("--effort <level>", "reasoning effort for every agent: default, low, medium, high, xhigh, max").option("--extra-args <args>", 'extra flags appended to every agent launch, e.g. "--remote-control"').option("--json", "output JSON: the run id and the spawned agent ids").action((agentSpecs, opts) => {
353
+ try {
354
+ if (agentSpecs.length === 0) {
355
+ throw new Error('add needs at least one agent, e.g. "reevesagents add codex"');
356
+ }
357
+ const parsed = agentSpecs.map(parseAgentSpec);
358
+ const available = preflightAvailability(parsed.map((spec) => spec.provider));
359
+ const run = opts.run ? resolveRun(opts.run) : latestActiveRun();
360
+ if (!run) {
361
+ throw new Error('no active workspace to add to. Start one with "reevesagents spawn"');
362
+ }
363
+ spawnIntoRun(run, parsed, opts, available);
364
+ } catch (err) {
365
+ console.error(err instanceof Error ? err.message : String(err));
366
+ process.exit(1);
367
+ }
368
+ }).addHelpText("after", `
393
369
  Adds agents to a workspace you already have, so you can grow it one at a time
394
370
  without passing a run id. With no --run it targets your most recent active run.
395
371
 
@@ -400,468 +376,541 @@ Example: start a workspace, then keep adding to it
400
376
 
401
377
  Agents added this way just run side by side; none controls the others unless
402
378
  you attach the Agent control MCP.`);
403
- program.command("runs").description("list runs").option("--json", "output JSON array").action((opts) => {
404
- autoCleanupRuns();
405
- const runs = listRuns().map((run) => ({ ...run, view_status: computeRunStatus(run, runHasLiveTmuxTarget(run)) }));
406
- if (opts.json) {
407
- console.log(JSON.stringify(runs, null, 2));
408
- return;
409
- }
410
- if (runs.length === 0) {
411
- console.log("no runs");
412
- return;
413
- }
414
- for (const run of runs) {
415
- const agents = listAgents(run.id);
416
- const root = agents.find((agent) => agent.role === "root");
417
- const note = agents.find((agent) => agent.task_note.trim())?.task_note ?? "";
418
- const rootProvider = root ? providerDisplayName(root.provider) : "-";
419
- console.log(`${run.id.slice(0, 8)} ${run.view_status.padEnd(7)} ${"agent run".padEnd(9)} ${rootProvider.padEnd(14)} ${String(agents.length).padStart(2)} ${"agents".padEnd(9)} ${age(run.started_at).padEnd(4)} ${run.name} ${run.working_dir}${note ? ` ${note}` : ""}`);
420
- }
421
- });
422
- program.command("reap").description("reap zombie agents: end any whose tmux window is gone or that outlive max_lifetime_ms").option("--json", "output JSON array of reaped agents").action((opts) => {
423
- const { reaped } = sweepAgents();
424
- if (opts.json) {
425
- console.log(JSON.stringify(reaped, null, 2));
426
- return;
427
- }
428
- if (reaped.length === 0) {
429
- console.log("no zombie agents");
430
- return;
431
- }
432
- for (const r of reaped) {
433
- console.log(`${r.agent_id.slice(0, 8)} ${r.run_id.slice(0, 8)} ${r.reason.padEnd(17)} ${String(Math.round(r.age_ms / 1e3)).padStart(5)}s ${r.nickname}`);
434
- }
435
- console.log(`reaped ${reaped.length} ${reaped.length === 1 ? "agent" : "agents"}`);
436
- });
437
- program.command("open <id>").description("open a run tmux tab set or an agent window").action((id) => {
438
- openTarget(id);
439
- });
440
- program.command("peek <agent-id>").description("show recent output from one agent").option("-n, --lines <n>", "number of lines", "20").option("--json", "output JSON with lines array").action((id, opts) => {
441
- const agent = resolveAgent(id);
442
- const lines = Number.parseInt(opts.lines, 10);
443
- const output = peekAgent(agent.id, Number.isFinite(lines) ? lines : 20);
444
- if (opts.json) {
445
- console.log(JSON.stringify({ agent_id: agent.id, lines: output ? output.split("\n") : [] }, null, 2));
446
- return;
447
- }
448
- if (!output) {
449
- console.error(`no output for agent ${agent.id}`);
450
- process.exit(1);
451
- }
452
- console.log(output);
453
- });
454
- program.command("stop <run-id>").description("stop one run").option("-y, --yes", "confirm stop").action((id, opts) => {
455
- requireDestructiveConfirmation(opts, "stop run");
456
- const run = resolveRun(id);
457
- const stopped = stopRun(run.id);
458
- console.log(`stopped ${stopped.id.slice(0, 8)} ${stopped.name}`);
459
- });
460
- program.command("kill <agent-id>").description("stop one agent").option("-y, --yes", "confirm stop").action((id, opts) => {
461
- requireDestructiveConfirmation(opts, "stop agent");
462
- const agent = resolveAgent(id);
463
- const killed = killAgent(agent.id);
464
- console.log(`stopped ${killed.id.slice(0, 8)} ${killed.nickname}`);
465
- });
466
- program.command("send <agent-id> <text...>").description("paste text into an agent").action((id, textParts) => {
467
- try {
379
+ }
380
+ function registerRuns(program2) {
381
+ program2.command("runs").description("list runs").option("--json", "output JSON array").action((opts) => {
382
+ autoCleanupRuns();
383
+ const runs = listRuns().map((run) => ({ ...run, view_status: computeRunStatus(run, runHasLiveTmuxTarget(run)) }));
384
+ if (opts.json) {
385
+ console.log(JSON.stringify(runs, null, 2));
386
+ return;
387
+ }
388
+ if (runs.length === 0) {
389
+ console.log("no runs");
390
+ return;
391
+ }
392
+ for (const run of runs) {
393
+ const agents = listAgents(run.id);
394
+ const root = agents.find((agent) => agent.role === "root");
395
+ const note = agents.find((agent) => agent.task_note.trim())?.task_note ?? "";
396
+ const rootProvider = root ? providerDisplayName(root.provider) : "-";
397
+ console.log(`${run.id.slice(0, 8)} ${run.view_status.padEnd(7)} ${"agent run".padEnd(9)} ${rootProvider.padEnd(14)} ${String(agents.length).padStart(2)} ${"agents".padEnd(9)} ${age(run.started_at).padEnd(4)} ${run.name} ${run.working_dir}${note ? ` ${note}` : ""}`);
398
+ }
399
+ });
400
+ }
401
+ function registerReap(program2) {
402
+ program2.command("reap").description("reap zombie agents: end any whose tmux window is gone or that outlive max_lifetime_ms").option("--json", "output JSON array of reaped agents").action((opts) => {
403
+ const { reaped } = sweepAgents();
404
+ if (opts.json) {
405
+ console.log(JSON.stringify(reaped, null, 2));
406
+ return;
407
+ }
408
+ if (reaped.length === 0) {
409
+ console.log("no zombie agents");
410
+ return;
411
+ }
412
+ for (const r of reaped) {
413
+ console.log(`${r.agent_id.slice(0, 8)} ${r.run_id.slice(0, 8)} ${r.reason.padEnd(17)} ${String(Math.round(r.age_ms / 1e3)).padStart(5)}s ${r.nickname}`);
414
+ }
415
+ console.log(`reaped ${reaped.length} ${reaped.length === 1 ? "agent" : "agents"}`);
416
+ });
417
+ }
418
+ function registerOpen(program2) {
419
+ program2.command("open <id>").description("open a run tmux tab set or an agent window").action((id) => {
420
+ openTarget(id);
421
+ });
422
+ }
423
+ function registerStop(program2) {
424
+ program2.command("stop <run-id>").description("stop one run").option("-y, --yes", "confirm stop").action((id, opts) => {
425
+ requireDestructiveConfirmation(opts, "stop run");
426
+ const run = resolveRun(id);
427
+ const stopped = stopRun(run.id);
428
+ console.log(`stopped ${stopped.id.slice(0, 8)} ${stopped.name}`);
429
+ });
430
+ }
431
+
432
+ // src/surfaces/cli/agents.ts
433
+ function registerPeek(program2) {
434
+ program2.command("peek <agent-id>").description("show recent output from one agent").option("-n, --lines <n>", "number of lines", "20").option("--json", "output JSON with lines array").action((id, opts) => {
468
435
  const agent = resolveAgent(id);
469
- sendText(agent.id, textParts.join(" "));
470
- console.log(`sent to ${agent.id.slice(0, 8)} ${agent.nickname}`);
471
- } catch (err) {
472
- console.error(err instanceof Error ? err.message : String(err));
473
- process.exit(1);
474
- }
475
- });
476
- program.command("key <agent-id> <key>").description(`send a single keypress to an agent (${ALLOWED_KEYS.join(", ")})`).action((id, key) => {
477
- try {
436
+ const lines = Number.parseInt(opts.lines, 10);
437
+ const output = peekAgent(agent.id, Number.isFinite(lines) ? lines : 20);
438
+ if (opts.json) {
439
+ console.log(JSON.stringify({ agent_id: agent.id, lines: output ? output.split("\n") : [] }, null, 2));
440
+ return;
441
+ }
442
+ if (!output) {
443
+ console.error(`no output for agent ${agent.id}`);
444
+ process.exit(1);
445
+ }
446
+ console.log(output);
447
+ });
448
+ }
449
+ function registerKill(program2) {
450
+ program2.command("kill <agent-id>").description("stop one agent").option("-y, --yes", "confirm stop").action((id, opts) => {
451
+ requireDestructiveConfirmation(opts, "stop agent");
478
452
  const agent = resolveAgent(id);
479
- if (!ALLOWED_KEYS.includes(key)) {
480
- throw new Error(`unsupported key: ${key} (allowed: ${ALLOWED_KEYS.join(", ")})`);
453
+ const killed = killAgent(agent.id);
454
+ console.log(`stopped ${killed.id.slice(0, 8)} ${killed.nickname}`);
455
+ });
456
+ }
457
+ function registerSend(program2) {
458
+ program2.command("send <agent-id> <text...>").description("paste text into an agent").action((id, textParts) => {
459
+ try {
460
+ const agent = resolveAgent(id);
461
+ sendText(agent.id, textParts.join(" "));
462
+ console.log(`sent to ${agent.id.slice(0, 8)} ${agent.nickname}`);
463
+ } catch (err) {
464
+ console.error(err instanceof Error ? err.message : String(err));
465
+ process.exit(1);
481
466
  }
482
- sendKey(agent.id, key);
483
- console.log(`sent ${key} to ${agent.id.slice(0, 8)} ${agent.nickname}`);
484
- } catch (err) {
485
- console.error(err instanceof Error ? err.message : String(err));
486
- process.exit(1);
487
- }
488
- });
489
- program.command("interrupt <agent-id>").description("send an interrupt (ctrl-c) to an agent").action((id) => {
490
- try {
467
+ });
468
+ }
469
+ function registerKey(program2) {
470
+ program2.command("key <agent-id> <key>").description(`send a single keypress to an agent (${ALLOWED_KEYS.join(", ")})`).action((id, key) => {
471
+ try {
472
+ const agent = resolveAgent(id);
473
+ if (!ALLOWED_KEYS.includes(key)) {
474
+ throw new Error(`unsupported key: ${key} (allowed: ${ALLOWED_KEYS.join(", ")})`);
475
+ }
476
+ sendKey(agent.id, key);
477
+ console.log(`sent ${key} to ${agent.id.slice(0, 8)} ${agent.nickname}`);
478
+ } catch (err) {
479
+ console.error(err instanceof Error ? err.message : String(err));
480
+ process.exit(1);
481
+ }
482
+ });
483
+ }
484
+ function registerInterrupt(program2) {
485
+ program2.command("interrupt <agent-id>").description("send an interrupt (ctrl-c) to an agent").action((id) => {
486
+ try {
487
+ const agent = resolveAgent(id);
488
+ interrupt(agent.id);
489
+ console.log(`interrupted ${agent.id.slice(0, 8)} ${agent.nickname}`);
490
+ } catch (err) {
491
+ console.error(err instanceof Error ? err.message : String(err));
492
+ process.exit(1);
493
+ }
494
+ });
495
+ }
496
+ function registerDelete(program2) {
497
+ program2.command("delete <agent-id>").description("delete an ended agent").option("-y, --yes", "confirm delete").action((id, opts) => {
498
+ requireDestructiveConfirmation(opts, "delete agent");
491
499
  const agent = resolveAgent(id);
492
- interrupt(agent.id);
493
- console.log(`interrupted ${agent.id.slice(0, 8)} ${agent.nickname}`);
494
- } catch (err) {
495
- console.error(err instanceof Error ? err.message : String(err));
496
- process.exit(1);
497
- }
498
- });
499
- program.command("delete <agent-id>").description("delete an ended agent").option("-y, --yes", "confirm delete").action((id, opts) => {
500
- requireDestructiveConfirmation(opts, "delete agent");
501
- const agent = resolveAgent(id);
502
- const deleted = deleteAgent(agent.id);
503
- console.log(`deleted ${deleted.id.slice(0, 8)} ${deleted.nickname}`);
504
- });
505
- program.command("delete-run <run-id>").description("delete an ended run").option("-y, --yes", "confirm delete").action((id, opts) => {
506
- requireDestructiveConfirmation(opts, "delete run");
507
- const run = readRun(id);
508
- if (run.status !== "ended" && run.ended_at === null) throw new Error("Stop run before deleting it");
509
- archiveAndRemoveRun(run.id, "ended");
510
- console.log(`deleted ${run.id.slice(0, 8)} ${run.name}`);
511
- });
512
- program.command("history").description("list archived run history").option("--json", "output JSON array").action((opts) => {
513
- const records = listRunHistory();
514
- if (opts.json) {
515
- console.log(JSON.stringify(records, null, 2));
516
- return;
517
- }
518
- if (records.length === 0) {
519
- console.log("no history");
520
- return;
521
- }
522
- for (const record of records) {
523
- const provider = record.root_provider ? providerDisplayName(record.root_provider) : "-";
524
- console.log(`${record.id.slice(0, 8)} ${record.status.padEnd(5)} ${provider.padEnd(14)} ${String(record.agent_count).padStart(2)} agents ${record.name} ${record.working_dir}`);
525
- }
526
- });
527
- program.command("delete-history <id>").description("delete one run history record").option("-y, --yes", "confirm delete").action((id, opts) => {
528
- requireDestructiveConfirmation(opts, "delete history record");
529
- if (!listRunHistory().some((record) => record.id === id)) throw new Error(`history record not found: ${id}`);
530
- deleteRunHistory(id);
531
- console.log(`deleted history ${id.slice(0, 8)}`);
532
- });
533
- program.command("providers").description("list providers with availability and known models").option("--json", "output JSON array").option("--models", "also print each provider's known models").action((opts) => {
534
- const available = detectAvailable();
535
- const providers = PROVIDERS.map((id) => ({
536
- id,
537
- name: providerDisplayName(id),
538
- available: available[id],
539
- color: providerColor(id),
540
- models: [...MODEL_CATALOG[id].models]
541
- }));
542
- if (opts.json) {
543
- console.log(JSON.stringify(providers, null, 2));
544
- return;
545
- }
546
- for (const provider of providers) {
547
- console.log(`${(provider.available ? "ok" : "--").padEnd(3)} ${provider.id.padEnd(10)} ${provider.name}`);
548
- if (opts.models) {
549
- for (const model of provider.models) console.log(` ${model}`);
500
+ const deleted = deleteAgent(agent.id);
501
+ console.log(`deleted ${deleted.id.slice(0, 8)} ${deleted.nickname}`);
502
+ });
503
+ }
504
+ function registerAgents(program2) {
505
+ program2.command("agents [run-id]").description("list agents, optionally only those in one run").option("--json", "output JSON array").action((runId, opts) => {
506
+ try {
507
+ const run = runId ? resolveRun(runId) : void 0;
508
+ const agents = listAgents(run?.id);
509
+ if (opts.json) {
510
+ console.log(JSON.stringify(agents, null, 2));
511
+ return;
512
+ }
513
+ if (agents.length === 0) {
514
+ console.log("no agents");
515
+ return;
516
+ }
517
+ for (const agent of agents) {
518
+ const note = agent.task_note.trim();
519
+ console.log(`${agent.id.slice(0, 8)} ${agent.run_id.slice(0, 8)} ${agent.role.padEnd(6)} ${agent.task_status.padEnd(7)} ${providerDisplayName(agent.provider).padEnd(14)} ${(agent.model || "default").padEnd(16)} ${agent.nickname}${note ? ` ${note}` : ""}`);
520
+ }
521
+ } catch (err) {
522
+ console.error(err instanceof Error ? err.message : String(err));
523
+ process.exit(1);
550
524
  }
551
- }
552
- });
553
- program.command("approvals").description("list pending approvals").option("--json", "output JSON array").action((opts) => {
554
- const approvals = listRunApprovals(void 0, "pending");
555
- if (opts.json) {
556
- console.log(JSON.stringify(approvals, null, 2));
557
- return;
558
- }
559
- if (approvals.length === 0) {
560
- console.log("no pending approvals");
561
- return;
562
- }
563
- for (const approval of approvals) {
564
- console.log(`${approval.id.slice(0, 8)} ${approval.risk.padEnd(6)} ${approval.action.padEnd(16)} ${approval.summary}`);
565
- }
566
- });
567
- program.command("approve <approval-id> [note]").description("approve a pending approval").action((id, note) => {
568
- try {
569
- const resolved = resolveRunApproval(id, "approved", note ?? "");
570
- console.log(`${resolved.status} ${resolved.id.slice(0, 8)} ${resolved.action}`);
571
- } catch (err) {
572
- console.error(err instanceof Error ? err.message : String(err));
573
- process.exit(1);
574
- }
575
- });
576
- program.command("deny <approval-id> [note]").description("deny a pending approval").action((id, note) => {
577
- try {
578
- const resolved = resolveRunApproval(id, "denied", note ?? "");
579
- console.log(`${resolved.status} ${resolved.id.slice(0, 8)} ${resolved.action}`);
580
- } catch (err) {
581
- console.error(err instanceof Error ? err.message : String(err));
582
- process.exit(1);
583
- }
584
- });
585
- program.command("setup").description("check your setup and connect installed CLIs (the first-run wizard)").option("--attach", "connect reevesagents to every installed host CLI (default only reports)").option("--json", "print the onboarding state as JSON").action(async (opts) => {
586
- try {
587
- const state = buildOnboardingState();
525
+ });
526
+ }
527
+
528
+ // src/surfaces/cli/history.ts
529
+ function registerDeleteRun(program2) {
530
+ program2.command("delete-run <run-id>").description("delete an ended run").option("-y, --yes", "confirm delete").action((id, opts) => {
531
+ requireDestructiveConfirmation(opts, "delete run");
532
+ const run = readRun(id);
533
+ if (run.status !== "ended" && run.ended_at === null) throw new Error("Stop run before deleting it");
534
+ archiveAndRemoveRun(run.id, "ended");
535
+ console.log(`deleted ${run.id.slice(0, 8)} ${run.name}`);
536
+ });
537
+ }
538
+ function registerHistory(program2) {
539
+ program2.command("history").description("list archived run history").option("--json", "output JSON array").action((opts) => {
540
+ const records = listRunHistory();
588
541
  if (opts.json) {
589
- console.log(JSON.stringify(state, null, 2));
542
+ console.log(JSON.stringify(records, null, 2));
590
543
  return;
591
544
  }
592
- console.log(`tmux ${state.tmuxOk ? "ok" : "missing (required; install tmux 3.0+)"}`);
593
- console.log(`node ${state.nodeOk ? "ok" : "too old (need >=20.19)"}`);
594
- console.log(`providers ${state.installedProviders.length > 0 ? state.installedProviders.map(providerDisplayName).join(", ") : "none installed"}`);
595
- if (state.installedProviders.length === 0) {
596
- console.log("\nInstall a provider CLI (for example Claude Code or Codex) and sign in, then run setup again.");
545
+ if (records.length === 0) {
546
+ console.log("no history");
597
547
  return;
598
548
  }
599
- console.log("\nTwo ways to use reevesagents:");
600
- console.log(` 1. Run agents yourself reevesagents spawn ${state.installedProviders[0]}`);
601
- console.log(" 2. Let one CLI drive others connect the Agent control MCP (below)");
602
- const installedHosts = state.hosts.filter((host) => host.installed);
603
- if (installedHosts.length > 0) {
604
- console.log("\nHost CLIs (can drive the others once connected):");
605
- for (const host of installedHosts) {
606
- const status = host.attached ? "connected" : host.manual ? "add manually" : "not connected";
607
- console.log(` ${host.key.padEnd(10)} ${status}`);
608
- }
549
+ for (const record of records) {
550
+ const provider = record.root_provider ? providerDisplayName(record.root_provider) : "-";
551
+ console.log(`${record.id.slice(0, 8)} ${record.status.padEnd(5)} ${provider.padEnd(14)} ${String(record.agent_count).padStart(2)} agents ${record.name} ${record.working_dir}`);
609
552
  }
610
- if (!opts.attach) {
611
- if (state.attachable.length > 0) {
612
- console.log(`
613
- To connect ${state.attachable.join(", ")}, run: reevesagents setup --attach`);
614
- } else if (state.attachedHosts.length > 0) {
615
- console.log("\nAll installed host CLIs are already connected. Restart them to load the tools.");
553
+ });
554
+ }
555
+ function registerDeleteHistory(program2) {
556
+ program2.command("delete-history <id>").description("delete one run history record").option("-y, --yes", "confirm delete").action((id, opts) => {
557
+ requireDestructiveConfirmation(opts, "delete history record");
558
+ if (!listRunHistory().some((record) => record.id === id)) throw new Error(`history record not found: ${id}`);
559
+ deleteRunHistory(id);
560
+ console.log(`deleted history ${id.slice(0, 8)}`);
561
+ });
562
+ }
563
+
564
+ // src/surfaces/cli/providers.ts
565
+ function registerProviders(program2) {
566
+ program2.command("providers").description("list providers with availability and known models").option("--json", "output JSON array").option("--models", "also print each provider's known models").action((opts) => {
567
+ const available = detectAvailable();
568
+ const providers = PROVIDERS.map((id) => ({
569
+ id,
570
+ name: providerDisplayName(id),
571
+ available: available[id],
572
+ color: providerColor(id),
573
+ models: [...MODEL_CATALOG[id].models]
574
+ }));
575
+ if (opts.json) {
576
+ console.log(JSON.stringify(providers, null, 2));
577
+ return;
578
+ }
579
+ for (const provider of providers) {
580
+ console.log(`${(provider.available ? "ok" : "--").padEnd(3)} ${provider.id.padEnd(10)} ${provider.name}`);
581
+ if (opts.models) {
582
+ for (const model of provider.models) console.log(` ${model}`);
616
583
  }
584
+ }
585
+ });
586
+ }
587
+
588
+ // src/surfaces/cli/approvals.ts
589
+ function registerApprovals(program2) {
590
+ program2.command("approvals").description("list pending approvals").option("--json", "output JSON array").action((opts) => {
591
+ const approvals = listRunApprovals(void 0, "pending");
592
+ if (opts.json) {
593
+ console.log(JSON.stringify(approvals, null, 2));
594
+ return;
595
+ }
596
+ if (approvals.length === 0) {
597
+ console.log("no pending approvals");
617
598
  return;
618
599
  }
619
- console.log("\nSetting up...");
620
- const result = await runOnboarding();
621
- if (result.skills.some((skill) => skill.ok)) {
622
- console.log(" ok skill installed for skill-aware CLIs (Claude, Codex, Kimi, OpenCode)");
600
+ for (const approval of approvals) {
601
+ console.log(`${approval.id.slice(0, 8)} ${approval.risk.padEnd(6)} ${approval.action.padEnd(16)} ${approval.summary}`);
623
602
  }
624
- for (const attached of result.attached) {
625
- console.log(` ${(attached.ok ? "ok" : "--").padEnd(3)} ${attached.key.padEnd(10)} ${attached.message}`);
603
+ });
604
+ }
605
+ function registerApprove(program2) {
606
+ program2.command("approve <approval-id> [note]").description("approve a pending approval").action((id, note) => {
607
+ try {
608
+ const resolved = resolveRunApproval(id, "approved", note ?? "");
609
+ console.log(`${resolved.status} ${resolved.id.slice(0, 8)} ${resolved.action}`);
610
+ } catch (err) {
611
+ console.error(err instanceof Error ? err.message : String(err));
612
+ process.exit(1);
613
+ }
614
+ });
615
+ }
616
+ function registerDeny(program2) {
617
+ program2.command("deny <approval-id> [note]").description("deny a pending approval").action((id, note) => {
618
+ try {
619
+ const resolved = resolveRunApproval(id, "denied", note ?? "");
620
+ console.log(`${resolved.status} ${resolved.id.slice(0, 8)} ${resolved.action}`);
621
+ } catch (err) {
622
+ console.error(err instanceof Error ? err.message : String(err));
623
+ process.exit(1);
626
624
  }
627
- if (result.verify?.ok) {
628
- console.log(`
625
+ });
626
+ }
627
+
628
+ // src/surfaces/cli/setup.ts
629
+ function registerSetup(program2) {
630
+ program2.command("setup").description("check your setup and connect installed CLIs (the first-run wizard)").option("--attach", "connect reevesagents to every installed host CLI (default only reports)").option("--json", "print the onboarding state as JSON").action(async (opts) => {
631
+ try {
632
+ const state = buildOnboardingState();
633
+ if (opts.json) {
634
+ console.log(JSON.stringify(state, null, 2));
635
+ return;
636
+ }
637
+ console.log(`tmux ${state.tmuxOk ? "ok" : "missing (required; install tmux 3.0+)"}`);
638
+ console.log(`node ${state.nodeOk ? "ok" : "too old (need >=20.19)"}`);
639
+ console.log(`providers ${state.installedProviders.length > 0 ? state.installedProviders.map(providerDisplayName).join(", ") : "none installed"}`);
640
+ if (state.installedProviders.length === 0) {
641
+ console.log("\nInstall a provider CLI (for example Claude Code or Codex) and sign in, then run setup again.");
642
+ return;
643
+ }
644
+ console.log("\nTwo ways to use reevesagents:");
645
+ console.log(` 1. Run agents yourself reevesagents spawn ${state.installedProviders[0]}`);
646
+ console.log(" 2. Let one CLI drive others connect the Agent control MCP (below)");
647
+ const installedHosts = state.hosts.filter((host) => host.installed);
648
+ if (installedHosts.length > 0) {
649
+ console.log("\nHost CLIs (can drive the others once connected):");
650
+ for (const host of installedHosts) {
651
+ const status = host.attached ? "connected" : host.manual ? "add manually" : "not connected";
652
+ console.log(` ${host.key.padEnd(10)} ${status}`);
653
+ }
654
+ }
655
+ if (!opts.attach) {
656
+ if (state.attachable.length > 0) {
657
+ console.log(`
658
+ To connect ${state.attachable.join(", ")}, run: reevesagents setup --attach`);
659
+ } else if (state.attachedHosts.length > 0) {
660
+ console.log("\nAll installed host CLIs are already connected. Restart them to load the tools.");
661
+ }
662
+ return;
663
+ }
664
+ console.log("\nSetting up...");
665
+ const result = await runOnboarding();
666
+ if (result.skills.some((skill) => skill.ok)) {
667
+ console.log(" ok skill installed for skill-aware CLIs (Claude, Codex, Kimi, OpenCode)");
668
+ }
669
+ for (const attached of result.attached) {
670
+ console.log(` ${(attached.ok ? "ok" : "--").padEnd(3)} ${attached.key.padEnd(10)} ${attached.message}`);
671
+ }
672
+ if (result.verify?.ok) {
673
+ console.log(`
629
674
  verified: ${result.verify.detail}.`);
630
- const keys = result.attached.filter((attached) => attached.ok).map((attached) => attached.key);
631
- console.log(`Restart ${keys.join(", ")} (start a new session), then ask it: "${suggestedAgentPrompt(state.installedProviders)}".`);
632
- } else if (result.verify) {
633
- console.log(`
675
+ const keys = result.attached.filter((attached) => attached.ok).map((attached) => attached.key);
676
+ console.log(`Restart ${keys.join(", ")} (start a new session), then ask it: "${suggestedAgentPrompt(state.installedProviders)}".`);
677
+ } else if (result.verify) {
678
+ console.log(`
634
679
  warning: the server did not start here: ${result.verify.detail}`);
635
- console.log("a host CLI will hit the same error. check that reevesagents is installed and re-run setup --attach.");
680
+ console.log("a host CLI will hit the same error. check that reevesagents is installed and re-run setup --attach.");
681
+ }
682
+ if (!result.attached.some((attached) => attached.ok) || result.verify?.ok === false) process.exitCode = 1;
683
+ } catch (err) {
684
+ console.error(err instanceof Error ? err.message : String(err));
685
+ process.exit(1);
636
686
  }
637
- if (!result.attached.some((attached) => attached.ok) || result.verify?.ok === false) process.exitCode = 1;
638
- } catch (err) {
639
- console.error(err instanceof Error ? err.message : String(err));
640
- process.exit(1);
641
- }
642
- });
643
- program.command("hosts").description("list MCP host CLIs and whether reevesagents is attached").option("--json", "output JSON array").action((opts) => {
644
- const hosts = hostStatus();
645
- if (opts.json) {
646
- console.log(JSON.stringify(hosts, null, 2));
647
- return;
648
- }
649
- for (const host of hosts) {
650
- const state = !host.installed ? "absent" : host.attached ? "attached" : host.manual ? "manual" : "detached";
651
- console.log(`${host.key.padEnd(10)} ${state.padEnd(9)} ${host.label}`);
652
- }
653
- });
654
- program.command("attach [cli]").description("attach the reevesagents MCP to one CLI, or all installed when omitted").option("--force", "rewrite the registration even if already attached (upgrades an old launcher)").action(async (cli, opts) => {
655
- try {
656
- const results = cli ? [attach(cli, opts.force)] : attachAll(opts.force);
657
- if (results.length === 0) {
658
- console.log("no MCP-capable CLI is installed here.");
659
- console.log('Install a host CLI (for example Claude Code or Codex) and sign in, then run "reevesagents attach" again.');
660
- process.exitCode = 1;
687
+ });
688
+ }
689
+ function registerSkills(program2) {
690
+ program2.command("skills [action]").description("install the reevesagents skill for skill-aware CLIs (action: status, install, remove)").option("--json", "output JSON").action((action, opts) => {
691
+ const verb = action ?? "status";
692
+ try {
693
+ if (verb === "install") {
694
+ const results = installSkills();
695
+ if (opts.json) {
696
+ console.log(JSON.stringify(results, null, 2));
697
+ return;
698
+ }
699
+ for (const r of results) console.log(`${(r.ok ? "ok" : "--").padEnd(3)} ${r.label.padEnd(24)} ${r.file}`);
700
+ console.log("\nrestart your CLIs to pick up the skill.");
701
+ if (results.some((r) => !r.ok)) process.exitCode = 1;
702
+ return;
703
+ }
704
+ if (verb === "remove") {
705
+ const results = removeSkills();
706
+ if (opts.json) {
707
+ console.log(JSON.stringify(results, null, 2));
708
+ return;
709
+ }
710
+ for (const r of results) console.log(`${(r.ok ? "ok" : "--").padEnd(3)} ${r.label.padEnd(24)} ${r.message}`);
711
+ if (results.some((r) => !r.ok)) process.exitCode = 1;
712
+ return;
713
+ }
714
+ if (verb === "status") {
715
+ const rows = skillsStatus();
716
+ if (opts.json) {
717
+ console.log(JSON.stringify(rows, null, 2));
718
+ return;
719
+ }
720
+ for (const r of rows) {
721
+ const state = !r.present ? "absent" : r.current ? "installed" : "outdated";
722
+ console.log(`${state.padEnd(10)} ${r.label.padEnd(24)} ${r.file}`);
723
+ }
724
+ console.log('\nrun "reevesagents skills install" to (re)install.');
725
+ return;
726
+ }
727
+ throw new Error(`unknown action: ${verb} (use status, install, or remove)`);
728
+ } catch (err) {
729
+ console.error(err instanceof Error ? err.message : String(err));
730
+ process.exit(1);
731
+ }
732
+ });
733
+ }
734
+ function registerDoctor(program2) {
735
+ program2.command("doctor").description("run setup and environment health checks").option("--json", "output JSON").action((opts) => {
736
+ const result = runDoctor();
737
+ const anyFail = result.checks.some((check) => check.status === "fail");
738
+ if (opts.json) {
739
+ console.log(JSON.stringify({ ok: !anyFail, checks: result.checks }, null, 2));
740
+ } else {
741
+ for (const check of result.checks) {
742
+ console.log(`${check.status.toUpperCase().padEnd(4)} ${check.name.padEnd(14)} ${check.detail}`);
743
+ }
744
+ }
745
+ process.exit(anyFail ? 1 : 0);
746
+ });
747
+ }
748
+
749
+ // src/surfaces/cli/hosts.ts
750
+ function registerHosts(program2) {
751
+ program2.command("hosts").description("list MCP host CLIs and whether reevesagents is attached").option("--json", "output JSON array").action((opts) => {
752
+ const hosts = hostStatus();
753
+ if (opts.json) {
754
+ console.log(JSON.stringify(hosts, null, 2));
661
755
  return;
662
756
  }
663
- for (const result of results) {
664
- console.log(`${(result.ok ? "ok" : "--").padEnd(3)} ${result.key.padEnd(10)} ${result.message}`);
757
+ for (const host of hosts) {
758
+ const state = !host.installed ? "absent" : host.attached ? "attached" : host.manual ? "manual" : "detached";
759
+ console.log(`${host.key.padEnd(10)} ${state.padEnd(9)} ${host.label}`);
665
760
  }
666
- const attached = results.filter((result) => result.ok);
667
- if (attached.length > 0) {
668
- const verify = await verifyServerLaunch();
669
- if (verify.ok) {
670
- console.log(`
761
+ });
762
+ }
763
+ function registerAttach(program2) {
764
+ program2.command("attach [cli]").description("attach the reevesagents MCP to one CLI, or all installed when omitted").option("--force", "rewrite the registration even if already attached (upgrades an old launcher)").action(async (cli, opts) => {
765
+ try {
766
+ const results = cli ? [attach(cli, opts.force)] : attachAll(opts.force);
767
+ if (results.length === 0) {
768
+ console.log("no MCP-capable CLI is installed here.");
769
+ console.log('Install a host CLI (for example Claude Code or Codex) and sign in, then run "reevesagents attach" again.');
770
+ process.exitCode = 1;
771
+ return;
772
+ }
773
+ for (const result of results) {
774
+ console.log(`${(result.ok ? "ok" : "--").padEnd(3)} ${result.key.padEnd(10)} ${result.message}`);
775
+ }
776
+ const attached = results.filter((result) => result.ok);
777
+ if (attached.length > 0) {
778
+ const verify = await verifyServerLaunch();
779
+ if (verify.ok) {
780
+ console.log(`
671
781
  verified: ${verify.detail}.`);
672
- console.log(`restart ${attached.map((result) => result.key).join(", ")} (start a new session) to load the tools,`);
673
- const available = detectAvailable();
674
- console.log(`then ask it: "${suggestedAgentPrompt(PROVIDERS.filter((provider) => available[provider]))}".`);
675
- } else {
676
- console.log(`
782
+ console.log(`restart ${attached.map((result) => result.key).join(", ")} (start a new session) to load the tools,`);
783
+ const available = detectAvailable();
784
+ console.log(`then ask it: "${suggestedAgentPrompt(PROVIDERS.filter((provider) => available[provider]))}".`);
785
+ } else {
786
+ console.log(`
677
787
  warning: the entry was written, but the server did not start here: ${verify.detail}`);
678
- console.log("a host CLI will hit the same error. check that reevesagents is installed and re-run attach.");
788
+ console.log("a host CLI will hit the same error. check that reevesagents is installed and re-run attach.");
789
+ process.exitCode = 1;
790
+ }
791
+ } else {
679
792
  process.exitCode = 1;
680
793
  }
681
- } else {
682
- process.exitCode = 1;
794
+ } catch (err) {
795
+ console.error(err instanceof Error ? err.message : String(err));
796
+ process.exit(1);
683
797
  }
684
- } catch (err) {
685
- console.error(err instanceof Error ? err.message : String(err));
686
- process.exit(1);
687
- }
688
- });
689
- program.command("detach <cli>").description("detach the reevesagents MCP from one CLI").action((cli) => {
690
- try {
691
- const result = detach(cli);
692
- console.log(`${(result.ok ? "ok" : "--").padEnd(3)} ${result.key.padEnd(10)} ${result.message}`);
693
- if (!result.ok) process.exitCode = 1;
694
- } catch (err) {
695
- console.error(err instanceof Error ? err.message : String(err));
696
- process.exit(1);
697
- }
698
- });
699
- program.command("skills [action]").description("install the reevesagents skill for skill-aware CLIs (action: status, install, remove)").option("--json", "output JSON").action((action, opts) => {
700
- const verb = action ?? "status";
701
- try {
702
- if (verb === "install") {
703
- const results = installSkills();
704
- if (opts.json) {
705
- console.log(JSON.stringify(results, null, 2));
798
+ });
799
+ }
800
+ function registerDetach(program2) {
801
+ program2.command("detach <cli>").description("detach the reevesagents MCP from one CLI").action((cli) => {
802
+ try {
803
+ const result = detach(cli);
804
+ console.log(`${(result.ok ? "ok" : "--").padEnd(3)} ${result.key.padEnd(10)} ${result.message}`);
805
+ if (!result.ok) process.exitCode = 1;
806
+ } catch (err) {
807
+ console.error(err instanceof Error ? err.message : String(err));
808
+ process.exit(1);
809
+ }
810
+ });
811
+ }
812
+ function registerMcp(program2) {
813
+ program2.command("mcp").description("start the agent control MCP server over stdio (for CLIs that have it attached)").action(async () => {
814
+ try {
815
+ const { startAgentMcpServer } = await import("./server-NREXCROR.js");
816
+ await startAgentMcpServer();
817
+ } catch (err) {
818
+ console.error(err instanceof Error ? err.message : String(err));
819
+ process.exit(1);
820
+ }
821
+ });
822
+ }
823
+
824
+ // src/surfaces/cli/config.ts
825
+ function registerConfig(program2) {
826
+ program2.command("config [key] [value]").description(`show config, get one value, or set one (keys: ${CONFIG_FIELDS.map((field) => field.key).join(", ")})`).option("--json", "output JSON for show or get").action((key, value, opts) => {
827
+ try {
828
+ if (key !== void 0 && value !== void 0) {
829
+ const cfg2 = setConfigValues({ [key]: parseConfigValue(key, value) });
830
+ const saved = cfg2.global;
831
+ console.log(`${key} = ${String(saved[key])}`);
706
832
  return;
707
833
  }
708
- for (const r of results) console.log(`${(r.ok ? "ok" : "--").padEnd(3)} ${r.label.padEnd(24)} ${r.file}`);
709
- console.log("\nrestart your CLIs to pick up the skill.");
710
- if (results.some((r) => !r.ok)) process.exitCode = 1;
711
- return;
712
- }
713
- if (verb === "remove") {
714
- const results = removeSkills();
715
- if (opts.json) {
716
- console.log(JSON.stringify(results, null, 2));
834
+ const cfg = loadConfig();
835
+ const global = cfg.global;
836
+ if (key !== void 0) {
837
+ if (!CONFIG_FIELDS.some((field) => field.key === key)) throw new Error(`unknown config field: ${key}`);
838
+ console.log(opts.json ? JSON.stringify(global[key]) : String(global[key]));
717
839
  return;
718
840
  }
719
- for (const r of results) console.log(`${(r.ok ? "ok" : "--").padEnd(3)} ${r.label.padEnd(24)} ${r.message}`);
720
- if (results.some((r) => !r.ok)) process.exitCode = 1;
721
- return;
722
- }
723
- if (verb === "status") {
724
- const rows = skillsStatus();
725
841
  if (opts.json) {
726
- console.log(JSON.stringify(rows, null, 2));
842
+ console.log(JSON.stringify(cfg.global, null, 2));
727
843
  return;
728
844
  }
729
- for (const r of rows) {
730
- const state = !r.present ? "absent" : r.current ? "installed" : "outdated";
731
- console.log(`${state.padEnd(10)} ${r.label.padEnd(24)} ${r.file}`);
845
+ for (const field of CONFIG_FIELDS) {
846
+ console.log(`${field.key.padEnd(20)} ${String(global[field.key])}`);
732
847
  }
733
- console.log('\nrun "reevesagents skills install" to (re)install.');
734
- return;
735
- }
736
- throw new Error(`unknown action: ${verb} (use status, install, or remove)`);
737
- } catch (err) {
738
- console.error(err instanceof Error ? err.message : String(err));
739
- process.exit(1);
740
- }
741
- });
742
- program.command("doctor").description("run setup and environment health checks").option("--json", "output JSON").action((opts) => {
743
- const result = runDoctor();
744
- const anyFail = result.checks.some((check) => check.status === "fail");
745
- if (opts.json) {
746
- console.log(JSON.stringify({ ok: !anyFail, checks: result.checks }, null, 2));
747
- } else {
748
- for (const check of result.checks) {
749
- console.log(`${check.status.toUpperCase().padEnd(4)} ${check.name.padEnd(14)} ${check.detail}`);
848
+ } catch (err) {
849
+ console.error(err instanceof Error ? err.message : String(err));
850
+ process.exit(1);
750
851
  }
751
- }
752
- process.exit(anyFail ? 1 : 0);
753
- });
754
- program.command("agents [run-id]").description("list agents, optionally only those in one run").option("--json", "output JSON array").action((runId, opts) => {
755
- try {
756
- const run = runId ? resolveRun(runId) : void 0;
757
- const agents = listAgents(run?.id);
852
+ });
853
+ }
854
+
855
+ // src/surfaces/cli/presets.ts
856
+ function registerPresets(program2) {
857
+ program2.command("presets").description("list saved presets").option("--json", "output JSON array").action((opts) => {
858
+ const presets = listPresets();
758
859
  if (opts.json) {
759
- console.log(JSON.stringify(agents, null, 2));
860
+ console.log(JSON.stringify(presets, null, 2));
760
861
  return;
761
862
  }
762
- if (agents.length === 0) {
763
- console.log("no agents");
863
+ if (presets.length === 0) {
864
+ console.log("no presets");
764
865
  return;
765
866
  }
766
- for (const agent of agents) {
767
- const note = agent.task_note.trim();
768
- console.log(`${agent.id.slice(0, 8)} ${agent.run_id.slice(0, 8)} ${agent.role.padEnd(6)} ${agent.task_status.padEnd(7)} ${providerDisplayName(agent.provider).padEnd(14)} ${(agent.model || "default").padEnd(16)} ${agent.nickname}${note ? ` ${note}` : ""}`);
867
+ for (const preset of presets) {
868
+ console.log(`${preset.name.padEnd(24)} ${String(1 + preset.workers.length).padStart(2)} agents ${preset.description}`);
769
869
  }
770
- } catch (err) {
771
- console.error(err instanceof Error ? err.message : String(err));
772
- process.exit(1);
773
- }
774
- });
775
- program.command("config [key] [value]").description(`show config, get one value, or set one (keys: ${CONFIG_FIELDS.map((field) => field.key).join(", ")})`).option("--json", "output JSON for show or get").action((key, value, opts) => {
776
- try {
777
- if (key !== void 0 && value !== void 0) {
778
- const cfg2 = setConfigValues({ [key]: parseConfigValue(key, value) });
779
- const saved = cfg2.global;
780
- console.log(`${key} = ${String(saved[key])}`);
781
- return;
782
- }
783
- const cfg = loadConfig();
784
- const global = cfg.global;
785
- if (key !== void 0) {
786
- if (!CONFIG_FIELDS.some((field) => field.key === key)) throw new Error(`unknown config field: ${key}`);
787
- console.log(opts.json ? JSON.stringify(global[key]) : String(global[key]));
788
- return;
789
- }
790
- if (opts.json) {
791
- console.log(JSON.stringify(cfg.global, null, 2));
792
- return;
793
- }
794
- for (const field of CONFIG_FIELDS) {
795
- console.log(`${field.key.padEnd(20)} ${String(global[field.key])}`);
870
+ });
871
+ }
872
+ function registerSavePreset(program2) {
873
+ program2.command("save-preset <run-id> <name> [description...]").description("save a run as a reusable preset").action((runId, name, description) => {
874
+ try {
875
+ const run = resolveRun(runId);
876
+ const tree = savePresetFromRun(run.id, name, description.join(" "));
877
+ console.log(`saved preset ${tree.name} ${1 + tree.workers.length} agents`);
878
+ } catch (err) {
879
+ console.error(err instanceof Error ? err.message : String(err));
880
+ process.exit(1);
796
881
  }
797
- } catch (err) {
798
- console.error(err instanceof Error ? err.message : String(err));
799
- process.exit(1);
800
- }
801
- });
802
- program.command("presets").description("list saved presets").option("--json", "output JSON array").action((opts) => {
803
- const presets = listPresets();
804
- if (opts.json) {
805
- console.log(JSON.stringify(presets, null, 2));
806
- return;
807
- }
808
- if (presets.length === 0) {
809
- console.log("no presets");
810
- return;
811
- }
812
- for (const preset of presets) {
813
- console.log(`${preset.name.padEnd(24)} ${String(1 + preset.workers.length).padStart(2)} agents ${preset.description}`);
814
- }
815
- });
816
- program.command("save-preset <run-id> <name> [description...]").description("save a run as a reusable preset").action((runId, name, description) => {
817
- try {
818
- const run = resolveRun(runId);
819
- const tree = savePresetFromRun(run.id, name, description.join(" "));
820
- console.log(`saved preset ${tree.name} ${1 + tree.workers.length} agents`);
821
- } catch (err) {
822
- console.error(err instanceof Error ? err.message : String(err));
823
- process.exit(1);
824
- }
825
- });
826
- program.command("delete-preset <name>").description("delete a saved preset").option("-y, --yes", "confirm delete").action((name, opts) => {
827
- requireDestructiveConfirmation(opts, "delete preset");
828
- if (!listPresets().some((preset) => preset.name === name)) throw new Error(`preset not found: ${name}`);
829
- deletePreset(name);
830
- console.log(`deleted preset ${name}`);
831
- });
832
- program.command("start-preset <name>").description("start a run from a saved preset").option("--name <name>", "override the run name").option("--cwd <dir>", "working directory", process.cwd()).action((name, opts) => {
833
- try {
882
+ });
883
+ }
884
+ function registerDeletePreset(program2) {
885
+ program2.command("delete-preset <name>").description("delete a saved preset").option("-y, --yes", "confirm delete").action((name, opts) => {
886
+ requireDestructiveConfirmation(opts, "delete preset");
834
887
  if (!listPresets().some((preset) => preset.name === name)) throw new Error(`preset not found: ${name}`);
835
- const result = startRunFromPreset(name, { name: opts.name, working_dir: opts.cwd });
836
- console.log(`started ${result.run.id.slice(0, 8)} ${result.run.name} ${result.agents.length} agents`);
837
- } catch (err) {
838
- console.error(err instanceof Error ? err.message : String(err));
839
- process.exit(1);
840
- }
841
- });
842
- program.command("web").description("start the on-demand loopback web UI for agents").option("--port <n>", "preferred port; falls back to the next free port").option("--no-open", "do not open the browser").action((opts) => {
843
- runWeb(opts).catch((err) => {
844
- console.error(err instanceof Error ? err.message : String(err));
845
- process.exit(1);
888
+ deletePreset(name);
889
+ console.log(`deleted preset ${name}`);
846
890
  });
847
- });
848
- program.command("mcp").description("start the agent control MCP server over stdio (for CLIs that have it attached)").action(async () => {
849
- try {
850
- const { startAgentMcpServer } = await import("./server-KTPEQQRJ.js");
851
- await startAgentMcpServer();
852
- } catch (err) {
853
- console.error(err instanceof Error ? err.message : String(err));
854
- process.exit(1);
855
- }
856
- });
891
+ }
892
+ function registerStartPreset(program2) {
893
+ program2.command("start-preset <name>").description("start a run from a saved preset").option("--name <name>", "override the run name").option("--cwd <dir>", "working directory", process.cwd()).action((name, opts) => {
894
+ try {
895
+ if (!listPresets().some((preset) => preset.name === name)) throw new Error(`preset not found: ${name}`);
896
+ const result = startRunFromPreset(name, { name: opts.name, working_dir: opts.cwd });
897
+ console.log(`started ${result.run.id.slice(0, 8)} ${result.run.name} ${result.agents.length} agents`);
898
+ } catch (err) {
899
+ console.error(err instanceof Error ? err.message : String(err));
900
+ process.exit(1);
901
+ }
902
+ });
903
+ }
904
+
905
+ // src/surfaces/cli/web.ts
857
906
  async function runWeb(opts) {
858
- const { checkWebExtras, webExtrasMessage } = await import("./extras-25AF6TAR.js");
907
+ const { checkWebExtras, webExtrasMessage } = await import("./extras-MWGWGEPB.js");
859
908
  const extras = await checkWebExtras();
860
909
  if (!extras.ok) {
861
910
  console.error(webExtrasMessage(extras.missing));
862
911
  process.exit(1);
863
912
  }
864
- const { startWebServer } = await import("./server-VR6AHRBE.js");
913
+ const { startWebServer } = await import("./server-Y2IEANCZ.js");
865
914
  const parsed = opts.port ? Number.parseInt(opts.port, 10) : void 0;
866
915
  const handle = await startWebServer({
867
916
  port: parsed !== void 0 && Number.isFinite(parsed) ? parsed : void 0,
@@ -875,17 +924,69 @@ async function runWeb(opts) {
875
924
  process.on("SIGINT", shutdown);
876
925
  process.on("SIGTERM", shutdown);
877
926
  }
927
+ function registerWeb(program2) {
928
+ program2.command("web").description("start the on-demand loopback web UI for agents").option("--port <n>", "preferred port; falls back to the next free port").option("--no-open", "do not open the browser").action((opts) => {
929
+ runWeb(opts).catch((err) => {
930
+ console.error(err instanceof Error ? err.message : String(err));
931
+ process.exit(1);
932
+ });
933
+ });
934
+ }
935
+
936
+ // src/surfaces/cli/index.ts
937
+ var program = new Command();
938
+ program.name("reevesagents").description("local tmux-first workspace manager for AI CLI agents").version(REEVESAGENTS_VERSION).addHelpText("after", `
939
+ First steps:
940
+ reevesagents doctor check tmux, Node, and which provider CLIs are installed
941
+ reevesagents providers list provider ids and aliases you can spawn
942
+ reevesagents spawn --help agent spec syntax and a multi-agent example
943
+
944
+ Let one agent drive others: "reevesagents attach <cli>" gives that CLI the
945
+ agent-control tools (spawn, send, read, stop) over MCP. Full agent guide: AGENTS.md.`);
946
+ registerSpawn(program);
947
+ registerAdd(program);
948
+ registerRuns(program);
949
+ registerReap(program);
950
+ registerOpen(program);
951
+ registerPeek(program);
952
+ registerStop(program);
953
+ registerKill(program);
954
+ registerSend(program);
955
+ registerKey(program);
956
+ registerInterrupt(program);
957
+ registerDelete(program);
958
+ registerDeleteRun(program);
959
+ registerHistory(program);
960
+ registerDeleteHistory(program);
961
+ registerProviders(program);
962
+ registerApprovals(program);
963
+ registerApprove(program);
964
+ registerDeny(program);
965
+ registerSetup(program);
966
+ registerHosts(program);
967
+ registerAttach(program);
968
+ registerDetach(program);
969
+ registerSkills(program);
970
+ registerDoctor(program);
971
+ registerAgents(program);
972
+ registerConfig(program);
973
+ registerPresets(program);
974
+ registerSavePreset(program);
975
+ registerDeletePreset(program);
976
+ registerStartPreset(program);
977
+ registerWeb(program);
978
+ registerMcp(program);
878
979
  async function renderTui() {
879
980
  prepareTuiColorEnv();
880
981
  const [{ default: React }, { render }, { Router }] = await Promise.all([
881
982
  import("react"),
882
983
  import("ink"),
883
- import("./router-Q2JZ7NEX.js")
984
+ import("./router-KMZQ52T2.js")
884
985
  ]);
885
986
  try {
886
987
  await render(React.createElement(Router), { alternateScreen: false }).waitUntilExit();
887
988
  } finally {
888
- const { closeTuiWebServer } = await import("./tui-launch-JTZU3RFS.js");
989
+ const { closeTuiWebServer } = await import("./tui-launch-ESUQ7SYU.js");
889
990
  await closeTuiWebServer();
890
991
  }
891
992
  process.exit(0);
@@ -938,7 +1039,6 @@ function isEntrypoint() {
938
1039
  }
939
1040
  if (isEntrypoint()) runCli();
940
1041
  export {
941
- program,
942
- tuiNewWindowArgs
1042
+ program
943
1043
  };
944
1044
  //# sourceMappingURL=cli.js.map