brl-subagent 2.8.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.
- package/AGENT.md +1 -1
- 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 +313 -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 +1 -1
- 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 +2 -3
- package/src/reports.ts +1 -7
- package/src/run-registry.ts +2 -3
- 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/scratch-root.ts +909 -0
- package/src/scratch-spawn.ts +256 -0
- package/src/session-manager.ts +75 -7
- 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 +42 -32
- package/src/types.ts +29 -3
- package/src/unit-params.ts +113 -0
- package/src/unit-run.ts +35 -15
- package/src/validate.ts +2 -3
- package/src/worktree-report.ts +142 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Purpose: The per-unit param merge (SubTask over global) and the unit display name, shared by chain/parallel/graph and the background fan-out.
|
|
2
|
+
/**
|
|
3
|
+
* brl-subagent — per-unit params (cycle S1, ADR 0027 D6)
|
|
4
|
+
*
|
|
5
|
+
* `mergeSubTaskParams` and `displayTaskName` used to be closures inside
|
|
6
|
+
* src/index.ts's default export. A closure cannot be imported, so the two
|
|
7
|
+
* consumers that needed the real thing kept substitutes: a hand-maintained
|
|
8
|
+
* replica in chain-parallel.test.ts and a SOURCE-TEXT ratchet in
|
|
9
|
+
* integration.test.ts. Extracted here for the reason params.ts was extracted
|
|
10
|
+
* (issue #59) — the tests drive the real function instead of a copy.
|
|
11
|
+
*
|
|
12
|
+
* The move is verbatim apart from the file's one captured binding:
|
|
13
|
+
* `state.config.maxThinkingLevel` is now the `maxThinkingLevel` parameter, so
|
|
14
|
+
* the merge reads no per-invocation state and stays a pure function of its
|
|
15
|
+
* arguments.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
resolveThinkingLevel,
|
|
20
|
+
type ApprovalMode,
|
|
21
|
+
type GitMode,
|
|
22
|
+
type Priority,
|
|
23
|
+
type ResolvedParams,
|
|
24
|
+
type SubTaskParams,
|
|
25
|
+
type SubagentToolOptions,
|
|
26
|
+
type ThinkingLevel,
|
|
27
|
+
} from "./types";
|
|
28
|
+
|
|
29
|
+
/** A merged unit: the fields every batch mode's spawn path reads. */
|
|
30
|
+
export type MergedSubTaskParams = {
|
|
31
|
+
task: string;
|
|
32
|
+
label: string | undefined;
|
|
33
|
+
model: string | undefined;
|
|
34
|
+
inheritSP: boolean;
|
|
35
|
+
customSP: string | undefined;
|
|
36
|
+
outputFile: string | undefined;
|
|
37
|
+
timeout: number | undefined;
|
|
38
|
+
effectiveCwd: string;
|
|
39
|
+
thinkingLevel: ThinkingLevel;
|
|
40
|
+
priority: Priority | undefined;
|
|
41
|
+
toolOptions: SubagentToolOptions | undefined;
|
|
42
|
+
resolvedGitMode: GitMode;
|
|
43
|
+
resolvedApprovalMode: ApprovalMode;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Merge global resolved params with a SubTaskParams.
|
|
48
|
+
* SubTask fields override global fields. Tools/excludeTools/noBuiltinTools
|
|
49
|
+
* are replaced entirely if set in the subTask, otherwise inherited from global.
|
|
50
|
+
*/
|
|
51
|
+
export function mergeSubTaskParams(
|
|
52
|
+
globalParams: ResolvedParams & { resolvedGitMode: GitMode; resolvedApprovalMode: ApprovalMode },
|
|
53
|
+
subTask: SubTaskParams,
|
|
54
|
+
maxThinkingLevel: ThinkingLevel,
|
|
55
|
+
): MergedSubTaskParams {
|
|
56
|
+
const mergedThinkingLevel = subTask.thinkingLevel
|
|
57
|
+
? resolveThinkingLevel(
|
|
58
|
+
subTask.thinkingLevel as ThinkingLevel,
|
|
59
|
+
maxThinkingLevel,
|
|
60
|
+
)
|
|
61
|
+
: globalParams.thinkingLevel;
|
|
62
|
+
|
|
63
|
+
const mergedTools = subTask.tools ?? globalParams.toolOptions?.tools;
|
|
64
|
+
// Fix: edit depends on write in pi's tool system.
|
|
65
|
+
const resolvedTools = mergedTools && mergedTools.includes("edit") && !mergedTools.includes("write")
|
|
66
|
+
? [...mergedTools, "write"]
|
|
67
|
+
: mergedTools;
|
|
68
|
+
const mergedExcludeTools = subTask.excludeTools ?? globalParams.toolOptions?.excludeTools;
|
|
69
|
+
const mergedNoBuiltinTools =
|
|
70
|
+
subTask.noBuiltinTools ?? globalParams.toolOptions?.noBuiltinTools;
|
|
71
|
+
|
|
72
|
+
const mergedToolOptions: SubagentToolOptions | undefined =
|
|
73
|
+
resolvedTools || mergedExcludeTools || mergedNoBuiltinTools
|
|
74
|
+
? {
|
|
75
|
+
tools: resolvedTools,
|
|
76
|
+
excludeTools: mergedExcludeTools,
|
|
77
|
+
noBuiltinTools: mergedNoBuiltinTools,
|
|
78
|
+
}
|
|
79
|
+
: undefined;
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
task: subTask.task || globalParams.task,
|
|
83
|
+
label: subTask.label ?? globalParams.label,
|
|
84
|
+
model: subTask.model,
|
|
85
|
+
inheritSP: subTask.inheritSystemPrompt ?? globalParams.inheritSP,
|
|
86
|
+
customSP: subTask.systemPrompt ?? globalParams.customSP,
|
|
87
|
+
outputFile: subTask.outputFile ?? globalParams.outputFile,
|
|
88
|
+
timeout: subTask.timeout ?? globalParams.timeout,
|
|
89
|
+
effectiveCwd: subTask.cwd ?? globalParams.effectiveCwd,
|
|
90
|
+
thinkingLevel: mergedThinkingLevel,
|
|
91
|
+
// Issue #114: per-unit priority — undefined when the step declares none
|
|
92
|
+
// (the caller then falls back to the call-level priority).
|
|
93
|
+
priority: subTask.priority && ["critical", "high", "normal", "low"].includes(subTask.priority)
|
|
94
|
+
? (subTask.priority as Priority)
|
|
95
|
+
: undefined,
|
|
96
|
+
toolOptions: mergedToolOptions,
|
|
97
|
+
resolvedGitMode: globalParams.resolvedGitMode,
|
|
98
|
+
resolvedApprovalMode: globalParams.resolvedApprovalMode,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Per-unit display name for validation prefixes: the label when present,
|
|
104
|
+
* else the task truncated to 60 chars. Shared by the foreground parallel
|
|
105
|
+
* pre-pass and the background fan-out pre-pass (issue #220) so a unit
|
|
106
|
+
* renders identically in either shape.
|
|
107
|
+
*/
|
|
108
|
+
export function displayTaskName(merged: MergedSubTaskParams): string {
|
|
109
|
+
return (
|
|
110
|
+
merged.label ??
|
|
111
|
+
(merged.task.length > 60 ? `${merged.task.slice(0, 57)}...` : merged.task)
|
|
112
|
+
);
|
|
113
|
+
}
|
package/src/unit-run.ts
CHANGED
|
@@ -16,26 +16,26 @@
|
|
|
16
16
|
* block and the background/retry registration paths remain in index.ts.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import type {
|
|
20
|
-
|
|
21
|
-
AgentToolUpdateCallback,
|
|
22
|
-
} from "@earendil-works/pi-agent-core";
|
|
19
|
+
import type { Logger } from "./logging";
|
|
20
|
+
import type { AgentToolResult, AgentToolUpdateCallback } from "@earendil-works/pi-agent-core";
|
|
23
21
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
import {
|
|
23
|
+
getFinalOutput,
|
|
24
|
+
classifyError,
|
|
25
|
+
DEFAULT_RECOVERY,
|
|
26
|
+
type SubagentResult,
|
|
27
|
+
type SubagentRun,
|
|
28
|
+
type SubagentToolOptions,
|
|
29
|
+
type Priority,
|
|
30
|
+
type RecoveryMode,
|
|
31
31
|
} from "./types";
|
|
32
|
-
import { getFinalOutput, classifyError, DEFAULT_RECOVERY } from "./types";
|
|
33
32
|
import { snapshotOriginalParams } from "./params";
|
|
34
33
|
import { currentProcessOwner } from "./recovery";
|
|
35
34
|
import { capOutput, stripAnsi, buildCrashResult } from "./sanitize";
|
|
35
|
+
import { prepareRunScratch } from "./scratch-spawn";
|
|
36
36
|
import { finalizeRunRecord, pruneSessionRuns } from "./history";
|
|
37
|
-
import type { Logger } from "./logging";
|
|
38
37
|
import { SessionState } from "./state";
|
|
38
|
+
import { attachWorktreeState } from "./worktree-report";
|
|
39
39
|
|
|
40
40
|
// ---------------------------------------------------------------------------
|
|
41
41
|
// Structural source for a per-unit run entry
|
|
@@ -43,8 +43,9 @@ import { SessionState } from "./state";
|
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* The per-unit fields shared by chain/parallel/graph modes (`merged` from
|
|
46
|
-
* mergeSubTaskParams). Kept structural so the call sites
|
|
47
|
-
*
|
|
46
|
+
* mergeSubTaskParams, unit-params.ts). Kept structural so the call sites
|
|
47
|
+
* verify by shape — this module writes a run record and has no reason to
|
|
48
|
+
* depend on the merge itself.
|
|
48
49
|
*/
|
|
49
50
|
export interface UnitRunSource {
|
|
50
51
|
task: string;
|
|
@@ -112,6 +113,12 @@ export function createUnitRun(
|
|
|
112
113
|
recoveryPosture: RecoveryMode = DEFAULT_RECOVERY,
|
|
113
114
|
): { runId: string; run: SubagentRun } {
|
|
114
115
|
const runId = crypto.randomUUID();
|
|
116
|
+
// Issue #511 (U2): the unit's scratch directory is created HERE, at record
|
|
117
|
+
// creation, so the record can carry it. Best-effort: the spawn seam in
|
|
118
|
+
// `runner.ts` re-prepares (idempotently) and is the gate that refuses to
|
|
119
|
+
// start a child whose root could not be placed — this call only decides what
|
|
120
|
+
// the durable record says.
|
|
121
|
+
const scratch = prepareRunScratch(runId);
|
|
115
122
|
const run: SubagentRun = {
|
|
116
123
|
id: runId,
|
|
117
124
|
task: source.task,
|
|
@@ -138,6 +145,13 @@ export function createUnitRun(
|
|
|
138
145
|
// U3 (D4): snapshot the posture so the boot notice/offer reads what was
|
|
139
146
|
// in force at dispatch.
|
|
140
147
|
recoveryPosture,
|
|
148
|
+
// Issue #511 (U2): attach the unit's scratch directory to the record at
|
|
149
|
+
// creation, so a retry of this run (the retry preamble, U3) can name the
|
|
150
|
+
// bank path from the durable record. Best-effort HERE: the spawn seam in
|
|
151
|
+
// `runner.ts` is the gate that refuses to start a child without one, so a
|
|
152
|
+
// refusal here persists a record with no `scratchDir` and the runner reports
|
|
153
|
+
// the named code.
|
|
154
|
+
scratchDir: scratch.ok ? scratch.runDir : undefined,
|
|
141
155
|
// The execution-shape fields (background/gitMode/approvalMode/force) are
|
|
142
156
|
// deliberately omitted: a fan-out unit retries as a SINGLE run, so it must
|
|
143
157
|
// not inherit the fan-out's background-ness. A retry that wants background
|
|
@@ -204,6 +218,11 @@ export function finalizeUnitRun(
|
|
|
204
218
|
* node"); `logContext` carries the mode-specific context fields (chain passes
|
|
205
219
|
* the step index, parallel passes the task index, graph passes the node id)
|
|
206
220
|
* spread into the log call alongside runId/error.
|
|
221
|
+
*
|
|
222
|
+
* Issue #474: `resolvedCwd` is the UNIT's cwd, and the block for it is attached
|
|
223
|
+
* to the rethrown error BEFORE the rethrow — the mode's outer catch only knows
|
|
224
|
+
* the dispatch cwd, so without the attachment a unit crash in its own directory
|
|
225
|
+
* would report a sibling's tree. `buildCrashResult` prefers the attachment.
|
|
207
226
|
*/
|
|
208
227
|
export function finalizeUnitRunCrash(
|
|
209
228
|
state: SessionState,
|
|
@@ -215,6 +234,7 @@ export function finalizeUnitRunCrash(
|
|
|
215
234
|
log: Logger,
|
|
216
235
|
logContext?: Record<string, unknown>,
|
|
217
236
|
): never {
|
|
237
|
+
attachWorktreeState(err, resolvedCwd);
|
|
218
238
|
const crash = buildCrashResult(modeLabel, err, resolvedCwd);
|
|
219
239
|
state.finalizeLiveSubagent(run.id);
|
|
220
240
|
const crashOutput = state.subagentSessions.get(run.id)?.liveOutput ?? "";
|
package/src/validate.ts
CHANGED
|
@@ -7,8 +7,7 @@
|
|
|
7
7
|
* LLM context), so it's consistent regardless of conductor state.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type
|
|
11
|
-
import { THINKING_LEVELS } from './types';
|
|
10
|
+
import { THINKING_LEVELS, type ThinkingLevel, type SubagentToolOptions } from './types';
|
|
12
11
|
import { DISPATCH_LINE_FORM, JEV_UNAVAILABLE, parseDispatchLine } from './dispatch-line';
|
|
13
12
|
import { isProcessChecksEnabled } from './project-flags';
|
|
14
13
|
|
|
@@ -451,7 +450,7 @@ export function validatePreTask(config: ValidateConfig): ValidateResult {
|
|
|
451
450
|
const gitPatterns = [/\b(commit|push|pull|merge|rebase|checkout|branch|pr|pull.request)\b/i];
|
|
452
451
|
if (gitPatterns.some(p => p.test(taskText)) && config.gitMode === 'none') {
|
|
453
452
|
warnings.push(
|
|
454
|
-
`
|
|
453
|
+
`gitMode is 'none' — the harness will not create or capture a branch; the task must run its own git commands`,
|
|
455
454
|
);
|
|
456
455
|
}
|
|
457
456
|
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Purpose: Formats the read-only worktree state a failed or stopped run may have left behind (issue #474).
|
|
2
|
+
/**
|
|
3
|
+
* brl-subagent — failure-path worktree state (issue #474)
|
|
4
|
+
*
|
|
5
|
+
* Rule 11 escalated `connection-drop` after three hits in one cycle: six of
|
|
6
|
+
* ~28 sweep dispatches ended without their unit, two leaving a **mutant applied**
|
|
7
|
+
* in a worktree. The mitigations (auto-retry, a progress bank, transcript
|
|
8
|
+
* retention) worked, but every death still cost the conductor a manual state
|
|
9
|
+
* audit — memory, not mechanism. Three dispatches measured the same gap: a
|
|
10
|
+
* settled failure reported the failure and nothing about the tree.
|
|
11
|
+
*
|
|
12
|
+
* This module is the FORMATTING half. `probeWorktree` (git.ts) does the reading,
|
|
13
|
+
* and the split is deliberate: execution stays where `architecture-rules`
|
|
14
|
+
* confines it, and this module never throws, never classifies a run and never
|
|
15
|
+
* decides whether the tree is safe — it reports. The decision stays with the
|
|
16
|
+
* conductor (rule-notes: a killed agent's worktree is hostile until read).
|
|
17
|
+
*
|
|
18
|
+
* It imports `./git` and `node:path` only. That is a hard constraint, not a
|
|
19
|
+
* preference: `sanitize.ts` imports THIS module for the one crash seam, so any
|
|
20
|
+
* edge back into `sanitize.ts` (or into a module that imports it) would close a
|
|
21
|
+
* runtime cycle.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import * as path from "node:path";
|
|
25
|
+
|
|
26
|
+
import { probeWorktree } from "./git";
|
|
27
|
+
|
|
28
|
+
/** The block's first line. One spelling, so a reader (and a test) can find it. */
|
|
29
|
+
const HEADING = "Worktree state (git, at failure):";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The caution line's job is to stop a conductor from reusing a tree it did not
|
|
33
|
+
* inspect. It carries no verdict — "may be" is the whole claim.
|
|
34
|
+
*/
|
|
35
|
+
const CAUTION =
|
|
36
|
+
" — uncommitted work may be a partially applied edit or a mutant; inspect before reusing.";
|
|
37
|
+
|
|
38
|
+
/** The property a rethrown unit crash carries its own block on (`finalizeUnitRunCrash`). */
|
|
39
|
+
export interface WorktreeStateCarrier {
|
|
40
|
+
worktreeState?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** An unavailable report — the block's whole body when the probe could not look. */
|
|
44
|
+
function unavailable(reason: string): string {
|
|
45
|
+
return `${HEADING}\n state: unavailable (${reason})`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** `1 file` / `2 files` — a count that reads as English in the report line. */
|
|
49
|
+
function fileCount(n: number): string {
|
|
50
|
+
return `${n} file${n === 1 ? "" : "s"}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Render a successful probe as the block. */
|
|
54
|
+
function renderProbe(probe: Extract<ReturnType<typeof probeWorktree>, { kind: "ok" }>): string {
|
|
55
|
+
const branch = probe.detached
|
|
56
|
+
? "(detached)"
|
|
57
|
+
: probe.unborn
|
|
58
|
+
? `${probe.branch ?? "(unborn)"} (unborn)`
|
|
59
|
+
: (probe.branch ?? "(unknown)");
|
|
60
|
+
const lineCounts =
|
|
61
|
+
probe.insertions === undefined ? "" : ` (+${probe.insertions}/−${probe.deletions ?? 0})`;
|
|
62
|
+
const lines = [
|
|
63
|
+
HEADING,
|
|
64
|
+
` branch: ${branch}`,
|
|
65
|
+
` dirty: ${fileCount(probe.dirtyFiles)}${lineCounts}`,
|
|
66
|
+
` staged: ${probe.stagedFiles}`,
|
|
67
|
+
];
|
|
68
|
+
// Only an unclean tree earns the caution: a clean failure has nothing to warn
|
|
69
|
+
// about, and a warning on every failure is a warning nobody reads.
|
|
70
|
+
if (probe.dirtyFiles + probe.stagedFiles > 0) lines.push(CAUTION);
|
|
71
|
+
return lines.join("\n");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The worktree-state block for `cwd`. ALWAYS returns text (never throws, never
|
|
76
|
+
* returns ""), because its callers append it to a message they must still
|
|
77
|
+
* deliver:
|
|
78
|
+
*
|
|
79
|
+
* - no cwd → `state: unavailable (no cwd)`;
|
|
80
|
+
* - a RELATIVE cwd → `state: unavailable (no recorded cwd)`. A background
|
|
81
|
+
* record written before #474 stamped `cwd` may hold the relative value the
|
|
82
|
+
* caller passed; resolving it against the conductor's process cwd would
|
|
83
|
+
* report a tree nobody ran in, so it is refused rather than guessed;
|
|
84
|
+
* - not a repo → `state: unavailable (not a git repository)`;
|
|
85
|
+
* - any read failure → `state: unavailable (<git's own reason>)`.
|
|
86
|
+
*
|
|
87
|
+
* The outer catch is belt-and-braces: `probeWorktree` classifies its own
|
|
88
|
+
* failures, and this one makes "never throws" a property of the formatter even
|
|
89
|
+
* if a future edit breaks that.
|
|
90
|
+
*/
|
|
91
|
+
export function describeWorktreeState(cwd: string | undefined): string {
|
|
92
|
+
if (cwd === undefined || cwd.length === 0) return unavailable("no cwd");
|
|
93
|
+
if (!path.isAbsolute(cwd)) return unavailable("no recorded cwd");
|
|
94
|
+
try {
|
|
95
|
+
const probe = probeWorktree(cwd);
|
|
96
|
+
if (probe.kind === "not-repo") return unavailable("not a git repository");
|
|
97
|
+
if (probe.kind === "unavailable") return unavailable(probe.reason);
|
|
98
|
+
return renderProbe(probe);
|
|
99
|
+
} catch (err) {
|
|
100
|
+
return unavailable(err instanceof Error ? err.message : String(err));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The block an error already carries, when a unit crash attached its OWN tree.
|
|
106
|
+
* A mode runner's outer catch only knows the dispatch cwd; `finalizeUnitRunCrash`
|
|
107
|
+
* attaches the crashing unit's block to the rethrown error so the mode-level
|
|
108
|
+
* crash reports the unit's worktree rather than a sibling's (issue #474).
|
|
109
|
+
*/
|
|
110
|
+
export function attachedWorktreeState(err: unknown): string | undefined {
|
|
111
|
+
if (typeof err !== "object" || err === null) return undefined;
|
|
112
|
+
const carried = (err as WorktreeStateCarrier).worktreeState;
|
|
113
|
+
return typeof carried === "string" && carried.length > 0 ? carried : undefined;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Attach the block for `cwd` to a rethrown error, best-effort.
|
|
118
|
+
*
|
|
119
|
+
* A thrown NON-OBJECT (a bare string) cannot carry anything, so the mode catch
|
|
120
|
+
* falls back to the dispatch cwd — a stated limit, not a silent one: real
|
|
121
|
+
* runner crashes throw `Error` instances.
|
|
122
|
+
*/
|
|
123
|
+
export function attachWorktreeState(err: unknown, cwd: string | undefined): void {
|
|
124
|
+
if (typeof err !== "object" || err === null) return;
|
|
125
|
+
(err as WorktreeStateCarrier).worktreeState = describeWorktreeState(cwd);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Append the worktree block to failure text, separated by a blank line.
|
|
130
|
+
*
|
|
131
|
+
* The block goes LAST (issue #474 v3): the crash envelope, the classified-failure
|
|
132
|
+
* message and its H1 warnings note are the reason, and a report of the residue
|
|
133
|
+
* belongs after the cause — never spliced into it.
|
|
134
|
+
*
|
|
135
|
+
* `err` is optional and only for the crash seam: when a unit crash carried its
|
|
136
|
+
* own block, that block wins over `cwd`, which the mode-level caller only knows
|
|
137
|
+
* as the dispatch cwd.
|
|
138
|
+
*/
|
|
139
|
+
export function appendWorktreeState(text: string, cwd: string | undefined, err?: unknown): string {
|
|
140
|
+
const block = attachedWorktreeState(err) ?? describeWorktreeState(cwd);
|
|
141
|
+
return `${text}\n\n${block}`;
|
|
142
|
+
}
|