@scotthuang/agent-knock-knock 0.2.44 → 0.2.47

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +148 -242
  3. package/dist/src/approval-policy.d.ts +1 -0
  4. package/dist/src/approval-policy.js +6 -0
  5. package/dist/src/approval-policy.js.map +1 -1
  6. package/dist/src/claude-hook-installer.d.ts +65 -0
  7. package/dist/src/claude-hook-installer.js +410 -0
  8. package/dist/src/claude-hook-installer.js.map +1 -0
  9. package/dist/src/claude-hook-protocol.d.ts +89 -0
  10. package/dist/src/claude-hook-protocol.js +243 -0
  11. package/dist/src/claude-hook-protocol.js.map +1 -0
  12. package/dist/src/claude-hook-store.d.ts +247 -0
  13. package/dist/src/claude-hook-store.js +1064 -0
  14. package/dist/src/claude-hook-store.js.map +1 -0
  15. package/dist/src/claude-terminal-agent-adapter.d.ts +47 -0
  16. package/dist/src/claude-terminal-agent-adapter.js +920 -0
  17. package/dist/src/claude-terminal-agent-adapter.js.map +1 -0
  18. package/dist/src/cli.js +1565 -772
  19. package/dist/src/cli.js.map +1 -1
  20. package/dist/src/codex-session-provider.d.ts +6 -32
  21. package/dist/src/codex-session-provider.js +2 -1
  22. package/dist/src/codex-session-provider.js.map +1 -1
  23. package/dist/src/codex-store-adapter.d.ts +3 -9
  24. package/dist/src/codex-store-adapter.js +5 -55
  25. package/dist/src/codex-store-adapter.js.map +1 -1
  26. package/dist/src/codex-terminal-agent-adapter.d.ts +34 -0
  27. package/dist/src/codex-terminal-agent-adapter.js +386 -0
  28. package/dist/src/codex-terminal-agent-adapter.js.map +1 -0
  29. package/dist/src/openclaw-plugin.js +60 -11
  30. package/dist/src/openclaw-plugin.js.map +1 -1
  31. package/dist/src/protocol.d.ts +1 -1
  32. package/dist/src/terminal-agent-adapter.d.ts +158 -0
  33. package/dist/src/terminal-agent-adapter.js +109 -0
  34. package/dist/src/terminal-agent-adapter.js.map +1 -0
  35. package/dist/src/terminal-agent-bridge.d.ts +114 -0
  36. package/dist/src/terminal-agent-bridge.js +487 -0
  37. package/dist/src/terminal-agent-bridge.js.map +1 -0
  38. package/dist/src/terminal-agent-registry.d.ts +7 -0
  39. package/dist/src/terminal-agent-registry.js +24 -0
  40. package/dist/src/terminal-agent-registry.js.map +1 -0
  41. package/dist/src/terminal-control-provider.d.ts +8 -6
  42. package/dist/src/terminal-control-provider.js +5 -5
  43. package/dist/src/terminal-control-provider.js.map +1 -1
  44. package/dist/src/terminal-process-source.d.ts +25 -0
  45. package/dist/src/terminal-process-source.js +77 -0
  46. package/dist/src/terminal-process-source.js.map +1 -0
  47. package/openclaw.plugin.json +7 -3
  48. package/package.json +1 -1
  49. package/templates/openclaw-skills/agent-knock-knock/SKILL.md +19 -16
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.47 - 2026-07-23
4
+
5
+ ### Added
6
+
7
+ - Add tmux control for Claude Code, including discovery, safe idle-only sends, Hook-backed monitoring, structured allow/deny, and exact-rule auto approval.
8
+ - Add an idempotent `install-claude-hooks` command that preserves existing Claude settings and hooks.
9
+
10
+ ### Fixed
11
+
12
+ - Bind Claude permission and Stop/StopFailure events to strong runtime identity, terminal, conversation, message, and active lease; keep background work from completing early and deliver each terminal result once.
13
+ - Show a redacted permission target summary, preserve conservative manual fallback for unverifiable dialogs, and normalize only the exact source-tagged Tokenjuice Claude wrapper for policy matching.
14
+
15
+ ## 0.2.46 - 2026-07-22
16
+
17
+ ### Added
18
+
19
+ - Add a registry-driven terminal-agent adapter layer, neutral process discovery, agent-aware terminal IDs, and a documented extension path while keeping legacy Codex IDs compatible.
20
+
21
+ ### Security
22
+
23
+ - Fail closed on missing capabilities and revalidate the full ordered approval-key action against a freshly captured prompt before sending terminal input.
24
+
25
+ ## 0.2.45 - 2026-07-20
26
+
27
+ ### Added
28
+
29
+ - Persist terminal callback delivery state and add bounded automatic retries plus `AKK retry-callback` / `agent_knock_knock_retry_callback` for idempotent manual recovery after delivery failures.
30
+
31
+ ### Fixed
32
+
33
+ - Require a request-hash-matched Codex rollout `task_complete` (or terminal-screen completion fallback) before closing terminal bridge tasks, preventing same-workspace assistant progress from another or unfinished turn from being reported as done.
34
+ - Keep terminal bridge tasks in `callback_pending` or `callback_failed` until their OpenClaw callback is actually delivered, and close them only after successful delivery.
35
+
3
36
  ## 0.2.44 - 2026-07-19
