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/CHANGELOG.md +14 -0
- package/README.md +191 -352
- package/dist/{chunk-FL3LI2MU.js → chunk-CFDTC6GY.js} +8 -8
- package/dist/{chunk-QMRLJAEV.js → chunk-HIJYVPYH.js} +2 -2
- package/dist/{chunk-EA6OGFOE.js → chunk-LXZNX6EJ.js} +5 -5
- package/dist/{chunk-CE6YASBF.js → chunk-PDJ2CPVO.js} +1342 -1381
- package/dist/{chunk-D24DQQ6V.js → chunk-Q3WWQP2R.js} +2 -2
- package/dist/{chunk-SFF7SYI6.js → chunk-TIDTHK3L.js} +16 -16
- package/dist/{chunk-NKT6GFCD.js → chunk-UH6K25MG.js} +16 -16
- package/dist/{chunk-TUYP7APK.js → chunk-X6EBVSC7.js} +25 -25
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +685 -585
- package/dist/{extras-25AF6TAR.js → extras-MWGWGEPB.js} +2 -2
- package/dist/index.d.ts +25 -23
- package/dist/index.js +3 -3
- package/dist/{open-browser-DRSIJQ37.js → open-browser-IQ5MTCWZ.js} +2 -2
- package/dist/{router-Q2JZ7NEX.js → router-KMZQ52T2.js} +164 -97
- package/dist/{server-KTPEQQRJ.js → server-NREXCROR.js} +8 -9
- package/dist/{server-VR6AHRBE.js → server-Y2IEANCZ.js} +18 -24
- package/dist/{tui-launch-JTZU3RFS.js → tui-launch-ESUQ7SYU.js} +2 -2
- package/package.json +17 -11
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
WEB_EXTRA_MODULES
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-Q3WWQP2R.js";
|
|
5
5
|
|
|
6
6
|
// src/core/model-data.ts
|
|
7
7
|
var CC_MODEL_SOURCE = "curated Claude Code aliases";
|
|
@@ -423,142 +423,6 @@ ${inspected.stderr ?? ""}`;
|
|
|
423
423
|
return result;
|
|
424
424
|
}
|
|
425
425
|
|
|
426
|
-
// src/utils/tokens.ts
|
|
427
|
-
var colors = {
|
|
428
|
-
text: {
|
|
429
|
-
primary: "#ece7dc",
|
|
430
|
-
// body text
|
|
431
|
-
dim: "#b8b0a3",
|
|
432
|
-
// labels, secondary text
|
|
433
|
-
muted: "#817b70",
|
|
434
|
-
// tertiary text, divider labels
|
|
435
|
-
faint: "#55504a",
|
|
436
|
-
// disabled, dashed border edges
|
|
437
|
-
subtle: "#292622"
|
|
438
|
-
// near-background tints
|
|
439
|
-
},
|
|
440
|
-
accent: {
|
|
441
|
-
bright: "#7eb8f5",
|
|
442
|
-
// selection cursor, focused text, current breadcrumb
|
|
443
|
-
primary: "#5a96e0",
|
|
444
|
-
// panel titles, links, emphasis
|
|
445
|
-
deep: "#4a6fa5",
|
|
446
|
-
// inactive panel borders
|
|
447
|
-
ink: "#1e2d3e"
|
|
448
|
-
// selected button fill
|
|
449
|
-
},
|
|
450
|
-
surface: {
|
|
451
|
-
selected: "#1e2d3e",
|
|
452
|
-
// selected action fill
|
|
453
|
-
rail: "#314253",
|
|
454
|
-
// card rails and active separators
|
|
455
|
-
border: "#3a4b5f",
|
|
456
|
-
// card border strokes
|
|
457
|
-
quiet: "#36383d"
|
|
458
|
-
// outer rules
|
|
459
|
-
},
|
|
460
|
-
status: {
|
|
461
|
-
ok: "#83a36f",
|
|
462
|
-
// running, ok, approved
|
|
463
|
-
warn: "#d7a84f",
|
|
464
|
-
// stale, blocked, warn
|
|
465
|
-
error: "#d56a60",
|
|
466
|
-
// failed, denied, fail
|
|
467
|
-
info: "#7fb4d6"
|
|
468
|
-
// neutral info
|
|
469
|
-
},
|
|
470
|
-
brand: {
|
|
471
|
-
blue: "#3a7ad8",
|
|
472
|
-
// wordmark base
|
|
473
|
-
pale: "#a5cdf7",
|
|
474
|
-
// wordmark highlight
|
|
475
|
-
gradient: ["#a5cdf7", "#7eb8f5", "#5a96e0", "#3a7ad8", "#2457a7"]
|
|
476
|
-
// breath cycle
|
|
477
|
-
},
|
|
478
|
-
// Provider brand colors live with each provider in the registry
|
|
479
|
-
// (launcher/provider-registry.ts); read them through providerColor() in
|
|
480
|
-
// utils/display.ts. They are kept distinct from accent.bright so a focused
|
|
481
|
-
// provider row does not collide visually with the selection cursor.
|
|
482
|
-
model: {
|
|
483
|
-
default: "#9b9488",
|
|
484
|
-
// CLI default or unset model
|
|
485
|
-
claude: "#e0a06f",
|
|
486
|
-
// Claude family
|
|
487
|
-
openai: "#72b7d6",
|
|
488
|
-
// OpenAI family
|
|
489
|
-
deepseek: "#7ac8bc",
|
|
490
|
-
// DeepSeek family
|
|
491
|
-
qwen: "#d1a25d",
|
|
492
|
-
// Qwen family
|
|
493
|
-
kimi: "#d0c268",
|
|
494
|
-
// Kimi family
|
|
495
|
-
local: "#92b37a",
|
|
496
|
-
// local/open model family
|
|
497
|
-
other: "#9ca8bd"
|
|
498
|
-
// known provider, unclassified model
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
var sep = {
|
|
502
|
-
dot: " \xB7 ",
|
|
503
|
-
pipe: " \u2502 ",
|
|
504
|
-
arr: " \u2192 "
|
|
505
|
-
};
|
|
506
|
-
var space = {
|
|
507
|
-
none: 0,
|
|
508
|
-
sm: 1,
|
|
509
|
-
md: 2,
|
|
510
|
-
lg: 3
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
// src/utils/display.ts
|
|
514
|
-
var PROVIDER_DISPLAY_NAMES = Object.fromEntries(
|
|
515
|
-
PROVIDER_DEFS.map((def) => [def.id, def.displayName])
|
|
516
|
-
);
|
|
517
|
-
function providerDisplayName(provider) {
|
|
518
|
-
return PROVIDER_DISPLAY_NAMES[provider] ?? provider;
|
|
519
|
-
}
|
|
520
|
-
function providerColor(p) {
|
|
521
|
-
return PROVIDER_REGISTRY[p]?.color ?? "gray";
|
|
522
|
-
}
|
|
523
|
-
function modelColor(model, provider) {
|
|
524
|
-
const lower = model.trim().toLowerCase();
|
|
525
|
-
if (!lower) return colors.model.default;
|
|
526
|
-
if (lower.includes("claude") || lower.includes("sonnet") || lower.includes("opus") || lower.includes("haiku")) return colors.model.claude;
|
|
527
|
-
if (lower.includes("gpt") || lower.includes("codex") || /\bo[134]\b/.test(lower)) return colors.model.openai;
|
|
528
|
-
if (lower.includes("deepseek")) return colors.model.deepseek;
|
|
529
|
-
if (lower.includes("qwen")) return colors.model.qwen;
|
|
530
|
-
if (lower.includes("kimi") || lower.includes("moonshot")) return colors.model.kimi;
|
|
531
|
-
if (lower.includes("llama") || lower.includes("mistral") || lower.includes("mixtral") || lower.includes("ollama") || lower.includes("lmstudio") || lower.includes("local")) return colors.model.local;
|
|
532
|
-
if (provider === "cc") return colors.model.claude;
|
|
533
|
-
if (provider === "codex") return colors.model.openai;
|
|
534
|
-
if (provider === "deepseek") return colors.model.deepseek;
|
|
535
|
-
if (provider === "qwen") return colors.model.qwen;
|
|
536
|
-
if (provider === "kimi") return colors.model.kimi;
|
|
537
|
-
return colors.model.other;
|
|
538
|
-
}
|
|
539
|
-
function modelBadgeLabel(model) {
|
|
540
|
-
const value = model.trim();
|
|
541
|
-
if (!value) return "default";
|
|
542
|
-
const slashIdx = value.lastIndexOf("/");
|
|
543
|
-
const label = slashIdx >= 0 && slashIdx < value.length - 1 ? value.slice(slashIdx + 1) : value;
|
|
544
|
-
return truncateLabel(label, 24);
|
|
545
|
-
}
|
|
546
|
-
function truncateLabel(label, max) {
|
|
547
|
-
if (label.length <= max) return label;
|
|
548
|
-
return `${label.slice(0, Math.max(1, max - 3))}...`;
|
|
549
|
-
}
|
|
550
|
-
var SECRET_PATTERNS = [
|
|
551
|
-
/sk-ant-[A-Za-z0-9\-_]{20,}/g,
|
|
552
|
-
/sk-[A-Za-z0-9\-_]{20,}/g,
|
|
553
|
-
/AIza[A-Za-z0-9\-_]{35}/g,
|
|
554
|
-
/gsk_[A-Za-z0-9\-_]{20,}/g
|
|
555
|
-
];
|
|
556
|
-
function redactSecrets(text) {
|
|
557
|
-
let result = text;
|
|
558
|
-
for (const pattern of SECRET_PATTERNS) result = result.replace(pattern, "[REDACTED]");
|
|
559
|
-
return result;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
426
|
// src/core/runs.ts
|
|
563
427
|
import {
|
|
564
428
|
chmodSync,
|
|
@@ -577,7 +441,108 @@ import {
|
|
|
577
441
|
import { randomUUID } from "crypto";
|
|
578
442
|
import { homedir } from "os";
|
|
579
443
|
import { dirname, join } from "path";
|
|
580
|
-
|
|
444
|
+
|
|
445
|
+
// src/core/redact.ts
|
|
446
|
+
var SECRET_PATTERNS = [
|
|
447
|
+
/sk-ant-[A-Za-z0-9\-_]{20,}/g,
|
|
448
|
+
/sk-[A-Za-z0-9\-_]{20,}/g,
|
|
449
|
+
/AIza[A-Za-z0-9\-_]{35}/g,
|
|
450
|
+
/gsk_[A-Za-z0-9\-_]{20,}/g
|
|
451
|
+
];
|
|
452
|
+
function redactSecrets(text) {
|
|
453
|
+
let result = text;
|
|
454
|
+
for (const pattern of SECRET_PATTERNS) result = result.replace(pattern, "[REDACTED]");
|
|
455
|
+
return result;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// src/core/tmux.ts
|
|
459
|
+
import { execFileSync as execFileSync2, spawnSync as spawnSync2 } from "child_process";
|
|
460
|
+
var realDriver = {
|
|
461
|
+
tmux(args, input) {
|
|
462
|
+
return execFileSync2("tmux", args, {
|
|
463
|
+
encoding: "utf8",
|
|
464
|
+
input,
|
|
465
|
+
stdio: input === void 0 ? ["ignore", "pipe", "pipe"] : ["pipe", "pipe", "pipe"]
|
|
466
|
+
}).trim();
|
|
467
|
+
},
|
|
468
|
+
delay(fn, ms) {
|
|
469
|
+
setTimeout(fn, ms);
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
var STALE_WINDOW_ERROR = "agent window no longer exists (tmux server may have restarted)";
|
|
473
|
+
function exactSession(session) {
|
|
474
|
+
return `=${session}`;
|
|
475
|
+
}
|
|
476
|
+
function tmuxAvailable() {
|
|
477
|
+
try {
|
|
478
|
+
const result = spawnSync2("tmux", ["-V"], { stdio: "ignore" });
|
|
479
|
+
return result.status === 0;
|
|
480
|
+
} catch {
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
function tmuxVersion() {
|
|
485
|
+
try {
|
|
486
|
+
return execFileSync2("tmux", ["-V"], { encoding: "utf8" }).trim();
|
|
487
|
+
} catch {
|
|
488
|
+
return null;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
function sessionExists(session) {
|
|
492
|
+
if (!session) return false;
|
|
493
|
+
try {
|
|
494
|
+
const result = spawnSync2("tmux", ["has-session", "-t", exactSession(session)], { stdio: "ignore" });
|
|
495
|
+
return result.status === 0;
|
|
496
|
+
} catch {
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function targetExists(target, session) {
|
|
501
|
+
if (!target || !session) return false;
|
|
502
|
+
try {
|
|
503
|
+
const args = target.startsWith("%") ? ["list-panes", "-s", "-t", exactSession(session), "-F", "#{pane_id}"] : ["list-windows", "-t", exactSession(session), "-F", "#{window_id}"];
|
|
504
|
+
const result = spawnSync2("tmux", args, { encoding: "utf8" });
|
|
505
|
+
return result.status === 0 && result.stdout.split("\n").some((line) => line.trim() === target);
|
|
506
|
+
} catch {
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
function windowIds(session) {
|
|
511
|
+
try {
|
|
512
|
+
return execFileSync2("tmux", ["list-windows", "-t", exactSession(session), "-F", "#{window_id}"], { encoding: "utf8" }).split("\n").map((line) => line.trim()).filter(Boolean);
|
|
513
|
+
} catch {
|
|
514
|
+
return [];
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function windowByName(session, name) {
|
|
518
|
+
try {
|
|
519
|
+
const rows = execFileSync2("tmux", ["list-windows", "-t", exactSession(session), "-F", "#{window_id} #{window_name} #{pane_current_command}"], { encoding: "utf8" }).split("\n").map((line) => line.trim()).filter(Boolean);
|
|
520
|
+
for (const row of rows) {
|
|
521
|
+
const [windowId, windowName, command = ""] = row.split(" ");
|
|
522
|
+
if (windowId && windowName === name) return { id: windowId, command };
|
|
523
|
+
}
|
|
524
|
+
} catch {
|
|
525
|
+
}
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
function windowInSession(driver, session, windowId) {
|
|
529
|
+
if (!session || !windowId) return false;
|
|
530
|
+
try {
|
|
531
|
+
return driver.tmux(["list-windows", "-t", exactSession(session), "-F", "#{window_id}"]).split("\n").some((line) => line.trim() === windowId);
|
|
532
|
+
} catch {
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
function paneInSession(driver, session, paneId) {
|
|
537
|
+
if (!session || !paneId) return false;
|
|
538
|
+
try {
|
|
539
|
+
return driver.tmux(["list-panes", "-s", "-t", exactSession(session), "-F", "#{pane_id}"]).split("\n").some((line) => line.trim() === paneId);
|
|
540
|
+
} catch {
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// src/core/runs.ts
|
|
581
546
|
function stateRoot() {
|
|
582
547
|
return process.env.REEVES_REGISTRY || join(homedir(), ".reeves");
|
|
583
548
|
}
|
|
@@ -944,52 +909,25 @@ function findAgent(agentId) {
|
|
|
944
909
|
}
|
|
945
910
|
throw new Error(`Agent not found: ${agentId}`);
|
|
946
911
|
}
|
|
947
|
-
function defaultTmuxSessionExists(session) {
|
|
948
|
-
if (!session) return false;
|
|
949
|
-
try {
|
|
950
|
-
const result = spawnSync2("tmux", ["has-session", "-t", `=${session}`], { stdio: "ignore" });
|
|
951
|
-
return result.status === 0;
|
|
952
|
-
} catch {
|
|
953
|
-
return false;
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
function defaultTmuxAvailable() {
|
|
957
|
-
try {
|
|
958
|
-
const result = spawnSync2("tmux", ["-V"], { stdio: "ignore" });
|
|
959
|
-
return result.status === 0;
|
|
960
|
-
} catch {
|
|
961
|
-
return false;
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
function defaultTmuxTargetExists(target, session) {
|
|
965
|
-
if (!target || !session) return false;
|
|
966
|
-
try {
|
|
967
|
-
const args = target.startsWith("%") ? ["list-panes", "-s", "-t", `=${session}`, "-F", "#{pane_id}"] : ["list-windows", "-t", `=${session}`, "-F", "#{window_id}"];
|
|
968
|
-
const result = spawnSync2("tmux", args, { encoding: "utf8" });
|
|
969
|
-
return result.status === 0 && result.stdout.split("\n").some((line) => line.trim() === target);
|
|
970
|
-
} catch {
|
|
971
|
-
return false;
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
912
|
function runHasLiveTmuxTarget(run, options = {}) {
|
|
975
|
-
const
|
|
976
|
-
const
|
|
913
|
+
const targetExists2 = options.targetExists ?? targetExists;
|
|
914
|
+
const sessionExists2 = options.sessionExists ?? sessionExists;
|
|
977
915
|
const agents = listAgents(run.id).filter((agent) => !agent.ended_at);
|
|
978
916
|
const windowedAgents = agents.filter((agent) => !agent.headless && agent.tmux_window_id);
|
|
979
|
-
if (windowedAgents.length > 0) return windowedAgents.some((agent) =>
|
|
980
|
-
return
|
|
917
|
+
if (windowedAgents.length > 0) return windowedAgents.some((agent) => targetExists2(agent.tmux_window_id, agent.tmux_session));
|
|
918
|
+
return sessionExists2(run.tmux_session);
|
|
981
919
|
}
|
|
982
920
|
function autoCleanupRuns(options = {}) {
|
|
983
|
-
const
|
|
984
|
-
const
|
|
985
|
-
const
|
|
986
|
-
const haveTmux = options.cleanStale === false ? false :
|
|
921
|
+
const sessionExists2 = options.sessionExists ?? sessionExists;
|
|
922
|
+
const targetExists2 = options.targetExists ?? targetExists;
|
|
923
|
+
const tmuxAvailable2 = options.sessionExists || options.targetExists ? () => true : options.tmuxAvailable ?? tmuxAvailable;
|
|
924
|
+
const haveTmux = options.cleanStale === false ? false : tmuxAvailable2();
|
|
987
925
|
const removed = [];
|
|
988
926
|
const archived = [];
|
|
989
927
|
const runs = listRunsUnlocked(true);
|
|
990
928
|
for (const run of runs) {
|
|
991
929
|
const isEnded = isRunEnded(run);
|
|
992
|
-
const isStale = !isEnded && haveTmux && !runHasLiveTmuxTarget(run, { sessionExists, targetExists });
|
|
930
|
+
const isStale = !isEnded && haveTmux && !runHasLiveTmuxTarget(run, { sessionExists: sessionExists2, targetExists: targetExists2 });
|
|
993
931
|
if (!isEnded && !isStale) continue;
|
|
994
932
|
try {
|
|
995
933
|
const record = archiveAndRemoveRun(run.id, isStale ? "stale" : "ended");
|
|
@@ -1001,1401 +939,1424 @@ function autoCleanupRuns(options = {}) {
|
|
|
1001
939
|
return { removed, archived };
|
|
1002
940
|
}
|
|
1003
941
|
|
|
1004
|
-
// src/
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
if (existsSync2(jsonc)) return jsonc;
|
|
1022
|
-
return json;
|
|
942
|
+
// src/i18n/languages.ts
|
|
943
|
+
var LANGUAGES = ["en", "de", "fr", "es", "pt", "it", "tr", "ru", "zh-Hans", "ar"];
|
|
944
|
+
var LANGUAGE_OPTIONS = [
|
|
945
|
+
{ code: "en", flag: "\u{1F1FA}\u{1F1F8}", name: "English", nativeName: "English", dir: "ltr" },
|
|
946
|
+
{ code: "de", flag: "\u{1F1E9}\u{1F1EA}", name: "German", nativeName: "Deutsch", dir: "ltr" },
|
|
947
|
+
{ code: "fr", flag: "\u{1F1EB}\u{1F1F7}", name: "French", nativeName: "Fran\xE7ais", dir: "ltr" },
|
|
948
|
+
{ code: "es", flag: "\u{1F1EA}\u{1F1F8}", name: "Spanish", nativeName: "Espa\xF1ol", dir: "ltr" },
|
|
949
|
+
{ code: "pt", flag: "\u{1F1F5}\u{1F1F9}", name: "Portuguese", nativeName: "Portugu\xEAs", dir: "ltr" },
|
|
950
|
+
{ code: "it", flag: "\u{1F1EE}\u{1F1F9}", name: "Italian", nativeName: "Italiano", dir: "ltr" },
|
|
951
|
+
{ code: "tr", flag: "\u{1F1F9}\u{1F1F7}", name: "Turkish", nativeName: "T\xFCrk\xE7e", dir: "ltr" },
|
|
952
|
+
{ code: "ru", flag: "\u{1F1F7}\u{1F1FA}", name: "Russian", nativeName: "\u0420\u0443\u0441\u0441\u043A\u0438\u0439", dir: "ltr" },
|
|
953
|
+
{ code: "zh-Hans", flag: "\u{1F1E8}\u{1F1F3}", name: "Simplified Chinese", nativeName: "\u7B80\u4F53\u4E2D\u6587", dir: "ltr" },
|
|
954
|
+
{ code: "ar", flag: "\u{1F1F8}\u{1F1E6}", name: "Arabic", nativeName: "\u0627\u0644\u0639\u0631\u0628\u064A\u0629", dir: "rtl" }
|
|
955
|
+
];
|
|
956
|
+
var DEFAULT_LANGUAGE = "en";
|
|
957
|
+
function isLanguageCode(value) {
|
|
958
|
+
return typeof value === "string" && LANGUAGES.includes(value);
|
|
1023
959
|
}
|
|
1024
|
-
function
|
|
1025
|
-
|
|
1026
|
-
const raw = readFileSync2(path, "utf-8").trim();
|
|
1027
|
-
if (!raw) return {};
|
|
1028
|
-
return JSON.parse(raw);
|
|
960
|
+
function languageOption(code) {
|
|
961
|
+
return LANGUAGE_OPTIONS.find((option) => option.code === code) ?? LANGUAGE_OPTIONS[0];
|
|
1029
962
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
963
|
+
|
|
964
|
+
// src/core/config.ts
|
|
965
|
+
import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, mkdirSync as mkdirSync2, renameSync as renameSync2 } from "fs";
|
|
966
|
+
import { homedir as homedir2 } from "os";
|
|
967
|
+
import { join as join2, dirname as dirname2 } from "path";
|
|
968
|
+
var SCHEMA_VERSION = 2;
|
|
969
|
+
var DEFAULT_GLOBAL = {
|
|
970
|
+
peek_interval_ms: 5e3,
|
|
971
|
+
peek_lines: 10,
|
|
972
|
+
max_depth: 5,
|
|
973
|
+
max_agents: 100,
|
|
974
|
+
ready_delay_ms: 5e3,
|
|
975
|
+
max_lifetime_ms: 0,
|
|
976
|
+
default_permissions: "ask",
|
|
977
|
+
language: DEFAULT_LANGUAGE
|
|
978
|
+
};
|
|
979
|
+
function configPath() {
|
|
980
|
+
const base = process.env.REEVES_CONFIG;
|
|
981
|
+
if (base) return base;
|
|
982
|
+
return join2(homedir2(), ".reeves", "config.json");
|
|
1032
983
|
}
|
|
1033
|
-
function
|
|
984
|
+
function configExists() {
|
|
1034
985
|
try {
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
return !!mcp && typeof mcp === "object" && SERVER_NAME in mcp;
|
|
986
|
+
readFileSync2(configPath(), "utf-8");
|
|
987
|
+
return true;
|
|
1038
988
|
} catch {
|
|
1039
989
|
return false;
|
|
1040
990
|
}
|
|
1041
991
|
}
|
|
1042
|
-
function
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
mcp[SERVER_NAME] = opencodeMcpEntry(cmd);
|
|
1048
|
-
cfg.mcp = mcp;
|
|
1049
|
-
mkdirSync2(dirname2(path), { recursive: true });
|
|
1050
|
-
writeFileSync2(path, `${JSON.stringify(cfg, null, 2)}
|
|
1051
|
-
`, "utf-8");
|
|
992
|
+
function defaultConfig() {
|
|
993
|
+
return {
|
|
994
|
+
version: SCHEMA_VERSION,
|
|
995
|
+
global: { ...DEFAULT_GLOBAL }
|
|
996
|
+
};
|
|
1052
997
|
}
|
|
1053
|
-
function
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
const
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
998
|
+
function mergeDefaults(raw) {
|
|
999
|
+
if (typeof raw !== "object" || raw === null) return defaultConfig();
|
|
1000
|
+
const obj = raw;
|
|
1001
|
+
const merged = {
|
|
1002
|
+
version: typeof obj.version === "number" ? obj.version : SCHEMA_VERSION,
|
|
1003
|
+
global: { ...DEFAULT_GLOBAL }
|
|
1004
|
+
};
|
|
1005
|
+
if (typeof obj.global === "object" && obj.global !== null) {
|
|
1006
|
+
const g = obj.global;
|
|
1007
|
+
if (typeof g.peek_interval_ms === "number" && g.peek_interval_ms > 0) merged.global.peek_interval_ms = g.peek_interval_ms;
|
|
1008
|
+
if (typeof g.peek_lines === "number" && g.peek_lines > 0) merged.global.peek_lines = g.peek_lines;
|
|
1009
|
+
if (typeof g.max_depth === "number" && g.max_depth > 0) merged.global.max_depth = g.max_depth;
|
|
1010
|
+
if (typeof g.max_agents === "number" && g.max_agents > 0) merged.global.max_agents = g.max_agents;
|
|
1011
|
+
if (typeof g.ready_delay_ms === "number" && g.ready_delay_ms >= 0) merged.global.ready_delay_ms = g.ready_delay_ms;
|
|
1012
|
+
if (typeof g.max_lifetime_ms === "number" && g.max_lifetime_ms >= 0) merged.global.max_lifetime_ms = g.max_lifetime_ms;
|
|
1013
|
+
if (g.default_permissions === "skip" || g.default_permissions === "ask") merged.global.default_permissions = g.default_permissions;
|
|
1014
|
+
if (isLanguageCode(g.language)) merged.global.language = g.language;
|
|
1062
1015
|
}
|
|
1016
|
+
return merged;
|
|
1063
1017
|
}
|
|
1064
|
-
function
|
|
1065
|
-
if (process.env.REEVES_HOME) return join2(process.env.REEVES_HOME, ".kimi-code");
|
|
1066
|
-
return process.env.KIMI_CODE_HOME || join2(homedir2(), ".kimi-code");
|
|
1067
|
-
}
|
|
1068
|
-
function isKimiCode(bin) {
|
|
1018
|
+
function loadConfig() {
|
|
1069
1019
|
try {
|
|
1070
|
-
const
|
|
1071
|
-
|
|
1072
|
-
timeout: STATUS_TIMEOUT_MS,
|
|
1073
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
1074
|
-
}).trim();
|
|
1075
|
-
return out !== "" && !/^kimi,/i.test(out);
|
|
1020
|
+
const content = readFileSync2(configPath(), "utf-8");
|
|
1021
|
+
return mergeDefaults(JSON.parse(content));
|
|
1076
1022
|
} catch {
|
|
1077
|
-
return
|
|
1023
|
+
return defaultConfig();
|
|
1078
1024
|
}
|
|
1079
1025
|
}
|
|
1080
|
-
function
|
|
1026
|
+
function saveConfig(cfg) {
|
|
1027
|
+
const path = configPath();
|
|
1028
|
+
const dir = dirname2(path);
|
|
1029
|
+
mkdirSync2(dir, { recursive: true });
|
|
1030
|
+
const tmp = `${path}.tmp`;
|
|
1031
|
+
writeFileSync2(tmp, JSON.stringify(cfg, null, 2), "utf-8");
|
|
1081
1032
|
try {
|
|
1082
|
-
|
|
1083
|
-
return Array.isArray(installed.plugins) && installed.plugins.some((p) => p.id === SERVER_NAME && p.enabled !== false);
|
|
1033
|
+
renameSync2(tmp, path);
|
|
1084
1034
|
} catch {
|
|
1085
|
-
|
|
1035
|
+
writeFileSync2(path, JSON.stringify(cfg, null, 2), "utf-8");
|
|
1086
1036
|
}
|
|
1037
|
+
return path;
|
|
1087
1038
|
}
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
}
|
|
1039
|
+
var CONFIG_FIELDS = [
|
|
1040
|
+
{ key: "peek_interval_ms", kind: "posint", label: "peek interval (ms)" },
|
|
1041
|
+
{ key: "peek_lines", kind: "posint", label: "peek lines" },
|
|
1042
|
+
{ key: "max_depth", kind: "posint", label: "max depth" },
|
|
1043
|
+
{ key: "max_agents", kind: "posint", label: "max agents" },
|
|
1044
|
+
{ key: "ready_delay_ms", kind: "nonneg-int", label: "ready delay (ms)" },
|
|
1045
|
+
{ key: "max_lifetime_ms", kind: "nonneg-int", label: "max agent lifetime (ms)" },
|
|
1046
|
+
{ key: "default_permissions", kind: "permissions", label: "default permissions" },
|
|
1047
|
+
{ key: "language", kind: "language", label: "language" }
|
|
1048
|
+
];
|
|
1049
|
+
function configFieldSpec(key) {
|
|
1050
|
+
const spec = CONFIG_FIELDS.find((field) => field.key === key);
|
|
1051
|
+
if (!spec) throw new Error(`unknown config field: ${key}`);
|
|
1052
|
+
return spec;
|
|
1095
1053
|
}
|
|
1096
|
-
function
|
|
1097
|
-
const
|
|
1098
|
-
|
|
1054
|
+
function parseConfigValue(key, raw) {
|
|
1055
|
+
const spec = configFieldSpec(key);
|
|
1056
|
+
if (spec.kind === "posint" || spec.kind === "nonneg-int") {
|
|
1057
|
+
const n = Number(raw);
|
|
1058
|
+
if (!Number.isFinite(n)) throw new Error(`${spec.label} must be a number`);
|
|
1059
|
+
return n;
|
|
1060
|
+
}
|
|
1061
|
+
return raw;
|
|
1099
1062
|
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
const path = join2(kimiCodeHome(), "mcp.json");
|
|
1115
|
-
if (!existsSync2(path)) return;
|
|
1116
|
-
const cfg = kimiCodeMcpConfig();
|
|
1117
|
-
const servers = cfg.mcpServers;
|
|
1118
|
-
if (servers && SERVER_NAME in servers) {
|
|
1119
|
-
delete servers[SERVER_NAME];
|
|
1120
|
-
writeFileSync2(path, `${JSON.stringify(cfg, null, 2)}
|
|
1121
|
-
`, "utf-8");
|
|
1122
|
-
}
|
|
1063
|
+
function validateConfigField(spec, value) {
|
|
1064
|
+
switch (spec.kind) {
|
|
1065
|
+
case "posint":
|
|
1066
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) throw new Error(`${spec.label} must be a positive integer`);
|
|
1067
|
+
return value;
|
|
1068
|
+
case "nonneg-int":
|
|
1069
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) throw new Error(`${spec.label} must be zero or a positive integer`);
|
|
1070
|
+
return value;
|
|
1071
|
+
case "permissions":
|
|
1072
|
+
if (value !== "ask" && value !== "skip") throw new Error(`${spec.label} must be ask or skip`);
|
|
1073
|
+
return value;
|
|
1074
|
+
case "language":
|
|
1075
|
+
if (!isLanguageCode(value)) throw new Error(`unknown language: ${String(value)}`);
|
|
1076
|
+
return value;
|
|
1123
1077
|
}
|
|
1124
|
-
}
|
|
1125
|
-
function
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
} catch {
|
|
1131
|
-
}
|
|
1078
|
+
}
|
|
1079
|
+
function setConfigValues(patch) {
|
|
1080
|
+
const cfg = loadConfig();
|
|
1081
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
1082
|
+
const spec = configFieldSpec(key);
|
|
1083
|
+
cfg.global[spec.key] = validateConfigField(spec, value);
|
|
1132
1084
|
}
|
|
1085
|
+
saveConfig(cfg);
|
|
1086
|
+
return cfg;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
// src/core/store.ts
|
|
1090
|
+
import { readFileSync as readFileSync3, writeFileSync as writeFileSync3, mkdirSync as mkdirSync3, readdirSync as readdirSync2, unlinkSync as unlinkSync2, renameSync as renameSync3, existsSync as existsSync2, chmodSync as chmodSync2 } from "fs";
|
|
1091
|
+
import { join as join3, dirname as dirname3 } from "path";
|
|
1092
|
+
function stateDir() {
|
|
1093
|
+
return stateRoot();
|
|
1094
|
+
}
|
|
1095
|
+
function presetsDir() {
|
|
1096
|
+
return join3(stateDir(), "presets");
|
|
1097
|
+
}
|
|
1098
|
+
function atomicWrite(path, data) {
|
|
1099
|
+
mkdirSync3(dirname3(path), { recursive: true });
|
|
1100
|
+
const tmp = `${path}.tmp`;
|
|
1101
|
+
writeFileSync3(tmp, JSON.stringify(data, null, 2), "utf-8");
|
|
1102
|
+
chmodSync2(tmp, 384);
|
|
1133
1103
|
try {
|
|
1134
|
-
|
|
1135
|
-
if (abs) return { command: abs, args: [SERVER_ARG] };
|
|
1104
|
+
renameSync3(tmp, path);
|
|
1136
1105
|
} catch {
|
|
1106
|
+
writeFileSync3(path, JSON.stringify(data, null, 2), "utf-8");
|
|
1137
1107
|
}
|
|
1138
|
-
return { command: SERVER_BIN, args: [SERVER_ARG] };
|
|
1139
1108
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
provider: "cc",
|
|
1143
|
-
// Claude Code defaults a new server to `local` (this directory only); pin
|
|
1144
|
-
// `user` so one attach covers every project on the machine.
|
|
1145
|
-
add: (cmd) => ["mcp", "add", SERVER_NAME, "-s", "user", "--", cmd.command, ...cmd.args],
|
|
1146
|
-
remove: ["mcp", "remove", SERVER_NAME],
|
|
1147
|
-
list: ["mcp", "list"]
|
|
1148
|
-
},
|
|
1149
|
-
{
|
|
1150
|
-
provider: "codex",
|
|
1151
|
-
add: (cmd) => ["mcp", "add", SERVER_NAME, "--", cmd.command, ...cmd.args],
|
|
1152
|
-
remove: ["mcp", "remove", SERVER_NAME],
|
|
1153
|
-
list: ["mcp", "list"]
|
|
1154
|
-
},
|
|
1155
|
-
{
|
|
1156
|
-
provider: "kimi",
|
|
1157
|
-
add: (cmd) => ["mcp", "add", SERVER_NAME, "--", cmd.command, ...cmd.args],
|
|
1158
|
-
remove: ["mcp", "remove", SERVER_NAME],
|
|
1159
|
-
list: ["mcp", "list"]
|
|
1160
|
-
},
|
|
1161
|
-
{
|
|
1162
|
-
provider: "qwen",
|
|
1163
|
-
// qwen (a gemini-cli fork) takes `<commandOrUrl> [args...]` with no `--`
|
|
1164
|
-
// separator, and already defaults its scope to `user`.
|
|
1165
|
-
add: (cmd) => ["mcp", "add", SERVER_NAME, cmd.command, ...cmd.args],
|
|
1166
|
-
remove: ["mcp", "remove", SERVER_NAME],
|
|
1167
|
-
list: ["mcp", "list"]
|
|
1168
|
-
},
|
|
1169
|
-
{
|
|
1170
|
-
provider: "hermes",
|
|
1171
|
-
// hermes takes --command and a variadic --args, so the entry path and `mcp`
|
|
1172
|
-
// both ride on one --args.
|
|
1173
|
-
add: (cmd) => ["mcp", "add", SERVER_NAME, "--command", cmd.command, "--args", ...cmd.args],
|
|
1174
|
-
remove: ["mcp", "remove", SERVER_NAME],
|
|
1175
|
-
list: ["mcp", "list"]
|
|
1176
|
-
},
|
|
1177
|
-
{
|
|
1178
|
-
// opencode's `mcp add` prompts interactively for a local server's command, so
|
|
1179
|
-
// we attach it by writing its config JSON directly instead.
|
|
1180
|
-
provider: "opencode",
|
|
1181
|
-
list: ["mcp", "list"],
|
|
1182
|
-
file: { attach: opencodeAttach, detach: opencodeDetach, attached: opencodeAttached }
|
|
1183
|
-
}
|
|
1184
|
-
];
|
|
1185
|
-
function hostBin(host) {
|
|
1186
|
-
return PROVIDER_REGISTRY[host.provider].bin;
|
|
1109
|
+
function isEffort(value) {
|
|
1110
|
+
return value === "default" || value === "low" || value === "medium" || value === "high" || value === "xhigh" || value === "max";
|
|
1187
1111
|
}
|
|
1188
|
-
function
|
|
1189
|
-
|
|
1112
|
+
function normalizeSlot(raw, fallbackDir = "") {
|
|
1113
|
+
const promptRaw = typeof raw.initial_prompt === "string" ? raw.initial_prompt : typeof raw.task_template === "string" ? raw.task_template : "";
|
|
1114
|
+
return {
|
|
1115
|
+
nickname_template: typeof raw.nickname_template === "string" ? raw.nickname_template : "agent",
|
|
1116
|
+
provider: isProvider(raw.provider) ? raw.provider : "cc",
|
|
1117
|
+
model: typeof raw.model === "string" ? raw.model : "",
|
|
1118
|
+
auth_mode: raw.auth_mode === "api-key" ? "api-key" : "default",
|
|
1119
|
+
effort: isEffort(raw.effort) ? raw.effort : "default",
|
|
1120
|
+
initial_prompt: promptRaw,
|
|
1121
|
+
working_dir: typeof raw.working_dir === "string" ? raw.working_dir : fallbackDir,
|
|
1122
|
+
permissions: raw.permissions === "skip" ? "skip" : "ask",
|
|
1123
|
+
rc_enabled: typeof raw.rc_enabled === "boolean" ? raw.rc_enabled : false
|
|
1124
|
+
};
|
|
1190
1125
|
}
|
|
1191
|
-
function
|
|
1192
|
-
if (
|
|
1193
|
-
|
|
1194
|
-
|
|
1126
|
+
function normalizePreset(raw) {
|
|
1127
|
+
if (typeof raw !== "object" || raw === null) return null;
|
|
1128
|
+
const obj = raw;
|
|
1129
|
+
const legacyDir = typeof obj.working_dir_pattern === "string" ? obj.working_dir_pattern : "";
|
|
1130
|
+
const rootRaw = typeof obj.root === "object" && obj.root !== null ? obj.root : {};
|
|
1131
|
+
const workersRaw = Array.isArray(obj.workers) ? obj.workers : [];
|
|
1132
|
+
return {
|
|
1133
|
+
name: typeof obj.name === "string" ? obj.name : "preset",
|
|
1134
|
+
description: typeof obj.description === "string" ? obj.description : "",
|
|
1135
|
+
root: normalizeSlot(rootRaw, legacyDir),
|
|
1136
|
+
workers: workersRaw.filter((w) => typeof w === "object" && w !== null).map((w) => normalizeSlot(w, legacyDir)),
|
|
1137
|
+
working_dir_pattern: legacyDir || void 0,
|
|
1138
|
+
created_at: typeof obj.created_at === "string" ? obj.created_at : (/* @__PURE__ */ new Date()).toISOString(),
|
|
1139
|
+
updated_at: typeof obj.updated_at === "string" ? obj.updated_at : (/* @__PURE__ */ new Date()).toISOString()
|
|
1140
|
+
};
|
|
1195
1141
|
}
|
|
1196
|
-
function
|
|
1142
|
+
function listPresets() {
|
|
1143
|
+
const dir = presetsDir();
|
|
1144
|
+
if (!existsSync2(dir)) return [];
|
|
1197
1145
|
try {
|
|
1198
|
-
|
|
1199
|
-
|
|
1146
|
+
return readdirSync2(dir).filter((f) => f.endsWith(".json")).map((f) => {
|
|
1147
|
+
try {
|
|
1148
|
+
return normalizePreset(JSON.parse(readFileSync3(join3(dir, f), "utf-8")));
|
|
1149
|
+
} catch {
|
|
1150
|
+
return null;
|
|
1151
|
+
}
|
|
1152
|
+
}).filter((t) => t !== null);
|
|
1200
1153
|
} catch {
|
|
1201
|
-
return
|
|
1154
|
+
return [];
|
|
1202
1155
|
}
|
|
1203
1156
|
}
|
|
1204
|
-
function
|
|
1157
|
+
function loadPreset(name) {
|
|
1205
1158
|
try {
|
|
1206
|
-
|
|
1207
|
-
encoding: "utf8",
|
|
1208
|
-
timeout: STATUS_TIMEOUT_MS,
|
|
1209
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
1210
|
-
});
|
|
1211
|
-
return /reevesagents(?![-\w])/i.test(out);
|
|
1159
|
+
return normalizePreset(JSON.parse(readFileSync3(join3(presetsDir(), `${name}.json`), "utf-8")));
|
|
1212
1160
|
} catch {
|
|
1213
|
-
return
|
|
1161
|
+
return null;
|
|
1214
1162
|
}
|
|
1215
1163
|
}
|
|
1216
|
-
function
|
|
1217
|
-
|
|
1218
|
-
encoding: "utf8",
|
|
1219
|
-
timeout: MGMT_TIMEOUT_MS,
|
|
1220
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
1221
|
-
});
|
|
1164
|
+
function savePreset(tree) {
|
|
1165
|
+
atomicWrite(join3(presetsDir(), `${tree.name}.json`), tree);
|
|
1222
1166
|
}
|
|
1223
|
-
function
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1167
|
+
function deletePreset(name) {
|
|
1168
|
+
try {
|
|
1169
|
+
unlinkSync2(join3(presetsDir(), `${name}.json`));
|
|
1170
|
+
} catch {
|
|
1171
|
+
}
|
|
1227
1172
|
}
|
|
1228
|
-
function
|
|
1229
|
-
|
|
1230
|
-
if (!host) throw new Error(`Unknown CLI: ${key}`);
|
|
1231
|
-
return host;
|
|
1173
|
+
function sanitizePresetName(raw) {
|
|
1174
|
+
return raw.trim().replace(/[^a-zA-Z0-9_-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 64);
|
|
1232
1175
|
}
|
|
1233
|
-
function
|
|
1234
|
-
return
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
});
|
|
1176
|
+
function agentToSlot(agent) {
|
|
1177
|
+
return {
|
|
1178
|
+
nickname_template: agent.nickname,
|
|
1179
|
+
provider: agent.provider,
|
|
1180
|
+
model: agent.model,
|
|
1181
|
+
auth_mode: "default",
|
|
1182
|
+
effort: "default",
|
|
1183
|
+
initial_prompt: agent.task,
|
|
1184
|
+
working_dir: agent.working_dir,
|
|
1185
|
+
permissions: agent.permissions,
|
|
1186
|
+
rc_enabled: agent.rc_enabled
|
|
1187
|
+
};
|
|
1246
1188
|
}
|
|
1247
|
-
function
|
|
1248
|
-
const
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
return { key, label, ok: false, message: `could not edit config (add it manually): ${cliError(err)}` };
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
try {
|
|
1271
|
-
if (force && host.remove) {
|
|
1272
|
-
try {
|
|
1273
|
-
runHostCommand(host, host.remove);
|
|
1274
|
-
} catch {
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
runHostCommand(host, host.add(resolveLaunchCmd()));
|
|
1278
|
-
return { key, label, ok: true, message: force ? "reattached" : "attached" };
|
|
1279
|
-
} catch (err) {
|
|
1280
|
-
return { key, label, ok: false, message: cliError(err) };
|
|
1281
|
-
}
|
|
1189
|
+
function savePresetFromRun(runId, name, description = "") {
|
|
1190
|
+
const presetName = sanitizePresetName(name);
|
|
1191
|
+
if (!presetName) throw new Error("preset name is required");
|
|
1192
|
+
const run = readRun(runId);
|
|
1193
|
+
const agents = listAgents(run.id).filter((agent) => !agent.headless);
|
|
1194
|
+
if (agents.length === 0) throw new Error("run has no agents to save as a preset");
|
|
1195
|
+
const root = agents.find((agent) => agent.role === "root") ?? agents[0];
|
|
1196
|
+
const workers = agents.filter((agent) => agent !== root);
|
|
1197
|
+
const existing = loadPreset(presetName);
|
|
1198
|
+
const now = nowIso();
|
|
1199
|
+
const tree = {
|
|
1200
|
+
name: presetName,
|
|
1201
|
+
description,
|
|
1202
|
+
root: agentToSlot(root),
|
|
1203
|
+
workers: workers.map(agentToSlot),
|
|
1204
|
+
created_at: existing?.created_at ?? now,
|
|
1205
|
+
updated_at: now
|
|
1206
|
+
};
|
|
1207
|
+
savePreset(tree);
|
|
1208
|
+
return tree;
|
|
1282
1209
|
}
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1210
|
+
|
|
1211
|
+
// src/utils/display.ts
|
|
1212
|
+
var MODEL_COLORS = {
|
|
1213
|
+
default: "#9b9488",
|
|
1214
|
+
// CLI default or unset model
|
|
1215
|
+
claude: "#e0a06f",
|
|
1216
|
+
// Claude family
|
|
1217
|
+
openai: "#72b7d6",
|
|
1218
|
+
// OpenAI family
|
|
1219
|
+
deepseek: "#7ac8bc",
|
|
1220
|
+
// DeepSeek family
|
|
1221
|
+
qwen: "#d1a25d",
|
|
1222
|
+
// Qwen family
|
|
1223
|
+
kimi: "#d0c268",
|
|
1224
|
+
// Kimi family
|
|
1225
|
+
local: "#92b37a",
|
|
1226
|
+
// local/open model family
|
|
1227
|
+
other: "#9ca8bd"
|
|
1228
|
+
// known provider, unclassified model
|
|
1229
|
+
};
|
|
1230
|
+
var PROVIDER_DISPLAY_NAMES = Object.fromEntries(
|
|
1231
|
+
PROVIDER_DEFS.map((def) => [def.id, def.displayName])
|
|
1232
|
+
);
|
|
1233
|
+
function providerDisplayName(provider) {
|
|
1234
|
+
return PROVIDER_DISPLAY_NAMES[provider] ?? provider;
|
|
1307
1235
|
}
|
|
1308
|
-
function
|
|
1309
|
-
return
|
|
1310
|
-
const file = hostFileOps(host);
|
|
1311
|
-
const attached = file ? file.attached() : isAttached(host);
|
|
1312
|
-
if (!force && attached) {
|
|
1313
|
-
return { key: host.provider, label: hostLabel(host), ok: true, message: "already attached" };
|
|
1314
|
-
}
|
|
1315
|
-
return attach(host.provider, force);
|
|
1316
|
-
});
|
|
1236
|
+
function providerColor(p) {
|
|
1237
|
+
return PROVIDER_REGISTRY[p]?.color ?? "gray";
|
|
1317
1238
|
}
|
|
1318
|
-
|
|
1319
|
-
const
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
} catch (err) {
|
|
1334
|
-
return { ok: false, detail: err instanceof Error ? err.message : String(err) };
|
|
1335
|
-
} finally {
|
|
1336
|
-
if (timer) clearTimeout(timer);
|
|
1337
|
-
try {
|
|
1338
|
-
await client.close();
|
|
1339
|
-
} catch {
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1239
|
+
function modelColor(model, provider) {
|
|
1240
|
+
const lower = model.trim().toLowerCase();
|
|
1241
|
+
if (!lower) return MODEL_COLORS.default;
|
|
1242
|
+
if (lower.includes("claude") || lower.includes("sonnet") || lower.includes("opus") || lower.includes("haiku")) return MODEL_COLORS.claude;
|
|
1243
|
+
if (lower.includes("gpt") || lower.includes("codex") || /\bo[134]\b/.test(lower)) return MODEL_COLORS.openai;
|
|
1244
|
+
if (lower.includes("deepseek")) return MODEL_COLORS.deepseek;
|
|
1245
|
+
if (lower.includes("qwen")) return MODEL_COLORS.qwen;
|
|
1246
|
+
if (lower.includes("kimi") || lower.includes("moonshot")) return MODEL_COLORS.kimi;
|
|
1247
|
+
if (lower.includes("llama") || lower.includes("mistral") || lower.includes("mixtral") || lower.includes("ollama") || lower.includes("lmstudio") || lower.includes("local")) return MODEL_COLORS.local;
|
|
1248
|
+
if (provider === "cc") return MODEL_COLORS.claude;
|
|
1249
|
+
if (provider === "codex") return MODEL_COLORS.openai;
|
|
1250
|
+
if (provider === "deepseek") return MODEL_COLORS.deepseek;
|
|
1251
|
+
if (provider === "qwen") return MODEL_COLORS.qwen;
|
|
1252
|
+
if (provider === "kimi") return MODEL_COLORS.kimi;
|
|
1253
|
+
return MODEL_COLORS.other;
|
|
1342
1254
|
}
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
var MIN_NODE_VERSION = [20, 19, 0];
|
|
1350
|
-
function parseNodeVersion(version) {
|
|
1351
|
-
const clean = version.startsWith("v") ? version.slice(1) : version;
|
|
1352
|
-
const [major = "0", minor = "0", patch = "0"] = clean.split(".");
|
|
1353
|
-
return [parseInt(major, 10) || 0, parseInt(minor, 10) || 0, parseInt(patch, 10) || 0];
|
|
1255
|
+
function modelBadgeLabel(model) {
|
|
1256
|
+
const value = model.trim();
|
|
1257
|
+
if (!value) return "default";
|
|
1258
|
+
const slashIdx = value.lastIndexOf("/");
|
|
1259
|
+
const label = slashIdx >= 0 && slashIdx < value.length - 1 ? value.slice(slashIdx + 1) : value;
|
|
1260
|
+
return truncateLabel(label, 24);
|
|
1354
1261
|
}
|
|
1355
|
-
function
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
if (version[i] < MIN_NODE_VERSION[i]) return false;
|
|
1359
|
-
}
|
|
1360
|
-
return true;
|
|
1262
|
+
function truncateLabel(label, max) {
|
|
1263
|
+
if (label.length <= max) return label;
|
|
1264
|
+
return `${label.slice(0, Math.max(1, max - 3))}...`;
|
|
1361
1265
|
}
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1266
|
+
|
|
1267
|
+
// src/core/runtime.ts
|
|
1268
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
1269
|
+
import stripAnsi from "strip-ansi";
|
|
1270
|
+
|
|
1271
|
+
// src/core/provider-launch.ts
|
|
1272
|
+
import { existsSync as existsSync3, statSync as statSync2 } from "fs";
|
|
1273
|
+
import { homedir as homedir3 } from "os";
|
|
1274
|
+
import { join as join4 } from "path";
|
|
1275
|
+
function expandHome(p) {
|
|
1276
|
+
if (p === "~") return homedir3();
|
|
1277
|
+
if (p.startsWith("~/")) return join4(homedir3(), p.slice(2));
|
|
1278
|
+
return p;
|
|
1371
1279
|
}
|
|
1372
|
-
function
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
}
|
|
1280
|
+
function resolveWorkingDir(requested, fallback) {
|
|
1281
|
+
if (!requested) return fallback;
|
|
1282
|
+
const expanded = expandHome(requested.trim());
|
|
1283
|
+
if (!expanded) return fallback;
|
|
1284
|
+
if (existsSync3(expanded) && statSync2(expanded).isDirectory()) return expanded;
|
|
1285
|
+
throw new Error(`Working directory does not exist: ${expanded}`);
|
|
1378
1286
|
}
|
|
1379
|
-
function
|
|
1380
|
-
return
|
|
1381
|
-
env.WSL_DISTRO_NAME || env.WSL_INTEROP || /microsoft|wsl/i.test(procVersion)
|
|
1382
|
-
);
|
|
1287
|
+
function shellQuote(s) {
|
|
1288
|
+
return `'${s.replace(/'/g, "'\\''")}'`;
|
|
1383
1289
|
}
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1290
|
+
|
|
1291
|
+
// src/core/runtime.ts
|
|
1292
|
+
var ALLOWED_KEYS = [
|
|
1293
|
+
"enter",
|
|
1294
|
+
"escape",
|
|
1295
|
+
"backspace",
|
|
1296
|
+
"tab",
|
|
1297
|
+
"space",
|
|
1298
|
+
"up",
|
|
1299
|
+
"down",
|
|
1300
|
+
"left",
|
|
1301
|
+
"right",
|
|
1302
|
+
"ctrl-c"
|
|
1303
|
+
];
|
|
1304
|
+
var POST_PASTE_ENTER_DELAY_MS = 1e3;
|
|
1305
|
+
var STARTUP_READY_POLL_MS = 1e3;
|
|
1306
|
+
var STARTUP_READY_TIMEOUT_MS = 2e4;
|
|
1307
|
+
var lastPasteAtByPane = /* @__PURE__ */ new Map();
|
|
1308
|
+
function sleepSync2(ms) {
|
|
1309
|
+
const buffer = new SharedArrayBuffer(4);
|
|
1310
|
+
const view = new Int32Array(buffer);
|
|
1311
|
+
Atomics.wait(view, 0, 0, ms);
|
|
1405
1312
|
}
|
|
1406
|
-
function
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
if (!match) return { name: "tmux", status: "warn", detail: `unexpected version format: ${versionStr}` };
|
|
1411
|
-
const major = parseInt(match[1] ?? "0", 10);
|
|
1412
|
-
const minor = parseInt(match[2] ?? "0", 10);
|
|
1413
|
-
if (major < 3) return { name: "tmux", status: "warn", detail: `tmux ${major}.${minor}; upgrade to 3.0+ recommended` };
|
|
1414
|
-
return { name: "tmux", status: "ok", detail: `tmux ${major}.${minor}` };
|
|
1415
|
-
} catch {
|
|
1416
|
-
return { name: "tmux", status: "fail", detail: "not on PATH" };
|
|
1417
|
-
}
|
|
1313
|
+
function waitAfterPaste(driver) {
|
|
1314
|
+
if (driver === realDriver) sleepSync2(POST_PASTE_ENTER_DELAY_MS);
|
|
1315
|
+
else driver.delay(() => {
|
|
1316
|
+
}, POST_PASTE_ENTER_DELAY_MS);
|
|
1418
1317
|
}
|
|
1419
|
-
function
|
|
1420
|
-
|
|
1421
|
-
const statuses = Object.entries(available).map(([name, isAvail]) => `${providerDisplayName(name)}: ${isAvail ? "ok" : "missing"}`).join("; ");
|
|
1422
|
-
const noneAvail = Object.values(available).every((value) => !value);
|
|
1423
|
-
return {
|
|
1424
|
-
name: "providers",
|
|
1425
|
-
status: noneAvail ? "fail" : "ok",
|
|
1426
|
-
detail: statuses
|
|
1427
|
-
};
|
|
1318
|
+
function normalizePaneOutput(output) {
|
|
1319
|
+
return stripAnsi(output).replace(/\s+/g, " ").trim().toLowerCase();
|
|
1428
1320
|
}
|
|
1429
|
-
function
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
const problems = installed.filter((provider) => !provider.ok).map((provider) => `${providerDisplayName(provider.provider)}: ${provider.detail}`);
|
|
1437
|
-
if (problems.length === 0) {
|
|
1438
|
-
return { name: "provider compat", status: "ok", detail: `${installed.map((provider) => providerDisplayName(provider.provider)).join(", ")} compatible` };
|
|
1439
|
-
}
|
|
1440
|
-
return {
|
|
1441
|
-
name: "provider compat",
|
|
1442
|
-
status: "warn",
|
|
1443
|
-
detail: problems.slice(0, 3).join("; ") + (problems.length > 3 ? `; +${problems.length - 3} more` : "")
|
|
1444
|
-
};
|
|
1321
|
+
function paneLooksReady(output, previousOutput) {
|
|
1322
|
+
const current = normalizePaneOutput(output);
|
|
1323
|
+
if (!current) return false;
|
|
1324
|
+
if (/\bready\b/.test(current)) return true;
|
|
1325
|
+
if (current.includes("type a message") || current.includes("enter your prompt")) return true;
|
|
1326
|
+
if (current.includes("what would you like") || current.includes("what do you want")) return true;
|
|
1327
|
+
return !!previousOutput && current === normalizePaneOutput(previousOutput);
|
|
1445
1328
|
}
|
|
1446
|
-
function
|
|
1447
|
-
|
|
1329
|
+
function pasteTextToPane(driver, paneId, text) {
|
|
1330
|
+
const bufferName = `reeves_${randomUUID2().slice(0, 8)}`;
|
|
1331
|
+
driver.tmux(["load-buffer", "-b", bufferName, "-"], text);
|
|
1448
1332
|
try {
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
} catch {
|
|
1452
|
-
return { name, status: "fail", detail: `${path} (not readable/writable)` };
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
function checkWebExtras() {
|
|
1456
|
-
const requireFrom = createRequire(import.meta.url);
|
|
1457
|
-
const missing = WEB_EXTRA_MODULES.filter((name) => {
|
|
1333
|
+
driver.tmux(["paste-buffer", "-b", bufferName, "-t", paneId]);
|
|
1334
|
+
} finally {
|
|
1458
1335
|
try {
|
|
1459
|
-
|
|
1460
|
-
return false;
|
|
1336
|
+
driver.tmux(["delete-buffer", "-b", bufferName]);
|
|
1461
1337
|
} catch {
|
|
1462
|
-
return true;
|
|
1463
1338
|
}
|
|
1464
|
-
});
|
|
1465
|
-
if (missing.length === 0) {
|
|
1466
|
-
return { name: "web extras", status: "ok", detail: `${WEB_EXTRA_MODULES.join(" + ")} present (web UI available)` };
|
|
1467
1339
|
}
|
|
1468
|
-
return { name: "web extras", status: "warn", detail: `${missing.join(", ")} not installed; TUI unaffected, web UI disabled` };
|
|
1469
1340
|
}
|
|
1470
|
-
function
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
return { name: "runs state", status: "ok", detail: `${runs.length} run${runs.length === 1 ? "" : "s"}` };
|
|
1474
|
-
} catch (err) {
|
|
1475
|
-
return {
|
|
1476
|
-
name: "runs state",
|
|
1477
|
-
status: "fail",
|
|
1478
|
-
detail: `error reading runs: ${err instanceof Error ? err.message : "unknown"}`
|
|
1479
|
-
};
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
function checkMcpServerCommand() {
|
|
1483
|
-
const cmd = resolveLaunchCmd();
|
|
1484
|
-
if (cmd.command === "reevesagents") {
|
|
1485
|
-
return {
|
|
1486
|
-
name: "mcp server",
|
|
1487
|
-
status: "warn",
|
|
1488
|
-
detail: "no absolute launcher resolved; attached host CLIs will fall back to their own PATH"
|
|
1489
|
-
};
|
|
1490
|
-
}
|
|
1491
|
-
try {
|
|
1492
|
-
accessSync(cmd.command, constants.X_OK);
|
|
1493
|
-
return { name: "mcp server", status: "ok", detail: `${cmd.command} ${cmd.args.join(" ")}` };
|
|
1494
|
-
} catch {
|
|
1495
|
-
return {
|
|
1496
|
-
name: "mcp server",
|
|
1497
|
-
status: "warn",
|
|
1498
|
-
detail: `${cmd.command} is not executable; re-run reevesagents attach after reinstalling`
|
|
1499
|
-
};
|
|
1500
|
-
}
|
|
1341
|
+
function sanitizeName(raw) {
|
|
1342
|
+
const cleaned = raw.trim().replace(/[^a-zA-Z0-9_-]/g, "-").replace(/-+/g, "-").slice(0, 40);
|
|
1343
|
+
return cleaned || "run";
|
|
1501
1344
|
}
|
|
1502
|
-
function
|
|
1503
|
-
return
|
|
1504
|
-
checks: [
|
|
1505
|
-
platformSupportCheck(),
|
|
1506
|
-
nodeVersionCheck(),
|
|
1507
|
-
checkTmux(),
|
|
1508
|
-
checkProviders(),
|
|
1509
|
-
checkProviderCompatibility(),
|
|
1510
|
-
checkPathAccess("state dir", stateRoot()),
|
|
1511
|
-
checkPathAccess("runs dir", runsDir()),
|
|
1512
|
-
checkPathAccess("presets dir", join3(stateRoot(), "presets")),
|
|
1513
|
-
checkRunsState(),
|
|
1514
|
-
checkWebExtras(),
|
|
1515
|
-
checkMcpServerCommand()
|
|
1516
|
-
]
|
|
1517
|
-
};
|
|
1345
|
+
function tmuxWindowName(provider, nickname) {
|
|
1346
|
+
return sanitizeName(nickname || provider).slice(0, 64);
|
|
1518
1347
|
}
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
var LANGUAGES = ["en", "de", "fr", "es", "pt", "it", "tr", "ru", "zh-Hans", "ar"];
|
|
1522
|
-
var LANGUAGE_OPTIONS = [
|
|
1523
|
-
{ code: "en", flag: "\u{1F1FA}\u{1F1F8}", name: "English", nativeName: "English", dir: "ltr" },
|
|
1524
|
-
{ code: "de", flag: "\u{1F1E9}\u{1F1EA}", name: "German", nativeName: "Deutsch", dir: "ltr" },
|
|
1525
|
-
{ code: "fr", flag: "\u{1F1EB}\u{1F1F7}", name: "French", nativeName: "Fran\xE7ais", dir: "ltr" },
|
|
1526
|
-
{ code: "es", flag: "\u{1F1EA}\u{1F1F8}", name: "Spanish", nativeName: "Espa\xF1ol", dir: "ltr" },
|
|
1527
|
-
{ code: "pt", flag: "\u{1F1F5}\u{1F1F9}", name: "Portuguese", nativeName: "Portugu\xEAs", dir: "ltr" },
|
|
1528
|
-
{ code: "it", flag: "\u{1F1EE}\u{1F1F9}", name: "Italian", nativeName: "Italiano", dir: "ltr" },
|
|
1529
|
-
{ code: "tr", flag: "\u{1F1F9}\u{1F1F7}", name: "Turkish", nativeName: "T\xFCrk\xE7e", dir: "ltr" },
|
|
1530
|
-
{ code: "ru", flag: "\u{1F1F7}\u{1F1FA}", name: "Russian", nativeName: "\u0420\u0443\u0441\u0441\u043A\u0438\u0439", dir: "ltr" },
|
|
1531
|
-
{ code: "zh-Hans", flag: "\u{1F1E8}\u{1F1F3}", name: "Simplified Chinese", nativeName: "\u7B80\u4F53\u4E2D\u6587", dir: "ltr" },
|
|
1532
|
-
{ code: "ar", flag: "\u{1F1F8}\u{1F1E6}", name: "Arabic", nativeName: "\u0627\u0644\u0639\u0631\u0628\u064A\u0629", dir: "rtl" }
|
|
1533
|
-
];
|
|
1534
|
-
var DEFAULT_LANGUAGE = "en";
|
|
1535
|
-
function isLanguageCode(value) {
|
|
1536
|
-
return typeof value === "string" && LANGUAGES.includes(value);
|
|
1348
|
+
function tmuxRunSessionName(runId, rawName) {
|
|
1349
|
+
return `reeves-${sanitizeName(rawName).slice(0, 24)}-${runId.slice(0, 8)}`.slice(0, 64);
|
|
1537
1350
|
}
|
|
1538
|
-
function
|
|
1539
|
-
|
|
1351
|
+
function childProcessOutput(err) {
|
|
1352
|
+
if (typeof err !== "object" || err === null) return "";
|
|
1353
|
+
const maybe = err;
|
|
1354
|
+
const stderr = Buffer.isBuffer(maybe.stderr) ? maybe.stderr.toString("utf8").trim() : "";
|
|
1355
|
+
if (stderr) return stderr;
|
|
1356
|
+
const stdout = Buffer.isBuffer(maybe.stdout) ? maybe.stdout.toString("utf8").trim() : "";
|
|
1357
|
+
return stdout;
|
|
1540
1358
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
var DEFAULT_GLOBAL = {
|
|
1548
|
-
peek_interval_ms: 5e3,
|
|
1549
|
-
peek_lines: 10,
|
|
1550
|
-
max_depth: 5,
|
|
1551
|
-
max_agents: 100,
|
|
1552
|
-
ready_delay_ms: 5e3,
|
|
1553
|
-
max_lifetime_ms: 0,
|
|
1554
|
-
default_permissions: "ask",
|
|
1555
|
-
language: DEFAULT_LANGUAGE
|
|
1556
|
-
};
|
|
1557
|
-
function configPath() {
|
|
1558
|
-
const base = process.env.REEVES_CONFIG;
|
|
1559
|
-
if (base) return base;
|
|
1560
|
-
return join4(homedir3(), ".reeves", "config.json");
|
|
1359
|
+
function parseTmuxIds(output) {
|
|
1360
|
+
const [windowId, paneId] = output.trim().split(/\s+/);
|
|
1361
|
+
if (!windowId?.startsWith("@") || !paneId?.startsWith("%")) {
|
|
1362
|
+
throw new Error(`Could not parse tmux ids from: ${output}`);
|
|
1363
|
+
}
|
|
1364
|
+
return { windowId, paneId };
|
|
1561
1365
|
}
|
|
1562
|
-
function
|
|
1366
|
+
function readDisplayIds(driver, target) {
|
|
1563
1367
|
try {
|
|
1564
|
-
|
|
1565
|
-
|
|
1368
|
+
const args = ["display-message", "-p"];
|
|
1369
|
+
if (target) args.push("-t", target);
|
|
1370
|
+
args.push("#{window_id} #{pane_id}");
|
|
1371
|
+
return parseTmuxIds(driver.tmux(args));
|
|
1566
1372
|
} catch {
|
|
1567
|
-
return
|
|
1373
|
+
return null;
|
|
1568
1374
|
}
|
|
1569
1375
|
}
|
|
1570
|
-
function
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
global: { ...DEFAULT_GLOBAL }
|
|
1574
|
-
};
|
|
1376
|
+
function requireProvider(provider, available) {
|
|
1377
|
+
if (!isProvider(provider)) throw new Error(`Unsupported provider: ${String(provider)}`);
|
|
1378
|
+
if (!available[provider]) throw new Error(`${providerDisplayName(provider)} not found on PATH`);
|
|
1575
1379
|
}
|
|
1576
|
-
function
|
|
1577
|
-
if (
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
if (typeof g.peek_lines === "number" && g.peek_lines > 0) merged.global.peek_lines = g.peek_lines;
|
|
1587
|
-
if (typeof g.max_depth === "number" && g.max_depth > 0) merged.global.max_depth = g.max_depth;
|
|
1588
|
-
if (typeof g.max_agents === "number" && g.max_agents > 0) merged.global.max_agents = g.max_agents;
|
|
1589
|
-
if (typeof g.ready_delay_ms === "number" && g.ready_delay_ms >= 0) merged.global.ready_delay_ms = g.ready_delay_ms;
|
|
1590
|
-
if (typeof g.max_lifetime_ms === "number" && g.max_lifetime_ms >= 0) merged.global.max_lifetime_ms = g.max_lifetime_ms;
|
|
1591
|
-
if (g.default_permissions === "skip" || g.default_permissions === "ask") merged.global.default_permissions = g.default_permissions;
|
|
1592
|
-
if (isLanguageCode(g.language)) merged.global.language = g.language;
|
|
1380
|
+
function pickReevesAnchor(driver) {
|
|
1381
|
+
if (process.env.TMUX) {
|
|
1382
|
+
try {
|
|
1383
|
+
const sessionName = driver.tmux(["display-message", "-p", "#S"]).trim();
|
|
1384
|
+
const ids2 = readDisplayIds(driver);
|
|
1385
|
+
if (sessionName && ids2) {
|
|
1386
|
+
return { sessionName, windowId: ids2.windowId, paneId: ids2.paneId };
|
|
1387
|
+
}
|
|
1388
|
+
} catch {
|
|
1389
|
+
}
|
|
1593
1390
|
}
|
|
1594
|
-
|
|
1595
|
-
}
|
|
1596
|
-
function loadConfig() {
|
|
1391
|
+
const fallbackName = "reeves";
|
|
1597
1392
|
try {
|
|
1598
|
-
|
|
1599
|
-
return mergeDefaults(JSON.parse(content));
|
|
1393
|
+
driver.tmux(["new-session", "-d", "-s", fallbackName, "-n", "reeves"]);
|
|
1600
1394
|
} catch {
|
|
1601
|
-
return defaultConfig();
|
|
1602
1395
|
}
|
|
1396
|
+
let ids = readDisplayIds(driver, `=${fallbackName}:reeves`);
|
|
1397
|
+
if (!ids) {
|
|
1398
|
+
try {
|
|
1399
|
+
driver.tmux(["new-window", "-d", "-t", `${fallbackName}:`, "-n", "reeves"]);
|
|
1400
|
+
} catch {
|
|
1401
|
+
}
|
|
1402
|
+
ids = readDisplayIds(driver, `=${fallbackName}:reeves`);
|
|
1403
|
+
}
|
|
1404
|
+
return { sessionName: fallbackName, windowId: ids?.windowId ?? "", paneId: ids?.paneId ?? "" };
|
|
1603
1405
|
}
|
|
1604
|
-
function
|
|
1605
|
-
|
|
1606
|
-
const
|
|
1607
|
-
mkdirSync3(dir, { recursive: true });
|
|
1608
|
-
const tmp = `${path}.tmp`;
|
|
1609
|
-
writeFileSync3(tmp, JSON.stringify(cfg, null, 2), "utf-8");
|
|
1406
|
+
function createRunSessionWithReevesTab(driver, tmuxSession, reevesAnchor, workingDir) {
|
|
1407
|
+
driver.tmux(["new-session", "-d", "-s", tmuxSession, "-n", "reeves", "-c", workingDir]);
|
|
1408
|
+
const source = reevesAnchor.windowId || `${reevesAnchor.sessionName}:reeves`;
|
|
1610
1409
|
try {
|
|
1611
|
-
|
|
1410
|
+
driver.tmux(["link-window", "-k", "-s", source, "-t", `${tmuxSession}:0`]);
|
|
1612
1411
|
} catch {
|
|
1613
|
-
writeFileSync3(path, JSON.stringify(cfg, null, 2), "utf-8");
|
|
1614
1412
|
}
|
|
1615
|
-
return path;
|
|
1616
1413
|
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
const spec = CONFIG_FIELDS.find((field) => field.key === key);
|
|
1629
|
-
if (!spec) throw new Error(`unknown config field: ${key}`);
|
|
1630
|
-
return spec;
|
|
1414
|
+
function terminalShellCommand(config, permissions) {
|
|
1415
|
+
const cmd = buildCommand({
|
|
1416
|
+
provider: config.provider,
|
|
1417
|
+
permissions,
|
|
1418
|
+
model: config.model,
|
|
1419
|
+
auth_mode: config.auth_mode,
|
|
1420
|
+
effort: config.effort,
|
|
1421
|
+
rc_enabled: false,
|
|
1422
|
+
extra_args: config.extra_args
|
|
1423
|
+
});
|
|
1424
|
+
return `exec ${cmd.map(shellQuote).join(" ")}`;
|
|
1631
1425
|
}
|
|
1632
|
-
function
|
|
1633
|
-
const
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1426
|
+
function sendDelayedStartupInput(driver, agent, config, readyDelayMs) {
|
|
1427
|
+
const task = config.task.trim();
|
|
1428
|
+
function sendStartupTask() {
|
|
1429
|
+
pasteTextToPane(driver, agent.tmux_pane_id, task);
|
|
1430
|
+
lastPasteAtByPane.set(agent.tmux_pane_id, Date.now());
|
|
1431
|
+
waitAfterPaste(driver);
|
|
1432
|
+
driver.tmux(["send-keys", "-t", agent.tmux_pane_id, "Enter"]);
|
|
1433
|
+
const current = readAgent(agent.run_id, agent.id);
|
|
1434
|
+
if (!current.ended_at && current.task_status === "queued") {
|
|
1435
|
+
updateAgent(agent.run_id, agent.id, { task_status: "working" });
|
|
1436
|
+
}
|
|
1638
1437
|
}
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
if (value !== "ask" && value !== "skip") throw new Error(`${spec.label} must be ask or skip`);
|
|
1651
|
-
return value;
|
|
1652
|
-
case "language":
|
|
1653
|
-
if (!isLanguageCode(value)) throw new Error(`unknown language: ${String(value)}`);
|
|
1654
|
-
return value;
|
|
1438
|
+
function waitForReadyThenSend(previousOutput = "", waitedMs = 0) {
|
|
1439
|
+
try {
|
|
1440
|
+
if (!paneInSession(driver, agent.tmux_session, agent.tmux_pane_id)) return;
|
|
1441
|
+
const output = driver.tmux(["capture-pane", "-p", "-e", "-S", "-80", "-t", agent.tmux_pane_id]);
|
|
1442
|
+
if (paneLooksReady(output, previousOutput) || waitedMs >= STARTUP_READY_TIMEOUT_MS) {
|
|
1443
|
+
sendStartupTask();
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1446
|
+
driver.delay(() => waitForReadyThenSend(output, waitedMs + STARTUP_READY_POLL_MS), STARTUP_READY_POLL_MS);
|
|
1447
|
+
} catch {
|
|
1448
|
+
}
|
|
1655
1449
|
}
|
|
1450
|
+
if (!task) return;
|
|
1451
|
+
driver.delay(() => waitForReadyThenSend(), readyDelayMs);
|
|
1656
1452
|
}
|
|
1657
|
-
function
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1453
|
+
function newAgentRecord(id, runId, tmuxSession, role, config, workingDir, ids, permissions) {
|
|
1454
|
+
return {
|
|
1455
|
+
id,
|
|
1456
|
+
run_id: runId,
|
|
1457
|
+
nickname: config.nickname || (role === "root" ? providerDisplayName(config.provider) : `${providerDisplayName(config.provider)} agent`),
|
|
1458
|
+
provider: config.provider,
|
|
1459
|
+
model: config.model,
|
|
1460
|
+
role,
|
|
1461
|
+
working_dir: workingDir,
|
|
1462
|
+
task: config.task.trim(),
|
|
1463
|
+
task_status: "queued",
|
|
1464
|
+
task_note: "",
|
|
1465
|
+
tmux_session: tmuxSession,
|
|
1466
|
+
tmux_window_id: ids.windowId,
|
|
1467
|
+
tmux_pane_id: ids.paneId,
|
|
1468
|
+
rc_enabled: false,
|
|
1469
|
+
permissions,
|
|
1470
|
+
inbox: [],
|
|
1471
|
+
last_seen: nowMs(),
|
|
1472
|
+
started_at: nowIso(),
|
|
1473
|
+
ended_at: null
|
|
1474
|
+
};
|
|
1665
1475
|
}
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1476
|
+
function createAgentWindow(runId, tmuxSession, role, config, inheritedWorkingDir, readyDelayMs, driver) {
|
|
1477
|
+
const cfg = loadConfig();
|
|
1478
|
+
const id = randomUUID2();
|
|
1479
|
+
const workingDir = resolveWorkingDir(config.working_dir, inheritedWorkingDir);
|
|
1480
|
+
const permissions = config.permissions ?? cfg.global.default_permissions;
|
|
1481
|
+
const shellCommand = terminalShellCommand(config, permissions);
|
|
1482
|
+
const nickname = config.nickname || providerDisplayName(config.provider);
|
|
1483
|
+
const output = driver.tmux([
|
|
1484
|
+
"new-window",
|
|
1485
|
+
"-d",
|
|
1486
|
+
"-P",
|
|
1487
|
+
"-F",
|
|
1488
|
+
"#{window_id} #{pane_id}",
|
|
1489
|
+
"-t",
|
|
1490
|
+
`${tmuxSession}:`,
|
|
1491
|
+
"-n",
|
|
1492
|
+
tmuxWindowName(config.provider, nickname),
|
|
1493
|
+
"-c",
|
|
1494
|
+
workingDir,
|
|
1495
|
+
shellCommand
|
|
1496
|
+
]);
|
|
1497
|
+
const agent = newAgentRecord(id, runId, tmuxSession, role, config, workingDir, parseTmuxIds(output), permissions);
|
|
1498
|
+
writeAgent(agent);
|
|
1499
|
+
sendDelayedStartupInput(driver, agent, config, readyDelayMs);
|
|
1500
|
+
return agent;
|
|
1672
1501
|
}
|
|
1673
|
-
function
|
|
1674
|
-
|
|
1502
|
+
function validateAgents(configs, available) {
|
|
1503
|
+
for (const config of configs) requireProvider(config.provider, available);
|
|
1675
1504
|
}
|
|
1676
|
-
function
|
|
1677
|
-
|
|
1678
|
-
const
|
|
1679
|
-
|
|
1680
|
-
|
|
1505
|
+
function startRun(request, options = {}) {
|
|
1506
|
+
const cfg = loadConfig();
|
|
1507
|
+
const driver = options.driver ?? realDriver;
|
|
1508
|
+
const available = options.available ?? detectAvailable();
|
|
1509
|
+
const workers = request.workers ?? [];
|
|
1510
|
+
validateAgents([request.root, ...workers], available);
|
|
1511
|
+
const runId = randomUUID2();
|
|
1512
|
+
const readyDelayMs = request.ready_delay_ms ?? cfg.global.ready_delay_ms;
|
|
1513
|
+
const workingDir = resolveWorkingDir(request.working_dir, process.cwd());
|
|
1514
|
+
const reevesAnchor = pickReevesAnchor(driver);
|
|
1515
|
+
const tmuxSession = tmuxRunSessionName(runId, request.name);
|
|
1516
|
+
let createdRunSession = false;
|
|
1681
1517
|
try {
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1518
|
+
createRunSessionWithReevesTab(driver, tmuxSession, reevesAnchor, workingDir);
|
|
1519
|
+
createdRunSession = true;
|
|
1520
|
+
const root = createAgentWindow(runId, tmuxSession, "root", request.root, workingDir, readyDelayMs, driver);
|
|
1521
|
+
const run = {
|
|
1522
|
+
id: runId,
|
|
1523
|
+
name: request.name,
|
|
1524
|
+
status: "running",
|
|
1525
|
+
tmux_session: tmuxSession,
|
|
1526
|
+
reeves_session: reevesAnchor.sessionName,
|
|
1527
|
+
reeves_window_id: reevesAnchor.windowId,
|
|
1528
|
+
reeves_pane_id: reevesAnchor.paneId,
|
|
1529
|
+
root_agent_id: root.id,
|
|
1530
|
+
working_dir: workingDir,
|
|
1531
|
+
preset_name: request.preset_name ?? null,
|
|
1532
|
+
started_at: nowIso(),
|
|
1533
|
+
ended_at: null
|
|
1534
|
+
};
|
|
1535
|
+
writeRun(run);
|
|
1536
|
+
const workerAgents = workers.map((worker) => {
|
|
1537
|
+
return createAgentWindow(runId, tmuxSession, "worker", worker, workingDir, readyDelayMs, driver);
|
|
1538
|
+
});
|
|
1539
|
+
return { run, agents: [root, ...workerAgents] };
|
|
1540
|
+
} catch (err) {
|
|
1541
|
+
if (createdRunSession) {
|
|
1542
|
+
try {
|
|
1543
|
+
driver.tmux(["kill-session", "-t", tmuxSession]);
|
|
1544
|
+
} catch {
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
removeRun(runId);
|
|
1548
|
+
const detail = childProcessOutput(err) || (err instanceof Error ? err.message : "tmux returned a non-zero exit code");
|
|
1549
|
+
throw new Error(`Failed to start run ${request.name}: ${detail}`, { cause: err });
|
|
1685
1550
|
}
|
|
1686
1551
|
}
|
|
1687
|
-
function
|
|
1688
|
-
return value === "default" || value === "low" || value === "medium" || value === "high" || value === "xhigh" || value === "max";
|
|
1689
|
-
}
|
|
1690
|
-
function normalizeSlot(raw, fallbackDir = "") {
|
|
1691
|
-
const promptRaw = typeof raw.initial_prompt === "string" ? raw.initial_prompt : typeof raw.task_template === "string" ? raw.task_template : "";
|
|
1552
|
+
function slotToLaunchConfig(slot) {
|
|
1692
1553
|
return {
|
|
1693
|
-
|
|
1694
|
-
provider:
|
|
1695
|
-
model:
|
|
1696
|
-
auth_mode:
|
|
1697
|
-
effort:
|
|
1698
|
-
|
|
1699
|
-
working_dir:
|
|
1700
|
-
permissions:
|
|
1701
|
-
rc_enabled:
|
|
1554
|
+
nickname: slot.nickname_template,
|
|
1555
|
+
provider: slot.provider,
|
|
1556
|
+
model: slot.model,
|
|
1557
|
+
auth_mode: slot.auth_mode,
|
|
1558
|
+
effort: slot.effort,
|
|
1559
|
+
task: slot.initial_prompt,
|
|
1560
|
+
working_dir: slot.working_dir,
|
|
1561
|
+
permissions: slot.permissions,
|
|
1562
|
+
rc_enabled: slot.rc_enabled
|
|
1702
1563
|
};
|
|
1703
1564
|
}
|
|
1704
|
-
function
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1565
|
+
function startRunFromPreset(presetName, opts = {}, options = {}) {
|
|
1566
|
+
const tree = loadPreset(presetName);
|
|
1567
|
+
if (!tree) throw new Error(`preset not found: ${presetName}`);
|
|
1568
|
+
return startRun({
|
|
1569
|
+
name: opts.name?.trim() || tree.name,
|
|
1570
|
+
working_dir: opts.working_dir || process.cwd(),
|
|
1571
|
+
root: slotToLaunchConfig(tree.root),
|
|
1572
|
+
workers: tree.workers.map(slotToLaunchConfig),
|
|
1573
|
+
preset_name: tree.name
|
|
1574
|
+
}, options);
|
|
1575
|
+
}
|
|
1576
|
+
function createHeadlessHeadAgent(runId, tmuxSession, provider, workingDir) {
|
|
1577
|
+
const cfg = loadConfig();
|
|
1578
|
+
const agent = {
|
|
1579
|
+
id: randomUUID2(),
|
|
1580
|
+
run_id: runId,
|
|
1581
|
+
nickname: providerDisplayName(provider),
|
|
1582
|
+
provider,
|
|
1583
|
+
model: "",
|
|
1584
|
+
role: "root",
|
|
1585
|
+
working_dir: workingDir,
|
|
1586
|
+
task: "",
|
|
1587
|
+
task_status: "working",
|
|
1588
|
+
task_note: "",
|
|
1589
|
+
tmux_session: tmuxSession,
|
|
1590
|
+
tmux_window_id: "",
|
|
1591
|
+
tmux_pane_id: "",
|
|
1592
|
+
rc_enabled: false,
|
|
1593
|
+
permissions: cfg.global.default_permissions,
|
|
1594
|
+
headless: true,
|
|
1595
|
+
inbox: [],
|
|
1596
|
+
last_seen: nowMs(),
|
|
1597
|
+
started_at: nowIso(),
|
|
1598
|
+
ended_at: null
|
|
1718
1599
|
};
|
|
1600
|
+
writeAgent(agent);
|
|
1601
|
+
return agent;
|
|
1719
1602
|
}
|
|
1720
|
-
function
|
|
1721
|
-
const
|
|
1722
|
-
|
|
1603
|
+
function startRunWithHead(headProvider, firstWorker, options = {}) {
|
|
1604
|
+
const cfg = loadConfig();
|
|
1605
|
+
const driver = options.driver ?? realDriver;
|
|
1606
|
+
const available = options.available ?? detectAvailable();
|
|
1607
|
+
validateAgents([firstWorker], available);
|
|
1608
|
+
const runId = randomUUID2();
|
|
1609
|
+
const readyDelayMs = cfg.global.ready_delay_ms;
|
|
1610
|
+
const workingDir = resolveWorkingDir(firstWorker.working_dir, process.cwd());
|
|
1611
|
+
const reevesAnchor = pickReevesAnchor(driver);
|
|
1612
|
+
const tmuxSession = tmuxRunSessionName(runId, providerDisplayName(headProvider));
|
|
1613
|
+
let createdRunSession = false;
|
|
1723
1614
|
try {
|
|
1724
|
-
|
|
1615
|
+
createRunSessionWithReevesTab(driver, tmuxSession, reevesAnchor, workingDir);
|
|
1616
|
+
createdRunSession = true;
|
|
1617
|
+
const head = createHeadlessHeadAgent(runId, tmuxSession, headProvider, workingDir);
|
|
1618
|
+
const run = {
|
|
1619
|
+
id: runId,
|
|
1620
|
+
name: providerDisplayName(headProvider),
|
|
1621
|
+
status: "running",
|
|
1622
|
+
tmux_session: tmuxSession,
|
|
1623
|
+
reeves_session: reevesAnchor.sessionName,
|
|
1624
|
+
reeves_window_id: reevesAnchor.windowId,
|
|
1625
|
+
reeves_pane_id: reevesAnchor.paneId,
|
|
1626
|
+
root_agent_id: head.id,
|
|
1627
|
+
working_dir: workingDir,
|
|
1628
|
+
preset_name: null,
|
|
1629
|
+
started_at: nowIso(),
|
|
1630
|
+
ended_at: null
|
|
1631
|
+
};
|
|
1632
|
+
writeRun(run);
|
|
1633
|
+
const worker = createAgentWindow(runId, tmuxSession, "worker", firstWorker, workingDir, readyDelayMs, driver);
|
|
1634
|
+
return { run, agents: [head, worker] };
|
|
1635
|
+
} catch (err) {
|
|
1636
|
+
if (createdRunSession) {
|
|
1725
1637
|
try {
|
|
1726
|
-
|
|
1638
|
+
driver.tmux(["kill-session", "-t", tmuxSession]);
|
|
1727
1639
|
} catch {
|
|
1728
|
-
return null;
|
|
1729
1640
|
}
|
|
1730
|
-
}
|
|
1731
|
-
|
|
1732
|
-
|
|
1641
|
+
}
|
|
1642
|
+
removeRun(runId);
|
|
1643
|
+
const detail = childProcessOutput(err) || (err instanceof Error ? err.message : "tmux returned a non-zero exit code");
|
|
1644
|
+
throw new Error(`Failed to start run ${providerDisplayName(headProvider)}: ${detail}`, { cause: err });
|
|
1733
1645
|
}
|
|
1734
1646
|
}
|
|
1735
|
-
function
|
|
1647
|
+
function spawnWorker(request, options = {}) {
|
|
1648
|
+
const cfg = loadConfig();
|
|
1649
|
+
const driver = options.driver ?? realDriver;
|
|
1650
|
+
const available = options.available ?? detectAvailable();
|
|
1651
|
+
requireProvider(request.provider, available);
|
|
1652
|
+
const run = readRun(request.run_id);
|
|
1653
|
+
if (run.status === "ended" || run.ended_at) throw new Error(`Run is ended: ${run.id}`);
|
|
1654
|
+
return createAgentWindow(
|
|
1655
|
+
run.id,
|
|
1656
|
+
run.tmux_session,
|
|
1657
|
+
"worker",
|
|
1658
|
+
request,
|
|
1659
|
+
run.working_dir,
|
|
1660
|
+
request.ready_delay_ms ?? cfg.global.ready_delay_ms,
|
|
1661
|
+
driver
|
|
1662
|
+
);
|
|
1663
|
+
}
|
|
1664
|
+
function openReeves(runId, options = {}) {
|
|
1665
|
+
const driver = options.driver ?? realDriver;
|
|
1666
|
+
const run = readRun(runId);
|
|
1667
|
+
const reevesSession = run.reeves_session ?? run.tmux_session;
|
|
1668
|
+
if (!run.reeves_window_id || !windowInSession(driver, reevesSession, run.reeves_window_id)) {
|
|
1669
|
+
throw new Error("Reeves TUI window is unavailable for this run");
|
|
1670
|
+
}
|
|
1671
|
+
const target = `${reevesSession}:${run.reeves_window_id}`;
|
|
1736
1672
|
try {
|
|
1737
|
-
|
|
1673
|
+
driver.tmux(["switch-client", "-t", target]);
|
|
1738
1674
|
} catch {
|
|
1739
|
-
return null;
|
|
1740
1675
|
}
|
|
1676
|
+
driver.tmux(["select-window", "-t", target]);
|
|
1741
1677
|
}
|
|
1742
|
-
function
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1678
|
+
function openRunTabs(runId, options = {}) {
|
|
1679
|
+
const driver = options.driver ?? realDriver;
|
|
1680
|
+
const run = readRun(runId);
|
|
1681
|
+
const target = `${run.tmux_session}:reeves`;
|
|
1746
1682
|
try {
|
|
1747
|
-
|
|
1683
|
+
driver.tmux(["switch-client", "-t", target]);
|
|
1748
1684
|
} catch {
|
|
1749
1685
|
}
|
|
1686
|
+
driver.tmux(["select-window", "-t", target]);
|
|
1750
1687
|
}
|
|
1751
|
-
function
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
working_dir: agent.working_dir,
|
|
1763
|
-
permissions: agent.permissions,
|
|
1764
|
-
rc_enabled: agent.rc_enabled
|
|
1765
|
-
};
|
|
1766
|
-
}
|
|
1767
|
-
function savePresetFromRun(runId, name, description = "") {
|
|
1768
|
-
const presetName = sanitizePresetName(name);
|
|
1769
|
-
if (!presetName) throw new Error("preset name is required");
|
|
1770
|
-
const run = readRun(runId);
|
|
1771
|
-
const agents = listAgents(run.id).filter((agent) => !agent.headless);
|
|
1772
|
-
if (agents.length === 0) throw new Error("run has no agents to save as a preset");
|
|
1773
|
-
const root = agents.find((agent) => agent.role === "root") ?? agents[0];
|
|
1774
|
-
const workers = agents.filter((agent) => agent !== root);
|
|
1775
|
-
const existing = loadPreset(presetName);
|
|
1776
|
-
const now = nowIso();
|
|
1777
|
-
const tree = {
|
|
1778
|
-
name: presetName,
|
|
1779
|
-
description,
|
|
1780
|
-
root: agentToSlot(root),
|
|
1781
|
-
workers: workers.map(agentToSlot),
|
|
1782
|
-
created_at: existing?.created_at ?? now,
|
|
1783
|
-
updated_at: now
|
|
1784
|
-
};
|
|
1785
|
-
savePreset(tree);
|
|
1786
|
-
return tree;
|
|
1688
|
+
function openAgent(agentId, options = {}) {
|
|
1689
|
+
const driver = options.driver ?? realDriver;
|
|
1690
|
+
const agent = findAgent(agentId);
|
|
1691
|
+
if (agent.headless || !agent.tmux_window_id) throw new Error("This agent is headless - no tmux window exists");
|
|
1692
|
+
if (!windowInSession(driver, agent.tmux_session, agent.tmux_window_id)) throw new Error(STALE_WINDOW_ERROR);
|
|
1693
|
+
const target = `${agent.tmux_session}:${agent.tmux_window_id}`;
|
|
1694
|
+
try {
|
|
1695
|
+
driver.tmux(["switch-client", "-t", target]);
|
|
1696
|
+
} catch {
|
|
1697
|
+
}
|
|
1698
|
+
driver.tmux(["select-window", "-t", target]);
|
|
1787
1699
|
}
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1700
|
+
function peekAgent(agentId, lines = 10, options = {}) {
|
|
1701
|
+
const driver = options.driver ?? realDriver;
|
|
1702
|
+
const n = Number.isFinite(lines) && lines > 0 ? Math.floor(lines) : 10;
|
|
1703
|
+
try {
|
|
1704
|
+
const agent = findAgent(agentId);
|
|
1705
|
+
if (agent.headless || !agent.tmux_pane_id) return "(headless agent - no output)";
|
|
1706
|
+
if (!paneInSession(driver, agent.tmux_session, agent.tmux_pane_id)) return "";
|
|
1707
|
+
let output = driver.tmux(["capture-pane", "-p", "-e", "-S", String(-n), "-t", agent.tmux_pane_id]);
|
|
1708
|
+
if (!output.trim()) {
|
|
1709
|
+
try {
|
|
1710
|
+
output = driver.tmux(["capture-pane", "-p", "-e", "-a", "-S", String(-n), "-t", agent.tmux_pane_id]);
|
|
1711
|
+
} catch {
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
return redactSecrets(stripAnsi(output).trim());
|
|
1715
|
+
} catch {
|
|
1716
|
+
return "";
|
|
1717
|
+
}
|
|
1802
1718
|
}
|
|
1803
|
-
function
|
|
1804
|
-
|
|
1805
|
-
const
|
|
1806
|
-
if (!
|
|
1807
|
-
if (
|
|
1808
|
-
|
|
1719
|
+
function sendText(agentId, text, options = {}) {
|
|
1720
|
+
const driver = options.driver ?? realDriver;
|
|
1721
|
+
const agent = findAgent(agentId);
|
|
1722
|
+
if (agent.headless || !agent.tmux_pane_id) throw new Error("This agent is headless - no tmux pane exists");
|
|
1723
|
+
if (!paneInSession(driver, agent.tmux_session, agent.tmux_pane_id)) throw new Error(STALE_WINDOW_ERROR);
|
|
1724
|
+
pasteTextToPane(driver, agent.tmux_pane_id, text);
|
|
1725
|
+
lastPasteAtByPane.set(agent.tmux_pane_id, Date.now());
|
|
1726
|
+
if (!agent.ended_at && agent.task_status === "queued") updateAgent(agent.run_id, agent.id, { task_status: "working" });
|
|
1809
1727
|
}
|
|
1810
|
-
function
|
|
1811
|
-
|
|
1728
|
+
function tmuxKey(key) {
|
|
1729
|
+
if (key === "enter") return "Enter";
|
|
1730
|
+
if (key === "escape") return "Escape";
|
|
1731
|
+
if (key === "backspace") return "BSpace";
|
|
1732
|
+
if (key === "tab") return "Tab";
|
|
1733
|
+
if (key === "space") return "Space";
|
|
1734
|
+
if (key === "up") return "Up";
|
|
1735
|
+
if (key === "down") return "Down";
|
|
1736
|
+
if (key === "left") return "Left";
|
|
1737
|
+
if (key === "right") return "Right";
|
|
1738
|
+
return "C-c";
|
|
1812
1739
|
}
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
"
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
"
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
var realDriver = {
|
|
1828
|
-
tmux(args, input) {
|
|
1829
|
-
return execFileSync4("tmux", args, {
|
|
1830
|
-
encoding: "utf8",
|
|
1831
|
-
input,
|
|
1832
|
-
stdio: input === void 0 ? ["ignore", "pipe", "pipe"] : ["pipe", "pipe", "pipe"]
|
|
1833
|
-
}).trim();
|
|
1834
|
-
},
|
|
1835
|
-
delay(fn, ms) {
|
|
1836
|
-
setTimeout(fn, ms);
|
|
1740
|
+
function sendKey(agentId, key, options = {}) {
|
|
1741
|
+
const driver = options.driver ?? realDriver;
|
|
1742
|
+
const agent = findAgent(agentId);
|
|
1743
|
+
if (agent.headless || !agent.tmux_pane_id) throw new Error("This agent is headless - no tmux pane exists");
|
|
1744
|
+
if (!ALLOWED_KEYS.includes(key)) throw new Error(`Unsupported key: ${String(key)}`);
|
|
1745
|
+
if (!paneInSession(driver, agent.tmux_session, agent.tmux_pane_id)) throw new Error(STALE_WINDOW_ERROR);
|
|
1746
|
+
if (key === "enter") {
|
|
1747
|
+
const lastPasteAt = lastPasteAtByPane.get(agent.tmux_pane_id) ?? 0;
|
|
1748
|
+
const remaining = POST_PASTE_ENTER_DELAY_MS - (Date.now() - lastPasteAt);
|
|
1749
|
+
if (remaining > 0) {
|
|
1750
|
+
if (driver === realDriver) sleepSync2(remaining);
|
|
1751
|
+
else driver.delay(() => {
|
|
1752
|
+
}, remaining);
|
|
1753
|
+
}
|
|
1837
1754
|
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
var STARTUP_READY_POLL_MS = 1e3;
|
|
1841
|
-
var STARTUP_READY_TIMEOUT_MS = 2e4;
|
|
1842
|
-
var lastPasteAtByPane = /* @__PURE__ */ new Map();
|
|
1843
|
-
function sleepSync2(ms) {
|
|
1844
|
-
const buffer = new SharedArrayBuffer(4);
|
|
1845
|
-
const view = new Int32Array(buffer);
|
|
1846
|
-
Atomics.wait(view, 0, 0, ms);
|
|
1755
|
+
driver.tmux(["send-keys", "-t", agent.tmux_pane_id, tmuxKey(key)]);
|
|
1756
|
+
if (!agent.ended_at && agent.task_status === "queued") updateAgent(agent.run_id, agent.id, { task_status: "working" });
|
|
1847
1757
|
}
|
|
1848
|
-
function
|
|
1849
|
-
|
|
1850
|
-
else driver.delay(() => {
|
|
1851
|
-
}, POST_PASTE_ENTER_DELAY_MS);
|
|
1758
|
+
function interrupt(agentId, options = {}) {
|
|
1759
|
+
sendKey(agentId, "ctrl-c", options);
|
|
1852
1760
|
}
|
|
1853
|
-
function
|
|
1854
|
-
|
|
1761
|
+
function killAgent(agentId, options = {}) {
|
|
1762
|
+
const driver = options.driver ?? realDriver;
|
|
1763
|
+
const agent = findAgent(agentId);
|
|
1764
|
+
const run = readRun(agent.run_id);
|
|
1765
|
+
if (windowInSession(driver, agent.tmux_session, agent.tmux_window_id)) {
|
|
1766
|
+
try {
|
|
1767
|
+
driver.tmux(["kill-window", "-t", agent.tmux_window_id]);
|
|
1768
|
+
} catch {
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
const endedAt = nowIso();
|
|
1772
|
+
updateAgent(agent.run_id, agent.id, { ended_at: endedAt, task_status: "done" });
|
|
1773
|
+
const updatedAgent = readAgent(agent.run_id, agent.id);
|
|
1774
|
+
const endedRun = endRunIfNoLiveAgents(agent.run_id, endedAt);
|
|
1775
|
+
if (endedRun.status === "ended" || endedRun.ended_at !== null) {
|
|
1776
|
+
const runOwnsSession = !!run.reeves_session && run.reeves_session !== run.tmux_session;
|
|
1777
|
+
if (runOwnsSession) {
|
|
1778
|
+
try {
|
|
1779
|
+
driver.tmux(["kill-session", "-t", `=${run.tmux_session}`]);
|
|
1780
|
+
} catch {
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
archiveAndRemoveRun(run.id, "ended");
|
|
1784
|
+
}
|
|
1785
|
+
return updatedAgent;
|
|
1855
1786
|
}
|
|
1856
|
-
function
|
|
1857
|
-
const
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
if (
|
|
1862
|
-
|
|
1787
|
+
function stopRun(runId, options = {}) {
|
|
1788
|
+
const driver = options.driver ?? realDriver;
|
|
1789
|
+
const run = readRun(runId);
|
|
1790
|
+
const endedAt = nowIso();
|
|
1791
|
+
const runOwnsSession = !!run.reeves_session && run.reeves_session !== run.tmux_session;
|
|
1792
|
+
if (runOwnsSession) {
|
|
1793
|
+
try {
|
|
1794
|
+
driver.tmux(["kill-session", "-t", `=${run.tmux_session}`]);
|
|
1795
|
+
} catch {
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
for (const agent of listAgents(run.id)) {
|
|
1799
|
+
if (agent.ended_at) continue;
|
|
1800
|
+
if (!runOwnsSession && windowInSession(driver, agent.tmux_session, agent.tmux_window_id)) {
|
|
1801
|
+
try {
|
|
1802
|
+
driver.tmux(["kill-window", "-t", agent.tmux_window_id]);
|
|
1803
|
+
} catch {
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
updateAgent(run.id, agent.id, { ended_at: endedAt });
|
|
1807
|
+
}
|
|
1808
|
+
const endedRun = { ...run, status: "ended", ended_at: endedAt };
|
|
1809
|
+
updateRun(run.id, { status: endedRun.status, ended_at: endedRun.ended_at });
|
|
1810
|
+
archiveAndRemoveRun(run.id, "ended");
|
|
1811
|
+
return endedRun;
|
|
1863
1812
|
}
|
|
1864
|
-
function
|
|
1865
|
-
const
|
|
1866
|
-
|
|
1813
|
+
function openTmuxTarget(id, options = {}) {
|
|
1814
|
+
const driver = options.driver ?? realDriver;
|
|
1815
|
+
let session;
|
|
1816
|
+
let window;
|
|
1817
|
+
let label;
|
|
1867
1818
|
try {
|
|
1868
|
-
|
|
1869
|
-
|
|
1819
|
+
const run = readRun(id);
|
|
1820
|
+
session = run.tmux_session;
|
|
1821
|
+
window = "reeves";
|
|
1822
|
+
label = run.name;
|
|
1823
|
+
} catch {
|
|
1870
1824
|
try {
|
|
1871
|
-
|
|
1825
|
+
const agent = findAgent(id);
|
|
1826
|
+
session = agent.tmux_session;
|
|
1827
|
+
window = agent.tmux_window_id;
|
|
1828
|
+
label = agent.nickname;
|
|
1872
1829
|
} catch {
|
|
1830
|
+
throw new Error(`no run or agent found: ${id}`);
|
|
1873
1831
|
}
|
|
1832
|
+
if (!windowInSession(driver, session, window)) throw new Error(STALE_WINDOW_ERROR);
|
|
1874
1833
|
}
|
|
1875
|
-
}
|
|
1876
|
-
var STALE_WINDOW_ERROR = "agent window no longer exists (tmux server may have restarted)";
|
|
1877
|
-
function windowInSession(driver, session, windowId) {
|
|
1878
|
-
if (!session || !windowId) return false;
|
|
1834
|
+
const target = `${session}:${window}`;
|
|
1879
1835
|
try {
|
|
1880
|
-
|
|
1836
|
+
driver.tmux(["switch-client", "-t", target]);
|
|
1881
1837
|
} catch {
|
|
1882
|
-
return false;
|
|
1883
1838
|
}
|
|
1884
|
-
}
|
|
1885
|
-
function paneInSession(driver, session, paneId) {
|
|
1886
|
-
if (!session || !paneId) return false;
|
|
1887
1839
|
try {
|
|
1888
|
-
|
|
1840
|
+
driver.tmux(["select-window", "-t", target]);
|
|
1889
1841
|
} catch {
|
|
1890
|
-
return false;
|
|
1891
1842
|
}
|
|
1843
|
+
return { session, window, label };
|
|
1892
1844
|
}
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
}
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1845
|
+
|
|
1846
|
+
// src/surfaces/mcp/installer.ts
|
|
1847
|
+
import { execFileSync as execFileSync3 } from "child_process";
|
|
1848
|
+
import { realpathSync, readFileSync as readFileSync4, writeFileSync as writeFileSync4, existsSync as existsSync4, mkdirSync as mkdirSync4 } from "fs";
|
|
1849
|
+
import { homedir as homedir4 } from "os";
|
|
1850
|
+
import { join as join5, dirname as dirname4 } from "path";
|
|
1851
|
+
var SERVER_NAME = "reevesagents";
|
|
1852
|
+
var SERVER_BIN = "reevesagents";
|
|
1853
|
+
var SERVER_ARG = "mcp";
|
|
1854
|
+
var MGMT_TIMEOUT_MS = 15e3;
|
|
1855
|
+
var STATUS_TIMEOUT_MS = 2e4;
|
|
1856
|
+
var VERIFY_TIMEOUT_MS = 2e4;
|
|
1857
|
+
function opencodeConfigPath() {
|
|
1858
|
+
const base = process.env.REEVES_HOME || homedir4();
|
|
1859
|
+
const dir = join5(base, ".config", "opencode");
|
|
1860
|
+
const jsonc = join5(dir, "opencode.jsonc");
|
|
1861
|
+
const json = join5(dir, "opencode.json");
|
|
1862
|
+
if (existsSync4(json)) return json;
|
|
1863
|
+
if (existsSync4(jsonc)) return jsonc;
|
|
1864
|
+
return json;
|
|
1902
1865
|
}
|
|
1903
|
-
function
|
|
1904
|
-
if (
|
|
1905
|
-
const
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
const stdout = Buffer.isBuffer(maybe.stdout) ? maybe.stdout.toString("utf8").trim() : "";
|
|
1909
|
-
return stdout;
|
|
1866
|
+
function readOpencodeConfig(path) {
|
|
1867
|
+
if (!existsSync4(path)) return {};
|
|
1868
|
+
const raw = readFileSync4(path, "utf-8").trim();
|
|
1869
|
+
if (!raw) return {};
|
|
1870
|
+
return JSON.parse(raw);
|
|
1910
1871
|
}
|
|
1911
|
-
function
|
|
1912
|
-
|
|
1913
|
-
if (!windowId?.startsWith("@") || !paneId?.startsWith("%")) {
|
|
1914
|
-
throw new Error(`Could not parse tmux ids from: ${output}`);
|
|
1915
|
-
}
|
|
1916
|
-
return { windowId, paneId };
|
|
1872
|
+
function opencodeMcpEntry(cmd) {
|
|
1873
|
+
return { type: "local", command: [cmd.command, ...cmd.args], enabled: true };
|
|
1917
1874
|
}
|
|
1918
|
-
function
|
|
1875
|
+
function opencodeAttached() {
|
|
1919
1876
|
try {
|
|
1920
|
-
const
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
return parseTmuxIds(driver.tmux(args));
|
|
1877
|
+
const cfg = readOpencodeConfig(opencodeConfigPath());
|
|
1878
|
+
const mcp = cfg.mcp;
|
|
1879
|
+
return !!mcp && typeof mcp === "object" && SERVER_NAME in mcp;
|
|
1924
1880
|
} catch {
|
|
1925
|
-
return
|
|
1881
|
+
return false;
|
|
1926
1882
|
}
|
|
1927
1883
|
}
|
|
1928
|
-
function
|
|
1929
|
-
|
|
1930
|
-
|
|
1884
|
+
function opencodeAttach(cmd) {
|
|
1885
|
+
const path = opencodeConfigPath();
|
|
1886
|
+
const cfg = readOpencodeConfig(path);
|
|
1887
|
+
if (!cfg.$schema) cfg.$schema = "https://opencode.ai/config.json";
|
|
1888
|
+
const mcp = typeof cfg.mcp === "object" && cfg.mcp !== null ? cfg.mcp : {};
|
|
1889
|
+
mcp[SERVER_NAME] = opencodeMcpEntry(cmd);
|
|
1890
|
+
cfg.mcp = mcp;
|
|
1891
|
+
mkdirSync4(dirname4(path), { recursive: true });
|
|
1892
|
+
writeFileSync4(path, `${JSON.stringify(cfg, null, 2)}
|
|
1893
|
+
`, "utf-8");
|
|
1931
1894
|
}
|
|
1932
|
-
function
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
}
|
|
1895
|
+
function opencodeDetach() {
|
|
1896
|
+
const path = opencodeConfigPath();
|
|
1897
|
+
if (!existsSync4(path)) return;
|
|
1898
|
+
const cfg = readOpencodeConfig(path);
|
|
1899
|
+
const mcp = cfg.mcp;
|
|
1900
|
+
if (mcp && SERVER_NAME in mcp) {
|
|
1901
|
+
delete mcp[SERVER_NAME];
|
|
1902
|
+
writeFileSync4(path, `${JSON.stringify(cfg, null, 2)}
|
|
1903
|
+
`, "utf-8");
|
|
1942
1904
|
}
|
|
1943
|
-
|
|
1905
|
+
}
|
|
1906
|
+
function kimiCodeHome() {
|
|
1907
|
+
if (process.env.REEVES_HOME) return join5(process.env.REEVES_HOME, ".kimi-code");
|
|
1908
|
+
return process.env.KIMI_CODE_HOME || join5(homedir4(), ".kimi-code");
|
|
1909
|
+
}
|
|
1910
|
+
function isKimiCode(bin) {
|
|
1944
1911
|
try {
|
|
1945
|
-
|
|
1912
|
+
const out = execFileSync3(bin, ["--version"], {
|
|
1913
|
+
encoding: "utf8",
|
|
1914
|
+
timeout: STATUS_TIMEOUT_MS,
|
|
1915
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1916
|
+
}).trim();
|
|
1917
|
+
return out !== "" && !/^kimi,/i.test(out);
|
|
1946
1918
|
} catch {
|
|
1919
|
+
return false;
|
|
1947
1920
|
}
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1921
|
+
}
|
|
1922
|
+
function kimiCodePluginAttached() {
|
|
1923
|
+
try {
|
|
1924
|
+
const installed = JSON.parse(readFileSync4(join5(kimiCodeHome(), "plugins", "installed.json"), "utf-8"));
|
|
1925
|
+
return Array.isArray(installed.plugins) && installed.plugins.some((p) => p.id === SERVER_NAME && p.enabled !== false);
|
|
1926
|
+
} catch {
|
|
1927
|
+
return false;
|
|
1955
1928
|
}
|
|
1956
|
-
return { sessionName: fallbackName, windowId: ids?.windowId ?? "", paneId: ids?.paneId ?? "" };
|
|
1957
1929
|
}
|
|
1958
|
-
function
|
|
1959
|
-
driver.tmux(["new-session", "-d", "-s", tmuxSession, "-n", "reeves", "-c", workingDir]);
|
|
1960
|
-
const source = reevesAnchor.windowId || `${reevesAnchor.sessionName}:reeves`;
|
|
1930
|
+
function kimiCodeMcpConfig() {
|
|
1961
1931
|
try {
|
|
1962
|
-
|
|
1932
|
+
const raw = readFileSync4(join5(kimiCodeHome(), "mcp.json"), "utf-8").trim();
|
|
1933
|
+
return raw ? JSON.parse(raw) : {};
|
|
1963
1934
|
} catch {
|
|
1935
|
+
return {};
|
|
1964
1936
|
}
|
|
1965
1937
|
}
|
|
1966
|
-
function
|
|
1967
|
-
const
|
|
1968
|
-
|
|
1969
|
-
permissions,
|
|
1970
|
-
model: config.model,
|
|
1971
|
-
auth_mode: config.auth_mode,
|
|
1972
|
-
effort: config.effort,
|
|
1973
|
-
rc_enabled: false,
|
|
1974
|
-
extra_args: config.extra_args
|
|
1975
|
-
});
|
|
1976
|
-
return `exec ${cmd.map(shellQuote).join(" ")}`;
|
|
1938
|
+
function kimiCodeMcpAttached() {
|
|
1939
|
+
const servers = kimiCodeMcpConfig().mcpServers;
|
|
1940
|
+
return !!servers && typeof servers === "object" && SERVER_NAME in servers;
|
|
1977
1941
|
}
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1942
|
+
var KIMI_CODE_FILE_OPS = {
|
|
1943
|
+
attached: () => kimiCodePluginAttached() || kimiCodeMcpAttached(),
|
|
1944
|
+
attach: (cmd) => {
|
|
1945
|
+
if (kimiCodePluginAttached()) return;
|
|
1946
|
+
const path = join5(kimiCodeHome(), "mcp.json");
|
|
1947
|
+
const cfg = kimiCodeMcpConfig();
|
|
1948
|
+
const servers = typeof cfg.mcpServers === "object" && cfg.mcpServers !== null ? cfg.mcpServers : {};
|
|
1949
|
+
servers[SERVER_NAME] = { command: cmd.command, args: cmd.args };
|
|
1950
|
+
cfg.mcpServers = servers;
|
|
1951
|
+
mkdirSync4(dirname4(path), { recursive: true });
|
|
1952
|
+
writeFileSync4(path, `${JSON.stringify(cfg, null, 2)}
|
|
1953
|
+
`, "utf-8");
|
|
1954
|
+
},
|
|
1955
|
+
detach: () => {
|
|
1956
|
+
const path = join5(kimiCodeHome(), "mcp.json");
|
|
1957
|
+
if (!existsSync4(path)) return;
|
|
1958
|
+
const cfg = kimiCodeMcpConfig();
|
|
1959
|
+
const servers = cfg.mcpServers;
|
|
1960
|
+
if (servers && SERVER_NAME in servers) {
|
|
1961
|
+
delete servers[SERVER_NAME];
|
|
1962
|
+
writeFileSync4(path, `${JSON.stringify(cfg, null, 2)}
|
|
1963
|
+
`, "utf-8");
|
|
1988
1964
|
}
|
|
1989
1965
|
}
|
|
1990
|
-
|
|
1966
|
+
};
|
|
1967
|
+
function resolveLaunchCmd(entry = process.argv[1]) {
|
|
1968
|
+
if (entry) {
|
|
1991
1969
|
try {
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
if (paneLooksReady(output, previousOutput) || waitedMs >= STARTUP_READY_TIMEOUT_MS) {
|
|
1995
|
-
sendStartupTask();
|
|
1996
|
-
return;
|
|
1997
|
-
}
|
|
1998
|
-
driver.delay(() => waitForReadyThenSend(output, waitedMs + STARTUP_READY_POLL_MS), STARTUP_READY_POLL_MS);
|
|
1970
|
+
const real = realpathSync(entry);
|
|
1971
|
+
if (/\.[cm]?js$/.test(real)) return { command: process.execPath, args: [real, SERVER_ARG] };
|
|
1999
1972
|
} catch {
|
|
2000
1973
|
}
|
|
2001
1974
|
}
|
|
2002
|
-
|
|
2003
|
-
|
|
1975
|
+
try {
|
|
1976
|
+
const abs = execFileSync3("which", [SERVER_BIN], { encoding: "utf8" }).trim();
|
|
1977
|
+
if (abs) return { command: abs, args: [SERVER_ARG] };
|
|
1978
|
+
} catch {
|
|
1979
|
+
}
|
|
1980
|
+
return { command: SERVER_BIN, args: [SERVER_ARG] };
|
|
2004
1981
|
}
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
1982
|
+
var HOSTS = [
|
|
1983
|
+
{
|
|
1984
|
+
provider: "cc",
|
|
1985
|
+
// Claude Code defaults a new server to `local` (this directory only); pin
|
|
1986
|
+
// `user` so one attach covers every project on the machine.
|
|
1987
|
+
add: (cmd) => ["mcp", "add", SERVER_NAME, "-s", "user", "--", cmd.command, ...cmd.args],
|
|
1988
|
+
remove: ["mcp", "remove", SERVER_NAME],
|
|
1989
|
+
list: ["mcp", "list"]
|
|
1990
|
+
},
|
|
1991
|
+
{
|
|
1992
|
+
provider: "codex",
|
|
1993
|
+
add: (cmd) => ["mcp", "add", SERVER_NAME, "--", cmd.command, ...cmd.args],
|
|
1994
|
+
remove: ["mcp", "remove", SERVER_NAME],
|
|
1995
|
+
list: ["mcp", "list"]
|
|
1996
|
+
},
|
|
1997
|
+
{
|
|
1998
|
+
provider: "kimi",
|
|
1999
|
+
add: (cmd) => ["mcp", "add", SERVER_NAME, "--", cmd.command, ...cmd.args],
|
|
2000
|
+
remove: ["mcp", "remove", SERVER_NAME],
|
|
2001
|
+
list: ["mcp", "list"]
|
|
2002
|
+
},
|
|
2003
|
+
{
|
|
2004
|
+
provider: "qwen",
|
|
2005
|
+
// qwen (a gemini-cli fork) takes `<commandOrUrl> [args...]` with no `--`
|
|
2006
|
+
// separator, and already defaults its scope to `user`.
|
|
2007
|
+
add: (cmd) => ["mcp", "add", SERVER_NAME, cmd.command, ...cmd.args],
|
|
2008
|
+
remove: ["mcp", "remove", SERVER_NAME],
|
|
2009
|
+
list: ["mcp", "list"]
|
|
2010
|
+
},
|
|
2011
|
+
{
|
|
2012
|
+
provider: "hermes",
|
|
2013
|
+
// hermes takes --command and a variadic --args, so the entry path and `mcp`
|
|
2014
|
+
// both ride on one --args.
|
|
2015
|
+
add: (cmd) => ["mcp", "add", SERVER_NAME, "--command", cmd.command, "--args", ...cmd.args],
|
|
2016
|
+
remove: ["mcp", "remove", SERVER_NAME],
|
|
2017
|
+
list: ["mcp", "list"]
|
|
2018
|
+
},
|
|
2019
|
+
{
|
|
2020
|
+
// opencode's `mcp add` prompts interactively for a local server's command, so
|
|
2021
|
+
// we attach it by writing its config JSON directly instead.
|
|
2022
|
+
provider: "opencode",
|
|
2023
|
+
list: ["mcp", "list"],
|
|
2024
|
+
file: { attach: opencodeAttach, detach: opencodeDetach, attached: opencodeAttached }
|
|
2025
|
+
}
|
|
2026
|
+
];
|
|
2027
|
+
function hostBin(host) {
|
|
2028
|
+
return PROVIDER_REGISTRY[host.provider].bin;
|
|
2027
2029
|
}
|
|
2028
|
-
function
|
|
2029
|
-
|
|
2030
|
-
const id = randomUUID2();
|
|
2031
|
-
const workingDir = resolveWorkingDir(config.working_dir, inheritedWorkingDir);
|
|
2032
|
-
const permissions = config.permissions ?? cfg.global.default_permissions;
|
|
2033
|
-
const shellCommand = terminalShellCommand(config, permissions);
|
|
2034
|
-
const nickname = config.nickname || providerDisplayName(config.provider);
|
|
2035
|
-
const output = driver.tmux([
|
|
2036
|
-
"new-window",
|
|
2037
|
-
"-d",
|
|
2038
|
-
"-P",
|
|
2039
|
-
"-F",
|
|
2040
|
-
"#{window_id} #{pane_id}",
|
|
2041
|
-
"-t",
|
|
2042
|
-
`${tmuxSession}:`,
|
|
2043
|
-
"-n",
|
|
2044
|
-
tmuxWindowName(config.provider, nickname),
|
|
2045
|
-
"-c",
|
|
2046
|
-
workingDir,
|
|
2047
|
-
shellCommand
|
|
2048
|
-
]);
|
|
2049
|
-
const agent = newAgentRecord(id, runId, tmuxSession, role, config, workingDir, parseTmuxIds(output), permissions);
|
|
2050
|
-
writeAgent(agent);
|
|
2051
|
-
sendDelayedStartupInput(driver, agent, config, readyDelayMs);
|
|
2052
|
-
return agent;
|
|
2030
|
+
function hostLabel(host) {
|
|
2031
|
+
return PROVIDER_REGISTRY[host.provider].displayName;
|
|
2053
2032
|
}
|
|
2054
|
-
function
|
|
2055
|
-
|
|
2033
|
+
function hostFileOps(host) {
|
|
2034
|
+
if (host.file) return host.file;
|
|
2035
|
+
if (host.provider === "kimi" && isKimiCode(hostBin(host))) return KIMI_CODE_FILE_OPS;
|
|
2036
|
+
return void 0;
|
|
2056
2037
|
}
|
|
2057
|
-
function
|
|
2058
|
-
const cfg = loadConfig();
|
|
2059
|
-
const driver = options.driver ?? realDriver;
|
|
2060
|
-
const available = options.available ?? detectAvailable();
|
|
2061
|
-
const workers = request.workers ?? [];
|
|
2062
|
-
validateAgents([request.root, ...workers], available);
|
|
2063
|
-
const runId = randomUUID2();
|
|
2064
|
-
const readyDelayMs = request.ready_delay_ms ?? cfg.global.ready_delay_ms;
|
|
2065
|
-
const workingDir = resolveWorkingDir(request.working_dir, process.cwd());
|
|
2066
|
-
const reevesAnchor = pickReevesAnchor(driver);
|
|
2067
|
-
const tmuxSession = tmuxRunSessionName(runId, request.name);
|
|
2068
|
-
let createdRunSession = false;
|
|
2038
|
+
function isInstalled(bin) {
|
|
2069
2039
|
try {
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
working_dir: workingDir,
|
|
2083
|
-
preset_name: request.preset_name ?? null,
|
|
2084
|
-
started_at: nowIso(),
|
|
2085
|
-
ended_at: null
|
|
2086
|
-
};
|
|
2087
|
-
writeRun(run);
|
|
2088
|
-
const workerAgents = workers.map((worker) => {
|
|
2089
|
-
return createAgentWindow(runId, tmuxSession, "worker", worker, workingDir, readyDelayMs, driver);
|
|
2040
|
+
execFileSync3("which", [bin], { stdio: "pipe" });
|
|
2041
|
+
return true;
|
|
2042
|
+
} catch {
|
|
2043
|
+
return false;
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
function isAttached(host) {
|
|
2047
|
+
try {
|
|
2048
|
+
const out = execFileSync3(hostBin(host), host.list, {
|
|
2049
|
+
encoding: "utf8",
|
|
2050
|
+
timeout: STATUS_TIMEOUT_MS,
|
|
2051
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
2090
2052
|
});
|
|
2091
|
-
return
|
|
2092
|
-
} catch
|
|
2093
|
-
|
|
2094
|
-
try {
|
|
2095
|
-
driver.tmux(["kill-session", "-t", tmuxSession]);
|
|
2096
|
-
} catch {
|
|
2097
|
-
}
|
|
2098
|
-
}
|
|
2099
|
-
removeRun(runId);
|
|
2100
|
-
const detail = childProcessOutput(err) || (err instanceof Error ? err.message : "tmux returned a non-zero exit code");
|
|
2101
|
-
throw new Error(`Failed to start run ${request.name}: ${detail}`, { cause: err });
|
|
2053
|
+
return /reevesagents(?![-\w])/i.test(out);
|
|
2054
|
+
} catch {
|
|
2055
|
+
return false;
|
|
2102
2056
|
}
|
|
2103
2057
|
}
|
|
2104
|
-
function
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
};
|
|
2058
|
+
function runHostCommand(host, args) {
|
|
2059
|
+
execFileSync3(hostBin(host), args, {
|
|
2060
|
+
encoding: "utf8",
|
|
2061
|
+
timeout: MGMT_TIMEOUT_MS,
|
|
2062
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
2063
|
+
});
|
|
2064
|
+
}
|
|
2065
|
+
function cliError(err) {
|
|
2066
|
+
const stderr = err && typeof err === "object" ? err.stderr : void 0;
|
|
2067
|
+
const text = typeof stderr === "string" ? stderr.trim() : Buffer.isBuffer(stderr) ? stderr.toString("utf8").trim() : "";
|
|
2068
|
+
return text || (err instanceof Error ? err.message : String(err));
|
|
2116
2069
|
}
|
|
2117
|
-
function
|
|
2118
|
-
const
|
|
2119
|
-
if (!
|
|
2120
|
-
return
|
|
2121
|
-
name: opts.name?.trim() || tree.name,
|
|
2122
|
-
working_dir: opts.working_dir || process.cwd(),
|
|
2123
|
-
root: slotToLaunchConfig(tree.root),
|
|
2124
|
-
workers: tree.workers.map(slotToLaunchConfig),
|
|
2125
|
-
preset_name: tree.name
|
|
2126
|
-
}, options);
|
|
2070
|
+
function findHost(key) {
|
|
2071
|
+
const host = HOSTS.find((item) => item.provider === key);
|
|
2072
|
+
if (!host) throw new Error(`Unknown CLI: ${key}`);
|
|
2073
|
+
return host;
|
|
2127
2074
|
}
|
|
2128
|
-
function
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
tmux_session: tmuxSession,
|
|
2142
|
-
tmux_window_id: "",
|
|
2143
|
-
tmux_pane_id: "",
|
|
2144
|
-
rc_enabled: false,
|
|
2145
|
-
permissions: cfg.global.default_permissions,
|
|
2146
|
-
headless: true,
|
|
2147
|
-
inbox: [],
|
|
2148
|
-
last_seen: nowMs(),
|
|
2149
|
-
started_at: nowIso(),
|
|
2150
|
-
ended_at: null
|
|
2151
|
-
};
|
|
2152
|
-
writeAgent(agent);
|
|
2153
|
-
return agent;
|
|
2075
|
+
function hostStatus() {
|
|
2076
|
+
return HOSTS.map((host) => {
|
|
2077
|
+
const installed = isInstalled(hostBin(host));
|
|
2078
|
+
const file = installed ? hostFileOps(host) : void 0;
|
|
2079
|
+
return {
|
|
2080
|
+
key: host.provider,
|
|
2081
|
+
bin: hostBin(host),
|
|
2082
|
+
label: hostLabel(host),
|
|
2083
|
+
installed,
|
|
2084
|
+
attached: installed && (file ? file.attached() : isAttached(host)),
|
|
2085
|
+
manual: host.add === void 0 && host.file === void 0
|
|
2086
|
+
};
|
|
2087
|
+
});
|
|
2154
2088
|
}
|
|
2155
|
-
function
|
|
2156
|
-
const
|
|
2157
|
-
const
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
const tmuxSession = tmuxRunSessionName(runId, providerDisplayName(headProvider));
|
|
2165
|
-
let createdRunSession = false;
|
|
2166
|
-
try {
|
|
2167
|
-
createRunSessionWithReevesTab(driver, tmuxSession, reevesAnchor, workingDir);
|
|
2168
|
-
createdRunSession = true;
|
|
2169
|
-
const head = createHeadlessHeadAgent(runId, tmuxSession, headProvider, workingDir);
|
|
2170
|
-
const run = {
|
|
2171
|
-
id: runId,
|
|
2172
|
-
name: providerDisplayName(headProvider),
|
|
2173
|
-
status: "running",
|
|
2174
|
-
tmux_session: tmuxSession,
|
|
2175
|
-
reeves_session: reevesAnchor.sessionName,
|
|
2176
|
-
reeves_window_id: reevesAnchor.windowId,
|
|
2177
|
-
reeves_pane_id: reevesAnchor.paneId,
|
|
2178
|
-
root_agent_id: head.id,
|
|
2179
|
-
working_dir: workingDir,
|
|
2180
|
-
preset_name: null,
|
|
2181
|
-
started_at: nowIso(),
|
|
2182
|
-
ended_at: null
|
|
2089
|
+
function attach(key, force = false) {
|
|
2090
|
+
const host = findHost(key);
|
|
2091
|
+
const label = hostLabel(host);
|
|
2092
|
+
if (!host.add && !host.file) {
|
|
2093
|
+
return {
|
|
2094
|
+
key,
|
|
2095
|
+
label,
|
|
2096
|
+
ok: false,
|
|
2097
|
+
message: `${label} must be added manually: add a stdio MCP server named "${SERVER_NAME}" that runs reevesagents mcp`
|
|
2183
2098
|
};
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
return {
|
|
2187
|
-
}
|
|
2188
|
-
|
|
2099
|
+
}
|
|
2100
|
+
if (!isInstalled(hostBin(host))) {
|
|
2101
|
+
return { key, label, ok: false, message: `${hostBin(host)} is not installed` };
|
|
2102
|
+
}
|
|
2103
|
+
const file = hostFileOps(host);
|
|
2104
|
+
if (file) {
|
|
2105
|
+
try {
|
|
2106
|
+
file.attach(resolveLaunchCmd());
|
|
2107
|
+
return { key, label, ok: true, message: force ? "reattached" : "attached" };
|
|
2108
|
+
} catch (err) {
|
|
2109
|
+
return { key, label, ok: false, message: `could not edit config (add it manually): ${cliError(err)}` };
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
try {
|
|
2113
|
+
if (force && host.remove) {
|
|
2189
2114
|
try {
|
|
2190
|
-
|
|
2115
|
+
runHostCommand(host, host.remove);
|
|
2191
2116
|
} catch {
|
|
2192
2117
|
}
|
|
2193
2118
|
}
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2119
|
+
runHostCommand(host, host.add(resolveLaunchCmd()));
|
|
2120
|
+
return { key, label, ok: true, message: force ? "reattached" : "attached" };
|
|
2121
|
+
} catch (err) {
|
|
2122
|
+
return { key, label, ok: false, message: cliError(err) };
|
|
2197
2123
|
}
|
|
2198
2124
|
}
|
|
2199
|
-
function
|
|
2200
|
-
const
|
|
2201
|
-
const
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
if (
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
}
|
|
2216
|
-
function openReeves(runId, options = {}) {
|
|
2217
|
-
const driver = options.driver ?? realDriver;
|
|
2218
|
-
const run = readRun(runId);
|
|
2219
|
-
const reevesSession = run.reeves_session ?? run.tmux_session;
|
|
2220
|
-
if (!run.reeves_window_id || !windowInSession(driver, reevesSession, run.reeves_window_id)) {
|
|
2221
|
-
throw new Error("Reeves TUI window is unavailable for this run");
|
|
2125
|
+
function detach(key) {
|
|
2126
|
+
const host = findHost(key);
|
|
2127
|
+
const label = hostLabel(host);
|
|
2128
|
+
if (!host.remove && !host.file) {
|
|
2129
|
+
return { key, label, ok: false, message: `${label} must be removed manually` };
|
|
2130
|
+
}
|
|
2131
|
+
if (!isInstalled(hostBin(host))) {
|
|
2132
|
+
return { key, label, ok: false, message: `${hostBin(host)} is not installed` };
|
|
2133
|
+
}
|
|
2134
|
+
const file = hostFileOps(host);
|
|
2135
|
+
if (file) {
|
|
2136
|
+
try {
|
|
2137
|
+
file.detach();
|
|
2138
|
+
return { key, label, ok: true, message: "detached" };
|
|
2139
|
+
} catch (err) {
|
|
2140
|
+
return { key, label, ok: false, message: cliError(err) };
|
|
2141
|
+
}
|
|
2222
2142
|
}
|
|
2223
|
-
const target = `${reevesSession}:${run.reeves_window_id}`;
|
|
2224
2143
|
try {
|
|
2225
|
-
|
|
2226
|
-
|
|
2144
|
+
runHostCommand(host, host.remove);
|
|
2145
|
+
return { key, label, ok: true, message: "detached" };
|
|
2146
|
+
} catch (err) {
|
|
2147
|
+
return { key, label, ok: false, message: cliError(err) };
|
|
2227
2148
|
}
|
|
2228
|
-
driver.tmux(["select-window", "-t", target]);
|
|
2229
2149
|
}
|
|
2230
|
-
function
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2150
|
+
function attachAll(force = false) {
|
|
2151
|
+
return HOSTS.filter((host) => (host.add || host.file) && isInstalled(hostBin(host))).map((host) => {
|
|
2152
|
+
const file = hostFileOps(host);
|
|
2153
|
+
const attached = file ? file.attached() : isAttached(host);
|
|
2154
|
+
if (!force && attached) {
|
|
2155
|
+
return { key: host.provider, label: hostLabel(host), ok: true, message: "already attached" };
|
|
2156
|
+
}
|
|
2157
|
+
return attach(host.provider, force);
|
|
2158
|
+
});
|
|
2159
|
+
}
|
|
2160
|
+
async function verifyServerLaunch(cmd = resolveLaunchCmd()) {
|
|
2161
|
+
const { Client } = await import("@modelcontextprotocol/sdk/client/index.js");
|
|
2162
|
+
const { StdioClientTransport } = await import("@modelcontextprotocol/sdk/client/stdio.js");
|
|
2163
|
+
const client = new Client({ name: "reevesagents-verify", version: "1" }, { capabilities: {} });
|
|
2164
|
+
const transport = new StdioClientTransport({ command: cmd.command, args: cmd.args, stderr: "ignore" });
|
|
2165
|
+
let timer;
|
|
2166
|
+
const timeout = new Promise((_, reject) => {
|
|
2167
|
+
timer = setTimeout(() => reject(new Error("timed out starting the MCP server")), VERIFY_TIMEOUT_MS);
|
|
2168
|
+
timer.unref?.();
|
|
2169
|
+
});
|
|
2234
2170
|
try {
|
|
2235
|
-
|
|
2236
|
-
|
|
2171
|
+
await Promise.race([client.connect(transport), timeout]);
|
|
2172
|
+
const listed = await Promise.race([client.listTools(), timeout]);
|
|
2173
|
+
const toolCount = Array.isArray(listed.tools) ? listed.tools.length : 0;
|
|
2174
|
+
return { ok: true, detail: `server started, ${toolCount} tools`, toolCount };
|
|
2175
|
+
} catch (err) {
|
|
2176
|
+
return { ok: false, detail: err instanceof Error ? err.message : String(err) };
|
|
2177
|
+
} finally {
|
|
2178
|
+
if (timer) clearTimeout(timer);
|
|
2179
|
+
try {
|
|
2180
|
+
await client.close();
|
|
2181
|
+
} catch {
|
|
2182
|
+
}
|
|
2237
2183
|
}
|
|
2238
|
-
driver.tmux(["select-window", "-t", target]);
|
|
2239
2184
|
}
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2185
|
+
|
|
2186
|
+
// src/core/doctor.ts
|
|
2187
|
+
import { accessSync, constants, existsSync as existsSync5, readFileSync as readFileSync5 } from "fs";
|
|
2188
|
+
import { createRequire } from "module";
|
|
2189
|
+
import { join as join6 } from "path";
|
|
2190
|
+
var MIN_NODE_VERSION = [20, 19, 0];
|
|
2191
|
+
function parseNodeVersion(version) {
|
|
2192
|
+
const clean = version.startsWith("v") ? version.slice(1) : version;
|
|
2193
|
+
const [major = "0", minor = "0", patch = "0"] = clean.split(".");
|
|
2194
|
+
return [parseInt(major, 10) || 0, parseInt(minor, 10) || 0, parseInt(patch, 10) || 0];
|
|
2195
|
+
}
|
|
2196
|
+
function nodeMeetsMinimum(version) {
|
|
2197
|
+
for (let i = 0; i < MIN_NODE_VERSION.length; i++) {
|
|
2198
|
+
if (version[i] > MIN_NODE_VERSION[i]) return true;
|
|
2199
|
+
if (version[i] < MIN_NODE_VERSION[i]) return false;
|
|
2249
2200
|
}
|
|
2250
|
-
|
|
2201
|
+
return true;
|
|
2202
|
+
}
|
|
2203
|
+
function nodeVersionCheck(rawVersion = process.version) {
|
|
2204
|
+
const version = rawVersion.startsWith("v") ? rawVersion.slice(1) : rawVersion;
|
|
2205
|
+
const parsed = parseNodeVersion(version);
|
|
2206
|
+
const ok = nodeMeetsMinimum(parsed);
|
|
2207
|
+
return {
|
|
2208
|
+
name: "node",
|
|
2209
|
+
status: ok ? "ok" : "fail",
|
|
2210
|
+
detail: ok ? version : `${version} (need >=20.19.0)`
|
|
2211
|
+
};
|
|
2251
2212
|
}
|
|
2252
|
-
function
|
|
2253
|
-
const driver = options.driver ?? realDriver;
|
|
2254
|
-
const n = Number.isFinite(lines) && lines > 0 ? Math.floor(lines) : 10;
|
|
2213
|
+
function readProcVersion() {
|
|
2255
2214
|
try {
|
|
2256
|
-
|
|
2257
|
-
if (agent.headless || !agent.tmux_pane_id) return "(headless agent - no output)";
|
|
2258
|
-
if (!paneInSession(driver, agent.tmux_session, agent.tmux_pane_id)) return "";
|
|
2259
|
-
let output = driver.tmux(["capture-pane", "-p", "-e", "-S", String(-n), "-t", agent.tmux_pane_id]);
|
|
2260
|
-
if (!output.trim()) {
|
|
2261
|
-
try {
|
|
2262
|
-
output = driver.tmux(["capture-pane", "-p", "-e", "-a", "-S", String(-n), "-t", agent.tmux_pane_id]);
|
|
2263
|
-
} catch {
|
|
2264
|
-
}
|
|
2265
|
-
}
|
|
2266
|
-
return redactSecrets(stripAnsi(output).trim());
|
|
2215
|
+
return readFileSync5("/proc/version", "utf-8");
|
|
2267
2216
|
} catch {
|
|
2268
2217
|
return "";
|
|
2269
2218
|
}
|
|
2270
2219
|
}
|
|
2271
|
-
function
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
if (!paneInSession(driver, agent.tmux_session, agent.tmux_pane_id)) throw new Error(STALE_WINDOW_ERROR);
|
|
2276
|
-
pasteTextToPane(driver, agent.tmux_pane_id, text);
|
|
2277
|
-
lastPasteAtByPane.set(agent.tmux_pane_id, Date.now());
|
|
2278
|
-
if (!agent.ended_at && agent.task_status === "queued") updateAgent(agent.run_id, agent.id, { task_status: "working" });
|
|
2279
|
-
}
|
|
2280
|
-
function tmuxKey(key) {
|
|
2281
|
-
if (key === "enter") return "Enter";
|
|
2282
|
-
if (key === "escape") return "Escape";
|
|
2283
|
-
if (key === "backspace") return "BSpace";
|
|
2284
|
-
if (key === "tab") return "Tab";
|
|
2285
|
-
if (key === "space") return "Space";
|
|
2286
|
-
if (key === "up") return "Up";
|
|
2287
|
-
if (key === "down") return "Down";
|
|
2288
|
-
if (key === "left") return "Left";
|
|
2289
|
-
if (key === "right") return "Right";
|
|
2290
|
-
return "C-c";
|
|
2220
|
+
function isWsl(env, procVersion) {
|
|
2221
|
+
return Boolean(
|
|
2222
|
+
env.WSL_DISTRO_NAME || env.WSL_INTEROP || /microsoft|wsl/i.test(procVersion)
|
|
2223
|
+
);
|
|
2291
2224
|
}
|
|
2292
|
-
function
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
const remaining = POST_PASTE_ENTER_DELAY_MS - (Date.now() - lastPasteAt);
|
|
2301
|
-
if (remaining > 0) {
|
|
2302
|
-
if (driver === realDriver) sleepSync2(remaining);
|
|
2303
|
-
else driver.delay(() => {
|
|
2304
|
-
}, remaining);
|
|
2305
|
-
}
|
|
2225
|
+
function platformSupportCheck(platform = process.platform, env = process.env, procVersion = platform === "linux" ? readProcVersion() : "") {
|
|
2226
|
+
if (platform === "darwin") return { name: "platform", status: "ok", detail: "macOS supported" };
|
|
2227
|
+
if (platform === "linux") {
|
|
2228
|
+
return {
|
|
2229
|
+
name: "platform",
|
|
2230
|
+
status: "ok",
|
|
2231
|
+
detail: isWsl(env, procVersion) ? "WSL supported" : "Linux supported"
|
|
2232
|
+
};
|
|
2306
2233
|
}
|
|
2307
|
-
|
|
2308
|
-
|
|
2234
|
+
if (platform === "win32") {
|
|
2235
|
+
return {
|
|
2236
|
+
name: "platform",
|
|
2237
|
+
status: "fail",
|
|
2238
|
+
detail: "native Windows unsupported; use WSL with tmux and provider CLIs installed inside WSL"
|
|
2239
|
+
};
|
|
2240
|
+
}
|
|
2241
|
+
return {
|
|
2242
|
+
name: "platform",
|
|
2243
|
+
status: "warn",
|
|
2244
|
+
detail: `${platform} is untested; supported targets are macOS, Linux, and WSL`
|
|
2245
|
+
};
|
|
2309
2246
|
}
|
|
2310
|
-
function
|
|
2311
|
-
|
|
2247
|
+
function checkTmux() {
|
|
2248
|
+
const versionStr = tmuxVersion();
|
|
2249
|
+
if (!versionStr) return { name: "tmux", status: "fail", detail: "not on PATH" };
|
|
2250
|
+
const match = versionStr.match(/tmux (\d+)\.(\d+)/);
|
|
2251
|
+
if (!match) return { name: "tmux", status: "warn", detail: `unexpected version format: ${versionStr}` };
|
|
2252
|
+
const major = parseInt(match[1] ?? "0", 10);
|
|
2253
|
+
const minor = parseInt(match[2] ?? "0", 10);
|
|
2254
|
+
if (major < 3) return { name: "tmux", status: "warn", detail: `tmux ${major}.${minor}; upgrade to 3.0+ recommended` };
|
|
2255
|
+
return { name: "tmux", status: "ok", detail: `tmux ${major}.${minor}` };
|
|
2312
2256
|
}
|
|
2313
|
-
function
|
|
2314
|
-
const
|
|
2315
|
-
const
|
|
2316
|
-
const
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
}
|
|
2323
|
-
const endedAt = nowIso();
|
|
2324
|
-
updateAgent(agent.run_id, agent.id, { ended_at: endedAt, task_status: "done" });
|
|
2325
|
-
const updatedAgent = readAgent(agent.run_id, agent.id);
|
|
2326
|
-
const endedRun = endRunIfNoLiveAgents(agent.run_id, endedAt);
|
|
2327
|
-
if (endedRun.status === "ended" || endedRun.ended_at !== null) {
|
|
2328
|
-
const runOwnsSession = !!run.reeves_session && run.reeves_session !== run.tmux_session;
|
|
2329
|
-
if (runOwnsSession) {
|
|
2330
|
-
try {
|
|
2331
|
-
driver.tmux(["kill-session", "-t", `=${run.tmux_session}`]);
|
|
2332
|
-
} catch {
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
archiveAndRemoveRun(run.id, "ended");
|
|
2336
|
-
}
|
|
2337
|
-
return updatedAgent;
|
|
2257
|
+
function checkProviders() {
|
|
2258
|
+
const available = detectAvailable();
|
|
2259
|
+
const statuses = Object.entries(available).map(([name, isAvail]) => `${providerDisplayName(name)}: ${isAvail ? "ok" : "missing"}`).join("; ");
|
|
2260
|
+
const noneAvail = Object.values(available).every((value) => !value);
|
|
2261
|
+
return {
|
|
2262
|
+
name: "providers",
|
|
2263
|
+
status: noneAvail ? "fail" : "ok",
|
|
2264
|
+
detail: statuses
|
|
2265
|
+
};
|
|
2338
2266
|
}
|
|
2339
|
-
function
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
const endedAt = nowIso();
|
|
2343
|
-
const runOwnsSession = !!run.reeves_session && run.reeves_session !== run.tmux_session;
|
|
2344
|
-
if (runOwnsSession) {
|
|
2345
|
-
try {
|
|
2346
|
-
driver.tmux(["kill-session", "-t", `=${run.tmux_session}`]);
|
|
2347
|
-
} catch {
|
|
2348
|
-
}
|
|
2267
|
+
function checkProviderCompatibility() {
|
|
2268
|
+
if (process.env.REEVES_DOCTOR_SKIP_PROVIDER_COMPAT === "1") {
|
|
2269
|
+
return { name: "provider compat", status: "warn", detail: "skipped by REEVES_DOCTOR_SKIP_PROVIDER_COMPAT" };
|
|
2349
2270
|
}
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
}
|
|
2357
|
-
}
|
|
2358
|
-
updateAgent(run.id, agent.id, { ended_at: endedAt });
|
|
2271
|
+
const compatibility = inspectProviderCompatibility();
|
|
2272
|
+
const installed = Object.values(compatibility).filter((provider) => provider.available);
|
|
2273
|
+
if (installed.length === 0) return { name: "provider compat", status: "warn", detail: "no installed providers to inspect" };
|
|
2274
|
+
const problems = installed.filter((provider) => !provider.ok).map((provider) => `${providerDisplayName(provider.provider)}: ${provider.detail}`);
|
|
2275
|
+
if (problems.length === 0) {
|
|
2276
|
+
return { name: "provider compat", status: "ok", detail: `${installed.map((provider) => providerDisplayName(provider.provider)).join(", ")} compatible` };
|
|
2359
2277
|
}
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2278
|
+
return {
|
|
2279
|
+
name: "provider compat",
|
|
2280
|
+
status: "warn",
|
|
2281
|
+
detail: problems.slice(0, 3).join("; ") + (problems.length > 3 ? `; +${problems.length - 3} more` : "")
|
|
2282
|
+
};
|
|
2364
2283
|
}
|
|
2365
|
-
function
|
|
2366
|
-
|
|
2367
|
-
let session;
|
|
2368
|
-
let window;
|
|
2369
|
-
let label;
|
|
2284
|
+
function checkPathAccess(name, path) {
|
|
2285
|
+
if (!existsSync5(path)) return { name, status: "warn", detail: `${path} (will be created on first use)` };
|
|
2370
2286
|
try {
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
window = "reeves";
|
|
2374
|
-
label = run.name;
|
|
2287
|
+
accessSync(path, constants.R_OK | constants.W_OK);
|
|
2288
|
+
return { name, status: "ok", detail: path };
|
|
2375
2289
|
} catch {
|
|
2290
|
+
return { name, status: "fail", detail: `${path} (not readable/writable)` };
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
function checkWebExtras() {
|
|
2294
|
+
const requireFrom = createRequire(import.meta.url);
|
|
2295
|
+
const missing = WEB_EXTRA_MODULES.filter((name) => {
|
|
2376
2296
|
try {
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
window = agent.tmux_window_id;
|
|
2380
|
-
label = agent.nickname;
|
|
2297
|
+
requireFrom.resolve(name);
|
|
2298
|
+
return false;
|
|
2381
2299
|
} catch {
|
|
2382
|
-
|
|
2300
|
+
return true;
|
|
2383
2301
|
}
|
|
2384
|
-
|
|
2302
|
+
});
|
|
2303
|
+
if (missing.length === 0) {
|
|
2304
|
+
return { name: "web extras", status: "ok", detail: `${WEB_EXTRA_MODULES.join(" + ")} present (web UI available)` };
|
|
2385
2305
|
}
|
|
2386
|
-
|
|
2306
|
+
return { name: "web extras", status: "warn", detail: `${missing.join(", ")} not installed; TUI unaffected, web UI disabled` };
|
|
2307
|
+
}
|
|
2308
|
+
function checkRunsState() {
|
|
2387
2309
|
try {
|
|
2388
|
-
|
|
2389
|
-
|
|
2310
|
+
const runs = listRuns();
|
|
2311
|
+
return { name: "runs state", status: "ok", detail: `${runs.length} run${runs.length === 1 ? "" : "s"}` };
|
|
2312
|
+
} catch (err) {
|
|
2313
|
+
return {
|
|
2314
|
+
name: "runs state",
|
|
2315
|
+
status: "fail",
|
|
2316
|
+
detail: `error reading runs: ${err instanceof Error ? err.message : "unknown"}`
|
|
2317
|
+
};
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
function checkMcpServerCommand() {
|
|
2321
|
+
const cmd = resolveLaunchCmd();
|
|
2322
|
+
if (cmd.command === "reevesagents") {
|
|
2323
|
+
return {
|
|
2324
|
+
name: "mcp server",
|
|
2325
|
+
status: "warn",
|
|
2326
|
+
detail: "no absolute launcher resolved; attached host CLIs will fall back to their own PATH"
|
|
2327
|
+
};
|
|
2390
2328
|
}
|
|
2391
2329
|
try {
|
|
2392
|
-
|
|
2330
|
+
accessSync(cmd.command, constants.X_OK);
|
|
2331
|
+
return { name: "mcp server", status: "ok", detail: `${cmd.command} ${cmd.args.join(" ")}` };
|
|
2393
2332
|
} catch {
|
|
2333
|
+
return {
|
|
2334
|
+
name: "mcp server",
|
|
2335
|
+
status: "warn",
|
|
2336
|
+
detail: `${cmd.command} is not executable; re-run reevesagents attach after reinstalling`
|
|
2337
|
+
};
|
|
2394
2338
|
}
|
|
2395
|
-
|
|
2339
|
+
}
|
|
2340
|
+
function runDoctor() {
|
|
2341
|
+
return {
|
|
2342
|
+
checks: [
|
|
2343
|
+
platformSupportCheck(),
|
|
2344
|
+
nodeVersionCheck(),
|
|
2345
|
+
checkTmux(),
|
|
2346
|
+
checkProviders(),
|
|
2347
|
+
checkProviderCompatibility(),
|
|
2348
|
+
checkPathAccess("state dir", stateRoot()),
|
|
2349
|
+
checkPathAccess("runs dir", runsDir()),
|
|
2350
|
+
checkPathAccess("presets dir", join6(stateRoot(), "presets")),
|
|
2351
|
+
checkRunsState(),
|
|
2352
|
+
checkWebExtras(),
|
|
2353
|
+
checkMcpServerCommand()
|
|
2354
|
+
]
|
|
2355
|
+
};
|
|
2396
2356
|
}
|
|
2397
2357
|
|
|
2398
2358
|
export {
|
|
2359
|
+
redactSecrets,
|
|
2399
2360
|
PROVIDER_DEFS,
|
|
2400
2361
|
coerceExtraArgs,
|
|
2401
2362
|
BIN,
|
|
@@ -2406,14 +2367,12 @@ export {
|
|
|
2406
2367
|
providerSupportsEffort,
|
|
2407
2368
|
buildCommand,
|
|
2408
2369
|
detectAvailable,
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
modelBadgeLabel,
|
|
2416
|
-
redactSecrets,
|
|
2370
|
+
exactSession,
|
|
2371
|
+
tmuxAvailable,
|
|
2372
|
+
sessionExists,
|
|
2373
|
+
targetExists,
|
|
2374
|
+
windowIds,
|
|
2375
|
+
windowByName,
|
|
2417
2376
|
stateRoot,
|
|
2418
2377
|
runsDir,
|
|
2419
2378
|
runDir,
|
|
@@ -2431,19 +2390,8 @@ export {
|
|
|
2431
2390
|
archiveAndRemoveRun,
|
|
2432
2391
|
listAgents,
|
|
2433
2392
|
findAgent,
|
|
2434
|
-
defaultTmuxAvailable,
|
|
2435
|
-
defaultTmuxTargetExists,
|
|
2436
2393
|
runHasLiveTmuxTarget,
|
|
2437
2394
|
autoCleanupRuns,
|
|
2438
|
-
resolveLaunchCmd,
|
|
2439
|
-
hostStatus,
|
|
2440
|
-
attach,
|
|
2441
|
-
detach,
|
|
2442
|
-
attachAll,
|
|
2443
|
-
verifyServerLaunch,
|
|
2444
|
-
nodeVersionCheck,
|
|
2445
|
-
checkTmux,
|
|
2446
|
-
runDoctor,
|
|
2447
2395
|
LANGUAGE_OPTIONS,
|
|
2448
2396
|
DEFAULT_LANGUAGE,
|
|
2449
2397
|
isLanguageCode,
|
|
@@ -2462,6 +2410,10 @@ export {
|
|
|
2462
2410
|
savePreset,
|
|
2463
2411
|
deletePreset,
|
|
2464
2412
|
savePresetFromRun,
|
|
2413
|
+
providerDisplayName,
|
|
2414
|
+
providerColor,
|
|
2415
|
+
modelColor,
|
|
2416
|
+
modelBadgeLabel,
|
|
2465
2417
|
ALLOWED_KEYS,
|
|
2466
2418
|
startRun,
|
|
2467
2419
|
startRunFromPreset,
|
|
@@ -2476,6 +2428,15 @@ export {
|
|
|
2476
2428
|
interrupt,
|
|
2477
2429
|
killAgent,
|
|
2478
2430
|
stopRun,
|
|
2479
|
-
openTmuxTarget
|
|
2431
|
+
openTmuxTarget,
|
|
2432
|
+
resolveLaunchCmd,
|
|
2433
|
+
hostStatus,
|
|
2434
|
+
attach,
|
|
2435
|
+
detach,
|
|
2436
|
+
attachAll,
|
|
2437
|
+
verifyServerLaunch,
|
|
2438
|
+
nodeVersionCheck,
|
|
2439
|
+
checkTmux,
|
|
2440
|
+
runDoctor
|
|
2480
2441
|
};
|
|
2481
|
-
//# sourceMappingURL=chunk-
|
|
2442
|
+
//# sourceMappingURL=chunk-PDJ2CPVO.js.map
|