brl-subagent 2.6.0 → 2.8.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/src/types.ts CHANGED
@@ -35,6 +35,28 @@ export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhi
35
35
 
36
36
  export const THINKING_LEVELS: ThinkingLevel[] = ["off", "minimal", "low", "medium", "high", "xhigh"];
37
37
 
38
+ /**
39
+ * Issue #443: the ONE membership test for a thinking level — the guard every
40
+ * seam that can launch a subagent calls before a DECLARED level is resolved.
41
+ *
42
+ * Why it is not `resolveThinkingLevel`: that function CLAMPS, and it cannot
43
+ * report failure. An unknown value (`"bogus"`, `"MAX"`, `" high"`) has index
44
+ * -1, so `THINKING_LEVELS[Math.min(-1, maxIdx)]` is `undefined` — the level is
45
+ * then erased into argv as `--thinking undefined`, pi warns and runs at ITS OWN
46
+ * default, and the configured cap is bypassed rather than a launch refused.
47
+ * Callers therefore check membership first and keep `resolveThinkingLevel`
48
+ * exactly as it is for valid input.
49
+ *
50
+ * Case- and whitespace-exact by construction (`THINKING_LEVELS.includes`), so
51
+ * `"High"` and `" high"` are rejected too. `""` is NOT a level: the dispatch
52
+ * seams preserve its existing meaning (top level → the configured maximum,
53
+ * per unit → the global level), so the empty string is handled by them, not
54
+ * here. pi's own `max` is not a delegated level.
55
+ */
56
+ export function isThinkingLevel(value: unknown): value is ThinkingLevel {
57
+ return typeof value === "string" && (THINKING_LEVELS as readonly string[]).includes(value);
58
+ }
59
+
38
60
  export type Priority = "critical" | "high" | "normal" | "low";
39
61
 
