@foldrun/core 24.10.0 → 24.12.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/runner.ts CHANGED
@@ -22,7 +22,7 @@ import { resolveAgentPath } from "./confine.ts";
22
22
  import { browserPodLine, podLossDecision, RERAN_ON_FULL } from "./browser-pod.ts";
23
23
  import { eventUrl } from "./webhook.ts";
24
24
  import { runStepInContainer, resolveResources, memoryGiB, heldCores, killRunSandboxes, classDisk, type StepTiming } from "./run-container.ts";
25
- import { readResources, hasOverride } from "./resources.ts";
25
+ import { readResources, hasOverride, anyMemoryMi } from "./resources.ts";
26
26
  import { hostSafeEnv, platformApiUrl } from "./host-env.ts";
27
27
  import { resolveModelCredential, credentialLine, accountModelBlock, isClaudeLoginToken, isModelEnvName, DECLARED_ENV_PREFIX } from "./model-credential.ts";
28
28
  import { parseJudge } from "./judge-verdict.ts";
@@ -567,20 +567,41 @@ export function agentRuntimeSpec(tenant: string, workspace: string, agentDir: st
567
567
  return mergeRuntimes(ownRuntime(front, agentDir, tenant), ...tools);
568
568
  }
569
569
 
570
- /** Every distinct runtime a workspace's agents need, with who needs it. */
570
+ /** The node disk one agent's steps may write: its `size:` class's, or its
571
+ * own `resources: disk` over it — the figure the runner gives its pod. */
572
+ export function agentDisk(agentDir: string): string {
573
+ const file = path.join(agentDir, "agent.md");
574
+ let front: Record<string, unknown> = {};
575
+ try {
576
+ // The step's own parser: it lifts `guardrail: { resources: … }` to the
577
+ // top, so both spellings of a disk override count here as they do there.
578
+ if (fs.existsSync(file)) front = configMatter(fs.readFileSync(file, "utf8")).data as Record<string, unknown>;
579
+ } catch {
580
+ /* frontmatter that does not parse: the class default, as `check` reports it */
581
+ }
582
+ const size: "small" | "large" | "heavy" = front.size === "small" ? "small" : front.size === "heavy" ? "heavy" : "large";
583
+ return resolveResources(size, readResources(front.resources).value).disk ?? classDisk(size);
584
+ }
585
+
586
+ /** Every distinct runtime a workspace's agents need, with who needs it and
587
+ * `disk`, the most node disk any of those agents' steps may write (a
588
+ * runtime built for them has at least that much room to be built in). */
571
589
  export function workspaceRuntimePlan(
572
590
  tenant: string,
573
591
  workspace: string,
574
- ): { fingerprint: string; spec: RuntimeSpec; agents: string[] }[] {
575
- const byFp = new Map<string, { fingerprint: string; spec: RuntimeSpec; agents: string[] }>();
592
+ ): { fingerprint: string; spec: RuntimeSpec; agents: string[]; disk: string }[] {
593
+ const byFp = new Map<string, { fingerprint: string; spec: RuntimeSpec; agents: string[]; disk: string }>();
576
594
  const agentsRoot = path.join(workspaceDir(tenant, workspace), "agents");
577
595
  if (!fs.existsSync(agentsRoot)) return [];
578
596
  for (const name of fs.readdirSync(agentsRoot).sort()) {
579
- const spec = agentRuntimeSpec(tenant, workspace, path.join(agentsRoot, name));
597
+ const dir = path.join(agentsRoot, name);
598
+ const spec = agentRuntimeSpec(tenant, workspace, dir);
580
599
  if (!spec) continue;
581
600
  const fp = fingerprint(spec);
582
- const entry = byFp.get(fp) ?? { fingerprint: fp, spec, agents: [] };
601
+ const disk = agentDisk(dir);
602
+ const entry = byFp.get(fp) ?? { fingerprint: fp, spec, agents: [], disk };
583
603
  entry.agents.push(name);
604
+ if (anyMemoryMi(disk) > anyMemoryMi(entry.disk)) entry.disk = disk;
584
605
  byFp.set(fp, entry);
585
606
  }
586
607
  return [...byFp.values()];