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.
Files changed (47) hide show
  1. package/AGENT.md +1 -1
  2. package/README.md +3 -3
  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 +3 -5
  9. package/src/delegate-handler.ts +2261 -0
  10. package/src/engineering-bar.ts +1 -1
  11. package/src/git.ts +220 -8
  12. package/src/headstate.ts +3 -3
  13. package/src/history.ts +21 -3
  14. package/src/index.ts +109 -4473
  15. package/src/loader.ts +1 -1
  16. package/src/logging.ts +1 -1
  17. package/src/mode-prologue.ts +4 -10
  18. package/src/mode-runners.ts +1575 -0
  19. package/src/notify-completion.ts +35 -8
  20. package/src/params.ts +14 -13
  21. package/src/preflight.ts +123 -16
  22. package/src/prelude.ts +14 -5
  23. package/src/presets.ts +3 -5
  24. package/src/proc.ts +2 -3
  25. package/src/recovery-engine.ts +1 -1
  26. package/src/recovery-surface.ts +1 -2
  27. package/src/recovery.ts +2 -3
  28. package/src/reports.ts +1 -7
  29. package/src/run-registry.ts +2 -3
  30. package/src/runner.ts +47 -18
  31. package/src/runtime.ts +50 -0
  32. package/src/sanitize.ts +20 -2
  33. package/src/scheduler.ts +1 -2
  34. package/src/scratch-root.ts +909 -0
  35. package/src/scratch-spawn.ts +256 -0
  36. package/src/session-manager.ts +75 -7
  37. package/src/state.ts +12 -14
  38. package/src/templates.ts +3 -5
  39. package/src/terminal-notifier.ts +405 -0
  40. package/src/transcript.ts +1 -1
  41. package/src/tui-format.ts +3 -1
  42. package/src/tui.ts +42 -32
  43. package/src/types.ts +29 -3
  44. package/src/unit-params.ts +113 -0
  45. package/src/unit-run.ts +35 -15
  46. package/src/validate.ts +2 -3
  47. package/src/worktree-report.ts +142 -0
