fwdloop 0.19.1 → 0.21.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/README.md +2 -0
- package/bin/fwdloop +22 -13
- package/package.json +1 -1
- package/src/audit-fold.js +177 -0
- package/src/authoring.js +24 -4
- package/src/books.js +4 -3
- package/src/closers.js +49 -2
- package/src/ctx-tools.js +1 -1
- package/src/diary.js +49 -0
- package/src/flow.js +218 -2
- package/src/flowmodel.js +42 -5
- package/src/jobkey.js +25 -0
- package/src/jsonl-append.js +29 -0
- package/src/model-step.js +103 -5
- package/src/monthly.js +3 -2
- package/src/panel/author.js +44 -18
- package/src/panel/authorcard.js +7 -13
- package/src/panel/authorflows.js +118 -24
- package/src/panel/authorresume.js +8 -4
- package/src/panel/authorstart.js +63 -18
- package/src/panel/authortrigger.js +250 -125
- package/src/panel/authorvalues.js +13 -2
- package/src/panel/data.js +279 -43
- package/src/panel/index.html +547 -150
- package/src/panel/needsyou.js +29 -0
- package/src/panel/scheduler.js +21 -22
- package/src/panel/server.js +30 -6
- package/src/primitives.js +44 -2
- package/src/provider.js +3 -2
- package/src/runner.js +58 -22
- package/src/runvalues.js +10 -2
- package/src/schedule.js +135 -0
- package/src/setup.js +0 -21
- package/src/summary-words.js +180 -7
- package/src/thinking.js +39 -0
- package/src/trigger-clock.js +18 -16
- package/src/trigger-files.js +37 -24
- package/src/trigger-line.js +6 -15
- package/src/try-checks.js +62 -0
- package/src/types.js +2 -1
- package/types/audit-fold.d.ts +54 -0
- package/types/authoring.d.ts +33 -2
- package/types/books.d.ts +17 -0
- package/types/ctx-tools.d.ts +1 -0
- package/types/diary.d.ts +57 -0
- package/types/flow.d.ts +106 -0
- package/types/flowmodel.d.ts +25 -3
- package/types/jobkey.d.ts +11 -0
- package/types/jsonl-append.d.ts +6 -0
- package/types/model-step.d.ts +4 -1
- package/types/panel/author.d.ts +47 -17
- package/types/panel/authorcard.d.ts +3 -6
- package/types/panel/authorflows.d.ts +38 -10
- package/types/panel/authorstart.d.ts +15 -2
- package/types/panel/authortrigger.d.ts +73 -41
- package/types/panel/authorvalues.d.ts +6 -0
- package/types/panel/data.d.ts +101 -19
- package/types/panel/needsyou.d.ts +20 -0
- package/types/runvalues.d.ts +5 -0
- package/types/schedule.d.ts +69 -0
- package/types/setup.d.ts +0 -19
- package/types/summary-words.d.ts +105 -2
- package/types/thinking.d.ts +31 -0
- package/types/trigger-clock.d.ts +8 -7
- package/types/trigger-files.d.ts +17 -10
- package/types/trigger-line.d.ts +16 -8
- package/types/try-checks.d.ts +55 -0
- package/types/types.d.ts +10 -1
package/src/panel/data.js
CHANGED
|
@@ -22,11 +22,12 @@
|
|
|
22
22
|
import {
|
|
23
23
|
existsSync, realpathSync,
|
|
24
24
|
} from 'node:fs';
|
|
25
|
+
import { createHash } from 'node:crypto';
|
|
25
26
|
import { plainPlanCheck } from '../plain-checks.js';
|
|
26
27
|
import { join, basename, sep } from 'node:path';
|
|
27
28
|
|
|
28
29
|
import {
|
|
29
|
-
readFlow, readRunJobCopy, listFlowNames, listRunIds, resolveRunDir, checkFlowName, readFileInside, readdirInside,
|
|
30
|
+
readFlow, readPlan, readRunPlan, readRunJobCopy, listFlowNames, listRunIds, resolveRunDir, checkFlowName, readFileInside, readdirInside,
|
|
30
31
|
} from '../flow.js';
|
|
31
32
|
import {
|
|
32
33
|
readAudit, readHistory, endRow, readPidRows, auditRowTokens, auditRowAt, auditRowTools,
|
|
@@ -39,9 +40,14 @@ import { applyRunValues, parseWaitMs, pickRunValues, VALUES_FILE_RE } from '../r
|
|
|
39
40
|
import { readSetup } from '../setup.js';
|
|
40
41
|
import { checkedLines, notCheckedBlock, NOT_CHECKED_LABEL } from '../checked.js';
|
|
41
42
|
import {
|
|
42
|
-
catchUpWords, endedWords, nextInWords, nextTimeWords, scheduledNextFor, scheduledWords,
|
|
43
|
+
NO_COPY_SAY, catchUpWords, endedLineWords, endedWords, needsLeftWords, nextInWords, nextTimeWords, scheduleAuditWords, scheduleBlockWords, scheduleFieldWords, scheduledNextFor, scheduledWords, startedWords,
|
|
43
44
|
} from '../summary-words.js';
|
|
44
45
|
import { MAX_STRUCTURE_RETRIES } from '../drafter.js';
|
|
46
|
+
import { thinkingRuleWords, thinkingTryWords } from '../thinking.js';
|
|
47
|
+
import { readRunThinking } from '../flowmodel.js';
|
|
48
|
+
import {
|
|
49
|
+
isTryRow, loadDiaries, deriveFold, cardLine, summaryLines,
|
|
50
|
+
} from '../audit-fold.js';
|
|
45
51
|
import {
|
|
46
52
|
runLiveness, booksFresh, readResumeLock,
|
|
47
53
|
} from '../liveness.js';
|
|
@@ -711,11 +717,6 @@ export function deriveStepTryMarks(closeClass, rows) {
|
|
|
711
717
|
return rows.map((r) => markForVerdict(r.verdict, closeClass));
|
|
712
718
|
}
|
|
713
719
|
|
|
714
|
-
/** A Stop's notes are not tries: the asked/not-honoured rows, and a `stopped` row that cut no try (no attempt number). */
|
|
715
|
-
function isTryRow(r) {
|
|
716
|
-
return r.verdict !== 'stop-asked' && r.verdict !== 'stop-not-honoured' && !(r.verdict === 'stopped' && !Number.isInteger(r.attempt));
|
|
717
|
-
}
|
|
718
|
-
|
|
719
720
|
/** The name of the one group for audit rows that name no step. */
|
|
720
721
|
const RUN_GROUP = 'run';
|
|
721
722
|
/** The one decider of a row's step name for the Audit tab: its step, else the run's own group name. */
|
|
@@ -874,6 +875,17 @@ export function summarizeSpendRows(spendRows) {
|
|
|
874
875
|
|
|
875
876
|
/** M6 F5: the ONE comparison of a run's halt record with the job on disk (`sameJob`; the runner refuses a Resume otherwise). */
|
|
876
877
|
const haltMatchesJob = (halt, flowRead) => halt.ok && flowRead.ok && halt.halt.signatureHash === flowRead.signature.flow;
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* M9 am12: the job a run is read against on the page = the one it resumes against (`readRunPlan`, its own kept copy). Only a run with no copy at
|
|
881
|
+
* all (before M6) falls back to the workflow's job, for DISPLAY; `ownCopy` is false there and the run cannot be resumed (the runner refuses it by name).
|
|
882
|
+
* @param {{root: string, name: string, catalogue: any, runDir: string}} a
|
|
883
|
+
*/
|
|
884
|
+
function readRunJob(a) {
|
|
885
|
+
const own = readRunPlan(a);
|
|
886
|
+
if (!own.ok && 'noCopy' in own) return { read: readPlan(a), ownCopy: false };
|
|
887
|
+
return { read: own, ownCopy: true };
|
|
888
|
+
}
|
|
877
889
|
/** 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. */
|
|
878
890
|
const runJobEdited = (halt, historyRow, flowRead) => halt.ok && flowRead.ok && historyRow !== null && historyRow.outcome === halt.halt.outcome && !haltMatchesJob(halt, flowRead);
|
|
879
891
|
/** The whole line (Runs, Ask and Inbox alike) of a stopped run whose job was edited since: no Resume is offered. */
|
|
@@ -893,7 +905,7 @@ const JOB_EDITED_LINE = 'stopped — the job was edited; start a new run';
|
|
|
893
905
|
* @returns {any}
|
|
894
906
|
*/
|
|
895
907
|
function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue, attempt = null, startingRun = undefined) {
|
|
896
|
-
const flowRead =
|
|
908
|
+
const { read: flowRead, ownCopy } = readRunJob({ root, name: flowName, catalogue, runDir });
|
|
897
909
|
// M4e amendment 5 item 3 / amendment 4 item 6: the run's own signed values (its newest version) lie over the flow's
|
|
898
910
|
const inForce = flowRead.ok ? applyRunValues(flowRead.arbiter, flowName, flowRead.signature.flow, pickRunValues(runDir)) : null;
|
|
899
911
|
const historyRows = readHistory(flowDir);
|
|
@@ -916,13 +928,14 @@ function loadRunContext(root, flowDir, runDir, flowName, runId, catalogue, attem
|
|
|
916
928
|
flowDir,
|
|
917
929
|
runDir,
|
|
918
930
|
flowRead,
|
|
931
|
+
ownCopy,
|
|
919
932
|
// the arbiter this run executes under (the flow's own unless the run has signed values), or null when the flow does not read
|
|
920
933
|
arbiter: inForce && inForce.ok ? inForce.arbiter : (flowRead.ok ? flowRead.arbiter : null),
|
|
921
934
|
historyRow,
|
|
922
935
|
// M4e amendment 4 item 4: a cap-halted or stopped run that can be continued (`halt.json` is the runner's record)
|
|
923
936
|
resumable: halt.ok && historyRow !== null && historyRow.outcome === halt.halt.outcome,
|
|
924
937
|
// M6 F5: the job on disk is still the one the run halted under (the runner refuses a Resume otherwise: "signature mismatch")
|
|
925
|
-
sameJob: haltMatchesJob(halt, flowRead),
|
|
938
|
+
sameJob: ownCopy && haltMatchesJob(halt, flowRead),
|
|
926
939
|
// M6 amendment 4: the stopped / cap-halted run whose job was edited since (the opposite of `sameJob`, only where the job could be read)
|
|
927
940
|
jobEdited: runJobEdited(halt, historyRow, flowRead),
|
|
928
941
|
// 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)
|
|
@@ -996,6 +1009,19 @@ function lastPidStartedAt(runDir) {
|
|
|
996
1009
|
return typeof at === 'string' && !Number.isNaN(Date.parse(at)) ? at : null;
|
|
997
1010
|
}
|
|
998
1011
|
|
|
1012
|
+
/** M9 am7 item 5: when the run's FIRST process began (a resumed run keeps its first start), or null when no pid row names one. @param {string} runDir */
|
|
1013
|
+
function firstPidStartedAt(runDir) {
|
|
1014
|
+
for (const r of readPidRows(runDir)) if (typeof r.startedAt === 'string' && !Number.isNaN(Date.parse(r.startedAt))) return r.startedAt;
|
|
1015
|
+
return null;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/** The run's own `trigger.json` (why it started), or null for a hand run. @param {string} runDir */
|
|
1019
|
+
function readTriggerRecord(runDir) {
|
|
1020
|
+
const f = readFileInside(runDir, 'trigger.json');
|
|
1021
|
+
if (!f.ok) return null;
|
|
1022
|
+
try { const j = JSON.parse(f.text); return j && typeof j === 'object' ? j : null; } catch { return null; }
|
|
1023
|
+
}
|
|
1024
|
+
|
|
999
1025
|
/** The ONE running rule for wording is the glyph's own (`computeGlyph` -> `[▶]`, which already
|
|
1000
1026
|
* folds in `runLiveness`): a run with no end row whose glyph is `[▶]` is running. */
|
|
1001
1027
|
const RUNNING_WHY = 'still running — not finished yet';
|
|
@@ -1007,7 +1033,7 @@ const isRunningNow = (ctx, glyph) => !ctx.historyRow && glyph === '[▶]';
|
|
|
1007
1033
|
* same object, so the page never offers what the door would refuse). `running` is the glyph's own rule (`isRunningNow`);
|
|
1008
1034
|
* a run with no process record yet is `starting`; a parked run (`[·]`/`[!]`, an open ask) is neither.
|
|
1009
1035
|
* @param {any} ctx `loadRunContext`'s result @param {string} glyph `computeGlyph`'s sign
|
|
1010
|
-
* @returns {{canStop: boolean, atAsk: boolean, stopRequested: boolean, starting: boolean, canResume: boolean, resumeOutcome: string|null, spentUsd: number|null, spendComplete: boolean|null, capUsd: number|null}}
|
|
1036
|
+
* @returns {{canStop: boolean, atAsk: boolean, stopRequested: boolean, starting: boolean, canResume: boolean, noCopySay: string|null, resumeOutcome: string|null, spentUsd: number|null, spendComplete: boolean|null, capUsd: number|null}}
|
|
1011
1037
|
*/
|
|
1012
1038
|
export function runControls(ctx, glyph, label = '') {
|
|
1013
1039
|
// M6 F1: ask.json stays on disk once the human has answered, so it blocks `running` only while the ask is unanswered
|
|
@@ -1023,6 +1049,8 @@ export function runControls(ctx, glyph, label = '') {
|
|
|
1023
1049
|
stopRequested: running && stopPending(ctx.runDir),
|
|
1024
1050
|
starting,
|
|
1025
1051
|
canResume,
|
|
1052
|
+
// M9 am12: a run that would be resumable but has no kept copy says why, never silence
|
|
1053
|
+
noCopySay: ctx.resumable === true && ctx.ownCopy === false ? NO_COPY_SAY : null,
|
|
1026
1054
|
resumeOutcome: canResume ? ctx.historyRow.outcome : null,
|
|
1027
1055
|
spentUsd: canResume && typeof ctx.historyRow.spentUsd === 'number' ? ctx.historyRow.spentUsd : null,
|
|
1028
1056
|
spendComplete: canResume ? ctx.historyRow.spendComplete !== false : null,
|
|
@@ -1044,6 +1072,19 @@ export function getRunControls({
|
|
|
1044
1072
|
return runControls(ctx, g.glyph, g.label);
|
|
1045
1073
|
}
|
|
1046
1074
|
|
|
1075
|
+
/**
|
|
1076
|
+
* M6 am9: the glyph and label of one run, by the panel's ONE rule (`computeGlyph`), read straight from the books. `null` when the run does not resolve.
|
|
1077
|
+
* "Red" in the signed text is exactly `glyph === '[✗]'`.
|
|
1078
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
1079
|
+
*/
|
|
1080
|
+
export function getRunGlyph({
|
|
1081
|
+
root, flow, runId, catalogue,
|
|
1082
|
+
}) {
|
|
1083
|
+
const run = resolveRunPath(root, flow, runId);
|
|
1084
|
+
if (!run.ok || !existsSync(run.runDir)) return null;
|
|
1085
|
+
return computeGlyph(loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue, null));
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1047
1088
|
/**
|
|
1048
1089
|
* `GET /api/runs` — every flow under `root`, every run under each flow
|
|
1049
1090
|
* (M4a scope item 2). A flow with zero runs still gets one row (`runId:
|
|
@@ -1108,7 +1149,9 @@ export function listRuns({ root, catalogue, resumeAttempt, startingRun, now = Da
|
|
|
1108
1149
|
pulse: glyphPulses({ glyph, label }),
|
|
1109
1150
|
stuck: glyph === '[II]',
|
|
1110
1151
|
controls,
|
|
1111
|
-
needs:
|
|
1152
|
+
needs: needsYouOf({
|
|
1153
|
+
runDir: run.runDir, ctx, glyph, controls, nowMs: now(), reopenAt: reopenableAt(run.runDir, ctx),
|
|
1154
|
+
}).tag,
|
|
1112
1155
|
live: isRunningNow(ctx, glyph),
|
|
1113
1156
|
model: deriveRunModel(ctx.auditRows),
|
|
1114
1157
|
resume: ctx.resume,
|
|
@@ -1138,7 +1181,7 @@ export function listRuns({ root, catalogue, resumeAttempt, startingRun, now = Da
|
|
|
1138
1181
|
* order given (M4c amendment 1 (c)); a flow's top row is therefore the first
|
|
1139
1182
|
* run of that flow here, so a waiting run is the parent with no second rule:
|
|
1140
1183
|
* 1 waiting on you — least time left first; a stuck run (`[II]`, amendment 2)
|
|
1141
|
-
* after the ones with a timer;
|
|
1184
|
+
* after the ones with a timer, only while it is still in Needs you (M11 am15: a stuck run past its 7 days is section 3);
|
|
1142
1185
|
* 2 running (`[▶]`, the glyph's own liveness rule);
|
|
1143
1186
|
* 3 everything else — finish time `at`, newest first.
|
|
1144
1187
|
* A row with no known time keeps input order at the end of its section.
|
|
@@ -1146,7 +1189,8 @@ export function listRuns({ root, catalogue, resumeAttempt, startingRun, now = Da
|
|
|
1146
1189
|
* @returns {any[]}
|
|
1147
1190
|
*/
|
|
1148
1191
|
export function orderRuns(rows) {
|
|
1149
|
-
|
|
1192
|
+
// M11 am15: a stuck run that has left Needs you (`needs` null: the 7 days, `needsYouOf`) is no longer a top row; it sorts by time like the rest.
|
|
1193
|
+
const sectionOf = (r) => ((r.waiting || (r.stuck && r.needs !== null)) ? 1 : r.glyph === '[▶]' ? 2 : 3);
|
|
1150
1194
|
return rows
|
|
1151
1195
|
.map((row, index) => ({ row, index }))
|
|
1152
1196
|
.sort((a, b) => {
|
|
@@ -1171,23 +1215,100 @@ export function orderRuns(rows) {
|
|
|
1171
1215
|
}
|
|
1172
1216
|
|
|
1173
1217
|
/**
|
|
1174
|
-
*
|
|
1175
|
-
* `Resume`: stuck `[II]`, or stopped `[■]` whose Run tab shows the Resume button.
|
|
1176
|
-
*
|
|
1177
|
-
*
|
|
1178
|
-
* @
|
|
1179
|
-
* @param {string|null} [at] the run's stop time from the books @param {number} [nowMs]
|
|
1180
|
-
* @returns {'Accept'|'Resume'|null}
|
|
1218
|
+
* The ONE rule for a run's Needs-you tag, read off the sign and `runControls` (no second rule). M11 am11 item 1-2: `Answer`: waiting at an open ask (was `Accept`).
|
|
1219
|
+
* `Reopen`: an expired ask that can still be reopened (`reopenAt`, its expiry time, is given). `Resume`: stuck `[II]`, or stopped `[■]` whose Run tab shows the Resume button.
|
|
1220
|
+
* An expired ask that cannot be reopened is never here. This is the tag BEFORE it leaves: see `needsYouOf` for the 7 days and Remove.
|
|
1221
|
+
* @param {string} glyph a `computeGlyph` sign @param {{atAsk: boolean, canResume: boolean}} controls `runControls`' answer @param {string|null} [reopenAt] expiry of a reopenable expired ask
|
|
1222
|
+
* @returns {'Answer'|'Reopen'|'Resume'|null}
|
|
1181
1223
|
*/
|
|
1182
|
-
|
|
1183
|
-
if (glyph === '[·]' && controls.atAsk) return '
|
|
1224
|
+
function needsYouKind(glyph, controls, reopenAt = null) {
|
|
1225
|
+
if (glyph === '[·]' && controls.atAsk) return 'Answer';
|
|
1226
|
+
if (reopenAt !== null) return 'Reopen';
|
|
1184
1227
|
if (glyph !== '[II]' && !(glyph === '[■]' && controls.canResume)) return null;
|
|
1185
|
-
const t = typeof at === 'string' ? Date.parse(at) : NaN;
|
|
1186
|
-
if (Number.isFinite(t) && nowMs - t >= RUNS_LIST_LIMITS.needsYouDays * 86_400_000) return null;
|
|
1187
1228
|
return 'Resume';
|
|
1188
1229
|
}
|
|
1189
1230
|
|
|
1190
|
-
/** M11
|
|
1231
|
+
/** M11 am3 item 5 / am11 item 4: exactly `needsYouDays` old (since the card joined) is out; no readable time stays in. @param {string|null|undefined} at @param {number} nowMs */
|
|
1232
|
+
const needsYouAged = (at, nowMs) => {
|
|
1233
|
+
const t = typeof at === 'string' ? Date.parse(at) : NaN;
|
|
1234
|
+
return Number.isFinite(t) && nowMs - t >= RUNS_LIST_LIMITS.needsYouDays * 86_400_000;
|
|
1235
|
+
};
|
|
1236
|
+
|
|
1237
|
+
/**
|
|
1238
|
+
* The tag with the 7-day rule (M11 am3 item 5, am4 item 1, am11 item 4): the card leaves Needs you `needsYouDays` after it joined. `at` is when it joined: the run's stop time
|
|
1239
|
+
* (a stuck `[II]` run has none; the caller passes the time its saved answer was written) or the ask's expiry for `Reopen`. An `Answer` run is never dropped by age (its ask has its own wait).
|
|
1240
|
+
* @param {string} glyph @param {{atAsk: boolean, canResume: boolean}} controls @param {string|null} [at] @param {number} [nowMs] @param {string|null} [reopenAt]
|
|
1241
|
+
* @returns {'Answer'|'Reopen'|'Resume'|null}
|
|
1242
|
+
*/
|
|
1243
|
+
export function needsYouTag(glyph, controls, at = null, nowMs = Date.now(), reopenAt = null) {
|
|
1244
|
+
const kind = needsYouKind(glyph, controls, reopenAt);
|
|
1245
|
+
if (kind === null || kind === 'Answer') return kind;
|
|
1246
|
+
return needsYouAged(kind === 'Reopen' ? reopenAt : at, nowMs) ? null : kind;
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
/** The marker file of one Needs-you episode: write-once, named by a hash of the episode key (a reopen / resume starts a NEW episode with another key). @param {string} key */
|
|
1250
|
+
export const needsRemovedFile = (key) => `needs-removed-${createHash('sha256').update(key).digest('hex').slice(0, 16)}.json`;
|
|
1251
|
+
|
|
1252
|
+
/** M11 am11 item 3: the human's Remove, written once for the episode it was written for, or null. @param {string} runDir @param {string} key @returns {{at: string}|null} */
|
|
1253
|
+
function readNeedsRemoval(runDir, key) {
|
|
1254
|
+
const f = readFileInside(runDir, needsRemovedFile(key));
|
|
1255
|
+
if (!f.ok) return null;
|
|
1256
|
+
try {
|
|
1257
|
+
const j = JSON.parse(f.text);
|
|
1258
|
+
return j && j.key === key && typeof j.at === 'string' ? { at: j.at } : null;
|
|
1259
|
+
} catch { return null; }
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
/**
|
|
1263
|
+
* M11 am11: where a run stands in Needs you, by the ONE rule (the runs list, the Remove route and the Audit all read it).
|
|
1264
|
+
* `tag`: what the card carries now, or null. `removable`: Remove from Needs you is offered (`Reopen` and `Resume`, never `Answer`). `left`: why a card that would be here is not
|
|
1265
|
+
* (item 3 `{by: 'you', at}`, item 4 `{by: 'age'}`). `key`: the episode a Remove is written for (item 5): the ask and its expiry for `Reopen`, the stop time for a stopped run, the saved-answer
|
|
1266
|
+
* time for a stuck one, so a reopened or resumed run that needs you again is a NEW episode and comes back.
|
|
1267
|
+
* @param {{runDir: string, ctx: any, glyph: string, controls: {atAsk: boolean, canResume: boolean}, nowMs: number, reopenAt: string|null}} o
|
|
1268
|
+
* @returns {{tag: 'Answer'|'Reopen'|'Resume'|null, removable: boolean, left: {by: 'you', at: string}|{by: 'age'}|null, key: string|null}}
|
|
1269
|
+
*/
|
|
1270
|
+
export function needsYouOf({
|
|
1271
|
+
runDir, ctx, glyph, controls, nowMs, reopenAt,
|
|
1272
|
+
}) {
|
|
1273
|
+
const kind = needsYouKind(glyph, controls, reopenAt);
|
|
1274
|
+
if (kind === null) return { tag: null, removable: false, left: null, key: null };
|
|
1275
|
+
if (kind === 'Answer') return { tag: 'Answer', removable: false, left: null, key: null };
|
|
1276
|
+
const stuck = glyph === '[II]';
|
|
1277
|
+
const at = kind === 'Reopen' ? reopenAt : (stuck ? ctx.savedAnswerAt : (ctx.historyRow ? ctx.historyRow.at : null));
|
|
1278
|
+
const key = kind === 'Reopen' ? `ask:${ctx.askJson.askId}@${reopenAt}` : `${stuck ? 'stuck' : 'stop'}:${at ?? ''}`;
|
|
1279
|
+
const removed = readNeedsRemoval(runDir, key);
|
|
1280
|
+
if (removed) return { tag: null, removable: false, left: { by: 'you', at: removed.at }, key };
|
|
1281
|
+
if (needsYouAged(at, nowMs)) return { tag: null, removable: false, left: { by: 'age' }, key };
|
|
1282
|
+
return { tag: kind, removable: true, left: null, key };
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
/**
|
|
1286
|
+
* M11 am11 item 2: the expiry time of this run's ask when it has expired and can still be reopened (the Ask tab's own `reopenOffer` rule), else null.
|
|
1287
|
+
* @param {string} runDir @param {any} ctx `loadRunContext`'s result
|
|
1288
|
+
*/
|
|
1289
|
+
function reopenableAt(runDir, ctx) {
|
|
1290
|
+
if (ctx.historyRow || !ctx.askJson) return null;
|
|
1291
|
+
const savedAskId = readSavedAnswer(runDir)?.askId;
|
|
1292
|
+
const hit = runAsksInOrder(runDir, false).find((a) => reopenOffer(a, ctx.askJson, ctx.resume, savedAskId === a.askId) !== null);
|
|
1293
|
+
return hit && typeof ctx.askJson.expiresAt === 'string' ? ctx.askJson.expiresAt : null;
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
/**
|
|
1297
|
+
* M11 am11: `needsYouOf` for one run, read straight from the books (the Remove route's and the Audit's read; the runs list calls `needsYouOf` itself with the context it already has).
|
|
1298
|
+
* `null` when the run does not resolve.
|
|
1299
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any, nowMs?: number, resumeAttempt?: (flow: string, runId: string) => any}} o
|
|
1300
|
+
*/
|
|
1301
|
+
export function getRunNeeds({
|
|
1302
|
+
root, flow, runId, catalogue, nowMs = Date.now(), resumeAttempt,
|
|
1303
|
+
}) {
|
|
1304
|
+
const run = resolveRunPath(root, flow, runId);
|
|
1305
|
+
if (!run.ok || !existsSync(run.runDir)) return null;
|
|
1306
|
+
const ctx = loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue, resumeAttempt?.(flow, runId) ?? null);
|
|
1307
|
+
const { glyph, label } = computeGlyph(ctx);
|
|
1308
|
+
const controls = runControls(ctx, glyph, label);
|
|
1309
|
+
return { runDir: run.runDir, ...needsYouOf({ runDir: run.runDir, ctx, glyph, controls, nowMs, reopenAt: reopenableAt(run.runDir, ctx) }) };
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1191
1312
|
export const RUNS_LIST_LIMITS = Object.freeze({ quietDays: 30, olderRuns: 7, needsYouDays: 7 });
|
|
1192
1313
|
|
|
1193
1314
|
/**
|
|
@@ -1264,6 +1385,7 @@ function enrichAuditRows(rawRows) {
|
|
|
1264
1385
|
action: deriveAuditAction(row),
|
|
1265
1386
|
tokensDisplay: deriveAuditTokensDisplay(row),
|
|
1266
1387
|
toolsPhrase: deriveAuditToolsPhrase(row),
|
|
1388
|
+
thinkingPhrase: thinkingTryWords(row.thinking), // M4d am26: null for a row that kept no thinking record
|
|
1267
1389
|
atWhy: deriveAuditAtWhy(row),
|
|
1268
1390
|
blocked: isBlockedVerdict(row.verdict),
|
|
1269
1391
|
}));
|
|
@@ -1316,9 +1438,10 @@ function waitingLineOf(ctx) {
|
|
|
1316
1438
|
*/
|
|
1317
1439
|
function jobWaitingLine(root, flowDir, flow, catalogue) {
|
|
1318
1440
|
const ids = listRunIds(flowDir).sort((a, b) => (Number(b.replace(/\D/g, '')) || 0) - (Number(a.replace(/\D/g, '')) || 0));
|
|
1441
|
+
const history = readHistory(flowDir); // `atAsk` needs no end row (`runControls`), so an ended run is skipped by the same `endRow` rule before a context is built for it
|
|
1319
1442
|
for (const id of ids) {
|
|
1320
1443
|
const run = resolveRunDir(flowDir, id);
|
|
1321
|
-
if (!run.ok || !readAsk(run.runDir)) continue; // eslint-disable-line no-continue
|
|
1444
|
+
if (!run.ok || endRow(history, run.runDir, id) !== null || !readAsk(run.runDir)) continue; // eslint-disable-line no-continue
|
|
1322
1445
|
const ctx = loadRunContext(root, flowDir, run.runDir, flow, id, catalogue, null);
|
|
1323
1446
|
const g = computeGlyph(ctx);
|
|
1324
1447
|
if (runControls(ctx, g.glyph, g.label).atAsk) return waitingLineOf(ctx);
|
|
@@ -1326,11 +1449,45 @@ function jobWaitingLine(root, flowDir, flow, catalogue) {
|
|
|
1326
1449
|
return null;
|
|
1327
1450
|
}
|
|
1328
1451
|
|
|
1452
|
+
/**
|
|
1453
|
+
* The Run tab's SCHEDULE block for one job, from the job's schedule facts `t` (`trigger.facts`, or null). ONE builder: the Run tab and the Audit's
|
|
1454
|
+
* `schedule` section (its red sign, M9 am11) both call it, so they cannot disagree.
|
|
1455
|
+
* @param {{root: string, flowDir: string, flow: string, catalogue: any, t: any, home?: string, now: () => number}} o
|
|
1456
|
+
*/
|
|
1457
|
+
function scheduleBlockOf({ root, flowDir, flow, catalogue, t, home, now }) {
|
|
1458
|
+
const fires = t && Array.isArray(t.fires) ? t.fires : [];
|
|
1459
|
+
const lastStart = fires.findLast((x) => x.outcome === 'started' && typeof x.runId === 'string');
|
|
1460
|
+
const lastRec = lastStart ? readTriggerRecord(join(flowDir, 'runs', lastStart.runId)) : null;
|
|
1461
|
+
const lastGlyph = lastStart ? getRunGlyph({ root, flow, runId: lastStart.runId, catalogue }) : null;
|
|
1462
|
+
const latest = fires.length > 0 ? fires[fires.length - 1] : null;
|
|
1463
|
+
return scheduleBlockWords({
|
|
1464
|
+
trigger: t && t.trigger ? t.trigger : null, home,
|
|
1465
|
+
last: lastStart ? { at: lastStart.at, runId: lastStart.runId, outcome: lastGlyph ? (SIGN_WORDS[lastGlyph.glyph] ?? 'ended') : 'ended', catchUp: !!(lastRec && lastRec.catchUp === true) } : null,
|
|
1466
|
+
nextSlotMs: t ? t.nextSlotMs : null, armed: !!(t && t.armed), nowMs: now(),
|
|
1467
|
+
problem: latest && latest.outcome !== 'started' && ['busy', 'monthly-exhausted', 'refused'].includes(latest.outcome) ? latest : null,
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
/**
|
|
1472
|
+
* M9 am11: is a run of this job running now? The runs list's own rule (`isRunningNow`: no end row and the glyph `[▶]`), not a run waiting at its ask.
|
|
1473
|
+
* @param {{root: string, flow: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any, startingRun?: (flow: string, runId: string) => boolean}} o
|
|
1474
|
+
*/
|
|
1475
|
+
function jobHasRunningRun({ root, flow, catalogue, resumeAttempt, startingRun }) {
|
|
1476
|
+
const flowDir = join(root, flow);
|
|
1477
|
+
for (const runId of listRunIds(flowDir)) {
|
|
1478
|
+
const run = resolveRunPath(root, flow, runId);
|
|
1479
|
+
if (!run.ok) continue;
|
|
1480
|
+
const ctx = loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue, resumeAttempt?.(flow, runId) ?? null, startingRun);
|
|
1481
|
+
if (isRunningNow(ctx, computeGlyph(ctx).glyph)) return true;
|
|
1482
|
+
}
|
|
1483
|
+
return false;
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1329
1486
|
/**
|
|
1330
1487
|
* M9 piece 6 (ladder M9 item 7): the summary block at the top of a run page, as data. Words come from `src/summary-words.js` only, built
|
|
1331
1488
|
* from typed facts (the history row's outcome, the declared step's line, the signed trigger and its ledger). `ended` is null while the run
|
|
1332
1489
|
* is live; `scheduled` is null when the job has no trigger; `canSchedule` (am3 item 1) is the trigger door's own `hasGreenRun` answer; `catchUp` is a fixed sentence when this run was started late (am2 item 1).
|
|
1333
|
-
* @returns {{ended: {reason: string, next: string}|null, scheduled: {text: string, next: string, nextRed: boolean}|null, canSchedule: boolean, catchUp: string|null}}
|
|
1490
|
+
* @returns {{ended: {reason: string, next: string}|null, scheduled: {text: string, next: string, nextRed: boolean}|null, schedule: {line1: string, line2: string|null, red: boolean}, canSchedule: boolean, catchUp: string|null}}
|
|
1334
1491
|
*/
|
|
1335
1492
|
function runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }) {
|
|
1336
1493
|
const died = !ctx.historyRow && glyph === '[?]';
|
|
@@ -1342,9 +1499,13 @@ function runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }) {
|
|
|
1342
1499
|
line = lineOfStep(ctx, emits);
|
|
1343
1500
|
}
|
|
1344
1501
|
const send = ctx.arbiter && Array.isArray(ctx.arbiter.sends) ? ctx.arbiter.sends.find((x) => x.target && typeof x.target.path === 'string') : undefined;
|
|
1345
|
-
const
|
|
1502
|
+
const endedPlain = endedWords({
|
|
1346
1503
|
outcome, died, line, destination: send ? send.target.path : null, canResume: ctx.resumable === true && ctx.sameJob === true, home,
|
|
1347
1504
|
});
|
|
1505
|
+
// M9 am7 item 1: ENDED opens with the run's local end date and time, then its outcome word, then today's reason (NEXT stays as it was)
|
|
1506
|
+
const ended = endedPlain === null ? null : {
|
|
1507
|
+
...endedPlain, reason: endedLineWords(ctx.historyRow && typeof ctx.historyRow.at === 'string' ? ctx.historyRow.at : null, outcome === 'rerun' ? null : (SIGN_WORDS[glyph] ?? null), endedPlain.reason),
|
|
1508
|
+
};
|
|
1348
1509
|
let scheduled = null;
|
|
1349
1510
|
const t = typeof triggerRead === 'function' ? triggerRead(ctx.flowName) : null;
|
|
1350
1511
|
if (t && t.trigger) {
|
|
@@ -1356,7 +1517,9 @@ function runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }) {
|
|
|
1356
1517
|
let rec = null;
|
|
1357
1518
|
const f = readFileInside(ctx.runDir, 'trigger.json');
|
|
1358
1519
|
if (f.ok) { try { rec = JSON.parse(f.text); } catch { rec = null; } }
|
|
1359
|
-
|
|
1520
|
+
// M9 am7 items 3-4: the SCHEDULE block replaces the SCHEDULED / NEXT rows. Words: src/summary-words.js, the same owner as the Job tab's Schedule field.
|
|
1521
|
+
const schedule = scheduleBlockOf({ root, flowDir: ctx.flowDir, flow: ctx.flowName, catalogue, t, home, now });
|
|
1522
|
+
return { ended, scheduled, schedule, canSchedule: !!(t && t.hasGreenRun), catchUp: catchUpWords(rec) };
|
|
1360
1523
|
}
|
|
1361
1524
|
|
|
1362
1525
|
/**
|
|
@@ -1387,7 +1550,12 @@ export function getRunDetail({
|
|
|
1387
1550
|
// summed copy. A step with no audit rows at all (never attempted) has no
|
|
1388
1551
|
// entry here — its card falls back to "not started", same as before.
|
|
1389
1552
|
const auditGroupsByStep = {};
|
|
1390
|
-
|
|
1553
|
+
// M4d am29 items 5-6: the cards' marker and new line, and the summary's two lines, come from the SAME fold the Audit draws (src/audit-fold.js)
|
|
1554
|
+
const diaries = loadDiaries(run.runDir);
|
|
1555
|
+
for (const g of deriveAuditGroups(enrichAuditRows(ctx.auditRows))) {
|
|
1556
|
+
const fold = g.run ? null : deriveFold(g, diaries);
|
|
1557
|
+
auditGroupsByStep[g.step] = fold ? { ...g, fold } : g;
|
|
1558
|
+
}
|
|
1391
1559
|
|
|
1392
1560
|
let steps = null;
|
|
1393
1561
|
let stepsWhy = null;
|
|
@@ -1456,6 +1624,10 @@ export function getRunDetail({
|
|
|
1456
1624
|
// (never attempted) — every field below stays `null`/empty rather
|
|
1457
1625
|
// than a guessed 0, matching `deriveAuditGroups`'s own honesty
|
|
1458
1626
|
// rules exactly (it's the SAME group object).
|
|
1627
|
+
// M4d am29 item 6: `[model]` / `[human · ask]` (null for a step with no record), and the one new line (`—` with no record); a human step's time is the page's
|
|
1628
|
+
who: group?.fold?.who ?? null,
|
|
1629
|
+
newLine: cardLine(group?.fold ?? null),
|
|
1630
|
+
lastAnswerAt: group?.fold?.lastAnswer?.at ?? null,
|
|
1459
1631
|
groupState: group ? group.state : null,
|
|
1460
1632
|
timeMs: group ? group.timeMs : null,
|
|
1461
1633
|
cost: group ? group.cost : null,
|
|
@@ -1593,6 +1765,10 @@ export function getRunDetail({
|
|
|
1593
1765
|
signWords: SIGN_WORDS,
|
|
1594
1766
|
pulse: glyphPulses({ glyph, label }),
|
|
1595
1767
|
controls: runControls(ctx, glyph, label),
|
|
1768
|
+
// M11 am11 item 3: where this run stands in Needs you now; the page shows Remove from Needs you only when `removable`
|
|
1769
|
+
needsYou: (({ tag, removable }) => ({ tag, removable }))(needsYouOf({
|
|
1770
|
+
runDir: run.runDir, ctx, glyph, controls: runControls(ctx, glyph, label), nowMs: now(), reopenAt: reopenableAt(run.runDir, ctx),
|
|
1771
|
+
})),
|
|
1596
1772
|
// M9 piece 6: the block at the top of the run page (ENDED / NEXT, SCHEDULED / NEXT), words set by code
|
|
1597
1773
|
summary: runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }),
|
|
1598
1774
|
resume: ctx.resume,
|
|
@@ -1603,6 +1779,8 @@ export function getRunDetail({
|
|
|
1603
1779
|
model,
|
|
1604
1780
|
modelWhy,
|
|
1605
1781
|
spendSummary,
|
|
1782
|
+
// M4d am29 item 5: `calls: …` and `checks: …` (`—` for a run with no diaries)
|
|
1783
|
+
runLines: summaryLines(diaries),
|
|
1606
1784
|
wallMs,
|
|
1607
1785
|
wallMsWhy,
|
|
1608
1786
|
steps,
|
|
@@ -1752,16 +1930,39 @@ export function getDraftBlock(flowDir, runDir) {
|
|
|
1752
1930
|
};
|
|
1753
1931
|
}
|
|
1754
1932
|
|
|
1933
|
+
/**
|
|
1934
|
+
* M4d am29 items 4-6: put each step group's `fold` (src/audit-fold.js) on it, in place. An ask step's fold names the file it asks about
|
|
1935
|
+
* (the artifact its first `reads` entry made), read from the run's own saved job when it can be read; otherwise the Path shows `—`.
|
|
1936
|
+
* @param {any[]} groups @param {string} runDir @param {string} flowDir @param {{root: string, flow: string, catalogue?: any}} o
|
|
1937
|
+
*/
|
|
1938
|
+
function attachFolds(groups, runDir, flowDir, { root, flow, catalogue }) {
|
|
1939
|
+
const d = loadDiaries(runDir);
|
|
1940
|
+
let steps = null;
|
|
1941
|
+
if (catalogue) {
|
|
1942
|
+
const job = readRunJob({ root, name: flow, catalogue, runDir }).read;
|
|
1943
|
+
if (job.ok) steps = job.declaration.steps ?? [];
|
|
1944
|
+
}
|
|
1945
|
+
for (const g of groups) {
|
|
1946
|
+
if (g.run) continue;
|
|
1947
|
+
const decl = steps?.find((x) => x.emits === g.step);
|
|
1948
|
+
const read = Array.isArray(decl?.reads) ? decl.reads[0] : null;
|
|
1949
|
+
const fold = deriveFold(g, d, { about: typeof read === 'string' ? `artifacts/${read}.json` : null });
|
|
1950
|
+
if (fold) g.fold = fold;
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1755
1954
|
/**
|
|
1756
1955
|
* `GET /api/runs/:flow/:runId/audit` — the Audit/logs tab (M4a scope item
|
|
1757
1956
|
* 2): the raw `audit.jsonl` rows, scoped strictly to this run (each run's
|
|
1758
1957
|
* own `audit.jsonl` file already carries only its own rows — there is no
|
|
1759
1958
|
* shared-sidecar contamination risk here the way bareloop's gate-audit
|
|
1760
1959
|
* sidecar had). `null` when the flow/runId doesn't resolve (404).
|
|
1761
|
-
* @param {{root: string, flow: string, runId: string}} opts
|
|
1762
|
-
* @returns {{flow:string, runId:string, rows:any[], groups:any[], draft:ReturnType<typeof getDraftBlock>, empty:boolean, why:string|null}|null}
|
|
1960
|
+
* @param {{root: string, flow: string, runId: string, scheduleRead?: (flow: string) => any, home?: string, catalogue?: any, resumeAttempt?: (flow: string, runId: string) => any, startingRun?: (flow: string, runId: string) => boolean, now?: () => number}} opts
|
|
1961
|
+
* @returns {{flow:string, runId:string, rows:any[], groups:any[], draft:ReturnType<typeof getDraftBlock>, needsLeft: string|null, schedule: ReturnType<typeof scheduleAuditWords>, empty:boolean, why:string|null}|null}
|
|
1763
1962
|
*/
|
|
1764
|
-
export function getRunAudit({
|
|
1963
|
+
export function getRunAudit({
|
|
1964
|
+
root, flow, runId, scheduleRead, home, catalogue, resumeAttempt, startingRun, now = Date.now,
|
|
1965
|
+
}) {
|
|
1765
1966
|
const run = resolveRunPath(root, flow, runId);
|
|
1766
1967
|
if (!run.ok) return null;
|
|
1767
1968
|
if (!existsSync(run.runDir)) return null;
|
|
@@ -1773,6 +1974,9 @@ export function getRunAudit({ root, flow, runId }) {
|
|
|
1773
1974
|
// (`tokensDisplay`) and the new Time column's old-row "why" (`atWhy`) are
|
|
1774
1975
|
// likewise derived here, off this same row, never client-side.
|
|
1775
1976
|
const rows = enrichAuditRows(rawRows);
|
|
1977
|
+
// M4d am29 items 4 and 7: each step's fold is read off the run's files on disk ($0 replay); a step with no record (an older run) has none and draws as before
|
|
1978
|
+
const groups = deriveAuditGroups(rows);
|
|
1979
|
+
attachFolds(groups, run.runDir, run.flowDir, { root, flow, catalogue });
|
|
1776
1980
|
return {
|
|
1777
1981
|
flow,
|
|
1778
1982
|
runId,
|
|
@@ -1780,8 +1984,26 @@ export function getRunAudit({ root, flow, runId }) {
|
|
|
1780
1984
|
// hamr's 2026-09-27 exit-check review #1: the Audit tab's grouped-by-
|
|
1781
1985
|
// step header pieces, computed here off these SAME enriched rows —
|
|
1782
1986
|
// never a second, client-side re-grouping.
|
|
1783
|
-
groups
|
|
1987
|
+
groups,
|
|
1784
1988
|
draft: getDraftBlock(run.flowDir, run.runDir),
|
|
1989
|
+
// M11 am11 items 3-4: the one row that says why the card left Needs you (by your Remove, or after 7 days); words: src/summary-words.js
|
|
1990
|
+
needsLeft: catalogue ? needsLeftWords(getRunNeeds({
|
|
1991
|
+
root, flow, runId, catalogue, nowMs: now(), resumeAttempt,
|
|
1992
|
+
})?.left ?? null) : null,
|
|
1993
|
+
// M9 am9 / am11: the `schedule` section, one for every run of a job that has a schedule now (null otherwise); words: src/summary-words.js
|
|
1994
|
+
schedule: (() => {
|
|
1995
|
+
const t = typeof scheduleRead === 'function' ? scheduleRead(flow) : null;
|
|
1996
|
+
if (!t) return null; // no schedule now: scheduleAuditWords still answers for a cancelled job that has am16 rows (M9 am18), else null
|
|
1997
|
+
const rec = readTriggerRecord(run.runDir);
|
|
1998
|
+
const at = firstPidStartedAt(run.runDir) ?? (rec && typeof rec.at === 'string' ? rec.at : null); // the fire's own stamp when the run kept no pid row yet
|
|
1999
|
+
const sched = scheduleAuditWords({
|
|
2000
|
+
trigger: t.trigger, runId, from: t.from ?? null, rec, startMs: at === null || Number.isNaN(Date.parse(at)) ? null : Date.parse(at),
|
|
2001
|
+
block: scheduleBlockOf({ root, flowDir: run.flowDir, flow, catalogue, t, home, now }),
|
|
2002
|
+
running: jobHasRunningRun({ root, flow, catalogue, resumeAttempt, startingRun }),
|
|
2003
|
+
fires: Array.isArray(t.allFires) ? t.allFires : [],
|
|
2004
|
+
});
|
|
2005
|
+
return sched === null ? null : { ...sched, word: SIGN_WORDS[sched.sign] ?? null }; // M9 am23: the header's word, from the one sign->word table
|
|
2006
|
+
})(),
|
|
1785
2007
|
empty: rows.length === 0,
|
|
1786
2008
|
why: rows.length === 0 ? 'audit.jsonl is empty or missing — no attempt has been made yet' : null,
|
|
1787
2009
|
};
|
|
@@ -1832,11 +2054,11 @@ function buildJobPlan(declaration, asks, flowDir, flowHash = null) {
|
|
|
1832
2054
|
* name carries its own why, never a blank or a guess. Field order (server
|
|
1833
2055
|
* order matches the page's own render order): prose, asks, model, cap
|
|
1834
2056
|
* (+redo cap), sources, sends, guardrails, plan (one row per step, amendment 34), signature.
|
|
1835
|
-
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
2057
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any, scheduleRead?: (flow: string) => any, home?: string}} opts
|
|
1836
2058
|
* @returns {any|null}
|
|
1837
2059
|
*/
|
|
1838
2060
|
export function getRunJob({
|
|
1839
|
-
root, flow, runId, catalogue,
|
|
2061
|
+
root, flow, runId, catalogue, scheduleRead, home,
|
|
1840
2062
|
}) {
|
|
1841
2063
|
const run = resolveRunPath(root, flow, runId);
|
|
1842
2064
|
if (!run.ok) return null;
|
|
@@ -1875,6 +2097,16 @@ export function getRunJob({
|
|
|
1875
2097
|
flow,
|
|
1876
2098
|
runId,
|
|
1877
2099
|
resolved: true,
|
|
2100
|
+
// M9 am6 items 1-2 / am7 item 5: how this run began and the workflow's schedule now; words from src/summary-words.js, the same owner as the Run tab's SCHEDULE block
|
|
2101
|
+
started: startedWords(readTriggerRecord(run.runDir), (() => { const at = firstPidStartedAt(run.runDir); return at === null ? null : Date.parse(at); })(), home),
|
|
2102
|
+
schedule: (() => {
|
|
2103
|
+
const f = typeof scheduleRead === 'function' ? scheduleRead(flow) : null;
|
|
2104
|
+
return scheduleFieldWords({
|
|
2105
|
+
trigger: f && f.trigger ? f.trigger : null, from: f?.from ?? null, model: f?.model ?? null, destination: f?.destination ?? null, inputs: f?.inputs ?? null, home,
|
|
2106
|
+
});
|
|
2107
|
+
})(),
|
|
2108
|
+
// M4d am28: the run's rule from its own thinking.json; a run with none (before am25) reads `—` (thinkingRuleWords(null)); the row always shows
|
|
2109
|
+
thinkingRule: thinkingRuleWords(readRunThinking(run.runDir)),
|
|
1878
2110
|
jobFrom: copy.present ? 'run' : 'current',
|
|
1879
2111
|
jobFromWhy: copy.present ? null : NO_JOB_COPY_WORDS,
|
|
1880
2112
|
model,
|
|
@@ -2334,11 +2566,11 @@ export function groupAskBlocks(asks) {
|
|
|
2334
2566
|
* M4b piece 4: also carries `resume` (the SAME `deriveResumeState` the run
|
|
2335
2567
|
* detail carries, `null` for a finished run or nothing to say) so the Ask tab
|
|
2336
2568
|
* can tell "open, answerable" from "answer saved" without a second fetch.
|
|
2337
|
-
* @param {{root: string, flow: string, runId: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any}} opts
|
|
2338
|
-
* @returns {{flow:string, runId:string, asks:any[], resume: any, blocks: any[]}|null}
|
|
2569
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any, now?: () => number}} opts
|
|
2570
|
+
* @returns {{flow:string, runId:string, asks:any[], resume: any, blocks: any[], needsYou: {tag: string|null, removable: boolean}}|null}
|
|
2339
2571
|
*/
|
|
2340
2572
|
export function getRunAsks({
|
|
2341
|
-
root, flow, runId, catalogue, resumeAttempt,
|
|
2573
|
+
root, flow, runId, catalogue, resumeAttempt, now = Date.now,
|
|
2342
2574
|
}) {
|
|
2343
2575
|
const run = resolveRunPath(root, flow, runId);
|
|
2344
2576
|
if (!run.ok) return null;
|
|
@@ -2350,8 +2582,8 @@ export function getRunAsks({
|
|
|
2350
2582
|
// Inbox — otherwise an open ask's Ask-tab header/body falls back to the
|
|
2351
2583
|
// raw status word "unanswered" and no time-left, disagreeing with the
|
|
2352
2584
|
// Inbox row for that exact same ask.
|
|
2353
|
-
const flowRead =
|
|
2354
|
-
root, name: flow, catalogue,
|
|
2585
|
+
const { read: flowRead } = readRunJob({
|
|
2586
|
+
root, name: flow, catalogue, runDir: run.runDir,
|
|
2355
2587
|
});
|
|
2356
2588
|
const ordered = runAsksInOrder(run.runDir, hasHistoryRow, histRow?.outcome === 'ask-expired', runJobEdited(readHaltRecord(run.runDir), histRow ?? null, flowRead));
|
|
2357
2589
|
const auditRows = readAudit(run.runDir);
|
|
@@ -2384,8 +2616,12 @@ export function getRunAsks({
|
|
|
2384
2616
|
stepLine: stepInfo[i].line,
|
|
2385
2617
|
stepWhy: stepInfo[i].why,
|
|
2386
2618
|
}));
|
|
2619
|
+
// M11 am11 item 3: the Ask tab of an expired-ask run offers Remove from Needs you when the card is in Needs you now
|
|
2620
|
+
const needs = getRunNeeds({
|
|
2621
|
+
root, flow, runId, catalogue, resumeAttempt, nowMs: now(),
|
|
2622
|
+
});
|
|
2387
2623
|
return {
|
|
2388
|
-
flow, runId, asks, resume, blocks: groupAskBlocks(asks),
|
|
2624
|
+
flow, runId, asks, resume, blocks: groupAskBlocks(asks), needsYou: { tag: needs?.tag ?? null, removable: needs?.removable === true },
|
|
2389
2625
|
};
|
|
2390
2626
|
}
|
|
2391
2627
|
|
|
@@ -2425,7 +2661,7 @@ export function listStops({ root, resumeAttempt, catalogue }) {
|
|
|
2425
2661
|
const savedAskId = readSavedAnswer(run.runDir)?.askId;
|
|
2426
2662
|
// 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)
|
|
2427
2663
|
const jobEdited = end !== null && (end.outcome === 'stopped' || end.outcome === 'cap-halt') && catalogue !== undefined
|
|
2428
|
-
&& runJobEdited(readHaltRecord(run.runDir), end,
|
|
2664
|
+
&& runJobEdited(readHaltRecord(run.runDir), end, readRunJob({ root, name: flowName, catalogue, runDir: run.runDir }).read);
|
|
2429
2665
|
const runAsks = runAsksInOrder(run.runDir, hasHistoryRow, end?.outcome === 'ask-expired', jobEdited).map((ask) => ({
|
|
2430
2666
|
flow: flowName,
|
|
2431
2667
|
runId,
|