openclaw-code-agent 3.0.0 → 3.1.0

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.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: Code Agent Orchestration
3
- description: Skill for orchestrating coding agent sessions from OpenClaw. Covers launching, monitoring, multi-turn interaction, lifecycle management, notifications, and parallel work patterns.
3
+ description: Skill for orchestrating coding agent sessions from OpenClaw. Covers launching, monitoring, multi-turn interaction, lifecycle management, notifications, and worktree decision rules.
4
4
  metadata:
5
5
  openclaw:
6
6
  homepage: https://github.com/goldmar/openclaw-code-agent
@@ -15,515 +15,226 @@ metadata:
15
15
 
16
16
  # Code Agent Orchestration
17
17
 
18
- You orchestrate coding agent sessions via the `openclaw-code-agent`. Each session is an autonomous agent that executes code tasks in the background.
18
+ Use `openclaw-code-agent` to run Claude Code or Codex sessions as background coding jobs from chat.
19
19
 
20
- ---
21
-
22
- ## 1. Launching sessions
23
-
24
- ### Mandatory rules
25
-
26
- - **Notifications are routed automatically** via `agentChannels` config. Do NOT pass `channel` manually — it bypasses automatic routing.
27
- - **Thread-aware routing**: When launched from a Telegram thread/topic, notifications are routed back to that same thread via `originThreadId`. This is handled automatically.
28
- - **Always pass `multi_turn: true`** unless the task is a guaranteed one-shot with no possible follow-up.
29
- - **Name the sessions** with `name` in kebab-case, short and descriptive.
30
- - **Set `workdir`** to the target project directory, not the agent's workspace.
31
- - **Default mode is `plan`**: Sessions start in plan mode. When the user approves a plan (e.g. "looks good", "go ahead"), the plugin automatically switches to `bypassPermissions` mode.
32
-
33
- ### Essential parameters
34
-
35
- | Parameter | When to use |
36
- |---|---|
37
- | `prompt` | Always. Clear and complete instruction. |
38
- | `name` | Always. Descriptive kebab-case (`fix-auth-bug`, `add-dark-mode`). |
39
- | `channel` | **Do NOT pass.** Resolved automatically via `agentChannels`. |
40
- | `workdir` | Always when the project is not in the `defaultWorkdir`. |
41
- | `multi_turn` | `true` by default unless explicitly one-shot. |
42
- | `model` | When you want to force a specific model (`"sonnet"`, `"opus"`, `"gpt-5.4"`). Subject to `harnesses.<name>.allowedModels` restrictions if configured. |
43
- | `system_prompt` | To inject project-specific context. |
44
- | `permission_mode` | `"plan"` by default. `"bypassPermissions"` for trusted tasks. |
45
-
46
- ### Harness-scoped model restrictions
47
-
48
- The plugin config restricts models per harness via `harnesses.<name>.allowedModels`:
49
-
50
- - **Matching:** Case-insensitive substring matching (e.g., `"sonnet"` matches `"claude-sonnet-4-6"`)
51
- - **Explicit model blocked:** If a caller explicitly requests a model not in that harness's `allowedModels`, the launch fails with an error
52
- - **Default model blocked:** If no model is specified and the resolved `harnesses.<name>.defaultModel` is not in `allowedModels`, the launch fails with a config error
53
- - **Not configured:** If `allowedModels` is empty or undefined for that harness, all models are allowed for that harness
54
-
55
- **Example configuration:**
56
- ```json
57
- {
58
- "harnesses": {
59
- "claude-code": {
60
- "defaultModel": "sonnet",
61
- "allowedModels": ["sonnet", "haiku"]
62
- },
63
- "codex": {
64
- "defaultModel": "gpt-5.4",
65
- "allowedModels": ["gpt-5.4"]
66
- }
67
- }
68
- }
69
- ```
70
-
71
- This configuration allows Claude models containing "sonnet" or "haiku" in their identifier, and restricts Codex launches to `gpt-5.4`.
20
+ ## 1. Launch Rules
72
21
 
73
- **Interaction with harness compatibility:**
74
- When both `harnesses.<name>.allowedModels` and harness compatibility constraints apply, you must satisfy BOTH:
75
- 1. The model must be in `harnesses.<name>.allowedModels` (if configured)
76
- 2. The model must be compatible with the chosen harness
22
+ - Do not pass `channel` manually. Routing comes from `agentChannels`, the current chat context, and `fallbackChannel`.
23
+ - Sessions are multi-turn. All sessions stay open for follow-up messages via `agent_respond`.
24
+ - Always set a short kebab-case `name` when you care about later follow-up.
25
+ - Set `workdir` to the target repo, not to the agent's own workspace.
26
+ - Default behavior is `permission_mode: "plan"` plus `planApproval: "ask"` plus `defaultWorktreeStrategy: "off"`.
27
+ - Use `permission_mode: "plan"` whenever the user wants a real planning checkpoint, reviewable plan, or approval buttons before implementation.
28
+ - Use `permission_mode: "bypassPermissions"` only when the user wants autonomous execution. Do not try to recreate plan mode by stuffing "plan only" into the prompt unless you intentionally want a soft fallback rather than the primary UX contract.
29
+ - In `plan` mode, the plan should be emitted directly in normal session output so the user can review it in chat. Do not tell the coding agent to write a plan document or markdown file unless the user explicitly asked for a file.
77
30
 
