@foldrun/core 24.10.0 → 24.11.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.
@@ -137,11 +137,17 @@ export declare function readAgentsMd(dir: string): {
137
137
  * the two can never disagree about what an agent needs.
138
138
  */
139
139
  export declare function agentRuntimeSpec(tenant: string, workspace: string, agentDir: string): RuntimeSpec | null;
140
- /** Every distinct runtime a workspace's agents need, with who needs it. */
140
+ /** The node disk one agent's steps may write: its `size:` class's, or its
141
+ * own `resources: disk` over it — the figure the runner gives its pod. */
142
+ export declare function agentDisk(agentDir: string): string;
143
+ /** Every distinct runtime a workspace's agents need, with who needs it and
144
+ * `disk`, the most node disk any of those agents' steps may write (a
145
+ * runtime built for them has at least that much room to be built in). */
141
146
  export declare function workspaceRuntimePlan(tenant: string, workspace: string): {
142
147
  fingerprint: string;
143
148
  spec: RuntimeSpec;
144
149
  agents: string[];
150
+ disk: string;
145
151
  }[];
146
152
  /**
147
153
  * The calendar a set of frontmatter asks for, with no cascade around it —
@@ -20,7 +20,7 @@ import { resolveAgentPath } from "./confine.js";
20
20
  import { browserPodLine, podLossDecision, RERAN_ON_FULL } from "./browser-pod.js";
21
21
  import { eventUrl } from "./webhook.js";
22
22
  import { runStepInContainer, resolveResources, memoryGiB, heldCores, killRunSandboxes, classDisk } from "./run-container.js";
23
- import { readResources, hasOverride } from "./resources.js";
23
+ import { readResources, hasOverride, anyMemoryMi } from "./resources.js";
24
24
  import { hostSafeEnv, platformApiUrl } from "./host-env.js";
25
25
  import { resolveModelCredential, credentialLine, accountModelBlock, isClaudeLoginToken, isModelEnvName, DECLARED_ENV_PREFIX } from "./model-credential.js";
26
26
  import { parseJudge } from "./judge-verdict.js";
@@ -484,19 +484,42 @@ export function agentRuntimeSpec(tenant, workspace, agentDir) {
484
484
  .map(toolRuntime);
485
485
  return mergeRuntimes(ownRuntime(front, agentDir, tenant), ...tools);
486
486
  }
487
- /** Every distinct runtime a workspace's agents need, with who needs it. */
487
+ /** The node disk one agent's steps may write: its `size:` class's, or its
488
+ * own `resources: disk` over it — the figure the runner gives its pod. */
489
+ export function agentDisk(agentDir) {
490
+ const file = path.join(agentDir, "agent.md");
491
+ let front = {};
492
+ try {
493
+ // The step's own parser: it lifts `guardrail: { resources: … }` to the
494
+ // top, so both spellings of a disk override count here as they do there.
495
+ if (fs.existsSync(file))
496
+ front = configMatter(fs.readFileSync(file, "utf8")).data;
497
+ }
498
+ catch {
499
+ /* frontmatter that does not parse: the class default, as `check` reports it */
500
+ }
501
+ const size = front.size === "small" ? "small" : front.size === "heavy" ? "heavy" : "large";
502
+ return resolveResources(size, readResources(front.resources).value).disk ?? classDisk(size);
503
+ }
504
+ /** Every distinct runtime a workspace's agents need, with who needs it and
505
+ * `disk`, the most node disk any of those agents' steps may write (a
506
+ * runtime built for them has at least that much room to be built in). */
488
507
  export function workspaceRuntimePlan(tenant, workspace) {
489
508
  const byFp = new Map();
490
509
  const agentsRoot = path.join(workspaceDir(tenant, workspace), "agents");
491
510
  if (!fs.existsSync(agentsRoot))
492
511
  return [];
493
512
  for (const name of fs.readdirSync(agentsRoot).sort()) {
494
- const spec = agentRuntimeSpec(tenant, workspace, path.join(agentsRoot, name));
513
+ const dir = path.join(agentsRoot, name);
514
+ const spec = agentRuntimeSpec(tenant, workspace, dir);
495
515
  if (!spec)
496
516
  continue;
497
517
  const fp = fingerprint(spec);
498
- const entry = byFp.get(fp) ?? { fingerprint: fp, spec, agents: [] };
518
+ const disk = agentDisk(dir);
519
+ const entry = byFp.get(fp) ?? { fingerprint: fp, spec, agents: [], disk };
499
520
  entry.agents.push(name);
521
+ if (anyMemoryMi(disk) > anyMemoryMi(entry.disk))
522
+ entry.disk = disk;
500
523
  byFp.set(fp, entry);
501
524
  }
502
525
  return [...byFp.values()];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "24.10.0",
3
+ "version": "24.11.0",
4
4
  "description": "Agents are just folders. The format, the runner, the checks.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
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()];