delegation-layer 0.1.20 → 0.1.22

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 (30) hide show
  1. package/README.md +2 -0
  2. package/package.json +1 -1
  3. package/plugins/delegation-layer/.claude-plugin/plugin.json +1 -1
  4. package/plugins/delegation-layer/.codex-plugin/plugin.json +1 -1
  5. package/plugins/delegation-layer/skills/agent-integration/SKILL.md +79 -25
  6. package/plugins/delegation-layer/skills/agent-integration/evals/evals.json +40 -0
  7. package/plugins/delegation-layer/skills/agent-integration/evals/routing.json +26 -0
  8. package/plugins/delegation-layer/skills/agent-integration/examples/json-results.md +2 -2
  9. package/plugins/delegation-layer/skills/agent-integration/examples/read-only-task.md +1 -2
  10. package/plugins/delegation-layer/skills/agent-integration/examples/workspace-write-task.md +1 -2
  11. package/plugins/delegation-layer/skills/agent-integration/references/collaboration.md +2 -2
  12. package/plugins/delegation-layer/skills/agent-integration/references/command-reference.md +9 -2
  13. package/plugins/delegation-layer/skills/agent-integration/references/continuation.md +1 -1
  14. package/plugins/delegation-layer/skills/agent-integration/references/interaction.md +110 -0
  15. package/plugins/delegation-layer/skills/agent-integration/references/result-handling.md +33 -4
  16. package/plugins/delegation-layer/skills/agent-integration/references/routing-rule.json +1 -1
  17. package/plugins/delegation-layer/skills/agent-integration/scripts/delegate-routing-context.sh +15 -1
  18. package/skills/agent-integration/SKILL.md +79 -25
  19. package/skills/agent-integration/evals/evals.json +40 -0
  20. package/skills/agent-integration/evals/routing.json +26 -0
  21. package/skills/agent-integration/examples/json-results.md +2 -2
  22. package/skills/agent-integration/examples/read-only-task.md +1 -2
  23. package/skills/agent-integration/examples/workspace-write-task.md +1 -2
  24. package/skills/agent-integration/references/collaboration.md +2 -2
  25. package/skills/agent-integration/references/command-reference.md +9 -2
  26. package/skills/agent-integration/references/continuation.md +1 -1
  27. package/skills/agent-integration/references/interaction.md +110 -0
  28. package/skills/agent-integration/references/result-handling.md +33 -4
  29. package/skills/agent-integration/references/routing-rule.json +1 -1
  30. package/skills/agent-integration/scripts/delegate-routing-context.sh +15 -1
package/README.md CHANGED
@@ -20,6 +20,8 @@ already use instead of replacing them.
20
20
  and time budget.
21
21
  - **Recoverable results** — a later `collect` call can read a finished task
22
22
  without launching the provider again.