78
- Example: If `harnesses.claude-code.allowedModels = ["sonnet", "gpt-4"]` and you use the default `claude-code` harness, only "sonnet" will work because "gpt-4" is not a Claude-compatible model.
79
-
80
- ### Examples
81
-
82
- ```
83
- # Simple task
84
- agent_launch(
85
- prompt: "Fix the null pointer in src/auth.ts line 42",
86
- name: "fix-null-auth",
87
- workdir: "/home/user/projects/myapp",
88
- multi_turn: true
89
- )
31
+ Example:
90
32
 
91
- # Full feature
33
+ ```text
92
34
  agent_launch(
93
- prompt: "Implement dark mode toggle in the settings page. Use the existing theme context in src/context/theme.tsx. Add a toggle switch component and persist the preference in localStorage.",
94
- name: "add-dark-mode",
95
- workdir: "/home/user/projects/myapp",
96
- multi_turn: true
35
+ prompt: "Fix the auth middleware bug and add tests",
36
+ name: "fix-auth",
37
+ workdir: "/home/user/projects/my-app"
97
38
  )
98
39
  ```
99
40
 
100
- ### Resume and fork
41
+ Resume and fork:
101
42
 
102
- ```
103
- # Resume a completed session
43
+ ```text
104
44
  agent_launch(
105
- prompt: "Continue. Also add error handling for the edge cases we discussed.",
106
- resume_session_id: "fix-null-auth",
107
- multi_turn: true
45
+ prompt: "Continue where you left off",
46
+ resume_session_id: "fix-auth"
108
47
  )
109
48
 
110
- # Fork to try an alternative approach
111
49
  agent_launch(
112
- prompt: "Try a completely different approach: use middleware instead of decorators.",
113
- resume_session_id: "refactor-db-repositories",
50
+ prompt: "Try a different approach",
51
+ resume_session_id: "fix-auth",
114
52
  fork_session: true,
115
- name: "refactor-db-middleware-approach",
116
- multi_turn: true
53
+ name: "fix-auth-alt"
117
54
  )
118
55
  ```
119
56
 
120
- ### Harness and model compatibility
57
+ ## 2. Anti-Cascade Rule
121
58
 
122
- | Harness | Supported Models | Examples |
123
- |---------|-----------------|---------|
124
- | `claude-code` | Anthropic only | `sonnet`, `opus`, `haiku`, `claude-sonnet-4-6` |
125
- | `codex` | OpenAI only | `gpt-4`, `gpt-5`, `o1`, `o3-mini` |
59
+ When you are woken because a session is waiting or completed, do not launch a new coding session in response. Only use the existing session with:
126
60
 
