fwdloop 0.19.0 → 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.
Files changed (52) hide show
  1. package/bin/fwdloop +22 -13
  2. package/package.json +1 -1
  3. package/src/authoring.js +23 -3
  4. package/src/books.js +3 -2
  5. package/src/flow.js +218 -2
  6. package/src/jobkey.js +25 -0
  7. package/src/jsonl-append.js +29 -0
  8. package/src/monthly.js +3 -2
  9. package/src/panel/author.js +44 -18
  10. package/src/panel/authorcard.js +7 -13
  11. package/src/panel/authorflows.js +118 -24
  12. package/src/panel/authorresume.js +8 -4
  13. package/src/panel/authorstart.js +63 -18
  14. package/src/panel/authortrigger.js +252 -128
  15. package/src/panel/authorvalues.js +13 -2
  16. package/src/panel/data.js +233 -36
  17. package/src/panel/index.html +330 -124
  18. package/src/panel/needsyou.js +29 -0
  19. package/src/panel/scheduler.js +23 -23
  20. package/src/panel/server.js +30 -6
  21. package/src/primitives.js +5 -6
  22. package/src/provider.js +3 -2
  23. package/src/runner.js +10 -10
  24. package/src/runvalues.js +10 -2
  25. package/src/schedule.js +135 -0
  26. package/src/setup.js +0 -21
  27. package/src/summary-words.js +180 -12
  28. package/src/trigger-clock.js +18 -16
  29. package/src/trigger-files.js +40 -27
  30. package/src/trigger-line.js +6 -15
  31. package/src/types.js +1 -1
  32. package/types/authoring.d.ts +32 -2
  33. package/types/flow.d.ts +106 -0
  34. package/types/jobkey.d.ts +11 -0
  35. package/types/jsonl-append.d.ts +6 -0
  36. package/types/panel/author.d.ts +48 -38
  37. package/types/panel/authorcard.d.ts +3 -6
  38. package/types/panel/authorflows.d.ts +38 -10
  39. package/types/panel/authorstart.d.ts +15 -2
  40. package/types/panel/authortrigger.d.ts +75 -63
  41. package/types/panel/authorvalues.d.ts +6 -0
  42. package/types/panel/data.d.ts +101 -19
  43. package/types/panel/needsyou.d.ts +20 -0
  44. package/types/primitives.d.ts +5 -0
  45. package/types/runvalues.d.ts +5 -0
  46. package/types/schedule.d.ts +69 -0
  47. package/types/setup.d.ts +0 -19
  48. package/types/summary-words.d.ts +105 -4
  49. package/types/trigger-clock.d.ts +8 -7
  50. package/types/trigger-files.d.ts +17 -10
  51. package/types/trigger-line.d.ts +16 -8
  52. package/types/types.d.ts +1 -1
@@ -1,25 +1,24 @@
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
1
  /** Every fire outcome of a job, oldest first, through the safe gateway. @param {string} flowDir @returns {any[]} */
4
2
  export function readOutcomes(flowDir: string): any[];
5
3
  /** The ONE writer of `triggers.jsonl`: append-only, one line per fire outcome. @param {string} flowDir @param {Record<string, any>} row */
6
4
  export function appendOutcome(flowDir: string, row: Record<string, any>): void;
7
5
  /**
8
6
  * 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).
7
+ * `job/` copy) is the job as it is now (prose and declaration, byte for byte: a schedule is its own file, so setting one never changes the job).
8
+ * A run from before runs kept a job copy has none to compare, so it counts only when its history row's signature is the job's current one.
12
9
  * @param {string} flowDir
13
10
  */
14
11
  export function hasGreenRunForJob(flowDir: string): boolean;
15
12
  /**
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
13
+ * The ONE writer of "this schedule was set": the starting point (am2 item 2). Idempotent per signing. A file kind records what is already there first
14
+ * (never runs; `baseline: false` = the folder is the same as the earlier signing's, whose rows were carried), then the armed row. Throws, naming why,
15
+ * when the target is not usable now.
16
+ * @param {string} flowDir @param {Schedule} schedule @param {number} now epoch ms @param {{baseline?: boolean}} [o]
20
17
  * @returns {{armed: boolean, already: boolean}}
21
18
  */
