@gorlitzer-labs/seldon 0.19.1 → 0.20.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 CHANGED
@@ -85,6 +85,8 @@ seldon lane start [dir] --task "fix the save crash" [--agent codex]
85
85
  seldon lane stop|resume|open <name or key>
86
86
  seldon lane rm <name or key> [--force] # a stopped lane: its worktree goes,
87
87
  # its branch too if git sees it merged
88
+ seldon lane read <name or key> [--json] # what it last said
89
+ seldon lane say <name or key> "use staging" # answer it (tmux agents, only while waiting)
88
90
  ```
89
91
 
90
92
  ## 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";
@@ -1482,7 +1482,7 @@ function lanesCmd(flags) {
1482
1482
  }
1483
1483
  }
1484
1484
 
1485
- function laneCmd(verb, arg, flags) {
1485
+ function laneCmd(verb, arg, flags, rest = []) {
1486
1486
  const fail = (msg) => { console.log(C.red(msg)); process.exitCode = 1; };
1487
1487
  if (verb === "start") {
1488
1488
  const root = projectRoot(path.resolve(arg || ".")) || path.resolve(arg || ".");
@@ -1490,9 +1490,33 @@ function laneCmd(verb, arg, flags) {
1490
1490
  const r = startLane({ root, name: path.basename(root), task, harness: flags.agent || "claude" });
1491
1491
  return r.ok ? console.log(C.green(`✓ started ${r.slug}`) + C.dim(` (${flags.agent || "claude"}) in ${root}`)) : fail(`could not start: ${r.error}`);
1492
1492
  }
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>');
1493
+ 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
1494
  const lane = arg && findLane(arg);
1495
1495
  if (!lane) return fail(`no lane ${arg || ""} — see: seldon lanes`);
1496
+ if (verb === "read") {
1497
+ const how = readCommand(lane);
1498
+ if (how.why) return fail(`can't read ${lane.name}: ${how.why}`);
1499
+ let text = "";
1500
+ if (how.transcript) {
1501
+ const dir = path.join(os.homedir(), ".claude", "projects");
1502
+ let file = null;
1503
+ try { for (const d of fs.readdirSync(dir)) { const f = path.join(dir, d, how.transcript); if (fs.existsSync(f)) { file = f; break; } } } catch {}
1504
+ if (!file) return fail(`can't read ${lane.name}: its conversation file is gone`);
1505
+ text = lastAssistantText(fs.readFileSync(file, "utf8"));
1506
+ } else {
1507
+ const r = spawnSync(how.bin, how.args, { encoding: "utf8" });
1508
+ if (r.status !== 0) return fail(`can't read ${lane.name}: ${(r.stderr || "").trim()}`);
1509
+ text = r.stdout.replace(/\s+$/, "");
1510
+ }
1511
+ if (flags.json) return console.log(JSON.stringify({ key: lane.key, name: lane.name, state: lane.state, waitingFor: lane.waitingFor || null, text }));
1512
+ return console.log(text || C.dim("(nothing yet)"));
1513
+ }
1514
+ if (verb === "say") {
1515
+ const how = sayCommands(lane, rest.join(" "));
1516
+ if (how.why) return fail(`can't tell ${lane.name}: ${how.why}`);
1517
+ for (const [bin, ...args] of how.cmds) if (spawnSync(bin, args).status !== 0) return fail(`can't tell ${lane.name}: ${bin} failed`);
1518
+ return console.log(C.green(`✓ told ${lane.name}`));
1519
+ }
1496
1520
  if (verb === "open") {
1497
1521
  const how = openCommand(lane);
1498
1522
  if (how.why) return fail(`can't open ${lane.name}: ${how.why}`);
@@ -1954,7 +1978,7 @@ const ids = tokens.filter((id) => byId[id]); // only the valid module
1954
1978
  if (cmd === "report") return reportCmd(tokens[0]);
1955
1979
  if (cmd === "lanes") return lanesCmd(flags);
1956
1980
  if (cmd === "machines") return machinesCmd(tokens[0], tokens[1], tokens[2]);
1957
- if (cmd === "lane") return laneCmd(tokens[0], tokens[1], flags);
1981
+ if (cmd === "lane") return laneCmd(tokens[0], tokens[1], flags, tokens.slice(2));
1958
1982
  if (cmd === "ws") return wsCmd(tokens[0], tokens[1]);
1959
1983
  if (cmd === "tell") return tellCmd(tokens, flags);
1960
1984
  if (cmd === "inbox") return inboxCmd(flags);
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gorlitzer-labs/seldon",
3
- "version": "0.19.1",
3
+ "version": "0.20.0",
4
4
  "description": "Install the Seldon stack — pick your tools from a checklist; each installs via its native method.",
5
5
  "type": "module",
6
6
  "bin": {