brl-subagent 2.3.9 → 2.5.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/AGENT.md +5 -0
- package/README.md +20 -8
- package/package.json +11 -9
- package/src/concurrency.ts +1 -0
- package/src/diff.ts +1 -0
- package/src/event-bus.ts +8 -2
- package/src/git.ts +68 -0
- package/src/history.ts +59 -1
- package/src/index.ts +244 -406
- package/src/kill-escalation.ts +94 -0
- package/src/logging.ts +58 -4
- package/src/messaging.ts +1 -0
- package/src/metrics.ts +1 -0
- package/src/model-availability.ts +1 -0
- package/src/notify-completion.ts +1 -0
- package/src/params.ts +1 -0
- package/src/paths.ts +1 -0
- package/src/preflight.ts +30 -14
- package/src/prelude.ts +1 -0
- package/src/presets.ts +1 -0
- package/src/proc.ts +140 -0
- package/src/prompt.ts +1 -0
- package/src/recovery-engine.ts +262 -0
- package/src/recovery.ts +325 -0
- package/src/reports.ts +64 -8
- package/src/router.ts +1 -0
- package/src/run-registry.ts +269 -0
- package/src/runner.ts +207 -16
- package/src/sanitize.ts +54 -3
- package/src/scheduler.ts +1 -0
- package/src/schema.ts +254 -0
- package/src/session-manager.ts +142 -111
- package/src/state.ts +52 -7
- package/src/templates.ts +1 -0
- package/src/transcript-path.ts +41 -0
- package/src/transcript-tail.ts +1 -0
- package/src/transcript.ts +14 -12
- package/src/tui-format.ts +1 -0
- package/src/tui.ts +231 -296
- package/src/types.ts +130 -2
- package/src/unit-run.ts +9 -0
- package/src/validate.ts +16 -2
package/src/schema.ts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
// Purpose: The registered `delegate_task` parameter schema — the single source of truth for its types.
|
|
2
|
+
/**
|
|
3
|
+
* delegate_task parameter schema — the SINGLE source of truth (issue #239).
|
|
4
|
+
* index.ts registers this object; DelegateTaskParams (types.ts) is
|
|
5
|
+
* Static<typeof delegateTaskParamsSchema>, so schema and types cannot drift.
|
|
6
|
+
*/
|
|
7
|
+
import { Type } from "typebox";
|
|
8
|
+
import { MAX_CHAIN_STEPS, MAX_PARALLEL_TASKS, MAX_GRAPH_TASKS } from "./types";
|
|
9
|
+
|
|
10
|
+
export const delegateTaskParamsSchema = Type.Object({
|
|
11
|
+
task: Type.Optional(Type.String({
|
|
12
|
+
description: "Detailed description of the task for the subagent to complete (required for single mode, optional for chain/tasks/graph)",
|
|
13
|
+
})),
|
|
14
|
+
systemPrompt: Type.Optional(
|
|
15
|
+
Type.String({
|
|
16
|
+
description:
|
|
17
|
+
"Custom system prompt or additional instructions for the subagent. " +
|
|
18
|
+
"When inheritSystemPrompt is true (default), this is appended after the inherited prompt. " +
|
|
19
|
+
"When inheritSystemPrompt is false, this replaces the inherited prompt entirely.",
|
|
20
|
+
}),
|
|
21
|
+
),
|
|
22
|
+
inheritSystemPrompt: Type.Optional(
|
|
23
|
+
Type.Boolean({
|
|
24
|
+
description:
|
|
25
|
+
"Whether to inherit the main agent's system prompt. " +
|
|
26
|
+
"Default: true. Set to false to use only your custom systemPrompt, " +
|
|
27
|
+
"or to avoid passing a large inherited prompt to the subagent.",
|
|
28
|
+
}),
|
|
29
|
+
),
|
|
30
|
+
thinkingLevel: Type.Optional(
|
|
31
|
+
Type.String({
|
|
32
|
+
description:
|
|
33
|
+
"Requested thinking level for this subagent call. " +
|
|
34
|
+
"One of: off, minimal, low, medium, high, xhigh. " +
|
|
35
|
+
"Capped at the user's configured maximum. If omitted, the user's configured level is used.",
|
|
36
|
+
}),
|
|
37
|
+
),
|
|
38
|
+
outputFile: Type.Optional(
|
|
39
|
+
Type.String({
|
|
40
|
+
description:
|
|
41
|
+
"Project-relative path where the subagent should write its full findings. " +
|
|
42
|
+
"When provided, the subagent is instructed to write complete output to this file " +
|
|
43
|
+
"and return only a structured summary.",
|
|
44
|
+
}),
|
|
45
|
+
),
|
|
46
|
+
label: Type.Optional(
|
|
47
|
+
Type.String({
|
|
48
|
+
description:
|
|
49
|
+
"Human-readable label for this subagent (e.g., 'security-audit', 'docs-review'). " +
|
|
50
|
+
"Appears in the status bar and tool call display. " +
|
|
51
|
+
"Omit to use the default anonymous counter.",
|
|
52
|
+
}),
|
|
53
|
+
),
|
|
54
|
+
model: Type.Optional(Type.String({ description: "Model override (provider/model-id). Defaults to the global subagent model." })),
|
|
55
|
+
timeout: Type.Optional(
|
|
56
|
+
Type.Number({
|
|
57
|
+
description:
|
|
58
|
+
"Maximum time in milliseconds the subagent is allowed to run. " +
|
|
59
|
+
"If exceeded, the subagent is killed and an error is returned. " +
|
|
60
|
+
"Background runs default to a 30-minute deadline when no timeout is given; an explicit timeout is honored as given (30 minutes is a default, not a ceiling). A raw value ≥ 2^31-1 normalizes to the default.",
|
|
61
|
+
}),
|
|
62
|
+
),
|
|
63
|
+
cwd: Type.Optional(
|
|
64
|
+
Type.String({
|
|
65
|
+
description:
|
|
66
|
+
"Working directory for the subagent. Must be an existing directory. " +
|
|
67
|
+
"Defaults to the conductor's current working directory.",
|
|
68
|
+
}),
|
|
69
|
+
),
|
|
70
|
+
tools: Type.Optional(
|
|
71
|
+
Type.Array(Type.String(), {
|
|
72
|
+
description:
|
|
73
|
+
"Explicit allowlist of tool names for the subagent. Maps to pi's --tools flag.",
|
|
74
|
+
}),
|
|
75
|
+
),
|
|
76
|
+
excludeTools: Type.Optional(
|
|
77
|
+
Type.Array(Type.String(), {
|
|
78
|
+
description:
|
|
79
|
+
"Tool names to disable for the subagent. Maps to pi's --exclude-tools flag.",
|
|
80
|
+
}),
|
|
81
|
+
),
|
|
82
|
+
noBuiltinTools: Type.Optional(
|
|
83
|
+
Type.Boolean({
|
|
84
|
+
description:
|
|
85
|
+
"Disable all built-in tools for the subagent. Maps to pi's --no-builtin-tools flag.",
|
|
86
|
+
}),
|
|
87
|
+
),
|
|
88
|
+
preset: Type.Optional(
|
|
89
|
+
Type.String({
|
|
90
|
+
description:
|
|
91
|
+
"Name of a saved delegation preset (created via /brl-subagent preset). " +
|
|
92
|
+
"Preset values are used as defaults; explicit parameters on this call override them.",
|
|
93
|
+
}),
|
|
94
|
+
),
|
|
95
|
+
template: Type.Optional(
|
|
96
|
+
Type.String({
|
|
97
|
+
description:
|
|
98
|
+
"Name of a saved task template. Use with params to fill template slots. " +
|
|
99
|
+
"Templates are file-backed: 9 builtin templates ship with the extension " +
|
|
100
|
+
"(browse via /brl-subagent templates); override or add via .md files in " +
|
|
101
|
+
"~/.pi/agent/brl-subagent/templates/ or .pi/brl-subagent/templates/ " +
|
|
102
|
+
"(project-local wins over user-global over builtin).",
|
|
103
|
+
}),
|
|
104
|
+
),
|
|
105
|
+
params: Type.Optional(
|
|
106
|
+
Type.Record(Type.String(), Type.String(), {
|
|
107
|
+
description:
|
|
108
|
+
"Parameter values for template ${param} slots. " +
|
|
109
|
+
"Keys are param names, values are the substitution text.",
|
|
110
|
+
}),
|
|
111
|
+
),
|
|
112
|
+
retryRunId: Type.Optional(
|
|
113
|
+
Type.String({
|
|
114
|
+
description:
|
|
115
|
+
"ID of a previously failed subagent run to retry. " +
|
|
116
|
+
"The retry rebuilds the parameter object from a fixed field set, falling back to the " +
|
|
117
|
+
"original run's recorded values, with explicit values on this call winning: task, label, " +
|
|
118
|
+
"model, preset, systemPrompt, inheritSystemPrompt, thinkingLevel, priority, outputFile, " +
|
|
119
|
+
"timeout, cwd, tools, excludeTools, noBuiltinTools, background, gitMode, approvalMode, force. " +
|
|
120
|
+
"The execution-shape fields ARE restored: a retried background run stays background (with its " +
|
|
121
|
+
"completion wake), and a retried branch-mode run keeps its work branch, its approvalMode " +
|
|
122
|
+
"gating and its force override. Qualify that by the effective gitMode - when neither the record " +
|
|
123
|
+
"nor this call carries one, the configured default applies, which may still be 'branch'. " +
|
|
124
|
+
"Not restored: chain/tasks/graph and params, so a retried multi-step run silently degrades to a " +
|
|
125
|
+
"single task - re-issue it fresh. retryOnTimeout is explicit-only: never restored, honoured when passed. " +
|
|
126
|
+
"template is asymmetric: the original's template is NOT restored, but a template passed on the " +
|
|
127
|
+
"retry call DOES take effect (it is resolved before the retry merge). " +
|
|
128
|
+
"Fan-out units (parallel/chain/graph origin) record no background, so retrying one is a single " +
|
|
129
|
+
"foreground run - pass background: true for a background retry. " +
|
|
130
|
+
"Only works with runs that ended in failure (exitCode != 0, timeout, error, or abort).",
|
|
131
|
+
}),
|
|
132
|
+
),
|
|
133
|
+
gitMode: Type.Optional(
|
|
134
|
+
Type.String({
|
|
135
|
+
description:
|
|
136
|
+
"Git integration mode for this subagent call. " +
|
|
137
|
+
"'branch' creates a work branch, captures the diff, and switches back. " +
|
|
138
|
+
"'none' (default) does nothing. Falls back to the configured default.",
|
|
139
|
+
}),
|
|
140
|
+
),
|
|
141
|
+
retryOnTimeout: Type.Optional(
|
|
142
|
+
Type.Boolean({
|
|
143
|
+
description:
|
|
144
|
+
"If true and a FOREGROUND subagent times out, automatically retry with the same parameters. " +
|
|
145
|
+
"Only retries once — the second timeout is treated as a final failure. " +
|
|
146
|
+
"Background runs are not auto-retried; re-dispatch with retryRunId.",
|
|
147
|
+
}),
|
|
148
|
+
),
|
|
149
|
+
approvalMode: Type.Optional(
|
|
150
|
+
Type.String({
|
|
151
|
+
description:
|
|
152
|
+
"Change approval mode: auto (never ask), writes (ask when files changed), " +
|
|
153
|
+
"always (ask every time). Default is user config (/brl-subagent approval).",
|
|
154
|
+
}),
|
|
155
|
+
),
|
|
156
|
+
force: Type.Optional(
|
|
157
|
+
Type.Boolean({
|
|
158
|
+
description:
|
|
159
|
+
"Override for capability pre-flight errors (default false). A dispatch is blocked when the task clearly needs a capability the resolved toolset lacks — " +
|
|
160
|
+
"a run/execute/test/compile/benchmark task with no bash, or an exploration task (search/grep/find/list/locate/glob) with none of find/ls/grep/bash. " +
|
|
161
|
+
"Set force: true to dispatch anyway: the mismatch is then delivered as a warning in the result instead of rejecting the call. " +
|
|
162
|
+
"Warnings are surfaced either way. force never suppresses outputFile-without-write conflicts.",
|
|
163
|
+
}),
|
|
164
|
+
),
|
|
165
|
+
background: Type.Optional(
|
|
166
|
+
Type.Boolean({
|
|
167
|
+
description:
|
|
168
|
+
"Run the subagent in the background without blocking the conductor. " +
|
|
169
|
+
"When true, the tool returns immediately with an agent ID. " +
|
|
170
|
+
"The conductor is woken with a completion message; use get_subagent_result for post-wake retrieval and stall checks. " +
|
|
171
|
+
"Supports a single task or the tasks array (a fan-out that starts one background agent per task; with tasks the call returns one ID per task and the conductor is woken once per agent as each finishes); combining background with chain or graph is rejected. " +
|
|
172
|
+
"Default: false (blocking mode).",
|
|
173
|
+
}),
|
|
174
|
+
),
|
|
175
|
+
priority: Type.Optional(
|
|
176
|
+
Type.Union([
|
|
177
|
+
Type.Literal("critical"),
|
|
178
|
+
Type.Literal("high"),
|
|
179
|
+
Type.Literal("normal"),
|
|
180
|
+
Type.Literal("low"),
|
|
181
|
+
], {
|
|
182
|
+
description: "Concurrency priority for this delegation: critical, high, normal, or low. Higher-priority delegations queue ahead. Defaults to normal.",
|
|
183
|
+
})
|
|
184
|
+
),
|
|
185
|
+
// Issue #114: NO per-step `priority` on chain[] — chain steps never
|
|
186
|
+
// compete for concurrency slots (the chain holds ONE slot for its whole
|
|
187
|
+
// duration); array order IS the priority.
|
|
188
|
+
chain: Type.Optional(Type.Array(Type.Object({
|
|
189
|
+
task: Type.String({ description: "Task description. Use {previous} to reference the previous step output." }),
|
|
190
|
+
label: Type.Optional(Type.String({})),
|
|
191
|
+
model: Type.Optional(Type.String({ description: "Model override for this step (provider/model-id). Defaults to the global subagent model." })),
|
|
192
|
+
thinkingLevel: Type.Optional(Type.String({})),
|
|
193
|
+
cwd: Type.Optional(Type.String({})),
|
|
194
|
+
timeout: Type.Optional(Type.Number({})),
|
|
195
|
+
outputFile: Type.Optional(Type.String({})),
|
|
196
|
+
tools: Type.Optional(Type.Array(Type.String({}))),
|
|
197
|
+
excludeTools: Type.Optional(Type.Array(Type.String({}))),
|
|
198
|
+
noBuiltinTools: Type.Optional(Type.Boolean({})),
|
|
199
|
+
systemPrompt: Type.Optional(Type.String({})),
|
|
200
|
+
inheritSystemPrompt: Type.Optional(Type.Boolean({})),
|
|
201
|
+
}), {
|
|
202
|
+
description: "Sequential chain of tasks. Each step receives the previous step output via {previous} placeholder in the task string. Chain stops at the first failure. Max " + MAX_CHAIN_STEPS + " steps."
|
|
203
|
+
})),
|
|
204
|
+
tasks: Type.Optional(Type.Array(Type.Object({
|
|
205
|
+
task: Type.String({ description: "Task description for this parallel subtask" }),
|
|
206
|
+
label: Type.Optional(Type.String({})),
|
|
207
|
+
model: Type.Optional(Type.String({ description: "Model override for this step (provider/model-id). Defaults to the global subagent model." })),
|
|
208
|
+
thinkingLevel: Type.Optional(Type.String({})),
|
|
209
|
+
priority: Type.Optional(
|
|
210
|
+
Type.Union([
|
|
211
|
+
Type.Literal("critical"),
|
|
212
|
+
Type.Literal("high"),
|
|
213
|
+
Type.Literal("normal"),
|
|
214
|
+
Type.Literal("low"),
|
|
215
|
+
], { description: "Concurrency priority for this subtask (overrides the call-level default)." })
|
|
216
|
+
),
|
|
217
|
+
cwd: Type.Optional(Type.String({})),
|
|
218
|
+
timeout: Type.Optional(Type.Number({})),
|
|
219
|
+
outputFile: Type.Optional(Type.String({})),
|
|
220
|
+
tools: Type.Optional(Type.Array(Type.String({}))),
|
|
221
|
+
excludeTools: Type.Optional(Type.Array(Type.String({}))),
|
|
222
|
+
noBuiltinTools: Type.Optional(Type.Boolean({})),
|
|
223
|
+
systemPrompt: Type.Optional(Type.String({})),
|
|
224
|
+
inheritSystemPrompt: Type.Optional(Type.Boolean({})),
|
|
225
|
+
}), {
|
|
226
|
+
description: "Parallel tasks to execute concurrently. All tasks run regardless of individual failures. Max " + MAX_PARALLEL_TASKS + " tasks."
|
|
227
|
+
})),
|
|
228
|
+
graph: Type.Optional(Type.Array(Type.Object({
|
|
229
|
+
id: Type.String({ description: "Unique identifier for this task node" }),
|
|
230
|
+
task: Type.String({ description: "Task description. Use {<nodeId>} to reference output from another task (the referenced node's own id, which must be a word-character id - letters, digits, underscore; ids like 'step-1' or 'node.a' are not matched and the braces are left as literal text)." }),
|
|
231
|
+
label: Type.Optional(Type.String({})),
|
|
232
|
+
model: Type.Optional(Type.String({ description: "Model override for this step (provider/model-id). Defaults to the global subagent model." })),
|
|
233
|
+
dependsOn: Type.Optional(Type.Array(Type.String({}), { description: "IDs of tasks that must complete before this one starts" })),
|
|
234
|
+
thinkingLevel: Type.Optional(Type.String({})),
|
|
235
|
+
priority: Type.Optional(
|
|
236
|
+
Type.Union([
|
|
237
|
+
Type.Literal("critical"),
|
|
238
|
+
Type.Literal("high"),
|
|
239
|
+
Type.Literal("normal"),
|
|
240
|
+
Type.Literal("low"),
|
|
241
|
+
], { description: "Concurrency priority for this subtask (overrides the call-level default)." })
|
|
242
|
+
),
|
|
243
|
+
cwd: Type.Optional(Type.String({})),
|
|
244
|
+
timeout: Type.Optional(Type.Number({})),
|
|
245
|
+
outputFile: Type.Optional(Type.String({})),
|
|
246
|
+
tools: Type.Optional(Type.Array(Type.String({}))),
|
|
247
|
+
excludeTools: Type.Optional(Type.Array(Type.String({}))),
|
|
248
|
+
noBuiltinTools: Type.Optional(Type.Boolean({})),
|
|
249
|
+
systemPrompt: Type.Optional(Type.String({})),
|
|
250
|
+
inheritSystemPrompt: Type.Optional(Type.Boolean({})),
|
|
251
|
+
}), {
|
|
252
|
+
description: "Declare tasks with dependencies. The scheduler parallelizes independent tasks and sequences dependent ones. Max " + MAX_GRAPH_TASKS + " tasks."
|
|
253
|
+
})),
|
|
254
|
+
});
|