Skip to content

Commit 6faa75f

Browse files
committed
refactor(cmux): move agent helpers to libexec
1 parent c9bd08f commit 6faa75f

21 files changed

Lines changed: 119 additions & 79 deletions

home/.chezmoiignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.hammerspoon
44
.raycast
55
Library
6+
.local/libexec/cmux
67
{{- end }}
78

89
{{- if ne .chezmoi.os "linux" }}

home/.chezmoiremove

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ mcp.json
2020
.codex/skills/my-team-share
2121
.config/cmux/settings.json
2222
.local/bin/cmux-workspace-note
23+
.local/bin/cmux-agent-board-auto-title
24+
.local/bin/cmux-agent-board-diff-open
25+
.local/bin/cmux-agent-board-diff-refresh
26+
.local/bin/cmux-agent-board-state
27+
.local/bin/cmux-agent-board-usage
28+
.local/bin/cmux-agent-status-sync
29+
.local/bin/cmux-resume-all-codex-sessions
2330
.config/systemd/user/claude-code-viewer.service.d/codex-subagents.conf
2431
.local/bin/dotfiles-apply-subagent-policy
2532
CLAUDE.md

home/dot_claude/settings.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"hooks": [
1717
{
1818
"type": "command",
19-
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/bin/cmux-agent-board-state\" stopped; fi",
19+
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/libexec/cmux/agent-board-state\" stopped; fi",
2020
"timeout": 5
2121
}
2222
]
@@ -27,7 +27,7 @@
2727
"hooks": [
2828
{
2929
"type": "command",
30-
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/bin/cmux-agent-board-state\" input; fi",
30+
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/libexec/cmux/agent-board-state\" input; fi",
3131
"timeout": 5
3232
}
3333
]
@@ -61,7 +61,7 @@
6161
"hooks": [
6262
{
6363
"type": "command",
64-
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/bin/cmux-agent-board-state\" working; fi",
64+
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/libexec/cmux/agent-board-state\" working; fi",
6565
"timeout": 5
6666
}
6767
]
@@ -71,7 +71,7 @@
7171
"hooks": [
7272
{
7373
"type": "command",
74-
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/bin/cmux-agent-board-state\" input; fi",
74+
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/libexec/cmux/agent-board-state\" input; fi",
7575
"timeout": 5
7676
}
7777
]
@@ -82,7 +82,7 @@
8282
"hooks": [
8383
{
8484
"type": "command",
85-
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/bin/cmux-agent-board-state\" working; fi",
85+
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/libexec/cmux/agent-board-state\" working; fi",
8686
"timeout": 5
8787
}
8888
]
@@ -93,7 +93,7 @@
9393
"hooks": [
9494
{
9595
"type": "command",
96-
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/bin/cmux-agent-board-state\" working; fi",
96+
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/libexec/cmux/agent-board-state\" working; fi",
9797
"timeout": 5
9898
}
9999
]
@@ -102,7 +102,7 @@
102102
"hooks": [
103103
{
104104
"type": "command",
105-
"command": "if [ -z \"${CMUX_SURFACE_ID:-}\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ] || [ \"${CMUX_AGENT_BOARD_AUTO_TITLE_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/bin/cmux-agent-board-auto-title\"; fi",
105+
"command": "if [ -z \"${CMUX_SURFACE_ID:-}\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ] || [ \"${CMUX_AGENT_BOARD_AUTO_TITLE_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/libexec/cmux/agent-board-auto-title\"; fi",
106106
"timeout": 5
107107
}
108108
]
@@ -113,7 +113,7 @@
113113
"hooks": [
114114
{
115115
"type": "command",
116-
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/bin/cmux-agent-board-state\" stopped; fi",
116+
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/libexec/cmux/agent-board-state\" stopped; fi",
117117
"timeout": 5
118118
}
119119
]
@@ -124,7 +124,7 @@
124124
"hooks": [
125125
{
126126
"type": "command",
127-
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/bin/cmux-agent-board-state\" clear; fi",
127+
"command": "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"${CMUX_CLAUDE_HOOKS_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/libexec/cmux/agent-board-state\" clear; fi",
128128
"timeout": 3
129129
}
130130
]

home/dot_codex/hooks.json.tmpl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
{{- if stat $hooksPath -}}
44
{{- $base = include $hooksPath | fromJson -}}
55
{{- end -}}
6-
{{- $working := "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"$CMUX_CODEX_HOOKS_DISABLED\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/bin/cmux-agent-board-state\" working; fi" -}}
7-
{{- $stopped := "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"$CMUX_CODEX_HOOKS_DISABLED\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/bin/cmux-agent-board-state\" stopped; fi" -}}
8-
{{- $input := "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"$CMUX_CODEX_HOOKS_DISABLED\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/bin/cmux-agent-board-state\" input; fi" -}}
9-
{{- $clear := "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"$CMUX_CODEX_HOOKS_DISABLED\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/bin/cmux-agent-board-state\" clear; fi" -}}
10-
{{- $autoTitle := "if [ -z \"${CMUX_SURFACE_ID:-}\" ] || [ \"${CMUX_CODEX_HOOKS_DISABLED:-}\" = \"1\" ] || [ \"${CMUX_AGENT_BOARD_AUTO_TITLE_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/bin/cmux-agent-board-auto-title\"; fi" -}}
6+
{{- $working := "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"$CMUX_CODEX_HOOKS_DISABLED\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/libexec/cmux/agent-board-state\" working; fi" -}}
7+
{{- $stopped := "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"$CMUX_CODEX_HOOKS_DISABLED\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/libexec/cmux/agent-board-state\" stopped; fi" -}}
8+
{{- $input := "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"$CMUX_CODEX_HOOKS_DISABLED\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/libexec/cmux/agent-board-state\" input; fi" -}}
9+
{{- $clear := "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"$CMUX_CODEX_HOOKS_DISABLED\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/libexec/cmux/agent-board-state\" clear; fi" -}}
10+
{{- $autoTitle := "if [ -z \"${CMUX_SURFACE_ID:-}\" ] || [ \"${CMUX_CODEX_HOOKS_DISABLED:-}\" = \"1\" ] || [ \"${CMUX_AGENT_BOARD_AUTO_TITLE_DISABLED:-}\" = \"1\" ]; then echo '{}'; else \"$HOME/.local/libexec/cmux/agent-board-auto-title\"; fi" -}}
1111
{{- $oldWorking := "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"$CMUX_CODEX_HOOKS_DISABLED\" = \"1\" ]; then echo '{}'; else cmux set-progress 0 --label working >/dev/null && echo '{}'; fi" -}}
1212
{{- $oldIdle := "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"$CMUX_CODEX_HOOKS_DISABLED\" = \"1\" ]; then echo '{}'; else cmux set-progress 1 --label idle >/dev/null && echo '{}'; fi" -}}
1313
{{- $oldClear := "if [ -z \"$CMUX_SURFACE_ID\" ] || [ \"$CMUX_CODEX_HOOKS_DISABLED\" = \"1\" ]; then echo '{}'; else cmux clear-progress >/dev/null && echo '{}'; fi" -}}
1414
{{ output "jq" "-n" "--argjson" "base" ($base | toJson) "--arg" "working" $working "--arg" "stopped" $stopped "--arg" "input" $input "--arg" "clear" $clear "--arg" "autoTitle" $autoTitle "--arg" "oldWorking" $oldWorking "--arg" "oldIdle" $oldIdle "--arg" "oldClear" $oldClear `
1515
def without_agent_board:
1616
map(select(
1717
((.hooks // []) | any(
18-
((.command // "") | contains("cmux-agent-board-state"))
18+
((.command // "") | contains("agent-board-state"))
1919
or .command == $oldWorking or .command == $oldIdle or .command == $oldClear
2020
)) | not
2121
));
@@ -25,7 +25,7 @@
2525
if ((.hooks // null) | type) == "array" then
2626
.hooks = [
2727
.hooks[]
28-
| select(((.command // "") | contains("cmux-agent-board-auto-title")) | not)
28+
| select(((.command // "") | contains("agent-board-auto-title")) | not)
2929
]
3030
else .
3131
end

home/dot_local/bin/executable_cmux-agent-board-auto-title renamed to home/dot_local/libexec/cmux/executable_agent-board-auto-title

File renamed without changes.

home/dot_local/bin/executable_cmux-agent-board-diff-open renamed to home/dot_local/libexec/cmux/executable_agent-board-diff-open

File renamed without changes.

home/dot_local/bin/executable_cmux-agent-board-diff-refresh renamed to home/dot_local/libexec/cmux/executable_agent-board-diff-refresh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ def main() -> None:
750750
"CMUX_AGENT_BOARD_LOCK", Path.home() / ".local/state/cmux/agent-board-diff-refresh.lock"
751751
)
752752
usage_bin = configured_path(
753-
"CMUX_AGENT_BOARD_USAGE", Path.home() / ".local/bin/cmux-agent-board-usage"
753+
"CMUX_AGENT_BOARD_USAGE", Path.home() / ".local/libexec/cmux/agent-board-usage"
754754
)
755755
usage_timeout = configured_timeout(
756756
"CMUX_AGENT_BOARD_USAGE_TIMEOUT", USAGE_TIMEOUT_SECONDS

home/dot_local/bin/executable_cmux-agent-board-state renamed to home/dot_local/libexec/cmux/executable_agent-board-state

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ if [[ -z "$surface_id" ]]; then
1717
fi
1818

1919
title_lock_dir="${CMUX_AGENT_BOARD_TITLE_LOCK_DIR:-$HOME/.local/state/cmux/agent-board-title-locks}"
20-
safe_surface_id="$(printf '%s' "$surface_id" | sed 's/[^A-Za-z0-9._-]/_/g')"
21-
mkdir -p "$title_lock_dir"
20+
safe_surface_id="${surface_id//[^A-Za-z0-9._-]/_}"
21+
[[ -d "$title_lock_dir" ]] || mkdir -p "$title_lock_dir"
2222
exec 9>"$title_lock_dir/${safe_surface_id}.lock"
2323
if command -v lockf >/dev/null 2>&1; then
2424
lockf -s -t 5 9 || lock_status=$?
@@ -49,25 +49,21 @@ case "$state" in
4949
;;
5050
esac
5151

52-
current_workspace_title="$({
53-
CMUX_QUIET=1 cmux workspace list --json
52+
title_assignments="$({
53+
CMUX_QUIET=1 cmux --json tree --workspace "$workspace_id"
5454
} | jq -er --arg workspace_id "$workspace_id" '
55-
.workspaces[]
56-
| select(.id == $workspace_id or .ref == $workspace_id)
57-
| .title
58-
')"
59-
60-
surface_list_params="$(jq -cn --arg workspace_id "$workspace_id" '{workspace_id: $workspace_id}')"
61-
current_surface_title="$({
62-
CMUX_QUIET=1 cmux rpc surface.list "$surface_list_params"
63-
} | jq -er --arg surface_id "$surface_id" '
64-
.surfaces
65-
| map(select(.id == $surface_id or .ref == $surface_id))
55+
.caller.surface_ref as $surface_ref
56+
| [.windows[].workspaces[] | select(.id == $workspace_id or .ref == $workspace_id)]
57+
| if length != 1 then error("workspace not found or not unique") else .[0] end
58+
| . as $workspace
59+
| [$workspace.panes[].surfaces[] | select(.ref == $surface_ref)]
6660
| if length != 1 then error("surface not found or not unique")
61+
elif ($workspace.title | type) != "string" then error("workspace title was not a string")
6762
elif (.[0].title | type) != "string" then error("surface title was not a string")
68-
else .[0].title
63+
else @sh "current_workspace_title=\($workspace.title) current_surface_title=\(.[0].title)"
6964
end
7065
')"
66+
eval "$title_assignments"
7167

7268
workspace_has_marker=false
7369
if [[ "$current_workspace_title" == *"$working_marker"*

home/dot_local/bin/executable_cmux-agent-board-usage renamed to home/dot_local/libexec/cmux/executable_agent-board-usage

File renamed without changes.

home/dot_local/bin/executable_cmux-resume-all-codex-sessions renamed to home/dot_local/libexec/cmux/executable_resume-all-codex-sessions

File renamed without changes.

0 commit comments

Comments
 (0)