fwdloop 0.19.1 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) 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 +250 -125
  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 +21 -22
  20. package/src/panel/server.js +30 -6
  21. package/src/provider.js +3 -2
  22. package/src/runner.js +10 -10
  23. package/src/runvalues.js +10 -2
  24. package/src/schedule.js +135 -0
  25. package/src/setup.js +0 -21
  26. package/src/summary-words.js +180 -7
  27. package/src/trigger-clock.js +18 -16
  28. package/src/trigger-files.js +37 -24
  29. package/src/trigger-line.js +6 -15
  30. package/src/types.js +1 -1
  31. package/types/authoring.d.ts +32 -2
  32. package/types/flow.d.ts +106 -0
  33. package/types/jobkey.d.ts +11 -0
  34. package/types/jsonl-append.d.ts +6 -0
  35. package/types/panel/author.d.ts +47 -17
  36. package/types/panel/authorcard.d.ts +3 -6
  37. package/types/panel/authorflows.d.ts +38 -10
  38. package/types/panel/authorstart.d.ts +15 -2
  39. package/types/panel/authortrigger.d.ts +73 -41
  40. package/types/panel/authorvalues.d.ts +6 -0
  41. package/types/panel/data.d.ts +101 -19
  42. package/types/panel/needsyou.d.ts +20 -0
  43. package/types/runvalues.d.ts +5 -0
  44. package/types/schedule.d.ts +69 -0
  45. package/types/setup.d.ts +0 -19
  46. package/types/summary-words.d.ts +105 -2
  47. package/types/trigger-clock.d.ts +8 -7
  48. package/types/trigger-files.d.ts +17 -10
  49. package/types/trigger-line.d.ts +16 -8
  50. package/types/types.d.ts +1 -1
@@ -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
+ };
@@ -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
@@ -13,8 +13,6 @@ export function slotWords(ms: number): string;
13
13
  export function nextTimeWords(ms: number, now: number): string;