@@ -0,0 +1,256 @@
1
+ // Purpose: The spawn seam for the shipped scratch root — resolves, creates, prunes and settles one run's directory.
2
+ /**
3
+ * brl-subagent — the scratch root at the spawn seam (issue #511, U2)
4
+ *
5
+ * WHY THIS MODULE EXISTS. `scratch-root.ts` (U1) decides WHERE a scratch path is
6
+ * allowed to live and how one is created safely; it creates nothing on its own.
7
+ * This module is the one caller that turns that verdict into a run's directory
8
+ * on the way to a spawn, so the two execution surfaces cannot disagree about
9
+ * the shape of a run's scratch:
10
+ *
11
+ * - FOREGROUND — `runner.ts` (`runSubagent`), the chokepoint every blocking
12
+ * dispatch passes through: single, chain, parallel, graph, and the timeout
13
+ * retry. The child is a real `pi` subprocess, so the directory rides its
14
+ * environment as `BRL_SCRATCH` (an `envOverrides` entry, which `getSafeEnv`
15
+ * applies LAST — so a value inherited from the parent process is replaced,
16
+ * never trusted).
17
+ * - BACKGROUND — `session-manager.ts` (`spawnBackgroundSession`), the single
18
+ * place a background agent record and run entry are created: single,
19
+ * fan-out and the transport retry all funnel through it. A background agent
20
+ * is an IN-PROCESS SDK session, not a subprocess — there is no per-run child
21
+ * environment to set (the SDK builds the shell env from `process.env` at
22
+ * command time, so a per-run value there would be process-global and racy).
23
+ * The directory and the run record's `scratchDir` are therefore the whole
24
+ * carrier on that surface.
25
+ *
26
+ * WHY THE SEAM IS NOT IN THE PREFLIGHT OR A BACKGROUND-ONLY TAIL. The
27
+ * foreground path deliberately skips the preflight, so a decision made there
28
+ * would miss every blocking dispatch; and resolving inside the background tail
29
+ * would miss the foreground one. Both surfaces call THIS module at their own
30
+ * spawn point instead.
31
+ *
32
+ * THE INVARIANT, stated once: by the time a child starts, `<root>/runs/<runId>`
33
+ * exists at 0700 and the child's environment carries that absolute path as
34
+ * `BRL_SCRATCH`. A refusal is named and PRE-SPAWN: the caller gets the code and
35
+ * message and no child starts (`runner.ts` returns the refusal as a failed
36
+ * result; `session-manager.ts` throws before the agent record exists, and its
37
+ * callers translate that into their ordinary spawn-failure shape).
38
+ *
39
+ * THE RESOLVER NEVER READS `BRL_SCRATCH`. `resolveRoot` reads `HOME` /
40
+ * `LOCALAPPDATA` only, so a child cannot steer its own root — and because
41
+ * `BRL_SCRATCH` is deliberately NOT in `getSafeEnv`'s allowlist, a nested child
42
+ * resolves its OWN root instead of inheriting its parent's (the parent's value
43
+ * is a path the parent chose; the grandchild's run is a different directory).
44
+ *
45
+ * BEST-EFFORT, NAMED AS SUCH. Two operations here can fail without failing the
46
+ * spawn: the retention prune (`pruneRuns` reports, never throws) and the settle
47
+ * marker (`markRunDone`); both log and continue. Resolution and creation are the
48
+ * opposite — they are named refusals that stop the spawn.
49
+ */
50
+
51
+ import { createLogger, type Logger } from "./logging";
52
+ import {
53
+ ensureRunDir,
54
+ markRunDone,
55
+ pruneRuns,
56
+ resolveRoot,
57
+ type RootOptions,
58
+ type RootWarningKind,
59
+ type ScratchRootCode,
60
+ } from "./scratch-root";
61
+
62
+ /**
63
+ * The child environment key carrying the run's scratch directory. Set through
64
+ * `envOverrides` (applied last by `getSafeEnv`), never allowlisted: an
65
+ * inherited value must be REPLACED, and a grandchild must resolve its own.
66
+ */
67
+ export const SCRATCH_ENV_KEY = "BRL_SCRATCH";
68
+
69
+ /**
70
+ * The logger for a seam whose caller has none to pass (`createUnitRun` writes a
71
+ * run record before any mode's logger is threaded through). Mirrors
72
+ * `runner.ts`'s `fallbackLog`: a diagnostic the caller could not instrument
73
+ * still has somewhere to land, and it is never dropped silently.
74
+ */
75
+ const fallbackLog = createLogger("scratch");
76
+
77
+ /**
78
+ * `prepareRunScratch`'s verdict: the run's directory, or the resolver's named
79
+ * refusal. The `ok: false` arm carries the U1 code verbatim — one taxonomy, so
80
+ * the caller, the message and the tests cannot drift.
81
+ */
82
+ export type RunScratch =
83
+ | { ok: true; root: string; runDir: string }
84
+ | { ok: false; code: ScratchRootCode; message: string };
85
+
86
+ /** What a caller may inject. Production passes nothing but the logger. */
87
+ export interface PrepareScratchOptions {
88
+ /** The seam's own sink. Absent falls back to the module logger. */
89
+ log?: Logger;
90
+ /**
91
+ * Root-resolution inputs, injected by tests only (`home` is the one that
92
+ * moves the layout). Production lets `resolveRoot` read the real environment.
93
+ */
94
+ root?: RootOptions;
95
+ /**
96
+ * The retention sweep, injected by tests only. Production uses `pruneRuns`;
97
+ * the injection exists so the containment below (a throwing sweep must not
98
+ * fail a spawn) is asserted against a sweep that really throws, rather than
99
+ * claimed from `pruneRuns`'s own best-effort contract.
100
+ */
101
+ prune?: typeof pruneRuns;
102
+ }
103
+
104
+ // ---------------------------------------------------------------------------
105
+ // Test-only redirects (mirroring __setStorageDir / __setRegistryDir)
106
+ // ---------------------------------------------------------------------------
107
+
108
+ /**
109
+ * A test-only root redirect. The suites that exercise a spawn cannot thread
110
+ * `RootOptions` through `runSubagent`/`spawnBackgroundSession`, and they must
111
+ * not write into the developer's real cache root. When set, the root is used
112
+ * AS GIVEN — `ensureRunDir` still validates the chain and creates at 0700, so
113
+ * the seam's guarantees are unchanged; only the platform map is bypassed.
114
+ *
115
+ * `createTempEnv` points this at a throwaway directory per test, so no suite
116
+ * creates anything under the real `$HOME`.
117
+ */
118
+ let rootRedirect: string | undefined;
119
+
120
+ /** TEST-ONLY: resolve every run's scratch under `root` instead of the platform cache. */
121
+ export function __setScratchRoot(root: string | undefined): void {
122
+ rootRedirect = root;
123
+ }
124
+
125
+ /** TEST-ONLY: forget the once-per-process root advisory. */
126
+ export function __resetScratchWarning(): void {
127
+ warnedRoot.clear();
128
+ }
129
+
130
+ // ---------------------------------------------------------------------------
131
+ // The root advisory — once per process, never once per run
132
+ // ---------------------------------------------------------------------------
133
+
134
+ /**
135
+ * The advisory KINDS already emitted, not one boolean. The resolver can carry two different warnings
136
+ * (a `tmpfs` mount and a group/other-writable ancestor, or both joined into one string), and a single
137
+ * flag would let the first kind swallow the second: the process would learn about the writable parent
138
+ * only if it happened to be resolved first. Keyed by kind rather than by text, because the mount
139
+ * sentence legitimately changes wording once the root exists (see `ROOT_WARNING_KINDS`).
140
+ */
141
+ const warnedRoot = new Set<RootWarningKind>();
142
+
143
+ /**
144
+ * One line per advisory KIND per process: a fan-out of twenty units prints one line, never twenty. A
145
+ * report can carry both kinds at once, and then that ONE line carries both sentences; a kind already
146
+ * reported never re-logs on its own, which is the whole point of keying on kinds rather than on one
147
+ * boolean — a single flag would let the first kind swallow the second.
148
+ */
149
+ function warnRootOnce(warning: string, kinds: readonly RootWarningKind[], log: Logger): void {
150
+ const fresh = kinds.filter((kind) => !warnedRoot.has(kind));
151
+ if (fresh.length === 0) return;
152
+ for (const kind of fresh) warnedRoot.add(kind);
153
+ log.warn(`scratch root: ${warning}`);
154
+ }
155
+
156
+ // ---------------------------------------------------------------------------
157
+ // The seam
158
+ // ---------------------------------------------------------------------------
159
+
160
+ /**
161
+ * Resolve the root, create `<root>/runs/<runId>` at 0700, and prune settled
162
+ * runs — the one call both spawn surfaces make.
163
+ *
164
+ * Order matters. Resolution comes first (a refusal there means nothing is
165
+ * created), then creation (`ensureRunDir` validates the chain before and after),
166
+ * then the sweep (which must never see the current run as prunable, hence
167
+ * `exclude`). Pruning AFTER creation is what makes `exclude` meaningful: the
168
+ * directory it protects is the one that was just made.
169
+ *
170
+ * A prune failure is contained here, not by the caller: a retention sweep that
171
+ * cannot delete a directory is a cache that grows, never a spawn that fails.
172
+ */
173
+ export function prepareRunScratch(runId: string, options: PrepareScratchOptions = {}): RunScratch {
174
+ const log = options.log ?? fallbackLog;
175
+ // Precedence, stated once: an EXPLICIT injection wins (the module's own
176
+ // tests), then the suite-level redirect (`createTempEnv`, the global test
177
+ // setup), then the resolver's real defaults — the production path.
178
+ const resolved =
179
+ options.root !== undefined
180
+ ? resolveRoot(options.root)
181
+ : rootRedirect !== undefined
182
+ ? { ok: true as const, root: rootRedirect }
183
+ : resolveRoot();
184
+ if (!resolved.ok) {
185
+ log.warn(`scratch root: refusing the spawn (${resolved.code}) — ${resolved.message}`);
186
+ return { ok: false, code: resolved.code, message: resolved.message };
187
+ }
188
+ if (resolved.warning !== undefined) warnRootOnce(resolved.warning, resolved.warningKinds ?? [], log);
189
+
190
+ const run = ensureRunDir(resolved.root, runId, options.root?.platform ? { platform: options.root.platform } : {});
191
+ if (!run.ok) {
192
+ log.warn(`scratch run dir: refusing the spawn (${run.code}) — ${run.message}`);
193
+ return { ok: false, code: run.code, message: run.message };
194
+ }
195
+
196
+ pruneSettled(run.root, run.runDir, log, options.prune ?? pruneRuns);
197
+ return { ok: true, root: run.root, runDir: run.runDir };
198
+ }
199
+
200
+ /** The retention sweep: report what it removed, never throw, never fail the spawn. */
201
+ function pruneSettled(root: string, runDir: string, log: Logger, sweep: typeof pruneRuns): void {
202
+ try {
203
+ const pruned = sweep(root, { exclude: runDir });
204
+ if (pruned.removed.length > 0) {
205
+ log.debug("scratch root: pruned settled run directories", {
206
+ root,
207
+ removed: pruned.removed.length,
208
+ kept: pruned.kept.length,
209
+ });
210
+ }
211
+ } catch (error) {
212
+ // `pruneRuns` reports rather than throws by construction; this belt covers
213
+ // a future edit of that contract, because a sweep is never worth a run.
214
+ log.warn("scratch root: prune failed — the spawn continues", {
215
+ root,
216
+ error: error instanceof Error ? error.message : String(error),
217
+ });
218
+ }
219
+ }
220
+
221
+ // ---------------------------------------------------------------------------
222
+ // The settle marker
223
+ // ---------------------------------------------------------------------------
224
+
225
+ /**
226
+ * Write the run's settle marker (`.done`) on a terminal path: done, failed or
227
+ * killed. Best-effort by contract — a marker that cannot be written is logged
228
+ * and the run's outcome is untouched, because retention is an optimization and
229
+ * boundedness is not this function's business.
230
+ *
231
+ * A run without a `scratchDir` (a pre-U2 record, or one whose preparation was
232
+ * refused before anything was created) is a no-op: there is no directory to
233
+ * mark, and a `.done` written beside a directory that does not exist would be a
234
+ * marker for nothing.
235
+ */
236
+ export function markSettled(run: { id?: string; scratchDir?: string }, log?: Logger): void {
237
+ if (run.scratchDir === undefined) return;
238
+ const sink = log ?? fallbackLog;
239
+ try {
240
+ const marked = markRunDone(run.scratchDir);
241
+ if (!marked.ok) {
242
+ sink.warn("scratch root: settle marker not written — the run's outcome is unchanged", {
243
+ runId: run.id,
244
+ runDir: run.scratchDir,
245
+ code: marked.code,
246
+ error: marked.message,
247
+ });
248
+ }
249
+ } catch (error) {
250
+ sink.warn("scratch root: settle marker threw — the run's outcome is unchanged", {
251
+ runId: run.id,
252
+ runDir: run.scratchDir,
253
+ error: error instanceof Error ? error.message : String(error),
254
+ });
255
+ }
256
+ }
@@ -1,11 +1,28 @@
1
1
  // Purpose: Background execution: SDK sessions (`createAgentSession`), agent records, timeouts, steering, and settle paths.
