@foldrun/core 17.2.0 → 17.4.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/approvals.js +3 -3
- package/dist/src/blob-cache.d.ts +58 -0
- package/dist/src/blob-cache.js +309 -0
- package/dist/src/blob-pins.d.ts +44 -0
- package/dist/src/blob-pins.js +61 -0
- package/dist/src/blob-store.d.ts +47 -0
- package/dist/src/blob-store.js +357 -0
- package/dist/src/blob-sweeper.d.ts +70 -0
- package/dist/src/blob-sweeper.js +254 -0
- package/dist/src/blob-types.d.ts +145 -0
- package/dist/src/blob-types.js +115 -0
- package/dist/src/browse-egress.d.ts +31 -0
- package/dist/src/browse-egress.js +43 -0
- package/dist/src/egress.d.ts +9 -0
- package/dist/src/evals.js +1 -1
- package/dist/src/history.d.ts +86 -9
- package/dist/src/history.js +132 -16
- package/dist/src/journal-store.d.ts +58 -0
- package/dist/src/journal-store.js +117 -0
- package/dist/src/manifest.d.ts +92 -0
- package/dist/src/manifest.js +239 -0
- package/dist/src/ops-log.js +26 -3
- package/dist/src/platform.d.ts +7 -0
- package/dist/src/platform.js +1 -0
- package/dist/src/publish.d.ts +134 -0
- package/dist/src/publish.js +434 -0
- package/dist/src/records.d.ts +72 -0
- package/dist/src/records.js +24 -0
- package/dist/src/revision-store.d.ts +161 -0
- package/dist/src/revision-store.js +378 -0
- package/dist/src/run-container.d.ts +20 -0
- package/dist/src/run-container.js +61 -0
- package/dist/src/runner.js +22 -4
- package/dist/src/s3-blob-store.d.ts +29 -0
- package/dist/src/s3-blob-store.js +458 -0
- package/dist/src/state-retention.d.ts +15 -0
- package/dist/src/state-retention.js +65 -0
- package/dist/src/storage.d.ts +29 -1
- package/dist/src/storage.js +331 -81
- package/dist/src/store.d.ts +41 -0
- package/dist/src/store.js +188 -5
- package/dist/src/trigger-log.js +17 -0
- package/dist/src/workspace-revisions.d.ts +259 -0
- package/dist/src/workspace-revisions.js +1274 -0
- package/package.json +1 -1
- package/src/approvals.ts +3 -3
- package/src/blob-cache.ts +354 -0
- package/src/blob-pins.ts +99 -0
- package/src/blob-store.ts +385 -0
- package/src/blob-sweeper.ts +308 -0
- package/src/blob-types.ts +216 -0
- package/src/browse-egress.ts +49 -1
- package/src/egress.ts +6 -0
- package/src/evals.ts +1 -1
- package/src/history.ts +182 -16
- package/src/journal-store.ts +152 -0
- package/src/manifest.ts +274 -0
- package/src/ops-log.ts +25 -3
- package/src/platform.ts +8 -0
- package/src/publish.ts +520 -0
- package/src/records.ts +105 -0
- package/src/revision-store.ts +513 -0
- package/src/run-container.ts +62 -0
- package/src/runner.ts +21 -4
- package/src/s3-blob-store.ts +489 -0
- package/src/state-retention.ts +83 -0
- package/src/storage.ts +335 -81
- package/src/store.ts +178 -5
- package/src/trigger-log.ts +15 -0
- package/src/workspace-revisions.ts +1324 -0
|
@@ -26,6 +26,7 @@ import crypto from "node:crypto";
|
|
|
26
26
|
import { spawn, spawnSync } from "node:child_process";
|
|
27
27
|
import { CAPTURE_CAP, isPlatformPath } from "./store.js";
|
|
28
28
|
import { divertedSummary, isDivertedPath, overlayTestWrites } from "./test-mode.js";
|
|
29
|
+
import { recordStepOutputs, pinRunBase } from "./workspace-revisions.js";
|
|
29
30
|
import { refusedBack, refusedLine, keptLine } from "./copy-back.js";
|
|
30
31
|
import { isFileValue, fileContent, installKeyMaterial } from "./secrets.js";
|
|
31
32
|
import { safeTenantSegment, systemInstallSh, SYSTEM_FROM_INPUT_SH, INSTALL_SOCKET, ROOT_ENV_RESET_SH, ROOT_SHELL_GUARD_SH, ROOT_ENV_FILE, STEP_ENV_FILE, stepEnvShell, rootEnvShell, SNAPSHOT_KEY_FILE } from "./runtime.js";
|
|
@@ -201,6 +202,39 @@ export function dropHandedIn(workspaceRoot, runId, ref) {
|
|
|
201
202
|
const file = handedInPath(workspaceRoot, runId, ref);
|
|
202
203
|
if (file)
|
|
203
204
|
fs.rmSync(file, { force: true });
|
|
205
|
+
const base = baseRevisionPath(workspaceRoot, runId, ref);
|
|
206
|
+
if (base)
|
|
207
|
+
fs.rmSync(base, { force: true });
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* The revisions a step's stage-in started from (FOL-126 fixes), kept on the host
|
|
211
|
+
* beside what it was handed, for the same reason: a driver that inherits the
|
|
212
|
+
* step publishes its copy-back against the SAME base, not against whatever the
|
|
213
|
+
* heads hold by then. Platform-owned, never staged, erased with the run.
|
|
214
|
+
*/
|
|
215
|
+
export function baseRevisionPath(workspaceRoot, runId, ref) {
|
|
216
|
+
const file = handedInPath(workspaceRoot, runId, ref);
|
|
217
|
+
return file ? file.replace(/\.json$/, ".base.json") : null;
|
|
218
|
+
}
|
|
219
|
+
export function writeBaseRevision(workspaceRoot, runId, ref, base) {
|
|
220
|
+
const file = baseRevisionPath(workspaceRoot, runId, ref);
|
|
221
|
+
if (!file)
|
|
222
|
+
return;
|
|
223
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
224
|
+
fs.writeFileSync(file, JSON.stringify(base));
|
|
225
|
+
}
|
|
226
|
+
export function readBaseRevision(workspaceRoot, runId, ref) {
|
|
227
|
+
const file = baseRevisionPath(workspaceRoot, runId, ref);
|
|
228
|
+
if (!file)
|
|
229
|
+
return undefined;
|
|
230
|
+
try {
|
|
231
|
+
const m = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
232
|
+
const ok = (v) => v === null || typeof v === "string";
|
|
233
|
+
return m && ok(m.workspace) && ok(m.state) ? { workspace: m.workspace ?? null, state: m.state ?? null } : undefined;
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
204
238
|
}
|
|
205
239
|
/**
|
|
206
240
|
* Every file's mtime under `dir`, relative path to milliseconds — so a copy
|
|
@@ -286,6 +320,7 @@ export function mergeAppends(was, host, next) {
|
|
|
286
320
|
}
|
|
287
321
|
export function applyContainerChanges(hostWs, containerWs, baseline, note, divert, opts = {}) {
|
|
288
322
|
const applied = [];
|
|
323
|
+
const written = [];
|
|
289
324
|
// Files a sandbox: own job's reply copied into this sandbox mid-step
|
|
290
325
|
// (delegate-tools.ts copyBackFiles), path → sha256 of what was written: for
|
|
291
326
|
// those, that is what the step started from. The job's change is already on
|
|
@@ -377,10 +412,16 @@ export function applyContainerChanges(hostWs, containerWs, baseline, note, diver
|
|
|
377
412
|
// other run's ledger rows on 2026-09-14. Merge appends; keep both
|
|
378
413
|
// sides of anything else.
|
|
379
414
|
const hostMoved = was !== undefined && hostNow !== null && !same(hostNow);
|
|
415
|
+
// What the step was handed, as a sha (null: no such file; undefined: not
|
|
416
|
+
// known). It is the base the head is held to — unless the folder was
|
|
417
|
+
// merged, which already folded the other writer's change in.
|
|
418
|
+
const handed = was === undefined ? undefined : was === null ? null : typeof was === "string" ? was : sha(was);
|
|
419
|
+
let foldedIn = false;
|
|
380
420
|
if (hostMoved) {
|
|
381
421
|
const merged = mergeAppends(was ?? null, hostNow, next);
|
|
382
422
|
if (merged) {
|
|
383
423
|
next = merged;
|
|
424
|
+
foldedIn = true;
|
|
384
425
|
}
|
|
385
426
|
else {
|
|
386
427
|
const ext = path.extname(rel);
|
|
@@ -390,6 +431,7 @@ export function applyContainerChanges(hostWs, containerWs, baseline, note, diver
|
|
|
390
431
|
fs.mkdirSync(path.dirname(conflictAbs), { recursive: true });
|
|
391
432
|
fs.writeFileSync(conflictAbs, next);
|
|
392
433
|
applied.push(conflictRel);
|
|
434
|
+
written.push({ path: conflictRel.replaceAll("\\", "/"), base: null, after: next });
|
|
393
435
|
note?.(`write-back conflict on ${rel.replaceAll("\\", "/")}: it changed on the workspace while this step ran, ` +
|
|
394
436
|
`and not only by appending — kept the workspace's version; this step's version is ${conflictRel.replaceAll("\\", "/")}`);
|
|
395
437
|
continue;
|
|
@@ -410,9 +452,22 @@ export function applyContainerChanges(hostWs, containerWs, baseline, note, diver
|
|
|
410
452
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
411
453
|
fs.writeFileSync(target, next);
|
|
412
454
|
applied.push(rel);
|
|
455
|
+
// The pinned base is what the folder held before this write (null: a new
|
|
456
|
+
// file) — for an untouched path that is what the step was handed.
|
|
457
|
+
written.push({ path: rel.replaceAll("\\", "/"), base: hostNow ? sha(hostNow) : null, after: next, handed: foldedIn ? undefined : handed });
|
|
413
458
|
}
|
|
414
459
|
};
|
|
415
460
|
walk(containerWs);
|
|
461
|
+
// The step's outputs as one revision (all its paths, or none). Never allowed
|
|
462
|
+
// to fail the copy-back: the folder is written already.
|
|
463
|
+
if (opts.revision && written.length) {
|
|
464
|
+
try {
|
|
465
|
+
recordStepOutputs(opts.revision.tenant, path.basename(hostWs), written, { runId: opts.revision.runId, step: opts.revision.step, base: opts.revision.base });
|
|
466
|
+
}
|
|
467
|
+
catch (err) {
|
|
468
|
+
note?.(`the step's files were written to the workspace but not recorded as a revision yet: ${err instanceof Error ? err.message : String(err)}`);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
416
471
|
return applied;
|
|
417
472
|
}
|
|
418
473
|
// ---------- the dependency cache ----------
|
|
@@ -1751,7 +1806,11 @@ export async function runStepInContainer(args) {
|
|
|
1751
1806
|
args.emit("info", line);
|
|
1752
1807
|
const staging = fs.mkdtempSync(path.join(os.tmpdir(), "foldrun-run-"));
|
|
1753
1808
|
let containerId = "";
|
|
1809
|
+
// The revisions this step starts from (FOL-126 fixes): taken before the
|
|
1810
|
+
// folder is copied, held until the copy-back is done.
|
|
1811
|
+
let pinned = null;
|
|
1754
1812
|
try {
|
|
1813
|
+
pinned = args.tenant ? await pinRunBase(args.tenant, path.basename(args.workspaceRoot), `${args.runId ?? "step"}:${crypto.randomBytes(4).toString("hex")}`) : null;
|
|
1755
1814
|
// Stage the workspace copy minus what the platform owns — the vault,
|
|
1756
1815
|
// hook state, run history. The container gets the trust boundary, not
|
|
1757
1816
|
// the bookkeeping. One definition of "platform-owned" for this filter,
|
|
@@ -1940,6 +1999,7 @@ export async function runStepInContainer(args) {
|
|
|
1940
1999
|
onRefused: (r) => refused.push(r),
|
|
1941
2000
|
allowConfig: args.configWrites === true,
|
|
1942
2001
|
onKept: (r) => kept.push(r),
|
|
2002
|
+
revision: args.tenant ? { tenant: args.tenant, runId: args.runId, step: containerId, base: pinned?.base ?? null } : undefined,
|
|
1943
2003
|
});
|
|
1944
2004
|
if (refused.length)
|
|
1945
2005
|
args.emit("info", refusedLine(refused));
|
|
@@ -1965,5 +2025,6 @@ export async function runStepInContainer(args) {
|
|
|
1965
2025
|
if (containerId)
|
|
1966
2026
|
spawnSync(cli(), ["rm", "-f", containerId], { stdio: "ignore" });
|
|
1967
2027
|
fs.rmSync(staging, { recursive: true, force: true });
|
|
2028
|
+
await pinned?.release();
|
|
1968
2029
|
}
|
|
1969
2030
|
}
|
package/dist/src/runner.js
CHANGED
|
@@ -49,7 +49,7 @@ import { PromptLayers, promptCacheKey } from "./prompt-layers.js";
|
|
|
49
49
|
import { loadCatalog, checkModel, clampEffort, catalogCost, findModel, tokenPriceOf } from "./catalog.js";
|
|
50
50
|
import { resolveSecrets, getSecret, materializeSecrets, secretSites, isClientCertValue, clientCertOf, withoutHeldCerts, isIdentityValue, identityOf } from "./secrets.js";
|
|
51
51
|
import { resolveNetwork, networkLine, networkEnforceWanted, proxyEnv, siteCovers, EGRESS_CA_ENV } from "./network.js";
|
|
52
|
-
import { BROWSER_CONFINED_ENV, browseNetworkLine, browseVerdict } from "./browse-egress.js";
|
|
52
|
+
import { BROWSER_CONFINED_ENV, VENDOR_DOOR_ENV, VENDOR_DOOR_HOSTS, browseNetworkLine, browseVerdict, vendorDoorFor } from "./browse-egress.js";
|
|
53
53
|
import { SEARCH_DOOR_ENV, searchDoorWanted, searchProvided } from "./search-egress.js";
|
|
54
54
|
import { materializeFileSecrets, cleanupFileSecrets } from "./secret-files.js";
|
|
55
55
|
import { buildApiTools, secretsUsedByApi } from "./api-tools.js";
|
|
@@ -2773,6 +2773,20 @@ mayDefer) {
|
|
|
2773
2773
|
// Secrets bound to sites in the vault: filled by the proxy for those
|
|
2774
2774
|
// sites alone, never put in the sandbox (egress.ts).
|
|
2775
2775
|
const boundSites = secretSites(tenant, Object.keys(liveSecrets), workspaceName);
|
|
2776
|
+
// FOL-145: a vendor browser the install holds through its vendor door —
|
|
2777
|
+
// the vendor's key bound to the vendor's hosts (so it is a name in the
|
|
2778
|
+
// sandbox and the proxy fills it, under the vendor's session rules),
|
|
2779
|
+
// and the door on the grant. Only where the install lists the vendor.
|
|
2780
|
+
// Only for a step that may browse: a step whose web block only fetches
|
|
2781
|
+
// or searches keeps its vendor calls as they were (Codex review).
|
|
2782
|
+
const mayBrowse = scriptSpecs.some((sc) => sc.name === "web") && (!web.actions || web.actions.includes("browse"));
|
|
2783
|
+
const vendorDoor = mayBrowse ? vendorDoorFor(clockEnv.FOLDRUN_BROWSER_VENDOR) : null;
|
|
2784
|
+
if (vendorDoor) {
|
|
2785
|
+
const key = clockEnv.FOLDRUN_BROWSER_SECRET;
|
|
2786
|
+
if (key && key in liveSecrets)
|
|
2787
|
+
boundSites[key] = [...new Set([...(boundSites[key] ?? []), ...VENDOR_DOOR_HOSTS[vendorDoor.vendor]])];
|
|
2788
|
+
grant.vendorDoor = vendorDoor;
|
|
2789
|
+
}
|
|
2776
2790
|
const network = resolveNetwork({
|
|
2777
2791
|
account: readAgentsMd(accountDir(tenant))?.data?.network,
|
|
2778
2792
|
workspace: readAgentsMd(workspaceRootOf(agentDir))?.data?.network,
|
|
@@ -2840,6 +2854,7 @@ mayDefer) {
|
|
|
2840
2854
|
enforce: lease.enforce === true,
|
|
2841
2855
|
vendor: clockEnv.FOLDRUN_BROWSER_VENDOR,
|
|
2842
2856
|
confines: !!isolation && platform.confinesBrowsing?.(isolation) === true,
|
|
2857
|
+
door: !!grant.vendorDoor,
|
|
2843
2858
|
})
|
|
2844
2859
|
: null;
|
|
2845
2860
|
if (lease && browse?.kind === "refuse") {
|
|
@@ -2882,10 +2897,10 @@ mayDefer) {
|
|
|
2882
2897
|
// credential as launch options instead (FOLDRUN_BROWSER_CONFINED).
|
|
2883
2898
|
// Every other browsing step is open by default, and its bound secrets
|
|
2884
2899
|
// materialise as they did before the door.
|
|
2885
|
-
const forward = lease?.proxy && (!browses || browse?.kind === "hosted") ? lease : null;
|
|
2900
|
+
const forward = lease?.proxy && (!browses || browse?.kind === "hosted" || browse?.kind === "vendor") ? lease : null;
|
|
2886
2901
|
// A browsing step on an install with the door says whether it is held
|
|
2887
2902
|
// to its list, and which tier its browser falls in (browse-egress.ts).
|
|
2888
|
-
push("info", browse ? browseNetworkLine(network, clockEnv.FOLDRUN_BROWSER_VENDOR, { hosted: browse.kind === "hosted" }) : networkLine(network, forward ? forward.enforce === true : null));
|
|
2903
|
+
push("info", browse ? browseNetworkLine(network, clockEnv.FOLDRUN_BROWSER_VENDOR, { hosted: browse.kind === "hosted", vendorDoor: browse.kind === "vendor" }) : networkLine(network, forward ? forward.enforce === true : null));
|
|
2889
2904
|
// Web search under a held list (FOL-128, search-egress.ts): the
|
|
2890
2905
|
// account's engine through the proxy's search door, for the actions
|
|
2891
2906
|
// our engine answers — decided here, from this step's own config and
|
|
@@ -3137,6 +3152,9 @@ mayDefer) {
|
|
|
3137
3152
|
// cannot go through it, and the platform starts no account
|
|
3138
3153
|
// browser pod for it (browse-egress.ts, FOL-110 phase 3).
|
|
3139
3154
|
...(browse?.kind === "hosted" ? { [BROWSER_CONFINED_ENV]: "1" } : {}),
|
|
3155
|
+
// FOL-145: its vendor's calls and remote-control socket go through
|
|
3156
|
+
// the egress proxy's /e/ door, under the vendor's session rules.
|
|
3157
|
+
...(browse?.kind === "vendor" ? { [VENDOR_DOOR_ENV]: "1" } : {}),
|
|
3140
3158
|
// The search door's address, for the driver: a step it walls
|
|
3141
3159
|
// searches there, with the tool told it is held (search-egress.ts).
|
|
3142
3160
|
...(grant.search && lease?.search ? { [SEARCH_DOOR_ENV]: lease.search } : {}),
|
|
@@ -4586,7 +4604,7 @@ function driveRunInner(tenant, workspace, run, modelOverride, tags, opts) {
|
|
|
4586
4604
|
// /source makes one too. A re-run comes through here as well.
|
|
4587
4605
|
run.drivenAt ??= new Date().toISOString();
|
|
4588
4606
|
if (run.revision === undefined)
|
|
4589
|
-
run.revision = latestRevisionId(tenant, workspace);
|
|
4607
|
+
run.revision = await latestRevisionId(tenant, workspace);
|
|
4590
4608
|
if (run.status !== "running") {
|
|
4591
4609
|
run.status = "running";
|
|
4592
4610
|
run.parkedAt = null;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type S3Config } from "./storage.ts";
|
|
2
|
+
import { bufferSource, type BlobStore, type BlobSweeper } from "./blob-types.ts";
|
|
3
|
+
/** S3's floor for every part but the last. R2 and MinIO enforce the same. */
|
|
4
|
+
export declare const MIN_PART_BYTES: number;
|
|
5
|
+
/** S3's ceiling on the number of parts. */
|
|
6
|
+
export declare const MAX_PARTS = 10000;
|
|
7
|
+
export interface S3BlobOptions {
|
|
8
|
+
/** Objects at or above this many bytes go up as multipart. */
|
|
9
|
+
multipartThresholdBytes: number;
|
|
10
|
+
/** Size of every part but the last. Raised if the object would need more
|
|
11
|
+
* than MAX_PARTS; never below MIN_PART_BYTES. */
|
|
12
|
+
partBytes: number;
|
|
13
|
+
/** Parts in flight at once for ONE upload. */
|
|
14
|
+
partConcurrency: number;
|
|
15
|
+
/** Per-part (and per single request) deadline floor and the throughput the
|
|
16
|
+
* deadline assumes on top of it. */
|
|
17
|
+
requestDeadlineMs: number;
|
|
18
|
+
minBytesPerSec: number;
|
|
19
|
+
}
|
|
20
|
+
export declare const DEFAULT_S3_OPTIONS: S3BlobOptions;
|
|
21
|
+
export declare function s3OptionsFromEnv(env?: NodeJS.ProcessEnv): S3BlobOptions;
|
|
22
|
+
/** The part size for an object: the configured one, raised until the object
|
|
23
|
+
* fits in MAX_PARTS parts. Every part but the last is exactly this size —
|
|
24
|
+
* R2 requires uniform parts, S3 and MinIO do not mind. */
|
|
25
|
+
export declare function planPartBytes(size: number, configured: number): number;
|
|
26
|
+
export declare function s3BlobStore(cfg: S3Config, given?: Partial<S3BlobOptions>): BlobStore & BlobSweeper & {
|
|
27
|
+
checkBucket(signal?: AbortSignal): Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
export { bufferSource };
|