updated codex tracker

This commit is contained in:
David Chen 2025-09-22 10:04:24 -07:00
parent 74c2fa6ced
commit 61ace2ef02
6 changed files with 293 additions and 138 deletions

View file

@ -14,3 +14,7 @@ When you need to call tools from the shell, **use this rubric**:
- YAML/XML: `yq`
- Use the `python3` command for python. There is no `python` command on this system.
TRACKER INTEGRATION
- Before starting substantive work, call the MCP tool `tracker_mark_start_working` exactly once with:
- `summary`: short description of planned work
- `tmux_id`: the provided TMUX_ID in the form `session_id::window_id::pane_id`

View file

@ -20,5 +20,6 @@ notify = ["/usr/bin/python3", "/Users/david/.config/codex/notify
# cwd = "/Users/david/Github/project-wiki-mcp"
# startup_timeout_ms = 20000
# [mcp_servers.tracker]
# command = "/Users/david/.config/agent-tracker/bin/tracker-mcp"
[mcp_servers.tracker]
command = "/Users/david/.config/agent-tracker/bin/tracker-mcp"
startup_timeout_ms = 20000

146
codex/notify.py Executable file
View file

@ -0,0 +1,146 @@
#!/usr/bin/env python3
import json
import os
import shlex
import shutil
import subprocess
import sys
def main() -> int:
if len(sys.argv) != 2:
print("Usage: notify.py <NOTIFICATION_JSON>")
return 1
try:
notification = json.loads(sys.argv[1])
except json.JSONDecodeError:
return 1
if notification.get("type") == "agent-turn-complete":
assistant_message = notification.get("last-assistant-message")
title = "Codex"
subtitle = assistant_message if assistant_message else "Turn Complete!"
input_messages = notification.get("input_messages", [])
# Build body and strip empty/whitespace-only lines for a tighter banner
raw_body = "\n".join(input_messages)
non_empty_lines = [ln for ln in raw_body.splitlines() if ln.strip()]
message = "\n".join(non_empty_lines).strip()
else:
print(f"not sending a push notification for: {notification}")
return 0
# Try to discover tmux target of the caller (session/window/pane)
# Prefer TMUX_PANE from env; fall back to parent process TTY.
tmux_path = shutil.which("tmux") or "/opt/homebrew/bin/tmux"
tmux_ids = None
if os.path.exists(tmux_path):
pane = os.environ.get("TMUX_PANE", "").strip()
try:
if pane:
out = subprocess.check_output(
[
tmux_path,
"display-message",
"-p",
"-t",
pane,
"#{session_id}:::#{window_id}:::#{pane_id}",
],
text=True,
).strip()
parts = out.split(":::")
if len(parts) == 3:
tmux_ids = tuple(parts)
except Exception:
tmux_ids = None
if tmux_ids is None:
try:
ppid = os.getppid()
tty = (
subprocess.check_output(
["ps", "-o", "tty=", "-p", str(ppid)], text=True
)
.strip()
.lstrip("?")
)
if tty:
out = subprocess.check_output(
[
tmux_path,
"display-message",
"-p",
"-c",
f"/dev/{tty}",
"#{session_id}:::#{window_id}:::#{pane_id}",
],
text=True,
).strip()
parts = out.split(":::")
if len(parts) == 3:
tmux_ids = tuple(parts)
except Exception:
tmux_ids = None
args = [
"terminal-notifier",
"-title",
title,
"-subtitle",
subtitle,
"-message",
message,
"-group",
"codex",
"-ignoreDnD",
"-activate",
"com.googlecode.iterm2",
]
# Before showing the banner: tell the tracker server we responded,
# attaching the assistant's response text as the completion note.
if tmux_ids is not None and assistant_message:
try:
tracker_bin = shutil.which("tracker-client")
if not tracker_bin:
tracker_bin = os.path.join(os.path.expanduser("~"), ".config", "agent-tracker", "bin", "tracker-client")
if os.path.exists(tracker_bin):
sid, wid, pid = [s.strip() for s in tmux_ids]
subprocess.check_output(
[
tracker_bin,
"command",
"-session-id",
sid,
"-window-id",
wid,
"-pane",
pid,
"-summary",
assistant_message,
"finish_task",
],
text=True,
)
except Exception:
pass
# On click: focus iTerm2 and switch tmux to the originating pane
if tmux_ids is not None:
sid, wid, pid = [s.strip() for s in tmux_ids]
switch_cmd = (
f"{shlex.quote(tmux_path)} switch-client -t {shlex.quote(sid)}"
f" && {shlex.quote(tmux_path)} select-window -t {shlex.quote(wid)}"
f" && {shlex.quote(tmux_path)} select-pane -t {shlex.quote(pid)}"
)
args += ["-execute", "sh -lc " + shlex.quote(switch_cmd)]
subprocess.check_output(args)
return 0
if __name__ == "__main__":
sys.exit(main())