@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/dist/src/customer.d.ts +7 -0
- package/dist/src/customer.js +26 -0
- package/dist/src/data-import.d.ts +156 -0
- package/dist/src/data-import.js +670 -0
- package/dist/src/records.d.ts +4 -0
- package/package.json +1 -1
- package/src/customer.ts +25 -0
- package/src/data-import.ts +764 -0
- package/src/records.ts +4 -0
package/dist/src/customer.d.ts
CHANGED
|
@@ -14,3 +14,10 @@ export declare function customerKey(tenant: string, customer: string): string;
|
|
|
14
14
|
* Returns the body unchanged when it is not JSON or not one of those.
|
|
15
15
|
*/
|
|
16
16
|
export declare function withProviderUser(body: Buffer, userId: string, shape: "anthropic" | "responses" | "chat"): Buffer;
|
|
17
|
+
/**
|
|
18
|
+
* How many runs of this end customer are open — queued, running or parked
|
|
19
|
+
* at a gate — across every workspace of the account. Read from the run
|
|
20
|
+
* records themselves, so a wiped cache never hands out more room than the
|
|
21
|
+
* customer has. What the platform's open-runs limit counts under its lock.
|
|
22
|
+
*/
|
|
23
|
+
export declare function openRunsOfCustomer(tenant: string, customer: string): number;
|
package/dist/src/customer.js
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
// partners' `user-1` are never one identity there, and the partner's own id
|
|
15
15
|
// never leaves foldrun.
|
|
16
16
|
import crypto from "node:crypto";
|
|
17
|
+
import { listRunSummaries, listWorkspaces } from "./store.js";
|
|
18
|
+
import { records } from "./records.js";
|
|
17
19
|
/** A customer id as a partner writes it: printable, no spaces, 1–128. */
|
|
18
20
|
export const CUSTOMER_ID = /^[A-Za-z0-9._:@-]{1,128}$/;
|
|
19
21
|
/** Null when the id is fine; otherwise why not. */
|
|
@@ -61,3 +63,27 @@ export function withProviderUser(body, userId, shape) {
|
|
|
61
63
|
}
|
|
62
64
|
return Buffer.from(JSON.stringify(parsed), "utf8");
|
|
63
65
|
}
|
|
66
|
+
const OPEN = new Set(["queued", "running", "awaiting-approval"]);
|
|
67
|
+
/**
|
|
68
|
+
* How many runs of this end customer are open — queued, running or parked
|
|
69
|
+
* at a gate — across every workspace of the account. Read from the run
|
|
70
|
+
* records themselves, so a wiped cache never hands out more room than the
|
|
71
|
+
* customer has. What the platform's open-runs limit counts under its lock.
|
|
72
|
+
*/
|
|
73
|
+
export function openRunsOfCustomer(tenant, customer) {
|
|
74
|
+
const workspaces = listWorkspaces(tenant).map((w) => w.name);
|
|
75
|
+
const port = records();
|
|
76
|
+
// The database's count covers every workspace whose records live there;
|
|
77
|
+
// a workspace still on files (its import pending — records() answers
|
|
78
|
+
// null for it) is counted from its own summaries and added (Codex review).
|
|
79
|
+
const counted = port?.openRunsOfCustomer ? port.openRunsOfCustomer(tenant, customer) : null;
|
|
80
|
+
let n = counted ?? 0;
|
|
81
|
+
for (const ws of workspaces) {
|
|
82
|
+
if (counted !== null && records(tenant, ws))
|
|
83
|
+
continue;
|
|
84
|
+
for (const s of listRunSummaries(tenant, ws))
|
|
85
|
+
if (s.customer === customer && OPEN.has(s.status))
|
|
86
|
+
n++;
|
|
87
|
+
}
|
|
88
|
+
return n;
|
|
89
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { type Deps } from "./publish.ts";
|
|
2
|
+
export declare const IMPORT_BY = "import:data-folder";
|
|
3
|
+
/** Files at or under this are read whole for the publish; a larger one is
|
|
4
|
+
* streamed from disk. */
|
|
5
|
+
export declare const LARGE_FILE_BYTES: number;
|
|
6
|
+
export interface SourceFile {
|
|
7
|
+
/** The manifest path (a conflict copy's path differs from `from`). */
|
|
8
|
+
path: string;
|
|
9
|
+
abs: string;
|
|
10
|
+
sha: string;
|
|
11
|
+
size: number;
|
|
12
|
+
mode: number;
|
|
13
|
+
side: "authored" | "state";
|
|
14
|
+
/** Set when this file is kept under a conflict-copy name; the path it wanted. */
|
|
15
|
+
from?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface Unmapped {
|
|
18
|
+
path: string;
|
|
19
|
+
reason: string;
|
|
20
|
+
/** Files inside (a folder), when counted. */
|
|
21
|
+
files?: number;
|
|
22
|
+
bytes?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface WorkspaceScan {
|
|
25
|
+
tenant: string;
|
|
26
|
+
workspace: string;
|
|
27
|
+
dir: string;
|
|
28
|
+
files: SourceFile[];
|
|
29
|
+
bytes: number;
|
|
30
|
+
unmapped: Unmapped[];
|
|
31
|
+
conflicts: {
|
|
32
|
+
path: string;
|
|
33
|
+
keptAs: string;
|
|
34
|
+
}[];
|
|
35
|
+
/** What runs/ holds on the volume, counted and never read: record files
|
|
36
|
+
* (FOL-152 moved those to rows) and output folders (runs/<id>/). */
|
|
37
|
+
runs: {
|
|
38
|
+
recordFiles: number;
|
|
39
|
+
outputFolders: number;
|
|
40
|
+
outputFiles: number;
|
|
41
|
+
outputBytes: number;
|
|
42
|
+
};
|
|
43
|
+
/** Set when the workspace cannot be imported at all (reason). */
|
|
44
|
+
error?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface TenantScan {
|
|
47
|
+
tenant: string;
|
|
48
|
+
workspaces: WorkspaceScan[];
|
|
49
|
+
/** Account-level folders and files nothing maps here (library/, .history/, storage/, secrets …). */
|
|
50
|
+
unmapped: Unmapped[];
|
|
51
|
+
}
|
|
52
|
+
export interface SourceScan {
|
|
53
|
+
source: string;
|
|
54
|
+
tenants: TenantScan[];
|
|
55
|
+
scannedAt: string;
|
|
56
|
+
}
|
|
57
|
+
export interface ScanOptions {
|
|
58
|
+
source: string;
|
|
59
|
+
/** Only these accounts / "account/workspace" pairs. */
|
|
60
|
+
tenants?: string[];
|
|
61
|
+
workspaces?: string[];
|
|
62
|
+
}
|
|
63
|
+
export declare function hashFile(abs: string): Promise<string>;
|
|
64
|
+
/**
|
|
65
|
+
* Two names that differ only by case cannot share a manifest. The first in
|
|
66
|
+
* byte order keeps its name; each later one is kept as a conflict copy beside
|
|
67
|
+
* it (deterministic, so a rerun names the same file). `rels` must be sorted.
|
|
68
|
+
* Pure, because a case-insensitive disk (a Mac) cannot hold the pair to test
|
|
69
|
+
* the scanner with.
|
|
70
|
+
*/
|
|
71
|
+
export declare function placeCaseVariants(rels: string[], seed: string): {
|
|
72
|
+
rel: string;
|
|
73
|
+
from?: string;
|
|
74
|
+
}[];
|
|
75
|
+
export declare function scanSource(opts: ScanOptions): Promise<SourceScan>;
|
|
76
|
+
export interface ImportOptions {
|
|
77
|
+
deps: Deps;
|
|
78
|
+
/** Delete head paths the folder does not have. Default off: an import never
|
|
79
|
+
* removes anything from the destination. */
|
|
80
|
+
mirror?: boolean;
|
|
81
|
+
/** Import a workspace whose history has revisions the importer did not make. */
|
|
82
|
+
force?: boolean;
|
|
83
|
+
by?: string;
|
|
84
|
+
}
|
|
85
|
+
export type WorkspaceStatus = "imported" | "unchanged" | "skipped" | "failed" | "empty";
|
|
86
|
+
export interface WorkspaceResult {
|
|
87
|
+
tenant: string;
|
|
88
|
+
workspace: string;
|
|
89
|
+
status: WorkspaceStatus;
|
|
90
|
+
reason?: string;
|
|
91
|
+
revisions: string[];
|
|
92
|
+
conflictsKept: number;
|
|
93
|
+
filesPublished: number;
|
|
94
|
+
/** Files streamed from disk (over LARGE_FILE_BYTES) rather than read whole. */
|
|
95
|
+
filesStreamed: number;
|
|
96
|
+
}
|
|
97
|
+
export interface ImportReport {
|
|
98
|
+
startedAt: string;
|
|
99
|
+
finishedAt: string;
|
|
100
|
+
results: WorkspaceResult[];
|
|
101
|
+
}
|
|
102
|
+
export declare function importWorkspace(scan: WorkspaceScan, opts: ImportOptions): Promise<WorkspaceResult>;
|
|
103
|
+
export declare function runImport(scan: SourceScan, opts: ImportOptions): Promise<ImportReport>;
|
|
104
|
+
export interface PlanWorkspace {
|
|
105
|
+
tenant: string;
|
|
106
|
+
workspace: string;
|
|
107
|
+
files: number;
|
|
108
|
+
bytes: number;
|
|
109
|
+
authoredFiles: number;
|
|
110
|
+
stateFiles: number;
|
|
111
|
+
revisionsToMake: number | "unknown";
|
|
112
|
+
alreadyThere: "yes" | "partly" | "no" | "unknown";
|
|
113
|
+
note?: string;
|
|
114
|
+
}
|
|
115
|
+
/** What an import would do, per workspace. Reads the destination's heads when
|
|
116
|
+
* given a Deps (never writes); without one, "unknown". */
|
|
117
|
+
export declare function planImport(scan: SourceScan, deps?: Deps): Promise<PlanWorkspace[]>;
|
|
118
|
+
export declare function renderPlan(scan: SourceScan, plan: PlanWorkspace[]): string;
|
|
119
|
+
export interface VerifyWorkspace {
|
|
120
|
+
tenant: string;
|
|
121
|
+
workspace: string;
|
|
122
|
+
pass: boolean;
|
|
123
|
+
expected: number;
|
|
124
|
+
inHead: number;
|
|
125
|
+
matched: number;
|
|
126
|
+
missing: string[];
|
|
127
|
+
mismatched: string[];
|
|
128
|
+
extra: string[];
|
|
129
|
+
/** Absent from the store, the wrong size, or (deep) bytes that do not hash to their name. */
|
|
130
|
+
badBlobs: string[];
|
|
131
|
+
notes: string[];
|
|
132
|
+
}
|
|
133
|
+
export interface VerifyReport {
|
|
134
|
+
verifiedAt: string;
|
|
135
|
+
source: string;
|
|
136
|
+
pass: boolean;
|
|
137
|
+
workspaces: VerifyWorkspace[];
|
|
138
|
+
}
|
|
139
|
+
export interface VerifyOptions {
|
|
140
|
+
deps: Deps;
|
|
141
|
+
/** Stream every blob back and hash it (default: confirm each exists with the right size). */
|
|
142
|
+
deep?: boolean;
|
|
143
|
+
/** Paths in the head that the folder does not have are fine. */
|
|
144
|
+
allowExtra?: boolean;
|
|
145
|
+
}
|
|
146
|
+
/** Compare every workspace's heads with the folder, by path, sha256 and mode —
|
|
147
|
+
* the folder's hashes are taken again now, not trusted from the scan. */
|
|
148
|
+
export declare function verifyImport(scan: SourceScan, opts: VerifyOptions): Promise<VerifyReport>;
|
|
149
|
+
export declare function renderVerify(r: VerifyReport): string;
|
|
150
|
+
/** Write import-verify.json and import-verify.txt. Refuses a folder inside the
|
|
151
|
+
* source, compared by real paths, so a link cannot point the report into it
|
|
152
|
+
* (Codex review). */
|
|
153
|
+
export declare function writeVerifyReport(dir: string, source: string, r: VerifyReport): {
|
|
154
|
+
json: string;
|
|
155
|
+
txt: string;
|
|
156
|
+
};
|