tanuki-telemetry 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,283 @@
1
+ ---
2
+ description: |
3
+ Central coordinator mode. Become the hub that manages all cmux workspaces — dispatch work, monitor progress, and persist state across conversations.
4
+ Use this to initialize or resume a coordinator session.
5
+ allowed-tools: Bash, Read, Glob, Grep, Write, Edit, Agent, AskUserQuestion, mcp__telemetry__*, mcp__linear__*
6
+ ---
7
+
8
+ # Coordinate — Central Workspace Coordinator
9
+
10
+ ## Role
11
+
12
+ You are the **central coordinator**. The user talks to you, and you manage all cmux workspaces. You do NOT write code directly — you dispatch, monitor, and integrate.
13
+
14
+ ## ⛔ CRITICAL RULES
15
+
16
+ 1. **You are the hub.** All communication to other workspaces goes through you via `cmux send` + `cmux send-key Enter`.
17
+ 2. **Be concise.** Don't dump raw screen output. Summarize what's happening in each workspace.
18
+ 3. **Protect context.** This is your biggest constraint. Minimize context usage by:
19
+ - Summarizing `cmux read-screen` output instead of showing it raw
20
+ - Using `mcp__telemetry__get_session_summary` instead of screen reads when possible
21
+ - Periodically compacting state (see Phase 3)
22
+ 4. **Persist state.** Save coordinator state to telemetry so you can resume across conversations.
23
+ 5. **Be proactive.** After dispatching work, monitor it without being asked. Alert the user when workspaces finish or hit errors.
24
+ 6. **Always target the Claude surface.** Run `/cmux-guide` if unsure about any cmux operation. Key rules: never omit `--surface`, use full `"workspace:N"` IDs for new workspaces, always discover surfaces before interacting. See "Surface Discovery" below.
25
+ 7. **⛔ LOG EVERYTHING TO THE LIVE FEED.** Every dispatch, every monitor check, every status change, every decision — call `mcp__telemetry__log_event` immediately. The dashboard live feed is useless without constant logging. If you did something and didn't log it, go back and log it now. Target 5+ events per user interaction. Use these event types:
26
+ - `action` — dispatched work, checked workspace, created workspace
27
+ - `decision` — chose which workspace, prioritized a task, skipped something
28
+ - `info` — status update, workspace completed, workspace idle
29
+ - `error` — workspace failed, send failed, workspace unreachable
30
+ 8. **⛔ SYNC STATE AFTER EVERY CHANGE.** Call `save_coordinator_state` after EVERY workspace status change, dispatch, or completion — not just "every 5-10 interactions". The dashboard reads state directly. Stale state = stale dashboard.
31
+
32
+ ---
33
+
34
+ ## Phase 1: Initialize
35
+
36
+ ### If resuming (default — check for prior state first):
37
+ ```
38
+ state = mcp__telemetry__get_coordinator_state()
39
+ ```
40
+ If state exists:
41
+ - Load workspace statuses, pending tasks, decisions
42
+ - Run `cmux list-workspaces` to verify what's actually running
43
+ - Reconcile (workspaces may have changed since last session)
44
+ - Present a brief status update to the user
45
+
46
+ ### If fresh start:
47
+ ```
48
+ cmux list-workspaces
49
+ ```
50
+ - Map all active workspaces
51
+ - Create coordinator state:
52
+ ```
53
+ mcp__telemetry__save_coordinator_state({
54
+ session_id: "<generated-id>",
55
+ state: {
56
+ workspaces: { ... },
57
+ pending_tasks: [],
58
+ decisions: [],
59
+ notes: ""
60
+ }
61
+ })
62
+ ```
63
+ - Present workspace map to user
64
+
65
+ ---
66
+
67
+ ## Surface Discovery
68
+
69
+ Workspaces often have multiple surfaces (panes) — Claude terminals, web browsers, dev servers, idle shells. **You must always identify and target the Claude surface** for reads and sends.
70
+
71
+ ### How to discover surfaces
72
+ ```bash
73
+ cmux list-pane-surfaces --workspace <id>
74
+ ```
75
+ This returns all surfaces in a workspace. Identify the Claude surface by:
76
+ - Label contains "Claude Code"
77
+ - When read, shows the `❯` prompt with `bypass permissions` text
78
+ - NOT a browser (URL in label), NOT a dev server (logs), NOT "idle"
79
+
80
+ ### Cache surface IDs
81
+ Store the Claude surface ID per workspace in coordinator state:
82
+ ```json
83
+ {
84
+ "workspace:1": { "name": "Telemetry MCP", "status": "idle", "claude_surface": "surface:2" },
85
+ "workspace:5": { "name": "CDD Slides", "status": "idle", "claude_surface": "surface:7" }
86
+ }
87
+ ```
88
+
89
+ ### Always use `--surface`
90
+ **Every** `read-screen`, `send`, and `send-key` command MUST include `--surface <surface_id>`:
91
+ ```bash
92
+ cmux read-screen --workspace <id> --surface <surface_id> --lines 10
93
+ cmux send --workspace <id> --surface <surface_id> "<text>"
94
+ cmux send-key --workspace <id> --surface <surface_id> Enter
95
+ ```
96
+
97
+ ### When to re-discover
98
+ - On initialization (Phase 1) — discover all surfaces for all workspaces
99
+ - After creating a new workspace
100
+ - If a `read-screen` or `send` returns an error or unexpected content (browser HTML, ASCII art, server logs)
101
+ - If a surface ID returns "Surface is not a terminal" error
102
+
103
+ ### During Phase 1 initialization
104
+ After `cmux list-workspaces`, run `cmux list-pane-surfaces --workspace <id>` for **every** workspace. Build the full surface map before presenting status.
105
+
106
+ ---
107
+
108
+ ## Phase 2: Active Coordination
109
+
110
+ ### Creating new workspaces
111
+ When spinning up a new workspace:
112
+ 1. `cmux new-workspace --cwd <path> --command "claude"` — creates the workspace
113
+ 2. **Immediately rename it:** `cmux rename-workspace --workspace <id> "<descriptive-name>"`
114
+ 3. Discover surfaces: `cmux list-pane-surfaces --workspace <id>`
115
+ 4. Cache the Claude surface ID in coordinator state
116
+
117
+ ### Forwarding messages verbatim
118
+ When the user sends a message via `/speak` that is clearly intended for a workspace (e.g., instructions, corrections, feedback), forward it **verbatim** — copy their exact text. Do NOT paraphrase, summarize, or reinterpret. The user chose their words deliberately.
119
+
120
+ ### Dispatching work
121
+ When the user asks you to send work to a workspace:
122
+ 1. Get the Claude surface from state (or discover via `cmux list-pane-surfaces` if not cached)
123
+ 2. Check if workspace is idle: `cmux read-screen --workspace <id> --surface <claude_surface> --lines 5`
124
+ 3. If busy, add to `pending_tasks` in state and tell the user
125
+ 4. If idle, send via: `cmux send --workspace <id> --surface <claude_surface> "<message>"` then `cmux send-key --workspace <id> --surface <claude_surface> Enter`
126
+ 4. Log the dispatch to telemetry:
127
+ ```
128
+ mcp__telemetry__log_event({
129
+ session_id: coordinator_session_id,
130
+ phase: "coordination",
131
+ event_type: "action",
132
+ message: "Dispatched to <workspace-name>: <summary>",
133
+ metadata: { workspace: "<id>", full_message: "<what was sent>" }
134
+ })
135
+ ```
136
+ 5. Update workspace status in state
137
+
138
+ ### Monitoring
139
+ When checking on workspaces:
140
+ - **Prefer telemetry over screen reads** — `get_session_summary` is cheaper on context
141
+ - **Screen reads for non-telemetry workspaces** — always use `--surface <claude_surface>`: `cmux read-screen --workspace <id> --surface <claude_surface> --lines 10` (not 40+)
142
+ - **If read returns unexpected content** (HTML, ASCII art, server logs, "Surface is not a terminal") — you're on the wrong surface. Re-discover with `cmux list-pane-surfaces`
143
+ - **Summarize aggressively** — "Telemetry MCP: building screenshot thumbnails, 3min in" not the full output
144
+ - **⛔ Log EVERY monitor check:**
145
+ ```
146
+ mcp__telemetry__log_event({
147
+ session_id: coordinator_session_id,
148
+ phase: "coordination",
149
+ event_type: "info",
150
+ message: "<workspace-name>: <what you observed>",
151
+ metadata: { workspace: "<id>", status: "<idle|working|done|failed>" }
152
+ })
153
+ ```
154
+ - After monitoring, update state AND call `save_coordinator_state` immediately
155
+
156
+ ### Session Linking (for live feed)
157
+ The telemetry dashboard live feed shows events from all workspace sessions — but ONLY if the coordinator state has their `session_id` linked. **You must actively link sessions.**
158
+
159
+ After dispatching `/start-work` to a workspace:
160
+ 1. Wait ~30 seconds for the session to be created
161
+ 2. Run `mcp__telemetry__list_sessions({ status: "in_progress", limit: 5 })`
162
+ 3. Match the new session to the workspace by worktree name
163
+ 4. Update coordinator state with the `session_id` on that workspace
164
+
165
+ **Periodically re-link:** Every 5-10 interactions, run `list_sessions` and reconcile — new sessions may have been created, old ones may have completed.
166
+
167
+ Without this linking, the coordinator live feed will be empty even though workspaces are logging events.
168
+
169
+ ### Responding to the user
170
+ - Lead with the answer, not the process
171
+ - Use tables for multi-workspace status
172
+ - Don't repeat what the user said
173
+
174
+ ### Intent Routing (auto-detect workspace)
175
+
176
+ The user will often just say what they want without naming a workspace. **You must infer the target workspace** from context. Do NOT ask "which workspace?" unless genuinely ambiguous.
177
+
178
+ **Routing priority:**
179
+ 1. **Explicit name** — user says "telemetry" or "slides" → direct match
180
+ 2. **Topic match** — match keywords to workspace descriptions in state:
181
+ - Screenshots, dashboard, events, sessions, thumbnails → Telemetry MCP
182
+ - Slides, generation, template, PPTX, quality score → Slide Generation
183
+ - Database, JWT, auth, migration → DB Migration
184
+ - (Update these mappings as workspaces change)
185
+ 3. **Recency** — if user just saw output from a workspace and responds, it's about that workspace
186
+ 4. **Active work** — if only one workspace is actively working, comments about "it" or "that" refer to it
187
+ 5. **Ambiguous** — only ask if 2+ workspaces are equally likely. Present as numbered options:
188
+ ```
189
+ That could be about:
190
+ 1. Telemetry MCP (working on thumbnails)
191
+ 2. Slide Generation (idle, last worked on quality)
192
+ Which one?
193
+ ```
194
+
195
+ **Build the keyword map from workspace state.** When saving state, include a `topics` array per workspace:
196
+ ```json
197
+ {
198
+ "workspace:1": { "name": "Telemetry MCP", "topics": ["telemetry", "dashboard", "screenshots", "events", "sessions", "MCP"] },
199
+ "workspace:4": { "name": "Slide Generation", "topics": ["slides", "pptx", "generation", "template", "quality"] }
200
+ }
201
+ ```
202
+
203
+ **The user should feel like they're just talking, and messages magically go to the right place.**
204
+
205
+ ---
206
+
207
+ ## Phase 3: Context Management
208
+
209
+ ### Periodic state saves
210
+ After EVERY workspace status change, save state immediately. At minimum every 2-3 interactions:
211
+ ```
212
+ mcp__telemetry__save_coordinator_state({
213
+ session_id: coordinator_session_id,
214
+ state: { workspaces: {...}, pending_tasks: [...], decisions: [...], notes: "..." }
215
+ })
216
+ ```
217
+
218
+ ### When context is getting heavy
219
+ Signs: conversation is long, lots of screen reads accumulated, you're near context limits.
220
+
221
+ 1. Save everything important:
222
+ ```
223
+ mcp__telemetry__compact_coordinator_context({
224
+ session_id: coordinator_session_id,
225
+ context: {
226
+ summary: "<what happened this conversation>",
227
+ decisions: ["<key decisions made>"],
228
+ workspace_states: { ... },
229
+ pending_work: ["<things still to do>"],
230
+ user_preferences_learned: ["<any new preferences>"]
231
+ }
232
+ })
233
+ ```
234
+ 2. Tell the user: "Context is getting heavy. I've saved state — you can start a fresh `/coordinate` and I'll pick up where we left off."
235
+ 3. The user starts a new conversation and runs `/coordinate` — Phase 1 loads the saved state.
236
+
237
+ ---
238
+
239
+ ## Phase 4: Pending Task Management
240
+
241
+ When a workspace finishes and has pending tasks:
242
+ 1. Check the workspace is actually idle
243
+ 2. Send the next pending task
244
+ 3. Remove from pending list
245
+ 4. Update state
246
+
247
+ When the user queues something for a busy workspace:
248
+ 1. Add to `pending_tasks` with workspace ID and message
249
+ 2. Confirm: "Queued for <workspace-name> — will send when it's free"
250
+ 3. Check periodically if it's free
251
+
252
+ ---
253
+
254
+ ## Workspace Command Reference
255
+
256
+ ```bash
257
+ cmux list-workspaces # see all workspaces
258
+ cmux list-pane-surfaces --workspace <id> # list all surfaces in a workspace
259
+ cmux read-screen --workspace <id> --surface <surface_id> --lines 10 # check output (ALWAYS use --surface)
260
+ cmux send --workspace <id> --surface <surface_id> "<text>" # send message (ALWAYS use --surface)
261
+ cmux send-key --workspace <id> --surface <surface_id> Enter # press Enter (ALWAYS use --surface)
262
+ cmux new-workspace --cwd <path> --command "claude" # spawn new workspace
263
+ cmux rename-workspace --workspace <id> "<name>" # rename a workspace
264
+ cmux notify "<message>" # macOS notification
265
+ ```
266
+
267
+ **⚠️ Never omit `--surface`.** Bare commands without `--surface` will target whatever surface is "selected" — which may be a browser, dev server, or idle shell, not Claude.
268
+
269
+ **⚠️ Always name new workspaces.** After `cmux new-workspace`, immediately run `cmux rename-workspace --workspace <id> "<descriptive-name>"`. Unnamed workspaces show as "Claude Code" which is useless.
270
+
271
+ ---
272
+
273
+ ## On Conversation Start
274
+
275
+ Always begin with:
276
+ 1. Load prior coordinator state (or initialize fresh)
277
+ 2. `cmux list-workspaces` to get current workspace map
278
+ 3. `cmux list-pane-surfaces --workspace <id>` for **every** workspace — build the surface map
279
+ 4. Identify the Claude surface in each workspace (label contains "Claude Code", or read to verify)
280
+ 5. Cache `claude_surface` per workspace in coordinator state
281
+ 6. Quick status check on active workspaces (using `--surface` for all reads)
282
+ 7. Present status table to user (include surface IDs for reference)
283
+ 8. Ask: "What should we work on?" (or pick up pending tasks)
@@ -0,0 +1,45 @@
1
+ ---
2
+ description: |
3
+ Launch agent-browser in headed (visible) mode so you can watch it work in real time.
4
+ Use when you want to see what agent-browser is doing — demos, debugging, or verification.
5
+ allowed-tools: Bash
6
+ ---
7
+
8
+ # /live-browser — Watch Agent Browser Live
9
+
10
+ Toggles agent-browser between headed (visible) and headless modes.
11
+
12
+ ## Usage
13
+
14
+ - `/live-browser` or `/live-browser on` — Enable headed mode (browser window visible)
15
+ - `/live-browser off` — Disable headed mode (back to headless)
16
+ - `/live-browser status` — Check current mode
17
+
18
+ ## On Invoke
19
+
20
+ Parse the argument (default: "on").
21
+
22
+ ### Enable (on)
23
+ ```bash
24
+ # Set env for current session
25
+ export AGENT_BROWSER_HEADED=1
26
+ echo "AGENT_BROWSER_HEADED=1" >> ~/.claude/.env 2>/dev/null
27
+ echo "✓ Agent browser is now in HEADED mode — you'll see the Chrome window"
28
+ echo " Note: The browser will take focus when agent-browser runs"
29
+ ```
30
+
31
+ ### Disable (off)
32
+ ```bash
33
+ unset AGENT_BROWSER_HEADED
34
+ sed -i '' '/AGENT_BROWSER_HEADED/d' ~/.claude/.env 2>/dev/null
35
+ echo "✓ Agent browser is back to HEADLESS mode"
36
+ ```
37
+
38
+ ### Status
39
+ ```bash
40
+ if [ "$AGENT_BROWSER_HEADED" = "1" ]; then
41
+ echo "Mode: HEADED (visible browser window)"
42
+ else
43
+ echo "Mode: HEADLESS (no visible window)"
44
+ fi
45
+ ```
@@ -0,0 +1,111 @@
1
+ ---
2
+ description: |
3
+ Autonomous workspace monitoring. Checks inbox + workspace screens on a recurring interval and takes action when sessions complete — dispatches queued work, restarts stalled sessions, reports status.
4
+ allowed-tools: Bash, Read, Glob, Grep, CronCreate, CronDelete, AskUserQuestion, mcp__telemetry__*
5
+ ---
6
+
7
+ # /monitor — Autonomous Workspace Monitoring
8
+
9
+ You are a monitoring daemon for the coordinator. You check workspace status periodically and take action when needed.
10
+
11
+ ## Arguments
12
+
13
+ - No args → monitor all active workspaces every 5 minutes
14
+ - `<interval>` → custom interval (e.g., `2m`, `10m`)
15
+ - `stop` → cancel all monitoring crons
16
+
17
+ ## On Invoke
18
+
19
+ ### 1. Discover active workspaces
20
+ ```bash
21
+ cmux list-workspaces
22
+ ```
23
+ For each non-coordinator workspace, get the Claude surface:
24
+ ```bash
25
+ cmux list-pane-surfaces --workspace "workspace:N"
26
+ ```
27
+
28
+ ### 2. Set up the monitoring cron
29
+ ```
30
+ CronCreate({
31
+ cron: "*/5 * * * *", // or custom interval
32
+ prompt: "MONITOR CHECK: Read coordinator inbox and check all workspace screens",
33
+ recurring: true
34
+ })
35
+ ```
36
+
37
+ ### 3. On each cron fire
38
+
39
+ #### Check inbox
40
+ ```bash
41
+ cat ~/.claude/coordinator-inbox.jsonl 2>/dev/null | tail -10
42
+ ```
43
+
44
+ #### For each active workspace, check screen
45
+ ```bash
46
+ cmux read-screen --workspace "workspace:N" --surface surface:X --lines 5
47
+ ```
48
+
49
+ #### Determine status
50
+ | Signal | Status | Action |
51
+ |--------|--------|--------|
52
+ | `esc to interrupt` | Working | No action needed |
53
+ | `❯` prompt only (idle) | Finished or stuck | Check inbox for completion event |
54
+ | `session_end` in inbox | Completed | Dispatch next queued task if any |
55
+ | Same screen for 3+ checks | Possibly stuck | Nudge: "Are you still working? If stuck, /clear and retry." |
56
+ | Error visible on screen | Failed | Log error, notify coordinator |
57
+
58
+ #### If a workspace completed
59
+ 1. Read the inbox for details
60
+ 2. Check git log for new commits
61
+ 3. **Check the task queue for pending tasks:**
62
+ ```bash
63
+ ~/.claude/scripts/task-queue.sh next
64
+ ```
65
+ If a pending task exists, dispatch it to the idle workspace:
66
+ ```bash
67
+ TASK_JSON=$(~/.claude/scripts/task-queue.sh claim "<workspace-name>")
68
+ TASK=$(echo "$TASK_JSON" | jq -r '.task')
69
+ CONTEXT=$(echo "$TASK_JSON" | jq -r '.context')
70
+ TASK_ID=$(echo "$TASK_JSON" | jq -r '.id')
71
+ ```
72
+ Then send the task to the workspace:
73
+ ```bash
74
+ cmux send --workspace "<workspace-id>" "/start-work --context=\"$CONTEXT\" $TASK"
75
+ ```
76
+ 4. **Track re-queue counts:** If a task has been re-queued 3+ times (check `requeue_count`), do NOT dispatch it again. Instead:
77
+ ```bash
78
+ ~/.claude/scripts/task-queue.sh fail "$TASK_ID" "Max re-queues reached, needs human review"
79
+ cmux notify "ESCALATE: Task $TASK_ID failed after 3 attempts"
80
+ ```
81
+ 5. Clear processed inbox messages
82
+ 6. Log status to telemetry
83
+
84
+ #### If a workspace seems stuck
85
+ 1. Check if it's waiting on something (Inngest job, API call, build)
86
+ 2. If idle for 3+ checks with no progress, send a nudge
87
+ 3. If nudge doesn't help after 2 more checks, restart the session
88
+
89
+ ### 4. Status report
90
+ Every 30 minutes (or 6 checks), output a summary including the task queue:
91
+ ```
92
+ MONITOR STATUS:
93
+ - ws:8 (CDD Marathon): Working, 3 commits since last report
94
+ - ws:11 (Import Fix): Completed, dispatched next task
95
+ - Inbox: 2 messages processed
96
+ - Task queue: 3 pending, 1 in_progress, 2 completed, 0 failed
97
+ ```
98
+ Check the queue:
99
+ ```bash
100
+ ~/.claude/scripts/task-queue.sh list
101
+ ```
102
+
103
+ ## Stopping
104
+ To stop monitoring:
105
+ ```
106
+ CronDelete <job-id>
107
+ ```
108
+ Or invoke `/monitor stop` which deletes all monitoring crons.
109
+
110
+ ## Key principle
111
+ **Don't just observe — act.** If a workspace finishes and there's queued work, dispatch it immediately. If a workspace is stuck, nudge it. The coordinator shouldn't have to manually check — that's your job.
@@ -0,0 +1,55 @@
1
+ ---
2
+ description: |
3
+ Record an agent-browser session as MP4 video. Start recording, perform actions, stop to encode.
4
+ Videos can be uploaded to telemetry as artifacts.
5
+ allowed-tools: Bash, mcp__telemetry__log_artifact
6
+ ---
7
+
8
+ # /record — Record Agent Browser Session
9
+
10
+ Records agent-browser screenshots at regular intervals and encodes them into an MP4 video.
11
+
12
+ ## Usage
13
+
14
+ - `/record` or `/record start` — Start recording (1 frame/sec)
15
+ - `/record start 500` — Start recording at 2 fps (500ms interval)
16
+ - `/record stop` — Stop and encode to MP4
17
+ - `/record stop --upload` — Stop, encode, and upload to telemetry
18
+ - `/record status` — Check recording status
19
+
20
+ ## On Invoke
21
+
22
+ Parse the argument. Default action is "start".
23
+
24
+ ### Start
25
+ ```bash
26
+ ~/.claude/scripts/record-browser.sh start "/tmp/browser-recording-$(date +%Y%m%d-%H%M%S).mp4" ${INTERVAL:-1000}
27
+ ```
28
+ Then tell the user: "Recording started. Perform your actions, then run `/record stop` when done."
29
+
30
+ ### Stop
31
+ ```bash
32
+ ~/.claude/scripts/record-browser.sh stop
33
+ ```
34
+ The script outputs the path to the MP4 file.
35
+
36
+ If `--upload` flag is present and a telemetry session is active, upload as artifact:
37
+ ```
38
+ mcp__telemetry__log_artifact({
39
+ session_id: current_session_id,
40
+ file_path: "/tmp/browser-recording-*.mp4",
41
+ artifact_type: "recording",
42
+ description: "Agent browser session recording"
43
+ })
44
+ ```
45
+
46
+ ### Status
47
+ ```bash
48
+ ~/.claude/scripts/record-browser.sh status
49
+ ```
50
+
51
+ ## Tips
52
+ - Start recording BEFORE navigating to the page you want to capture
53
+ - Higher fps (lower interval) = smoother video but larger file
54
+ - Default 1fps is good for demos, use 500ms for smoother action
55
+ - Videos are saved to /tmp/ by default — upload to telemetry for persistence
@@ -0,0 +1,144 @@
1
+ ---
2
+ description: |
3
+ Spawn a watcher process that monitors the current workspace and auto-sends a resume command after /clear.
4
+ Keeps coordinator sessions alive across context clears by auto-restarting them.
5
+ allowed-tools: Bash, Read, Write, Edit, AskUserQuestion
6
+ ---
7
+
8
+ # Revive — Auto-Resume After /clear
9
+
10
+ Spawn a background watcher that monitors this workspace and automatically sends a resume command when Claude becomes idle (after /clear or session restart).
11
+
12
+ ## Usage
13
+
14
+ ```
15
+ /revive # Start watcher with defaults (/coordinate)
16
+ /revive /start-work --resume # Resume a start-work session instead
17
+ /revive --stop # Stop the watcher
18
+ /revive --status # Check if watcher is running
19
+ ```
20
+
21
+ ## Instructions
22
+
23
+ Parse the user's arguments from `$ARGUMENTS`:
24
+ - If empty or no special flags → start the watcher with default command `/coordinate`
25
+ - If `--stop` → stop the running watcher
26
+ - If `--status` → report watcher status
27
+ - Otherwise → use the argument as the resume command
28
+
29
+ ### Starting the Watcher
30
+
31
+ 1. **Check if a watcher is already running:**
32
+ ```bash
33
+ if [ -f ~/.claude/revive-watcher.pid ]; then
34
+ PID=$(cat ~/.claude/revive-watcher.pid)
35
+ if kill -0 "$PID" 2>/dev/null; then
36
+ echo "Watcher already running (PID $PID). Stop it first with /revive --stop"
37
+ # Ask user if they want to restart
38
+ fi
39
+ fi
40
+ ```
41
+
42
+ 2. **Detect the current workspace and surface:**
43
+ The watcher needs to know which cmux workspace and surface to monitor. Use `cmux list-workspaces` and identify the current one.
44
+
45
+ ```bash
46
+ # List workspaces to find the right one
47
+ cmux list-workspaces
48
+ ```
49
+
50
+ Then identify the Claude surface within that workspace:
51
+ ```bash
52
+ # Try reading common surfaces to find the Claude prompt
53
+ for s in surface:5 surface:3 surface:1; do
54
+ SCREEN=$(cmux read-screen --workspace <workspace_id> --surface "$s" --lines 3 2>/dev/null)
55
+ if echo "$SCREEN" | grep -qE "claude|bypass|❯"; then
56
+ echo "Found Claude on $s"
57
+ break
58
+ fi
59
+ done
60
+ ```
61
+
62
+ 3. **Start the watcher in the background:**
63
+ ```bash
64
+ RESUME_CMD="${ARGUMENTS:-/coordinate}"
65
+ # Strip --stop/--status flags if present
66
+ if [[ "$RESUME_CMD" == "--stop" ]] || [[ "$RESUME_CMD" == "--status" ]]; then
67
+ # Handle these cases separately (see below)
68
+ :
69
+ else
70
+ nohup ~/.claude/scripts/revive-watcher.sh \
71
+ --workspace "$WORKSPACE" \
72
+ --surface "$SURFACE" \
73
+ --command "$RESUME_CMD" \
74
+ > ~/.claude/revive-watcher.log 2>&1 &
75
+
76
+ echo "Revive watcher started (PID $!)"
77
+ echo " Monitoring: $WORKSPACE $SURFACE"
78
+ echo " Resume command: $RESUME_CMD"
79
+ echo " Log: ~/.claude/revive-watcher.log"
80
+ echo ""
81
+ echo "When you /clear, the watcher will detect the idle prompt and"
82
+ echo "automatically send '$RESUME_CMD' to restart the session."
83
+ echo ""
84
+ echo "To stop: /revive --stop"
85
+ fi
86
+ ```
87
+
88
+ ### Stopping the Watcher
89
+
90
+ ```bash
91
+ if [ -f ~/.claude/revive-watcher.pid ]; then
92
+ PID=$(cat ~/.claude/revive-watcher.pid)
93
+ if kill -0 "$PID" 2>/dev/null; then
94
+ kill "$PID"
95
+ echo "Watcher stopped (PID $PID)."
96
+ else
97
+ echo "Watcher was not running (stale PID file)."
98
+ rm -f ~/.claude/revive-watcher.pid
99
+ fi
100
+ else
101
+ echo "No watcher running."
102
+ fi
103
+ ```
104
+
105
+ ### Checking Status
106
+
107
+ ```bash
108
+ if [ -f ~/.claude/revive-watcher.pid ]; then
109
+ PID=$(cat ~/.claude/revive-watcher.pid)
110
+ if kill -0 "$PID" 2>/dev/null; then
111
+ echo "Watcher is running (PID $PID)"
112
+ echo "Last 5 log lines:"
113
+ tail -5 ~/.claude/revive-watcher.log 2>/dev/null || echo "(no log yet)"
114
+ else
115
+ echo "Watcher is NOT running (stale PID file)."
116
+ rm -f ~/.claude/revive-watcher.pid
117
+ fi
118
+ else
119
+ echo "No watcher configured."
120
+ fi
121
+ ```
122
+
123
+ ## How It Works
124
+
125
+ The watcher polls the workspace screen every 10 seconds. It detects idle state by checking:
126
+ - The prompt marker (`❯`) is visible
127
+ - "esc to interrupt" is NOT visible (meaning Claude isn't actively working)
128
+ - "bypass permissions" or "What can I help" text appears (indicating a fresh prompt)
129
+
130
+ When idle is detected, it sends the resume command and enters a 60-second cooldown to avoid double-sending.
131
+
132
+ ## Configuration
133
+
134
+ The watcher script (`~/.claude/scripts/revive-watcher.sh`) accepts these options:
135
+ - `--workspace <id>` — Which cmux workspace to monitor
136
+ - `--surface <id>` — Which surface within the workspace (default: auto-detect)
137
+ - `--command <cmd>` — What to send on resume (default: `/coordinate`)
138
+ - `--interval <secs>` — Poll frequency (default: 10)
139
+ - `--once` — Send once and exit (for one-shot revival)
140
+ - `--quiet` — Suppress log output
141
+
142
+ ## Implementation
143
+
144
+ Execute the above steps based on the parsed arguments. Present the result to the user clearly.
@@ -0,0 +1,49 @@
1
+ ---
2
+ description: |
3
+ Send a message to the coordinator workspace from a separate terminal. Sets up a simple input loop that routes your messages to the active coordinator.
4
+ allowed-tools: Bash
5
+ ---
6
+
7
+ # /speak — Talk to the Coordinator
8
+
9
+ Sets up a message relay from this terminal to the coordinator workspace. Your messages get sent directly to the coordinator's Claude session.
10
+
11
+ ## On Invoke
12
+
13
+ 1. Find the coordinator target (saved by /coordinate on startup):
14
+ ```bash
15
+ cat ~/.claude/coordinator-target 2>/dev/null
16
+ ```
17
+
18
+ 2. If no target file exists, discover it:
19
+ ```bash
20
+ # List workspaces and find the one named "Main Conversation" or the coordinator
21
+ cmux list-workspaces
22
+ # Ask the user which workspace is the coordinator
23
+ ```
24
+
25
+ 3. Start the relay loop:
26
+ ```bash
27
+ echo "Connected to coordinator. Type messages below. Ctrl+C to exit."
28
+ echo "---"
29
+ while IFS= read -r -p "> " msg; do
30
+ if [ -z "$msg" ]; then continue; fi
31
+ target=$(cat ~/.claude/coordinator-target 2>/dev/null)
32
+ if [ -z "$target" ]; then
33
+ echo "No coordinator target found. Run /coordinate first."
34
+ continue
35
+ fi
36
+ tw=${target% *}
37
+ ts=${target#* }
38
+ cmux send --workspace $tw --surface $ts "$msg" 2>/dev/null
39
+ cmux send-key --workspace $tw --surface $ts Enter 2>/dev/null
40
+ echo " → sent"
41
+ done
42
+ ```
43
+
44
+ ## If coordinator-target doesn't exist
45
+
46
+ Guide the user:
47
+ 1. The coordinator needs to run `/coordinate` first, which writes `~/.claude/coordinator-target`
48
+ 2. Or manually set it: `echo "workspace:1 surface:5" > ~/.claude/coordinator-target`
49
+ 3. Find the right values with: `cmux list-workspaces` then `cmux list-pane-surfaces --workspace <id>`