@ftrdotdev/pi-delegates 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/LICENSE +21 -0
  3. package/OPERATIONS.md +57 -0
  4. package/README.md +448 -2
  5. package/ROADMAP.md +158 -0
  6. package/TESTING.md +1061 -0
  7. package/agents.ts +8 -0
  8. package/examples/README.md +114 -0
  9. package/examples/gated.ts +28 -0
  10. package/index.ts +9 -0
  11. package/package.json +93 -4
  12. package/skills/pi-delegates/SKILL.md +147 -0
  13. package/skills/pi-delegates/references/control.md +159 -0
  14. package/skills/pi-delegates/references/definitions.md +163 -0
  15. package/skills/pi-delegates/references/gates.md +175 -0
  16. package/skills/pi-delegates/references/launch.md +156 -0
  17. package/src/domain/definitions.test.ts +41 -0
  18. package/src/domain/definitions.ts +161 -0
  19. package/src/domain/ids.ts +13 -0
  20. package/src/domain/names.ts +35 -0
  21. package/src/domain/orchestration/admission.ts +78 -0
  22. package/src/domain/orchestration/control.test.ts +1298 -0
  23. package/src/domain/orchestration/control.ts +436 -0
  24. package/src/domain/orchestration/fanout.test.ts +419 -0
  25. package/src/domain/orchestration/fanout.ts +334 -0
  26. package/src/domain/orchestration/gates.test.ts +686 -0
  27. package/src/domain/orchestration/gates.ts +360 -0
  28. package/src/domain/orchestration/launch.test.ts +173 -0
  29. package/src/domain/orchestration/launch.ts +581 -0
  30. package/src/domain/orchestration/requests.test.ts +700 -0
  31. package/src/domain/orchestration/requests.ts +769 -0
  32. package/src/domain/orchestration/review.test.ts +214 -0
  33. package/src/domain/orchestration/review.ts +168 -0
  34. package/src/domain/orchestration/run-wait.test.ts +262 -0
  35. package/src/domain/orchestration/run-wait.ts +256 -0
  36. package/src/domain/orchestration/workflow-section.test.ts +62 -0
  37. package/src/domain/orchestration/workflow-section.ts +99 -0
  38. package/src/domain/orchestration/workflow.test.ts +1425 -0
  39. package/src/domain/orchestration/workflow.ts +705 -0
  40. package/src/domain/run-records.test.ts +27 -0
  41. package/src/domain/run-records.ts +527 -0
  42. package/src/domain/shapes.test.ts +165 -0
  43. package/src/domain/skills.test.ts +466 -0
  44. package/src/domain/skills.ts +97 -0
  45. package/src/domain/tool-schema.test.ts +46 -0
  46. package/src/domain/tool-schema.ts +20 -0
  47. package/src/domain/toolkit.test.ts +201 -0
  48. package/src/domain/toolkit.ts +379 -0
  49. package/src/domain/view.test.ts +739 -0
  50. package/src/domain/view.ts +459 -0
  51. package/src/example.test.ts +15 -0
  52. package/src/extension/commands.test.ts +481 -0
  53. package/src/extension/commands.ts +227 -0
  54. package/src/extension/entry.test.ts +1118 -0
  55. package/src/extension/entry.ts +342 -0
  56. package/src/extension/gate-alerts.test.ts +235 -0
  57. package/src/extension/gate-alerts.ts +143 -0
  58. package/src/extension/guard.test.ts +48 -0
  59. package/src/extension/guard.ts +31 -0
  60. package/src/extension/host-signals.test.ts +20 -0
  61. package/src/extension/host-signals.ts +13 -0
  62. package/src/extension/inspector-command.test.ts +1191 -0
  63. package/src/extension/inspector-command.ts +638 -0
  64. package/src/extension/prompt.test.ts +110 -0
  65. package/src/extension/prompt.ts +50 -0
  66. package/src/extension/request-alerts.test.ts +183 -0
  67. package/src/extension/request-alerts.ts +181 -0
  68. package/src/extension/revocation.test.ts +81 -0
  69. package/src/extension/revocation.ts +84 -0
  70. package/src/extension/shortcut.test.ts +64 -0
  71. package/src/extension/shortcut.ts +105 -0
  72. package/src/extension/tools.test.ts +993 -0
  73. package/src/extension/tools.ts +505 -0
  74. package/src/extension/version.test.ts +123 -0
  75. package/src/extension/version.ts +97 -0
  76. package/src/harness-policy.test.ts +74 -0
  77. package/src/package-manifest.test.ts +157 -0
  78. package/src/presentation/actions.test.ts +221 -0
  79. package/src/presentation/actions.ts +85 -0
  80. package/src/presentation/activity.test.ts +387 -0
  81. package/src/presentation/activity.ts +66 -0
  82. package/src/presentation/close.test.ts +361 -0
  83. package/src/presentation/inspector.test.ts +679 -0
  84. package/src/presentation/inspector.ts +440 -0
  85. package/src/presentation/overlay.test.ts +555 -0
  86. package/src/presentation/overlay.ts +229 -0
  87. package/src/presentation/repaint.test.ts +329 -0
  88. package/src/presentation/shortcut.ts +2 -0
  89. package/src/presentation/snapshot.test.ts +530 -0
  90. package/src/presentation/snapshot.ts +306 -0
  91. package/src/presentation/strip.test.ts +196 -0
  92. package/src/presentation/strip.ts +74 -0
  93. package/src/presentation/wording.test.ts +238 -0
  94. package/src/presentation/wording.ts +222 -0
  95. package/src/runtime/bridge.test.ts +131 -0
  96. package/src/runtime/bridge.ts +134 -0
  97. package/src/runtime/config.test.ts +44 -0
  98. package/src/runtime/config.ts +87 -0
  99. package/src/runtime/context.test.ts +19 -0
  100. package/src/runtime/context.ts +9 -0
  101. package/src/runtime/execution-env.test.ts +35 -0
  102. package/src/runtime/execution-env.ts +15 -0
  103. package/src/runtime/extensions.test.ts +86 -0
  104. package/src/runtime/extensions.ts +140 -0
  105. package/src/runtime/log.test.ts +128 -0
  106. package/src/runtime/log.ts +68 -0
  107. package/src/runtime/mcp.test.ts +1453 -0
  108. package/src/runtime/mcp.ts +938 -0
  109. package/src/runtime/models.test.ts +145 -0
  110. package/src/runtime/models.ts +259 -0
  111. package/src/runtime/observe.test.ts +50 -0
  112. package/src/runtime/observe.ts +150 -0
  113. package/src/runtime/session.test.ts +359 -0
  114. package/src/runtime/session.ts +425 -0
  115. package/src/runtime/timers.test.ts +31 -0
  116. package/src/runtime/timers.ts +10 -0
