fwdloop 0.8.1 → 0.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/src/panel/data.js CHANGED
@@ -32,7 +32,9 @@ import {
32
32
  } from '../books.js';
33
33
  import { readAsk, readRunState, readLog } from '../runner.js';
34
34
  import { readSpendRows } from '../provider.js';
35
- import { readAskEvidence, listArchivedAsks } from '../ask.js';
35
+ import {
36
+ readAskEvidence, listArchivedAsks, normalizeDecision, DECISION_STATUS,
37
+ } from '../ask.js';
36
38
 
37
39
  /** `{ ok:false, red }` result shape every exported function here can return
38
40
  * instead of throwing — the server maps this to a 4xx, never a crash.
@@ -99,23 +101,87 @@ function resolveRunPath(root, flowName, runId) {
99
101
  }
100
102
 
101
103
  /**
102
- * A consumed-answer marker exists for this run — `answerAsk`'s own write
104
+ * A consumed-answer marker exists for THIS ask (`askId`) — `answerAsk`'s own write
103
105
  * (`src/ask.js`) renames to `answer.<askId>.consumed.json` on accept, and
104
106
  * `resumeRun` (`src/runner.js`) does the same when it consumes an in-place
105
107
  * `answer.json`. A directory-naming-convention check, not a "book" with its
106
108
  * own single-row shape, so it lives here rather than growing a one-off
107
- * reader in either writer's module.
109
+ * reader in either writer's module. Per the signed rule (ladder M4a scope
110
+ * item 4) it is per the OPEN ask's askId: after redo -> re-park the old
111
+ * ask's marker stays on disk and must not answer the new ask. An ask with no
112
+ * askId (pre-M3) can be paired with no marker: false.
108
113
  * @param {string} runDir
114
+ * @param {string|null} askId the open ask's own askId
109
115
  * @returns {boolean}
110
116
  */
