reevesagents 1.7.1 → 1.7.3
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 +3 -1
- package/dist/{chunk-64F5HXFT.js → chunk-7K3XRI7L.js} +2 -2
- package/dist/{chunk-ZK24DAS5.js → chunk-EXUYSBTC.js} +16 -16
- package/dist/{chunk-6YE7JRID.js → chunk-GNS5ULTD.js} +2 -2
- package/dist/{chunk-LHUVET65.js → chunk-GSWMKYSU.js} +1358 -1327
- package/dist/{chunk-5XIBZCJJ.js → chunk-JX6SHZKB.js} +8 -8
- package/dist/{chunk-X3C4CRMT.js → chunk-MKNSEZTG.js} +25 -25
- package/dist/{chunk-4CVXS5HU.js → chunk-OVNVE2TJ.js} +2 -2
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +683 -583
- package/dist/index.d.ts +25 -23
- package/dist/index.js +2 -2
- package/dist/{router-7PMCRHOB.js → router-RZANKWMI.js} +97 -30
- package/dist/{server-77NGKAHW.js → server-R2A7E5WC.js} +4 -4
- package/dist/{server-AZAISL3I.js → server-WLXS227K.js} +9 -15
- package/dist/{tui-launch-V3ZEPE65.js → tui-launch-6V756ZBI.js} +2 -2
- package/package.json +1 -1
|
@@ -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,1331 +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 (entry) {
|
|
1066
|
-
try {
|
|
1067
|
-
const real = realpathSync(entry);
|
|
1068
|
-
if (/\.[cm]?js$/.test(real)) return { command: process.execPath, args: [real, SERVER_ARG] };
|
|
1069
|
-
} catch {
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1018
|
+
function loadConfig() {
|
|
1072
1019
|
try {
|
|
1073
|
-
const
|
|
1074
|
-
|
|
1020
|
+
const content = readFileSync2(configPath(), "utf-8");
|
|
1021
|
+
return mergeDefaults(JSON.parse(content));
|
|
1075
1022
|
} catch {
|
|
1023
|
+
return defaultConfig();
|
|
1076
1024
|
}
|
|
1077
|
-
return { command: SERVER_BIN, args: [SERVER_ARG] };
|
|
1078
1025
|
}
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
provider: "codex",
|
|
1090
|
-
add: (cmd) => ["mcp", "add", SERVER_NAME, "--", cmd.command, ...cmd.args],
|
|
1091
|
-
remove: ["mcp", "remove", SERVER_NAME],
|
|
1092
|
-
list: ["mcp", "list"]
|
|
1093
|
-
},
|
|
1094
|
-
{
|
|
1095
|
-
provider: "kimi",
|
|
1096
|
-
add: (cmd) => ["mcp", "add", SERVER_NAME, "--", cmd.command, ...cmd.args],
|
|
1097
|
-
remove: ["mcp", "remove", SERVER_NAME],
|
|
1098
|
-
list: ["mcp", "list"]
|
|
1099
|
-
},
|
|
1100
|
-
{
|
|
1101
|
-
provider: "qwen",
|
|
1102
|
-
// qwen (a gemini-cli fork) takes `<commandOrUrl> [args...]` with no `--`
|
|
1103
|
-
// separator, and already defaults its scope to `user`.
|
|
1104
|
-
add: (cmd) => ["mcp", "add", SERVER_NAME, cmd.command, ...cmd.args],
|
|
1105
|
-
remove: ["mcp", "remove", SERVER_NAME],
|
|
1106
|
-
list: ["mcp", "list"]
|
|
1107
|
-
},
|
|
1108
|
-
{
|
|
1109
|
-
provider: "hermes",
|
|
1110
|
-
// hermes takes --command and a variadic --args, so the entry path and `mcp`
|
|
1111
|
-
// both ride on one --args.
|
|
1112
|
-
add: (cmd) => ["mcp", "add", SERVER_NAME, "--command", cmd.command, "--args", ...cmd.args],
|
|
1113
|
-
remove: ["mcp", "remove", SERVER_NAME],
|
|
1114
|
-
list: ["mcp", "list"]
|
|
1115
|
-
},
|
|
1116
|
-
{
|
|
1117
|
-
// opencode's `mcp add` prompts interactively for a local server's command, so
|
|
1118
|
-
// we attach it by writing its config JSON directly instead.
|
|
1119
|
-
provider: "opencode",
|
|
1120
|
-
list: ["mcp", "list"],
|
|
1121
|
-
file: { attach: opencodeAttach, detach: opencodeDetach, attached: opencodeAttached }
|
|
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");
|
|
1032
|
+
try {
|
|
1033
|
+
renameSync2(tmp, path);
|
|
1034
|
+
} catch {
|
|
1035
|
+
writeFileSync2(path, JSON.stringify(cfg, null, 2), "utf-8");
|
|
1122
1036
|
}
|
|
1037
|
+
return path;
|
|
1038
|
+
}
|
|
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" }
|
|
1123
1048
|
];
|
|
1124
|
-
function
|
|
1125
|
-
|
|
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;
|
|
1126
1053
|
}
|
|
1127
|
-
function
|
|
1128
|
-
|
|
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;
|
|
1129
1062
|
}
|
|
1130
|
-
function
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
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;
|
|
1136
1077
|
}
|
|
1137
1078
|
}
|
|
1138
|
-
function
|
|
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);
|
|
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);
|
|
1139
1103
|
try {
|
|
1140
|
-
|
|
1141
|
-
encoding: "utf8",
|
|
1142
|
-
timeout: STATUS_TIMEOUT_MS,
|
|
1143
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
1144
|
-
});
|
|
1145
|
-
return /reevesagents(?![-\w])/i.test(out);
|
|
1104
|
+
renameSync3(tmp, path);
|
|
1146
1105
|
} catch {
|
|
1147
|
-
|
|
1106
|
+
writeFileSync3(path, JSON.stringify(data, null, 2), "utf-8");
|
|
1148
1107
|
}
|
|
1149
1108
|
}
|
|
1150
|
-
function
|
|
1151
|
-
|
|
1152
|
-
encoding: "utf8",
|
|
1153
|
-
timeout: MGMT_TIMEOUT_MS,
|
|
1154
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
1155
|
-
});
|
|
1156
|
-
}
|
|
1157
|
-
function cliError(err) {
|
|
1158
|
-
const stderr = err && typeof err === "object" ? err.stderr : void 0;
|
|
1159
|
-
const text = typeof stderr === "string" ? stderr.trim() : Buffer.isBuffer(stderr) ? stderr.toString("utf8").trim() : "";
|
|
1160
|
-
return text || (err instanceof Error ? err.message : String(err));
|
|
1109
|
+
function isEffort(value) {
|
|
1110
|
+
return value === "default" || value === "low" || value === "medium" || value === "high" || value === "xhigh" || value === "max";
|
|
1161
1111
|
}
|
|
1162
|
-
function
|
|
1163
|
-
const
|
|
1164
|
-
|
|
1165
|
-
|
|
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
|
+
};
|
|
1166
1125
|
}
|
|
1167
|
-
function
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
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
|
+
};
|
|
1179
1141
|
}
|
|
1180
|
-
function
|
|
1181
|
-
const
|
|
1182
|
-
|
|
1183
|
-
if (!host.add && !host.file) {
|
|
1184
|
-
return {
|
|
1185
|
-
key,
|
|
1186
|
-
label,
|
|
1187
|
-
ok: false,
|
|
1188
|
-
message: `${label} must be added manually: add a stdio MCP server named "${SERVER_NAME}" that runs reevesagents mcp`
|
|
1189
|
-
};
|
|
1190
|
-
}
|
|
1191
|
-
if (!isInstalled(hostBin(host))) {
|
|
1192
|
-
return { key, label, ok: false, message: `${hostBin(host)} is not installed` };
|
|
1193
|
-
}
|
|
1194
|
-
if (host.file) {
|
|
1195
|
-
try {
|
|
1196
|
-
host.file.attach(resolveLaunchCmd());
|
|
1197
|
-
return { key, label, ok: true, message: force ? "reattached" : "attached" };
|
|
1198
|
-
} catch (err) {
|
|
1199
|
-
return { key, label, ok: false, message: `could not edit config (add it manually): ${cliError(err)}` };
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1142
|
+
function listPresets() {
|
|
1143
|
+
const dir = presetsDir();
|
|
1144
|
+
if (!existsSync2(dir)) return [];
|
|
1202
1145
|
try {
|
|
1203
|
-
|
|
1146
|
+
return readdirSync2(dir).filter((f) => f.endsWith(".json")).map((f) => {
|
|
1204
1147
|
try {
|
|
1205
|
-
|
|
1148
|
+
return normalizePreset(JSON.parse(readFileSync3(join3(dir, f), "utf-8")));
|
|
1206
1149
|
} catch {
|
|
1150
|
+
return null;
|
|
1207
1151
|
}
|
|
1208
|
-
}
|
|
1209
|
-
|
|
1210
|
-
return
|
|
1211
|
-
} catch (err) {
|
|
1212
|
-
return { key, label, ok: false, message: cliError(err) };
|
|
1152
|
+
}).filter((t) => t !== null);
|
|
1153
|
+
} catch {
|
|
1154
|
+
return [];
|
|
1213
1155
|
}
|
|
1214
1156
|
}
|
|
1215
|
-
function
|
|
1216
|
-
const host = findHost(key);
|
|
1217
|
-
const label = hostLabel(host);
|
|
1218
|
-
if (!host.remove && !host.file) {
|
|
1219
|
-
return { key, label, ok: false, message: `${label} must be removed manually` };
|
|
1220
|
-
}
|
|
1221
|
-
if (!isInstalled(hostBin(host))) {
|
|
1222
|
-
return { key, label, ok: false, message: `${hostBin(host)} is not installed` };
|
|
1223
|
-
}
|
|
1224
|
-
if (host.file) {
|
|
1225
|
-
try {
|
|
1226
|
-
host.file.detach();
|
|
1227
|
-
return { key, label, ok: true, message: "detached" };
|
|
1228
|
-
} catch (err) {
|
|
1229
|
-
return { key, label, ok: false, message: cliError(err) };
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1157
|
+
function loadPreset(name) {
|
|
1232
1158
|
try {
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
return { key, label, ok: false, message: cliError(err) };
|
|
1159
|
+
return normalizePreset(JSON.parse(readFileSync3(join3(presetsDir(), `${name}.json`), "utf-8")));
|
|
1160
|
+
} catch {
|
|
1161
|
+
return null;
|
|
1237
1162
|
}
|
|
1238
1163
|
}
|
|
1239
|
-
function
|
|
1240
|
-
|
|
1241
|
-
const attached = host.file ? host.file.attached() : isAttached(host);
|
|
1242
|
-
if (!force && attached) {
|
|
1243
|
-
return { key: host.provider, label: hostLabel(host), ok: true, message: "already attached" };
|
|
1244
|
-
}
|
|
1245
|
-
return attach(host.provider, force);
|
|
1246
|
-
});
|
|
1164
|
+
function savePreset(tree) {
|
|
1165
|
+
atomicWrite(join3(presetsDir(), `${tree.name}.json`), tree);
|
|
1247
1166
|
}
|
|
1248
|
-
|
|
1249
|
-
const { Client } = await import("@modelcontextprotocol/sdk/client/index.js");
|
|
1250
|
-
const { StdioClientTransport } = await import("@modelcontextprotocol/sdk/client/stdio.js");
|
|
1251
|
-
const client = new Client({ name: "reevesagents-verify", version: "1" }, { capabilities: {} });
|
|
1252
|
-
const transport = new StdioClientTransport({ command: cmd.command, args: cmd.args, stderr: "ignore" });
|
|
1253
|
-
let timer;
|
|
1254
|
-
const timeout = new Promise((_, reject) => {
|
|
1255
|
-
timer = setTimeout(() => reject(new Error("timed out starting the MCP server")), VERIFY_TIMEOUT_MS);
|
|
1256
|
-
timer.unref?.();
|
|
1257
|
-
});
|
|
1167
|
+
function deletePreset(name) {
|
|
1258
1168
|
try {
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1169
|
+
unlinkSync2(join3(presetsDir(), `${name}.json`));
|
|
1170
|
+
} catch {
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
function sanitizePresetName(raw) {
|
|
1174
|
+
return raw.trim().replace(/[^a-zA-Z0-9_-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 64);
|
|
1175
|
+
}
|
|
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
|
+
};
|
|
1188
|
+
}
|
|
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;
|
|
1209
|
+
}
|
|
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;
|
|
1235
|
+
}
|
|
1236
|
+
function providerColor(p) {
|
|
1237
|
+
return PROVIDER_REGISTRY[p]?.color ?? "gray";
|
|
1238
|
+
}
|
|
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;
|
|
1254
|
+
}
|
|
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);
|
|
1261
|
+
}
|
|
1262
|
+
function truncateLabel(label, max) {
|
|
1263
|
+
if (label.length <= max) return label;
|
|
1264
|
+
return `${label.slice(0, Math.max(1, max - 3))}...`;
|
|
1265
|
+
}
|
|
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;
|
|
1279
|
+
}
|
|
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}`);
|
|
1286
|
+
}
|
|
1287
|
+
function shellQuote(s) {
|
|
1288
|
+
return `'${s.replace(/'/g, "'\\''")}'`;
|
|
1289
|
+
}
|
|
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);
|
|
1312
|
+
}
|
|
1313
|
+
function waitAfterPaste(driver) {
|
|
1314
|
+
if (driver === realDriver) sleepSync2(POST_PASTE_ENTER_DELAY_MS);
|
|
1315
|
+
else driver.delay(() => {
|
|
1316
|
+
}, POST_PASTE_ENTER_DELAY_MS);
|
|
1317
|
+
}
|
|
1318
|
+
function normalizePaneOutput(output) {
|
|
1319
|
+
return stripAnsi(output).replace(/\s+/g, " ").trim().toLowerCase();
|
|
1320
|
+
}
|
|
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);
|
|
1328
|
+
}
|
|
1329
|
+
function pasteTextToPane(driver, paneId, text) {
|
|
1330
|
+
const bufferName = `reeves_${randomUUID2().slice(0, 8)}`;
|
|
1331
|
+
driver.tmux(["load-buffer", "-b", bufferName, "-"], text);
|
|
1332
|
+
try {
|
|
1333
|
+
driver.tmux(["paste-buffer", "-b", bufferName, "-t", paneId]);
|
|
1265
1334
|
} finally {
|
|
1266
|
-
if (timer) clearTimeout(timer);
|
|
1267
1335
|
try {
|
|
1268
|
-
|
|
1336
|
+
driver.tmux(["delete-buffer", "-b", bufferName]);
|
|
1269
1337
|
} catch {
|
|
1270
1338
|
}
|
|
1271
1339
|
}
|
|
1272
1340
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
import { accessSync, constants, existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
|
|
1277
|
-
import { createRequire } from "module";
|
|
1278
|
-
import { join as join3 } from "path";
|
|
1279
|
-
var MIN_NODE_VERSION = [20, 19, 0];
|
|
1280
|
-
function parseNodeVersion(version) {
|
|
1281
|
-
const clean = version.startsWith("v") ? version.slice(1) : version;
|
|
1282
|
-
const [major = "0", minor = "0", patch = "0"] = clean.split(".");
|
|
1283
|
-
return [parseInt(major, 10) || 0, parseInt(minor, 10) || 0, parseInt(patch, 10) || 0];
|
|
1341
|
+
function sanitizeName(raw) {
|
|
1342
|
+
const cleaned = raw.trim().replace(/[^a-zA-Z0-9_-]/g, "-").replace(/-+/g, "-").slice(0, 40);
|
|
1343
|
+
return cleaned || "run";
|
|
1284
1344
|
}
|
|
1285
|
-
function
|
|
1286
|
-
|
|
1287
|
-
if (version[i] > MIN_NODE_VERSION[i]) return true;
|
|
1288
|
-
if (version[i] < MIN_NODE_VERSION[i]) return false;
|
|
1289
|
-
}
|
|
1290
|
-
return true;
|
|
1345
|
+
function tmuxWindowName(provider, nickname) {
|
|
1346
|
+
return sanitizeName(nickname || provider).slice(0, 64);
|
|
1291
1347
|
}
|
|
1292
|
-
function
|
|
1293
|
-
|
|
1294
|
-
const parsed = parseNodeVersion(version);
|
|
1295
|
-
const ok = nodeMeetsMinimum(parsed);
|
|
1296
|
-
return {
|
|
1297
|
-
name: "node",
|
|
1298
|
-
status: ok ? "ok" : "fail",
|
|
1299
|
-
detail: ok ? version : `${version} (need >=20.19.0)`
|
|
1300
|
-
};
|
|
1348
|
+
function tmuxRunSessionName(runId, rawName) {
|
|
1349
|
+
return `reeves-${sanitizeName(rawName).slice(0, 24)}-${runId.slice(0, 8)}`.slice(0, 64);
|
|
1301
1350
|
}
|
|
1302
|
-
function
|
|
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;
|
|
1358
|
+
}
|
|
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 };
|
|
1365
|
+
}
|
|
1366
|
+
function readDisplayIds(driver, target) {
|
|
1303
1367
|
try {
|
|
1304
|
-
|
|
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));
|
|
1305
1372
|
} catch {
|
|
1306
|
-
return
|
|
1373
|
+
return null;
|
|
1307
1374
|
}
|
|
1308
1375
|
}
|
|
1309
|
-
function
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
);
|
|
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`);
|
|
1313
1379
|
}
|
|
1314
|
-
function
|
|
1315
|
-
if (
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
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
|
+
}
|
|
1322
1390
|
}
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
detail: "native Windows unsupported; use WSL with tmux and provider CLIs installed inside WSL"
|
|
1328
|
-
};
|
|
1391
|
+
const fallbackName = "reeves";
|
|
1392
|
+
try {
|
|
1393
|
+
driver.tmux(["new-session", "-d", "-s", fallbackName, "-n", "reeves"]);
|
|
1394
|
+
} catch {
|
|
1329
1395
|
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
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 ?? "" };
|
|
1335
1405
|
}
|
|
1336
|
-
function
|
|
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`;
|
|
1337
1409
|
try {
|
|
1338
|
-
|
|
1339
|
-
const match = versionStr.match(/tmux (\d+)\.(\d+)/);
|
|
1340
|
-
if (!match) return { name: "tmux", status: "warn", detail: `unexpected version format: ${versionStr}` };
|
|
1341
|
-
const major = parseInt(match[1] ?? "0", 10);
|
|
1342
|
-
const minor = parseInt(match[2] ?? "0", 10);
|
|
1343
|
-
if (major < 3) return { name: "tmux", status: "warn", detail: `tmux ${major}.${minor}; upgrade to 3.0+ recommended` };
|
|
1344
|
-
return { name: "tmux", status: "ok", detail: `tmux ${major}.${minor}` };
|
|
1410
|
+
driver.tmux(["link-window", "-k", "-s", source, "-t", `${tmuxSession}:0`]);
|
|
1345
1411
|
} catch {
|
|
1346
|
-
return { name: "tmux", status: "fail", detail: "not on PATH" };
|
|
1347
1412
|
}
|
|
1348
1413
|
}
|
|
1349
|
-
function
|
|
1350
|
-
const
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
if (process.env.REEVES_DOCTOR_SKIP_PROVIDER_COMPAT === "1") {
|
|
1361
|
-
return { name: "provider compat", status: "warn", detail: "skipped by REEVES_DOCTOR_SKIP_PROVIDER_COMPAT" };
|
|
1362
|
-
}
|
|
1363
|
-
const compatibility = inspectProviderCompatibility();
|
|
1364
|
-
const installed = Object.values(compatibility).filter((provider) => provider.available);
|
|
1365
|
-
if (installed.length === 0) return { name: "provider compat", status: "warn", detail: "no installed providers to inspect" };
|
|
1366
|
-
const problems = installed.filter((provider) => !provider.ok).map((provider) => `${providerDisplayName(provider.provider)}: ${provider.detail}`);
|
|
1367
|
-
if (problems.length === 0) {
|
|
1368
|
-
return { name: "provider compat", status: "ok", detail: `${installed.map((provider) => providerDisplayName(provider.provider)).join(", ")} compatible` };
|
|
1369
|
-
}
|
|
1370
|
-
return {
|
|
1371
|
-
name: "provider compat",
|
|
1372
|
-
status: "warn",
|
|
1373
|
-
detail: problems.slice(0, 3).join("; ") + (problems.length > 3 ? `; +${problems.length - 3} more` : "")
|
|
1374
|
-
};
|
|
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(" ")}`;
|
|
1375
1425
|
}
|
|
1376
|
-
function
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
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
|
+
}
|
|
1383
1437
|
}
|
|
1384
|
-
|
|
1385
|
-
function checkWebExtras() {
|
|
1386
|
-
const requireFrom = createRequire(import.meta.url);
|
|
1387
|
-
const missing = WEB_EXTRA_MODULES.filter((name) => {
|
|
1438
|
+
function waitForReadyThenSend(previousOutput = "", waitedMs = 0) {
|
|
1388
1439
|
try {
|
|
1389
|
-
|
|
1390
|
-
|
|
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);
|
|
1391
1447
|
} catch {
|
|
1392
|
-
return true;
|
|
1393
1448
|
}
|
|
1394
|
-
});
|
|
1395
|
-
if (missing.length === 0) {
|
|
1396
|
-
return { name: "web extras", status: "ok", detail: `${WEB_EXTRA_MODULES.join(" + ")} present (web UI available)` };
|
|
1397
|
-
}
|
|
1398
|
-
return { name: "web extras", status: "warn", detail: `${missing.join(", ")} not installed; TUI unaffected, web UI disabled` };
|
|
1399
|
-
}
|
|
1400
|
-
function checkRunsState() {
|
|
1401
|
-
try {
|
|
1402
|
-
const runs = listRuns();
|
|
1403
|
-
return { name: "runs state", status: "ok", detail: `${runs.length} run${runs.length === 1 ? "" : "s"}` };
|
|
1404
|
-
} catch (err) {
|
|
1405
|
-
return {
|
|
1406
|
-
name: "runs state",
|
|
1407
|
-
status: "fail",
|
|
1408
|
-
detail: `error reading runs: ${err instanceof Error ? err.message : "unknown"}`
|
|
1409
|
-
};
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
function checkMcpServerCommand() {
|
|
1413
|
-
const cmd = resolveLaunchCmd();
|
|
1414
|
-
if (cmd.command === "reevesagents") {
|
|
1415
|
-
return {
|
|
1416
|
-
name: "mcp server",
|
|
1417
|
-
status: "warn",
|
|
1418
|
-
detail: "no absolute launcher resolved; attached host CLIs will fall back to their own PATH"
|
|
1419
|
-
};
|
|
1420
|
-
}
|
|
1421
|
-
try {
|
|
1422
|
-
accessSync(cmd.command, constants.X_OK);
|
|
1423
|
-
return { name: "mcp server", status: "ok", detail: `${cmd.command} ${cmd.args.join(" ")}` };
|
|
1424
|
-
} catch {
|
|
1425
|
-
return {
|
|
1426
|
-
name: "mcp server",
|
|
1427
|
-
status: "warn",
|
|
1428
|
-
detail: `${cmd.command} is not executable; re-run reevesagents attach after reinstalling`
|
|
1429
|
-
};
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
function runDoctor() {
|
|
1433
|
-
return {
|
|
1434
|
-
checks: [
|
|
1435
|
-
platformSupportCheck(),
|
|
1436
|
-
nodeVersionCheck(),
|
|
1437
|
-
checkTmux(),
|
|
1438
|
-
checkProviders(),
|
|
1439
|
-
checkProviderCompatibility(),
|
|
1440
|
-
checkPathAccess("state dir", stateRoot()),
|
|
1441
|
-
checkPathAccess("runs dir", runsDir()),
|
|
1442
|
-
checkPathAccess("presets dir", join3(stateRoot(), "presets")),
|
|
1443
|
-
checkRunsState(),
|
|
1444
|
-
checkWebExtras(),
|
|
1445
|
-
checkMcpServerCommand()
|
|
1446
|
-
]
|
|
1447
|
-
};
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
// src/i18n/languages.ts
|
|
1451
|
-
var LANGUAGES = ["en", "de", "fr", "es", "pt", "it", "tr", "ru", "zh-Hans", "ar"];
|
|
1452
|
-
var LANGUAGE_OPTIONS = [
|
|
1453
|
-
{ code: "en", flag: "\u{1F1FA}\u{1F1F8}", name: "English", nativeName: "English", dir: "ltr" },
|
|
1454
|
-
{ code: "de", flag: "\u{1F1E9}\u{1F1EA}", name: "German", nativeName: "Deutsch", dir: "ltr" },
|
|
1455
|
-
{ code: "fr", flag: "\u{1F1EB}\u{1F1F7}", name: "French", nativeName: "Fran\xE7ais", dir: "ltr" },
|
|
1456
|
-
{ code: "es", flag: "\u{1F1EA}\u{1F1F8}", name: "Spanish", nativeName: "Espa\xF1ol", dir: "ltr" },
|
|
1457
|
-
{ code: "pt", flag: "\u{1F1F5}\u{1F1F9}", name: "Portuguese", nativeName: "Portugu\xEAs", dir: "ltr" },
|
|
1458
|
-
{ code: "it", flag: "\u{1F1EE}\u{1F1F9}", name: "Italian", nativeName: "Italiano", dir: "ltr" },
|
|
1459
|
-
{ code: "tr", flag: "\u{1F1F9}\u{1F1F7}", name: "Turkish", nativeName: "T\xFCrk\xE7e", dir: "ltr" },
|
|
1460
|
-
{ code: "ru", flag: "\u{1F1F7}\u{1F1FA}", name: "Russian", nativeName: "\u0420\u0443\u0441\u0441\u043A\u0438\u0439", dir: "ltr" },
|
|
1461
|
-
{ code: "zh-Hans", flag: "\u{1F1E8}\u{1F1F3}", name: "Simplified Chinese", nativeName: "\u7B80\u4F53\u4E2D\u6587", dir: "ltr" },
|
|
1462
|
-
{ code: "ar", flag: "\u{1F1F8}\u{1F1E6}", name: "Arabic", nativeName: "\u0627\u0644\u0639\u0631\u0628\u064A\u0629", dir: "rtl" }
|
|
1463
|
-
];
|
|
1464
|
-
var DEFAULT_LANGUAGE = "en";
|
|
1465
|
-
function isLanguageCode(value) {
|
|
1466
|
-
return typeof value === "string" && LANGUAGES.includes(value);
|
|
1467
|
-
}
|
|
1468
|
-
function languageOption(code) {
|
|
1469
|
-
return LANGUAGE_OPTIONS.find((option) => option.code === code) ?? LANGUAGE_OPTIONS[0];
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
// src/core/config.ts
|
|
1473
|
-
import { readFileSync as readFileSync4, writeFileSync as writeFileSync3, mkdirSync as mkdirSync3, renameSync as renameSync2 } from "fs";
|
|
1474
|
-
import { homedir as homedir3 } from "os";
|
|
1475
|
-
import { join as join4, dirname as dirname3 } from "path";
|
|
1476
|
-
var SCHEMA_VERSION = 2;
|
|
1477
|
-
var DEFAULT_GLOBAL = {
|
|
1478
|
-
peek_interval_ms: 5e3,
|
|
1479
|
-
peek_lines: 10,
|
|
1480
|
-
max_depth: 5,
|
|
1481
|
-
max_agents: 100,
|
|
1482
|
-
ready_delay_ms: 5e3,
|
|
1483
|
-
max_lifetime_ms: 0,
|
|
1484
|
-
default_permissions: "ask",
|
|
1485
|
-
language: DEFAULT_LANGUAGE
|
|
1486
|
-
};
|
|
1487
|
-
function configPath() {
|
|
1488
|
-
const base = process.env.REEVES_CONFIG;
|
|
1489
|
-
if (base) return base;
|
|
1490
|
-
return join4(homedir3(), ".reeves", "config.json");
|
|
1491
|
-
}
|
|
1492
|
-
function configExists() {
|
|
1493
|
-
try {
|
|
1494
|
-
readFileSync4(configPath(), "utf-8");
|
|
1495
|
-
return true;
|
|
1496
|
-
} catch {
|
|
1497
|
-
return false;
|
|
1498
1449
|
}
|
|
1450
|
+
if (!task) return;
|
|
1451
|
+
driver.delay(() => waitForReadyThenSend(), readyDelayMs);
|
|
1499
1452
|
}
|
|
1500
|
-
function
|
|
1453
|
+
function newAgentRecord(id, runId, tmuxSession, role, config, workingDir, ids, permissions) {
|
|
1501
1454
|
return {
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
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
|
|
1512
1474
|
};
|
|
1513
|
-
if (typeof obj.global === "object" && obj.global !== null) {
|
|
1514
|
-
const g = obj.global;
|
|
1515
|
-
if (typeof g.peek_interval_ms === "number" && g.peek_interval_ms > 0) merged.global.peek_interval_ms = g.peek_interval_ms;
|
|
1516
|
-
if (typeof g.peek_lines === "number" && g.peek_lines > 0) merged.global.peek_lines = g.peek_lines;
|
|
1517
|
-
if (typeof g.max_depth === "number" && g.max_depth > 0) merged.global.max_depth = g.max_depth;
|
|
1518
|
-
if (typeof g.max_agents === "number" && g.max_agents > 0) merged.global.max_agents = g.max_agents;
|
|
1519
|
-
if (typeof g.ready_delay_ms === "number" && g.ready_delay_ms >= 0) merged.global.ready_delay_ms = g.ready_delay_ms;
|
|
1520
|
-
if (typeof g.max_lifetime_ms === "number" && g.max_lifetime_ms >= 0) merged.global.max_lifetime_ms = g.max_lifetime_ms;
|
|
1521
|
-
if (g.default_permissions === "skip" || g.default_permissions === "ask") merged.global.default_permissions = g.default_permissions;
|
|
1522
|
-
if (isLanguageCode(g.language)) merged.global.language = g.language;
|
|
1523
|
-
}
|
|
1524
|
-
return merged;
|
|
1525
|
-
}
|
|
1526
|
-
function loadConfig() {
|
|
1527
|
-
try {
|
|
1528
|
-
const content = readFileSync4(configPath(), "utf-8");
|
|
1529
|
-
return mergeDefaults(JSON.parse(content));
|
|
1530
|
-
} catch {
|
|
1531
|
-
return defaultConfig();
|
|
1532
|
-
}
|
|
1533
1475
|
}
|
|
1534
|
-
function
|
|
1535
|
-
const path = configPath();
|
|
1536
|
-
const dir = dirname3(path);
|
|
1537
|
-
mkdirSync3(dir, { recursive: true });
|
|
1538
|
-
const tmp = `${path}.tmp`;
|
|
1539
|
-
writeFileSync3(tmp, JSON.stringify(cfg, null, 2), "utf-8");
|
|
1540
|
-
try {
|
|
1541
|
-
renameSync2(tmp, path);
|
|
1542
|
-
} catch {
|
|
1543
|
-
writeFileSync3(path, JSON.stringify(cfg, null, 2), "utf-8");
|
|
1544
|
-
}
|
|
1545
|
-
return path;
|
|
1546
|
-
}
|
|
1547
|
-
var CONFIG_FIELDS = [
|
|
1548
|
-
{ key: "peek_interval_ms", kind: "posint", label: "peek interval (ms)" },
|
|
1549
|
-
{ key: "peek_lines", kind: "posint", label: "peek lines" },
|
|
1550
|
-
{ key: "max_depth", kind: "posint", label: "max depth" },
|
|
1551
|
-
{ key: "max_agents", kind: "posint", label: "max agents" },
|
|
1552
|
-
{ key: "ready_delay_ms", kind: "nonneg-int", label: "ready delay (ms)" },
|
|
1553
|
-
{ key: "max_lifetime_ms", kind: "nonneg-int", label: "max agent lifetime (ms)" },
|
|
1554
|
-
{ key: "default_permissions", kind: "permissions", label: "default permissions" },
|
|
1555
|
-
{ key: "language", kind: "language", label: "language" }
|
|
1556
|
-
];
|
|
1557
|
-
function configFieldSpec(key) {
|
|
1558
|
-
const spec = CONFIG_FIELDS.find((field) => field.key === key);
|
|
1559
|
-
if (!spec) throw new Error(`unknown config field: ${key}`);
|
|
1560
|
-
return spec;
|
|
1561
|
-
}
|
|
1562
|
-
function parseConfigValue(key, raw) {
|
|
1563
|
-
const spec = configFieldSpec(key);
|
|
1564
|
-
if (spec.kind === "posint" || spec.kind === "nonneg-int") {
|
|
1565
|
-
const n = Number(raw);
|
|
1566
|
-
if (!Number.isFinite(n)) throw new Error(`${spec.label} must be a number`);
|
|
1567
|
-
return n;
|
|
1568
|
-
}
|
|
1569
|
-
return raw;
|
|
1570
|
-
}
|
|
1571
|
-
function validateConfigField(spec, value) {
|
|
1572
|
-
switch (spec.kind) {
|
|
1573
|
-
case "posint":
|
|
1574
|
-
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) throw new Error(`${spec.label} must be a positive integer`);
|
|
1575
|
-
return value;
|
|
1576
|
-
case "nonneg-int":
|
|
1577
|
-
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) throw new Error(`${spec.label} must be zero or a positive integer`);
|
|
1578
|
-
return value;
|
|
1579
|
-
case "permissions":
|
|
1580
|
-
if (value !== "ask" && value !== "skip") throw new Error(`${spec.label} must be ask or skip`);
|
|
1581
|
-
return value;
|
|
1582
|
-
case "language":
|
|
1583
|
-
if (!isLanguageCode(value)) throw new Error(`unknown language: ${String(value)}`);
|
|
1584
|
-
return value;
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
function setConfigValues(patch) {
|
|
1476
|
+
function createAgentWindow(runId, tmuxSession, role, config, inheritedWorkingDir, readyDelayMs, driver) {
|
|
1588
1477
|
const cfg = loadConfig();
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
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;
|
|
1602
1501
|
}
|
|
1603
|
-
function
|
|
1604
|
-
|
|
1502
|
+
function validateAgents(configs, available) {
|
|
1503
|
+
for (const config of configs) requireProvider(config.provider, available);
|
|
1605
1504
|
}
|
|
1606
|
-
function
|
|
1607
|
-
|
|
1608
|
-
const
|
|
1609
|
-
|
|
1610
|
-
|
|
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;
|
|
1611
1517
|
try {
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
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 });
|
|
1615
1550
|
}
|
|
1616
1551
|
}
|
|
1617
|
-
function
|
|
1618
|
-
return value === "default" || value === "low" || value === "medium" || value === "high" || value === "xhigh" || value === "max";
|
|
1619
|
-
}
|
|
1620
|
-
function normalizeSlot(raw, fallbackDir = "") {
|
|
1621
|
-
const promptRaw = typeof raw.initial_prompt === "string" ? raw.initial_prompt : typeof raw.task_template === "string" ? raw.task_template : "";
|
|
1552
|
+
function slotToLaunchConfig(slot) {
|
|
1622
1553
|
return {
|
|
1623
|
-
|
|
1624
|
-
provider:
|
|
1625
|
-
model:
|
|
1626
|
-
auth_mode:
|
|
1627
|
-
effort:
|
|
1628
|
-
|
|
1629
|
-
working_dir:
|
|
1630
|
-
permissions:
|
|
1631
|
-
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
|
|
1632
1563
|
};
|
|
1633
1564
|
}
|
|
1634
|
-
function
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
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
|
|
1648
1599
|
};
|
|
1600
|
+
writeAgent(agent);
|
|
1601
|
+
return agent;
|
|
1649
1602
|
}
|
|
1650
|
-
function
|
|
1651
|
-
const
|
|
1652
|
-
|
|
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;
|
|
1653
1614
|
try {
|
|
1654
|
-
|
|
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) {
|
|
1655
1637
|
try {
|
|
1656
|
-
|
|
1638
|
+
driver.tmux(["kill-session", "-t", tmuxSession]);
|
|
1657
1639
|
} catch {
|
|
1658
|
-
return null;
|
|
1659
1640
|
}
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
|
|
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 });
|
|
1663
1645
|
}
|
|
1664
1646
|
}
|
|
1665
|
-
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}`;
|
|
1666
1672
|
try {
|
|
1667
|
-
|
|
1673
|
+
driver.tmux(["switch-client", "-t", target]);
|
|
1668
1674
|
} catch {
|
|
1669
|
-
return null;
|
|
1670
1675
|
}
|
|
1676
|
+
driver.tmux(["select-window", "-t", target]);
|
|
1671
1677
|
}
|
|
1672
|
-
function
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1678
|
+
function openRunTabs(runId, options = {}) {
|
|
1679
|
+
const driver = options.driver ?? realDriver;
|
|
1680
|
+
const run = readRun(runId);
|
|
1681
|
+
const target = `${run.tmux_session}:reeves`;
|
|
1676
1682
|
try {
|
|
1677
|
-
|
|
1683
|
+
driver.tmux(["switch-client", "-t", target]);
|
|
1678
1684
|
} catch {
|
|
1679
1685
|
}
|
|
1686
|
+
driver.tmux(["select-window", "-t", target]);
|
|
1680
1687
|
}
|
|
1681
|
-
function
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
working_dir: agent.working_dir,
|
|
1693
|
-
permissions: agent.permissions,
|
|
1694
|
-
rc_enabled: agent.rc_enabled
|
|
1695
|
-
};
|
|
1696
|
-
}
|
|
1697
|
-
function savePresetFromRun(runId, name, description = "") {
|
|
1698
|
-
const presetName = sanitizePresetName(name);
|
|
1699
|
-
if (!presetName) throw new Error("preset name is required");
|
|
1700
|
-
const run = readRun(runId);
|
|
1701
|
-
const agents = listAgents(run.id).filter((agent) => !agent.headless);
|
|
1702
|
-
if (agents.length === 0) throw new Error("run has no agents to save as a preset");
|
|
1703
|
-
const root = agents.find((agent) => agent.role === "root") ?? agents[0];
|
|
1704
|
-
const workers = agents.filter((agent) => agent !== root);
|
|
1705
|
-
const existing = loadPreset(presetName);
|
|
1706
|
-
const now = nowIso();
|
|
1707
|
-
const tree = {
|
|
1708
|
-
name: presetName,
|
|
1709
|
-
description,
|
|
1710
|
-
root: agentToSlot(root),
|
|
1711
|
-
workers: workers.map(agentToSlot),
|
|
1712
|
-
created_at: existing?.created_at ?? now,
|
|
1713
|
-
updated_at: now
|
|
1714
|
-
};
|
|
1715
|
-
savePreset(tree);
|
|
1716
|
-
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]);
|
|
1717
1699
|
}
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
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
|
+
}
|
|
1732
1718
|
}
|
|
1733
|
-
function
|
|
1734
|
-
|
|
1735
|
-
const
|
|
1736
|
-
if (!
|
|
1737
|
-
if (
|
|
1738
|
-
|
|
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" });
|
|
1739
1727
|
}
|
|
1740
|
-
function
|
|
1741
|
-
|
|
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";
|
|
1742
1739
|
}
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
"
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
"
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
var realDriver = {
|
|
1758
|
-
tmux(args, input) {
|
|
1759
|
-
return execFileSync4("tmux", args, {
|
|
1760
|
-
encoding: "utf8",
|
|
1761
|
-
input,
|
|
1762
|
-
stdio: input === void 0 ? ["ignore", "pipe", "pipe"] : ["pipe", "pipe", "pipe"]
|
|
1763
|
-
}).trim();
|
|
1764
|
-
},
|
|
1765
|
-
delay(fn, ms) {
|
|
1766
|
-
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
|
+
}
|
|
1767
1754
|
}
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
var STARTUP_READY_POLL_MS = 1e3;
|
|
1771
|
-
var STARTUP_READY_TIMEOUT_MS = 2e4;
|
|
1772
|
-
var lastPasteAtByPane = /* @__PURE__ */ new Map();
|
|
1773
|
-
function sleepSync2(ms) {
|
|
1774
|
-
const buffer = new SharedArrayBuffer(4);
|
|
1775
|
-
const view = new Int32Array(buffer);
|
|
1776
|
-
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" });
|
|
1777
1757
|
}
|
|
1778
|
-
function
|
|
1779
|
-
|
|
1780
|
-
else driver.delay(() => {
|
|
1781
|
-
}, POST_PASTE_ENTER_DELAY_MS);
|
|
1758
|
+
function interrupt(agentId, options = {}) {
|
|
1759
|
+
sendKey(agentId, "ctrl-c", options);
|
|
1782
1760
|
}
|
|
1783
|
-
function
|
|
1784
|
-
|
|
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;
|
|
1785
1786
|
}
|
|
1786
|
-
function
|
|
1787
|
-
const
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
if (
|
|
1792
|
-
|
|
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;
|
|
1793
1812
|
}
|
|
1794
|
-
function
|
|
1795
|
-
const
|
|
1796
|
-
|
|
1813
|
+
function openTmuxTarget(id, options = {}) {
|
|
1814
|
+
const driver = options.driver ?? realDriver;
|
|
1815
|
+
let session;
|
|
1816
|
+
let window;
|
|
1817
|
+
let label;
|
|
1797
1818
|
try {
|
|
1798
|
-
|
|
1799
|
-
|
|
1819
|
+
const run = readRun(id);
|
|
1820
|
+
session = run.tmux_session;
|
|
1821
|
+
window = "reeves";
|
|
1822
|
+
label = run.name;
|
|
1823
|
+
} catch {
|
|
1800
1824
|
try {
|
|
1801
|
-
|
|
1825
|
+
const agent = findAgent(id);
|
|
1826
|
+
session = agent.tmux_session;
|
|
1827
|
+
window = agent.tmux_window_id;
|
|
1828
|
+
label = agent.nickname;
|
|
1802
1829
|
} catch {
|
|
1830
|
+
throw new Error(`no run or agent found: ${id}`);
|
|
1803
1831
|
}
|
|
1832
|
+
if (!windowInSession(driver, session, window)) throw new Error(STALE_WINDOW_ERROR);
|
|
1804
1833
|
}
|
|
1805
|
-
}
|
|
1806
|
-
var STALE_WINDOW_ERROR = "agent window no longer exists (tmux server may have restarted)";
|
|
1807
|
-
function windowInSession(driver, session, windowId) {
|
|
1808
|
-
if (!session || !windowId) return false;
|
|
1834
|
+
const target = `${session}:${window}`;
|
|
1809
1835
|
try {
|
|
1810
|
-
|
|
1836
|
+
driver.tmux(["switch-client", "-t", target]);
|
|
1811
1837
|
} catch {
|
|
1812
|
-
return false;
|
|
1813
1838
|
}
|
|
1814
|
-
}
|
|
1815
|
-
function paneInSession(driver, session, paneId) {
|
|
1816
|
-
if (!session || !paneId) return false;
|
|
1817
1839
|
try {
|
|
1818
|
-
|
|
1840
|
+
driver.tmux(["select-window", "-t", target]);
|
|
1819
1841
|
} catch {
|
|
1820
|
-
return false;
|
|
1821
1842
|
}
|
|
1843
|
+
return { session, window, label };
|
|
1822
1844
|
}
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1845
|
+
|
|
1846
|
+
// src/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;
|
|
1826
1865
|
}
|
|
1827
|
-
function
|
|
1828
|
-
|
|
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);
|
|
1829
1871
|
}
|
|
1830
|
-
function
|
|
1831
|
-
return
|
|
1872
|
+
function opencodeMcpEntry(cmd) {
|
|
1873
|
+
return { type: "local", command: [cmd.command, ...cmd.args], enabled: true };
|
|
1832
1874
|
}
|
|
1833
|
-
function
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1875
|
+
function opencodeAttached() {
|
|
1876
|
+
try {
|
|
1877
|
+
const cfg = readOpencodeConfig(opencodeConfigPath());
|
|
1878
|
+
const mcp = cfg.mcp;
|
|
1879
|
+
return !!mcp && typeof mcp === "object" && SERVER_NAME in mcp;
|
|
1880
|
+
} catch {
|
|
1881
|
+
return false;
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
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");
|
|
1840
1894
|
}
|
|
1841
|
-
function
|
|
1842
|
-
const
|
|
1843
|
-
if (!
|
|
1844
|
-
|
|
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");
|
|
1845
1904
|
}
|
|
1846
|
-
return { windowId, paneId };
|
|
1847
1905
|
}
|
|
1848
|
-
function
|
|
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) {
|
|
1849
1911
|
try {
|
|
1850
|
-
const
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
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);
|
|
1854
1918
|
} catch {
|
|
1855
|
-
return
|
|
1919
|
+
return false;
|
|
1856
1920
|
}
|
|
1857
1921
|
}
|
|
1858
|
-
function
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
try {
|
|
1865
|
-
const sessionName = driver.tmux(["display-message", "-p", "#S"]).trim();
|
|
1866
|
-
const ids2 = readDisplayIds(driver);
|
|
1867
|
-
if (sessionName && ids2) {
|
|
1868
|
-
return { sessionName, windowId: ids2.windowId, paneId: ids2.paneId };
|
|
1869
|
-
}
|
|
1870
|
-
} catch {
|
|
1871
|
-
}
|
|
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;
|
|
1872
1928
|
}
|
|
1873
|
-
|
|
1929
|
+
}
|
|
1930
|
+
function kimiCodeMcpConfig() {
|
|
1874
1931
|
try {
|
|
1875
|
-
|
|
1932
|
+
const raw = readFileSync4(join5(kimiCodeHome(), "mcp.json"), "utf-8").trim();
|
|
1933
|
+
return raw ? JSON.parse(raw) : {};
|
|
1876
1934
|
} catch {
|
|
1935
|
+
return {};
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
function kimiCodeMcpAttached() {
|
|
1939
|
+
const servers = kimiCodeMcpConfig().mcpServers;
|
|
1940
|
+
return !!servers && typeof servers === "object" && SERVER_NAME in servers;
|
|
1941
|
+
}
|
|
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");
|
|
1964
|
+
}
|
|
1877
1965
|
}
|
|
1878
|
-
|
|
1879
|
-
|
|
1966
|
+
};
|
|
1967
|
+
function resolveLaunchCmd(entry = process.argv[1]) {
|
|
1968
|
+
if (entry) {
|
|
1880
1969
|
try {
|
|
1881
|
-
|
|
1970
|
+
const real = realpathSync(entry);
|
|
1971
|
+
if (/\.[cm]?js$/.test(real)) return { command: process.execPath, args: [real, SERVER_ARG] };
|
|
1882
1972
|
} catch {
|
|
1883
1973
|
}
|
|
1884
|
-
ids = readDisplayIds(driver, `=${fallbackName}:reeves`);
|
|
1885
1974
|
}
|
|
1886
|
-
return { sessionName: fallbackName, windowId: ids?.windowId ?? "", paneId: ids?.paneId ?? "" };
|
|
1887
|
-
}
|
|
1888
|
-
function createRunSessionWithReevesTab(driver, tmuxSession, reevesAnchor, workingDir) {
|
|
1889
|
-
driver.tmux(["new-session", "-d", "-s", tmuxSession, "-n", "reeves", "-c", workingDir]);
|
|
1890
|
-
const source = reevesAnchor.windowId || `${reevesAnchor.sessionName}:reeves`;
|
|
1891
1975
|
try {
|
|
1892
|
-
|
|
1976
|
+
const abs = execFileSync3("which", [SERVER_BIN], { encoding: "utf8" }).trim();
|
|
1977
|
+
if (abs) return { command: abs, args: [SERVER_ARG] };
|
|
1893
1978
|
} catch {
|
|
1894
1979
|
}
|
|
1980
|
+
return { command: SERVER_BIN, args: [SERVER_ARG] };
|
|
1895
1981
|
}
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
provider:
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
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 }
|
|
1931
2025
|
}
|
|
1932
|
-
|
|
1933
|
-
|
|
2026
|
+
];
|
|
2027
|
+
function hostBin(host) {
|
|
2028
|
+
return PROVIDER_REGISTRY[host.provider].bin;
|
|
1934
2029
|
}
|
|
1935
|
-
function
|
|
1936
|
-
return
|
|
1937
|
-
id,
|
|
1938
|
-
run_id: runId,
|
|
1939
|
-
nickname: config.nickname || (role === "root" ? providerDisplayName(config.provider) : `${providerDisplayName(config.provider)} agent`),
|
|
1940
|
-
provider: config.provider,
|
|
1941
|
-
model: config.model,
|
|
1942
|
-
role,
|
|
1943
|
-
working_dir: workingDir,
|
|
1944
|
-
task: config.task.trim(),
|
|
1945
|
-
task_status: "queued",
|
|
1946
|
-
task_note: "",
|
|
1947
|
-
tmux_session: tmuxSession,
|
|
1948
|
-
tmux_window_id: ids.windowId,
|
|
1949
|
-
tmux_pane_id: ids.paneId,
|
|
1950
|
-
rc_enabled: false,
|
|
1951
|
-
permissions,
|
|
1952
|
-
inbox: [],
|
|
1953
|
-
last_seen: nowMs(),
|
|
1954
|
-
started_at: nowIso(),
|
|
1955
|
-
ended_at: null
|
|
1956
|
-
};
|
|
2030
|
+
function hostLabel(host) {
|
|
2031
|
+
return PROVIDER_REGISTRY[host.provider].displayName;
|
|
1957
2032
|
}
|
|
1958
|
-
function
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
const permissions = config.permissions ?? cfg.global.default_permissions;
|
|
1963
|
-
const shellCommand = terminalShellCommand(config, permissions);
|
|
1964
|
-
const nickname = config.nickname || providerDisplayName(config.provider);
|
|
1965
|
-
const output = driver.tmux([
|
|
1966
|
-
"new-window",
|
|
1967
|
-
"-d",
|
|
1968
|
-
"-P",
|
|
1969
|
-
"-F",
|
|
1970
|
-
"#{window_id} #{pane_id}",
|
|
1971
|
-
"-t",
|
|
1972
|
-
`${tmuxSession}:`,
|
|
1973
|
-
"-n",
|
|
1974
|
-
tmuxWindowName(config.provider, nickname),
|
|
1975
|
-
"-c",
|
|
1976
|
-
workingDir,
|
|
1977
|
-
shellCommand
|
|
1978
|
-
]);
|
|
1979
|
-
const agent = newAgentRecord(id, runId, tmuxSession, role, config, workingDir, parseTmuxIds(output), permissions);
|
|
1980
|
-
writeAgent(agent);
|
|
1981
|
-
sendDelayedStartupInput(driver, agent, config, readyDelayMs);
|
|
1982
|
-
return agent;
|
|
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;
|
|
1983
2037
|
}
|
|
1984
|
-
function
|
|
1985
|
-
|
|
2038
|
+
function isInstalled(bin) {
|
|
2039
|
+
try {
|
|
2040
|
+
execFileSync3("which", [bin], { stdio: "pipe" });
|
|
2041
|
+
return true;
|
|
2042
|
+
} catch {
|
|
2043
|
+
return false;
|
|
2044
|
+
}
|
|
1986
2045
|
}
|
|
1987
|
-
function
|
|
1988
|
-
const cfg = loadConfig();
|
|
1989
|
-
const driver = options.driver ?? realDriver;
|
|
1990
|
-
const available = options.available ?? detectAvailable();
|
|
1991
|
-
const workers = request.workers ?? [];
|
|
1992
|
-
validateAgents([request.root, ...workers], available);
|
|
1993
|
-
const runId = randomUUID2();
|
|
1994
|
-
const readyDelayMs = request.ready_delay_ms ?? cfg.global.ready_delay_ms;
|
|
1995
|
-
const workingDir = resolveWorkingDir(request.working_dir, process.cwd());
|
|
1996
|
-
const reevesAnchor = pickReevesAnchor(driver);
|
|
1997
|
-
const tmuxSession = tmuxRunSessionName(runId, request.name);
|
|
1998
|
-
let createdRunSession = false;
|
|
2046
|
+
function isAttached(host) {
|
|
1999
2047
|
try {
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
reeves_session: reevesAnchor.sessionName,
|
|
2009
|
-
reeves_window_id: reevesAnchor.windowId,
|
|
2010
|
-
reeves_pane_id: reevesAnchor.paneId,
|
|
2011
|
-
root_agent_id: root.id,
|
|
2012
|
-
working_dir: workingDir,
|
|
2013
|
-
preset_name: request.preset_name ?? null,
|
|
2014
|
-
started_at: nowIso(),
|
|
2015
|
-
ended_at: null
|
|
2016
|
-
};
|
|
2017
|
-
writeRun(run);
|
|
2018
|
-
const workerAgents = workers.map((worker) => {
|
|
2019
|
-
return createAgentWindow(runId, tmuxSession, "worker", worker, workingDir, readyDelayMs, driver);
|
|
2020
|
-
});
|
|
2021
|
-
return { run, agents: [root, ...workerAgents] };
|
|
2022
|
-
} catch (err) {
|
|
2023
|
-
if (createdRunSession) {
|
|
2024
|
-
try {
|
|
2025
|
-
driver.tmux(["kill-session", "-t", tmuxSession]);
|
|
2026
|
-
} catch {
|
|
2027
|
-
}
|
|
2028
|
-
}
|
|
2029
|
-
removeRun(runId);
|
|
2030
|
-
const detail = childProcessOutput(err) || (err instanceof Error ? err.message : "tmux returned a non-zero exit code");
|
|
2031
|
-
throw new Error(`Failed to start run ${request.name}: ${detail}`, { cause: err });
|
|
2048
|
+
const out = execFileSync3(hostBin(host), host.list, {
|
|
2049
|
+
encoding: "utf8",
|
|
2050
|
+
timeout: STATUS_TIMEOUT_MS,
|
|
2051
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
2052
|
+
});
|
|
2053
|
+
return /reevesagents(?![-\w])/i.test(out);
|
|
2054
|
+
} catch {
|
|
2055
|
+
return false;
|
|
2032
2056
|
}
|
|
2033
2057
|
}
|
|
2034
|
-
function
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
effort: slot.effort,
|
|
2041
|
-
task: slot.initial_prompt,
|
|
2042
|
-
working_dir: slot.working_dir,
|
|
2043
|
-
permissions: slot.permissions,
|
|
2044
|
-
rc_enabled: slot.rc_enabled
|
|
2045
|
-
};
|
|
2058
|
+
function runHostCommand(host, args) {
|
|
2059
|
+
execFileSync3(hostBin(host), args, {
|
|
2060
|
+
encoding: "utf8",
|
|
2061
|
+
timeout: MGMT_TIMEOUT_MS,
|
|
2062
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
2063
|
+
});
|
|
2046
2064
|
}
|
|
2047
|
-
function
|
|
2048
|
-
const
|
|
2049
|
-
|
|
2050
|
-
return
|
|
2051
|
-
name: opts.name?.trim() || tree.name,
|
|
2052
|
-
working_dir: opts.working_dir || process.cwd(),
|
|
2053
|
-
root: slotToLaunchConfig(tree.root),
|
|
2054
|
-
workers: tree.workers.map(slotToLaunchConfig),
|
|
2055
|
-
preset_name: tree.name
|
|
2056
|
-
}, options);
|
|
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));
|
|
2057
2069
|
}
|
|
2058
|
-
function
|
|
2059
|
-
const
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
run_id: runId,
|
|
2063
|
-
nickname: providerDisplayName(provider),
|
|
2064
|
-
provider,
|
|
2065
|
-
model: "",
|
|
2066
|
-
role: "root",
|
|
2067
|
-
working_dir: workingDir,
|
|
2068
|
-
task: "",
|
|
2069
|
-
task_status: "working",
|
|
2070
|
-
task_note: "",
|
|
2071
|
-
tmux_session: tmuxSession,
|
|
2072
|
-
tmux_window_id: "",
|
|
2073
|
-
tmux_pane_id: "",
|
|
2074
|
-
rc_enabled: false,
|
|
2075
|
-
permissions: cfg.global.default_permissions,
|
|
2076
|
-
headless: true,
|
|
2077
|
-
inbox: [],
|
|
2078
|
-
last_seen: nowMs(),
|
|
2079
|
-
started_at: nowIso(),
|
|
2080
|
-
ended_at: null
|
|
2081
|
-
};
|
|
2082
|
-
writeAgent(agent);
|
|
2083
|
-
return agent;
|
|
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;
|
|
2084
2074
|
}
|
|
2085
|
-
function
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
try {
|
|
2097
|
-
createRunSessionWithReevesTab(driver, tmuxSession, reevesAnchor, workingDir);
|
|
2098
|
-
createdRunSession = true;
|
|
2099
|
-
const head = createHeadlessHeadAgent(runId, tmuxSession, headProvider, workingDir);
|
|
2100
|
-
const run = {
|
|
2101
|
-
id: runId,
|
|
2102
|
-
name: providerDisplayName(headProvider),
|
|
2103
|
-
status: "running",
|
|
2104
|
-
tmux_session: tmuxSession,
|
|
2105
|
-
reeves_session: reevesAnchor.sessionName,
|
|
2106
|
-
reeves_window_id: reevesAnchor.windowId,
|
|
2107
|
-
reeves_pane_id: reevesAnchor.paneId,
|
|
2108
|
-
root_agent_id: head.id,
|
|
2109
|
-
working_dir: workingDir,
|
|
2110
|
-
preset_name: null,
|
|
2111
|
-
started_at: nowIso(),
|
|
2112
|
-
ended_at: null
|
|
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
|
|
2113
2086
|
};
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
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`
|
|
2098
|
+
};
|
|
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) {
|
|
2119
2114
|
try {
|
|
2120
|
-
|
|
2115
|
+
runHostCommand(host, host.remove);
|
|
2121
2116
|
} catch {
|
|
2122
2117
|
}
|
|
2123
2118
|
}
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
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) };
|
|
2127
2123
|
}
|
|
2128
2124
|
}
|
|
2129
|
-
function
|
|
2130
|
-
const
|
|
2131
|
-
const
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
if (
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
}
|
|
2146
|
-
function openReeves(runId, options = {}) {
|
|
2147
|
-
const driver = options.driver ?? realDriver;
|
|
2148
|
-
const run = readRun(runId);
|
|
2149
|
-
const reevesSession = run.reeves_session ?? run.tmux_session;
|
|
2150
|
-
if (!run.reeves_window_id || !windowInSession(driver, reevesSession, run.reeves_window_id)) {
|
|
2151
|
-
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
|
+
}
|
|
2152
2142
|
}
|
|
2153
|
-
const target = `${reevesSession}:${run.reeves_window_id}`;
|
|
2154
2143
|
try {
|
|
2155
|
-
|
|
2156
|
-
|
|
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) };
|
|
2157
2148
|
}
|
|
2158
|
-
driver.tmux(["select-window", "-t", target]);
|
|
2159
2149
|
}
|
|
2160
|
-
function
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
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
|
+
});
|
|
2164
2170
|
try {
|
|
2165
|
-
|
|
2166
|
-
|
|
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
|
+
}
|
|
2167
2183
|
}
|
|
2168
|
-
driver.tmux(["select-window", "-t", target]);
|
|
2169
2184
|
}
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
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;
|
|
2179
2200
|
}
|
|
2180
|
-
|
|
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
|
+
};
|
|
2181
2212
|
}
|
|
2182
|
-
function
|
|
2183
|
-
const driver = options.driver ?? realDriver;
|
|
2184
|
-
const n = Number.isFinite(lines) && lines > 0 ? Math.floor(lines) : 10;
|
|
2213
|
+
function readProcVersion() {
|
|
2185
2214
|
try {
|
|
2186
|
-
|
|
2187
|
-
if (agent.headless || !agent.tmux_pane_id) return "(headless agent - no output)";
|
|
2188
|
-
if (!paneInSession(driver, agent.tmux_session, agent.tmux_pane_id)) return "";
|
|
2189
|
-
let output = driver.tmux(["capture-pane", "-p", "-e", "-S", String(-n), "-t", agent.tmux_pane_id]);
|
|
2190
|
-
if (!output.trim()) {
|
|
2191
|
-
try {
|
|
2192
|
-
output = driver.tmux(["capture-pane", "-p", "-e", "-a", "-S", String(-n), "-t", agent.tmux_pane_id]);
|
|
2193
|
-
} catch {
|
|
2194
|
-
}
|
|
2195
|
-
}
|
|
2196
|
-
return redactSecrets(stripAnsi(output).trim());
|
|
2215
|
+
return readFileSync5("/proc/version", "utf-8");
|
|
2197
2216
|
} catch {
|
|
2198
2217
|
return "";
|
|
2199
2218
|
}
|
|
2200
2219
|
}
|
|
2201
|
-
function
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
if (!paneInSession(driver, agent.tmux_session, agent.tmux_pane_id)) throw new Error(STALE_WINDOW_ERROR);
|
|
2206
|
-
pasteTextToPane(driver, agent.tmux_pane_id, text);
|
|
2207
|
-
lastPasteAtByPane.set(agent.tmux_pane_id, Date.now());
|
|
2208
|
-
if (!agent.ended_at && agent.task_status === "queued") updateAgent(agent.run_id, agent.id, { task_status: "working" });
|
|
2209
|
-
}
|
|
2210
|
-
function tmuxKey(key) {
|
|
2211
|
-
if (key === "enter") return "Enter";
|
|
2212
|
-
if (key === "escape") return "Escape";
|
|
2213
|
-
if (key === "backspace") return "BSpace";
|
|
2214
|
-
if (key === "tab") return "Tab";
|
|
2215
|
-
if (key === "space") return "Space";
|
|
2216
|
-
if (key === "up") return "Up";
|
|
2217
|
-
if (key === "down") return "Down";
|
|
2218
|
-
if (key === "left") return "Left";
|
|
2219
|
-
if (key === "right") return "Right";
|
|
2220
|
-
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
|
+
);
|
|
2221
2224
|
}
|
|
2222
|
-
function
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
const remaining = POST_PASTE_ENTER_DELAY_MS - (Date.now() - lastPasteAt);
|
|
2231
|
-
if (remaining > 0) {
|
|
2232
|
-
if (driver === realDriver) sleepSync2(remaining);
|
|
2233
|
-
else driver.delay(() => {
|
|
2234
|
-
}, remaining);
|
|
2235
|
-
}
|
|
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
|
+
};
|
|
2236
2233
|
}
|
|
2237
|
-
|
|
2238
|
-
|
|
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
|
+
};
|
|
2239
2246
|
}
|
|
2240
|
-
function
|
|
2241
|
-
|
|
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}` };
|
|
2242
2256
|
}
|
|
2243
|
-
function
|
|
2244
|
-
const
|
|
2245
|
-
const
|
|
2246
|
-
const
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
}
|
|
2253
|
-
const endedAt = nowIso();
|
|
2254
|
-
updateAgent(agent.run_id, agent.id, { ended_at: endedAt, task_status: "done" });
|
|
2255
|
-
const updatedAgent = readAgent(agent.run_id, agent.id);
|
|
2256
|
-
const endedRun = endRunIfNoLiveAgents(agent.run_id, endedAt);
|
|
2257
|
-
if (endedRun.status === "ended" || endedRun.ended_at !== null) {
|
|
2258
|
-
const runOwnsSession = !!run.reeves_session && run.reeves_session !== run.tmux_session;
|
|
2259
|
-
if (runOwnsSession) {
|
|
2260
|
-
try {
|
|
2261
|
-
driver.tmux(["kill-session", "-t", `=${run.tmux_session}`]);
|
|
2262
|
-
} catch {
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
archiveAndRemoveRun(run.id, "ended");
|
|
2266
|
-
}
|
|
2267
|
-
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
|
+
};
|
|
2268
2266
|
}
|
|
2269
|
-
function
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
const endedAt = nowIso();
|
|
2273
|
-
const runOwnsSession = !!run.reeves_session && run.reeves_session !== run.tmux_session;
|
|
2274
|
-
if (runOwnsSession) {
|
|
2275
|
-
try {
|
|
2276
|
-
driver.tmux(["kill-session", "-t", `=${run.tmux_session}`]);
|
|
2277
|
-
} catch {
|
|
2278
|
-
}
|
|
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" };
|
|
2279
2270
|
}
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
}
|
|
2287
|
-
}
|
|
2288
|
-
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` };
|
|
2289
2277
|
}
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2278
|
+
return {
|
|
2279
|
+
name: "provider compat",
|
|
2280
|
+
status: "warn",
|
|
2281
|
+
detail: problems.slice(0, 3).join("; ") + (problems.length > 3 ? `; +${problems.length - 3} more` : "")
|
|
2282
|
+
};
|
|
2294
2283
|
}
|
|
2295
|
-
function
|
|
2296
|
-
|
|
2297
|
-
let session;
|
|
2298
|
-
let window;
|
|
2299
|
-
let label;
|
|
2284
|
+
function checkPathAccess(name, path) {
|
|
2285
|
+
if (!existsSync5(path)) return { name, status: "warn", detail: `${path} (will be created on first use)` };
|
|
2300
2286
|
try {
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
window = "reeves";
|
|
2304
|
-
label = run.name;
|
|
2287
|
+
accessSync(path, constants.R_OK | constants.W_OK);
|
|
2288
|
+
return { name, status: "ok", detail: path };
|
|
2305
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) => {
|
|
2306
2296
|
try {
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
window = agent.tmux_window_id;
|
|
2310
|
-
label = agent.nickname;
|
|
2297
|
+
requireFrom.resolve(name);
|
|
2298
|
+
return false;
|
|
2311
2299
|
} catch {
|
|
2312
|
-
|
|
2300
|
+
return true;
|
|
2313
2301
|
}
|
|
2314
|
-
|
|
2302
|
+
});
|
|
2303
|
+
if (missing.length === 0) {
|
|
2304
|
+
return { name: "web extras", status: "ok", detail: `${WEB_EXTRA_MODULES.join(" + ")} present (web UI available)` };
|
|
2315
2305
|
}
|
|
2316
|
-
|
|
2306
|
+
return { name: "web extras", status: "warn", detail: `${missing.join(", ")} not installed; TUI unaffected, web UI disabled` };
|
|
2307
|
+
}
|
|
2308
|
+
function checkRunsState() {
|
|
2317
2309
|
try {
|
|
2318
|
-
|
|
2319
|
-
|
|
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
|
+
};
|
|
2320
2328
|
}
|
|
2321
2329
|
try {
|
|
2322
|
-
|
|
2330
|
+
accessSync(cmd.command, constants.X_OK);
|
|
2331
|
+
return { name: "mcp server", status: "ok", detail: `${cmd.command} ${cmd.args.join(" ")}` };
|
|
2323
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
|
+
};
|
|
2324
2338
|
}
|
|
2325
|
-
|
|
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
|
+
};
|
|
2326
2356
|
}
|
|
2327
2357
|
|
|
2328
2358
|
export {
|
|
2359
|
+
redactSecrets,
|
|
2329
2360
|
PROVIDER_DEFS,
|
|
2330
2361
|
coerceExtraArgs,
|
|
2331
2362
|
BIN,
|
|
@@ -2336,14 +2367,12 @@ export {
|
|
|
2336
2367
|
providerSupportsEffort,
|
|
2337
2368
|
buildCommand,
|
|
2338
2369
|
detectAvailable,
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
modelBadgeLabel,
|
|
2346
|
-
redactSecrets,
|
|
2370
|
+
exactSession,
|
|
2371
|
+
tmuxAvailable,
|
|
2372
|
+
sessionExists,
|
|
2373
|
+
targetExists,
|
|
2374
|
+
windowIds,
|
|
2375
|
+
windowByName,
|
|
2347
2376
|
stateRoot,
|
|
2348
2377
|
runsDir,
|
|
2349
2378
|
runDir,
|
|
@@ -2361,19 +2390,8 @@ export {
|
|
|
2361
2390
|
archiveAndRemoveRun,
|
|
2362
2391
|
listAgents,
|
|
2363
2392
|
findAgent,
|
|
2364
|
-
defaultTmuxAvailable,
|
|
2365
|
-
defaultTmuxTargetExists,
|
|
2366
2393
|
runHasLiveTmuxTarget,
|
|
2367
2394
|
autoCleanupRuns,
|
|
2368
|
-
resolveLaunchCmd,
|
|
2369
|
-
hostStatus,
|
|
2370
|
-
attach,
|
|
2371
|
-
detach,
|
|
2372
|
-
attachAll,
|
|
2373
|
-
verifyServerLaunch,
|
|
2374
|
-
nodeVersionCheck,
|
|
2375
|
-
checkTmux,
|
|
2376
|
-
runDoctor,
|
|
2377
2395
|
LANGUAGE_OPTIONS,
|
|
2378
2396
|
DEFAULT_LANGUAGE,
|
|
2379
2397
|
isLanguageCode,
|
|
@@ -2392,6 +2410,10 @@ export {
|
|
|
2392
2410
|
savePreset,
|
|
2393
2411
|
deletePreset,
|
|
2394
2412
|
savePresetFromRun,
|
|
2413
|
+
providerDisplayName,
|
|
2414
|
+
providerColor,
|
|
2415
|
+
modelColor,
|
|
2416
|
+
modelBadgeLabel,
|
|
2395
2417
|
ALLOWED_KEYS,
|
|
2396
2418
|
startRun,
|
|
2397
2419
|
startRunFromPreset,
|
|
@@ -2406,6 +2428,15 @@ export {
|
|
|
2406
2428
|
interrupt,
|
|
2407
2429
|
killAgent,
|
|
2408
2430
|
stopRun,
|
|
2409
|
-
openTmuxTarget
|
|
2431
|
+
openTmuxTarget,
|
|
2432
|
+
resolveLaunchCmd,
|
|
2433
|
+
hostStatus,
|
|
2434
|
+
attach,
|
|
2435
|
+
detach,
|
|
2436
|
+
attachAll,
|
|
2437
|
+
verifyServerLaunch,
|
|
2438
|
+
nodeVersionCheck,
|
|
2439
|
+
checkTmux,
|
|
2440
|
+
runDoctor
|
|
2410
2441
|
};
|
|
2411
|
-
//# sourceMappingURL=chunk-
|
|
2442
|
+
//# sourceMappingURL=chunk-GSWMKYSU.js.map
|