23
+ - **Clarify while work runs** — answer native questions through Delegate; steer
24
+ an active Codex turn without restarting it. [Interactive tasks](docs/cli-reference.md#interactive-tasks).
23
25
  - **Resumable turns** — a durable timeout can continue the exact provider
24
26
  session through a linked successor task.
25
27
  - **Runtime compatibility** — the selected provider's executable and advertised
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "delegation-layer",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "Multi-provider AI agent delegation CLI and Agent Skill for running bounded coding tasks across provider CLIs.",
5
5
  "keywords": [
6
6
  "ai-agents",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "delegation-layer",
3
3
  "displayName": "Delegation Layer",
4
- "version": "0.1.20",
4
+ "version": "0.1.22",
5
5
  "description": "Consult external AI harnesses and CCR-configured models for reviews, research, implementation, and debate through the resumable Delegate CLI.",
6
6
  "author": {
7
7
  "name": "Hesham Karam",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "delegation-layer",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "Consult external AI harnesses and CCR-configured models for reviews, research, implementation, and debate through the resumable Delegate CLI.",
5
5
  "author": {
6
6
  "name": "Hesham Karam",
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: agent-integration
3
- description: Coordinate external agent, model, and separate harness tasks through Delegate, including research, implementation, tests, reviews, consultations, comparisons, and debates. Use before choosing an external integration; ordinary native subagents and questions about tools remain local.
3
+ description: Use Delegate for work assigned to another agent, model, or separate harness CLI session. Load this before a provider-specific skill or plugin, including when a user names a CLI for research, implementation, tests, reviews, consultations, comparisons, or debates. A named destination still routes through Delegate. Ordinary same-harness subagents and questions about tools remain local; respect an explicit choice of another integration.
4
4
  ---
5
5
 
6
6
  # Delegation Layer
@@ -13,6 +13,8 @@ external harness to do work. Requests such as “ask Codex to review this”,
13
13
  collaboration even when the user never mentions Delegate. The same applies
14
14
  when you decide external expertise is useful to fulfill the user's task.
15
15
  These names are examples; discover supported destinations through the CLI.
16
+ A destination name identifies who should do the work; it does not by itself
17
+ select a provider-specific skill, plugin, or direct CLI integration.
16
18
  “Claude Code Router” and “CCR” mean `ccr:print`, not ordinary Claude Code.
17
19
  For that request, use Delegate with a CCR model alias; a Claude-specific skill
18
20
  or subscription model does not fulfill the requested route.
@@ -36,8 +38,10 @@ not turn that request into an environment-repair task. When a response says
36
38
  `failure.next_action: "stop_and_report"`, that attempt is finished. Include its
37
39
  failure in your final response without opening a clarification dialog to choose
38
40
  a fallback. For `task_record: not_created`, identify the requested destination
39
- and quote the returned `task_id` (if present), `task_record`, `failure`, and
40
- `error`. Do not append inferred state paths or provider-setup diagnoses. Do not run diagnostic commands, retry it, or use another integration.
41
+ and include the saved JSON failure response verbatim. A `task_id` can be returned
42
+ even when no task record was created. Do not infer that an unavailable provider
43
+ is uninstalled or unauthenticated. Do not append inferred state paths or
44
+ provider-setup diagnoses, run diagnostic commands, retry it, or use another integration.
41
45
  Troubleshooting requires a separate user request. Other independently requested
42
46
  tasks may proceed; the failed attempt must remain reported as failed or blocked.
43
47
 
@@ -64,26 +68,38 @@ tasks may proceed; the failed attempt must remain reported as failed or blocked.
64
68
  Delegate owns the supervisor lifecycle. Never install, configure, start,
65
69
  inspect, or repair Pueue, and never poll a task unless the response says its
66
70
  `task_record` is `created`.
67
- 5. Observe with `status` and collect with `collect`. Keep collection in the
71
+ 5. Observe tasks only through Delegate `status`, `collect`, or `events`.
72
+ Do not run `ps`, `pgrep`, process-tree searches, or supervisor commands to
73
+ monitor delegated work. Pending output is normal startup or work in progress;
74
+ empty `pending_requests` means keep collecting, not diagnose the environment.
75
+ Environment diagnostics require a separately requested troubleshooting task.
76
+ Keep collection in the
68
77
  foreground until all requested tasks reach a terminal result or an explicit
69
78
  blocker. Do not end a headless turn promising a background notification.
70
- Pending publication (exit 3) means keep waiting, not success. Only detach
79
+ Pending publication (exit 3) means keep waiting, not success. When the JSON
80
+ includes an outstanding `interaction.pending_requests` batch, follow
81
+ [active-task interaction](references/interaction.md) before waiting again. Only detach
71
82
  when the user explicitly requests it, retaining the exact task IDs.
72
83
  Collection may recover the
73
84
  saved supervisor only to observe an already-requested budget stop; it never
74
85
  launches a provider or retries a task.
75
- 6. If a task is timed out and its JSON says `continuation.resumable: true`, use
86
+ 6. If `failure.next_action` is `recheck`, follow
87
+ [offline recovery](references/result-handling.md#offline-recovery) once for
88
+ that task. Rechecking saved evidence does not run the provider again.
89
+ Otherwise, report a rejected result without redispatching or reading raw
90
+ output as an answer.
91
+ 7. If a task is timed out and its JSON says `continuation.resumable: true`, use
76
92
  `continue --task TASK_ID`, optionally with a new `--brief`. Do not create a
77
93
  fresh unrelated dispatch to replace a resumable task.
78
- 7. Treat `blocked` authentication as unresolved. Do not call it compatible,
94
+ 8. Treat `blocked` authentication as unresolved. Do not call it compatible,
79
95
  successful, or failed provider behavior, and do not invent login commands.
80
- 8. Never put credentials, tokens, or unrestricted provider output in a brief,
96
+ 9. Never put credentials, tokens, or unrestricted provider output in a brief,
81
97
  option, receipt, or agent message.
82
- 9. Permission modes select provider-native behavior, not an independent sandbox.
98
+ 10. Permission modes select provider-native behavior, not an independent sandbox.
83
99
  Providers load their own configuration and extensions. If a task is rejected,
84
100
  report delegate's evidence; do not assume the user's configuration is faulty
85
101
  or remove MCP servers, plugins, settings, or credentials to make it pass.
86
- 10. The model chooses ordinary-task fan-out by issuing independent `dispatch`
102
+ 11. The model chooses ordinary-task fan-out by issuing independent `dispatch`
87
103
  commands concurrently. The private supervisor does not impose a task-count
88
104
  or CPU-based limit. Use this for independent investigation, debate, review,
89
105
  or provider comparison. Concurrent write tasks must use separate workspaces
@@ -121,7 +137,7 @@ normal task. For an explicitly requested readiness check, see
121
137
  [preflight guidance](references/command-reference.md#checking-readiness).
122
138
 
123
139
  The catalog and `capabilities` response expose supported permission modes,
124
- request options, continuation, and the read-only mechanism. A read-only
140
+ request options, continuation, native interaction, and the read-only mechanism. A read-only
125
141
  capability with `containment: "provider-owned"` selects the provider's native
126
142
  behavior but is not an independent delegate-owned sandbox. Static discovery
127
143
  does not prove authentication or live acceptance; use the dispatch or live
@@ -143,46 +159,74 @@ it remains ambiguous or discovery is unavailable, ask for the exact model ID;
143
159
  do not turn a display name into a guessed alias. An explicit ID needs no such
144
160
  clarification just because it is absent from discovery.
145
161
 
162
+ For planning, consultation, debate, or other external work that may need
163
+ answers or guidance while it runs, read [active-task interaction](references/interaction.md)
164
+ and use `--interactive` when supported. Answer known facts yourself; ask the
165
+ user for missing preferences, authorization, or scope. Keep ordinary native
166
+ subagents available under the same-harness rule above.
167
+
146
168
  ### 3. Prepare separate paths and a finite brief
147
169
 
148
170
  Use an existing task brief when one is supplied. Otherwise create a bounded
149
171
  brief file that contains the requested work and its acceptance criteria. Keep
150
172
  the state root outside the workspace and provider-writable trees (which can
151
- include the system temporary directory). Use `DELEGATE_ROOT` when supplied:
173
+ include the system temporary directory). Use `DELEGATE_ROOT` when supplied.
174
+ Pass a regular file path for `--brief`, not shell process substitution such as
175
+ `<(...)` or an ephemeral `/dev/fd/...` path.
152
176
 
153
177
  Run path preparation and dispatch in **one shell/tool invocation**, as shown
154
178
  below. Shell variables may disappear between tool calls. For later commands,
155
179
  use the actual saved absolute paths or assign them again in that invocation;
156
180
  never pass an empty `--root`, `--brief`, or `--cwd`.
157
181
 
158
- Replace the example brief below with the actual user request. Do not place the state
182
+ Write the brief as the **worker’s own assignment**, not a copy of the
183
+ orchestration request. For “consult another agent about X”, tell the worker
184
+ “Investigate X and return your findings; you are the assigned worker, do not
185
+ delegate this assignment.” Keep dispatching, answering questions, and
186
+ collecting results in the lead session unless recursive delegation was
187
+ explicitly requested.
188
+
189
+ Replace the example brief below with that bounded worker assignment. Do not place the state
159
190
  root inside the workspace or place secrets in either path’s task data. Keep it
160
191
  outside provider configuration and runtime directories as well. If delegate
161
192
  rejects a caller-supplied state root, report the placement error rather than
162
- silently replacing that root. If no root was supplied, choose one outside the
163
- workspace and reuse it. Do not change provider settings. Retain the selected
164
- root for every observation and continuation.
193
+ silently replacing that root. For every task command, use
194
+ `--root "${DELEGATE_ROOT:-$HOME/delegation-state}"` as shown below. This reads the supplied root in each shell call and uses the
195
+ same default when none was supplied; no root setup or new directory choice is
196
+ needed. If the user explicitly requests another root, substitute that exact
197
+ absolute path consistently. Do not change provider settings or switch roots
198
+ when waiting, replying, steering, or continuing.
165
199
 
166
200
  ### 4. Dispatch one bounded turn
167
201
 
168
202
  Use automatic selection unless the user named a destination.
169
203
  For a named harness or provider resolved in step 2, replace `--auto` with `--provider PROVIDER_ID`; never
170
- combine the two:
204
+ combine the two.
205
+
206
+ Capture the dispatch exit code with `if`, as below. This prints the response
207
+ even when dispatch fails and the surrounding shell has `set -e` enabled.
171
208
 
172
209
  ```sh
173
- STATE_ROOT="${DELEGATE_ROOT:-$HOME/delegation-state}"
174
210
  WORKSPACE="$PWD"
175
211
  BRIEF="$(mktemp)"
212
+ RESPONSE="$(mktemp)"
176
213
  cat >"$BRIEF" <<'EOF'
177
214
  Describe the delegated task, the files or behavior to change, and the checks
178
215
  that must pass. Keep the response concise and report validation evidence.
179
216
  EOF
180
- delegate --root "$STATE_ROOT" dispatch --auto \
217
+ printf 'Saved response: %s\n' "$RESPONSE"
218
+ if delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" dispatch --auto \
181
219
  --brief "$BRIEF" \
182
220
  --cwd "$WORKSPACE" \
183
221
  --permission read-only \
184
222
  --budget 30m \
185
- --json
223
+ --json >"$RESPONSE"; then
224
+ dispatch_exit=0
225
+ else
226
+ dispatch_exit=$?
227
+ fi
228
+ cat "$RESPONSE"
229
+ printf '\nDispatch exit: %s; saved response: %s\n' "$dispatch_exit" "$RESPONSE"
186
230
  ```
187
231
 
188
232
  For an authorized code change, use `--permission workspace-write`; this requests
@@ -201,6 +245,12 @@ files, never background commands writing to the same stdout. Read
201
245
  [parallel reviews and debates](references/collaboration.md) when coordinating
202
246
  multiple participants or challenge rounds.
203
247
 
248
+ Capture the response and exit status in the **original** dispatch invocation,
249
+ as above. Read the saved response if you need it again. Never repeat dispatch
250
+ to obtain its exit code, recover output, or confirm that it worked: each call
251
+ can create new paid work. Once a response says `task_record: created`, save its
252
+ `task_id` and switch to observation. A missing exit code does not undo admission.
253
+
204
254
  Save the exact `task_id` from the JSON response. Apply this decision separately
205
255
  for **each attempt**, including requests issued together:
206
256
 
@@ -219,16 +269,20 @@ never retry that uncertain ID or run Pueue commands.
219
269
 
220
270
  ### 5. Observe and collect
221
271
 
222
- Use the same state root and task ID:
272
+ Use the same state root and task ID. Each command below resolves the root
273
+ in its own shell call, so it does not depend on a previous shell variable:
223
274
 
224
275
  ```sh
225
- delegate --root "$STATE_ROOT" status TASK_ID --json
226
- delegate --root "$STATE_ROOT" collect TASK_ID --watch 5s --json
276
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" status TASK_ID --json
277
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" collect TASK_ID --watch 5s --json
227
278
  ```
228
279
 
229
280
  Check `status` first: if it is `timed_out`, follow step 6 even when publication
230
- is pending and no outcome is present. Otherwise, if `collect` exits with code
231
- `3` because publication is still pending, wait a short interval and run
281
+ is pending and no outcome is present. If `interaction.pending_requests` is
282
+ nonempty and the interaction is not closed, answer the questions using
283
+ [active-task interaction](references/interaction.md) before collecting again.
284
+ Otherwise, if `collect` exits with code `3` because publication is still
285
+ pending, wait a short interval and run
232
286
  `collect` again. Do not dispatch again. Continue until
233
287
  the response has a terminal `outcome` or a bounded operational error that
234
288
  requires the caller’s attention.
@@ -56,6 +56,46 @@
56
56
  "name": "write-timeout",
57
57
  "prompt": "An authorized write task has status timed_out, publication unknown, no outcome, and continuation.resumable true.",
58
58
  "expected": ["delegate continue --task", "same state root", "new task id", "do not wait indefinitely for an outcome", "no fresh unrelated dispatch"]
59
+ },
60
+ {
61
+ "name": "admitted-without-explicit-exit-marker",
62
+ "prompt": "Dispatch returned task_record created, admission admitted, and a task_id. The shell output did not include a separate EXIT marker. Confirm the task and collect its result.",
63
+ "expected": ["use status with returned task_id", "read saved dispatch response if needed", "do not dispatch again to print an exit code", "exactly one admitted task for the assignment"]
64
+ },
65
+ {
66
+ "name": "supplied-root-across-shell-calls",
67
+ "prompt": "DELEGATE_ROOT is already set. Consult a separate external agent and answer its questions; each shell tool call starts a new shell.",
68
+ "expected": ["use supplied DELEGATE_ROOT on dispatch, status, collect, reply, steer, and continue", "resolve the same root in each shell call", "no invented task-specific root"]
69
+ },
70
+ {
71
+ "name": "pending-without-questions",
72
+ "prompt": "The admitted task is running. Collect exits 3 with pending publication, empty pending_requests, and no operational error.",
73
+ "expected": ["keep collecting the same task", "no ps or pgrep or process-tree inspection", "no supervisor commands", "no duplicate dispatch", "answer through delegate reply when a question appears"]
74
+ },
75
+ {
76
+ "name": "interactive-worker-assignment",
77
+ "prompt": "Consult a separate external agent about a pricing plan and answer its questions from README.md.",
78
+ "expected": ["brief assigns the pricing investigation directly", "worker does not recruit another external agent", "lead answers through delegate reply", "do not copy the orchestration request verbatim"]
79
+ },
80
+ {
81
+ "name": "interactive-clarification",
82
+ "prompt": "An external planning task returned pending.kind interaction with question IDs, choices, and free_text false. The requested preference is not in the user brief.",
83
+ "expected": ["read references/interaction.md", "ask user for missing preference", "reply through delegate with exact request and question IDs", "stable message ID", "continue collecting"]
84
+ },
85
+ {
86
+ "name": "interactive-steering",
87
+ "prompt": "The user adds guidance while an interactive external task is running and its capabilities advertise steering.",
88
+ "expected": ["delegate steer", "preserve task model permission and budget", "do not cancel and redispatch", "receipt is not completion"]
89
+ },
90
+ {
91
+ "name": "interactive-unknown-delivery",
92
+ "prompt": "A reply submission lost its CLI response. Its recorded delivery is unknown.",
93
+ "expected": ["same message ID and exact content to retrieve receipt", "no new message ID retry", "no native CLI bypass", "observe task"]
94
+ },
95
+ {
96
+ "name": "interactive-unsupported-destination",
97
+ "prompt": "A named external provider supports continuation but neither native clarification nor steering. The user wants a discussion with it.",
98
+ "expected": ["preserve named provider", "ordinary bounded turns and continuation", "explain no active-turn questions", "do not pass unsupported interactive flag"]
59
99
  }
60
100
  ]
61
101
  }
@@ -199,6 +199,32 @@
199
199
  ],
200
200
  "split": "validation"
201
201
  },
