diff --git a/plugins/orca-fleet/.claude-plugin/plugin.json b/plugins/orca-fleet/.claude-plugin/plugin.json index a477a47..48ffadb 100644 --- a/plugins/orca-fleet/.claude-plugin/plugin.json +++ b/plugins/orca-fleet/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "orca-fleet", - "version": "0.5.0", + "version": "0.5.1", "description": "Part of Orca Strator (included in the orca-strator bundle). Runs one or several fleets of Claude Code sessions: orchestrators, lanes and checkers, with an Admiral above several fleets, with handovers to a fresh session when context fills. Each project keeps its own facts in one config file.", "author": { "name": "Mehmet Mutlu" diff --git a/plugins/orca-fleet/scripts/successor.py b/plugins/orca-fleet/scripts/successor.py index b9d39ab..362c504 100644 --- a/plugins/orca-fleet/scripts/successor.py +++ b/plugins/orca-fleet/scripts/successor.py @@ -106,7 +106,16 @@ def command(name, prompt, cwd, account_prefix=None): return f"cd {shlex.quote(cwd)} && {account_prefix or ''}{env}command claude -n {shlex.quote(name)} {shlex.quote(prompt)}" +def tab_line(line): + """The line typed into a new Terminal tab: the session, then `exit 0` so the tab's shell ends + (and Terminal closes the window) when the session closes. A failed `cd` stops the chain before + `exit`, so the error stays on screen. The clipboard copy keeps the plain line.""" + head, sep, rest = line.partition(" && ") + return f"{head} && {{ {rest} ; exit 0; }}" if sep else line + + def open_tab(line): + line = tab_line(line) esc = line.replace("\\", "\\\\").replace('"', '\\"') r = subprocess.run(["osascript", "-e", f'tell application "Terminal" to do script "{esc}"'], capture_output=True, text=True, timeout=20) diff --git a/plugins/orca-fleet/scripts/test_successor.py b/plugins/orca-fleet/scripts/test_successor.py new file mode 100644 index 0000000..1f161a9 --- /dev/null +++ b/plugins/orca-fleet/scripts/test_successor.py @@ -0,0 +1,24 @@ +import subprocess +import unittest + +import successor + + +class TabLine(unittest.TestCase): + def test_exit_runs_only_after_the_session(self): + line = successor.tab_line("cd /tmp && echo ran") + self.assertEqual(line, "cd /tmp && { echo ran ; exit 0; }") + out = subprocess.run(["zsh", "-c", line + "; echo AFTER"], capture_output=True, text=True) + self.assertEqual(out.stdout.strip(), "ran") # exit 0 ended the shell before AFTER + + def test_failed_cd_keeps_the_shell(self): + out = subprocess.run(["zsh", "-c", successor.tab_line("cd /nonexistent-dir && echo ran") + "; echo STILL"], + capture_output=True, text=True) + self.assertEqual(out.stdout.strip(), "STILL") + + def test_line_without_chain_is_unchanged(self): + self.assertEqual(successor.tab_line("claude"), "claude") + + +if __name__ == "__main__": + unittest.main() diff --git a/plugins/orca-move/.claude-plugin/plugin.json b/plugins/orca-move/.claude-plugin/plugin.json index d17b3b8..c794403 100644 --- a/plugins/orca-move/.claude-plugin/plugin.json +++ b/plugins/orca-move/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "orca-move", - "version": "0.1.4", + "version": "0.1.5", "description": "Part of Orca Strator (included in the orca-strator bundle). Moves a live session, or every session of an account, to a twin account when one nears its limit, and tells the sessions it works with where it went.", "author": { "name": "Mehmet Mutlu" diff --git a/plugins/orca-move/skills/switch/scripts/move.py b/plugins/orca-move/skills/switch/scripts/move.py index ef9791a..33f2390 100644 --- a/plugins/orca-move/skills/switch/scripts/move.py +++ b/plugins/orca-move/skills/switch/scripts/move.py @@ -226,7 +226,9 @@ def plan(target=None): "terminal": os.environ.get("TERM_PROGRAM") or "", "cwd": cwd, "script": str(script), - "line": f"sh ~/{script.relative_to(HOME)}", + # `&& exit 0`: when the resumed session closes normally, the tab's shell ends too and + # Terminal closes the window instead of leaving an empty prompt behind. + "line": f"sh ~/{script.relative_to(HOME)} && exit 0", "body": f"cd {shlex.quote(cwd)} && {env} && exec claude --resume {sid} '/orca-move:after-move'\n", "note": str(MOVES / f"{sid}.md"), "autoExit": mod_loaded(rec["pid"], rec.get("procStart"), cur_dir),