@gorlitzer-labs/seldon 0.11.0 → 0.12.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
@@ -74,6 +74,8 @@ recorded in `~/.seldon/lanes.json`. A plan item shows the lane working on it.
74
74
  seldon lanes [--json] # every agent here
75
75
  seldon lane start [dir] --task "fix the save crash" [--agent codex]
76
76
  seldon lane stop|resume|open <name or key>
77
+ seldon lane rm <name or key> [--force] # a stopped lane: its worktree goes,
78
+ # its branch too if git sees it merged
77
79
  ```
78
80
 
79
81
  ## Codex and opencode: let them report their state
package/bin/seldon.js CHANGED
@@ -10,7 +10,7 @@ import { MODULES, byId, DEPS, RAW, MONOREPO, withRequires, platformOk } from "..
10
10
  import { ensureSiblingPath, loadState, resolveProject, adopt as fAdopt, staff as fStaff, attach as fAttach, hiveOf, sameDir } from "../lib/projects.mjs";
11
11
  import { readLanes, readPlan, addToPlan, projectRoot, writeReport } from "../lib/agents.mjs";
12
12
  import { openCommand, stopCommand, transitions, laneForItem, slugify, HARNESSES } from "../lib/lanes.mjs";
13
- import { startLane, stopLane, resumeLane, findLane } from "../lib/actions.mjs";
13
+ import { startLane, stopLane, resumeLane, removeLane, findLane } from "../lib/actions.mjs";
14
14
  import { listMachines, addMachine, fetchLanes, remoteGroups, sshArgs, lastJsonLine } from "../lib/machines.mjs";
15
15
  import { notify } from "../lib/notify.mjs";
16
16
  import { reportFromEvent, mergeCodexHooks, removeCodexHooks, opencodePlugin } from "../lib/reports.mjs";
@@ -1505,7 +1505,7 @@ function laneCmd(verb, arg, flags) {
1505
1505
  const r = startLane({ root, name: path.basename(root), task, harness: flags.agent || "claude" });
1506
1506
  return r.ok ? console.log(C.green(`✓ started ${r.slug}`) + C.dim(` (${flags.agent || "claude"}) in ${root}`)) : fail(`could not start: ${r.error}`);
1507
1507
  }
1508
- if (!["stop", "resume", "open"].includes(verb)) return fail('usage: seldon lane start [dir] --task "…" [--agent claude|codex|opencode] · seldon lane stop|resume|open <key>');
1508
+ 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>');
1509
1509
  const lane = arg && findLane(arg);
1510
1510
  if (!lane) return fail(`no lane ${arg || ""} — see: seldon lanes`);
1511
1511
  if (verb === "open") {
@@ -1514,6 +1514,13 @@ function laneCmd(verb, arg, flags) {
1514
1514
  process.exitCode = spawnSync(how.bin, how.args, { stdio: "inherit", cwd: how.cwd }).status ?? 1;
1515
1515
  return;
1516
1516
  }
1517
+ if (verb === "rm") {
1518
+ const r = removeLane(lane, { force: !!flags.force });
1519
+ if (r.why) return fail(`can't remove ${lane.name}: ${r.why}`);
1520
+ if (!r.ok) return fail(`rm failed: ${r.error}`);
1521
+ return console.log(C.green(`✓ removed ${lane.name}`) + C.dim(!r.branch ? "" : r.branchDeleted ? ` (merged branch ${r.branch} deleted too)`
1522
+ : ` (kept branch ${r.branch}: git does not see it merged; if it was squash-merged: git branch -D ${r.branch})`));
1523
+ }
1517
1524
  const r = verb === "stop" ? stopLane(lane) : resumeLane(lane);
1518
1525
  if (r.why) return fail(`can't ${verb} ${lane.name}: ${r.why}`);
1519
1526
  if (!r.ok) return fail(`${verb} failed: ${r.error}`);
package/lib/actions.mjs CHANGED
@@ -1,13 +1,13 @@
1
- // What you can do to a lane, in one place: start, stop, resume. The panel calls these, and so
1
+ // What you can do to a lane, in one place: start, stop, resume, remove. The panel calls these, and so
2
2
  // does `seldon lane …` — which is also how the panel acts on another machine (it runs
3
3
  // `ssh <machine> seldon lane …`). One implementation, so the two can never disagree.
4
4
  import { join } from "node:path";
5
5
  import { existsSync } from "node:fs";
6
6
  import { execFileSync } from "node:child_process";
