fwdloop 0.16.0 → 0.18.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.
Files changed (64) hide show
  1. package/README.md +2 -0
  2. package/bin/fwdloop +10 -7
  3. package/package.json +1 -1
  4. package/src/authoring.js +6 -6
  5. package/src/books.js +6 -1
  6. package/src/catalogue.json +9 -3
  7. package/src/ctx-tools.js +245 -0
  8. package/src/draft-steps.js +89 -30
  9. package/src/drafter.js +28 -4
  10. package/src/draftspend.js +109 -3
  11. package/src/liveness.js +34 -10
  12. package/src/panel/author.js +125 -37
  13. package/src/panel/authorcard.js +15 -10
  14. package/src/panel/authorflows.js +9 -3
  15. package/src/panel/authorresume.js +5 -4
  16. package/src/panel/authorstart.js +21 -9
  17. package/src/panel/authortrigger.js +384 -0
  18. package/src/panel/authorvalues.js +5 -3
  19. package/src/panel/data.js +104 -16
  20. package/src/panel/index.html +257 -44
  21. package/src/panel/scheduler.js +125 -0
  22. package/src/panel/server.js +24 -10
  23. package/src/panel/settings.js +2 -2
  24. package/src/plain-checks.js +51 -0
  25. package/src/primitives.js +34 -3
  26. package/src/provider.js +17 -8
  27. package/src/run-store.js +47 -0
  28. package/src/runner.js +2 -0
  29. package/src/runvalues.js +5 -3
  30. package/src/setup.js +24 -0
  31. package/src/signed-text.js +26 -0
  32. package/src/summary-words.js +155 -0
  33. package/src/trigger-clock.js +142 -0
  34. package/src/trigger-files.js +212 -0
  35. package/src/trigger-line.js +86 -0
  36. package/src/types.js +1 -0
  37. package/src/version.js +13 -0
  38. package/types/authoring.d.ts +1 -3
  39. package/types/ctx-tools.d.ts +18 -0
  40. package/types/draft-steps.d.ts +38 -5
  41. package/types/drafter.d.ts +3 -3
  42. package/types/draftspend.d.ts +56 -0
  43. package/types/liveness.d.ts +7 -1
  44. package/types/panel/author.d.ts +149 -146
  45. package/types/panel/authorcard.d.ts +12 -2
  46. package/types/panel/authorflows.d.ts +11 -3
  47. package/types/panel/authorstart.d.ts +7 -4
  48. package/types/panel/authortrigger.d.ts +210 -0
  49. package/types/panel/authorvalues.d.ts +3 -1
  50. package/types/panel/data.d.ts +14 -7
  51. package/types/panel/scheduler.d.ts +15 -0
  52. package/types/panel/server.d.ts +11 -3
  53. package/types/plain-checks.d.ts +22 -0
  54. package/types/primitives.d.ts +0 -6
  55. package/types/provider.d.ts +7 -1
  56. package/types/run-store.d.ts +11 -0
  57. package/types/runvalues.d.ts +1 -1
  58. package/types/setup.d.ts +27 -0
  59. package/types/summary-words.d.ts +53 -0
  60. package/types/trigger-clock.d.ts +60 -0
  61. package/types/trigger-files.d.ts +90 -0
  62. package/types/trigger-line.d.ts +44 -0
  63. package/types/types.d.ts +4 -0
  64. package/types/version.d.ts +2 -0
@@ -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;
@@ -0,0 +1,2 @@
1
+ /** @param {string|URL} [file] a package.json (a test passes a copy) @returns {string|null} */
2
+ export function readOwnVersion(file?: string | URL): string | null;