127
- - When user says "with sonnet/opus/haiku" → use `harness: "claude-code"` (or omit — it's the default)
128
- - When user says "with gpt-4/o1/o3" → use `harness: "codex"`
129
- - **Never** pass Anthropic models to codex harness or OpenAI models to claude-code harness
61
+ - `agent_output`
62
+ - `agent_respond`
63
+ - `agent_merge`
64
+ - `agent_pr`
65
+ - `agent_worktree_status`
130
66
 
131
- If `harnesses.<name>.allowedModels` is configured, both explicit model requests and default models outside that list are rejected with an error. When the default model is not allowed, the error message directs you to update the plugin config.
67
+ ## 2a. Resume vs. Spawn Rule (CRITICAL)
132
68
 
133
- ---
69
+ **Always resume — never spawn fresh — when a session already exists for the task.**
134
70
 
135
- ## 2. Anti-cascade rules (CRITICAL)
71
+ | Situation | Correct action |
72
+ |-----------|---------------|
73
+ | Session waiting for plan approval | `agent_respond(session, message, approve=true)` |
74
+ | Session waiting for a question answer | `agent_respond(session, message)` |
75
+ | Session killed/stopped by restart | `agent_respond(session, message)` — killed sessions auto-resume on next `agent_respond` |
76
+ | Session completed, user wants to extend/revise | `agent_launch(resume_session_id=session_id)` |
77
+ | Worktree has uncommitted work after a crash | `agent_respond` on the stopped session first; only if truly unrecoverable, relaunch with the worktree still in place |
136
78
 
137
- **When woken by a waiting-for-input or completion event, you MUST ONLY use `agent_respond` or `agent_output` for the referenced session. NEVER launch new sessions in response to wake events.**
79
+ **Never use `agent_launch` to start a fresh session when `agent_respond` would work.** Spawning fresh loses conversation history, may duplicate worktrees, and confuses the user.
138
80
 
139
- This prevents cascading session creation. The orchestrator exists to manage existing sessions, not to spawn new ones from wake events.
81
+ Only spawn a genuinely new session for work that is **completely independent** of any existing session.
140
82
 
141
- ---
142
-
143
- ## 3. Monitoring sessions
83
+ ## 3. Monitoring
144
84
 
145
- ### List sessions
85
+ Use:
146
86
 
147
- ```
148
- # All sessions
87
+ ```text
149
88
  agent_sessions()
150
-
151
- # Only running sessions
152
89
  agent_sessions(status: "running")
153
-
154
- # Completed sessions (for resume)
155
- agent_sessions(status: "completed")
156
- ```
157
-
158
- ### View output
159
-
160
- ```
161
- # Summary (last 50 lines)
162
- agent_output(session: "fix-null-auth")
163
-
164
- # Full output (up to 2000 lines)
165
- agent_output(session: "fix-null-auth", full: true)
166
-
167
- # Specific last N lines
168
- agent_output(session: "fix-null-auth", lines: 100)
169
- ```
170
-
171
- ### Interpreting session state
172
-
173
- The `agent_output` header shows status, phase, cost, and duration:
174
- ```
175
- Session: fix-auth [abc123] | Status: RUNNING | Phase: planning | Cost: $0.0312 | Duration: 2m15s
176
- ```
177
-
178
- The `Phase:` indicator for running sessions:
179
- - `Phase: planning` — the agent is writing a plan
180
- - `Phase: awaiting-plan-approval` — plan submitted, waiting for review
181
- - `Phase: implementing` — actively writing code
182
-
183
- The `agent_sessions` listing also shows phase and cost when available:
184
- ```
185
- 🟢 fix-auth [abc123] (2m15s | $0.03) — multi-turn
186
- ⚙️ Phase: planning
187
- ```
188
-
189
- **Recency rule:** Always trust the Phase indicator and the *latest* (bottom) output lines. If earlier output mentions plan mode but Phase says `implementing`, the session has transitioned. Do NOT report it as "waiting for approval."
190
-
191
- ---
192
-
193
- ## 4. Multi-turn interaction
194
-
195
- ### Send a follow-up
196
-
197
- ```
198
- # Reply to an agent question
199
- agent_respond(session: "add-dark-mode", message: "Yes, use CSS variables for the theme colors.")
200
-
201
- # Redirect a running session (interrupts the current turn)
202
- agent_respond(session: "add-dark-mode", message: "Stop. Use Tailwind dark: classes instead of CSS variables.", interrupt: true)
203
- ```
204
-
205
- ### Auto-respond rules (STRICT)
206
-
207
- **Auto-respond immediately with `agent_respond`:**
208
- - Permission requests to read/write files or run bash commands -> `"Yes, proceed."`
209
- - Explicit confirmations like "Should I continue?" -> `"Yes, continue."`
210
-
211
- **Forward to the user (everything else):**
212
- - Architecture decisions (Redis vs PostgreSQL, REST vs GraphQL...)
213
- - Destructive operations (deleting files, dropping tables...)
214
- - Ambiguous requirements not covered by the initial prompt
215
- - Scope changes ("This will require refactoring 15 files")
216
- - Anything involving credentials, secrets, or production environments
217
- - Questions about approach, design, or implementation choices
218
- - Codebase clarification questions
219
- - When in doubt -> always forward to the user
220
-
221
- **When forwarding to the user, quote the agent's exact question. Do NOT add your own analysis, interpretation, or commentary.**
222
-
223
- ### Interaction cycle
224
-
225
- 1. Session launches -> runs in background
226
- 2. Wake event arrives when the session is waiting for input
227
- 3. Read the question with `agent_output(session, full: true)`
228
- 4. Decide: auto-respond (permissions/confirmations only) or forward
229
- 5. If auto-respond: `agent_respond(session, answer)`
230
- 6. If forward: relay the agent's exact question to the user, wait for their response, then `agent_respond`
231
-
232
- ---
233
-
234
- ## 5. Lifecycle management
235
-
236
- ### Stop or complete a session
237
-
238
- ```
239
- # Kill a stuck/looping session
240
- agent_kill(session: "fix-null-auth")
241
-
242
- # Mark a session as successfully completed
243
- agent_kill(session: "fix-null-auth", reason: "completed")
244
- ```
245
-
246
- Use `agent_kill` (no reason) when:
247
- - The session is stuck or looping
248
- - The user requests a stop
249
-
250
- Use `agent_kill(reason: "completed")` when:
251
- - The turn output shows the task is done — this sends a `✅ Completed` notification
252
- - Prefer this over letting the idle timer expire
253
-
254
- ### Idle completion and auto-resume
255
-
256
- - After a turn completes without a question, the session is immediately **paused** (killed with reason `done`, auto-resumable).
257
- - On the next `agent_respond` to a completed or idle-killed session, the plugin **auto-resumes** by spawning a new session with the same session ID — conversation context is preserved.
258
- - Sessions idle for `idleTimeoutMinutes` (default: 15 min) are killed with reason `idle-timeout` and also auto-resume on next respond.
259
- - Sessions killed for any reason except `startup-timeout` auto-resume on next `agent_respond`. This includes user-killed sessions (`agent_kill`), shutdown-killed sessions (gateway restart), and idle-timeout sessions.
260
-
261
- ### Timeouts
262
-
263
- - Idle multi-turn sessions are automatically killed after `idleTimeoutMinutes` (default: 15 min)
264
- - Completed sessions are garbage-collected after 1h but remain resumable via persisted IDs
265
-
266
- ### Check the result after completion
267
-
268
- When a session completes (completion wake event):
269
-
270
- 1. `agent_output(session: "xxx", full: true)` to read the result
271
- 2. Summarize briefly: files changed, cost, duration, any issues
272
- 3. If failed, analyze the error and decide: relaunch, fork, or escalate
273
-
274
- ---
275
-
276
- ## 6. Notifications
277
-
278
- ### Thread-based routing
279
-
280
- Notifications are routed to the Telegram thread/topic where the session was launched. This is handled automatically via `originThreadId` — no manual configuration needed. The `agentChannels` config handles chat-level routing, and the thread ID handles within-chat routing.
281
-
282
- ### Events
283
-
284
- | Event | What happens |
285
- |---|---|
286
- | Session starts | Silent (command response confirms launch) |
287
- | Session completed | `✅ Completed` — brief one-liner to originating thread |
288
- | Session completed (deliverable mode) | `📄 Deliverable ready` — when launched with `output_mode: "deliverable"` |
289
- | Session failed | `❌ Failed` — error notification with `harnessSessionId` and resume guidance |
290
- | Waiting for input | `❓ Waiting for input` — wake event (only when the agent actually asks a question) |
291
- | Turn completes without a question | `⏸️ Paused after turn \| Auto-resumable` |
292
- | `agent_respond` send | `↪️` — notification sent for every `agent_respond` call |
293
- | `agent_respond` plan approval | `👍` — notification sent when `approve: true` |
294
- | Session auto-resumes | `▶️ Auto-resumed` |
295
- | Session idle-times out | `💤 Idle timeout` |
296
- | Session is forcibly stopped | `⛔ Stopped ...` with the specific stop reason |
297
- | Worktree decision pending (`ask`) | Inline Telegram buttons sent to user (Merge locally / Create PR) — Alice must NOT preempt |
298
- | Worktree decision pending (`delegate`) | Wake sent to Alice with diff context — Alice must decide and call `agent_merge` or `agent_pr` |
299
-
300
- ### Sending completion summaries — use `message send`, not inline reply
301
-
302
- When you process a CC session completion wake and want to notify the user with a summary, **always send the summary via the `message` tool** rather than as an inline session reply:
303
-
304
- ```bash
305
- # Correct — standalone message, guaranteed notification ping
306
- openclaw message send --channel telegram --target <chatId> --thread-id <topicId> \
307
- --message "✅ [session-name] Done — <one-line summary>"
90
+ agent_output(session: "fix-auth", lines: 100)
91
+ agent_output(session: "fix-auth", full: true)
308
92
  ```
309
93
 
310
- **Why this matters**: Alice's inline session replies are sent as Telegram *replies* (`reply_to_message_id`) to the message that triggered the wake. Because the plugin's ⏸️ status notification typically arrives just before the wake fires, Alice's reply targets that bot message — and Telegram does not re-ping the user when a bot replies to a recent bot message in an already-active topic thread. The `message` tool sends a standalone new message (`message_thread_id` only, no `reply_to_message_id`), which always generates a fresh notification ping.
94
+ Trust the latest output and current phase. Do not report an old planning state after the session has already moved into implementation.
95
+ Treat these wake fields as authoritative session state, not hints:
311
96
 
312
- **Rule**: Inline replies are fine for conversational back-and-forth. For any user-facing "session done" notification that must reliably reach the user, use `message send` explicitly.
97
+ - `requestedPermissionMode`
98
+ - `effectivePermissionMode` / current permission mode (`currentPermissionMode` in plugin payloads)
99
+ - `approvalExecutionState`
313
100
 
314
- The Telegram chat ID and topic thread ID are available from the current conversation context.
101
+ Do not reinterpret approval behavior from transcript fragments when these fields are present.
315
102
 
316
- ### Worktree `ask` strategy — no duplicate summary
103
+ Completion and approval state handling:
317
104
 
318
- When a session completes with `worktree_strategy: "ask"`, the plugin sends the user a single consolidated Telegram message that contains:
319
- - The full commit list and diff stats
320
- - The ⬇️ Merge locally / 🔀 Create PR inline buttons
105
+ - `approved_then_implemented` means normal approved execution. Do not frame it as rogue, surprising, or a bypass.
106
+ - `implemented_without_required_approval` means the session left a required approval gate. Treat that as the actual approval-bypass case.
107
+ - `awaiting_approval` means the session is still waiting at the gate. Do not describe implementation as started.
108
+ - If the plugin wake says it already sent the canonical approval or completion message, do not send a duplicate plain-text recap unless you are adding real synthesis, a risk callout, or concrete next-step guidance.
321
109
 
322
- **Do NOT send a separate completion summary.** The button message IS the completion signal. Sending an additional "✅ Done!" or "Here's what was done:" message creates duplicates and confuses the user.
110
+ ## 4. Respond Rules
323
111
 
324
- This applies when the wake message says "Worktree strategy buttons delivered to user." — treat that as confirmation that the user is already fully informed. Take no further action until the user clicks a button.
112
+ Auto-respond immediately only for:
325
113
 
326
- **Buttons are handled automatically by the plugin.** When the user taps a button, the plugin's callback router dispatches the action (`agent_merge` or `agent_pr`) directly — no agent `agent_merge`/`agent_pr` call is needed in response to a button tap. If the action succeeds, the plugin sends a result notification. If the action fails, a failure notification is sent. Alice does not need to poll or intervene.
114
+ - permission requests for file reads, writes, or shell commands
115
+ - explicit continuation prompts such as "Should I continue?"
327
116
 
328
- ---
117
+ Forward everything else to the user:
329
118
 
330
- ### Plan Execute mode switch
119
+ - architecture or design choices
120
+ - destructive operations
121
+ - scope changes
122
+ - credentials or production questions
123
+ - ambiguous requirements
124
+ - anything you are not certain you should answer autonomously
331
125
 
332
- Sessions start in `plan` mode by default. When you reply with **only** an approval keyword as the **entire message** (`"go ahead"`, `"implement"`, `"looks good"`, `"approved"`, `"lgtm"`, `"do it"`, `"proceed"`, `"execute"`, `"ship it"`), the plugin switches the session to `bypassPermissions` mode. The message must contain **only** the keyword — extra text will prevent the switch. To approve and also give instructions, send the approval keyword first, then send implementation details as a separate follow-up message.
126
+ When forwarding, quote the session's exact question. Do not add your own commentary.
333
127
 
334
- ### Permission escalation with `approve: true`
128
+ Examples:
335
129
 
336
- The `approve` parameter on `agent_respond` escalates session permissions to `bypassPermissions`. It works in two scenarios:
130
+ ```text
131
+ agent_respond(session: "fix-auth", message: "Yes, proceed.")
337
132
 
338
- 1. **Plan mode approval**: When a session has a pending plan approval (after `ExitPlanMode` / `set_permission_mode`), `approve: true` approves the plan and switches to `bypassPermissions`. Sends a 👍 notification.
339
- 2. **`default` mode escalation**: When a session in `default` mode keeps prompting for shell/exec command permissions, `approve: true` escalates to `bypassPermissions` to skip all remaining prompts.
340
-
341
- If the session is already in `bypassPermissions` mode, `approve: true` is a no-op. In `plan` mode without a pending plan, it is ignored.
342
-
343
- ```
344
- # Escalate a session that keeps prompting for bash permissions
345
- agent_respond(session: "fix-auth", message: "proceed", approve: true)
133
+ agent_respond(
134
+ session: "fix-auth",
135
+ message: "Stop. Do not touch the database schema.",
136
+ interrupt: true
137
+ )
346
138
  ```
347
139
 
348
- ### Plan approval modes
349
-
350
- The `planApproval` config controls how the orchestrator handles plan-approval events:
351
-
352
- - **`ask`** (default): The orchestrator always forwards plans to the user. It never auto-approves on the user's behalf.
353
- - **`delegate`**: The orchestrator autonomously decides whether to approve or escalate each plan to the user. Approve when the plan is low-risk, well-scoped, and matches the original task. Escalate when the plan involves destructive operations, credentials/production, architectural decisions, scope expansion, or ambiguous requirements. When in doubt, always escalate.
354
- - **`approve`**: The orchestrator can auto-approve straightforward, low-risk plans. Before approving, it verifies the working directory, codebase, and scope.
355
-
356
- #### Delegate mode decision criteria
357
-
358
- When operating in `delegate` mode, **approve** the plan directly if ALL of the following are true:
359
- - The plan scope matches the original task request
360
- - The changes are low-risk (no destructive operations, no credential handling, no production deployments)
361
- - The plan is clear and well-scoped (no ambiguous requirements or open design questions)
362
- - No architectural decisions that the user should weigh in on
363
- - The working directory and codebase are correct
364
-
365
- **Escalate** to the user (forward with 👋 and wait) if ANY of the following are true:
366
- - Destructive operations (deleting files, dropping tables, force-pushing)
367
- - Credentials, secrets, or production environments
368
- - Architectural decisions not covered by the original task
369
- - Scope expanded beyond the original request
370
- - Ambiguous requirements or assumptions the user should confirm
371
- - When in doubt — always escalate
372
-
373
- ---
374
-
375
- ## 7. Worktree workflow
140
+ ## 5. Plan Approval
376
141
 
377
- When a session uses `worktree_strategy`, the agent runs in an isolated git branch. After completion, the branch needs to be merged or published as a PR.
142
+ Mode selection:
378
143
 
379
- ### Strategies at a glance
144
+ - `permission_mode: "plan"` is the primary contract for planning sessions. It produces a plan-review stop and is the only mode you should rely on for explicit approval UX.
145
+ - `permission_mode: "bypassPermissions"` is for autonomous execution. Do not try to recreate plan mode by stuffing "plan only", "do not implement yet", or similar text into the prompt.
146
+ - If the user says "investigate first", "show me the plan", "plan only", or "wait for approval before coding", launch in `plan` mode.
147
+ - If the user says "just do it", "run autonomously", or wants uninterrupted execution, use `bypassPermissions`.
148
+ - In `plan` mode, the plan belongs in the agent's normal output stream. Do not ask the coding agent to write `PLAN.md`, investigation notes, or similar artifacts unless the user explicitly requested a file deliverable.
380
149
 
381
- | Strategy | What it does | When to use |
382
- |---|---|---|
383
- | `off` | No worktree. Session runs in main checkout | Simple/trusted tasks where isolation isn't needed |
384
- | `ask` (default) | Push branch and send inline buttons (Merge locally / Create PR); wake orchestrator with full decision context | User should decide — the interactive default |
385
- | `delegate` | Push branch and wake orchestrator to decide autonomously (merge, create PR, or leave for later) | Set via `defaultWorktreeStrategy` config — orchestrator decides autonomously |
386
- | `auto-merge` | Automatically merge back to base branch on completion; spawns conflict-resolver if needed | Trusted tasks on a safe branch |
387
- | `auto-pr` | Automatically open a GitHub PR on completion (requires `gh`) | Feature branches needing review |
388
- | `manual` | Push the branch; no further action — user handles merge/PR manually | You want to review diffs before merging |
150
+ Approve a pending plan with:
389
151
 
390
- ### Launch with worktree isolation
391
-
392
- ```
393
- agent_launch(
394
- prompt: "Implement the new user settings page",
395
- name: "user-settings",
396
- workdir: "/app",
397
- worktree_strategy: "auto-pr"
152
+ ```text
153
+ agent_respond(
154
+ session: "fix-auth",
155
+ message: "Approved. Go ahead.",
156
+ approve: true,
157
+ userInitiated: true
398
158
  )
399
159
  ```
400
160
 
401
- ### Post-completion behavior by strategy
402
-
403
- When a session with a worktree completes, your action depends on the strategy:
404
-
405
- | Strategy | What to do after completion |
406
- |---|---|
407
- | `ask` | **Do nothing.** The plugin sends inline Telegram buttons (Merge locally / Create PR) to the user. **Never** call `agent_merge`, `agent_pr`, or any `git` command — wait for the user to decide. |
408
- | `delegate` | You receive a `worktree-delegate` wake with diff context. Evaluate and act (see *Delegate mode* below). |
409
- | `auto-merge` | No action needed — merge happens automatically. Watch for `worktree-merge-success` or `worktree-merge-conflict` notification. |
410
- | `auto-pr` | No action needed — PR is created/updated automatically. |
411
- | `manual` | Call `agent_merge` or `agent_pr` **only** when the user explicitly asks. |
412
- | `off` | No worktree — nothing to merge. |
161
+ Rules:
413
162
 
414
- Note: the ⏸️ turn-complete wake is suppressed for both `ask` and `delegate` strategies the worktree decision notification replaces it as the completion signal.
163
+ - `approve: true` approves a pending plan or escalates a `default` mode session into `bypassPermissions`.
164
+ - Do not send approval and revision feedback in the same call.
165
+ - In `planApproval: "ask"`, the user is expected to approve or revise. Wait for that input.
166
+ - Telegram users may get inline `Approve`, `Reject`, and `Revise` buttons for plan review.
415
167
 
416
- ### Delegate mode: deciding merge vs PR
168
+ ## 6. Worktree Decision Rules
417
169
 
418
- When you receive a `worktree-delegate` wake:
170
+ ### `ask`
419
171
 
420
- 1. **Evaluate the diff** read the commit count, files changed, and diff summary included in the wake message
421
- 2. **Compare to original task scope** — does the diff match what was asked?
422
- 3. **Decide:**
423
- - **Call `agent_merge`** when: changes are low-risk, well-scoped, match the original task, and no code review is needed
424
- - **Call `agent_pr`** when: changes are non-trivial, touch many files, introduce significant complexity, or when uncertain
425
- - **Escalate to the user** when: changes are ambiguous, out of scope, or involve sensitive areas
426
- 4. **Notify the user briefly** — send a short message with your decision and one-sentence reasoning (e.g. "Merged `agent/feature-x` — straightforward 2-file change matching the original task.")
427
- 5. **Never use raw `git` commands** — always use `agent_merge` or `agent_pr`
172
+ Do nothing after completion. The plugin already informed the user and attached 4 buttons:
173
+ - **✅ Merge** — merge branch locally
174
+ - **📬 Open PR** — create a GitHub PR
175
+ - **⏭️ Decide later** snooze reminders for 24h
176
+ - **🗑️ Dismiss (deletes branch)** permanently delete branch and worktree (irreversible)
428
177
 
429
- ### Check worktree status
178
+ Do not call `agent_merge` or `agent_pr` unless the user explicitly asks after that.
430
179
 
431
- ```
432
- agent_worktree_status() # all sessions with worktrees
433
- agent_worktree_status(session: "user-settings") # specific session
434
- ```
180
+ ### `delegate`
435
181
 
436
- ### Manual merge or PR after `manual`/`ask`
182
+ Read the diff context from the wake, then decide:
437
183
 
438
- ```
439
- # Merge back to base branch
440
- agent_merge(session: "user-settings", strategy: "merge")
184
+ - `agent_merge` for low-risk, clearly scoped changes that match the task
185
+ - **NEVER call `agent_pr()` autonomously** — always escalate PR decisions to the user
186
+ - escalate to the user if scope or risk is unclear, or if a PR is the safer choice
187
+ - if the wake already says the plugin sent the canonical completion message, only add user-facing follow-up when you need synthesis, risk framing, or concrete next steps beyond that message
441
188
 
442
- # Or create/update a GitHub PR
443
- agent_pr(session: "user-settings", title: "Add user settings page")
444
- ```
189
+ ### `manual`
445
190
 
446
- ### Resume with worktree context
191
+ Wait for an explicit user request before calling `agent_merge` or `agent_pr`.
447
192
 
448
- When resuming a session that had a worktree, the worktree context (branch, strategy, PR URL) is inherited automatically — no need to pass `worktree_strategy` again:
193
+ ### Never
449
194
 
450
- ```
451
- agent_launch(
452
- prompt: "Continuealso add unit tests",
453
- resume_session_id: "user-settings"
454
- )
455
- ```
195
+ - never use raw `git merge` or raw PR commands in place of the plugin tools
196
+ - never clear a pending worktree decision by inventing your own workaround; use `agent_worktree_cleanup(session: "...", dismiss_session: true)` to permanently dismiss
197
+ - never call `agent_pr()` autonomously in `delegate` flows always escalate to the user for PR decisions
456
198
 
457
- ### Deliverable mode
199
+ ## 6b. Planning Document Policy
458
200
 
459
- For document/report generation tasks, use `output_mode: "deliverable"` to send 📄 instead of ✅:
201
+ - Do NOT ask the coding agent to write planning documents, investigation notes, or analysis artifacts as files unless the user explicitly requested a file
202
+ - Do NOT commit planning documents, investigation notes, or analysis artifacts to the branch
203
+ - Only commit actual code, configuration, tests, and documentation changes that were explicitly requested as part of the task
460
204
 
461
- ```
462
- agent_launch(
463
- prompt: "Write a technical spec for the new auth system",
464
- name: "auth-spec",
465
- output_mode: "deliverable"
466
- )
467
- ```
205
+ ## 6c. Resume vs New Session
468
206
 
469
- ---
207
+ - When resuming a session with an existing worktree, use `resume_session_id` with `agent_launch`
208
+ - Do not create a new session if the old worktree branch still has unmerged changes — resume instead
209
+ - If the user wants a fresh start, use `fork_session: true` to branch from the previous session state
470
210
 
471
- ## 8. Best practices
211
+ ## 7. Lifecycle Notes
472
212
 
473
- ### Launch checklist
213
+ - `agent_respond` auto-resumes paused, idle-killed, and most other terminal sessions.
214
+ - The only common non-resumable path is `startup-timeout`.
215
+ - Terminal runtime sessions are evicted after `sessionGcAgeMinutes` (default 1440 minutes), but persisted metadata remains resumable.
216
+ - `agent_stats` is the quick operator view for aggregate cost and duration.
474
217
 
475
- 1. `agentChannels` is configured for this workdir -> notifications arrive
476
- 2. `multi_turn: true` -> interaction is possible after launch
477
- 3. `name` is descriptive -> easy to identify in `agent_sessions`
478
- 4. `workdir` points to the correct project -> the agent works in the right directory
218
+ ## 8. Chat Commands
479
219
 
480
- ### Parallel tasks
220
+ Common command equivalents:
481
221
 
482
- ```
483
- # Launch multiple sessions on independent tasks
484
- agent_launch(prompt: "Build the frontend auth page", name: "frontend-auth", workdir: "/app/frontend", multi_turn: true)
485
- agent_launch(prompt: "Build the backend auth API", name: "backend-auth", workdir: "/app/backend", multi_turn: true)
222
+ ```text
223
+ /agent --name fix-auth Fix the auth middleware bug
224
+ /agent_sessions
225
+ /agent_output fix-auth
226
+ /agent_respond fix-auth Add tests too
227
+ /agent_kill fix-auth
228
+ /agent_resume --fork fix-auth Try a different approach
229
+ /agent_stats
486
230
  ```
487
231
 
488
- - Respect the `maxSessions` limit (default: 5)
489
- - Each session must have a unique `name`
490
- - Monitor each session individually via wake events
232
+ ## 9. Anti-Patterns
491
233
 
492
- ### Reporting results
493
-
494
- When a session completes, keep summaries brief:
495
- - Files changed
496
- - Cost and duration
497
- - Any issues or remaining TODOs
498
-
499
- ---
500
-
501
- ## 9. Anti-patterns
502
-
503
- | Anti-pattern | Consequence | Fix |
504
- |---|---|---|
505
- | Launching new sessions from wake events | Cascading sessions | Only use `agent_respond`/`agent_output` when woken |
506
- | Adding commentary when forwarding questions | User gets noise, not the question | Quote the agent's exact question, nothing else |
507
- | Auto-responding to design/architecture questions | Decisions made without user input | Only auto-respond to permissions and explicit confirmations |
508
- | Passing `channel` explicitly | Bypasses automatic routing | Let `agentChannels` handle routing automatically |
509
- | Not checking the result of a completed session | User doesn't know what happened | Always read `agent_output` and summarize briefly |
510
- | Launching too many sessions in parallel | `maxSessions` limit reached | Respect the limit, prioritize, sequence if necessary |
511
- | Calling `agent_merge` or `agent_pr` when strategy is `ask` | Bypasses the user's inline-button decision | Wait for the Telegram buttons — do nothing until the user decides |
512
- | Using raw `git merge` instead of `agent_merge` | Skips conflict resolution, cleanup, and session state tracking | Always use `agent_merge` when the user asks to merge a worktree branch |
513
-
514
- ---
234
+ - Do not pass a `multi_turn` or `multi_turn_disabled` parameter; all sessions are multi-turn and the parameter no longer exists.
235
+ - Do not pass `channel` manually unless you are debugging routing at a very low level.
236
+ - Do not auto-answer design or scope questions.
237
+ - Do not launch new sessions from wake events.
238
+ - Do not merge or PR an `ask` worktree behind the user's back.
515
239
 
516
- ## 10. Quick tool reference
517
-
518
- | Tool | Usage | Key parameters |
519
- |---|---|---|
520
- | `agent_launch` | Launch a session | `prompt`, `name`, `workdir`, `multi_turn`, `worktree_strategy`, `output_mode` |
521
- | `agent_sessions` | List sessions | `status` (all/running/completed/failed/killed) |
522
- | `agent_output` | Read the output | `session`, `full`, `lines` |
523
- | `agent_kill` | Kill or complete a session | `session`, `reason` (`"completed"` or omit) |
524
- | `agent_respond` | Send a follow-up | `session`, `message`, `interrupt`, `approve` |
525
- | `agent_stats` | Usage metrics | none |
526
- | `agent_worktree_status` | Show worktree status for sessions | `session` (optional — omit for all) |
527
- | `agent_merge` | Merge worktree branch to base | `session`, `base_branch`, `strategy`, `push`, `delete_branch` |
528
- | `agent_pr` | Create/update GitHub PR for worktree branch | `session`, `title`, `body`, `base_branch`, `force_new` |
529
- | `agent_worktree_cleanup` | Clean up merged agent/* branches | `workdir`, `base_branch`, `skip_session_check`, `dry_run`, `session` |
240
+ See `README.md` for the product overview and `docs/REFERENCE.md` for the canonical operator reference.