@gorlitzer-labs/seldon 0.19.1 → 0.21.0
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/README.md +4 -0
- package/bin/seldon.js +49 -8
- package/lib/lanes.mjs +33 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,6 +48,8 @@ Every agent, on every machine, beside the one you're talking to. One key to swit
|
|
|
48
48
|
| `Alt-h` | home: the full panel on the right |
|
|
49
49
|
| `Alt-q` | leave. Agents keep running |
|
|
50
50
|
|
|
51
|
+
In the list: `n` **new agent** (type the task, pick 1 claude · 2 codex · 3 opencode), `⏎` open, `tab` next ⚑.
|
|
52
|
+
|
|
51
53
|
- **Real terminals.** The right side is the agent itself, not a copy.
|
|
52
54
|
- **Switching never stops anything.** Leave, reconnect from anywhere, it's all still there.
|
|
53
55
|
- **Both laptops, one list.** Agents on `seldon machines` open over ssh in the same pane. A sleeping one shows ☾ and waits.
|
|
@@ -85,6 +87,8 @@ seldon lane start [dir] --task "fix the save crash" [--agent codex]
|
|
|
85
87
|
seldon lane stop|resume|open <name or key>
|
|
86
88
|
seldon lane rm <name or key> [--force] # a stopped lane: its worktree goes,
|
|
87
89
|
# its branch too if git sees it merged
|
|
90
|
+
seldon lane read <name or key> [--json] # what it last said
|
|
91
|
+
seldon lane say <name or key> "use staging" # answer it (tmux agents, only while waiting)
|
|
88
92
|
```
|
|
89
93
|
|
|
90
94
|
## Codex and opencode: let them report their state
|
package/bin/seldon.js
CHANGED
|
@@ -10,7 +10,7 @@ import readline from "node:readline";
|
|
|
10
10
|
import { MODULES, byId, DEPS, RAW, MONOREPO, withRequires, platformOk } from "../modules.mjs";
|
|
11
11
|
import { ensureSiblingPath, has, loadState, resolveProject, adopt as fAdopt, staff as fStaff, attach as fAttach, hiveOf, sameDir } from "../lib/projects.mjs";
|
|
12
12
|
import { readLanes, readPlan, addToPlan, projectRoot, writeReport } from "../lib/agents.mjs";
|
|
13
|
-
import { openCommand, stopCommand, transitions, laneForItem, slugify, HARNESSES } from "../lib/lanes.mjs";
|
|
13
|
+
import { openCommand, stopCommand, readCommand, lastAssistantText, sayCommands, transitions, laneForItem, slugify, HARNESSES } from "../lib/lanes.mjs";
|
|
14
14
|
import { startLane, stopLane, resumeLane, removeLane, findLane } from "../lib/actions.mjs";
|
|
15
15
|
import { listMachines, addMachine, fetchLanes, machinePoller, sshArgs, lastJsonLine } from "../lib/machines.mjs";
|
|
16
16
|
import { notify } from "../lib/notify.mjs";
|
|
@@ -908,7 +908,7 @@ const pad = (text, width, color = (x) => x) => color(String(text)) + " ".repeat(
|
|
|
908
908
|
// grouped by the project it works on, the ones waiting on you first. Lanes are read from the
|
|
909
909
|
// harnesses themselves (lib/agents.mjs), not from rooms, so the panel works with or without
|
|
910
910
|
// factory and apiary; when factory is there its projects and plans are shown too.
|
|
911
|
-
async function panel() {
|
|
911
|
+
async function panel({ newFor = null } = {}) {
|
|
912
912
|
ensureSiblingPath();
|
|
913
913
|
let groups = [], state = null, rows = [], cur = 0, note = "";
|
|
914
914
|
let lastState = 0;
|
|
@@ -1158,6 +1158,14 @@ async function panel() {
|
|
|
1158
1158
|
},
|
|
1159
1159
|
};
|
|
1160
1160
|
|
|
1161
|
+
// Opened by the workspace's n: go straight to "new agent" for the project of the agent that
|
|
1162
|
+
// was selected there (or the repo seldon runs in), so starting one is one key from the list.
|
|
1163
|
+
if (newFor !== null) {
|
|
1164
|
+
const projects = rows.filter((r) => r.type === "project").map((r) => r.project);
|
|
1165
|
+
const p = projects.find((x) => (x.lanes || []).some((l) => l.key === newFor)) || projects.find((x) => sameDir(x.root, here)) || projects[0];
|
|
1166
|
+
if (p) ask(`NEW AGENT · ${p.name}`, "task ›", (task) => pickHarness(p, task));
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1161
1169
|
await rawSession({
|
|
1162
1170
|
draw,
|
|
1163
1171
|
onError: (e) => { note = C.red("error: ") + (e?.message || String(e)); mode = { name: "home" }; },
|
|
@@ -1482,7 +1490,7 @@ function lanesCmd(flags) {
|
|
|
1482
1490
|
}
|
|
1483
1491
|
}
|
|
1484
1492
|
|
|
1485
|
-
function laneCmd(verb, arg, flags) {
|
|
1493
|
+
function laneCmd(verb, arg, flags, rest = []) {
|
|
1486
1494
|
const fail = (msg) => { console.log(C.red(msg)); process.exitCode = 1; };
|
|
1487
1495
|
if (verb === "start") {
|
|
1488
1496
|
const root = projectRoot(path.resolve(arg || ".")) || path.resolve(arg || ".");
|
|
@@ -1490,9 +1498,33 @@ function laneCmd(verb, arg, flags) {
|
|
|
1490
1498
|
const r = startLane({ root, name: path.basename(root), task, harness: flags.agent || "claude" });
|
|
1491
1499
|
return r.ok ? console.log(C.green(`✓ started ${r.slug}`) + C.dim(` (${flags.agent || "claude"}) in ${root}`)) : fail(`could not start: ${r.error}`);
|
|
1492
1500
|
}
|
|
1493
|
-
if (!["stop", "resume", "open", "rm"].includes(verb)) return fail('usage: seldon lane start [dir] --task "…" [--agent claude|codex|opencode] · seldon lane stop|resume|open|rm <key>');
|
|
1501
|
+
if (!["stop", "resume", "open", "rm", "read", "say"].includes(verb)) return fail('usage: seldon lane start [dir] --task "…" [--agent claude|codex|opencode] · seldon lane stop|resume|open|rm|read <key> · seldon lane say <key> "text"');
|
|
1494
1502
|
const lane = arg && findLane(arg);
|
|
1495
1503
|
if (!lane) return fail(`no lane ${arg || ""} — see: seldon lanes`);
|
|
1504
|
+
if (verb === "read") {
|
|
1505
|
+
const how = readCommand(lane);
|
|
1506
|
+
if (how.why) return fail(`can't read ${lane.name}: ${how.why}`);
|
|
1507
|
+
let text = "";
|
|
1508
|
+
if (how.transcript) {
|
|
1509
|
+
const dir = path.join(os.homedir(), ".claude", "projects");
|
|
1510
|
+
let file = null;
|
|
1511
|
+
try { for (const d of fs.readdirSync(dir)) { const f = path.join(dir, d, how.transcript); if (fs.existsSync(f)) { file = f; break; } } } catch {}
|
|
1512
|
+
if (!file) return fail(`can't read ${lane.name}: its conversation file is gone`);
|
|
1513
|
+
text = lastAssistantText(fs.readFileSync(file, "utf8"));
|
|
1514
|
+
} else {
|
|
1515
|
+
const r = spawnSync(how.bin, how.args, { encoding: "utf8" });
|
|
1516
|
+
if (r.status !== 0) return fail(`can't read ${lane.name}: ${(r.stderr || "").trim()}`);
|
|
1517
|
+
text = r.stdout.replace(/\s+$/, "");
|
|
1518
|
+
}
|
|
1519
|
+
if (flags.json) return console.log(JSON.stringify({ key: lane.key, name: lane.name, state: lane.state, waitingFor: lane.waitingFor || null, text }));
|
|
1520
|
+
return console.log(text || C.dim("(nothing yet)"));
|
|
1521
|
+
}
|
|
1522
|
+
if (verb === "say") {
|
|
1523
|
+
const how = sayCommands(lane, rest.join(" "));
|
|
1524
|
+
if (how.why) return fail(`can't tell ${lane.name}: ${how.why}`);
|
|
1525
|
+
for (const [bin, ...args] of how.cmds) if (spawnSync(bin, args).status !== 0) return fail(`can't tell ${lane.name}: ${bin} failed`);
|
|
1526
|
+
return console.log(C.green(`✓ told ${lane.name}`));
|
|
1527
|
+
}
|
|
1496
1528
|
if (verb === "open") {
|
|
1497
1529
|
const how = openCommand(lane);
|
|
1498
1530
|
if (how.why) return fail(`can't open ${lane.name}: ${how.why}`);
|
|
@@ -1546,6 +1578,14 @@ function wsOpen(row) {
|
|
|
1546
1578
|
wsSave(WS_CURRENT, row.off ? "" : row.key);
|
|
1547
1579
|
wsFocus(main);
|
|
1548
1580
|
}
|
|
1581
|
+
// n in the list: the panel, on the right, already asking for the new agent's task.
|
|
1582
|
+
function wsNewAgent(row) {
|
|
1583
|
+
const main = wsOpt("@main");
|
|
1584
|
+
const argv = ["panel", "--new", ...(row && !row.off ? ["--for", row.key] : [])].map(shq).join(" ");
|
|
1585
|
+
wsTmux(["respawn-pane", "-k", "-t", main, `sh -c ${shq(`${wsSelf()} ${argv}; exec ${wsHome()}`)}`]);
|
|
1586
|
+
wsSave(WS_CURRENT, "");
|
|
1587
|
+
wsFocus(main);
|
|
1588
|
+
}
|
|
1549
1589
|
function wsGoHome() {
|
|
1550
1590
|
const main = wsOpt("@main");
|
|
1551
1591
|
wsTmux(["respawn-pane", "-k", "-t", main, wsHome()]);
|
|
@@ -1578,7 +1618,7 @@ async function wsSidebar() {
|
|
|
1578
1618
|
const width = process.stdout.columns || 38, height = process.stdout.rows || 40;
|
|
1579
1619
|
const open = wsCurrent(), h = wsHeadline(rows);
|
|
1580
1620
|
const head = [` ${C.bold("SELDON")} ${h.need ? C.gold(`⚑ ${h.need}`) : C.dim("⚑ 0")} ${C.green(`● ${h.busy}`)}`, ""];
|
|
1581
|
-
const foot = ["", C.dim(" ⏎ open · n next ⚑ · h home"), C.dim(" Alt-1…9 from any pane · q leave"), ...(note ? [" " + note] : [])];
|
|
1621
|
+
const foot = ["", C.dim(" ⏎ open · n new agent · tab next ⚑ · h home"), C.dim(" Alt-1…9 from any pane · q leave"), ...(note ? [" " + note] : [])];
|
|
1582
1622
|
const body = []; let curLine = 0, last = null;
|
|
1583
1623
|
if (!rows.length) body.push(C.dim(" no agents running"), C.dim(" h, then n starts one"));
|
|
1584
1624
|
const faces = assignEmoji(rows.map((r) => r.name));
|
|
@@ -1607,7 +1647,8 @@ async function wsSidebar() {
|
|
|
1607
1647
|
else if (key?.name === "down" || str === "j") cur = Math.min(rows.length - 1, cur + 1);
|
|
1608
1648
|
else if (key?.name === "return") openRow(rows[cur]);
|
|
1609
1649
|
else if (/^[1-9]$/.test(str || "")) openRow(findRow(rows, str));
|
|
1610
|
-
else if (str === "n")
|
|
1650
|
+
else if (str === "n") wsNewAgent(rows[cur]);
|
|
1651
|
+
else if (key?.name === "tab") { const r = nextNeeding(rows, wsCurrent()); if (r) openRow(r); else note = C.dim("nobody is waiting on you"); }
|
|
1611
1652
|
else if (str === "h") wsGoHome();
|
|
1612
1653
|
else if (str === "r") load();
|
|
1613
1654
|
else if (str === "q" || (key?.ctrl && key.name === "c")) wsTmux(["detach-client"]);
|
|
@@ -1954,12 +1995,12 @@ const ids = tokens.filter((id) => byId[id]); // only the valid module
|
|
|
1954
1995
|
if (cmd === "report") return reportCmd(tokens[0]);
|
|
1955
1996
|
if (cmd === "lanes") return lanesCmd(flags);
|
|
1956
1997
|
if (cmd === "machines") return machinesCmd(tokens[0], tokens[1], tokens[2]);
|
|
1957
|
-
if (cmd === "lane") return laneCmd(tokens[0], tokens[1], flags);
|
|
1998
|
+
if (cmd === "lane") return laneCmd(tokens[0], tokens[1], flags, tokens.slice(2));
|
|
1958
1999
|
if (cmd === "ws") return wsCmd(tokens[0], tokens[1]);
|
|
1959
2000
|
if (cmd === "tell") return tellCmd(tokens, flags);
|
|
1960
2001
|
if (cmd === "inbox") return inboxCmd(flags);
|
|
1961
2002
|
if (cmd === "setup") return setupCmd(tokens[0], flags);
|
|
1962
|
-
if (cmd === "panel") return panel();
|
|
2003
|
+
if (cmd === "panel") return panel({ newFor: flags.new ? (typeof flags.for === "string" ? flags.for : "") : null });
|
|
1963
2004
|
if (cmd && cmd !== "install") { help(); process.exitCode = 1; return; }
|
|
1964
2005
|
if (cmd === "install") return install_picker({ dev }); // `install` with no ids
|
|
1965
2006
|
|
package/lib/lanes.mjs
CHANGED
|
@@ -139,6 +139,39 @@ export function openCommand(lane) {
|
|
|
139
139
|
return { why: "it runs in a terminal seldon cannot reach — switch to that window" };
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
// ---- reading an agent and answering it (what the voice uses) ----------------------
|
|
143
|
+
// What an agent last said. Claude keeps its conversation on disk, which still reads after its
|
|
144
|
+
// process is gone; any other agent is read off its tmux screen.
|
|
145
|
+
export function readCommand(lane, lines = 40) {
|
|
146
|
+
if (lane.harness === "claude" && lane.sessionId) return { transcript: `${lane.sessionId}.jsonl` };
|
|
147
|
+
if (lane.tmuxSession) return { bin: "tmux", args: ["capture-pane", "-p", "-J", "-t", lane.tmuxSession, "-S", `-${lines}`] };
|
|
148
|
+
return { why: "seldon cannot see where it runs" };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// The last thing the assistant wrote, from a Claude transcript (JSON lines).
|
|
152
|
+
export function lastAssistantText(jsonl) {
|
|
153
|
+
const rows = String(jsonl).split("\n");
|
|
154
|
+
for (let i = rows.length - 1; i >= 0; i--) {
|
|
155
|
+
let e; try { e = JSON.parse(rows[i]); } catch { continue; }
|
|
156
|
+
if (e?.type !== "assistant") continue;
|
|
157
|
+
const c = e.message?.content;
|
|
158
|
+
const text = typeof c === "string" ? c : Array.isArray(c) ? c.filter((b) => b?.type === "text").map((b) => b.text).join("\n") : "";
|
|
159
|
+
if (text.trim()) return text.trim();
|
|
160
|
+
}
|
|
161
|
+
return "";
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Type a line into an agent and press Enter. Only an agent that is waiting gets typed into, so
|
|
165
|
+
// a misheard sentence never lands in the middle of its work. Only tmux can be typed into: a
|
|
166
|
+
// Claude background session has no way in from outside, so the answer is to open it.
|
|
167
|
+
export function sayCommands(lane, text) {
|
|
168
|
+
const line = String(text || "").replace(/[\r\n]+/g, " ").trim();
|
|
169
|
+
if (!line) return { why: "nothing to say" };
|
|
170
|
+
if (lane.state !== "needs-you" && lane.state !== "idle") return { why: `it is ${lane.state || "busy"}, not waiting for you` };
|
|
171
|
+
if (!lane.tmuxSession) return { why: "it is a background session — open it to answer" };
|
|
172
|
+
return { cmds: [["tmux", "send-keys", "-t", lane.tmuxSession, "-l", line], ["tmux", "send-keys", "-t", lane.tmuxSession, "Enter"]] };
|
|
173
|
+
}
|
|
174
|
+
|
|
142
175
|
// ---- starting and stopping lanes -------------------------------------------------
|
|
143
176
|
// A lane's name is its task, slugged: it names the session, the branch and the worktree, so
|
|
144
177
|
// the plan item, the running agent and the branch on GitHub all read the same.
|