@gorlitzer-labs/seldon 0.19.0 → 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
@@ -8,11 +8,11 @@ import fs from "node:fs";
8
8
  import os from "node:os";
9
9
  import readline from "node:readline";
10
10
  import { MODULES, byId, DEPS, RAW, MONOREPO, withRequires, platformOk } from "../modules.mjs";
11
- import { ensureSiblingPath, loadState, resolveProject, adopt as fAdopt, staff as fStaff, attach as fAttach, hiveOf, sameDir } from "../lib/projects.mjs";
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
- import { listMachines, addMachine, fetchLanes, remoteGroups, sshArgs, lastJsonLine } from "../lib/machines.mjs";
15
+ import { listMachines, addMachine, fetchLanes, machinePoller, sshArgs, lastJsonLine } from "../lib/machines.mjs";
16
16
  import { notify } from "../lib/notify.mjs";
17
17
  import { sendCard, watchCard, KINDS, tokenName, readChat, writeChat, chatFromUpdates, getUpdates, sendText, sendFile, pollUpdates, fileFromMessage, inboxName, freeName, noteLine, downloadFile, react, MAX_DOWNLOAD } from "../lib/telegram.mjs";
18
18
  import { reportFromEvent, mergeCodexHooks, removeCodexHooks, opencodePlugin } from "../lib/reports.mjs";
@@ -63,8 +63,8 @@ function run(cmd, args, opts = {}) {
63
63
  return r.status === 0;
64
64
  }
65
65
 
66
- // Is a command on PATH? (used to pick the fastest package manager)
67
- const has = (bin) => { try { execSync(`command -v ${bin}`, { stdio: "ignore" }); return true; } catch { return false; } };
66
+ // Colour per lane state, shared by the panel and the workspace list.
67
+ const TINT = { "needs-you": C.gold, working: C.green, running: C.green, idle: C.dim, failed: C.red, stopped: C.dim, off: C.dim };
68
68
 
69
69
  // A usable uv, for Python modules. Prefer one on PATH; else a prior isolated
70
70
  // copy; else bootstrap uv into ~/.seldon/bin with NO shell/profile changes.
@@ -326,7 +326,7 @@ async function doInstall(ids, { dev } = {}) {
326
326
  const bad = results.filter(([, r]) => !r).map(([i]) => i);
327
327
  console.log("\n" + C.bold("Done. ") + C.green(good.join(", ") || "—") + (bad.length ? " " + C.red("failed: " + bad.join(", ")) : ""));
328
328
  // demerzel's models are the heavy part — offer to pull them now, at install time.
329
- if (good.includes("demerzel")) await ensureDemerzelModels({ ask: true });
329
+ if (good.includes("demerzel")) await ensureDemerzelModels();
330
330
  }
331
331
 
332
332
  // ---- uninstall --------------------------------------------------------------
