fwdloop 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @param {{ root: string, home?: string, skipMonthly?: boolean, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null, keyNames?: string[] }, bin?: string, childRunning?: (dir: string) => boolean, thinkingSupport?: typeof bareagentThinkingSupport }} opts
2
+ * @param {{ root: string, home?: string, skipMonthly?: boolean, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null, keyNames?: string[] }, bin?: string, childRunning?: (dir: string) => boolean, thinkingSupport?: typeof bareagentThinkingSupport, now?: () => number }} opts
3
3
  * `loadEnv` is the keys-file door (`keysForDoor`): called before EVERY spawn and every reply that quotes a log, so editing
4
4
  * the file needs no restart. Its `env` is BOTH the child's spawn env AND the scrub list (POC (a), M4d wiring rule).
5
5
  */
@@ -16,75 +16,17 @@ export function createAuthor(opts: {
16
16
  bin?: string;
17
17
  childRunning?: (dir: string) => boolean;
18
18
  thinkingSupport?: typeof bareagentThinkingSupport;
19
+ now?: () => number;
19
20
  }): {
20
- flows: () => {
21
- status: number;
21
+ /** `GET /api/author/flows`, each listed job carrying its trigger card (M9 piece 5): the typed trigger, its words, and why it cannot be set (no good run yet). */
22
+ flows(): {
22
23
  body: {
24
+ flows: any[];
23
25
  ok: boolean;
24
- flows: never[];
25
26
  leftThisMonth?: undefined;
26
- };
27
- } | {
28
- status: number;
29
- body: {
27
+ } | {
28
+ flows: any[];
30
29
  ok: boolean;
31
- flows: {
32
- edit: {
33
- ok: boolean;
34
- say: string;
35
- card?: undefined;
36
- flowHash?: undefined;
37
- } | {
38
- ok: boolean;
39
- card: {
40
- job: string;
41
- inputs: string;
42
- destination: string;
43
- capUsd: string;
44
- askWait: string;
45
- };
46
- flowHash: any;
47
- say?: undefined;
48
- };
49
- values: {
50
- capUsd: number;
51
- destination: string | null;
52
- askWaits: Record<string, string>;
53
- };
54
- jobLines: any;
55
- hasSend: boolean;
56
- capFloorUsd: number;
57
- floorModel: string | null;
58
- model: {
59
- slot: string;
60
- model: string;
61
- label: string;
62
- } | null;
63
- flow: string;
64
- capUsd: any;
65
- roles: any;
66
- nextRunId: string;
67
- lastRunId: string | null;
68
- lastSources: Record<string, string>;
69
- leftThisMonth: any;
70
- runs: {
71
- sources: Record<string, string>;
72
- values: {
73
- capUsd: number;
74
- destination: string | null;
75
- askWaits: Record<string, string>;
76
- };
77
- runId: string;
78
- }[];
79
- stats: {
80
- steps: any;
81
- asks: number;
82
- green: number;
83
- notGreen: number;
84
- avgSpendUsd: number | null;
85
- avgWallMs: number | null;
86
- };
87
- }[];
88
30
  leftThisMonth: {
89
31
  limitUsd: null;
90
32
  leftUsd: null;
@@ -97,86 +39,10 @@ export function createAuthor(opts: {
97
39
  say: string;
98
40
  };
99
41
  };
100
- };
101
- runAgain: (flow: string | null, runId: string | null) => {
102
- status: any;
103
- body: {
104
- ok: boolean;
105
- refused: string;
106
- say: any;
107
- };
108
- } | {
109
42
  status: number;
110
- body: {
111
- ok: boolean;
112
- flow: {
113
- edit: {
114
- ok: boolean;
115
- say: string;
116
- card?: undefined;
117
- flowHash?: undefined;
118
- } | {
119
- ok: boolean;
120
- card: {
121
- job: string;
122
- inputs: string;
123
- destination: string;
124
- capUsd: string;
125
- askWait: string;
126
- };
127
- flowHash: any;
128
- say?: undefined;
129
- };
130
- values: {
131
- capUsd: number;
132
- destination: string | null;
133
- askWaits: Record<string, string>;
134
- };
135
- jobLines: any;
136
- hasSend: boolean;
137
- capFloorUsd: number;
138
- floorModel: string | null;
139
- model: {
140
- slot: string;
141
- model: string;
142
- label: string;
143
- } | null;
144
- flow: string;
145
- capUsd: any;
146
- roles: any;
147
- nextRunId: string;
148
- lastRunId: string | null;
149
- lastSources: Record<string, string>;
150
- leftThisMonth: any;
151
- runs: {
152
- sources: Record<string, string>;
153
- values: {
154
- capUsd: number;
155
- destination: string | null;
156
- askWaits: Record<string, string>;
157
- };
158
- runId: string;
159
- }[];
160
- stats: {
161
- steps: any;
162
- asks: number;
163
- green: number;
164
- notGreen: number;
165
- avgSpendUsd: number | null;
166
- avgWallMs: number | null;
167
- };
168
- };
169
- pick: {
170
- sources: Record<string, string>;
171
- values: {
172
- capUsd: number;
173
- destination: string | null;
174
- askWaits: Record<string, string>;
175
- };
176
- runId: string;
177
- };
178
- };
179
43
  };
44
+ /** `GET /api/author/run-again`, its flow entry carrying the trigger card like the list's entries do. @param {string|null} flow @param {string|null} runId */
45
+ runAgain(flow: string | null, runId: string | null): any;
180
46
  run: (body: any) => {
181
47
  status: any;
182
48
  body: any;
@@ -185,6 +51,141 @@ export function createAuthor(opts: {
185
51
  status: any;
186
52
  body: any;
187
53
  };
54
+ trigger: {
55
+ inspect: (body: any) => {
56
+ ok: false;
57
+ reply: {
58
+ status: number;
59
+ body: {
60
+ ok: boolean;
61
+ };
62
+ };
63
+ } | {
64
+ ok: true;
65
+ flow: any;
66
+ read: import("../types.js").ReadFlowOk;
67
+ trigger: import("../trigger-line.js").Trigger | null;
68
+ flowDir: string;
69
+ realRoot: string;
70
+ proseText: string;
71
+ declaration: any;
72
+ hash: string;
73
+ };
74
+ now: () => number;
75
+ prepare(body: any): {
76
+ status: number;
77
+ body: {
78
+ ok: boolean;
79
+ };
80
+ } | {
81
+ status: number;
82
+ body: {
83
+ ok: boolean;
84
+ flow: any;
85
+ trigger: import("../trigger-line.js").Trigger | null;
86
+ words: string | null;
87
+ hash: string;
88
+ };
89
+ };
90
+ set(body: any): {
91
+ status: number;
92
+ body: {
93
+ ok: boolean;
94
+ };
95
+ } | {
96
+ status: number;
97
+ body: {
98
+ ok: boolean;
99
+ refused: string;
100
+ say: string;
101
+ reds?: undefined;
102
+ };
103
+ } | {
104
+ status: number;
105
+ body: {
106
+ ok: boolean;
107
+ refused: string;
108
+ say: string;
109
+ reds: any[];
110
+ };
111
+ } | {
112
+ status: number;
113
+ body: {
114
+ say?: string | undefined;
115
+ ok: boolean;
116
+ flow: any;
117
+ trigger: import("../trigger-line.js").Trigger | null;
118
+ words: string | null;
119
+ flowHash: string;
120
+ armed: boolean;
121
+ refused?: undefined;
122
+ reds?: undefined;
123
+ };
124
+ };
125
+ scan(): {
126
+ flow: string;
127
+ flowDir: string;
128
+ read: import("../types.js").ReadFlowOk;
129
+ trigger: import("./authortrigger.js").Trigger;
130
+ }[];
131
+ ensureArmed(job: {
132
+ flowDir: string;
133
+ read: any;
134
+ trigger: Trigger;
135
+ }): {
136
+ armed: boolean;
137
+ already: boolean;
138
+ };
139
+ busy(job: {
140
+ flow: string;
141
+ }): boolean;
142
+ note(job: {
143
+ flow: string;
144
+ flowDir: string;
145
+ trigger: Trigger;
146
+ }, row: Record<string, any>): void;
147
+ refuse(job: {
148
+ flow: string;
149
+ flowDir: string;
150
+ trigger: Trigger;
151
+ }, why: string): void;
152
+ fire(job: {
153
+ flow: string;
154
+ flowDir: string;
155
+ read: any;
156
+ trigger: Trigger;
157
+ }, cause: {
158
+ kind: "clock";
159
+ slot: number;
160
+ catchUp: boolean;
161
+ missed: number;
162
+ } | {
163
+ kind: "file";
164
+ path: string;
165
+ sha: string;
166
+ }, hooks?: {
167
+ told?: (outcome: string) => boolean;
168
+ beforeStart?: () => void;
169
+ }): Record<string, any>;
170
+ read(flow: string): {
171
+ flow: string;
172
+ trigger: import("../trigger-line.js").Trigger | null;
173
+ flowHash: string;
174
+ armed: boolean;
175
+ armedAt: number | null;
176
+ nextSlotMs: number | null;
177
+ lastOutcome: any;
178
+ hasGreenRun: boolean;
179
+ } | null;
180
+ card(flow: string): {
181
+ trigger: import("../trigger-line.js").Trigger | null;
182
+ words: string | null;
183
+ armed: boolean;
184
+ hasGreenRun: boolean;
185
+ refusal: string | null;
186
+ editNote: string | null;
187
+ } | null;
188
+ };
188
189
  resumePrepare: (body: any) => any;
189
190
  resumeForm: (flow: string | null, runId: string | null) => {
190
191
  status: any;
@@ -232,6 +233,8 @@ export function createAuthor(opts: {
232
233
  say: string;
233
234
  };
234
235
  };
236
+ /** The starter's "this run's start is in phase `starting`" for the Runs list and a run's page (`startingFor`, the ONE rule). @param {string} flow @param {string} runId */
237
+ startingRun(flow: string, runId: string): boolean;
235
238
  /** `GET /api/author/start/:startId`: the start's phase, read from its files. @param {string} id */
236
239
  startGet(id: string): {
237
240
  status: number;
@@ -44,6 +44,14 @@ export function createFlowsDoor(opts: {
44
44
  }): {
45
45
  /** M6 amendments 1 and 3: the sentence that says why this flow cannot be edited now, or null (the sign route's check). @param {string} name */
46
46
  editBlock(name: string): string | null;
47
+ /** M9: the source paths the newest run of this job used, role -> path (blank = none), for a start a trigger fires. @param {string} name @param {string[]} roles */
48
+ lastSourcesOf(name: string, roles: string[]): {
49
+ runId: null;
50
+ sources: Record<string, string>;
51
+ } | {
52
+ runId: string;
53
+ sources: Record<string, string>;
54
+ };
47
55
  /** `GET /api/author/flows`. */
48
56
  flows(): {
49
57
  status: number;
@@ -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
- * @param {{ kind: 'run'|'sign', flow: string, runId: string, sources: {role: string, path: string}[], values?: any, pick?: {slot: string, model: string}|null }} a
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;