From a84fa292ceac4db34cdc11284542e7ef191f9030 Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Thu, 22 Oct 2026 15:25:31 +0100 Subject: [PATCH] remove agent session title integration Change-Id: I4cd2d9572ad830114cecb92cd8fd29326a6a6964 --- modules/home/ai-agent/default.nix | 60 ++++------ modules/home/ai-agent/global-context.md | 6 - .../skills/updating-session-title/SKILL.md | 43 -------- .../scripts/set_title.py | 103 ------------------ modules/home/ai-agent/statusline.sh | 12 -- 5 files changed, 19 insertions(+), 205 deletions(-) delete mode 100644 modules/home/ai-agent/skills/updating-session-title/SKILL.md delete mode 100644 modules/home/ai-agent/skills/updating-session-title/scripts/set_title.py diff --git a/modules/home/ai-agent/default.nix b/modules/home/ai-agent/default.nix index 6517036..ffbbd09 100644 --- a/modules/home/ai-agent/default.nix +++ b/modules/home/ai-agent/default.nix @@ -57,18 +57,6 @@ let "opencode" = ".opencode/skills"; } .${config.ai-agent.agent}; - sessionTitleSkill = ./skills/updating-session-title; - sessionTitlePromptHook = [ - { - hooks = [ - { - type = "command"; - command = "${lib.escapeShellArg "${config.home.profileDirectory}/bin/agent-session-title"} --prompt-start"; - timeout = 2; - } - ]; - } - ]; commitMessageHook = [ { matcher = "Bash"; @@ -118,27 +106,31 @@ let } ) httpMcpServers; }; - tgmcp ="${inputs.tg.packages.${pkgs.stdenv.hostPlatform.system}.tgmcp}/bin/tgmcp"; + tgmcp = "${inputs.tg.packages.${pkgs.stdenv.hostPlatform.system}.tgmcp}/bin/tgmcp"; agentPackage = if config.ai-agent.agent == "codex" then pkgs.symlinkJoin { - name = "codex-with-session-title"; + name = "codex-with-mcp"; paths = [ llmAgentsPkgs.codex ]; nativeBuildInputs = [ pkgs.makeWrapper ]; postBuild = '' - wrapProgram "$out/bin/codex" --add-flags '-c tui.terminal_title=[] -c tui.alternate_screen=always --enable hooks' \ + wrapProgram "$out/bin/codex" --add-flags '-c tui.alternate_screen=always --enable hooks' \ --add-flags '-c tui.keymap.chat.edit_queued_message=ctrl-up -c tui.theme="catppuccin-mocha"' \ - ${lib.concatStrings ( - lib.mapAttrsToList ( - name: server: - "--add-flag -c --add-flag ${lib.escapeShellArg "mcp_servers.${name}.command=\"${server.command}\""} " - ) stdioMcpServers - ++ lib.mapAttrsToList ( - name: server: - "--add-flag -c --add-flag ${lib.escapeShellArg "mcp_servers.${name}.url=\"${server.url}\""} " - + lib.optionalString (server.bearerTokenFile != null) "--add-flag -c --add-flag ${lib.escapeShellArg "mcp_servers.${name}.bearer_token_env_var=\"${mcpTokenVar name}\""} " - ) httpMcpServers - )} \ + ${ + lib.concatStrings ( + lib.mapAttrsToList ( + name: server: + "--add-flag -c --add-flag ${lib.escapeShellArg "mcp_servers.${name}.command=\"${server.command}\""} " + ) stdioMcpServers + ++ lib.mapAttrsToList ( + name: server: + "--add-flag -c --add-flag ${lib.escapeShellArg "mcp_servers.${name}.url=\"${server.url}\""} " + + + lib.optionalString (server.bearerTokenFile != null) + "--add-flag -c --add-flag ${lib.escapeShellArg "mcp_servers.${name}.bearer_token_env_var=\"${mcpTokenVar name}\""} " + ) httpMcpServers + ) + } \ ${exportMcpTokens} ''; } @@ -149,9 +141,7 @@ let nativeBuildInputs = [ pkgs.makeWrapper ]; # The `=` form stops the variadic --mcp-config from consuming a positional prompt. postBuild = '' - wrapProgram "$out/bin/claude" ${exportMcpTokens} --add-flag "--mcp-config=${ - pkgs.writeText "claude-mcp.json" (builtins.toJSON claudeMcpConfig) - }" + wrapProgram "$out/bin/claude" ${exportMcpTokens} --add-flag "--mcp-config=${pkgs.writeText "claude-mcp.json" (builtins.toJSON claudeMcpConfig)}" ''; } else @@ -181,10 +171,8 @@ let env = { DISABLE_AUTOUPDATER = "1"; DISABLE_UPDATES = "1"; - CLAUDE_CODE_DISABLE_TERMINAL_TITLE = "1"; }; hooks = { - UserPromptSubmit = sessionTitlePromptHook; PostToolUse = commitMessageHook; PreToolUse = commitMessageHook ++ commentSkillHook; TaskCompleted = [ @@ -263,13 +251,6 @@ in pkgs.ripgrep pkgs.jq pkgs.ast-grep - (pkgs.writeShellApplication { - name = "agent-session-title"; - runtimeInputs = lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.procps ]; - text = '' - exec ${pkgs.python3}/bin/python3 ${sessionTitleSkill}/scripts/set_title.py "$@" - ''; - }) ]; home.sessionVariables.CLAUDE_CODE_FORCE_SESSION_PERSISTENCE = "1"; @@ -327,7 +308,6 @@ in }; ".codex/hooks.json".text = builtins.toJSON { - hooks.UserPromptSubmit = sessionTitlePromptHook; hooks.PostToolUse = commitMessageHook; hooks.PreToolUse = commitMessageHook; }; @@ -352,8 +332,6 @@ in }; }; - xdg.configFile."ai-agent/skills/updating-session-title".source = sessionTitleSkill; - home.activation.removeCodexPromptStackBack = lib.hm.dag.entryAfter [ "writeBoundary" ] '' codexConfig=${lib.escapeShellArg "${config.home.homeDirectory}/.codex/config.toml"} if [ -f "$codexConfig" ]; then diff --git a/modules/home/ai-agent/global-context.md b/modules/home/ai-agent/global-context.md index 5f71ccf..5a5e1ca 100644 --- a/modules/home/ai-agent/global-context.md +++ b/modules/home/ai-agent/global-context.md @@ -1,9 +1,3 @@ -Session titles: - -- As the first tool action of every main-agent turn, run `agent-session-title ' · '` before reading files, loading skills, or investigating the task. Use the Jira key, `repo#number` for another issue tracker, or the repository name. If the activity is not clear yet, use `reading your message`. Do not leave a previous `done:` or `needs` title visible while starting work. -- After that first update, read `~/.config/ai-agent/skills/updating-session-title/SKILL.md` once per session. Update the title when your activity changes and before your final response. Subagents must leave the title alone. -- The prompt-submission hook resets the title before model processing. Still make the concrete activity update your first tool action; this also covers sessions where the hook has not loaded. - Follow the Google developer documentation style guide when writing prose: - Be conversational and friendly, not stiff or robotic; avoid jargon and business-speak. diff --git a/modules/home/ai-agent/skills/updating-session-title/SKILL.md b/modules/home/ai-agent/skills/updating-session-title/SKILL.md deleted file mode 100644 index e79157c..0000000 --- a/modules/home/ai-agent/skills/updating-session-title/SKILL.md +++ /dev/null @@ -1,43 +0,0 @@ ---- -name: updating-session-title -description: Updates the terminal tab title with the ticket or repository and a concrete activity or request. Use as the first tool action of each main-agent turn, when the activity changes, and before handing control back in a terminal coding session. ---- - -# Updating session titles - -Only update the title from the main agent. Subagents share its terminal and must leave the title alone. - -Make the title update your first tool action after each user message, before reading files or loading other skills. If you need to establish the task, use `reading your message` and replace it with the concrete activity as soon as you know it. Do not postpone the update until after planning or investigation. - -Use ` · `. Choose the prefix from the issue you are working on: - -- For Jira, use the issue key, such as `GPUPINT-1782`. -- For other issue trackers, use `repo#number`. Issue 20 in `tangled.org/starhaven.dev/papermario-dx` becomes `papermario-dx#20`. -- Without an established issue, use the repository or directory name. Do not invent an issue reference. - -Keep the description short but include what you are investigating, changing, testing, or asking for. Aim for about 80 characters or fewer without dropping the useful subject. - -| Situation | Title | -| --- | --- | -| Investigating a board boot timeout for a ticket | `GPUPINT-1782 · tracing FPGA boot timeout` | -| Testing reconnect behavior for that ticket | `GPUPINT-1782 · testing reconnect after reset` | -| Asking for a decision about retry behavior | `GPUPINT-1782 · needs decision on retry limit` | -| Investigating camera jitter for Tangled issue 20 | `papermario-dx#20 · tracing camera jitter` | -| Waiting for feedback about title formatting | `infra · needs feedback on tab title format` | -| Finishing the terminal-title setup with no request outstanding | `infra · done: terminal title setup` | - -Update at meaningful activity changes and before the final response. Keep the ticket prefix while working on that ticket. If you need an answer or approval, state what it concerns. If the work is complete, say `done: `; do not imply that you need a reply. After the initial prompt reset, avoid vague statuses such as `working`, `testing`, or `needs input` without a subject. - -Run the installed helper with the full title as one quoted argument: - -```sh -agent-session-title 'infra · adding terminal title fallback' -``` - -If the command is unavailable, run `python3 scripts/set_title.py ''` using the script path relative to this skill directory. Use a normal shell command without allocating an extra pseudo-terminal: a temporary tool terminal can capture the escape sequence instead of displaying it. Quote the title as shell data; never interpolate unquoted conversation text into a command. - -The helper resolves `ZELLIJ_PANE_ID` to its containing tab and targets that tab explicitly. A pane ID is not a tab ID. Outside Zellij, it writes an OSC 2 title to the controlling terminal or the nearest ancestor's terminal. Ghostty supports this sequence; an interactive SSH connection can carry it to the local terminal. Without an accessible terminal, the helper skips the update. In a Claude Code session, it also saves the title under `$XDG_RUNTIME_DIR/agent-session-title/`, named by session ID, for the status line to show. If an update fails, continue the main task without retry loops or permission requests. - -The managed Codex and Claude `UserPromptSubmit` command hooks run `agent-session-title --prompt-start` synchronously before model processing. The hook reads the event JSON from stdin and sets `reading your message` without sending prompt text to the terminal. In Zellij, it retains the existing ticket or repository prefix. Outside Zellij, it uses the working directory name until your first activity update supplies the ticket. The two-second hook timeout limits delays when the terminal is unavailable. - -The managed Codex launcher enables hooks, and both agents disable their built-in title updates. Codex requires review and trust of a new or changed user hook through `/hooks`; installation does not grant that trust. If a running session has not loaded the hook, reload or restart it. Keep the first-action title update as a fallback. diff --git a/modules/home/ai-agent/skills/updating-session-title/scripts/set_title.py b/modules/home/ai-agent/skills/updating-session-title/scripts/set_title.py deleted file mode 100644 index 9350d22..0000000 --- a/modules/home/ai-agent/skills/updating-session-title/scripts/set_title.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env python3 -"""Set the calling agent's Zellij tab or terminal title.""" - -import argparse -import json -import os -from pathlib import Path -import subprocess -import sys -import tempfile - - -def run(*args): - return subprocess.check_output( - args, text=True, stderr=subprocess.DEVNULL, timeout=3 - ) - - -def zellij_pane(): - pane_id = int(os.environ["ZELLIJ_PANE_ID"]) - panes = json.loads(run("zellij", "action", "list-panes", "--tab", "--json")) - return next(p for p in panes if not p["is_plugin"] and p["id"] == pane_id) - - -def rename_zellij_tab(title, pane): - run("zellij", "action", "rename-tab", "--tab-id", str(pane["tab_id"]), title) - - -def title_file(session_id): - """Where a session's title is kept for its status line to read.""" - runtime = os.environ.get("XDG_RUNTIME_DIR") or tempfile.gettempdir() - return Path(runtime) / "agent-session-title" / session_id - - -def write_terminal_title(title): - sequence = f"\033]2;{title}\007".encode("utf-8") - try: - with open("/dev/tty", "wb", buffering=0) as terminal: - terminal.write(sequence) - return - except OSError: - pass - - # Agent shell tools can detach from the agent's controlling terminal. - pid = os.getppid() - while pid > 1: - parent, tty = run("ps", "-o", "ppid=", "-o", "tty=", "-p", str(pid)).split() - if tty not in ("?", "??", "-"): - with open(f"/dev/{tty}", "wb", buffering=0) as terminal: - terminal.write(sequence) - return - pid = int(parent) - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - mode = parser.add_mutually_exclusive_group(required=True) - mode.add_argument("title", nargs="?") - mode.add_argument("--prompt-start", action="store_true") - args = parser.parse_args() - - try: - payload = {} - if args.prompt_start: - payload = json.load(sys.stdin) - if payload.get("hook_event_name") != "UserPromptSubmit" or payload.get("agent_id"): - return - - session_id = payload.get("session_id") or os.environ.get("CLAUDE_CODE_SESSION_ID") - pane = None - if "ZELLIJ" in os.environ or "ZELLIJ_PANE_ID" in os.environ: - pane = zellij_pane() - - title = args.title - if args.prompt_start: - prefix = Path(payload.get("cwd") or os.getcwd()).name or "session" - previous = pane.get("tab_name", "") if pane else "" - if not previous and session_id and title_file(session_id).exists(): - previous = title_file(session_id).read_text() - if " · " in previous: - prefix = previous.split(" · ", 1)[0] - title = f"{prefix} · reading your message" - title = " ".join( - "".join(c for c in title if c.isprintable() or c.isspace()).split() - )[:120] - if not title: - return - - if session_id: - path = title_file(session_id) - path.parent.mkdir(mode=0o700, exist_ok=True) - path.write_text(title) - - if pane: - rename_zellij_tab(title, pane) - else: - write_terminal_title(title) - except (OSError, ValueError, KeyError, StopIteration, subprocess.SubprocessError) as error: - print(f"Session title update skipped: {error}", file=sys.stderr) - - -if __name__ == "__main__": - main() diff --git a/modules/home/ai-agent/statusline.sh b/modules/home/ai-agent/statusline.sh index 72e6acc..32b0755 100644 --- a/modules/home/ai-agent/statusline.sh +++ b/modules/home/ai-agent/statusline.sh @@ -1,9 +1,4 @@ -# Claude Code status line, laid out like the Starship prompt: directory and -# jj bookmark, then the session title from agent-session-title, the model, -# and how much of the context window is used. - input=$(cat) -session_id=$(jq -r '.session_id // empty' <<<"$input") cwd=$(jq -r '.workspace.current_dir // .cwd' <<<"$input") model=$(jq -r '.model.display_name // empty' <<<"$input") used=$(jq -r '.context_window.used_percentage // empty' <<<"$input") @@ -20,15 +15,8 @@ bookmark=$(cd "$cwd" && jj --ignore-working-copy log --no-graph \ -r 'latest(::@ & (bookmarks() | remote_bookmarks()))' \ -T 'coalesce(bookmarks.join(", "), remote_bookmarks.join(", "))' 2>/dev/null) || bookmark= -title_file="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}/agent-session-title/$session_id" -title= -if [[ -n $session_id && -f $title_file ]]; then - title=$(<"$title_file") -fi - printf '\033[2m%s\033[0m' "$dir" [[ -n $bookmark ]] && printf ' \033[1;33m%s\033[0m' "$bookmark" -[[ -n $title ]] && printf ' %s' "$title" printf '\033[2m' [[ -n $model ]] && printf ' | %s' "$model" [[ -n $used ]] && printf ' | ctx %.0f%%' "$used" -- knotmirror 0.0.1