@foldrun/core 14.5.0 → 15.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/store.ts CHANGED
@@ -55,7 +55,8 @@ import { parseRemotes, remoteNetworkHosts, A2A_LIMIT_KEY, type RemoteSpec } from
55
55
  import { parseBudget, budgetProblem } from "./budget.ts";
56
56
  import { timezoneProblem } from "./clock.ts";
57
57
  import { parseStepLimits, readLimits } from "./limits.ts";
58
- import { networkProblems, resolveNetwork, type NetworkPolicy } from "./network.ts";
58
+ import { networkEnforceWanted, networkProblems, resolveNetwork, type NetworkPolicy } from "./network.ts";
59
+ import { browseVendorOf } from "./browse-egress.ts";
59
60
  import { webProblems, webWarnings, runnerEngines, webConfig } from "./providers.ts";
60
61
  import { actionProblems } from "./web-actions.ts";
61
62
  import { languageProblem } from "./language.ts";
@@ -1050,8 +1051,9 @@ export interface AgentInfo {
1050
1051
  * the default (open when it may fetch or browse the web, else trusted).
1051
1052
  * `implied` here is its `apis:` hosts; a run also adds its MCP servers',
1052
1053
  * its web providers' and its bound secrets' sites. */
1053
- /** browses: the step may browse — not held to its list yet (FOL-110). */
1054
- network: NetworkPolicy & { readsWeb: boolean; browses: boolean };
1054
+ /** browses: the step may browse; enforceWanted and browseVendor are what
1055
+ * this folder says toward browseVerdict (FOL-110) — the install says the rest. */
1056
+ network: NetworkPolicy & { readsWeb: boolean; browses: boolean; enforceWanted: boolean; browseVendor: string | null };
1055
1057
  /** Tools this agent declares inline rather than in `tools:` — `apis:`,
1056
1058
  * `scripts:` and `mcpServers:` names — which a limit may also name. */
1057
1059
  inlineTools: string[];
@@ -1677,9 +1679,14 @@ export function listAgents(tenant: string, workspace: string): AgentInfo[] {
1677
1679
  ],
1678
1680
  }),
1679
1681
  readsWeb,
1680
- // The runner's own test (runner.ts `browses`): such a step gets no
1681
- // forward proxy yet, so its list does not hold (FOL-110).
1682
+ // The runner's own test (runner.ts `browses`). Whether its list holds
1683
+ // for such a step depends on the install too (browse-egress.ts
1684
+ // browseVerdict): the two fields below are this folder's half of it.
1682
1685
  browses: tools.includes("web") && (!actions || actions.includes("browse")),
1686
+ // network_enforce: true in the account's or workspace's AGENTS.md.
1687
+ enforceWanted: networkEnforceWanted(accountFront.network_enforce, workspaceFront.network_enforce),
1688
+ // The vendor its web.browse names, null for foldrun's own browser.
1689
+ browseVendor: browseVendorOf(webConfig(data, { ...accountFront, ...workspaceFront }).raw.browse),
1683
1690
  };