2
2
  import { randomUUID } from 'crypto';
3
3
  import { basename, dirname, join, resolve } from 'path';
4
- import { writeFileSync, readFileSync, readdirSync, existsSync, rmSync, statSync } from 'fs';
5
- import type { Dirent } from 'fs';
6
- import type { BackgroundAgent, AgentStatus, GitMode, RecoveryMode, SubagentResult, SubagentRun, ThinkingLevel, SubagentToolOptions, UsageStats, ErrorCategory } from './types';
7
- import { EMPTY_USAGE, classifyError, classifyTerminalOutcome, isProviderError, coherentFailureReason, SUBAGENT_ABORTED_MESSAGE, NO_ASSISTANT_OUTPUT_REASON, PROMPT_NEVER_ISSUED_MESSAGE } from './types';
8
- import type { AssistantEvidence } from './types';
4
+ import { writeFileSync, readFileSync, readdirSync, existsSync, rmSync, statSync, type Dirent } from 'fs';
5
+ import {
6
+ EMPTY_USAGE,
7
+ classifyError,
8
+ classifyTerminalOutcome,
9
+ isProviderError,
10
+ coherentFailureReason,
11
+ SUBAGENT_ABORTED_MESSAGE,
12
+ NO_ASSISTANT_OUTPUT_REASON,
13
+ PROMPT_NEVER_ISSUED_MESSAGE,
14
+ type BackgroundAgent,
15
+ type AgentStatus,
16
+ type GitMode,
17
+ type RecoveryMode,
18
+ type SubagentResult,
19
+ type SubagentRun,
20
+ type ThinkingLevel,
21
+ type SubagentToolOptions,
22
+ type UsageStats,
23
+ type ErrorCategory,
24
+ type AssistantEvidence,
25
+ } from './types';
9
26
  import { accumulateUsage } from './runner';