22
- export function armFor(flowDir: string, flowHash: string, trigger: Trigger, now: number): {
19
+ export function armFor(flowDir: string, schedule: Schedule, now: number, o?: {
20
+ baseline?: boolean;
21
+ }): {
23
22
  armed: boolean;
24
23
  already: boolean;
25
24
  };
@@ -38,26 +37,6 @@ export function createTriggerDoor(opts: {
38
37
  }[];
39
38
  now?: () => number;
40
39
  }): {
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
40
  /** `POST /api/author/trigger-prepare`: the first click. Checks, signs and writes nothing. @param {any} body */
62
41
  prepare(body: any): {
63
42
  status: number;
@@ -75,8 +54,8 @@ export function createTriggerDoor(opts: {
75
54
  };
76
55
  };
77
56
  /**
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.
57
+ * `POST /api/author/trigger`: the second click, carrying the hash it was shown. Writes `schedule.json` (signed by the human who clicked) and arms it, or
58
+ * (trigger null) cancels. The job's files are never opened for writing. $0: no drafter, no run. A run that is starting, working or waiting is never touched.
80
59
  * @param {any} body
81
60
  */
82
61
  set(body: any): {
@@ -90,79 +69,88 @@ export function createTriggerDoor(opts: {
90
69
  ok: boolean;
91
70
  refused: string;
92
71
  say: string;
93
- reds?: undefined;
72
+ flow?: undefined;
73
+ trigger?: undefined;
74
+ words?: undefined;
75
+ armed?: undefined;
76
+ flowHash?: undefined;
77
+ sig?: undefined;
94
78
  };
95
79
  } | {
96
80
  status: number;
97
81
  body: {
98
82
  ok: boolean;
99
- refused: string;
100
- say: string;
101
- reds: any[];
83
+ flow: any;
84
+ trigger: null;
85
+ words: string | null;
86
+ armed: boolean;
87
+ refused?: undefined;
88
+ say?: undefined;
89
+ flowHash?: undefined;
90
+ sig?: undefined;
102
91
  };
103
92
  } | {
104
93
  status: number;
105
94
  body: {
106
- say?: string | undefined;
107
95
  ok: boolean;
108
96
  flow: any;
109
- trigger: import("../trigger-line.js").Trigger | null;
97
+ trigger: import("../trigger-line.js").Trigger;
110
98
  words: string | null;
111
99
  flowHash: string;
100
+ sig: string;
112
101
  armed: boolean;
113
102
  refused?: undefined;
114
- reds?: undefined;
103
+ say?: undefined;
115
104
  };
116
105
  };
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). */
106
+ /** Every job with a live schedule, as the scheduler needs it: `{flow, flowDir, read, schedule, trigger, sig}`. Reads each job the way the CLI will (signature verified). */
118
107
  scan(): {
119
108
  flow: string;
120
109
  flowDir: string;
121
110
  read: import("../types.js").ReadFlowOk;
122
- trigger: Trigger;
111
+ schedule: import("../schedule.js").Schedule;
112
+ trigger: import("../trigger-line.js").Trigger;
113
+ sig: string;
123
114
  }[];
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 */
115
+ /** A schedule whose job was Edited since (M9 am1: By hand again) is cancelled the way Cancel does it, once. Called at the top of every scheduler tick. */
116
+ retireStale(): void;
117
+ /** M9 am3/am8: is a run of this job starting or still working? A run waiting at its ask is not busy. (the same check `fire` makes first) @param {{flow: string}} job */
134
118
  busy(job: {
135
119
  flow: string;
136
120
  }): 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 */
121
+ /** 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, sig: string}} job @param {Record<string, any>} row */
138
122
  note(job: {
139
123
  flow: string;
140
124
  flowDir: string;
141
125
  trigger: Trigger;
126
+ sig: string;
142
127
  }, row: Record<string, any>): void;
143
128
  /**
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
129
+ * One row in `triggers.jsonl` that is not a fire (the trigger could not be watched). @param {{flow: string, flowDir: string, trigger: Trigger, sig: string}} job @param {string} why
145
130
  */
146
131
  refuse(job: {
147
132
  flow: string;
148
133
  flowDir: string;
149
134
  trigger: Trigger;
135
+ sig: string;
150
136
  }, why: string): void;
151
137
  /**
152
138
  * 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
139
  * 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
140
  * 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
141
+ * @param {{flow: string, flowDir: string, read: any, trigger: Trigger, schedule: Schedule}} job
156
142
  * @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.
143
+ * @param {{ told?: (row: Record<string, any>) => boolean, beforeStart?: () => void, holdIfCannotStart?: boolean }} [hooks] M9 am3 (a queued file): `told(row)` true = this file
144
+ * already has a row for that outcome and reason (`why`), so none is written again (the outcome is still returned); `beforeStart` runs right before the ONE
145
+ * start, once every check has passed: the scheduler writes the file's `ran` row there. `holdIfCannotStart` (a queued file, M9 am17): the starter's `canStart` is asked first, and a no writes nothing
146
+ * (no row, no `beforeStart`) and returns outcome `cannot-start`.
160
147
  */
161
148
  fire(job: {
162
149
  flow: string;
163
150
  flowDir: string;
164
151
  read: any;
165
152
  trigger: Trigger;
153
+ schedule: Schedule;
166
154
  }, cause: {
167
155
  kind: "clock";
168
156
  slot: number;
@@ -173,18 +161,43 @@ export function createTriggerDoor(opts: {
173
161
  path: string;
174
162
  sha: string;
175
163
  }, hooks?: {
176
- told?: (outcome: string) => boolean;
164
+ told?: (row: Record<string, any>) => boolean;
177
165
  beforeStart?: () => void;
166
+ holdIfCannotStart?: boolean;
178
167
  }): Record<string, any>;
179
168
  /**
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.
169
+ * What a card shows of a job's schedule, as data (no words): the trigger (null = By hand), whether it is armed, the next slot (clock kinds), the last
170
+ * fire outcome of THIS signing (rows with its `sig`, never a wall-clock compare). `null` when the job is not a readable signed job.
182
171
  * @param {string} flow
183
172
  */
184
173
  read(flow: string): {
185
174
  flow: string;
186
175
  trigger: import("../trigger-line.js").Trigger | null;
187
176
  flowHash: string;
177
+ sig: string | null;
178
+ armed: boolean;
179
+ armedAt: number | null;
180
+ nextSlotMs: number | null;
181
+ lastOutcome: any;
182
+ hasGreenRun: boolean;
183
+ } | null;
184
+ /**
185
+ * M9 am6/am7: every fact the Job tab's Schedule field, a run's Audit schedule rows and the Run tab's SCHEDULE block are built from, for one job: the
186
+ * schedule, what it is bound to (the run it was set from, model, destination, inputs: what the fire reads from `schedule.json`), the fires of this signing
187
+ * (each one `triggers.jsonl` row with its `sig`) and the newest one. Data only; the words are `src/summary-words.js`'s. `null` when the job is not a readable signed job.
188
+ * @param {string} flow
189
+ */
190
+ facts(flow: string): {
191
+ from: string | null;
192
+ model: string | null;
193
+ destination: string | null;
194
+ inputs: string[];
195
+ fires: any[];
196
+ allFires: any[];
197
+ flow: string;
198
+ trigger: import("../trigger-line.js").Trigger | null;
199
+ flowHash: string;
200
+ sig: string | null;
188
201
  armed: boolean;
189
202
  armedAt: number | null;
190
203
  nextSlotMs: number | null;
@@ -193,8 +206,7 @@ export function createTriggerDoor(opts: {
193
206
  } | null;
194
207
  /**
195
208
  * 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.
209
+ * no good run, the server's refusal sentence (the page shows it and disables the dropdown; it invents no words). `null` when the job is not a readable signed job.
198
210
  * @param {string} flow
199
211
  */
200
212
  card(flow: string): {
@@ -203,8 +215,8 @@ export function createTriggerDoor(opts: {
203
215
  armed: boolean;
204
216
  hasGreenRun: boolean;
205
217
  refusal: string | null;
206
- editNote: string | null;
207
218
  } | null;
208
219
  };
209
220
  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
221
  export type Trigger = import("../trigger-line.js").Trigger;
222
+ export type Schedule = import("../schedule.js").Schedule;
@@ -4,6 +4,11 @@
4
4
  * @param {number} spentUsd @param {number} floorUsd
5
5
  */
6
6
  export function leastResumeCapUsd(spentUsd: number, floorUsd: number): number;
7
+ /**
8
+ * The one sentence for a cap that is not above what is already spent (a Resume's door and note, and the Cap note of a card that belongs to a draft, M4d am23).
9
+ * @param {number} spentUsd @param {number} floorUsd
10
+ */
11
+ export function capAboveSpentText(spentUsd: number, floorUsd: number): string;
7
12
  /**
8
13
  * @param {object} a
9
14
  * @param {string[]} a.allowedKeys the body keys this door takes; any other key is refused by name
@@ -60,5 +65,6 @@ export function checkValues({ allowedKeys, body, base, realRoot, capOnly, floorU
60
65
  };
61
66
  export const NEW_FLOW_SAY: "Only the files, the destination, the money cap and an ask's wait can change from one run to the next. A change to a job line, an ask's words or the steps is a new flow: use New job.";
62
67
  export const RESUME_ONLY_CAP_SAY: "A resume changes only the cap. New files or a new destination or ask wait is a new run of this flow (Run a signed flow); a change to a job line or an ask is a new flow (New job).";
68
+ export function capNotAboveSpent(capUsd: number, alreadyUsd: number): boolean;
63
69
  export { valuesHash };
64
70
  import { valuesHash } from '../runvalues.js';
@@ -405,7 +405,7 @@ export function summarizeSpendRows(spendRows: any[]): {
405
405
  * same object, so the page never offers what the door would refuse). `running` is the glyph's own rule (`isRunningNow`);
406
406
  * a run with no process record yet is `starting`; a parked run (`[·]`/`[!]`, an open ask) is neither.
407
407
  * @param {any} ctx `loadRunContext`'s result @param {string} glyph `computeGlyph`'s sign
408
- * @returns {{canStop: boolean, atAsk: boolean, stopRequested: boolean, starting: boolean, canResume: boolean, resumeOutcome: string|null, spentUsd: number|null, spendComplete: boolean|null, capUsd: number|null}}
408
+ * @returns {{canStop: boolean, atAsk: boolean, stopRequested: boolean, starting: boolean, canResume: boolean, noCopySay: string|null, resumeOutcome: string|null, spentUsd: number|null, spendComplete: boolean|null, capUsd: number|null}}
409
409
  */
410
410
  export function runControls(ctx: any, glyph: string, label?: string): {
411
411
  canStop: boolean;
@@ -413,6 +413,7 @@ export function runControls(ctx: any, glyph: string, label?: string): {
413
413
  stopRequested: boolean;
414
414
  starting: boolean;
415
415
  canResume: boolean;
416
+ noCopySay: string | null;
416
417
  resumeOutcome: string | null;
417
418
  spentUsd: number | null;
418
419
  spendComplete: boolean | null;
@@ -433,11 +434,26 @@ export function getRunControls({ root, flow, runId, catalogue, }: {
433
434
  stopRequested: boolean;
434
435
  starting: boolean;
435
436
  canResume: boolean;
437
+ noCopySay: string | null;
436
438
  resumeOutcome: string | null;
437
439
  spentUsd: number | null;
438
440
  spendComplete: boolean | null;
439
441
  capUsd: number | null;
440
442
  } | null;
443
+ /**
444
+ * M6 am9: the glyph and label of one run, by the panel's ONE rule (`computeGlyph`), read straight from the books. `null` when the run does not resolve.
445
+ * "Red" in the signed text is exactly `glyph === '[✗]'`.
446
+ * @param {{root: string, flow: string, runId: string, catalogue: any}} opts
447
+ */
448
+ export function getRunGlyph({ root, flow, runId, catalogue, }: {
449
+ root: string;
450
+ flow: string;
451
+ runId: string;
452
+ catalogue: any;
453
+ }): {
454
+ glyph: "[\u2713]" | "[\u2717]" | "[\u00B7]" | "[!]" | "[\u25B6]" | "[?]" | "[II]" | "[\u25A0]";
455
+ label: string;
456
+ } | null;
441
457
  /**
442
458
  * `GET /api/runs` — every flow under `root`, every run under each flow
443
459
  * (M4a scope item 2). A flow with zero runs still gets one row (`runId:
@@ -460,7 +476,7 @@ export function listRuns({ root, catalogue, resumeAttempt, startingRun, now }: {
460
476
  * order given (M4c amendment 1 (c)); a flow's top row is therefore the first
461
477
  * run of that flow here, so a waiting run is the parent with no second rule:
462
478
  * 1 waiting on you — least time left first; a stuck run (`[II]`, amendment 2)
463
- * after the ones with a timer;
479
+ * after the ones with a timer, only while it is still in Needs you (M11 am15: a stuck run past its 7 days is section 3);
464
480
  * 2 running (`[▶]`, the glyph's own liveness rule);
465
481
  * 3 everything else — finish time `at`, newest first.
466
482
  * A row with no known time keeps input order at the end of its section.
@@ -469,18 +485,68 @@ export function listRuns({ root, catalogue, resumeAttempt, startingRun, now }: {
469
485
  */
470
486
  export function orderRuns(rows: any[]): any[];
471
487
  /**
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}
488
+ * The tag with the 7-day rule (M11 am3 item 5, am4 item 1, am11 item 4): the card leaves Needs you `needsYouDays` after it joined. `at` is when it joined: the run's stop time
489
+ * (a stuck `[II]` run has none; the caller passes the time its saved answer was written) or the ask's expiry for `Reopen`. An `Answer` run is never dropped by age (its ask has its own wait).
490
+ * @param {string} glyph @param {{atAsk: boolean, canResume: boolean}} controls @param {string|null} [at] @param {number} [nowMs] @param {string|null} [reopenAt]
491
+ * @returns {'Answer'|'Reopen'|'Resume'|null}
479
492
  */
480
493
  export function needsYouTag(glyph: string, controls: {
481
494
  atAsk: boolean;
482
495
  canResume: boolean;
483
- }, at?: string | null, nowMs?: number): "Accept" | "Resume" | null;
496
+ }, at?: string | null, nowMs?: number, reopenAt?: string | null): "Answer" | "Reopen" | "Resume" | null;
497
+ /**
498
+ * M11 am11: where a run stands in Needs you, by the ONE rule (the runs list, the Remove route and the Audit all read it).
499
+ * `tag`: what the card carries now, or null. `removable`: Remove from Needs you is offered (`Reopen` and `Resume`, never `Answer`). `left`: why a card that would be here is not
500
+ * (item 3 `{by: 'you', at}`, item 4 `{by: 'age'}`). `key`: the episode a Remove is written for (item 5): the ask and its expiry for `Reopen`, the stop time for a stopped run, the saved-answer
501
+ * time for a stuck one, so a reopened or resumed run that needs you again is a NEW episode and comes back.
502
+ * @param {{runDir: string, ctx: any, glyph: string, controls: {atAsk: boolean, canResume: boolean}, nowMs: number, reopenAt: string|null}} o
503
+ * @returns {{tag: 'Answer'|'Reopen'|'Resume'|null, removable: boolean, left: {by: 'you', at: string}|{by: 'age'}|null, key: string|null}}
504
+ */
505
+ export function needsYouOf({ runDir, ctx, glyph, controls, nowMs, reopenAt, }: {
506
+ runDir: string;
507
+ ctx: any;
508
+ glyph: string;
509
+ controls: {
510
+ atAsk: boolean;
511
+ canResume: boolean;
512
+ };
513
+ nowMs: number;
514
+ reopenAt: string | null;
515
+ }): {
516
+ tag: "Answer" | "Reopen" | "Resume" | null;
517
+ removable: boolean;
518
+ left: {
519
+ by: "you";
520
+ at: string;
521
+ } | {
522
+ by: "age";
523
+ } | null;
524
+ key: string | null;
525
+ };
526
+ /**
527
+ * M11 am11: `needsYouOf` for one run, read straight from the books (the Remove route's and the Audit's read; the runs list calls `needsYouOf` itself with the context it already has).
528
+ * `null` when the run does not resolve.
529
+ * @param {{root: string, flow: string, runId: string, catalogue: any, nowMs?: number, resumeAttempt?: (flow: string, runId: string) => any}} o
530
+ */
531
+ export function getRunNeeds({ root, flow, runId, catalogue, nowMs, resumeAttempt, }: {
532
+ root: string;
533
+ flow: string;
534
+ runId: string;
535
+ catalogue: any;
536
+ nowMs?: number;
537
+ resumeAttempt?: (flow: string, runId: string) => any;
538
+ }): {
539
+ tag: "Answer" | "Reopen" | "Resume" | null;
540
+ removable: boolean;
541
+ left: {
542
+ by: "you";
543
+ at: string;
544
+ } | {
545
+ by: "age";
546
+ } | null;
547
+ key: string | null;
548
+ runDir: string;
549
+ } | null;
484
550
  /**
485
551
  * 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
552
  * `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.
@@ -591,19 +657,27 @@ export function getDraftBlock(flowDir: string, runDir: string): {
591
657
  * own `audit.jsonl` file already carries only its own rows — there is no
592
658
  * shared-sidecar contamination risk here the way bareloop's gate-audit
593
659
  * sidecar had). `null` when the flow/runId doesn't resolve (404).
594
- * @param {{root: string, flow: string, runId: string}} opts
595
- * @returns {{flow:string, runId:string, rows:any[], groups:any[], draft:ReturnType<typeof getDraftBlock>, empty:boolean, why:string|null}|null}
660
+ * @param {{root: string, flow: string, runId: string, scheduleRead?: (flow: string) => any, home?: string, catalogue?: any, resumeAttempt?: (flow: string, runId: string) => any, startingRun?: (flow: string, runId: string) => boolean, now?: () => number}} opts
661
+ * @returns {{flow:string, runId:string, rows:any[], groups:any[], draft:ReturnType<typeof getDraftBlock>, needsLeft: string|null, schedule: ReturnType<typeof scheduleAuditWords>, empty:boolean, why:string|null}|null}
596
662
  */
597
- export function getRunAudit({ root, flow, runId }: {
663
+ export function getRunAudit({ root, flow, runId, scheduleRead, home, catalogue, resumeAttempt, startingRun, now, }: {
598
664
  root: string;
599
665
  flow: string;
600
666
  runId: string;
667
+ scheduleRead?: (flow: string) => any;
668
+ home?: string;
669
+ catalogue?: any;
670
+ resumeAttempt?: (flow: string, runId: string) => any;
671
+ startingRun?: (flow: string, runId: string) => boolean;
672
+ now?: () => number;
601
673
  }): {
602
674
  flow: string;
603
675
  runId: string;
604
676
  rows: any[];
605
677
  groups: any[];
606
678
  draft: ReturnType<typeof getDraftBlock>;
679
+ needsLeft: string | null;
680
+ schedule: ReturnType<typeof scheduleAuditWords>;
607
681
  empty: boolean;
608
682
  why: string | null;
609
683
  } | null;
@@ -616,14 +690,16 @@ export function getRunAudit({ root, flow, runId }: {
616
690
  * name carries its own why, never a blank or a guess. Field order (server
617
691
  * order matches the page's own render order): prose, asks, model, cap
618
692
  * (+redo cap), sources, sends, guardrails, plan (one row per step, amendment 34), signature.
619
- * @param {{root: string, flow: string, runId: string, catalogue: any}} opts
693
+ * @param {{root: string, flow: string, runId: string, catalogue: any, scheduleRead?: (flow: string) => any, home?: string}} opts
620
694
  * @returns {any|null}
621
695
  */
622
- export function getRunJob({ root, flow, runId, catalogue, }: {
696
+ export function getRunJob({ root, flow, runId, catalogue, scheduleRead, home, }: {
623
697
  root: string;
624
698
  flow: string;
625
699
  runId: string;
626
700
  catalogue: any;
701
+ scheduleRead?: (flow: string) => any;
702
+ home?: string;
627
703
  }): any | null;
628
704
  /**
629
705
  * hamr's 2026-09-27 exit-check review #3: which declared step (and its
@@ -681,21 +757,26 @@ export function groupAskBlocks(asks: any[]): any[];
681
757
  * M4b piece 4: also carries `resume` (the SAME `deriveResumeState` the run
682
758
  * detail carries, `null` for a finished run or nothing to say) so the Ask tab
683
759
  * can tell "open, answerable" from "answer saved" without a second fetch.
684
- * @param {{root: string, flow: string, runId: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any}} opts
685
- * @returns {{flow:string, runId:string, asks:any[], resume: any, blocks: any[]}|null}
760
+ * @param {{root: string, flow: string, runId: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any, now?: () => number}} opts
761
+ * @returns {{flow:string, runId:string, asks:any[], resume: any, blocks: any[], needsYou: {tag: string|null, removable: boolean}}|null}
686
762
  */
687
- export function getRunAsks({ root, flow, runId, catalogue, resumeAttempt, }: {
763
+ export function getRunAsks({ root, flow, runId, catalogue, resumeAttempt, now, }: {
688
764
  root: string;
689
765
  flow: string;
690
766
  runId: string;
691
767
  catalogue: any;
692
768
  resumeAttempt?: (flow: string, runId: string) => any;
769
+ now?: () => number;
693
770
  }): {
694
771
  flow: string;
695
772
  runId: string;
696
773
  asks: any[];
697
774
  resume: any;
698
775
  blocks: any[];
776
+ needsYou: {
777
+ tag: string | null;
778
+ removable: boolean;
779
+ };
699
780
  } | null;
700
781
  /**
701
782
  * `GET /api/inbox` — every stop (parked ask, open or past) across every
@@ -770,7 +851,7 @@ export const STUCK_REASONS: {
770
851
  why: string;
771
852
  };
772
853
  };
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`. */
854
+ export function needsRemovedFile(key: string): string;
774
855
  export const RUNS_LIST_LIMITS: Readonly<{
775
856
  quietDays: 30;
776
857
  olderRuns: 7;
@@ -780,3 +861,4 @@ export const RUNS_LIST_LIMITS: Readonly<{
780
861
  export const NO_DRAFT_WORDS: "no draft record";
781
862
  /** M6: what the Job tab says for a run that started before runs kept a copy of their job. */
782
863
  export const NO_JOB_COPY_WORDS: "This run started before runs kept a copy of their job, so this shows the job as it is now.";
864
+ import { scheduleAuditWords } from '../summary-words.js';
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Write the marker for the episode the card is in now. Refused unless the run is in Needs you with a removable tag (`Reopen` or `Resume`, never `Answer`) right now.
3
+ * @param {{root: string, flow: string, runId: string, catalogue: any, nowMs?: number, at?: string, resumeAttempt?: (flow: string, runId: string) => any}} o
4
+ * @returns {{ok: true}|{ok: false, refused: 'no-such-run'|'not-in-needs-you', say: string}}
5
+ */
6
+ export function removeFromNeedsYou({ root, flow, runId, catalogue, nowMs, at, resumeAttempt, }: {
7
+ root: string;
8
+ flow: string;
9
+ runId: string;
10
+ catalogue: any;
11
+ nowMs?: number;
12
+ at?: string;
13
+ resumeAttempt?: (flow: string, runId: string) => any;
14
+ }): {
15
+ ok: true;
16
+ } | {
17
+ ok: false;
18
+ refused: "no-such-run" | "not-in-needs-you";
19
+ say: string;
20
+ };
@@ -50,4 +50,9 @@ export class GateRefusal extends Error {
50
50
  path: any;
51
51
  rule: any;
52
52
  }
53
+ /** The verbs this piece actually implements (the switch below, as data) —
54
+ * one writer for "is this verb wired": `resolvePrimitives`'s own reds use
55
+ * it, and `src/runner.js`'s preflight (F46: a step granted a
56
+ * catalogue-present-but-unwired verb must refuse before any model call or
57
+ * spend) imports this SAME set rather than keeping a second copy of the list. */
53
58
  export const WIRED_VERBS: Set<string>;
@@ -30,6 +30,11 @@ export function valuesHash({ flow, flowSignatureHash, runId, version, values, }:
30
30
  }): string;
31
31
  /** True when `a` and `b` are the same values (cap, destination, every wait). */
32
32
  export function sameValues(a: any, b: any): boolean;
33
+ /** The model a run was signed to use instead of its flow's recorded one, or null (the flow's). The ONE reader. @param {ReturnType<typeof pickRunValues>} picked */
34
+ export function runModelOf(picked: ReturnType<typeof pickRunValues>): {
35
+ slot: any;
36
+ model: any;
37
+ } | null;
33
38
  /**
34
39
  * The ONE writer of a version file: write-once (`wx`), mode 0600. Refuses a record whose hash does not match its own fields.
35
40
  * @param {string} runDir
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The job's schedule, or null (no file, unreadable, not the shape, or a file whose own hashes do not check: it was changed after it was signed, so it
3
+ * is not the schedule a human signed and nothing acts on it). Read through the safe gateway.
4
+ * @param {string} flowDir @returns {Schedule|null}
5
+ */
6
+ export function readSchedule(flowDir: string): Schedule | null;
7
+ /** THE writer of `schedule.json`: atomic (temp file, then rename). @param {string} flowDir @param {Schedule} schedule */
8
+ export function writeSchedule(flowDir: string, schedule: Schedule): void;
9
+ /** The only remover of `schedule.json`. @param {string} flowDir */
10
+ export function removeSchedule(flowDir: string): void;
11
+ /** Does a re-sign keep the same kind and the same folder/file (so the queue and the baseline stand)? @param {Trigger|null|undefined} cur @param {Trigger|null} next */
12
+ export function sameTarget(cur: Trigger | null | undefined, next: Trigger | null): boolean;
13
+ /**
14
+ * Every file waiting under signing `sig` leaves its queue: one `dropped` row (under `sig`) and ONE row in the outcome file with am16's words. The drop is written
15
+ * BEFORE the row: a crash loses a row, never doubles one. @param {string} flowDir @param {string} sig
16
+ * @param {number} nowMs @param {(row: Record<string, any>) => void} note writes one outcome row
17
+ */
18
+ export function dropQueue(flowDir: string, sig: string, nowMs: number, note: (row: Record<string, any>) => void): void;
19
+ /**
20
+ * The folder is the same: signing `to` takes over everything `from` knew about the files (baseline, arrived, ran, dropped, in order), so the queue and
21
+ * the starting point stand. Written BEFORE the new `schedule.json`; the old signing's waiting files are marked `carried` after it (`finishCarry`).
22
+ * @param {string} flowDir @param {string} from @param {string} to
23
+ */
24
+ export function carryQueue(flowDir: string, from: string, to: string): void;
25
+ /** The old signing's files that `carryQueue` copied are no longer its own to run. @param {string} flowDir @param {string} from @param {number} nowMs */
26
+ export function finishCarry(flowDir: string, from: string, nowMs: number): void;
27
+ /** Cancel's own row in the ledger. @param {string} flowDir @param {string} sig @param {number} nowMs */
28
+ export function recordCancelled(flowDir: string, sig: string, nowMs: number): void;
29
+ /** @typedef {import('./trigger-line.js').Trigger} Trigger */
30
+ /**
31
+ * @typedef {{
32
+ * v: 1, flow: string, trigger: Trigger, flowSignatureHash: string, bound: string, sig: string, signedBy: string, signedAt: string,
33
+ * model: {slot: string, model: string}|null, destination: string|null, inputs: {role: string, path: string}[]|null,
34
+ * plan: {run: string, flowHash: string, declSha: string}|null, from: string|null,
35
+ * }} Schedule
36
+ */
37
+ export const SCHEDULE_FILE: "schedule.json";
38
+ export const LEDGER_FILE: "schedule-ledger.jsonl";
39
+ export function droppedSay(name: string): string;
40
+ export function scheduleFileOf(flowDir: string): string;
41
+ export function ledgerOf(flowDir: string): string;
42
+ export function sigOf(bound: string, signedAt: string): string;
43
+ export function isArmed(flowDir: string, sig: string): boolean;
44
+ export type Trigger = import("./trigger-line.js").Trigger;
45
+ export type Schedule = {
46
+ v: 1;
47
+ flow: string;
48
+ trigger: Trigger;
49
+ flowSignatureHash: string;
50
+ bound: string;
51
+ sig: string;
52
+ signedBy: string;
53
+ signedAt: string;
54
+ model: {
55
+ slot: string;
56
+ model: string;
57
+ } | null;
58
+ destination: string | null;
59
+ inputs: {
60
+ role: string;
61
+ path: string;
62
+ }[] | null;
63
+ plan: {
64
+ run: string;
65
+ flowHash: string;
66
+ declSha: string;
67
+ } | null;
68
+ from: string | null;
69
+ };
package/types/setup.d.ts CHANGED
@@ -70,25 +70,6 @@ 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
- };
92
73
  /**
93
74
  * 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).
94
75
  * @param {string} flowDir