fwdloop 0.17.0 → 0.19.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 +2 -1
- package/package.json +1 -1
- package/src/books.js +6 -1
- package/src/panel/author.js +24 -4
- package/src/panel/authorcard.js +2 -1
- package/src/panel/authorflows.js +6 -0
- package/src/panel/authorstart.js +21 -9
- package/src/panel/authortrigger.js +384 -0
- package/src/panel/data.js +173 -13
- package/src/panel/index.html +486 -263
- package/src/panel/scheduler.js +125 -0
- package/src/panel/server.js +26 -9
- package/src/runvalues.js +5 -3
- package/src/setup.js +21 -0
- package/src/signed-text.js +26 -0
- package/src/summary-words.js +176 -0
- package/src/trigger-clock.js +142 -0
- package/src/trigger-files.js +212 -0
- package/src/trigger-line.js +86 -0
- package/src/types.js +1 -0
- package/types/panel/author.d.ts +146 -143
- package/types/panel/authorflows.d.ts +8 -0
- package/types/panel/authorstart.d.ts +7 -4
- package/types/panel/authortrigger.d.ts +210 -0
- package/types/panel/data.d.ts +69 -7
- package/types/panel/scheduler.d.ts +15 -0
- package/types/panel/server.d.ts +9 -3
- package/types/runvalues.d.ts +1 -1
- package/types/setup.d.ts +19 -0
- package/types/summary-words.d.ts +60 -0
- package/types/trigger-clock.d.ts +60 -0
- package/types/trigger-files.d.ts +90 -0
- package/types/trigger-line.d.ts +44 -0
- package/types/types.d.ts +4 -0
package/types/panel/data.d.ts
CHANGED
|
@@ -173,12 +173,13 @@ export function glyphPulses(g: {
|
|
|
173
173
|
* - `[II]` stuck (M4c amendment 2, `isStuck`) — the answer is saved, not taken,
|
|
174
174
|
* and no live process (pid row or resume lock holder) carries the run on.
|
|
175
175
|
* A saved answer with a live process is `[▶]` working on your answer.
|
|
176
|
+
* - `[▶]` starting (live-walk fix) — no end row, no open ask, no pid row yet, and the starter reads this run's start folder as phase `starting` (`ctx.starting`).
|
|
176
177
|
* - `[?]` crashed after taking your answer (amendment 2 (f)) — the answer was
|
|
177
178
|
* consumed, the process is gone, no end row: cannot be carried on.
|
|
178
|
-
* @param {{historyRow: any, askJson: any, consumedAnswerExists: boolean, hasStateJson: boolean, resume?: any, liveness?: 'running'|'gone'|'unknown', booksFresh?: boolean, lock?: string, resumable?: boolean, stoppedAtAsk?: string|null, jobEdited?: boolean}} ctx
|
|
179
|
+
* @param {{historyRow: any, askJson: any, consumedAnswerExists: boolean, hasStateJson: boolean, resume?: any, liveness?: 'running'|'gone'|'unknown', booksFresh?: boolean, lock?: string, resumable?: boolean, stoppedAtAsk?: string|null, jobEdited?: boolean, starting?: boolean}} ctx
|
|
179
180
|
* @returns {{glyph: '[✓]'|'[✗]'|'[·]'|'[!]'|'[▶]'|'[?]'|'[II]'|'[■]', label: string}}
|
|
180
181
|
*/
|
|
181
|
-
export function computeGlyph({ historyRow, askJson, consumedAnswerExists, hasStateJson, resume, liveness, booksFresh, lock, resumable, stoppedAtAsk, jobEdited, }: {
|
|
182
|
+
export function computeGlyph({ historyRow, askJson, consumedAnswerExists, hasStateJson, resume, liveness, booksFresh, lock, resumable, stoppedAtAsk, jobEdited, starting, }: {
|
|
182
183
|
historyRow: any;
|
|
183
184
|
askJson: any;
|
|
184
185
|
consumedAnswerExists: boolean;
|
|
@@ -190,6 +191,7 @@ export function computeGlyph({ historyRow, askJson, consumedAnswerExists, hasSta
|
|
|
190
191
|
resumable?: boolean;
|
|
191
192
|
stoppedAtAsk?: string | null;
|
|
192
193
|
jobEdited?: boolean;
|
|
194
|
+
starting?: boolean;
|
|
193
195
|
}): {
|
|
194
196
|
glyph: "[\u2713]" | "[\u2717]" | "[\u00B7]" | "[!]" | "[\u25B6]" | "[?]" | "[II]" | "[\u25A0]";
|
|
195
197
|
label: string;
|
|
@@ -442,14 +444,16 @@ export function getRunControls({ root, flow, runId, catalogue, }: {
|
|
|
442
444
|
* null`, an explicit `why`) — no flow is silently missing from the list.
|
|
443
445
|
* Ordered by `orderRuns` (waiting on you, running, then newest `at` first; a row
|
|
444
446
|
* with no `at` is never given a guessed one).
|
|
445
|
-
* @param {{root: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any}} opts
|
|
446
|
-
* `resumeAttempt`: the panel's in-memory resume-attempt lookup (M4b piece 2); absent = none.
|
|
447
|
+
* @param {{root: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any, startingRun?: (flow: string, runId: string) => boolean, now?: () => number}} opts
|
|
448
|
+
* `now`: the clock for Needs you's 7-day rule (absent = Date.now). `startingRun`: the starter's phase-`starting` rule for one run (absent = no). `resumeAttempt`: the panel's in-memory resume-attempt lookup (M4b piece 2); absent = none.
|
|
447
449
|
* @returns {any[]}
|
|
448
450
|
*/
|
|
449
|
-
export function listRuns({ root, catalogue, resumeAttempt }: {
|
|
451
|
+
export function listRuns({ root, catalogue, resumeAttempt, startingRun, now }: {
|
|
450
452
|
root: string;
|
|
451
453
|
catalogue: any;
|
|
452
454
|
resumeAttempt?: (flow: string, runId: string) => any;
|
|
455
|
+
startingRun?: (flow: string, runId: string) => boolean;
|
|
456
|
+
now?: () => number;
|
|
453
457
|
}): any[];
|
|
454
458
|
/**
|
|
455
459
|
* The ONE ordering of Runs — History and Workflows both render the list in the
|
|
@@ -464,6 +468,54 @@ export function listRuns({ root, catalogue, resumeAttempt }: {
|
|
|
464
468
|
* @returns {any[]}
|
|
465
469
|
*/
|
|
466
470
|
export function orderRuns(rows: any[]): any[];
|
|
471
|
+
/**
|
|
472
|
+
* M11 am1 item 2 + am2: the ONE rule for a run's Needs-you tag, read off the sign and `runControls` (no second rule). `Accept`: waiting at an open ask.
|
|
473
|
+
* `Resume`: stuck `[II]`, or stopped `[■]` whose Run tab shows the Resume button. An expired ask `[!]` is never here (it stays in the Inbox).
|
|
474
|
+
* M11 am3 item 5: a Resume run leaves Needs you once its stop time (`at`, the history row's) is `RUNS_LIST_LIMITS.needsYouDays` old; exactly that old is out.
|
|
475
|
+
* M11 am4 item 1: a stuck `[II]` run has no stop time; the caller passes the time its saved answer was written. A run with no readable time stays in. An Accept run is never dropped by age (its ask has its own wait).
|
|
476
|
+
* @param {string} glyph a `computeGlyph` sign @param {{atAsk: boolean, canResume: boolean}} controls `runControls`' answer
|
|
477
|
+
* @param {string|null} [at] the run's stop time from the books @param {number} [nowMs]
|
|
478
|
+
* @returns {'Accept'|'Resume'|null}
|
|
479
|
+
*/
|
|
480
|
+
export function needsYouTag(glyph: string, controls: {
|
|
481
|
+
atAsk: boolean;
|
|
482
|
+
canResume: boolean;
|
|
483
|
+
}, at?: string | null, nowMs?: number): "Accept" | "Resume" | null;
|
|
484
|
+
/**
|
|
485
|
+
* M11: one entry per job (flow), newest activity first. A job's activity is its newest KNOWN run time (`at`, else `askedAt`, else `startedAt`);
|
|
486
|
+
* `quiet` only when that time is known and older than the quiet limit: an unknown age is never guessed into quiet, and a job with no runs is not quiet.
|
|
487
|
+
* @param {any[]} rows `listRuns` rows @param {number} nowMs
|
|
488
|
+
* @returns {{flow: string, quiet: boolean, activityMs: number|null}[]}
|
|
489
|
+
*/
|
|
490
|
+
export function summarizeJobs(rows: any[], nowMs: number): {
|
|
491
|
+
flow: string;
|
|
492
|
+
quiet: boolean;
|
|
493
|
+
activityMs: number | null;
|
|
494
|
+
}[];
|
|
495
|
+
/**
|
|
496
|
+
* M11 am1 item 3: every job with a trigger, soonest next run first (a job with no clock slot — a file trigger, or not armed yet — after those that
|
|
497
|
+
* have one, by name). Built from the owners the run page's SCHEDULED block uses (`triggerRead`, `scheduledWords`); `at` / `in` are null when
|
|
498
|
+
* there is no next time (nothing is invented). A job that cannot be read, or has no trigger, is absent.
|
|
499
|
+
* M11 am4 item 2: each card carries `runId`, the job's newest run (the first row `listRuns` gives that job, the one the runs list heads its job card with), or null when it has none.
|
|
500
|
+
* @param {{root: string, triggerRead: (flow: string) => any, now?: () => number, home?: string, rows?: {flow: string, runId: string|null}[]}} opts
|
|
501
|
+
* @returns {{flow: string, at: string|null, in: string|null, words: string, runId: string|null}[]}
|
|
502
|
+
*/
|
|
503
|
+
export function listScheduled({ root, triggerRead, now, home, rows, }: {
|
|
504
|
+
root: string;
|
|
505
|
+
triggerRead: (flow: string) => any;
|
|
506
|
+
now?: () => number;
|
|
507
|
+
home?: string;
|
|
508
|
+
rows?: {
|
|
509
|
+
flow: string;
|
|
510
|
+
runId: string | null;
|
|
511
|
+
}[];
|
|
512
|
+
}): {
|
|
513
|
+
flow: string;
|
|
514
|
+
at: string | null;
|
|
515
|
+
in: string | null;
|
|
516
|
+
words: string;
|
|
517
|
+
runId: string | null;
|
|
518
|
+
}[];
|
|
467
519
|
/**
|
|
468
520
|
* `GET /api/runs/:flow/:runId` — the Run tab (M4a scope item 2): the step
|
|
469
521
|
* map from `declaration.steps`, step cards -> attempts from `audit.jsonl`
|
|
@@ -471,15 +523,19 @@ export function orderRuns(rows: any[]): any[];
|
|
|
471
523
|
* `log.json`. `null` when the flow/runId doesn't resolve to a real run
|
|
472
524
|
* directory at all (caller renders 404); a `red` field names why a
|
|
473
525
|
* sub-derivation couldn't fill (never invented).
|
|
474
|
-
* @param {{root: string, flow: string, runId: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any}} opts
|
|
526
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any, startingRun?: (flow: string, runId: string) => boolean, triggerRead?: (flow: string) => any, now?: () => number, home?: string}} opts
|
|
475
527
|
* @returns {any|null}
|
|
476
528
|
*/
|
|
477
|
-
export function getRunDetail({ root, flow, runId, catalogue, resumeAttempt, }: {
|
|
529
|
+
export function getRunDetail({ root, flow, runId, catalogue, resumeAttempt, startingRun, triggerRead, now, home, }: {
|
|
478
530
|
root: string;
|
|
479
531
|
flow: string;
|
|
480
532
|
runId: string;
|
|
481
533
|
catalogue: any;
|
|
482
534
|
resumeAttempt?: (flow: string, runId: string) => any;
|
|
535
|
+
startingRun?: (flow: string, runId: string) => boolean;
|
|
536
|
+
triggerRead?: (flow: string) => any;
|
|
537
|
+
now?: () => number;
|
|
538
|
+
home?: string;
|
|
483
539
|
}): any | null;
|
|
484
540
|
/**
|
|
485
541
|
* What the Draft adds up to, ONE place (the Map box, the first step card and the Audit group all read it, so the three can never disagree).
|
|
@@ -714,6 +770,12 @@ export const STUCK_REASONS: {
|
|
|
714
770
|
why: string;
|
|
715
771
|
};
|
|
716
772
|
};
|
|
773
|
+
/** M11 scope item 2.5/2.6 and rules, am3 item 5: the named limits of the runs list, in ONE place (30 quiet days, 7 older runs, 7 days in Needs you for a Resume run). The page reads them from `GET /api/runs`. */
|
|
774
|
+
export const RUNS_LIST_LIMITS: Readonly<{
|
|
775
|
+
quietDays: 30;
|
|
776
|
+
olderRuns: 7;
|
|
777
|
+
needsYouDays: 7;
|
|
778
|
+
}>;
|
|
717
779
|
/** The words the Draft says for a flow with no `setup.jsonl` (M4e amendment 6 item 4; renamed Draft by amendment 7 item 2). */
|
|
718
780
|
export const NO_DRAFT_WORDS: "no draft record";
|
|
719
781
|
/** M6: what the Job tab says for a run that started before runs kept a copy of their job. */
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {{ door: ReturnType<typeof import('./authortrigger.js').createTriggerDoor>, now?: () => number, intervalMs?: number }} opts
|
|
3
|
+
* `intervalMs` 0 = no timer (a test drives `tick`).
|
|
4
|
+
*/
|
|
5
|
+
export function createScheduler(opts: {
|
|
6
|
+
door: ReturnType<typeof import("./authortrigger.js").createTriggerDoor>;
|
|
7
|
+
now?: () => number;
|
|
8
|
+
intervalMs?: number;
|
|
9
|
+
}): {
|
|
10
|
+
tick: () => void;
|
|
11
|
+
/** Start the real timer (idempotent). */
|
|
12
|
+
start(): void;
|
|
13
|
+
/** Stop it (idempotent). The server's close calls this. */
|
|
14
|
+
stop(): void;
|
|
15
|
+
};
|
package/types/panel/server.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* real listening socket where that is simpler.
|
|
5
5
|
* @param {import('node:http').IncomingMessage} req
|
|
6
6
|
* @param {import('node:http').ServerResponse} res
|
|
7
|
-
* @param {{ root: string, port: number, packagePath?: string, resumer: ReturnType<typeof createResumer>, settings: ReturnType<typeof createSettings>, author: ReturnType<typeof createAuthor
|
|
7
|
+
* @param {{ root: string, port: number, packagePath?: string, resumer: ReturnType<typeof createResumer>, settings: ReturnType<typeof createSettings>, author: ReturnType<typeof createAuthor>, now?: () => number }} opts
|
|
8
8
|
*/
|
|
9
9
|
export function handleRequest(req: import("node:http").IncomingMessage, res: import("node:http").ServerResponse, opts: {
|
|
10
10
|
root: string;
|
|
@@ -13,6 +13,7 @@ export function handleRequest(req: import("node:http").IncomingMessage, res: imp
|
|
|
13
13
|
resumer: ReturnType<typeof createResumer>;
|
|
14
14
|
settings: ReturnType<typeof createSettings>;
|
|
15
15
|
author: ReturnType<typeof createAuthor>;
|
|
16
|
+
now?: () => number;
|
|
16
17
|
}): void;
|
|
17
18
|
/**
|
|
18
19
|
* Start the panel server. Binds `127.0.0.1` ONLY. A taken port is a LOUD,
|
|
@@ -20,9 +21,9 @@ export function handleRequest(req: import("node:http").IncomingMessage, res: imp
|
|
|
20
21
|
* header). Resolves once actually listening; rejects on a bind error
|
|
21
22
|
* (including `EADDRINUSE`) with a `.port` field on the error for the
|
|
22
23
|
* caller's message.
|
|
23
|
-
* @param {{ port?: number, root: string, packagePath?: string, settings?: { home?: string, env?: Record<string,string|undefined>, fetch?: typeof fetch, now?: () => number, openFolderSpawn?: Function, platform?: string }, resume?: { env?: Record<string,string|undefined>, bin?: string, logDir?: string, maxTries?: number, windowMs?: number, slotMs?: number }, author?: { env?: Record<string,string|undefined>, loadEnv?: () => any, bin?: string } }} opts
|
|
24
|
+
* @param {{ port?: number, root: string, packagePath?: string, settings?: { home?: string, env?: Record<string,string|undefined>, fetch?: typeof fetch, now?: () => number, openFolderSpawn?: Function, platform?: string }, resume?: { env?: Record<string,string|undefined>, bin?: string, logDir?: string, maxTries?: number, windowMs?: number, slotMs?: number }, author?: { env?: Record<string,string|undefined>, loadEnv?: () => any, bin?: string, now?: () => number }, scheduler?: { intervalMs?: number } }} opts
|
|
24
25
|
* `resume` and `author` are for tests only (a fake env/bin, a short retry window); the CLI passes none.
|
|
25
|
-
* @returns {Promise<{ server: import('node:http').Server, port: number, close: () => Promise<void> }>}
|
|
26
|
+
* @returns {Promise<{ server: import('node:http').Server, port: number, tick: () => void, close: () => Promise<void> }>}
|
|
26
27
|
*/
|
|
27
28
|
export function createPanelServer(opts: {
|
|
28
29
|
port?: number;
|
|
@@ -48,10 +49,15 @@ export function createPanelServer(opts: {
|
|
|
48
49
|
env?: Record<string, string | undefined>;
|
|
49
50
|
loadEnv?: () => any;
|
|
50
51
|
bin?: string;
|
|
52
|
+
now?: () => number;
|
|
53
|
+
};
|
|
54
|
+
scheduler?: {
|
|
55
|
+
intervalMs?: number;
|
|
51
56
|
};
|
|
52
57
|
}): Promise<{
|
|
53
58
|
server: import("node:http").Server;
|
|
54
59
|
port: number;
|
|
60
|
+
tick: () => void;
|
|
55
61
|
close: () => Promise<void>;
|
|
56
62
|
}>;
|
|
57
63
|
/**
|
package/types/runvalues.d.ts
CHANGED
|
@@ -89,7 +89,7 @@ export function applyRunValues(arbiter: any, flow: string, flowSignatureHash: st
|
|
|
89
89
|
};
|
|
90
90
|
/**
|
|
91
91
|
* A start that refused before the run began (monthly limit, empty key ...) leaves a run folder holding nothing but its signed values
|
|
92
|
-
* file: remove
|
|
92
|
+
* file and/or its trigger record: remove those so the folder can be removed too and the run name is not burned. Never touches a folder with anything else.
|
|
93
93
|
* @param {string} runDir @returns {boolean} true when the file was removed
|
|
94
94
|
*/
|
|
95
95
|
export function dropUnstartedValues(runDir: string): boolean;
|
package/types/setup.d.ts
CHANGED
|
@@ -70,6 +70,25 @@ export function writeSetup({ flowDir, secrets, ...rest }: {
|
|
|
70
70
|
ok: false;
|
|
71
71
|
red: string;
|
|
72
72
|
};
|
|
73
|
+
/**
|
|
74
|
+
* M9 item 2: a trigger-only re-sign signs the same plan under a new flow hash. The old `setup.jsonl` bytes are written back untouched (append-only)
|
|
75
|
+
* and ONE row is added: kind `trigger-resign`, the record of the signing it continues (its plan hash and "Not checked" list, copied) under the new
|
|
76
|
+
* `flowHash`, naming the old one in `resignOf`. A reader that wants this job's record looks for the row whose `flowHash` is the job's. Never throws.
|
|
77
|
+
* @param {{ flowDir: string, oldText: string, oldFlowHash: string, newFlowHash: string, at: string }} a
|
|
78
|
+
* @returns {{ ok: true } | { ok: false, red: string }}
|
|
79
|
+
*/
|
|
80
|
+
export function carrySetup({ flowDir, oldText, oldFlowHash, newFlowHash, at }: {
|
|
81
|
+
flowDir: string;
|
|
82
|
+
oldText: string;
|
|
83
|
+
oldFlowHash: string;
|
|
84
|
+
newFlowHash: string;
|
|
85
|
+
at: string;
|
|
86
|
+
}): {
|
|
87
|
+
ok: true;
|
|
88
|
+
} | {
|
|
89
|
+
ok: false;
|
|
90
|
+
red: string;
|
|
91
|
+
};
|
|
73
92
|
/**
|
|
74
93
|
* The flow's setup rows, through the one safe gateway. `present:false` = a flow signed before amendment 6 (or a file that cannot be read).
|
|
75
94
|
* @param {string} flowDir
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SCHEDULED: what starts the job, in words. `null` (By hand) has no sentence.
|
|
3
|
+
* @param {Trigger|null} t @param {string} [home]
|
|
4
|
+
* @returns {string|null}
|
|
5
|
+
*/
|
|
6
|
+
export function scheduledWords(t: Trigger | null, home?: string): string | null;
|
|
7
|
+
/** "Mon 13 Oct, 09:00" — local time, fixed English names (never the machine's locale). @param {number} ms */
|
|
8
|
+
export function slotWords(ms: number): string;
|
|
9
|
+
/**
|
|
10
|
+
* M11 am1 item 3, the Scheduled card's first line: "today 17:00", "tomorrow 09:00", else the date the NEXT line already says ("Tue 20 Oct, 09:05").
|
|
11
|
+
* Local time, by calendar day. @param {number} ms the next run @param {number} now
|
|
12
|
+
*/
|
|
13
|
+
export function nextTimeWords(ms: number, now: number): string;
|
|
14
|
+
/** M11 am1 item 3, the Scheduled card's second line start: "next in 20m" / "next in 3h" / "next in 3d" (whole units, rounded down, never "0m"). @param {number} ms @param {number} now */
|
|
15
|
+
export function nextInWords(ms: number, now: number): string;
|
|
16
|
+
/** am1, said before a human signs an edit of a job that has a trigger. @param {Trigger|null} t @param {string} [home] */
|
|
17
|
+
export function editClearsWords(t: Trigger | null, home?: string): string | null;
|
|
18
|
+
/**
|
|
19
|
+
* NEXT of a job with a trigger. One sentence, first match wins:
|
|
20
|
+
* 1. a run of this job is waiting at its ask (the next run waits too);
|
|
21
|
+
* 2. the latest outcome this month is `monthly-exhausted` (the signed sentence, amounts from the row);
|
|
22
|
+
* 3. a clock kind with a next slot; 4. a file kind that is armed; 5. not armed yet.
|
|
23
|
+
* A last outcome of `refused` goes in front of 3-5, so a trigger that cannot start is never silent.
|
|
24
|
+
* `red` is the typed flag for "the human must act": monthly-exhausted and the refused lead. The page paints it; it never guesses from the text.
|
|
25
|
+
* @param {{trigger: Trigger, armed: boolean, nextSlotMs: number|null, lastOutcome: any, waitingLine: number|null, now: number}} f
|
|
26
|
+
* @returns {{text: string, red: boolean}}
|
|
27
|
+
*/
|
|
28
|
+
export function scheduledNextFor(f: {
|
|
29
|
+
trigger: Trigger;
|
|
30
|
+
armed: boolean;
|
|
31
|
+
nextSlotMs: number | null;
|
|
32
|
+
lastOutcome: any;
|
|
33
|
+
waitingLine: number | null;
|
|
34
|
+
now: number;
|
|
35
|
+
}): {
|
|
36
|
+
text: string;
|
|
37
|
+
red: boolean;
|
|
38
|
+
};
|
|
39
|
+
/** The NEXT sentence alone. @param {Parameters<typeof scheduledNextFor>[0]} f */
|
|
40
|
+
export function scheduledNext(f: Parameters<typeof scheduledNextFor>[0]): string;
|
|
41
|
+
/** Fixed catch-up sentence (am2 item 1) from a run's `trigger.json`. @param {any} rec */
|
|
42
|
+
export function catchUpWords(rec: any): "This run was a catch-up: it started more than 2 minutes after its set time (the panel was off)." | null;
|
|
43
|
+
/**
|
|
44
|
+
* ENDED / NEXT of a finished run. Every outcome the history row can hold has a fixed sentence; an unknown one gets an honest fixed fallback
|
|
45
|
+
* that names the code and guesses nothing. `null` when there is no ending (still running, waiting, or no history row and not died).
|
|
46
|
+
* @param {{outcome: string|null, died?: boolean, line: number|null, destination: string|null, canResume: boolean, home?: string}} f
|
|
47
|
+
* @returns {{reason: string, next: string}|null}
|
|
48
|
+
*/
|
|
49
|
+
export function endedWords(f: {
|
|
50
|
+
outcome: string | null;
|
|
51
|
+
died?: boolean;
|
|
52
|
+
line: number | null;
|
|
53
|
+
destination: string | null;
|
|
54
|
+
canResume: boolean;
|
|
55
|
+
home?: string;
|
|
56
|
+
}): {
|
|
57
|
+
reason: string;
|
|
58
|
+
next: string;
|
|
59
|
+
} | null;
|
|
60
|
+
export type Trigger = import("./trigger-line.js").Trigger;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The only way a schedule enters the system. Refuses anything else, naming the field.
|
|
3
|
+
* @param {unknown} s
|
|
4
|
+
* @returns {Schedule}
|
|
5
|
+
*/
|
|
6
|
+
export function validateSchedule(s: unknown): Schedule;
|
|
7
|
+
/**
|
|
8
|
+
* Is a run due at `now`? Slots missed (panel off) collapse to ONE fire, for the latest slot, marked catch-up.
|
|
9
|
+
* Catch-up = more than one slot was missed, or the latest slot is more than GRACE_MS old.
|
|
10
|
+
* @param {Schedule} schedule
|
|
11
|
+
* @param {ClockRow[]} rows
|
|
12
|
+
* @param {number} now epoch ms
|
|
13
|
+
* @returns {Due}
|
|
14
|
+
*/
|
|
15
|
+
export function due(schedule: Schedule, rows: ClockRow[], now: number): Due;
|
|
16
|
+
/**
|
|
17
|
+
* The next slot time strictly after `afterMs` (epoch ms). Words ("Next run Mon 13 Oct, 09:00.") are the caller's.
|
|
18
|
+
* @param {Schedule} schedule
|
|
19
|
+
* @param {number} afterMs
|
|
20
|
+
* @returns {number}
|
|
21
|
+
*/
|
|
22
|
+
export function nextSlot(schedule: Schedule, afterMs: number): number;
|
|
23
|
+
/** @param {string} file @returns {ClockRow[]} every row on disk, oldest first; a missing file is no rows. */
|
|
24
|
+
export function readRows(file: string): ClockRow[];
|
|
25
|
+
/** The trigger was set at `now`: no slot before this ever fires. @param {string} file @param {number} now */
|
|
26
|
+
export function armTrigger(file: string, now: number): void;
|
|
27
|
+
/**
|
|
28
|
+
* Record that the run for this due slot is starting. Call BEFORE starting the run: a crash loses a run, never doubles one.
|
|
29
|
+
* @param {string} file @param {Due} d the result of `due` with fire true @param {number} now
|
|
30
|
+
*/
|
|
31
|
+
export function recordFire(file: string, d: Due, now: number): void;
|
|
32
|
+
/** @typedef {{kind:'daily'|'weekdays', hour:number, minute:number} | {kind:'weekly', day:string, hour:number, minute:number}} Schedule */
|
|
33
|
+
/** @typedef {{id:string, kind:'armed'|'fire', at:number, slot?:number, catchUp?:boolean, missed?:number}} ClockRow */
|
|
34
|
+
/** @typedef {{fire:boolean, catchUp:boolean, missed:number, slot?:number}} Due */
|
|
35
|
+
/** A slot seen MORE than this after its set time is a catch-up (M9 am2 item 1). Exactly this late is on time. */
|
|
36
|
+
export const GRACE_MS: 120000;
|
|
37
|
+
export type Schedule = {
|
|
38
|
+
kind: "daily" | "weekdays";
|
|
39
|
+
hour: number;
|
|
40
|
+
minute: number;
|
|
41
|
+
} | {
|
|
42
|
+
kind: "weekly";
|
|
43
|
+
day: string;
|
|
44
|
+
hour: number;
|
|
45
|
+
minute: number;
|
|
46
|
+
};
|
|
47
|
+
export type ClockRow = {
|
|
48
|
+
id: string;
|
|
49
|
+
kind: "armed" | "fire";
|
|
50
|
+
at: number;
|
|
51
|
+
slot?: number;
|
|
52
|
+
catchUp?: boolean;
|
|
53
|
+
missed?: number;
|
|
54
|
+
};
|
|
55
|
+
export type Due = {
|
|
56
|
+
fire: boolean;
|
|
57
|
+
catchUp: boolean;
|
|
58
|
+
missed: number;
|
|
59
|
+
slot?: number;
|
|
60
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/** @param {string} file @returns {SeenRow[]} */
|
|
2
|
+
export function readSeen(file: string): SeenRow[];
|
|
3
|
+
/** 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 */
|
|
4
|
+
export function recordArrived(ledger: string, item: ToRun & {
|
|
5
|
+
name?: string;
|
|
6
|
+
}, at: number): boolean;
|
|
7
|
+
/** `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 */
|
|
8
|
+
export function recordDropped(ledger: string, item: {
|
|
9
|
+
sha: string;
|
|
10
|
+
path: string;
|
|
11
|
+
size: number;
|
|
12
|
+
id?: string;
|
|
13
|
+
}, why: "deleted" | "changed", at: number): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The queue: arrived and neither ran nor dropped, oldest arrival first. Identical arrival times: by name, then by sha (deterministic).
|
|
16
|
+
* @param {SeenRow[]} rows @returns {(SeenRow & {path:string})[]}
|
|
17
|
+
*/
|
|
18
|
+
export function queueOf(rows: SeenRow[]): (SeenRow & {
|
|
19
|
+
path: string;
|
|
20
|
+
})[];
|
|
21
|
+
/**
|
|
22
|
+
* At a queued file's turn, look at it again, at use time: lstat (no symlink, a regular file), realpath of its folder, re-hash.
|
|
23
|
+
* @param {{path:string, sha:string}} item
|
|
24
|
+
* @returns {{state:'ok', path:string, sha:string, size:number} | {state:'deleted', say:string} | {state:'changed', sha:string}}
|
|
25
|
+
*/
|
|
26
|
+
export function recheck(item: {
|
|
27
|
+
path: string;
|
|
28
|
+
sha: string;
|
|
29
|
+
}): {
|
|
30
|
+
state: "ok";
|
|
31
|
+
path: string;
|
|
32
|
+
sha: string;
|
|
33
|
+
size: number;
|
|
34
|
+
} | {
|
|
35
|
+
state: "deleted";
|
|
36
|
+
say: string;
|
|
37
|
+
} | {
|
|
38
|
+
state: "changed";
|
|
39
|
+
sha: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The target is usable NOW, or an Error naming why: a file that is not a symlink and not something else (a file that does not exist yet
|
|
43
|
+
* is allowed: it may arrive), a folder that exists, resolved with realpathSync. The one rule `arm` and a door's set-time check share.
|
|
44
|
+
* @param {'new'|'updated'} mode @param {string} target
|
|
45
|
+
*/
|
|
46
|
+
export function checkTarget(mode: "new" | "updated", target: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* @param {{mode:'new'|'updated', target:string, ledger:string}} opts target = folder (new) or file (updated)
|
|
49
|
+
*/
|
|
50
|
+
export function createFileTrigger({ mode, target, ledger }: {
|
|
51
|
+
mode: "new" | "updated";
|
|
52
|
+
target: string;
|
|
53
|
+
ledger: string;
|
|
54
|
+
}): {
|
|
55
|
+
arm: () => void;
|
|
56
|
+
poll: () => {
|
|
57
|
+
arrived: ToRun[];
|
|
58
|
+
refused: Refused[];
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
/** @typedef {{id:string, kind:'baseline'|'arrived'|'ran'|'dropped', sha:string, name:string, size:number, at:number, path?:string, why?:string, of?:string}} SeenRow */
|
|
62
|
+
/** @typedef {{path:string, sha:string, size:number}} ToRun */
|
|
63
|
+
/** @typedef {{path:string, why:string}} Refused */
|
|
64
|
+
/** Consecutive polls with the same size and mtime before a file is taken. (Two matches in a row = taken on the third sighting.) */
|
|
65
|
+
export const STABLE_POLLS: 2;
|
|
66
|
+
export function recordRan(ledger: string, item: {
|
|
67
|
+
sha: string;
|
|
68
|
+
path: string;
|
|
69
|
+
size: number;
|
|
70
|
+
}, at: number): boolean;
|
|
71
|
+
export type SeenRow = {
|
|
72
|
+
id: string;
|
|
73
|
+
kind: "baseline" | "arrived" | "ran" | "dropped";
|
|
74
|
+
sha: string;
|
|
75
|
+
name: string;
|
|
76
|
+
size: number;
|
|
77
|
+
at: number;
|
|
78
|
+
path?: string;
|
|
79
|
+
why?: string;
|
|
80
|
+
of?: string;
|
|
81
|
+
};
|
|
82
|
+
export type ToRun = {
|
|
83
|
+
path: string;
|
|
84
|
+
sha: string;
|
|
85
|
+
size: number;
|
|
86
|
+
};
|
|
87
|
+
export type Refused = {
|
|
88
|
+
path: string;
|
|
89
|
+
why: string;
|
|
90
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The text after `trigger ` on a guardrail line, as a typed trigger. Never throws.
|
|
3
|
+
* @param {string} text
|
|
4
|
+
* @returns {{ok: true, trigger: Trigger} | {ok: false, error: string}}
|
|
5
|
+
*/
|
|
6
|
+
export function parseTrigger(text: string): {
|
|
7
|
+
ok: true;
|
|
8
|
+
trigger: Trigger;
|
|
9
|
+
} | {
|
|
10
|
+
ok: false;
|
|
11
|
+
error: string;
|
|
12
|
+
};
|
|
13
|
+
/** The signed-text line for a trigger. @param {Trigger} t */
|
|
14
|
+
export function triggerLine(t: Trigger): string;
|
|
15
|
+
/** The prose without any trigger line. Everything else is byte-for-byte what it was. @param {string} prose */
|
|
16
|
+
export function stripTrigger(prose: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* 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
|
|
19
|
+
* 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.
|
|
20
|
+
* @param {string} prose @param {Trigger|null} trigger
|
|
21
|
+
*/
|
|
22
|
+
export function proseWithTrigger(prose: string, trigger: Trigger | null): string;
|
|
23
|
+
/**
|
|
24
|
+
* What the human's second click carries: binds the job, the exact signature it was shown at and the trigger.
|
|
25
|
+
* @param {{flow: string, flowSignatureHash: string, trigger: Trigger|null}} a
|
|
26
|
+
*/
|
|
27
|
+
export function triggerHash({ flow, flowSignatureHash, trigger }: {
|
|
28
|
+
flow: string;
|
|
29
|
+
flowSignatureHash: string;
|
|
30
|
+
trigger: Trigger | null;
|
|
31
|
+
}): string;
|
|
32
|
+
export function isTriggerLine(line: string): boolean;
|
|
33
|
+
/** 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. */
|
|
34
|
+
export const TRIGGER_RECORD_FILE: "trigger.json";
|
|
35
|
+
export type Schedule = import("./trigger-clock.js").Schedule;
|
|
36
|
+
export type Trigger = Schedule | {
|
|
37
|
+
kind: "file-updated";
|
|
38
|
+
role: string;
|
|
39
|
+
path: string;
|
|
40
|
+
} | {
|
|
41
|
+
kind: "new-file";
|
|
42
|
+
role: string;
|
|
43
|
+
folder: string;
|
|
44
|
+
};
|
package/types/types.d.ts
CHANGED
|
@@ -94,6 +94,10 @@ export type Arbiter = {
|
|
|
94
94
|
* - `round budget <int><s|m|h>`. Default 120000.
|
|
95
95
|
*/
|
|
96
96
|
roundBudgetMs: number;
|
|
97
|
+
/**
|
|
98
|
+
* - `trigger <kind> ...` (M9). Default null = By hand.
|
|
99
|
+
*/
|
|
100
|
+
trigger: import("./trigger-line.js").Trigger | null;
|
|
97
101
|
};
|
|
98
102
|
export type SignedTextOk = {
|
|
99
103
|
ok: true;
|