7
7
  import {
8
- readLanes, runSteps, run, harnessBins, recordLane, markLane, SELDON_HOME,
8
+ readLanes, runSteps, run, harnessBins, recordLane, markLane, forgetLane, projectRoot, SELDON_HOME,
9
9
  } from "./agents.mjs";
10
- import { startCommands, resumeCommands, stopCommand, slugify, uniqueSlug, HARNESSES } from "./lanes.mjs";
10
+ import { startCommands, resumeCommands, stopCommand, removeCommands, slugify, uniqueSlug, HARNESSES } from "./lanes.mjs";
11
11
 
12
12
  const branchExists = (root, ref) => {
13
13
  try { execFileSync("git", ["-C", root, "rev-parse", "--verify", "--quiet", `refs/heads/${ref}`], { stdio: "ignore" }); return true; } catch { return false; }
@@ -45,6 +45,18 @@ export function resumeLane(lane) {
45
45
  return { ...r, fresh: !!how.fresh };
46
46
  }
47
47
 
48
+ // Worktree gone, branch deleted only if merged. Says which branch it kept, and why.
49
+ export function removeLane(lane, { force = false } = {}) {
50
+ const git = (...args) => { try { return execFileSync("git", ["-C", lane.cwd, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim(); } catch { return null; } };
51
+ const how = removeCommands(lane, { root: projectRoot(lane.cwd), branch: git("rev-parse", "--abbrev-ref", "HEAD"), dirty: !!git("status", "--porcelain"), force });
52
+ if (how.why) return { ok: false, why: how.why };
53
+ const r = runSteps(how.cmds);
54
+ if (!r.ok) return r;
55
+ if (lane.tmuxSession && lane.harness !== "claude") forgetLane(lane.tmuxSession);
56
+ const branch = how.branch?.args.at(-1) ?? null;
57
+ return { ok: true, branch, branchDeleted: !!how.branch && run(how.branch, { quiet: true }).ok };
58
+ }
59
+
48
60
  export const allLanes = () => readLanes().flatMap((g) => g.lanes);
49
61
  // By key, or by name when exactly one lane has it (keys are long; names are what you see).
50
62
  export function findLane(ref) {
package/lib/agents.mjs CHANGED
@@ -67,6 +67,11 @@ export function markLane(session, patch) {
67
67
  writeLanes(readJson(LANES_FILE, []).map((e) => (e.session === session ? { ...e, ...patch } : e)));
68
68
  }
69
69
 
70
+ // Removed: the lane is gone for good, so it is not listed as stopped either.
71
+ export function forgetLane(session) {
72
+ writeLanes(readJson(LANES_FILE, []).filter((e) => e.session !== session));
73
+ }
74
+
70
75
  // tmux session -> { harness, task, startedAt }: seldon's lanes plus apiary's Codex agents.
71
76
  export function knownSessions() {
72
77
  const known = {};
package/lib/lanes.mjs CHANGED
@@ -233,6 +233,20 @@ export function resumeCommands(lane, { bins = {}, env = {} } = {}) {
233
233
  };
234
234
  }
235
235
 
236
+ // ---- removing a finished lane ------------------------------------------------------
237
+ // What a done lane leaves behind is a worktree and a branch. rm takes the worktree, and the
238
+ // branch only when git can see it is merged (`git branch -d` refuses otherwise). A squash-merged
239
+ // branch looks unmerged to git, so it is kept and named, never force-deleted.
240
+ export function removeCommands(lane, { root, branch, dirty = false, force = false } = {}) {
241
+ if (!["stopped", "failed"].includes(lane.state)) return { why: `it is ${lane.state}, stop it first` };
242
+ if (!root || !lane.cwd || lane.cwd.replace(/\/+$/, "") === root.replace(/\/+$/, "")) return { why: "it works in the repo itself, not in a worktree of its own" };
243
+ if (dirty && !force) return { why: "its worktree has uncommitted changes: commit them, or --force to throw them away" };
244
+ return {
245
+ cmds: [{ bin: "git", args: ["-C", root, "worktree", "remove", ...(force ? ["--force"] : []), lane.cwd], quiet: true }],
246
+ branch: branch && branch !== "HEAD" ? { bin: "git", args: ["-C", root, "branch", "-d", branch], quiet: true } : null,
247
+ };
248
+ }
249
+
236
250
  // ---- telling the human ----------------------------------------------------------------
237
251
  // What changed since the last look that a person should hear about: an agent that starts
238
252
  // waiting on them, fails, or finishes. Only TRANSITIONS — a lane that stays blocked is not
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gorlitzer-labs/seldon",
3
- "version": "0.11.0",
3
+ "version": "0.12.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": {