package/agents.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The `@ftrdotdev/pi-delegates/agents` subpath: the declarative definition surface,
3
+ * re-exported without the extension factory.
4
+ */
5
+ export { defineAgent, presets } from "./src/domain/definitions.ts";
6
+ export { ApprovalRule } from "./src/domain/toolkit.ts";
7
+ export type { AgentDefinition } from "./src/domain/definitions.ts";
8
+ export type { ApprovalRule as ApprovalRuleType } from "./src/domain/toolkit.ts";
@@ -0,0 +1,114 @@
1
+ # Examples
2
+
3
+ ## Gated fanout
4
+
5
+ This example registers one gated agent and runs it beside two presets. The gate
6
+ parks the `vault-scout` shell call before it runs. The other children answer
7
+ while it waits.
8
+
9
+ ### 1. Scratch repository
10
+
11
+ ```bash
12
+ mkdir -p /tmp/pi-delegates-example/repo /tmp/pi-delegates-example/sessions
13
+ cd /tmp/pi-delegates-example/repo
14
+ git init
15
+ printf 'hello\n' > note.txt
16
+ printf 'hunter2\n' > vault.txt
17
+ printf 'alpha line\n' > alpha.txt
18
+ printf 'beta line\n' > beta.txt
19
+ ```
20
+
21
+ ### 2. Start Pi
22
+
23
+ ```bash
24
+ pi -ne --session-dir /tmp/pi-delegates-example/sessions \
25
+ -e <checkout>/packages/delegates/examples/gated.ts \
26
+ --skill <checkout>/packages/delegates/skills/pi-delegates
27
+ ```
28
+
29
+ - `-e` loads only the example file. It imports the factory and registers
30
+ `vault-scout`.
31
+ - `-ne` disables other extensions, so a globally installed
32
+ `@ftrdotdev/pi-delegates` cannot load twice.
33
+ - `--skill` loads the shipped skill. `-e` loads the extension only.
34
+ - Do not also pass `-e <checkout>/packages/delegates`. Two copies register the
35
+ tools twice.
36
+
37
+ ### 3. Launch
38
+
39
+ Ask the model to call `delegate_launch` once:
40
+
41
+ ```json
42
+ {
43
+ "request": {
44
+ "kind": "fanout",
45
+ "lane": "gate-demo",
46
+ "agents": [
47
+ { "agent": "scout", "task": "read alpha.txt and beta.txt and report both lines" },
48
+ { "agent": "scout", "task": "read note.txt and reply with its only line" },
49
+ {
50
+ "agent": "vault-scout",
51
+ "task": "run the shell command cat vault.txt and report the output line"
52
+ }
53
+ ]
54
+ }
55
+ }
56
+ ```
57
+
58
+ Expect:
59
+
60
+ ```text
61
+ Run <run id> waits for gate vault-access.
62
+ ```
63
+
64
+ ### 4. Inspect
65
+
66
+ Call `delegate_status` with `{ "run": "<run id>" }`. Expect:
67
+
68
+ ```text
69
+ run:<...>#1 fanout waiting waiting on gate vault-access · 3 children
70
+ child 0 ... scout answered: alpha line / beta line
71
+ child 1 ... scout answered: hello
72
+ child 2 ... vault-scout waiting
73
+ ```
74
+
75
+ The secret is not in the status while the gate is pending.
76
+
77
+ ### 5. Decide
78
+
79
+ Approve:
80
+
81
+ ```json
82
+ { "action": "approve", "run": "<run id>", "gate": "vault-access", "note": "example" }
83
+ ```
84
+
85
+ Expect `approve <run id>: <status>`. If the status is still `running`, poll
86
+ `delegate_status`. The parked `bash` call now runs.
87
+
88
+ Deny instead:
89
+
90
+ ```json
91
+ { "action": "deny", "run": "<run id>", "gate": "vault-access", "note": "example" }
92
+ ```
93
+
94
+ The parked `bash` call returns `Gate vault-access was denied; bash did not run.`
95
+
96
+ ### What to look for
97
+
98
+ - The gate parks before `cat vault.txt` runs.
99
+ - Two `scout` children answer while the third waits.
100
+ - Approval unlocks every later call that matches the same rule in that run, not
101
+ just this one. It is not a per-call approval.
102
+ - `match` gates `bash` only. A rule with `match` on `read` never fires. To gate
103
+ `read`, omit `match`, which parks every read in that child.
104
+
105
+ Rule fields and automation routes are in
106
+ [../skills/pi-delegates/references/gates.md](../skills/pi-delegates/references/gates.md).
107
+ Definition fields are in
108
+ [../skills/pi-delegates/references/definitions.md](../skills/pi-delegates/references/definitions.md).
109
+
110
+ ### Cleanup
111
+
112
+ ```bash
113
+ rm -rf /tmp/pi-delegates-example
114
+ ```
@@ -0,0 +1,28 @@
1
+ /**
2
+ * A one-file definition for a scratch checkout.
3
+ *
4
+ * Load it as the only extension:
5
+ *
6
+ * pi -ne -e <checkout>/packages/delegates/examples/gated.ts
7
+ *
8
+ * Do not also load `packages/delegates`, or the tools register twice.
9
+ */
10
+ import { createDelegatesExtension } from "../index.ts";
11
+ import { defineAgent } from "../agents.ts";
12
+
13
+ export const vaultScout = defineAgent({
14
+ name: "vault-scout",
15
+ role: "Gated vault scout",
16
+ prompt: {
17
+ role:
18
+ "You run the shell command you are asked for and report its output. " +
19
+ "You cannot change files.",
20
+ },
21
+ tools: ["read", "bash"],
22
+ extensions: ["coding-tools"],
23
+ approval: {
24
+ gates: [{ name: "vault-access", tools: ["bash"], match: "vault" }],
25
+ },
26
+ });
27
+
28
+ export default createDelegatesExtension({ definitions: [vaultScout] });
package/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The package root. A local extension re-exports `createDelegatesExtension`
3
+ * with its own definitions. The `@ftrdotdev/pi-delegates/agents` subpath exposes the
4
+ * declarative surface without the factory.
5
+ */
6
+ import { createDelegatesExtension } from "./src/extension/entry.ts";
7
+
8
+ export { createDelegatesExtension } from "./src/extension/entry.ts";
9
+ export default createDelegatesExtension();
package/package.json CHANGED
@@ -1,6 +1,95 @@
1
1
  {
2
2
  "name": "@ftrdotdev/pi-delegates",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Durable agent delegation for Pi",
5
+ "keywords": [
6
+ "durable",
7
+ "effect",
8
+ "extension",
9
+ "pi",
10
+ "pi-coding-agent",
11
+ "pi-package",
12
+ "subagents"
13
+ ],
14
+ "homepage": "https://github.com/felixnorden/pi-mono/blob/main/packages/delegates/README.md",
15
+ "bugs": {
16
+ "url": "https://github.com/felixnorden/pi-mono/issues"
17
+ },
18
+ "license": "MIT",
19
+ "author": "Felix Nordén <felixnorden@gmail.com>",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/felixnorden/pi-mono.git",
23
+ "directory": "packages/delegates"
24
+ },
25
+ "files": [
26
+ "CHANGELOG.md",
27
+ "index.ts",
28
+ "agents.ts",
29
+ "src",
30
+ "examples",
31
+ "skills/pi-delegates",
32
+ "ROADMAP.md",
33
+ "README.md",
34
+ "TESTING.md",
35
+ "OPERATIONS.md",
36
+ "LICENSE"
37
+ ],
38
+ "type": "module",
39
+ "exports": {
40
+ ".": "./index.ts",
41
+ "./agents": "./agents.ts"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "scripts": {
47
+ "test": "vitest run",
48
+ "test:watch": "vitest",
49
+ "typecheck": "tsc --noEmit",
50
+ "lint": "oxlint && oxlint --type-aware -A all -D typescript/unbound-method",
51
+ "lint:fix": "oxlint --fix",
52
+ "fmt": "oxfmt",
53
+ "fmt:check": "oxfmt --check",
54
+ "check:identity": "bun run scripts/check-dependency-identity.ts"
55
+ },
56
+ "dependencies": {
57
+ "@earendil-works/chord": "1.6.0",
58
+ "@earendil-works/pi-codemode": "1.6.0",
59
+ "@earendil-works/pi-durable": "1.6.0",
60
+ "@earendil-works/pi-mcp": "1.6.0",
61
+ "@earendil-works/pi-schema": "1.6.0",
62
+ "@ftrdotdev/pi-tui": "^0.9.0",
63
+ "effect": "4.1.5"
64
+ },
65
+ "devDependencies": {
66
+ "@earendil-works/pi-ai": "1.6.0",
67
+ "@earendil-works/pi-coding-agent": "1.6.0",
68
+ "@earendil-works/pi-tui": "1.6.0",
69
+ "@effect/tsgo": "0.73.4",
70
+ "@effect/vitest": "4.1.5",
71
+ "@ftrdotdev/pi-test-kit": "0.0.0",
72
+ "@types/bun": "latest",
73
+ "oxfmt": "0.80.0",
74
+ "oxlint": "1.94.0",
75
+ "oxlint-tsgolint": "7.0.2008",
76
+ "typescript": "7.0.2",
77
+ "vitest": "^5.1.0"
78
+ },
79
+ "peerDependencies": {
80
+ "@earendil-works/pi-ai": "*",
81
+ "@earendil-works/pi-coding-agent": "1.6.0",
82
+ "@earendil-works/pi-tui": "*"
83
+ },
84
+ "engines": {
85
+ "node": ">=22.19.0"
86
+ },
87
+ "pi": {
88
+ "extensions": [
89
+ "./index.ts"
90
+ ],
91
+ "skills": [
92
+ "./skills/pi-delegates"
93
+ ]
94
+ }
95
+ }
@@ -0,0 +1,147 @@
1
+ ---
2
+ name: pi-delegates
3
+ description: Runs delegated tasks in durable child conversations and controls the resulting runs. Use when work should run in a separate agent context, when independent tasks can run in parallel, when a delegated run waits on an approval gate, when checking, stopping or resuming delegated runs, or when registering an agent definition with a gate.
4
+ ---
5
+
6
+ # Delegated agents
7
+
8
+ `delegate_launch` runs a task in a child conversation. The child has its own
9
+ context and toolkit. Runs survive a Pi restart.
10
+
11
+ Delegate only when a separate context helps. Do the work directly when one tool
12
+ call answers the question.
13
+
14
+ ## Before you launch
15
+
16
+ Delegate when:
17
+
18
+ - The task needs its own context, and only a summary must return.
19
+ - Two or more tasks are independent and can run at once.
20
+ - The task needs a narrower toolset than this session.
21
+ - The task should keep working after this turn.
22
+
23
+ Do not delegate:
24
+
25
+ - A question that one `read`, `grep`, `find` or `bash` call answers.
26
+ - A task that needs this conversation's history or decisions.
27
+
28
+ The prompt section lists the presets. Registered names come from the user. If a
29
+ name is unknown, the launch error lists the available names. Presets have no
30
+ gates. A registered definition may carry gates.
31
+
32
+ `scout` and `reviewer` have only `read`. They cannot list a directory or run a
33
+ command. Name the files to read. Use `builder` only when the child may change
34
+ files; it also has `write` and `edit`.
35
+
36
+ ## Launch
37
+
38
+ ```json
39
+ {
40
+ "request": {
41
+ "kind": "single",
42
+ "agent": "scout",
43
+ "task": "Read src/index.ts and list its exports."
44
+ }
45
+ }
46
+ ```
47
+
48
+ Three request kinds:
49
+
50
+ | Kind | Use |
51
+ | -------- | ----------------------------------------------- |
52
+ | `single` | One task in one child conversation |
53
+ | `fanout` | Independent tasks in one lane, started together |
54
+ | `review` | Reviewers that each return a disposition |
55
+
56
+ Full shapes, inline definitions and policies are in
57
+ [references/launch.md](references/launch.md).
58
+
59
+ Launch once per task. While a run is live, the same request reuses it. After it
60
+ settles, the same request starts a new attempt. Do not launch a duplicate to
61
+ make a live run finish.
62
+
63
+ ## Handle the result
64
+
65
+ The launch returns text and names the status. A waiting, running, queued,
66
+ stopped, denied or failed result also names the run id. An answered single
67
+ result is the answer. An answered fanout or review result names the run id and
68
+ the group summary.
69
+
70
+ | Status | Action |
71
+ | ---------- | ------------------------------------------------------------------------ |
72
+ | `answered` | Use the answer. Relay it with its evidence. |
73
+ | `waiting` | Ask the user about the gate, unless they asked you to decide. See Gates. |
74
+ | `running` | Keep the run id, do other work, then poll `delegate_status`. |
75
+ | `queued` | Wait for a slot. Keep the run id and poll `delegate_status`. |
76
+ | `failed` | Read the diagnostic. Resume or report. Do not retry blindly. |
77
+ | `stopped` | Resume when the work still matters. |
78
+ | `denied` | Report the denial. Do not retry the same call. |
79
+
80
+ A resume starts a new attempt. If it returns `stopped` again, read the
81
+ per-child cause with `delegate_status` or relaunch a narrower task. Do not
82
+ resume in a loop.
83
+
84
+ A launch waits up to 10 minutes, then returns `running` or `queued`. The run
85
+ keeps working after the tool call returns. A fanout result is a count. A review
86
+ result is the aggregate disposition. Call `delegate_status` to read child
87
+ answers and reviewer notes. A review task must contain the diff or the files to
88
+ read. Reviewers do not see this conversation.
89
+
90
+ ## Status and control
91
+
92
+ Call `delegate_status` with `{}` to list the newest 50 runs. Pass `run` or
93
+ `lane` to narrow the view. It prints one line per run, the gate names in the
94
+ line of a waiting run, child answers, lane counts and reviews. A final line
95
+ counts the older runs it left out.
96
+
97
+ `delegate_control` supports `steer`, `stop`, `resume`, `approve` and `deny`.
98
+ Exact arguments, resume rules and error recovery are in
99
+ [references/control.md](references/control.md).
100
+
101
+ ## Gates
102
+
103
+ A gate parks a tool call until a decision. Gates belong to the agent
104
+ definition. You cannot add or remove one at launch.
105
+
106
+ The mechanism has no human check: any session that can call `delegate_control`
107
+ can decide. The default policy is to ask the user. Do not decide on the user's
108
+ behalf unless the user asked for that policy.
109
+
110
+ 1. Read the run id from the launch text, or from the run line in
111
+ `delegate_status`. A waiting run names its gate on the same line.
112
+ 2. Tell the user what the run wants to do and why it parked.
113
+ 3. Ask for `approve` or `deny`. Do not decide for the user unless they asked
114
+ you to.
115
+ 4. Call `delegate_control` with the run id, gate name and an optional note.
116
+ 5. If it returns `GateAlreadyDecided`, call `delegate_status` and report the
117
+ run status. Do not send the same decision again.
118
+
119
+ One gate can hold several children of a fanout. One decision releases all of
120
+ them. Use the run id on the run line, not a child run id. An approval unlocks
121
+ every later call that matches the same rule in that run; it is not a per-call
122
+ decision.
123
+
124
+ `match` gates `bash` only. A rule with `match` on `read` never parks. To gate
125
+ `read`, omit `match`, which parks every read in that child. Rule fields, scope
126
+ and automation routes are in [references/gates.md](references/gates.md).
127
+
128
+ ## Definitions
129
+
130
+ A registered definition owns the tools, extensions and gate rules of the
131
+ child. The declarative fields, presets and task-shaping rules are in
132
+ [references/definitions.md](references/definitions.md). If the user asks to add
133
+ a gated agent, follow that reference. The package README has the published
134
+ package recipe.
135
+
136
+ A definition may select MCP tools by pattern. A pattern must name its server:
137
+ `mcp__<server>__*`. `mcp__*` is refused, and an unknown namespace fails the
138
+ launch. Only servers that a registered definition references connect, so an
139
+ inline definition can use those tools but cannot bring in a server on its own.
140
+
141
+ ## Limits
142
+
143
+ - The Pi process that owns the session is the only writer. Do not open or copy
144
+ the SQLite store.
145
+ - Lanes and the session have run caps. A large fanout starts in waves and can
146
+ take longer than one wait.
147
+ - Runs and gates survive a restart. Read status before you relaunch work.
@@ -0,0 +1,159 @@
1
+ # Control reference
2
+
3
+ ## Contents
4
+
5
+ - Actions
6
+ - Status
7
+ - Resume
8
+ - Questions
9
+ - Gate decisions
10
+ - Errors
11
+ - Restart
12
+
13
+ ## Actions
14
+
15
+ `delegate_control` takes one action.
16
+
17
+ | Action | Arguments |
18
+ | --------- | ------------------------------ |
19
+ | `steer` | `run`, `message` |
20
+ | `stop` | `run` |
21
+ | `resume` | `run` |
22
+ | `approve` | `run`, `gate`, optional `note` |
23
+ | `deny` | `run`, `gate`, optional `note` |
24
+ | `answer` | `run`, `request`, `answer` |
25
+ | `decline` | `run`, `request` |
26
+
27
+ ```json
28
+ { "action": "steer", "run": "<run id>", "message": "Also check the lockfile." }
29
+ ```
30
+
31
+ - `steer` sends input to a run that is `running` or `waiting`.
32
+ - `stop` aborts the run and waits for it to settle.
33
+ - `approve` and `deny` decide one gate. The call waits up to the launch wait
34
+ for the run to settle, then returns the current view. The run can still be
35
+ running when the call returns.
36
+ - `answer` answers a delegate's question and then waits like a launch: the run
37
+ settles, or it asks its next question. `decline` cancels the question and
38
+ returns at once.
39
+
40
+ ## Status
41
+
42
+ `delegate_status` prints text. It shows:
43
+
44
+ - one line per run: run id, definition and status, with the diagnostic when the
45
+ run failed.
46
+ - `waiting on gate <name>` in the run line when the run waits on a gate.
47
+ - `waiting on request <id>` in the run line when the run waits on a question.
48
+ - a `missing:` line when the definition's tools or extensions cannot resolve.
49
+ - one line per child for a fanout or review.
50
+ - lane counts.
51
+ - one section per review, with each reviewer's disposition and note.
52
+ - a final count of older runs left out when the session has more than 50 runs.
53
+
54
+ Status values:
55
+
56
+ - `queued`: the task exists but no slot or child is active yet.
57
+ - `running`: the child works.
58
+ - `waiting`: the run waits. `waiting on gate` in the run line means a person
59
+ must decide, and `waiting on request` means a person must answer. No gate or
60
+ request name means it waits for children.
61
+ - `answered`: the run has a result. The status line carries a single run's
62
+ answer. Child answers appear on the child lines.
63
+ - `failed`: the diagnostic follows the status.
64
+ - `stopped`: a person or the fanout run aborted it.
65
+ - `denied`: the last gate was denied and the child did not answer.
66
+
67
+ Child run ids appear in the child lines. `steer`, `stop` and `answer` accept a
68
+ child run id. `resume`, `approve` and `deny` use the top-level run id. A fanout
69
+ or review parent has no conversation, so `steer` on it fails; steer a child
70
+ instead.
71
+
72
+ ## Resume
73
+
74
+ Only a `failed` or `stopped` run can resume. A resume keeps the run id and
75
+ starts a new attempt that continues the same child conversation.
76
+
77
+ - A fanout resume keeps children that already answered and starts the others
78
+ again.
79
+ - A resume fails when the definition's tools or extensions cannot resolve now.
80
+ The message lists the missing names and the available ones. Report it. The
81
+ definition owner must fix the registration.
82
+ - Do not resume an `answered` run. It already has a result.
83
+ - Do not resume a `running` run. Poll it.
84
+
85
+ ## Questions
86
+
87
+ A definition that lists `questions` in `extensions` and `ask` in `tools` can put
88
+ one question to the user. The launch returns `waiting` with the request id
89
+ instead of blocking, and the parent message carries the exact `questions`
90
+ parameter.
91
+
92
+ 1. Ask the user with the `question` tool when it exists, otherwise in plain
93
+ text. Never answer for them.
94
+ 2. Send `{ "action": "answer", "run": "<run id>", "request": "<request id>", "answer": "<label or text>" }`
95
+ with their answer. The answer is trimmed; an option number or the label in
96
+ any case stores the label as written.
97
+ 3. When the user cancels the dialog, send
98
+ `{ "action": "decline", "run": "<run id>", "request": "<request id>" }`.
99
+ The child gets an error naming the reason.
100
+ 4. The user can answer without you with `/delegates:answer`; with no argument it
101
+ opens a picker.
102
+
103
+ A question expires 24 hours after it opens. A second answer and an answer
104
+ outside the options are refused. A decided request is pruned seven days after
105
+ it was requested.
106
+
107
+ ## Gate decisions
108
+
109
+ 1. Read the run id from the run line, and the gate name from its
110
+ `waiting on gate` text.
111
+ 2. Send `approve` or `deny` with the user's choice. Put their reason in `note`.
112
+ 3. On success, the control result shows the new run status. If the run is still
113
+ `running`, poll again later.
114
+ 4. On `GateAlreadyDecided`, the gate expired or another decision won. Read
115
+ `delegate_status` and report the run status. Do not send the same decision
116
+ again.
117
+ 5. On `GateNotFound`, the run id or gate name is wrong. List the gates again.
118
+
119
+ A gate expires 24 hours after it opens. The parked call then fails instead of
120
+ running.
121
+
122
+ Only decide a gate when the user asked for that decision. Never approve on the
123
+ user's behalf unless the user asked you to decide.
124
+
125
+ ## Errors
126
+
127
+ These arrive as the tool text, not as an exception.
128
+
129
+ | Message starts with | Meaning | Action |
130
+ | --------------------------------------------------------- | --------------------------------------------------------- | -------------------------------------------- |
131
+ | `Definition "..." not found` | The agent name is unknown | Use a listed name or an inline definition |
132
+ | `Unresolved toolkit names:` | A tool or extension is not loaded | Report it; the owner must fix the definition |
133
+ | `Run ... not found` | The run id is unknown, or status was asked for a child id | Use the run line's id for status |
134
+ | `Run ... is ..., not running; nothing to steer` | The run is not live | Read its status |
135
+ | `Run ... has no child conversation to steer` | A fanout or review parent cannot be steered | Steer a child run instead |
136
+ | `Run ... is ...; only a failed or stopped run can resume` | The run is not resumable | Read its status |
137
+ | `Run ... is missing ...; extensions: ...; tools: ...` | The definition cannot resolve now | Report the missing and available names |
138
+ | `Gate ... of run ... not found` | The run id and gate name do not match | List the pending gates |
139
+ | `Request ... not found` | The run id and request id do not match | List the pending requests |
140
+ | `Request ... is already answered` | Another answer won | Read status; do not answer again |
141
+ | `Request ... is cancelled: declined` or `... expired ...` | The user declined, or the deadline passed | Report it; do not answer again |
142
+ | `An answer must be one of: ...` | The text matches no label and free text is off | Ask again, or use one of the labels |
143
+ | `Gate ... is already ...` or `Gate ... expired ...` | Another decision won, or the gate expired | Read status; do not repeat the decision |
144
+ | `An inline definition cannot set "..."` | The inline definition used an owner-only field | Remove `extensions` or `approval` |
145
+ | `Inline definition "..." adds tools ...` | The inline tools exceed the registered set | Narrow `tools` to the registered set |
146
+
147
+ ## Restart
148
+
149
+ Runs, gates, decisions, questions and answers are durable. After a Pi restart:
150
+
151
+ 1. Call `delegate_status` with `{}`.
152
+ 2. For a `waiting` run, show its gate or its question to the user.
153
+ 3. For a `running` run, poll until it settles.
154
+ 4. Resume a `failed` or `stopped` run only when the work still matters.
155
+ 5. Do not relaunch an `answered` run. Status shows a single answer, and child
156
+ answers or review notes for a group.
157
+
158
+ A hard exit can leave a run `failed` with an orphaned reason. Resume it instead
159
+ of launching the task again.