111
- function hasConsumedAnswer(runDir) {
112
- if (!existsSync(runDir)) return false;
117
+ function hasConsumedAnswer(runDir, askId) {
118
+ if (!existsSync(runDir) || typeof askId !== 'string' || askId.length === 0) return false;
113
119
  // F48 round 3: `readdirInside` (`src/flow.js`) skips a symlinked entry
114
120
  // rather than reporting its name — a run dir cannot be made to show a
115
121
  // consumed answer that isn't really there by planting a symlink named to
116
122
  // match the pattern.
117
123
  const names = readdirInside(runDir, '.');
118
- return names.some((n) => /^answer\..*\.consumed\.json$/.test(n));
124
+ return names.includes(`answer.${askId}.consumed.json`);
125
+ }
126
+
127
+ /**
128
+ * M4b piece 2: a SAVED, not-yet-consumed answer — `answer.json` (what
129
+ * `answerAsk` writes; the resume consumes it by renaming it away, F44). Read
130
+ * through `readFileInside` (a symlinked file is "none"). `null` when there is
131
+ * none or it is unreadable/unparseable or names no askId.
132
+ * @param {string} runDir
133
+ * @returns {{askId: string, decision: string|null}|null}
134
+ */
135
+ export function readSavedAnswer(runDir) {
136
+ const r = readFileInside(runDir, 'answer.json');
137
+ if (!r.ok) return null;
138
+ try {
139
+ const a = JSON.parse(r.text);
140
+ if (a && typeof a.askId === 'string' && a.askId.length > 0) {
141
+ return { askId: a.askId, decision: typeof a.decision === 'string' ? normalizeDecision(a.decision) : null };
142
+ }
143
+ } catch { /* unparseable: not a usable answer */ }
144
+ return null;
145
+ }
146
+
147
+ /** What the `resume` field says when the panel has no attempt record for a run
148
+ * (it restarted since the answer was saved) — said so, never blank. */
149
+ export const RESUME_REASON_UNKNOWN = 'reason unknown: the panel restarted, so it has no record of the resume attempt';
150
+
151
+ /**
152
+ * M4b amendment 1 scope 2: the ONE derivation of "answer saved, resume not
153
+ * started". From the books: an answer saved (`answer.json` present) and so
154
+ * unconsumed. From the panel's in-memory attempt record (`attempt`, may be
155
+ * null): whether a resume is still being started, and the resume's own refusal.
156
+ * `null` when there is nothing to say (no saved answer and no attempt).
157
+ * @param {{savedAnswer: {askId:string, decision:string|null}|null, attempt: any}} ctx
158
+ * @returns {{state: 'starting'|'not-started'|'took-over', askId: string|null, tries: number|null, maxTries: number|null, reason: string|null, label: string}|null}
159
+ */
160
+ export function deriveResumeState({ savedAnswer, attempt }) {
161
+ const tries = attempt ? attempt.tries : null;
162
+ const maxTries = attempt ? attempt.maxTries : null;
163
+ if (savedAnswer) {
164
+ if (attempt && attempt.state === 'in-flight' && attempt.askId === savedAnswer.askId) {
165
+ return {
166
+ state: 'starting', askId: savedAnswer.askId, tries, maxTries, reason: null, label: 'answer saved, resume starting',
167
+ };
168
+ }
169
+ const mine = attempt && attempt.askId === savedAnswer.askId;
170
+ return {
171
+ state: 'not-started',
172
+ askId: savedAnswer.askId,
173
+ tries: mine ? tries : null,
174
+ maxTries: mine ? maxTries : null,
175
+ reason: mine && typeof attempt.refusal === 'string' && attempt.refusal.length > 0 ? attempt.refusal : RESUME_REASON_UNKNOWN,
176
+ label: 'answer saved, resume not started',
177
+ };
178
+ }
179
+ if (attempt) {
180
+ return {
181
+ state: 'took-over', askId: attempt.askId, tries, maxTries, reason: null, label: 'resume took over the answer',
182
+ };
183
+ }
184
+ return null;
119
185
  }
120
186
 
121
187
  /**
@@ -143,16 +209,24 @@ function hasConsumedAnswer(runDir) {
143
209
  * `resume.lock` carries no pid and nothing checks liveness (M4a's own
144
210
  * open POC question), so a crashed resumer and a live one look the same
145
211
  * on disk. Never guessed into `[✗]` or `[✓]`.
146
- * @param {{historyRow: any, askJson: any, consumedAnswerExists: boolean, hasStateJson: boolean}} ctx
212
+ * - `[·]` answer saved, resume not started / starting (M4b amendment 1) —
213
+ * `answer.json` still on disk (`resume` = `deriveResumeState`): never
214
+ * "waiting on you" (the human already answered) and never a success.
215
+ * @param {{historyRow: any, askJson: any, consumedAnswerExists: boolean, hasStateJson: boolean, resume?: any}} ctx
147
216
  * @returns {{glyph: '[✓]'|'[✗]'|'[·]'|'[!]'|'[?]', label: string}}
148
217
  */
149
218
  export function computeGlyph({
150
- historyRow, askJson, consumedAnswerExists, hasStateJson,
219
+ historyRow, askJson, consumedAnswerExists, hasStateJson, resume,
151
220
  }) {
152
221
  if (historyRow) {
153
222
  if (historyRow.outcome === 'complete') return { glyph: '[✓]', label: 'passed' };
223
+ // M4b amendment 3: a run the human ended on purpose with rerun is not a failure.
224
+ if (historyRow.outcome === 'rerun') return { glyph: '[✗]', label: 'stopped by you (rerun), a fresh run was started' };
154
225
  return { glyph: '[✗]', label: `failed (${historyRow.outcome ?? 'unknown outcome'})` };
155
226
  }
227
+ if (askJson && resume && (resume.state === 'starting' || resume.state === 'not-started')) {
228
+ return { glyph: '[·]', label: resume.label };
229
+ }
156
230
  // No history row. A park never writes one, and a consumed answer file
157
231
  // stays on disk until resume writes its own history row — "no history
158
232
  // row" alone never means died.
@@ -247,7 +321,7 @@ export function deriveRunModel(auditRows) {
247
321
  * place that ever passes a third argument (`unjudgedCount`) into
248
322
  * `recordAudit`, so `Object.prototype.hasOwnProperty.call(row,
249
323
  * 'unjudgedCount')` is true for exactly that step's own rows (paused,
250
- * and the human's own accept/reject/rerun/refused answers) and false for
324
+ * and the human's own accept/redo/rerun/refused answers) and false for
251
325
  * every other row shape in the book — a real, always-present marker
252
326
  * (`unjudgedCount` is a number, 0 included, never omitted on an ask row),
253
327
  * never the step's close class (a NON-ask hitl step, e.g. a plain write
@@ -380,8 +454,8 @@ export function deriveAuditAtWhy(row) {
380
454
  * ONE server-side function naming exactly which verdicts count as "did not
381
455
  * pass", derived strictly from a row's own `verdict` string (never a second,
382
456
  * client-side guess). Blocked: `not-done`, `red` (a mechanical close miss OR
383
- * a human's own reject on a hitl step — both are "this attempt did not
384
- * pass"), `refused` (a blank reject/rerun reason), `ask-timeout` and
457
+ * a human's own redo on a hitl step — both are "this attempt did not
458
+ * pass"), `refused` (a blank redo/rerun reason), `ask-timeout` and
385
459
  * `ask-expired` (the human never answered in time), `cap-halt`,
386
460
  * `provider-red`, `pricing-red`, `close-casualty` (every other halt shape
387
461
  * `src/runner.js` records). NOT blocked: `green`/`hitl` (passed), `paused`
@@ -402,7 +476,7 @@ export function isBlockedVerdict(verdict) {
402
476
  * audit row — a `hitl`-classed ask step's `paused` row and its own
403
477
  * resolution row are the SAME try, the same pairing `computeTryCount`
404
478
  * already applies) for the Audit tab's grouped-by-step header. `✓` passed
405
- * (`green`/`hitl`), `✗` failed/rejected/blocked (everything
479
+ * (`green`/`hitl`), `✗` failed/redone/blocked (everything
406
480
  * `isBlockedVerdict` names, plus any other non-passing verdict), `·` still
407
481
  * open (`paused`/`refused`/`ask-timeout`/`ask-expired` — waiting, not yet
408
482
  * resolved either way). A `refused` (blank-reason) row is its own re-ask,
@@ -413,7 +487,7 @@ export function isBlockedVerdict(verdict) {
413
487
  * @returns {'✓'|'✗'|'·'}
414
488
  */
415
489
  function markForVerdict(verdict, closeClass) {
416
- if (closeClass === 'hitl' && verdict === 'red') return '✗'; // the human's own reject
490
+ if (closeClass === 'hitl' && verdict === 'red') return '✗'; // the human's own redo
417
491
  if (verdict === 'green' || verdict === 'hitl') return '✓';
418
492
  if (verdict === 'paused' || verdict === 'refused' || verdict === 'ask-timeout' || verdict === 'ask-expired') return '·';
419
493
  return '✗';
@@ -609,9 +683,10 @@ export function summarizeSpendRows(spendRows) {
609
683
  * @param {string} flowName
610
684
  * @param {string} runId
611
685
  * @param {any} catalogue
686
+ * @param {any} [attempt] the panel's in-memory resume-attempt record for this run, or null
612
687
  * @returns {any}
613
688
  */
614
- function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue) {
689
+ function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue, attempt = null) {
615
690
  const flowRead = readFlow({ root, name: flowName, catalogue });
616
691
  const historyRows = readHistory(flowDir);
617
692
  const historyRow = historyRows.find((r) => r && r.runId === runId) ?? null;
@@ -620,7 +695,9 @@ function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue) {
620
695
  const logJson = readLog(runDir);
621
696
  const askJson = readAsk(runDir);
622
697
  const stateJson = readRunState(runDir);
623
- const consumedAnswerExists = hasConsumedAnswer(runDir);
698
+ const consumedAnswerExists = hasConsumedAnswer(runDir, askJson && typeof askJson.askId === 'string' ? askJson.askId : null);
699
+ // A finished run has no resume to report (its history row says how it ended).
700
+ const resume = historyRow ? null : deriveResumeState({ savedAnswer: readSavedAnswer(runDir), attempt });
624
701
 
625
702
  return {
626
703
  flowName,
@@ -636,6 +713,7 @@ function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue) {
636
713
  stateJson,
637
714
  consumedAnswerExists,
638
715
  hasStateJson: stateJson !== null,
716
+ resume,
639
717
  };
640
718
  }
641
719
 
@@ -646,10 +724,11 @@ function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue) {
646
724
  * Newest-first by history `at` where known; a row with no history row (died
647
725
  * or still parked) sorts after every row that has one, in flow/run order
648
726
  * (a real ordering, never `Date.now()` guessed in for a missing `at`).
649
- * @param {{root: string, catalogue: any}} opts
727
+ * @param {{root: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any}} opts
728
+ * `resumeAttempt`: the panel's in-memory resume-attempt lookup (M4b piece 2); absent = none.
650
729
  * @returns {any[]}
651
730
  */
652
- export function listRuns({ root, catalogue }) {
731
+ export function listRuns({ root, catalogue, resumeAttempt }) {
653
732
  const rows = [];
654
733
  for (const flowName of listFlowNames(root)) {
655
734
  const flowDir = join(root, flowName);
@@ -669,7 +748,7 @@ export function listRuns({ root, catalogue }) {
669
748
  });
670
749
  continue;
671
750
  }
672
- const ctx = loadRunContext(root, run.flowDir, run.runDir, flowName, runId, catalogue);
751
+ const ctx = loadRunContext(root, run.flowDir, run.runDir, flowName, runId, catalogue, resumeAttempt?.(flowName, runId) ?? null);
673
752
  const { glyph, label } = computeGlyph(ctx);
674
753
  let spend;
675
754
  if (ctx.historyRow) {
@@ -692,6 +771,7 @@ export function listRuns({ root, catalogue }) {
692
771
  runId,
693
772
  glyph,
694
773
  label,
774
+ resume: ctx.resume,
695
775
  spend,
696
776
  spendWhy: (!ctx.historyRow && spend === null) ? 'no history row yet and no priced spend.jsonl rows — nothing to floor' : null,
697
777
  at: ctx.historyRow ? ctx.historyRow.at : null,
@@ -770,17 +850,17 @@ function computeTryCount(closeClass, list) {
770
850
  * `log.json`. `null` when the flow/runId doesn't resolve to a real run
771
851
  * directory at all (caller renders 404); a `red` field names why a
772
852
  * sub-derivation couldn't fill (never invented).
773
- * @param {{root: string, flow: string, runId: string, catalogue: any}} opts
853
+ * @param {{root: string, flow: string, runId: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any}} opts
774
854
  * @returns {any|null}
775
855
  */
776
856
  export function getRunDetail({
777
- root, flow, runId, catalogue,
857
+ root, flow, runId, catalogue, resumeAttempt,
778
858
  }) {
779
859
  const run = resolveRunPath(root, flow, runId);
780
860
  if (!run.ok) return null;
781
861
  if (!existsSync(run.runDir)) return null;
782
862
 
783
- const ctx = loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue);
863
+ const ctx = loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue, resumeAttempt?.(flow, runId) ?? null);
784
864
  const { glyph, label } = computeGlyph(ctx);
785
865
 
786
866
  // hamr's 2026-09-27 step-card review: the Run tab's step cards reuse the
@@ -911,6 +991,13 @@ export function getRunDetail({
911
991
  let stopReasonWhy = null;
912
992
  if (ctx.historyRow && ctx.historyRow.outcome === 'complete') {
913
993
  stopReasonWhy = 'run completed clean — there is no stop reason to show';
994
+ } else if (ctx.historyRow && ctx.historyRow.outcome === 'rerun') {
995
+ // M4b amendment 3: the human ended this run on purpose; an earlier redo's
996
+ // audit row is not "why it stopped".
997
+ stopReasonWhy = 'stopped by you (rerun), a fresh run was started — there is no failure to show';
998
+ } else if (ctx.resume && (ctx.resume.state === 'starting' || ctx.resume.state === 'not-started')) {
999
+ // M4b amendment 1: the human already answered — never "waiting on you".
1000
+ stopReasonWhy = ctx.resume.reason ? `${ctx.resume.label}: ${ctx.resume.reason}` : ctx.resume.label;
914
1001
  } else if (!ctx.historyRow && ctx.askJson && !ctx.consumedAnswerExists) {
915
1002
  stopReasonWhy = `waiting on you: ${typeof ctx.askJson.question === 'string' && ctx.askJson.question.length > 0 ? ctx.askJson.question : 'no question recorded'}`;
916
1003
  } else if (ctx.logJson && typeof ctx.logJson.red === 'string' && ctx.logJson.red.length > 0) {
@@ -982,6 +1069,7 @@ export function getRunDetail({
982
1069
  runId,
983
1070
  glyph,
984
1071
  label,
1072
+ resume: ctx.resume,
985
1073
  outcome: ctx.historyRow ? ctx.historyRow.outcome : null,
986
1074
  outcomeWhy: ctx.historyRow ? null : 'no history row (parked or died before completion)',
987
1075
  capUsd: ctx.historyRow ? ctx.historyRow.capUsd : (ctx.flowRead.ok ? ctx.flowRead.arbiter.capUsd : null),
@@ -1201,7 +1289,7 @@ export function getRunJob({
1201
1289
  // ad-hoc reconstruction. Status vocabulary, used everywhere in the panel
1202
1290
  // (Inbox list, Ask tab, both API responses), is exactly the words
1203
1291
  // `listArchivedAsks` itself already returns from the books' own decision
1204
- // field: `accepted` / `rejected` / `reran` / `expired` / `unanswered` (a
1292
+ // field: `accepted` / `redo` / `reran` / `expired` / `unanswered` (a
1205
1293
  // parked, not-yet-expired ask with no consumed answer — this IS "open" in
1206
1294
  // the UI) / `open` (the rare case `listArchivedAsks` falls back to when an
1207
1295
  // archived ask.json itself fails to parse — no question/evidence can be
@@ -1214,7 +1302,7 @@ export function getRunJob({
1214
1302
  * its book-derived status is `unanswered` (parked, not yet answered, not
1215
1303
  * expired — `listArchivedAsks` already applies the expiry check at read
1216
1304
  * time) or the rare unparseable-archive fallback `open`. Every other status
1217
- * (`accepted`/`rejected`/`reran`/`expired`, or an `unrecognised: X` decision
1305
+ * (`accepted`/`redo`/`reran`/`expired`, or an `unrecognised: X` decision
1218
1306
  * value) is a PAST stop.
1219
1307
  * @param {string} status
1220
1308
  * @returns {boolean}
@@ -1241,12 +1329,24 @@ function isOpenStatus(status) {
1241
1329
  * can't be parsed (never a guessed number).
1242
1330
  * @param {any} ask one row from `runAsksInOrder`
1243
1331
  * @param {boolean} hasHistoryRow
1244
- * @returns {{open: boolean, timeLeftMs: number|null}}
1332
+ * @param {any} [resume] the run's `deriveResumeState` result, or null
1333
+ * @returns {{open: boolean, waiting: boolean, resume: any, timeLeftMs: number|null}}
1245
1334
  */
1246
- function deriveAskOpenFields(ask, hasHistoryRow) {
1335
+ function deriveAskOpenFields(ask, hasHistoryRow, resume = null) {
1247
1336
  const open = isOpenStatus(ask.status) && !hasHistoryRow;
1248
- const expiresMs = open && typeof ask.expiresAt === 'string' ? Date.parse(ask.expiresAt) : NaN;
1249
- return { open, timeLeftMs: open && Number.isFinite(expiresMs) ? Math.max(0, expiresMs - Date.now()) : null };
1337
+ // M4b fix: the ONE decision "is this ask waiting on the human". An open ask
1338
+ // whose answer is already saved (`resume` = `deriveResumeState` for THIS
1339
+ // ask, the run's own label) is open but not waiting: the human answered.
1340
+ const answered = open && resume != null && resume.askId === ask.askId
1341
+ && (resume.state === 'starting' || resume.state === 'not-started');
1342
+ const waiting = open && !answered;
1343
+ const expiresMs = waiting && typeof ask.expiresAt === 'string' ? Date.parse(ask.expiresAt) : NaN;
1344
+ return {
1345
+ open,
1346
+ waiting,
1347
+ resume: answered ? resume : null,
1348
+ timeLeftMs: waiting && Number.isFinite(expiresMs) ? Math.max(0, expiresMs - Date.now()) : null,
1349
+ };
1250
1350
  }
1251
1351
 
1252
1352
  /**
@@ -1328,7 +1428,6 @@ function legacyRunAsks(runDir, hasHistoryRow) {
1328
1428
  const currentAskId = askJson && typeof askJson.askId === 'string' ? askJson.askId : null;
1329
1429
 
1330
1430
  const consumedFiles = names.filter((n) => CONSUMED_ANSWER_RE.test(n)).sort();
1331
- const decisionToStatus = { accept: 'accepted', reject: 'rejected', rerun: 'reran' };
1332
1431
 
1333
1432
  for (const file of consumedFiles) {
1334
1433
  const match = CONSUMED_ANSWER_RE.exec(file);
@@ -1356,7 +1455,7 @@ function legacyRunAsks(runDir, hasHistoryRow) {
1356
1455
  questionWhy: 'question not kept (before M4a-1)',
1357
1456
  askedAt: null,
1358
1457
  expiresAt: null,
1359
- status: decisionToStatus[parsed.decision] ?? `unrecognised: ${parsed.decision}`,
1458
+ status: DECISION_STATUS[normalizeDecision(parsed.decision)] ?? `unrecognised: ${parsed.decision}`,
1360
1459
  reason: typeof parsed.reason === 'string' ? parsed.reason : null,
1361
1460
  answeredAt: typeof parsed.answeredAt === 'string' ? parsed.answeredAt : null,
1362
1461
  archived: false,
@@ -1496,11 +1595,14 @@ export function deriveAskStepInfo(orderedAsks, auditRows, declSteps) {
1496
1595
  * 3" — a plain array position, not derived from any book) and `stepName`/
1497
1596
  * `stepLine`/`stepWhy` (`deriveAskStepInfo`) so the Ask tab's header can
1498
1597
  * name which ask is open without the client re-deriving any of it.
1499
- * @param {{root: string, flow: string, runId: string, catalogue: any}} opts
1500
- * @returns {{flow:string, runId:string, asks:any[]}|null}
1598
+ * M4b piece 4: also carries `resume` (the SAME `deriveResumeState` the run
1599
+ * detail carries, `null` for a finished run or nothing to say) so the Ask tab
1600
+ * can tell "open, answerable" from "answer saved" without a second fetch.
1601
+ * @param {{root: string, flow: string, runId: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any}} opts
1602
+ * @returns {{flow:string, runId:string, asks:any[], resume: any}|null}
1501
1603
  */
1502
1604
  export function getRunAsks({
1503
- root, flow, runId, catalogue,
1605
+ root, flow, runId, catalogue, resumeAttempt,
1504
1606
  }) {
1505
1607
  const run = resolveRunPath(root, flow, runId);
1506
1608
  if (!run.ok) return null;
@@ -1518,16 +1620,19 @@ export function getRunAsks({
1518
1620
  });
1519
1621
  const declSteps = flowRead.ok ? flowRead.declaration.steps : null;
1520
1622
  const stepInfo = deriveAskStepInfo(ordered, auditRows, declSteps);
1623
+ const resume = hasHistoryRow ? null : deriveResumeState({ savedAnswer: readSavedAnswer(run.runDir), attempt: resumeAttempt?.(flow, runId) ?? null });
1521
1624
  const asks = ordered.map((ask, i) => ({
1522
1625
  ...ask,
1523
- ...deriveAskOpenFields(ask, hasHistoryRow),
1626
+ ...deriveAskOpenFields(ask, hasHistoryRow, resume),
1524
1627
  index: i + 1,
1525
1628
  total: ordered.length,
1526
1629
  stepName: stepInfo[i].step,
1527
1630
  stepLine: stepInfo[i].line,
1528
1631
  stepWhy: stepInfo[i].why,
1529
1632
  }));
1530
- return { flow, runId, asks };
1633
+ return {
1634
+ flow, runId, asks, resume,
1635
+ };
1531
1636
  }
1532
1637
 
1533
1638
  /**
@@ -1545,10 +1650,10 @@ export function getRunAsks({
1545
1650
  * force-`false` here as a second, independent check (belt-and-braces on the
1546
1651
  * one thing the brief calls out by name: "the Inbox tab's open count counts
1547
1652
  * only truly open asks — parked run, no history row, unexpired, unanswered").
1548
- * @param {{root: string}} opts
1653
+ * @param {{root: string, resumeAttempt?: (flow: string, runId: string) => any}} opts
1549
1654
  * @returns {any[]}
1550
1655
  */
1551
- export function listStops({ root }) {
1656
+ export function listStops({ root, resumeAttempt }) {
1552
1657
  const rows = [];
1553
1658
  for (const flowName of listFlowNames(root)) {
1554
1659
  const flowDir = join(root, flowName);
@@ -1557,12 +1662,13 @@ export function listStops({ root }) {
1557
1662
  const run = resolveRunPath(root, flowName, runId);
1558
1663
  if (!run.ok) continue;
1559
1664
  const hasHistoryRow = historyRunIds.has(runId);
1665
+ const resume = hasHistoryRow ? null : deriveResumeState({ savedAnswer: readSavedAnswer(run.runDir), attempt: resumeAttempt?.(flowName, runId) ?? null });
1560
1666
  for (const ask of runAsksInOrder(run.runDir, hasHistoryRow)) {
1561
1667
  rows.push({
1562
1668
  flow: flowName,
1563
1669
  runId,
1564
1670
  ...ask,
1565
- ...deriveAskOpenFields(ask, hasHistoryRow),
1671
+ ...deriveAskOpenFields(ask, hasHistoryRow, resume),
1566
1672
  });
1567
1673
  }
1568
1674
  }
@@ -1570,8 +1676,8 @@ export function listStops({ root }) {
1570
1676
  return rows
1571
1677
  .map((row, index) => ({ row, index }))
1572
1678
  .sort((a, b) => {
1573
- if (a.row.open !== b.row.open) return a.row.open ? -1 : 1;
1574
- if (a.row.open && b.row.open) {
1679
+ if (a.row.waiting !== b.row.waiting) return a.row.waiting ? -1 : 1;
1680
+ if (a.row.waiting && b.row.waiting) {
1575
1681
  const at = typeof a.row.timeLeftMs === 'number' ? a.row.timeLeftMs : Infinity;
1576
1682
  const bt = typeof b.row.timeLeftMs === 'number' ? b.row.timeLeftMs : Infinity;
1577
1683
  if (at !== bt) return at - bt;