fwdloop 0.38.0 → 0.39.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/bin/fwdloop +21 -19
- package/package.json +1 -1
- package/src/ask.js +70 -148
- package/src/audit-fold.js +5 -4
- package/src/auditchecks.js +6 -4
- package/src/authoring.js +32 -60
- package/src/blockasks.js +2 -1
- package/src/blockassemble.js +3 -2
- package/src/blockdraft.js +2 -2
- package/src/blockpick.js +5 -5
- package/src/books.js +217 -12
- package/src/checkblock.js +20 -41
- package/src/checklistsign.js +25 -3
- package/src/checklook.js +3 -1
- package/src/checkpick.js +5 -76
- package/src/cited-source.js +4 -4
- package/src/citedcheck.js +6 -11
- package/src/citedwords.js +9 -8
- package/src/closers.js +9 -6
- package/src/declaration.js +14 -49
- package/src/diary.js +23 -1
- package/src/draft-steps.js +11 -1
- package/src/drafter.js +13 -9
- package/src/draftfiles.js +127 -0
- package/src/draftspend.js +165 -17
- package/src/flow.js +42 -87
- package/src/flowmodel.js +1 -1
- package/src/index.js +3 -2
- package/src/inside.js +86 -0
- package/src/jsonl-append.js +33 -1
- package/src/learn.js +1 -1
- package/src/learnstore.js +20 -22
- package/src/line-checks.js +1 -1
- package/src/liveness.js +3 -0
- package/src/mcp-use.js +8 -9
- package/src/memo.js +13 -16
- package/src/model-step.js +2 -2
- package/src/page-words.js +8 -0
- package/src/pageask.js +8 -3
- package/src/pagebits.js +8 -1
- package/src/pagedropwords.js +1 -1
- package/src/pagerules.js +6 -3
- package/src/panel/author.js +99 -75
- package/src/panel/authorcard.js +21 -8
- package/src/panel/authorflows.js +3 -3
- package/src/panel/authorresume.js +3 -3
- package/src/panel/authorstart.js +15 -16
- package/src/panel/authortrigger.js +43 -70
- package/src/panel/data.js +125 -168
- package/src/panel/index.html +122 -61
- package/src/panel/jobgrid.js +3 -7
- package/src/panel/result.js +7 -10
- package/src/panel/resume.js +4 -3
- package/src/panel/scheduler.js +9 -9
- package/src/panel/server.js +8 -4
- package/src/panel/spawn.js +22 -11
- package/src/panel/tickets.js +2 -2
- package/src/pickrecord.js +51 -31
- package/src/placerule.js +3 -4
- package/src/planrebuild.js +19 -19
- package/src/primitives.js +1 -1
- package/src/provider.js +1 -1
- package/src/reasons.js +25 -0
- package/src/runfile.js +26 -2
- package/src/runner.js +57 -105
- package/src/runvalues.js +47 -24
- package/src/schedule-choices.js +41 -0
- package/src/schedule-shape.js +39 -0
- package/src/schedule.js +9 -8
- package/src/setup.js +20 -36
- package/src/shaperows.js +2 -2
- package/src/sheetblock.js +2 -2
- package/src/sheetbuild.js +5 -5
- package/src/sheetrun.js +4 -5
- package/src/summary-words.js +2 -1
- package/src/thinking.js +5 -2
- package/src/ticketrows.js +7 -28
- package/src/trigger-clock.js +9 -23
- package/src/trigger-files.js +30 -22
- package/src/trigger-tickets.js +15 -14
- package/src/try-checks.js +2 -1
- package/src/types.js +2 -0
- package/types/ask.d.ts +25 -20
- package/types/authoring.d.ts +7 -42
- package/types/blockpick.d.ts +1 -1
- package/types/books.d.ts +256 -4
- package/types/checkblock.d.ts +1 -23
- package/types/checklist.d.ts +3 -3
- package/types/checklistsign.d.ts +7 -0
- package/types/checkpick.d.ts +0 -21
- package/types/citedwords.d.ts +7 -4
- package/types/closers.d.ts +1 -0
- package/types/declaration.d.ts +4 -14
- package/types/diary.d.ts +14 -1
- package/types/draft-steps.d.ts +7 -0
- package/types/drafter.d.ts +1 -1
- package/types/draftfiles.d.ts +89 -0
- package/types/draftspend.d.ts +74 -0
- package/types/flow.d.ts +32 -54
- package/types/index.d.ts +3 -3
- package/types/inside.d.ts +58 -0
- package/types/jsonl-append.d.ts +20 -0
- package/types/learnstore.d.ts +0 -2
- package/types/liveness.d.ts +1 -0
- package/types/page-words.d.ts +6 -0
- package/types/pageask.d.ts +2 -0
- package/types/pagebits.d.ts +3 -0
- package/types/pagerules.d.ts +1 -0
- package/types/panel/author.d.ts +7 -3
- package/types/panel/authorcard.d.ts +0 -6
- package/types/panel/authorflows.d.ts +4 -4
- package/types/panel/authortrigger.d.ts +16 -2
- package/types/panel/data.d.ts +36 -11
- package/types/panel/spawn.d.ts +18 -2
- package/types/pickrecord.d.ts +29 -0
- package/types/reasons.d.ts +23 -0
- package/types/runfile.d.ts +14 -0
- package/types/runner.d.ts +6 -38
- package/types/runvalues.d.ts +17 -2
- package/types/schedule-choices.d.ts +9 -0
- package/types/schedule-shape.d.ts +15 -0
- package/types/sheetbuild.d.ts +1 -1
- package/types/thinking.d.ts +1 -0
- package/types/ticketrows.d.ts +0 -9
- package/types/trigger-clock.d.ts +3 -2
- package/types/trigger-files.d.ts +15 -4
- package/types/types.d.ts +8 -0
package/src/panel/data.js
CHANGED
|
@@ -28,17 +28,17 @@ import { plainPlanCheck, pickPlanRed } from '../plain-checks.js';
|
|
|
28
28
|
import { compareNatural } from '../natural.js';
|
|
29
29
|
import { join, sep } from 'node:path';
|
|
30
30
|
|
|
31
|
+
import { readFlow, readPlan, readRunPlan, readRunJobCopy, listFlowNames, listRunIds, resolveRunDir, checkFlowName } from '../flow.js';
|
|
32
|
+
import { readFileInside, readdirInside } from '../inside.js';
|
|
31
33
|
import {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
import {
|
|
35
|
-
readAudit, readHistory, endRow, readPidRows, auditRowTokens, auditRowAt, auditRowTools,
|
|
34
|
+
readAudit, readHistory, endRow, readPidRows, readSavedAnswer, processStarted, readRunState, readLog, readHaltRecord, readTriggerRecord, consumedAnswerName, askIdOfConsumedName,
|
|
35
|
+
endingWord, isBlockedEnding, isGoodEnding, isOpenEnding, isWaitingEnding, isStopNote, isResumableEnding, redWhyOf, isDraftRowVerdict, auditRowTokens, auditRowAt, auditRowTools,
|
|
36
36
|
} from '../books.js';
|
|
37
37
|
import {
|
|
38
|
-
readAsk,
|
|
38
|
+
readAsk, stopPending,
|
|
39
39
|
} from '../runner.js';
|
|
40
40
|
import { readSpendRows } from '../provider.js';
|
|
41
|
-
import { applyRunValues, parseWaitMs, pickRunValues
|
|
41
|
+
import { applyRunValues, listRunValues, parseWaitMs, pickRunValues } from '../runvalues.js';
|
|
42
42
|
import { readSetup } from '../setup.js';
|
|
43
43
|
import { parseHintBlock } from '../learn.js';
|
|
44
44
|
import { checkedLines, notCheckedView, notCheckedLabelOf, listPartRows } from '../checked.js';
|
|
@@ -50,14 +50,15 @@ import { panelQuestionText, decidedWords } from '../pageask.js';
|
|
|
50
50
|
import { csvRolesOf, askSheetCard } from '../sheetblock.js';
|
|
51
51
|
import { readSheetChecks } from '../sheet-record.js';
|
|
52
52
|
import {
|
|
53
|
-
NO_COPY_SAY, catchUpWords, endedLineWords, endedWords, needsLeftWords, nextInWords, nextTimeWords, scheduleAuditWords, scheduleBlockWords, scheduleFieldWords, scheduledNextFor, scheduledWords, startedWords,
|
|
53
|
+
NO_COPY_SAY, catchUpWords, endedLineWords, endedWords, needsLeftWords, nextInWords, nextTimeWords, scheduleAuditWords, scheduleBlockWords, scheduleFieldWords, scheduledNextFor, scheduledWords, startedNothing, startedWords,
|
|
54
54
|
} from '../summary-words.js';
|
|
55
55
|
import { MAX_STRUCTURE_RETRIES } from '../drafter.js';
|
|
56
56
|
import { hasResultCards, checkTypeOf, buildResult, downloadOf, readCitedChecks } from './result.js';
|
|
57
57
|
import { ticketListOf, ticketScheduleOf } from './tickets.js';
|
|
58
|
-
import { buildJobGrid } from './jobgrid.js';
|
|
59
|
-
import { readChecks } from '../diary.js';
|
|
60
|
-
import {
|
|
58
|
+
import { buildJobGrid, runMoney } from './jobgrid.js';
|
|
59
|
+
import { readChecks, readTryStarts } from '../diary.js';
|
|
60
|
+
import { mmss, stepped } from '../draftspend.js';
|
|
61
|
+
import { readRerunWords, readRunInputs } from '../runfile.js';
|
|
61
62
|
import { filterUnsure } from '../ticket-labels.js';
|
|
62
63
|
import { readSchedule } from '../schedule.js';
|
|
63
64
|
import { flowTypeOf } from '../declaration.js';
|
|
@@ -68,7 +69,7 @@ import {
|
|
|
68
69
|
isTryRow, loadDiaries, deriveFold, cardLine, summaryLines,
|
|
69
70
|
} from '../audit-fold.js';
|
|
70
71
|
import {
|
|
71
|
-
runLiveness, booksFresh, readResumeLock,
|
|
72
|
+
runLiveness, booksFresh, readResumeLock, lockMayBeHeld,
|
|
72
73
|
} from '../liveness.js';
|
|
73
74
|
import {
|
|
74
75
|
readAskEvidence, listArchivedAsks, normalizeDecision, DECISION_STATUS, decisionStatus, answerTiming,
|
|
@@ -161,31 +162,19 @@ export function hasConsumedAnswer(runDir, askId) {
|
|
|
161
162
|
// consumed answer that isn't really there by planting a symlink named to
|
|
162
163
|
// match the pattern.
|
|
163
164
|
const names = readdirInside(runDir, '.');
|
|
164
|
-
return names.includes(
|
|
165
|
+
return names.includes(consumedAnswerName(askId));
|
|
165
166
|
}
|
|
166
167
|
|
|
167
168
|
/**
|
|
168
|
-
* M4b piece 2: a SAVED, not-yet-consumed answer
|
|
169
|
-
* `
|
|
170
|
-
* through `readFileInside` (a symlinked file is "none"). `null` when there is
|
|
171
|
-
* none or it is unreadable/unparseable or names no askId.
|
|
169
|
+
* M4b piece 2: a SAVED, not-yet-consumed answer, as the panel shows it: `readSavedAnswer` (src/books.js, the one reader) read for an answer that names an ask.
|
|
170
|
+
* `null` when there is none or it is unreadable, unparseable or names no askId. `broken` is the reader's own field (M20 am3b item 1).
|
|
172
171
|
* @param {string} runDir
|
|
173
|
-
* @returns {{askId: string, decision: string|null, answeredAt: string|null}|null}
|
|
172
|
+
* @returns {{askId: string, decision: string|null, answeredAt: string|null, broken: boolean}|null}
|
|
174
173
|
*/
|
|
175
|
-
export function
|
|
176
|
-
const r =
|
|
177
|
-
if (!r.ok) return null;
|
|
178
|
-
|
|
179
|
-
const a = JSON.parse(r.text);
|
|
180
|
-
if (a && typeof a.askId === 'string' && a.askId.length > 0) {
|
|
181
|
-
return {
|
|
182
|
-
askId: a.askId,
|
|
183
|
-
decision: typeof a.decision === 'string' ? normalizeDecision(a.decision) : null,
|
|
184
|
-
answeredAt: typeof a.answeredAt === 'string' ? a.answeredAt : null,
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
} catch { /* unparseable: not a usable answer */ }
|
|
188
|
-
return null;
|
|
174
|
+
export function savedAnswerOf(runDir) {
|
|
175
|
+
const r = readSavedAnswer(runDir);
|
|
176
|
+
if (!r.ok || r.askId === null) return null;
|
|
177
|
+
return { askId: r.askId, decision: r.decision === null ? null : normalizeDecision(r.decision), answeredAt: r.answeredAt, broken: r.broken };
|
|
189
178
|
}
|
|
190
179
|
|
|
191
180
|
/** What the `resume` field says when the panel has no attempt record for a run
|
|
@@ -202,7 +191,7 @@ export const RESUME_REASON_UNKNOWN = 'reason unknown: the panel restarted, so it
|
|
|
202
191
|
* answer for that ask that was NOT saved in time, once the deadline has passed, is not a resumable answer: it reads
|
|
203
192
|
* as none, so the ask is expired and offers the reopen (M4c-fix amendment 1 (b)). One with no readable time, before
|
|
204
193
|
* the deadline, reads `broken` (amendment 1 (a)).
|
|
205
|
-
* @param {{savedAnswer: {askId:string, decision:string|null, answeredAt?:string|null}|null, attempt: any, ask?: any}} ctx
|
|
194
|
+
* @param {{savedAnswer: {askId:string, decision:string|null, answeredAt?:string|null, broken?: boolean}|null, attempt: any, ask?: any}} ctx
|
|
206
195
|
* @returns {{state: 'starting'|'not-started'|'broken'|'took-over', askId: string|null, tries: number|null, maxTries: number|null, reason: string|null, label: string}|null}
|
|
207
196
|
*/
|
|
208
197
|
export function deriveResumeState({ savedAnswer: savedOnDisk, attempt, ask = null }) {
|
|
@@ -216,7 +205,7 @@ export function deriveResumeState({ savedAnswer: savedOnDisk, attempt, ask = nul
|
|
|
216
205
|
if (saved) {
|
|
217
206
|
// M4c-fix amendment 1 (a): a saved answer with no readable time is broken — the resume would refuse it every
|
|
218
207
|
// time. It is not stuck, not "answer saved": the doors come back with a note, and answering again sets it aside.
|
|
219
|
-
if (
|
|
208
|
+
if (saved.broken) {
|
|
220
209
|
return {
|
|
221
210
|
state: 'broken', askId: saved.askId, tries: null, maxTries: null, reason: BROKEN_ANSWER_WHY, label: BROKEN_LABEL,
|
|
222
211
|
};
|
|
@@ -244,6 +233,10 @@ export function deriveResumeState({ savedAnswer: savedOnDisk, attempt, ask = nul
|
|
|
244
233
|
return null;
|
|
245
234
|
}
|
|
246
235
|
|
|
236
|
+
/** M20 am8: the one question "is THIS ask's saved answer being picked up, or the run stopped before using it" (`resume` = `deriveResumeState`: starting or not-started, for this ask) @param {any} resume @param {unknown} askId @returns {boolean} */
|
|
237
|
+
export const answerPickedUp = (resume, askId) => resume != null && resume.askId === askId
|
|
238
|
+
&& (resume.state === 'starting' || resume.state === 'not-started');
|
|
239
|
+
|
|
247
240
|
export const WAITING_LABEL = 'waiting on you (parked, unanswered)';
|
|
248
241
|
export const STUCK_LABEL = 'stuck — your answer is saved; the run stopped before using it';
|
|
249
242
|
export const STUCK_LOCK_LABEL = 'stuck — an old resume lock is in the way';
|
|
@@ -257,7 +250,7 @@ export const CRASHED_LABEL = 'crashed after taking your answer — start a fresh
|
|
|
257
250
|
* @type {Record<string, string>}
|
|
258
251
|
*/
|
|
259
252
|
export const SIGN_WORDS = {
|
|
260
|
-
'[▶]': 'running', '[·]': 'waiting', '[II]': 'stuck', '[!]': 'expired', '[?]': 'crashed', '[✓]': '
|
|
253
|
+
'[▶]': 'running', '[·]': 'waiting', '[II]': 'stuck', '[!]': endingWord('ask-expired') ?? '', '[?]': 'crashed', '[✓]': endingWord('complete') ?? '', '[✗]': endingWord('red') ?? '', '[■]': endingWord('stopped') ?? '', '[–]': endingWord('skipped') ?? '',
|
|
261
254
|
};
|
|
262
255
|
|
|
263
256
|
/**
|
|
@@ -265,11 +258,12 @@ export const SIGN_WORDS = {
|
|
|
265
258
|
* opens with the word ("stuck — …") or is the word itself ("passed") loses that repeat, so it is never said twice.
|
|
266
259
|
* `noWord`: a run the human ended on purpose with rerun wears `[✗]` but is never called "failed" (M4b amendment 3),
|
|
267
260
|
* so it shows its plain line alone.
|
|
268
|
-
* @param {string} glyph a `computeGlyph` sign @param {string} label its plain line @param {boolean} [noWord]
|
|
261
|
+
* @param {string} glyph a `computeGlyph` sign @param {string} label its plain line @param {boolean} [noWord] @param {{outcome: string|null|undefined, resumable: boolean}|null} [ending] the run's end row outcome and whether it can be continued
|
|
269
262
|
* @returns {{word: string|null, line: string|null}}
|
|
270
263
|
*/
|
|
271
|
-
export function signParts(glyph, label, noWord = false) {
|
|
272
|
-
|
|
264
|
+
export function signParts(glyph, label, noWord = false, ending = null) {
|
|
265
|
+
// M20 am1 items 1 and 9: a run that has ended reads the word of its ENDING (the one table, src/books.js); a sign alone gives the word for the rest
|
|
266
|
+
const word = noWord ? null : ((ending && ending.outcome ? endingWord(ending.outcome, ending.resumable) : null) ?? SIGN_WORDS[glyph] ?? null);
|
|
273
267
|
if (word === null) return { word: null, line: label ?? null };
|
|
274
268
|
if (typeof label !== 'string' || label === word) return { word, line: null };
|
|
275
269
|
if (label.startsWith(`${word} — `)) return { word, line: label.slice(word.length + 3) };
|
|
@@ -305,7 +299,7 @@ export const STUCK_REASONS = {
|
|
|
305
299
|
* @returns {{stuck: false, reason: null, label: null, why: null}|{stuck: true, reason: 'retry'|'lock-no-holder', label: string, why: string|null}}
|
|
306
300
|
*/
|
|
307
301
|
export function stuckState({ resume, liveness, lock }) {
|
|
308
|
-
if (!resume || resume.state !== 'not-started' || liveness === 'running' || lock
|
|
302
|
+
if (!resume || resume.state !== 'not-started' || liveness === 'running' || lockMayBeHeld(lock)) {
|
|
309
303
|
return {
|
|
310
304
|
stuck: false, reason: null, label: null, why: null,
|
|
311
305
|
};
|
|
@@ -402,12 +396,14 @@ export function computeGlyph({
|
|
|
402
396
|
// M12 piece 3 (item 9): a ticket the signed labels do not match, or a closed one: grey, never failed
|
|
403
397
|
if (historyRow.outcome === 'skipped') return { glyph: '[–]', label: typeof historyRow.skipReason === 'string' && historyRow.skipReason !== '' ? `skipped — ${historyRow.skipReason}` : 'skipped' };
|
|
404
398
|
// M6 amendment 4: a stopped (or cap-halted) run whose job was edited and signed since cannot be resumed; the words say so.
|
|
405
|
-
if (jobEdited === true && (historyRow.outcome
|
|
399
|
+
if (jobEdited === true && isResumableEnding(historyRow.outcome)) return { glyph: '[■]', label: JOB_EDITED_LINE };
|
|
406
400
|
// M4e amendment 4 item 4: a run the human stopped, or one that hit its money cap and can be continued, is `[■]` stopped — never "failed".
|
|
407
401
|
if (historyRow.outcome === 'stopped') {
|
|
408
402
|
return { glyph: '[■]', label: stoppedAtAsk ? `${stoppedAtAsk}${STOPPED_AT_ASK_START_RE.test(stoppedAtAsk) ? ';' : ' —'} Resume to go on` : 'stopped — after the step that was running; Resume to go on' };
|
|
409
403
|
}
|
|
410
404
|
if (historyRow.outcome === 'cap-halt' && resumable) return { glyph: '[■]', label: 'stopped — the money cap was reached; raise it and Resume' };
|
|
405
|
+
// M20 am1 item 9: a cap-halt that cannot be resumed wears the stop sign with its own word, never "failed (cap-halt)"
|
|
406
|
+
if (historyRow.outcome === 'cap-halt') return { glyph: '[■]', label: endingWord('cap-halt', false) ?? '' };
|
|
411
407
|
// M4b amendment 3: a run the human ended on purpose with rerun is not a failure.
|
|
412
408
|
if (historyRow.outcome === 'rerun') return { glyph: '[✗]', label: 'stopped by you (rerun), a fresh run was started' };
|
|
413
409
|
// M4c-fix amendment 1 (c): a run ended because its ask expired is `[!]` expired, never failed (it spent nothing more).
|
|
@@ -472,18 +468,15 @@ export function costDisplay(spentUsd, spendComplete) {
|
|
|
472
468
|
}
|
|
473
469
|
|
|
474
470
|
/**
|
|
475
|
-
* A
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
* @param {any[]} spendRows
|
|
480
|
-
* @returns {string|null}
|
|
471
|
+
* A run's spend in the Runs list and the Run tab's words (four decimals even for an exact zero; the ticket grid writes a bare zero, src/panel/jobgrid.js `moneyWords`, on the guard's
|
|
472
|
+
* allow-list). The NUMBER is `runMoney`'s (M20 am3g item 24): the history row's total, else the priced spend rows as an "at least" floor (used ONLY when there is no history
|
|
473
|
+
* row yet), else null (never `$0` for unknown). A history row whose total is not a number gives null, never the rows' floor.
|
|
474
|
+
* @param {any} historyRow @param {any[]} spendRows @returns {string|null}
|
|
481
475
|
*/
|
|
482
|
-
function
|
|
483
|
-
const
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
return `at least $${sum.toFixed(4)}`;
|
|
476
|
+
function runSpendDisplay(historyRow, spendRows) {
|
|
477
|
+
const m = runMoney(historyRow ?? null, historyRow ? [] : spendRows);
|
|
478
|
+
const cd = m.usd === null ? null : costDisplay(m.usd, m.complete);
|
|
479
|
+
return cd !== null && cd.ok ? cd.display : null;
|
|
487
480
|
}
|
|
488
481
|
|
|
489
482
|
/**
|
|
@@ -670,11 +663,8 @@ export function deriveAuditAtWhy(row) {
|
|
|
670
663
|
* @param {string|null|undefined} verdict
|
|
671
664
|
* @returns {boolean}
|
|
672
665
|
*/
|
|
673
|
-
const BLOCKED_VERDICTS = new Set([
|
|
674
|
-
'not-done', 'red', 'refused', 'ask-timeout', 'ask-expired', 'cap-halt', 'provider-red', 'pricing-red', 'close-casualty',
|
|
675
|
-
]);
|
|
676
666
|
export function isBlockedVerdict(verdict) {
|
|
677
|
-
return
|
|
667
|
+
return isBlockedEnding(verdict);
|
|
678
668
|
}
|
|
679
669
|
|
|
680
670
|
/**
|
|
@@ -694,8 +684,8 @@ export function isBlockedVerdict(verdict) {
|
|
|
694
684
|
*/
|
|
695
685
|
function markForVerdict(verdict, closeClass) {
|
|
696
686
|
if (closeClass === 'hitl' && verdict === 'red') return '✗'; // the human's own redo
|
|
697
|
-
if (verdict
|
|
698
|
-
if (verdict
|
|
687
|
+
if (isGoodEnding(verdict)) return '✓';
|
|
688
|
+
if (isOpenEnding(verdict)) return '·';
|
|
699
689
|
return '✗';
|
|
700
690
|
}
|
|
701
691
|
|
|
@@ -760,11 +750,11 @@ function auditStepName(step) {
|
|
|
760
750
|
*/
|
|
761
751
|
export function deriveStepGroupState(rows) {
|
|
762
752
|
// a Stop's notes (asked / not honoured) say nothing about the step's own state; a step with only notes reads as stopped
|
|
763
|
-
const own = rows.filter((r) => r.verdict
|
|
753
|
+
const own = rows.filter((r) => !isStopNote(r.verdict));
|
|
764
754
|
const last = own.length > 0 ? own[own.length - 1] : rows[rows.length - 1];
|
|
765
|
-
if (last.verdict
|
|
755
|
+
if (isWaitingEnding(last.verdict)) return 'waiting';
|
|
766
756
|
if (last.verdict === 'stopped') return 'user-stopped';
|
|
767
|
-
return (last.verdict
|
|
757
|
+
return isGoodEnding(last.verdict) ? 'done' : 'stopped';
|
|
768
758
|
}
|
|
769
759
|
|
|
770
760
|
/**
|
|
@@ -939,7 +929,7 @@ function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue, attem
|
|
|
939
929
|
const stateJson = readRunState(runDir);
|
|
940
930
|
const consumedAnswerExists = hasConsumedAnswer(runDir, askJson && typeof askJson.askId === 'string' ? askJson.askId : null);
|
|
941
931
|
// A finished run has no resume to report (its history row says how it ended).
|
|
942
|
-
const savedAnswer = historyRow ? null :
|
|
932
|
+
const savedAnswer = historyRow ? null : savedAnswerOf(runDir);
|
|
943
933
|
const resume = historyRow ? null : deriveResumeState({ savedAnswer, attempt, ask: askJson });
|
|
944
934
|
const stuckInputs = historyRow ? { liveness: 'unknown', lock: 'none' } : readStuckInputs(runDir);
|
|
945
935
|
|
|
@@ -975,6 +965,8 @@ function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue, attem
|
|
|
975
965
|
liveness: stuckInputs.liveness,
|
|
976
966
|
lock: stuckInputs.lock,
|
|
977
967
|
booksFresh: historyRow ? false : booksFresh(runDir),
|
|
968
|
+
// M20 am1 item 8: the newest `try-start` diary row of a run with no end row (the NOW row reads it), else null
|
|
969
|
+
tryStart: historyRow ? null : (readTryStarts(runDir).at(-1) ?? null),
|
|
978
970
|
// M4c exit walk: when the process that is working on the run started (its newest pid row's
|
|
979
971
|
// own `startedAt`), so a `[▶]` run has a real time and never "parked or died". Not a book change.
|
|
980
972
|
startedAt: historyRow ? null : lastPidStartedAt(runDir),
|
|
@@ -1016,7 +1008,7 @@ function lastStoppedAtAsk(runDir, auditRows, hasHistoryRow) {
|
|
|
1016
1008
|
const stopped = auditRows.filter((r) => r.verdict === 'stopped' && typeof r.gap === 'string' && !Number.isInteger(r.attempt));
|
|
1017
1009
|
const last = stopped.length > 0 ? stopped[stopped.length - 1] : null;
|
|
1018
1010
|
if (!last || !STOPPED_AT_ASK_RE.test(last.gap)) return null;
|
|
1019
|
-
const ordered = runAsksInOrder(runDir, hasHistoryRow);
|
|
1011
|
+
const ordered = runAsksInOrder(runDir, hasHistoryRow, auditRows);
|
|
1020
1012
|
const stepOf = deriveAskStepInfo(ordered, auditRows, null);
|
|
1021
1013
|
const words = stoppedAskWords(ordered, auditRows);
|
|
1022
1014
|
const i = stepOf.findIndex((x) => x.step !== null && x.step === last.step);
|
|
@@ -1036,13 +1028,6 @@ function firstPidStartedAt(runDir) {
|
|
|
1036
1028
|
return null;
|
|
1037
1029
|
}
|
|
1038
1030
|
|
|
1039
|
-
/** The run's own `trigger.json` (why it started), or null for a hand run. @param {string} runDir */
|
|
1040
|
-
function readTriggerRecord(runDir) {
|
|
1041
|
-
const f = readFileInside(runDir, 'trigger.json');
|
|
1042
|
-
if (!f.ok) return null;
|
|
1043
|
-
try { const j = JSON.parse(f.text); return j && typeof j === 'object' ? j : null; } catch { return null; }
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
1031
|
/** The ONE running rule for wording is the glyph's own (`computeGlyph` -> `[▶]`, which already
|
|
1047
1032
|
* folds in `runLiveness`): a run with no end row whose glyph is `[▶]` is running. */
|
|
1048
1033
|
const RUNNING_WHY = 'still running — not finished yet';
|
|
@@ -1062,7 +1047,7 @@ export function runControls(ctx, glyph, label = '') {
|
|
|
1062
1047
|
const running = isRunningNow(ctx, glyph) && (!ctx.askJson || ctx.consumedAnswerExists || ctx.resume?.state === 'not-started');
|
|
1063
1048
|
// M4e amendment 13: a run waiting at its ask (open, unanswered, not expired) shows Stop too; it stops the run at the ask.
|
|
1064
1049
|
const atAsk = !ctx.historyRow && !!ctx.askJson && glyph === '[·]' && label === WAITING_LABEL;
|
|
1065
|
-
const starting = !ctx.historyRow && !ctx.askJson &&
|
|
1050
|
+
const starting = !ctx.historyRow && !ctx.askJson && !processStarted(ctx.runDir);
|
|
1066
1051
|
const canResume = ctx.resumable === true && ctx.sameJob === true;
|
|
1067
1052
|
return {
|
|
1068
1053
|
canStop: running || atAsk,
|
|
@@ -1154,17 +1139,11 @@ export function listRuns({ root, catalogue, resumeAttempt, startingRun, now = Da
|
|
|
1154
1139
|
const controls = runControls(ctx, glyph, label);
|
|
1155
1140
|
// M4c amendment 1 (c): the ask waiting on the human, by the same rule
|
|
1156
1141
|
// listStops uses (deriveAskOpenFields) — the least time left if several.
|
|
1157
|
-
const waitingAsk = runAsksInOrder(run.runDir, !!ctx.historyRow)
|
|
1142
|
+
const waitingAsk = runAsksInOrder(run.runDir, !!ctx.historyRow, ctx.auditRows)
|
|
1158
1143
|
.map((ask) => ({ ask, ...deriveAskOpenFields(ask, !!ctx.historyRow, ctx.resume) }))
|
|
1159
1144
|
.filter((r) => r.waiting)
|
|
1160
1145
|
.reduce((best, r) => (best === null || (r.timeLeftMs ?? Infinity) < (best.timeLeftMs ?? Infinity) ? r : best), /** @type {any} */ (null));
|
|
1161
|
-
|
|
1162
|
-
if (ctx.historyRow) {
|
|
1163
|
-
const cd = costDisplay(ctx.historyRow.spentUsd, ctx.historyRow.spendComplete);
|
|
1164
|
-
spend = cd.ok ? cd.display : null;
|
|
1165
|
-
} else {
|
|
1166
|
-
spend = spendFloorDisplay(ctx.spendRows);
|
|
1167
|
-
}
|
|
1146
|
+
const spend = runSpendDisplay(ctx.historyRow, ctx.spendRows);
|
|
1168
1147
|
// browser re-walk bug #4: a parked run's ask.json holds a real,
|
|
1169
1148
|
// book-held timestamp (`askedAt`) — a run with an open ask is never
|
|
1170
1149
|
// "unknown", even with no history row yet. `atWhy`'s generic "no
|
|
@@ -1179,7 +1158,7 @@ export function listRuns({ root, catalogue, resumeAttempt, startingRun, now = Da
|
|
|
1179
1158
|
runId,
|
|
1180
1159
|
glyph,
|
|
1181
1160
|
label,
|
|
1182
|
-
...signParts(glyph, label, ctx.historyRow?.outcome === 'rerun'),
|
|
1161
|
+
...signParts(glyph, label, ctx.historyRow?.outcome === 'rerun', ctx.historyRow ? { outcome: ctx.historyRow.outcome, resumable: ctx.resumable === true } : null),
|
|
1183
1162
|
pulse: glyphPulses({ glyph, label }),
|
|
1184
1163
|
stuck: glyph === '[II]',
|
|
1185
1164
|
controls,
|
|
@@ -1324,8 +1303,8 @@ export function needsYouOf({
|
|
|
1324
1303
|
*/
|
|
1325
1304
|
function runReopenOffer(runDir, ctx) {
|
|
1326
1305
|
if (ctx.historyRow || !ctx.askJson) return null;
|
|
1327
|
-
const savedAskId =
|
|
1328
|
-
for (const a of runAsksInOrder(runDir, false)) {
|
|
1306
|
+
const savedAskId = savedAnswerOf(runDir)?.askId;
|
|
1307
|
+
for (const a of runAsksInOrder(runDir, false, ctx.auditRows)) {
|
|
1329
1308
|
const offer = reopenOffer(a, ctx.askJson, ctx.resume, savedAskId === a.askId);
|
|
1330
1309
|
if (offer !== null) return { askId: a.askId, ...offer };
|
|
1331
1310
|
}
|
|
@@ -1485,11 +1464,11 @@ function waitingLineOf(ctx) {
|
|
|
1485
1464
|
*/
|
|
1486
1465
|
function jobWaitingLine(root, flowDir, flow, catalogue) {
|
|
1487
1466
|
const ids = listRunIds(flowDir).sort((a, b) => compareNatural(b, a));
|
|
1488
|
-
const history = readHistory(flowDir); // `atAsk` needs no end row (`runControls`), so an ended run is skipped by the same `endRow` rule before a context is built for it
|
|
1489
1467
|
for (const id of ids) {
|
|
1490
1468
|
const run = resolveRunDir(flowDir, id);
|
|
1491
|
-
if (!run.ok ||
|
|
1469
|
+
if (!run.ok || !readAsk(run.runDir)) continue; // eslint-disable-line no-continue
|
|
1492
1470
|
const ctx = loadRunContext(root, flowDir, run.runDir, flow, id, catalogue, null);
|
|
1471
|
+
if (ctx.historyRow !== null) continue; // `atAsk` needs no end row (`runControls`): an ended run is skipped by the same `endRow` rule
|
|
1493
1472
|
const g = computeGlyph(ctx);
|
|
1494
1473
|
if (runControls(ctx, g.glyph, g.label).atAsk) return waitingLineOf(ctx);
|
|
1495
1474
|
}
|
|
@@ -1511,7 +1490,7 @@ function scheduleBlockOf({ root, flowDir, flow, catalogue, t, home, now }) {
|
|
|
1511
1490
|
trigger: t && t.trigger ? t.trigger : null, home,
|
|
1512
1491
|
last: lastStart ? { at: lastStart.at, runId: lastStart.runId, outcome: lastGlyph ? (SIGN_WORDS[lastGlyph.glyph] ?? 'ended') : 'ended', catchUp: !!(lastRec && lastRec.catchUp === true) } : null,
|
|
1513
1492
|
nextSlotMs: t ? t.nextSlotMs : null, armed: !!(t && t.armed), waiting: !!(t && t.waiting), lookProblem: t ? t.lookProblem ?? null : null, nowMs: now(),
|
|
1514
|
-
problem:
|
|
1493
|
+
problem: startedNothing(latest) ? latest : null,
|
|
1515
1494
|
});
|
|
1516
1495
|
}
|
|
1517
1496
|
|
|
@@ -1530,11 +1509,25 @@ function jobHasRunningRun({ root, flow, catalogue, resumeAttempt, startingRun })
|
|
|
1530
1509
|
return false;
|
|
1531
1510
|
}
|
|
1532
1511
|
|
|
1512
|
+
// borrowed-from: bareloop src/panel/server.js@v0.63.0 (7bc2719b): nowOf (the NOW row's words and its 30 s steps); fwd reads its own report-only `try-start` diary row, and the try ends at the first audit row written at or after it (an equal time counts as ended)
|
|
1513
|
+
/**
|
|
1514
|
+
* M20 am1 item 8: the Run tab's NOW row, "AI working · M:SS", only while the run is live (`[▶]`, no end row) and a model step's try is running: the newest
|
|
1515
|
+
* `try-start` row has no audit row written at or after it. Anything else is null (nothing is made up between tries). The time moves in 30 s steps (`stepped`).
|
|
1516
|
+
* @param {any} ctx `loadRunContext`'s result @param {string} glyph `computeGlyph`'s sign @param {number} nowMs @returns {string|null}
|
|
1517
|
+
*/
|
|
1518
|
+
export function nowOf(ctx, glyph, nowMs) {
|
|
1519
|
+
if (!isRunningNow(ctx, glyph) || !ctx.tryStart) return null;
|
|
1520
|
+
const from = Date.parse(ctx.tryStart.at);
|
|
1521
|
+
if (!Number.isFinite(from)) return null;
|
|
1522
|
+
if (ctx.auditRows.some((r) => typeof r.at === 'string' && r.at >= ctx.tryStart.at)) return null;
|
|
1523
|
+
return `AI working \u00B7 ${mmss(stepped(nowMs - from))}`;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1533
1526
|
/**
|
|
1534
1527
|
* M9 piece 6 (ladder M9 item 7): the summary block at the top of a run page, as data. Words come from `src/summary-words.js` only, built
|
|
1535
1528
|
* from typed facts (the history row's outcome, the declared step's line, the signed trigger and its ledger). `ended` is null while the run
|
|
1536
1529
|
* is live; `scheduled` is null when the job has no trigger; `canSchedule` (am3 item 1) is the trigger door's own `hasGreenRun` answer; `catchUp` is a fixed sentence when this run was started late (am2 item 1).
|
|
1537
|
-
* @returns {{ended: {reason: string, next: string}|null, scheduled: {text: string, next: string, nextRed: boolean}|null, schedule: {line1: string, line2: string|null, red: boolean}, canSchedule: boolean, catchUp: string|null}}
|
|
1530
|
+
* @returns {{ended: {reason: string, next: string}|null, scheduled: {text: string, next: string, nextRed: boolean}|null, schedule: {line1: string, line2: string|null, red: boolean}, canSchedule: boolean, catchUp: string|null, now: string|null}}
|
|
1538
1531
|
*/
|
|
1539
1532
|
function runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }) {
|
|
1540
1533
|
const died = !ctx.historyRow && glyph === '[?]';
|
|
@@ -1561,12 +1554,10 @@ function runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }) {
|
|
|
1561
1554
|
});
|
|
1562
1555
|
scheduled = { text: String(scheduledWords(t.trigger, home)), next: nx.text, nextRed: nx.red };
|
|
1563
1556
|
}
|
|
1564
|
-
|
|
1565
|
-
const f = readFileInside(ctx.runDir, 'trigger.json');
|
|
1566
|
-
if (f.ok) { try { rec = JSON.parse(f.text); } catch { rec = null; } }
|
|
1557
|
+
const rec = readTriggerRecord(ctx.runDir);
|
|
1567
1558
|
// M9 am7 items 3-4: the SCHEDULE block replaces the SCHEDULED / NEXT rows. Words: src/summary-words.js, the same owner as the Job tab's Schedule field.
|
|
1568
1559
|
const schedule = scheduleBlockOf({ root, flowDir: ctx.flowDir, flow: ctx.flowName, catalogue, t, home, now });
|
|
1569
|
-
return { ended, scheduled, schedule, canSchedule: !!(t && t.hasGreenRun), catchUp: catchUpWords(rec) };
|
|
1560
|
+
return { ended, scheduled, schedule, canSchedule: !!(t && t.hasGreenRun), catchUp: catchUpWords(rec), now: nowOf(ctx, glyph, now()) };
|
|
1570
1561
|
}
|
|
1571
1562
|
|
|
1572
1563
|
/**
|
|
@@ -1695,7 +1686,7 @@ export function getRunDetail({
|
|
|
1695
1686
|
tryMarks: group ? group.tryMarks : [],
|
|
1696
1687
|
// Filled below, ONLY on the one step that actually stopped this
|
|
1697
1688
|
// run (never guessed onto every step) — see stoppedStepEmits.
|
|
1698
|
-
stoppedReason: null,
|
|
1689
|
+
stoppedReason: /** @type {string|null} */ (null),
|
|
1699
1690
|
};
|
|
1700
1691
|
});
|
|
1701
1692
|
}
|
|
@@ -1731,6 +1722,7 @@ export function getRunDetail({
|
|
|
1731
1722
|
// (`askJson` present, no consumed answer — the same test `computeGlyph`
|
|
1732
1723
|
// uses for "waiting on you") reports the ask's own question as its whole
|
|
1733
1724
|
// "why", never an unrelated earlier attempt's gap.
|
|
1725
|
+
/** @type {string|null} */
|
|
1734
1726
|
let stopReason = null;
|
|
1735
1727
|
let stopReasonWhy = null;
|
|
1736
1728
|
if (ctx.historyRow && ctx.historyRow.outcome === 'complete') {
|
|
@@ -1747,18 +1739,11 @@ export function getRunDetail({
|
|
|
1747
1739
|
stopReasonWhy = ctx.resume.reason ? `${ctx.resume.label}: ${ctx.resume.reason}` : ctx.resume.label;
|
|
1748
1740
|
} else if (!ctx.historyRow && ctx.askJson && !ctx.consumedAnswerExists) {
|
|
1749
1741
|
stopReasonWhy = `waiting on you: ${typeof ctx.askJson.question === 'string' && ctx.askJson.question.length > 0 ? ctx.askJson.question : 'no question recorded'}`;
|
|
1750
|
-
} else if (ctx.logJson && typeof ctx.logJson.red === 'string' && ctx.logJson.red.length > 0) {
|
|
1751
|
-
stopReason = ctx.logJson.red;
|
|
1752
1742
|
} else {
|
|
1753
|
-
//
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
for (const r of ctx.auditRows) {
|
|
1758
|
-
if (r.verdict === 'not-done' || r.verdict === 'red') redRow = r;
|
|
1759
|
-
}
|
|
1760
|
-
if (redRow) {
|
|
1761
|
-
stopReason = `${redRow.step}: ${redRow.gap}`;
|
|
1743
|
+
// the log's red, else the LAST red audit row (`redWhyOf`, the one rule the Result tab asks too)
|
|
1744
|
+
const why = redWhyOf(ctx.logJson, ctx.auditRows);
|
|
1745
|
+
if (why !== null) {
|
|
1746
|
+
stopReason = why;
|
|
1762
1747
|
} else {
|
|
1763
1748
|
stopReasonWhy = 'run has not stopped on a red/not-done step (still parked, waiting, or clean so far)';
|
|
1764
1749
|
}
|
|
@@ -1796,13 +1781,7 @@ export function getRunDetail({
|
|
|
1796
1781
|
: (ctx.historyRow ? 'history row has no wallMs recorded'
|
|
1797
1782
|
: isRunningNow(ctx, glyph) ? RUNNING_WHY : 'no history row yet (parked or died before completion)');
|
|
1798
1783
|
|
|
1799
|
-
|
|
1800
|
-
if (ctx.historyRow) {
|
|
1801
|
-
const cd = costDisplay(ctx.historyRow.spentUsd, ctx.historyRow.spendComplete);
|
|
1802
|
-
spend = cd.ok ? cd.display : null;
|
|
1803
|
-
} else {
|
|
1804
|
-
spend = spendFloorDisplay(ctx.spendRows);
|
|
1805
|
-
}
|
|
1784
|
+
const spend = runSpendDisplay(ctx.historyRow, ctx.spendRows);
|
|
1806
1785
|
|
|
1807
1786
|
// hamr's review #1 (Summary tab): model + spend.jsonl totals — read here
|
|
1808
1787
|
// ONCE, off the same auditRows/spendRows this function already loaded, so
|
|
@@ -1818,7 +1797,7 @@ export function getRunDetail({
|
|
|
1818
1797
|
runId,
|
|
1819
1798
|
glyph,
|
|
1820
1799
|
label,
|
|
1821
|
-
...signParts(glyph, label, ctx.historyRow?.outcome === 'rerun'),
|
|
1800
|
+
...signParts(glyph, label, ctx.historyRow?.outcome === 'rerun', ctx.historyRow ? { outcome: ctx.historyRow.outcome, resumable: ctx.resumable === true } : null),
|
|
1822
1801
|
signWords: SIGN_WORDS,
|
|
1823
1802
|
pulse: glyphPulses({ glyph, label }),
|
|
1824
1803
|
controls: runControls(ctx, glyph, label),
|
|
@@ -1919,7 +1898,7 @@ export function getDraftBlock(flowDir, runDir) {
|
|
|
1919
1898
|
attempt, step: 'drafting', class: 'hitl', verdict: 'hitl', at: r.at ?? null, setup: true, blocked: false, action: 'human', tokensDisplay: { kind: 'no-model' }, ...extra,
|
|
1920
1899
|
});
|
|
1921
1900
|
const model = (r, attempt, label) => ({
|
|
1922
|
-
attempt, step: 'drafting', class: null, verdict: r.verdict
|
|
1901
|
+
attempt, step: 'drafting', class: null, verdict: isDraftRowVerdict(r.verdict) ? r.verdict : 'not-done', gap: r.gap ?? '', at: r.at ?? null, setup: true, blocked: false,
|
|
1923
1902
|
action: `${label} · ${r.model ?? 'model not recorded'}${r.hash ? ` · plan ${String(r.hash).slice(0, 8)}` : ''}`,
|
|
1924
1903
|
usd: typeof r.costUsd === 'number' ? r.costUsd : undefined, spendComplete: r.spendComplete === true, tokensDisplay: { kind: 'no-model' },
|
|
1925
1904
|
...(typeof r.wallMs === 'number' ? { wallMs: r.wallMs } : {}),
|
|
@@ -1971,28 +1950,20 @@ export function getDraftBlock(flowDir, runDir) {
|
|
|
1971
1950
|
else if (r.kind === 'sign') rows.push(human(r, n, { action: `sign (${r.signedBy ?? 'you'})`, gap: `plan ${String(r.hash ?? '').slice(0, 12)}` }));
|
|
1972
1951
|
});
|
|
1973
1952
|
}
|
|
1974
|
-
const versions =
|
|
1975
|
-
for (const
|
|
1976
|
-
|
|
1977
|
-
if (
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
const
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
const waits = v && typeof v === 'object' && v.askWaits && typeof v.askWaits === 'object'
|
|
1986
|
-
? Object.entries(v.askWaits).map(([line, wait]) => ({ line, wait: String(wait), waitMs: parseWaitMs(wait) })) : [];
|
|
1987
|
-
const head = v && typeof v === 'object' ? [`cap $${v.capUsd}`, v.destination ? `destination ${v.destination}` : null].filter(Boolean) : [];
|
|
1988
|
-
const gap = v && typeof v === 'object'
|
|
1989
|
-
? [...head, waits.length ? `ask waits ${waits.map((w) => `line ${w.line}: ${w.wait}`).join(', ')}` : null].filter(Boolean).join(' · ')
|
|
1990
|
-
: `${file} could not be read`;
|
|
1991
|
-
happened.push(`${version === 0 ? 'signed to run' : 'signed to resume'} (${rec?.signedBy ?? 'you'})`);
|
|
1992
|
-
rows.push(human({ at: rec?.at }, rows.length + 1, { action: `${version === 0 ? 'Sign & run' : 'Sign & resume'} (${rec?.signedBy ?? 'you'})`, gap, ...(waits.length ? { gapHead: head, gapWaits: waits } : {}) }));
|
|
1953
|
+
const versions = listRunValues(runDir);
|
|
1954
|
+
for (const e of versions) {
|
|
1955
|
+
// M20 am3 item 6: the run's own parser read this file; a version it refuses shows as that refusal, never as a signed row
|
|
1956
|
+
if (!e.ok) { rows.push(human({ at: undefined }, rows.length + 1, { action: e.red, gap: '' })); continue; } // eslint-disable-line no-continue -- a refused version is not a signed one
|
|
1957
|
+
const { version, record: rec } = e;
|
|
1958
|
+
const v = rec.values;
|
|
1959
|
+
const waits = Object.entries(v.askWaits).map(([line, wait]) => ({ line, wait: String(wait), waitMs: parseWaitMs(wait) }));
|
|
1960
|
+
const head = [`cap $${v.capUsd}`, v.destination ? `destination ${v.destination}` : null].filter(Boolean);
|
|
1961
|
+
const gap = [...head, waits.length ? `ask waits ${waits.map((w) => `line ${w.line}: ${w.wait}`).join(', ')}` : null].filter(Boolean).join(' · ');
|
|
1962
|
+
happened.push(`${version === 0 ? 'signed to run' : 'signed to resume'} (${rec.signedBy ?? 'you'})`);
|
|
1963
|
+
rows.push(human({ at: rec.at }, rows.length + 1, { action: `${version === 0 ? 'Sign & run' : 'Sign & resume'} (${rec.signedBy ?? 'you'})`, gap, ...(waits.length ? { gapHead: head, gapWaits: waits } : {}) }));
|
|
1993
1964
|
}
|
|
1994
1965
|
const lastSign = setup.present ? [...setup.rows].reverse().find((r) => r.kind === 'sign') : undefined;
|
|
1995
|
-
const humanChecks = setup.present ? setup.rows.filter((r) => r.kind === 'note' || r.kind === 'sign' || r.kind === 'revise' || r.kind === 'redraft').length + versions.length : null;
|
|
1966
|
+
const humanChecks = setup.present ? setup.rows.filter((r) => r.kind === 'note' || r.kind === 'sign' || r.kind === 'revise' || r.kind === 'redraft').length + versions.filter((e) => e.ok).length : null;
|
|
1996
1967
|
const totals = setup.present
|
|
1997
1968
|
? draftTotals(setup.rows.filter((r) => r.kind === 'draft' || r.kind === 'change' || r.kind === 'revise' || r.kind === 'redraft' || r.kind === 'startover'), { cardAt: setup.rows.find((r) => r.kind === 'card')?.at, signAt: lastSign?.at, humanChecks })
|
|
1998
1969
|
: null;
|
|
@@ -2018,9 +1989,8 @@ function attachFolds(groups, runDir, flowDir, { root, flow, catalogue }) {
|
|
|
2018
1989
|
if (job.ok) steps = job.declaration.steps ?? [];
|
|
2019
1990
|
}
|
|
2020
1991
|
// M14 am1 item 1: a rerun's own run.json holds the reason it started with; the Audit shows it on the first step, where that reason was handed
|
|
2021
|
-
const
|
|
2022
|
-
|
|
2023
|
-
let rerun = rr && typeof rr === 'object' && rr.decision === 'rerun' && typeof rr.words === 'string' ? { words: rr.words } : null;
|
|
1992
|
+
const rerunWords = readRerunWords(runDir);
|
|
1993
|
+
let rerun = rerunWords !== null ? { words: rerunWords } : null;
|
|
2024
1994
|
for (const g of groups) {
|
|
2025
1995
|
if (g.run) continue;
|
|
2026
1996
|
const decl = steps?.find((x) => x.emits === g.step);
|
|
@@ -2046,7 +2016,7 @@ export function getRunAudit({
|
|
|
2046
2016
|
const run = resolveRunPath(root, flow, runId);
|
|
2047
2017
|
if (!run.ok) return null;
|
|
2048
2018
|
if (!existsSync(run.runDir)) return null;
|
|
2049
|
-
const rawRows =
|
|
2019
|
+
const rawRows = loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue, null).auditRows;
|
|
2050
2020
|
// hamr's review #6: the Audit tab's "Action" column is derived server-side
|
|
2051
2021
|
// (never guessed client-side from partial data) — `action` is added to
|
|
2052
2022
|
// each row here, off that SAME row's own fields, book order preserved.
|
|
@@ -2213,7 +2183,7 @@ export function getRunJob({
|
|
|
2213
2183
|
// per-attempt `audit.jsonl` field the Run tab's summary uses
|
|
2214
2184
|
// (`deriveRunModel`) and says so plainly when it does, rather than
|
|
2215
2185
|
// pretending the signed prose named it.
|
|
2216
|
-
const auditRows =
|
|
2186
|
+
const auditRows = loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue, null).auditRows;
|
|
2217
2187
|
const model = deriveRunModel(auditRows);
|
|
2218
2188
|
// the run's own signed values (cap, send folder, ask waits) when it has them; the flow's own otherwise
|
|
2219
2189
|
const applied = applyRunValues(flowRead.arbiter, flow, sig.flow, pickRunValues(run.runDir));
|
|
@@ -2464,14 +2434,12 @@ function isOpenStatus(status) {
|
|
|
2464
2434
|
function deriveAskOpenFields(ask, hasHistoryRow, resume = null) {
|
|
2465
2435
|
// M4c amendment 3: an ask past its deadline reads `expired`, but one whose answer was saved in time
|
|
2466
2436
|
// (`resume` is null for a late/unreadable one, `deriveResumeState`) is still open: it can be carried on.
|
|
2467
|
-
const answerSaved = resume
|
|
2468
|
-
&& (resume.state === 'starting' || resume.state === 'not-started');
|
|
2437
|
+
const answerSaved = answerPickedUp(resume, ask.askId);
|
|
2469
2438
|
const open = (isOpenStatus(ask.status) || (ask.status === 'expired' && answerSaved)) && !hasHistoryRow;
|
|
2470
2439
|
// M4b fix: the ONE decision "is this ask waiting on the human". An open ask
|
|
2471
2440
|
// whose answer is already saved (`resume` = `deriveResumeState` for THIS
|
|
2472
2441
|
// ask, the run's own label) is open but not waiting: the human answered.
|
|
2473
|
-
const answered = open && resume
|
|
2474
|
-
&& (resume.state === 'starting' || resume.state === 'not-started');
|
|
2442
|
+
const answered = open && answerPickedUp(resume, ask.askId);
|
|
2475
2443
|
const waiting = open && !answered;
|
|
2476
2444
|
const expiresMs = waiting && typeof ask.expiresAt === 'string' ? Date.parse(ask.expiresAt) : NaN;
|
|
2477
2445
|
return {
|
|
@@ -2493,7 +2461,7 @@ function deriveAskOpenFields(ask, hasHistoryRow, resume = null) {
|
|
|
2493
2461
|
*/
|
|
2494
2462
|
function reopenOffer(ask, openAskJson, resume, lateAnswerSaved = false) {
|
|
2495
2463
|
if (!openAskJson || openAskJson.askId !== ask.askId || ask.status !== 'expired') return null;
|
|
2496
|
-
if (resume
|
|
2464
|
+
if (answerPickedUp(resume, ask.askId)) return null;
|
|
2497
2465
|
// `late`: an answer was saved but came after the deadline (the page says so, instead of "nobody answered");
|
|
2498
2466
|
// `why` is that line, the one the Ask tab and the Inbox row both draw.
|
|
2499
2467
|
return Number.isFinite(openAskJson.waitMs)
|
|
@@ -2545,13 +2513,6 @@ function normalizeArchivedRow(a) {
|
|
|
2545
2513
|
};
|
|
2546
2514
|
}
|
|
2547
2515
|
|
|
2548
|
-
/** `^answer\.<askId>\.consumed\.json$` — deliberately excludes
|
|
2549
|
-
* `answer.stale.<n>.json` (no capture group would match "stale" as a real
|
|
2550
|
-
* askId; the stale-quarantine writer in `src/ask.js` uses that different
|
|
2551
|
-
* name specifically so this convention-based scan never mistakes a
|
|
2552
|
-
* quarantined stale answer for a real consumed one). */
|
|
2553
|
-
const CONSUMED_ANSWER_RE = /^answer\.(.+)\.consumed\.json$/;
|
|
2554
|
-
|
|
2555
2516
|
/** The line under an ask that ended expired though an answer was saved: the answer came too late. */
|
|
2556
2517
|
const LATE_ANSWER_WHY = 'Your answer came after the deadline.';
|
|
2557
2518
|
/** The line under an expired ask nobody answered. */
|
|
@@ -2588,12 +2549,10 @@ function legacyRunAsks(runDir, hasHistoryRow) {
|
|
|
2588
2549
|
const askJson = readAsk(runDir);
|
|
2589
2550
|
const currentAskId = askJson && typeof askJson.askId === 'string' ? askJson.askId : null;
|
|
2590
2551
|
|
|
2591
|
-
const consumedFiles = names.filter((n) =>
|
|
2552
|
+
const consumedFiles = names.filter((n) => askIdOfConsumedName(n) !== null).sort();
|
|
2592
2553
|
|
|
2593
2554
|
for (const file of consumedFiles) {
|
|
2594
|
-
const
|
|
2595
|
-
if (!match) continue; // eslint-disable-line no-continue -- filtered by the same regex above; never actually null
|
|
2596
|
-
const askId = match[1];
|
|
2555
|
+
const askId = /** @type {string} */ (askIdOfConsumedName(file));
|
|
2597
2556
|
const fileRead = readFileInside(runDir, file);
|
|
2598
2557
|
if (!fileRead.ok) {
|
|
2599
2558
|
continue; // eslint-disable-line no-continue -- missing/symlink-refused, same as a torn write: skipped, never invented
|
|
@@ -2631,7 +2590,7 @@ function legacyRunAsks(runDir, hasHistoryRow) {
|
|
|
2631
2590
|
// "still open" stop at that point, no matter what its own askId says.
|
|
2632
2591
|
if (askJson && !hasHistoryRow) {
|
|
2633
2592
|
const hasConsumed = currentAskId !== null
|
|
2634
|
-
&& consumedFiles.includes(
|
|
2593
|
+
&& consumedFiles.includes(consumedAnswerName(currentAskId));
|
|
2635
2594
|
if (!hasConsumed) {
|
|
2636
2595
|
if (currentAskId === null) {
|
|
2637
2596
|
// A genuine pre-M3 ask.json: no askId/expiresAt at all — cannot be
|
|
@@ -2685,7 +2644,7 @@ function legacyRunAsks(runDir, hasHistoryRow) {
|
|
|
2685
2644
|
* (hamr's 2026-09-27 live check).
|
|
2686
2645
|
* @returns {any[]}
|
|
2687
2646
|
*/
|
|
2688
|
-
function runAsksInOrder(runDir, hasHistoryRow, endedExpired = false, jobEdited = false) {
|
|
2647
|
+
function runAsksInOrder(runDir, hasHistoryRow, auditRows, endedExpired = false, jobEdited = false) {
|
|
2689
2648
|
const archivedResult = listArchivedAsks(runDir);
|
|
2690
2649
|
const rows = archivedResult.archived
|
|
2691
2650
|
? archivedResult.asks.map(normalizeArchivedRow)
|
|
@@ -2708,7 +2667,7 @@ function runAsksInOrder(runDir, hasHistoryRow, endedExpired = false, jobEdited =
|
|
|
2708
2667
|
// reader of which step each ask belongs to) names for it, matched to the `stopped at the ask of step N` row written for that step.
|
|
2709
2668
|
// Never by counting those rows in order: a Stop that landed before any ask parked writes one too, with no ask behind it.
|
|
2710
2669
|
if (ordered.some((a) => a.status === 'stopped')) {
|
|
2711
|
-
const words = stoppedAskWords(ordered,
|
|
2670
|
+
const words = stoppedAskWords(ordered, auditRows);
|
|
2712
2671
|
for (let i = 0; i < ordered.length; i++) {
|
|
2713
2672
|
if (ordered[i].status === 'stopped' && words[i] !== null) ordered[i] = { ...ordered[i], statusText: words[i] };
|
|
2714
2673
|
}
|
|
@@ -2860,21 +2819,20 @@ export function getRunAsks({
|
|
|
2860
2819
|
const run = resolveRunPath(root, flow, runId);
|
|
2861
2820
|
if (!run.ok) return null;
|
|
2862
2821
|
if (!existsSync(run.runDir)) return null;
|
|
2863
|
-
const
|
|
2822
|
+
const ctx = loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue, null);
|
|
2823
|
+
const histRow = ctx.historyRow ?? undefined;
|
|
2864
2824
|
const hasHistoryRow = !!histRow;
|
|
2865
2825
|
// hamr's 2026-09-27 browser-walk bug #4: the Ask tab's own asks must carry
|
|
2866
2826
|
// the SAME `open`/`timeLeftMs` fields listStops already computes for the
|
|
2867
2827
|
// Inbox — otherwise an open ask's Ask-tab header/body falls back to the
|
|
2868
2828
|
// raw status word "unanswered" and no time-left, disagreeing with the
|
|
2869
2829
|
// Inbox row for that exact same ask.
|
|
2870
|
-
const
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
const ordered = runAsksInOrder(run.runDir, hasHistoryRow, histRow?.outcome === 'ask-expired', runJobEdited(readHaltRecord(run.runDir), histRow ?? null, flowRead));
|
|
2874
|
-
const auditRows = readAudit(run.runDir);
|
|
2830
|
+
const flowRead = ctx.flowRead;
|
|
2831
|
+
const auditRows = ctx.auditRows;
|
|
2832
|
+
const ordered = runAsksInOrder(run.runDir, hasHistoryRow, auditRows, histRow?.outcome === 'ask-expired', ctx.jobEdited);
|
|
2875
2833
|
const declSteps = flowRead.ok ? flowRead.declaration.steps : null;
|
|
2876
2834
|
const stepInfo = deriveAskStepInfo(ordered, auditRows, declSteps);
|
|
2877
|
-
let resume = hasHistoryRow ? null : deriveResumeState({ savedAnswer:
|
|
2835
|
+
let resume = hasHistoryRow ? null : deriveResumeState({ savedAnswer: savedAnswerOf(run.runDir), attempt: resumeAttempt?.(flow, runId) ?? null, ask: readAsk(run.runDir) });
|
|
2878
2836
|
// M4c amendment 2: the Ask tab says what the run list says — stuck, by the one rule (`stuckState`).
|
|
2879
2837
|
let runStuckNow = false;
|
|
2880
2838
|
if (resume) {
|
|
@@ -2914,7 +2872,7 @@ export function getRunAsks({
|
|
|
2914
2872
|
const asks = ordered.map(withSheet).map(withCited).map((ask, i) => ({
|
|
2915
2873
|
...ask,
|
|
2916
2874
|
...deriveAskOpenFields(ask, hasHistoryRow, resume),
|
|
2917
|
-
reopen: reopenOffer(ask, openAskJson, resume,
|
|
2875
|
+
reopen: reopenOffer(ask, openAskJson, resume, savedAnswerOf(run.runDir)?.askId === ask.askId),
|
|
2918
2876
|
stuck: runStuckNow && resume?.askId === ask.askId,
|
|
2919
2877
|
index: i + 1,
|
|
2920
2878
|
total: ordered.length,
|
|
@@ -2954,22 +2912,21 @@ export function listStops({ root, resumeAttempt, catalogue }) {
|
|
|
2954
2912
|
const rows = [];
|
|
2955
2913
|
for (const flowName of listFlowNames(root)) {
|
|
2956
2914
|
const flowDir = join(root, flowName);
|
|
2957
|
-
const historyRows = readHistory(flowDir).filter((r) => r && typeof r.runId === 'string');
|
|
2958
2915
|
for (const runId of listRunIds(flowDir)) {
|
|
2959
2916
|
const run = resolveRunPath(root, flowName, runId);
|
|
2960
2917
|
if (!run.ok) continue;
|
|
2961
|
-
const
|
|
2918
|
+
const ctx = loadRunContext(root, flowDir, run.runDir, flowName, runId, catalogue, null);
|
|
2919
|
+
const end = ctx.historyRow;
|
|
2962
2920
|
const hasHistoryRow = end !== null;
|
|
2963
|
-
const resume = hasHistoryRow ? null : deriveResumeState({ savedAnswer:
|
|
2921
|
+
const resume = hasHistoryRow ? null : deriveResumeState({ savedAnswer: savedAnswerOf(run.runDir), attempt: resumeAttempt?.(flowName, runId) ?? null, ask: readAsk(run.runDir) });
|
|
2964
2922
|
// M4c amendment 2: stuck by the ONE rule (`stuckState`), marked on the ask whose answer is saved.
|
|
2965
2923
|
const st = runStuck(run.runDir, resume);
|
|
2966
2924
|
const stuckAskId = !hasHistoryRow && st.stuck ? (resume?.askId ?? null) : null;
|
|
2967
2925
|
const openAskJson = hasHistoryRow ? null : readAsk(run.runDir);
|
|
2968
|
-
const savedAskId =
|
|
2926
|
+
const savedAskId = savedAnswerOf(run.runDir)?.askId;
|
|
2969
2927
|
// M6 amendment 4: read the job only for a run that ended stopped / cap-halted (and only when the caller gave the catalogue to read it with)
|
|
2970
|
-
const jobEdited = end !== null && (end.outcome
|
|
2971
|
-
|
|
2972
|
-
const runAsks = runAsksInOrder(run.runDir, hasHistoryRow, end?.outcome === 'ask-expired', jobEdited).map((ask) => ({
|
|
2928
|
+
const jobEdited = end !== null && isResumableEnding(end.outcome) && catalogue !== undefined && ctx.jobEdited;
|
|
2929
|
+
const runAsks = runAsksInOrder(run.runDir, hasHistoryRow, ctx.auditRows, end?.outcome === 'ask-expired', jobEdited).map((ask) => ({
|
|
2973
2930
|
flow: flowName,
|
|
2974
2931
|
runId,
|
|
2975
2932
|
...ask,
|