1684
1691
  return {
1685
1692
  network,
@@ -43,6 +43,9 @@ export type TriggerOutcome =
43
43
  | "overlap-skipped"
44
44
  | "missed"
45
45
  | "filtered"
46
+ /** The account already had its most runs waiting for their turn
47
+ * (FOL-100, 5 Nov 2026): this one was refused, not lined up. */
48
+ | "queue-full"
46
49
  | "failed";
47
50
 
48
51
  export interface TriggerEvent {
@@ -57,6 +60,20 @@ export interface TriggerEvent {
57
60
  runId?: string;
58
61
  }
59
62
 
63
+ /** A refused start's own code, for rollbackTrigger: a lowercase word an
64
+ * error that carries an HTTP status also carries (`waiting_cap`), never a
65
+ * system errno (`ENOENT`). Undefined for anything else. */
66
+ export function refusalCode(err: unknown): string | undefined {
67
+ const o = err as { code?: unknown; status?: unknown } | null;
68
+ return o && typeof o.status === "number" && typeof o.code === "string" && /^[a-z][a-z0-9_]*$/.test(o.code) ? o.code : undefined;
69
+ }
70
+
71
+ /** The outcome a start that threw is logged as: `queue-full` for the
72
+ * account's waiting cap, else `failed`. */
73
+ export function failedOutcome(code: string | undefined): TriggerOutcome {
74
+ return code === "waiting_cap" ? "queue-full" : "failed";
75
+ }
76
+
60
77
  function logFile(tenant: string, workspace: string) {
61
78
  return path.join(workspaceDir(tenant, workspace), "trigger-log.jsonl");
62
79
  }
package/src/triggers.ts CHANGED
@@ -12,8 +12,10 @@
12
12
  // read that run's fields; it receives what the run concluded, as text, and
13
13
  // an agent reads it — the same rule as every other handoff in the format.
14
14
 
15
+ import { opsLog, opsError } from "./ops-log.ts";
15
16
  import crypto from "node:crypto";
16
17
  import { platform } from "./platform.ts";
18
+ import { refusalCode } from "./trigger-log.ts";
17
19
  import { listFlows, readRun, runVerdict, type FlowInfo, type FlowStep, type RunRecord } from "./store.ts";
18
20
  import { getSecret, signingSecretShown } from "./secrets.ts";
19
21
 
@@ -92,7 +94,7 @@ export async function fireChainedFlows(tenant: string, workspace: string, finish
92
94
  try {
93
95
  const gate = await platform.admitTrigger(tenant, workspace, flow, { body, tag: "previous_run", fields: chainFields(finished) });
94
96
  if (!gate.admit) {
95
- console.log(`[foldrun] trigger: flow — ${tenant}/${workspace}/${flow.name} not started: ${gate.detail}`);
97
+ opsLog("info", "trigger.flow_not_started", { tenant, workspace, flow: flow.name, reason: gate.reason });
96
98
  continue;
97
99
  }
98
100
  try {
@@ -102,13 +104,13 @@ export async function fireChainedFlows(tenant: string, workspace: string, finish
102
104
  `after:${finished.flow}`,
103
105
  ], null, finished.test ? { test: true } : {});
104
106
  started.push(run.id);
105
- console.log(`[foldrun] trigger: flow — ${tenant}/${workspace}/${flow.name} started after ${finished.flow} ${finished.status}`);
107
+ opsLog("info", "trigger.flow_started", { tenant, workspace, flow: flow.name, runId: run.id, kind: "previous_run", outcome: finished.status });
106
108
  } catch (err) {
107
- await platform.rollbackTrigger(tenant, workspace, flow, { reason: err instanceof Error ? err.message : String(err) });
109
+ await platform.rollbackTrigger(tenant, workspace, flow, { reason: err instanceof Error ? err.message : String(err), code: refusalCode(err) });
108
110
  throw err;
109
111
  }
110
112
  } catch (err) {
111
- console.error(`[foldrun] trigger: flow — ${tenant}/${workspace}/${flow.name}:`, err instanceof Error ? err.message : err);
113
+ opsError("trigger.flow_failed", err, { tenant, workspace, flow: flow.name });
112
114
  }
113
115
  }
114
116
  return started;
@@ -157,7 +159,7 @@ export async function fireStorageTriggers(
157
159
  // forty runs — which is exactly what `debounce:` is for.
158
160
  const gate = await platform.admitTrigger(tenant, workspace, flow, { body, tag: "storage_event", fields: { by, paths: hits } });
159
161
  if (!gate.admit) {
160
- console.log(`[foldrun] trigger: storage — ${tenant}/${workspace}/${flow.name} not started: ${gate.detail}`);
162
+ opsLog("info", "trigger.storage_not_started", { tenant, workspace, flow: flow.name, reason: gate.reason });
161
163
  continue;
162
164
  }
163
165
  try {
@@ -166,11 +168,11 @@ export async function fireStorageTriggers(
166
168
  ]);
167
169
  started.push(run.id);
168
170
  } catch (err) {
169
- await platform.rollbackTrigger(tenant, workspace, flow, { reason: err instanceof Error ? err.message : String(err) });
171
+ await platform.rollbackTrigger(tenant, workspace, flow, { reason: err instanceof Error ? err.message : String(err), code: refusalCode(err) });
170
172
  throw err;
171
173
  }
172
174
  } catch (err) {
173
- console.error(`[foldrun] trigger: storage — ${tenant}/${workspace}/${flow.name}:`, err instanceof Error ? err.message : err);
175
+ opsError("trigger.storage_failed", err, { tenant, workspace, flow: flow.name });
174
176
  }
175
177
  }
176
178
  return started;
package/src/webhook.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  // identity under the install's secret key. Stable across restarts, unique
3
3
  // per flow, and rotating FOLDRUN_SECRET_KEY invalidates every hook at once.
4
4
 
5
+ import { opsLog } from "./ops-log.ts";
5
6
  import fs from "node:fs";
6
7
  import path from "node:path";
7
8
  import { workspaceDir } from "./store.ts";
@@ -225,8 +226,8 @@ function noteRefusal(tenant: string, workspace: string, delivery: HookDelivery)
225
226
  seen.since++;
226
227
  return;
227
228
  }
228
- const more = seen?.since ? ` (and ${seen.since} more since the last note)` : "";
229
- console.warn(`[hooks] refused a delivery to ${key}/${delivery.flow}: ${delivery.outcome}${more}`);
229
+ // count: this one and those refused since the last note.
230
+ opsLog("warn", "webhook.delivery_refused", { tenant, workspace, flow: delivery.flow, outcome: delivery.outcome, count: (seen?.since ?? 0) + 1 });
230
231
  refusalNotes.set(key, { at: now, since: 0 });
231
232
  if (refusalNotes.size > 10_000) refusalNotes.clear(); // bounded: a note lost beats memory
232
233
  }