10
27
  import * as eventBus from './event-bus';
11
28
  import * as transcript from './transcript';
@@ -13,8 +30,20 @@ import { createEvent } from './event-bus';
13
30
  import { assertSafeAgentId, sanitizeErrorMessage } from './sanitize';
14
31
  import { wrapTask } from './prompt';
15
32
  import { createLogger } from './logging';
16
- import { getCurrentBranch, getHeadState, restoreHead, createWorkBranch, newWorkBranchName, captureDiff, deleteBranch, hasUncommittedChanges, getRepoRoot, commitAll, captureWorkingDiff } from './git';
17
- import type { HeadState } from './git';
33
+ import {
34
+ getCurrentBranch,
35
+ getHeadState,
36
+ restoreHead,
37
+ createWorkBranch,
38
+ newWorkBranchName,
39
+ captureDiff,
40
+ deleteBranch,
41
+ hasUncommittedChanges,
42
+ getRepoRoot,
43
+ commitAll,
44
+ captureWorkingDiff,
45
+ type HeadState,
46
+ } from './git';
18
47
  import { clearHeadState, readHeadState, writeHeadState, HEAD_STATE_VERSION } from './headstate';
19
48
  import { effectiveBackgroundBudget } from './validate';
20
49
  import { currentProcessOwner, classifyOwner, defaultRecoveryDeps } from './recovery';
