@rasensio/aidlc 2.33.0 → 2.34.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 (54) hide show
  1. package/dist/autopilot/driver.d.ts +32 -14
  2. package/dist/autopilot/driver.d.ts.map +1 -1
  3. package/dist/autopilot/driver.js +123 -27
  4. package/dist/autopilot/driver.js.map +1 -1
  5. package/dist/autopilot/pending.d.ts.map +1 -1
  6. package/dist/autopilot/pending.js +10 -5
  7. package/dist/autopilot/pending.js.map +1 -1
  8. package/dist/autopilot/reopen.d.ts +53 -0
  9. package/dist/autopilot/reopen.d.ts.map +1 -0
  10. package/dist/autopilot/reopen.js +120 -0
  11. package/dist/autopilot/reopen.js.map +1 -0
  12. package/dist/autopilot/state.d.ts +8 -0
  13. package/dist/autopilot/state.d.ts.map +1 -1
  14. package/dist/autopilot/state.js.map +1 -1
  15. package/dist/autopilot/watch.d.ts.map +1 -1
  16. package/dist/autopilot/watch.js +8 -3
  17. package/dist/autopilot/watch.js.map +1 -1
  18. package/dist/commands/amend.d.ts.map +1 -1
  19. package/dist/commands/amend.js +49 -6
  20. package/dist/commands/amend.js.map +1 -1
  21. package/dist/commands/autopilot.d.ts.map +1 -1
  22. package/dist/commands/autopilot.js +15 -5
  23. package/dist/commands/autopilot.js.map +1 -1
  24. package/dist/commands/claim.d.ts +20 -0
  25. package/dist/commands/claim.d.ts.map +1 -1
  26. package/dist/commands/claim.js +31 -17
  27. package/dist/commands/claim.js.map +1 -1
  28. package/dist/compile/adapters/claude-code.d.ts.map +1 -1
  29. package/dist/compile/adapters/claude-code.js +6 -0
  30. package/dist/compile/adapters/claude-code.js.map +1 -1
  31. package/dist/compile/reviewer-guard.d.ts +2 -1
  32. package/dist/compile/reviewer-guard.d.ts.map +1 -1
  33. package/dist/compile/reviewer-guard.js +4 -2
  34. package/dist/compile/reviewer-guard.js.map +1 -1
  35. package/dist/doctor/migrations/index.d.ts.map +1 -1
  36. package/dist/doctor/migrations/index.js +2 -0
  37. package/dist/doctor/migrations/index.js.map +1 -1
  38. package/dist/doctor/migrations/outdated-approval-guard.d.ts +20 -0
  39. package/dist/doctor/migrations/outdated-approval-guard.d.ts.map +1 -0
  40. package/dist/doctor/migrations/outdated-approval-guard.js +39 -0
  41. package/dist/doctor/migrations/outdated-approval-guard.js.map +1 -0
  42. package/dist/hooks/approval-guard.d.ts +5 -2
  43. package/dist/hooks/approval-guard.d.ts.map +1 -1
  44. package/dist/hooks/approval-guard.js +7 -3
  45. package/dist/hooks/approval-guard.js.map +1 -1
  46. package/dist/hooks/install.d.ts +13 -0
  47. package/dist/hooks/install.d.ts.map +1 -1
  48. package/dist/hooks/install.js +60 -4
  49. package/dist/hooks/install.js.map +1 -1
  50. package/dist/hooks/node-runner.d.ts +42 -0
  51. package/dist/hooks/node-runner.d.ts.map +1 -0
  52. package/dist/hooks/node-runner.js +128 -0
  53. package/dist/hooks/node-runner.js.map +1 -0
  54. package/package.json +2 -2
@@ -19,6 +19,7 @@ import { type EffectiveRates } from '../cost/rates.js';
19
19
  import { type Host } from '../core/host.js';
20
20
  import type { Notice } from './notify.js';
21
21
  import type { AutopilotConfig, AutopilotItem, AutopilotPaths, AutopilotState, ItemStep, TypedLaunch } from './state.js';
22
+ import { instancePhase, instanceTemplate, type PhaseOrder, type Reopen } from './reopen.js';
22
23
  import { type PausePhase, type Stops } from './stops.js';
