fwdloop 0.19.0 → 0.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fwdloop",
3
- "version": "0.19.0",
3
+ "version": "0.19.1",
4
4
  "description": "Describe a job as steps and guardrails; an agent builds the workflow, pauses for humans where you said, checks every step happened, and reruns it under budgets it cannot touch.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -216,9 +216,6 @@ export function createTriggerDoor(opts) {
216
216
  }
217
217
 
218
218
  return {
219
- inspect,
220
- now,
221
-
222
219
  /** `POST /api/author/trigger-prepare`: the first click. Checks, signs and writes nothing. @param {any} body */
223
220
  prepare(body) {
224
221
  const s = inspect(body);
@@ -296,8 +293,8 @@ export function createTriggerDoor(opts) {
296
293
  * The fire / ran ledger row was written by the caller BEFORE this, so a crash loses a run and never doubles one.
297
294
  * @param {{flow: string, flowDir: string, read: any, trigger: Trigger}} job
298
295
  * @param {{kind: 'clock', slot: number, catchUp: boolean, missed: number} | {kind: 'file', path: string, sha: string}} cause
299
- * @param {{ told?: (outcome: string) => boolean, beforeStart?: () => void }} [hooks] M9 am3 (a queued file): `told(outcome)` true = this file
300
- * already has a row for that outcome, so none is written again (the outcome is still returned); `beforeStart` runs right before the ONE
296
+ * @param {{ told?: (row: Record<string, any>) => boolean, beforeStart?: () => void }} [hooks] M9 am3 (a queued file): `told(row)` true = this file
297
+ * 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
301
298
  * start, once every check has passed: the scheduler writes the file's `ran` row there.
302
299
  */
303
300
  fire(job, cause, hooks = {}) {
@@ -307,7 +304,7 @@ export function createTriggerDoor(opts) {
307
304
  at: new Date(now()).toISOString(), flow, trigger: desc,
308
305
  ...(cause.kind === 'clock' ? { slot: new Date(cause.slot).toISOString(), catchUp: cause.catchUp, missed: cause.missed } : { file: cause.path, sha: cause.sha, catchUp: false }),
309
306
  };
310
- const done = (/** @type {Record<string, any>} */ r) => { const row = /** @type {Record<string, any>} */ ({ ...base, ...r }); if (!(row.outcome !== 'started' && hooks.told?.(row.outcome))) appendOutcome(flowDir, row); return row; };
307
+ const done = (/** @type {Record<string, any>} */ r) => { const row = /** @type {Record<string, any>} */ ({ ...base, ...r }); if (!(row.outcome !== 'started' && hooks.told?.(row))) appendOutcome(flowDir, row); return row; };
311
308
  const busy = flowsDoor.editBlock(flow); // one run at a time per job: starting, running, or waiting at its ask
312
309
  if (busy !== null) return done({ outcome: 'busy', say: busy });
313
310
  const claim = monthlyClaim(read.arbiter.capUsd); // the same check the Run door decides on
@@ -355,7 +352,9 @@ export function createTriggerDoor(opts) {
355
352
  const { trigger } = r.arbiter;
356
353
  const clock = readRows(join(triggerLedgerDir(flowDir, r.signature.flow), 'clock.jsonl'));
357
354
  const armed = clock.find((x) => x.kind === 'armed');
358
- const outcomes = readOutcomes(flowDir);
355
+ // triggers.jsonl spans every trigger the job ever had and its rows carry words, not the hash: only rows from this signing on are this trigger's
356
+ const since = Date.parse(r.signature.signedAt);
357
+ const outcomes = readOutcomes(flowDir).filter((o) => Date.parse(o.at) >= since);
359
358
  const clockKind = trigger !== null && (trigger.kind === 'daily' || trigger.kind === 'weekdays' || trigger.kind === 'weekly');
360
359
  return {
361
360
  flow, trigger, flowHash: r.signature.flow, armed: armed !== undefined, armedAt: armed ? armed.at : null,
@@ -43,9 +43,10 @@ export function createScheduler(opts) {
43
43
  function runQueue(job, ledger, nowMs) {
44
44
  let queue = queueOf(readSeen(ledger));
45
45
  if (queue.length === 0) return;
46
- const spoken = new Set(readOutcomes(job.flowDir).filter((r) => typeof r.sha === 'string').map((r) => `${r.sha}|${r.outcome}`));
46
+ const key = (/** @type {string} */ sha, /** @type {Record<string, any>} */ r) => `${sha}|${r.outcome}|${r.why ?? ''}`; // a refusal is told once PER REASON; busy / monthly carry no `why`
47
+ const spoken = new Set(readOutcomes(job.flowDir).filter((r) => typeof r.sha === 'string').map((r) => key(r.sha, r)));
47
48
  const cause = (/** @type {any} */ q) => ({ kind: /** @type {'file'} */ ('file'), path: q.path, sha: q.sha });
48
- const told = (/** @type {any} */ q) => (/** @type {string} */ outcome) => { const k = `${q.sha}|${outcome}`; const had = spoken.has(k); spoken.add(k); return had; };
49
+ const told = (/** @type {any} */ q) => (/** @type {Record<string, any>} */ row) => { const k = key(q.sha, row); const had = spoken.has(k); spoken.add(k); return had; };
49
50
  if (door.busy(job)) {
50
51
  for (const q of queue) door.fire(job, cause(q), { told: told(q) });
51
52
  return;
package/src/primitives.js CHANGED
@@ -269,16 +269,15 @@ function addressCellsPrimitiveTool(inputsByRole) {
269
269
  };
270
270
  }
271
271
 
272
- /** The verbs this piece actually implements (the switch below, as data) —
273
- * one writer for "is this verb wired": `resolvePrimitives`'s own reds use
274
- * it, and `src/runner.js`'s preflight (F46: a step granted a
275
- * catalogue-present-but-unwired verb, e.g. litectx's `compress`, must
276
- * refuse before any model call or spend) imports this SAME set rather than
277
- * keeping a second copy of the list. */
278
272
  /** M7: the in-run tools over this run's own store (src/ctx-tools.js). `remember`/`forget` are
279
273
  * deliberately absent: memory lasts one run (PRD: no learning between flows). */
280
274
  const CTX_VERBS = Object.freeze(['recall', 'get', 'recent', 'related', 'impact', 'compress', 'peek', 'stash']);
281
275
 
276
+ /** The verbs this piece actually implements (the switch below, as data) —
277
+ * one writer for "is this verb wired": `resolvePrimitives`'s own reds use
278
+ * it, and `src/runner.js`'s preflight (F46: a step granted a
279
+ * catalogue-present-but-unwired verb must refuse before any model call or
280
+ * spend) imports this SAME set rather than keeping a second copy of the list. */
282
281
  export const WIRED_VERBS = new Set(['read', 'grep', 'write', 'edit', 'readDocx', 'addressCells', ...CTX_VERBS]);
283
282
 
284
283
  /** The wired menu, one place: the catalogue entries whose verb is in
@@ -107,11 +107,6 @@ export function scheduledNextFor(f) {
107
107
  return say(`${lead}Next run ${slotWords(nextSlotMs)}.`, red);
108
108
  }
109
109
 
110
- /** The NEXT sentence alone. @param {Parameters<typeof scheduledNextFor>[0]} f */
111
- export function scheduledNext(f) {
112
- return scheduledNextFor(f).text;
113
- }
114
-
115
110
  /** Fixed catch-up sentence (am2 item 1) from a run's `trigger.json`. @param {any} rec */
116
111
  export function catchUpWords(rec) {
117
112
  return rec && typeof rec === 'object' && rec.catchUp === true ? 'This run was a catch-up: it started more than 2 minutes after its set time (the panel was off).' : null;
@@ -49,13 +49,13 @@ const waiting = (rows, a) => a.kind === 'arrived'
49
49
  /**
50
50
  * Does this finished version arrive? Item 6 + am2: only a sha that already RAN never arrives again; one already arrived and still queued does not
51
51
  * arrive twice; one that was dropped (never ran) may. A `baseline` blocks only while it is still the starting point: file-updated = until the file
52
- * has changed away (any later arrived/ran/dropped row of ANOTHER sha); new-file = for that name + sha (a copy under a new name is a new file).
53
- * @param {SeenRow[]} rows @param {{sha:string, name:string}} it @param {'new'|'updated'} mode
52
+ * has changed away (any later arrived/ran/dropped row of ANOTHER sha); new-file = for that sha for good (hamr 2026-10-13: content present at arm never runs, so a renamed or copied baseline file is not new).
53
+ * @param {SeenRow[]} rows @param {{sha:string}} it @param {'new'|'updated'} mode
54
54
  */
55
55
  function arrives(rows, it, mode) {
56
56
  const mine = ofSha(rows, it.sha);
57
57
  if (mine.some((r) => r.kind === 'ran' || waiting(rows, r))) return false;
58
- const bi = rows.findLastIndex((r) => r.kind === 'baseline' && r.sha === it.sha && (mode === 'updated' || r.name === it.name));
58
+ const bi = rows.findLastIndex((r) => r.kind === 'baseline' && r.sha === it.sha);
59
59
  if (bi < 0) return true;
60
60
  return mode === 'updated' && rows.slice(bi + 1).some((r) => r.kind !== 'baseline' && r.sha !== it.sha);
61
61
  }
@@ -176,7 +176,7 @@ export function createFileTrigger({ mode, target, ledger }) {
176
176
  const st2 = lstatSync(p);
177
177
  if (`${st2.size}:${st2.mtimeMs}` !== t.key) return 'changed'; // changed while reading: retry next poll
178
178
  const sha = sha256(buf);
179
- if (!arrives(readSeen(ledger), { sha, name: basename(p) }, mode)) return null; // ran, still queued, or still the starting point
179
+ if (!arrives(readSeen(ledger), { sha }, mode)) return null; // ran, still queued, or still the starting point
180
180
  return { path: p, sha, size: buf.length };
181
181
  }
182
182
 
@@ -52,26 +52,6 @@ export function createAuthor(opts: {
52
52
  body: any;
53
53
  };
54
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
55
  prepare(body: any): {
76
56
  status: number;
77
57
  body: {
@@ -164,7 +144,7 @@ export function createAuthor(opts: {
164
144
  path: string;
165
145
  sha: string;
166
146
  }, hooks?: {
167
- told?: (outcome: string) => boolean;
147
+ told?: (row: Record<string, any>) => boolean;
168
148
  beforeStart?: () => void;
169
149
  }): Record<string, any>;
170
150
  read(flow: string): {
@@ -38,26 +38,6 @@ export function createTriggerDoor(opts: {
38
38
  }[];
39
39
  now?: () => number;
40
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
41
  /** `POST /api/author/trigger-prepare`: the first click. Checks, signs and writes nothing. @param {any} body */
62
42
  prepare(body: any): {
63
43
  status: number;
@@ -154,8 +134,8 @@ export function createTriggerDoor(opts: {
154
134
  * The fire / ran ledger row was written by the caller BEFORE this, so a crash loses a run and never doubles one.
155
135
  * @param {{flow: string, flowDir: string, read: any, trigger: Trigger}} job
156
136
  * @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
137
+ * @param {{ told?: (row: Record<string, any>) => boolean, beforeStart?: () => void }} [hooks] M9 am3 (a queued file): `told(row)` true = this file
138
+ * 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
159
139
  * start, once every check has passed: the scheduler writes the file's `ran` row there.
160
140
  */
161
141
  fire(job: {
@@ -173,7 +153,7 @@ export function createTriggerDoor(opts: {
173
153
  path: string;
174
154
  sha: string;
175
155
  }, hooks?: {
176
- told?: (outcome: string) => boolean;
156
+ told?: (row: Record<string, any>) => boolean;
177
157
  beforeStart?: () => void;
178
158
  }): Record<string, any>;
179
159
  /**
@@ -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>;
@@ -36,8 +36,6 @@ export function scheduledNextFor(f: {
36
36
  text: string;
37
37
  red: boolean;
38
38
  };
39
- /** The NEXT sentence alone. @param {Parameters<typeof scheduledNextFor>[0]} f */
40
- export function scheduledNext(f: Parameters<typeof scheduledNextFor>[0]): string;
41
39
  /** Fixed catch-up sentence (am2 item 1) from a run's `trigger.json`. @param {any} rec */
42
40
  export function catchUpWords(rec: any): "This run was a catch-up: it started more than 2 minutes after its set time (the panel was off)." | null;
43
41
  /**