fwdloop 0.19.1 → 0.20.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 +22 -13
- package/package.json +1 -1
- package/src/authoring.js +23 -3
- package/src/books.js +3 -2
- package/src/flow.js +218 -2
- package/src/jobkey.js +25 -0
- package/src/jsonl-append.js +29 -0
- 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 +233 -36
- package/src/panel/index.html +330 -124
- package/src/panel/needsyou.js +29 -0
- package/src/panel/scheduler.js +21 -22
- package/src/panel/server.js +30 -6
- package/src/provider.js +3 -2
- package/src/runner.js +10 -10
- 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/trigger-clock.js +18 -16
- package/src/trigger-files.js +37 -24
- package/src/trigger-line.js +6 -15
- package/src/types.js +1 -1
- package/types/authoring.d.ts +32 -2
- package/types/flow.d.ts +106 -0
- package/types/jobkey.d.ts +11 -0
- package/types/jsonl-append.d.ts +6 -0
- 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/trigger-clock.d.ts +8 -7
- package/types/trigger-files.d.ts +17 -10
- package/types/trigger-line.d.ts +16 -8
- package/types/types.d.ts +1 -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,7 +40,7 @@ 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';
|
|
45
46
|
import {
|
|
@@ -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
|
/**
|
|
@@ -1316,9 +1437,10 @@ function waitingLineOf(ctx) {
|
|
|
1316
1437
|
*/
|
|
1317
1438
|
function jobWaitingLine(root, flowDir, flow, catalogue) {
|
|
1318
1439
|
const ids = listRunIds(flowDir).sort((a, b) => (Number(b.replace(/\D/g, '')) || 0) - (Number(a.replace(/\D/g, '')) || 0));
|
|
1440
|
+
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
1441
|
for (const id of ids) {
|
|
1320
1442
|
const run = resolveRunDir(flowDir, id);
|
|
1321
|
-
if (!run.ok || !readAsk(run.runDir)) continue; // eslint-disable-line no-continue
|
|
1443
|
+
if (!run.ok || endRow(history, run.runDir, id) !== null || !readAsk(run.runDir)) continue; // eslint-disable-line no-continue
|
|
1322
1444
|
const ctx = loadRunContext(root, flowDir, run.runDir, flow, id, catalogue, null);
|
|
1323
1445
|
const g = computeGlyph(ctx);
|
|
1324
1446
|
if (runControls(ctx, g.glyph, g.label).atAsk) return waitingLineOf(ctx);
|
|
@@ -1326,11 +1448,45 @@ function jobWaitingLine(root, flowDir, flow, catalogue) {
|
|
|
1326
1448
|
return null;
|
|
1327
1449
|
}
|
|
1328
1450
|
|
|
1451
|
+
/**
|
|
1452
|
+
* 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
|
|
1453
|
+
* `schedule` section (its red sign, M9 am11) both call it, so they cannot disagree.
|
|
1454
|
+
* @param {{root: string, flowDir: string, flow: string, catalogue: any, t: any, home?: string, now: () => number}} o
|
|
1455
|
+
*/
|
|
1456
|
+
function scheduleBlockOf({ root, flowDir, flow, catalogue, t, home, now }) {
|
|
1457
|
+
const fires = t && Array.isArray(t.fires) ? t.fires : [];
|
|
1458
|
+
const lastStart = fires.findLast((x) => x.outcome === 'started' && typeof x.runId === 'string');
|
|
1459
|
+
const lastRec = lastStart ? readTriggerRecord(join(flowDir, 'runs', lastStart.runId)) : null;
|
|
1460
|
+
const lastGlyph = lastStart ? getRunGlyph({ root, flow, runId: lastStart.runId, catalogue }) : null;
|
|
1461
|
+
const latest = fires.length > 0 ? fires[fires.length - 1] : null;
|
|
1462
|
+
return scheduleBlockWords({
|
|
1463
|
+
trigger: t && t.trigger ? t.trigger : null, home,
|
|
1464
|
+
last: lastStart ? { at: lastStart.at, runId: lastStart.runId, outcome: lastGlyph ? (SIGN_WORDS[lastGlyph.glyph] ?? 'ended') : 'ended', catchUp: !!(lastRec && lastRec.catchUp === true) } : null,
|
|
1465
|
+
nextSlotMs: t ? t.nextSlotMs : null, armed: !!(t && t.armed), nowMs: now(),
|
|
1466
|
+
problem: latest && latest.outcome !== 'started' && ['busy', 'monthly-exhausted', 'refused'].includes(latest.outcome) ? latest : null,
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
/**
|
|
1471
|
+
* 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.
|
|
1472
|
+
* @param {{root: string, flow: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any, startingRun?: (flow: string, runId: string) => boolean}} o
|
|
1473
|
+
*/
|
|
1474
|
+
function jobHasRunningRun({ root, flow, catalogue, resumeAttempt, startingRun }) {
|
|
1475
|
+
const flowDir = join(root, flow);
|
|
1476
|
+
for (const runId of listRunIds(flowDir)) {
|
|
1477
|
+
const run = resolveRunPath(root, flow, runId);
|
|
1478
|
+
if (!run.ok) continue;
|
|
1479
|
+
const ctx = loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue, resumeAttempt?.(flow, runId) ?? null, startingRun);
|
|
1480
|
+
if (isRunningNow(ctx, computeGlyph(ctx).glyph)) return true;
|
|
1481
|
+
}
|
|
1482
|
+
return false;
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1329
1485
|
/**
|
|
1330
1486
|
* 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
1487
|
* 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
1488
|
* 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}}
|
|
1489
|
+
* @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
1490
|
*/
|
|
1335
1491
|
function runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }) {
|
|
1336
1492
|
const died = !ctx.historyRow && glyph === '[?]';
|
|
@@ -1342,9 +1498,13 @@ function runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }) {
|
|
|
1342
1498
|
line = lineOfStep(ctx, emits);
|
|
1343
1499
|
}
|
|
1344
1500
|
const send = ctx.arbiter && Array.isArray(ctx.arbiter.sends) ? ctx.arbiter.sends.find((x) => x.target && typeof x.target.path === 'string') : undefined;
|
|
1345
|
-
const
|
|
1501
|
+
const endedPlain = endedWords({
|
|
1346
1502
|
outcome, died, line, destination: send ? send.target.path : null, canResume: ctx.resumable === true && ctx.sameJob === true, home,
|
|
1347
1503
|
});
|
|
1504
|
+
// 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)
|
|
1505
|
+
const ended = endedPlain === null ? null : {
|
|
1506
|
+
...endedPlain, reason: endedLineWords(ctx.historyRow && typeof ctx.historyRow.at === 'string' ? ctx.historyRow.at : null, outcome === 'rerun' ? null : (SIGN_WORDS[glyph] ?? null), endedPlain.reason),
|
|
1507
|
+
};
|
|
1348
1508
|
let scheduled = null;
|
|
1349
1509
|
const t = typeof triggerRead === 'function' ? triggerRead(ctx.flowName) : null;
|
|
1350
1510
|
if (t && t.trigger) {
|
|
@@ -1356,7 +1516,9 @@ function runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }) {
|
|
|
1356
1516
|
let rec = null;
|
|
1357
1517
|
const f = readFileInside(ctx.runDir, 'trigger.json');
|
|
1358
1518
|
if (f.ok) { try { rec = JSON.parse(f.text); } catch { rec = null; } }
|
|
1359
|
-
|
|
1519
|
+
// 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.
|
|
1520
|
+
const schedule = scheduleBlockOf({ root, flowDir: ctx.flowDir, flow: ctx.flowName, catalogue, t, home, now });
|
|
1521
|
+
return { ended, scheduled, schedule, canSchedule: !!(t && t.hasGreenRun), catchUp: catchUpWords(rec) };
|
|
1360
1522
|
}
|
|
1361
1523
|
|
|
1362
1524
|
/**
|
|
@@ -1593,6 +1755,10 @@ export function getRunDetail({
|
|
|
1593
1755
|
signWords: SIGN_WORDS,
|
|
1594
1756
|
pulse: glyphPulses({ glyph, label }),
|
|
1595
1757
|
controls: runControls(ctx, glyph, label),
|
|
1758
|
+
// M11 am11 item 3: where this run stands in Needs you now; the page shows Remove from Needs you only when `removable`
|
|
1759
|
+
needsYou: (({ tag, removable }) => ({ tag, removable }))(needsYouOf({
|
|
1760
|
+
runDir: run.runDir, ctx, glyph, controls: runControls(ctx, glyph, label), nowMs: now(), reopenAt: reopenableAt(run.runDir, ctx),
|
|
1761
|
+
})),
|
|
1596
1762
|
// M9 piece 6: the block at the top of the run page (ENDED / NEXT, SCHEDULED / NEXT), words set by code
|
|
1597
1763
|
summary: runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }),
|
|
1598
1764
|
resume: ctx.resume,
|
|
@@ -1758,10 +1924,12 @@ export function getDraftBlock(flowDir, runDir) {
|
|
|
1758
1924
|
* own `audit.jsonl` file already carries only its own rows — there is no
|
|
1759
1925
|
* shared-sidecar contamination risk here the way bareloop's gate-audit
|
|
1760
1926
|
* 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}
|
|
1927
|
+
* @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
|
|
1928
|
+
* @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
1929
|
*/
|
|
1764
|
-
export function getRunAudit({
|
|
1930
|
+
export function getRunAudit({
|
|
1931
|
+
root, flow, runId, scheduleRead, home, catalogue, resumeAttempt, startingRun, now = Date.now,
|
|
1932
|
+
}) {
|
|
1765
1933
|
const run = resolveRunPath(root, flow, runId);
|
|
1766
1934
|
if (!run.ok) return null;
|
|
1767
1935
|
if (!existsSync(run.runDir)) return null;
|
|
@@ -1782,6 +1950,23 @@ export function getRunAudit({ root, flow, runId }) {
|
|
|
1782
1950
|
// never a second, client-side re-grouping.
|
|
1783
1951
|
groups: deriveAuditGroups(rows),
|
|
1784
1952
|
draft: getDraftBlock(run.flowDir, run.runDir),
|
|
1953
|
+
// 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
|
|
1954
|
+
needsLeft: catalogue ? needsLeftWords(getRunNeeds({
|
|
1955
|
+
root, flow, runId, catalogue, nowMs: now(), resumeAttempt,
|
|
1956
|
+
})?.left ?? null) : null,
|
|
1957
|
+
// 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
|
|
1958
|
+
schedule: (() => {
|
|
1959
|
+
const t = typeof scheduleRead === 'function' ? scheduleRead(flow) : null;
|
|
1960
|
+
if (!t) return null; // no schedule now: scheduleAuditWords still answers for a cancelled job that has am16 rows (M9 am18), else null
|
|
1961
|
+
const rec = readTriggerRecord(run.runDir);
|
|
1962
|
+
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
|
|
1963
|
+
return scheduleAuditWords({
|
|
1964
|
+
trigger: t.trigger, runId, from: t.from ?? null, rec, startMs: at === null || Number.isNaN(Date.parse(at)) ? null : Date.parse(at),
|
|
1965
|
+
block: scheduleBlockOf({ root, flowDir: run.flowDir, flow, catalogue, t, home, now }),
|
|
1966
|
+
running: jobHasRunningRun({ root, flow, catalogue, resumeAttempt, startingRun }),
|
|
1967
|
+
fires: Array.isArray(t.allFires) ? t.allFires : [],
|
|
1968
|
+
});
|
|
1969
|
+
})(),
|
|
1785
1970
|
empty: rows.length === 0,
|
|
1786
1971
|
why: rows.length === 0 ? 'audit.jsonl is empty or missing — no attempt has been made yet' : null,
|
|
1787
1972
|
};
|
|
@@ -1832,11 +2017,11 @@ function buildJobPlan(declaration, asks, flowDir, flowHash = null) {
|
|
|
1832
2017
|
* name carries its own why, never a blank or a guess. Field order (server
|
|
1833
2018
|
* order matches the page's own render order): prose, asks, model, cap
|
|
1834
2019
|
* (+redo cap), sources, sends, guardrails, plan (one row per step, amendment 34), signature.
|
|
1835
|
-
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
2020
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any, scheduleRead?: (flow: string) => any, home?: string}} opts
|
|
1836
2021
|
* @returns {any|null}
|
|
1837
2022
|
*/
|
|
1838
2023
|
export function getRunJob({
|
|
1839
|
-
root, flow, runId, catalogue,
|
|
2024
|
+
root, flow, runId, catalogue, scheduleRead, home,
|
|
1840
2025
|
}) {
|
|
1841
2026
|
const run = resolveRunPath(root, flow, runId);
|
|
1842
2027
|
if (!run.ok) return null;
|
|
@@ -1875,6 +2060,14 @@ export function getRunJob({
|
|
|
1875
2060
|
flow,
|
|
1876
2061
|
runId,
|
|
1877
2062
|
resolved: true,
|
|
2063
|
+
// 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
|
|
2064
|
+
started: startedWords(readTriggerRecord(run.runDir), (() => { const at = firstPidStartedAt(run.runDir); return at === null ? null : Date.parse(at); })(), home),
|
|
2065
|
+
schedule: (() => {
|
|
2066
|
+
const f = typeof scheduleRead === 'function' ? scheduleRead(flow) : null;
|
|
2067
|
+
return scheduleFieldWords({
|
|
2068
|
+
trigger: f && f.trigger ? f.trigger : null, from: f?.from ?? null, model: f?.model ?? null, destination: f?.destination ?? null, inputs: f?.inputs ?? null, home,
|
|
2069
|
+
});
|
|
2070
|
+
})(),
|
|
1878
2071
|
jobFrom: copy.present ? 'run' : 'current',
|
|
1879
2072
|
jobFromWhy: copy.present ? null : NO_JOB_COPY_WORDS,
|
|
1880
2073
|
model,
|
|
@@ -2334,11 +2527,11 @@ export function groupAskBlocks(asks) {
|
|
|
2334
2527
|
* M4b piece 4: also carries `resume` (the SAME `deriveResumeState` the run
|
|
2335
2528
|
* detail carries, `null` for a finished run or nothing to say) so the Ask tab
|
|
2336
2529
|
* 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}
|
|
2530
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any, now?: () => number}} opts
|
|
2531
|
+
* @returns {{flow:string, runId:string, asks:any[], resume: any, blocks: any[], needsYou: {tag: string|null, removable: boolean}}|null}
|
|
2339
2532
|
*/
|
|
2340
2533
|
export function getRunAsks({
|
|
2341
|
-
root, flow, runId, catalogue, resumeAttempt,
|
|
2534
|
+
root, flow, runId, catalogue, resumeAttempt, now = Date.now,
|
|
2342
2535
|
}) {
|
|
2343
2536
|
const run = resolveRunPath(root, flow, runId);
|
|
2344
2537
|
if (!run.ok) return null;
|
|
@@ -2350,8 +2543,8 @@ export function getRunAsks({
|
|
|
2350
2543
|
// Inbox — otherwise an open ask's Ask-tab header/body falls back to the
|
|
2351
2544
|
// raw status word "unanswered" and no time-left, disagreeing with the
|
|
2352
2545
|
// Inbox row for that exact same ask.
|
|
2353
|
-
const flowRead =
|
|
2354
|
-
root, name: flow, catalogue,
|
|
2546
|
+
const { read: flowRead } = readRunJob({
|
|
2547
|
+
root, name: flow, catalogue, runDir: run.runDir,
|
|
2355
2548
|
});
|
|
2356
2549
|
const ordered = runAsksInOrder(run.runDir, hasHistoryRow, histRow?.outcome === 'ask-expired', runJobEdited(readHaltRecord(run.runDir), histRow ?? null, flowRead));
|
|
2357
2550
|
const auditRows = readAudit(run.runDir);
|
|
@@ -2384,8 +2577,12 @@ export function getRunAsks({
|
|
|
2384
2577
|
stepLine: stepInfo[i].line,
|
|
2385
2578
|
stepWhy: stepInfo[i].why,
|
|
2386
2579
|
}));
|
|
2580
|
+
// 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
|
|
2581
|
+
const needs = getRunNeeds({
|
|
2582
|
+
root, flow, runId, catalogue, resumeAttempt, nowMs: now(),
|
|
2583
|
+
});
|
|
2387
2584
|
return {
|
|
2388
|
-
flow, runId, asks, resume, blocks: groupAskBlocks(asks),
|
|
2585
|
+
flow, runId, asks, resume, blocks: groupAskBlocks(asks), needsYou: { tag: needs?.tag ?? null, removable: needs?.removable === true },
|
|
2389
2586
|
};
|
|
2390
2587
|
}
|
|
2391
2588
|
|
|
@@ -2425,7 +2622,7 @@ export function listStops({ root, resumeAttempt, catalogue }) {
|
|
|
2425
2622
|
const savedAskId = readSavedAnswer(run.runDir)?.askId;
|
|
2426
2623
|
// 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
2624
|
const jobEdited = end !== null && (end.outcome === 'stopped' || end.outcome === 'cap-halt') && catalogue !== undefined
|
|
2428
|
-
&& runJobEdited(readHaltRecord(run.runDir), end,
|
|
2625
|
+
&& runJobEdited(readHaltRecord(run.runDir), end, readRunJob({ root, name: flowName, catalogue, runDir: run.runDir }).read);
|
|
2429
2626
|
const runAsks = runAsksInOrder(run.runDir, hasHistoryRow, end?.outcome === 'ask-expired', jobEdited).map((ask) => ({
|
|
2430
2627
|
flow: flowName,
|
|
2431
2628
|
runId,
|