@ftrdotdev/pi-delegates 0.0.0-stage → 0.2.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.
- package/CHANGELOG.md +128 -0
- package/LICENSE +21 -0
- package/OPERATIONS.md +130 -0
- package/README.md +456 -2
- package/ROADMAP.md +179 -0
- package/TESTING.md +896 -0
- package/agents.ts +8 -0
- package/examples/README.md +114 -0
- package/examples/gated.ts +28 -0
- package/index.ts +9 -0
- package/package.json +94 -4
- package/skills/pi-delegates/SKILL.md +176 -0
- package/skills/pi-delegates/references/control.md +159 -0
- package/skills/pi-delegates/references/definitions.md +163 -0
- package/skills/pi-delegates/references/gates.md +175 -0
- package/skills/pi-delegates/references/launch.md +184 -0
- package/src/docs-contract.test.ts +106 -0
- package/src/domain/definitions.test.ts +41 -0
- package/src/domain/definitions.ts +163 -0
- package/src/domain/failure.ts +33 -0
- package/src/domain/ids.ts +13 -0
- package/src/domain/model-source.ts +30 -0
- package/src/domain/names.ts +35 -0
- package/src/domain/orchestration/admission.ts +78 -0
- package/src/domain/orchestration/control.test.ts +1332 -0
- package/src/domain/orchestration/control.ts +457 -0
- package/src/domain/orchestration/fanout.test.ts +524 -0
- package/src/domain/orchestration/fanout.ts +372 -0
- package/src/domain/orchestration/gates.test.ts +685 -0
- package/src/domain/orchestration/gates.ts +360 -0
- package/src/domain/orchestration/launch.test.ts +372 -0
- package/src/domain/orchestration/launch.ts +691 -0
- package/src/domain/orchestration/requests.test.ts +695 -0
- package/src/domain/orchestration/requests.ts +782 -0
- package/src/domain/orchestration/review.test.ts +292 -0
- package/src/domain/orchestration/review.ts +168 -0
- package/src/domain/orchestration/run-wait.test.ts +265 -0
- package/src/domain/orchestration/run-wait.ts +256 -0
- package/src/domain/orchestration/workflow-section.test.ts +62 -0
- package/src/domain/orchestration/workflow-section.ts +99 -0
- package/src/domain/orchestration/workflow.test.ts +1566 -0
- package/src/domain/orchestration/workflow.ts +778 -0
- package/src/domain/run-records.test.ts +27 -0
- package/src/domain/run-records.ts +689 -0
- package/src/domain/settlement.test.ts +186 -0
- package/src/domain/settlement.ts +137 -0
- package/src/domain/shapes.test.ts +185 -0
- package/src/domain/skills.test.ts +477 -0
- package/src/domain/skills.ts +114 -0
- package/src/domain/tool-schema.test.ts +46 -0
- package/src/domain/tool-schema.ts +20 -0
- package/src/domain/toolkit.test.ts +215 -0
- package/src/domain/toolkit.ts +374 -0
- package/src/domain/turn-budget.test.ts +37 -0
- package/src/domain/turn-budget.ts +23 -0
- package/src/domain/view.test.ts +803 -0
- package/src/domain/view.ts +491 -0
- package/src/example.test.ts +15 -0
- package/src/extension/commands.test.ts +485 -0
- package/src/extension/commands.ts +230 -0
- package/src/extension/entry.test.ts +1276 -0
- package/src/extension/entry.ts +380 -0
- package/src/extension/gate-alerts.test.ts +237 -0
- package/src/extension/gate-alerts.ts +143 -0
- package/src/extension/guard.test.ts +48 -0
- package/src/extension/guard.ts +31 -0
- package/src/extension/host-signals.test.ts +20 -0
- package/src/extension/host-signals.ts +13 -0
- package/src/extension/inspector-command.test.ts +1343 -0
- package/src/extension/inspector-command.ts +685 -0
- package/src/extension/prompt.test.ts +108 -0
- package/src/extension/prompt.ts +50 -0
- package/src/extension/request-alerts.test.ts +183 -0
- package/src/extension/request-alerts.ts +181 -0
- package/src/extension/retry-observer.test.ts +292 -0
- package/src/extension/retry-observer.ts +150 -0
- package/src/extension/revocation.test.ts +81 -0
- package/src/extension/revocation.ts +84 -0
- package/src/extension/settle-alerts.test.ts +579 -0
- package/src/extension/settle-alerts.ts +175 -0
- package/src/extension/shortcut.test.ts +62 -0
- package/src/extension/shortcut.ts +105 -0
- package/src/extension/tools.test.ts +1294 -0
- package/src/extension/tools.ts +553 -0
- package/src/extension/version.test.ts +115 -0
- package/src/extension/version.ts +97 -0
- package/src/goldens.test.ts +294 -0
- package/src/harness-policy.test.ts +76 -0
- package/src/layers.test.ts +309 -0
- package/src/layers.ts +405 -0
- package/src/package-manifest.test.ts +170 -0
- package/src/presentation/actions.test.ts +221 -0
- package/src/presentation/actions.ts +85 -0
- package/src/presentation/activity.test.ts +386 -0
- package/src/presentation/activity.ts +66 -0
- package/src/presentation/close.test.ts +359 -0
- package/src/presentation/inspector.test.ts +682 -0
- package/src/presentation/inspector.ts +442 -0
- package/src/presentation/overlay.test.ts +553 -0
- package/src/presentation/overlay.ts +229 -0
- package/src/presentation/repaint.test.ts +365 -0
- package/src/presentation/shortcut.ts +2 -0
- package/src/presentation/snapshot.test.ts +535 -0
- package/src/presentation/snapshot.ts +306 -0
- package/src/presentation/status.test.ts +43 -0
- package/src/presentation/status.ts +30 -0
- package/src/presentation/strip.test.ts +203 -0
- package/src/presentation/strip.ts +67 -0
- package/src/presentation/wording.test.ts +388 -0
- package/src/presentation/wording.ts +294 -0
- package/src/runtime/bridge.test.ts +131 -0
- package/src/runtime/bridge.ts +128 -0
- package/src/runtime/clock.test.ts +31 -0
- package/src/runtime/clock.ts +31 -0
- package/src/runtime/config.test.ts +63 -0
- package/src/runtime/config.ts +92 -0
- package/src/runtime/context.test.ts +19 -0
- package/src/runtime/context.ts +9 -0
- package/src/runtime/execution-env.test.ts +33 -0
- package/src/runtime/execution-env.ts +15 -0
- package/src/runtime/extensions.test.ts +86 -0
- package/src/runtime/extensions.ts +152 -0
- package/src/runtime/handle.ts +54 -0
- package/src/runtime/log.test.ts +140 -0
- package/src/runtime/log.ts +91 -0
- package/src/runtime/mcp.test.ts +1450 -0
- package/src/runtime/mcp.ts +1005 -0
- package/src/runtime/models.test.ts +145 -0
- package/src/runtime/models.ts +259 -0
- package/src/runtime/observe.test.ts +50 -0
- package/src/runtime/observe.ts +150 -0
- package/src/runtime/runtime-state.test.ts +25 -0
- package/src/runtime/runtime-state.ts +36 -0
- package/src/runtime/session-tag.ts +11 -0
- package/src/runtime/session.test.ts +352 -0
- package/src/runtime/session.ts +263 -0
- package/src/runtime/storage.ts +29 -0
- package/src/test-hygiene.test.ts +97 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Definition reference
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Two shapes
|
|
6
|
+
- Registered definition fields
|
|
7
|
+
- Presets
|
|
8
|
+
- Register a definition
|
|
9
|
+
- Inline definition
|
|
10
|
+
- Task shaping
|
|
11
|
+
- Where names resolve
|
|
12
|
+
|
|
13
|
+
## Two shapes
|
|
14
|
+
|
|
15
|
+
A definition describes a child conversation: its prompt, tools, extensions,
|
|
16
|
+
model, working directory and approval rules.
|
|
17
|
+
|
|
18
|
+
- A **registered definition** is created in a Pi extension and passed to
|
|
19
|
+
`createDelegatesExtension({ definitions: [...] })`. It owns `extensions` and
|
|
20
|
+
`approval`.
|
|
21
|
+
- An **inline definition** is sent inside a `single` launch. It narrows a
|
|
22
|
+
registered definition or defines a one-off agent. It owns neither
|
|
23
|
+
`extensions` nor `approval`.
|
|
24
|
+
|
|
25
|
+
## Registered definition fields
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { defineAgent } from "@ftrdotdev/pi-delegates/agents";
|
|
29
|
+
|
|
30
|
+
const deployer = defineAgent({
|
|
31
|
+
name: "deployer",
|
|
32
|
+
role: "Deploy agent",
|
|
33
|
+
prompt: { role: "You deploy the service and report the result." },
|
|
34
|
+
tools: ["read", "bash"],
|
|
35
|
+
extensions: ["coding-tools"],
|
|
36
|
+
approval: {
|
|
37
|
+
gates: [{ name: "deploy", tools: ["bash"], match: "deploy" }],
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
| Field | Required | Meaning |
|
|
43
|
+
| ---------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
44
|
+
| `name` | yes | The name `delegate_launch` uses. A registered name overrides the preset of the same name. |
|
|
45
|
+
| `role` | yes | Short label in status and the prompt section. |
|
|
46
|
+
| `prompt.role` | yes | The child's role instructions. |
|
|
47
|
+
| `prompt.shared` | no | Text rendered before `prompt.role`. |
|
|
48
|
+
| `tools` | yes | Tool names the child may call. Each name must resolve at launch. |
|
|
49
|
+
| `extensions` | yes | Installed durable extension names. `coding-tools` is the built-in coding extension. `gate-guard` is added automatically when `approval.gates` is non-empty. |
|
|
50
|
+
| `approval.gates` | yes | Gate rules committed with the run's toolkit. Use `{ "gates": [] }` for no gate. See [gates.md](gates.md). |
|
|
51
|
+
| `model` | no | `{ "provider": "...", "modelId": "..." }`. Omitted: the host session's model at launch. |
|
|
52
|
+
| `thinkingLevel` | no | `off`, `minimal`, `low`, `medium`, `high`, `xhigh` or `max`. Omitted: the host session's level at launch. |
|
|
53
|
+
| `cwd` | no | The child's working directory. Omitted: the host session's working directory at launch. |
|
|
54
|
+
|
|
55
|
+
`defineAgent` only types the object. It does not validate names. The launch
|
|
56
|
+
resolves every tool and extension name and fails before a run exists when one
|
|
57
|
+
is missing.
|
|
58
|
+
|
|
59
|
+
## Presets
|
|
60
|
+
|
|
61
|
+
| Preset | Role | Tools |
|
|
62
|
+
| ---------- | -------------------- | ------------------------------- |
|
|
63
|
+
| `scout` | Read-only explorer | `read` |
|
|
64
|
+
| `builder` | Implementation agent | `read`, `bash`, `write`, `edit` |
|
|
65
|
+
| `reviewer` | Review agent | `read` |
|
|
66
|
+
|
|
67
|
+
Presets use the host session's model and thinking level at launch. They carry
|
|
68
|
+
no approval rules.
|
|
69
|
+
|
|
70
|
+
The prompt section lists the presets. `/delegates` lists the presets and every
|
|
71
|
+
registered definition. A registered definition that does not reuse a preset
|
|
72
|
+
name is not added to the prompt section, so an agent knows it only when the
|
|
73
|
+
user names it or the launch error lists it.
|
|
74
|
+
|
|
75
|
+
## Register a definition
|
|
76
|
+
|
|
77
|
+
### From a checkout
|
|
78
|
+
|
|
79
|
+
Load a single definition file. The file imports the package, exports the
|
|
80
|
+
extension factory, and Pi loads no other copy:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pi -ne -e <checkout>/packages/delegates/examples/gated.ts
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
See [examples/README.md](../../../examples/README.md) for the scratch repository
|
|
87
|
+
and the fanout request.
|
|
88
|
+
|
|
89
|
+
### From a published package
|
|
90
|
+
|
|
91
|
+
Create a local package that depends on `@ftrdotdev/pi-delegates` and re-exports
|
|
92
|
+
the factory. Follow "Register an agent with a gate" in the package README. Do
|
|
93
|
+
not also load the package or the checkout: two copies register the tools twice.
|
|
94
|
+
|
|
95
|
+
## Inline definition
|
|
96
|
+
|
|
97
|
+
Add `definition` to a `single` request:
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"request": {
|
|
102
|
+
"kind": "single",
|
|
103
|
+
"agent": "scout",
|
|
104
|
+
"task": "List the exports in src/index.ts.",
|
|
105
|
+
"definition": {
|
|
106
|
+
"name": "scout",
|
|
107
|
+
"role": "Scout",
|
|
108
|
+
"prompt": { "role": "You inspect code and report names." },
|
|
109
|
+
"tools": ["read"],
|
|
110
|
+
"thinkingLevel": "low"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Rules:
|
|
117
|
+
|
|
118
|
+
- `extensions` and `approval` are rejected with the field name.
|
|
119
|
+
- When the name is registered, `tools` must be a subset of the registered
|
|
120
|
+
tools. The launch names every extra tool and writes no run.
|
|
121
|
+
- When the name is registered, the registered prompt, role, extensions and
|
|
122
|
+
approval win. The inline definition can narrow `tools` and fill a field the
|
|
123
|
+
registered definition leaves empty.
|
|
124
|
+
- When the name is not registered, the one-off agent gets `coding-tools` and no
|
|
125
|
+
gates.
|
|
126
|
+
- An omitted `model` or `thinkingLevel` falls back to the registered value,
|
|
127
|
+
then to the host session's value at launch.
|
|
128
|
+
|
|
129
|
+
## Task shaping
|
|
130
|
+
|
|
131
|
+
- `scout` and `reviewer` have only `read`. They cannot list a directory, run a
|
|
132
|
+
command or write a file. Name the files to read. Use `builder` only when the
|
|
133
|
+
child may change files; it also has `write` and `edit`.
|
|
134
|
+
- Ask for one bounded answer. An open-ended "explore and summarize each
|
|
135
|
+
directory" can exhaust the turn limit and end `stopped`. A narrow request
|
|
136
|
+
such as "read package.json and quote the test script" answers.
|
|
137
|
+
- Reviewers see only `task` and their role prompt. Paste the diff or name the
|
|
138
|
+
files they must read.
|
|
139
|
+
- A fanout task is one child's whole instruction. It does not see this
|
|
140
|
+
conversation.
|
|
141
|
+
- A resumed `stopped` run starts a new attempt. If it returns `stopped` again,
|
|
142
|
+
read the per-child cause with `delegate_status` or relaunch a narrower task.
|
|
143
|
+
Do not resume in a loop.
|
|
144
|
+
|
|
145
|
+
## Where names resolve
|
|
146
|
+
|
|
147
|
+
The runtime registry holds the installed durable extensions and tools. The
|
|
148
|
+
launch resolves `tools` and `extensions` against it before it writes a run. A
|
|
149
|
+
missing name returns:
|
|
150
|
+
|
|
151
|
+
```text
|
|
152
|
+
Unresolved toolkit names: <names>. Available extensions: <names>. Available tools: <names>.
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Report the message. The definition owner must fix the registration.
|
|
156
|
+
|
|
157
|
+
A definition may select MCP tools by pattern. A pattern must name its server:
|
|
158
|
+
`mcp__<server>__*` or `mcp__<server>__<prefix>*`. `mcp__*`, a partial namespace
|
|
159
|
+
and a `*` outside `mcp__` are refused. An unknown namespace fails the launch and
|
|
160
|
+
lists the available namespaces and the configured servers that are not
|
|
161
|
+
connected. Only servers that a registered definition references connect, so an
|
|
162
|
+
inline definition cannot bring in a server on its own. The package README has
|
|
163
|
+
the `mcp.json` rules.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Gate reference
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- What a gate is
|
|
6
|
+
- Rule fields
|
|
7
|
+
- What parks
|
|
8
|
+
- Scope and stickiness
|
|
9
|
+
- Decide a gate
|
|
10
|
+
- Who can decide
|
|
11
|
+
- Automation
|
|
12
|
+
- Expiry and errors
|
|
13
|
+
|
|
14
|
+
## What a gate is
|
|
15
|
+
|
|
16
|
+
A gate is a durable suspend point. When a tool call matches a rule, the call
|
|
17
|
+
stops before the tool runs. The run stays open. A `delegate_control` approve or
|
|
18
|
+
deny decides the gate, and the parked call resumes, runs or fails.
|
|
19
|
+
|
|
20
|
+
A gate belongs to a registered definition. An inline definition cannot add,
|
|
21
|
+
remove or change one. Presets carry no gates.
|
|
22
|
+
|
|
23
|
+
## Rule fields
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
approval: {
|
|
27
|
+
gates: [{ name: "deploy", tools: ["bash"], match: "deploy" }],
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
| Field | Required | Meaning |
|
|
32
|
+
| ------- | -------- | ------------------------------------------------------------------------------ |
|
|
33
|
+
| `name` | yes | The gate name. One decision covers this name in every child of the run. |
|
|
34
|
+
| `tools` | yes | Tool names the rule watches. A name outside the list never parks. |
|
|
35
|
+
| `match` | no | Case-sensitive substring of the raw `bash` command. It applies to `bash` only. |
|
|
36
|
+
|
|
37
|
+
`gate-guard` is added to the child's extensions when `approval.gates` is
|
|
38
|
+
non-empty. The child's `bash` and other coding tools are wrapped so the check
|
|
39
|
+
runs before the real tool.
|
|
40
|
+
|
|
41
|
+
## What parks
|
|
42
|
+
|
|
43
|
+
For each call, the wrapper finds the first rule whose `tools` contains the tool
|
|
44
|
+
name, then:
|
|
45
|
+
|
|
46
|
+
- If `match` is absent, the call parks.
|
|
47
|
+
- If `match` is present and the tool is `bash`, the call parks when the raw
|
|
48
|
+
`command` argument contains the substring.
|
|
49
|
+
- If `match` is present and the tool is not `bash`, the call does not park.
|
|
50
|
+
|
|
51
|
+
Two consequences matter:
|
|
52
|
+
|
|
53
|
+
- A rule with `match` on `read` never fires. The read runs and returns its
|
|
54
|
+
content. The gate does not warn. Put `match` on `bash`, or omit `match` to
|
|
55
|
+
gate every read.
|
|
56
|
+
- `tools: ["read"]` with no `match` parks every read in that child, including
|
|
57
|
+
reads the child needs for context.
|
|
58
|
+
|
|
59
|
+
The match is a plain substring check, not a shell parse. `cat vault.txt` and
|
|
60
|
+
`cat ./sec/vault` both match `vault`. `cat VAULT.txt` and `cat ./sec/v` do not.
|
|
61
|
+
The rule does not know whether the command is safe.
|
|
62
|
+
|
|
63
|
+
## Scope and stickiness
|
|
64
|
+
|
|
65
|
+
A gate is keyed by `(run id, gate name)`.
|
|
66
|
+
|
|
67
|
+
- The run id is the launch run. For a fanout or review, every child uses the
|
|
68
|
+
parent run id.
|
|
69
|
+
- The gate name is the rule's `name`. Two definitions with the same gate name
|
|
70
|
+
in one run share one gate and one decision.
|
|
71
|
+
- Every parked task and child is appended to the gate record. One decision
|
|
72
|
+
releases every task parked on that name.
|
|
73
|
+
|
|
74
|
+
A decision is permanent for the run:
|
|
75
|
+
|
|
76
|
+
- `approved`: every later call that matches the same rule in that run runs
|
|
77
|
+
without parking. The gate is a one-time unlock, not a per-call approval.
|
|
78
|
+
- `denied` or `expired`: every later call that matches the same rule returns
|
|
79
|
+
the blocked result and does not run.
|
|
80
|
+
|
|
81
|
+
A different rule with a different gate name keeps its own decision.
|
|
82
|
+
|
|
83
|
+
There is no per-call approval and no revocation. To change the rules, start a
|
|
84
|
+
new run with a different definition.
|
|
85
|
+
|
|
86
|
+
## Decide a gate
|
|
87
|
+
|
|
88
|
+
Use `delegate_control`:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{ "action": "approve", "run": "<run id>", "gate": "deploy", "note": "checked the plan" }
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{ "action": "deny", "run": "<run id>", "gate": "deploy", "note": "wrong service" }
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The call writes one decision, then waits for the run to settle up to the launch
|
|
99
|
+
wait. The run can still be `running` when the call returns. It records
|
|
100
|
+
`decidedBy.sessionId`, the deciding session.
|
|
101
|
+
|
|
102
|
+
`approve` and `deny` use the top-level run id. A child run id is not the gate
|
|
103
|
+
handle.
|
|
104
|
+
|
|
105
|
+
The first decision wins. A second decision returns `GateAlreadyDecided` and
|
|
106
|
+
names the current status. A decision after the deadline returns the same error
|
|
107
|
+
with `expired`. Read `delegate_status` and report it. Do not send the decision
|
|
108
|
+
again.
|
|
109
|
+
|
|
110
|
+
## Who can decide
|
|
111
|
+
|
|
112
|
+
The mechanism has no notion of a person. Any session that can call
|
|
113
|
+
`delegate_control` approve or deny can decide a gate. `decideGate` is the
|
|
114
|
+
writer behind that tool; it is not exported from `index.ts`.
|
|
115
|
+
|
|
116
|
+
The shipped skill tells the agent to ask the user before it decides. That is a
|
|
117
|
+
policy, not an enforcement. An orchestrator can apply a different policy.
|
|
118
|
+
|
|
119
|
+
A child cannot decide its own gate. A child toolkit holds only its definition's
|
|
120
|
+
tools, never `delegate_control`.
|
|
121
|
+
|
|
122
|
+
## Automation
|
|
123
|
+
|
|
124
|
+
Three routes exist today.
|
|
125
|
+
|
|
126
|
+
1. **An orchestrator session or codemode block.** A block can call
|
|
127
|
+
`delegate_launch`, poll with `delegate_status`, apply a rule, then call
|
|
128
|
+
`delegate_control`. Nothing in the mechanism requires a human.
|
|
129
|
+
2. **An extension tool around `decideGate`.** An embedder can map evidence to
|
|
130
|
+
approve or deny. This imports an internal module path, so it is not a
|
|
131
|
+
supported API.
|
|
132
|
+
3. **No gate.** A definition without rules never parks. This is the automation
|
|
133
|
+
baseline.
|
|
134
|
+
|
|
135
|
+
What does not exist:
|
|
136
|
+
|
|
137
|
+
- No auto-approve rule, predicate or policy engine at park time.
|
|
138
|
+
- No per-call approval. Scope is `(run, gate)`.
|
|
139
|
+
- No external decider. The Pi process that owns the session is the only
|
|
140
|
+
writer.
|
|
141
|
+
- No self-approval by the child.
|
|
142
|
+
|
|
143
|
+
Example codemode recipe:
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
const launch = await tools.delegate_launch({
|
|
147
|
+
request: { kind: "single", agent: "deployer", task: "deploy the service" },
|
|
148
|
+
});
|
|
149
|
+
const run = /run:\S+?#\d+/.exec(launch)?.[0];
|
|
150
|
+
const status = await tools.delegate_status({ run });
|
|
151
|
+
if (status.includes("waiting on gate deploy")) {
|
|
152
|
+
await tools.delegate_control({ action: "approve", run, gate: "deploy", note: "allowlist hit" });
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The block must hold the run id and decide from evidence it can see. It cannot
|
|
157
|
+
inspect the parked command: `delegate_status` prints the gate name and the
|
|
158
|
+
child state, not the command.
|
|
159
|
+
|
|
160
|
+
## Expiry and errors
|
|
161
|
+
|
|
162
|
+
A gate expires 24 hours after it opens. The parked call then returns
|
|
163
|
+
`Gate <name> expired; <tool> did not run.` as an error result. A late decision
|
|
164
|
+
returns `GateAlreadyDecided` with `expired before a decision`.
|
|
165
|
+
|
|
166
|
+
| Message | Meaning |
|
|
167
|
+
| ---------------------------------------------------- | ------------------------------------------------------ |
|
|
168
|
+
| `Gate <name> was denied; <tool> did not run.` | The decision was deny. The tool did not run. |
|
|
169
|
+
| `Gate <name> expired; <tool> did not run.` | The deadline passed. The tool did not run. |
|
|
170
|
+
| `Gate <name> is already <status>` | Another decision won. Read status; do not repeat. |
|
|
171
|
+
| `Gate <name> of run <id> expired before a decision.` | The deadline passed before a decision. Do not repeat. |
|
|
172
|
+
| `Gate <name> of run <id> not found` | The run id and gate name do not match. List the gates. |
|
|
173
|
+
|
|
174
|
+
`delegate_status` shows a waiting run as `waiting on gate <name>` and its
|
|
175
|
+
parked child as `waiting`.
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# Launch reference
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Request wrapper
|
|
6
|
+
- Single
|
|
7
|
+
- Inline definition
|
|
8
|
+
- Fanout
|
|
9
|
+
- Review
|
|
10
|
+
- Waiting and deadlines
|
|
11
|
+
- Mistakes to avoid
|
|
12
|
+
|
|
13
|
+
## Request wrapper
|
|
14
|
+
|
|
15
|
+
Every call has one top-level `request` object. The `kind` field goes inside
|
|
16
|
+
`request`.
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"request": {
|
|
21
|
+
"kind": "single",
|
|
22
|
+
"agent": "scout",
|
|
23
|
+
"task": "Read package.json and quote the test script."
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Single
|
|
29
|
+
|
|
30
|
+
Fields are `agent`, `task` and optional `definition`.
|
|
31
|
+
|
|
32
|
+
- `agent` is a preset or a registered name.
|
|
33
|
+
- `task` is the child's whole instruction. The child sees this text and its
|
|
34
|
+
definition prompt, not this conversation.
|
|
35
|
+
- A single run uses lane `default`.
|
|
36
|
+
|
|
37
|
+
Use `single` for one bounded task. Use several singles when each task needs its
|
|
38
|
+
own run record and answer.
|
|
39
|
+
|
|
40
|
+
## Inline definition
|
|
41
|
+
|
|
42
|
+
Add `definition` to a single request to narrow a registered agent or to define a
|
|
43
|
+
one-off agent.
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"request": {
|
|
48
|
+
"kind": "single",
|
|
49
|
+
"agent": "scout",
|
|
50
|
+
"task": "Read src/index.ts and list the exported functions.",
|
|
51
|
+
"definition": {
|
|
52
|
+
"name": "scout",
|
|
53
|
+
"role": "Scout",
|
|
54
|
+
"prompt": { "role": "You inspect code and report names." },
|
|
55
|
+
"tools": ["read"],
|
|
56
|
+
"thinkingLevel": "low"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Fields are `name`, `role`, `prompt.shared` (optional), `prompt.role`, `tools`,
|
|
63
|
+
optional `model` (`{ "provider": "...", "modelId": "..." }`), optional
|
|
64
|
+
`thinkingLevel`, optional `cwd`.
|
|
65
|
+
|
|
66
|
+
Rules:
|
|
67
|
+
|
|
68
|
+
- `extensions` and `approval` belong to a registered definition. Sending either
|
|
69
|
+
is rejected with the field name.
|
|
70
|
+
- Inline tools must be a subset of the registered agent's tools when the name
|
|
71
|
+
is registered. Otherwise the launch fails and names the extra tools.
|
|
72
|
+
- With no registered agent of that name, the inline agent gets the coding
|
|
73
|
+
toolkit and no gates.
|
|
74
|
+
- An omitted model or thinking level falls back to the registered agent's value,
|
|
75
|
+
then to the host session's value at launch.
|
|
76
|
+
|
|
77
|
+
## Fanout
|
|
78
|
+
|
|
79
|
+
Fields are `lane`, `agents` and optional `policy`.
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"request": {
|
|
84
|
+
"kind": "fanout",
|
|
85
|
+
"lane": "audit",
|
|
86
|
+
"agents": [
|
|
87
|
+
{ "agent": "scout", "task": "Read src/index.ts and list the exports." },
|
|
88
|
+
{ "agent": "scout", "task": "Read package.json and quote the build script." }
|
|
89
|
+
],
|
|
90
|
+
"policy": "allSettled"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
- `lane` is required. Every child runs in it.
|
|
96
|
+
- `agents` keeps its order. Child index and status order match.
|
|
97
|
+
- `policy` is `allSettled` (default) or `failFast`. `failFast` aborts the other
|
|
98
|
+
children after one fails. Under `allSettled`, every child finishes.
|
|
99
|
+
- Caps apply. Children start in waves when a lane or the session is full.
|
|
100
|
+
- The fanout answer is a count, such as `3 children answered`. The result names
|
|
101
|
+
the run id. Call `delegate_status` with that id and read the child lines.
|
|
102
|
+
- One failed child fails the fanout run and names the child index and agent.
|
|
103
|
+
Children that had already answered keep their answers; the rest stop.
|
|
104
|
+
- A gate on any child belongs to the fanout run id. One decision releases every
|
|
105
|
+
child parked on that gate.
|
|
106
|
+
|
|
107
|
+
## Review
|
|
108
|
+
|
|
109
|
+
Fields are `task`, `reviewers` and optional `lane` (default `review`).
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"request": {
|
|
114
|
+
"kind": "review",
|
|
115
|
+
"task": "Review src/auth.ts for correctness. Read it and src/auth.test.ts.",
|
|
116
|
+
"reviewers": [{ "agent": "reviewer" }, { "agent": "reviewer" }]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Each reviewer gets the task plus an instruction to end with:
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{ "disposition": "accepted" | "changes_requested" | "rejected" | "inconclusive", "note": "..." }
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The review answer is the aggregate, in this order: `rejected` if any reviewer
|
|
128
|
+
rejects, then `changes_requested`, then `inconclusive`, otherwise `accepted`.
|
|
129
|
+
A missing or invalid disposition counts as `inconclusive`.
|
|
130
|
+
|
|
131
|
+
The aggregate alone does not say what to change. Call `delegate_status` with
|
|
132
|
+
`{}` and read `reviews` for each reviewer's disposition and note.
|
|
133
|
+
|
|
134
|
+
The review does not capture a diff. Reviewers see only `task` and their role
|
|
135
|
+
prompt. Paste the diff into `task`, or name the files they must read.
|
|
136
|
+
|
|
137
|
+
## Detached execution
|
|
138
|
+
|
|
139
|
+
`"execution": "detached"` returns the run id and the opening status at once,
|
|
140
|
+
with no wait and no deadline; `delegate_status` and one status notice report the
|
|
141
|
+
run afterwards. `"execution": "wait"` and an absent field are the same request
|
|
142
|
+
and the same run. Single, fanout and review requests all accept the field.
|
|
143
|
+
|
|
144
|
+
A workflow script's `launch` and `launch_many` take the same field. They answer
|
|
145
|
+
the run id, the opening status and an empty answer, so a script can start a
|
|
146
|
+
child and keep working. `launch_many` answers one entry per child. A scripted
|
|
147
|
+
detached launch reports the status at claim, which is `queued`; reading the child
|
|
148
|
+
would race its own start. A detached group also waits until its children are
|
|
149
|
+
claimed (at most 5 seconds), so the answer names one entry per child.
|
|
150
|
+
|
|
151
|
+
```json
|
|
152
|
+
{
|
|
153
|
+
"request": {
|
|
154
|
+
"kind": "single",
|
|
155
|
+
"agent": "builder",
|
|
156
|
+
"task": "Run the full test suite and report the failures.",
|
|
157
|
+
"execution": "detached"
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
A gate or request alert still starts a turn, for a detached run too: it needs a
|
|
163
|
+
decision, so it cannot wait for you to type.
|
|
164
|
+
|
|
165
|
+
## Waiting and deadlines
|
|
166
|
+
|
|
167
|
+
A launch returns as soon as one of these happens:
|
|
168
|
+
|
|
169
|
+
- The child or group settles. The result is `answered`, `failed`, `stopped` or
|
|
170
|
+
`denied`.
|
|
171
|
+
- A gate becomes pending. The result is `waiting` with `gates`.
|
|
172
|
+
- The wait deadline passes. The result is `running` or `queued` with the run id.
|
|
173
|
+
|
|
174
|
+
The default deadline is 10 minutes. A running or queued run is not lost. Poll
|
|
175
|
+
`delegate_status` or wait for the user to ask again.
|
|
176
|
+
|
|
177
|
+
## Mistakes to avoid
|
|
178
|
+
|
|
179
|
+
- `kind` at the top level instead of inside `request`.
|
|
180
|
+
- A fanout without `lane`.
|
|
181
|
+
- Launching the same task twice after a timeout. Poll the first run.
|
|
182
|
+
- Reading only the fanout count or review aggregate. Call `delegate_status` to
|
|
183
|
+
read child answers and reviewer notes.
|
|
184
|
+
- Sending `extensions` or `approval` in an inline definition.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import { join, readText } from "../test-support/platform.ts";
|
|
3
|
+
import { DEFAULTS } from "./runtime/config.ts";
|
|
4
|
+
|
|
5
|
+
const root = join(import.meta.dirname, "..");
|
|
6
|
+
const read = (relative: string): Promise<string> => readText(join(root, relative));
|
|
7
|
+
|
|
8
|
+
/** The document an agent reads before it launches work. */
|
|
9
|
+
it("the skill teaches the budget and the remedies", async () => {
|
|
10
|
+
const skill = await read("skills/pi-delegates/SKILL.md");
|
|
11
|
+
assert.ok(skill.includes("## Turn budget"), "the skill has a Turn budget section");
|
|
12
|
+
assert.ok(skill.includes("## Failures"), "the skill has a Failures section");
|
|
13
|
+
const budget = skill.slice(skill.indexOf("## Turn budget"), skill.indexOf("## Failures"));
|
|
14
|
+
for (const part of ["maxTurns", "caps.maxTurns", "turn_limit", "defaults.maxTurns"]) {
|
|
15
|
+
assert.ok(budget.includes(part), `the budget section names ${part}`);
|
|
16
|
+
}
|
|
17
|
+
assert.match(budget, /never\s+goes\s+below\s+one\s+round/, "the budget section states the floor");
|
|
18
|
+
// The four levels in order: child, request, definition, then the default. Compared
|
|
19
|
+
// by position, not as one sentence, so the paragraph may wrap anywhere.
|
|
20
|
+
const order = [
|
|
21
|
+
"A child's value wins",
|
|
22
|
+
"the request's",
|
|
23
|
+
"the definition's",
|
|
24
|
+
"`defaults.maxTurns`",
|
|
25
|
+
].map((part) => budget.indexOf(part));
|
|
26
|
+
assert.ok(
|
|
27
|
+
order.every((at) => at >= 0),
|
|
28
|
+
"the budget section states every level of the precedence",
|
|
29
|
+
);
|
|
30
|
+
assert.deepStrictEqual(
|
|
31
|
+
[...order].sort((left, right) => left - right),
|
|
32
|
+
order,
|
|
33
|
+
"the budget section states the precedence in order",
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const failures = skill.slice(skill.indexOf("## Failures"));
|
|
37
|
+
for (const part of [
|
|
38
|
+
"model_error",
|
|
39
|
+
"turn_limit",
|
|
40
|
+
"no_model",
|
|
41
|
+
"internal",
|
|
42
|
+
"nothing_to_answer",
|
|
43
|
+
"relaunch",
|
|
44
|
+
"narrow",
|
|
45
|
+
"fix_config",
|
|
46
|
+
]) {
|
|
47
|
+
assert.ok(failures.includes(part), `the failures section names ${part}`);
|
|
48
|
+
}
|
|
49
|
+
// The rendering is `(reason): detail`, the form `delegate_status` prints.
|
|
50
|
+
assert.ok(failures.includes("`(reason): detail`"), "the failures section states the format");
|
|
51
|
+
assert.ok(
|
|
52
|
+
failures.includes("retryable") && failures.toLowerCase().includes("already"),
|
|
53
|
+
"the failures section states that retryable means durable already retried",
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("the reference documents execution and the empty answer", async () => {
|
|
58
|
+
const reference = await read("skills/pi-delegates/references/launch.md");
|
|
59
|
+
assert.ok(reference.includes('"execution": "detached"'), "the reference names the value");
|
|
60
|
+
assert.ok(reference.includes("empty"), "the reference states the empty scripted answer");
|
|
61
|
+
assert.ok(
|
|
62
|
+
reference.includes("A gate or request alert still starts a turn"),
|
|
63
|
+
"the reference states that a gate or request alert still starts a turn",
|
|
64
|
+
);
|
|
65
|
+
assert.ok(
|
|
66
|
+
reference.includes("at most 5 seconds"),
|
|
67
|
+
"the reference states the detached group's admission bound",
|
|
68
|
+
);
|
|
69
|
+
assert.ok(
|
|
70
|
+
reference.includes("the status at claim, which is `queued`"),
|
|
71
|
+
"the reference states the scripted detached status",
|
|
72
|
+
);
|
|
73
|
+
assert.ok(
|
|
74
|
+
reference.includes("absent") && reference.includes("wait"),
|
|
75
|
+
"the reference states that an absent field means waiting",
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("OPERATIONS lists the codes, their cardinality and three narrow warnings", async () => {
|
|
80
|
+
const operations = await read("OPERATIONS.md");
|
|
81
|
+
for (const code of ["run.retry", "run.failed", "run.settled"]) {
|
|
82
|
+
assert.ok(operations.includes(code), `OPERATIONS lists ${code}`);
|
|
83
|
+
}
|
|
84
|
+
assert.ok(
|
|
85
|
+
operations.includes("one `run.retry` warning per scheduled retry attempt") ||
|
|
86
|
+
operations.includes("one warning per scheduled retry attempt"),
|
|
87
|
+
"OPERATIONS states one retry line per attempt",
|
|
88
|
+
);
|
|
89
|
+
assert.ok(
|
|
90
|
+
operations.includes("exactly one") && operations.includes("run.failed"),
|
|
91
|
+
"OPERATIONS states one failure line per failed run",
|
|
92
|
+
);
|
|
93
|
+
for (const code of ["settle.notify_failed", "retry.observer_failed", "settle.scan_truncated"]) {
|
|
94
|
+
assert.ok(operations.includes(code), `OPERATIONS lists ${code}`);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("the README sample matches the defaults", async () => {
|
|
99
|
+
const readme = await read("README.md");
|
|
100
|
+
assert.ok(readme.includes(`"maxTurns": ${DEFAULTS.maxTurns}`), "the sample shows the default");
|
|
101
|
+
assert.ok(
|
|
102
|
+
readme.includes(`"maxTurns": ${DEFAULTS.maxTurnsCeiling}`),
|
|
103
|
+
"the sample shows the ceiling under caps",
|
|
104
|
+
);
|
|
105
|
+
assert.match(readme, /no\s+budget\s+goes\s+below\s+one\s+round/, "the README states the floor");
|
|
106
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import { createCatalogue, presets, type AgentDefinition } from "./definitions.ts";
|
|
3
|
+
import { CODING_EXTENSION } from "./names.ts";
|
|
4
|
+
|
|
5
|
+
const registered = (name: string): AgentDefinition => ({
|
|
6
|
+
name,
|
|
7
|
+
role: `${name} role`,
|
|
8
|
+
prompt: { role: `${name} prompt` },
|
|
9
|
+
tools: ["read"],
|
|
10
|
+
extensions: [CODING_EXTENSION],
|
|
11
|
+
approval: { gates: [] },
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const namesOf = (definitions: readonly AgentDefinition[]): readonly string[] =>
|
|
15
|
+
definitions.map((definition) => definition.name);
|
|
16
|
+
|
|
17
|
+
it("an empty catalogue is the presets and finds each by name", () => {
|
|
18
|
+
const catalogue = createCatalogue();
|
|
19
|
+
assert.deepStrictEqual(catalogue.all, presets);
|
|
20
|
+
assert.deepStrictEqual(catalogue.presets, presets);
|
|
21
|
+
assert.strictEqual(catalogue.find("scout"), presets[0]);
|
|
22
|
+
assert.strictEqual(catalogue.find("nobody"), undefined);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("a registered preset name overrides the preset in both lists", () => {
|
|
26
|
+
const override = registered("builder");
|
|
27
|
+
const catalogue = createCatalogue([override]);
|
|
28
|
+
assert.deepStrictEqual(namesOf(catalogue.presets), ["scout", "builder", "reviewer"]);
|
|
29
|
+
assert.strictEqual(catalogue.presets[1], override);
|
|
30
|
+
assert.strictEqual(catalogue.all[1], override);
|
|
31
|
+
assert.strictEqual(catalogue.find("builder"), override);
|
|
32
|
+
assert.strictEqual(catalogue.all.length, presets.length);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("a name that is not a preset is appended to all and left out of presets", () => {
|
|
36
|
+
const custom = registered("deployer");
|
|
37
|
+
const catalogue = createCatalogue([custom]);
|
|
38
|
+
assert.deepStrictEqual(namesOf(catalogue.all), [...namesOf(presets), "deployer"]);
|
|
39
|
+
assert.deepStrictEqual(catalogue.presets, presets);
|
|
40
|
+
assert.strictEqual(catalogue.find("deployer"), custom);
|
|
41
|
+
});
|