202
+ {
203
+ "name": "recheck-recoverable",
204
+ "prompt": "Ask a separate Codex CLI session to review pricing.py against README.md without editing. If the terminal result is rejected with failure.next_action=recheck, recheck the same task once and report only the verified recovered answer.",
205
+ "external": true,
206
+ "provider": "codex:exec",
207
+ "fixture_scenario": "recoverable-rejection",
208
+ "holdout": true,
209
+ "split": "validation"
210
+ },
211
+ {
212
+ "name": "recheck-still-rejected",
213
+ "prompt": "Ask a separate Codex CLI session to review pricing.py against README.md without editing. If the terminal result is rejected with failure.next_action=recheck, recheck the same task once and report the rejection without using raw output as an answer.",
214
+ "external": true,
215
+ "provider": "codex:exec",
216
+ "fixture_scenario": "still-rejected-recheck",
217
+ "holdout": true,
218
+ "split": "validation"
219
+ },
220
+ {
221
+ "name": "external-collaboration-holdout",
222
+ "prompt": "Ask a separate Codex CLI session to review pricing.py against README.md and report its finding without editing.",
223
+ "external": true,
224
+ "provider": "codex:exec",
225
+ "holdout": true,
226
+ "split": "validation"
227
+ },
202
228
  {
203
229
  "name": "requested-model-effort",
204
230
  "prompt": "Ask a separate Codex CLI session to review pricing.py without edits. Use model gpt-5.6-luna and effort max, preserving both choices.",
@@ -1,8 +1,8 @@
1
1
  # JSON decision sketch
2
2
 
3
3
  ```sh
4
- delegate --root "$STATE_ROOT" status "$TASK_ID" --json
5
- delegate --root "$STATE_ROOT" collect "$TASK_ID" --watch 5s --json
4
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" status "$TASK_ID" --json
5
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" collect "$TASK_ID" --watch 5s --json
6
6
  ```
7
7
 
8
8
  Decision order:
@@ -1,10 +1,9 @@
1
1
  # Read-only task
2
2
 
3
3
  ```sh
4
- STATE_ROOT="${DELEGATE_ROOT:-$HOME/delegation-state}"
5
4
  BRIEF="$(mktemp)"
6
5
  printf '%s\n' 'Inspect the workspace and summarize the current test failures. Do not edit files.' >"$BRIEF"
7
- delegate --root "$STATE_ROOT" dispatch --auto \
6
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" dispatch --auto \
8
7
  --brief "$BRIEF" --cwd "$PWD" --permission read-only --budget 15m --json
9
8
  ```
10
9
 
@@ -1,8 +1,7 @@
1
1
  # Authorized workspace write task
2
2
 
3
3
  ```sh
4
- STATE_ROOT="${DELEGATE_ROOT:-$HOME/delegation-state}"
5
- delegate --root "$STATE_ROOT" dispatch --auto \
4
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" dispatch --auto \
6
5
  --brief "$PWD/delegated-task.md" --cwd "$PWD" \
7
6
  --permission workspace-write --budget 30m --json
8
7
  ```
@@ -19,14 +19,14 @@ RECEIPTS="$(mktemp -d)" || exit 1
19
19
  # Set these absolute paths and catalog IDs in this same tool invocation.
20
20
  # BRIEF_A and BRIEF_B contain the real independent assignments.
21
21
  (
22
- delegate --root "$STATE_ROOT" dispatch --provider "$PROVIDER_A" \
22
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" dispatch --provider "$PROVIDER_A" \
23
23
  --brief "$BRIEF_A" --cwd "$WORKSPACE_A" \
24
24
  --permission read-only --budget 30m --json \
25
25
  >"$RECEIPTS/review-a.json" 2>"$RECEIPTS/review-a.stderr"
26
26
  printf '%s\n' "$?" >"$RECEIPTS/review-a.exit"
27
27
  ) &
28
28
  (
29
- delegate --root "$STATE_ROOT" dispatch --provider "$PROVIDER_B" \
29
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" dispatch --provider "$PROVIDER_B" \
30
30
  --brief "$BRIEF_B" --cwd "$WORKSPACE_B" \
31
31
  --permission read-only --budget 30m --json \
32
32
  >"$RECEIPTS/review-b.json" 2>"$RECEIPTS/review-b.stderr"
@@ -13,7 +13,11 @@ All paths passed to `--root`, `--cwd`, and `--brief` must be absolute. Add
13
13
  | `delegate dispatch --auto ... --json` | Select and admit one bounded turn | Yes, at most once |
14
14
  | `delegate status TASK --json` | Reconcile and observe task state | No provider launch |
15
15
  | `delegate collect TASK --watch 5s --json` | Read or wait for publication | No provider launch |
16
+ | `delegate recheck TASK --json` | Reassess eligible rejected evidence offline | No provider launch; original outcome unchanged |
16
17
  | `delegate continue --task TASK ... --json` | Create an exact-session successor | Yes, at most once for the successor |
18
+ | `delegate reply TASK --request ID --answers FILE --id MESSAGE_ID --json` | Answer a pending native question | No new launch |
19
+ | `delegate steer TASK --brief FILE --id MESSAGE_ID --json` | Guide a supported active turn | No new launch |
20
+ | `delegate events TASK --after SEQUENCE --watch 5s --json` | Read a bounded interaction event page | No |
17
21
  | `delegate logs TASK --json` | Return validated output descriptors | No |
18
22
  | `delegate cancel TASK --json` | Record one explicit stop request | Stops, does not relaunch |
19
23
 
@@ -30,9 +34,11 @@ Dispatch flags:
30
34
  - `--auto`: let the CLI select a ready provider;
31
35
  - `--provider ID`: preserve the caller’s named harness or provider, resolved through the catalog;
32
36
  - `--model MODEL` and `--effort VALUE`: provider-advertised choices (CCR requires a model alias);
33
- Codex maps effort to TOML `model_reasoning_effort`, while Claude and AGY
37
+ Codex maps effort to TOML `model_reasoning_effort` for ordinary turns or a native
38
+ turn parameter for interactive turns, while Claude and AGY
34
39
  pass native effort flags; Pi maps effort to `--thinking`; OpenCode maps it to
35
40
  `--variant`; CCR forwards effort to Claude and uses `--model` as a CCR alias; `default` is omitted;
41
+ - `--interactive`: enable advertised native clarification and steering; see [interaction](interaction.md);
36
42
  - `--native-timeout DURATION`: optional provider-native timeout where advertised.
37
43
 
38
44
  Model discovery uses the same `--provider ID` profiles and accepts an optional
@@ -47,7 +53,8 @@ Continuation flags:
47
53
 
48
54
  - `--task TASK`: predecessor task ID;
49
55
  - `--brief FILE`: optional new follow-up instruction;
50
- - `--budget DURATION`, `--model MODEL`, and `--effort VALUE`: optional overrides.
56
+ - `--budget DURATION`, `--model MODEL`, and `--effort VALUE`: optional overrides;
57
+ - `--interactive`: enable interaction when supported; already-interactive predecessors keep it.
51
58
 
52
59
  ## Choosing models and effort
53
60
 
@@ -17,7 +17,7 @@ When `status` or `collect` reports a timed-out turn with:
17
17
  run:
18
18
 
19
19
  ```sh
20
- delegate --root "$STATE_ROOT" continue \
20
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" continue \
21
21
  --task PREDECESSOR_TASK_ID \
22
22
  --brief FOLLOW_UP_BRIEF \
23
23
  --budget 30m \
@@ -0,0 +1,110 @@
1
+ # Questions and guidance during an active task
2
+
3
+ Use this reference when an external task may need clarification or guidance
4
+ before it finishes, including planning, consultation, and debate. Use only
5
+ Delegate commands; do not open a terminal session with the provider.
6
+
7
+ ## Choose the transport
8
+
9
+ Read the selected provider's `interaction` capability and
10
+ `interaction.supported_modes`. `clarification` and `steering` are independent.
11
+ Add `--interactive` to dispatch when the chosen provider and permission mode
12
+ support the interaction you need. Keep the user's exact provider, model,
13
+ effort, workspace, permission, and budget.
14
+
15
+ Without a named provider, `dispatch --auto --interactive` selects among
16
+ providers that support interaction. If a named provider does not support it,
17
+ use ordinary bounded turns and `continue` for discussion when native
18
+ continuation is available. Explain that questions cannot be answered during
19
+ that provider's active turn. Never replace the requested provider silently.
20
+
21
+ In the worker brief, explicitly request **native structured clarification**:
22
+ "Use your native question tool to request clarification and await its answer.
23
+ Do not ask only in final text or a progress message and then sleep: the lead
24
+ can answer structured requests, not an unstructured prompt. If the question
25
+ tool is unavailable, report that blocker and finish instead of waiting."
26
+ Assign the actual work directly; the worker should not start another delegate.
27
+
28
+ No change is needed for self-contained tasks that do not need mid-turn input.
29
+ Continuation inherits interaction from its predecessor. `continue --task ID
30
+ --interactive` can enable it for a previously ordinary task.
31
+
32
+ ## Respond to questions
33
+
34
+ 1. Save the admitted task ID and state root. Run `collect TASK_ID --watch 30s
35
+ --json` with that same root. Exit 3 is pending, not completion. Collection
36
+ returns early when there is an outstanding native question.
37
+ 2. Read `interaction.pending_requests`. Use the returned request ID, question
38
+ IDs, options, `multiple`, and `free_text`; do not invent or guess IDs.
39
+ 3. Answer facts already supplied by the user or verified during the task.
40
+ Ask the user for missing preferences, business decisions, new scope, or
41
+ authorization. Do not guess an answer to keep the worker moving. A question
42
+ reply does not approve tool access or change the task's permission mode.
43
+ 4. Write one JSON object mapping **every question ID in that request** to an
44
+ array of answer strings. A single-choice question takes one value. Use exact
45
+ option labels unless `free_text` permits another answer. Example:
46
+
47
+ ```json
48
+ {"color": ["Blue"], "sections": ["Summary", "Evidence"]}
49
+ ```
50
+
51
+ 5. Allocate a new 32-character lowercase hexadecimal message ID and save it
52
+ together with the exact answers. Submit once:
53
+
54
+ ```sh
55
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" reply "$task_id" \
56
+ --request "$request_id" --answers "$answers_file" \
57
+ --id "$message_id" --json
58
+ ```
59
+
60
+ 6. Keep collecting. A receipt is not task completion. Only the task's
61
+ authoritative `outcome` establishes the final result.
62
+
63
+ Use the same root expression for dispatch, collection, reply, and steering.
64
+ If the user explicitly chose another root, use that exact path for all of
65
+ them. The other variables stand for actual values saved from this task;
66
+ reassign them in each shell invocation if your tool does not preserve variables.
67
+ A pending response without questions means keep collecting, not inspect OS
68
+ processes or dispatch a replacement task.
69
+
70
+ ## Guide active work
71
+
72
+ When `interaction.capabilities.steering` is true and the task is active, put
73
+ additional guidance in a brief file and submit:
74
+
75
+ ```sh
76
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" steer "$task_id" \
77
+ --brief "$guidance_file" --id "$message_id" --json
78
+ ```
79
+
80
+ Steering is guidance to the existing turn. It does not change provider, model,
81
+ effort, workspace, permission, or budget. Once the turn ends, use `continue`
82
+ for another authorized turn instead. Do not cancel and redispatch simply to
83
+ send guidance.
84
+
85
+ ## Interpret delivery precisely
86
+
87
+ | State | What it establishes |
88
+ | --- | --- |
89
+ | `queued` | Delegate durably accepted the message; native delivery is pending. |
90
+ | `unknown` | Delivery was reserved or attempted, but its result is uncertain. |
91
+ | `sent` | The native input write completed; no native acknowledgement is established. |
92
+ | `acknowledged` | A correlated native response acknowledged the message. This does not prove the model followed guidance. |
93
+ | `rejected` | The message could not be delivered or the native protocol rejected it. Read the reason. |
94
+
95
+ If a submission response was lost, repeat the **same message ID and exact
96
+ content** to recover its receipt. Never allocate a fresh ID to retry an
97
+ `unknown` delivery. Delegate will not replay an ambiguous native write.
98
+ Changed content with an existing ID is a conflict. Observe the task instead
99
+ of guessing whether it consumed the message.
100
+
101
+ `events TASK_ID --after SEQUENCE --watch 30s --json` returns a bounded event
102
+ page. Save the returned `cursor` for the next page. Events and interaction
103
+ state are progress evidence, not a replacement for `collect` and `outcome`.
104
+
105
+ Waiting for an answer consumes the original execution budget; it does not
106
+ pause or extend it. `interaction.deadline` shows the recorded wall-clock
107
+ boundary when execution has started. If the task ends while waiting, do not
108
+ reply to the old request. Follow the ordinary continuation guidance only when
109
+ Delegate reports the task resumable. Preserve any verified answers in the new
110
+ brief; uncertain delivery must not become an automatic replay.
@@ -15,10 +15,13 @@ the same as a successful provider result.
15
15
  permits a linked successor even when no outcome has been published.
16
16
  4. If `publication` is committed and `outcome.verdict` is committed, return
17
17
  the result and its payload/evidence descriptors.
18
- 5. If `outcome.verdict` is rejected, report a terminal rejected result with its
19
- refusal and evidence. Do not retry automatically.
20
- 6. Otherwise, if `liveness` is queued or running or publication is pending,
21
- observe the same task again with a finite watch interval.
18
+ 5. If `outcome.verdict` is rejected and `failure.next_action` is `recheck`,
19
+ follow [offline recovery](#offline-recovery) once. Otherwise report the
20
+ terminal rejection with its diagnostic and evidence. Do not redispatch.
21
+ 6. If `pending.kind` is `interaction`, handle the returned questions using
22
+ [interaction guidance](interaction.md) before waiting again. Otherwise, if
23
+ `liveness` is queued or running or publication is pending, observe the same
24
+ task with a finite watch interval.
22
25
  7. If authentication is `blocked`, preserve that neutral state and tell the
23
26
  caller what prerequisite is unavailable without inventing a login command.
24
27
  8. Never relaunch an uncertain task by guessing. Observe only a task whose
@@ -42,3 +45,29 @@ checks static readiness; runtime verification requires the supervised probe.
42
45
  Versions and help are observations, not semantic-version allowlists.
43
46
  Authentication is a separate live gate (`not_run`, `passed`, or `blocked`).
44
47
  Report a blocked prerequisite without inventing a login command or retrying.
48
+
49
+ ## Offline recovery
50
+
51
+ When Delegate returns `failure.next_action: "recheck"`, use the same root and
52
+ exact task ID:
53
+
54
+ ```sh
55
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" recheck TASK_ID --json
56
+ ```
57
+
58
+ This command checks the already sealed evidence with an explicitly compatible
59
+ new interpreter. It does not run the provider, contact a service, spend model
60
+ tokens, or change the original outcome.
61
+
62
+ - Exit `0` with `recheck.status: "recovered"`: use only the answer descriptor
63
+ returned for that recheck. Report that the answer was recovered from saved
64
+ evidence. The original `publication` remains `rejected`; do not call the
65
+ original task committed or use recovery to infer continuation permission.
66
+ - Exit `4` with `recheck.status: "rejected"`: report the diagnostic and stop.
67
+ - Exit `1` or `2`, or any response without a verified recovered answer:
68
+ report the error and stop. Do not read raw streams as a substitute answer,
69
+ invent a result path, run a provider directly, or launch a replacement task.
70
+
71
+ Keep the assessment ID and source/target descriptors with the result. Do not
72
+ loop on the same recheck. A separate user request is required for further
73
+ troubleshooting or a new provider task.
@@ -1 +1 @@
1
- "For work assigned to an external agent, model, or separate harness session, load the installed agent-integration skill before choosing tools and use Delegate. This includes research, implementation, testing, review, consultation, comparison, and debate, including external collaboration you choose. Discover destinations through Delegate. Preserve requested model IDs, effort, and permissions; do not guess ambiguous model identifiers. For task commands, set STATE_ROOT=\"${DELEGATE_ROOT:-$HOME/delegation-state}\" and pass --root \"$STATE_ROOT\" in the same shell invocation; reuse that root for dispatch, observation, and continuation, never an invented /tmp root. Keep each concurrent request and its response associated separately. Naming a CLI identifies the destination, not a request to bypass Delegate. Earlier assistant-generated direct-launch workflows do not override this preference. Native same-harness subagents remain available unless a separate session is requested. Respect an explicit user choice of another integration; otherwise do not substitute provider CLIs, plugins, or APIs after a Delegate blocker. A stop_and_report failure ends that attempt: report it without retrying, diagnosing setup, or offering a fallback. Continue other independent requests. Keep collection in the foreground until completion or a reported blocker unless the user requested detachment. Merely discussing or configuring a tool is not delegation."
1
+ "For work assigned to an external agent, model, or separate harness session, load the installed agent-integration skill before choosing tools and use Delegate. This includes research, implementation, testing, review, consultation, comparison, and debate, including external collaboration you choose. Discover destinations through Delegate. Preserve requested model IDs, effort, and permissions; do not guess ambiguous model identifiers. For task commands, pass --root \"${DELEGATE_ROOT:-$HOME/delegation-state}\" directly in each shell invocation; reuse that root for dispatch, observation, and continuation, never an invented /tmp root. If the user explicitly requests another root, use that exact path consistently. Keep each concurrent request and its response associated separately. Capture each dispatch response and exit status once; after task_record created, observe that task ID. Never dispatch again merely to recover output or inspect its exit status. Naming a CLI identifies the destination, not a request to bypass Delegate. Earlier assistant-generated direct-launch workflows do not override this preference. Native same-harness subagents remain available unless a separate session is requested. Respect an explicit user choice of another integration; otherwise do not substitute provider CLIs, plugins, or APIs after a Delegate blocker. A stop_and_report failure ends that attempt: report it without retrying, diagnosing setup, or offering a fallback. Continue other independent requests. Keep collection in the foreground until completion or a reported blocker unless the user requested detachment. Pending work is observed through Delegate status, collect, or events, not OS process searches or supervisor commands. Merely discussing or configuring a tool is not delegation."
@@ -9,4 +9,18 @@ script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
9
9
  rule_file="$script_dir/../references/routing-rule.json"
10
10
  # Read before emitting anything so a missing asset cannot produce partial JSON.
11
11
  rule=$(cat "$rule_file")
12
- printf '{"hookSpecificOutput":{"hookEventName":"%s","additionalContext":%s}}\n' "$event" "$rule"
12
+ skill_file="$(CDPATH= cd -- "$script_dir/.." && pwd)/SKILL.md"
13
+ DELEGATE_ROUTING_EVENT="$event" DELEGATE_ROUTING_RULE="$rule" DELEGATE_ROUTING_SKILL="$skill_file" awk '
14
+ BEGIN {
15
+ # Paths are task data, not shell code. Escape every JSON control character.
16
+ for (i = 1; i < 32; i++) escapes[sprintf("%c", i)] = sprintf("\\u%04x", i)
17
+ escapes["\\"] = "\\\\"
18
+ escapes["\""] = "\\\""
19
+ path = ENVIRON["DELEGATE_ROUTING_SKILL"]
20
+ for (i = 1; i <= length(path); i++) {
21
+ character = substr(path, i, 1)
22
+ escaped = escaped ((character in escapes) ? escapes[character] : character)
23
+ }
24
+ # The maintained rule is a JSON string. Keep its escaping when prefixing it.
25
+ printf "{\"hookSpecificOutput\":{\"hookEventName\":\"%s\",\"additionalContext\":\"Read the complete agent-integration skill at %s. %s}}\n", ENVIRON["DELEGATE_ROUTING_EVENT"], escaped, substr(ENVIRON["DELEGATE_ROUTING_RULE"], 2)
26
+ }'
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: agent-integration
3
- description: Coordinate external agent, model, and separate harness tasks through Delegate, including research, implementation, tests, reviews, consultations, comparisons, and debates. Use before choosing an external integration; ordinary native subagents and questions about tools remain local.
3
+ description: Use Delegate for work assigned to another agent, model, or separate harness CLI session. Load this before a provider-specific skill or plugin, including when a user names a CLI for research, implementation, tests, reviews, consultations, comparisons, or debates. A named destination still routes through Delegate. Ordinary same-harness subagents and questions about tools remain local; respect an explicit choice of another integration.
4
4
  ---
5
5
 
6
6
  # Delegation Layer
@@ -13,6 +13,8 @@ external harness to do work. Requests such as “ask Codex to review this”,
13
13
  collaboration even when the user never mentions Delegate. The same applies
14
14
  when you decide external expertise is useful to fulfill the user's task.
15
15
  These names are examples; discover supported destinations through the CLI.
16
+ A destination name identifies who should do the work; it does not by itself
17
+ select a provider-specific skill, plugin, or direct CLI integration.
16
18
  “Claude Code Router” and “CCR” mean `ccr:print`, not ordinary Claude Code.
17
19
  For that request, use Delegate with a CCR model alias; a Claude-specific skill
18
20
  or subscription model does not fulfill the requested route.
@@ -36,8 +38,10 @@ not turn that request into an environment-repair task. When a response says
36
38
  `failure.next_action: "stop_and_report"`, that attempt is finished. Include its
37
39
  failure in your final response without opening a clarification dialog to choose
38
40
  a fallback. For `task_record: not_created`, identify the requested destination
39
- and quote the returned `task_id` (if present), `task_record`, `failure`, and
40
- `error`. Do not append inferred state paths or provider-setup diagnoses. Do not run diagnostic commands, retry it, or use another integration.
41
+ and include the saved JSON failure response verbatim. A `task_id` can be returned
42
+ even when no task record was created. Do not infer that an unavailable provider
43
+ is uninstalled or unauthenticated. Do not append inferred state paths or
44
+ provider-setup diagnoses, run diagnostic commands, retry it, or use another integration.
41
45
  Troubleshooting requires a separate user request. Other independently requested
42
46
  tasks may proceed; the failed attempt must remain reported as failed or blocked.
43
47
 
@@ -64,26 +68,38 @@ tasks may proceed; the failed attempt must remain reported as failed or blocked.
64
68
  Delegate owns the supervisor lifecycle. Never install, configure, start,
65
69
  inspect, or repair Pueue, and never poll a task unless the response says its
66
70
  `task_record` is `created`.
67
- 5. Observe with `status` and collect with `collect`. Keep collection in the
71
+ 5. Observe tasks only through Delegate `status`, `collect`, or `events`.
72
+ Do not run `ps`, `pgrep`, process-tree searches, or supervisor commands to
73
+ monitor delegated work. Pending output is normal startup or work in progress;
74
+ empty `pending_requests` means keep collecting, not diagnose the environment.
75
+ Environment diagnostics require a separately requested troubleshooting task.
76
+ Keep collection in the
68
77
  foreground until all requested tasks reach a terminal result or an explicit
69
78
  blocker. Do not end a headless turn promising a background notification.
70
- Pending publication (exit 3) means keep waiting, not success. Only detach
79
+ Pending publication (exit 3) means keep waiting, not success. When the JSON
80
+ includes an outstanding `interaction.pending_requests` batch, follow
81
+ [active-task interaction](references/interaction.md) before waiting again. Only detach
71
82
  when the user explicitly requests it, retaining the exact task IDs.
72
83
  Collection may recover the
73
84
  saved supervisor only to observe an already-requested budget stop; it never
74
85
  launches a provider or retries a task.
75
- 6. If a task is timed out and its JSON says `continuation.resumable: true`, use
86
+ 6. If `failure.next_action` is `recheck`, follow
87
+ [offline recovery](references/result-handling.md#offline-recovery) once for
88
+ that task. Rechecking saved evidence does not run the provider again.
89
+ Otherwise, report a rejected result without redispatching or reading raw
90
+ output as an answer.
91
+ 7. If a task is timed out and its JSON says `continuation.resumable: true`, use
76
92
  `continue --task TASK_ID`, optionally with a new `--brief`. Do not create a
77
93
  fresh unrelated dispatch to replace a resumable task.
78
- 7. Treat `blocked` authentication as unresolved. Do not call it compatible,
94
+ 8. Treat `blocked` authentication as unresolved. Do not call it compatible,
79
95
  successful, or failed provider behavior, and do not invent login commands.
80
- 8. Never put credentials, tokens, or unrestricted provider output in a brief,
96
+ 9. Never put credentials, tokens, or unrestricted provider output in a brief,
81
97
  option, receipt, or agent message.
82
- 9. Permission modes select provider-native behavior, not an independent sandbox.
98
+ 10. Permission modes select provider-native behavior, not an independent sandbox.
83
99
  Providers load their own configuration and extensions. If a task is rejected,
84
100
  report delegate's evidence; do not assume the user's configuration is faulty
85
101
  or remove MCP servers, plugins, settings, or credentials to make it pass.
86
- 10. The model chooses ordinary-task fan-out by issuing independent `dispatch`
102
+ 11. The model chooses ordinary-task fan-out by issuing independent `dispatch`
87
103
  commands concurrently. The private supervisor does not impose a task-count
88
104
  or CPU-based limit. Use this for independent investigation, debate, review,
89
105
  or provider comparison. Concurrent write tasks must use separate workspaces
@@ -121,7 +137,7 @@ normal task. For an explicitly requested readiness check, see
121
137
  [preflight guidance](references/command-reference.md#checking-readiness).
122
138
 
123
139
  The catalog and `capabilities` response expose supported permission modes,
124
- request options, continuation, and the read-only mechanism. A read-only
140
+ request options, continuation, native interaction, and the read-only mechanism. A read-only
125
141
  capability with `containment: "provider-owned"` selects the provider's native
126
142
  behavior but is not an independent delegate-owned sandbox. Static discovery
127
143
  does not prove authentication or live acceptance; use the dispatch or live
@@ -143,46 +159,74 @@ it remains ambiguous or discovery is unavailable, ask for the exact model ID;
143
159
  do not turn a display name into a guessed alias. An explicit ID needs no such
144
160
  clarification just because it is absent from discovery.
145
161
 
162
+ For planning, consultation, debate, or other external work that may need
163
+ answers or guidance while it runs, read [active-task interaction](references/interaction.md)
164
+ and use `--interactive` when supported. Answer known facts yourself; ask the
165
+ user for missing preferences, authorization, or scope. Keep ordinary native
166
+ subagents available under the same-harness rule above.
167
+
146
168
  ### 3. Prepare separate paths and a finite brief
147
169
 
148
170
  Use an existing task brief when one is supplied. Otherwise create a bounded
149
171
  brief file that contains the requested work and its acceptance criteria. Keep
150
172
  the state root outside the workspace and provider-writable trees (which can
151
- include the system temporary directory). Use `DELEGATE_ROOT` when supplied:
173
+ include the system temporary directory). Use `DELEGATE_ROOT` when supplied.
174
+ Pass a regular file path for `--brief`, not shell process substitution such as
175
+ `<(...)` or an ephemeral `/dev/fd/...` path.
152
176
 
153
177
  Run path preparation and dispatch in **one shell/tool invocation**, as shown
154
178
  below. Shell variables may disappear between tool calls. For later commands,
155
179
  use the actual saved absolute paths or assign them again in that invocation;
156
180
  never pass an empty `--root`, `--brief`, or `--cwd`.
157
181
 
158
- Replace the example brief below with the actual user request. Do not place the state
182
+ Write the brief as the **worker’s own assignment**, not a copy of the
183
+ orchestration request. For “consult another agent about X”, tell the worker
184
+ “Investigate X and return your findings; you are the assigned worker, do not
185
+ delegate this assignment.” Keep dispatching, answering questions, and
186
+ collecting results in the lead session unless recursive delegation was
187
+ explicitly requested.
188
+
189
+ Replace the example brief below with that bounded worker assignment. Do not place the state
159
190
  root inside the workspace or place secrets in either path’s task data. Keep it
160
191
  outside provider configuration and runtime directories as well. If delegate
161
192
  rejects a caller-supplied state root, report the placement error rather than
162
- silently replacing that root. If no root was supplied, choose one outside the
163
- workspace and reuse it. Do not change provider settings. Retain the selected
164
- root for every observation and continuation.
193
+ silently replacing that root. For every task command, use
194
+ `--root "${DELEGATE_ROOT:-$HOME/delegation-state}"` as shown below. This reads the supplied root in each shell call and uses the
195
+ same default when none was supplied; no root setup or new directory choice is
196
+ needed. If the user explicitly requests another root, substitute that exact
197
+ absolute path consistently. Do not change provider settings or switch roots
198
+ when waiting, replying, steering, or continuing.
165
199
 
166
200
  ### 4. Dispatch one bounded turn
167
201
 
168
202
  Use automatic selection unless the user named a destination.
169
203
  For a named harness or provider resolved in step 2, replace `--auto` with `--provider PROVIDER_ID`; never
170
- combine the two:
204
+ combine the two.
205
+
206
+ Capture the dispatch exit code with `if`, as below. This prints the response
207
+ even when dispatch fails and the surrounding shell has `set -e` enabled.
171
208
 
172
209
  ```sh
173
- STATE_ROOT="${DELEGATE_ROOT:-$HOME/delegation-state}"
174
210
  WORKSPACE="$PWD"
175
211
  BRIEF="$(mktemp)"
212
+ RESPONSE="$(mktemp)"
176
213
  cat >"$BRIEF" <<'EOF'
177
214
  Describe the delegated task, the files or behavior to change, and the checks
178
215
  that must pass. Keep the response concise and report validation evidence.
179
216
  EOF
180
- delegate --root "$STATE_ROOT" dispatch --auto \
217
+ printf 'Saved response: %s\n' "$RESPONSE"
218
+ if delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" dispatch --auto \
181
219
  --brief "$BRIEF" \
182
220
  --cwd "$WORKSPACE" \
183
221
  --permission read-only \
184
222
  --budget 30m \
185
- --json
223
+ --json >"$RESPONSE"; then
224
+ dispatch_exit=0
225
+ else
226
+ dispatch_exit=$?
227
+ fi
228
+ cat "$RESPONSE"
229
+ printf '\nDispatch exit: %s; saved response: %s\n' "$dispatch_exit" "$RESPONSE"
186
230
  ```
187
231
 
188
232
  For an authorized code change, use `--permission workspace-write`; this requests
@@ -201,6 +245,12 @@ files, never background commands writing to the same stdout. Read
201
245
  [parallel reviews and debates](references/collaboration.md) when coordinating
202
246
  multiple participants or challenge rounds.
203
247
 
248
+ Capture the response and exit status in the **original** dispatch invocation,
249
+ as above. Read the saved response if you need it again. Never repeat dispatch
250
+ to obtain its exit code, recover output, or confirm that it worked: each call
251
+ can create new paid work. Once a response says `task_record: created`, save its
252
+ `task_id` and switch to observation. A missing exit code does not undo admission.
253
+
204
254
  Save the exact `task_id` from the JSON response. Apply this decision separately
205
255
  for **each attempt**, including requests issued together:
206
256
 
@@ -219,16 +269,20 @@ never retry that uncertain ID or run Pueue commands.
219
269
 
220
270
  ### 5. Observe and collect
221
271
 
222
- Use the same state root and task ID:
272
+ Use the same state root and task ID. Each command below resolves the root
273
+ in its own shell call, so it does not depend on a previous shell variable:
223
274
 
224
275
  ```sh
225
- delegate --root "$STATE_ROOT" status TASK_ID --json
226
- delegate --root "$STATE_ROOT" collect TASK_ID --watch 5s --json
276
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" status TASK_ID --json
277
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" collect TASK_ID --watch 5s --json
227
278
  ```
228
279
 
229
280
  Check `status` first: if it is `timed_out`, follow step 6 even when publication
230
- is pending and no outcome is present. Otherwise, if `collect` exits with code
231
- `3` because publication is still pending, wait a short interval and run
281
+ is pending and no outcome is present. If `interaction.pending_requests` is
282
+ nonempty and the interaction is not closed, answer the questions using
283
+ [active-task interaction](references/interaction.md) before collecting again.
284
+ Otherwise, if `collect` exits with code `3` because publication is still
285
+ pending, wait a short interval and run
232
286
  `collect` again. Do not dispatch again. Continue until
233
287
  the response has a terminal `outcome` or a bounded operational error that
234
288
  requires the caller’s attention.
@@ -56,6 +56,46 @@
56
56
  "name": "write-timeout",
57
57
  "prompt": "An authorized write task has status timed_out, publication unknown, no outcome, and continuation.resumable true.",
58
58
  "expected": ["delegate continue --task", "same state root", "new task id", "do not wait indefinitely for an outcome", "no fresh unrelated dispatch"]
59
+ },
60
+ {
61
+ "name": "admitted-without-explicit-exit-marker",
62
+ "prompt": "Dispatch returned task_record created, admission admitted, and a task_id. The shell output did not include a separate EXIT marker. Confirm the task and collect its result.",
63
+ "expected": ["use status with returned task_id", "read saved dispatch response if needed", "do not dispatch again to print an exit code", "exactly one admitted task for the assignment"]
64
+ },
65
+ {
66
+ "name": "supplied-root-across-shell-calls",
67
+ "prompt": "DELEGATE_ROOT is already set. Consult a separate external agent and answer its questions; each shell tool call starts a new shell.",
68
+ "expected": ["use supplied DELEGATE_ROOT on dispatch, status, collect, reply, steer, and continue", "resolve the same root in each shell call", "no invented task-specific root"]
69
+ },
70
+ {
71
+ "name": "pending-without-questions",
72
+ "prompt": "The admitted task is running. Collect exits 3 with pending publication, empty pending_requests, and no operational error.",
73
+ "expected": ["keep collecting the same task", "no ps or pgrep or process-tree inspection", "no supervisor commands", "no duplicate dispatch", "answer through delegate reply when a question appears"]
74
+ },
75
+ {
76
+ "name": "interactive-worker-assignment",
77
+ "prompt": "Consult a separate external agent about a pricing plan and answer its questions from README.md.",
78
+ "expected": ["brief assigns the pricing investigation directly", "worker does not recruit another external agent", "lead answers through delegate reply", "do not copy the orchestration request verbatim"]
79
+ },
80
+ {
81
+ "name": "interactive-clarification",
82
+ "prompt": "An external planning task returned pending.kind interaction with question IDs, choices, and free_text false. The requested preference is not in the user brief.",
83
+ "expected": ["read references/interaction.md", "ask user for missing preference", "reply through delegate with exact request and question IDs", "stable message ID", "continue collecting"]
84
+ },
85
+ {
86
+ "name": "interactive-steering",
87
+ "prompt": "The user adds guidance while an interactive external task is running and its capabilities advertise steering.",
88
+ "expected": ["delegate steer", "preserve task model permission and budget", "do not cancel and redispatch", "receipt is not completion"]
89
+ },
90
+ {
91
+ "name": "interactive-unknown-delivery",
92
+ "prompt": "A reply submission lost its CLI response. Its recorded delivery is unknown.",
93
+ "expected": ["same message ID and exact content to retrieve receipt", "no new message ID retry", "no native CLI bypass", "observe task"]
94
+ },
95
+ {
96
+ "name": "interactive-unsupported-destination",
97
+ "prompt": "A named external provider supports continuation but neither native clarification nor steering. The user wants a discussion with it.",
98
+ "expected": ["preserve named provider", "ordinary bounded turns and continuation", "explain no active-turn questions", "do not pass unsupported interactive flag"]
59
99
  }
60
100
  ]
61
101
  }
@@ -199,6 +199,32 @@
199
199
  ],
200
200
  "split": "validation"
201
201
  },
202
+ {
203
+ "name": "recheck-recoverable",
204
+ "prompt": "Ask a separate Codex CLI session to review pricing.py against README.md without editing. If the terminal result is rejected with failure.next_action=recheck, recheck the same task once and report only the verified recovered answer.",
205
+ "external": true,
206
+ "provider": "codex:exec",
207
+ "fixture_scenario": "recoverable-rejection",
208
+ "holdout": true,
209
+ "split": "validation"
210
+ },
211
+ {
212
+ "name": "recheck-still-rejected",
213
+ "prompt": "Ask a separate Codex CLI session to review pricing.py against README.md without editing. If the terminal result is rejected with failure.next_action=recheck, recheck the same task once and report the rejection without using raw output as an answer.",
214
+ "external": true,
215
+ "provider": "codex:exec",
216
+ "fixture_scenario": "still-rejected-recheck",
217
+ "holdout": true,
218
+ "split": "validation"
219
+ },
220
+ {
221
+ "name": "external-collaboration-holdout",
222
+ "prompt": "Ask a separate Codex CLI session to review pricing.py against README.md and report its finding without editing.",
223
+ "external": true,
224
+ "provider": "codex:exec",
225
+ "holdout": true,
226
+ "split": "validation"
227
+ },
202
228
  {
203
229
  "name": "requested-model-effort",
204
230
  "prompt": "Ask a separate Codex CLI session to review pricing.py without edits. Use model gpt-5.6-luna and effort max, preserving both choices.",
@@ -1,8 +1,8 @@
1
1
  # JSON decision sketch
2
2
 
3
3
  ```sh
4
- delegate --root "$STATE_ROOT" status "$TASK_ID" --json
5
- delegate --root "$STATE_ROOT" collect "$TASK_ID" --watch 5s --json
4
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" status "$TASK_ID" --json
5
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" collect "$TASK_ID" --watch 5s --json
6
6
  ```
7
7
 
8
8
  Decision order:
@@ -1,10 +1,9 @@
1
1
  # Read-only task
2
2
 
3
3
  ```sh
4
- STATE_ROOT="${DELEGATE_ROOT:-$HOME/delegation-state}"
5
4
  BRIEF="$(mktemp)"
6
5
  printf '%s\n' 'Inspect the workspace and summarize the current test failures. Do not edit files.' >"$BRIEF"
7
- delegate --root "$STATE_ROOT" dispatch --auto \
6
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" dispatch --auto \
8
7
  --brief "$BRIEF" --cwd "$PWD" --permission read-only --budget 15m --json
9
8
  ```
10
9
 
@@ -1,8 +1,7 @@
1
1
  # Authorized workspace write task
2
2
 
3
3
  ```sh
4
- STATE_ROOT="${DELEGATE_ROOT:-$HOME/delegation-state}"
5
- delegate --root "$STATE_ROOT" dispatch --auto \
4
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" dispatch --auto \
6
5
  --brief "$PWD/delegated-task.md" --cwd "$PWD" \
7
6
  --permission workspace-write --budget 30m --json
8
7
  ```
@@ -19,14 +19,14 @@ RECEIPTS="$(mktemp -d)" || exit 1
19
19
  # Set these absolute paths and catalog IDs in this same tool invocation.
20
20
  # BRIEF_A and BRIEF_B contain the real independent assignments.
21
21
  (
22
- delegate --root "$STATE_ROOT" dispatch --provider "$PROVIDER_A" \
22
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" dispatch --provider "$PROVIDER_A" \
23
23
  --brief "$BRIEF_A" --cwd "$WORKSPACE_A" \
24
24
  --permission read-only --budget 30m --json \
25
25
  >"$RECEIPTS/review-a.json" 2>"$RECEIPTS/review-a.stderr"
26
26
  printf '%s\n' "$?" >"$RECEIPTS/review-a.exit"
27
27
  ) &
28
28
  (
29
- delegate --root "$STATE_ROOT" dispatch --provider "$PROVIDER_B" \
29
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" dispatch --provider "$PROVIDER_B" \
30
30
  --brief "$BRIEF_B" --cwd "$WORKSPACE_B" \
31
31
  --permission read-only --budget 30m --json \
32
32
  >"$RECEIPTS/review-b.json" 2>"$RECEIPTS/review-b.stderr"
@@ -13,7 +13,11 @@ All paths passed to `--root`, `--cwd`, and `--brief` must be absolute. Add
13
13
  | `delegate dispatch --auto ... --json` | Select and admit one bounded turn | Yes, at most once |
14
14
  | `delegate status TASK --json` | Reconcile and observe task state | No provider launch |
15
15
  | `delegate collect TASK --watch 5s --json` | Read or wait for publication | No provider launch |
16
+ | `delegate recheck TASK --json` | Reassess eligible rejected evidence offline | No provider launch; original outcome unchanged |
16
17
  | `delegate continue --task TASK ... --json` | Create an exact-session successor | Yes, at most once for the successor |
18
+ | `delegate reply TASK --request ID --answers FILE --id MESSAGE_ID --json` | Answer a pending native question | No new launch |
19
+ | `delegate steer TASK --brief FILE --id MESSAGE_ID --json` | Guide a supported active turn | No new launch |
20
+ | `delegate events TASK --after SEQUENCE --watch 5s --json` | Read a bounded interaction event page | No |
17
21
  | `delegate logs TASK --json` | Return validated output descriptors | No |
18
22
  | `delegate cancel TASK --json` | Record one explicit stop request | Stops, does not relaunch |
19
23
 
@@ -30,9 +34,11 @@ Dispatch flags:
30
34
  - `--auto`: let the CLI select a ready provider;
31
35
  - `--provider ID`: preserve the caller’s named harness or provider, resolved through the catalog;
32
36
  - `--model MODEL` and `--effort VALUE`: provider-advertised choices (CCR requires a model alias);
33
- Codex maps effort to TOML `model_reasoning_effort`, while Claude and AGY
37
+ Codex maps effort to TOML `model_reasoning_effort` for ordinary turns or a native
38
+ turn parameter for interactive turns, while Claude and AGY
34
39
  pass native effort flags; Pi maps effort to `--thinking`; OpenCode maps it to
35
40
  `--variant`; CCR forwards effort to Claude and uses `--model` as a CCR alias; `default` is omitted;
41
+ - `--interactive`: enable advertised native clarification and steering; see [interaction](interaction.md);
36
42
  - `--native-timeout DURATION`: optional provider-native timeout where advertised.
37
43
 
38
44
  Model discovery uses the same `--provider ID` profiles and accepts an optional
@@ -47,7 +53,8 @@ Continuation flags:
47
53
 
48
54
  - `--task TASK`: predecessor task ID;
49
55
  - `--brief FILE`: optional new follow-up instruction;
50
- - `--budget DURATION`, `--model MODEL`, and `--effort VALUE`: optional overrides.
56
+ - `--budget DURATION`, `--model MODEL`, and `--effort VALUE`: optional overrides;
57
+ - `--interactive`: enable interaction when supported; already-interactive predecessors keep it.
51
58
 
52
59
  ## Choosing models and effort
53
60
 
@@ -17,7 +17,7 @@ When `status` or `collect` reports a timed-out turn with:
17
17
  run:
18
18
 
19
19
  ```sh
20
- delegate --root "$STATE_ROOT" continue \
20
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" continue \
21
21
  --task PREDECESSOR_TASK_ID \
22
22
  --brief FOLLOW_UP_BRIEF \
23
23
  --budget 30m \
@@ -0,0 +1,110 @@
1
+ # Questions and guidance during an active task
2
+
3
+ Use this reference when an external task may need clarification or guidance
4
+ before it finishes, including planning, consultation, and debate. Use only
5
+ Delegate commands; do not open a terminal session with the provider.
6
+
7
+ ## Choose the transport
8
+
9
+ Read the selected provider's `interaction` capability and
10
+ `interaction.supported_modes`. `clarification` and `steering` are independent.
11
+ Add `--interactive` to dispatch when the chosen provider and permission mode
12
+ support the interaction you need. Keep the user's exact provider, model,
13
+ effort, workspace, permission, and budget.
14
+
15
+ Without a named provider, `dispatch --auto --interactive` selects among
16
+ providers that support interaction. If a named provider does not support it,
17
+ use ordinary bounded turns and `continue` for discussion when native
18
+ continuation is available. Explain that questions cannot be answered during
19
+ that provider's active turn. Never replace the requested provider silently.
20
+
21
+ In the worker brief, explicitly request **native structured clarification**:
22
+ "Use your native question tool to request clarification and await its answer.
23
+ Do not ask only in final text or a progress message and then sleep: the lead
24
+ can answer structured requests, not an unstructured prompt. If the question
25
+ tool is unavailable, report that blocker and finish instead of waiting."
26
+ Assign the actual work directly; the worker should not start another delegate.
27
+
28
+ No change is needed for self-contained tasks that do not need mid-turn input.
29
+ Continuation inherits interaction from its predecessor. `continue --task ID
30
+ --interactive` can enable it for a previously ordinary task.
31
+
32
+ ## Respond to questions
33
+
34
+ 1. Save the admitted task ID and state root. Run `collect TASK_ID --watch 30s
35
+ --json` with that same root. Exit 3 is pending, not completion. Collection
36
+ returns early when there is an outstanding native question.
37
+ 2. Read `interaction.pending_requests`. Use the returned request ID, question
38
+ IDs, options, `multiple`, and `free_text`; do not invent or guess IDs.
39
+ 3. Answer facts already supplied by the user or verified during the task.
40
+ Ask the user for missing preferences, business decisions, new scope, or
41
+ authorization. Do not guess an answer to keep the worker moving. A question
42
+ reply does not approve tool access or change the task's permission mode.
43
+ 4. Write one JSON object mapping **every question ID in that request** to an
44
+ array of answer strings. A single-choice question takes one value. Use exact
45
+ option labels unless `free_text` permits another answer. Example:
46
+
47
+ ```json
48
+ {"color": ["Blue"], "sections": ["Summary", "Evidence"]}
49
+ ```
50
+
51
+ 5. Allocate a new 32-character lowercase hexadecimal message ID and save it
52
+ together with the exact answers. Submit once:
53
+
54
+ ```sh
55
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" reply "$task_id" \
56
+ --request "$request_id" --answers "$answers_file" \
57
+ --id "$message_id" --json
58
+ ```
59
+
60
+ 6. Keep collecting. A receipt is not task completion. Only the task's
61
+ authoritative `outcome` establishes the final result.
62
+
63
+ Use the same root expression for dispatch, collection, reply, and steering.
64
+ If the user explicitly chose another root, use that exact path for all of
65
+ them. The other variables stand for actual values saved from this task;
66
+ reassign them in each shell invocation if your tool does not preserve variables.
67
+ A pending response without questions means keep collecting, not inspect OS
68
+ processes or dispatch a replacement task.
69
+
70
+ ## Guide active work
71
+
72
+ When `interaction.capabilities.steering` is true and the task is active, put
73
+ additional guidance in a brief file and submit:
74
+
75
+ ```sh
76
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" steer "$task_id" \
77
+ --brief "$guidance_file" --id "$message_id" --json
78
+ ```
79
+
80
+ Steering is guidance to the existing turn. It does not change provider, model,
81
+ effort, workspace, permission, or budget. Once the turn ends, use `continue`
82
+ for another authorized turn instead. Do not cancel and redispatch simply to
83
+ send guidance.
84
+
85
+ ## Interpret delivery precisely
86
+
87
+ | State | What it establishes |
88
+ | --- | --- |
89
+ | `queued` | Delegate durably accepted the message; native delivery is pending. |
90
+ | `unknown` | Delivery was reserved or attempted, but its result is uncertain. |
91
+ | `sent` | The native input write completed; no native acknowledgement is established. |
92
+ | `acknowledged` | A correlated native response acknowledged the message. This does not prove the model followed guidance. |
93
+ | `rejected` | The message could not be delivered or the native protocol rejected it. Read the reason. |
94
+
95
+ If a submission response was lost, repeat the **same message ID and exact
96
+ content** to recover its receipt. Never allocate a fresh ID to retry an
97
+ `unknown` delivery. Delegate will not replay an ambiguous native write.
98
+ Changed content with an existing ID is a conflict. Observe the task instead
99
+ of guessing whether it consumed the message.
100
+
101
+ `events TASK_ID --after SEQUENCE --watch 30s --json` returns a bounded event
102
+ page. Save the returned `cursor` for the next page. Events and interaction
103
+ state are progress evidence, not a replacement for `collect` and `outcome`.
104
+
105
+ Waiting for an answer consumes the original execution budget; it does not
106
+ pause or extend it. `interaction.deadline` shows the recorded wall-clock
107
+ boundary when execution has started. If the task ends while waiting, do not
108
+ reply to the old request. Follow the ordinary continuation guidance only when
109
+ Delegate reports the task resumable. Preserve any verified answers in the new
110
+ brief; uncertain delivery must not become an automatic replay.
@@ -15,10 +15,13 @@ the same as a successful provider result.
15
15
  permits a linked successor even when no outcome has been published.
16
16
  4. If `publication` is committed and `outcome.verdict` is committed, return
17
17
  the result and its payload/evidence descriptors.
18
- 5. If `outcome.verdict` is rejected, report a terminal rejected result with its
19
- refusal and evidence. Do not retry automatically.
20
- 6. Otherwise, if `liveness` is queued or running or publication is pending,
21
- observe the same task again with a finite watch interval.
18
+ 5. If `outcome.verdict` is rejected and `failure.next_action` is `recheck`,
19
+ follow [offline recovery](#offline-recovery) once. Otherwise report the
20
+ terminal rejection with its diagnostic and evidence. Do not redispatch.
21
+ 6. If `pending.kind` is `interaction`, handle the returned questions using
22
+ [interaction guidance](interaction.md) before waiting again. Otherwise, if
23
+ `liveness` is queued or running or publication is pending, observe the same
24
+ task with a finite watch interval.
22
25
  7. If authentication is `blocked`, preserve that neutral state and tell the
23
26
  caller what prerequisite is unavailable without inventing a login command.
24
27
  8. Never relaunch an uncertain task by guessing. Observe only a task whose
@@ -42,3 +45,29 @@ checks static readiness; runtime verification requires the supervised probe.
42
45
  Versions and help are observations, not semantic-version allowlists.
43
46
  Authentication is a separate live gate (`not_run`, `passed`, or `blocked`).
44
47
  Report a blocked prerequisite without inventing a login command or retrying.
48
+
49
+ ## Offline recovery
50
+
51
+ When Delegate returns `failure.next_action: "recheck"`, use the same root and
52
+ exact task ID:
53
+
54
+ ```sh
55
+ delegate --root "${DELEGATE_ROOT:-$HOME/delegation-state}" recheck TASK_ID --json
56
+ ```
57
+
58
+ This command checks the already sealed evidence with an explicitly compatible
59
+ new interpreter. It does not run the provider, contact a service, spend model
60
+ tokens, or change the original outcome.
61
+
62
+ - Exit `0` with `recheck.status: "recovered"`: use only the answer descriptor
63
+ returned for that recheck. Report that the answer was recovered from saved
64
+ evidence. The original `publication` remains `rejected`; do not call the
65
+ original task committed or use recovery to infer continuation permission.
66
+ - Exit `4` with `recheck.status: "rejected"`: report the diagnostic and stop.
67
+ - Exit `1` or `2`, or any response without a verified recovered answer:
68
+ report the error and stop. Do not read raw streams as a substitute answer,
69
+ invent a result path, run a provider directly, or launch a replacement task.
70
+
71
+ Keep the assessment ID and source/target descriptors with the result. Do not
72
+ loop on the same recheck. A separate user request is required for further
73
+ troubleshooting or a new provider task.
@@ -1 +1 @@
1
- "For work assigned to an external agent, model, or separate harness session, load the installed agent-integration skill before choosing tools and use Delegate. This includes research, implementation, testing, review, consultation, comparison, and debate, including external collaboration you choose. Discover destinations through Delegate. Preserve requested model IDs, effort, and permissions; do not guess ambiguous model identifiers. For task commands, set STATE_ROOT=\"${DELEGATE_ROOT:-$HOME/delegation-state}\" and pass --root \"$STATE_ROOT\" in the same shell invocation; reuse that root for dispatch, observation, and continuation, never an invented /tmp root. Keep each concurrent request and its response associated separately. Naming a CLI identifies the destination, not a request to bypass Delegate. Earlier assistant-generated direct-launch workflows do not override this preference. Native same-harness subagents remain available unless a separate session is requested. Respect an explicit user choice of another integration; otherwise do not substitute provider CLIs, plugins, or APIs after a Delegate blocker. A stop_and_report failure ends that attempt: report it without retrying, diagnosing setup, or offering a fallback. Continue other independent requests. Keep collection in the foreground until completion or a reported blocker unless the user requested detachment. Merely discussing or configuring a tool is not delegation."
1
+ "For work assigned to an external agent, model, or separate harness session, load the installed agent-integration skill before choosing tools and use Delegate. This includes research, implementation, testing, review, consultation, comparison, and debate, including external collaboration you choose. Discover destinations through Delegate. Preserve requested model IDs, effort, and permissions; do not guess ambiguous model identifiers. For task commands, pass --root \"${DELEGATE_ROOT:-$HOME/delegation-state}\" directly in each shell invocation; reuse that root for dispatch, observation, and continuation, never an invented /tmp root. If the user explicitly requests another root, use that exact path consistently. Keep each concurrent request and its response associated separately. Capture each dispatch response and exit status once; after task_record created, observe that task ID. Never dispatch again merely to recover output or inspect its exit status. Naming a CLI identifies the destination, not a request to bypass Delegate. Earlier assistant-generated direct-launch workflows do not override this preference. Native same-harness subagents remain available unless a separate session is requested. Respect an explicit user choice of another integration; otherwise do not substitute provider CLIs, plugins, or APIs after a Delegate blocker. A stop_and_report failure ends that attempt: report it without retrying, diagnosing setup, or offering a fallback. Continue other independent requests. Keep collection in the foreground until completion or a reported blocker unless the user requested detachment. Pending work is observed through Delegate status, collect, or events, not OS process searches or supervisor commands. Merely discussing or configuring a tool is not delegation."
@@ -9,4 +9,18 @@ script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
9
9
  rule_file="$script_dir/../references/routing-rule.json"
10
10
  # Read before emitting anything so a missing asset cannot produce partial JSON.
11
11
  rule=$(cat "$rule_file")
12
- printf '{"hookSpecificOutput":{"hookEventName":"%s","additionalContext":%s}}\n' "$event" "$rule"
12
+ skill_file="$(CDPATH= cd -- "$script_dir/.." && pwd)/SKILL.md"
13
+ DELEGATE_ROUTING_EVENT="$event" DELEGATE_ROUTING_RULE="$rule" DELEGATE_ROUTING_SKILL="$skill_file" awk '
14
+ BEGIN {
15
+ # Paths are task data, not shell code. Escape every JSON control character.
16
+ for (i = 1; i < 32; i++) escapes[sprintf("%c", i)] = sprintf("\\u%04x", i)
17
+ escapes["\\"] = "\\\\"
18
+ escapes["\""] = "\\\""
19
+ path = ENVIRON["DELEGATE_ROUTING_SKILL"]
20
+ for (i = 1; i <= length(path); i++) {
21
+ character = substr(path, i, 1)
22
+ escaped = escaped ((character in escapes) ? escapes[character] : character)
23
+ }
24
+ # The maintained rule is a JSON string. Keep its escaping when prefixing it.
25
+ printf "{\"hookSpecificOutput\":{\"hookEventName\":\"%s\",\"additionalContext\":\"Read the complete agent-integration skill at %s. %s}}\n", ENVIRON["DELEGATE_ROUTING_EVENT"], escaped, substr(ENVIRON["DELEGATE_ROUTING_RULE"], 2)
26
+ }'