fwdloop 0.17.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.
- 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 +87 -11
- package/src/panel/index.html +183 -2
- package/src/panel/scheduler.js +125 -0
- package/src/panel/server.js +17 -8
- package/src/runvalues.js +5 -3
- package/src/setup.js +21 -0
- package/src/signed-text.js +26 -0
- package/src/summary-words.js +155 -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 +14 -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 +53 -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
|
@@ -14,19 +14,21 @@ export function createStarter(opts: {
|
|
|
14
14
|
runDir: string;
|
|
15
15
|
say?: undefined;
|
|
16
16
|
};
|
|
17
|
-
startingFor: (flow: string, keys: string[]) => string | null;
|
|
17
|
+
startingFor: (flow: string, keys: string[], runId?: string) => string | null;
|
|
18
18
|
/**
|
|
19
19
|
* Start `fwdloop run` for a flow whose every $0 check already passed at the calling door. Re-checks the run id here (nothing
|
|
20
20
|
* awaits between this check and the spawn). 202 { startId, runId } or a refusal; a refusal creates nothing.
|
|
21
21
|
* `runId` '' = no typed id: the start CLAIMS the next `run-<n>` itself (claimRunId, folder created exclusively; amendment 3).
|
|
22
22
|
* `values` (M4e amendment 5 item 3): the human's signed values for THIS run (the page's second click), written once into the run's own
|
|
23
23
|
* folder as `signed-values.json` BEFORE the spawn; the run then uses them (`pickRunValues`). None = the flow's own.
|
|
24
|
-
*
|
|
24
|
+
* `trigger` (M9): `{kind, reason, catchUp, ...}` for a start a trigger fired (kind 'trigger'): written once into the run's own folder as `trigger.json`
|
|
25
|
+
* BEFORE the spawn; `appendHistory` copies it into the run's history row (the catch-up mark, am2 item 1).
|
|
26
|
+
* @param {{ kind: 'run'|'sign'|'trigger', flow: string, runId: string, sources: {role: string, path: string}[], values?: any, pick?: {slot: string, model: string}|null, trigger?: Record<string, any>|null }} a
|
|
25
27
|
* @param {{ env: Record<string, string|undefined>, keyNames?: string[] }} loaded the keys load: its env is the child's env AND (with its key names) the scrub list
|
|
26
28
|
* @returns {{ status: number, body: any }}
|
|
27
29
|
*/
|
|
28
|
-
start({ kind, flow, runId, sources, values, pick, }: {
|
|
29
|
-
kind: "run" | "sign";
|
|
30
|
+
start({ kind, flow, runId, sources, values, pick, trigger, }: {
|
|
31
|
+
kind: "run" | "sign" | "trigger";
|
|
30
32
|
flow: string;
|
|
31
33
|
runId: string;
|
|
32
34
|
sources: {
|
|
@@ -38,6 +40,7 @@ export function createStarter(opts: {
|
|
|
38
40
|
slot: string;
|
|
39
41
|
model: string;
|
|
40
42
|
} | null;
|
|
43
|
+
trigger?: Record<string, any> | null;
|
|
41
44
|
}, loaded: {
|
|
42
45
|
env: Record<string, string | undefined>;
|
|
43
46
|
keyNames?: string[];
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/** The folder holding the ledgers of ONE signed trigger. @param {string} flowDir @param {string} flowHash */
|
|
2
|
+
export function triggerLedgerDir(flowDir: string, flowHash: string): string;
|
|
3
|
+
/** Every fire outcome of a job, oldest first, through the safe gateway. @param {string} flowDir @returns {any[]} */
|
|
4
|
+
export function readOutcomes(flowDir: string): any[];
|
|
5
|
+
/** The ONE writer of `triggers.jsonl`: append-only, one line per fire outcome. @param {string} flowDir @param {Record<string, any>} row */
|
|
6
|
+
export function appendOutcome(flowDir: string, row: Record<string, any>): void;
|
|
7
|
+
/**
|
|
8
|
+
* M9 item 1 and 2: does this job have "one green run"? The ONE function that decides it. A passed run counts when the job it ran (its own
|
|
9
|
+
* `job/` copy) is the current job WITHOUT its trigger line: so changing only the trigger keeps the run (item 2), and an Edit that changes
|
|
10
|
+
* the steps, a guardrail or the cap does not (am1). A run from before runs kept a job copy has none to compare, so it counts only when its
|
|
11
|
+
* history row's signature is the job's current one (a job signed since then is not the job it ran, unless that signing only added or changed its trigger line: see signingsOf).
|
|
12
|
+
* @param {string} flowDir
|
|
13
|
+
*/
|
|
14
|
+
export function hasGreenRunForJob(flowDir: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The ONE writer of "this trigger was set": the starting point (am2 item 2). Idempotent. A file kind records what is already there first
|
|
17
|
+
* (never runs), then the armed row, so a failure between the two leaves it unarmed and the next call finishes it. Throws, naming why, when
|
|
18
|
+
* the target is not usable now.
|
|
19
|
+
* @param {string} flowDir @param {string} flowHash @param {Trigger} trigger @param {number} now epoch ms
|
|
20
|
+
* @returns {{armed: boolean, already: boolean}}
|
|
21
|
+
*/
|
|
22
|
+
export function armFor(flowDir: string, flowHash: string, trigger: Trigger, now: number): {
|
|
23
|
+
armed: boolean;
|
|
24
|
+
already: boolean;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* @param {{ root: string, flowsDoor: ReturnType<typeof import('./authorflows.js').createFlowsDoor>, starter: ReturnType<typeof import('./authorstart.js').createStarter>, loadEnv: () => any, monthlyClaim: (usd: number) => any, modelRefusal: (card: any, loaded: any) => { field: string, say: string }[], now?: () => number }} opts
|
|
28
|
+
*/
|
|
29
|
+
export function createTriggerDoor(opts: {
|
|
30
|
+
root: string;
|
|
31
|
+
flowsDoor: ReturnType<typeof import("./authorflows.js").createFlowsDoor>;
|
|
32
|
+
starter: ReturnType<typeof import("./authorstart.js").createStarter>;
|
|
33
|
+
loadEnv: () => any;
|
|
34
|
+
monthlyClaim: (usd: number) => any;
|
|
35
|
+
modelRefusal: (card: any, loaded: any) => {
|
|
36
|
+
field: string;
|
|
37
|
+
say: string;
|
|
38
|
+
}[];
|
|
39
|
+
now?: () => number;
|
|
40
|
+
}): {
|
|
41
|
+
inspect: (body: any) => {
|
|
42
|
+
ok: false;
|
|
43
|
+
reply: {
|
|
44
|
+
status: number;
|
|
45
|
+
body: {
|
|
46
|
+
ok: boolean;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
} | {
|
|
50
|
+
ok: true;
|
|
51
|
+
flow: any;
|
|
52
|
+
read: import("../types.js").ReadFlowOk;
|
|
53
|
+
trigger: import("../trigger-line.js").Trigger | null;
|
|
54
|
+
flowDir: string;
|
|
55
|
+
realRoot: string;
|
|
56
|
+
proseText: string;
|
|
57
|
+
declaration: any;
|
|
58
|
+
hash: string;
|
|
59
|
+
};
|
|
60
|
+
now: () => number;
|
|
61
|
+
/** `POST /api/author/trigger-prepare`: the first click. Checks, signs and writes nothing. @param {any} body */
|
|
62
|
+
prepare(body: any): {
|
|
63
|
+
status: number;
|
|
64
|
+
body: {
|
|
65
|
+
ok: boolean;
|
|
66
|
+
};
|
|
67
|
+
} | {
|
|
68
|
+
status: number;
|
|
69
|
+
body: {
|
|
70
|
+
ok: boolean;
|
|
71
|
+
flow: any;
|
|
72
|
+
trigger: import("../trigger-line.js").Trigger | null;
|
|
73
|
+
words: string | null;
|
|
74
|
+
hash: string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* `POST /api/author/trigger`: the second click, carrying the hash it was shown. Re-signs the SAME plan (declaration.json byte for byte,
|
|
79
|
+
* prose.txt with only its trigger line changed) through the M6 replace path, then arms the trigger. $0: no drafter, no run.
|
|
80
|
+
* @param {any} body
|
|
81
|
+
*/
|
|
82
|
+
set(body: any): {
|
|
83
|
+
status: number;
|
|
84
|
+
body: {
|
|
85
|
+
ok: boolean;
|
|
86
|
+
};
|
|
87
|
+
} | {
|
|
88
|
+
status: number;
|
|
89
|
+
body: {
|
|
90
|
+
ok: boolean;
|
|
91
|
+
refused: string;
|
|
92
|
+
say: string;
|
|
93
|
+
reds?: undefined;
|
|
94
|
+
};
|
|
95
|
+
} | {
|
|
96
|
+
status: number;
|
|
97
|
+
body: {
|
|
98
|
+
ok: boolean;
|
|
99
|
+
refused: string;
|
|
100
|
+
say: string;
|
|
101
|
+
reds: any[];
|
|
102
|
+
};
|
|
103
|
+
} | {
|
|
104
|
+
status: number;
|
|
105
|
+
body: {
|
|
106
|
+
say?: string | undefined;
|
|
107
|
+
ok: boolean;
|
|
108
|
+
flow: any;
|
|
109
|
+
trigger: import("../trigger-line.js").Trigger | null;
|
|
110
|
+
words: string | null;
|
|
111
|
+
flowHash: string;
|
|
112
|
+
armed: boolean;
|
|
113
|
+
refused?: undefined;
|
|
114
|
+
reds?: undefined;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
/** Every signed job that has a trigger, as the scheduler needs it: `{flow, flowDir, read, trigger}`. Reads each job the way the CLI will (signature verified). */
|
|
118
|
+
scan(): {
|
|
119
|
+
flow: string;
|
|
120
|
+
flowDir: string;
|
|
121
|
+
read: import("../types.js").ReadFlowOk;
|
|
122
|
+
trigger: Trigger;
|
|
123
|
+
}[];
|
|
124
|
+
/** Arm this job's signed trigger if it is not armed yet (a crash between the sign and the arm). Idempotent; throws naming why. @param {{flowDir: string, read: any, trigger: Trigger}} job */
|
|
125
|
+
ensureArmed(job: {
|
|
126
|
+
flowDir: string;
|
|
127
|
+
read: any;
|
|
128
|
+
trigger: Trigger;
|
|
129
|
+
}): {
|
|
130
|
+
armed: boolean;
|
|
131
|
+
already: boolean;
|
|
132
|
+
};
|
|
133
|
+
/** M9 am3: is a run of this job starting, running or waiting at an ask? (the same check `fire` makes first) @param {{flow: string}} job */
|
|
134
|
+
busy(job: {
|
|
135
|
+
flow: string;
|
|
136
|
+
}): boolean;
|
|
137
|
+
/** M9 am3: one row for a queued file that is not a fire (deleted / changed before its turn). @param {{flow: string, flowDir: string, trigger: Trigger}} job @param {Record<string, any>} row */
|
|
138
|
+
note(job: {
|
|
139
|
+
flow: string;
|
|
140
|
+
flowDir: string;
|
|
141
|
+
trigger: Trigger;
|
|
142
|
+
}, row: Record<string, any>): void;
|
|
143
|
+
/**
|
|
144
|
+
* One row in `triggers.jsonl` that is not a fire (the trigger could not be watched). @param {{flow: string, flowDir: string, trigger: Trigger}} job @param {string} why
|
|
145
|
+
*/
|
|
146
|
+
refuse(job: {
|
|
147
|
+
flow: string;
|
|
148
|
+
flowDir: string;
|
|
149
|
+
trigger: Trigger;
|
|
150
|
+
}, why: string): void;
|
|
151
|
+
/**
|
|
152
|
+
* M9 item 3-5: one fire, in this order, each outcome ONE row in `triggers.jsonl`: busy -> monthly-exhausted -> refused (an input or the keys
|
|
153
|
+
* are missing) -> started through the ONE start path (kind `trigger`; the reason and the catch-up mark go into the run's own folder first).
|
|
154
|
+
* The fire / ran ledger row was written by the caller BEFORE this, so a crash loses a run and never doubles one.
|
|
155
|
+
* @param {{flow: string, flowDir: string, read: any, trigger: Trigger}} job
|
|
156
|
+
* @param {{kind: 'clock', slot: number, catchUp: boolean, missed: number} | {kind: 'file', path: string, sha: string}} cause
|
|
157
|
+
* @param {{ told?: (outcome: string) => boolean, beforeStart?: () => void }} [hooks] M9 am3 (a queued file): `told(outcome)` true = this file
|
|
158
|
+
* already has a row for that outcome, so none is written again (the outcome is still returned); `beforeStart` runs right before the ONE
|
|
159
|
+
* start, once every check has passed: the scheduler writes the file's `ran` row there.
|
|
160
|
+
*/
|
|
161
|
+
fire(job: {
|
|
162
|
+
flow: string;
|
|
163
|
+
flowDir: string;
|
|
164
|
+
read: any;
|
|
165
|
+
trigger: Trigger;
|
|
166
|
+
}, cause: {
|
|
167
|
+
kind: "clock";
|
|
168
|
+
slot: number;
|
|
169
|
+
catchUp: boolean;
|
|
170
|
+
missed: number;
|
|
171
|
+
} | {
|
|
172
|
+
kind: "file";
|
|
173
|
+
path: string;
|
|
174
|
+
sha: string;
|
|
175
|
+
}, hooks?: {
|
|
176
|
+
told?: (outcome: string) => boolean;
|
|
177
|
+
beforeStart?: () => void;
|
|
178
|
+
}): Record<string, any>;
|
|
179
|
+
/**
|
|
180
|
+
* What a card shows of a job's trigger, as data (no words): the signed trigger, whether it is armed, the next slot (clock kinds), the last
|
|
181
|
+
* fire outcome. `null` when the job is not a readable signed job.
|
|
182
|
+
* @param {string} flow
|
|
183
|
+
*/
|
|
184
|
+
read(flow: string): {
|
|
185
|
+
flow: string;
|
|
186
|
+
trigger: import("../trigger-line.js").Trigger | null;
|
|
187
|
+
flowHash: string;
|
|
188
|
+
armed: boolean;
|
|
189
|
+
armedAt: number | null;
|
|
190
|
+
nextSlotMs: number | null;
|
|
191
|
+
lastOutcome: any;
|
|
192
|
+
hasGreenRun: boolean;
|
|
193
|
+
} | null;
|
|
194
|
+
/**
|
|
195
|
+
* What the Run card's dropdown needs of one job (M9 piece 5): the typed trigger, its words, whether it is armed, and, when the job has had
|
|
196
|
+
* no good run, the server's refusal sentence (the page shows it and disables the dropdown; it invents no words). `editNote` is am1's
|
|
197
|
+
* warning, set only when the job has a trigger. `null` when the job is not a readable signed job.
|
|
198
|
+
* @param {string} flow
|
|
199
|
+
*/
|
|
200
|
+
card(flow: string): {
|
|
201
|
+
trigger: import("../trigger-line.js").Trigger | null;
|
|
202
|
+
words: string | null;
|
|
203
|
+
armed: boolean;
|
|
204
|
+
hasGreenRun: boolean;
|
|
205
|
+
refusal: string | null;
|
|
206
|
+
editNote: string | null;
|
|
207
|
+
} | null;
|
|
208
|
+
};
|
|
209
|
+
export const NO_GREEN_SAY: "This job has not had a good run yet. Run it once by hand and get it right first; then you can set when it runs. Nothing was changed.";
|
|
210
|
+
export type Trigger = import("../trigger-line.js").Trigger;
|
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,15 @@ 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}} opts
|
|
448
|
+
* `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 }: {
|
|
450
452
|
root: string;
|
|
451
453
|
catalogue: any;
|
|
452
454
|
resumeAttempt?: (flow: string, runId: string) => any;
|
|
455
|
+
startingRun?: (flow: string, runId: string) => boolean;
|
|
453
456
|
}): any[];
|
|
454
457
|
/**
|
|
455
458
|
* The ONE ordering of Runs — History and Workflows both render the list in the
|
|
@@ -471,15 +474,19 @@ export function orderRuns(rows: any[]): any[];
|
|
|
471
474
|
* `log.json`. `null` when the flow/runId doesn't resolve to a real run
|
|
472
475
|
* directory at all (caller renders 404); a `red` field names why a
|
|
473
476
|
* sub-derivation couldn't fill (never invented).
|
|
474
|
-
* @param {{root: string, flow: string, runId: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any}} opts
|
|
477
|
+
* @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
478
|
* @returns {any|null}
|
|
476
479
|
*/
|
|
477
|
-
export function getRunDetail({ root, flow, runId, catalogue, resumeAttempt, }: {
|
|
480
|
+
export function getRunDetail({ root, flow, runId, catalogue, resumeAttempt, startingRun, triggerRead, now, home, }: {
|
|
478
481
|
root: string;
|
|
479
482
|
flow: string;
|
|
480
483
|
runId: string;
|
|
481
484
|
catalogue: any;
|
|
482
485
|
resumeAttempt?: (flow: string, runId: string) => any;
|
|
486
|
+
startingRun?: (flow: string, runId: string) => boolean;
|
|
487
|
+
triggerRead?: (flow: string) => any;
|
|
488
|
+
now?: () => number;
|
|
489
|
+
home?: string;
|
|
483
490
|
}): any | null;
|
|
484
491
|
/**
|
|
485
492
|
* 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).
|
|
@@ -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,53 @@
|
|
|
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
|
+
/** am1, said before a human signs an edit of a job that has a trigger. @param {Trigger|null} t @param {string} [home] */
|
|
10
|
+
export function editClearsWords(t: Trigger | null, home?: string): string | null;
|
|
11
|
+
/**
|
|
12
|
+
* NEXT of a job with a trigger. One sentence, first match wins:
|
|
13
|
+
* 1. a run of this job is waiting at its ask (the next run waits too);
|
|
14
|
+
* 2. the latest outcome this month is `monthly-exhausted` (the signed sentence, amounts from the row);
|
|
15
|
+
* 3. a clock kind with a next slot; 4. a file kind that is armed; 5. not armed yet.
|
|
16
|
+
* A last outcome of `refused` goes in front of 3-5, so a trigger that cannot start is never silent.
|
|
17
|
+
* `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.
|
|
18
|
+
* @param {{trigger: Trigger, armed: boolean, nextSlotMs: number|null, lastOutcome: any, waitingLine: number|null, now: number}} f
|
|
19
|
+
* @returns {{text: string, red: boolean}}
|
|
20
|
+
*/
|
|
21
|
+
export function scheduledNextFor(f: {
|
|
22
|
+
trigger: Trigger;
|
|
23
|
+
armed: boolean;
|
|
24
|
+
nextSlotMs: number | null;
|
|
25
|
+
lastOutcome: any;
|
|
26
|
+
waitingLine: number | null;
|
|
27
|
+
now: number;
|
|
28
|
+
}): {
|
|
29
|
+
text: string;
|
|
30
|
+
red: boolean;
|
|
31
|
+
};
|
|
32
|
+
/** The NEXT sentence alone. @param {Parameters<typeof scheduledNextFor>[0]} f */
|
|
33
|
+
export function scheduledNext(f: Parameters<typeof scheduledNextFor>[0]): string;
|
|
34
|
+
/** Fixed catch-up sentence (am2 item 1) from a run's `trigger.json`. @param {any} rec */
|
|
35
|
+
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;
|
|
36
|
+
/**
|
|
37
|
+
* 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
|
|
38
|
+
* that names the code and guesses nothing. `null` when there is no ending (still running, waiting, or no history row and not died).
|
|
39
|
+
* @param {{outcome: string|null, died?: boolean, line: number|null, destination: string|null, canResume: boolean, home?: string}} f
|
|
40
|
+
* @returns {{reason: string, next: string}|null}
|
|
41
|
+
*/
|
|
42
|
+
export function endedWords(f: {
|
|
43
|
+
outcome: string | null;
|
|
44
|
+
died?: boolean;
|
|
45
|
+
line: number | null;
|
|
46
|
+
destination: string | null;
|
|
47
|
+
canResume: boolean;
|
|
48
|
+
home?: string;
|
|
49
|
+
}): {
|
|
50
|
+
reason: string;
|
|
51
|
+
next: string;
|
|
52
|
+
} | null;
|
|
53
|
+
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
|
+
};
|