40
62
  export const PRIORITY_ORDER: Record<Priority, number> = {
@@ -80,6 +102,14 @@ export const SUBAGENT_ABORTED_MESSAGE = "Subagent aborted by user";
80
102
  // SUBAGENT_ABORTED_MESSAGE match) — keep the literal in sync with classifyError.
81
103
  export const SUBAGENT_SIGNAL_KILLED_MESSAGE = "Subagent killed by external signal";
82
104
 
105
+ // Issue #447: the honest stamp for a dispatch that never reached
106
+ // `session.prompt()`. Shared by the in-process pre-start cleanup
107
+ // (session-manager) and the boot scan's never-started finalize (recovery) so
108
+ // the two surfaces cannot describe the same non-event differently. It carries
109
+ // no classifyError keyword on purpose — a pre-start failure is `unknown`, not a
110
+ // timeout, an abort, or an exit error.
111
+ export const PROMPT_NEVER_ISSUED_MESSAGE = "Subagent prompt was never issued";
112
+
83
113
  /**
84
114
  * Classify a subagent result into an error category based on its errorMessage,
85
115
  * stopReason, exitCode, and stderr content. Inspects patterns in priority order.
@@ -288,6 +318,46 @@ export interface ProcessOwner {
288
318
  start: string;
289
319
  }
290
320
 
321
+ /**
322
+ * Issue #381 (audit D5): the retry-override snapshot taken from the caller's
323
+ * raw delegate_task params at dispatch (see `snapshotOriginalParams` in
324
+ * params.ts). Declared once so the snapshotter and the run record cannot
325
+ * drift apart; `errorCategory` is deliberately NOT a snapshot field — the
326
+ * failure paths stamp it onto `originalParams` after the fact.
327
+ */
328
+ export interface SnapshotParams {
329
+ systemPrompt?: string;
330
+ inheritSystemPrompt?: boolean;
331
+ model?: string;
332
+ thinkingLevel?: string;
333
+ /** Issue #114: per-unit priority survives retries. */
334
+ priority?: string;
335
+ outputFile?: string;
336
+ timeout?: number;
337
+ cwd?: string;
338
+ tools?: string[];
339
+ excludeTools?: string[];
340
+ noBuiltinTools?: boolean;
341
+ preset?: string;
342
+ /**
343
+ * Issue #227: the execution-shape fields survive retries, so a retried
344
+ * background run stays background and a retried branch-mode run keeps its
345
+ * work branch, its approvalMode gating and its force override.
346
+ */
347
+ background?: boolean;
348
+ gitMode?: string;
349
+ approvalMode?: string;
350
+ force?: boolean;
351
+ /**
352
+ * Issue #401: the original, un-prefixed task — recorded ONLY by the transport
353
+ * auto-retry spawn site, whose child record's `task` also carries the resume
354
+ * preamble. `snapshotOriginalParams` never writes it (the run record's `task`
355
+ * is the normal carrier); it exists so a further retry resolves from the
356
+ * original text instead of stacking preambles.
357
+ */
358
+ task?: string;
359
+ }
360
+
291
361
  export interface SubagentRun {
292
362
  id: string;
293
363
  task: string;
@@ -342,6 +412,20 @@ export interface SubagentRun {
342
412
  // Option B U3 (D4): the recovery posture in force when this run was
343
413
  // dispatched. Additive: a pre-U3 record lacks it and reads as "offer".
344
414
  recoveryPosture?: RecoveryMode;
415
+ /**
416
+ * Issue #447: the acceptance marker. `null` at creation — the dispatch is
417
+ * TRACKED (agent record + run entry + registry entry written) but has not
418
+ * reached `session.prompt()`; an ISO timestamp written immediately before
419
+ * the prompt; absent on records written before the field existed.
420
+ *
421
+ * The tri-state IS the compatibility contract: `null` cannot be produced by
422
+ * a pre-upgrade record (JSON keeps `null`, where `undefined` would vanish),
423
+ * so the boot scan reads `null` as never-started without taking the retry
424
+ * offer away from a legacy record. It is NOT a display status — the
425
+ * vocabulary stays running | completed | failed | stopped, and "started,
426
+ * outcome unknown" remains #439's business (see `isInterruptedRun`).
427
+ */
428
+ acceptedAt?: string | null;
345
429
  startedAt: string;
346
430
  finishedAt?: string;
347
431
  durationMs?: number;
@@ -351,29 +435,8 @@ export interface SubagentRun {
351
435
  errorMessage?: string;
352
436
  outputSummary?: string;
353
437
  fullOutput?: string;
354
- originalParams?: {
355
- systemPrompt?: string;
356
- inheritSystemPrompt?: boolean;
357
- model?: string;
358
- thinkingLevel?: string;
359
- // Issue #114: per-unit priority survives retries — the snapshot carries
360
- // it through so a retried run keeps its priority.
361
- priority?: string;
362
- outputFile?: string;
363
- timeout?: number;
364
- cwd?: string;
365
- tools?: string[];
366
- excludeTools?: string[];
367
- noBuiltinTools?: boolean;
368
- preset?: string;
369
- // Issue #227: the execution-shape fields survive retries, so a retried
370
- // background run stays background and a retried branch-mode run keeps its
371
- // work branch, its approvalMode gating and its force override. Additive:
372
- // records written before this change simply lack the keys.
373
- background?: boolean;
374
- gitMode?: string;
375
- approvalMode?: string;
376
- force?: boolean;
438
+ originalParams?: SnapshotParams & {
439
+ /** Issue #179 (D1/D2): classification stamped by the failure paths. */
377
440
  errorCategory?: ErrorCategory;
378
441
  };
379
442
  }
@@ -387,6 +450,13 @@ export interface LiveSubagent {
387
450
  // Issue #114: per-unit priority for the drill-in header (`p:critical` etc.).
388
451
  priority?: string;
389
452
  startedAt: number;
453
+ /**
454
+ * Issue #423: absolute deadline (epoch ms) for this run, when it has a timer.
455
+ * Absent for a foreground run with no explicit timeout (foreground has no
456
+ * default deadline) and for a background run with no persisted budget (an
457
+ * old record). Display only — the kill remains the timer owner's business.
458
+ */
459
+ deadlineAt?: number;
390
460
  liveOutput: string;
391
461
  usage: { input: number; output: number };
392
462
  ctx: ExtensionContext;
@@ -750,6 +820,13 @@ export interface BackgroundAgent {
750
820
  status: AgentStatus;
751
821
  startedAt: number;
752
822
  completedAt?: number;
823
+ /**
824
+ * Issue #423: the EFFECTIVE budget of this background run (explicit timeout,
825
+ * else the 30 m default), persisted at spawn so the result and wake can
826
+ * state it after the closure that armed the timer is gone. Absent on records
827
+ * written before the field existed — read as "no budget known".
828
+ */
829
+ timeoutMs?: number;
753
830
  task: string;
754
831
  model: string;
755
832
  thinkingLevel: ThinkingLevel;
@@ -758,6 +835,13 @@ export interface BackgroundAgent {
758
835
  error?: string;
759
836
  result?: SubagentResult;
760
837
  finalOutput?: string;
838
+ /**
839
+ * Issue #465: the work branch this run's `gitMode=branch` isolation created,
840
+ * stamped when the branch is created so a DURABLE record names it even if the
841
+ * run never settles (a stuck owner never writes `result.gitBranch`, which is
842
+ * settle-only). Serializable on purpose — a refusal's message is built from it.
843
+ */
844
+ workBranch?: string;
761
845
  /** @internal — session reference for live monitor polling */
762
846
  _sessionRef?: import('@earendil-works/pi-coding-agent').AgentSession;
763
847
  /**
@@ -783,10 +867,59 @@ export interface BackgroundAgent {
783
867
  recoveryPosture?: RecoveryMode;
784
868
  }
785
869
 
870
+ /**
871
+ * Issue #439: the part of a spawned background run that is needed to REPORT it,
872
+ * captured as a plain record the instant the spawn returns.
873
+ *
874
+ * Why a separate record rather than the agent itself: everything after the
875
+ * spawn is contained (a fault there must classify the run as STARTED, never as
876
+ * a failed spawn), and a containment whose degraded path still formats from the
877
+ * live agent re-opens the window it exists to close. Callers format from these
878
+ * fields only; `label` is `description` under the name `delegate_task` takes it
879
+ * from the caller, so a fan-out can render its unit label from the same record.
880
+ */
881
+ export interface BackgroundAgentIdentity {
882
+ id: string;
883
+ label?: string;
884
+ description: string;
885
+ task: string;
886
+ status: AgentStatus;
887
+ model: string;
888
+ }
889
+
890
+ /**
891
+ * Issue #439: what the background-spawn tail returns. `agent` is the live
892
+ * record the tail's own poller/deadline close over; `identity` is the plain
893
+ * reporting record (all callers format from it); `tailFailures` is the
894
+ * containments' ledger — empty when the whole tail attached.
895
+ *
896
+ * A non-empty `tailFailures` means exactly one thing: **the run started and its
897
+ * monitoring is degraded**. It is never a spawn failure, so no caller may
898
+ * classify it as an error (the transport retry reads `isError` as "did not
899
+ * start" and would surface a false source failure).
900
+ */
901
+ export interface BackgroundAgentSpawnResult {
902
+ agent: BackgroundAgent;
903
+ identity: BackgroundAgentIdentity;
904
+ tailFailures: string[];
905
+ }
906
+
786
907
  // ---------------------------------------------------------------------------
787
908
  // Helper functions
788
909
  // ---------------------------------------------------------------------------
789
910
 
911
+ /**
912
+ * The approval modes that make a background spawn impossible (W5, issue #28).
913
+ *
914
+ * ONE definition, two consumers — `rejectApprovalAlwaysInBackground`
915
+ * (prelude.ts, the background gates) and `resolveThinkingDispatchSwitch`
916
+ * (params.ts, the dispatch pre-flight that must not switch a dispatch into a
917
+ * rejection — issue #433). A re-spelled `=== "always"` at either site is the
918
+ * drift this helper exists to prevent: widening or narrowing what background
919
+ * can accept must change the pre-flight's verdict in the same edit.
920
+ */
921
+ export const approvalBlocksBackground = (m: ApprovalMode): boolean => m === "always";
922
+
790
923
  export function resolveThinkingLevel(
791
924
  requested: ThinkingLevel | undefined,
792
925
  maxAllowed: ThinkingLevel,
@@ -797,6 +930,26 @@ export function resolveThinkingLevel(
797
930
  return THINKING_LEVELS[Math.min(requestedIdx, maxIdx)];
798
931
  }
799
932
 
933
+ /**
934
+ * Issue #443: the value that actually REACHES resolution — the per-call
935
+ * declaration, else the selected preset's — before any clamping.
936
+ *
937
+ * ONE spelling, three readers: `resolveSubagentParams` merges it, and both
938
+ * dispatch seams guard it (`execute` and `spawnBackgroundRun`, the latter for
939
+ * the transport auto-retry). A guard that computed this differently would
940
+ * judge a value the merge never uses, which is the silent-drift class this
941
+ * helper removes; `resolveThinkingLevel` then clamps what it returns.
942
+ *
943
+ * `undefined` (omitted) and `""` are returned unchanged on purpose — they are
944
+ * existing declarations, not values to judge (see `isThinkingLevel`).
945
+ */
946
+ export function declaredThinkingLevel(
947
+ callLevel: string | undefined,
948
+ presetLevel: string | undefined,
949
+ ): string | undefined {
950
+ return callLevel ?? presetLevel;
951
+ }
952
+
800
953
  export function formatTokens(count: number): string {
801
954
  if (count < 1000) return count.toString();
802
955
  if (count < 10_000) return `${(count / 1000).toFixed(1)}k`;
@@ -929,6 +1082,30 @@ export interface TerminalOutcome {
929
1082
  errorCategory?: ErrorCategory;
930
1083
  }
931
1084
 
1085
+ /**
1086
+ * Issue #449: what the settle site saw in the session's PROJECTED message array.
1087
+ *
1088
+ * `"absent"` means exactly ONE thing: the array was READ and contained no
1089
+ * assistant message. It is supplied only by the background settle site, which
1090
+ * reads the projection the SDK rewrote before settling; a missing or throwing
1091
+ * `messages` getter is `"unknown"` (it never reaches the classifier — the settle
1092
+ * handler's catch-all owns it), and a projection holding an assistant message is
1093
+ * `"present"` whatever that message contains.
1094
+ */
1095
+ export type AssistantEvidence = "present" | "absent" | "unknown";
1096
+
1097
+ /**
1098
+ * Issue #449: the fixed failure headline for a run that settled with no
1099
+ * assistant output. The omitted message cannot be recovered, so this asserts the
1100
+ * OBSERVATION (no output) and only offers truncation as a possibility — it never
1101
+ * claims truncation as fact. Deliberately free of every TRANSPORT_SIGNATURES
1102
+ * substring (transport-retry.ts), so an automatic transport retry cannot fire on
1103
+ * this class; its `incomplete` category is independently excluded by that
1104
+ * predicate's class gate.
1105
+ */
1106
+ export const NO_ASSISTANT_OUTPUT_REASON =
1107
+ "Run settled with no assistant output — the provider's response may have been truncated and omitted by the SDK (see #449)";
1108
+
932
1109
  /**
933
1110
  * Issue #179 (D1): classify a run's terminal outcome from its final assistant
934
1111
  * stopReason. This is the settle-time counterpart to classifyError/isSubagentError
@@ -936,16 +1113,25 @@ export interface TerminalOutcome {
936
1113
  *
937
1114
  * | stopReason | status | errorCategory |
938
1115
  * |--------------------------|-----------|----------------------------|
939
- * | stop / undefined | completed | — |
1116
+ * | stop | completed | — |
1117
+ * | undefined | completed | — |
1118
+ * | undefined + absent (449) | failed | incomplete |
940
1119
  * | aborted | stopped | aborted |
941
1120
  * | error | failed | from classifyError |
942
1121
  * | length | failed | truncated |
943
1122
  * | toolUse/deferred/pending | failed | incomplete |
1123
+ *
1124
+ * Issue #449: `extra.assistantEvidence` defaults to `"unknown"`, so every caller
1125
+ * that does not pass it keeps the pre-#449 result byte for byte. Only an already-
1126
+ * KNOWN terminal outcome (the switch arms above) beats the evidence; the evidence
1127
+ * decides the formerly-default case alone. The omitted message is unrecoverable,
1128
+ * so this is a structural guard: it cannot tell a truncation omission from any
1129
+ * other resolve-with-no-assistant-message.
944
1130
  */
945
1131
  export function classifyTerminalOutcome(
946
1132
  stopReason: string | undefined,
947
1133
  errorMessage?: string,
948
- extra?: { stderr?: string; exitCode?: number },
1134
+ extra?: { stderr?: string; exitCode?: number; assistantEvidence?: AssistantEvidence },
949
1135
  ): TerminalOutcome {
950
1136
  switch (stopReason) {
951
1137
  case "aborted":
@@ -967,6 +1153,14 @@ export function classifyTerminalOutcome(
967
1153
  }),
968
1154
  };
969
1155
  default:
1156
+ // Issue #449: no terminal stopReason at all. A projection READ as an
1157
+ // array holding no assistant message is not a success — the still-open
1158
+ // turn has no answer to show for itself. Only the MISSING reason can be
1159
+ // decided by the evidence: any stopReason the caller observed (including
1160
+ // "stop") is an already-known outcome and keeps its existing result.
1161
+ if (stopReason === undefined && extra?.assistantEvidence === "absent") {
1162
+ return { status: "failed", errorCategory: "incomplete" };
1163
+ }
970
1164
  return { status: "completed" };
971
1165
  }
972
1166
  }
package/src/unit-run.ts CHANGED
@@ -269,13 +269,21 @@ export function pruneHistoryIfNeeded(
269
269
  * `labelOverride` supplies the live entry's label when the caller wants one
270
270
  * that differs from `run.label` (e.g. chain's unlabeled-step fallback).
271
271
  * When omitted the live label defaults to `run.label`.
272
+ *
273
+ * `timeoutMs` is the run's MERGED timeout (param/preset/template) — never the
274
+ * raw caller param (issue #423). It becomes the live entry's absolute
275
+ * `deadlineAt`, anchored on the run's own start clock. Absent or non-positive
276
+ * means "no deadline": a foreground run has no default deadline.
272
277
  */
273
278
  export function registerLiveRun(
274
279
  state: SessionState,
275
280
  run: SubagentRun,
276
281
  ctx: ExtensionContext,
277
282
  labelOverride?: string,
283
+ timeoutMs?: number,
278
284
  ): void {
285
+ const startedAt = new Date(run.startedAt).getTime();
286
+ const deadlineAt = timeoutMs && timeoutMs > 0 ? startedAt + timeoutMs : undefined;
279
287
  state.registerLiveSubagent(run.id, {
280
288
  id: run.id,
281
289
  label: labelOverride ?? run.label,
@@ -283,7 +291,8 @@ export function registerLiveRun(
283
291
  model: run.model,
284
292
  thinkingLevel: run.thinkingLevel,
285
293
  priority: run.priority,
286
- startedAt: new Date(run.startedAt).getTime(),
294
+ startedAt,
295
+ ...(deadlineAt !== undefined ? { deadlineAt } : {}),
287
296
  ctx,
288
297
  });
289
298
  }
package/src/validate.ts CHANGED
@@ -9,6 +9,8 @@
9
9
 
10
10
  import type { ThinkingLevel, SubagentToolOptions } from './types';
11
11
  import { THINKING_LEVELS } from './types';
12
+ import { DISPATCH_LINE_FORM, JEV_UNAVAILABLE, parseDispatchLine } from './dispatch-line';
13
+ import { isProcessChecksEnabled } from './project-flags';
12
14
 
13
15
  // ── Types ────────────────────────────────────────────────────────────
14
16
 
@@ -27,6 +29,28 @@ export interface ValidateConfig {
27
29
  * can never succeed, so force does not apply to it.
28
30
  */
29
31
  force?: boolean;
32
+ /**
33
+ * The project this dispatch runs in (the resolved dispatch cwd). The
34
+ * project-local process checks key on it: no cwd means no project to
35
+ * consult, so unit callers that never resolve one perform no check
36
+ * (issues #412, #415).
37
+ */
38
+ cwd?: string;
39
+ /**
40
+ * delegate_task's `noJev` param — the STATED bypass for the Jev-line check
41
+ * (issue #412, ADR 0018). It downgrades the rejection to a warning that
42
+ * carries the reason, so the bypass is visible in the result, never silent.
43
+ * It bypasses ONLY the line check: every capability conflict still rejects
44
+ * (unlike `force`, which is capability-only).
45
+ *
46
+ * Typed `unknown` on purpose (issue #419, ADR 0020): the schema DECLARES a
47
+ * non-empty string, but the harness validates with `coerce: true` and
48
+ * pi-schema's string rule stringifies booleans/numbers before the handler
49
+ * runs, so the value that arrives is not guaranteed to be the declared type
50
+ * (a direct caller can pass anything at all). `readNoJevReason` is the
51
+ * runtime guard, and it is the ONLY place this value may be read.
52
+ */
53
+ noJev?: unknown;
30
54
  }
31
55
 
32
56
  export interface ValidateResult {
@@ -288,6 +312,55 @@ export function diagnoseFailure(config: DiagnoseConfig): string[] {
288
312
  return suggestions;
289
313
  }
290
314
 
315
+ // ── The noJev bypass reason (issue #419, ADR 0020) ───────────────────
316
+
317
+ /**
318
+ * What the harness's coercion turns a non-string reason INTO: `compile(schema,
319
+ * { coerce: true })` stringifies booleans and numbers, so `noJev: true`
320
+ * reaches the handler as `"true"` — a value that passes `Type.String({
321
+ * minLength: 1 })` and is NOT a stated reason. Matching the coerced text is the
322
+ * only way to tell it apart from a real one at this seam.
323
+ */
324
+ const COERCED_PRIMITIVE_RE = /^(true|false|-?\d+(\.\d+)?)$/i;
325
+
326
+ /** The three outcomes of reading `noJev`: no bypass, a usable reason, or a refusal. */
327
+ type NoJevVerdict =
328
+ | { kind: 'absent' }
329
+ | { kind: 'reason'; reason: string }
330
+ | { kind: 'invalid'; problem: string };
331
+
332
+ /**
333
+ * Reads `noJev` defensively. The schema declares a non-empty string, but that
334
+ * is a DECLARATION, not a runtime guarantee: coercion stringifies primitives
335
+ * (above), and a direct caller can pass any value. So: never `.trim()` a
336
+ * non-string, and treat a coerced primitive (or an empty/whitespace reason) as
337
+ * an INVALID bypass rather than a usable one — a boolean must neither bypass
338
+ * the check nor crash it.
339
+ */
340
+ function readNoJevReason(value: unknown): NoJevVerdict {
341
+ // Omitted, or an optional `null` (pi-schema drops those during coercion):
342
+ // no bypass was stated, so the caller gets the plain missing-line error.
343
+ if (value === undefined || value === null) return { kind: 'absent' };
344
+ if (typeof value !== 'string') {
345
+ const shape = Array.isArray(value) ? 'array' : typeof value;
346
+ return { kind: 'invalid', problem: `expected a non-empty reason string, got ${shape}` };
347
+ }
348
+ const reason = value.trim();
349
+ if (reason === '') {
350
+ return { kind: 'invalid', problem: 'the reason is empty' };
351
+ }
352
+ if (COERCED_PRIMITIVE_RE.test(reason)) {
353
+ const coerced = /^(true|false)$/i.test(reason) ? 'boolean' : 'number';
354
+ return {
355
+ kind: 'invalid',
356
+ problem:
357
+ `\`${reason}\` is a coerced ${coerced}, not a stated reason — the tool-argument validator ` +
358
+ `stringifies booleans and numbers before the handler sees them`,
359
+ };
360
+ }
361
+ return { kind: 'reason', reason };
362
+ }
363
+
291
364
  // ── Main validation ──────────────────────────────────────────────────
292
365
 
293
366
  export function validatePreTask(config: ValidateConfig): ValidateResult {
@@ -304,6 +377,39 @@ export function validatePreTask(config: ValidateConfig): ValidateResult {
304
377
  return { valid: true, warnings: [], errors: [] };
305
378
  }
306
379
 
380
+ // Issue #412 (absorbs #407): the Jev dispatch line, checked BEFORE anything
381
+ // spawns. Opt-in per project via the umbrella `processChecks` flag (#415,
382
+ // ADR 0019): this is our process, not a product requirement, so a user's
383
+ // dispatch is never rejected for a missing line. The flag read is fail-open
384
+ // (`src/project-flags.ts`). `noJev` — a stated reason — downgrades the
385
+ // rejection to a WARNING that names the reason, so the bypass is surfaced
386
+ // rather than silent (ADR 0007's pattern). The reason itself is read through
387
+ // a runtime guard, never off the declared type (issue #419, ADR 0020): a
388
+ // boolean/number arrives here coercion-stringified, and it must be refused
389
+ // as the missing line, not accepted as a bypass.
390
+ if (isProcessChecksEnabled(config.cwd)) {
391
+ const verdict = parseDispatchLine(taskText);
392
+ if (!verdict.ok) {
393
+ const bypass = readNoJevReason(config.noJev);
394
+ if (bypass.kind === 'reason') {
395
+ warnings.push(
396
+ `noJev override: the Jev dispatch line was skipped — ${bypass.reason} (${verdict.reason})`,
397
+ );
398
+ } else {
399
+ if (bypass.kind === 'invalid') {
400
+ errors.push(
401
+ `invalid noJev: ${bypass.problem}. Pass the reason the line was skipped as a non-empty string (e.g. noJev: "classifier unreachable; maintainer approved"), or append the line.`,
402
+ );
403
+ }
404
+ errors.push(
405
+ `missing Jev dispatch line: ${verdict.reason}. ` +
406
+ `Classify with the Jev classifier, format the answer with \`jev-check --line '<json>'\` (it prints the line verbatim), and append it to the task as: ${DISPATCH_LINE_FORM}. ` +
407
+ `When the classifier did not run, append \`${JEV_UNAVAILABLE}\` instead, or pass noJev: "<reason>".`,
408
+ );
409
+ }
410
+ }
411
+ }
412
+
307
413
  // Check tool requirements. A missing capability is warning-class by
308
414
  // default (conductor can judge); the high-confidence capability-critical
309
415
  // cases (blockingPatterns) are promoted to ERRORS unless `force` is set.
@@ -415,3 +521,17 @@ export function normalizeTimeout(timeout: number | undefined): number | undefine
415
521
  if (timeout >= 2 ** 31 - 1) return undefined;
416
522
  return timeout;
417
523
  }
524
+
525
+ /**
526
+ * The EFFECTIVE budget of a BACKGROUND run: the normalized explicit `timeout`,
527
+ * or {@link DEFAULT_BACKGROUND_DEADLINE_MS} when there is none (issue #423).
528
+ *
529
+ * The single definition of "30 m default" for the background path — the W3
530
+ * timer, the persisted record's `timeoutMs` and every display of the budget
531
+ * derive from here, so a displayed deadline cannot drift from the armed timer.
532
+ * Not used by the foreground path: a foreground run has NO default deadline,
533
+ * so an absent timeout there means "no deadline", not 30 m.
534
+ */
535
+ export function effectiveBackgroundBudget(timeout: number | undefined): number {
536
+ return normalizeTimeout(timeout) ?? DEFAULT_BACKGROUND_DEADLINE_MS;
537
+ }