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/summary-words.js
CHANGED
|
@@ -69,13 +69,6 @@ export function nextInWords(ms, now) {
|
|
|
69
69
|
return hours < 48 ? `next in ${hours}h` : `next in ${Math.floor(hours / 24)}d`;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
/** am1, said before a human signs an edit of a job that has a trigger. @param {Trigger|null} t @param {string} [home] */
|
|
73
|
-
export function editClearsWords(t, home) {
|
|
74
|
-
const w = scheduledWords(t, home);
|
|
75
|
-
if (w === null) return null;
|
|
76
|
-
return `This job runs by itself (${w}). Signing this edit clears that back to By hand. You can set it again once the new job has had one good run.`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
72
|
/**
|
|
80
73
|
* NEXT of a job with a trigger. One sentence, first match wins:
|
|
81
74
|
* 1. a run of this job is waiting at its ask (the next run waits too);
|
|
@@ -169,3 +162,183 @@ export function endedWords(f) {
|
|
|
169
162
|
}
|
|
170
163
|
}
|
|
171
164
|
}
|
|
165
|
+
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
// M9 am6 / am7 (docs/wiki/the-module-ladder.md): the words of "how did this run begin", "what schedule does the workflow have", the Audit's schedule rows and
|
|
168
|
+
// the Run tab's SCHEDULE block. ONE owner: the Job tab's Schedule field and the Run tab's SCHEDULE line 1 are built by `scheduleHead`, the run's
|
|
169
|
+
// Started line and the Audit's first row by `startedParts`. Pure: typed facts in, a fixed sentence out; no model text reaches any of it.
|
|
170
|
+
// ---------------------------------------------------------------------------
|
|
171
|
+
|
|
172
|
+
/** "MM/DD HH:MM", local time: the same form as the run cards' `rlShortDate`. @param {number|string} when epoch ms or an ISO string */
|
|
173
|
+
export function shortStamp(when) {
|
|
174
|
+
const d = new Date(typeof when === 'string' ? Date.parse(when) : when);
|
|
175
|
+
if (Number.isNaN(d.getTime())) return '';
|
|
176
|
+
return `${two(d.getMonth() + 1)}/${two(d.getDate())} ${two(d.getHours())}:${two(d.getMinutes())}`;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** "Tue 10/20 09:05": the day name then the short stamp. @param {number} ms */
|
|
180
|
+
export function dayStamp(ms) {
|
|
181
|
+
return `${DAY_SHORT[new Date(ms).getDay()]} ${shortStamp(ms)}`;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* The schedule in words, lower-case first ("every day at 08:15"): the SINGLE line-1 of the Run tab's SCHEDULE block and the first part of the Job tab's
|
|
186
|
+
* Schedule field. `null` (no schedule) has no sentence. @param {Trigger|null} t @param {string} [home]
|
|
187
|
+
*/
|
|
188
|
+
export function scheduleHead(t, home) {
|
|
189
|
+
const w = scheduledWords(t, home);
|
|
190
|
+
return w === null ? null : `${w.charAt(0).toLowerCase()}${w.slice(1)}`;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The Job tab's "Schedule" field: the workflow's schedule now and what it is bound to, parts joined by " · ", or `none`.
|
|
195
|
+
* @param {{trigger: Trigger|null, from?: string|null, model?: string|null, destination?: string|null, inputs?: string[]|null, home?: string}} f
|
|
196
|
+
*/
|
|
197
|
+
export function scheduleFieldWords(f) {
|
|
198
|
+
const head = scheduleHead(f.trigger, f.home);
|
|
199
|
+
if (head === null) return 'none';
|
|
200
|
+
return [head, f.from ? `from ${f.from}` : null, f.model || null, f.destination ? tilde(f.destination, f.home) : null, f.inputs && f.inputs.length > 0 ? f.inputs.join(', ') : null]
|
|
201
|
+
.filter((x) => x !== null).join(' · ');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** A run's `trigger.json` record -> the typed pieces of "how it began", or `null` for a hand run. @param {any} rec */
|
|
205
|
+
function startedKind(rec) {
|
|
206
|
+
if (!rec || typeof rec !== 'object') return null;
|
|
207
|
+
return rec.kind === 'file' || rec.kind === 'clock' ? rec.kind : null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The Job tab's Started line: `By hand · 10/15 13:46`, `By the schedule: every day at 08:15 · catch-up, 10 min late · 10/15 08:16`,
|
|
212
|
+
* `By a new file: aging-oct.csv · …`, `By a file update: aging.csv · …`. The trailing stamp is the run's start (am7 item 5); absent when the books do not hold one.
|
|
213
|
+
* @param {any} rec the run's trigger.json or null @param {number|null} startMs @param {string} [home]
|
|
214
|
+
*/
|
|
215
|
+
export function startedWords(rec, startMs, home) {
|
|
216
|
+
const stamp = startMs === null || startMs === undefined ? null : shortStamp(startMs);
|
|
217
|
+
const kind = startedKind(rec);
|
|
218
|
+
let head = 'By hand';
|
|
219
|
+
if (kind === 'clock') {
|
|
220
|
+
const late = rec.catchUp === true ? (Number.isFinite(rec.lateMin) ? `catch-up, ${rec.lateMin} min late` : 'catch-up') : null;
|
|
221
|
+
head = `By the schedule: ${rec.words ?? rec.trigger ?? 'a schedule'}${late ? ` · ${late}` : ''}`;
|
|
222
|
+
} else if (kind === 'file') {
|
|
223
|
+
const name = typeof rec.file === 'string' ? basename(rec.file) : '';
|
|
224
|
+
const updated = rec.triggerKind === 'file-updated';
|
|
225
|
+
head = `${updated ? 'By a file update' : 'By a new file'}${name ? `: ${name}` : ''}`;
|
|
226
|
+
}
|
|
227
|
+
return stamp ? `${head} · ${stamp}` : head;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** M9 am8 item 3: the busy sentence, in the busy row of `triggers.jsonl` and in the SCHEDULE block. One owner; the scheduler writes it, the words read it. */
|
|
231
|
+
export const SCHEDULE_BUSY_SAY = 'a run of this job was still working';
|
|
232
|
+
|
|
233
|
+
/** A month-used-up fire in the SCHEDULE block's words (am8 item 5): `month used up: $0.01 left, needs $0.50`. @param {any} row */
|
|
234
|
+
function monthUsedUpWords(row) {
|
|
235
|
+
const left = typeof row.leftUsd === 'number' ? `${row.atLeast === true ? 'at most ' : ''}${money(row.leftUsd)} left` : 'not enough left';
|
|
236
|
+
return `month used up: ${left}${typeof row.needUsd === 'number' ? `, needs ${money(row.needUsd)}` : ''}`;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* The Run tab's SCHEDULE block (am7 item 3, am8 items 2-8): `{line1, line2, red}`. Line 1 = the schedule words or `By hand`. Line 2 (only with a schedule):
|
|
241
|
+
* `no run yet` before any fire; else `last <stamp> · ` then the newest fire's words, then `next ...`:
|
|
242
|
+
* - a start: `<run-N> · <outcome>[ · catch-up]` (a run waiting at its ask: `<run-N> · waiting for your answer (the next run does not wait)`), normal;
|
|
243
|
+
* - busy: `busy: a run of this job was still working`, normal (it clears by itself);
|
|
244
|
+
* - month used up: `month used up: $0.01 left, needs $0.50 · next: raise the limit in Settings, or it starts on the 1st`, red only while `nowMs` is still that month;
|
|
245
|
+
* - refused: `refused: <why> · next: fix it in Cancel / modify schedule`, red until a later good start.
|
|
246
|
+
* `next` otherwise: `next <day stamp>`, `next: waiting for a new file` (file schedule) or `next: not armed yet`.
|
|
247
|
+
* @param {{trigger: Trigger|null, home?: string, last: {at: string, runId: string, outcome: string, catchUp: boolean}|null, nextSlotMs: number|null, armed: boolean, problem: any, nowMs?: number}} f
|
|
248
|
+
* `problem`: the newest fire when it started nothing (busy, monthly-exhausted, refused), else null.
|
|
249
|
+
* @returns {{line1: string, line2: string|null, red: boolean}}
|
|
250
|
+
*/
|
|
251
|
+
export function scheduleBlockWords(f) {
|
|
252
|
+
const head = scheduleHead(f.trigger, f.home);
|
|
253
|
+
const tr = f.trigger;
|
|
254
|
+
if (head === null || tr === null) return { line1: 'By hand', line2: null, red: false };
|
|
255
|
+
const file = tr.kind === 'new-file' || tr.kind === 'file-updated';
|
|
256
|
+
const next = file ? 'next: waiting for a new file' : (f.nextSlotMs !== null && f.armed ? `next ${dayStamp(f.nextSlotMs)}` : 'next: not armed yet');
|
|
257
|
+
const p = f.problem;
|
|
258
|
+
if (p) {
|
|
259
|
+
const stamp = `last ${shortStamp(p.at)}`;
|
|
260
|
+
if (p.outcome === 'busy') return { line1: head, line2: `${stamp} · busy: ${SCHEDULE_BUSY_SAY} · ${next}`, red: false };
|
|
261
|
+
if (p.outcome === 'monthly-exhausted') {
|
|
262
|
+
const month = (/** @type {number} */ ms) => { const d = new Date(ms); return d.getFullYear() * 12 + d.getMonth(); };
|
|
263
|
+
const still = month(Date.parse(p.at)) === month(f.nowMs ?? Date.now());
|
|
264
|
+
return { line1: head, line2: `${stamp} · ${monthUsedUpWords(p)} · ${still ? 'next: raise the limit in Settings, or it starts on the 1st' : next}`, red: still };
|
|
265
|
+
}
|
|
266
|
+
return { line1: head, line2: `${stamp} · refused: ${String(p.why ?? 'it was refused').trim()} · next: fix it in Cancel / modify schedule`, red: true };
|
|
267
|
+
}
|
|
268
|
+
if (!f.last) return { line1: head, line2: `no run yet · ${next}`, red: false };
|
|
269
|
+
const outcome = f.last.outcome === 'waiting' ? 'waiting for your answer (the next run does not wait)' : `${f.last.outcome}${f.last.catchUp ? ' · catch-up' : ''}`;
|
|
270
|
+
return { line1: head, line2: `last ${shortStamp(f.last.at)} · ${f.last.runId} · ${outcome} · ${next}`, red: false };
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** M9 am9 item 3: a `refused` fire's reason ends `Nothing started.` once, whether the scheduler already said so or not. @param {unknown} why */
|
|
274
|
+
function refusedWords(why) {
|
|
275
|
+
const w = String(why ?? 'it was refused').trim().replace(/\s*Nothing started\.?$/, '').replace(/\.$/, '');
|
|
276
|
+
return `refused: ${w || 'it was refused'}. Nothing started.`;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** Fires that started nothing (the three outcomes of am8), the only rows `tries` may hold. @param {any} row */
|
|
280
|
+
export const startedNothing = (row) => row && (row.outcome === 'busy' || row.outcome === 'monthly-exhausted' || row.outcome === 'refused');
|
|
281
|
+
|
|
282
|
+
/** M9 am16/am18: a file that waited when the schedule changed and so will not run; its row carries the signed sentence in `say`. @param {any} row */
|
|
283
|
+
const droppedByChange = (row) => !!row && row.outcome === 'schedule-changed' && typeof row.say === 'string';
|
|
284
|
+
|
|
285
|
+
/** M9 am9 item 3: one `tries` row's words, after its stamp; the am8 owners' sentences. @param {any} row a triggers.jsonl row that started nothing */
|
|
286
|
+
function triesRowWords(row) {
|
|
287
|
+
if (droppedByChange(row)) return row.say;
|
|
288
|
+
if (row.outcome === 'busy') return `busy: ${String(row.say ?? SCHEDULE_BUSY_SAY).replace(/\.$/, '')}. Nothing started.`;
|
|
289
|
+
if (row.outcome === 'monthly-exhausted') return `${monthUsedUpWords(row)}. Nothing started.`;
|
|
290
|
+
return refusedWords(row.why);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** M9 am9 item 4: at most this many `tries` show. */
|
|
294
|
+
export const SCHEDULE_TRIES_SHOWN = 7;
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* M9 am9 / am11: a run's Audit `schedule` section (one for every run of a job that has a schedule NOW; `null` when it has none). Folded head
|
|
298
|
+
* `<sign> <schedule words> · from run-7 · 2 tries started nothing`; unfolded rows `this run` and `tries` (stamp + words each).
|
|
299
|
+
* The schedule words are the SAME `line1` the Run tab's SCHEDULE block carries; the sign is `[▶]` while a run of the job is running, `[✗]` when that block is red, else `[·]` (am11).
|
|
300
|
+
* @param {{trigger: Trigger|null, runId: string, from: string|null, rec: any, startMs: number|null, block: {line1: string, red: boolean}, running: boolean, fires: any[]}} f
|
|
301
|
+
* `rec`: this run's trigger.json or null (a hand run); `fires`: every triggers.jsonl row of the job, across every signing.
|
|
302
|
+
* @returns {{sign: string, head: string, rows: Array<{label: string, stamp: string, text: string}>}|null}
|
|
303
|
+
*/
|
|
304
|
+
export function scheduleAuditWords(f) {
|
|
305
|
+
// M9 am18: the am16 `schedule-changed` rows are listed with the tries, also after the schedule is cancelled (no trigger now, such rows exist)
|
|
306
|
+
if (f.trigger === null && !f.fires.some(droppedByChange)) return null;
|
|
307
|
+
const tries = f.fires.filter(startedNothing).reverse();
|
|
308
|
+
const listed = f.fires.filter((r) => startedNothing(r) || droppedByChange(r)).reverse();
|
|
309
|
+
const sign = f.running ? '[\u25B6]' : (f.block.red ? '[\u2717]' : '[\u00B7]');
|
|
310
|
+
const k = tries.length;
|
|
311
|
+
const head = [f.block.line1, f.from ? `from ${f.from}` : null, k > 0 ? `${k} ${k === 1 ? 'try' : 'tries'} started nothing` : null].filter((x) => x !== null).join(' \u00b7 ');
|
|
312
|
+
const kind = startedKind(f.rec);
|
|
313
|
+
let what = 'by hand.';
|
|
314
|
+
if (kind === 'clock') what = `started by the schedule \u00b7 ${f.rec.words ?? f.rec.trigger ?? 'a schedule'}${f.rec.catchUp === true ? ' \u00b7 catch-up' : ''}`;
|
|
315
|
+
else if (kind === 'file') {
|
|
316
|
+
const name = typeof f.rec.file === 'string' ? basename(f.rec.file) : '';
|
|
317
|
+
what = `started by the schedule \u00b7 ${f.rec.triggerKind === 'file-updated' ? 'file update' : 'new file'}${name ? ` ${name}` : ''}`;
|
|
318
|
+
}
|
|
319
|
+
if (f.from !== null && f.from === f.runId) what += kind === null ? ' The schedule was set from this run.' : '. The schedule was set from this run.';
|
|
320
|
+
/** @type {Array<{label: string, stamp: string, text: string}>} */
|
|
321
|
+
const rows = [{ label: 'this run', stamp: f.startMs === null ? '' : shortStamp(f.startMs), text: what }];
|
|
322
|
+
const shown = listed.slice(0, SCHEDULE_TRIES_SHOWN);
|
|
323
|
+
if (shown.length === 0) rows.push({ label: 'tries', stamp: '', text: 'none' });
|
|
324
|
+
else shown.forEach((r, i) => rows.push({ label: i === 0 ? 'tries' : '', stamp: shortStamp(r.at), text: triesRowWords(r) }));
|
|
325
|
+
return { sign, head, rows };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* M11 am11 items 3-4: the Audit row that says why a card left Needs you: `removed from Needs you by you · 10/15 08:15`, or `removed from Needs you after 7 days`. `null` when it did not.
|
|
330
|
+
* @param {{by: 'you', at: string}|{by: 'age'}|null} left
|
|
331
|
+
*/
|
|
332
|
+
export function needsLeftWords(left) {
|
|
333
|
+
if (left === null) return null;
|
|
334
|
+
return left.by === 'you' ? `removed from Needs you by you \u00b7 ${shortStamp(left.at)}` : 'removed from Needs you after 7 days';
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** ENDED (am7 item 1): `10/14 08:16 · passed · Goal met.`. The stamp is the run's local end time; the word is the run's outcome word (none for a run ended on purpose). @param {string|null} at ISO @param {string|null} word @param {string} reason */
|
|
338
|
+
export function endedLineWords(at, word, reason) {
|
|
339
|
+
const stamp = at ? shortStamp(at) : '';
|
|
340
|
+
return [stamp || null, word || null, reason].filter((x) => x !== null).join(' · ');
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** M9 am12: what a stopped run with no kept copy of its job says where Resume would be (a run made before runs kept one). The one owner of these words. */
|
|
344
|
+
export const NO_COPY_SAY = 'This run started before runs kept their own copy of the job, so it cannot carry on. Start a new run.';
|
package/src/trigger-clock.js
CHANGED
|
@@ -12,12 +12,14 @@
|
|
|
12
12
|
// { id:'fire:<slotMs>', kind:'fire', slot, at, catchUp, missed } one run started for that slot
|
|
13
13
|
// Starting a run is NOT this file; the caller does it after `recordFire`.
|
|
14
14
|
import {
|
|
15
|
-
|
|
15
|
+
mkdirSync,
|
|
16
16
|
} from 'node:fs';
|
|
17
17
|
import { dirname } from 'node:path';
|
|
18
18
|
|
|
19
|
+
import { appendRow, ledgerText } from './jsonl-append.js';
|
|
20
|
+
|
|
19
21
|
/** @typedef {{kind:'daily'|'weekdays', hour:number, minute:number} | {kind:'weekly', day:string, hour:number, minute:number}} Schedule */
|
|
20
|
-
/** @typedef {{id:string, kind:'armed'|'fire', at:number, slot?:number, catchUp?:boolean, missed?:number}} ClockRow */
|
|
22
|
+
/** @typedef {{id:string, kind:'armed'|'fire', at:number, slot?:number, catchUp?:boolean, missed?:number, sig?:string}} ClockRow */
|
|
21
23
|
/** @typedef {{fire:boolean, catchUp:boolean, missed:number, slot?:number}} Due */
|
|
22
24
|
|
|
23
25
|
/** A slot seen MORE than this after its set time is a catch-up (M9 am2 item 1). Exactly this late is on time. */
|
|
@@ -114,29 +116,29 @@ export function nextSlot(schedule, afterMs) {
|
|
|
114
116
|
return /** @type {number} */ (found);
|
|
115
117
|
}
|
|
116
118
|
|
|
117
|
-
/** @param {string} file @returns {ClockRow[]} every row on disk, oldest first; a missing file is no rows. */
|
|
118
|
-
export function readRows(file) {
|
|
119
|
-
|
|
120
|
-
return
|
|
119
|
+
/** @param {string} file @param {string} [sig] M9 am20: only the rows of that schedule signing (the one schedule ledger carries every signing's rows); absent = every row @returns {ClockRow[]} every row on disk that parses, oldest first; a missing file is no rows; a line a crash tore mid-append is skipped (`appendOnce` starts each append on a fresh line, so it never glues onto the next row). */
|
|
120
|
+
export function readRows(file, sig) {
|
|
121
|
+
const rows = ledgerText(file).split('\n').filter(Boolean).flatMap((l) => { try { return [JSON.parse(l)]; } catch { return []; } });
|
|
122
|
+
return sig === undefined ? rows : rows.filter((r) => r.sig === sig);
|
|
121
123
|
}
|
|
122
124
|
|
|
123
|
-
/** Append one row; a row whose id is already on disk is refused (write-once). @param {string} file @param {ClockRow} row */
|
|
124
|
-
function appendOnce(file, row) {
|
|
125
|
-
if (readRows(file).some((r) => r.id === row.id)) throw new Error(`ledger row ${row.id} already written`);
|
|
125
|
+
/** Append one row; a row whose id is already on disk (under the same signing) is refused (write-once). @param {string} file @param {ClockRow} row @param {string} [sig] stamped on the row (M9 am20) */
|
|
126
|
+
function appendOnce(file, row, sig) {
|
|
127
|
+
if (readRows(file, sig).some((r) => r.id === row.id)) throw new Error(`ledger row ${row.id} already written`);
|
|
126
128
|
mkdirSync(dirname(file), { recursive: true });
|
|
127
|
-
|
|
129
|
+
appendRow(file, sig === undefined ? row : { ...row, sig });
|
|
128
130
|
}
|
|
129
131
|
|
|
130
|
-
/** The trigger was set at `now`: no slot before this ever fires. @param {string} file @param {number} now */
|
|
131
|
-
export function armTrigger(file, now) {
|
|
132
|
-
appendOnce(file, { id: `armed:${now}`, kind: 'armed', at: now });
|
|
132
|
+
/** The trigger was set at `now`: no slot before this ever fires. @param {string} file @param {number} now @param {string} [sig] */
|
|
133
|
+
export function armTrigger(file, now, sig) {
|
|
134
|
+
appendOnce(file, { id: `armed:${now}`, kind: 'armed', at: now }, sig);
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
/**
|
|
136
138
|
* Record that the run for this due slot is starting. Call BEFORE starting the run: a crash loses a run, never doubles one.
|
|
137
|
-
* @param {string} file @param {Due} d the result of `due` with fire true @param {number} now
|
|
139
|
+
* @param {string} file @param {Due} d the result of `due` with fire true @param {number} now @param {string} [sig]
|
|
138
140
|
*/
|
|
139
|
-
export function recordFire(file, d, now) {
|
|
141
|
+
export function recordFire(file, d, now, sig) {
|
|
140
142
|
if (!d.fire || d.slot === undefined) throw new Error('recordFire needs a due result with fire true');
|
|
141
|
-
appendOnce(file, { id: `fire:${d.slot}`, kind: 'fire', slot: d.slot, at: now, catchUp: d.catchUp, missed: d.missed });
|
|
143
|
+
appendOnce(file, { id: `fire:${d.slot}`, kind: 'fire', slot: d.slot, at: now, catchUp: d.catchUp, missed: d.missed }, sig);
|
|
142
144
|
}
|
package/src/trigger-files.js
CHANGED
|
@@ -14,29 +14,31 @@
|
|
|
14
14
|
// one. 'dropped' = it was deleted / changed before its turn. A sha with a `ran` row never arrives again, whatever its name or mtime; see `arrives` for baseline / queued / dropped.
|
|
15
15
|
// poll() writes nothing: it only reports finished files whose sha is new.
|
|
16
16
|
import {
|
|
17
|
-
|
|
17
|
+
existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync,
|
|
18
18
|
} from 'node:fs';
|
|
19
19
|
import { basename, dirname, join } from 'node:path';
|
|
20
20
|
import { createHash } from 'node:crypto';
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
import { appendRow, ledgerText } from './jsonl-append.js';
|
|
23
|
+
|
|
24
|
+
/** @typedef {{id:string, kind:'baseline'|'arrived'|'ran'|'dropped', sha:string, name:string, size:number, at:number, path?:string, why?:string, of?:string, sig?:string}} SeenRow */
|
|
23
25
|
/** @typedef {{path:string, sha:string, size:number}} ToRun */
|
|
24
26
|
/** @typedef {{path:string, why:string}} Refused */
|
|
25
27
|
|
|
26
28
|
/** Consecutive polls with the same size and mtime before a file is taken. (Two matches in a row = taken on the third sighting.) */
|
|
27
29
|
export const STABLE_POLLS = 2;
|
|
28
30
|
|
|
29
|
-
/** @param {string} file @returns {SeenRow[]} */
|
|
30
|
-
export function readSeen(file) {
|
|
31
|
-
|
|
32
|
-
return
|
|
31
|
+
/** Every row that parses; a line a crash tore mid-append is skipped (it counts as not written). `appendSeen` starts each append on a fresh line, so a torn line can never glue onto the next row. @param {string} file @param {string} [sig] M9 am20: only the rows of that schedule signing (the one schedule ledger carries every signing's rows); absent = every row @returns {SeenRow[]} */
|
|
32
|
+
export function readSeen(file, sig) {
|
|
33
|
+
const rows = ledgerText(file).split('\n').filter(Boolean).flatMap((l) => { try { return [JSON.parse(l)]; } catch { return []; } });
|
|
34
|
+
return sig === undefined ? rows : rows.filter((r) => r.sig === sig);
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
/** The ONE appender: write-once by id (a second row with the same id is not written). @param {string} file @param {SeenRow} row @returns {boolean} written */
|
|
36
|
-
function appendSeen(file, row) {
|
|
37
|
-
if (readSeen(file).some((r) => r.id === row.id)) return false;
|
|
37
|
+
/** The ONE appender: write-once by id within a signing (a second row with the same id is not written). Starts on a fresh line when the file does not end in a newline (a torn last line). @param {string} file @param {SeenRow} row @param {string} [sig] stamped on the row @returns {boolean} written */
|
|
38
|
+
function appendSeen(file, row, sig) {
|
|
39
|
+
if (readSeen(file, sig).some((r) => r.id === row.id)) return false;
|
|
38
40
|
mkdirSync(dirname(file), { recursive: true });
|
|
39
|
-
|
|
41
|
+
appendRow(file, sig === undefined ? row : { ...row, sig });
|
|
40
42
|
return true;
|
|
41
43
|
}
|
|
42
44
|
|
|
@@ -57,22 +59,22 @@ function arrives(rows, it, mode) {
|
|
|
57
59
|
if (mine.some((r) => r.kind === 'ran' || waiting(rows, r))) return false;
|
|
58
60
|
const bi = rows.findLastIndex((r) => r.kind === 'baseline' && r.sha === it.sha);
|
|
59
61
|
if (bi < 0) return true;
|
|
60
|
-
return mode === 'updated' && rows.slice(bi + 1).some((r) => r.kind
|
|
62
|
+
return mode === 'updated' && rows.slice(bi + 1).some((r) => (r.kind === 'arrived' || r.kind === 'ran' || r.kind === 'dropped') && r.sha !== it.sha); // file rows only: the ledger also holds `armed` / `fire` / `cancelled` rows (M9 am20)
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
/** Arrived rows are never overwritten: the 2nd arrival of a sha (after a drop) gets its own id. @param {string} ledger @param {ToRun & {name?:string}} item @param {number} at the scheduler's clock, never the file's mtime */
|
|
64
|
-
export function recordArrived(ledger, item, at) {
|
|
65
|
-
const rows = readSeen(ledger);
|
|
65
|
+
/** Arrived rows are never overwritten: the 2nd arrival of a sha (after a drop) gets its own id. @param {string} ledger @param {ToRun & {name?:string}} item @param {number} at the scheduler's clock, never the file's mtime @param {string} [sig] */
|
|
66
|
+
export function recordArrived(ledger, item, at, sig) {
|
|
67
|
+
const rows = readSeen(ledger, sig);
|
|
66
68
|
if (rows.some((r) => r.sha === item.sha && (r.kind === 'ran' || waiting(rows, r)))) return false; // one writer decides: ran or already queued
|
|
67
69
|
const n = rows.filter((r) => r.kind === 'arrived' && r.sha === item.sha).length;
|
|
68
|
-
return appendSeen(ledger, { id: n ? `arrived:${item.sha}:${n}` : `arrived:${item.sha}`, kind: 'arrived', sha: item.sha, name: basename(item.path), size: item.size, path: item.path, at });
|
|
70
|
+
return appendSeen(ledger, { id: n ? `arrived:${item.sha}:${n}` : `arrived:${item.sha}`, kind: 'arrived', sha: item.sha, name: basename(item.path), size: item.size, path: item.path, at }, sig);
|
|
69
71
|
}
|
|
70
|
-
/** Call immediately before the run is started. @param {string} ledger @param {{sha:string, path:string, size:number}} item @param {number} at */
|
|
71
|
-
export const recordRan = (ledger, item, at) => appendSeen(ledger, { id: `ran:${item.sha}`, kind: 'ran', sha: item.sha, name: basename(item.path), size: item.size, at });
|
|
72
|
-
/** `of` = the arrived row it cancels (item.id when a queue row is passed). @param {string} ledger @param {{sha:string, path:string, size:number, id?:string}} item @param {'deleted'|'changed'} why @param {number} at */
|
|
73
|
-
export function recordDropped(ledger, item, why, at) {
|
|
72
|
+
/** Call immediately before the run is started. @param {string} ledger @param {{sha:string, path:string, size:number}} item @param {number} at @param {string} [sig] */
|
|
73
|
+
export const recordRan = (ledger, item, at, sig) => appendSeen(ledger, { id: `ran:${item.sha}`, kind: 'ran', sha: item.sha, name: basename(item.path), size: item.size, at }, sig);
|
|
74
|
+
/** `of` = the arrived row it cancels (item.id when a queue row is passed). @param {string} ledger @param {{sha:string, path:string, size:number, id?:string}} item @param {'deleted'|'changed'|'schedule-changed'|'carried'} why @param {number} at @param {string} [sig] */
|
|
75
|
+
export function recordDropped(ledger, item, why, at, sig) {
|
|
74
76
|
const of = item.id ?? `arrived:${item.sha}`;
|
|
75
|
-
return appendSeen(ledger, { id: `dropped:${of}`, kind: 'dropped', sha: item.sha, name: basename(item.path), size: item.size, why, at, of });
|
|
77
|
+
return appendSeen(ledger, { id: `dropped:${of}`, kind: 'dropped', sha: item.sha, name: basename(item.path), size: item.size, why, at, of }, sig);
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
/**
|
|
@@ -123,9 +125,20 @@ export function checkTarget(mode, target) {
|
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
/**
|
|
126
|
-
*
|
|
128
|
+
* M9 am16: does a trigger on this target still watch this file? New: the file sits directly in the same (real) folder. Updated: it is the same (real) file. False when the target cannot be resolved.
|
|
129
|
+
* @param {'new'|'updated'} mode @param {string} target @param {string} filePath a queued file's path as the watcher recorded it (a real path)
|
|
130
|
+
*/
|
|
131
|
+
export function watches(mode, target, filePath) {
|
|
132
|
+
try {
|
|
133
|
+
if (mode === 'new') return realpathSync(target) === dirname(filePath);
|
|
134
|
+
return join(realpathSync(dirname(target)), basename(target)) === filePath;
|
|
135
|
+
} catch { return false; }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @param {{mode:'new'|'updated', target:string, ledger:string, sig?:string}} opts target = folder (new) or file (updated); `sig` (M9 am20) = the schedule signing every row this trigger reads and writes belongs to
|
|
127
140
|
*/
|
|
128
|
-
export function createFileTrigger({ mode, target, ledger }) {
|
|
141
|
+
export function createFileTrigger({ mode, target, ledger, sig }) {
|
|
129
142
|
if (mode !== 'new' && mode !== 'updated') throw new Error(`file trigger mode "${mode}" is not one of new, updated`);
|
|
130
143
|
/** @type {Map<string, {key:string, same:number, takenKey:string|null}>} */
|
|
131
144
|
const track = new Map();
|
|
@@ -166,7 +179,7 @@ export function createFileTrigger({ mode, target, ledger }) {
|
|
|
166
179
|
for (const p of candidates().files) {
|
|
167
180
|
const buf = readFileSync(p);
|
|
168
181
|
const sha = sha256(buf);
|
|
169
|
-
appendSeen(ledger, { id: `baseline:${sha}:${basename(p)}`, kind: 'baseline', sha, name: basename(p), size: buf.length, at: Date.now() }); // write-once: re-arming adds nothing
|
|
182
|
+
appendSeen(ledger, { id: `baseline:${sha}:${basename(p)}`, kind: 'baseline', sha, name: basename(p), size: buf.length, at: Date.now() }, sig); // write-once: re-arming adds nothing
|
|
170
183
|
}
|
|
171
184
|
}
|
|
172
185
|
|
|
@@ -176,7 +189,7 @@ export function createFileTrigger({ mode, target, ledger }) {
|
|
|
176
189
|
const st2 = lstatSync(p);
|
|
177
190
|
if (`${st2.size}:${st2.mtimeMs}` !== t.key) return 'changed'; // changed while reading: retry next poll
|
|
178
191
|
const sha = sha256(buf);
|
|
179
|
-
if (!arrives(readSeen(ledger), { sha }, mode)) return null; // ran, still queued, or still the starting point
|
|
192
|
+
if (!arrives(readSeen(ledger, sig), { sha }, mode)) return null; // ran, still queued, or still the starting point
|
|
180
193
|
return { path: p, sha, size: buf.length };
|
|
181
194
|
}
|
|
182
195
|
|
package/src/trigger-line.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// M9 piece 3 (docs/wiki/the-module-ladder.md, "M9" item 1, am1): the trigger as typed data in the signed arbiter block.
|
|
2
|
-
// Pure text: the grammar of the one `guardrail: trigger ...` line
|
|
2
|
+
// Pure text: the grammar of the one `guardrail: trigger ...` line. M9 am20: a schedule is its own signed file (src/schedule.js); NOTHING writes this line any more.
|
|
3
|
+
// The signed-text parser still accepts it so a job signed before am20 still reads and verifies, but nothing acts on it: such a job is By hand.
|
|
3
4
|
//
|
|
4
5
|
// guardrail: trigger daily 09:00
|
|
5
6
|
// guardrail: trigger weekdays 09:00
|
|
@@ -63,23 +64,13 @@ export function stripTrigger(prose) {
|
|
|
63
64
|
return prose.split('\n').filter((l) => !LINE_RE.test(l)).join('\n');
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
/**
|
|
67
|
-
* The ONE writer of the trigger line: the prose with its trigger line replaced by this trigger's (or removed for null). With no trigger
|
|
68
|
-
* in and none asked for, the text is returned unchanged. The arbiter block is last in a signed text, so the line goes at the end.
|
|
69
|
-
* @param {string} prose @param {Trigger|null} trigger
|
|
70
|
-
*/
|
|
71
|
-
export function proseWithTrigger(prose, trigger) {
|
|
72
|
-
const stripped = stripTrigger(prose);
|
|
73
|
-
if (trigger === null) return stripped;
|
|
74
|
-
return `${stripped.replace(/\s*$/, '')}\n${triggerLine(trigger)}\n`;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
67
|
/**
|
|
78
68
|
* What the human's second click carries: binds the job, the exact signature it was shown at and the trigger.
|
|
79
|
-
* @param {{flow: string, flowSignatureHash: string, trigger: Trigger|null}} a
|
|
69
|
+
* @param {{flow: string, flowSignatureHash: string, trigger: Trigger|null, model?: {slot: string, model: string}|null, destination?: string|null, inputs?: {role: string, path: string}[]|null, plan?: {run: string, flowHash: string, declSha: string}|null}} a
|
|
80
70
|
*/
|
|
81
|
-
export function triggerHash({ flow, flowSignatureHash, trigger }) {
|
|
82
|
-
|
|
71
|
+
export function triggerHash({ flow, flowSignatureHash, trigger, model = null, destination = null, inputs = null, plan = null }) {
|
|
72
|
+
// M6 am5 item 3: the scheduled model is part of what the click signs; absent = the exact bytes (and hashes) a trigger had before
|
|
73
|
+
return createHash('sha256').update(JSON.stringify({ m9: 'trigger', flow, flowSignatureHash, trigger, ...(model ? { model } : {}), ...(destination ? { destination } : {}), ...(inputs ? { inputs } : {}), ...(plan ? { plan } : {}) })).digest('hex');
|
|
83
74
|
}
|
|
84
75
|
|
|
85
76
|
/** M9: the file a triggered start writes (once, before the spawn) into the run's own folder: why this run started. `appendHistory` copies it into the run's history row. */
|
package/src/types.js
CHANGED
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
* @property {string[]} skills - `skills <name>[, <name>...]`. Default ['core'].
|
|
50
50
|
* @property {SourceSlot[]} sources - zero or more `source <role> = file:<path>`.
|
|
51
51
|
* @property {number} roundBudgetMs - `round budget <int><s|m|h>`. Default 120000.
|
|
52
|
-
* @property {import("./trigger-line.js").Trigger|null} trigger - `trigger <kind> ...` (M9). Default null = By hand.
|
|
52
|
+
* @property {import("./trigger-line.js").Trigger|null} trigger - `trigger <kind> ...` (M9). Default null = By hand. M9 am20: read for jobs signed before, NEVER acted on (a schedule is `schedule.json`).
|
|
53
53
|
*/
|
|
54
54
|
|
|
55
55
|
/**
|
package/types/authoring.d.ts
CHANGED
|
@@ -149,9 +149,11 @@ export function draftToDir({ proseFile, dir, root, name, slot, model, draftThink
|
|
|
149
149
|
* `sessionDir` (the panel's draft folder: card, notes, every change) widens the setup record; the CLI has none, so its record is the one plan folder.
|
|
150
150
|
* M6: `replaces: {flowHash}` (a draft opened from an existing signed job, carrying that job's signature hash) makes this sign REPLACE that job
|
|
151
151
|
* (`writeFlow` checks the hash is still the job's); without it a taken name is refused as ever.
|
|
152
|
-
*
|
|
152
|
+
* M6 am9: `asRunOf: {flow}` (a red run's redraft of an UNCHANGED job) signs the plan as the plan of a NEW run of that existing workflow: the workflow's own files are
|
|
153
|
+
* never written (`writeRunPlan`), and a plan whose job key is not the workflow's is refused here, at sign time.
|
|
154
|
+
* @param {{dir: any, approve?: any, signedBy: any, signedAt?: string, env?: Record<string, string|undefined>, keyNames?: string[], sessionDir?: string, replaces?: {flowHash: string}, asRunOf?: {flow: string}}} a
|
|
153
155
|
*/
|
|
154
|
-
export function signDraft({ dir, approve, signedBy, signedAt, env, keyNames, sessionDir, replaces, }: {
|
|
156
|
+
export function signDraft({ dir, approve, signedBy, signedAt, env, keyNames, sessionDir, replaces, asRunOf, }: {
|
|
155
157
|
dir: any;
|
|
156
158
|
approve?: any;
|
|
157
159
|
signedBy: any;
|
|
@@ -162,9 +164,34 @@ export function signDraft({ dir, approve, signedBy, signedAt, env, keyNames, ses
|
|
|
162
164
|
replaces?: {
|
|
163
165
|
flowHash: string;
|
|
164
166
|
};
|
|
167
|
+
asRunOf?: {
|
|
168
|
+
flow: string;
|
|
169
|
+
};
|
|
165
170
|
}): {
|
|
166
171
|
ok: boolean;
|
|
167
172
|
reds: any[];
|
|
173
|
+
} | {
|
|
174
|
+
ok: boolean;
|
|
175
|
+
flowDir: string;
|
|
176
|
+
runId: string;
|
|
177
|
+
runDir: string;
|
|
178
|
+
signature: any;
|
|
179
|
+
setup: {
|
|
180
|
+
ok: true;
|
|
181
|
+
file: string;
|
|
182
|
+
rows: number;
|
|
183
|
+
} | {
|
|
184
|
+
ok: false;
|
|
185
|
+
red: string;
|
|
186
|
+
};
|
|
187
|
+
modelRecord: {
|
|
188
|
+
ok: boolean;
|
|
189
|
+
recorded: boolean;
|
|
190
|
+
};
|
|
191
|
+
modelPick: {
|
|
192
|
+
slot: string;
|
|
193
|
+
model: string;
|
|
194
|
+
} | null;
|
|
168
195
|
} | {
|
|
169
196
|
ok: boolean;
|
|
170
197
|
flowDir: string;
|
|
@@ -181,6 +208,9 @@ export function signDraft({ dir, approve, signedBy, signedAt, env, keyNames, ses
|
|
|
181
208
|
ok: boolean;
|
|
182
209
|
recorded: boolean;
|
|
183
210
|
};
|
|
211
|
+
runId?: undefined;
|
|
212
|
+
runDir?: undefined;
|
|
213
|
+
modelPick?: undefined;
|
|
184
214
|
};
|
|
185
215
|
export const SPEC_HASH_FILE: "spec.hash";
|
|
186
216
|
/** The one folder under the flows root where the panel keeps its draft folders (M4e). Starts with a dot, so it is never a flow name. */
|
package/types/flow.d.ts
CHANGED
|
@@ -201,6 +201,71 @@ export function writeFlow({ root, name, proseText, declaration, signedBy, signed
|
|
|
201
201
|
* @param {string} flowDir @returns {string|null}
|
|
202
202
|
*/
|
|
203
203
|
export function signedHashOf(flowDir: string): string | null;
|
|
204
|
+
/**
|
|
205
|
+
* M6 am9 ("Each run keeps the plan it ran"): which plan does a reuse of run `runDir` run? `{same:true}` = the workflow's own plan (the run kept no copy, as a run made
|
|
206
|
+
* before M6, or its kept plan is byte-equal to the workflow's declaration and prose, a trigger line aside). `{same:false, read}` = a different kept plan, already verified.
|
|
207
|
+
* `{ok:false, red}` = a kept plan that does not verify: refused by name, never swapped for the workflow's.
|
|
208
|
+
* @param {{root: string, name: string, runDir: string, catalogue: unknown}} a
|
|
209
|
+
* @returns {{ok: true, same: true} | {ok: true, same: false, read: ReadFlowResult & {ok: true}} | {ok: false, red: string}}
|
|
210
|
+
*/
|
|
211
|
+
export function planForReuse({ root, name, runDir, catalogue, }: {
|
|
212
|
+
root: string;
|
|
213
|
+
name: string;
|
|
214
|
+
runDir: string;
|
|
215
|
+
catalogue: unknown;
|
|
216
|
+
}): {
|
|
217
|
+
ok: true;
|
|
218
|
+
same: true;
|
|
219
|
+
} | {
|
|
220
|
+
ok: true;
|
|
221
|
+
same: false;
|
|
222
|
+
read: ReadFlowResult & {
|
|
223
|
+
ok: true;
|
|
224
|
+
};
|
|
225
|
+
} | {
|
|
226
|
+
ok: false;
|
|
227
|
+
red: string;
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* M6 am9: give the run folder `runDir` a verified copy of the plan run `fromRunDir` kept (`job/` write-once, then `plan.json {planOf}`), so the run executes
|
|
231
|
+
* it. Nothing is signed: the bytes already carry a signature, proved here. A failure removes what this call wrote.
|
|
232
|
+
* @param {{fromRunDir: string, runDir: string, catalogue: unknown}} a
|
|
233
|
+
* @returns {{ok: true} | {ok: false, red: string}}
|
|
234
|
+
*/
|
|
235
|
+
export function copyRunPlan({ fromRunDir, runDir, catalogue }: {
|
|
236
|
+
fromRunDir: string;
|
|
237
|
+
runDir: string;
|
|
238
|
+
catalogue: unknown;
|
|
239
|
+
}): {
|
|
240
|
+
ok: true;
|
|
241
|
+
} | {
|
|
242
|
+
ok: false;
|
|
243
|
+
red: string;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* M6 am9 ("a red run always drafts"): sign a plan as the plan of a NEW run of an existing workflow. Same checks and the same `signFlow` as `writeFlow`,
|
|
247
|
+
* but nothing of the workflow is written: the run folder is claimed (`claimRunId`) and receives `job/{prose.txt,declaration.json,signature.json}` write-once,
|
|
248
|
+
* then `plan.json` last (the file that makes the run execute it). A failure removes the run folder this call claimed. The caller proves the job is unchanged.
|
|
249
|
+
* @param {{root: unknown, name: unknown, proseText: unknown, declaration: unknown, signedBy: unknown, signedAt: unknown, catalogue: unknown}} a
|
|
250
|
+
* @returns {{ok: true, runId: string, runDir: string, signature: any} | {ok: false, reds: string[]}}
|
|
251
|
+
*/
|
|
252
|
+
export function writeRunPlan({ root, name, proseText, declaration, signedBy, signedAt, catalogue, }: {
|
|
253
|
+
root: unknown;
|
|
254
|
+
name: unknown;
|
|
255
|
+
proseText: unknown;
|
|
256
|
+
declaration: unknown;
|
|
257
|
+
signedBy: unknown;
|
|
258
|
+
signedAt: unknown;
|
|
259
|
+
catalogue: unknown;
|
|
260
|
+
}): {
|
|
261
|
+
ok: true;
|
|
262
|
+
runId: string;
|
|
263
|
+
runDir: string;
|
|
264
|
+
signature: any;
|
|
265
|
+
} | {
|
|
266
|
+
ok: false;
|
|
267
|
+
reds: string[];
|
|
268
|
+
};
|
|
204
269
|
/**
|
|
205
270
|
* Read and verify a signed flow from `<root>/<name>/`. Verifies the bytes on
|
|
206
271
|
* disk against the signature FIRST — before anything in the flow is
|
|
@@ -228,6 +293,38 @@ export function writeRunJobCopy(flowDir: string, runDir: string, expectedFlowHas
|
|
|
228
293
|
ok: false;
|
|
229
294
|
red: string;
|
|
230
295
|
};
|
|
296
|
+
/** M6 am9: does this run execute its own kept plan? The ONE test (no marker = the flow folder's plan, as every run before am9). @param {string} runDir */
|
|
297
|
+
export function runOwnsPlan(runDir: string): boolean;
|
|
298
|
+
/**
|
|
299
|
+
* M6 am9: the ONE reader of the plan a run executes. A run whose folder holds `plan.json` reads its own verified copy (`<run>/job/`); every other
|
|
300
|
+
* run (and a read with no run) reads the flow folder exactly as `readFlow` does. Never throws; a kept plan that does not verify is a red, never swapped for the flow's.
|
|
301
|
+
* @param {{root: unknown, name: unknown, catalogue: unknown, runDir?: string|null}} a
|
|
302
|
+
* @returns {ReadFlowResult}
|
|
303
|
+
*/
|
|
304
|
+
export function readPlan({ root, name, catalogue, runDir }: {
|
|
305
|
+
root: unknown;
|
|
306
|
+
name: unknown;
|
|
307
|
+
catalogue: unknown;
|
|
308
|
+
runDir?: string | null;
|
|
309
|
+
}): ReadFlowResult;
|
|
310
|
+
/**
|
|
311
|
+
* M9 am12: the ONE reader of "the job this run resumes against" (an answer, Resume, Reopen, continue-after-cap, the panel's resume controls).
|
|
312
|
+
* Always the run's OWN kept copy, verified against that copy's own signature (a run with `plan.json` reads it through `readPlan`, the same
|
|
313
|
+
* `<run>/job/`); never the workflow's current job, so a Cancel or an Edit of the workflow does not strand a waiting run. A copy that fails its
|
|
314
|
+
* signature is a red naming it; a run with no copy (it started before M6) is a red with `noCopy: true`, never the flow's job. Never throws.
|
|
315
|
+
* @param {{root: unknown, name: unknown, catalogue: unknown, runDir: string}} a
|
|
316
|
+
* @returns {ReadFlowResult | {ok: false, reds: string[], noCopy: true}}
|
|
317
|
+
*/
|
|
318
|
+
export function readRunPlan({ root, name, catalogue, runDir }: {
|
|
319
|
+
root: unknown;
|
|
320
|
+
name: unknown;
|
|
321
|
+
catalogue: unknown;
|
|
322
|
+
runDir: string;
|
|
323
|
+
}): ReadFlowResult | {
|
|
324
|
+
ok: false;
|
|
325
|
+
reds: string[];
|
|
326
|
+
noCopy: true;
|
|
327
|
+
};
|
|
231
328
|
/**
|
|
232
329
|
* M6: the job a run ran, from its own copy. `{present:false}` = the run has none (it started before M6). `{present:true, ok:true, ...}` = the same
|
|
233
330
|
* shape as a good `readFlow` (lines, arbiter, declaration, signature, classes), after the copy was verified against the copied signature.
|
|
@@ -240,6 +337,13 @@ export function readRunJobCopy(runDir: string, catalogue: unknown): {
|
|
|
240
337
|
} | ({
|
|
241
338
|
present: true;
|
|
242
339
|
} & ReadFlowResult);
|
|
340
|
+
/**
|
|
341
|
+
* M6 am5 item 2: the name suggested for the new workflow a changed job becomes: `<base>-N`, N the first free number from 2. A trailing `-N` of
|
|
342
|
+
* `name` is stripped first when what is left is itself a workflow here (aging-live-4-2 -> base aging-live-4; aging-live-4 keeps its 4). "Free" = nothing at all by that name under root (a folder or a file), the same
|
|
343
|
+
* test the card's name check makes. Pure read; the sign still refuses a name taken meanwhile (writeFlow never overwrites).
|
|
344
|
+
* @param {string} root @param {string} name
|
|
345
|
+
*/
|
|
346
|
+
export function suggestFlowName(root: string, name: string): string;
|
|
243
347
|
/** @typedef {import('./types.js').WriteFlowResult} WriteFlowResult */
|
|
244
348
|
/** @typedef {import('./types.js').ReadFlowResult} ReadFlowResult */
|
|
245
349
|
/** @typedef {import('./types.js').CheckFlowNameResult} CheckFlowNameResult */
|
|
@@ -248,6 +352,8 @@ export function readRunJobCopy(runDir: string, catalogue: unknown): {
|
|
|
248
352
|
export const FLOW_FILES: readonly string[];
|
|
249
353
|
/** The one folder under the flows root where the panel keeps each run start's own files (M4e piece 2b). A dot-name, so never a flow. */
|
|
250
354
|
export const PANEL_STARTS_DIR: ".starts";
|
|
355
|
+
/** M6 am9: a run's folder holds this file when the run executes the plan it keeps (`<run>/job/`), not the flow folder's. Written once, by the run's plan writer. */
|
|
356
|
+
export const RUN_PLAN_MARKER: "plan.json";
|
|
251
357
|
export type WriteFlowResult = import("./types.js").WriteFlowResult;
|
|
252
358
|
export type ReadFlowResult = import("./types.js").ReadFlowResult;
|
|
253
359
|
export type CheckFlowNameResult = import("./types.js").CheckFlowNameResult;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The key of the job as the card's job box types it. @param {string} job */
|
|
2
|
+
export function jobKeyOfCard(job: string): string;
|
|
3
|
+
/** The key of a signed job. @param {{ lines: {n: number, text: string, guardrail: string}[], arbiter: any }} signed `parseSignedText`'s ok result */
|
|
4
|
+
export function jobKeyOfSigned({ lines, arbiter }: {
|
|
5
|
+
lines: {
|
|
6
|
+
n: number;
|
|
7
|
+
text: string;
|
|
8
|
+
guardrail: string;
|
|
9
|
+
}[];
|
|
10
|
+
arbiter: any;
|
|
11
|
+
}): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The ledger's text, '' when there is no file yet. @param {string} file */
|
|
2
|
+
export function ledgerText(file: string): string;
|
|
3
|
+
/** Append one JSON row as its own line; a torn last line gets its newline first. The parent folder must exist. @param {string} file @param {unknown} row @param {{mode?: number}} [options] e.g. `{ mode: 0o600 }` */
|
|
4
|
+
export function appendRow(file: string, row: unknown, options?: {
|
|
5
|
+
mode?: number;
|
|
6
|
+
}): void;
|