brl-subagent 2.9.1 → 2.9.3
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/CHANGELOG.md +366 -0
- package/README.md +11 -5
- package/package.json +14 -11
- 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 +21 -5
- package/src/boot-recovery.ts +16 -0
- package/src/brief.ts +228 -0
- package/src/delegate-handler.ts +51 -12
- package/src/dispatch-header.ts +226 -0
- package/src/history.ts +0 -6
- package/src/index.ts +27 -5
- package/src/kill-escalation.ts +32 -9
- package/src/mode-prologue.ts +3 -11
- package/src/mode-runners.ts +0 -3
- package/src/notify-completion.ts +81 -12
- package/src/params.ts +10 -2
- package/src/prelude.ts +1 -9
- package/src/proc.ts +73 -15
- package/src/project-flags.ts +42 -6
- 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 +121 -1
- package/src/runner.ts +308 -10
- package/src/schema.ts +0 -11
- package/src/session-manager.ts +490 -54
- package/src/state.ts +16 -1
- package/src/stop-lineage.ts +280 -0
- package/src/templates.ts +97 -1
- package/src/terminal-notifier.ts +70 -4
- package/src/types.ts +110 -0
- package/src/unit-run.ts +7 -2
- package/src/validate.ts +47 -86
- 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/dispatch-line.ts +0 -144
package/src/delegate-handler.ts
CHANGED
|
@@ -111,7 +111,7 @@ import {
|
|
|
111
111
|
import { delegateTaskParamsSchema } from "./schema";
|
|
112
112
|
import { readProcessChecks } from "./project-flags";
|
|
113
113
|
import { buildSubagentPrompt, describePromptMode } from "./prompt";
|
|
114
|
-
import { runSubagent } from "./runner";
|
|
114
|
+
import { runSubagent, usageGroupsFrom } from "./runner";
|
|
115
115
|
import { currentProcessOwner, newDispatchIdentity } from "./recovery";
|
|
116
116
|
import { writeHeadState, clearHeadState, HEAD_STATE_VERSION } from "./headstate";
|
|
117
117
|
import { clearInflightRun } from "./run-registry";
|
|
@@ -295,7 +295,7 @@ function warnUnknownParams(
|
|
|
295
295
|
function applyTemplate(
|
|
296
296
|
params: DelegateTaskParams,
|
|
297
297
|
templates: readonly TaskTemplate[],
|
|
298
|
-
deps: Pick<NormalizeDeps, "pi" | "log">,
|
|
298
|
+
deps: Pick<NormalizeDeps, "pi" | "log" | "ctx">,
|
|
299
299
|
): Outcome<void> {
|
|
300
300
|
const { pi, log } = deps;
|
|
301
301
|
if (!params.template) return { ok: true, value: undefined };
|
|
@@ -318,7 +318,11 @@ function applyTemplate(
|
|
|
318
318
|
};
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
-
|
|
321
|
+
// Issue #606 (§3a): the renderer needs the DISPATCH cwd, because a template
|
|
322
|
+
// with no `dispatch:` field is refused only where the project opted in.
|
|
323
|
+
const resolved = resolveTemplate(templateEntry, params.params ?? {}, {
|
|
324
|
+
cwd: templateDispatchCwd(params, deps.ctx),
|
|
325
|
+
});
|
|
322
326
|
if (!resolved.ok) {
|
|
323
327
|
return {
|
|
324
328
|
ok: false,
|
|
@@ -376,6 +380,18 @@ function applyTemplate(
|
|
|
376
380
|
return { ok: true, value: undefined };
|
|
377
381
|
}
|
|
378
382
|
|
|
383
|
+
/**
|
|
384
|
+
* The cwd a rendered dispatch will run in, as far as THIS seam can know it:
|
|
385
|
+
* the call's own `cwd` resolved against the harness cwd, else the harness cwd.
|
|
386
|
+
* The later resolver may refine it (a worktree branch, a per-step cwd), so this
|
|
387
|
+
* is the project the CONDUCTOR named — and the read is fail-open, which is what
|
|
388
|
+
* keeps a template rendering untouched in a project that never opted in.
|
|
389
|
+
*/
|
|
390
|
+
function templateDispatchCwd(params: DelegateTaskParams, ctx: ExtensionContext): string {
|
|
391
|
+
const declared = typeof params.cwd === "string" ? params.cwd : "";
|
|
392
|
+
return declared === "" ? ctx.cwd : path.resolve(ctx.cwd, declared);
|
|
393
|
+
}
|
|
394
|
+
|
|
379
395
|
/**
|
|
380
396
|
* Seam A — resolve the dispatch inputs: unknown-param warning, template
|
|
381
397
|
* resolution, retry restore (issue #430).
|
|
@@ -402,7 +418,7 @@ function normalizeInput(
|
|
|
402
418
|
// A1: the two pre-resolution notices (unknown keys, ignored task) and the
|
|
403
419
|
// template application itself.
|
|
404
420
|
warnUnknownParams(params, { pi, log });
|
|
405
|
-
const templated = applyTemplate(params, state.config.templates, { pi, log });
|
|
421
|
+
const templated = applyTemplate(params, state.config.templates, { pi, log, ctx });
|
|
406
422
|
if (!templated.ok) return templated;
|
|
407
423
|
|
|
408
424
|
// Handle retryRunId — MUST run after template resolution and before the
|
|
@@ -881,7 +897,19 @@ function routeDispatch(
|
|
|
881
897
|
if (useBackground) {
|
|
882
898
|
return {
|
|
883
899
|
kind: "returned",
|
|
884
|
-
|
|
900
|
+
// Issue #616: a background spawn reached from `delegate_task` is a
|
|
901
|
+
// CALLER-driven retry when a `retryRunId` resolved — `"manual"`, never
|
|
902
|
+
// `"transport"`. Only `scheduleTransportRetry` may claim the automatic
|
|
903
|
+
// cause, because only it IS the automatic retry.
|
|
904
|
+
result: runners.spawnBackgroundRun(
|
|
905
|
+
pi,
|
|
906
|
+
ctx,
|
|
907
|
+
params,
|
|
908
|
+
singleTask,
|
|
909
|
+
retrySourceRun,
|
|
910
|
+
undefined,
|
|
911
|
+
retrySourceRun ? "manual" : undefined,
|
|
912
|
+
),
|
|
885
913
|
};
|
|
886
914
|
}
|
|
887
915
|
|
|
@@ -944,7 +972,7 @@ interface ForegroundPrepared {
|
|
|
944
972
|
*
|
|
945
973
|
* `force` degrades a capability error to a warning (B2's override) — the flag
|
|
946
974
|
* is read off `params` here because it is a CALL-level decision, not a resolved
|
|
947
|
-
* value; `cwd
|
|
975
|
+
* value; `cwd` likewise reaches H1 straight from the dispatch.
|
|
948
976
|
*/
|
|
949
977
|
function prepareForeground(
|
|
950
978
|
params: DelegateTaskParams,
|
|
@@ -1050,7 +1078,6 @@ function prepareForeground(
|
|
|
1050
1078
|
outputFile: resolvedOutputFile,
|
|
1051
1079
|
force: params.force,
|
|
1052
1080
|
cwd: resolvedCwd,
|
|
1053
|
-
noJev: params.noJev,
|
|
1054
1081
|
});
|
|
1055
1082
|
if (validation.warnings.length > 0) {
|
|
1056
1083
|
log.warn("Pre-task validation warnings", { warnings: validation.warnings });
|
|
@@ -1524,7 +1551,11 @@ function registerForegroundRun(
|
|
|
1524
1551
|
// Option B U1: durability identity — a retry inherits the original
|
|
1525
1552
|
// dispatchId and records resumeOf/attempt; a fresh marker keys the
|
|
1526
1553
|
// child process for boot-time orphan discovery.
|
|
1527
|
-
|
|
1554
|
+
// Issue #616: a foreground retry is always CALLER-driven (`retryRunId` or
|
|
1555
|
+
// `retryOnTimeout`), so its cause is `manual` — there is no automatic
|
|
1556
|
+
// foreground retry. Recorded for completeness; a foreground run has no agent
|
|
1557
|
+
// record, so the dispatch-scoped stop never reaches it (stated non-goal).
|
|
1558
|
+
const identity = newDispatchIdentity(retrySourceRun, retrySourceRun ? "manual" : undefined);
|
|
1528
1559
|
// Issue #511 (U2): create this run's scratch directory at record creation so
|
|
1529
1560
|
// the record can name it (the retry preamble, U3, reads `scratchDir`). The
|
|
1530
1561
|
// spawn seam in `runner.ts` re-prepares idempotently and is the gate that
|
|
@@ -1545,6 +1576,7 @@ function registerForegroundRun(
|
|
|
1545
1576
|
dispatchId: identity.dispatchId,
|
|
1546
1577
|
resumeOf: identity.resumeOf,
|
|
1547
1578
|
attempt: identity.attempt,
|
|
1579
|
+
retryCause: identity.retryCause,
|
|
1548
1580
|
owner: currentProcessOwner(),
|
|
1549
1581
|
childMarker: crypto.randomUUID(),
|
|
1550
1582
|
// U3 (D4): the session recovery posture at dispatch.
|
|
@@ -1769,7 +1801,9 @@ function terminalizePreStartRejection(
|
|
|
1769
1801
|
};
|
|
1770
1802
|
finalizeRunRecord(run, rejection, "", new Date(run.startedAt).getTime());
|
|
1771
1803
|
run.originalParams = { ...run.originalParams, errorCategory: rejection.errorCategory };
|
|
1772
|
-
|
|
1804
|
+
// Issue #648: nothing ran, so the group list is empty by measurement and the
|
|
1805
|
+
// run record is still written — the required payload makes that explicit.
|
|
1806
|
+
state.persistSettledRun(pi, run, usageGroupsFrom(rejection.messages));
|
|
1773
1807
|
state.finalizeLiveSubagent(run.id);
|
|
1774
1808
|
}
|
|
1775
1809
|
|
|
@@ -1917,7 +1951,10 @@ function finalizeForegroundResult(
|
|
|
1917
1951
|
...run.originalParams,
|
|
1918
1952
|
errorCategory: result.errorCategory,
|
|
1919
1953
|
};
|
|
1920
|
-
|
|
1954
|
+
// Issue #648 (Q6): the terminal write carries the run's spend through the
|
|
1955
|
+
// required-payload choke point — `result` is the LAST attempt's result, so the
|
|
1956
|
+
// same-id timeout re-entry appends the retry's groups exactly once.
|
|
1957
|
+
state.persistSettledRun(pi, run, usageGroupsFrom(result.messages));
|
|
1921
1958
|
|
|
1922
1959
|
// R2: Prune old run entries
|
|
1923
1960
|
pruneHistoryIfNeeded(state, ctx, log);
|
|
@@ -2073,7 +2110,9 @@ function finalizeCrashedRun(err: unknown, run: SubagentRun, deps: CrashDeps): To
|
|
|
2073
2110
|
crashOutput,
|
|
2074
2111
|
new Date(run.startedAt).getTime(),
|
|
2075
2112
|
);
|
|
2076
|
-
|
|
2113
|
+
// Issue #648: a crash carries no assistant turns of its own; the crash
|
|
2114
|
+
// result's (empty) messages are the measured source.
|
|
2115
|
+
state.persistSettledRun(pi, run, usageGroupsFrom(result.details.messages));
|
|
2077
2116
|
|
|
2078
2117
|
return result;
|
|
2079
2118
|
}
|
|
@@ -2154,7 +2193,7 @@ export function createDelegateHandler(
|
|
|
2154
2193
|
`Use preset to apply a delegation configuration (built-in or custom via /brl-subagent preset). Preset values are defaults — explicit parameters override them. IMPORTANT: some presets restrict tools — e.g. outputFile requires the subagent's write tool, which security-auditor and code-reviewer exclude. Built-in presets: ${presetRestrictionSummary}. Custom presets are NOT listed here — inspect them via /brl-subagent preset before combining with outputFile or tool-dependent work. When combining a preset with outputFile or tool-dependent work, verify the preset allows the required tools.`,
|
|
2155
2194
|
buildTemplateGuideline(templateSummary),
|
|
2156
2195
|
"To retry a failed subagent, pass its run ID as retryRunId. The retry restores the recorded params - including background, gitMode, approvalMode, force - with explicit values on this call winning. Multi-step runs degrade to a single task. See the retryRunId description for the full field list.",
|
|
2157
|
-
"Set retryOnTimeout: true to automatically retry a FOREGROUND subagent that times out. Only retries once — the second timeout is treated as a final failure. A background run is not retried on its deadline, but it IS retried once automatically when it dies on a transport-class error (a
|
|
2196
|
+
"Set retryOnTimeout: true to automatically retry a FOREGROUND subagent that times out. Only retries once — the second timeout is treated as a final failure. A background run is not retried on its deadline, but it IS retried once automatically when it dies on a transport-class error (a transport death at any point before the run settles, not only before it starts work), recorded as attempt 2 and announced with a warning toast — do not re-dispatch it yourself. A second transport death is NOT retried again: that settle is an ordinary failure, and its completion notice says to change the shape (run it in the conductor, override the model, or split the brief). Any other background failure needs an explicit retryRunId.",
|
|
2158
2197
|
"Background is the CONDITIONAL default for delegate_task. With background omitted, a single task or a tasks fan-out runs in the BACKGROUND when the effective approvalMode is 'auto' (call param, else config): the tool returns an agent ID immediately, and with tasks it fans out — every task starts as its own background agent, one ID per task in task order, and the conductor is woken once per agent as each finishes. It stays FOREGROUND when the effective approvalMode is 'writes' or 'always' (a background run has no approval dialog, so a gate that needs the user must keep blocking), and for chain and graph (they block by definition; an explicit background: true with chain/graph is rejected). Pass background: false for a quick probe whose answer the next step needs inline; pass background: true to force a background run where the default would block. Background runs wake the conductor with a structured completion message when they finish — do not poll: polling is only correct when completion notifications are disabled (completionNotify \"off\"); one status check as a stall check is legitimate. A background run defaults to a 30-minute deadline when no timeout is given.",
|
|
2159
2198
|
"",
|
|
2160
2199
|
"## Conductor Guardrails",
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// Purpose: The mandatory dispatch header (issue #606): split it from the task body and parse it.
|
|
2
|
+
/**
|
|
3
|
+
* The dispatch header — one definition, two consumers (issue #606, Unit 1).
|
|
4
|
+
*
|
|
5
|
+
* Every dispatch task must open with a block:
|
|
6
|
+
*
|
|
7
|
+
* dispatch: impl | review | probe | docs
|
|
8
|
+
* brief: <slug> (required when dispatch: impl)
|
|
9
|
+
* brief: none — <reason> (the stated escape; reason non-empty)
|
|
10
|
+
*
|
|
11
|
+
* Two consumers, never two parsers:
|
|
12
|
+
* - `parseDispatchHeader` — the validator's gate (src/validate.ts). It reads
|
|
13
|
+
* the leading BLOCK only, so a task that merely quotes `dispatch: impl` in
|
|
14
|
+
* its prose (inline or fenced) stays valid (T3).
|
|
15
|
+
* - `splitDispatchHeader` — the router's seam (src/params.ts keeps the header
|
|
16
|
+
* out of `classifyTask`). A header would otherwise re-route a dispatch:
|
|
17
|
+
* `dispatch: review` matches the code-reviewer rule before the body's own
|
|
18
|
+
* "write tests" ever reaches the test-engineer rule (spec §3b).
|
|
19
|
+
*
|
|
20
|
+
* BOUNDARY, stated once so CRLF/BOM/blank-separator cases have one answer:
|
|
21
|
+
* the block starts at the first non-blank line and consumes consecutive lines
|
|
22
|
+
* matching `^(dispatch|brief):`, ending at the first line that does not
|
|
23
|
+
* match (a blank line ends it too). The task is `\r?\n`-split and a leading BOM
|
|
24
|
+
* is stripped before the first line is read. A title (`# Task`) before the block
|
|
25
|
+
* ends it — that is a refusal, not a tolerance, because a silent tolerance would
|
|
26
|
+
* let a quoted example at the top of a task become the declaration.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/** The four dispatch kinds. `impl` is the gated class: it needs a brief. */
|
|
30
|
+
export const DISPATCH_KINDS = ["impl", "review", "probe", "docs"] as const;
|
|
31
|
+
export type DispatchKind = (typeof DISPATCH_KINDS)[number];
|
|
32
|
+
|
|
33
|
+
/** The kinds as one comma-separated list, quoted verbatim in every refusal. */
|
|
34
|
+
export const DISPATCH_KIND_LIST = DISPATCH_KINDS.join(", ");
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The three accepted forms, quoted VERBATIM in every refusal so the conductor
|
|
38
|
+
* never has to guess. Kept as one constant: a second copy is a second truth.
|
|
39
|
+
*/
|
|
40
|
+
export const DISPATCH_HEADER_FORMS = [
|
|
41
|
+
"dispatch: impl | review | probe | docs",
|
|
42
|
+
"brief: <slug> (required when dispatch: impl)",
|
|
43
|
+
"brief: none — <reason> (the stated escape; reason non-empty)",
|
|
44
|
+
].join("\n");
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A brief slug: one path component, lowercase alphanumeric plus interior
|
|
48
|
+
* hyphens, 1-64 characters. `none` is reserved for the escape and is therefore
|
|
49
|
+
* rejected as a slug. Separators, dots and traversal are all refused by this
|
|
50
|
+
* pattern — never join a slug that has not matched it.
|
|
51
|
+
*/
|
|
52
|
+
export const BRIEF_SLUG_PATTERN = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
53
|
+
|
|
54
|
+
/** The reserved escape token (`brief: none — <reason>`). */
|
|
55
|
+
export const BRIEF_ESCAPE_TOKEN = "none";
|
|
56
|
+
|
|
57
|
+
/** A line that belongs to the leading block. Anchored: an indented copy does not. */
|
|
58
|
+
const BLOCK_LINE_RE = /^(dispatch|brief):/;
|
|
59
|
+
|
|
60
|
+
const DISPATCH_PREFIX = "dispatch:";
|
|
61
|
+
const BRIEF_PREFIX = "brief:";
|
|
62
|
+
const EM_DASH = "—";
|
|
63
|
+
|
|
64
|
+
/** The token is reserved only when it STANDS ALONE — `none-extra` is a legal slug. */
|
|
65
|
+
const ESCAPE_PREFIX_RE = new RegExp(`^${BRIEF_ESCAPE_TOKEN}(?:\\s|$)`);
|
|
66
|
+
const ESCAPE_VALUE_RE = new RegExp(`^${BRIEF_ESCAPE_TOKEN}\\s*${EM_DASH}\\s*(.*)$`);
|
|
67
|
+
|
|
68
|
+
export interface DispatchHeaderSplit {
|
|
69
|
+
/** The consumed block, `\n`-joined (empty when the task does not open with one). */
|
|
70
|
+
header: string;
|
|
71
|
+
/** Everything after the block. */
|
|
72
|
+
body: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** A brief reference: a signed brief's slug, or the stated escape and its reason. */
|
|
76
|
+
export type BriefDeclaration =
|
|
77
|
+
| { kind: "slug"; slug: string }
|
|
78
|
+
| { kind: "none"; reason: string };
|
|
79
|
+
|
|
80
|
+
export type DispatchHeaderVerdict =
|
|
81
|
+
| { ok: true; kind: DispatchKind; brief: BriefDeclaration | undefined }
|
|
82
|
+
| { ok: false; reason: string };
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Split a task into its leading dispatch block and the body that follows.
|
|
86
|
+
*
|
|
87
|
+
* Pure and total: any string maps to a pair, and `header + "\n" + body`
|
|
88
|
+
* reconstructs the task apart from the leading blank lines the block start
|
|
89
|
+
* consumes. Never throws — the validator and the router both call it on
|
|
90
|
+
* conductor-supplied text.
|
|
91
|
+
*/
|
|
92
|
+
export function splitDispatchHeader(task: string): DispatchHeaderSplit {
|
|
93
|
+
const text = String(task ?? "").replace(/^\uFEFF/, "");
|
|
94
|
+
const lines = text.split(/\r?\n/);
|
|
95
|
+
|
|
96
|
+
let start = 0;
|
|
97
|
+
while (start < lines.length && lines[start].trim() === "") start++;
|
|
98
|
+
|
|
99
|
+
let end = start;
|
|
100
|
+
while (end < lines.length && BLOCK_LINE_RE.test(lines[end])) end++;
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
header: lines.slice(start, end).join("\n"),
|
|
104
|
+
body: lines.slice(end).join("\n"),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** One refusal shape: the finding first, then the three accepted forms verbatim. */
|
|
109
|
+
function refuse(detail: string): DispatchHeaderVerdict {
|
|
110
|
+
return { ok: false, reason: `${detail} The accepted dispatch block is:\n${DISPATCH_HEADER_FORMS}` };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The block's value for one prefix (`undefined` when the line carries none). */
|
|
114
|
+
function lineValue(line: string, prefix: string): string {
|
|
115
|
+
return line.slice(prefix.length).trim();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Parse one `brief:` value into its declaration, or the reason it is not one. */
|
|
119
|
+
function parseBriefValue(value: string): BriefDeclaration | { error: string } {
|
|
120
|
+
if (value === "") {
|
|
121
|
+
return { error: "the brief line needs a value — a slug, or the stated escape." };
|
|
122
|
+
}
|
|
123
|
+
// The escape is `none — <reason>` with an EM DASH. The bare token is judged
|
|
124
|
+
// here so `brief: none` cannot slide through as a slug.
|
|
125
|
+
if (ESCAPE_PREFIX_RE.test(value)) {
|
|
126
|
+
const match = ESCAPE_VALUE_RE.exec(value);
|
|
127
|
+
if (match === null) {
|
|
128
|
+
return {
|
|
129
|
+
error: `the brief escape is \`brief: ${BRIEF_ESCAPE_TOKEN} ${EM_DASH} <reason>\` — the em dash and the reason are both required.`,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const reason = match[1].trim();
|
|
133
|
+
if (reason === "") {
|
|
134
|
+
return { error: "the brief escape's reason is empty — say why no brief was agreed." };
|
|
135
|
+
}
|
|
136
|
+
return { kind: "none", reason };
|
|
137
|
+
}
|
|
138
|
+
if (value === BRIEF_ESCAPE_TOKEN || !BRIEF_SLUG_PATTERN.test(value)) {
|
|
139
|
+
return {
|
|
140
|
+
error:
|
|
141
|
+
`invalid brief slug "${value}": a slug matches ${BRIEF_SLUG_PATTERN.source}, ` +
|
|
142
|
+
`is a single path component (no "/", no ".", no ".."), and "${BRIEF_ESCAPE_TOKEN}" is reserved for the escape.`,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return { kind: "slug", slug: value };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Parse the leading dispatch block. Refusals quote the three accepted forms
|
|
150
|
+
* verbatim (§3); success returns the kind and, when one was declared, the brief.
|
|
151
|
+
*
|
|
152
|
+
* A task that does NOT open with a block is refused, and the reason says which:
|
|
153
|
+
* a stray `dispatch:` line later in the text gets "the block must be the first
|
|
154
|
+
* content" (P12), because that is the mistake an author actually makes.
|
|
155
|
+
*/
|
|
156
|
+
export function parseDispatchHeader(task: string): DispatchHeaderVerdict {
|
|
157
|
+
const { header, body } = splitDispatchHeader(task);
|
|
158
|
+
const blockLines = header === "" ? [] : header.split("\n");
|
|
159
|
+
|
|
160
|
+
const dispatchLines = blockLines.filter((line) => line.startsWith(DISPATCH_PREFIX));
|
|
161
|
+
if (dispatchLines.length === 0) {
|
|
162
|
+
const strayDeclaration = body.split(/\r?\n/).some((line) => line.startsWith(DISPATCH_PREFIX));
|
|
163
|
+
return refuse(
|
|
164
|
+
strayDeclaration
|
|
165
|
+
? "missing dispatch header: the block must be the first content — the task's first non-blank line " +
|
|
166
|
+
"is not one of `dispatch:`/`brief:`, so a later declaration is outside the block. " +
|
|
167
|
+
"Move the block to the top of the task."
|
|
168
|
+
: "missing dispatch header: the task's first non-blank line must declare the kind.",
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
if (dispatchLines.length > 1) {
|
|
172
|
+
return refuse("more than one `dispatch:` line in the leading block — declare the kind exactly once.");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const dispatchRest = lineValue(dispatchLines[0], DISPATCH_PREFIX);
|
|
176
|
+
if (dispatchRest === "") {
|
|
177
|
+
return refuse("the dispatch line has no kind — name exactly one.");
|
|
178
|
+
}
|
|
179
|
+
// The one-token rule: no trailing comment, no extra words. `dispatch: impl #
|
|
180
|
+
// note` is ambiguous, and an ambiguous declaration is not a declaration.
|
|
181
|
+
if (/\s/.test(dispatchRest)) {
|
|
182
|
+
return refuse(
|
|
183
|
+
`the dispatch line takes exactly one token — no trailing comment or extra words after "${dispatchRest.split(/\s+/)[0]}".`,
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
if (!(DISPATCH_KINDS as readonly string[]).includes(dispatchRest)) {
|
|
187
|
+
return refuse(`unknown dispatch kind "${dispatchRest}" — must be one of: ${DISPATCH_KIND_LIST}.`);
|
|
188
|
+
}
|
|
189
|
+
const kind = dispatchRest as DispatchKind;
|
|
190
|
+
|
|
191
|
+
const briefLines = blockLines.filter((line) => line.startsWith(BRIEF_PREFIX));
|
|
192
|
+
if (briefLines.length > 1) {
|
|
193
|
+
return refuse("more than one `brief:` line in the leading block — declare the brief exactly once.");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
let brief: BriefDeclaration | undefined;
|
|
197
|
+
if (briefLines.length === 1) {
|
|
198
|
+
const parsed = parseBriefValue(lineValue(briefLines[0], BRIEF_PREFIX));
|
|
199
|
+
if ("error" in parsed) return refuse(parsed.error);
|
|
200
|
+
brief = parsed;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (kind === "impl" && brief === undefined) {
|
|
204
|
+
return refuse(
|
|
205
|
+
"`dispatch: impl` requires a brief — add `brief: <slug>` (the file is briefs/<slug>.md) " +
|
|
206
|
+
`or \`brief: ${BRIEF_ESCAPE_TOKEN} ${EM_DASH} <reason>\` for the stated escape.`,
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return { ok: true, kind, brief };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* The frontmatter `dispatch:` field's problem, or `undefined` when it is absent
|
|
215
|
+
* or one of the four kinds. Shared by the template's load-time validation and
|
|
216
|
+
* its render-time check: an unknown or misspelled value must be an error naming
|
|
217
|
+
* the field and the allowed set, never a silently ignored key (spec §3a).
|
|
218
|
+
*/
|
|
219
|
+
export function dispatchFieldProblem(value: unknown): string | undefined {
|
|
220
|
+
if (value === undefined) return undefined;
|
|
221
|
+
if (typeof value !== "string" || !(DISPATCH_KINDS as readonly string[]).includes(value)) {
|
|
222
|
+
const shown = typeof value === "string" ? `"${value}"` : JSON.stringify(value);
|
|
223
|
+
return `invalid "dispatch" value ${shown} — must be one of: ${DISPATCH_KIND_LIST}.`;
|
|
224
|
+
}
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
package/src/history.ts
CHANGED
|
@@ -197,11 +197,6 @@ export function resolveRetryParams(
|
|
|
197
197
|
gitMode?: string;
|
|
198
198
|
approvalMode?: string;
|
|
199
199
|
force?: boolean;
|
|
200
|
-
/** The call-level Jev-line bypass (issue #412) — kept so an explicit
|
|
201
|
-
* noJev on a retry call still reaches the validation seam; it is never
|
|
202
|
-
* inherited from the original (a bypass is per dispatch, and the
|
|
203
|
-
* original's line already rides the recorded task). */
|
|
204
|
-
noJev?: string;
|
|
205
200
|
},
|
|
206
201
|
run: SubagentRun,
|
|
207
202
|
): typeof params {
|
|
@@ -226,7 +221,6 @@ export function resolveRetryParams(
|
|
|
226
221
|
gitMode: params.gitMode ?? orig?.gitMode,
|
|
227
222
|
approvalMode: params.approvalMode ?? orig?.approvalMode,
|
|
228
223
|
force: params.force ?? orig?.force,
|
|
229
|
-
noJev: params.noJev,
|
|
230
224
|
};
|
|
231
225
|
}
|
|
232
226
|
|
package/src/index.ts
CHANGED
|
@@ -42,6 +42,7 @@ import { loadBuiltinPresets, loadCustomPresets, getAllPresets, writePresetFile }
|
|
|
42
42
|
import { cleanupTempDirs, reapActiveChildren } from "./runner";
|
|
43
43
|
import { clearProgressLinger, repaintStatus, stopProgressTicker } from "./concurrency";
|
|
44
44
|
import { setLogCwd } from "./logging";
|
|
45
|
+
import { createGuardStartNotice } from "./background-guard";
|
|
45
46
|
import { createTerminalNotifier } from "./terminal-notifier";
|
|
46
47
|
|
|
47
48
|
// ---------------------------------------------------------------------------
|
|
@@ -113,11 +114,7 @@ type _NonResolutionDelegateKey =
|
|
|
113
114
|
| "retryOnTimeout"
|
|
114
115
|
| "model"
|
|
115
116
|
| "priority"
|
|
116
|
-
| "background"
|
|
117
|
-
// Issue #412: `force`/`noJev` are consumed at the validation seam (they
|
|
118
|
-
// reach `validatePreTask`, not the merge), so `force` stays in the resolver's
|
|
119
|
-
// key list while `noJev` — never read by resolution — is excluded here.
|
|
120
|
-
| "noJev";
|
|
117
|
+
| "background";
|
|
121
118
|
type _ResolveInputCoverage = _ExpectNever<
|
|
122
119
|
Exclude<_KnownDelegateKey, keyof ResolveInputParams | _NonResolutionDelegateKey>
|
|
123
120
|
>;
|
|
@@ -162,6 +159,13 @@ export default function (pi: ExtensionAPI) {
|
|
|
162
159
|
resetRecoveryNotice,
|
|
163
160
|
} = createBootRecovery(rt);
|
|
164
161
|
|
|
162
|
+
// Issue #620 (Q14): the cheap half of "required". A project that names a
|
|
163
|
+
// background guard must hear about a guard that never loaded — the silence is
|
|
164
|
+
// what let #620 hide — but exactly once per process, and not at all when the
|
|
165
|
+
// project did not opt in. The latch is per invocation (D5), like every other
|
|
166
|
+
// once-per-boot flag here.
|
|
167
|
+
const guardStartNotice = createGuardStartNotice();
|
|
168
|
+
|
|
165
169
|
// -------------------------------------------------------------------
|
|
166
170
|
// Config change callback
|
|
167
171
|
// -------------------------------------------------------------------
|
|
@@ -239,6 +243,13 @@ export default function (pi: ExtensionAPI) {
|
|
|
239
243
|
// Issue #179 (D6): createLogger ran at module load with no cwd — point
|
|
240
244
|
// the shared file sink at this session's cwd now that it exists.
|
|
241
245
|
setLogCwd(ctx.cwd);
|
|
246
|
+
// Issue #620 (Q14): one warning per process when this project names a
|
|
247
|
+
// background guard that is not loaded. Silent for an absent key and for
|
|
248
|
+
// "none" — a project that did not opt in never sees our machinery.
|
|
249
|
+
{
|
|
250
|
+
const warning = guardStartNotice(ctx.cwd);
|
|
251
|
+
if (warning !== null) log.warn(warning);
|
|
252
|
+
}
|
|
242
253
|
// Load built-in presets
|
|
243
254
|
const presetsDir = pkgPath("presets");
|
|
244
255
|
state.builtinPresets = loadBuiltinPresets(presetsDir, log);
|
|
@@ -287,6 +298,17 @@ export default function (pi: ExtensionAPI) {
|
|
|
287
298
|
// records interrupted BEFORE anything else touches their worktrees.
|
|
288
299
|
await performBootRecovery();
|
|
289
300
|
|
|
301
|
+
// Issue #616 / review 624 (B1): reclaim the armed-retry markers a conductor
|
|
302
|
+
// left behind when it died between an arm write and the retry's spawn. No
|
|
303
|
+
// run-shaped reader enumerates `armed/` (that is what keeps an intent from
|
|
304
|
+
// rendering as a run row), so nothing else would ever notice them, and a
|
|
305
|
+
// stale marker makes every later stop of its dispatch cancel a phantom.
|
|
306
|
+
{
|
|
307
|
+
const { sweepStaleArmedRetries } = await import("./retry-armed");
|
|
308
|
+
const swept = sweepStaleArmedRetries();
|
|
309
|
+
if (swept.reclaimed > 0) log.info("Reclaimed stale armed-retry markers", swept);
|
|
310
|
+
}
|
|
311
|
+
|
|
290
312
|
// Issue #466 (ADR 0026 D2/D5): reconcile the durable head-state records —
|
|
291
313
|
// the ONE step allowed to move git at boot, and only for a record whose
|
|
292
314
|
// owner it has proved dead.
|
package/src/kill-escalation.ts
CHANGED
|
@@ -51,8 +51,10 @@
|
|
|
51
51
|
*
|
|
52
52
|
* #299 RE-REVIEW FIX A.1 closes one more major on `0fa2fc2`:
|
|
53
53
|
* - A reaped pid must classify as GONE in `pidGone` (positive `kill(pid,0)`
|
|
54
|
-
* sample + `/proc/<pid>/stat` ENOENT — see src/proc.ts), so our
|
|
55
|
-
* leader is not mistaken for a live FOREIGN pid and refused its
|
|
54
|
+
* sample + `/proc/<pid>/stat` ENOENT **or** ESRCH — see src/proc.ts), so our
|
|
55
|
+
* own reaped leader is not mistaken for a live FOREIGN pid and refused its
|
|
56
|
+
* group kill. Both vanished codes are absence-of-process evidence; any other
|
|
57
|
+
* read failure stays ambiguous.
|
|
56
58
|
* - Honest reporting: a REFUSED final group SIGKILL over a group that still
|
|
57
59
|
* has live members is counted as a survivor (`refusedForceKillGroup`), so a
|
|
58
60
|
* guard decision can never yield a clean `survivors=[]` over a live group we
|
|
@@ -138,11 +140,14 @@ export function __setProcessGroupKillSupportedForTest(value: boolean | undefined
|
|
|
138
140
|
*
|
|
139
141
|
* - direct pid signal — allowed only when `isOwn(pid)` is true;
|
|
140
142
|
* - group signal — allowed when `isOwn(pid)` is true OR the pid is confirmed
|
|
141
|
-
* GONE (`!pidAlive(pid)`).
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
143
|
+
* GONE (`!pidAlive(pid)`). The gone case keeps D5's group SIGKILL for a
|
|
144
|
+
* TERM-stubborn member working after the leader exits, and it PREMISES that
|
|
145
|
+
* the pgid still names OUR group — which the reuse check cannot prove: a pid
|
|
146
|
+
* reused by a FOREIGN process and then reaped can leave its number naming
|
|
147
|
+
* that foreign group, and a same-uid group signal is not `EPERM`ed by the
|
|
148
|
+
* kernel (the boundary is uid, not the marker — see `groupTarget`). An ALIVE
|
|
149
|
+
* pid that no longer carries the marker IS the review's reused-pid case:
|
|
150
|
+
* EVERY signal is skipped, never unverified.
|
|
146
151
|
*
|
|
147
152
|
* `onSkip` records a refused signal. A skipped signal is never retried
|
|
148
153
|
* unverified.
|
|
@@ -248,6 +253,15 @@ function bestEffortGroupKill(
|
|
|
248
253
|
* (D5).
|
|
249
254
|
*
|
|
250
255
|
* `guard` (optional) re-verifies a marker-derived pid at signal time (Major 1).
|
|
256
|
+
*
|
|
257
|
+
* BOUNDARY (pre-existing, NOT widened by #644): `isGone` licenses the group
|
|
258
|
+
* signal when the pid is gone, which assumes the pgid still names OUR group. A
|
|
259
|
+
* pid reused by a FOREIGN process and then reaped can leave its number naming
|
|
260
|
+
* that foreign group — and a same-uid group is not `EPERM`ed by the kernel, so
|
|
261
|
+
* `kill(-pgid)` lands on it. The marker constrains the pid, not the pgid; the
|
|
262
|
+
* real boundary here is uid, not the reuse check. This is identical on the
|
|
263
|
+
* pre-existing `ENOENT` path — #644 only adds a second vanished errno to the
|
|
264
|
+
* same classification, so it does not widen the exposure.
|
|
251
265
|
*/
|
|
252
266
|
export function groupTarget(
|
|
253
267
|
pid: number,
|
|
@@ -258,8 +272,10 @@ export function groupTarget(
|
|
|
258
272
|
guard?: SignalGuard,
|
|
259
273
|
): EscalationTarget {
|
|
260
274
|
// A group signal is skipped ONLY for a live pid that is no longer ours (the
|
|
261
|
-
// reused-pid case). A gone/zombie leader's
|
|
262
|
-
// members
|
|
275
|
+
// reused-pid case). A gone/zombie leader's group signal must still land (D5):
|
|
276
|
+
// those members are exactly the ones we need to reach. The pgid is trusted to
|
|
277
|
+
// name OUR group; a reused-then-reaped pid number naming a same-uid FOREIGN
|
|
278
|
+
// group is the known residual documented in BOUNDARY above.
|
|
263
279
|
// #299 re-review A.1: remember a REFUSED final group SIGKILL so the escalation
|
|
264
280
|
// can report the still-live group it could not end (never a clean report).
|
|
265
281
|
let finalGroupRefused = false;
|
|
@@ -306,6 +322,13 @@ export function groupTarget(
|
|
|
306
322
|
// #299 fix A.2: only a POSITIVELY empty group (`false`) may report clean.
|
|
307
323
|
// `undefined` (unknown inspection) and an ABSENT reader both mean emptiness
|
|
308
324
|
// could not be established, so the fail-safe is to count a survivor.
|
|
325
|
+
//
|
|
326
|
+
// #644 residual (deliberate, decision Q3): this one boolean therefore CONFLATES
|
|
327
|
+
// "the group has live members we could not signal" with "the group's state could
|
|
328
|
+
// not be established" (an ambiguous read — `undefined`). Both are reported as one
|
|
329
|
+
// bare pid. That is deliberate: no consumer branches on the distinction and the
|
|
330
|
+
// operator's action is the same (inspect the pid), so making it visible is its own
|
|
331
|
+
// unit rather than a field added here.
|
|
309
332
|
refusedForceKillGroup: () =>
|
|
310
333
|
finalGroupRefused && (groupHasMembers ? groupHasMembers(pid) !== false : true),
|
|
311
334
|
};
|
package/src/mode-prologue.ts
CHANGED
|
@@ -49,12 +49,7 @@ import { depthLimitRejection, gateSessionCost, rejection, runPreTaskValidation,
|
|
|
49
49
|
/** The params object the shared resolver consumes (`ResolveInputParams`,
|
|
50
50
|
* params.ts) — the same type the background and single paths pass. */
|
|
51
51
|
export interface ModePrologueInput {
|
|
52
|
-
|
|
53
|
-
* `noJev` is carried alongside the resolution inputs rather than inside
|
|
54
|
-
* `ResolveInputParams`: resolution never reads it, but the mode-level H1
|
|
55
|
-
* gate forwards it as the call's stated bypass (issue #412).
|
|
56
|
-
*/
|
|
57
|
-
params: ResolveInputParams & { noJev?: string };
|
|
52
|
+
params: ResolveInputParams;
|
|
58
53
|
state: SessionState;
|
|
59
54
|
ctx: ExtensionContext;
|
|
60
55
|
log: Logger;
|
|
@@ -149,12 +144,9 @@ export function runModePrologue(input: ModePrologueInput): ModePrologueOutcome {
|
|
|
149
144
|
thinkingLevel: globalParams.thinkingLevel,
|
|
150
145
|
gitMode: globalParams.resolvedGitMode,
|
|
151
146
|
outputFile: globalParams.outputFile,
|
|
152
|
-
//
|
|
153
|
-
//
|
|
154
|
-
// call-level stated bypass — the mode-level task text is the caller's
|
|
155
|
-
// own, so it is checked and bypassable exactly like a single task.
|
|
147
|
+
// Project-local process checks key on the DISPATCH cwd (the project
|
|
148
|
+
// whose manifest opts in).
|
|
156
149
|
cwd: targets.cwd,
|
|
157
|
-
noJev: params.noJev,
|
|
158
150
|
},
|
|
159
151
|
});
|
|
160
152
|
if (preTask.error) return { ok: false, error: preTask.error };
|
package/src/mode-runners.ts
CHANGED
|
@@ -384,7 +384,6 @@ function rejectedUnitResult(
|
|
|
384
384
|
ctx,
|
|
385
385
|
log,
|
|
386
386
|
force: params.force as boolean | undefined,
|
|
387
|
-
noJev: params.noJev,
|
|
388
387
|
// Issue #443: the DECLARED per-step level (the merged one is resolved).
|
|
389
388
|
declaredThinkingLevel: (step) => step.thinkingLevel,
|
|
390
389
|
merge: (step) =>
|
|
@@ -787,7 +786,6 @@ function rejectedUnitResult(
|
|
|
787
786
|
ctx,
|
|
788
787
|
log,
|
|
789
788
|
force: params.force as boolean | undefined,
|
|
790
|
-
noJev: params.noJev,
|
|
791
789
|
// Issue #443: the DECLARED per-task level (the merged one is resolved).
|
|
792
790
|
declaredThinkingLevel: (task) => task.thinkingLevel,
|
|
793
791
|
merge: (task) =>
|
|
@@ -1215,7 +1213,6 @@ function rejectedUnitResult(
|
|
|
1215
1213
|
ctx,
|
|
1216
1214
|
log,
|
|
1217
1215
|
force: params.force as boolean | undefined,
|
|
1218
|
-
noJev: params.noJev,
|
|
1219
1216
|
// Issue #443: the DECLARED per-node level (the merged one is resolved).
|
|
1220
1217
|
declaredThinkingLevel: (node) => node.thinkingLevel,
|
|
1221
1218
|
merge: (node) =>
|