@@ -22,6 +51,7 @@ import { persistRunRecord, listInflightRuns, clearInflightRun, type InflightRun
22
51
  import { isTransportRetryable } from './transport-retry';
23
52
  import { ensureOwnerOnlyDir, repairOwnerOnlyFiles } from './store-permissions';
24
53
  import { buildEngineeringBarSection } from './engineering-bar';
54
+ import { prepareRunScratch, markSettled } from './scratch-spawn';
25
55
 
26
56
  const log = createLogger('brl-subagent');
27
57
  import type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';
@@ -1339,6 +1369,26 @@ export async function spawnBackgroundSession(
1339
1369
 
1340
1370
  try {
1341
1371
  const id = generateUUID();
1372
+ // Issue #511 (U2): the scratch seam for the BACKGROUND surface. This function
1373
+ // is the single place a background agent record and run entry are created
1374
+ // (single, fan-out and the transport retry all pass through it), so the run's
1375
+ // directory is resolved and created HERE — before the SDK is asked for a
1376
+ // session, and therefore before `session.prompt()` can start the child.
1377
+ //
1378
+ // A refusal is PRE-SPAWN and NAMED: it throws before any record exists, and
1379
+ // both pipeline callers translate a throw from this function into their
1380
+ // ordinary "Failed to spawn background agent: …" result — the same shape as
1381
+ // every other spawn failure.
1382
+ //
1383
+ // NOTE, stated rather than implied: a background run is an IN-PROCESS SDK
1384
+ // session, so there is no child environment to carry `BRL_SCRATCH` (the SDK
1385
+ // composes the shell env from `process.env` at command time, which a per-run
1386
+ // value cannot vary without race). The directory and the record's
1387
+ // `scratchDir` are this surface's whole carrier.
1388
+ const scratch = prepareRunScratch(id, { log });
1389
+ if (!scratch.ok) {
1390
+ throw new Error(`scratch root unavailable (${scratch.code}): ${scratch.message}`);
1391
+ }
1342
1392
  const effectiveCwd = params.cwd ?? ctx.cwd;
1343
1393
  // Dynamic import — static import fails under concurrent jiti loads
1344
1394
  const { getAgentDir, createAgentSession, SessionManager, SettingsManager, DefaultResourceLoader } = await import('@earendil-works/pi-coding-agent');
@@ -1506,6 +1556,12 @@ export async function spawnBackgroundSession(
1506
1556
  model: params.model || 'unknown',
1507
1557
  thinkingLevel: params.thinkingLevel || 'medium',
1508
1558
  priority: params.priority,
1559
+ // Issue #474: the directory this run was spawned in, stamped so a settled
1560
+ // failure can report the worktree it may have left. `effectiveCwd` is the
1561
+ // resolved, validated absolute path (params.cwd ?? ctx.cwd), and
1562
+ // `persistAgent` strips only the live-only pointers — so this survives the
1563
+ // record and the completion wake can read it.
1564
+ cwd: effectiveCwd,
1509
1565
  dispatchId,
1510
1566
  resumeOf: params.resumeOf,
1511
1567
  attempt,
@@ -1545,6 +1601,10 @@ export async function spawnBackgroundSession(
1545
1601
  attempt,
1546
1602
  owner,
1547
1603
  recoveryPosture: params.recoveryPosture,
1604
+ // Issue #511 (U2): the run's scratch directory (`<root>/runs/<id>`, 0700),
1605
+ // created above. Persisted at spawn so the retry preamble (U3) and the
1606
+ // settle path read one value rather than re-deriving a location.
1607
+ scratchDir: scratch.runDir,
1548
1608
  // Issue #447: the acceptance marker starts `null` — the dispatch is
1549
1609
  // TRACKED from here on (agent record + registry entry) but the prompt has
1550
1610
  // not been issued. Only the write immediately above `session.prompt()`
@@ -1621,6 +1681,14 @@ export async function spawnBackgroundSession(
1621
1681
  error?: string,
1622
1682
  terminal?: { stopReason?: string; errorCategory?: ErrorCategory; prune?: boolean },
1623
1683
  ): SubagentRun | undefined => {
1684
+ // Issue #511 (U2): settling includes the scratch directory's `.done` marker.
1685
+ // This is the SINGLE terminal choke point for a background run (git-setup
1686
+ // refusal, a synchronous prompt throw, the .then/.catch branches, the
1687
+ // catch-all and the deadline), so the marker is written here and no settle
1688
+ // path can forget it. Best-effort: `markSettled` logs and never throws, so
1689
+ // it cannot change the run's outcome. A run with no directory (a pre-U2
1690
+ // record) is a no-op.
1691
+ markSettled(run, log);
1624
1692
  const usage = agent.result?.usage ?? EMPTY_USAGE;
1625
1693
  const finalOutput = agent.finalOutput ?? "";
1626
1694
  // The TRUE category of THIS call — see the note on `classifyFailure`.
package/src/state.ts CHANGED
@@ -9,20 +9,9 @@
9
9
  * F9: State schema validation — validates on load, migrates legacy formats.
10
10
  */
11
11
 
12
- import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
13
- import type {
14
- SubagentState,
15
- SubagentRun,
16
- LiveSubagent,
17
- ThinkingLevel,
18
- ApprovalMode,
19
- CompletionNotifyMode,
20
- RecoveryMode,
21
- CircuitBreakerState,
22
- Priority,
23
- ModeContext,
24
- } from "./types";
12
+ import type { Logger } from "./logging";
25
13
  import type { TranscriptMessage } from "./transcript-tail";
14
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
26
15
  import {
27
16
  isSubagentStateShape,
28
17
  isSubagentRunShape,
@@ -38,10 +27,19 @@ import {
38
27
  MAX_CONSECUTIVE_FAILURES,
39
28
  CIRCUIT_BREAKER_RESET_MS,
40
29
  CIRCUIT_DEGRADED_THINKING,
30
+ type SubagentState,
31
+ type SubagentRun,
32
+ type LiveSubagent,
33
+ type ThinkingLevel,
34
+ type ApprovalMode,
35
+ type CompletionNotifyMode,
36
+ type RecoveryMode,
37
+ type CircuitBreakerState,
38
+ type Priority,
39
+ type ModeContext,
41
40
  } from "./types";
42
41
  import { cleanupRuns } from "./history";
43
42
  import { persistRunRecord, type InflightRunKind } from "./run-registry";
44
- import type { Logger } from "./logging";
45
43
 
46
44
  // ---------------------------------------------------------------------------
47
45
  // Live-monitor staleness sweep (issue #52 part 2)
package/src/templates.ts CHANGED
@@ -22,13 +22,11 @@
22
22
  * // resolved.value.task now has placeholders filled
23
23
  */
24
24
 
25
+ import type { Logger } from "./logging";
25
26
  import * as fs from "node:fs";
26
27
  import * as path from "node:path";
27
- import type { TaskTemplate, ThinkingLevel, SubagentPreset } from "./types";
28
- import { TEMPLATE_PARAM_RE, THINKING_LEVELS } from "./types";
29
- import type { Logger } from "./logging";
30
- import { applyFrontmatterMappers, loadMarkdownRecords } from "./loader";
31
- import type { FrontmatterFieldMapper, FrontmatterMapContext } from "./loader";
28
+ import { TEMPLATE_PARAM_RE, THINKING_LEVELS, type TaskTemplate, type ThinkingLevel, type SubagentPreset } from "./types";
29
+ import { applyFrontmatterMappers, loadMarkdownRecords, type FrontmatterFieldMapper, type FrontmatterMapContext } from "./loader";
32
30
  import { sanitizeFileName } from "./presets";
33
31
  import { pkgPath } from "./paths";
34
32