@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/dist/src/browse-egress.d.ts +45 -4
- package/dist/src/browse-egress.js +58 -16
- package/dist/src/capture.js +2 -1
- package/dist/src/mail.js +2 -1
- package/dist/src/notify.js +12 -7
- package/dist/src/ops-log.d.ts +55 -0
- package/dist/src/ops-log.js +389 -0
- package/dist/src/platform.d.ts +15 -1
- package/dist/src/runner.js +50 -16
- package/dist/src/secrets.js +4 -3
- package/dist/src/step-exec.d.ts +4 -2
- package/dist/src/step-exec.js +10 -4
- package/dist/src/storage.js +2 -1
- package/dist/src/store.d.ts +4 -1
- package/dist/src/store.js +9 -3
- package/dist/src/trigger-log.d.ts +11 -1
- package/dist/src/trigger-log.js +12 -0
- package/dist/src/triggers.js +9 -7
- package/dist/src/webhook.js +3 -2
- package/package.json +1 -1
- package/src/browse-egress.ts +88 -17
- package/src/capture.ts +2 -1
- package/src/mail.ts +2 -1
- package/src/notify.ts +12 -9
- package/src/ops-log.ts +399 -0
- package/src/platform.ts +13 -1
- package/src/runner.ts +50 -16
- package/src/secrets.ts +4 -5
- package/src/step-exec.ts +10 -4
- package/src/storage.ts +2 -1
- package/src/store.ts +12 -5
- package/src/trigger-log.ts +17 -0
- package/src/triggers.ts +9 -7
- package/src/webhook.ts +3 -2
|
@@ -1,11 +1,52 @@
|
|
|
1
|
-
import { type NetworkPolicy } from "./network.ts";
|
|
1
|
+
import { type NetworkLevel, type NetworkPolicy } from "./network.ts";
|
|
2
2
|
export type BrowseTier = "hosted" | "vendor" | "none";
|
|
3
|
+
/** Set to "1" in a browsing step held to its list (browseVerdict "hosted"):
|
|
4
|
+
* the web tool gives its browser the forward door as launch options and
|
|
5
|
+
* refuses what cannot go through it; the platform starts no account browser
|
|
6
|
+
* pod for the step (its pod could not reach one, and that pod is not walled). */
|
|
7
|
+
export declare const BROWSER_CONFINED_ENV = "FOLDRUN_BROWSER_CONFINED";
|
|
8
|
+
/** The vendor a `web.browse` value names (the runner's FOLDRUN_BROWSER_VENDOR),
|
|
9
|
+
* or null for foldrun's own browser — read the way runner.ts reads it. */
|
|
10
|
+
export declare function browseVendorOf(browse: unknown): string | null;
|
|
3
11
|
/** Which tier a step's browser falls in: no vendor (or foldrun) is ours. */
|
|
4
12
|
export declare function browseTier(vendor: string | null | undefined): {
|
|
5
13
|
tier: BrowseTier;
|
|
6
14
|
title: string;
|
|
7
15
|
};
|
|
16
|
+
/** How one browsing step is held to its `network:` list:
|
|
17
|
+
*
|
|
18
|
+
* legacy — as before phase 3: no forward proxy, the pod keeps the world,
|
|
19
|
+
* and the trace says the list does not hold. An open list, a
|
|
20
|
+
* report-only install, or an executor that cannot wall the
|
|
21
|
+
* step's network.
|
|
22
|
+
* hosted — enforced: the step gets the forward proxy, its pod is walled
|
|
23
|
+
* to the egress proxy and DNS, and foldrun's browser runs in it.
|
|
24
|
+
* refuse — a vendor's browser under a restricted, enforced list on an
|
|
25
|
+
* install that holds browsing: it browses from the vendor's
|
|
26
|
+
* network, which nothing here can hold to the list, so the step
|
|
27
|
+
* is refused before anything connects (decision 4). */
|
|
28
|
+
export type BrowseVerdict = {
|
|
29
|
+
kind: "legacy";
|
|
30
|
+
} | {
|
|
31
|
+
kind: "hosted";
|
|
32
|
+
} | {
|
|
33
|
+
kind: "refuse";
|
|
34
|
+
message: string;
|
|
35
|
+
};
|
|
36
|
+
export declare function browseVerdict(o: {
|
|
37
|
+
/** The step's resolved level (network.ts). */
|
|
38
|
+
level: NetworkLevel;
|
|
39
|
+
/** Will the proxy refuse a site off the list (lease.enforce)? */
|
|
40
|
+
enforce: boolean;
|
|
41
|
+
/** FOLDRUN_BROWSER_VENDOR: the vendor the agent named, if any. */
|
|
42
|
+
vendor: string | null | undefined;
|
|
43
|
+
/** Can this executor wall the step's network (Platform.confinesBrowsing)? */
|
|
44
|
+
confines: boolean;
|
|
45
|
+
}): BrowseVerdict;
|
|
8
46
|
/** The trace's network line for a step that may browse, on an install with
|
|
9
|
-
* an egress proxy: the step's list, and
|
|
10
|
-
*
|
|
11
|
-
|
|
47
|
+
* an egress proxy: the step's list, and whether it holds — `hosted` when
|
|
48
|
+
* browseVerdict put the step under the wall, else the plain fact that it
|
|
49
|
+
* does not hold yet, for the browser or anything else in the step. */
|
|
50
|
+
export declare function browseNetworkLine(policy: NetworkPolicy, vendor: string | null | undefined, opts?: {
|
|
51
|
+
hosted?: boolean;
|
|
52
|
+
}): string;
|
|
@@ -1,22 +1,42 @@
|
|
|
1
1
|
// Browsing and `network:` (FOL-110, foldrun-docs/proposals/browse-egress.md).
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// gives it no forward proxy (a browser in the sandbox cannot send credentials
|
|
5
|
-
// written into a proxy URL), so the browser — and every other program in that
|
|
6
|
-
// step — reaches sites directly. Until the browse service and hosted
|
|
7
|
-
// enforcement ship, the trace says so plainly, and says which of the three
|
|
8
|
-
// tiers this step's browser will fall in:
|
|
3
|
+
// Three tiers, said in the trace:
|
|
9
4
|
//
|
|
10
5
|
// hosted — foldrun's own browser (the account's browser pod, Lightpanda,
|
|
11
|
-
// Obscura, a live session): our network boundary
|
|
6
|
+
// Obscura, a live session): our network boundary confines it.
|
|
12
7
|
// vendor — a vendor that takes a customer proxy (Browserbase, Steel,
|
|
13
8
|
// Hyperbrowser, Browserless): through the egress proxy, enforced
|
|
14
|
-
// once that vendor is qualified by our own tests.
|
|
9
|
+
// once that vendor is qualified by our own tests (phase 4).
|
|
15
10
|
// none — a vendor that always browses through its own network (Bright
|
|
16
11
|
// Data, ZenRows) or any DevTools address: never enforced; a
|
|
17
|
-
// restricted, enforced `network:`
|
|
18
|
-
|
|
12
|
+
// restricted, enforced `network:` refuses it.
|
|
13
|
+
//
|
|
14
|
+
// Phase 3 (hosted enforcement) holds a browsing step to its list where the
|
|
15
|
+
// executor can wall the step's network (the k8s tier, with the install's
|
|
16
|
+
// FOLDRUN_BROWSE_ENFORCE=1 — Platform.confinesBrowsing). Such a step gets the
|
|
17
|
+
// forward proxy like any other, so its run pod is `filtered`: it reaches the
|
|
18
|
+
// egress proxy and DNS and nothing else, and the browser runs inside it, in
|
|
19
|
+
// the step's own pod. A client that sets another proxy, a CDP context with
|
|
20
|
+
// its own proxyServer, a curl that ignores HTTPS_PROXY — each finds no route,
|
|
21
|
+
// never a way round the list. Not covered: DNS lookups through the cluster's
|
|
22
|
+
// resolver, which the wall admits and nothing here restricts. browseVerdict
|
|
23
|
+
// says, for one step, which of the three ways it goes; everywhere else (no
|
|
24
|
+
// wall, an open or report-only list) the step browses as it did before
|
|
25
|
+
// phase 3, and the trace says so.
|
|
26
|
+
import { findBrowserApi, readBrowseSettings, resolveSearch } from "./providers.js";
|
|
19
27
|
import { networkLine } from "./network.js";
|
|
28
|
+
/** Set to "1" in a browsing step held to its list (browseVerdict "hosted"):
|
|
29
|
+
* the web tool gives its browser the forward door as launch options and
|
|
30
|
+
* refuses what cannot go through it; the platform starts no account browser
|
|
31
|
+
* pod for the step (its pod could not reach one, and that pod is not walled). */
|
|
32
|
+
export const BROWSER_CONFINED_ENV = "FOLDRUN_BROWSER_CONFINED";
|
|
33
|
+
/** The vendor a `web.browse` value names (the runner's FOLDRUN_BROWSER_VENDOR),
|
|
34
|
+
* or null for foldrun's own browser — read the way runner.ts reads it. */
|
|
35
|
+
export function browseVendorOf(browse) {
|
|
36
|
+
const read = readBrowseSettings(browse);
|
|
37
|
+
const choice = resolveSearch(read.rest, "browse");
|
|
38
|
+
return choice.shape === "direct" && choice.provider ? choice.provider : null;
|
|
39
|
+
}
|
|
20
40
|
/** Which tier a step's browser falls in: no vendor (or foldrun) is ours. */
|
|
21
41
|
export function browseTier(vendor) {
|
|
22
42
|
const name = (vendor ?? "").trim().toLowerCase();
|
|
@@ -27,15 +47,37 @@ export function browseTier(vendor) {
|
|
|
27
47
|
return { tier: "none", title: name };
|
|
28
48
|
return { tier: api.egress === "proxy" ? "vendor" : "none", title: api.title };
|
|
29
49
|
}
|
|
50
|
+
export function browseVerdict(o) {
|
|
51
|
+
if (o.level === "open" || !o.enforce || !o.confines)
|
|
52
|
+
return { kind: "legacy" };
|
|
53
|
+
const { tier, title } = browseTier(o.vendor);
|
|
54
|
+
if (tier === "hosted")
|
|
55
|
+
return { kind: "hosted" };
|
|
56
|
+
const why = tier === "vendor"
|
|
57
|
+
? `${title} browses from its own network, and foldrun cannot hold it to network: until that vendor is qualified (FOL-110 phase 4)`
|
|
58
|
+
: `${title} always browses through its own network, and nothing can hold it to network:`;
|
|
59
|
+
return {
|
|
60
|
+
kind: "refuse",
|
|
61
|
+
message: `browse: refused before it connected — this step's network: ${o.level} is enforced, and ${why}. ` +
|
|
62
|
+
`Drop browse: ${(o.vendor ?? "").trim()} from the agent's web: block to browse with foldrun's own browser, which is held to the list; ` +
|
|
63
|
+
`or, to accept browsing that no list holds for this one agent, give that agent network: open.`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
30
66
|
/** The trace's network line for a step that may browse, on an install with
|
|
31
|
-
* an egress proxy: the step's list, and
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
|
|
67
|
+
* an egress proxy: the step's list, and whether it holds — `hosted` when
|
|
68
|
+
* browseVerdict put the step under the wall, else the plain fact that it
|
|
69
|
+
* does not hold yet, for the browser or anything else in the step. */
|
|
70
|
+
export function browseNetworkLine(policy, vendor, opts = {}) {
|
|
35
71
|
const what = networkLine(policy, true);
|
|
36
|
-
|
|
72
|
+
if (opts.hosted) {
|
|
73
|
+
return `${what} — enforced — hosted: the browser runs inside this step's sandbox, whose network reaches only the egress proxy (which holds the list) and DNS, so a page, a script or a changed proxy setting reaches no site off the list; DNS lookups themselves are not restricted.`;
|
|
74
|
+
}
|
|
75
|
+
const { tier, title } = browseTier(vendor);
|
|
76
|
+
const now = " — not enforced in this step: it may browse, and browsing does not go through the egress proxy here, so the browser and every other program in this step reach sites directly";
|
|
37
77
|
const later = tier === "hosted"
|
|
38
|
-
?
|
|
78
|
+
? policy.level === "open"
|
|
79
|
+
? `. Its browser is ${title}; with an open list there is nothing to hold it to`
|
|
80
|
+
: `. Its browser is ${title}: it is held to network: on an install that confines browsing, with the list enforced (FOL-110)`
|
|
39
81
|
: tier === "vendor"
|
|
40
82
|
? `. Its browser (${title}) browses from the vendor's network: it comes under network: through the egress proxy once that vendor is qualified (FOL-110)`
|
|
41
83
|
: `. Its browser (${title}) always browses through its own network and cannot be held to network: — a restricted, enforced network: will refuse it (FOL-110)`;
|
package/dist/src/capture.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// credential or a private key — a key the agent read from a file or a page
|
|
5
5
|
// is not in the vault, and is still a key. Masked first, cut second, so a
|
|
6
6
|
// secret on the cap's edge is never kept half. Recording never fails the step.
|
|
7
|
+
import { opsError } from "./ops-log.js";
|
|
7
8
|
import { redactText } from "./scan.js";
|
|
8
9
|
import { writeCapturedCall, CAPTURE_CAP } from "./store.js";
|
|
9
10
|
import { isFileValue, fileContent, isApiValue, apiConfigOf, isClientCertValue, clientCertOf } from "./secrets.js";
|
|
@@ -112,7 +113,7 @@ redactSecrets) {
|
|
|
112
113
|
return true;
|
|
113
114
|
}
|
|
114
115
|
catch (err) {
|
|
115
|
-
|
|
116
|
+
opsError("capture.write_failed", err, { tool, runId });
|
|
116
117
|
return false;
|
|
117
118
|
}
|
|
118
119
|
}
|
package/dist/src/mail.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
// The preference is asked at send time, here, through platform.mailPreference
|
|
24
24
|
// — the platform keeps them as records. A laptop has no preferences store and
|
|
25
25
|
// sends everything, which is what it always did.
|
|
26
|
+
import { opsError } from "./ops-log.js";
|
|
26
27
|
import crypto from "node:crypto";
|
|
27
28
|
import { platform } from "./platform.js";
|
|
28
29
|
import { installKey, publicUrl } from "./webhook.js";
|
|
@@ -178,7 +179,7 @@ export async function mailWanted(tenant, email, category, workspace = null) {
|
|
|
178
179
|
catch (err) {
|
|
179
180
|
// A preferences store that cannot be read sends: a missed alert is
|
|
180
181
|
// worse than one unwanted mail, and the next send asks again.
|
|
181
|
-
|
|
182
|
+
opsError("mail.preference_unreadable", err, { tenant, kind: category, outcome: "sent" }, "warn");
|
|
182
183
|
return true;
|
|
183
184
|
}
|
|
184
185
|
}
|
package/dist/src/notify.js
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
// Defaults: failed and awaiting-approval. Completed is opt-in — a schedule
|
|
31
31
|
// that works is the quiet kind of good news, and a channel that pings on
|
|
32
32
|
// every success gets muted, which un-pings the failures too.
|
|
33
|
+
import { opsLog, opsError } from "./ops-log.js";
|
|
33
34
|
import crypto from "node:crypto";
|
|
34
35
|
import { readAgentsMd } from "./runner.js";
|
|
35
36
|
import { accountDir, workspaceDir, runCost, readFlow, runVerdict } from "./store.js";
|
|
@@ -159,7 +160,7 @@ export function signatureHeaders(tenant, workspace, config, body) {
|
|
|
159
160
|
return {};
|
|
160
161
|
const secret = getSecret(tenant, config.signingSecret, workspace);
|
|
161
162
|
if (!secret) {
|
|
162
|
-
|
|
163
|
+
opsLog("warn", "notify.signing_secret_missing", { tenant, workspace, outcome: "sent_unsigned" });
|
|
163
164
|
return {};
|
|
164
165
|
}
|
|
165
166
|
const timestamp = Math.floor(Date.now() / 1000).toString();
|
|
@@ -437,7 +438,7 @@ export async function sendPlainNotificationOutcome(tenant, workspace, msg) {
|
|
|
437
438
|
return { ok: r.ok, retrying: r.retrying === true };
|
|
438
439
|
}
|
|
439
440
|
catch (err) {
|
|
440
|
-
|
|
441
|
+
opsError("notify.event_failed", err, { tenant, workspace, kind: msg.event });
|
|
441
442
|
return no;
|
|
442
443
|
}
|
|
443
444
|
}
|
|
@@ -594,7 +595,9 @@ export async function sendRunNotification(tenant, workspace, run) {
|
|
|
594
595
|
if (config.email) {
|
|
595
596
|
const mail = notifyMail(tenant, workspace);
|
|
596
597
|
if (!mail) {
|
|
597
|
-
|
|
598
|
+
// RESEND_API_KEY (and EMAIL_FROM) on the account, or
|
|
599
|
+
// FOLDRUN_RESEND_API_KEY on the platform.
|
|
600
|
+
opsLog("error", "notify.no_mail_credential", { tenant, workspace });
|
|
598
601
|
return false;
|
|
599
602
|
}
|
|
600
603
|
// A gate is its own category: a person may want failures and not
|
|
@@ -629,7 +632,9 @@ export async function sendRunNotification(tenant, workspace, run) {
|
|
|
629
632
|
// Resend's body says WHY — "domain not verified", "can only send to
|
|
630
633
|
// your own address" — and a status alone sent someone to the wrong
|
|
631
634
|
// dashboard for twenty minutes on 2026-09-06.
|
|
632
|
-
|
|
635
|
+
// The provider's words stay out of our log (they quote what was
|
|
636
|
+
// sent); the status is what an operator can act on.
|
|
637
|
+
opsLog("error", "notify.email_failed", { tenant, workspace, status: r.status });
|
|
633
638
|
return false;
|
|
634
639
|
}
|
|
635
640
|
return true;
|
|
@@ -638,19 +643,19 @@ export async function sendRunNotification(tenant, workspace, run) {
|
|
|
638
643
|
// vault instead of in a file that gets committed.
|
|
639
644
|
const target = webhookTarget(tenant, workspace, config);
|
|
640
645
|
if (!target.url) {
|
|
641
|
-
|
|
646
|
+
opsLog("error", "notify.no_webhook_url", { tenant, workspace, reason: target.refused ? "refused" : "secret_not_set" });
|
|
642
647
|
return false;
|
|
643
648
|
}
|
|
644
649
|
const event = blocked ? "blocked" : run.status;
|
|
645
650
|
const r = await platform.deliverWebhook(tenant, workspace, { event, body: JSON.stringify(body), retry: true });
|
|
646
651
|
if (!r.ok) {
|
|
647
|
-
|
|
652
|
+
opsLog("error", "notify.webhook_failed", { tenant, workspace, status: r.statusCode, retrying: r.retrying === true });
|
|
648
653
|
return false;
|
|
649
654
|
}
|
|
650
655
|
return true;
|
|
651
656
|
}
|
|
652
657
|
catch (err) {
|
|
653
|
-
|
|
658
|
+
opsError("notify.failed", err, { tenant, workspace });
|
|
654
659
|
return false;
|
|
655
660
|
}
|
|
656
661
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Why something failed, in one word an operator can count. Small on
|
|
2
|
+
* purpose: a class is a bucket on a dashboard, not a diagnosis. */
|
|
3
|
+
export declare const ERROR_CLASSES: readonly ["policy_denied", "timeout", "oom", "disk_full", "model_error", "network_error", "user_code_error", "not_found", "cancelled", "platform_error"];
|
|
4
|
+
export type ErrorClass = (typeof ERROR_CLASSES)[number];
|
|
5
|
+
export declare function isErrorClass(v: unknown): v is ErrorClass;
|
|
6
|
+
/** The platform-wide failure causes an issue is grouped by (issues.ts
|
|
7
|
+
* PLATFORM_CAUSES keys), as a log field. */
|
|
8
|
+
export declare const CAUSES: readonly ["sandbox", "model-auth", "model-cap", "model-busy", "worker"];
|
|
9
|
+
type Kind = "id" | "num" | "word" | "code" | "class" | "cause" | "errorName" | "frame" | "frames" | "bool";
|
|
10
|
+
/** Every field a platform log line may carry, and its shape. Adding one is
|
|
11
|
+
* a decision that its values can never be an account's content. */
|
|
12
|
+
export declare const FIELDS: Record<string, Kind>;
|
|
13
|
+
export type OpsValue = string | number | boolean | null | undefined | readonly string[];
|
|
14
|
+
export type OpsFields = Record<string, OpsValue>;
|
|
15
|
+
export type OpsLevel = "info" | "warn" | "error";
|
|
16
|
+
/**
|
|
17
|
+
* The line as an object: the event, the fields that fit, and how many did
|
|
18
|
+
* not (by count — a refused field's name could itself be the content).
|
|
19
|
+
*/
|
|
20
|
+
export declare function opsLine(level: OpsLevel, event: string, fields?: OpsFields): Record<string, unknown>;
|
|
21
|
+
/** Is this process inside the boundary — a hosted pod? */
|
|
22
|
+
export declare function opsBoundaryInstalled(): boolean;
|
|
23
|
+
/** Say something about the platform: an event and its fields. */
|
|
24
|
+
export declare function opsLog(level: OpsLevel, event: string, fields?: OpsFields): void;
|
|
25
|
+
/** Which class an error belongs to — from its code, its name and its status;
|
|
26
|
+
* a few fixed markers our own code and the cluster write are matched in its
|
|
27
|
+
* message, which never leaves this function. */
|
|
28
|
+
export declare function errorClass(err: unknown): ErrorClass;
|
|
29
|
+
/** `file.ts:12` frames of our code from a stack, first `max` of them. The
|
|
30
|
+
* first line (the message) is never read, and function names are left
|
|
31
|
+
* out: only a base name and a line, which a sentence cannot be. */
|
|
32
|
+
export declare function stackFrames(stack: unknown, max?: number, skip?: number): string[];
|
|
33
|
+
/** The fields of an error a log line may carry. Never throws: a getter on a
|
|
34
|
+
* strange object is not allowed to take the log down with it. */
|
|
35
|
+
export declare function errorFields(err: unknown): OpsFields;
|
|
36
|
+
/** An Error whose message is for a person and whose `reason` — a word —
|
|
37
|
+
* is what a hosted log says instead: `throw withOpsReason(new Error("egress.ts
|
|
38
|
+
* needs FOLDRUN_EGRESS_URL…"), "no_egress_url")`. */
|
|
39
|
+
export declare function withOpsReason<E extends Error>(err: E, reason: string): E;
|
|
40
|
+
/** A failure: its class and where it happened — never its words inside the
|
|
41
|
+
* boundary. A field the caller names (an `errorClass` it knows) wins. */
|
|
42
|
+
export declare function opsError(event: string, err: unknown, fields?: OpsFields, level?: OpsLevel): void;
|
|
43
|
+
export interface BoundaryOptions {
|
|
44
|
+
/** On an uncaught exception or unhandled rejection: log its class and
|
|
45
|
+
* exit 1, as Node would — for processes with no handler of their own
|
|
46
|
+
* (the worker, egress, the assistant; Next.js has its own). */
|
|
47
|
+
exitOnUncaught?: boolean;
|
|
48
|
+
env?: NodeJS.ProcessEnv;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Put this process inside the boundary. Idempotent. Off only where
|
|
52
|
+
* FOLDRUN_LOG_MODE=raw or NODE_ENV=development (`next dev`).
|
|
53
|
+
*/
|
|
54
|
+
export declare function installOpsBoundary(opts?: BoundaryOptions): boolean;
|
|
55
|
+
export {};
|