@foldrun/core 19.0.0 → 19.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "19.0.0",
3
+ "version": "19.2.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/customer.ts CHANGED
@@ -15,6 +15,8 @@
15
15
  // never leaves foldrun.
16
16
 
17
17
  import crypto from "node:crypto";
18
+ import { listRunSummaries, listWorkspaces } from "./store.ts";
19
+ import { records } from "./records.ts";
18
20
 
19
21
  /** A customer id as a partner writes it: printable, no spaces, 1–128. */
20
22
  export const CUSTOMER_ID = /^[A-Za-z0-9._:@-]{1,128}$/;
@@ -61,3 +63,26 @@ export function withProviderUser(body: Buffer, userId: string, shape: "anthropic
61
63
  }
62
64
  return Buffer.from(JSON.stringify(parsed), "utf8");
63
65
  }
66
+
67
+ const OPEN = new Set(["queued", "running", "awaiting-approval"]);
68
+
69
+ /**
70
+ * How many runs of this end customer are open — queued, running or parked
71
+ * at a gate — across every workspace of the account. Read from the run
72
+ * records themselves, so a wiped cache never hands out more room than the
73
+ * customer has. What the platform's open-runs limit counts under its lock.
74
+ */
75
+ export function openRunsOfCustomer(tenant: string, customer: string): number {
76
+ const workspaces = listWorkspaces(tenant).map((w) => w.name);
77
+ const port = records();
78
+ // The database's count covers every workspace whose records live there;
79
+ // a workspace still on files (its import pending — records() answers
80
+ // null for it) is counted from its own summaries and added (Codex review).
81
+ const counted = port?.openRunsOfCustomer ? port.openRunsOfCustomer(tenant, customer) : null;
82
+ let n = counted ?? 0;
83
+ for (const ws of workspaces) {
84
+ if (counted !== null && records(tenant, ws)) continue;
85
+ for (const s of listRunSummaries(tenant, ws)) if (s.customer === customer && OPEN.has(s.status)) n++;
86
+ }
87
+ return n;
88
+ }