@@ -495,30 +495,6 @@ function demerzelModelsMissing() {
495
495
  const demerzelModelsReady = () => demerzelModelsMissing().length === 0;
496
496
  const demerzelInstalled = () => fs.existsSync(path.join(SELDON_HOME, "demerzel", ".venv", "bin", "python"));
497
497
 
498
- // This machine's Tailscale IPv4 (100.64.0.0/10), or null. Tries PATH then the
499
- // macOS app location. Used to expose the voice to your phone over the tailnet.
500
- function tailnetIp() {
501
- for (const bin of ["tailscale", "/Applications/Tailscale.app/Contents/MacOS/tailscale"]) {
502
- try {
503
- const ip = execSync(`${bin} ip -4`, { stdio: ["ignore", "pipe", "ignore"] }).toString().trim().split(/\s+/)[0];
504
- if (/^100\./.test(ip)) return ip;
505
- } catch {}
506
- }
507
- // CLI missing/moved? The tailnet address is still on a utun interface —
508
- // read it straight from the OS (Tailscale's CGNAT range is 100.64.0.0/10).
509
- try {
510
- const out = execSync("ifconfig", { stdio: ["ignore", "pipe", "ignore"] }).toString();
511
- const m = out.match(/inet (100\.(?:6[4-9]|[7-9]\d|1[01]\d|12[0-7])\.\d+\.\d+)/);
512
- if (m) return m[1];
513
- } catch {}
514
- try { // linux `ip addr`
515
- const out = execSync("ip -4 addr", { stdio: ["ignore", "pipe", "ignore"] }).toString();
516
- const m = out.match(/inet (100\.(?:6[4-9]|[7-9]\d|1[01]\d|12[0-7])\.\d+\.\d+)/);
517
- if (m) return m[1];
518
- } catch {}
519
- return null;
520
- }
521
-
522
498
  // Find the Tailscale CLI (PATH, homebrew, or the macOS app bundle).
523
499
  function tailscaleBin() {
524
500
  for (const b of ["tailscale", "/opt/homebrew/bin/tailscale", "/usr/local/bin/tailscale", "/Applications/Tailscale.app/Contents/MacOS/tailscale", "/usr/bin/tailscale"]) {
@@ -571,7 +547,7 @@ function tailscaleServeSetup() {
571
547
  // Fetch demerzel's model set (~25 GB) — offered, never silent. Respects the
572
548
  // chosen LLM (DEMERZEL_LLM) so `seldon install demerzel` / `seldon up` pull the
573
549
  // model you'll actually run. --models forces yes, --no-models forces skip.
574
- async function ensureDemerzelModels({ ask = true } = {}) {
550
+ async function ensureDemerzelModels() {
575
551
  if (!demerzelInstalled() || !platformOk(byId.demerzel)) return false;
576
552
  if (demerzelModelsReady()) return true;
577
553
  const home = path.join(SELDON_HOME, "demerzel");
@@ -691,7 +667,7 @@ async function up() {
691
667
  const home = path.join(SELDON_HOME, "demerzel");
692
668
  if (!platformOk(dem)) later.push("Voice (demerzel) needs macOS on Apple silicon — skipped here.");
693
669
  else {
694
- if (!demerzelModelsReady()) await ensureDemerzelModels({ ask: true }); // offer the fetch inline
670
+ if (!demerzelModelsReady()) await ensureDemerzelModels(); // offer the fetch inline
695
671
  if (demerzelModelsReady()) {
696
672
  const env = { ...process.env };
697
673
  // --- choose the brain (remembered) ---
@@ -945,14 +921,7 @@ async function panel() {
945
921
  // slow or sleeping machine never freezes this screen; `seen` says how each one answered.
946
922
  const machines = listMachines();
947
923
  const seen = new Map(); // name -> { groups, error, at, inflight }
948
- const pollMachines = () => {
949
- for (const m of machines) {
950
- const was = seen.get(m.name) || {};
951
- if (was.inflight || (was.at && Date.now() - was.at < 10_000)) continue;
952
- seen.set(m.name, { ...was, inflight: true });
953
- fetchLanes(m, (r) => { seen.set(m.name, { groups: r.lanes ? remoteGroups(m, r.lanes) : was.groups || [], error: r.error || null, at: Date.now(), inflight: false }); });
954
- }
955
- };
924
+ const pollMachines = machinePoller(machines, seen);
956
925
  const machineOf = (name) => machines.find((m) => m.name === name);
957
926
  // Run seldon (or foundation) on a machine. `tty`: it may need a terminal (a trust dialog),
958
927
  // so it inherits this one; otherwise its output is captured for the note line.
@@ -975,7 +944,7 @@ async function panel() {
975
944
  const allLanes = () => groups.flatMap((g) => g.lanes);
976
945
 
977
946
  const svc = (label, on) => (on ? C.green("●") : C.dim("○")) + " " + label;
978
- const tint = { "needs-you": C.gold, working: C.green, running: C.green, idle: C.dim, failed: C.red, stopped: C.dim };
947
+ const tint = TINT;
979
948
  // Below 70 columns (a phone over ssh) a lane is one short line: glyph, name, the state in a
980
949
  // word. The full detail is one ⏎ away.
981
950
  const narrow = () => (process.stdout.columns || 100) < 70;
@@ -1513,7 +1482,7 @@ function lanesCmd(flags) {
1513
1482
  }
1514
1483
  }
1515
1484
 
1516
- function laneCmd(verb, arg, flags) {
1485
+ function laneCmd(verb, arg, flags, rest = []) {
1517
1486
  const fail = (msg) => { console.log(C.red(msg)); process.exitCode = 1; };
1518
1487
  if (verb === "start") {
1519
1488
  const root = projectRoot(path.resolve(arg || ".")) || path.resolve(arg || ".");
@@ -1521,9 +1490,33 @@ function laneCmd(verb, arg, flags) {
1521
1490
  const r = startLane({ root, name: path.basename(root), task, harness: flags.agent || "claude" });
1522
1491
  return r.ok ? console.log(C.green(`✓ started ${r.slug}`) + C.dim(` (${flags.agent || "claude"}) in ${root}`)) : fail(`could not start: ${r.error}`);
1523
1492
  }
1524
- 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"');
1525
1494
  const lane = arg && findLane(arg);
1526
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
+ }
1527
1520
  if (verb === "open") {
1528
1521
  const how = openCommand(lane);
1529
1522
  if (how.why) return fail(`can't open ${lane.name}: ${how.why}`);
@@ -1590,14 +1583,7 @@ async function wsSidebar() {
1590
1583
  ensureSiblingPath();
1591
1584
  const machines = listMachines();
1592
1585
  const seen = new Map();
1593
- const poll = () => {
1594
- for (const m of machines) {
1595
- const was = seen.get(m.name) || {};
1596
- if (was.inflight || (was.at && Date.now() - was.at < 10_000)) continue;
1597
- seen.set(m.name, { ...was, inflight: true });
1598
- fetchLanes(m, (r) => { seen.set(m.name, { groups: r.lanes ? remoteGroups(m, r.lanes) : was.groups || [], error: r.error || null, at: Date.now(), inflight: false }); });
1599
- }
1600
- };
1586
+ const poll = machinePoller(machines, seen);
1601
1587
  let rows = [], cur = 0, note = "";
1602
1588
  const home = wsHome();
1603
1589
  const load = () => {
@@ -1611,7 +1597,7 @@ async function wsSidebar() {
1611
1597
  cur = keep >= 0 ? keep : Math.min(cur, Math.max(0, rows.length - 1));
1612
1598
  wsSave(WS_ROWS, JSON.stringify(rows.map((r) => ({ n: r.n, key: r.key, name: r.name, state: r.state, off: r.off, cmd: paneCommand(r, { machines, home }) }))));
1613
1599
  };
1614
- const tint = { "needs-you": C.gold, working: C.green, running: C.green, idle: C.dim, failed: C.red, stopped: C.dim, off: C.dim };
1600
+ const tint = TINT;
1615
1601
  const draw = () => {
1616
1602
  const width = process.stdout.columns || 38, height = process.stdout.rows || 40;
1617
1603
  const open = wsCurrent(), h = wsHeadline(rows);
@@ -1934,7 +1920,7 @@ function holdsCmd() {
1934
1920
  // (`--no-attach`). The value form has to be CONSUMED: filtering out everything starting with
1935
1921
  // `--` and keeping the rest as positionals read `seldon go --agent claude` as the project
1936
1922
  // named "claude".
1937
- const VALUE_FLAGS = new Set(["agent", "model", "effort", "name", "port", "pm", "stall", "dir", "for", "wait", "as", "note", "interval", "task", "owner", "file", "token-name", "card"]);
1923
+ const VALUE_FLAGS = new Set(["agent", "model", "effort", "name", "pm", "dir", "for", "wait", "as", "note", "interval", "task", "file", "token-name", "card"]);
1938
1924
  function parseArgv(raw) {
1939
1925
  const flags = {}, positional = [];
1940
1926
  for (let i = 0; i < raw.length; i++) {
@@ -1992,12 +1978,12 @@ const ids = tokens.filter((id) => byId[id]); // only the valid module
1992
1978
  if (cmd === "report") return reportCmd(tokens[0]);
1993
1979
  if (cmd === "lanes") return lanesCmd(flags);
1994
1980
  if (cmd === "machines") return machinesCmd(tokens[0], tokens[1], tokens[2]);
1995
- if (cmd === "lane") return laneCmd(tokens[0], tokens[1], flags);
1996
- if (cmd === "ws" || cmd === "workspace") return wsCmd(tokens[0], tokens[1]);
1981
+ if (cmd === "lane") return laneCmd(tokens[0], tokens[1], flags, tokens.slice(2));
1982
+ if (cmd === "ws") return wsCmd(tokens[0], tokens[1]);
1997
1983
  if (cmd === "tell") return tellCmd(tokens, flags);
1998
1984
  if (cmd === "inbox") return inboxCmd(flags);
1999
1985
  if (cmd === "setup") return setupCmd(tokens[0], flags);
2000
- if (cmd === "panel" || cmd === "board") return panel();
1986
+ if (cmd === "panel") return panel();
2001
1987
  if (cmd && cmd !== "install") { help(); process.exitCode = 1; return; }
2002
1988
  if (cmd === "install") return install_picker({ dev }); // `install` with no ids
2003
1989
 
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/lib/machines.mjs CHANGED
@@ -11,7 +11,7 @@ import { join } from "node:path";
11
11
  import { homedir } from "node:os";
12
12
  import { groupByProject } from "./lanes.mjs";
13
13
 
14
- export const REALMS_DIR = join(homedir(), ".config", "bifrost", "realms");
14
+ const REALMS_DIR = join(homedir(), ".config", "bifrost", "realms");
15
15
 
16
16
  // Read narrowly — two keys, quotes stripped, nothing executed. Sourcing a file to learn a
17
17
  // hostname is not something to do.
@@ -80,3 +80,16 @@ export function fetchLanes(machine, cb) {
80
80
  cb(lanes ? { lanes } : { error: err ? (err.killed ? "timed out" : "unreachable") : "no seldon there" });
81
81
  });
82
82
  }
83
+
84
+ // Poll every machine's lanes in the background, at most every 10s each, so a slow or sleeping
85
+ // machine never blocks a redraw. `seen` maps name -> { groups, error, at, inflight }.
86
+ export function machinePoller(machines, seen, fetch = fetchLanes) {
87
+ return () => {
88
+ for (const m of machines) {
89
+ const was = seen.get(m.name) || {};
90
+ if (was.inflight || (was.at && Date.now() - was.at < 10_000)) continue;
91
+ seen.set(m.name, { ...was, inflight: true });
92
+ fetch(m, (r) => { seen.set(m.name, { groups: r.lanes ? remoteGroups(m, r.lanes) : was.groups || [], error: r.error || null, at: Date.now(), inflight: false }); });
93
+ }
94
+ };
95
+ }
package/lib/projects.mjs CHANGED
@@ -52,11 +52,6 @@ export function gitRootOf(dir) {
52
52
  const realish = (p) => { try { return fs.realpathSync(p); } catch { return p; } };
53
53
  export const sameDir = (a, b) => !!a && !!b && realish(a) === realish(b);
54
54
 
55
- // A repo carries its hive in .factory.json — the local truth, which survives a pruned or
56
- // hand-edited registry.
57
- export function localHive(dir) {
58
- try { return JSON.parse(readFileSync(path.join(dir, ".factory.json"), "utf8")); } catch { return null; }
59
- }
60
55
 
61
56
  /**
62
57
  * What did the user mean, and what do we know about it?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gorlitzer-labs/seldon",
3
- "version": "0.19.0",
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": {