fwdloop 0.10.0 → 0.12.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 +130 -20
- package/package.json +1 -1
- package/src/ask.js +200 -8
- package/src/authoring.js +34 -6
- package/src/config.js +255 -0
- package/src/drafter.js +12 -8
- package/src/keysfile.js +180 -0
- package/src/liveness.js +7 -7
- package/src/model-step.js +16 -6
- package/src/monthly.js +231 -0
- package/src/panel/data.js +200 -73
- package/src/panel/index.html +750 -120
- package/src/panel/lock.js +42 -0
- package/src/panel/resume.js +43 -7
- package/src/panel/server.js +295 -47
- package/src/panel/settings.js +268 -0
- package/src/provider.js +194 -35
- package/src/providershapes.js +19 -0
- package/src/runner.js +47 -10
- package/types/ask.d.ts +70 -1
- package/types/authoring.d.ts +3 -2
- package/types/config.d.ts +51 -0
- package/types/drafter.d.ts +4 -2
- package/types/keysfile.d.ts +90 -0
- package/types/liveness.d.ts +2 -1
- package/types/model-step.d.ts +3 -1
- package/types/monthly.d.ts +109 -0
- package/types/panel/data.d.ts +108 -29
- package/types/panel/lock.d.ts +21 -0
- package/types/panel/resume.d.ts +12 -1
- package/types/panel/server.d.ts +39 -3
- package/types/panel/settings.d.ts +23 -0
- package/types/provider.d.ts +126 -70
- package/types/providershapes.d.ts +11 -0
package/src/panel/data.js
CHANGED
|
@@ -33,18 +33,20 @@ import {
|
|
|
33
33
|
import { readAsk, readRunState, readLog } from '../runner.js';
|
|
34
34
|
import { readSpendRows } from '../provider.js';
|
|
35
35
|
import {
|
|
36
|
-
runLiveness, booksFresh, readResumeLock,
|
|
36
|
+
runLiveness, booksFresh, readResumeLock,
|
|
37
37
|
} from '../liveness.js';
|
|
38
38
|
import {
|
|
39
|
-
readAskEvidence, listArchivedAsks, normalizeDecision, DECISION_STATUS, answerTiming,
|
|
39
|
+
readAskEvidence, listArchivedAsks, normalizeDecision, DECISION_STATUS, decisionStatus, answerTiming,
|
|
40
40
|
} from '../ask.js';
|
|
41
41
|
|
|
42
42
|
/** `{ ok:false, red }` result shape every exported function here can return
|
|
43
43
|
* instead of throwing — the server maps this to a 4xx, never a crash.
|
|
44
|
+
* `why` is an optional machine reason the server can branch on (never matched from `red`).
|
|
44
45
|
* @param {string} red
|
|
45
|
-
* @
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
* @param {'outside-root'} [why]
|
|
47
|
+
* @returns {{ok:false, red:string, why?:'outside-root'}} */
|
|
48
|
+
function refuse(red, why) {
|
|
49
|
+
return why ? { ok: false, red, why } : { ok: false, red };
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
/**
|
|
@@ -63,9 +65,9 @@ function refuse(red) {
|
|
|
63
65
|
* Returns the flow directory, or a refusal.
|
|
64
66
|
* @param {string} root
|
|
65
67
|
* @param {string} flowName
|
|
66
|
-
* @returns {{ok:true, flowDir:string}|{ok:false, red:string}}
|
|
68
|
+
* @returns {{ok:true, flowDir:string}|{ok:false, red:string, why?:'outside-root'}}
|
|
67
69
|
*/
|
|
68
|
-
function resolveFlowDir(root, flowName) {
|
|
70
|
+
export function resolveFlowDir(root, flowName) {
|
|
69
71
|
const check = checkFlowName(flowName);
|
|
70
72
|
if (!check.ok) return refuse(check.red);
|
|
71
73
|
const flowDir = join(root, flowName);
|
|
@@ -75,11 +77,11 @@ function resolveFlowDir(root, flowName) {
|
|
|
75
77
|
try {
|
|
76
78
|
realFlowDir = realpathSync(flowDir);
|
|
77
79
|
realRoot = realpathSync(root);
|
|
78
|
-
} catch
|
|
79
|
-
return refuse(`flow: could not resolve "${
|
|
80
|
+
} catch {
|
|
81
|
+
return refuse(`flow: could not resolve "${flowName}"`);
|
|
80
82
|
}
|
|
81
83
|
if (realFlowDir !== realRoot && !realFlowDir.startsWith(realRoot + sep)) {
|
|
82
|
-
return refuse(`flow: "${flowName}" is a symlink that resolves outside root
|
|
84
|
+
return refuse(`flow: "${flowName}" is a symlink that resolves outside root — refused`, 'outside-root');
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
return { ok: true, flowDir };
|
|
@@ -117,7 +119,7 @@ function resolveRunPath(root, flowName, runId) {
|
|
|
117
119
|
* @param {string|null} askId the open ask's own askId
|
|
118
120
|
* @returns {boolean}
|
|
119
121
|
*/
|
|
120
|
-
function hasConsumedAnswer(runDir, askId) {
|
|
122
|
+
export function hasConsumedAnswer(runDir, askId) {
|
|
121
123
|
if (!existsSync(runDir) || typeof askId !== 'string' || askId.length === 0) return false;
|
|
122
124
|
// F48 round 3: `readdirInside` (`src/flow.js`) skips a symlinked entry
|
|
123
125
|
// rather than reporting its name — a run dir cannot be made to show a
|
|
@@ -157,35 +159,43 @@ export const RESUME_REASON_UNKNOWN = 'reason unknown: the panel restarted, so it
|
|
|
157
159
|
|
|
158
160
|
/**
|
|
159
161
|
* M4b amendment 1 scope 2: the ONE derivation of "answer saved, resume not
|
|
160
|
-
* started"
|
|
161
|
-
* unconsumed. From the panel's in-memory attempt record (`attempt`, may be
|
|
162
|
+
* started" (now worded "your answer is saved; the run stopped before using it" — M4c-fix amendment 3 (c)).
|
|
163
|
+
* From the books: an answer saved (`answer.json` present) and so unconsumed. From the panel's in-memory attempt record (`attempt`, may be
|
|
162
164
|
* null): whether a resume is still being started, and the resume's own refusal.
|
|
163
165
|
* `null` when there is nothing to say (no saved answer and no attempt).
|
|
164
|
-
* M4c amendment 3: `ask` (the run's open `ask.json`, may be null
|
|
165
|
-
* NOT saved in time
|
|
166
|
-
* none, so the
|
|
166
|
+
* M4c amendment 3: `ask` (the run's open `ask.json`, may be null; its `expiresAt` is the effective deadline). A saved
|
|
167
|
+
* answer for that ask that was NOT saved in time, once the deadline has passed, is not a resumable answer: it reads
|
|
168
|
+
* as none, so the ask is expired and offers the reopen (M4c-fix amendment 1 (b)). One with no readable time, before
|
|
169
|
+
* the deadline, reads `broken` (amendment 1 (a)).
|
|
167
170
|
* @param {{savedAnswer: {askId:string, decision:string|null, answeredAt?:string|null}|null, attempt: any, ask?: any}} ctx
|
|
168
|
-
* @returns {{state: 'starting'|'not-started'|'took-over', askId: string|null, tries: number|null, maxTries: number|null, reason: string|null, label: string}|null}
|
|
171
|
+
* @returns {{state: 'starting'|'not-started'|'broken'|'took-over', askId: string|null, tries: number|null, maxTries: number|null, reason: string|null, label: string}|null}
|
|
169
172
|
*/
|
|
170
173
|
export function deriveResumeState({ savedAnswer: saved, attempt, ask = null }) {
|
|
171
|
-
const pastDeadline = ask && saved && ask.askId === saved.askId && Date.parse(ask.expiresAt) < Date.now();
|
|
172
|
-
|
|
174
|
+
const pastDeadline = !!(ask && saved && ask.askId === saved.askId && Date.parse(ask.expiresAt) < Date.now());
|
|
175
|
+
if (saved && pastDeadline && answerTiming(saved.answeredAt, ask.expiresAt) !== 'on-time') return null;
|
|
173
176
|
const tries = attempt ? attempt.tries : null;
|
|
174
177
|
const maxTries = attempt ? attempt.maxTries : null;
|
|
175
|
-
if (
|
|
176
|
-
|
|
178
|
+
if (saved) {
|
|
179
|
+
// M4c-fix amendment 1 (a): a saved answer with no readable time is broken — the resume would refuse it every
|
|
180
|
+
// time. It is not stuck, not "answer saved": the doors come back with a note, and answering again sets it aside.
|
|
181
|
+
if (Number.isNaN(Date.parse(saved.answeredAt ?? ''))) {
|
|
177
182
|
return {
|
|
178
|
-
state: '
|
|
183
|
+
state: 'broken', askId: saved.askId, tries: null, maxTries: null, reason: BROKEN_ANSWER_WHY, label: BROKEN_LABEL,
|
|
179
184
|
};
|
|
180
185
|
}
|
|
181
|
-
|
|
186
|
+
if (attempt && attempt.state === 'in-flight' && attempt.askId === saved.askId) {
|
|
187
|
+
return {
|
|
188
|
+
state: 'starting', askId: saved.askId, tries, maxTries, reason: null, label: 'your answer is saved; the run is picking it up',
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
const mine = attempt && attempt.askId === saved.askId;
|
|
182
192
|
return {
|
|
183
193
|
state: 'not-started',
|
|
184
|
-
askId:
|
|
194
|
+
askId: saved.askId,
|
|
185
195
|
tries: mine ? tries : null,
|
|
186
196
|
maxTries: mine ? maxTries : null,
|
|
187
197
|
reason: mine && typeof attempt.refusal === 'string' && attempt.refusal.length > 0 ? attempt.refusal : RESUME_REASON_UNKNOWN,
|
|
188
|
-
label: 'answer saved
|
|
198
|
+
label: 'your answer is saved; the run stopped before using it',
|
|
189
199
|
};
|
|
190
200
|
}
|
|
191
201
|
if (attempt) {
|
|
@@ -197,35 +207,96 @@ export function deriveResumeState({ savedAnswer: saved, attempt, ask = null }) {
|
|
|
197
207
|
}
|
|
198
208
|
|
|
199
209
|
export const WAITING_LABEL = 'waiting on you (parked, unanswered)';
|
|
200
|
-
export const STUCK_LABEL = 'stuck — answer saved
|
|
201
|
-
export const STUCK_LOCK_LABEL = 'stuck —
|
|
210
|
+
export const STUCK_LABEL = 'stuck — your answer is saved; the run stopped before using it';
|
|
211
|
+
export const STUCK_LOCK_LABEL = 'stuck — an old resume lock is in the way';
|
|
212
|
+
export const BROKEN_LABEL = 'Your saved answer could not be read.';
|
|
213
|
+
export const BROKEN_ANSWER_WHY = 'Please answer again; the broken one is kept aside.';
|
|
202
214
|
export const CRASHED_LABEL = 'crashed after taking your answer — start a fresh run';
|
|
203
215
|
|
|
204
216
|
/**
|
|
205
|
-
* M4c amendment 2 (
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
217
|
+
* M4c-fix amendment 2 (g): the ONE table from a sign to its bold word. Runs, the Inbox and the run header all show
|
|
218
|
+
* the word this table gives (the server stamps it on every row; the page never invents one).
|
|
219
|
+
* @type {Record<string, string>}
|
|
220
|
+
*/
|
|
221
|
+
export const SIGN_WORDS = {
|
|
222
|
+
'[▶]': 'running', '[·]': 'waiting', '[II]': 'stuck', '[!]': 'expired', '[?]': 'crashed', '[✓]': 'passed', '[✗]': 'failed',
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The sign's word and the plain line after the dash. The existing plain line is kept as is; only a line that already
|
|
227
|
+
* opens with the word ("stuck — …") or is the word itself ("passed") loses that repeat, so it is never said twice.
|
|
228
|
+
* `noWord`: a run the human ended on purpose with rerun wears `[✗]` but is never called "failed" (M4b amendment 3),
|
|
229
|
+
* so it shows its plain line alone.
|
|
230
|
+
* @param {string} glyph a `computeGlyph` sign @param {string} label its plain line @param {boolean} [noWord]
|
|
231
|
+
* @returns {{word: string|null, line: string|null}}
|
|
232
|
+
*/
|
|
233
|
+
export function signParts(glyph, label, noWord = false) {
|
|
234
|
+
const word = noWord ? null : (SIGN_WORDS[glyph] ?? null);
|
|
235
|
+
if (word === null) return { word: null, line: label ?? null };
|
|
236
|
+
if (typeof label !== 'string' || label === word) return { word, line: null };
|
|
237
|
+
return { word, line: label.startsWith(`${word} — `) ? label.slice(word.length + 3) : label };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** The sign an Inbox row wears (null for a past answer, which shows its status word instead). */
|
|
241
|
+
function stopGlyph(r) {
|
|
242
|
+
if (r.working) return '[▶]';
|
|
243
|
+
if (r.stuck) return '[II]';
|
|
244
|
+
if (r.waiting || r.resume) return '[·]';
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** The typed reasons a stuck run can have. `retry`: nothing is wrong that the books name, so trying again is the
|
|
249
|
+
* action. `lock-no-holder`: the resume lock has no recorded holder, so trying again can never work. */
|
|
250
|
+
export const STUCK_REASONS = {
|
|
251
|
+
retry: { label: STUCK_LABEL, why: null },
|
|
252
|
+
'lock-no-holder': { label: STUCK_LOCK_LABEL, why: 'the resume lock has no recorded holder (a lock from before holders were recorded, or a torn write)' },
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* The ONE decision "is this run stuck, why, and what does it say" (M4c amendment 2 (a), amendment 3 (e), M4c-fix 15,
|
|
257
|
+
* 16). The answer is saved and not yet taken (`resume.state === 'not-started'`: `answer.json` is on disk; the
|
|
258
|
+
* panel's transient 'starting' and the `late` state are not stuck) and nothing is carrying the run on: the newest
|
|
259
|
+
* pid row's process is not alive AND the resume lock is not held by a live process, nor by one whose liveness
|
|
260
|
+
* cannot be told (`unknown`: never called stuck). The reason is typed, derived from the lock file and the saved
|
|
261
|
+
* answer themselves — never from a refusal string, so it is the same after a panel restart. Everything that shows
|
|
262
|
+
* "stuck" (computeGlyph, the Inbox, Runs, the Ask tab) reads this.
|
|
211
263
|
* @param {{resume?: any, liveness?: 'running'|'gone'|'unknown', lock?: string}} ctx
|
|
212
|
-
* @returns {
|
|
264
|
+
* @returns {{stuck: false, reason: null, label: null, why: null}|{stuck: true, reason: 'retry'|'lock-no-holder', label: string, why: string|null}}
|
|
213
265
|
*/
|
|
214
|
-
export function
|
|
215
|
-
|
|
266
|
+
export function stuckState({ resume, liveness, lock }) {
|
|
267
|
+
if (!resume || resume.state !== 'not-started' || liveness === 'running' || lock === 'live' || lock === 'unknown') {
|
|
268
|
+
return {
|
|
269
|
+
stuck: false, reason: null, label: null, why: null,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
// The runner takes the lock before it reads the answer, so a lock problem is what it would refuse on first.
|
|
273
|
+
const reason = lock === 'empty' ? 'lock-no-holder' : 'retry';
|
|
274
|
+
return { stuck: true, reason, ...STUCK_REASONS[reason] };
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** @param {{resume?: any, liveness?: 'running'|'gone'|'unknown', lock?: string}} ctx @returns {boolean} */
|
|
278
|
+
export function isStuck(ctx) {
|
|
279
|
+
return stuckState(ctx).stuck;
|
|
216
280
|
}
|
|
217
281
|
|
|
218
282
|
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
* the file by hand. Every other stuck run keeps `STUCK_LABEL`.
|
|
223
|
-
* @param {{resume?: any, lock?: string}} ctx
|
|
224
|
-
* @returns {string}
|
|
283
|
+
* The ONE filesystem read behind "stuck": the newest pid row's liveness and the resume lock, read together once.
|
|
284
|
+
* @param {string} runDir
|
|
285
|
+
* @returns {{liveness: 'running'|'gone'|'unknown', lock: 'none'|'live'|'dead'|'unknown'|'empty', lockPath: string}}
|
|
225
286
|
*/
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
287
|
+
function readStuckInputs(runDir) {
|
|
288
|
+
const lock = readResumeLock(runDir);
|
|
289
|
+
return { liveness: runLiveness(runDir), lock: lock.state, lockPath: lock.path };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Read a run's stuck state: the inputs once, then `stuckState`. Used by the Ask tab and the Inbox; the run
|
|
294
|
+
* list's own read is `loadRunContext` (the same `readStuckInputs`).
|
|
295
|
+
* @param {string} runDir @param {any} resume the run's `deriveResumeState`
|
|
296
|
+
*/
|
|
297
|
+
function runStuck(runDir, resume) {
|
|
298
|
+
const inputs = readStuckInputs(runDir);
|
|
299
|
+
return { ...inputs, ...stuckState({ resume, ...inputs }) };
|
|
229
300
|
}
|
|
230
301
|
|
|
231
302
|
/**
|
|
@@ -264,7 +335,7 @@ export function glyphPulses(g) {
|
|
|
264
335
|
* - `[?]` died / unknown — no history row, no open ask, and either the
|
|
265
336
|
* pid row's process is gone (M4c), or there is no pid row / no /proc and
|
|
266
337
|
* the books are older than 10 minutes. Never guessed into `[✗]` or `[✓]`.
|
|
267
|
-
* - `[·]` answer saved
|
|
338
|
+
* - `[·]` your answer is saved; the run stopped before using it / starting (M4b amendment 1) —
|
|
268
339
|
* `answer.json` still on disk (`resume` = `deriveResumeState`): never
|
|
269
340
|
* "waiting on you" (the human already answered) and never a success.
|
|
270
341
|
* - `[▶]` running (M4c) — no end row, no open unanswered ask, and either the
|
|
@@ -287,13 +358,16 @@ export function computeGlyph({
|
|
|
287
358
|
if (historyRow.outcome === 'complete') return { glyph: '[✓]', label: 'passed' };
|
|
288
359
|
// M4b amendment 3: a run the human ended on purpose with rerun is not a failure.
|
|
289
360
|
if (historyRow.outcome === 'rerun') return { glyph: '[✗]', label: 'stopped by you (rerun), a fresh run was started' };
|
|
361
|
+
// M4c-fix amendment 1 (c): a run ended because its ask expired is `[!]` expired, never failed (it spent nothing more).
|
|
362
|
+
if (historyRow.outcome === 'ask-expired') return { glyph: '[!]', label: 'ask expired — nobody answered in time' };
|
|
290
363
|
return { glyph: '[✗]', label: `failed (${historyRow.outcome ?? 'unknown outcome'})` };
|
|
291
364
|
}
|
|
292
365
|
if (askJson && resume && resume.state === 'starting') {
|
|
293
366
|
return { glyph: '[·]', label: resume.label };
|
|
294
367
|
}
|
|
295
368
|
if (askJson && resume && resume.state === 'not-started') {
|
|
296
|
-
|
|
369
|
+
const stuck = stuckState({ resume, liveness, lock });
|
|
370
|
+
if (stuck.stuck) return { glyph: '[II]', label: stuck.label };
|
|
297
371
|
return { glyph: '[▶]', label: 'working on your answer' };
|
|
298
372
|
}
|
|
299
373
|
// No history row. A park never writes one, and a consumed answer file
|
|
@@ -567,7 +641,7 @@ export function isBlockedVerdict(verdict) {
|
|
|
567
641
|
function markForVerdict(verdict, closeClass) {
|
|
568
642
|
if (closeClass === 'hitl' && verdict === 'red') return '✗'; // the human's own redo
|
|
569
643
|
if (verdict === 'green' || verdict === 'hitl') return '✓';
|
|
570
|
-
if (verdict === 'paused' || verdict === 'refused' || verdict === 'ask-timeout' || verdict === 'ask-expired') return '·';
|
|
644
|
+
if (verdict === 'paused' || verdict === 'refused' || verdict === 'ask-timeout' || verdict === 'ask-expired' || verdict === 'ask-reopened' || verdict === 'lock-removed') return '·';
|
|
571
645
|
return '✗';
|
|
572
646
|
}
|
|
573
647
|
|
|
@@ -776,6 +850,7 @@ function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue, attem
|
|
|
776
850
|
const consumedAnswerExists = hasConsumedAnswer(runDir, askJson && typeof askJson.askId === 'string' ? askJson.askId : null);
|
|
777
851
|
// A finished run has no resume to report (its history row says how it ended).
|
|
778
852
|
const resume = historyRow ? null : deriveResumeState({ savedAnswer: readSavedAnswer(runDir), attempt, ask: askJson });
|
|
853
|
+
const stuckInputs = historyRow ? { liveness: 'unknown', lock: 'none' } : readStuckInputs(runDir);
|
|
779
854
|
|
|
780
855
|
return {
|
|
781
856
|
flowName,
|
|
@@ -793,8 +868,8 @@ function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue, attem
|
|
|
793
868
|
hasStateJson: stateJson !== null,
|
|
794
869
|
resume,
|
|
795
870
|
// M4c: only read for a run with no end row (an end row always wins).
|
|
796
|
-
liveness:
|
|
797
|
-
lock:
|
|
871
|
+
liveness: stuckInputs.liveness,
|
|
872
|
+
lock: stuckInputs.lock,
|
|
798
873
|
booksFresh: historyRow ? false : booksFresh(runDir),
|
|
799
874
|
// M4c exit walk: when the process that is working on the run started (its newest pid row's
|
|
800
875
|
// own `startedAt`), so a `[▶]` run has a real time and never "parked or died". Not a book change.
|
|
@@ -874,6 +949,7 @@ export function listRuns({ root, catalogue, resumeAttempt }) {
|
|
|
874
949
|
runId,
|
|
875
950
|
glyph,
|
|
876
951
|
label,
|
|
952
|
+
...signParts(glyph, label, ctx.historyRow?.outcome === 'rerun'),
|
|
877
953
|
pulse: glyphPulses({ glyph, label }),
|
|
878
954
|
stuck: glyph === '[II]',
|
|
879
955
|
resume: ctx.resume,
|
|
@@ -1208,6 +1284,8 @@ export function getRunDetail({
|
|
|
1208
1284
|
runId,
|
|
1209
1285
|
glyph,
|
|
1210
1286
|
label,
|
|
1287
|
+
...signParts(glyph, label, ctx.historyRow?.outcome === 'rerun'),
|
|
1288
|
+
signWords: SIGN_WORDS,
|
|
1211
1289
|
pulse: glyphPulses({ glyph, label }),
|
|
1212
1290
|
resume: ctx.resume,
|
|
1213
1291
|
outcome: ctx.historyRow ? ctx.historyRow.outcome : null,
|
|
@@ -1496,6 +1574,25 @@ function deriveAskOpenFields(ask, hasHistoryRow, resume = null) {
|
|
|
1496
1574
|
};
|
|
1497
1575
|
}
|
|
1498
1576
|
|
|
1577
|
+
/**
|
|
1578
|
+
* M4c-fix amendment 1 (b): does this ask offer the human's "Reopen"? Only the run's current open ask (`ask.json`),
|
|
1579
|
+
* only once its deadline has passed with no usable answer waiting (`resume` is null for it: a late or unreadable saved
|
|
1580
|
+
* answer reads as none, an in-time one is resumed, not reopened), only while the run has not ended. `waitMs` is the
|
|
1581
|
+
* signed wait it repeats; `late` says an answer was saved but came after the deadline. The Run's end row is the caller's `openAskJson === null`.
|
|
1582
|
+
* @param {any} ask one row from `runAsksInOrder` @param {any} openAskJson `readAsk` of the run, or null (ended)
|
|
1583
|
+
* @param {any} resume the run's `deriveResumeState`
|
|
1584
|
+
* @returns {{waitMs: number, late: boolean, why: string}|null}
|
|
1585
|
+
*/
|
|
1586
|
+
function reopenOffer(ask, openAskJson, resume, lateAnswerSaved = false) {
|
|
1587
|
+
if (!openAskJson || openAskJson.askId !== ask.askId || ask.status !== 'expired') return null;
|
|
1588
|
+
if (resume && resume.askId === ask.askId && (resume.state === 'starting' || resume.state === 'not-started')) return null;
|
|
1589
|
+
// `late`: an answer was saved but came after the deadline (the page says so, instead of "nobody answered");
|
|
1590
|
+
// `why` is that line, the one the Ask tab and the Inbox row both draw.
|
|
1591
|
+
return Number.isFinite(openAskJson.waitMs)
|
|
1592
|
+
? { waitMs: openAskJson.waitMs, late: lateAnswerSaved, why: lateAnswerSaved ? LATE_ANSWER_WHY : NO_ANSWER_WHY }
|
|
1593
|
+
: null;
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1499
1596
|
/**
|
|
1500
1597
|
* `readAskEvidence`'s own return shape (`src/ask.js`) carries the draft as
|
|
1501
1598
|
* `{ text: string } | null` (never a bare string) so a caller can tell "no
|
|
@@ -1544,6 +1641,11 @@ function normalizeArchivedRow(a) {
|
|
|
1544
1641
|
* quarantined stale answer for a real consumed one). */
|
|
1545
1642
|
const CONSUMED_ANSWER_RE = /^answer\.(.+)\.consumed\.json$/;
|
|
1546
1643
|
|
|
1644
|
+
/** The line under an ask that ended expired though an answer was saved: the answer came too late. */
|
|
1645
|
+
const LATE_ANSWER_WHY = 'Your answer came after the deadline.';
|
|
1646
|
+
/** The line under an expired ask nobody answered. */
|
|
1647
|
+
const NO_ANSWER_WHY = 'Nobody answered in time.';
|
|
1648
|
+
|
|
1547
1649
|
/**
|
|
1548
1650
|
* The pre-M4a-1 fallback reader (M4a-1 scope item 1): for a run with no
|
|
1549
1651
|
* `asks/` archive directory at all, reconstructs what the books STILL hold —
|
|
@@ -1591,6 +1693,7 @@ function legacyRunAsks(runDir, hasHistoryRow) {
|
|
|
1591
1693
|
} catch {
|
|
1592
1694
|
continue; // eslint-disable-line no-continue -- a torn write is skipped, never invented
|
|
1593
1695
|
}
|
|
1696
|
+
if (parsed === null || typeof parsed !== 'object') continue; // eslint-disable-line no-continue -- valid JSON that is no answer (`null`, a number) is skipped like a torn write
|
|
1594
1697
|
// A consumed legacy row never recovers question/askedAt/expiresAt from
|
|
1595
1698
|
// the CURRENT ask.json, even when its askId happens to still match it —
|
|
1596
1699
|
// the single mutable slot is not a reliable append log for a past ask
|
|
@@ -1603,7 +1706,7 @@ function legacyRunAsks(runDir, hasHistoryRow) {
|
|
|
1603
1706
|
questionWhy: 'question not kept (before M4a-1)',
|
|
1604
1707
|
askedAt: null,
|
|
1605
1708
|
expiresAt: null,
|
|
1606
|
-
status:
|
|
1709
|
+
status: decisionStatus(parsed.decision) ?? `unrecognised: ${parsed.decision}`,
|
|
1607
1710
|
reason: typeof parsed.reason === 'string' ? parsed.reason : null,
|
|
1608
1711
|
answeredAt: typeof parsed.answeredAt === 'string' ? parsed.answeredAt : null,
|
|
1609
1712
|
archived: false,
|
|
@@ -1671,12 +1774,12 @@ function legacyRunAsks(runDir, hasHistoryRow) {
|
|
|
1671
1774
|
* (hamr's 2026-09-27 live check).
|
|
1672
1775
|
* @returns {any[]}
|
|
1673
1776
|
*/
|
|
1674
|
-
function runAsksInOrder(runDir, hasHistoryRow) {
|
|
1777
|
+
function runAsksInOrder(runDir, hasHistoryRow, endedExpired = false) {
|
|
1675
1778
|
const archivedResult = listArchivedAsks(runDir);
|
|
1676
1779
|
const rows = archivedResult.archived
|
|
1677
1780
|
? archivedResult.asks.map(normalizeArchivedRow)
|
|
1678
1781
|
: legacyRunAsks(runDir, hasHistoryRow);
|
|
1679
|
-
|
|
1782
|
+
const ordered = rows
|
|
1680
1783
|
.map((row, index) => ({ row, index }))
|
|
1681
1784
|
.sort((a, b) => {
|
|
1682
1785
|
const am = typeof a.row.askedAt === 'string' ? Date.parse(a.row.askedAt) : NaN;
|
|
@@ -1688,6 +1791,13 @@ function runAsksInOrder(runDir, hasHistoryRow) {
|
|
|
1688
1791
|
return a.index - b.index;
|
|
1689
1792
|
})
|
|
1690
1793
|
.map(({ row }) => row);
|
|
1794
|
+
// M4c-fix amendment 1 (c): a run ended because its ask expired reads expired, never accepted. The late answer the
|
|
1795
|
+
// terminal resume consumed was refused, so the newest ask carries `expired` (and says why), not the answer's word.
|
|
1796
|
+
const last = ordered[ordered.length - 1];
|
|
1797
|
+
if (endedExpired && last && (last.status === 'accepted' || last.status === 'redo' || last.status === 'reran')) {
|
|
1798
|
+
ordered[ordered.length - 1] = { ...last, status: 'expired', reason: null, why: LATE_ANSWER_WHY };
|
|
1799
|
+
}
|
|
1800
|
+
return ordered;
|
|
1691
1801
|
}
|
|
1692
1802
|
|
|
1693
1803
|
/**
|
|
@@ -1803,13 +1913,14 @@ export function getRunAsks({
|
|
|
1803
1913
|
const run = resolveRunPath(root, flow, runId);
|
|
1804
1914
|
if (!run.ok) return null;
|
|
1805
1915
|
if (!existsSync(run.runDir)) return null;
|
|
1806
|
-
const
|
|
1916
|
+
const histRow = readHistory(run.flowDir).find((r) => r && r.runId === runId);
|
|
1917
|
+
const hasHistoryRow = !!histRow;
|
|
1807
1918
|
// hamr's 2026-09-27 browser-walk bug #4: the Ask tab's own asks must carry
|
|
1808
1919
|
// the SAME `open`/`timeLeftMs` fields listStops already computes for the
|
|
1809
1920
|
// Inbox — otherwise an open ask's Ask-tab header/body falls back to the
|
|
1810
1921
|
// raw status word "unanswered" and no time-left, disagreeing with the
|
|
1811
1922
|
// Inbox row for that exact same ask.
|
|
1812
|
-
const ordered = runAsksInOrder(run.runDir, hasHistoryRow);
|
|
1923
|
+
const ordered = runAsksInOrder(run.runDir, hasHistoryRow, histRow?.outcome === 'ask-expired');
|
|
1813
1924
|
const auditRows = readAudit(run.runDir);
|
|
1814
1925
|
const flowRead = readFlow({
|
|
1815
1926
|
root, name: flow, catalogue,
|
|
@@ -1817,18 +1928,26 @@ export function getRunAsks({
|
|
|
1817
1928
|
const declSteps = flowRead.ok ? flowRead.declaration.steps : null;
|
|
1818
1929
|
const stepInfo = deriveAskStepInfo(ordered, auditRows, declSteps);
|
|
1819
1930
|
let resume = hasHistoryRow ? null : deriveResumeState({ savedAnswer: readSavedAnswer(run.runDir), attempt: resumeAttempt?.(flow, runId) ?? null, ask: readAsk(run.runDir) });
|
|
1820
|
-
// M4c amendment 2: the Ask tab says what the run list says — stuck, by the one rule (`
|
|
1821
|
-
let
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1931
|
+
// M4c amendment 2: the Ask tab says what the run list says — stuck, by the one rule (`stuckState`).
|
|
1932
|
+
let runStuckNow = false;
|
|
1933
|
+
if (resume) {
|
|
1934
|
+
const st = runStuck(run.runDir, resume);
|
|
1935
|
+
if (st.stuck) {
|
|
1936
|
+
resume = {
|
|
1937
|
+
...resume,
|
|
1938
|
+
label: st.label,
|
|
1939
|
+
...(resume.reason === RESUME_REASON_UNKNOWN && st.why ? { reason: st.why } : {}),
|
|
1940
|
+
...(st.reason === 'lock-no-holder' ? { lockPath: st.lockPath } : {}),
|
|
1941
|
+
};
|
|
1942
|
+
runStuckNow = true;
|
|
1943
|
+
}
|
|
1827
1944
|
}
|
|
1945
|
+
const openAskJson = hasHistoryRow ? null : readAsk(run.runDir);
|
|
1828
1946
|
const asks = ordered.map((ask, i) => ({
|
|
1829
1947
|
...ask,
|
|
1830
1948
|
...deriveAskOpenFields(ask, hasHistoryRow, resume),
|
|
1831
|
-
|
|
1949
|
+
reopen: reopenOffer(ask, openAskJson, resume, readSavedAnswer(run.runDir)?.askId === ask.askId),
|
|
1950
|
+
stuck: runStuckNow && resume?.askId === ask.askId,
|
|
1832
1951
|
index: i + 1,
|
|
1833
1952
|
total: ordered.length,
|
|
1834
1953
|
stepName: stepInfo[i].step,
|
|
@@ -1862,31 +1981,36 @@ export function listStops({ root, resumeAttempt }) {
|
|
|
1862
1981
|
const rows = [];
|
|
1863
1982
|
for (const flowName of listFlowNames(root)) {
|
|
1864
1983
|
const flowDir = join(root, flowName);
|
|
1865
|
-
const
|
|
1984
|
+
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));
|
|
1866
1987
|
for (const runId of listRunIds(flowDir)) {
|
|
1867
1988
|
const run = resolveRunPath(root, flowName, runId);
|
|
1868
1989
|
if (!run.ok) continue;
|
|
1869
1990
|
const hasHistoryRow = historyRunIds.has(runId);
|
|
1870
1991
|
const resume = hasHistoryRow ? null : deriveResumeState({ savedAnswer: readSavedAnswer(run.runDir), attempt: resumeAttempt?.(flowName, runId) ?? null, ask: readAsk(run.runDir) });
|
|
1871
|
-
// M4c amendment 2: stuck by the ONE rule (`
|
|
1872
|
-
const
|
|
1873
|
-
const stuckAskId = !hasHistoryRow &&
|
|
1874
|
-
|
|
1875
|
-
const
|
|
1876
|
-
const runAsks = runAsksInOrder(run.runDir, hasHistoryRow).map((ask) => ({
|
|
1992
|
+
// M4c amendment 2: stuck by the ONE rule (`stuckState`), marked on the ask whose answer is saved.
|
|
1993
|
+
const st = runStuck(run.runDir, resume);
|
|
1994
|
+
const stuckAskId = !hasHistoryRow && st.stuck ? (resume?.askId ?? null) : null;
|
|
1995
|
+
const openAskJson = hasHistoryRow ? null : readAsk(run.runDir);
|
|
1996
|
+
const savedAskId = readSavedAnswer(run.runDir)?.askId;
|
|
1997
|
+
const runAsks = runAsksInOrder(run.runDir, hasHistoryRow, expiredEnds.has(runId)).map((ask) => ({
|
|
1877
1998
|
flow: flowName,
|
|
1878
1999
|
runId,
|
|
1879
2000
|
...ask,
|
|
1880
2001
|
...deriveAskOpenFields(ask, hasHistoryRow, resume),
|
|
2002
|
+
// an expired ask still open to Reopen says why, by the same offer (and line) its Ask tab draws
|
|
2003
|
+
...(ask.why ? {} : { why: reopenOffer(ask, openAskJson, resume, savedAskId === ask.askId)?.why }),
|
|
1881
2004
|
stuck: stuckAskId !== null && ask.askId === stuckAskId,
|
|
1882
|
-
stuckLabel: stuckAskId !== null && ask.askId === stuckAskId ?
|
|
2005
|
+
stuckLabel: stuckAskId !== null && ask.askId === stuckAskId ? st.label : null,
|
|
2006
|
+
stuckLine: stuckAskId !== null && ask.askId === stuckAskId ? signParts('[II]', st.label ?? '').line : null,
|
|
1883
2007
|
}));
|
|
1884
2008
|
// M4c item 4: a run with no end row, no ask waiting on the human and no
|
|
1885
2009
|
// saved-but-unresumed answer, whose newest pid row is alive, is "working
|
|
1886
2010
|
// on your <decision>" — marked on that run's newest answered ask (the
|
|
1887
2011
|
// one the live process took). `runLiveness` is the ONE liveness rule.
|
|
1888
2012
|
const nothingWaiting = !runAsks.some((r) => r.waiting || r.resume);
|
|
1889
|
-
if (!hasHistoryRow && nothingWaiting &&
|
|
2013
|
+
if (!hasHistoryRow && nothingWaiting && st.liveness === 'running') {
|
|
1890
2014
|
const answered = runAsks.filter((r) => WORKING_WORD[r.status]);
|
|
1891
2015
|
const newest = answered.reduce((best, r) => (best === null || sortMs(r.answeredAt) >= sortMs(best.answeredAt) ? r : best), null);
|
|
1892
2016
|
if (newest) newest.working = WORKING_WORD[newest.status];
|
|
@@ -1894,7 +2018,10 @@ export function listStops({ root, resumeAttempt }) {
|
|
|
1894
2018
|
for (const r of runAsks) rows.push(r);
|
|
1895
2019
|
}
|
|
1896
2020
|
}
|
|
1897
|
-
return orderStops(rows)
|
|
2021
|
+
return orderStops(rows).map((r) => {
|
|
2022
|
+
const glyph = stopGlyph(r);
|
|
2023
|
+
return glyph === null ? r : { ...r, glyph, word: SIGN_WORDS[glyph] };
|
|
2024
|
+
});
|
|
1898
2025
|
}
|
|
1899
2026
|
|
|
1900
2027
|
/** ask status -> the answer's own word, for "working on your <word>…". */
|