brl-subagent 2.8.0 → 2.9.1
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 +17 -2
- package/README.md +3 -3
- package/package.json +6 -5
- package/src/agent-tools.ts +332 -0
- package/src/background-pipeline.ts +1025 -0
- package/src/boot-recovery.ts +360 -0
- package/src/commands.ts +137 -0
- package/src/concurrency.ts +3 -5
- package/src/delegate-handler.ts +2261 -0
- package/src/engineering-bar.ts +1 -1
- package/src/git.ts +220 -8
- package/src/headstate.ts +3 -3
- package/src/history.ts +21 -3
- package/src/index.ts +109 -4473
- package/src/loader.ts +1 -1
- package/src/logging.ts +67 -4
- package/src/mode-prologue.ts +4 -10
- package/src/mode-runners.ts +1575 -0
- package/src/notify-completion.ts +35 -8
- package/src/params.ts +14 -13
- package/src/preflight.ts +123 -16
- package/src/prelude.ts +14 -5
- package/src/presets.ts +3 -5
- package/src/proc.ts +2 -3
- package/src/recovery-engine.ts +1 -1
- package/src/recovery-surface.ts +1 -2
- package/src/recovery.ts +238 -10
- package/src/reports.ts +1 -7
- package/src/run-registry.ts +133 -10
- package/src/runner.ts +47 -18
- package/src/runtime.ts +50 -0
- package/src/sanitize.ts +20 -2
- package/src/scheduler.ts +1 -2
- package/src/schema.ts +4 -2
- package/src/scratch-root.ts +909 -0
- package/src/scratch-spawn.ts +256 -0
- package/src/session-manager.ts +587 -81
- package/src/state.ts +12 -14
- package/src/templates.ts +3 -5
- package/src/terminal-notifier.ts +405 -0
- package/src/transcript.ts +1 -1
- package/src/tui-format.ts +3 -1
- package/src/tui.ts +46 -36
- package/src/types.ts +29 -3
- package/src/unit-params.ts +113 -0
- package/src/unit-run.ts +35 -15
- package/src/validate.ts +28 -9
- package/src/worktree-report.ts +142 -0
package/src/runtime.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Purpose: The per-invocation runtime context (pi, log, state) the composition root builds once and hands to the mode runners.
|
|
2
|
+
/**
|
|
3
|
+
* brl-subagent — the runtime context (cycle S2, ADR 0027 D1/D3)
|
|
4
|
+
*
|
|
5
|
+
* ADR 0027 D1 splits the composition root from the code it composes. The mode
|
|
6
|
+
* runners (S2) are the first consumers that need the three long-lived bindings
|
|
7
|
+
* `src/index.ts`'s `default` export used to own as closures: `pi` (the extension
|
|
8
|
+
* API), `log` (the session logger) and `state` (the session-bound store).
|
|
9
|
+
*
|
|
10
|
+
* `RuntimeContext` names those three, and `createRuntime` builds them with the
|
|
11
|
+
* exact order and arguments `index.ts` used inline — `createLogger` first
|
|
12
|
+
* because `createSessionState` takes the logger. D1 is why this is a value, not
|
|
13
|
+
* a module-level singleton: one context per `initExtension` invocation, so two
|
|
14
|
+
* loaded sessions in one process share no state.
|
|
15
|
+
*
|
|
16
|
+
* Deliberately NOT part of the context (D3): `sessionCtx`,
|
|
17
|
+
* `recoveryNoticeDelivered` and the other `default`-export closures. The runners
|
|
18
|
+
* never read them (recon at 46b427e: zero references across the moved range);
|
|
19
|
+
* adding one here without a consumer would be a binding the split does not
|
|
20
|
+
* need. ADR 0027 F1: if a runner ever needs a fourth field, the split is wrong —
|
|
21
|
+
* report it rather than widening this interface.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
25
|
+
import { createLogger, type Logger } from "./logging";
|
|
26
|
+
import { createSessionState, type SessionState } from "./state";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The three bindings the mode runners read, captured once per extension
|
|
30
|
+
* invocation. `readonly` because the split's contract is "handed in, never
|
|
31
|
+
* rebound": `createRuntime` produces it, `createModeRunners` destructures it,
|
|
32
|
+
* and nothing downstream reassigns a field (a rebind would be a second owner).
|
|
33
|
+
*/
|
|
34
|
+
export interface RuntimeContext {
|
|
35
|
+
readonly pi: ExtensionAPI;
|
|
36
|
+
readonly log: Logger;
|
|
37
|
+
readonly state: SessionState;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Build the runtime context for one extension invocation — the same two calls
|
|
42
|
+
* `index.ts` made inline (log → state, in that order). The only reason this is a
|
|
43
|
+
* function rather than three lines at the call site: the S2 boundary test drives
|
|
44
|
+
* two contexts and asserts they are independent (ADR 0027 D1).
|
|
45
|
+
*/
|
|
46
|
+
export function createRuntime(pi: ExtensionAPI): RuntimeContext {
|
|
47
|
+
const log = createLogger("brl-subagent");
|
|
48
|
+
const state = createSessionState(log);
|
|
49
|
+
return { pi, log, state };
|
|
50
|
+
}
|
package/src/sanitize.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import * as path from "node:path";
|
|
10
10
|
import * as fs from "node:fs";
|
|
11
11
|
import { EMPTY_USAGE, DEFAULT_OUTPUT_CAP_BYTES } from "./types";
|
|
12
|
+
import { appendWorktreeState } from "./worktree-report";
|
|
12
13
|
|
|
13
14
|
// ---------------------------------------------------------------------------
|
|
14
15
|
// F1: Input sanitization
|
|
@@ -152,6 +153,14 @@ export function assertSafeAgentId(id: string): void {
|
|
|
152
153
|
const SAFE_ENV_KEYS = new Set([
|
|
153
154
|
"PATH",
|
|
154
155
|
"HOME",
|
|
156
|
+
// Issue #511 (U2): the Windows halves of the same question. The shipped
|
|
157
|
+
// scratch root is `%LOCALAPPDATA%\brl-subagent` there, and `USERPROFILE` is
|
|
158
|
+
// what a nested child needs to find its own home at all — `HOME` alone leaves
|
|
159
|
+
// a Windows grandchild with no root to resolve. Symmetric with `HOME`, and
|
|
160
|
+
// deliberately NOT a place for `BRL_SCRATCH`: that value is per-run, so it is
|
|
161
|
+
// overridden at the spawn seam and stripped from anything inherited.
|
|
162
|
+
"USERPROFILE",
|
|
163
|
+
"LOCALAPPDATA",
|
|
155
164
|
"USER",
|
|
156
165
|
"LANG",
|
|
157
166
|
"LC_ALL",
|
|
@@ -316,7 +325,7 @@ function neutralizePathPrefix(text: string, prefix: string, replacement: string)
|
|
|
316
325
|
* 4. Caps length at 2000 chars with an ellipsis marker.
|
|
317
326
|
*
|
|
318
327
|
* Remaining-absolute-path policy: paths OUTSIDE the project root and its
|
|
319
|
-
* parent are left as-is (e.g. `/etc/passwd`, `/usr/bin/node`, `/
|
|
328
|
+
* parent are left as-is (e.g. `/etc/passwd`, `/usr/bin/node`, `/var/log/x.log`).
|
|
320
329
|
* Issue #30 is specifically about CWD/home disclosure; system paths carry no
|
|
321
330
|
* personal structure and keeping them preserves debugging value. Messages
|
|
322
331
|
* that are short and clean (no ANSI, no cwd/parent prefixes) pass through
|
|
@@ -357,6 +366,13 @@ export function sanitizeErrorMessage(msg: string, cwd?: string): string {
|
|
|
357
366
|
* serializes `content` into the LLM context, while the raw text persists to
|
|
358
367
|
* the session file for post-mortems (issue #68 framing: extraction is DRY,
|
|
359
368
|
* not a stderr-content change).
|
|
369
|
+
*
|
|
370
|
+
* Issue #474: this is the ONE crash seam (single, chain, graph and the per-unit
|
|
371
|
+
* finalizer all build their envelope here), so the worktree-state block is
|
|
372
|
+
* appended here rather than at seven call sites. `err` may carry the crashing
|
|
373
|
+
* UNIT's own block (`finalizeUnitRunCrash` attaches it) and that wins over
|
|
374
|
+
* `cwd`, which a mode-level caller only knows as the dispatch cwd. The block is
|
|
375
|
+
* appended, never spliced: the cause reads first, the residue after.
|
|
360
376
|
*/
|
|
361
377
|
export function buildCrashResult(mode: string, err: unknown, cwd: string): {
|
|
362
378
|
content: Array<{ type: "text"; text: string }>;
|
|
@@ -374,7 +390,9 @@ export function buildCrashResult(mode: string, err: unknown, cwd: string): {
|
|
|
374
390
|
cwd,
|
|
375
391
|
);
|
|
376
392
|
return {
|
|
377
|
-
content: [
|
|
393
|
+
content: [
|
|
394
|
+
{ type: "text", text: appendWorktreeState(`${mode} crashed: ${errorMessage}`, cwd, err) },
|
|
395
|
+
],
|
|
378
396
|
details: {
|
|
379
397
|
messages: [],
|
|
380
398
|
usage: { ...EMPTY_USAGE },
|
package/src/scheduler.ts
CHANGED
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* and graph validation for P10 dependency graph mode.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type
|
|
10
|
-
import { MAX_GRAPH_TASKS } from "./types";
|
|
9
|
+
import { MAX_GRAPH_TASKS, type GraphTask } from "./types";
|
|
11
10
|
|
|
12
11
|
// ---------------------------------------------------------------------------
|
|
13
12
|
// Cycle detection — three-color DFS
|
package/src/schema.ts
CHANGED
|
@@ -128,8 +128,10 @@ export const delegateTaskParamsSchema = Type.Object({
|
|
|
128
128
|
Type.Number({
|
|
129
129
|
description:
|
|
130
130
|
"Maximum time in milliseconds the subagent is allowed to run. " +
|
|
131
|
-
"
|
|
132
|
-
"
|
|
131
|
+
"A **background** run with no valid timeout (none passed, or normalized away) gets the 30-minute default deadline; a **foreground** run has no default. " +
|
|
132
|
+
"An explicit **positive** timeout is honored as given, except values that normalize to no timeout (a raw value `≥ 2^31-1` or a nonpositive value; a background run then gets the 30-minute default, a foreground run has none) and the opt-in `processChecks` high/xhigh foreground switch, which may drop an explicit timeout. " +
|
|
133
|
+
"**Foreground expiry** kills the process (SIGTERM, 5s grace, then SIGKILL); the expired attempt's result is a timeout error, and with `retryOnTimeout: true` the tool may retry automatically and return the later result. " +
|
|
134
|
+
"**Background expiry** requests a cooperative abort — a prompt that ignores it keeps running; the run's **timeout snapshot** (`failed`/`timeout`) is written at expiry, and a later settle **amends** that record (never re-classifies it).",
|
|
133
135
|
}),
|
|
134
136
|
),
|
|
135
137
|
cwd: Type.Optional(
|