Keep a parked chunk out of the epic's and its repo's running slots

This commit is contained in:
2026-11-18 23:11:31 +01:00
parent 004c76679e
commit 1df19f4ac8
5 changed files with 148 additions and 16 deletions
+25 -3
View File
@@ -14,6 +14,8 @@ NEEDED = (3, 2)
# What a window's name ends in while its chunk waits for the human. tmux's status bar shows the name, and `!` after it once the bell rang.
WAITS = " ?"
BELL = "\a"
# What follows a window's name while its chunk is parked, before what its pull request waits on, as in `ABC-34 awaits an approval`. A parked chunk takes no running slot (docs/decisions.md → `do-epic: drives one Jira epic …`, "Long gates").
PARKED = " awaits "
# What a session's name opens with: LOOP for a project's chunks under loop-claude, EPIC for an epic's chunks under do-epic.
LOOP = "loop"
EPIC = "epic"
@@ -41,12 +43,14 @@ class Window:
@dataclasses.dataclass(frozen=True)
class Listed:
"""A window of the project's session, as tmux lists it."""
# Without WAITS.
# Without WAITS, and without PARKED and what follows it.
name: str
# tmux's ID of the window, such as `@3`.
id: str
# Whether its loop has exited: `remain-on-exit failed` keeps the window of a loop that failed, so its last lines stay readable.
dead: bool
# Whether its chunk is parked: its name held PARKED.
parked: bool = False
@dataclasses.dataclass(frozen=True)
@@ -76,14 +80,20 @@ def listed(session: str, run: Tmux) -> list[Listed]:
"""The windows of session; none where tmux lists none, as while the session doesn't exist or no tmux server runs."""
done = run(["list-windows", "-t", f"={session}", "-F", "#{window_name}\t#{pane_dead}\t#{window_id}"])
rows = [line.split("\t") for line in done.stdout.splitlines()] if done.returncode == 0 else []
return [Listed(row[0].removesuffix(WAITS), row[2], row[1] == "1") for row in rows if len(row) == 3]
return [as_listed(row[0], row[2], row[1]) for row in rows if len(row) == 3]
def as_listed(shown: str, id: str, pane_dead: str) -> Listed:
"""The window tmux shows under the name shown, with the ID id and `#{pane_dead}` as pane_dead."""
name, parked, _ = shown.removesuffix(WAITS).partition(PARKED)
return Listed(name, id, pane_dead == "1", bool(parked))
def everywhere(run: Tmux) -> list[Placed]:
"""The windows of every session; none where no tmux server runs."""
done = run(["list-windows", "-a", "-F", f"#{{session_name}}\t#{{window_name}}\t#{{pane_dead}}\t#{{window_id}}\t#{{{ROOT}}}"])
rows = [line.split("\t") for line in done.stdout.splitlines()] if done.returncode == 0 else []
return [Placed(row[0], Listed(row[1].removesuffix(WAITS), row[3], row[2] == "1"), row[4]) for row in rows if len(row) == 5]
return [Placed(row[0], as_listed(row[1], row[3], row[2]), row[4]) for row in rows if len(row) == 5]
def start_window(window: Window, cwd: str, env: typing.Mapping[str, str], command: list[str], first: bool, owned: bool, run: Tmux) -> Failure | None:
@@ -131,6 +141,18 @@ def mark(window: Window, waits: bool, run: Tmux) -> None:
run(["rename-window", "-t", window.pane, window.name + (WAITS if waits else "")])
def park(window: Window, on: str, run: Tmux) -> None:
"""Shows window's chunk as parked while its pull request awaits on, such as `an approval`: the name says so, and the window names no folder its chunk works in, so no checkout counts it as a running chunk."""
run(["rename-window", "-t", window.pane, window.name + PARKED + on])
run(["set-option", "-w", "-u", "-t", window.pane, ROOT])
def unpark(window: Window, root: str, run: Tmux) -> None:
"""Shows window's chunk as running again, in the folder root."""
run(["rename-window", "-t", window.pane, window.name])
run(["set-option", "-w", "-t", window.pane, ROOT, root])
def show(session: str, inside: bool) -> list[str]:
"""The tmux arguments that put session on the human's terminal: inside tmux the client switches to it, and outside a new client attaches."""
return ["switch-client" if inside else "attach-session", "-t", f"={session}"]