herdr-orchestra 6.20.0 → 6.23.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/CHANGELOG.md CHANGED
@@ -2,6 +2,39 @@
2
2
 
3
3
  All notable changes. Versions follow [semantic versioning](https://semver.org).
4
4
 
5
+ ## [6.23.0] - 2026-11-27
6
+
7
+ Subagent mode now belongs to Pi only. Before, `orch setup --mode subagent` saved one machine-wide `"mode": "subagent"`, so every lead got Pi's subagent steps, even Antigravity, Claude Code or Codex.
8
+
9
+ Example: you turn on subagent mode in Pi, then plan a feature with Antigravity. Before, `orch lead plan` in Antigravity printed `SUBAGENT MODE (Pi, one window)` and told it to skip herdr and use Pi subagents. Now Antigravity gets the normal panes playbook, and Pi still gets subagent mode.
10
+
11
+ ### Fixed
12
+ - **The mode is saved per agent**: `~/.config/herdr-orchestra/config.json` holds `"modes": {"pi": "subagent"}`. Any agent not listed uses panes mode.
13
+ - **Subagent mode is refused for agents that have none.** Only Pi has it today (through pi-subagents), so orch never gives another agent subagent instructions. `orch mode subagent --agent claude` says no. `orch setup --mode subagent` from a plain terminal saves it for Pi.
14
+ - **orch knows which agent is asking**: from `AI_AGENT` (Pi sets `pi`, Claude Code sets `claude-code_...`), then `PI_CODING_AGENT`, `CLAUDECODE`, `CODEX_*` or `OPENCODE`. When it can't tell (for example Antigravity), the agent gets panes. `--agent <kind>` or `ORCH_AGENT=<kind>` says it by hand.
15
+ - **An old Pi run no longer leaks into the next plan.** If the repo's last run was a Pi subagent run, another agent's `orch lead plan` / `orch lead run` still gets panes. `orch sync` gives a new plan subagent mode only when its `Lead:` is Pi and Pi's saved mode is subagent.
16
+ - `orch mode` shows this agent's mode, and the modes saved for other agents (`saved per agent: pi=subagent`).
17
+ - **herdr's sidebar could miss a short review.** The sidebar name (`reviewer · reviewing M2`) was only sent once per event-manager round, so a review that finished quickly never showed up there. Now it is sent as soon as a coder's job or a review starts. This also fixes a test that failed now and then in CI.
18
+
19
+ ### Added
20
+ - `ORCH_MODE=panes|subagent` changes the mode for one command, for example `ORCH_MODE=panes orch lead plan` in Pi. `subagent` works only in Pi.
21
+ - `--agent <kind>` on `orch mode`, `orch setup` and `orch lead plan|run`.
22
+
23
+ ### Changed
24
+ - An old config with `"mode": "subagent"` keeps working: orch reads it as Pi's only. The next `orch mode` or `orch setup --mode` saves it as `"modes": {"pi": "subagent"}` and prints `MOVED`. The Pi extension (`/orch-mode`) reads and writes the new format too.
25
+
26
+ ### Not yet tried
27
+ - With real Pi and Antigravity windows. Tested with orch's simulated agents and the Pi extension test harness. Pi sets `AI_AGENT=pi` and `PI_CODING_AGENT=true` (checked in `@earendil-works/pi-coding-agent`); Antigravity sets no known mark, so it is treated as "not Pi" (panes).
28
+
29
+ ## [6.22.0] - 2026-11-26
30
+
31
+ The board popup (`prefix+a`) now opens in the repo of the pane you were in. Before, it could answer "This folder is not a git repo with an orch run" even while a run was going.
32
+
33
+ Example: you are in the `rupee-flow` space with a run going and press `ctrl+b`, then `a`. The popup used to start in a folder that was not your repo. Now it starts in your pane's folder and shows the run.
34
+
35
+ ### Fixed
36
+ - **The popup started in the wrong folder.** Herdr starts a popup in the plugin's own folder unless it is told otherwise. orch looked for the pane's folder under field names Herdr does not use, found none, and told Herdr nothing. It now reads Herdr's real fields: the focused pane's folder, else the space's folder, else its worktree. It prefers the folder whose repo has an orch run (also from a coder's worktree pane), and always passes the folder to Herdr with `--cwd`.
37
+ - When the popup still is not in a repo, it now says which folder it is in.
5
38
  ## [6.20.0] - 2026-11-26
