-
Notifications
You must be signed in to change notification settings - Fork 0
feat: show Board in an automatic three-line HUD #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
qiankunli
wants to merge
3
commits into
main
Choose a base branch
from
feat/board-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --- | ||
| description: Configure Claude Code's native devloop Board status line | ||
| --- | ||
|
|
||
| Configure the native Claude Code Board status line using the plugin's installer: | ||
|
|
||
| ```bash | ||
| "${CLAUDE_PLUGIN_ROOT}/scripts/python" "${CLAUDE_PLUGIN_ROOT}/scripts/setup_claude_board.py" \ | ||
| --plugin-root "${CLAUDE_PLUGIN_ROOT}" | ||
| ``` | ||
|
|
||
| If the installer exits with `CONFLICT`, an existing non-devloop `statusLine` was found. | ||
| Ask the user whether to replace it. Only after explicit confirmation, rerun the same | ||
| command with `--replace`. Never edit or overwrite the existing status line manually. | ||
|
|
||
| On success, tell the user Claude reloads settings automatically and the Board should | ||
| appear after the next interaction. The installer prints a backup path when it changes | ||
| an existing settings file. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #!/usr/bin/env python3 | ||
| """SessionStart side effect: best-effort automatic Board HUD inside tmux.""" | ||
| from __future__ import annotations | ||
|
|
||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) | ||
|
|
||
| from hooks import hook_io # noqa: E402 | ||
| from ui.board.tmux import ensure_hud_pane # noqa: E402 | ||
|
|
||
|
|
||
| def handle(inp: hook_io.HookInput) -> None: | ||
| ensure_hud_pane(inp.cwd, inp.session_id) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(hook_io.observe(handle)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| #!/usr/bin/env python3 | ||
| """Render Board state for native status lines and the tmux sidecar.""" | ||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import os | ||
| import shutil | ||
| import signal | ||
| import sys | ||
| import time | ||
| from pathlib import Path | ||
|
|
||
| sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) | ||
|
|
||
| from domain.board import BoardRuntime # noqa: E402 | ||
| from lib import config # noqa: E402 | ||
| from ui.board.hud import ( # noqa: E402 | ||
| HudPulseTracker, | ||
| frame_from_snapshot, | ||
| render_frame, | ||
| render_statusline, | ||
| ) | ||
| from ui.board.tmux import LEADER_ENV, pane_command # noqa: E402 | ||
|
|
||
|
|
||
| def _runtime(cwd: str, session_id: str) -> BoardRuntime | None: | ||
| return BoardRuntime.resolve(cwd, session_id) | ||
|
|
||
|
|
||
| def _snapshot(cwd: str, session_id: str) -> dict: | ||
| runtime = _runtime(cwd, session_id) | ||
| return runtime.snapshot() if runtime else {"root": cwd, "focus": None, "items": []} | ||
|
|
||
|
|
||
| def _watch_text(cwd: str, session_id: str, tracker: HudPulseTracker) -> str | None: | ||
| """Keep the last visible frame when a transient Board read is unavailable.""" | ||
| try: | ||
| snapshot = _snapshot(cwd, session_id) | ||
| frame = frame_from_snapshot(snapshot, tracker) | ||
| return render_frame(frame, shutil.get_terminal_size((120, 3)).columns, True) | ||
| except (OSError, ValueError): | ||
| return None | ||
|
|
||
|
|
||
| def _shell_commands(environ: dict[str, str] | None = None) -> set[str]: | ||
| environ = os.environ if environ is None else environ | ||
| commands = {"bash", "dash", "fish", "sh", "zsh"} | ||
| configured = Path(environ.get("SHELL", "")).name | ||
| if configured: | ||
| commands.add(configured) | ||
| return commands | ||
|
|
||
|
|
||
| def _args() -> argparse.Namespace: | ||
| parser = argparse.ArgumentParser(description="Render devloop's Board HUD") | ||
| parser.add_argument("--watch", action="store_true") | ||
| parser.add_argument("--json", action="store_true") | ||
| parser.add_argument("--claude-statusline", action="store_true") | ||
| parser.add_argument("--cwd", default=str(Path.cwd())) | ||
| parser.add_argument("--session-id", default=os.environ.get("DEVLOOP_HUD_SESSION", "")) | ||
| parser.add_argument("--leader-pane", default=os.environ.get(LEADER_ENV, "")) | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| def main() -> int: | ||
| args = _args() | ||
| if args.claude_statusline: | ||
| try: | ||
| payload = json.loads(sys.stdin.read() or "{}") | ||
| except json.JSONDecodeError: | ||
| return 0 | ||
| workspace = payload.get("workspace") if isinstance(payload, dict) else None | ||
| cwd = ( | ||
| workspace.get("current_dir") | ||
| if isinstance(workspace, dict) and workspace.get("current_dir") | ||
| else payload.get("cwd") if isinstance(payload, dict) else None | ||
| ) or args.cwd | ||
| session_id = ( | ||
| str(payload.get("session_id") or args.session_id) | ||
| if isinstance(payload, dict) | ||
| else args.session_id | ||
| ) | ||
| if not config.board_hud(cwd).get("enabled", True): | ||
| return 0 | ||
| runtime = _runtime(cwd, session_id) | ||
| if runtime is None: | ||
| return 0 | ||
| columns = os.environ.get("COLUMNS", "") | ||
| width = int(columns) if columns.isdigit() else shutil.get_terminal_size((120, 2)).columns | ||
| frame = frame_from_snapshot(runtime.snapshot()) | ||
| print(render_statusline(frame, max(1, width - 4), not os.environ.get("NO_COLOR"))) | ||
| return 0 | ||
| if args.json: | ||
| print(json.dumps(_snapshot(args.cwd, args.session_id), indent=2, ensure_ascii=False)) | ||
| return 0 | ||
| if not args.watch: | ||
| frame = frame_from_snapshot(_snapshot(args.cwd, args.session_id)) | ||
| print(render_frame(frame, shutil.get_terminal_size((120, 3)).columns, sys.stdout.isatty())) | ||
| return 0 | ||
|
|
||
| stopped = False | ||
|
|
||
| def stop(_signum=None, _frame=None): | ||
| nonlocal stopped | ||
| stopped = True | ||
|
|
||
| signal.signal(signal.SIGINT, stop) | ||
| signal.signal(signal.SIGTERM, stop) | ||
| tracker = HudPulseTracker() | ||
| inactive_leader_ticks = 0 | ||
| shell_commands = _shell_commands() | ||
| sys.stdout.write("\x1b[?25l\x1b[2J\x1b[H") | ||
| sys.stdout.flush() | ||
| try: | ||
| while not stopped: | ||
| if args.leader_pane: | ||
| leader_command = pane_command(args.leader_pane) | ||
| if leader_command is None: | ||
| break | ||
| inactive_leader_ticks = ( | ||
| inactive_leader_ticks + 1 | ||
| if Path(leader_command).name in shell_commands | ||
| else 0 | ||
| ) | ||
| if inactive_leader_ticks >= 3: | ||
| break | ||
| text = _watch_text(args.cwd, args.session_id, tracker) | ||
| if text is not None: | ||
| lines = "\n".join("\x1b[2K" + line for line in text.splitlines()) | ||
| sys.stdout.write("\x1b[H" + lines + "\x1b[J") | ||
| sys.stdout.flush() | ||
| time.sleep(1) | ||
| finally: | ||
| sys.stdout.write("\x1b[?25h") | ||
| sys.stdout.flush() | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 devloop code-review · seed-2.1-pro
The watch loop does not catch exceptions from
_snapshot(),frame_from_snapshot(), orrender_frame(). IfBoardRuntime.resolve()raises (e.g., due to corrupted state files, permission errors, or transient I/O failures), the HUD process crashes and the dashboard disappears. Thefinallyblock does restore the cursor, but the service still stops unexpectedly. Consider wrapping the snapshot + render logic in atry/exceptthat falls back to a minimal error display and continues the loop.ccr:fp=cfd64e2511ae
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ccr:label=minor — HUD sidecar 是只读观察面;状态暂时不可读会让 pane 退出。已在 scripts/board_hud.py::_watch_text 捕获 OSError/ValueError 并保留上一帧。