brl-subagent 2.9.1 → 2.9.2
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 +3 -0
- package/README.md +11 -5
- package/package.json +7 -6
- package/src/agent-tools.ts +178 -19
- package/src/atomic-write.ts +101 -0
- package/src/background-guard.ts +295 -0
- package/src/background-pipeline.ts +19 -1
- package/src/boot-recovery.ts +16 -0
- package/src/brief.ts +228 -0
- package/src/delegate-handler.ts +39 -6
- package/src/dispatch-header.ts +230 -0
- package/src/index.ts +26 -0
- package/src/notify-completion.ts +81 -12
- package/src/params.ts +9 -1
- package/src/project-flags.ts +39 -2
- package/src/recovery-engine.ts +16 -2
- package/src/recovery.ts +29 -0
- package/src/retry-armed.ts +383 -0
- package/src/run-registry.ts +26 -1
- package/src/session-manager.ts +410 -38
- package/src/stop-lineage.ts +280 -0
- package/src/templates.ts +97 -1
- package/src/terminal-notifier.ts +69 -3
- package/src/types.ts +94 -0
- package/src/validate.ts +57 -0
- package/templates/analyze-data.md +1 -0
- package/templates/code-review.md +1 -0
- package/templates/debug-issue.md +1 -0
- package/templates/implement-feature.md +1 -0
- package/templates/prototype.md +1 -0
- package/templates/refactor.md +1 -0
- package/templates/security-audit.md +1 -0
- package/templates/write-docs.md +1 -0
- package/templates/write-tests.md +1 -0
package/src/types.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* All shared type definitions and constants for the brl-subagent extension.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import type { DispatchKind } from "./dispatch-header";
|
|
8
9
|
import type { delegateTaskParamsSchema } from "./schema";
|
|
9
10
|
import type { TranscriptMessage } from "./transcript-tail";
|
|
10
11
|
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
@@ -31,6 +32,38 @@ export type RecoveryMode = (typeof RECOVERY_MODES)[number];
|
|
|
31
32
|
|
|
32
33
|
export const DEFAULT_RECOVERY: RecoveryMode = "offer";
|
|
33
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Issue #616: the TERMINAL statuses of an agent record — one definition, shared
|
|
37
|
+
* by `session-manager`'s `isTerminalAgentStatus` (the long-standing export) and
|
|
38
|
+
* by the stop contract, which must not accept the word "Stopped" for a record
|
|
39
|
+
* that is still live.
|
|
40
|
+
*/
|
|
41
|
+
export const TERMINAL_AGENT_STATUSES = ["completed", "failed", "stopped"] as const;
|
|
42
|
+
|
|
43
|
+
export function isTerminalAgentStatusValue(status: AgentStatus): boolean {
|
|
44
|
+
return (TERMINAL_AGENT_STATUSES as readonly string[]).includes(status);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Issue #616: WHY a retry attempt exists. Two different retries mint the same
|
|
49
|
+
* lineage shape (same `dispatchId`, `resumeOf` pointing at the source,
|
|
50
|
+
* `attempt + 1`), so the shape alone cannot tell them apart:
|
|
51
|
+
*
|
|
52
|
+
* - `"transport"` — the background transport auto-retry (#365): the run died
|
|
53
|
+
* on a transport-class error and one replacement was dispatched for it.
|
|
54
|
+
* It is part of the dispatch a `stop_subagent` aims at.
|
|
55
|
+
* - `"manual"` — a caller-driven retry (`retryRunId`): a run someone
|
|
56
|
+
* deliberately started. A stop aimed at the original dispatch must NOT
|
|
57
|
+
* halt it (naming it directly does).
|
|
58
|
+
*
|
|
59
|
+
* Additive by contract: a record written before this field exists lacks it, and
|
|
60
|
+
* ABSENT READS AS **UNKNOWN** — never as either cause, and never as the
|
|
61
|
+
* stop-scoped one. Inference from the parent's failure class cannot substitute:
|
|
62
|
+
* a manual retry of a transport-failed attempt looks identical (issue #616 F6).
|
|
63
|
+
*/
|
|
64
|
+
export const RETRY_CAUSES = ["transport", "manual"] as const;
|
|
65
|
+
export type RetryCause = (typeof RETRY_CAUSES)[number];
|
|
66
|
+
|
|
34
67
|
export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
35
68
|
|
|
36
69
|
export const THINKING_LEVELS: ThinkingLevel[] = ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
@@ -110,6 +143,19 @@ export const SUBAGENT_SIGNAL_KILLED_MESSAGE = "Subagent killed by external signa
|
|
|
110
143
|
// timeout, an abort, or an exit error.
|
|
111
144
|
export const PROMPT_NEVER_ISSUED_MESSAGE = "Subagent prompt was never issued";
|
|
112
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Issue #616 (Q3): the stamp on a transport retry that a dispatch-scoped stop
|
|
148
|
+
* cancelled while it was being set up — armed, but never prompted. Shared by the
|
|
149
|
+
* pre-prompt gate that writes it (session-manager) and the stop tool, which
|
|
150
|
+
* reports the cancel, so the two surfaces cannot describe the same non-event
|
|
151
|
+
* differently.
|
|
152
|
+
*
|
|
153
|
+
* It deliberately carries the "aborted" vocabulary `classifyError` already maps
|
|
154
|
+
* (like SUBAGENT_ABORTED_MESSAGE): a cancelled retry is a stop, never a failure.
|
|
155
|
+
*/
|
|
156
|
+
export const CANCELLED_RETRY_MESSAGE =
|
|
157
|
+
"Transport retry stopped before its prompt was issued (cancelled by stop_subagent)";
|
|
158
|
+
|
|
113
159
|
/**
|
|
114
160
|
* Classify a subagent result into an error category based on its errorMessage,
|
|
115
161
|
* stopReason, exitCode, and stderr content. Inspects patterns in priority order.
|
|
@@ -201,6 +247,12 @@ export interface TaskTemplate {
|
|
|
201
247
|
excludeTools?: string[];
|
|
202
248
|
noBuiltinTools?: boolean;
|
|
203
249
|
inheritSystemPrompt?: boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Issue #606 (§3a): the kind a rendered dispatch declares. Validated as an
|
|
252
|
+
* ENUM (an unknown or misspelled value is a render error naming the field
|
|
253
|
+
* and the allowed set — never a silently ignored key).
|
|
254
|
+
*/
|
|
255
|
+
dispatch?: DispatchKind;
|
|
204
256
|
}
|
|
205
257
|
|
|
206
258
|
export interface CircuitBreakerState {
|
|
@@ -406,6 +458,12 @@ export interface SubagentRun {
|
|
|
406
458
|
dispatchId?: string;
|
|
407
459
|
resumeOf?: string;
|
|
408
460
|
attempt?: number;
|
|
461
|
+
/**
|
|
462
|
+
* Issue #616: why THIS attempt exists. Absent on a first dispatch and on every
|
|
463
|
+
* record written before the field existed — absent means UNKNOWN, and unknown
|
|
464
|
+
* is never treated as the stop-scoped cause (`transport`).
|
|
465
|
+
*/
|
|
466
|
+
retryCause?: RetryCause;
|
|
409
467
|
interruptedAt?: string;
|
|
410
468
|
owner?: ProcessOwner;
|
|
411
469
|
childMarker?: string;
|
|
@@ -852,6 +910,17 @@ export interface BackgroundAgent {
|
|
|
852
910
|
// Issue #114: per-unit priority for the drill-in header (`p:critical` etc.).
|
|
853
911
|
priority?: string;
|
|
854
912
|
error?: string;
|
|
913
|
+
/**
|
|
914
|
+
* Issue #574: the KIND of this record's terminal state, stamped by the status
|
|
915
|
+
* flip that produced it — a deadline and a user stop are BOTH
|
|
916
|
+
* `status:"stopped"`, so the status alone cannot name the friction. Additive:
|
|
917
|
+
* absent on records written before the field existed, and never invented by
|
|
918
|
+
* the settlement or the boot scan (a record that stopped for an unknown
|
|
919
|
+
* reason reads as "no kind known", not as `aborted`).
|
|
920
|
+
*/
|
|
921
|
+
errorCategory?: ErrorCategory;
|
|
922
|
+
/** The terminal stopReason of that same flip (mirrors `SubagentRun.stopReason`). */
|
|
923
|
+
stopReason?: string;
|
|
855
924
|
result?: SubagentResult;
|
|
856
925
|
finalOutput?: string;
|
|
857
926
|
/**
|
|
@@ -885,6 +954,10 @@ export interface BackgroundAgent {
|
|
|
885
954
|
dispatchId?: string;
|
|
886
955
|
resumeOf?: string;
|
|
887
956
|
attempt?: number;
|
|
957
|
+
// Issue #616: why this attempt exists (mirrors `SubagentRun.retryCause`).
|
|
958
|
+
// Persisted so the stop lineage can scope a dispatch-scoped stop to the
|
|
959
|
+
// automatic transport retries; absent means unknown, never "transport".
|
|
960
|
+
retryCause?: RetryCause;
|
|
888
961
|
interruptedAt?: string;
|
|
889
962
|
owner?: ProcessOwner;
|
|
890
963
|
childMarker?: string;
|
|
@@ -1310,9 +1383,30 @@ export function isSubagentRunShape(value: unknown): value is SubagentRun {
|
|
|
1310
1383
|
if (v.recoveryPosture !== undefined) {
|
|
1311
1384
|
if (!RECOVERY_MODES.includes(v.recoveryPosture as RecoveryMode)) return false;
|
|
1312
1385
|
}
|
|
1386
|
+
// Issue #616: a MISTYPED retry cause is rejected like any other bad field; an
|
|
1387
|
+
// ABSENT one is fine (a first dispatch, and every pre-#616 record) and reads
|
|
1388
|
+
// as unknown through `runRetryCause`.
|
|
1389
|
+
if (v.retryCause !== undefined) {
|
|
1390
|
+
if (!(RETRY_CAUSES as readonly unknown[]).includes(v.retryCause)) return false;
|
|
1391
|
+
}
|
|
1313
1392
|
return true;
|
|
1314
1393
|
}
|
|
1315
1394
|
|
|
1395
|
+
/**
|
|
1396
|
+
* Issue #616: the retry cause recorded for an attempt, or `undefined` when it
|
|
1397
|
+
* cannot be established. ONE reader, so no consumer invents a cause: absent (a
|
|
1398
|
+
* first dispatch, a pre-#616 record) and an unrecognized value both read as
|
|
1399
|
+
* unknown. Unknown is NOT `"transport"` — the stop contract must never widen a
|
|
1400
|
+
* dispatch-scoped stop on a cause it cannot prove.
|
|
1401
|
+
*/
|
|
1402
|
+
export function runRetryCause(
|
|
1403
|
+
run: Pick<SubagentRun, "retryCause">,
|
|
1404
|
+
): RetryCause | undefined {
|
|
1405
|
+
return (RETRY_CAUSES as readonly unknown[]).includes(run.retryCause)
|
|
1406
|
+
? run.retryCause
|
|
1407
|
+
: undefined;
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1316
1410
|
/**
|
|
1317
1411
|
* Option B U3 (D4): the recovery posture recorded for a run. Absent (pre-U3
|
|
1318
1412
|
* records) or an unrecognized value reads as the default "offer" — the
|
package/src/validate.ts
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
import { THINKING_LEVELS, type ThinkingLevel, type SubagentToolOptions } from './types';
|
|
11
11
|
import { DISPATCH_LINE_FORM, JEV_UNAVAILABLE, parseDispatchLine } from './dispatch-line';
|
|
12
|
+
import { parseDispatchHeader, type BriefDeclaration } from './dispatch-header';
|
|
13
|
+
import { validateBriefFile } from './brief';
|
|
12
14
|
import { isProcessChecksEnabled } from './project-flags';
|
|
13
15
|
|
|
14
16
|
// ── Types ────────────────────────────────────────────────────────────
|
|
@@ -380,6 +382,56 @@ function readNoJevReason(value: unknown): NoJevVerdict {
|
|
|
380
382
|
return { kind: 'reason', reason };
|
|
381
383
|
}
|
|
382
384
|
|
|
385
|
+
// ── The dispatch header (issue #606, Unit 1) ─────────────────────────
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* The mandatory dispatch header, checked at the same seam as the Jev line and
|
|
389
|
+
* behind the SAME umbrella flag (#415) — no new manifest key. Four rules
|
|
390
|
+
* (spec §3), each refused with the three accepted forms quoted verbatim:
|
|
391
|
+
*
|
|
392
|
+
* 1. no `dispatch:` in the leading block → refused;
|
|
393
|
+
* 2. `dispatch: impl` with no `brief:` → refused;
|
|
394
|
+
* 3. `brief: <slug>` → briefs/<slug>.md in the dispatch
|
|
395
|
+
* cwd's tree must exist and satisfy §2 (src/brief.ts), else refused;
|
|
396
|
+
* 4. `brief: none — <reason>` → valid, WARNED with the reason.
|
|
397
|
+
*
|
|
398
|
+
* Rule 4 is warning-class on every validating path on purpose: the escape is a
|
|
399
|
+
* recorded gap (like noJev), not a silent one, and the statement "no code from
|
|
400
|
+
* an unagreed plan" stays honest only while an escape is visible (a refusal or
|
|
401
|
+
* a surfaced warning — never a quiet pass).
|
|
402
|
+
*/
|
|
403
|
+
function checkDispatchHeader(
|
|
404
|
+
taskText: string,
|
|
405
|
+
cwd: string | undefined,
|
|
406
|
+
errors: string[],
|
|
407
|
+
warnings: string[],
|
|
408
|
+
): void {
|
|
409
|
+
// Unreachable behind the flag (a check that is ON has a cwd), stated so the
|
|
410
|
+
// seam never depends on that inference.
|
|
411
|
+
if (cwd === undefined) return;
|
|
412
|
+
|
|
413
|
+
const verdict = parseDispatchHeader(taskText);
|
|
414
|
+
if (!verdict.ok) {
|
|
415
|
+
errors.push(verdict.reason);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const brief: BriefDeclaration | undefined = verdict.brief;
|
|
420
|
+
if (brief === undefined) return;
|
|
421
|
+
|
|
422
|
+
if (brief.kind === "none") {
|
|
423
|
+
warnings.push(
|
|
424
|
+
`dispatch: ${verdict.kind} escaped the signed brief — no brief was agreed because ${brief.reason}`,
|
|
425
|
+
);
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const checked = validateBriefFile(cwd, brief.slug);
|
|
430
|
+
if (!checked.ok) {
|
|
431
|
+
errors.push(checked.reason);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
383
435
|
// ── Main validation ──────────────────────────────────────────────────
|
|
384
436
|
|
|
385
437
|
export function validatePreTask(config: ValidateConfig): ValidateResult {
|
|
@@ -427,6 +479,11 @@ export function validatePreTask(config: ValidateConfig): ValidateResult {
|
|
|
427
479
|
);
|
|
428
480
|
}
|
|
429
481
|
}
|
|
482
|
+
|
|
483
|
+
// Issue #606 (Unit 1): the dispatch header, behind the SAME flag. It runs
|
|
484
|
+
// after the Jev check so a task missing both names both — a conductor
|
|
485
|
+
// should not have to re-dispatch twice to learn two independent rules.
|
|
486
|
+
checkDispatchHeader(taskText, config.cwd, errors, warnings);
|
|
430
487
|
}
|
|
431
488
|
|
|
432
489
|
// Check tool requirements. A missing capability is warning-class by
|
package/templates/code-review.md
CHANGED
package/templates/debug-issue.md
CHANGED
package/templates/prototype.md
CHANGED
package/templates/refactor.md
CHANGED
package/templates/write-docs.md
CHANGED