fwdloop 0.13.0 → 0.15.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 +25 -12
- package/package.json +2 -2
- package/src/authoring.js +73 -39
- package/src/canrun.js +71 -1
- package/src/catalogue.json +2 -2
- package/src/checked.js +54 -0
- package/src/closers.js +112 -91
- package/src/declaration.js +115 -11
- package/src/drafter.js +139 -39
- package/src/flow.js +220 -5
- package/src/keysfile.js +4 -2
- package/src/model-step.js +1 -1
- package/src/monthly.js +139 -17
- package/src/panel/author.js +226 -64
- package/src/panel/authorcard.js +99 -4
- package/src/panel/authorflows.js +51 -10
- package/src/panel/authorresume.js +2 -2
- package/src/panel/authorstart.js +18 -10
- package/src/panel/data.js +147 -81
- package/src/panel/index.html +497 -338
- package/src/panel/server.js +5 -2
- package/src/panel/settings.js +1 -1
- package/src/runner.js +105 -48
- package/src/setup.js +21 -14
- package/src/signed-diff.js +71 -0
- package/types/authoring.d.ts +52 -14
- package/types/canrun.d.ts +33 -1
- package/types/checked.d.ts +25 -0
- package/types/closers.d.ts +47 -28
- package/types/declaration.d.ts +16 -2
- package/types/drafter.d.ts +146 -11
- package/types/flow.d.ts +42 -2
- package/types/model-step.d.ts +1 -6
- package/types/monthly.d.ts +25 -1
- package/types/panel/author.d.ts +55 -40
- package/types/panel/authorcard.d.ts +54 -0
- package/types/panel/authorflows.d.ts +39 -0
- package/types/panel/authorstart.d.ts +1 -0
- package/types/panel/data.d.ts +11 -56
- package/types/runner.d.ts +11 -3
- package/types/setup.d.ts +6 -12
- package/types/signed-diff.d.ts +10 -0
package/src/panel/authorflows.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// run starts only through `authorstart.js`'s one `start`. Reads the disk; writes nothing.
|
|
4
4
|
//
|
|
5
5
|
// flows() only flows whose `readFlow` passes (a missing, unsigned or tampered flow is never listed), that `canFlowRun` accepts
|
|
6
|
-
// (the one function shared with the run's own preflight: an unwired verb is not listed) and that have at least one
|
|
6
|
+
// (the one function shared with the run's own preflight: an unwired verb is not listed; amendment 22) and that have at least one
|
|
7
7
|
// passed run (amendment 7 item 7; Run again reaches the rest), each with its signed
|
|
8
8
|
// cap, its declared source roles, the source paths the NEWEST run of that flow used (its `inputs.json`
|
|
9
9
|
// manifest `source` field; blank when none) and what is left this month (a courtesy: the CLI's own monthly
|
|
@@ -15,11 +15,11 @@ import { join } from 'node:path';
|
|
|
15
15
|
|
|
16
16
|
import { scrub } from '../authoring.js';
|
|
17
17
|
import { endRow, readHistory } from '../books.js';
|
|
18
|
-
import { canFlowRun } from '../canrun.js';
|
|
18
|
+
import { canFlowRun, willNotRunSay } from '../canrun.js';
|
|
19
19
|
import { loadCatalogue } from '../catalogue.js';
|
|
20
20
|
import { ConfigError, readConfig } from '../config.js';
|
|
21
21
|
import {
|
|
22
|
-
checkFlowName, listFlowNames, listRunIds, nextRunId, readFileInside, readFlow, resolveRunDir,
|
|
22
|
+
changeSentence, checkFlowName, listFlowNames, listRunIds, nextRunId, readFileInside, readFlow, resolveRunDir,
|
|
23
23
|
} from '../flow.js';
|
|
24
24
|
import { spendSummary } from '../monthly.js';
|
|
25
25
|
import { userInfo } from 'node:os';
|
|
@@ -27,11 +27,16 @@ import {
|
|
|
27
27
|
applyRunValues, flowValues, pickRunValues, valuesHash,
|
|
28
28
|
} from '../runvalues.js';
|
|
29
29
|
import {
|
|
30
|
-
capFloorFor, capFloorText, checkInputRows, runInputRows,
|
|
30
|
+
capFloorFor, capFloorText, cardFromSigned, checkInputRows, runInputRows,
|
|
31
31
|
} from './authorcard.js';
|
|
32
32
|
import { checkValues } from './authorvalues.js';
|
|
33
|
+
import { getRunControls } from './data.js';
|
|
33
34
|
import { providerKeys } from './spawn.js';
|
|
34
35
|
|
|
36
|
+
/** M6 amendment 1: the sentence the page shows and the sign route refuses with, for a job with a run running or waiting at its ask. @param {string} runId */
|
|
37
|
+
export const editBlockedSay = (runId) => `finish or stop ${runId} first`;
|
|
38
|
+
/** M6 amendment 3: the sentence for a job with a start still alive (its start folder in phase `starting`). */
|
|
39
|
+
export const EDIT_STARTING_SAY = 'a run is starting';
|
|
35
40
|
const NO_LIMIT = 'no monthly limit set';
|
|
36
41
|
/** The body keys a run start takes (amendment 5 item 2): the open boxes plus the hash of the second click. Any other key is refused by name. */
|
|
37
42
|
const RUN_KEYS = ['flow', 'inputs', 'runId', 'destination', 'capUsd', 'askWaits', 'hash'];
|
|
@@ -169,7 +174,12 @@ export function createFlowsDoor(opts) {
|
|
|
169
174
|
if (!named.ok) return reply(400, { refused: 'flow', refusals: [{ field: 'flow', say: `${named.red}.` }] });
|
|
170
175
|
const read = readSigned(realRoot, flow);
|
|
171
176
|
if (!read.ok) {
|
|
172
|
-
return reply(400, { refused: 'flow', refusals: [{ field: 'flow', say: `"${flow}" is not a signed flow that passes its checks, so it will not run
|
|
177
|
+
return reply(400, { refused: 'flow', refusals: [{ field: 'flow', say: `"${flow}" is not a signed flow that passes its checks, so it will not run.${changeSentence(read.reds.map((r) => scrub(String(r), keys)))}` }], reds: read.reds.map((r) => scrub(String(r), keys)) });
|
|
178
|
+
}
|
|
179
|
+
const can = canFlowRun(read); // amendment 21 item 1: a flow the list shows refused is refused here too, in the same sentence
|
|
180
|
+
if (!can.ok) {
|
|
181
|
+
const red = scrub(String(can.red), keys);
|
|
182
|
+
return reply(409, { refused: 'flow', say: willNotRunSay(flow, red), refusals: [{ field: 'flow', say: willNotRunSay(flow, red) }] });
|
|
173
183
|
}
|
|
174
184
|
const checked = checkValues({
|
|
175
185
|
allowedKeys: RUN_KEYS, body, base: flowValues(read.arbiter), realRoot, capOnly: false, floorUsd: formFacts(read).capFloorUsd, monthlyClaim,
|
|
@@ -201,6 +211,25 @@ export function createFlowsDoor(opts) {
|
|
|
201
211
|
};
|
|
202
212
|
}
|
|
203
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Why a job cannot be edited right now, in the sentence the page shows and the sign route refuses with; `null` when it can. M6 amendment 1:
|
|
216
|
+
* the newest run that is running or waiting at its ask, by the panel's ONE decision (`runControls`, via `getRunControls`: `canStop`) ->
|
|
217
|
+
* "finish or stop run-N first". M6 amendment 3: a start folder in phase `starting` for this flow whose child is alive (`starter.startingFor`,
|
|
218
|
+
* the start door's own rule) -> "a run is starting"; a start that is done, refused or dead unlocks. A stopped, finished or expired run does not count.
|
|
219
|
+
* @param {string} realRoot @param {string} name @returns {string|null}
|
|
220
|
+
*/
|
|
221
|
+
function editBlockOf(realRoot, name) {
|
|
222
|
+
const cat = loadCatalogue();
|
|
223
|
+
if (!cat.ok) return null;
|
|
224
|
+
if (starter.startingFor(name, []) !== null) return EDIT_STARTING_SAY;
|
|
225
|
+
const ids = listRunIds(join(realRoot, name)).filter((id) => /^run-\d+$/.test(id)).sort((a, b) => Number(b.slice(4)) - Number(a.slice(4)));
|
|
226
|
+
for (const id of ids) {
|
|
227
|
+
const c = getRunControls({ root: realRoot, flow: name, runId: id, catalogue: cat.primitives });
|
|
228
|
+
if (c?.canStop === true) return editBlockedSay(id);
|
|
229
|
+
}
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
|
|
204
233
|
/** One flow's record for the page: its signed values and facts, its last run's inputs, its passed runs and its track record. @param {string} realRoot @param {string} name @param {any} read @param {any} left */
|
|
205
234
|
function entryFor(realRoot, name, read, left) {
|
|
206
235
|
const roles = (read.arbiter.sources ?? []).map((s) => s.role);
|
|
@@ -211,10 +240,22 @@ export function createFlowsDoor(opts) {
|
|
|
211
240
|
flow: name, capUsd: read.arbiter.capUsd, roles, nextRunId: nextRunId(flowDir), lastRunId: last.runId, lastSources: last.sources, leftThisMonth: left,
|
|
212
241
|
runs: passed, stats,
|
|
213
242
|
...formFacts(read),
|
|
243
|
+
// M6: the job as a card to edit (`ok:true, card, flowHash` = the signature hash it is opened at), or why it cannot be (`ok:false, say`)
|
|
244
|
+
edit: (() => {
|
|
245
|
+
const blocked = editBlockOf(realRoot, name);
|
|
246
|
+
if (blocked !== null) return { ok: false, say: blocked };
|
|
247
|
+
const c = cardFromSigned(read); return c.ok ? { ok: true, card: c.card, flowHash: read.signature.flow } : c;
|
|
248
|
+
})(),
|
|
214
249
|
};
|
|
215
250
|
}
|
|
216
251
|
|
|
217
252
|
return {
|
|
253
|
+
/** M6 amendments 1 and 3: the sentence that says why this flow cannot be edited now, or null (the sign route's check). @param {string} name */
|
|
254
|
+
editBlock(name) {
|
|
255
|
+
const realRoot = realRootOrNull();
|
|
256
|
+
return realRoot === null ? null : editBlockOf(realRoot, name);
|
|
257
|
+
},
|
|
258
|
+
|
|
218
259
|
/** `GET /api/author/flows`. */
|
|
219
260
|
flows() {
|
|
220
261
|
const realRoot = realRootOrNull();
|
|
@@ -223,7 +264,7 @@ export function createFlowsDoor(opts) {
|
|
|
223
264
|
const flows = [];
|
|
224
265
|
for (const name of listFlowNames(realRoot)) {
|
|
225
266
|
const read = readSigned(realRoot, name);
|
|
226
|
-
if (!canFlowRun(read).ok) continue;
|
|
267
|
+
if (!canFlowRun(read).ok) continue; // a refused flow (unreadable, unwired verb, unbuildable check) is never listed
|
|
227
268
|
const entry = entryFor(realRoot, name, read, left);
|
|
228
269
|
if (entry.runs.length === 0) continue; // amendment 7 item 7: only a flow with a passed run is listed
|
|
229
270
|
flows.push(entry);
|
|
@@ -249,13 +290,13 @@ export function createFlowsDoor(opts) {
|
|
|
249
290
|
const rr = resolveRunDir(join(realRoot, flow), runId);
|
|
250
291
|
if (!rr.ok) return no(400, `${rr.red}.`);
|
|
251
292
|
if (!listRunIds(join(realRoot, flow)).includes(runId)) return no(404, `"${flow}" has no run "${runId}".`);
|
|
252
|
-
const
|
|
253
|
-
const can = canFlowRun(
|
|
293
|
+
const readRaw = readSigned(realRoot, flow);
|
|
294
|
+
const can = canFlowRun(readRaw);
|
|
254
295
|
if (!can.ok) {
|
|
255
296
|
const red = scrub(String(can.red), providerKeys(loadEnv().env));
|
|
256
|
-
return no(409,
|
|
297
|
+
return no(409, willNotRunSay(flow, red), { red });
|
|
257
298
|
}
|
|
258
|
-
|
|
299
|
+
const read = /** @type {Extract<typeof readRaw, { ok: true }>} */ (readRaw); // canFlowRun refuses every failed read above
|
|
259
300
|
const roles = (read.arbiter.sources ?? []).map((s) => s.role);
|
|
260
301
|
return {
|
|
261
302
|
status: 200,
|
|
@@ -16,7 +16,7 @@ import { userInfo } from 'node:os';
|
|
|
16
16
|
|
|
17
17
|
import { scrub } from '../authoring.js';
|
|
18
18
|
import { loadCatalogue } from '../catalogue.js';
|
|
19
|
-
import { checkFlowName, readFileInside, readFlow, resolveRunDir } from '../flow.js';
|
|
19
|
+
import { changeSentence, checkFlowName, readFileInside, readFlow, resolveRunDir } from '../flow.js';
|
|
20
20
|
import { readResumeLock } from '../liveness.js';
|
|
21
21
|
import { auditSpend } from '../runner.js';
|
|
22
22
|
import {
|
|
@@ -56,7 +56,7 @@ export function createResumeDoor(opts) {
|
|
|
56
56
|
const cat = loadCatalogue();
|
|
57
57
|
if (!cat.ok) return no(500, { refused: 'catalogue', say: 'The catalogue could not be loaded. Nothing was signed.' });
|
|
58
58
|
const read = readFlow({ root: realRoot, name: flow, catalogue: cat.primitives });
|
|
59
|
-
if (!read.ok) return no(400, { refused: 'flow', say: `"${flow}" is not a signed flow that passes its checks, so a run of it will not resume
|
|
59
|
+
if (!read.ok) return no(400, { refused: 'flow', say: `"${flow}" is not a signed flow that passes its checks, so a run of it will not resume.${changeSentence(read.reds)}` });
|
|
60
60
|
const controls = getRunControls({
|
|
61
61
|
root: realRoot, flow, runId, catalogue: cat.primitives,
|
|
62
62
|
});
|
package/src/panel/authorstart.js
CHANGED
|
@@ -106,8 +106,20 @@ export function createStarter(opts) {
|
|
|
106
106
|
return d === null ? null : readStart(join(d, id), id, keys);
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
+
/** M6 amendment 3: the ONE rule for "a run of this flow is starting": the newest start folder of the flow in phase `starting`, or null. @param {string} flow @param {string[]} keys */
|
|
110
|
+
function startingFor(flow, keys) {
|
|
111
|
+
const sd = startsDir();
|
|
112
|
+
if (sd === null) return null;
|
|
113
|
+
for (const id of readdirInside(sd, '.').filter((n) => ID_RE.test(n)).sort().reverse()) {
|
|
114
|
+
const v = readStart(join(sd, id), id, keys);
|
|
115
|
+
if (v && v.flow === flow && v.phase === 'starting') return id;
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
109
120
|
return {
|
|
110
121
|
checkRun,
|
|
122
|
+
startingFor,
|
|
111
123
|
|
|
112
124
|
/**
|
|
113
125
|
* Start `fwdloop run` for a flow whose every $0 check already passed at the calling door. Re-checks the run id here (nothing
|
|
@@ -150,12 +162,10 @@ export function createStarter(opts) {
|
|
|
150
162
|
}
|
|
151
163
|
const keys = providerKeys(env);
|
|
152
164
|
// one start at a time while one is still spawning for this flow (a double click, two tabs)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return { status: 409, body: { ok: false, refused: 'start-live', startId: id, say: 'A run of this flow is already starting. Wait for it.' } };
|
|
158
|
-
}
|
|
165
|
+
const startingId = startingFor(flow, keys);
|
|
166
|
+
if (startingId !== null) {
|
|
167
|
+
unclaim();
|
|
168
|
+
return { status: 409, body: { ok: false, refused: 'start-live', startId: startingId, say: 'A run of this flow is already starting. Wait for it.' } };
|
|
159
169
|
}
|
|
160
170
|
const id = newId();
|
|
161
171
|
const dir = join(sd, id);
|
|
@@ -190,10 +200,8 @@ export function createStarter(opts) {
|
|
|
190
200
|
const sd = startsDir();
|
|
191
201
|
if (sd === null) return { status: 400, body: { ok: false, refused: 'root', say: 'The flows folder this panel serves does not exist.' } };
|
|
192
202
|
const keys = providerKeys(env);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (v && v.flow === flow && v.phase === 'starting') return { status: 409, body: { ok: false, refused: 'start-live', startId: id, say: 'A run of this flow is already starting. Wait for it.' } };
|
|
196
|
-
}
|
|
203
|
+
const startingId = startingFor(flow, keys);
|
|
204
|
+
if (startingId !== null) return { status: 409, body: { ok: false, refused: 'start-live', startId: startingId, say: 'A run of this flow is already starting. Wait for it.' } };
|
|
197
205
|
const id = newId();
|
|
198
206
|
const dir = join(sd, id);
|
|
199
207
|
mkdirSync(sd, { recursive: true, mode: 0o700 });
|
package/src/panel/data.js
CHANGED
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
import { join, basename, sep } from 'node:path';
|
|
26
26
|
|
|
27
27
|
import {
|
|
28
|
-
readFlow, listFlowNames, listRunIds, resolveRunDir, checkFlowName, readFileInside, readdirInside,
|
|
28
|
+
readFlow, readRunJobCopy, listFlowNames, listRunIds, resolveRunDir, checkFlowName, readFileInside, readdirInside,
|
|
29
29
|
} from '../flow.js';
|
|
30
30
|
import {
|
|
31
31
|
readAudit, readHistory, endRow, readPidRows, auditRowTokens, auditRowAt, auditRowTools,
|
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
import { readSpendRows } from '../provider.js';
|
|
37
37
|
import { applyRunValues, parseWaitMs, pickRunValues, VALUES_FILE_RE } from '../runvalues.js';
|
|
38
38
|
import { readSetup } from '../setup.js';
|
|
39
|
+
import { checkedLines, notCheckedBlock, NOT_CHECKED_LABEL } from '../checked.js';
|
|
39
40
|
import { MAX_STRUCTURE_RETRIES } from '../drafter.js';
|
|
40
41
|
import {
|
|
41
42
|
runLiveness, booksFresh, readResumeLock,
|
|
@@ -242,7 +243,10 @@ export function signParts(glyph, label, noWord = false) {
|
|
|
242
243
|
const word = noWord ? null : (SIGN_WORDS[glyph] ?? null);
|
|
243
244
|
if (word === null) return { word: null, line: label ?? null };
|
|
244
245
|
if (typeof label !== 'string' || label === word) return { word, line: null };
|
|
245
|
-
|
|
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 };
|
|
246
250
|
}
|
|
247
251
|
|
|
248
252
|
/** The sign an Inbox row wears (null for a past answer, which shows its status word instead). */
|
|
@@ -357,16 +361,20 @@ export function glyphPulses(g) {
|
|
|
357
361
|
* A saved answer with a live process is `[▶]` working on your answer.
|
|
358
362
|
* - `[?]` crashed after taking your answer (amendment 2 (f)) — the answer was
|
|
359
363
|
* consumed, the process is gone, no end row: cannot be carried on.
|
|
360
|
-
* @param {{historyRow: any, askJson: any, consumedAnswerExists: boolean, hasStateJson: boolean, resume?: any, liveness?: 'running'|'gone'|'unknown', booksFresh?: boolean, lock?: string, resumable?: boolean}} ctx
|
|
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, jobEdited?: boolean}} ctx
|
|
361
365
|
* @returns {{glyph: '[✓]'|'[✗]'|'[·]'|'[!]'|'[▶]'|'[?]'|'[II]'|'[■]', label: string}}
|
|
362
366
|
*/
|
|
363
367
|
export function computeGlyph({
|
|
364
|
-
historyRow, askJson, consumedAnswerExists, hasStateJson, resume, liveness, booksFresh, lock, resumable,
|
|
368
|
+
historyRow, askJson, consumedAnswerExists, hasStateJson, resume, liveness, booksFresh, lock, resumable, stoppedAtAsk, jobEdited,
|
|
365
369
|
}) {
|
|
366
370
|
if (historyRow) {
|
|
367
371
|
if (historyRow.outcome === 'complete') return { glyph: '[✓]', label: 'passed' };
|
|
372
|
+
// M6 amendment 4: a stopped (or cap-halted) run whose job was edited and signed since cannot be resumed; the words say so.
|
|
373
|
+
if (jobEdited === true && (historyRow.outcome === 'stopped' || historyRow.outcome === 'cap-halt')) return { glyph: '[■]', label: JOB_EDITED_LINE };
|
|
368
374
|
// 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".
|
|
369
|
-
if (historyRow.outcome === 'stopped')
|
|
375
|
+
if (historyRow.outcome === 'stopped') {
|
|
376
|
+
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' };
|
|
377
|
+
}
|
|
370
378
|
if (historyRow.outcome === 'cap-halt' && resumable) return { glyph: '[■]', label: 'stopped — the money cap was reached; raise it and Resume' };
|
|
371
379
|
// M4b amendment 3: a run the human ended on purpose with rerun is not a failure.
|
|
372
380
|
if (historyRow.outcome === 'rerun') return { glyph: '[✗]', label: 'stopped by you (rerun), a fresh run was started' };
|
|
@@ -857,6 +865,13 @@ export function summarizeSpendRows(spendRows) {
|
|
|
857
865
|
};
|
|
858
866
|
}
|
|
859
867
|
|
|
868
|
+
/** M6 F5: the ONE comparison of a run's halt record with the job on disk (`sameJob`; the runner refuses a Resume otherwise). */
|
|
869
|
+
const haltMatchesJob = (halt, flowRead) => halt.ok && flowRead.ok && halt.halt.signatureHash === flowRead.signature.flow;
|
|
870
|
+
/** M6 amendment 4: a stopped / cap-halted run (its halt record agrees with its end row) whose readable job is not the one it halted under. */
|
|
871
|
+
const runJobEdited = (halt, historyRow, flowRead) => halt.ok && flowRead.ok && historyRow !== null && historyRow.outcome === halt.halt.outcome && !haltMatchesJob(halt, flowRead);
|
|
872
|
+
/** The whole line (Runs, Ask and Inbox alike) of a stopped run whose job was edited since: no Resume is offered. */
|
|
873
|
+
const JOB_EDITED_LINE = 'stopped — the job was edited; start a new run';
|
|
874
|
+
|
|
860
875
|
/**
|
|
861
876
|
* Read every book fwdloop can hold for one run, once. The shared context
|
|
862
877
|
* every deriver below (and the POC before it) builds its fields from.
|
|
@@ -897,6 +912,12 @@ function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue, attem
|
|
|
897
912
|
historyRow,
|
|
898
913
|
// M4e amendment 4 item 4: a cap-halted or stopped run that can be continued (`halt.json` is the runner's record)
|
|
899
914
|
resumable: halt.ok && historyRow !== null && historyRow.outcome === halt.halt.outcome,
|
|
915
|
+
// M6 F5: the job on disk is still the one the run halted under (the runner refuses a Resume otherwise: "signature mismatch")
|
|
916
|
+
sameJob: haltMatchesJob(halt, flowRead),
|
|
917
|
+
// M6 amendment 4: the stopped / cap-halted run whose job was edited since (the opposite of `sameJob`, only where the job could be read)
|
|
918
|
+
jobEdited: runJobEdited(halt, historyRow, flowRead),
|
|
919
|
+
// 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)
|
|
920
|
+
stoppedAtAsk: lastStoppedAtAsk(runDir, auditRows, historyRow !== null),
|
|
900
921
|
auditRows,
|
|
901
922
|
spendRows,
|
|
902
923
|
logJson,
|
|
@@ -915,6 +936,47 @@ function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue, attem
|
|
|
915
936
|
};
|
|
916
937
|
}
|
|
917
938
|
|
|
939
|
+
const STOPPED_AT_ASK_RE = /^stopped at the ask of step \d+$/;
|
|
940
|
+
const STOPPED_AT_ASK_START_RE = /^stopped at the ask of step \d+/;
|
|
941
|
+
/**
|
|
942
|
+
* 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`
|
|
943
|
+
* row written for the step `deriveAskStepInfo` pairs it with, or null when the books cannot name that step (never a guess; never
|
|
944
|
+
* by counting those rows in order: a Stop that landed before any ask parked writes one too, with no ask behind it).
|
|
945
|
+
* @param {any[]} ordered `runAsksInOrder`'s asks, oldest-first @param {any[]} audit this run's audit rows
|
|
946
|
+
* @returns {(string|null)[]}
|
|
947
|
+
*/
|
|
948
|
+
function stoppedAskWords(ordered, audit) {
|
|
949
|
+
const stepOf = deriveAskStepInfo(ordered, audit, null);
|
|
950
|
+
const atAsk = audit.filter((r) => r.verdict === 'stopped' && STOPPED_AT_ASK_RE.test(String(r.gap)));
|
|
951
|
+
return ordered.map((_, i) => {
|
|
952
|
+
if (stepOf[i].step === null) return null;
|
|
953
|
+
const words = atAsk.filter((r) => r.step === stepOf[i].step).pop()?.gap;
|
|
954
|
+
return typeof words === 'string' ? words : null;
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
/** 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. */
|
|
959
|
+
const STOPPED_STEP_UNKNOWN = 'stopped';
|
|
960
|
+
/** The whole line a stopped run reads when its step cannot be named (Runs, Ask and Inbox alike; am41 item 4). `computeGlyph` builds the same words from STOPPED_STEP_UNKNOWN. */
|
|
961
|
+
const STOPPED_UNKNOWN_LINE = `${STOPPED_STEP_UNKNOWN} — Resume to go on`;
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* How a stopped run was stopped, for its Runs label: the newest `stopped` audit row, when the runner wrote its `gap` as
|
|
965
|
+
* `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
|
|
966
|
+
* (`stoppedAskWords`, the one reader); `stopped` alone when the step cannot be known; null for any other stop (after a step, before step 1).
|
|
967
|
+
* @param {string} runDir @param {any[]} auditRows @param {boolean} hasHistoryRow @returns {string|null}
|
|
968
|
+
*/
|
|
969
|
+
function lastStoppedAtAsk(runDir, auditRows, hasHistoryRow) {
|
|
970
|
+
const stopped = auditRows.filter((r) => r.verdict === 'stopped' && typeof r.gap === 'string' && !Number.isInteger(r.attempt));
|
|
971
|
+
const last = stopped.length > 0 ? stopped[stopped.length - 1] : null;
|
|
972
|
+
if (!last || !STOPPED_AT_ASK_RE.test(last.gap)) return null;
|
|
973
|
+
const ordered = runAsksInOrder(runDir, hasHistoryRow);
|
|
974
|
+
const stepOf = deriveAskStepInfo(ordered, auditRows, null);
|
|
975
|
+
const words = stoppedAskWords(ordered, auditRows);
|
|
976
|
+
const i = stepOf.findIndex((x) => x.step !== null && x.step === last.step);
|
|
977
|
+
return i >= 0 && words[i] !== null ? words[i] : STOPPED_STEP_UNKNOWN;
|
|
978
|
+
}
|
|
979
|
+
|
|
918
980
|
/** @param {string} runDir @returns {string|null} */
|
|
919
981
|
function lastPidStartedAt(runDir) {
|
|
920
982
|
const rows = readPidRows(runDir);
|
|
@@ -936,11 +998,13 @@ const isRunningNow = (ctx, glyph) => !ctx.historyRow && glyph === '[▶]';
|
|
|
936
998
|
* @returns {{canStop: boolean, atAsk: boolean, stopRequested: boolean, starting: boolean, canResume: boolean, resumeOutcome: string|null, spentUsd: number|null, spendComplete: boolean|null, capUsd: number|null}}
|
|
937
999
|
*/
|
|
938
1000
|
export function runControls(ctx, glyph, label = '') {
|
|
939
|
-
|
|
1001
|
+
// M6 F1: ask.json stays on disk once the human has answered, so it blocks `running` only while the ask is unanswered
|
|
1002
|
+
// (`[▶]` with an ask is only ever "working on your answer": a saved answer, or a consumed one with a live process).
|
|
1003
|
+
const running = isRunningNow(ctx, glyph) && (!ctx.askJson || ctx.consumedAnswerExists || ctx.resume?.state === 'not-started');
|
|
940
1004
|
// M4e amendment 13: a run waiting at its ask (open, unanswered, not expired) shows Stop too; it stops the run at the ask.
|
|
941
1005
|
const atAsk = !ctx.historyRow && !!ctx.askJson && glyph === '[·]' && label === WAITING_LABEL;
|
|
942
1006
|
const starting = !ctx.historyRow && !ctx.askJson && readPidRows(ctx.runDir).length === 0;
|
|
943
|
-
const canResume = ctx.resumable === true;
|
|
1007
|
+
const canResume = ctx.resumable === true && ctx.sameJob === true;
|
|
944
1008
|
return {
|
|
945
1009
|
canStop: running || atAsk,
|
|
946
1010
|
atAsk,
|
|
@@ -1409,12 +1473,14 @@ export function getRunDetail({
|
|
|
1409
1473
|
|
|
1410
1474
|
/** The words the Draft says for a flow with no `setup.jsonl` (M4e amendment 6 item 4; renamed Draft by amendment 7 item 2). */
|
|
1411
1475
|
export const NO_DRAFT_WORDS = 'no draft record';
|
|
1476
|
+
/** M6: what the Job tab says for a run that started before runs kept a copy of their job. */
|
|
1477
|
+
export const NO_JOB_COPY_WORDS = 'This run started before runs kept a copy of their job, so this shows the job as it is now.';
|
|
1412
1478
|
|
|
1413
1479
|
/**
|
|
1414
1480
|
* 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).
|
|
1415
1481
|
* 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
|
|
1416
1482
|
* 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
|
|
1417
|
-
* unknown never shows as a smaller exact number; no model rows = `null`. `humanChecks` = the note rows + the sign row + the run's signed-values
|
|
1483
|
+
* 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
|
|
1418
1484
|
* rows (the card is not a check), given by the caller as `ctx.humanChecks`. Money follows `costDisplay` ("at least $X" for a floor).
|
|
1419
1485
|
* @param {any[]} modelRows the draft and change rows (`kind` draft | change) of `setup.jsonl`
|
|
1420
1486
|
* @param {{cardAt?: any, signAt?: any, humanChecks?: number|null}} [ctx]
|
|
@@ -1465,6 +1531,9 @@ export function getDraftBlock(flowDir, runDir) {
|
|
|
1465
1531
|
else if (r.kind === 'note') happened.push('your note');
|
|
1466
1532
|
else if (r.kind === 'draft') happened.push(r.verdict === 'green' ? `drafting${retry(r)}` : 'draft red');
|
|
1467
1533
|
else if (r.kind === 'change') happened.push(r.verdict === 'red' ? 'change red' : `changing${retry(r)}`);
|
|
1534
|
+
else if (r.kind === 'startover') happened.push(r.verdict === 'green' ? `starting over${retry(r)}` : 'start over red');
|
|
1535
|
+
else if (r.kind === 'revise') happened.push(r.verdict === 'red' ? 'revise red' : `revising${retry(r)}`);
|
|
1536
|
+
else if (r.kind === 'redraft') happened.push(r.verdict === 'red' ? 'redraft red' : `redrafting with your answers${retry(r)}`);
|
|
1468
1537
|
else if (r.kind === 'sign') happened.push(`signed (${r.signedBy ?? 'you'})`);
|
|
1469
1538
|
if (r.kind === 'card') {
|
|
1470
1539
|
const c = r.card && typeof r.card === 'object' ? r.card : {};
|
|
@@ -1474,6 +1543,9 @@ export function getDraftBlock(flowDir, runDir) {
|
|
|
1474
1543
|
} else if (r.kind === 'note') rows.push(human(r, n, { action: 'note (you)', gap: String(r.text ?? '') }));
|
|
1475
1544
|
else if (r.kind === 'draft') rows.push(model(r, n, 'draft'));
|
|
1476
1545
|
else if (r.kind === 'change') rows.push(model(r, n, `change ${r.n}`));
|
|
1546
|
+
else if (r.kind === 'startover') rows.push(model(r, n, 'start over'));
|
|
1547
|
+
else if (r.kind === 'revise') rows.push(model(r, n, `revise ${r.n}`));
|
|
1548
|
+
else if (r.kind === 'redraft') rows.push(model(r, n, `answers redraft ${r.n}`));
|
|
1477
1549
|
else if (r.kind === 'sign') rows.push(human(r, n, { action: `sign (${r.signedBy ?? 'you'})`, gap: `plan ${String(r.hash ?? '').slice(0, 12)}` }));
|
|
1478
1550
|
});
|
|
1479
1551
|
}
|
|
@@ -1498,9 +1570,9 @@ export function getDraftBlock(flowDir, runDir) {
|
|
|
1498
1570
|
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 } : {}) }));
|
|
1499
1571
|
}
|
|
1500
1572
|
const lastSign = setup.present ? [...setup.rows].reverse().find((r) => r.kind === 'sign') : undefined;
|
|
1501
|
-
const humanChecks = setup.present ? setup.rows.filter((r) => r.kind === 'note' || r.kind === 'sign').length + versions.length : null;
|
|
1573
|
+
const humanChecks = setup.present ? setup.rows.filter((r) => r.kind === 'note' || r.kind === 'sign' || r.kind === 'revise' || r.kind === 'redraft').length + versions.length : null;
|
|
1502
1574
|
const totals = setup.present
|
|
1503
|
-
? draftTotals(setup.rows.filter((r) => r.kind === 'draft' || r.kind === 'change'), { cardAt: setup.rows.find((r) => r.kind === 'card')?.at, signAt: lastSign?.at, humanChecks })
|
|
1575
|
+
? 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 })
|
|
1504
1576
|
: null;
|
|
1505
1577
|
// the group the Audit tab draws as a normal card (collapsed by default) and the box the Map and the first step card read
|
|
1506
1578
|
// `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)
|
|
@@ -1547,66 +1619,36 @@ export function getRunAudit({ root, flow, runId }) {
|
|
|
1547
1619
|
}
|
|
1548
1620
|
|
|
1549
1621
|
/**
|
|
1550
|
-
*
|
|
1551
|
-
*
|
|
1552
|
-
*
|
|
1553
|
-
*
|
|
1554
|
-
*
|
|
1555
|
-
*
|
|
1556
|
-
* DROPPED per the fit-check). `runId` is only used to confirm the run
|
|
1557
|
-
* exists at all; `null` when it doesn't (404).
|
|
1558
|
-
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
1559
|
-
* @returns {any|null}
|
|
1560
|
-
*/
|
|
1561
|
-
/**
|
|
1562
|
-
* hamr's 2026-09-27 exit-check review #5: one plain-words sentence for a
|
|
1563
|
-
* declared step's own close rule — the Job tab's "Success" field. Derived
|
|
1564
|
-
* STRICTLY from `step.close` (and, for the "your accept" wording, whether
|
|
1565
|
-
* this step is the one line `arbiter.asks[]` itself binds to) — never a
|
|
1566
|
-
* fabricated cite/shape value:
|
|
1567
|
-
* - `hitl`: "human check", or "human check (your accept)" when this step's
|
|
1568
|
-
* own `fromLine` is a signed ask line (the ask step itself — the one a
|
|
1569
|
-
* human pauses a run on, distinct from an ordinary hitl pass-through
|
|
1570
|
-
* step with no ask binding).
|
|
1571
|
-
* - `softgreen`: "shape: N headings (a / b / c)" when `close.shape.sections`
|
|
1572
|
-
* is signed, "max W words" appended when `close.shape.maxWords` is
|
|
1573
|
-
* signed, "blocks of L lines" / "must carry: a, b" for the invoice-block
|
|
1574
|
-
* shape keys (`linesPerInvoice`/`mustCarry`) — every signed shape key
|
|
1575
|
-
* shown, nothing invented; "shape (no shape rules signed)" when a
|
|
1576
|
-
* softgreen step signs no `close.shape` at all (declaration.js allows
|
|
1577
|
-
* this — an empty/absent shape is not itself a red).
|
|
1578
|
-
* - `green`: "cited" — `CLOSE_ALLOWED` (`src/declaration.js`) never lets a
|
|
1579
|
-
* step declare WHAT it cites ahead of time (that's the drafted
|
|
1580
|
-
* artifact's own per-run field data, not signed prose), so there is
|
|
1581
|
-
* never anything honest to append here.
|
|
1582
|
-
* - anything else: the raw class name, named as unknown, never silently
|
|
1583
|
-
* dropped or guessed into one of the three above; no class at all names
|
|
1584
|
-
* that plainly too.
|
|
1585
|
-
* @param {{close?: {class?: string, shape?: any}, fromLine?: number|null}} step one `declaration.steps` entry
|
|
1586
|
-
* @param {Array<{line:number}>} arbiterAsks `arbiter.asks`, for the "your accept" check
|
|
1587
|
-
* @returns {string}
|
|
1622
|
+
* 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
|
|
1623
|
+
* 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
|
|
1624
|
+
* 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
|
|
1625
|
+
* signed before amendment 36, which the page says in words; never an empty list read as "nothing".
|
|
1626
|
+
* M6: a sign row that names another signing than the job being shown (`flowHash`) is not this job's record: `recorded:false`, never the new job's words.
|
|
1627
|
+
* @param {any} declaration @param {Array<{line:number, ttlMs?:number}>} asks @param {string} flowDir @param {string|null} [flowHash] the signature hash of the job being shown
|
|
1588
1628
|
*/
|
|
1589
|
-
|
|
1590
|
-
const
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
const
|
|
1594
|
-
return
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1629
|
+
function buildJobPlan(declaration, asks, flowDir, flowHash = null) {
|
|
1630
|
+
const lines = checkedLines(declaration, { askLines: asks.map((x) => x.line) });
|
|
1631
|
+
const declSteps = Array.isArray(declaration?.steps) ? declaration.steps : [];
|
|
1632
|
+
const steps = declSteps.map((st, i) => {
|
|
1633
|
+
const ak = asks.find((x) => x.line === st.fromLine);
|
|
1634
|
+
return {
|
|
1635
|
+
step: i + 1,
|
|
1636
|
+
line: Number.isInteger(st.fromLine) ? st.fromLine : null,
|
|
1637
|
+
reads: Array.isArray(st.reads) ? st.reads : [],
|
|
1638
|
+
makes: typeof st.emits === 'string' ? st.emits : null,
|
|
1639
|
+
mayDo: Array.isArray(st.primitives) ? st.primitives : [],
|
|
1640
|
+
check: lines[i].sentences,
|
|
1641
|
+
checkClass: lines[i].class,
|
|
1642
|
+
ask: !!ak,
|
|
1643
|
+
waitMs: ak && typeof ak.ttlMs === 'number' ? ak.ttlMs : null,
|
|
1644
|
+
};
|
|
1645
|
+
});
|
|
1646
|
+
const setup = readSetup(flowDir);
|
|
1647
|
+
const signRow = setup.present ? setup.rows.find((r) => r.kind === 'sign') : undefined;
|
|
1648
|
+
const ofThisJob = !!signRow && (typeof signRow.flowHash !== 'string' || flowHash === null || signRow.flowHash === flowHash);
|
|
1649
|
+
const nc = ofThisJob ? signRow?.notChecked : undefined;
|
|
1650
|
+
const recorded = !!nc && Array.isArray(nc.items);
|
|
1651
|
+
return { steps, notChecked: { label: NOT_CHECKED_LABEL, items: recorded ? notCheckedBlock(nc.items).items : [], recorded } };
|
|
1610
1652
|
}
|
|
1611
1653
|
|
|
1612
1654
|
/**
|
|
@@ -1617,8 +1659,7 @@ export function deriveStepSuccessText(step, arbiterAsks) {
|
|
|
1617
1659
|
* signature.json/prose lines — nothing invented; a piece the books can't
|
|
1618
1660
|
* name carries its own why, never a blank or a guess. Field order (server
|
|
1619
1661
|
* order matches the page's own render order): prose, asks, model, cap
|
|
1620
|
-
* (+redo cap), sources, sends, guardrails,
|
|
1621
|
-
* `deriveStepSuccessText`), signature.
|
|
1662
|
+
* (+redo cap), sources, sends, guardrails, plan (one row per step, amendment 34), signature.
|
|
1622
1663
|
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
1623
1664
|
* @returns {any|null}
|
|
1624
1665
|
*/
|
|
@@ -1629,7 +1670,15 @@ export function getRunJob({
|
|
|
1629
1670
|
if (!run.ok) return null;
|
|
1630
1671
|
if (!existsSync(run.runDir)) return null;
|
|
1631
1672
|
|
|
1632
|
-
|
|
1673
|
+
// M6: the job THIS run ran is its own copy (`<run>/job/`, saved when it started). A run from before M6 has none: it shows the flow's job as it is
|
|
1674
|
+
// now and says so (`jobFrom: 'current'`, `jobFromWhy`). A copy that does not verify is refused by name, never swapped for the flow's job.
|
|
1675
|
+
const copy = readRunJobCopy(run.runDir, catalogue);
|
|
1676
|
+
if (copy.present && !copy.ok) {
|
|
1677
|
+
return {
|
|
1678
|
+
flow, runId, resolved: false, why: `This run's saved copy of its job does not match its signature, so it is not shown: ${copy.reds.join('; ')}`,
|
|
1679
|
+
};
|
|
1680
|
+
}
|
|
1681
|
+
const flowRead = copy.present ? copy : readFlow({ root, name: flow, catalogue });
|
|
1633
1682
|
if (!flowRead.ok) {
|
|
1634
1683
|
return {
|
|
1635
1684
|
flow, runId, resolved: false, why: `readFlow refused: ${flowRead.reds.join('; ')}`,
|
|
@@ -1650,11 +1699,12 @@ export function getRunJob({
|
|
|
1650
1699
|
const asks = a.asks ?? [];
|
|
1651
1700
|
const sends = a.sends ?? [];
|
|
1652
1701
|
const sources = a.sources ?? [];
|
|
1653
|
-
const declSteps = Array.isArray(flowRead.declaration?.steps) ? flowRead.declaration.steps : [];
|
|
1654
1702
|
return {
|
|
1655
1703
|
flow,
|
|
1656
1704
|
runId,
|
|
1657
1705
|
resolved: true,
|
|
1706
|
+
jobFrom: copy.present ? 'run' : 'current',
|
|
1707
|
+
jobFromWhy: copy.present ? null : NO_JOB_COPY_WORDS,
|
|
1658
1708
|
model,
|
|
1659
1709
|
// `model` is read from this run's own audit.jsonl rows, never the signed
|
|
1660
1710
|
// prose/declaration (neither records one) — the page says so in words
|
|
@@ -1684,8 +1734,7 @@ export function getRunJob({
|
|
|
1684
1734
|
guardrails: flowRead.lines
|
|
1685
1735
|
.filter((l) => typeof l.guardrail === 'string' && l.guardrail.length > 0)
|
|
1686
1736
|
.map((l) => ({ line: l.n, guardrail: l.guardrail })),
|
|
1687
|
-
|
|
1688
|
-
success: declSteps.map((s) => ({ step: s.emits, text: deriveStepSuccessText(s, asks) })),
|
|
1737
|
+
plan: buildJobPlan(flowRead.declaration, asks, run.flowDir, typeof sig?.flow === 'string' ? sig.flow : null),
|
|
1689
1738
|
signature: (sig && typeof sig.signedBy === 'string' && typeof sig.signedAt === 'string' && typeof sig.flow === 'string')
|
|
1690
1739
|
? { signedBy: sig.signedBy, signedAt: sig.signedAt, hash: sig.flow }
|
|
1691
1740
|
: null,
|
|
@@ -1969,7 +2018,7 @@ function legacyRunAsks(runDir, hasHistoryRow) {
|
|
|
1969
2018
|
* (hamr's 2026-09-27 live check).
|
|
1970
2019
|
* @returns {any[]}
|
|
1971
2020
|
*/
|
|
1972
|
-
function runAsksInOrder(runDir, hasHistoryRow, endedExpired = false) {
|
|
2021
|
+
function runAsksInOrder(runDir, hasHistoryRow, endedExpired = false, jobEdited = false) {
|
|
1973
2022
|
const archivedResult = listArchivedAsks(runDir);
|
|
1974
2023
|
const rows = archivedResult.archived
|
|
1975
2024
|
? archivedResult.asks.map(normalizeArchivedRow)
|
|
@@ -1988,6 +2037,20 @@ function runAsksInOrder(runDir, hasHistoryRow, endedExpired = false) {
|
|
|
1988
2037
|
.map(({ row }) => row);
|
|
1989
2038
|
// M4c-fix amendment 1 (c): a run ended because its ask expired reads expired, never accepted. The late answer the
|
|
1990
2039
|
// terminal resume consumed was refused, so the newest ask carries `expired` (and says why), not the answer's word.
|
|
2040
|
+
// amendment 17 1A: an ask a Stop set aside takes its words from its OWN place in the run: the step `deriveAskStepInfo` (the one
|
|
2041
|
+
// 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.
|
|
2042
|
+
// Never by counting those rows in order: a Stop that landed before any ask parked writes one too, with no ask behind it.
|
|
2043
|
+
if (ordered.some((a) => a.status === 'stopped')) {
|
|
2044
|
+
const words = stoppedAskWords(ordered, readAudit(runDir));
|
|
2045
|
+
for (let i = 0; i < ordered.length; i++) {
|
|
2046
|
+
if (ordered[i].status === 'stopped' && words[i] !== null) ordered[i] = { ...ordered[i], statusText: words[i] };
|
|
2047
|
+
}
|
|
2048
|
+
// am41 item 4: the newest stopped ask whose step the books cannot name says what the Runs label says (the same words), not a bare "stopped".
|
|
2049
|
+
const newest = ordered.length - 1;
|
|
2050
|
+
if (ordered[newest].status === 'stopped' && words[newest] === null) ordered[newest] = { ...ordered[newest], statusText: STOPPED_UNKNOWN_LINE };
|
|
2051
|
+
// M6 amendment 4: the job was edited since the stop, so no stopped ask promises a Resume
|
|
2052
|
+
if (jobEdited) for (let i = 0; i < ordered.length; i++) if (ordered[i].status === 'stopped') ordered[i] = { ...ordered[i], statusText: JOB_EDITED_LINE };
|
|
2053
|
+
}
|
|
1991
2054
|
const last = ordered[ordered.length - 1];
|
|
1992
2055
|
if (endedExpired && last && (last.status === 'accepted' || last.status === 'redo' || last.status === 'reran')) {
|
|
1993
2056
|
ordered[ordered.length - 1] = { ...last, status: 'expired', reason: null, why: LATE_ANSWER_WHY };
|
|
@@ -2115,11 +2178,11 @@ export function getRunAsks({
|
|
|
2115
2178
|
// Inbox — otherwise an open ask's Ask-tab header/body falls back to the
|
|
2116
2179
|
// raw status word "unanswered" and no time-left, disagreeing with the
|
|
2117
2180
|
// Inbox row for that exact same ask.
|
|
2118
|
-
const ordered = runAsksInOrder(run.runDir, hasHistoryRow, histRow?.outcome === 'ask-expired');
|
|
2119
|
-
const auditRows = readAudit(run.runDir);
|
|
2120
2181
|
const flowRead = readFlow({
|
|
2121
2182
|
root, name: flow, catalogue,
|
|
2122
2183
|
});
|
|
2184
|
+
const ordered = runAsksInOrder(run.runDir, hasHistoryRow, histRow?.outcome === 'ask-expired', runJobEdited(readHaltRecord(run.runDir), histRow ?? null, flowRead));
|
|
2185
|
+
const auditRows = readAudit(run.runDir);
|
|
2123
2186
|
const declSteps = flowRead.ok ? flowRead.declaration.steps : null;
|
|
2124
2187
|
const stepInfo = deriveAskStepInfo(ordered, auditRows, declSteps);
|
|
2125
2188
|
let resume = hasHistoryRow ? null : deriveResumeState({ savedAnswer: readSavedAnswer(run.runDir), attempt: resumeAttempt?.(flow, runId) ?? null, ask: readAsk(run.runDir) });
|
|
@@ -2169,10 +2232,10 @@ export function getRunAsks({
|
|
|
2169
2232
|
* force-`false` here as a second, independent check (belt-and-braces on the
|
|
2170
2233
|
* one thing the brief calls out by name: "the Inbox tab's open count counts
|
|
2171
2234
|
* only truly open asks — parked run, no history row, unexpired, unanswered").
|
|
2172
|
-
* @param {{root: string, resumeAttempt?: (flow: string, runId: string) => any}} opts
|
|
2235
|
+
* @param {{root: string, resumeAttempt?: (flow: string, runId: string) => any, catalogue?: any}} opts
|
|
2173
2236
|
* @returns {any[]}
|
|
2174
2237
|
*/
|
|
2175
|
-
export function listStops({ root, resumeAttempt }) {
|
|
2238
|
+
export function listStops({ root, resumeAttempt, catalogue }) {
|
|
2176
2239
|
const rows = [];
|
|
2177
2240
|
for (const flowName of listFlowNames(root)) {
|
|
2178
2241
|
const flowDir = join(root, flowName);
|
|
@@ -2188,7 +2251,10 @@ export function listStops({ root, resumeAttempt }) {
|
|
|
2188
2251
|
const stuckAskId = !hasHistoryRow && st.stuck ? (resume?.askId ?? null) : null;
|
|
2189
2252
|
const openAskJson = hasHistoryRow ? null : readAsk(run.runDir);
|
|
2190
2253
|
const savedAskId = readSavedAnswer(run.runDir)?.askId;
|
|
2191
|
-
|
|
2254
|
+
// 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)
|
|
2255
|
+
const jobEdited = end !== null && (end.outcome === 'stopped' || end.outcome === 'cap-halt') && catalogue !== undefined
|
|
2256
|
+
&& runJobEdited(readHaltRecord(run.runDir), end, readFlow({ root, name: flowName, catalogue }));
|
|
2257
|
+
const runAsks = runAsksInOrder(run.runDir, hasHistoryRow, end?.outcome === 'ask-expired', jobEdited).map((ask) => ({
|
|
2192
2258
|
flow: flowName,
|
|
2193
2259
|
runId,
|
|
2194
2260
|
...ask,
|