fwdloop 0.12.0 → 0.14.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 +155 -27
- package/package.json +2 -2
- package/src/ask.js +3 -0
- package/src/authoring.js +135 -16
- package/src/books.js +23 -2
- package/src/canrun.js +106 -0
- package/src/catalogue.json +2 -2
- package/src/checked.js +50 -0
- package/src/closers.js +112 -91
- package/src/config.js +2 -1
- package/src/declaration.js +175 -3
- package/src/drafter.js +148 -10
- package/src/draftspend.js +70 -0
- package/src/flow.js +43 -0
- package/src/keysfile.js +4 -2
- package/src/liveness.js +1 -1
- package/src/model-step.js +31 -5
- package/src/monthly.js +195 -28
- package/src/panel/author.js +638 -0
- package/src/panel/authorcard.js +340 -0
- package/src/panel/authorflows.js +317 -0
- package/src/panel/authorresume.js +149 -0
- package/src/panel/authorstart.js +257 -0
- package/src/panel/authorvalues.js +110 -0
- package/src/panel/data.js +318 -99
- package/src/panel/index.html +2000 -330
- package/src/panel/resume.js +6 -8
- package/src/panel/server.js +122 -119
- package/src/panel/settings.js +8 -6
- package/src/panel/spawn.js +77 -0
- package/src/provider.js +12 -17
- package/src/runner.js +707 -104
- package/src/runvalues.js +178 -0
- package/src/send.js +10 -3
- package/src/setup.js +127 -0
- package/types/authoring.d.ts +56 -2
- package/types/books.d.ts +14 -2
- package/types/canrun.d.ts +64 -0
- package/types/checked.d.ts +23 -0
- package/types/closers.d.ts +47 -28
- package/types/config.d.ts +1 -0
- package/types/declaration.d.ts +23 -1
- package/types/drafter.d.ts +151 -2
- package/types/draftspend.d.ts +21 -0
- package/types/flow.d.ts +23 -0
- package/types/liveness.d.ts +2 -2
- package/types/model-step.d.ts +4 -7
- package/types/monthly.d.ts +46 -1
- package/types/panel/author.d.ts +316 -0
- package/types/panel/authorcard.d.ts +142 -0
- package/types/panel/authorflows.d.ts +175 -0
- package/types/panel/authorresume.d.ts +32 -0
- package/types/panel/authorstart.d.ts +115 -0
- package/types/panel/authorvalues.d.ts +62 -0
- package/types/panel/data.d.ts +105 -63
- package/types/panel/server.d.ts +11 -33
- package/types/panel/spawn.d.ts +30 -0
- package/types/provider.d.ts +6 -9
- package/types/runner.d.ts +129 -6
- package/types/runvalues.d.ts +97 -0
- package/types/send.d.ts +5 -1
- package/types/setup.d.ts +77 -0
package/src/panel/data.js
CHANGED
|
@@ -28,10 +28,16 @@ import {
|
|
|
28
28
|
readFlow, listFlowNames, listRunIds, resolveRunDir, checkFlowName, readFileInside, readdirInside,
|
|
29
29
|
} from '../flow.js';
|
|
30
30
|
import {
|
|
31
|
-
readAudit, readHistory, readPidRows, auditRowTokens, auditRowAt, auditRowTools,
|
|
31
|
+
readAudit, readHistory, endRow, readPidRows, auditRowTokens, auditRowAt, auditRowTools,
|
|
32
32
|
} from '../books.js';
|
|
33
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
readAsk, readRunState, readLog, readHaltRecord, stopPending,
|
|
35
|
+
} from '../runner.js';
|
|
34
36
|
import { readSpendRows } from '../provider.js';
|
|
37
|
+
import { applyRunValues, parseWaitMs, pickRunValues, VALUES_FILE_RE } from '../runvalues.js';
|
|
38
|
+
import { readSetup } from '../setup.js';
|
|
39
|
+
import { checkedLines, notCheckedBlock, NOT_CHECKED_LABEL } from '../checked.js';
|
|
40
|
+
import { MAX_STRUCTURE_RETRIES } from '../drafter.js';
|
|
35
41
|
import {
|
|
36
42
|
runLiveness, booksFresh, readResumeLock,
|
|
37
43
|
} from '../liveness.js';
|
|
@@ -170,7 +176,10 @@ export const RESUME_REASON_UNKNOWN = 'reason unknown: the panel restarted, so it
|
|
|
170
176
|
* @param {{savedAnswer: {askId:string, decision:string|null, answeredAt?:string|null}|null, attempt: any, ask?: any}} ctx
|
|
171
177
|
* @returns {{state: 'starting'|'not-started'|'broken'|'took-over', askId: string|null, tries: number|null, maxTries: number|null, reason: string|null, label: string}|null}
|
|
172
178
|
*/
|
|
173
|
-
export function deriveResumeState({ savedAnswer:
|
|
179
|
+
export function deriveResumeState({ savedAnswer: savedOnDisk, attempt, ask = null }) {
|
|
180
|
+
// An answer.json naming another ask than the open one is not this run's answer (answerAsk refuses to write one; a
|
|
181
|
+
// hand-placed file can): the run reads as what it is, waiting at the open ask. Readers never move the file.
|
|
182
|
+
const saved = savedOnDisk && ask && typeof ask.askId === 'string' && savedOnDisk.askId !== ask.askId ? null : savedOnDisk;
|
|
174
183
|
const pastDeadline = !!(ask && saved && ask.askId === saved.askId && Date.parse(ask.expiresAt) < Date.now());
|
|
175
184
|
if (saved && pastDeadline && answerTiming(saved.answeredAt, ask.expiresAt) !== 'on-time') return null;
|
|
176
185
|
const tries = attempt ? attempt.tries : null;
|
|
@@ -219,7 +228,7 @@ export const CRASHED_LABEL = 'crashed after taking your answer — start a fresh
|
|
|
219
228
|
* @type {Record<string, string>}
|
|
220
229
|
*/
|
|
221
230
|
export const SIGN_WORDS = {
|
|
222
|
-
'[▶]': 'running', '[·]': 'waiting', '[II]': 'stuck', '[!]': 'expired', '[?]': 'crashed', '[✓]': 'passed', '[✗]': 'failed',
|
|
231
|
+
'[▶]': 'running', '[·]': 'waiting', '[II]': 'stuck', '[!]': 'expired', '[?]': 'crashed', '[✓]': 'passed', '[✗]': 'failed', '[■]': 'stopped',
|
|
223
232
|
};
|
|
224
233
|
|
|
225
234
|
/**
|
|
@@ -234,7 +243,10 @@ export function signParts(glyph, label, noWord = false) {
|
|
|
234
243
|
const word = noWord ? null : (SIGN_WORDS[glyph] ?? null);
|
|
235
244
|
if (word === null) return { word: null, line: label ?? null };
|
|
236
245
|
if (typeof label !== 'string' || label === word) return { word, line: null };
|
|
237
|
-
|
|
246
|
+
if (label.startsWith(`${word} — `)) return { word, line: label.slice(word.length + 3) };
|
|
247
|
+
// amendment 16 I4: the signed words `stopped at the ask of step N` are drawn whole, never as a bold "stopped" + dash + the rest
|
|
248
|
+
if (STOPPED_AT_ASK_START_RE.test(label)) return { word: null, line: label };
|
|
249
|
+
return { word, line: label };
|
|
238
250
|
}
|
|
239
251
|
|
|
240
252
|
/** The sign an Inbox row wears (null for a past answer, which shows its status word instead). */
|
|
@@ -317,6 +329,7 @@ export function glyphPulses(g) {
|
|
|
317
329
|
* `computeGlyph`, the derivation the M4a POC proved against every real run
|
|
318
330
|
* on disk. Ladder wording (M4a scope item 4):
|
|
319
331
|
* - `[✓]` passed — a history row with `outcome:'complete'`.
|
|
332
|
+
* - `[■]` stopped (M4e amendment 4) — a history row `stopped`, or `cap-halt` with a halt record to continue from.
|
|
320
333
|
* - `[✗]` failed — a history row with any other outcome (never `[?]`).
|
|
321
334
|
* - `[·]` waiting on you — parked (`ask.json` present), no consumed answer,
|
|
322
335
|
* NOT past its own `expiresAt`.
|
|
@@ -348,14 +361,19 @@ export function glyphPulses(g) {
|
|
|
348
361
|
* A saved answer with a live process is `[▶]` working on your answer.
|
|
349
362
|
* - `[?]` crashed after taking your answer (amendment 2 (f)) — the answer was
|
|
350
363
|
* consumed, the process is gone, no end row: cannot be carried on.
|
|
351
|
-
* @param {{historyRow: any, askJson: any, consumedAnswerExists: boolean, hasStateJson: boolean, resume?: any, liveness?: 'running'|'gone'|'unknown', booksFresh?: boolean, lock?: string}} ctx
|
|
352
|
-
* @returns {{glyph: '[✓]'|'[✗]'|'[·]'|'[!]'|'[▶]'|'[?]'|'[II]', label: string}}
|
|
364
|
+
* @param {{historyRow: any, askJson: any, consumedAnswerExists: boolean, hasStateJson: boolean, resume?: any, liveness?: 'running'|'gone'|'unknown', booksFresh?: boolean, lock?: string, resumable?: boolean, stoppedAtAsk?: string|null}} ctx
|
|
365
|
+
* @returns {{glyph: '[✓]'|'[✗]'|'[·]'|'[!]'|'[▶]'|'[?]'|'[II]'|'[■]', label: string}}
|
|
353
366
|
*/
|
|
354
367
|
export function computeGlyph({
|
|
355
|
-
historyRow, askJson, consumedAnswerExists, hasStateJson, resume, liveness, booksFresh, lock,
|
|
368
|
+
historyRow, askJson, consumedAnswerExists, hasStateJson, resume, liveness, booksFresh, lock, resumable, stoppedAtAsk,
|
|
356
369
|
}) {
|
|
357
370
|
if (historyRow) {
|
|
358
371
|
if (historyRow.outcome === 'complete') return { glyph: '[✓]', label: 'passed' };
|
|
372
|
+
// 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".
|
|
373
|
+
if (historyRow.outcome === 'stopped') {
|
|
374
|
+
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' };
|
|
375
|
+
}
|
|
376
|
+
if (historyRow.outcome === 'cap-halt' && resumable) return { glyph: '[■]', label: 'stopped — the money cap was reached; raise it and Resume' };
|
|
359
377
|
// M4b amendment 3: a run the human ended on purpose with rerun is not a failure.
|
|
360
378
|
if (historyRow.outcome === 'rerun') return { glyph: '[✗]', label: 'stopped by you (rerun), a fresh run was started' };
|
|
361
379
|
// M4c-fix amendment 1 (c): a run ended because its ask expired is `[!]` expired, never failed (it spent nothing more).
|
|
@@ -641,7 +659,7 @@ export function isBlockedVerdict(verdict) {
|
|
|
641
659
|
function markForVerdict(verdict, closeClass) {
|
|
642
660
|
if (closeClass === 'hitl' && verdict === 'red') return '✗'; // the human's own redo
|
|
643
661
|
if (verdict === 'green' || verdict === 'hitl') return '✓';
|
|
644
|
-
if (verdict === 'paused' || verdict === 'refused' || verdict === 'ask-timeout' || verdict === 'ask-expired' || verdict === 'ask-reopened' || verdict === 'lock-removed') return '·';
|
|
662
|
+
if (verdict === 'paused' || verdict === 'refused' || verdict === 'ask-timeout' || verdict === 'ask-expired' || verdict === 'ask-reopened' || verdict === 'lock-removed' || verdict === 'stop-asked' || verdict === 'stopped' || verdict === 'stop-not-honoured') return '·';
|
|
645
663
|
return '✗';
|
|
646
664
|
}
|
|
647
665
|
|
|
@@ -684,22 +702,37 @@ export function deriveStepTryMarks(closeClass, rows) {
|
|
|
684
702
|
return rows.map((r) => markForVerdict(r.verdict, closeClass));
|
|
685
703
|
}
|
|
686
704
|
|
|
705
|
+
/** A Stop's notes are not tries: the asked/not-honoured rows, and a `stopped` row that cut no try (no attempt number). */
|
|
706
|
+
function isTryRow(r) {
|
|
707
|
+
return r.verdict !== 'stop-asked' && r.verdict !== 'stop-not-honoured' && !(r.verdict === 'stopped' && !Number.isInteger(r.attempt));
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
/** The name of the one group for audit rows that name no step. */
|
|
711
|
+
const RUN_GROUP = 'run';
|
|
712
|
+
/** The one decider of a row's step name for the Audit tab: its step, else the run's own group name. */
|
|
713
|
+
function auditStepName(step) {
|
|
714
|
+
return typeof step === 'string' && step.length > 0 ? step : RUN_GROUP;
|
|
715
|
+
}
|
|
716
|
+
|
|
687
717
|
/**
|
|
688
718
|
* A step group's own state word for the Audit tab's collapsed header —
|
|
689
|
-
* the
|
|
690
|
-
*
|
|
691
|
-
* be computed server-side too, off the SAME last-row-wins logic): `waiting`
|
|
719
|
+
* the ONE decider of a step's state: the Run tab's map and cards read it too
|
|
720
|
+
* (`groupState` on each step; the page keeps no rule of its own), last-row-wins: `waiting`
|
|
692
721
|
* (the run is currently parked on this step — its last attempt's verdict is
|
|
693
722
|
* `paused`/`refused`), `done` (the last attempt passed — `green`/`hitl`),
|
|
694
|
-
* `stopped` (
|
|
723
|
+
* `user-stopped` (M4e amendment 10: the step's own last row is `stopped`, a Stop
|
|
724
|
+
* the human asked), `stopped` (the last attempt failed for any other reason). A group only
|
|
695
725
|
* ever exists for a step with at least one row, so `pending` never appears
|
|
696
726
|
* here (unlike the Run tab's map, which also covers never-attempted steps).
|
|
697
727
|
* @param {Array<{verdict:string}>} rows one step's own audit rows, book order
|
|
698
|
-
* @returns {'done'|'waiting'|'stopped'}
|
|
728
|
+
* @returns {'done'|'waiting'|'stopped'|'user-stopped'}
|
|
699
729
|
*/
|
|
700
730
|
export function deriveStepGroupState(rows) {
|
|
701
|
-
|
|
731
|
+
// a Stop's notes (asked / not honoured) say nothing about the step's own state; a step with only notes reads as stopped
|
|
732
|
+
const own = rows.filter((r) => r.verdict !== 'stop-asked' && r.verdict !== 'stop-not-honoured');
|
|
733
|
+
const last = own.length > 0 ? own[own.length - 1] : rows[rows.length - 1];
|
|
702
734
|
if (last.verdict === 'paused' || last.verdict === 'refused') return 'waiting';
|
|
735
|
+
if (last.verdict === 'stopped') return 'user-stopped';
|
|
703
736
|
return (last.verdict === 'green' || last.verdict === 'hitl') ? 'done' : 'stopped';
|
|
704
737
|
}
|
|
705
738
|
|
|
@@ -731,13 +764,16 @@ export function deriveStepGroupState(rows) {
|
|
|
731
764
|
*/
|
|
732
765
|
export function deriveAuditGroups(enrichedRows) {
|
|
733
766
|
const order = [];
|
|
734
|
-
const byStep =
|
|
767
|
+
const byStep = new Map();
|
|
768
|
+
// a row naming no step (a Stop before step 1) is the run's own: one group, `run: true`, never a null id
|
|
735
769
|
for (const r of enrichedRows) {
|
|
736
|
-
|
|
737
|
-
byStep[
|
|
770
|
+
const key = typeof r.step === 'string' && r.step.length > 0 ? r.step : null;
|
|
771
|
+
if (!byStep.has(key)) { byStep.set(key, []); order.push(key); }
|
|
772
|
+
byStep.get(key).push(r);
|
|
738
773
|
}
|
|
739
|
-
return order.map((
|
|
740
|
-
const rows = byStep
|
|
774
|
+
return order.map((key) => {
|
|
775
|
+
const rows = byStep.get(key);
|
|
776
|
+
const step = auditStepName(key);
|
|
741
777
|
const closeClass = rows[0].class ?? null;
|
|
742
778
|
const timeMs = rows.reduce((acc, r) => acc + (typeof r.wallMs === 'number' ? r.wallMs : 0), 0);
|
|
743
779
|
|
|
@@ -764,7 +800,7 @@ export function deriveAuditGroups(enrichedRows) {
|
|
|
764
800
|
}
|
|
765
801
|
const tokensTotalValue = (anyNotRecorded || !anyTotal) ? null : tokensTotal;
|
|
766
802
|
|
|
767
|
-
const tryMarks = deriveStepTryMarks(closeClass, rows);
|
|
803
|
+
const tryMarks = deriveStepTryMarks(closeClass, rows.filter(isTryRow));
|
|
768
804
|
const { toolsTotal, toolsWhy, ungranted } = summarizeStepTools(rows);
|
|
769
805
|
return {
|
|
770
806
|
step,
|
|
@@ -777,8 +813,9 @@ export function deriveAuditGroups(enrichedRows) {
|
|
|
777
813
|
toolsTotal,
|
|
778
814
|
toolsWhy,
|
|
779
815
|
ungranted,
|
|
780
|
-
tryCount: tryMarks.length,
|
|
781
|
-
tryMarks,
|
|
816
|
+
tryCount: key === null ? 0 : tryMarks.length,
|
|
817
|
+
tryMarks: key === null ? [] : tryMarks,
|
|
818
|
+
...(key === null ? { run: true } : {}),
|
|
782
819
|
rows,
|
|
783
820
|
};
|
|
784
821
|
});
|
|
@@ -840,8 +877,11 @@ export function summarizeSpendRows(spendRows) {
|
|
|
840
877
|
*/
|
|
841
878
|
function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue, attempt = null) {
|
|
842
879
|
const flowRead = readFlow({ root, name: flowName, catalogue });
|
|
880
|
+
// M4e amendment 5 item 3 / amendment 4 item 6: the run's own signed values (its newest version) lie over the flow's
|
|
881
|
+
const inForce = flowRead.ok ? applyRunValues(flowRead.arbiter, flowName, flowRead.signature.flow, pickRunValues(runDir)) : null;
|
|
843
882
|
const historyRows = readHistory(flowDir);
|
|
844
|
-
const historyRow = historyRows
|
|
883
|
+
const historyRow = endRow(historyRows, runDir, runId);
|
|
884
|
+
const halt = readHaltRecord(runDir);
|
|
845
885
|
const auditRows = readAudit(runDir);
|
|
846
886
|
const spendRows = readSpendRows(join(runDir, 'spend.jsonl'));
|
|
847
887
|
const logJson = readLog(runDir);
|
|
@@ -858,7 +898,13 @@ function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue, attem
|
|
|
858
898
|
flowDir,
|
|
859
899
|
runDir,
|
|
860
900
|
flowRead,
|
|
901
|
+
// the arbiter this run executes under (the flow's own unless the run has signed values), or null when the flow does not read
|
|
902
|
+
arbiter: inForce && inForce.ok ? inForce.arbiter : (flowRead.ok ? flowRead.arbiter : null),
|
|
861
903
|
historyRow,
|
|
904
|
+
// M4e amendment 4 item 4: a cap-halted or stopped run that can be continued (`halt.json` is the runner's record)
|
|
905
|
+
resumable: halt.ok && historyRow !== null && historyRow.outcome === halt.halt.outcome,
|
|
906
|
+
// amendment 16 I4: how a stopped run was stopped, in the runner's own words (`stopped at the ask of step N`), or null (stopped after a step)
|
|
907
|
+
stoppedAtAsk: lastStoppedAtAsk(runDir, auditRows, historyRow !== null),
|
|
862
908
|
auditRows,
|
|
863
909
|
spendRows,
|
|
864
910
|
logJson,
|
|
@@ -877,6 +923,45 @@ function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue, attem
|
|
|
877
923
|
};
|
|
878
924
|
}
|
|
879
925
|
|
|
926
|
+
const STOPPED_AT_ASK_RE = /^stopped at the ask of step \d+$/;
|
|
927
|
+
const STOPPED_AT_ASK_START_RE = /^stopped at the ask of step \d+/;
|
|
928
|
+
/**
|
|
929
|
+
* The ONE reader of the words a stopped ask wears (amendment 19 3): for each ask, oldest-first, the `stopped at the ask of step N`
|
|
930
|
+
* row written for the step `deriveAskStepInfo` pairs it with, or null when the books cannot name that step (never a guess; never
|
|
931
|
+
* by counting those rows in order: a Stop that landed before any ask parked writes one too, with no ask behind it).
|
|
932
|
+
* @param {any[]} ordered `runAsksInOrder`'s asks, oldest-first @param {any[]} audit this run's audit rows
|
|
933
|
+
* @returns {(string|null)[]}
|
|
934
|
+
*/
|
|
935
|
+
function stoppedAskWords(ordered, audit) {
|
|
936
|
+
const stepOf = deriveAskStepInfo(ordered, audit, null);
|
|
937
|
+
const atAsk = audit.filter((r) => r.verdict === 'stopped' && STOPPED_AT_ASK_RE.test(String(r.gap)));
|
|
938
|
+
return ordered.map((_, i) => {
|
|
939
|
+
if (stepOf[i].step === null) return null;
|
|
940
|
+
const words = atAsk.filter((r) => r.step === stepOf[i].step).pop()?.gap;
|
|
941
|
+
return typeof words === 'string' ? words : null;
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/** What the Runs label says of a run stopped at an ask whose step the books cannot name; the Ask tab and the Inbox say the same. */
|
|
946
|
+
const STOPPED_STEP_UNKNOWN = 'stopped';
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* How a stopped run was stopped, for its Runs label: the newest `stopped` audit row, when the runner wrote its `gap` as
|
|
950
|
+
* `stopped at the ask of step N` (amendment 13's signed words) -> those words, as the Ask tab's row for that ask reads them
|
|
951
|
+
* (`stoppedAskWords`, the one reader); `stopped` alone when the step cannot be known; null for any other stop (after a step, before step 1).
|
|
952
|
+
* @param {string} runDir @param {any[]} auditRows @param {boolean} hasHistoryRow @returns {string|null}
|
|
953
|
+
*/
|
|
954
|
+
function lastStoppedAtAsk(runDir, auditRows, hasHistoryRow) {
|
|
955
|
+
const stopped = auditRows.filter((r) => r.verdict === 'stopped' && typeof r.gap === 'string' && !Number.isInteger(r.attempt));
|
|
956
|
+
const last = stopped.length > 0 ? stopped[stopped.length - 1] : null;
|
|
957
|
+
if (!last || !STOPPED_AT_ASK_RE.test(last.gap)) return null;
|
|
958
|
+
const ordered = runAsksInOrder(runDir, hasHistoryRow);
|
|
959
|
+
const stepOf = deriveAskStepInfo(ordered, auditRows, null);
|
|
960
|
+
const words = stoppedAskWords(ordered, auditRows);
|
|
961
|
+
const i = stepOf.findIndex((x) => x.step !== null && x.step === last.step);
|
|
962
|
+
return i >= 0 && words[i] !== null ? words[i] : STOPPED_STEP_UNKNOWN;
|
|
963
|
+
}
|
|
964
|
+
|
|
880
965
|
/** @param {string} runDir @returns {string|null} */
|
|
881
966
|
function lastPidStartedAt(runDir) {
|
|
882
967
|
const rows = readPidRows(runDir);
|
|
@@ -890,6 +975,46 @@ const RUNNING_WHY = 'still running — not finished yet';
|
|
|
890
975
|
/** @param {any} ctx @param {string} glyph */
|
|
891
976
|
const isRunningNow = (ctx, glyph) => !ctx.historyRow && glyph === '[▶]';
|
|
892
977
|
|
|
978
|
+
/**
|
|
979
|
+
* M4e amendment 4 item 4: the ONE decision for the Run tab's Stop and Resume buttons (the Stop and Resume doors read the
|
|
980
|
+
* same object, so the page never offers what the door would refuse). `running` is the glyph's own rule (`isRunningNow`);
|
|
981
|
+
* a run with no process record yet is `starting`; a parked run (`[·]`/`[!]`, an open ask) is neither.
|
|
982
|
+
* @param {any} ctx `loadRunContext`'s result @param {string} glyph `computeGlyph`'s sign
|
|
983
|
+
* @returns {{canStop: boolean, atAsk: boolean, stopRequested: boolean, starting: boolean, canResume: boolean, resumeOutcome: string|null, spentUsd: number|null, spendComplete: boolean|null, capUsd: number|null}}
|
|
984
|
+
*/
|
|
985
|
+
export function runControls(ctx, glyph, label = '') {
|
|
986
|
+
const running = isRunningNow(ctx, glyph) && !ctx.askJson;
|
|
987
|
+
// M4e amendment 13: a run waiting at its ask (open, unanswered, not expired) shows Stop too; it stops the run at the ask.
|
|
988
|
+
const atAsk = !ctx.historyRow && !!ctx.askJson && glyph === '[·]' && label === WAITING_LABEL;
|
|
989
|
+
const starting = !ctx.historyRow && !ctx.askJson && readPidRows(ctx.runDir).length === 0;
|
|
990
|
+
const canResume = ctx.resumable === true;
|
|
991
|
+
return {
|
|
992
|
+
canStop: running || atAsk,
|
|
993
|
+
atAsk,
|
|
994
|
+
stopRequested: running && stopPending(ctx.runDir),
|
|
995
|
+
starting,
|
|
996
|
+
canResume,
|
|
997
|
+
resumeOutcome: canResume ? ctx.historyRow.outcome : null,
|
|
998
|
+
spentUsd: canResume && typeof ctx.historyRow.spentUsd === 'number' ? ctx.historyRow.spentUsd : null,
|
|
999
|
+
spendComplete: canResume ? ctx.historyRow.spendComplete !== false : null,
|
|
1000
|
+
capUsd: canResume && typeof ctx.historyRow.capUsd === 'number' ? ctx.historyRow.capUsd : null,
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* `runControls` for one run read straight from the books (the Stop door's own read). `null` when the run does not resolve.
|
|
1006
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
1007
|
+
*/
|
|
1008
|
+
export function getRunControls({
|
|
1009
|
+
root, flow, runId, catalogue,
|
|
1010
|
+
}) {
|
|
1011
|
+
const run = resolveRunPath(root, flow, runId);
|
|
1012
|
+
if (!run.ok || !existsSync(run.runDir)) return null;
|
|
1013
|
+
const ctx = loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue, null);
|
|
1014
|
+
const g = computeGlyph(ctx);
|
|
1015
|
+
return runControls(ctx, g.glyph, g.label);
|
|
1016
|
+
}
|
|
1017
|
+
|
|
893
1018
|
/**
|
|
894
1019
|
* `GET /api/runs` — every flow under `root`, every run under each flow
|
|
895
1020
|
* (M4a scope item 2). A flow with zero runs still gets one row (`runId:
|
|
@@ -952,6 +1077,7 @@ export function listRuns({ root, catalogue, resumeAttempt }) {
|
|
|
952
1077
|
...signParts(glyph, label, ctx.historyRow?.outcome === 'rerun'),
|
|
953
1078
|
pulse: glyphPulses({ glyph, label }),
|
|
954
1079
|
stuck: glyph === '[II]',
|
|
1080
|
+
controls: runControls(ctx, glyph, label),
|
|
955
1081
|
resume: ctx.resume,
|
|
956
1082
|
spend,
|
|
957
1083
|
spendWhy: (!ctx.historyRow && spend === null)
|
|
@@ -961,6 +1087,7 @@ export function listRuns({ root, catalogue, resumeAttempt }) {
|
|
|
961
1087
|
waitingAskId: waitingAsk ? waitingAsk.ask.askId : null,
|
|
962
1088
|
timeLeftMs: waitingAsk ? waitingAsk.timeLeftMs : null,
|
|
963
1089
|
at: ctx.historyRow ? ctx.historyRow.at : null,
|
|
1090
|
+
wallMs: ctx.historyRow && typeof ctx.historyRow.wallMs === 'number' ? ctx.historyRow.wallMs : null,
|
|
964
1091
|
askedAt,
|
|
965
1092
|
startedAt: isRunningNow(ctx, glyph) ? ctx.startedAt : null,
|
|
966
1093
|
atWhy: (ctx.historyRow || askedAt) ? null
|
|
@@ -1023,6 +1150,7 @@ export function orderRuns(rows) {
|
|
|
1023
1150
|
function enrichAuditRows(rawRows) {
|
|
1024
1151
|
return rawRows.map((row) => ({
|
|
1025
1152
|
...row,
|
|
1153
|
+
stepName: auditStepName(row.step),
|
|
1026
1154
|
action: deriveAuditAction(row),
|
|
1027
1155
|
tokensDisplay: deriveAuditTokensDisplay(row),
|
|
1028
1156
|
toolsPhrase: deriveAuditToolsPhrase(row),
|
|
@@ -1042,11 +1170,12 @@ function enrichAuditRows(rawRows) {
|
|
|
1042
1170
|
* pairing at all — each row IS one model attempt, so try N stays
|
|
1043
1171
|
* `list.length` there, unchanged from before this fix.
|
|
1044
1172
|
* @param {string|null} closeClass
|
|
1045
|
-
* @param {Array<{verdict:string}>}
|
|
1173
|
+
* @param {Array<{verdict:string}>} listAll
|
|
1046
1174
|
* @returns {number}
|
|
1047
1175
|
*/
|
|
1048
|
-
function computeTryCount(closeClass,
|
|
1049
|
-
|
|
1176
|
+
function computeTryCount(closeClass, listAll) {
|
|
1177
|
+
const list = (listAll ?? []).filter(isTryRow);
|
|
1178
|
+
if (!list.length) return 0;
|
|
1050
1179
|
if (closeClass === 'hitl') {
|
|
1051
1180
|
const pausedCount = list.filter((a) => a.verdict === 'paused').length;
|
|
1052
1181
|
// No paused row at all is not a shape this step ever produces in
|
|
@@ -1209,6 +1338,9 @@ export function getRunDetail({
|
|
|
1209
1338
|
// M4b amendment 3: the human ended this run on purpose; an earlier redo's
|
|
1210
1339
|
// audit row is not "why it stopped".
|
|
1211
1340
|
stopReasonWhy = 'stopped by you (rerun), a fresh run was started — there is no failure to show';
|
|
1341
|
+
} else if (ctx.historyRow && ctx.historyRow.outcome === 'stopped') {
|
|
1342
|
+
// M4e amendment 4: the human's Stop is not a failure on any step; no step card carries it.
|
|
1343
|
+
stopReasonWhy = typeof ctx.logJson?.red === 'string' && ctx.logJson.red.length > 0 ? ctx.logJson.red : 'stopped by you';
|
|
1212
1344
|
} else if (ctx.resume && (ctx.resume.state === 'starting' || ctx.resume.state === 'not-started')) {
|
|
1213
1345
|
// M4b amendment 1: the human already answered — never "waiting on you".
|
|
1214
1346
|
stopReasonWhy = ctx.resume.reason ? `${ctx.resume.label}: ${ctx.resume.reason}` : ctx.resume.label;
|
|
@@ -1287,10 +1419,11 @@ export function getRunDetail({
|
|
|
1287
1419
|
...signParts(glyph, label, ctx.historyRow?.outcome === 'rerun'),
|
|
1288
1420
|
signWords: SIGN_WORDS,
|
|
1289
1421
|
pulse: glyphPulses({ glyph, label }),
|
|
1422
|
+
controls: runControls(ctx, glyph, label),
|
|
1290
1423
|
resume: ctx.resume,
|
|
1291
1424
|
outcome: ctx.historyRow ? ctx.historyRow.outcome : null,
|
|
1292
1425
|
outcomeWhy: ctx.historyRow ? null : (isRunningNow(ctx, glyph) ? RUNNING_WHY : 'no history row (parked or died before completion)'),
|
|
1293
|
-
capUsd: ctx.historyRow ? ctx.historyRow.capUsd : (ctx.
|
|
1426
|
+
capUsd: ctx.historyRow ? ctx.historyRow.capUsd : (ctx.arbiter ? ctx.arbiter.capUsd : null),
|
|
1294
1427
|
spend,
|
|
1295
1428
|
model,
|
|
1296
1429
|
modelWhy,
|
|
@@ -1299,6 +1432,8 @@ export function getRunDetail({
|
|
|
1299
1432
|
wallMsWhy,
|
|
1300
1433
|
steps,
|
|
1301
1434
|
stepsWhy,
|
|
1435
|
+
// M4e amendment 7 item 2: the Draft is the run's first step on the Map and under it — one summary, read from the same function the Audit group uses
|
|
1436
|
+
draft: ((b) => ({ ...b.summary, rows: b.rows }))(getDraftBlock(ctx.flowDir, ctx.runDir)),
|
|
1302
1437
|
modelWrote,
|
|
1303
1438
|
modelWroteWhy,
|
|
1304
1439
|
stopReason,
|
|
@@ -1319,6 +1454,116 @@ export function getRunDetail({
|
|
|
1319
1454
|
};
|
|
1320
1455
|
}
|
|
1321
1456
|
|
|
1457
|
+
/** The words the Draft says for a flow with no `setup.jsonl` (M4e amendment 6 item 4; renamed Draft by amendment 7 item 2). */
|
|
1458
|
+
export const NO_DRAFT_WORDS = 'no draft record';
|
|
1459
|
+
|
|
1460
|
+
/**
|
|
1461
|
+
* What the Draft adds up to, ONE place (the Map box, the first step card and the Audit group all read it, so the three can never disagree).
|
|
1462
|
+
* M4e amendment 9: `timeMs` is the card row's `at` to the sign row's `at` (the whole drafting, human time included), `null` when either has no
|
|
1463
|
+
* usable `at`; never a sum of the model rows' `wallMs`. `calls` sums the rows' `calls`, a row with none counts 1 and sets `callsAtLeast`, so an
|
|
1464
|
+
* unknown never shows as a smaller exact number; no model rows = `null`. `humanChecks` = the note rows + the revise rows (each is the card the human edited and sent) + the sign row + the run's signed-values
|
|
1465
|
+
* rows (the card is not a check), given by the caller as `ctx.humanChecks`. Money follows `costDisplay` ("at least $X" for a floor).
|
|
1466
|
+
* @param {any[]} modelRows the draft and change rows (`kind` draft | change) of `setup.jsonl`
|
|
1467
|
+
* @param {{cardAt?: any, signAt?: any, humanChecks?: number|null}} [ctx]
|
|
1468
|
+
* @returns {{calls: number|null, callsAtLeast: boolean, timeMs: number|null, humanChecks: number|null, usd: number|null, spendComplete: boolean, cost: string|null, modelRows: number}}
|
|
1469
|
+
*/
|
|
1470
|
+
export function draftTotals(modelRows, ctx = {}) {
|
|
1471
|
+
const priced = modelRows.filter((r) => typeof r.costUsd === 'number');
|
|
1472
|
+
const usd = priced.length > 0 ? priced.reduce((a, r) => a + r.costUsd, 0) : null;
|
|
1473
|
+
const spendComplete = modelRows.length > 0 && priced.length === modelRows.length && modelRows.every((r) => r.spendComplete === true);
|
|
1474
|
+
const cd = usd === null ? null : costDisplay(usd, spendComplete);
|
|
1475
|
+
const t0 = typeof ctx.cardAt === 'string' ? Date.parse(ctx.cardAt) : NaN;
|
|
1476
|
+
const t1 = typeof ctx.signAt === 'string' ? Date.parse(ctx.signAt) : NaN;
|
|
1477
|
+
const timeMs = Number.isFinite(t0) && Number.isFinite(t1) && t1 >= t0 ? t1 - t0 : null;
|
|
1478
|
+
const calls = modelRows.length > 0 ? modelRows.reduce((a, r) => a + (typeof r.calls === 'number' ? r.calls : 1), 0) : null;
|
|
1479
|
+
return {
|
|
1480
|
+
calls, callsAtLeast: modelRows.some((r) => typeof r.calls !== 'number'), timeMs,
|
|
1481
|
+
humanChecks: typeof ctx.humanChecks === 'number' && Number.isInteger(ctx.humanChecks) ? ctx.humanChecks : null,
|
|
1482
|
+
usd, spendComplete, cost: cd && cd.ok ? cd.display : null, modelRows: modelRows.length,
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
/**
|
|
1487
|
+
* M4e amendment 6 item 4 / amendment 7 item 2: the Draft of a run — the flow's own `setup.jsonl` (card, drafts, changes, notes, sign), then this
|
|
1488
|
+
* run's own signed-values rows (amendment 5: "Sign & run" for version 0, "Sign & resume" for a later version), every row in the SAME shape
|
|
1489
|
+
* as the run's audit rows so the page draws both with one row builder. Reads only through the safe gateways; never throws.
|
|
1490
|
+
* @param {string} flowDir @param {string} runDir
|
|
1491
|
+
* @returns {{present: boolean, why: string|null, rows: any[], summary: {present: boolean, why?: string, calls?: number|null, callsAtLeast?: boolean, humanChecks?: number|null, timeMs?: number|null, usd?: number|null, spendComplete?: boolean, cost?: string|null, modelRows?: number}}}
|
|
1492
|
+
*/
|
|
1493
|
+
export function getDraftBlock(flowDir, runDir) {
|
|
1494
|
+
const setup = readSetup(flowDir);
|
|
1495
|
+
const rows = [];
|
|
1496
|
+
const human = (r, attempt, extra) => ({
|
|
1497
|
+
attempt, step: 'drafting', class: 'hitl', verdict: 'hitl', at: r.at ?? null, setup: true, blocked: false, action: 'human', tokensDisplay: { kind: 'no-model' }, ...extra,
|
|
1498
|
+
});
|
|
1499
|
+
const model = (r, attempt, label) => ({
|
|
1500
|
+
attempt, step: 'drafting', class: null, verdict: r.verdict === 'green' ? 'green' : (r.verdict === 'red' ? 'red' : 'not-done'), gap: r.gap ?? '', at: r.at ?? null, setup: true, blocked: false,
|
|
1501
|
+
action: `${label} · ${r.model ?? 'model not recorded'}${r.hash ? ` · plan ${String(r.hash).slice(0, 8)}` : ''}`,
|
|
1502
|
+
usd: typeof r.costUsd === 'number' ? r.costUsd : undefined, spendComplete: r.spendComplete === true, tokensDisplay: { kind: 'no-model' },
|
|
1503
|
+
...(typeof r.wallMs === 'number' ? { wallMs: r.wallMs } : {}),
|
|
1504
|
+
});
|
|
1505
|
+
// M4e amendment 8 item 1, line 4: one short phrase per Draft row, in order (the drafting card joins them with ` · `)
|
|
1506
|
+
const happened = [];
|
|
1507
|
+
const retry = (r) => (Number.isInteger(r.structureRetries) && r.structureRetries >= 1 ? ` (retry ${r.structureRetries} of ${MAX_STRUCTURE_RETRIES})` : '');
|
|
1508
|
+
if (setup.present) {
|
|
1509
|
+
setup.rows.forEach((r, i) => {
|
|
1510
|
+
const n = i + 1;
|
|
1511
|
+
if (r.kind === 'card') happened.push('your card');
|
|
1512
|
+
else if (r.kind === 'note') happened.push('your note');
|
|
1513
|
+
else if (r.kind === 'draft') happened.push(r.verdict === 'green' ? `drafting${retry(r)}` : 'draft red');
|
|
1514
|
+
else if (r.kind === 'change') happened.push(r.verdict === 'red' ? 'change red' : `changing${retry(r)}`);
|
|
1515
|
+
else if (r.kind === 'startover') happened.push(r.verdict === 'green' ? `starting over${retry(r)}` : 'start over red');
|
|
1516
|
+
else if (r.kind === 'revise') happened.push(r.verdict === 'red' ? 'revise red' : `revising${retry(r)}`);
|
|
1517
|
+
else if (r.kind === 'redraft') happened.push(r.verdict === 'red' ? 'redraft red' : `redrafting with your answers${retry(r)}`);
|
|
1518
|
+
else if (r.kind === 'sign') happened.push(`signed (${r.signedBy ?? 'you'})`);
|
|
1519
|
+
if (r.kind === 'card') {
|
|
1520
|
+
const c = r.card && typeof r.card === 'object' ? r.card : {};
|
|
1521
|
+
const gap = [`flow ${c.flowName ?? '?'}`, `cap $${c.capUsd ?? '?'}`, c.destination ? `destination ${c.destination}` : null, c.askWait ? `ask wait ${c.askWait}` : null,
|
|
1522
|
+
typeof c.inputs === 'string' && c.inputs.trim() ? `inputs: ${c.inputs.trim().replace(/\n+/g, ' / ')}` : null, `job: ${String(c.job ?? '').trim().replace(/\n+/g, ' / ')}`].filter(Boolean).join(' · ');
|
|
1523
|
+
rows.push(human(r, n, { action: 'card (you)', gap }));
|
|
1524
|
+
} else if (r.kind === 'note') rows.push(human(r, n, { action: 'note (you)', gap: String(r.text ?? '') }));
|
|
1525
|
+
else if (r.kind === 'draft') rows.push(model(r, n, 'draft'));
|
|
1526
|
+
else if (r.kind === 'change') rows.push(model(r, n, `change ${r.n}`));
|
|
1527
|
+
else if (r.kind === 'startover') rows.push(model(r, n, 'start over'));
|
|
1528
|
+
else if (r.kind === 'revise') rows.push(model(r, n, `revise ${r.n}`));
|
|
1529
|
+
else if (r.kind === 'redraft') rows.push(model(r, n, `answers redraft ${r.n}`));
|
|
1530
|
+
else if (r.kind === 'sign') rows.push(human(r, n, { action: `sign (${r.signedBy ?? 'you'})`, gap: `plan ${String(r.hash ?? '').slice(0, 12)}` }));
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
const versions = [];
|
|
1534
|
+
for (const f of readdirInside(runDir, '.')) {
|
|
1535
|
+
const m = VALUES_FILE_RE.exec(f);
|
|
1536
|
+
if (m !== null) versions.push({ file: f, version: m[1] === undefined ? 0 : Number(m[1]) });
|
|
1537
|
+
}
|
|
1538
|
+
versions.sort((a, b) => a.version - b.version);
|
|
1539
|
+
for (const { file, version } of versions) {
|
|
1540
|
+
const t = readFileInside(runDir, file);
|
|
1541
|
+
let rec = null;
|
|
1542
|
+
try { rec = t.ok ? JSON.parse(t.text) : null; } catch { rec = null; }
|
|
1543
|
+
const v = rec && typeof rec === 'object' ? rec.values : null;
|
|
1544
|
+
const waits = v && typeof v === 'object' && v.askWaits && typeof v.askWaits === 'object'
|
|
1545
|
+
? Object.entries(v.askWaits).map(([line, wait]) => ({ line, wait: String(wait), waitMs: parseWaitMs(wait) })) : [];
|
|
1546
|
+
const head = v && typeof v === 'object' ? [`cap $${v.capUsd}`, v.destination ? `destination ${v.destination}` : null].filter(Boolean) : [];
|
|
1547
|
+
const gap = v && typeof v === 'object'
|
|
1548
|
+
? [...head, waits.length ? `ask waits ${waits.map((w) => `line ${w.line}: ${w.wait}`).join(', ')}` : null].filter(Boolean).join(' · ')
|
|
1549
|
+
: `${file} could not be read`;
|
|
1550
|
+
happened.push(`${version === 0 ? 'signed to run' : 'signed to resume'} (${rec?.signedBy ?? 'you'})`);
|
|
1551
|
+
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 } : {}) }));
|
|
1552
|
+
}
|
|
1553
|
+
const lastSign = setup.present ? [...setup.rows].reverse().find((r) => r.kind === 'sign') : undefined;
|
|
1554
|
+
const humanChecks = setup.present ? setup.rows.filter((r) => r.kind === 'note' || r.kind === 'sign' || r.kind === 'revise' || r.kind === 'redraft').length + versions.length : null;
|
|
1555
|
+
const totals = setup.present
|
|
1556
|
+
? 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 })
|
|
1557
|
+
: null;
|
|
1558
|
+
// the group the Audit tab draws as a normal card (collapsed by default) and the box the Map and the first step card read
|
|
1559
|
+
// `ended` = how the drafting ended: `done` only with a sign row, else `not signed` (no `red` state: a red change shows on line 4 only)
|
|
1560
|
+
const ended = setup.present && setup.rows.some((r) => r.kind === 'sign') ? 'done' : 'not signed';
|
|
1561
|
+
const summary = setup.present && totals ? { present: true, ...totals, ended, happened } : { present: false, why: NO_DRAFT_WORDS };
|
|
1562
|
+
return {
|
|
1563
|
+
present: setup.present, why: setup.present ? null : NO_DRAFT_WORDS, rows, summary,
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1322
1567
|
/**
|
|
1323
1568
|
* `GET /api/runs/:flow/:runId/audit` — the Audit/logs tab (M4a scope item
|
|
1324
1569
|
* 2): the raw `audit.jsonl` rows, scoped strictly to this run (each run's
|
|
@@ -1326,7 +1571,7 @@ export function getRunDetail({
|
|
|
1326
1571
|
* shared-sidecar contamination risk here the way bareloop's gate-audit
|
|
1327
1572
|
* sidecar had). `null` when the flow/runId doesn't resolve (404).
|
|
1328
1573
|
* @param {{root: string, flow: string, runId: string}} opts
|
|
1329
|
-
* @returns {{flow:string, runId:string, rows:any[], groups:any[], empty:boolean, why:string|null}|null}
|
|
1574
|
+
* @returns {{flow:string, runId:string, rows:any[], groups:any[], draft:ReturnType<typeof getDraftBlock>, empty:boolean, why:string|null}|null}
|
|
1330
1575
|
*/
|
|
1331
1576
|
export function getRunAudit({ root, flow, runId }) {
|
|
1332
1577
|
const run = resolveRunPath(root, flow, runId);
|
|
@@ -1348,72 +1593,39 @@ export function getRunAudit({ root, flow, runId }) {
|
|
|
1348
1593
|
// step header pieces, computed here off these SAME enriched rows —
|
|
1349
1594
|
// never a second, client-side re-grouping.
|
|
1350
1595
|
groups: deriveAuditGroups(rows),
|
|
1596
|
+
draft: getDraftBlock(run.flowDir, run.runDir),
|
|
1351
1597
|
empty: rows.length === 0,
|
|
1352
1598
|
why: rows.length === 0 ? 'audit.jsonl is empty or missing — no attempt has been made yet' : null,
|
|
1353
1599
|
};
|
|
1354
1600
|
}
|
|
1355
1601
|
|
|
1356
1602
|
/**
|
|
1357
|
-
*
|
|
1358
|
-
*
|
|
1359
|
-
*
|
|
1360
|
-
*
|
|
1361
|
-
*
|
|
1362
|
-
* multi-source provenance chain to resolve (unlike bareloop's `getRunJob` —
|
|
1363
|
-
* DROPPED per the fit-check). `runId` is only used to confirm the run
|
|
1364
|
-
* exists at all; `null` when it doesn't (404).
|
|
1365
|
-
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
1366
|
-
* @returns {any|null}
|
|
1367
|
-
*/
|
|
1368
|
-
/**
|
|
1369
|
-
* hamr's 2026-09-27 exit-check review #5: one plain-words sentence for a
|
|
1370
|
-
* declared step's own close rule — the Job tab's "Success" field. Derived
|
|
1371
|
-
* STRICTLY from `step.close` (and, for the "your accept" wording, whether
|
|
1372
|
-
* this step is the one line `arbiter.asks[]` itself binds to) — never a
|
|
1373
|
-
* fabricated cite/shape value:
|
|
1374
|
-
* - `hitl`: "human check", or "human check (your accept)" when this step's
|
|
1375
|
-
* own `fromLine` is a signed ask line (the ask step itself — the one a
|
|
1376
|
-
* human pauses a run on, distinct from an ordinary hitl pass-through
|
|
1377
|
-
* step with no ask binding).
|
|
1378
|
-
* - `softgreen`: "shape: N headings (a / b / c)" when `close.shape.sections`
|
|
1379
|
-
* is signed, "max W words" appended when `close.shape.maxWords` is
|
|
1380
|
-
* signed, "blocks of L lines" / "must carry: a, b" for the invoice-block
|
|
1381
|
-
* shape keys (`linesPerInvoice`/`mustCarry`) — every signed shape key
|
|
1382
|
-
* shown, nothing invented; "shape (no shape rules signed)" when a
|
|
1383
|
-
* softgreen step signs no `close.shape` at all (declaration.js allows
|
|
1384
|
-
* this — an empty/absent shape is not itself a red).
|
|
1385
|
-
* - `green`: "cited" — `CLOSE_ALLOWED` (`src/declaration.js`) never lets a
|
|
1386
|
-
* step declare WHAT it cites ahead of time (that's the drafted
|
|
1387
|
-
* artifact's own per-run field data, not signed prose), so there is
|
|
1388
|
-
* never anything honest to append here.
|
|
1389
|
-
* - anything else: the raw class name, named as unknown, never silently
|
|
1390
|
-
* dropped or guessed into one of the three above; no class at all names
|
|
1391
|
-
* that plainly too.
|
|
1392
|
-
* @param {{close?: {class?: string, shape?: any}, fromLine?: number|null}} step one `declaration.steps` entry
|
|
1393
|
-
* @param {Array<{line:number}>} arbiterAsks `arbiter.asks`, for the "your accept" check
|
|
1394
|
-
* @returns {string}
|
|
1603
|
+
* M4e amendment 34: the signed plan as the Job tab shows it. One row per declared step: the job line it came from, what it reads, what it makes, the
|
|
1604
|
+
* primitives it may use (an ask step grants none), its check (the `checkedLines` sentences, the same words the human saw at sign) and, for the step a
|
|
1605
|
+
* signed ask binds to, that ask's wait. "Not checked" comes from the sign row of the flow's setup.jsonl: `recorded:false` (and no items) for a flow
|
|
1606
|
+
* signed before amendment 36, which the page says in words; never an empty list read as "nothing".
|
|
1607
|
+
* @param {any} declaration @param {Array<{line:number, ttlMs?:number}>} asks @param {string} flowDir
|
|
1395
1608
|
*/
|
|
1396
|
-
|
|
1397
|
-
const
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
}
|
|
1416
|
-
return `unknown close class "${cls}"`;
|
|
1609
|
+
function buildJobPlan(declaration, asks, flowDir) {
|
|
1610
|
+
const lines = checkedLines(declaration, { hasAsk: asks.length > 0 });
|
|
1611
|
+
const steps = (Array.isArray(declaration?.steps) ? declaration.steps : []).map((st, i) => {
|
|
1612
|
+
const ak = asks.find((x) => x.line === st.fromLine);
|
|
1613
|
+
return {
|
|
1614
|
+
step: i + 1,
|
|
1615
|
+
line: Number.isInteger(st.fromLine) ? st.fromLine : null,
|
|
1616
|
+
reads: Array.isArray(st.reads) ? st.reads : [],
|
|
1617
|
+
makes: typeof st.emits === 'string' ? st.emits : null,
|
|
1618
|
+
mayDo: Array.isArray(st.primitives) ? st.primitives : [],
|
|
1619
|
+
check: lines[i].sentences,
|
|
1620
|
+
checkClass: lines[i].class,
|
|
1621
|
+
ask: !!ak,
|
|
1622
|
+
waitMs: ak && typeof ak.ttlMs === 'number' ? ak.ttlMs : null,
|
|
1623
|
+
};
|
|
1624
|
+
});
|
|
1625
|
+
const setup = readSetup(flowDir);
|
|
1626
|
+
const nc = setup.present ? setup.rows.find((r) => r.kind === 'sign')?.notChecked : undefined;
|
|
1627
|
+
const recorded = !!nc && Array.isArray(nc.items);
|
|
1628
|
+
return { steps, notChecked: { label: NOT_CHECKED_LABEL, items: recorded ? notCheckedBlock(nc.items).items : [], recorded } };
|
|
1417
1629
|
}
|
|
1418
1630
|
|
|
1419
1631
|
/**
|
|
@@ -1424,8 +1636,7 @@ export function deriveStepSuccessText(step, arbiterAsks) {
|
|
|
1424
1636
|
* signature.json/prose lines — nothing invented; a piece the books can't
|
|
1425
1637
|
* name carries its own why, never a blank or a guess. Field order (server
|
|
1426
1638
|
* order matches the page's own render order): prose, asks, model, cap
|
|
1427
|
-
* (+redo cap), sources, sends, guardrails,
|
|
1428
|
-
* `deriveStepSuccessText`), signature.
|
|
1639
|
+
* (+redo cap), sources, sends, guardrails, plan (one row per step, amendment 34), signature.
|
|
1429
1640
|
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
1430
1641
|
* @returns {any|null}
|
|
1431
1642
|
*/
|
|
@@ -1451,11 +1662,12 @@ export function getRunJob({
|
|
|
1451
1662
|
// pretending the signed prose named it.
|
|
1452
1663
|
const auditRows = readAudit(run.runDir);
|
|
1453
1664
|
const model = deriveRunModel(auditRows);
|
|
1454
|
-
|
|
1665
|
+
// the run's own signed values (cap, send folder, ask waits) when it has them; the flow's own otherwise
|
|
1666
|
+
const applied = applyRunValues(flowRead.arbiter, flow, sig.flow, pickRunValues(run.runDir));
|
|
1667
|
+
const a = (applied.ok ? applied.arbiter : flowRead.arbiter) ?? {};
|
|
1455
1668
|
const asks = a.asks ?? [];
|
|
1456
1669
|
const sends = a.sends ?? [];
|
|
1457
1670
|
const sources = a.sources ?? [];
|
|
1458
|
-
const declSteps = Array.isArray(flowRead.declaration?.steps) ? flowRead.declaration.steps : [];
|
|
1459
1671
|
return {
|
|
1460
1672
|
flow,
|
|
1461
1673
|
runId,
|
|
@@ -1489,8 +1701,7 @@ export function getRunJob({
|
|
|
1489
1701
|
guardrails: flowRead.lines
|
|
1490
1702
|
.filter((l) => typeof l.guardrail === 'string' && l.guardrail.length > 0)
|
|
1491
1703
|
.map((l) => ({ line: l.n, guardrail: l.guardrail })),
|
|
1492
|
-
|
|
1493
|
-
success: declSteps.map((s) => ({ step: s.emits, text: deriveStepSuccessText(s, asks) })),
|
|
1704
|
+
plan: buildJobPlan(flowRead.declaration, asks, run.flowDir),
|
|
1494
1705
|
signature: (sig && typeof sig.signedBy === 'string' && typeof sig.signedAt === 'string' && typeof sig.flow === 'string')
|
|
1495
1706
|
? { signedBy: sig.signedBy, signedAt: sig.signedAt, hash: sig.flow }
|
|
1496
1707
|
: null,
|
|
@@ -1793,6 +2004,15 @@ function runAsksInOrder(runDir, hasHistoryRow, endedExpired = false) {
|
|
|
1793
2004
|
.map(({ row }) => row);
|
|
1794
2005
|
// M4c-fix amendment 1 (c): a run ended because its ask expired reads expired, never accepted. The late answer the
|
|
1795
2006
|
// terminal resume consumed was refused, so the newest ask carries `expired` (and says why), not the answer's word.
|
|
2007
|
+
// amendment 17 1A: an ask a Stop set aside takes its words from its OWN place in the run: the step `deriveAskStepInfo` (the one
|
|
2008
|
+
// 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.
|
|
2009
|
+
// Never by counting those rows in order: a Stop that landed before any ask parked writes one too, with no ask behind it.
|
|
2010
|
+
if (ordered.some((a) => a.status === 'stopped')) {
|
|
2011
|
+
const words = stoppedAskWords(ordered, readAudit(runDir));
|
|
2012
|
+
for (let i = 0; i < ordered.length; i++) {
|
|
2013
|
+
if (ordered[i].status === 'stopped' && words[i] !== null) ordered[i] = { ...ordered[i], statusText: words[i] };
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
1796
2016
|
const last = ordered[ordered.length - 1];
|
|
1797
2017
|
if (endedExpired && last && (last.status === 'accepted' || last.status === 'redo' || last.status === 'reran')) {
|
|
1798
2018
|
ordered[ordered.length - 1] = { ...last, status: 'expired', reason: null, why: LATE_ANSWER_WHY };
|
|
@@ -1913,7 +2133,7 @@ export function getRunAsks({
|
|
|
1913
2133
|
const run = resolveRunPath(root, flow, runId);
|
|
1914
2134
|
if (!run.ok) return null;
|
|
1915
2135
|
if (!existsSync(run.runDir)) return null;
|
|
1916
|
-
const histRow = readHistory(run.flowDir).
|
|
2136
|
+
const histRow = endRow(readHistory(run.flowDir), run.runDir, runId) ?? undefined;
|
|
1917
2137
|
const hasHistoryRow = !!histRow;
|
|
1918
2138
|
// hamr's 2026-09-27 browser-walk bug #4: the Ask tab's own asks must carry
|
|
1919
2139
|
// the SAME `open`/`timeLeftMs` fields listStops already computes for the
|
|
@@ -1982,19 +2202,18 @@ export function listStops({ root, resumeAttempt }) {
|
|
|
1982
2202
|
for (const flowName of listFlowNames(root)) {
|
|
1983
2203
|
const flowDir = join(root, flowName);
|
|
1984
2204
|
const historyRows = readHistory(flowDir).filter((r) => r && typeof r.runId === 'string');
|
|
1985
|
-
const historyRunIds = new Set(historyRows.map((r) => r.runId));
|
|
1986
|
-
const expiredEnds = new Set(historyRows.filter((r) => r.outcome === 'ask-expired').map((r) => r.runId));
|
|
1987
2205
|
for (const runId of listRunIds(flowDir)) {
|
|
1988
2206
|
const run = resolveRunPath(root, flowName, runId);
|
|
1989
2207
|
if (!run.ok) continue;
|
|
1990
|
-
const
|
|
2208
|
+
const end = endRow(historyRows, run.runDir, runId);
|
|
2209
|
+
const hasHistoryRow = end !== null;
|
|
1991
2210
|
const resume = hasHistoryRow ? null : deriveResumeState({ savedAnswer: readSavedAnswer(run.runDir), attempt: resumeAttempt?.(flowName, runId) ?? null, ask: readAsk(run.runDir) });
|
|
1992
2211
|
// M4c amendment 2: stuck by the ONE rule (`stuckState`), marked on the ask whose answer is saved.
|
|
1993
2212
|
const st = runStuck(run.runDir, resume);
|
|
1994
2213
|
const stuckAskId = !hasHistoryRow && st.stuck ? (resume?.askId ?? null) : null;
|
|
1995
2214
|
const openAskJson = hasHistoryRow ? null : readAsk(run.runDir);
|
|
1996
2215
|
const savedAskId = readSavedAnswer(run.runDir)?.askId;
|
|
1997
|
-
const runAsks = runAsksInOrder(run.runDir, hasHistoryRow,
|
|
2216
|
+
const runAsks = runAsksInOrder(run.runDir, hasHistoryRow, end?.outcome === 'ask-expired').map((ask) => ({
|
|
1998
2217
|
flow: flowName,
|
|
1999
2218
|
runId,
|
|
2000
2219
|
...ask,
|