4
37
 
5
38
  ### Fixed
package/README.md CHANGED
@@ -2,151 +2,102 @@
2
2
 
3
3
  ![Agent Knock Knock cover: OpenClaw knocking on coding agents' door](docs/assets/agent-knock-knock-cover.jpg)
4
4
 
5
- Agent Knock Knock lets OpenClaw delegate work to local coding agents such as Codex, Claude Code, and Cursor, keep those delegations alive as reusable tasks, and route follow-up messages or results back through OpenClaw.
5
+ Agent Knock Knock (AKK) lets OpenClaw delegate work to local Codex, Claude Code, and Cursor agents, preserve each task for follow-ups, and route results back to chat—even on channels without threads. It can also discover native Codex sessions and control Codex or Claude Code already running in tmux.
6
6
 
7
- The name is literal: OpenClaw knocks on the door of another coding agent, hands it a task, waits for the callback, and can knock again later with follow-up instructions. AKK provides the persistent task layer that makes that workflow practical across chat channels.
8
-
9
- ## Why This Exists
10
-
11
- OpenClaw already has built-in session spawning, but persistent ACP sessions can depend on thread-bound channels such as Discord or Telegram. That model works well when the external channel can attach replies to a stable thread.
12
-
13
- Channels such as WeChat and many direct-message surfaces do not provide that same thread primitive. Without an external thread, OpenClaw needs another durable place to remember which coding agents are working, which task each agent owns, and where follow-up messages should go.
14
-
15
- Agent Knock Knock fills that gap. It keeps local task state outside the chat channel, uses ACPX / ACP to talk to coding agents, and gives OpenClaw tools to delegate, list, inspect, continue, cancel, and close work without relying on any external channel feature.
16
-
17
- BTW, it can also [take over a Codex task](#native-codex-takeover) you started in a terminal, so when you are away from your computer, OpenClaw can still pick it up and keep going.
18
-
19
- ## What It Provides
20
-
21
- - ACPX-backed delegation to Codex, Claude Code, and Cursor
22
- - Reusable task sessions for follow-up messages after the first result
23
- - Task listing, status inspection, follow-up send, cooperative cancellation, and local close
24
- - Structured callbacks back into OpenClaw through the plugin Gateway method
25
- - Conversation state stored in the user's home directory for recovery across OpenClaw turns
26
- - Runtime diagnostics logs with local timestamps, redaction, and retention cleanup
27
- - A short `AKK` routing convention for chat and `/akk` command surfaces
28
-
29
- See [ROADMAP.md](ROADMAP.md) for planned reliability work and future orchestration features.
30
-
31
- ## Architecture
32
-
33
- OpenClaw is the top-level orchestrator. Agent Knock Knock runs as the OpenClaw plugin bridge, uses ACPX / ACP to communicate with local coding agents, and keeps enough local task state for OpenClaw to manage many concurrent coding-agent sessions.
34
-
35
- ```mermaid
36
- flowchart LR
37
- user["User / chat surface"] --> openclaw["OpenClaw"]
38
- openclaw --> plugin["Agent Knock Knock<br/>OpenClaw plugin"]
39
- plugin --> state["Local task state<br/>~/.agent-knock-knock"]
40
- plugin --> acpx["ACPX / ACP"]
41
- plugin --> terminal["Terminal bridge<br/>tmux Codex"]
42
- acpx --> codex["Codex"]
43
- acpx --> claude["Claude Code"]
44
- acpx --> cursor["Cursor"]
45
- terminal --> codex
46
- codex --> plugin
47
- claude --> plugin
48
- cursor --> plugin
49
- plugin --> callback["OpenClaw callback"]
50
- callback --> openclaw
51
- ```
7
+ ## Install
52
8
 
53
- ## Prerequisites
9
+ Requirements:
54
10
 
55
11
  - Node.js 20+
56
12
  - OpenClaw installed and running
57
- - ACPX installed globally:
58
-
59
- ```bash
60
- npm install -g acpx
61
- acpx --version
62
- ```
63
-
64
- - At least one local coding agent:
65
- - Codex, if you want Codex delegation
66
- - Claude Code, if you want Claude delegation
67
- - Cursor, if you want Cursor delegation
68
-
69
- Agent Knock Knock does not manage Codex, Claude Code, or Cursor authentication. Make sure the agent you want to use is already installed and logged in before delegating tasks.
70
-
71
- ## Install
72
-
73
- Install Agent Knock Knock globally:
13
+ - [ACPX](https://github.com/openclaw/acpx) installed globally
14
+ - At least one authenticated coding agent: Codex, Claude Code, or Cursor
74
15
 
75
16
  ```bash
17
+ npm install -g acpx
76
18
  npm install -g @scotthuang/agent-knock-knock
77
19
  agent-knock-knock install-openclaw
78
20
  agent-knock-knock doctor
79
21
  ```
80
22
 
81
- `install-openclaw` installs or updates and enables the OpenClaw plugin from the npm package, installs the Agent Knock Knock skill template, and restarts the OpenClaw Gateway by default. The command is safe to rerun when the plugin is already installed. Use `--skill-only` to update only the skill template, or `--no-restart` if you want to restart the Gateway yourself.
23
+ `install-openclaw` installs or updates the plugin, enables it, installs the AKK skill template, and restarts the OpenClaw Gateway. It is safe to rerun. Use `--skill-only` to skip plugin installation; add `--no-restart` to skip the automatic Gateway restart.
82
24
 
83
- If you are developing from a local checkout, you can ask OpenClaw to install it for you:
25
+ To control Claude Code sessions in tmux, install AKK's structured hooks once:
84
26
 
85
- ```text
86
- Install this Agent Knock Knock project into my local OpenClaw:
87
- 1. Make sure Node.js 20+, OpenClaw, and at least one local coding agent such as Codex, Claude Code, or Cursor are installed.
88
- 2. Install ACPX globally if it is missing: npm install -g acpx.
89
- 3. Run npm install.
90
- 4. Run npm run build.
91
- 5. Link and enable the OpenClaw plugin from this repository.
92
- 6. Install the Agent Knock Knock skill template into ~/.openclaw/skills/agent-knock-knock/SKILL.md.
93
- 7. Restart the OpenClaw Gateway.
27
+ ```bash
28
+ agent-knock-knock install-claude-hooks
94
29
  ```
95
30
 
96
- Local development installation:
31
+ The installer merges AKK hooks into `~/.claude/settings.json` and preserves existing settings and hooks. Rerun it if the AKK executable path changes.
97
32
 
98
- Install the plugin into OpenClaw during local development:
33
+ If OpenClaw runs from a local checkout or another nonstandard location, pass its CLI explicitly:
99
34
 
100
35
  ```bash
101
- npm install
102
- npm run build
103
- openclaw plugins install --link .
104
- openclaw plugins enable agent-knock-knock
36
+ agent-knock-knock install-openclaw --openclaw-bin /path/to/openclaw/openclaw.mjs
105
37
  ```
106
38
 
107
- Install the OpenClaw skill template so OpenClaw learns when to route chat requests to AKK:
39
+ For local AKK development:
108
40
 
109
41
  ```bash
110
- mkdir -p ~/.openclaw/skills/agent-knock-knock
111
- cp templates/openclaw-skills/agent-knock-knock/SKILL.md ~/.openclaw/skills/agent-knock-knock/SKILL.md
42
+ npm install
43
+ npm run build
44
+ node dist/src/cli.js install-openclaw
112
45
  ```
113
46
 
114
- Apply local project updates to OpenClaw:
47
+ Rerun the build and installer after pulling or editing plugin sources. OpenClaw loads the compiled files from `dist/`.
115
48
 
116
- ```bash
117
- npm install
118
- npm run build
119
- openclaw plugins install --link .
120
- openclaw plugins enable agent-knock-knock
121
- openclaw gateway restart
49
+ ## Quick Start
50
+
51
+ Start a task from an OpenClaw chat, then use its conversation ID for follow-ups:
52
+
53
+ ```text
54
+ AKK Codex: inspect this repository and summarize it
55
+ AKK status <conversation-id>
56
+ AKK send <conversation-id>: run the tests and fix any failures
57
+ AKK list
122
58
  ```
123
59
 
124
- Run this after pulling new code or editing TypeScript/plugin files. The OpenClaw plugin loads compiled files from `dist/`, so source changes do not take effect until `npm run build` has run and the Gateway has reloaded the linked plugin. If the skill template changes, copy `templates/openclaw-skills/agent-knock-knock/SKILL.md` to `~/.openclaw/skills/agent-knock-knock/SKILL.md` again.
60
+ If no agent is named, AKK uses the configured `defaultAgent`, falling back to Codex.
61
+
62
+ ## Why AKK
63
+
64
+ OpenClaw can spawn agents directly, but persistent sessions may depend on channel threads. WeChat and many direct-message surfaces do not provide that primitive. AKK keeps task state outside the chat channel so OpenClaw can recover, inspect, and continue coding-agent work from any supported surface.
65
+
66
+ OpenClaw remains the orchestrator. AKK provides the plugin bridge, ACPX/ACP transport, durable task state, tmux terminal control, and structured callbacks.
67
+
68
+ ```mermaid
69
+ flowchart LR
70
+ user["User / chat surface"] --> openclaw["OpenClaw"]
71
+ openclaw --> plugin["AKK plugin"]
72
+ plugin --> state["Task state<br/>~/.agent-knock-knock"]
73
+ plugin --> acpx["ACPX/ACP"]
74
+ plugin --> terminal["tmux terminal bridge"]
75
+ acpx --> codex["Codex"]
76
+ acpx --> claude["Claude Code"]
77
+ acpx --> cursor["Cursor"]
78
+ terminal --> codex
79
+ terminal --> claude
80
+ codex --> plugin
81
+ claude --> plugin
82
+ cursor --> plugin
83
+ plugin --> callback["OpenClaw callback"]
84
+ callback --> openclaw
85
+ ```
125
86
 
126
- ## OpenClaw Plugin
87
+ See [ROADMAP.md](ROADMAP.md) for planned reliability and orchestration work.
127
88
 
128
- Use `AKK` or `akk` in OpenClaw chat to delegate coding work. If no agent is named, AKK uses the plugin `defaultAgent`; if that is unset, it falls back to Codex. Explicit agent names override the default.
89
+ ## Usage
129
90
 
130
- Useful chat-style prompts:
91
+ Use conversational `AKK` prompts on any chat surface. Explicit agent names override the configured default:
131
92
 
132
93
  ```text
133
- akk: fix the failing tests in this project
134
- AKK Codex: review the current branch and propose a small fix
135
94
  AKK Claude: review the latest commit
136
95
  AKK Cursor: fix the flaky UI test
137
- akk list
138
- akk status <conversation-id>
139
- akk describe <conversation-id>
140
- akk send <conversation-id>: continue with the smaller implementation
141
- akk cancel <conversation-id>
142
- akk renew <conversation-id> --minutes 180
143
- akk recover <conversation-id>
144
- akk close <conversation-id>
145
- AKK terminal takeover Codex <native-session-id>
146
- AKK approve <conversation-id>
96
+ AKK describe <conversation-id>
97
+ AKK recover <conversation-id>
147
98
  ```
148
99
 
149
- Surfaces that support OpenClaw native commands can use the same workflow through `/akk`:
100
+ Surfaces with native commands also support:
150
101
 
151
102
  ```text
152
103
  /akk <task>
@@ -155,31 +106,18 @@ Surfaces that support OpenClaw native commands can use the same workflow through
155
106
  /akk cursor <task>
156
107
  /akk list
157
108
  /akk status <conversation-id>
109
+ /akk describe <conversation-id>
158
110
  /akk send <conversation-id> <message>
159
111
  /akk cancel <conversation-id>
160
112
  /akk renew <conversation-id> [minutes]
113
+ /akk retry-callback <conversation-id>
114
+ /akk recover <conversation-id>
161
115
  /akk close <conversation-id> [reason]
162
116
  ```
163
117
 
164
- Optional default-agent config:
165
-
166
- ```json5
167
- {
168
- plugins: {
169
- entries: {
170
- "agent-knock-knock": {
171
- config: {
172
- defaultAgent: "codex", // "codex", "claude", or "cursor"
173
- agentTimeoutMinutes: 60, // terminal inactivity timeout
174
- agentHardTimeoutMinutes: 720 // terminal task lifetime ceiling
175
- }
176
- }
177
- }
178
- }
179
- }
180
- ```
118
+ ## Configuration
181
119
 
182
- Optional deterministic auto-approval policy for terminal-controlled Codex sessions:
120
+ Configure AKK under `plugins.entries.agent-knock-knock.config` in `~/.openclaw/openclaw.json`:
183
121
 
184
122
  ```json5
185
123
  {
@@ -187,21 +125,8 @@ Optional deterministic auto-approval policy for terminal-controlled Codex sessio
187
125
  entries: {
188
126
  "agent-knock-knock": {
189
127
  config: {
190
- autoApprove: {
191
- enabled: true,
192
- rules: [
193
- {
194
- id: "project-read-status",
195
- agents: ["codex"],
196
- workspaces: ["/Users/scott/project"],
197
- commands: [
198
- ["pwd"],
199
- ["git", "status"],
200
- ["git", "diff", "--stat"]
201
- ]
202
- }
203
- ]
204
- }
128
+ defaultAgent: "codex",
129
+ workspace: "/Users/scott/project"
205
130
  }
206
131
  }
207
132
  }
@@ -209,118 +134,121 @@ Optional deterministic auto-approval policy for terminal-controlled Codex sessio
209
134
  }
210
135
  ```
211
136
 
212
- Auto-approval is disabled by default. Rules use exact argument-vector matching and apply only to Codex `run command` prompts in the configured workspace. Shell composition, command substitution, glob expansion, environment assignments, unparseable commands, and paths outside the workspace always fall back to user approval. The OpenClaw plugin reads this trusted configuration inside the Gateway; it is not exposed as model-controlled tool input. AKK rechecks the visible prompt fingerprint immediately before sending the approval key and records the matched rule and policy fingerprint in the conversation event log.
213
-
214
- ## Native Codex Takeover
215
-
216
- Experimental: AKK can list and take over Codex CLI sessions that were started outside AKK. This is useful when you started Codex in a terminal, left the machine, and want OpenClaw to continue managing that work from chat.
137
+ | Option | Default | Purpose |
138
+ | --- | --- | --- |
139
+ | `defaultAgent` | `codex` | Agent used when a request does not name one. |
140
+ | `workspace` | OpenClaw process directory | Working directory for delegated tasks. |
141
+ | `storeDir` | `~/.agent-knock-knock/conversations` | Conversation state location. |
142
+ | `openclawBin` | Auto-detected | OpenClaw CLI used for callback delivery. |
143
+ | `codexAllProxy`, `cursorAllProxy`, `allProxy` | Unset | Per-agent or shared `ALL_PROXY` for ACPX launches. |
144
+ | `codexModel`, `cursorModel`, `model` | Unset | Per-agent or shared ACPX model override. |
145
+ | `defaultCodexSession`, `defaultClaudeSession`, `defaultCursorSession` | Generated per task | Named ACPX session to reuse. |
146
+ | `idleTimeoutMinutes` | `10080` | Time before an idle task is lazily closed. |
147
+ | `agentTimeoutMinutes` | `60` | Callback timeout; terminal bridges treat it as an inactivity timeout. |
148
+ | `agentHardTimeoutMinutes` | `720` | Maximum terminal bridge monitor lifetime. |
149
+ | `softLimit`, `hardLimit` | `50`, `100` | Response-requiring round limits. |
217
150
 
218
- List current AKK-managed and local agent work:
151
+ See [`openclaw.plugin.json`](openclaw.plugin.json) for the complete schema and compatibility aliases.
219
152
 
220
- ```text
221
- AKK list
222
- ```
223
-
224
- `AKK list` returns separate groups for:
153
+ ## Native Sessions and tmux Control
225
154
 
226
- - `delegated`: AKK-managed background tasks.
227
- - `native`: local native sessions that AKK can discover but cannot directly control.
228
- - `terminal_controlled`: local sessions running in a controllable terminal provider. The current provider is tmux. These entries include terminal metadata, command capabilities, and concise approval state when a visible approval prompt is detected.
229
- - `terminal_controlled` entries can be addressed directly by their `id` from `AKK list` for `AKK send <id>`, `AKK status <id>`, `AKK cancel <id>`, and `AKK approve <id>`. They do not need an AKK state file before terminal control.
230
- - Background sends to terminal-controlled Codex sessions use terminal bridge mode: AKK types only the user-facing task text into the tmux pane, monitors Codex rollout/terminal state, and delivers the OpenClaw callback itself when it observes completion.
231
- - Terminal bridge timeout is activity-aware. Visible Codex work, active background terminals, rollout updates, and meaningful terminal changes extend the inactivity deadline. A separate hard lifetime still stops permanently running monitors.
232
- - If a live terminal task is marked `stalled`, `AKK renew <conversation-id> --minutes <minutes>` restarts monitoring without sending text or keys to Codex. Renewal preserves the original callback destination and task hard deadline.
233
- - `AKK status <terminal-controlled-id>` is the unified way to inspect current terminal output. AKK captures the terminal pane internally and returns `terminal_screen`; there is no separate public screen-capture command.
234
- - `AKK describe <id>` summarizes what a listed session is about. AKK-managed sessions use saved conversation history; native and terminal-controlled Codex sessions use exact Codex rollout history when a session id is available, fall back to cwd-matched rollout history when needed, and otherwise report only visible terminal/process context with lower confidence.
155
+ Experimental: AKK can discover Codex CLI sessions started outside AKK and control Codex or Claude Code sessions in tmux. `AKK list` separates managed `delegated` tasks, discovered `native` sessions, and tmux-backed `terminal_controlled` sessions. Native stop/resume and fork takeover remain Codex-only.
235
156
 
236
- Takeover prompts:
237
-
238
- ```text
239
- AKK takeover Codex <native-session-id>
240
- AKK terminal takeover Codex <native-session-id>
241
- AKK fork takeover Codex <native-session-id>
242
- AKK approve <conversation-id>
243
- ```
157
+ | Strategy | Behavior |
158
+ | --- | --- |
159
+ | `AKK takeover Codex <session-id>` | After confirmation, stop and attach the matching CLI; the next send resumes it. |
160
+ | `AKK terminal takeover Codex <session-id>` | After confirmation, control the existing tmux session without stopping it. |
161
+ | `AKK fork takeover Codex <session-id>` | Keep the original running and create a new task from an OpenClaw-approved summary. |
244
162
 
245
- Strategies:
163
+ A terminal-controlled ID works directly with `send`, `status`, `describe`, and `cancel`. Claude accepts new messages only at a verified idle prompt. Codex visible prompts can also be approved directly. Claude structured approval and durable monitoring require a managed lease: use `send --background` first (the OpenClaw send tool already does this), then use the returned managed conversation ID with `approve`, `cancel`, or `status`. Monitoring is activity-aware and has a separate hard lifetime. Use `renew` for a stalled monitor and `retry-callback` if callback delivery remains failed.
246
164
 
247
- - `takeover`: stop an active matching Codex CLI after explicit confirmation, then resume it under AKK.
248
- - `terminal takeover`: attach an active Codex CLI running inside a controllable terminal provider after explicit confirmation. AKK sends follow-ups directly to the terminal pane, can send Control-C for cancel, and can approve the currently visible Codex approval prompt.
249
- - `fork takeover`: keep the original Codex CLI running, ask OpenClaw to summarize bounded source context, then create a new AKK-managed fork from that summary.
165
+ New terminal-controlled IDs use `terminal:v2:tmux:<agent>:<target>:<pid>`, for example `terminal:v2:tmux:claude:claude-work:0.1:33389`. Legacy `terminal:tmux:<target>:<pid>` IDs remain valid and are treated as Codex. Cursor tmux sessions are not yet supported.
250
166
 
251
- For long-running local Codex sessions that you may want OpenClaw to operate from WeChat, run Codex inside tmux. AKK does not require tmux, but tmux enables terminal-control takeover without stopping the original process:
167
+ Start sessions you may want to control remotely inside tmux:
252
168
 
253
169
  ```bash
254
170
  tmux new -s codex-work
255
171
  codex
256
- ```
257
-
258
- Avoid starting a second live client on the same active Codex session. It can mix session history in ways that neither live client sees until a later resume.
259
172
 
260
- ## Approval Behavior
173
+ tmux new -s claude-work
174
+ claude
175
+ ```
261
176
 
262
- AKK sends ACPX-backed coding-agent prompts with `--approve-all` so ACPX permission requests can proceed without an additional OpenClaw turn.
177
+ For Claude Code, `send --background` creates the managed lease that binds hook events to the exact session, terminal, conversation, and message. A `Stop` event produces one callback from `last_assistant_message` only after background tasks and scheduled jobs have finished; `StopFailure` produces an actionable error. If hooks are unavailable or identity is stale or ambiguous, AKK can still discover, send, and inspect through tmux, but it will not approve or claim durable completion. `cancel` uses Escape only when no unverified permission dialog is visible; unsafe dialogs must be resolved manually in the terminal.
263
178
 
264
- Claude Code permission requests work with this model. For example, a Claude Code write outside the repository workspace triggers ACPX `session/request_permission`; with `--approve-all`, ACPX approves the request and the write can complete.
179
+ Avoid opening a second live client on the same agent session; concurrent clients can produce inconsistent visible history.
265
180
 
266
- Codex does not currently behave the same way for every sensitive operation under AKK. Some Codex sandbox-sensitive actions, such as writing outside the workspace in non-interactive execution, may fail directly with sandbox or permission errors instead of surfacing an ACPX permission request that AKK can approve. In those cases the action is currently unavailable through AKK's background Codex path; prefer Claude Code for tasks that require ACPX-approved filesystem access outside the workspace, or redesign the task to stay inside the configured workspace.
181
+ ## Approvals
267
182
 
268
- For terminal bridge sends to tmux-backed Codex sessions, AKK watches the terminal pane. If Codex shows an approval prompt, AKK sends OpenClaw a `question` callback with a safe terminal excerpt and explicit routing instructions: approve with `AKK approve <conversation-id>` / `agent_knock_knock_approve`, or deny/stop with `AKK cancel <conversation-id>` / `agent_knock_knock_cancel`. After an approval is sent, AKK resumes terminal bridge monitoring and waits for the final Codex result callback.
183
+ AKK runs ACPX-backed agents with `--approve-all`. Claude Code surfaces permission requests through ACPX, but some Codex sandbox-sensitive operations fail directly. Keep Codex background work inside its workspace, or prefer Claude Code when a task requires ACPX-approved access elsewhere.
269
184
 
270
- ## Development
185
+ For tmux-backed Codex, AKK reports visible approval prompts. For Claude Code, the installed hook reports structured `PermissionRequest` events and AKK shows the tool name plus a redacted, bounded target summary without copying the full tool input. Inspect the current request through OpenClaw, then use `AKK approve <conversation-id>` to allow it or `AKK cancel <conversation-id>` to deny and stop. Unknown, stale, or ambiguous requests are never approved or interrupted by synthetic keys; resolve those dialogs manually in the terminal.
271
186
 
272
- Build TypeScript sources:
187
+ Trusted terminal commands can be auto-approved with a deterministic policy:
273
188
 
274
- ```bash
275
- npm run build
189
+ ```json5
190
+ autoApprove: {
191
+ enabled: true,
192
+ rules: [{
193
+ id: "project-read-status",
194
+ agents: ["codex", "claude"],
195
+ workspaces: ["/Users/scott/project"],
196
+ commands: [
197
+ ["pwd"],
198
+ ["git", "status"],
199
+ ["git", "diff", "--stat"]
200
+ ]
201
+ }]
202
+ }
276
203
  ```
277
204
 
278
- Run type checking without writing `dist/`:
205
+ Place `autoApprove` inside the plugin `config` object. It is disabled by default and applies only to exact Codex run-command or Claude Code `Bash` argument vectors inside configured workspaces. Shell composition, substitutions, globs, environment assignments, unparseable commands, and out-of-workspace paths always require user approval. AKK revalidates the current request immediately before approval and records the matched rule and policy fingerprint.
279
206
 
280
- ```bash
281
- npm run typecheck
282
- ```
207
+ ## Troubleshooting
283
208
 
284
- Run the full test suite. This builds first, then runs the compiled TypeScript tests from `dist/test` against the compiled `dist/src` output:
209
+ Start with `agent-knock-knock doctor`. It checks Node.js, OpenClaw, ACPX, at least one supported coding-agent command, and the packaged plugin files. The OpenClaw CLI must be on `PATH` or in a common user install directory for this check.
285
210
 
286
- ```bash
287
- npm test
288
- ```
211
+ | Symptom | Action |
212
+ | --- | --- |
213
+ | Installer or callbacks cannot find a local OpenClaw CLI | Set `openclawBin` and pass `--openclaw-bin` to `install-openclaw`. |
214
+ | Source changes do not appear | Build, reinstall from the checkout, and restart the Gateway. |
215
+ | Terminal bridge task is `stalled` | Run `AKK renew <conversation-id> --minutes <minutes>`. |
216
+ | ACPX task is `stalled` | Inspect `status --trace`; close and redelegate if the executor cannot continue. |
217
+ | Task is `callback_failed` | Run `AKK retry-callback <conversation-id>`. |
218
+ | Codex delegation rejects the deprecated adapter | Remove the old override or select a supported adapter as described below. |
219
+ | Terminal takeover is unavailable | Run Codex or Claude Code inside tmux and check `AKK list` for a `terminal_controlled` entry. |
220
+ | Claude permission or completion is not detected | Run `agent-knock-knock install-claude-hooks`, then retry in the managed tmux session. |
289
221
 
290
- Run a two-Claude simulation:
222
+ For local diagnostics, use:
291
223
 
292
224
  ```bash
293
- node scripts/two-claude-weather-test.js --location 广州
225
+ agent-knock-knock status --conversation <conversation-id> --trace
226
+ agent-knock-knock list --terminal-debug
227
+ agent-knock-knock list --managed-only # skip native and terminal discovery
294
228
  ```
295
229
 
296
- Run named simulations:
230
+ ### Codex ACP Adapter
297
231
 
298
- ```bash
299
- npm run simulate:architecture
300
- npm run simulate:weather
301
- ```
302
-
303
- Print a readable transcript from an NDJSON log:
232
+ Codex delegation uses `npx -y @agentclientprotocol/codex-acp@^1.1.0` by default and rejects the deprecated `@zed-industries/codex-acp`. The first run may take longer while `npx` downloads the adapter. To select another compatible adapter, set this in the environment that runs OpenClaw/AKK:
304
233
 
305
234
  ```bash
306
- npm run transcript -- --conversation .agent-knock-knock/conversations/<conversation-id>
235
+ export AKK_CODEX_ACPX_AGENT_COMMAND='your-compatible-adapter-command'
307
236
  ```
308
237
 
309
- You can also read a specific event log file:
310
-
311
- ```bash
312
- npm run transcript -- --log .agent-knock-knock/conversations/<conversation-id>/events.ndjson
313
- ```
314
-
315
- Include raw model exchange events when debugging prompt/response payloads:
238
+ ## Development
316
239
 
317
240
  ```bash
318
- npm run transcript -- --conversation .agent-knock-knock/conversations/<conversation-id> --include-raw
241
+ npm run build # compile TypeScript into dist/
242
+ npm run typecheck # check types without writing output
243
+ npm test # build and run the full test suite
244
+ npm run simulate:architecture # run a named two-agent simulation
245
+ npm run simulate:weather
246
+ npm run transcript -- --conversation ~/.agent-knock-knock/conversations/<conversation-id>
319
247
  ```
320
248
 
321
- ## Storage
249
+ Pass `--include-raw` to the transcript command only when debugging model exchange events. See [CONTRIBUTING.md](CONTRIBUTING.md) for the development and pull request workflow.
322
250
 
323
- Conversation state is stored under the user's home directory so a new OpenClaw session can recover the shared context independently from OpenClaw's own app state:
251
+ ## Storage and Logs
324
252
 
325
253
  ```text
326
254
  ~/.agent-knock-knock/
@@ -333,47 +261,25 @@ Conversation state is stored under the user's home directory so a new OpenClaw s
333
261
  runtime-YYYY-MM-DD.ndjson
334
262
  ```
335
263
 
336
- Use `--store-dir <dir>` to override the conversation store location. `--log-dir <dir>` is still accepted as a compatibility alias. `<agent>-output.log` is diagnostic-only; OpenClaw should not read it as part of agent communication.
337
-
338
- Runtime logs are diagnostic-only and are safe to use for local troubleshooting. They keep local timestamps, preserve useful absolute paths, redact common secrets, and are cleaned up by retention policy. Use `AKK_LOG_DIR`, `AKK_LOG_LEVEL`, and `AKK_LOG_RETENTION_DAYS` to override the defaults.
339
-
340
- ## Defaults
264
+ Use `--store-dir <dir>` to override the conversation store; `--log-dir` remains a compatibility alias. Agent output and runtime logs are diagnostic-only and are not part of OpenClaw-agent communication.
341
265
 
342
- - Default agent: configured with `defaultAgent`; fallback is `codex`
343
- - OpenClaw session: inherited from the current OpenClaw session; fallback is `agent:main:main`
344
- - Delegated ACPX session: generated per new task, unless `session`, `codexSession`, `claudeSession`, or `cursorSession` is configured
345
- - Agent callback/terminal inactivity timeout: `60` minutes before an inactive waiting task is marked `stalled`
346
- - Terminal bridge hard lifetime: `720` minutes for a still-running monitor with no approval or completion result, even if other activity continues
347
- - Idle timeout: `10080` minutes before an idle task is lazily closed
348
- - Soft response limit: `50` rounds
349
- - Hard response limit: `100` rounds
350
- - Store directory: `~/.agent-knock-knock/conversations`
351
- - Runtime log directory: `~/.agent-knock-knock/logs`
352
- - Runtime log retention: `14` days
353
- - Codex model: unset by default; configure `codexModel` only when your ACPX Codex setup requires one
354
- - Cursor model: unset by default; configure `cursorModel` only when your ACPX Cursor setup requires one
266
+ Runtime logs use local timestamps, redact common secrets, and are cleaned by retention policy. Configure them with `AKK_LOG_DIR`, `AKK_LOG_LEVEL`, and `AKK_LOG_RETENTION_DAYS`. Defaults are `~/.agent-knock-knock/logs` and 14 days.
355
267
 
356
268
  ## Release
357
269
 
358
- `package.json` is the version source. Create releases with npm's version command so the version commit and git tag stay aligned:
270
+ `package.json` is the version source. Create a release with npm's version command, then push the commit and tag:
359
271
 
360
272
  ```bash
361
- npm version patch
273
+ npm version patch # or minor / major
362
274
  git push
363
275
  git push --tags
364
276
  ```
365
277
 
366
- Use `minor` for feature releases and `major` for breaking changes. Tags matching `v*` trigger the GitHub Actions release workflow, which runs the test suite, publishes `@scotthuang/agent-knock-knock` to npm with public access, and creates a GitHub Release from the tag notes.
367
-
368
- The release workflow requires an `NPM_TOKEN` repository secret with permission to publish the npm package. GitHub's built-in `GITHUB_TOKEN` is used for creating the GitHub Release.
369
-
370
- ## Contributing
371
-
372
- See [CONTRIBUTING.md](CONTRIBUTING.md) for local development, test, and pull request guidance.
278
+ Tags matching `v*` run the release workflow, which tests the package, publishes it to npm, and creates a GitHub Release. Publishing requires an `NPM_TOKEN` repository secret.
373
279
 
374
280
  ## Security
375
281
 
376
- Please do not open public issues for sensitive security reports. See [SECURITY.md](SECURITY.md).
282
+ Do not open public issues for sensitive security reports. See [SECURITY.md](SECURITY.md).
377
283
 
378
284
  ## License
379
285
 
@@ -1,6 +1,7 @@
1
1
  export interface ApprovalCandidate {
2
2
  agent: string;
3
3
  kind: string;
4
+ decisionMode?: "keys" | "structured";
4
5
  command?: string;
5
6
  cwd?: string;
6
7
  fingerprint: string;
@@ -23,6 +23,9 @@ export function approvalCandidateFromMessage(message) {
23
23
  agent,
24
24
  kind,
25
25
  fingerprint,
26
+ ...(candidate?.decision_mode === "structured" || candidate?.decision_mode === "keys"
27
+ ? { decisionMode: candidate.decision_mode }
28
+ : {}),
26
29
  command: stringValue(candidate?.command),
27
30
  cwd: stringValue(candidate?.cwd),
28
31
  terminalTarget: stringValue(candidate?.terminal_target)
@@ -36,6 +39,9 @@ export function evaluateApprovalPolicy({ policy, candidate }) {
36
39
  if (candidate.kind !== "run_command") {
37
40
  return ask(`approval kind is not supported: ${candidate.kind}`, policyFingerprint);
38
41
  }
42
+ if (candidate.agent === "claude" && candidate.decisionMode !== "structured") {
43
+ return ask("Claude auto approval requires a structured hook request", policyFingerprint);
44
+ }
39
45
  if (!candidate.command) {
40
46
  return ask("approval command is unavailable", policyFingerprint);
41
47
  }