brl-subagent 2.7.0 → 2.9.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 (51) hide show
  1. package/AGENT.md +3 -3
  2. package/README.md +18 -10
  3. package/package.json +6 -5
  4. package/src/agent-tools.ts +332 -0
  5. package/src/background-pipeline.ts +1025 -0
  6. package/src/boot-recovery.ts +313 -0
  7. package/src/commands.ts +137 -0
  8. package/src/concurrency.ts +26 -5
  9. package/src/delegate-handler.ts +2261 -0
  10. package/src/engineering-bar.ts +69 -0
  11. package/src/event-bus.ts +10 -0
  12. package/src/git.ts +274 -5
  13. package/src/headstate.ts +471 -0
  14. package/src/history.ts +21 -3
  15. package/src/index.ts +127 -3943
  16. package/src/kill-escalation.ts +87 -7
  17. package/src/loader.ts +47 -1
  18. package/src/logging.ts +1 -1
  19. package/src/mode-prologue.ts +4 -10
  20. package/src/mode-runners.ts +1575 -0
  21. package/src/notify-completion.ts +180 -12
  22. package/src/params.ts +211 -37
  23. package/src/preflight.ts +123 -16
  24. package/src/prelude.ts +92 -7
  25. package/src/presets.ts +85 -18
  26. package/src/proc.ts +2 -3
  27. package/src/project-flags.ts +3 -3
  28. package/src/recovery-engine.ts +11 -1
  29. package/src/recovery-surface.ts +1 -2
  30. package/src/recovery.ts +155 -20
  31. package/src/reports.ts +1 -7
  32. package/src/run-registry.ts +22 -3
  33. package/src/runner.ts +80 -21
  34. package/src/runtime.ts +50 -0
  35. package/src/sanitize.ts +20 -2
  36. package/src/scheduler.ts +1 -2
  37. package/src/schema.ts +37 -7
  38. package/src/scratch-root.ts +909 -0
  39. package/src/scratch-spawn.ts +256 -0
  40. package/src/session-manager.ts +854 -200
  41. package/src/state.ts +130 -30
  42. package/src/templates.ts +42 -17
  43. package/src/terminal-notifier.ts +405 -0
  44. package/src/transcript.ts +1 -1
  45. package/src/tui-format.ts +177 -7
  46. package/src/tui.ts +115 -57
  47. package/src/types.ts +206 -5
  48. package/src/unit-params.ts +113 -0
  49. package/src/unit-run.ts +45 -16
  50. package/src/validate.ts +89 -11
  51. package/src/worktree-report.ts +142 -0
package/src/schema.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * Static<typeof delegateTaskParamsSchema>, so schema and types cannot drift.
6
6
  */
7
7
  import { Type } from "typebox";
8
- import { MAX_CHAIN_STEPS, MAX_PARALLEL_TASKS, MAX_GRAPH_TASKS } from "./types";
8
+ import { MAX_CHAIN_STEPS, MAX_PARALLEL_TASKS, MAX_GRAPH_TASKS, THINKING_LEVELS } from "./types";
9
9
 
10
10
  /**
11
11
  * Issue #381 (audit D7): the per-unit fields registered for `chain[]` steps,
@@ -24,8 +24,34 @@ const STEP_HEAD_FIELDS = {
24
24
  model: Type.Optional(Type.String({ description: "Model override for this step (provider/model-id). Defaults to the global subagent model." })),
25
25
  };
26
26
 
27
+ /**
28
+ * Issue #443: the accepted thinking levels as a schema `enum`, derived from
29
+ * `THINKING_LEVELS` so the declaration cannot drift from the runtime guard
30
+ * (`isThinkingLevel`).
31
+ *
32
+ * The EMPTY STRING is a member on purpose: it is an existing declaration with a
33
+ * meaning (call level → the configured maximum, per unit → inherit the global
34
+ * level), so the enum must not turn it into a validation failure. An `enum`
35
+ * beats a union of literals here because pi-schema's error names the whole set
36
+ * (`thinkingLevel: expected one of [...]`) instead of only the first branch.
37
+ *
38
+ * This is the FIRST line of defence only: pi validates raw tool arguments, so
39
+ * a preset object, a restored `retryRunId` value, the transport retry's rebuilt
40
+ * params and every per-unit declaration reach the handler WITHOUT passing here.
41
+ * `invalidThinkingLevelRejection` (prelude.ts) is the runtime guard.
42
+ */
43
+ const THINKING_LEVEL_ENUM = [...THINKING_LEVELS, ""];
44
+
27
45
  const STEP_THINKING_LEVEL_FIELD = {
28
- thinkingLevel: Type.Optional(Type.String({})),
46
+ thinkingLevel: Type.Optional(
47
+ Type.String({
48
+ enum: THINKING_LEVEL_ENUM,
49
+ description:
50
+ "Thinking level override for this subtask. Same values and rules as the call-level thinkingLevel: " +
51
+ `${THINKING_LEVELS.join(", ")} (exact match). An unknown value rejects the whole batch before anything starts. ` +
52
+ "Empty inherits the call-level level.",
53
+ }),
54
+ ),
29
55
  };