14
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
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
16
  /**
19
17
  * NEXT of a job with a trigger. One sentence, first match wins:
20
18
  * 1. a run of this job is waiting at its ask (the next run waits too);
@@ -55,4 +53,109 @@ export function endedWords(f: {
55
53
  reason: string;
56
54
  next: string;
57
55
  } | null;
56
+ /** "MM/DD HH:MM", local time: the same form as the run cards' `rlShortDate`. @param {number|string} when epoch ms or an ISO string */
57
+ export function shortStamp(when: number | string): string;
58
+ /** "Tue 10/20 09:05": the day name then the short stamp. @param {number} ms */
59
+ export function dayStamp(ms: number): string;
60
+ /**
61
+ * The schedule in words, lower-case first ("every day at 08:15"): the SINGLE line-1 of the Run tab's SCHEDULE block and the first part of the Job tab's
62
+ * Schedule field. `null` (no schedule) has no sentence. @param {Trigger|null} t @param {string} [home]
63
+ */
64
+ export function scheduleHead(t: Trigger | null, home?: string): string | null;
65
+ /**
66
+ * The Job tab's "Schedule" field: the workflow's schedule now and what it is bound to, parts joined by " · ", or `none`.
67
+ * @param {{trigger: Trigger|null, from?: string|null, model?: string|null, destination?: string|null, inputs?: string[]|null, home?: string}} f
68
+ */
69
+ export function scheduleFieldWords(f: {
70
+ trigger: Trigger | null;
71
+ from?: string | null;
72
+ model?: string | null;
73
+ destination?: string | null;
74
+ inputs?: string[] | null;
75
+ home?: string;
76
+ }): string;
77
+ /**
78
+ * The Job tab's Started line: `By hand · 10/15 13:46`, `By the schedule: every day at 08:15 · catch-up, 10 min late · 10/15 08:16`,
79
+ * `By a new file: aging-oct.csv · …`, `By a file update: aging.csv · …`. The trailing stamp is the run's start (am7 item 5); absent when the books do not hold one.
80
+ * @param {any} rec the run's trigger.json or null @param {number|null} startMs @param {string} [home]
81
+ */
82
+ export function startedWords(rec: any, startMs: number | null, home?: string): string;
83
+ /**
84
+ * The Run tab's SCHEDULE block (am7 item 3, am8 items 2-8): `{line1, line2, red}`. Line 1 = the schedule words or `By hand`. Line 2 (only with a schedule):
85
+ * `no run yet` before any fire; else `last <stamp> · ` then the newest fire's words, then `next ...`:
86
+ * - a start: `<run-N> · <outcome>[ · catch-up]` (a run waiting at its ask: `<run-N> · waiting for your answer (the next run does not wait)`), normal;
87
+ * - busy: `busy: a run of this job was still working`, normal (it clears by itself);
88
+ * - month used up: `month used up: $0.01 left, needs $0.50 · next: raise the limit in Settings, or it starts on the 1st`, red only while `nowMs` is still that month;
89
+ * - refused: `refused: <why> · next: fix it in Cancel / modify schedule`, red until a later good start.
90
+ * `next` otherwise: `next <day stamp>`, `next: waiting for a new file` (file schedule) or `next: not armed yet`.
91
+ * @param {{trigger: Trigger|null, home?: string, last: {at: string, runId: string, outcome: string, catchUp: boolean}|null, nextSlotMs: number|null, armed: boolean, problem: any, nowMs?: number}} f
92
+ * `problem`: the newest fire when it started nothing (busy, monthly-exhausted, refused), else null.
93
+ * @returns {{line1: string, line2: string|null, red: boolean}}
94
+ */
95
+ export function scheduleBlockWords(f: {
96
+ trigger: Trigger | null;
97
+ home?: string;
98
+ last: {
99
+ at: string;
100
+ runId: string;
101
+ outcome: string;
102
+ catchUp: boolean;
103
+ } | null;
104
+ nextSlotMs: number | null;
105
+ armed: boolean;
106
+ problem: any;
107
+ nowMs?: number;
108
+ }): {
109
+ line1: string;
110
+ line2: string | null;
111
+ red: boolean;
112
+ };
113
+ /**
114
+ * M9 am9 / am11: a run's Audit `schedule` section (one for every run of a job that has a schedule NOW; `null` when it has none). Folded head
115
+ * `<sign> <schedule words> · from run-7 · 2 tries started nothing`; unfolded rows `this run` and `tries` (stamp + words each).
116
+ * The schedule words are the SAME `line1` the Run tab's SCHEDULE block carries; the sign is `[▶]` while a run of the job is running, `[✗]` when that block is red, else `[·]` (am11).
117
+ * @param {{trigger: Trigger|null, runId: string, from: string|null, rec: any, startMs: number|null, block: {line1: string, red: boolean}, running: boolean, fires: any[]}} f
118
+ * `rec`: this run's trigger.json or null (a hand run); `fires`: every triggers.jsonl row of the job, across every signing.
119
+ * @returns {{sign: string, head: string, rows: Array<{label: string, stamp: string, text: string}>}|null}
120
+ */
121
+ export function scheduleAuditWords(f: {
122
+ trigger: Trigger | null;
123
+ runId: string;
124
+ from: string | null;
125
+ rec: any;
126
+ startMs: number | null;
127
+ block: {
128
+ line1: string;
129
+ red: boolean;
130
+ };
131
+ running: boolean;
132
+ fires: any[];
133
+ }): {
134
+ sign: string;
135
+ head: string;
136
+ rows: Array<{
137
+ label: string;
138
+ stamp: string;
139
+ text: string;
140
+ }>;
141
+ } | null;
142
+ /**
143
+ * M11 am11 items 3-4: the Audit row that says why a card left Needs you: `removed from Needs you by you · 10/15 08:15`, or `removed from Needs you after 7 days`. `null` when it did not.
144
+ * @param {{by: 'you', at: string}|{by: 'age'}|null} left
145
+ */
146
+ export function needsLeftWords(left: {
147
+ by: "you";
148
+ at: string;
149
+ } | {
150
+ by: "age";
151
+ } | null): string | null;
152
+ /** ENDED (am7 item 1): `10/14 08:16 · passed · Goal met.`. The stamp is the run's local end time; the word is the run's outcome word (none for a run ended on purpose). @param {string|null} at ISO @param {string|null} word @param {string} reason */
153
+ export function endedLineWords(at: string | null, word: string | null, reason: string): string;
154
+ /** M9 am8 item 3: the busy sentence, in the busy row of `triggers.jsonl` and in the SCHEDULE block. One owner; the scheduler writes it, the words read it. */
155
+ export const SCHEDULE_BUSY_SAY: "a run of this job was still working";
156
+ export function startedNothing(row: any): any;
157
+ /** M9 am9 item 4: at most this many `tries` show. */
158
+ export const SCHEDULE_TRIES_SHOWN: 7;
159
+ /** M9 am12: what a stopped run with no kept copy of its job says where Resume would be (a run made before runs kept one). The one owner of these words. */
160
+ export const NO_COPY_SAY: "This run started before runs kept their own copy of the job, so it cannot carry on. Start a new run.";
58
161
  export type Trigger = import("./trigger-line.js").Trigger;