6
39
 
7
40
  The tests run in about 5 minutes instead of about 21. Nothing in orch changed, and no check was removed, skipped or made easier.
package/README.md CHANGED
@@ -291,7 +291,7 @@ Runs have two modes. Nothing changes for anyone who never picks the second one.
291
291
  | `panes` (default) | herdr panes, as described above | the event manager; the lead dispatches and pauses |
292
292
  | `subagent` | inside one Pi window, as Pi subagents ([pi-subagents](https://www.npmjs.com/package/@tintinweb/pi-subagents)) | the lead, one milestone at a time |
293
293
 
294
- Switch with `/orch-mode subagent` in Pi; `/orch-mode` alone shows the mode, and Pi's footer shows it too (`orch: subagent`). The choice is saved in `~/.config/herdr-orchestra/config.json`, and a run keeps the mode it was planned in.
294
+ Switch with `/orch-mode subagent` in Pi; `/orch-mode` alone shows the mode, and Pi's footer shows it too (`orch: subagent`). The choice is saved for Pi only, in `~/.config/herdr-orchestra/config.json` (`"modes": {"pi": "subagent"}`): every other agent (Claude Code, Codex, Antigravity, ...) keeps leading in panes mode, because subagent mode exists only for Pi. A run keeps the mode it was planned in. A config from before 6.23.0 with one `"mode": "subagent"` is read as Pi's, and `orch mode` saves it the new way.
295
295
 
296
296
  `/orch-mode subagent` also sets subagent mode up, right there in Pi, with no terminal step: it installs the `orch` command if it is missing or old, writes the coder and reviewer agents, installs pi-subagents, and reloads Pi so the `Agent` tool is ready. It ends with `Done: subagent mode is ready.` `/orch-setup --mode subagent` does the same. From a normal terminal (no Pi open), the same setup is:
297
297
 
@@ -303,7 +303,7 @@ Setup writes `~/.pi/agent/agents/coder.md` and `reviewer.md` (the reviewer canno
303
303
 
304
304
  ```json
305
305
  {
306
- "mode": "subagent",
306
+ "modes": { "pi": "subagent" },
307
307
  "subagent": {
308
308
  "coder": { "model": "anthropic/claude-sonnet-4-5", "thinking": "medium", "max_turns": 80 },
309
309
  "reviewer": { "model": "openai/gpt-5", "thinking": "high" }
package/VERSION CHANGED
@@ -1 +1 @@
1
- 6.20.0
1
+ 6.23.0
Binary file
package/bin/orch CHANGED
@@ -1642,7 +1642,7 @@ def cmd_sync(args):
1642
1642
  "title": title_m.group(1) if title_m else branch,
1643
1643
  "commits": commits,
1644
1644
  "mode": mode,
1645
- "orch_mode": old.get("orch_mode") or config_mode(), # panes (herdr) or subagent (Pi): kept for the run
1645
+ "orch_mode": plan_orch_mode(old, branch, lead[1][0] if lead else None), # panes, or subagent (Pi leads only)
1646
1646
  "quick_because": quick_because if quick else None,
1647
1647
  "green_tree": old.get("green_tree"),
1648
1648
  "integration_broken": old.get("integration_broken"),
@@ -5260,6 +5260,11 @@ def _autopilot(args):
5260
5260
  out = (r.stdout + r.stderr).strip()
5261
5261
  if r.returncode not in ok:
5262
5262
  raise RuntimeError(f"orch {' '.join(str(x) for x in a)} -> exit {r.returncode}: {out}")
5263
+ if r.returncode == 0 and a[0] in ("send", "review"):
5264
+ # a job just started: tell herdr's sidebar now, not at the next round (a short review could be missed)
5265
+ with contextlib.suppress(NameError):
5266
+ if names:
5267
+ names.update(load())
5263
5268
  return r.returncode, out
5264
5269
 
5265
5270
  def patch_state(fn):
@@ -6875,7 +6880,7 @@ def team_up(args):
6875
6880
  flag = mode_flag(args, "usage: orch team up [--dry-run] [--mode panes|subagent]")
6876
6881
  dry = "--dry-run" in args
6877
6882
  if flag and not dry:
6878
- set_mode(flag, hint=False)
6883
+ set_mode(flag, hint=False, agent=mode_target(flag, "usage: orch team up [--dry-run] [--mode panes|subagent]"))
6879
6884
  st = load()
6880
6885
  if (flag or run_mode(st)) == "subagent":
6881
6886
  print("mode subagent: no panes to open; the coder and the reviewer are Pi subagents")
@@ -8003,9 +8008,12 @@ USAGE = """usage: orch <command> [args]
8003
8008
  team up [--dry-run] [--mode panes|subagent]
8004
8009
  open a herdr pane for every agent in the plan herdr can't find, in its folder, and name it
8005
8010
  (subagent mode: no panes; sets up the Pi coder/reviewer subagents instead)
8006
- mode [panes|subagent] which mode runs use: panes (herdr panes, the default) or subagent (one Pi window)
8007
- setup [--mode panes|subagent] get this machine ready for a mode; subagent: write ~/.pi/agent/agents/coder.md and
8008
- reviewer.md from ~/.config/herdr-orchestra/config.json and install pi-subagents
8011
+ mode [panes|subagent] [--agent <kind>] this agent's mode, or save one: panes (herdr panes, the default for
8012
+ every agent) or subagent (one Pi window; Pi only). Saved per agent in
8013
+ ~/.config/herdr-orchestra/config.json ("modes": {"pi": "subagent"}); ORCH_MODE=panes|subagent
8014
+ overrides it for one command. orch finds the agent by itself (ORCH_AGENT=<kind> to say it)
8015
+ setup [--mode panes|subagent] [--agent <kind>] get this machine ready for a mode; subagent (saved for Pi): write
8016
+ ~/.pi/agent/agents/coder.md and reviewer.md from the config and install pi-subagents
8009
8017
  agents the agent registry: kinds, installed?, roles, herdr detection, launch commands
8010
8018
  agents launch <kind> [--model <id>] [--role reviewer] print the command that starts <kind> in a pane
8011
8019
  (auto-approve edits; --role reviewer: its read-only reviewer command when it has one)
@@ -8313,6 +8321,8 @@ def lead_self_name():
8313
8321
 
8314
8322
  def cmd_lead(args):
8315
8323
  """orch lead plan|run -> print the lead playbook; orch lead whoami -> this pane + how to name it `lead`."""
8324
+ args = list(args)
8325
+ agent_flag(args, "usage: orch lead plan|run [--agent <kind>]") # which agent leads, when orch can't tell
8316
8326
  sub = args[0] if args else ""
8317
8327
  if sub in ("plan", "run"):
8318
8328
  pb = asset(f"playbooks/{sub}.md") or die(f"playbooks/{sub}.md not found next to orch or in the install")
@@ -9156,9 +9166,84 @@ def config_save(data):
9156
9166
  os.replace(tmp, p)
9157
9167
 
9158
9168
 
9159
- def config_mode():
9160
- m = str(config_load().get("mode") or "panes").lower()
9161
- return m if m in ORCH_MODES else "panes"
9169
+ # The mode is saved per agent (`modes` in the config, e.g. {"modes": {"pi": "subagent"}}): an agent not listed
9170
+ # runs in panes mode. Subagent mode exists only for Pi today (it needs @tintinweb/pi-subagents), so orch never gives
9171
+ # another agent (Claude Code, Codex, Antigravity, ...) subagent instructions, whatever the config says.
9172
+ # Before 6.23.0 the config had one machine-wide `"mode"`; a saved `"mode": "subagent"` is read as Pi's, and the next
9173
+ # save moves it to `modes.pi`.
9174
+ SUBAGENT_AGENTS = ("pi",)
9175
+ AGENT_RE_KIND = re.compile(r"^[a-z][a-z0-9_-]{0,31}$")
9176
+ AGENT_OVERRIDE = None # set by `--agent <kind>`
9177
+
9178
+
9179
+ def config_modes(conf=None):
9180
+ """{agent: mode} from the config, with the old machine-wide `mode: subagent` read as Pi's."""
9181
+ conf = config_load() if conf is None else conf
9182
+ raw = conf.get("modes") if isinstance(conf.get("modes"), dict) else {}
9183
+ out = {str(k).lower(): str(v).lower() for k, v in raw.items() if str(v).lower() in ORCH_MODES}
9184
+ if str(conf.get("mode") or "").lower() == "subagent":
9185
+ out.setdefault("pi", "subagent")
9186
+ return out
9187
+
9188
+
9189
+ def config_mode(agent="pi"):
9190
+ """The mode saved for this agent; panes when none is saved, or when the agent has no subagent mode."""
9191
+ m = config_modes().get(agent or "", "panes")
9192
+ return m if m == "panes" or agent in SUBAGENT_AGENTS else "panes"
9193
+
9194
+
9195
+ def calling_agent():
9196
+ """Which agent runs this orch command (its kind, as in agents.toml), or None when orch can't tell.
9197
+ `--agent` or ORCH_AGENT win; then AI_AGENT, which the innermost agent sets (Pi: "pi", Claude Code:
9198
+ "claude-code_..."); then the marks agents leave in their shell (PI_CODING_AGENT, CLAUDECODE, CODEX_*, OPENCODE)."""
9199
+ e = os.environ
9200
+ v = (AGENT_OVERRIDE or e.get("ORCH_AGENT") or "").strip().lower()
9201
+ if v:
9202
+ return v
9203
+ names = {"pi": "pi", "claude": "claude", "codex": "codex", "opencode": "opencode", "amp": "amp",
9204
+ "hermes": "hermes", "agy": "agy", "antigravity": "agy", "gemini": "agy"}
9205
+ first = (re.split(r"[^a-z0-9]+", (e.get("AI_AGENT") or "").strip().lower()) or [""])[0]
9206
+ if first:
9207
+ return names.get(first, first if AGENT_RE_KIND.match(first) else None)
9208
+ if e.get("PI_CODING_AGENT") == "true":
9209
+ return "pi"
9210
+ if e.get("CLAUDECODE") == "1":
9211
+ return "claude"
9212
+ if any(k.startswith("CODEX_") for k in e):
9213
+ return "codex"
9214
+ if e.get("OPENCODE"):
9215
+ return "opencode"
9216
+ return None
9217
+
9218
+
9219
+ def agent_flag(args, usage):
9220
+ """Take `--agent <kind>` (or `--agent=<kind>`) out of args and use it as the calling agent; returns it or None."""
9221
+ global AGENT_OVERRIDE
9222
+ for i, a in enumerate(list(args)):
9223
+ if a == "--agent" or a.startswith("--agent="):
9224
+ val = (a.split("=", 1)[1] if "=" in a else (args[i + 1] if len(args) > i + 1 else "")).strip().lower()
9225
+ del args[i:i + (1 if "=" in a else 2)]
9226
+ if not AGENT_RE_KIND.match(val):
9227
+ die(f"--agent needs an agent kind such as pi, claude, codex or agy, got {val!r} — {usage}")
9228
+ AGENT_OVERRIDE = val
9229
+ return val
9230
+ return None
9231
+
9232
+
9233
+ def mode_env():
9234
+ """ORCH_MODE=panes|subagent: a one-command override (e.g. `ORCH_MODE=panes orch lead plan`); None when unset."""
9235
+ v = (os.environ.get("ORCH_MODE") or "").strip().lower()
9236
+ if not v:
9237
+ return None
9238
+ if v not in ORCH_MODES:
9239
+ die(f"ORCH_MODE must be panes or subagent, got {v!r}")
9240
+ return v
9241
+
9242
+
9243
+ def no_subagent_for(agent):
9244
+ return (f"subagent mode is only for Pi today (it uses Pi's pi-subagents); "
9245
+ f"{'this agent (' + agent + ')' if agent else 'orch cannot tell which agent this is, so it'} "
9246
+ f"uses panes mode. In Pi orch finds it by itself; elsewhere add `--agent pi` or set ORCH_AGENT=pi")
9162
9247
 
9163
9248
 
9164
9249
  def run_mode(st):
@@ -9197,17 +9282,48 @@ def _repo_state_path():
9197
9282
  return p if p.exists() else None
9198
9283
 
9199
9284
 
9200
- def current_mode():
9201
- """(mode, where it comes from): this repo's run, else the machine's config, else panes."""
9285
+ def current_mode(agent=...):
9286
+ """(mode, where it comes from) for the agent running orch: a one-command ORCH_MODE, else this repo's run, else
9287
+ the mode saved for this agent, else panes. Only Pi has a subagent mode, so any other agent gets panes even when
9288
+ this repo's last run or the config says subagent (that is Pi's)."""
9289
+ agent = calling_agent() if agent is ... else agent
9290
+ env = mode_env()
9291
+ if env == "subagent" and agent not in SUBAGENT_AGENTS:
9292
+ die("ORCH_MODE=subagent: " + no_subagent_for(agent))
9293
+ if env:
9294
+ return env, "ORCH_MODE"
9295
+ run = None
9202
9296
  with contextlib.suppress(Exception):
9203
9297
  p = _repo_state_path()
9204
9298
  if p:
9205
- return run_mode(json.loads(p.read_text())), "this repo's run"
9206
- if "mode" in config_load():
9207
- return config_mode(), short(user_config_file())
9299
+ run = run_mode(json.loads(p.read_text()))
9300
+ if agent not in SUBAGENT_AGENTS:
9301
+ if run == "panes":
9302
+ return "panes", "this repo's run"
9303
+ if run == "subagent" or "subagent" in config_modes().values():
9304
+ return "panes", f"{agent or 'this agent'}: subagent mode is only for Pi"
9305
+ return "panes", "default"
9306
+ if run:
9307
+ return run, "this repo's run"
9308
+ if agent in config_modes():
9309
+ return config_mode(agent), f"{agent}, in {short(user_config_file())}"
9208
9310
  return "panes", "default"
9209
9311
 
9210
9312
 
9313
+ def plan_orch_mode(old, branch, lead_kind):
9314
+ """The mode a run synced from the plan gets: subagent only when its lead is Pi and Pi's saved mode (or the run
9315
+ this plan already had, on the same branch) is subagent; every other lead runs in panes."""
9316
+ kind = (lead_kind or calling_agent() or "").lower()
9317
+ env = mode_env()
9318
+ if kind not in SUBAGENT_AGENTS:
9319
+ return "panes"
9320
+ if env:
9321
+ return env
9322
+ if old.get("branch") == branch and old.get("orch_mode") in ORCH_MODES:
9323
+ return old["orch_mode"]
9324
+ return config_mode(kind)
9325
+
9326
+
9211
9327
  def mode_flag(args, usage):
9212
9328
  """Take `--mode <panes|subagent>` (or `--mode=...`) out of args; returns the mode or None."""
9213
9329
  for i, a in enumerate(list(args)):
@@ -9376,16 +9492,30 @@ def pi_setup():
9376
9492
  return problems + 1
9377
9493
 
9378
9494
 
9495
+ def mode_target(mode, usage):
9496
+ """Which agent `orch mode` / `orch setup --mode` saves the mode for: `--agent`, else the agent running orch.
9497
+ Subagent mode is Pi's, so `--mode subagent` with no agent named (a plain terminal) is saved for Pi."""
9498
+ agent = AGENT_OVERRIDE or calling_agent()
9499
+ if mode == "subagent":
9500
+ if AGENT_OVERRIDE and agent not in SUBAGENT_AGENTS:
9501
+ die(f"{agent} has no subagent mode: it is only for Pi today (Pi's pi-subagents). {agent} stays in panes "
9502
+ f"mode — {usage}")
9503
+ return agent if agent in SUBAGENT_AGENTS else "pi"
9504
+ return agent if agent in SUBAGENT_AGENTS or AGENT_OVERRIDE else "pi"
9505
+
9506
+
9379
9507
  def cmd_setup(args):
9380
- """orch setup [--mode panes|subagent] -> get this machine ready for a mode (and save it with --mode)."""
9381
- usage = "usage: orch setup [--mode panes|subagent]"
9508
+ """orch setup [--mode panes|subagent] [--agent <kind>] -> get this machine ready for a mode (save it with --mode)."""
9509
+ usage = "usage: orch setup [--mode panes|subagent] [--agent <kind>]"
9382
9510
  args = list(args)
9511
+ agent_flag(args, usage)
9383
9512
  flag = mode_flag(args, usage)
9384
9513
  if args:
9385
9514
  die(usage)
9386
9515
  if flag:
9387
- set_mode(flag, hint=False)
9388
- mode = flag or current_mode()[0]
9516
+ set_mode(flag, hint=False, agent=mode_target(flag, usage))
9517
+ # setup only ever prepares Pi's subagents, so with no --mode it looks at Pi's saved mode too
9518
+ mode = flag or ("subagent" if "subagent" in (current_mode()[0], config_mode("pi")) else "panes")
9389
9519
  if mode == "panes":
9390
9520
  print("mode panes: nothing to set up here. Coders and the reviewer run in herdr panes; `orch team up` opens "
9391
9521
  "them when a run starts.")
@@ -9394,22 +9524,47 @@ def cmd_setup(args):
9394
9524
 
9395
9525
 
9396
9526
  def cmd_mode(args):
9397
- """orch mode -> which mode is active and where it comes from; orch mode panes|subagent -> switch."""
9527
+ """orch mode -> this agent's mode and where it comes from; orch mode panes|subagent [--agent <kind>] -> save it
9528
+ for that agent (subagent: Pi only)."""
9529
+ usage = "usage: orch mode [panes|subagent] [--agent <kind>]"
9530
+ args = list(args)
9531
+ agent_flag(args, usage)
9398
9532
  if not args:
9399
- mode, src = current_mode()
9533
+ agent = calling_agent()
9534
+ mode, src = current_mode(agent)
9400
9535
  print(f"mode: {mode} ({src})")
9536
+ saved = config_modes()
9537
+ others = {k: v for k, v in saved.items() if k != agent and v != "panes"}
9538
+ if others:
9539
+ print("saved per agent: " + ", ".join(f"{k}={v}" for k, v in sorted(others.items()))
9540
+ + " (every other agent: panes)")
9541
+ if "modes" not in config_load() and "pi" in saved:
9542
+ print(f"NOTE {short(user_config_file())} still has the old machine-wide \"mode\": \"subagent\". orch "
9543
+ f"reads it as Pi's only; `orch mode subagent` (or panes) saves it the new way")
9401
9544
  return
9402
9545
  if len(args) != 1 or args[0].lower() not in ORCH_MODES:
9403
- die("usage: orch mode [panes|subagent]")
9404
- set_mode(args[0].lower())
9546
+ die(usage)
9547
+ set_mode(args[0].lower(), agent=mode_target(args[0].lower(), usage))
9405
9548
 
9406
9549
 
9407
- def set_mode(mode, hint=True):
9408
- """Save the machine's mode, and switch this repo's run too when nothing in it is in progress."""
9550
+ def set_mode(mode, hint=True, agent="pi"):
9551
+ """Save the mode for one agent (`modes.<agent>`), and switch this repo's run too when its lead is that agent and
9552
+ nothing in it is in progress. The old machine-wide `mode` key is moved into `modes.pi`."""
9409
9553
  c = config_load()
9410
- c["mode"] = mode
9554
+ modes = config_modes(c)
9555
+ moved = "mode" in c
9556
+ c.pop("mode", None)
9557
+ if mode == "panes":
9558
+ modes.pop(agent, None)
9559
+ else:
9560
+ modes[agent] = mode
9561
+ c["modes"] = modes
9411
9562
  config_save(c)
9412
- print(f"mode: {mode} (saved in {short(user_config_file())})")
9563
+ print(f"mode: {mode} for {agent} (saved in {short(user_config_file())}; "
9564
+ + ("every other agent uses panes)" if mode == "subagent" else
9565
+ "agents with no saved mode use panes)"))
9566
+ if moved:
9567
+ print("MOVED the old machine-wide \"mode\" setting: it now applies to Pi only (\"modes\": {\"pi\": ...})")
9413
9568
  p = None
9414
9569
  with contextlib.suppress(Exception):
9415
9570
  p = _repo_state_path()
@@ -9419,11 +9574,16 @@ def set_mode(mode, hint=True):
9419
9574
  with state_lock():
9420
9575
  st = load()
9421
9576
  busy = [k for k, v in st["tasks"].items() if v["status"] in ACTIVE]
9422
- if run_mode(st) != mode and (driver_alive() or busy):
9577
+ lead_kind = ((st.get("lead") or {}).get("kind") or "").lower()
9578
+ if mode == "subagent" and lead_kind not in SUBAGENT_AGENTS:
9579
+ if run_mode(st) != mode:
9580
+ print(f"this repo's run stays {run_mode(st)}: its lead is {lead_kind or 'not named'}, and "
9581
+ f"subagent mode needs `Lead: lead (pi)` (the next Pi-led plan uses it)")
9582
+ elif run_mode(st) != mode and (driver_alive() or busy):
9423
9583
  print(f"NOT CHANGED this repo's run stays {run_mode(st)}: "
9424
9584
  + (f"{', '.join(busy)} in progress" if busy else "the event manager is running")
9425
9585
  + ". Switch when nothing is in progress.")
9426
- elif run_mode(st) != mode:
9586
+ elif run_mode(st) != mode and (lead_kind == agent or (not lead_kind and agent in SUBAGENT_AGENTS)):
9427
9587
  st["orch_mode"] = mode
9428
9588
  save(st)
9429
9589
  print(f"this repo's run: {mode}")
@@ -7,7 +7,11 @@
7
7
  // read it, and `npx herdr-orchestra` ignores it.
8
8
  //
9
9
  // Where the mode comes from: this repo's run (.orchestrate/state.json, `orch_mode`; a run from before 6.2.0 is
10
- // panes), else ~/.config/herdr-orchestra/config.json (`mode`), else panes.
10
+ // panes), else Pi's saved mode in ~/.config/herdr-orchestra/config.json (`modes.pi`; before 6.23.0 one
11
+ // machine-wide `mode`, now read as Pi's only), else panes. The mode is saved per agent, so subagent mode set here
12
+ // never reaches Claude Code, Codex, Antigravity or any other agent: they stay in panes mode.
13
+ // (orch knows Pi is asking from AI_AGENT=pi / PI_CODING_AGENT, which Pi sets for every command it runs.)
14
+
11
15
  //
12
16
  // Commands: /orch-mode [panes|subagent] show or switch the mode; `subagent` also sets it up (below)
13
17
  // /orch-setup [--mode panes|subagent] install the `orch` command from this package (needed once)
@@ -30,7 +34,7 @@ type Mode = "panes" | "subagent";
30
34
  const MODES: Mode[] = ["panes", "subagent"];
31
35
  const STATUS_KEY = "orch";
32
36
  /** `orch setup` result lines (bin/orch pi_setup and set_mode). */
33
- const SETUP_LINE = /^(WROTE|ok |KEPT|REFUSED|NO PI|INSTALL|INSTALLED|FAILED|mode:|mode panes:|this repo|NOT CHANGED|run it yourself)/;
37
+ const SETUP_LINE = /^(WROTE|ok |KEPT|REFUSED|NO PI|INSTALL|INSTALLED|FAILED|mode:|mode panes:|MOVED|this repo|NOT CHANGED|run it yourself)/;
34
38
 
35
39
  function packageRoot(): string {
36
40
  const here = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
@@ -153,14 +157,27 @@ async function readMode(pi: ExtensionAPI, cwd: string): Promise<{ mode: Mode; fr
153
157
  const st = readJson(state);
154
158
  if (st) return { mode: asMode(st.orch_mode) ?? "panes", from: "this repo's run" };
155
159
  }
156
- const saved = asMode(readJson(configFile())?.mode);
160
+ const saved = piSavedMode(readJson(configFile()));
157
161
  return saved ? { mode: saved, from: configFile() } : { mode: "panes", from: "default" };
158
162
  }
159
163
 
164
+ /** Pi's saved mode: `modes.pi`, else the old machine-wide `mode: subagent` (read as Pi's). */
165
+ function piSavedMode(data: Record<string, unknown> | undefined): Mode | undefined {
166
+ const modes = data?.modes;
167
+ const own = modes && typeof modes === "object" && !Array.isArray(modes) ? asMode((modes as Record<string, unknown>).pi) : undefined;
168
+ return own ?? (asMode(data?.mode) === "subagent" ? "subagent" : undefined);
169
+ }
170
+
160
171
  function saveConfigMode(mode: Mode): void {
161
172
  const path = configFile();
162
173
  const data = readJson(path) ?? {};
163
- data.mode = mode;
174
+ const old = data.modes && typeof data.modes === "object" && !Array.isArray(data.modes) ? (data.modes as Record<string, unknown>) : {};
175
+ const modes: Record<string, unknown> = { ...old };
176
+ if (asMode(data.mode) === "subagent" && !("pi" in modes)) modes.pi = "subagent";
177
+ delete data.mode;
178
+ if (mode === "subagent") modes.pi = mode;
179
+ else delete modes.pi;
180
+ data.modes = modes;
164
181
  mkdirSync(dirname(path), { recursive: true });
165
182
  writeFileSync(path + ".tmp", JSON.stringify(data, null, 2) + "\n");
166
183
  renameSync(path + ".tmp", path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "herdr-orchestra",
3
- "version": "6.20.0",
3
+ "version": "6.23.0",
4
4
  "description": "Orchestrate AI coding agents (Claude Code, Codex, OpenCode, Amp, Pi) as one team: a lead plans, coders build, a reviewer checks, you get one PR. Runs in Herdr panes, or in one Pi window with subagents.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -3,6 +3,6 @@
3
3
  orch=$(command -v orch || echo "$HOME/.local/bin/orch")
4
4
  [ -x "$orch" ] || { echo "orch not found on PATH — install herdr-orchestra (npx herdr-orchestra@latest)"; sleep 5; exit 1; }
5
5
  if ! git rev-parse --show-toplevel >/dev/null 2>&1; then
6
- echo "This folder is not a git repo with an orch run. Open the board from a pane inside the repo."; sleep 5; exit 1
6
+ echo "This folder ($(pwd)) is not a git repo with an orch run. Open the board from a pane inside the repo."; sleep 5; exit 1
7
7
  fi
8
8
  exec "$orch" board
@@ -1,23 +1,29 @@
1
1
  #!/bin/sh
2
- # Opens the board popup in the folder of the pane you were in (that is where the run's repo is).
2
+ # Opens the board popup in the repo of the pane you were in. Herdr starts a popup in the plugin's own folder unless
3
+ # told otherwise, so the folder is passed with --cwd: the focused pane's folder, else the space's folder, else its worktree.
3
4
  dir=$(python3 - <<'PY' 2>/dev/null
4
- import json, os
5
- def find(o, keys):
6
- if isinstance(o, dict):
7
- for k in keys:
8
- if isinstance(o.get(k), str) and os.path.isdir(o[k]):
9
- return o[k]
10
- o = list(o.values())
11
- if isinstance(o, list):
12
- for v in o:
13
- r = find(v, keys)
14
- if r:
15
- return r
16
- return None
5
+ import json, os, subprocess
17
6
  try:
18
- print(find(json.loads(os.environ.get("HERDR_PLUGIN_CONTEXT_JSON") or "{}"), ("foreground_cwd", "cwd", "path")) or "")
7
+ ctx = json.loads(os.environ.get("HERDR_PLUGIN_CONTEXT_JSON") or "{}")
19
8
  except ValueError:
20
- print("")
9
+ ctx = {}
10
+ wt = ctx.get("worktree") if isinstance(ctx.get("worktree"), dict) else {}
11
+ cands = [c for c in (ctx.get("focused_pane_cwd"), ctx.get("workspace_cwd"), wt.get("path")) if isinstance(c, str) and os.path.isdir(c)]
12
+
13
+ def toplevel(d):
14
+ r = subprocess.run(["git", "-C", d, "rev-parse", "--show-toplevel"], capture_output=True, text=True)
15
+ return r.stdout.strip() if r.returncode == 0 else None
16
+
17
+ def has_run(d):
18
+ # a worktree's pane has its own top level; the run lives in the main repo (the git common dir's parent)
19
+ r = subprocess.run(["git", "-C", d, "rev-parse", "--git-common-dir"], capture_output=True, text=True)
20
+ if r.returncode != 0:
21
+ return False
22
+ common = os.path.normpath(os.path.join(d, r.stdout.strip()))
23
+ return os.path.isfile(os.path.join(os.path.dirname(common), ".orchestrate", "state.json"))
24
+
25
+ pick = next((c for c in cands if has_run(c)), None) or next((c for c in cands if toplevel(c)), None) or (cands[0] if cands else "")
26
+ print(pick)
21
27
  PY
22
28
  )
23
29
  herdr=${HERDR_BIN_PATH:-herdr}