30
56
 
31
57
  /** Per-unit concurrency priority — tasks[] and graph[] only (issue #114). */
@@ -73,10 +99,12 @@ export const delegateTaskParamsSchema = Type.Object({
73
99
  ),
74
100
  thinkingLevel: Type.Optional(
75
101
  Type.String({
102
+ enum: THINKING_LEVEL_ENUM,
76
103
  description:
77
104
  "Requested thinking level for this subagent call. " +
78
- "One of: off, minimal, low, medium, high, xhigh. " +
79
- "Capped at the user's configured maximum. If omitted, the user's configured level is used.",
105
+ `One of: ${THINKING_LEVELS.join(", ")} — matched exactly, so case and whitespace matter. ` +
106
+ "An unknown value is rejected (pi's own `max` is not a delegated level). " +
107
+ "Capped at the user's configured maximum. If omitted, or an empty string, the user's configured level is used.",
80
108
  }),
81
109
  ),
82
110
  outputFile: Type.Optional(
@@ -114,7 +142,8 @@ export const delegateTaskParamsSchema = Type.Object({
114
142
  tools: Type.Optional(
115
143
  Type.Array(Type.String(), {
116
144
  description:
117
- "Explicit allowlist of tool names for the subagent. Maps to pi's --tools flag.",
145
+ "Explicit allowlist of tool names for the subagent. Maps to pi's --tools flag. " +
146
+ "An EMPTY array means no child tools (pi --no-tools); omitting the field keeps pi's defaults.",
118
147
  }),
119
148
  ),
120
149
  excludeTools: Type.Optional(
@@ -211,7 +240,8 @@ export const delegateTaskParamsSchema = Type.Object({
211
240
  minLength: 1,
212
241
  description:
213
242
  "Stated bypass for the Jev dispatch-line pre-flight, which is active ONLY in a project whose package.json sets the `brl-subagent.processChecks` field (this repository). " +
214
- "A NON-EMPTY reason string: the dispatch proceeds and the reason is surfaced as a warning in the result, so the bypass is never silent. " +
243
+ "A reason string that states WHY the line is missing: the dispatch proceeds and the reason is surfaced as a warning in the result, so the bypass is never silent. " +
244
+ "The reason is validated when the dispatch is handled, not by this schema: the argument validator coerces loosely typed input, so a boolean or a number arrives as its text (`true` becomes \"true\") and is REFUSED exactly like an absent bypass. " +
215
245
  "It bypasses ONLY the line check — capability conflicts still reject (unlike force). " +
216
246
  "Append `jev: unavailable` to the task instead when the classifier did not run.",
217
247
  }),
@@ -224,7 +254,7 @@ export const delegateTaskParamsSchema = Type.Object({
224
254
  "The conductor is woken with a completion message; use get_subagent_result for post-wake retrieval and stall checks. " +
225
255
  "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. " +
226
256
  "Default: conditional. Omitted, a single task or tasks fan-out runs in the BACKGROUND when the effective approvalMode is 'auto' (call param, else config); it stays foreground for 'writes'/'always' (a background run has no approval dialog, so the gate must stay in front of the user) and for chain/graph, which block by definition. " +
227
- "Pass background: false for a quick probe whose answer the next step needs inline. Explicit true/false wins. ONE pre-flight exception exists, and only in a project that opted into its own process checks (package.json `brl-subagent.processChecks: true`; this repository): a high/xhigh-thinking dispatch with background: false AND an explicit timeout is switched to background and the explicit timeout is dropped, because a foreground run loses its whole work at a timeout while a background run keeps its session and is retried on a transport error; pass force: true to keep it foreground. Without that project opt-in the explicit shape and its timeout stand. " +
257
+ "Pass background: false for a quick probe whose answer the next step needs inline. Explicit true/false wins. ONE pre-flight exception exists, and only in a project that opted into its own process checks (package.json `brl-subagent.processChecks: true`; this repository): a high/xhigh-thinking dispatch that resolves FOREGROUND and carries an explicit timeout loses that timeout, because a foreground run persists nothing and a deadline there loses all its work. The shape it lands in depends on the effective approvalMode (call param, else config), in two outcomes: when a background run is possible (explicit background: false with 'auto'/'writes') the dispatch is switched to background, where the 30-minute default applies; when it is not (an effective 'always', which background cannot present a dialog for, or an omitted background whose approval mode keeps it foreground) the run STAYS FOREGROUND with NO deadline at all, so the call blocks until the child settles instead of being killed. Either outcome is announced to the conductor and the user; pass force: true to keep the explicit timeout. The same judgement is made PER BATCH UNIT: a tasks/chain/graph unit that declares its own high/xhigh thinking level with a positive timeout has that unit's timeout dropped before it runs, while a background fan-out unit keeps its own — there the deadline is the budget. Without that project opt-in the explicit shape and its timeout stand. " +
228
258
  "A background run defaults to a 30-minute deadline when no timeout is given.",
229
259
  }),
230
260
  ),