@@ -20,17 +20,17 @@ export function due(schedule: Schedule, rows: ClockRow[], now: number): Due;
20
20
  * @returns {number}
21
21
  */
22
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;
23
+ /** @param {string} file @param {string} [sig] M9 am20: only the rows of that schedule signing (the one schedule ledger carries every signing's rows); absent = every row @returns {ClockRow[]} every row on disk that parses, oldest first; a missing file is no rows; a line a crash tore mid-append is skipped (`appendOnce` starts each append on a fresh line, so it never glues onto the next row). */
24
+ export function readRows(file: string, sig?: string): ClockRow[];
25
+ /** The trigger was set at `now`: no slot before this ever fires. @param {string} file @param {number} now @param {string} [sig] */
26
+ export function armTrigger(file: string, now: number, sig?: string): void;
27
27
  /**
28
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
29
+ * @param {string} file @param {Due} d the result of `due` with fire true @param {number} now @param {string} [sig]
30
30
  */
31
- export function recordFire(file: string, d: Due, now: number): void;
31
+ export function recordFire(file: string, d: Due, now: number, sig?: string): void;
32
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 */
33
+ /** @typedef {{id:string, kind:'armed'|'fire', at:number, slot?:number, catchUp?:boolean, missed?:number, sig?:string}} ClockRow */
34
34
  /** @typedef {{fire:boolean, catchUp:boolean, missed:number, slot?:number}} Due */
35
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
36
  export const GRACE_MS: 120000;
@@ -51,6 +51,7 @@ export type ClockRow = {
51
51
  slot?: number;
52
52
  catchUp?: boolean;
53
53
  missed?: number;
54
+ sig?: string;
54
55
  };
55
56
  export type Due = {
56
57
  fire: boolean;
@@ -1,16 +1,16 @@
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 */
1
+ /** Every row that parses; a line a crash tore mid-append is skipped (it counts as not written). `appendSeen` starts each append on a fresh line, so a torn line can never glue onto the next row. @param {string} file @param {string} [sig] M9 am20: only the rows of that schedule signing (the one schedule ledger carries every signing's rows); absent = every row @returns {SeenRow[]} */
2
+ export function readSeen(file: string, sig?: 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 @param {string} [sig] */
4
4
  export function recordArrived(ledger: string, item: ToRun & {
5
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 */
6
+ }, at: number, sig?: string): 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'|'schedule-changed'|'carried'} why @param {number} at @param {string} [sig] */
8
8
  export function recordDropped(ledger: string, item: {
9
9
  sha: string;
10
10
  path: string;
11
11
  size: number;
12
12
  id?: string;
13
- }, why: "deleted" | "changed", at: number): boolean;
13
+ }, why: "deleted" | "changed" | "schedule-changed" | "carried", at: number, sig?: string): boolean;
14
14
  /**
15
15
  * The queue: arrived and neither ran nor dropped, oldest arrival first. Identical arrival times: by name, then by sha (deterministic).
16
16
  * @param {SeenRow[]} rows @returns {(SeenRow & {path:string})[]}
@@ -45,12 +45,18 @@ export function recheck(item: {
45
45
  */
46
46
  export function checkTarget(mode: "new" | "updated", target: string): void;
47
47
  /**
48
- * @param {{mode:'new'|'updated', target:string, ledger:string}} opts target = folder (new) or file (updated)
48
+ * M9 am16: does a trigger on this target still watch this file? New: the file sits directly in the same (real) folder. Updated: it is the same (real) file. False when the target cannot be resolved.
49
+ * @param {'new'|'updated'} mode @param {string} target @param {string} filePath a queued file's path as the watcher recorded it (a real path)
49
50
  */