23
24
  export interface RunResult {
24
25
  status: number;
@@ -126,6 +127,11 @@ export interface DriverCtx {
126
127
  * their next one (finished-work-tidies-itself/AC-5, requirements Q1).
127
128
  */
128
129
  retroPush?: boolean;
130
+ /**
131
+ * The phase order of the templates a worktree runs on. Absent: {@link templatePhaseOrder}, the
132
+ * built-ins plus the worktree's `.aidlc/templates/` (switch-never-rebuilds design C2).
133
+ */
134
+ phaseOrder?: (projectRoot: string) => PhaseOrder;
129
135
  }
130
136
  /** How many builds a run may still start, and what to tell it (autopilot-on-demand/AC-7). */
131
137
  export interface Budget {
@@ -211,17 +217,7 @@ export declare function firstOutputLine(text: string): string | null;
211
217
  * would hit it (autopilot-reads-agent-result/AC-26).
212
218
  */
213
219
  export declare function launchBlocked(state: AutopilotState, now: number): string | null;
214
- /**
215
- * The instance's `current_phase` in its worktree, or null when unreadable. Shared with the
216
- * view. Only a phase-shaped name: the agent writes this file, and the phase reaches park
217
- * reasons committed to the roadmap (autopilot-reads-agent-result/AC-29).
218
- */
219
- export declare function instancePhase(read: (path: string) => string | null, item: Pick<AutopilotItem, 'name' | 'worktree'>): string | null;
220
- /**
221
- * The instance's `template` in its worktree, or null when unreadable. The same shape rule as
222
- * {@link instancePhase}: the agent writes this file, so only a template-shaped name is read.
223
- */
224
- export declare function instanceTemplate(read: (path: string) => string | null, item: Pick<AutopilotItem, 'name' | 'worktree'>): string | null;
220
+ export { instancePhase, instanceTemplate };
225
221
  /**
226
222
  * The post files missing for this item, as paths from the project root, `.json` first. Empty
227
223
  * when none is owed: the template is not one that ships a post or cannot be read (design D4),
@@ -281,6 +277,12 @@ export type ApproveOutcome = {
281
277
  ok: true;
282
278
  item: AutopilotItem;
283
279
  phase: PausePhase;
280
+ }
281
+ /** An `awaiting-merge` item whose worktree was reopened: the next pass relaunches its agent. */
282
+ | {
283
+ ok: true;
284
+ item: AutopilotItem;
285
+ reopened: Reopen;
284
286
  } | {
285
287
  ok: false;
286
288
  reason: string;
@@ -294,7 +296,13 @@ export declare function approveItem(state: AutopilotState, name: string, host?:
294
296
  watcher?: {
295
297
  by: string;
296
298
  at: string;
297
- }): ApproveOutcome;
299
+ },
300
+ /**
301
+ * Reads whether an item's worktree was reopened. Handed in, so this stays a function of
302
+ * `state.json` plus what it is given (switch-never-rebuilds design D5); absent, an
303
+ * `awaiting-merge` item is refused as before.
304
+ */
305
+ reopenedOf?: (item: AutopilotItem) => Reopen | null): ApproveOutcome;
298
306
  /** One pass. Returns the new state; the caller saves it (not in a dry run). */
299
307
  export declare function tick(ctx: DriverCtx, state: AutopilotState, budget?: Budget): AutopilotState;
300
308
  /** How often the attended retrospective's runner checks on its agent. */
@@ -316,6 +324,17 @@ export declare function stepsOf(state: AutopilotState): Map<string, ItemStep>;
316
324
  * fourteen places a step is set, means a new handler cannot forget it.
317
325
  */
318
326
  export declare function markStepChanges(state: AutopilotState, before: Map<string, ItemStep>, now: number): void;
327
+ /**
328
+ * Why a reopened item is not waiting for a merge, in words, for `status` and the watch view
329
+ * alike; null when it is not reopened. `reopen` is the worktree's, read for an `awaiting-merge`
330
+ * item (switch-never-rebuilds/AC-5).
331
+ */
332
+ export declare function reopenedNote(i: AutopilotItem, reopen: Reopen | null): string | null;
333
+ /**
334
+ * The worktree's reopen for an `awaiting-merge` item, the one step whose meaning a reopen
335
+ * changes before a pass has seen it; null for every other step, at no read (AC-5, AC-7).
336
+ */
337
+ export declare function awaitingMergeReopen(read: (path: string) => string | null, i: AutopilotItem, order?: (projectRoot: string) => PhaseOrder): Reopen | null;
319
338
  /** The item's pull request check in words, or '' when it has none (pr-checker-earns-merge/AC-8). */
320
339
  export declare function checkNote(i: AutopilotItem): string;
321
340
  /**
@@ -326,6 +345,5 @@ export declare function checkNote(i: AutopilotItem): string;
326
345
  */
327
346
  export declare function driverLine(stopped: boolean, state: AutopilotState, now: number, lastPass?: (iso: string) => string): string;
328
347
  export declare function queueLine(state: AutopilotState): string | null;
329
- export declare function statusLines(ctx: Pick<DriverCtx, 'fs' | 'paths' | 'now'>, state: AutopilotState, host?: Host): string[];
330
- export {};
348
+ export declare function statusLines(ctx: Pick<DriverCtx, 'fs' | 'paths' | 'now' | 'phaseOrder'>, state: AutopilotState, host?: Host): string[];
331
349
  //# sourceMappingURL=driver.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../../src/autopilot/driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAOH,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE/E,OAAO,EAAsB,KAAK,IAAI,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AAE,MAAM,EACX,QAAQ,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAqB,GAC/C,MAAM,CAIR;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,GAAG,IAAI,CAE9D;AAYD,wBAAgB,WAAW,CACzB,GAAG,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,GAAG,OAAO,GAAG,KAAK,GAAG,YAAY,CAAC,EAC3D,KAAK,EAAE,cAAc,EACrB,IAAI,GAAE,IAAe,GACpB,MAAM,EAAE,CAcV"}
@@ -30,6 +30,7 @@ import { recordPath } from '../closeout/gate-criterion.js';
30
30
  import { readOutcome, withOutcome } from '../closeout/outcome.js';
31
31
  import { REASON_MAX, RESET_WAIT_MAX_MS, codexEnd, emptyCodexProgress, firstLine, lastClaudeResult, readClaudeResult, readCodexEvents, refusalSuffix, resetAt, stoppedBy, summaryLines, } from './result.js';
32
32
  import { emptyState, retroMarker, retroSnapshotPath } from './state.js';
33
+ import { instancePhase, instanceTemplate, reopenedText, reopenedTo, templatePhaseOrder, } from './reopen.js';
33
34
  import { RETRO_LIMIT_MS, retroAllowed, retroChanges, retroPrompt } from './retro.js';
34
35
  import { capInForce, tokensLeft } from './cap.js';
35
36
  import { fmtTokens } from '../commands/cost.js';
@@ -588,28 +589,12 @@ function park(ctx, io, state, item, reason, budget) {
588
589
  notice(ctx, 'item parked', `${item.name}: ${reason}`);
589
590
  drop(state, item, budget);
590
591
  }
591
- /**
592
- * The instance's `current_phase` in its worktree, or null when unreadable. Shared with the
593
- * view. Only a phase-shaped name: the agent writes this file, and the phase reaches park
594
- * reasons committed to the roadmap (autopilot-reads-agent-result/AC-29).
595
- */
596
- export function instancePhase(read, item) {
597
- const yaml = read(`${item.worktree}/.aidlc/state/${item.name}/instance.yaml`) ?? '';
598
- // A name of word characters and hyphens ending at a space or the line's end: what `\S+`
599
- // read for every real phase — a trailing comment too — without its escapes.
600
- return /^current_phase:[ \t]*([A-Za-z0-9_-]{1,32})(?=\s|$)/m.exec(yaml)?.[1] ?? null;
601
- }
592
+ // Moved to reopen.ts, which this file imports; re-exported so no importer changes
593
+ // (switch-never-rebuilds design C1).
594
+ export { instancePhase, instanceTemplate };
602
595
  function currentPhase(ctx, item) {
603
596
  return instancePhase(ctx.fs.read, item);
604
597
  }
605
- /**
606
- * The instance's `template` in its worktree, or null when unreadable. The same shape rule as
607
- * {@link instancePhase}: the agent writes this file, so only a template-shaped name is read.
608
- */
609
- export function instanceTemplate(read, item) {
610
- const yaml = read(`${item.worktree}/.aidlc/state/${item.name}/instance.yaml`) ?? '';
611
- return /^template:[ \t]*([A-Za-z0-9_-]{1,64})(?=\s|$)/m.exec(yaml)?.[1] ?? null;
612
- }
613
598
  /**
614
599
  * The post files missing for this item, as paths from the project root, `.json` first. Empty
615
600
  * when none is owed: the template is not one that ships a post or cannot be read (design D4),
@@ -1259,19 +1244,42 @@ function advanceApproved(ctx, io, state, item, budget) {
1259
1244
  if (awaitIfPaused(ctx, item) === 'wait')
1260
1245
  return;
1261
1246
  if (currentPhase(ctx, item) === 'deployment') {
1247
+ // The phase moved on again: whatever reopened it is behind it.
1248
+ delete item.reopened;
1262
1249
  item.step = 'building';
1263
1250
  openPullRequest(ctx, io, state, item, budget);
1264
1251
  return;
1265
1252
  }
1253
+ const reopen = item.reopened;
1254
+ // A reopened item says why it is not relaunched yet, once, instead of sitting silent
1255
+ // where it used to wait for a merge (switch-never-rebuilds/AC-2).
1256
+ const waits = (why) => {
1257
+ if (reopen === undefined)
1258
+ return;
1259
+ const text = `${reopenedText(reopen)} — the relaunch waits for ${why}`;
1260
+ if (item.last_event?.text !== text)
1261
+ tell(ctx, item, text);
1262
+ };
1266
1263
  // A relaunch is a build like any other: it waits for a slot, ahead of new items,
1267
1264
  // since this pass serves it before `startBuilds` runs.
1268
- if (building(state) >= buildSlots(ctx))
1265
+ if (building(state) >= buildSlots(ctx)) {
1266
+ waits('a free build slot');
1269
1267
  return;
1268
+ }
1270
1269
  // And for the session limit, still `approved` (autopilot-reads-agent-result/AC-26).
1271
- if (launchBlocked(state, ctx.now()) !== null)
1270
+ const limit = launchBlocked(state, ctx.now());
1271
+ if (limit !== null) {
1272
+ waits(`the session limit to reset at ${limit}`);
1272
1273
  return;
1274
+ }
1273
1275
  item.step = 'building';
1274
- tell(ctx, item, 'approved — relaunching the agent to carry on');
1276
+ if (reopen !== undefined) {
1277
+ delete item.reopened;
1278
+ tell(ctx, item, `${reopenedText(reopen)} — relaunching the agent`);
1279
+ }
1280
+ else {
1281
+ tell(ctx, item, 'approved — relaunching the agent to carry on');
1282
+ }
1275
1283
  // The run's budget: a park for the cap here must reach `run.finished`, or `--items n` never ends.
1276
1284
  // A fresh agent for the phase the instance is at (phase-agents-on-tier-models/AC-10).
1277
1285
  launchPhase(ctx, io, state, item, budget, { release: true });
@@ -1866,11 +1874,45 @@ function failRetro(ctx, io, state, item, snap, why, budget, known) {
1866
1874
  notice(ctx, 'retrospective failed', `${item.name}: ${why}`);
1867
1875
  finishRetro(ctx, state, item, budget);
1868
1876
  }
1869
- /** Waiting for a person to merge: only their answer moves it (autopilot-stop-controls/AC-19). */
1877
+ /**
1878
+ * Waiting for a person to merge: their answer moves it (autopilot-stop-controls/AC-19), and
1879
+ * so does their reopening a phase before deployment, which sends it back to its agent
1880
+ * (switch-never-rebuilds/AC-1).
1881
+ */
1870
1882
  function advanceAwaitingMerge(ctx, io, state, item, budget) {
1871
1883
  const view = prView(ctx, io, item);
1884
+ if (answeredByPerson(ctx, io, state, item, view, budget))
1885
+ return;
1872
1886
  // Silent otherwise: a "still waiting" line would repeat every pass.
1873
- answeredByPerson(ctx, io, state, item, view, budget);
1887
+ rebuildIfReopened(ctx, io, state, item, view, budget);
1888
+ }
1889
+ /**
1890
+ * The item's reopen, read from its worktree with the templates of its branch; null is "not
1891
+ * reopened", and every unreadable thing is null (switch-never-rebuilds/AC-7, design D4).
1892
+ */
1893
+ function reopened(ctx, item) {
1894
+ return reopenedTo(ctx.fs.read, item, (ctx.phaseOrder ?? templatePhaseOrder)(item.worktree));
1895
+ }
1896
+ /**
1897
+ * Send a reopened item with an open pull request back to its agent, and say whether it was.
1898
+ * Only a pull request read as open: one that cannot be read is not known to be neither merged
1899
+ * nor closed, so it waits a pass (switch-never-rebuilds/AC-1, design D2).
1900
+ */
1901
+ function rebuildIfReopened(ctx, io, state, item, view, budget) {
1902
+ if (view?.state !== 'OPEN')
1903
+ return false;
1904
+ const r = reopened(ctx, item);
1905
+ if (r === null)
1906
+ return false;
1907
+ // The old head's verdict is not the new head's, and it must not merge meanwhile (AC-1).
1908
+ delete item.check;
1909
+ dequeue(state, item);
1910
+ item.reopened = r;
1911
+ // `approved` already means "a fresh agent for the current phase at the next free slot",
1912
+ // and holds no slot while it waits (design D1, AC-2).
1913
+ item.step = 'approved';
1914
+ advanceApproved(ctx, io, state, item, budget);
1915
+ return true;
1874
1916
  }
1875
1917
  /**
1876
1918
  * The branch conflicts with main: hand it back to the agent, twice at most,
@@ -2180,6 +2222,15 @@ function advanceChecking(ctx, io, state, item, budget) {
2180
2222
  park(ctx, io, state, item, cap === undefined ? `budget reached — spent ${microToUsd(spent)}` : capReached(cap, spent), budget);
2181
2223
  return;
2182
2224
  }
2225
+ // Reopened while it ran: the checker was left to end, and its verdict is neither recorded,
2226
+ // posted nor acted on. Back at `pr-open`, the next pass relaunches it there, the one place
2227
+ // that holds the open-pull-request condition (switch-never-rebuilds/AC-3, design D3).
2228
+ const reopen = reopened(ctx, item);
2229
+ if (reopen !== null) {
2230
+ delete item.check;
2231
+ tell(ctx, item, `${reopenedText(reopen)} — check ${check.n}'s verdict is discarded`);
2232
+ return;
2233
+ }
2183
2234
  if (end === null) {
2184
2235
  check.blocked = launchFailure(ctx, item)?.replace(/^agent/, 'checker') ?? 'the checker ended with no readable result';
2185
2236
  return;
@@ -2336,6 +2387,10 @@ function advancePr(ctx, io, state, item, budget) {
2336
2387
  // A person merging before CI finishes is still the merge the stop asked for.
2337
2388
  if (atPr ? answeredByPerson(ctx, io, state, item, view, budget) : droppedIfMerged(ctx, state, item, view, budget))
2338
2389
  return;
2390
+ // Before CI is read: with the check discarded, a green run would launch a fresh checker on
2391
+ // the head the person rejected (switch-never-rebuilds/AC-1, design C2).
2392
+ if (rebuildIfReopened(ctx, io, state, item, view, budget))
2393
+ return;
2339
2394
  const host = hostOf(ctx);
2340
2395
  const read = readChecks(ctx, io, item, host, view);
2341
2396
  if (read === null)
@@ -2885,12 +2940,27 @@ export function forgetItem(state, name) {
2885
2940
  */
2886
2941
  export function approveItem(state, name, host = 'github',
2887
2942
  /** Who approved in the watching session, and when; absent for an approval at a terminal. */
2888
- watcher) {
2943
+ watcher,
2944
+ /**
2945
+ * Reads whether an item's worktree was reopened. Handed in, so this stays a function of
2946
+ * `state.json` plus what it is given (switch-never-rebuilds design D5); absent, an
2947
+ * `awaiting-merge` item is refused as before.
2948
+ */
2949
+ reopenedOf) {
2889
2950
  const item = state.items.find((i) => i.name === name);
2890
2951
  if (item === undefined) {
2891
2952
  return { ok: false, reason: `autopilot is not tracking "${name}" — \`aidlc autopilot status\` lists what it tracks` };
2892
2953
  }
2893
2954
  if (item.step === 'awaiting-merge') {
2955
+ // Reopened before deployment: what the pass would do on its own, now (switch-never-rebuilds/AC-6).
2956
+ const reopen = reopenedOf?.(item) ?? null;
2957
+ if (reopen !== null) {
2958
+ delete item.check;
2959
+ dequeue(state, item);
2960
+ item.reopened = reopen;
2961
+ item.step = 'approved';
2962
+ return { ok: true, item, reopened: reopen };
2963
+ }
2894
2964
  return { ok: false, reason: `${name} is waiting for you to merge ${ref(host, item.pr)} — merging it is the approval` };
2895
2965
  }
2896
2966
  if (item.step !== 'awaiting-review' || item.review === undefined) {
@@ -2991,8 +3061,33 @@ export function markStepChanges(state, before, now) {
2991
3061
  item.step_since = { step: item.step, at };
2992
3062
  }
2993
3063
  }
3064
+ /**
3065
+ * Why a reopened item is not waiting for a merge, in words, for `status` and the watch view
3066
+ * alike; null when it is not reopened. `reopen` is the worktree's, read for an `awaiting-merge`
3067
+ * item (switch-never-rebuilds/AC-5).
3068
+ */
3069
+ export function reopenedNote(i, reopen) {
3070
+ if (i.step === 'awaiting-merge' && reopen !== null) {
3071
+ return `${reopenedText(reopen)}; autopilot relaunches its agent at its next pass`;
3072
+ }
3073
+ if (i.step === 'approved' && i.reopened !== undefined) {
3074
+ return `${reopenedText(i.reopened)}; autopilot relaunches its agent at the next pass with a free build slot`;
3075
+ }
3076
+ return null;
3077
+ }
3078
+ /**
3079
+ * The worktree's reopen for an `awaiting-merge` item, the one step whose meaning a reopen
3080
+ * changes before a pass has seen it; null for every other step, at no read (AC-5, AC-7).
3081
+ */
3082
+ export function awaitingMergeReopen(read, i, order = templatePhaseOrder) {
3083
+ return i.step === 'awaiting-merge' ? reopenedTo(read, i, order(i.worktree)) : null;
3084
+ }
2994
3085
  /** What a person is being waited on for, in words (autopilot-stop-controls/AC-14, AC-20). */
2995
- function waitingFor(i, host) {
3086
+ function waitingFor(i, host, reopen) {
3087
+ // Never "waiting for you to merge" an item the person reopened (switch-never-rebuilds/AC-5).
3088
+ const reopenedNow = reopenedNote(i, reopen);
3089
+ if (reopenedNow !== null)
3090
+ return ` — ${reopenedNow}`;
2996
3091
  if (i.step === 'awaiting-review') {
2997
3092
  return ` — waiting for your review after ${i.review ?? 'a phase'} in ${i.worktree}; approve with \`aidlc autopilot approve ${i.name}\``;
2998
3093
  }
@@ -3050,8 +3145,9 @@ export function statusLines(ctx, state, host = 'github') {
3050
3145
  if (state.items.length === 0)
3051
3146
  lines.push('no items in flight');
3052
3147
  for (const i of state.items) {
3148
+ const reopen = awaitingMergeReopen(ctx.fs.read, i, ctx.phaseOrder);
3053
3149
  lines.push(`${i.name}: ${i.step}${i.pr ? ` PR #${i.pr}` : ''} — CI failures ${i.ci_failures ?? 0}` +
3054
- `${checkNote(i)}${waitingFor(i, host)}${i.error ? ` — last error: ${i.error}` : ''}`);
3150
+ `${checkNote(i)}${waitingFor(i, host, reopen)}${i.error ? ` — last error: ${i.error}` : ''}`);
3055
3151
  lines.push(...decisionCards(ctx, i));
3056
3152
  }
3057
3153
  const queue = queueLine(state);