50
- export function createFileTrigger({ mode, target, ledger }: {
51
+ export function watches(mode: "new" | "updated", target: string, filePath: string): boolean;
52
+ /**
53
+ * @param {{mode:'new'|'updated', target:string, ledger:string, sig?:string}} opts target = folder (new) or file (updated); `sig` (M9 am20) = the schedule signing every row this trigger reads and writes belongs to
54
+ */
55
+ export function createFileTrigger({ mode, target, ledger, sig }: {
51
56
  mode: "new" | "updated";
52
57
  target: string;
53
58
  ledger: string;
59
+ sig?: string;
54
60
  }): {
55
61
  arm: () => void;
56
62
  poll: () => {
@@ -58,7 +64,7 @@ export function createFileTrigger({ mode, target, ledger }: {
58
64
  refused: Refused[];
59
65
  };
60
66
  };
61
- /** @typedef {{id:string, kind:'baseline'|'arrived'|'ran'|'dropped', sha:string, name:string, size:number, at:number, path?:string, why?:string, of?:string}} SeenRow */
67
+ /** @typedef {{id:string, kind:'baseline'|'arrived'|'ran'|'dropped', sha:string, name:string, size:number, at:number, path?:string, why?:string, of?:string, sig?:string}} SeenRow */
62
68
  /** @typedef {{path:string, sha:string, size:number}} ToRun */
63
69
  /** @typedef {{path:string, why:string}} Refused */
64
70
  /** Consecutive polls with the same size and mtime before a file is taken. (Two matches in a row = taken on the third sighting.) */
@@ -67,7 +73,7 @@ export function recordRan(ledger: string, item: {
67
73
  sha: string;
68
74
  path: string;
69
75
  size: number;
70
- }, at: number): boolean;
76
+ }, at: number, sig?: string): boolean;
71
77
  export type SeenRow = {
72
78
  id: string;
73
79
  kind: "baseline" | "arrived" | "ran" | "dropped";
@@ -78,6 +84,7 @@ export type SeenRow = {
78
84
  path?: string;
79
85
  why?: string;
80
86
  of?: string;
87
+ sig?: string;
81
88
  };
82
89
  export type ToRun = {
83
90
  path: string;
@@ -14,20 +14,28 @@ export function parseTrigger(text: string): {
14
14
  export function triggerLine(t: Trigger): string;
15
15
  /** The prose without any trigger line. Everything else is byte-for-byte what it was. @param {string} prose */
16
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
17
  /**
24
18
  * 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
19
+ * @param {{flow: string, flowSignatureHash: string, trigger: Trigger|null, model?: {slot: string, model: string}|null, destination?: string|null, inputs?: {role: string, path: string}[]|null, plan?: {run: string, flowHash: string, declSha: string}|null}} a
26
20
  */
27
- export function triggerHash({ flow, flowSignatureHash, trigger }: {
21
+ export function triggerHash({ flow, flowSignatureHash, trigger, model, destination, inputs, plan }: {
28
22
  flow: string;
29
23
  flowSignatureHash: string;
30
24
  trigger: Trigger | null;
25
+ model?: {
26
+ slot: string;
27
+ model: string;
28
+ } | null;
29
+ destination?: string | null;
30
+ inputs?: {
31
+ role: string;
32
+ path: string;
33
+ }[] | null;
34
+ plan?: {
35
+ run: string;
36
+ flowHash: string;
37
+ declSha: string;
38
+ } | null;
31
39
  }): string;
32
40
  export function isTriggerLine(line: string): boolean;
33
41
  /** M9: the file a triggered start writes (once, before the spawn) into the run's own folder: why this run started. `appendHistory` copies it into the run's history row. */
package/types/types.d.ts CHANGED
@@ -95,7 +95,7 @@ export type Arbiter = {
95
95
  */
96
96
  roundBudgetMs: number;
97
97
  /**
98
- * - `trigger <kind> ...` (M9). Default null = By hand.
98
+ * - `trigger <kind> ...` (M9). Default null = By hand. M9 am20: read for jobs signed before, NEVER acted on (a schedule is `schedule.json`).
99
99
  */
100
100
  trigger: import("./trigger-line.js").Trigger | null;
101
101
  };