@fungi.computer/computer 0.10.0 → 0.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/README.md +8 -5
- package/container/resource-bounds.mjs +26 -2
- package/dist/computer-backends.d.ts +14 -0
- package/dist/computer-backends.js +8 -0
- package/dist/container-policy.js +1 -1
- package/dist/files.d.ts +2 -0
- package/dist/files.js +12 -0
- package/dist/fleet/computers.d.ts +3 -1
- package/dist/fleet/inventory-wire.d.ts +8 -0
- package/dist/fleet/inventory-wire.js +3 -0
- package/dist/fleet/inventory.d.ts +1 -0
- package/dist/fleet/inventory.js +9 -3
- package/dist/fleet/lifecycle.d.ts +11 -0
- package/dist/fleet/lifecycle.js +22 -1
- package/dist/fleet/runtime-usage.d.ts +4 -2
- package/dist/fleet/runtime-usage.js +12 -9
- package/dist/fleet/slots.d.ts +1 -1
- package/dist/fleet/slots.js +3 -3
- package/dist/fleet/wire.d.ts +13 -0
- package/dist/fleet/wire.js +3 -1
- package/dist/host-config.d.ts +16 -0
- package/dist/host-config.js +16 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.js +49 -8
- package/dist/metered-container-host.d.ts +2 -2
- package/dist/metered-container-host.js +4 -1
- package/dist/on-box-vm.d.ts +11 -1
- package/dist/on-box-vm.js +12 -1
- package/dist/process-inventory.d.ts +18 -0
- package/dist/process-inventory.js +19 -0
- package/dist/team-candidate-builder.mjs +25 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -129,11 +129,14 @@ backend termination are different events. A reachable backend can preserve a
|
|
|
129
129
|
process across Worker reconstruction; a sleeping or stopped backend does not
|
|
130
130
|
keep that process alive.
|
|
131
131
|
|
|
132
|
-
Ordinary command execution is bounded to
|
|
133
|
-
process operations
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
Ordinary command execution is bounded to ten minutes. Long-running work uses
|
|
133
|
+
process operations: `start_process` detaches a command with no run-time limit
|
|
134
|
+
(it lives within the Computer's awake window), `process_logs` reads its retained
|
|
135
|
+
output tail, `wait_process` waits up to a bound for its exit, and `kill_process`
|
|
136
|
+
stops it. Port exposure is explicit and bounded. Ports 8080 and 7681 belong to
|
|
137
|
+
Computer control/terminal daemons and cannot be application previews. The Hub
|
|
138
|
+
owns preview admission and URLs; this runtime does not expose arbitrary Computer
|
|
139
|
+
control endpoints to the browser.
|
|
137
140
|
|
|
138
141
|
[Container policy](src/container-policy.ts) configures idle sleep and respects
|
|
139
142
|
`HOSTED_COMPUTERS`. Invalid pause settings fail closed. Network access follows
|
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* What each Computer size gives an on-box VM. The names match
|
|
3
|
+
* `computerSizeSchema` in `src/computer-backends.ts`, which a test pins.
|
|
4
|
+
*/
|
|
5
|
+
export const computerSizes = Object.freeze({
|
|
6
|
+
small: Object.freeze({ vcpus: 2, memoryMib: 4_096 }),
|
|
7
|
+
default: Object.freeze({ vcpus: 4, memoryMib: 8_192 }),
|
|
8
|
+
large: Object.freeze({ vcpus: 8, memoryMib: 16_384 }),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
/** A Cloudflare `standard-4` instance: the platform container's one size. */
|
|
12
|
+
export const platformContainerResources = Object.freeze({
|
|
3
13
|
vcpus: 4,
|
|
4
14
|
memoryMib: 12_288,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
/** The ceiling shared by the platform image and on-box host: the largest size. */
|
|
18
|
+
export const computerResourceBounds = Object.freeze({
|
|
19
|
+
vcpus: computerSizes.large.vcpus,
|
|
20
|
+
memoryMib: computerSizes.large.memoryMib,
|
|
5
21
|
diskGib: 20,
|
|
6
22
|
pidsMax: 256,
|
|
7
23
|
maxRuntimeMs: 24 * 60 * 60 * 1_000,
|
|
@@ -28,6 +44,14 @@ export function computerRuntimeExpired(startedAt, now, maximumRuntimeMs) {
|
|
|
28
44
|
return now - startedAt >= maximumRuntimeMs;
|
|
29
45
|
}
|
|
30
46
|
|
|
47
|
+
/** The VM resources one size selects, refusing a name that is not a size. */
|
|
48
|
+
export function computerSizeResources(size) {
|
|
49
|
+
if (!Object.hasOwn(computerSizes, size))
|
|
50
|
+
throw new Error(`Computer size ${String(size)} is not offered`);
|
|
51
|
+
const { vcpus, memoryMib } = computerSizes[size];
|
|
52
|
+
return { vcpus, memMib: memoryMib };
|
|
53
|
+
}
|
|
54
|
+
|
|
31
55
|
/** The host may provision a smaller VM, never a larger Computer. */
|
|
32
56
|
export function boundedVmResources({ vcpus, memMib, diskGib, pidsMax }) {
|
|
33
57
|
return {
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* A Computer's size, chosen at creation. It selects the on-box VM's vCPUs and
|
|
4
|
+
* memory and the retail price. Platform containers have one fixed instance
|
|
5
|
+
* type and ignore it. The resources behind each name live in
|
|
6
|
+
* `container/resource-bounds.mjs`, which the VM host also reads.
|
|
7
|
+
*/
|
|
8
|
+
export declare const computerSizeSchema: z.ZodEnum<{
|
|
9
|
+
default: "default";
|
|
10
|
+
small: "small";
|
|
11
|
+
large: "large";
|
|
12
|
+
}>;
|
|
13
|
+
export type ComputerSize = z.infer<typeof computerSizeSchema>;
|
|
14
|
+
export declare const defaultComputerSize: ComputerSize;
|
|
2
15
|
/** A backend the platform runs: a Cloudflare container or an on-box VM. */
|
|
3
16
|
export declare const hostedBackingSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
4
17
|
kind: z.ZodLiteral<"platform-container">;
|
|
@@ -89,5 +102,6 @@ export declare function routeComputerBackend(backends: readonly AttachedBackend[
|
|
|
89
102
|
export type ContainerRuntimeStart = Readonly<{
|
|
90
103
|
runtimeId: string;
|
|
91
104
|
backing: HostedBacking;
|
|
105
|
+
size: ComputerSize;
|
|
92
106
|
startedAt: number;
|
|
93
107
|
}>;
|
|
@@ -10,6 +10,14 @@ import * as z from "zod";
|
|
|
10
10
|
*/
|
|
11
11
|
const hostIdSchema = z.lazy(() => z.string().regex(/^[a-z0-9][a-z0-9-]{0,62}$/));
|
|
12
12
|
const labelSchema = z.lazy(() => z.string().trim().min(1).max(256));
|
|
13
|
+
/**
|
|
14
|
+
* A Computer's size, chosen at creation. It selects the on-box VM's vCPUs and
|
|
15
|
+
* memory and the retail price. Platform containers have one fixed instance
|
|
16
|
+
* type and ignore it. The resources behind each name live in
|
|
17
|
+
* `container/resource-bounds.mjs`, which the VM host also reads.
|
|
18
|
+
*/
|
|
19
|
+
export const computerSizeSchema = z.enum(["small", "default", "large"]);
|
|
20
|
+
export const defaultComputerSize = "default";
|
|
13
21
|
/** A backend the platform runs: a Cloudflare container or an on-box VM. */
|
|
14
22
|
export const hostedBackingSchema = z.discriminatedUnion("kind", [
|
|
15
23
|
z.strictObject({ kind: z.literal("platform-container") }),
|
package/dist/container-policy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
/** The one idle window: a Computer sleeps this long after its last activity. */
|
|
3
|
-
export const computerContainerSleepAfterMs =
|
|
3
|
+
export const computerContainerSleepAfterMs = 60 * 60 * 1_000;
|
|
4
4
|
/** A kept-awake container's platform backstop: the 24 hour runtime ceiling. */
|
|
5
5
|
export const computerKeepAwakeTimeoutMs = 24 * 60 * 60 * 1_000;
|
|
6
6
|
const hostedComputersSchema = z
|
package/dist/files.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export type Utf8Page = Readonly<{
|
|
|
12
12
|
}>;
|
|
13
13
|
/** Decode a bounded byte page without consuming an incomplete final UTF-8 character. */
|
|
14
14
|
export declare function decodeUtf8Page(bytes: Uint8Array, path: string, moreBytesRemain: boolean): Utf8Page;
|
|
15
|
+
/** Whether anything exists at `path`; any other stat failure reaches the caller. */
|
|
16
|
+
export declare function workspaceFileExists(provider: SQLiteWorkspaceProvider, path: string): boolean;
|
|
15
17
|
/** Read raw bounded bytes without Workspace.fs's BOM-stripping UTF-8 path. */
|
|
16
18
|
export declare function readBoundedWorkspaceText(provider: SQLiteWorkspaceProvider, path: string, maximumBytes: number): string;
|
|
17
19
|
/** Adapt native Workspace.fs at the one real file boundary. */
|
package/dist/files.js
CHANGED
|
@@ -44,6 +44,18 @@ async function readBytes(workspace, path, byteOffset, byteLength) {
|
|
|
44
44
|
const source = await workspace.fs.readFile(path, options);
|
|
45
45
|
return new Uint8Array(await new Response(source).arrayBuffer());
|
|
46
46
|
}
|
|
47
|
+
/** Whether anything exists at `path`; any other stat failure reaches the caller. */
|
|
48
|
+
export function workspaceFileExists(provider, path) {
|
|
49
|
+
try {
|
|
50
|
+
provider.statSync(path);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (missingSchema.safeParse(error).success)
|
|
55
|
+
return false;
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
47
59
|
/** Read raw bounded bytes without Workspace.fs's BOM-stripping UTF-8 path. */
|
|
48
60
|
export function readBoundedWorkspaceText(provider, path, maximumBytes) {
|
|
49
61
|
const stat = provider.statSync(path);
|
|
@@ -12,6 +12,7 @@ export declare function createFleetComputers(owner: WatchdogSqliteOwner, capacit
|
|
|
12
12
|
readonly computers: Readonly<{
|
|
13
13
|
computerId: string;
|
|
14
14
|
name: string;
|
|
15
|
+
size: import("../computer-backends.js").ComputerSize;
|
|
15
16
|
createdAt: number;
|
|
16
17
|
updatedAt: number;
|
|
17
18
|
}>[];
|
|
@@ -24,6 +25,7 @@ export declare function createFleetComputers(owner: WatchdogSqliteOwner, capacit
|
|
|
24
25
|
computer: Readonly<{
|
|
25
26
|
computerId: string;
|
|
26
27
|
name: string;
|
|
28
|
+
size: import("../computer-backends.js").ComputerSize;
|
|
27
29
|
createdAt: number;
|
|
28
30
|
updatedAt: number;
|
|
29
31
|
}>;
|
|
@@ -45,7 +47,7 @@ export declare function createFleetComputers(owner: WatchdogSqliteOwner, capacit
|
|
|
45
47
|
hostLabel: string;
|
|
46
48
|
folderLabel: string;
|
|
47
49
|
})[] | null;
|
|
48
|
-
reserveSlot: (computerId: string) => Readonly<{
|
|
50
|
+
reserveSlot: (computerId: string, limit?: number) => Readonly<{
|
|
49
51
|
kind: "reserved";
|
|
50
52
|
runningComputers: number;
|
|
51
53
|
}> | Readonly<{
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { type ComputerSize } from "../computer-backends.js";
|
|
2
3
|
/** Opaque host identity; the fleet does not interpret the actor kind. */
|
|
3
4
|
export type FleetActor = Readonly<{
|
|
4
5
|
kind: string;
|
|
@@ -8,16 +9,23 @@ export type FleetActor = Readonly<{
|
|
|
8
9
|
export type FleetComputer = Readonly<{
|
|
9
10
|
computerId: string;
|
|
10
11
|
name: string;
|
|
12
|
+
size: ComputerSize;
|
|
11
13
|
createdAt: number;
|
|
12
14
|
updatedAt: number;
|
|
13
15
|
}>;
|
|
14
16
|
/** A durable create receipt binds the complete request to its actor. */
|
|
15
17
|
export declare const computerCreateRequestSchema: z.ZodObject<{
|
|
16
18
|
name: z.ZodOptional<z.ZodString>;
|
|
19
|
+
size: z.ZodOptional<z.ZodEnum<{
|
|
20
|
+
default: "default";
|
|
21
|
+
small: "small";
|
|
22
|
+
large: "large";
|
|
23
|
+
}>>;
|
|
17
24
|
requestId: z.ZodString;
|
|
18
25
|
}, z.core.$strict>;
|
|
19
26
|
export type ComputerCreateRequest = Readonly<{
|
|
20
27
|
name?: string | undefined;
|
|
28
|
+
size?: ComputerSize | undefined;
|
|
21
29
|
requestId: string;
|
|
22
30
|
}>;
|
|
23
31
|
/** Inventory pages retain stable ordering and a bounded response. */
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { computerSizeSchema } from "../computer-backends.js";
|
|
2
3
|
/** A durable create receipt binds the complete request to its actor. */
|
|
3
4
|
export const computerCreateRequestSchema = z.strictObject({
|
|
4
5
|
name: z.string().min(1).max(256).optional(),
|
|
6
|
+
/** Omitted means `default`. */
|
|
7
|
+
size: computerSizeSchema.optional(),
|
|
5
8
|
requestId: z.string().min(1).max(256),
|
|
6
9
|
});
|
|
7
10
|
/** Inventory pages retain stable ordering and a bounded response. */
|
package/dist/fleet/inventory.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { words } from "@fungi.computer/cairn";
|
|
2
2
|
import { defineIdFamily } from "@fungi.computer/cairn/id";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
+
import { computerSizeSchema, defaultComputerSize, } from "../computer-backends.js";
|
|
4
5
|
import { ComputerInventoryError, computerPageSchema, } from "./inventory-wire.js";
|
|
5
6
|
const computerIds = defineIdFamily({
|
|
6
7
|
family: "computer",
|
|
@@ -10,6 +11,7 @@ const computerIds = defineIdFamily({
|
|
|
10
11
|
const rowSchema = z.lazy(() => z.strictObject({
|
|
11
12
|
computer_id: z.string().min(1),
|
|
12
13
|
name: z.string().min(1).max(256),
|
|
14
|
+
size: computerSizeSchema,
|
|
13
15
|
actor_kind: z.string().min(1),
|
|
14
16
|
actor_id: z.string().min(1).max(256),
|
|
15
17
|
active: z.number().int().min(0).max(1),
|
|
@@ -24,7 +26,7 @@ const receiptSchema = z.lazy(() => z.strictObject({
|
|
|
24
26
|
name: z.string().min(1).max(256),
|
|
25
27
|
computer_id: z.string().min(1),
|
|
26
28
|
}));
|
|
27
|
-
const selectRow = "SELECT computer_id,name,actor_kind,actor_id,active,created_at,updated_at FROM hub_team_computers";
|
|
29
|
+
const selectRow = "SELECT computer_id,name,size,actor_kind,actor_id,active,created_at,updated_at FROM hub_team_computers";
|
|
28
30
|
function actorColumns(actor) {
|
|
29
31
|
return { actorId: actor.id, actorKind: actor.kind };
|
|
30
32
|
}
|
|
@@ -35,7 +37,7 @@ function sameActor(actorKind, actorId, actor) {
|
|
|
35
37
|
export function createFleetInventory(options) {
|
|
36
38
|
const { sql } = options;
|
|
37
39
|
const ensure = () => {
|
|
38
|
-
sql.exec("CREATE TABLE IF NOT EXISTS hub_team_computers (computer_id TEXT PRIMARY KEY, name TEXT NOT NULL UNIQUE, actor_kind TEXT NOT NULL, actor_id TEXT NOT NULL, active INTEGER NOT NULL DEFAULT 1 CHECK (active IN (0,1)), created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL) STRICT");
|
|
40
|
+
sql.exec("CREATE TABLE IF NOT EXISTS hub_team_computers (computer_id TEXT PRIMARY KEY, name TEXT NOT NULL UNIQUE, size TEXT NOT NULL CHECK (size IN ('small','default','large')), actor_kind TEXT NOT NULL, actor_id TEXT NOT NULL, active INTEGER NOT NULL DEFAULT 1 CHECK (active IN (0,1)), created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL) STRICT");
|
|
39
41
|
sql.exec("CREATE TABLE IF NOT EXISTS hub_team_computer_create_receipts (request_id TEXT PRIMARY KEY, actor_kind TEXT NOT NULL, actor_id TEXT NOT NULL, requested_name TEXT, name TEXT NOT NULL, computer_id TEXT NOT NULL REFERENCES hub_team_computers(computer_id)) STRICT");
|
|
40
42
|
};
|
|
41
43
|
const decode = (row) => {
|
|
@@ -45,6 +47,7 @@ export function createFleetInventory(options) {
|
|
|
45
47
|
return {
|
|
46
48
|
computerId: id.value,
|
|
47
49
|
name: row.name,
|
|
50
|
+
size: row.size,
|
|
48
51
|
createdAt: row.created_at,
|
|
49
52
|
updatedAt: row.updated_at,
|
|
50
53
|
};
|
|
@@ -122,6 +125,9 @@ export function createFleetInventory(options) {
|
|
|
122
125
|
.toArray()[0]);
|
|
123
126
|
if (stored.success && stored.data.active === 0)
|
|
124
127
|
throw new ComputerInventoryError("request_conflict");
|
|
128
|
+
if (stored.success &&
|
|
129
|
+
stored.data.size !== (request.size ?? defaultComputerSize))
|
|
130
|
+
throw new ComputerInventoryError("request_conflict");
|
|
125
131
|
if (!stored.success ||
|
|
126
132
|
stored.data.name !== receipt.data.name ||
|
|
127
133
|
stored.data.actor_kind !== receipt.data.actor_kind ||
|
|
@@ -142,7 +148,7 @@ export function createFleetInventory(options) {
|
|
|
142
148
|
const computerId = computerIds.computer.generate();
|
|
143
149
|
const now = Date.now();
|
|
144
150
|
const columns = actorColumns(actor);
|
|
145
|
-
sql.exec("INSERT INTO hub_team_computers (computer_id,name,actor_kind,actor_id,active,created_at,updated_at) VALUES (
|
|
151
|
+
sql.exec("INSERT INTO hub_team_computers (computer_id,name,size,actor_kind,actor_id,active,created_at,updated_at) VALUES (?,?,?,?,?,?,?,?)", computerId, name, request.size ?? defaultComputerSize, columns.actorKind, columns.actorId, 1, now, now);
|
|
146
152
|
sql.exec("INSERT INTO hub_team_computer_create_receipts (request_id,actor_kind,actor_id,requested_name,name,computer_id) VALUES (?,?,?,?,?,?)", request.requestId, columns.actorKind, columns.actorId, request.name ?? null, name, computerId);
|
|
147
153
|
const created = read(computerId);
|
|
148
154
|
if (created === null)
|
|
@@ -65,6 +65,17 @@ export declare class FleetLifecycle {
|
|
|
65
65
|
startHostedComputer(admitted: (backing: HostedBacking, run: () => Promise<void>) => Promise<void>): Promise<{
|
|
66
66
|
state: "running";
|
|
67
67
|
}>;
|
|
68
|
+
/**
|
|
69
|
+
* The owner's Stop: bring the runtime's workspace changes back into the
|
|
70
|
+
* durable workspace, then end the hosted runtime. Durable files survive, the
|
|
71
|
+
* Computer reads as sleeping, and the next start pushes them back. A Computer
|
|
72
|
+
* with a boot or operation in flight is refused rather than cut off.
|
|
73
|
+
*/
|
|
74
|
+
stopHostedComputer(): Promise<{
|
|
75
|
+
state: "sleeping";
|
|
76
|
+
} | {
|
|
77
|
+
error: "busy";
|
|
78
|
+
}>;
|
|
68
79
|
/** Read liveness without waking a sleeping backend. Queue state wins over booting. */
|
|
69
80
|
readComputerState(): Promise<{
|
|
70
81
|
state: "queued";
|
package/dist/fleet/lifecycle.js
CHANGED
|
@@ -79,6 +79,26 @@ export class FleetLifecycle {
|
|
|
79
79
|
finish();
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* The owner's Stop: bring the runtime's workspace changes back into the
|
|
84
|
+
* durable workspace, then end the hosted runtime. Durable files survive, the
|
|
85
|
+
* Computer reads as sleeping, and the next start pushes them back. A Computer
|
|
86
|
+
* with a boot or operation in flight is refused rather than cut off.
|
|
87
|
+
*/
|
|
88
|
+
async stopHostedComputer() {
|
|
89
|
+
await this.awaitRuntimeMaintenance();
|
|
90
|
+
if (this.hasPendingOperations)
|
|
91
|
+
return { error: "busy" };
|
|
92
|
+
const hosted = this.ports.backend.requireHostedRoute();
|
|
93
|
+
this.usage.ensure();
|
|
94
|
+
if (await this.ports.backend.containerRunning(hosted.backing)) {
|
|
95
|
+
await this.ports.backend.syncRecycledWorkspace(hosted.backing);
|
|
96
|
+
await this.destroyRuntime(hosted.backing, "Computer stopped by its owner");
|
|
97
|
+
this.ports.backend.endedByIdleSleep(attachedBackendId(hosted.backing));
|
|
98
|
+
}
|
|
99
|
+
await this.observeOpenRuntimes();
|
|
100
|
+
return { state: "sleeping" };
|
|
101
|
+
}
|
|
82
102
|
/** Read liveness without waking a sleeping backend. Queue state wins over booting. */
|
|
83
103
|
async readComputerState() {
|
|
84
104
|
const backends = await this.readAttachedBackends();
|
|
@@ -272,6 +292,7 @@ export class FleetLifecycle {
|
|
|
272
292
|
this.containerRuntimeStarted({
|
|
273
293
|
runtimeId: current.runtimeId,
|
|
274
294
|
backing,
|
|
295
|
+
size: row.size,
|
|
275
296
|
startedAt: Date.now(),
|
|
276
297
|
});
|
|
277
298
|
}
|
|
@@ -314,7 +335,7 @@ export class FleetLifecycle {
|
|
|
314
335
|
.state();
|
|
315
336
|
if (!current.running || current.runtimeId !== row.runtimeId)
|
|
316
337
|
continue;
|
|
317
|
-
this.usage.requestRecycle(row.runtimeId, backing, Date.now());
|
|
338
|
+
this.usage.requestRecycle(row.runtimeId, backing, row.size, Date.now());
|
|
318
339
|
await this.armRuntimeWatch(Date.now() + vmRecycleQuietMs);
|
|
319
340
|
const started = await this.ports.backend
|
|
320
341
|
.hostedContainerHost(backing)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WatchdogSqliteOwner } from "@fungi.computer/watchdog";
|
|
2
|
-
import { type ContainerRuntimeStart, type HostedBacking } from "../computer-backends.js";
|
|
2
|
+
import { type ComputerSize, type ContainerRuntimeStart, type HostedBacking } from "../computer-backends.js";
|
|
3
3
|
import type { ComputerFact, ComputerProvenance, ComputerUsageInterval } from "./wire.js";
|
|
4
4
|
/**
|
|
5
5
|
* Computer-local interval ledger; the host owns usage settlement.
|
|
@@ -26,6 +26,7 @@ export declare class ComputerRuntimeUsage {
|
|
|
26
26
|
recycleCandidates(before: number): {
|
|
27
27
|
runtimeId: string;
|
|
28
28
|
backing: HostedBacking;
|
|
29
|
+
size: ComputerSize;
|
|
29
30
|
}[];
|
|
30
31
|
private ensureRecycle;
|
|
31
32
|
pendingRecycles(): {
|
|
@@ -33,9 +34,10 @@ export declare class ComputerRuntimeUsage {
|
|
|
33
34
|
backing: Extract<HostedBacking, {
|
|
34
35
|
kind: "on-box-vm";
|
|
35
36
|
}>;
|
|
37
|
+
size: ComputerSize;
|
|
36
38
|
requestedAt: number;
|
|
37
39
|
}[];
|
|
38
|
-
requestRecycle(runtimeId: string, backing: HostedBacking, requestedAt: number): void;
|
|
40
|
+
requestRecycle(runtimeId: string, backing: HostedBacking, size: ComputerSize, requestedAt: number): void;
|
|
39
41
|
finishRecycle(runtimeId: string): void;
|
|
40
42
|
oldestVmStart(): number | null;
|
|
41
43
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { hostedBackingSchema, } from "../computer-backends.js";
|
|
2
|
+
import { computerSizeSchema, hostedBackingSchema, } from "../computer-backends.js";
|
|
3
3
|
/**
|
|
4
4
|
* Computer-local interval ledger; the host owns usage settlement.
|
|
5
5
|
*
|
|
@@ -15,12 +15,12 @@ export class ComputerRuntimeUsage {
|
|
|
15
15
|
this.checkpointMs = checkpointMs;
|
|
16
16
|
}
|
|
17
17
|
ensure() {
|
|
18
|
-
this.sql.exec("CREATE TABLE IF NOT EXISTS hub_computer_runtime_usage (runtime_id TEXT PRIMARY KEY, backing TEXT NOT NULL, started_at INTEGER NOT NULL, observed_at INTEGER NOT NULL, ended INTEGER NOT NULL CHECK (ended IN (0,1)), delivered_at INTEGER NOT NULL DEFAULT -1) STRICT");
|
|
18
|
+
this.sql.exec("CREATE TABLE IF NOT EXISTS hub_computer_runtime_usage (runtime_id TEXT PRIMARY KEY, backing TEXT NOT NULL, size TEXT NOT NULL CHECK (size IN ('small','default','large')), started_at INTEGER NOT NULL, observed_at INTEGER NOT NULL, ended INTEGER NOT NULL CHECK (ended IN (0,1)), delivered_at INTEGER NOT NULL DEFAULT -1) STRICT");
|
|
19
19
|
this.sql.exec("CREATE TABLE IF NOT EXISTS hub_computer_runtime_activity (runtime_id TEXT PRIMARY KEY, last_activity_at INTEGER NOT NULL) STRICT");
|
|
20
20
|
}
|
|
21
21
|
started(start) {
|
|
22
22
|
this.ensure();
|
|
23
|
-
this.sql.exec("INSERT OR IGNORE INTO hub_computer_runtime_usage (runtime_id, backing, started_at, observed_at, ended) VALUES (
|
|
23
|
+
this.sql.exec("INSERT OR IGNORE INTO hub_computer_runtime_usage (runtime_id, backing, size, started_at, observed_at, ended) VALUES (?,?,?,?,?,0)", start.runtimeId, JSON.stringify(start.backing), start.size, start.startedAt, start.startedAt);
|
|
24
24
|
this.sql.exec("INSERT OR IGNORE INTO hub_computer_runtime_activity (runtime_id, last_activity_at) VALUES (?,?)", start.runtimeId, start.startedAt);
|
|
25
25
|
}
|
|
26
26
|
touchActivity(backing, at) {
|
|
@@ -62,20 +62,21 @@ export class ComputerRuntimeUsage {
|
|
|
62
62
|
}
|
|
63
63
|
recycleCandidates(before) {
|
|
64
64
|
return this.sql
|
|
65
|
-
.exec("SELECT runtime_id,backing FROM hub_computer_runtime_usage WHERE ended=0 AND started_at<=?", before)
|
|
65
|
+
.exec("SELECT runtime_id,backing,size FROM hub_computer_runtime_usage WHERE ended=0 AND started_at<=?", before)
|
|
66
66
|
.toArray()
|
|
67
67
|
.map((row) => ({
|
|
68
68
|
runtimeId: z.string().parse(row.runtime_id),
|
|
69
69
|
backing: hostedBackingSchema.parse(JSON.parse(z.string().parse(row.backing))),
|
|
70
|
+
size: computerSizeSchema.parse(row.size),
|
|
70
71
|
}));
|
|
71
72
|
}
|
|
72
73
|
ensureRecycle() {
|
|
73
|
-
this.sql.exec("CREATE TABLE IF NOT EXISTS hub_computer_vm_recycle (runtime_id TEXT PRIMARY KEY, backing TEXT NOT NULL, requested_at INTEGER NOT NULL) STRICT");
|
|
74
|
+
this.sql.exec("CREATE TABLE IF NOT EXISTS hub_computer_vm_recycle (runtime_id TEXT PRIMARY KEY, backing TEXT NOT NULL, size TEXT NOT NULL CHECK (size IN ('small','default','large')), requested_at INTEGER NOT NULL) STRICT");
|
|
74
75
|
}
|
|
75
76
|
pendingRecycles() {
|
|
76
77
|
this.ensureRecycle();
|
|
77
78
|
return this.sql
|
|
78
|
-
.exec("SELECT runtime_id,backing,requested_at FROM hub_computer_vm_recycle")
|
|
79
|
+
.exec("SELECT runtime_id,backing,size,requested_at FROM hub_computer_vm_recycle")
|
|
79
80
|
.toArray()
|
|
80
81
|
.map((row) => {
|
|
81
82
|
const backing = hostedBackingSchema.parse(JSON.parse(z.string().parse(row.backing)));
|
|
@@ -84,13 +85,14 @@ export class ComputerRuntimeUsage {
|
|
|
84
85
|
return {
|
|
85
86
|
runtimeId: z.string().parse(row.runtime_id),
|
|
86
87
|
backing,
|
|
88
|
+
size: computerSizeSchema.parse(row.size),
|
|
87
89
|
requestedAt: z.number().parse(row.requested_at),
|
|
88
90
|
};
|
|
89
91
|
});
|
|
90
92
|
}
|
|
91
|
-
requestRecycle(runtimeId, backing, requestedAt) {
|
|
93
|
+
requestRecycle(runtimeId, backing, size, requestedAt) {
|
|
92
94
|
this.ensureRecycle();
|
|
93
|
-
this.sql.exec("INSERT INTO hub_computer_vm_recycle (runtime_id,backing,requested_at) VALUES (
|
|
95
|
+
this.sql.exec("INSERT INTO hub_computer_vm_recycle (runtime_id,backing,size,requested_at) VALUES (?,?,?,?)", runtimeId, JSON.stringify(backing), size, requestedAt);
|
|
94
96
|
}
|
|
95
97
|
finishRecycle(runtimeId) {
|
|
96
98
|
this.sql.exec("DELETE FROM hub_computer_vm_recycle WHERE runtime_id=?", runtimeId);
|
|
@@ -116,11 +118,12 @@ export class ComputerRuntimeUsage {
|
|
|
116
118
|
}
|
|
117
119
|
pending() {
|
|
118
120
|
return this.sql
|
|
119
|
-
.exec("SELECT runtime_id, backing, started_at, observed_at, ended FROM hub_computer_runtime_usage WHERE observed_at > delivered_at OR ended = 1 LIMIT 64")
|
|
121
|
+
.exec("SELECT runtime_id, backing, size, started_at, observed_at, ended FROM hub_computer_runtime_usage WHERE observed_at > delivered_at OR ended = 1 LIMIT 64")
|
|
120
122
|
.toArray()
|
|
121
123
|
.map((row) => ({
|
|
122
124
|
runtimeId: z.string().parse(row.runtime_id),
|
|
123
125
|
backing: hostedBackingSchema.parse(JSON.parse(z.string().parse(row.backing))),
|
|
126
|
+
size: computerSizeSchema.parse(row.size),
|
|
124
127
|
startedAt: z.number().parse(row.started_at),
|
|
125
128
|
observedAt: z.number().parse(row.observed_at),
|
|
126
129
|
ended: row.ended === 1,
|
package/dist/fleet/slots.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare function createFleetSlots(options: Readonly<{
|
|
|
24
24
|
toArray: () => readonly import("@fungi.computer/watchdog").WatchdogSqliteRow[];
|
|
25
25
|
}>;
|
|
26
26
|
count: () => number;
|
|
27
|
-
reserve: (computerId: string) => FleetSlotReservation;
|
|
27
|
+
reserve: (computerId: string, limit?: number) => FleetSlotReservation;
|
|
28
28
|
release: (computerId: string) => void;
|
|
29
29
|
};
|
|
30
30
|
export {};
|
package/dist/fleet/slots.js
CHANGED
|
@@ -14,7 +14,7 @@ export function createFleetSlots(options, capacity) {
|
|
|
14
14
|
return z.number().int().nonnegative().parse(row.count);
|
|
15
15
|
};
|
|
16
16
|
/** Capacity-only synchronous admission for a hosted cold start. */
|
|
17
|
-
const reserve = (computerId) => {
|
|
17
|
+
const reserve = (computerId, limit = capacity.limit) => {
|
|
18
18
|
try {
|
|
19
19
|
return options.transactionSync(() => {
|
|
20
20
|
const existing = sql
|
|
@@ -23,11 +23,11 @@ export function createFleetSlots(options, capacity) {
|
|
|
23
23
|
const running = count();
|
|
24
24
|
if (existing !== undefined)
|
|
25
25
|
return { kind: "reserved", runningComputers: running };
|
|
26
|
-
if (running >=
|
|
26
|
+
if (running >= limit)
|
|
27
27
|
return {
|
|
28
28
|
kind: "capacity",
|
|
29
29
|
runningComputers: running,
|
|
30
|
-
limit
|
|
30
|
+
limit,
|
|
31
31
|
retryAfterSeconds: capacity.retryAfterSeconds,
|
|
32
32
|
};
|
|
33
33
|
sql.exec("INSERT INTO hub_team_running_computers (computer_id) VALUES (?)", computerId);
|
package/dist/fleet/wire.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare const computerActionSchema: z.ZodEnum<{
|
|
|
24
24
|
processList: "processList";
|
|
25
25
|
processKill: "processKill";
|
|
26
26
|
processLogs: "processLogs";
|
|
27
|
+
processWait: "processWait";
|
|
27
28
|
exposePort: "exposePort";
|
|
28
29
|
unexposePort: "unexposePort";
|
|
29
30
|
listPorts: "listPorts";
|
|
@@ -61,6 +62,7 @@ export declare const computerGrantSchema: z.ZodObject<{
|
|
|
61
62
|
processList: "processList";
|
|
62
63
|
processKill: "processKill";
|
|
63
64
|
processLogs: "processLogs";
|
|
65
|
+
processWait: "processWait";
|
|
64
66
|
exposePort: "exposePort";
|
|
65
67
|
unexposePort: "unexposePort";
|
|
66
68
|
listPorts: "listPorts";
|
|
@@ -167,6 +169,11 @@ export declare const computerUsageIntervalSchema: z.ZodObject<{
|
|
|
167
169
|
kind: z.ZodLiteral<"on-box-vm">;
|
|
168
170
|
hostId: z.ZodLazy<z.ZodString>;
|
|
169
171
|
}, z.core.$strict>], "kind">;
|
|
172
|
+
size: z.ZodEnum<{
|
|
173
|
+
default: "default";
|
|
174
|
+
small: "small";
|
|
175
|
+
large: "large";
|
|
176
|
+
}>;
|
|
170
177
|
startedAt: z.ZodNumber;
|
|
171
178
|
observedAt: z.ZodNumber;
|
|
172
179
|
ended: z.ZodBoolean;
|
|
@@ -180,6 +187,7 @@ export type ComputerUsageInterval = Readonly<{
|
|
|
180
187
|
kind: "on-box-vm";
|
|
181
188
|
hostId: string;
|
|
182
189
|
}>;
|
|
190
|
+
size: "small" | "default" | "large";
|
|
183
191
|
startedAt: number;
|
|
184
192
|
observedAt: number;
|
|
185
193
|
ended: boolean;
|
|
@@ -242,6 +250,11 @@ export declare const computerFactSchema: z.ZodLazy<z.ZodDiscriminatedUnion<[z.Zo
|
|
|
242
250
|
kind: z.ZodLiteral<"on-box-vm">;
|
|
243
251
|
hostId: z.ZodLazy<z.ZodString>;
|
|
244
252
|
}, z.core.$strict>], "kind">;
|
|
253
|
+
size: z.ZodEnum<{
|
|
254
|
+
default: "default";
|
|
255
|
+
small: "small";
|
|
256
|
+
large: "large";
|
|
257
|
+
}>;
|
|
245
258
|
startedAt: z.ZodNumber;
|
|
246
259
|
observedAt: z.ZodNumber;
|
|
247
260
|
ended: z.ZodBoolean;
|
package/dist/fleet/wire.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { computerOperationSchema, computerValueSchema, pathSchema, } from "@fungi.computer/computer-contract";
|
|
3
|
-
import { attachedBackendId, hostedBackingSchema, localBackendSchema, } from "../computer-backends.js";
|
|
3
|
+
import { attachedBackendId, computerSizeSchema, hostedBackingSchema, localBackendSchema, } from "../computer-backends.js";
|
|
4
4
|
/** Operations the host may admit on one Computer. */
|
|
5
5
|
export const computerActionSchema = z.enum([
|
|
6
6
|
...computerOperationSchema.options,
|
|
@@ -11,6 +11,7 @@ export const computerActionSchema = z.enum([
|
|
|
11
11
|
"processList",
|
|
12
12
|
"processKill",
|
|
13
13
|
"processLogs",
|
|
14
|
+
"processWait",
|
|
14
15
|
"exposePort",
|
|
15
16
|
"unexposePort",
|
|
16
17
|
"listPorts",
|
|
@@ -98,6 +99,7 @@ const factIdentity = {
|
|
|
98
99
|
export const computerUsageIntervalSchema = z.strictObject({
|
|
99
100
|
runtimeId: z.string().min(1).max(128),
|
|
100
101
|
backing: hostedBackingSchema,
|
|
102
|
+
size: computerSizeSchema,
|
|
101
103
|
startedAt: z.number().int().nonnegative(),
|
|
102
104
|
/** The last observed instant; final once `ended` is true. */
|
|
103
105
|
observedAt: z.number().int().nonnegative(),
|
package/dist/host-config.d.ts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* What one running VM of each size counts against a host's capacity, in
|
|
4
|
+
* half-default-VM units: the configured memory in 4 GiB steps (4, 8 and 16
|
|
5
|
+
* GiB). Configured memory bounds what a busy guest can pin, where the measured
|
|
6
|
+
* resident size of an idle VM (about 0.43 GiB) bounds nothing. A host's
|
|
7
|
+
* `maxActive` and `reservedHeadroom` still count default-size VMs, so a host
|
|
8
|
+
* admits the same number of default VMs as before, twice as many small ones and
|
|
9
|
+
* half as many large ones.
|
|
10
|
+
*/
|
|
11
|
+
export declare const computerSizeUnits: {
|
|
12
|
+
readonly small: 1;
|
|
13
|
+
readonly default: 2;
|
|
14
|
+
readonly large: 4;
|
|
15
|
+
};
|
|
16
|
+
/** Units one default-size VM holds: the factor between `maxActive` and units. */
|
|
17
|
+
export declare const unitsPerDefaultVm: 2;
|
|
2
18
|
/** One VM host's active capacity, including slots held back as headroom. */
|
|
3
19
|
export declare const hostCapacitySchema: z.ZodObject<{
|
|
4
20
|
maxActive: z.ZodNumber;
|
package/dist/host-config.js
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* What one running VM of each size counts against a host's capacity, in
|
|
4
|
+
* half-default-VM units: the configured memory in 4 GiB steps (4, 8 and 16
|
|
5
|
+
* GiB). Configured memory bounds what a busy guest can pin, where the measured
|
|
6
|
+
* resident size of an idle VM (about 0.43 GiB) bounds nothing. A host's
|
|
7
|
+
* `maxActive` and `reservedHeadroom` still count default-size VMs, so a host
|
|
8
|
+
* admits the same number of default VMs as before, twice as many small ones and
|
|
9
|
+
* half as many large ones.
|
|
10
|
+
*/
|
|
11
|
+
export const computerSizeUnits = {
|
|
12
|
+
small: 1,
|
|
13
|
+
default: 2,
|
|
14
|
+
large: 4,
|
|
15
|
+
};
|
|
16
|
+
/** Units one default-size VM holds: the factor between `maxActive` and units. */
|
|
17
|
+
export const unitsPerDefaultVm = computerSizeUnits.default;
|
|
2
18
|
/** One VM host's active capacity, including slots held back as headroom. */
|
|
3
19
|
export const hostCapacitySchema = z
|
|
4
20
|
.strictObject({
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,10 @@ import { type IWorkspaceContainerAPI } from "@fungi.computer/cloudflare-computer
|
|
|
6
6
|
import { DurableObject } from "cloudflare:workers";
|
|
7
7
|
import type { FilesPort } from "@fungi.computer/knapsack";
|
|
8
8
|
import { z } from "zod";
|
|
9
|
-
import { type ComputerExecutionBudget, type ComputerExecutionHostHooks, type ComputerExecRequest, type ComputerOperationResult, type ComputerFileReadInput, type ComputerFileByteReadInput, type ComputerFileReplacement, type ComputerFileReplacementResult, type ComputerValue, writeInputSchema, writeOutputSchema, processLogsOutputSchema, type ComputerProcess } from "@fungi.computer/computer-contract";
|
|
9
|
+
import { type ComputerExecutionBudget, type ComputerExecutionHostHooks, type ComputerExecRequest, type ComputerOperationResult, type ComputerFileReadInput, type ComputerFileByteReadInput, type ComputerFileReplacement, type ComputerFileReplacementResult, type ComputerValue, writeInputSchema, writeOutputSchema, processLogsOutputSchema, processWaitOutputSchema, type ComputerProcess } from "@fungi.computer/computer-contract";
|
|
10
10
|
import { createWorkspaceFilesPort } from "./files.js";
|
|
11
11
|
import { OnBoxVmContainerHost, type OnBoxVmEnv, type OnBoxVmPlacement } from "./on-box-vm.js";
|
|
12
|
-
import { type AttachedBackend, type AttachedBackendView, type BackendNeed, type BackendRoute, type ContainerRuntimeStart, type HostedBacking } from "./computer-backends.js";
|
|
12
|
+
import { type AttachedBackend, type AttachedBackendView, type BackendNeed, type BackendRoute, type ComputerSize, type ContainerRuntimeStart, type HostedBacking } from "./computer-backends.js";
|
|
13
13
|
import { LocalBackendConnections } from "./local-backend.js";
|
|
14
14
|
/** Files needs only the native Workspace lease and its atomic replacement door. */
|
|
15
15
|
export type ComputerFilesRpc = Readonly<{
|
|
@@ -103,6 +103,8 @@ declare class ContainerComputer extends ContainerComputerBase {
|
|
|
103
103
|
* overrides this with the list its Team projected down.
|
|
104
104
|
*/
|
|
105
105
|
protected attachedBackends(): readonly AttachedBackend[];
|
|
106
|
+
/** This Computer's size, which the owner knows; the default until it says. */
|
|
107
|
+
protected computerSize(): ComputerSize;
|
|
106
108
|
/** A runtime of a hosted backend started; owners meter it. */
|
|
107
109
|
protected containerRuntimeStarted(start: ContainerRuntimeStart): void;
|
|
108
110
|
/** The single routing decision over this Computer's attached backends. */
|
|
@@ -298,6 +300,12 @@ export declare class ComputerDO extends ContainerComputer implements ComputerFil
|
|
|
298
300
|
/** The retained last output lines of one process, with its record. */
|
|
299
301
|
processLogs(input: ComputerValue): z.output<typeof processLogsOutputSchema>;
|
|
300
302
|
protected processLogsAfterAcceptance(input: ComputerValue, accept: () => void): z.output<typeof processLogsOutputSchema>;
|
|
303
|
+
/**
|
|
304
|
+
* Wait up to a bound for one process to exit, then return its record and
|
|
305
|
+
* retained output tail. The process keeps running past a timed-out wait.
|
|
306
|
+
*/
|
|
307
|
+
waitProcess(input: ComputerValue): Promise<z.output<typeof processWaitOutputSchema>>;
|
|
308
|
+
protected waitProcessAfterAcceptance(input: ComputerValue, accept: () => void): Promise<z.output<typeof processWaitOutputSchema>>;
|
|
301
309
|
/** Send SIGTERM to one running process; its exit is recorded when observed. */
|
|
302
310
|
killProcess(input: ComputerValue): Promise<{
|
|
303
311
|
process: ComputerProcess;
|
package/dist/index.js
CHANGED
|
@@ -68,17 +68,17 @@ import { z } from "zod";
|
|
|
68
68
|
import { SystemTrustContainerBackend } from "./container-system-trust.js";
|
|
69
69
|
import { computerTransportBackend } from "./transport-backend.js";
|
|
70
70
|
import { PullPendingTracker } from "./pull-pending.js";
|
|
71
|
-
import { ComputerFileConflict, ComputerFileRangeError, ComputerFileTooLargeError, capabilityNameSchema, computerValueSchema, computerCapabilities, computerPortInputSchema, computerPortOutputSchema, computerPortRemovalOutputSchema, computerPortsOutputSchema, computerPortSchema, ComputerPortLimitError, ComputerPortReservedError, computerTerminalPort, isComputerReservedPort, maximumExposedPorts, maximumProcessRecords, execInputSchema, execOutputSchema, computerToolResult, computerExecutionRequestSchema, genericComputerExecutionBudget, mintComputerRequestId, listInputSchema, listOutputSchema, maximumFileBytes, mkdirInputSchema, mkdirOutputSchema, moveInputSchema, moveOutputSchema, ComputerFileMoveError, readInputSchema, readBytesInputSchema, readOutputSchema, replaceInputSchema, writeInputSchema, writeOutputSchema, processIdInputSchema, processKillOutputSchema, processListOutputSchema, processLogsInputSchema, processLogsOutputSchema, maximumProcessLogLines, processStartInputSchema, processStartToolInputSchema, ComputerProcessNotFoundError, } from "@fungi.computer/computer-contract";
|
|
72
|
-
import { createWorkspaceFilesPort, readBoundedWorkspaceText, listWorkspaceFiles, } from "./files.js";
|
|
71
|
+
import { ComputerFileConflict, ComputerFileRangeError, ComputerFileTooLargeError, capabilityNameSchema, computerValueSchema, computerCapabilities, computerPortInputSchema, computerPortOutputSchema, computerPortRemovalOutputSchema, computerPortsOutputSchema, computerPortSchema, ComputerPortLimitError, ComputerPortReservedError, computerTerminalPort, isComputerReservedPort, maximumExposedPorts, maximumProcessRecords, execInputSchema, execOutputSchema, computerToolResult, computerExecutionRequestSchema, genericComputerExecutionBudget, mintComputerRequestId, listInputSchema, listOutputSchema, maximumFileBytes, mkdirInputSchema, mkdirOutputSchema, moveInputSchema, moveOutputSchema, ComputerFileMoveError, readInputSchema, readBytesInputSchema, readOutputSchema, replaceInputSchema, writeInputSchema, writeOutputSchema, processIdInputSchema, processKillOutputSchema, processListOutputSchema, processLogsInputSchema, processLogsOutputSchema, processWaitInputSchema, processWaitOutputSchema, maximumProcessLogLines, processStartInputSchema, processStartToolInputSchema, ComputerProcessNotFoundError, } from "@fungi.computer/computer-contract";
|
|
72
|
+
import { createWorkspaceFilesPort, readBoundedWorkspaceText, workspaceFileExists, listWorkspaceFiles, } from "./files.js";
|
|
73
73
|
import { computerExecutionResult } from "./execution-result.js";
|
|
74
74
|
import { ComputerOperationRecord } from "./operation-record.js";
|
|
75
75
|
import { createComputerExecutionLifecycle } from "./execution-lifecycle.js";
|
|
76
76
|
import { applyWorkspacePatch } from "./files-patch.js";
|
|
77
|
-
import { ComputerProcessInventory, drainProcessExit, ProcessLogTail, failedObservation, observeProcess, } from "./process-inventory.js";
|
|
77
|
+
import { ComputerProcessInventory, drainProcessExit, ProcessLogTail, failedObservation, observeProcess, waitForProcessExit, } from "./process-inventory.js";
|
|
78
78
|
import { assertComputerContainersEnabled, ComputerContainersPausedError, configureComputerContainer, hostedComputerContainersPaused, } from "./container-policy.js";
|
|
79
79
|
import { OnBoxVmContainerHost, onBoxVmPlacement, } from "./on-box-vm.js";
|
|
80
80
|
import { computerKeepAwake } from "./fleet/keep-awake.js";
|
|
81
|
-
import { attachedBackendId, describeAttachedBackend, routeComputerBackend, } from "./computer-backends.js";
|
|
81
|
+
import { attachedBackendId, defaultComputerSize, describeAttachedBackend, routeComputerBackend, } from "./computer-backends.js";
|
|
82
82
|
import { MeteredContainerHost } from "./metered-container-host.js";
|
|
83
83
|
import { LocalBackendConnections, LocalWorkspaceBackend, localBackendDialPath, ownerLocalBackendDialPath, verifyLocalBackendDial, } from "./local-backend.js";
|
|
84
84
|
const computerBinding = "COMPUTER";
|
|
@@ -369,6 +369,10 @@ class ContainerComputer extends ContainerComputerBase {
|
|
|
369
369
|
this.localConnections.park(backendId, server);
|
|
370
370
|
return new Response(null, { status: 101, webSocket: client });
|
|
371
371
|
}
|
|
372
|
+
/** This Computer's size, which the owner knows; the default until it says. */
|
|
373
|
+
computerSize() {
|
|
374
|
+
return defaultComputerSize;
|
|
375
|
+
}
|
|
372
376
|
/** A runtime of a hosted backend started; owners meter it. */
|
|
373
377
|
containerRuntimeStarted(start) {
|
|
374
378
|
void start;
|
|
@@ -409,7 +413,7 @@ class ContainerComputer extends ContainerComputerBase {
|
|
|
409
413
|
const host = backing.kind === "platform-container"
|
|
410
414
|
? this.getWorkspaceContainer()
|
|
411
415
|
: this.onBoxVmHost(backing.hostId);
|
|
412
|
-
return new MeteredContainerHost(host, backing, (start) => {
|
|
416
|
+
return new MeteredContainerHost(host, backing, () => this.computerSize(), (start) => {
|
|
413
417
|
this.containerRuntimeStarted(start);
|
|
414
418
|
});
|
|
415
419
|
}
|
|
@@ -428,7 +432,7 @@ class ContainerComputer extends ContainerComputerBase {
|
|
|
428
432
|
}
|
|
429
433
|
/** Let the consuming owner admit boots while preserving the runtime host seam. */
|
|
430
434
|
createOnBoxVmHost(placement) {
|
|
431
|
-
return new OnBoxVmContainerHost(placement, this.bindings, this.state.id.toString());
|
|
435
|
+
return new OnBoxVmContainerHost(placement, this.bindings, this.state.id.toString(), () => this.computerSize());
|
|
432
436
|
}
|
|
433
437
|
/** Whether a hosted backend's runtime is running now. */
|
|
434
438
|
async containerRunning(backing) {
|
|
@@ -1073,6 +1077,10 @@ export class ComputerDO extends ContainerComputer {
|
|
|
1073
1077
|
return await this.listProcessesAfterAcceptance(accept);
|
|
1074
1078
|
case "kill_process":
|
|
1075
1079
|
return await this.killProcessAfterAcceptance(input, accept);
|
|
1080
|
+
case "process_logs":
|
|
1081
|
+
return this.processLogsAfterAcceptance(input, accept);
|
|
1082
|
+
case "wait_process":
|
|
1083
|
+
return await this.waitProcessAfterAcceptance(input, accept);
|
|
1076
1084
|
}
|
|
1077
1085
|
const workspace = await this.readyWorkspace();
|
|
1078
1086
|
accept();
|
|
@@ -1389,6 +1397,36 @@ export class ComputerDO extends ContainerComputer {
|
|
|
1389
1397
|
truncated: log.truncated || log.lines.length > wanted,
|
|
1390
1398
|
});
|
|
1391
1399
|
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Wait up to a bound for one process to exit, then return its record and
|
|
1402
|
+
* retained output tail. The process keeps running past a timed-out wait.
|
|
1403
|
+
*/
|
|
1404
|
+
async waitProcess(input) {
|
|
1405
|
+
return await this.waitProcessAfterAcceptance(input, () => undefined);
|
|
1406
|
+
}
|
|
1407
|
+
async waitProcessAfterAcceptance(input, accept) {
|
|
1408
|
+
const { id, timeoutMs } = processWaitInputSchema.parse(input);
|
|
1409
|
+
accept();
|
|
1410
|
+
const waited = await waitForProcessExit({
|
|
1411
|
+
read: () => {
|
|
1412
|
+
const row = this.#processes.get(id);
|
|
1413
|
+
if (row === undefined)
|
|
1414
|
+
throw new ComputerProcessNotFoundError(id);
|
|
1415
|
+
return row;
|
|
1416
|
+
},
|
|
1417
|
+
observe: (row) => this.#observeOwnedProcess(row),
|
|
1418
|
+
now: Date.now,
|
|
1419
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
1420
|
+
timeoutMs,
|
|
1421
|
+
});
|
|
1422
|
+
const log = this.#processes.logOf(id);
|
|
1423
|
+
return processWaitOutputSchema.parse({
|
|
1424
|
+
process: this.#processReceipt(waited.process),
|
|
1425
|
+
lines: (log?.lines ?? []).slice(-maximumProcessLogLines),
|
|
1426
|
+
truncated: log?.truncated ?? false,
|
|
1427
|
+
timedOut: waited.timedOut,
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1392
1430
|
/** Send SIGTERM to one running process; its exit is recorded when observed. */
|
|
1393
1431
|
async killProcess(input) {
|
|
1394
1432
|
return await this.killProcessAfterAcceptance(input, () => undefined);
|
|
@@ -1635,8 +1673,11 @@ export class ComputerDO extends ContainerComputer {
|
|
|
1635
1673
|
const provider = new SQLiteWorkspaceProvider(workspace.fs.db);
|
|
1636
1674
|
const result = writeOutputSchema.parse(this.state.storage.transactionSync(() => {
|
|
1637
1675
|
accept();
|
|
1638
|
-
|
|
1639
|
-
|
|
1676
|
+
if (replacement.expectedContent === null) {
|
|
1677
|
+
if (workspaceFileExists(provider, replacement.path))
|
|
1678
|
+
throw new ComputerFileConflict();
|
|
1679
|
+
}
|
|
1680
|
+
else if (readBoundedWorkspaceText(provider, replacement.path, maximumFileBytes) !== replacement.expectedContent) {
|
|
1640
1681
|
throw new ComputerFileConflict();
|
|
1641
1682
|
}
|
|
1642
1683
|
provider.writeFileSync(replacement.path, replacement.content);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IWorkspaceContainerAPI, WorkspaceRef } from "@fungi.computer/cloudflare-computer/backends/container";
|
|
2
|
-
import type { ContainerRuntimeStart, HostedBacking } from "./computer-backends.js";
|
|
2
|
+
import type { ComputerSize, ContainerRuntimeStart, HostedBacking } from "./computer-backends.js";
|
|
3
3
|
/**
|
|
4
4
|
* A container host that reports each runtime it starts. Every other call
|
|
5
5
|
* passes through unchanged, so the container backend cannot tell it apart
|
|
@@ -7,7 +7,7 @@ import type { ContainerRuntimeStart, HostedBacking } from "./computer-backends.j
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class MeteredContainerHost implements IWorkspaceContainerAPI {
|
|
9
9
|
#private;
|
|
10
|
-
constructor(host: IWorkspaceContainerAPI, backing: HostedBacking, started: (start: ContainerRuntimeStart) => void);
|
|
10
|
+
constructor(host: IWorkspaceContainerAPI, backing: HostedBacking, size: () => ComputerSize, started: (start: ContainerRuntimeStart) => void);
|
|
11
11
|
start(env: Record<string, string>, enableInternet: boolean): Promise<{
|
|
12
12
|
runtimeId: string;
|
|
13
13
|
}>;
|
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
export class MeteredContainerHost {
|
|
7
7
|
#host;
|
|
8
8
|
#backing;
|
|
9
|
+
#size;
|
|
9
10
|
#started;
|
|
10
|
-
constructor(host, backing, started) {
|
|
11
|
+
constructor(host, backing, size, started) {
|
|
11
12
|
this.#host = host;
|
|
12
13
|
this.#backing = backing;
|
|
14
|
+
this.#size = size;
|
|
13
15
|
this.#started = started;
|
|
14
16
|
}
|
|
15
17
|
async #report(boot) {
|
|
@@ -17,6 +19,7 @@ export class MeteredContainerHost {
|
|
|
17
19
|
this.#started({
|
|
18
20
|
runtimeId: runtime.runtimeId,
|
|
19
21
|
backing: this.#backing,
|
|
22
|
+
size: this.#size(),
|
|
20
23
|
startedAt: Date.now(),
|
|
21
24
|
});
|
|
22
25
|
return runtime;
|
package/dist/on-box-vm.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IWorkspaceContainerAPI, WorkspaceRef } from "@fungi.computer/cloudflare-computer/backends/container";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { type ComputerSize } from "./computer-backends.js";
|
|
3
4
|
/**
|
|
4
5
|
* The on-box VM backing of a Computer's container.
|
|
5
6
|
*
|
|
@@ -58,6 +59,11 @@ declare const vmInventorySchema: z.ZodArray<z.ZodObject<{
|
|
|
58
59
|
id: z.ZodString;
|
|
59
60
|
name: z.ZodString;
|
|
60
61
|
lastActive: z.ZodNumber;
|
|
62
|
+
size: z.ZodEnum<{
|
|
63
|
+
default: "default";
|
|
64
|
+
small: "small";
|
|
65
|
+
large: "large";
|
|
66
|
+
}>;
|
|
61
67
|
}, z.core.$strict>>;
|
|
62
68
|
export type OnBoxVmInventory = z.infer<typeof vmInventorySchema>;
|
|
63
69
|
export type OnBoxVmOperation = "status" | "start" | "restart" | "destroy" | "intercept" | "inventory";
|
|
@@ -74,7 +80,11 @@ export declare class OnBoxVmTimeoutError extends OnBoxVmTimeoutError_base<{
|
|
|
74
80
|
/** One Durable Object's view of its microVM through the host service. */
|
|
75
81
|
export declare class OnBoxVmContainerHost implements IWorkspaceContainerAPI {
|
|
76
82
|
#private;
|
|
77
|
-
|
|
83
|
+
/**
|
|
84
|
+
* `size` names the Computer's size at each boot; a host built only to read
|
|
85
|
+
* or stop VMs omits it and cannot boot one.
|
|
86
|
+
*/
|
|
87
|
+
constructor(placement: OnBoxVmPlacement, env: OnBoxVmEnv, vmId: string, size?: () => ComputerSize);
|
|
78
88
|
/** Signed host-wide inventory; includes VMs outside this Hub's directory. */
|
|
79
89
|
inventory(): Promise<OnBoxVmInventory>;
|
|
80
90
|
start(env: Record<string, string>, enableInternet: boolean): Promise<{
|
package/dist/on-box-vm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { computerSizeSchema } from "./computer-backends.js";
|
|
2
3
|
import * as Data from "effect/Data";
|
|
3
4
|
import { SeamReplayPartitions, importSeamSigner, importSeamVerifiers, seamBodyDigest, seamHeader, signSeamRequest, unsignedPayload, verifySeamRequest, } from "@fungi.computer/seam";
|
|
4
5
|
function accessHeaders(env) {
|
|
@@ -86,6 +87,7 @@ const vmInventorySchema = z.array(vmStateSchema.extend({
|
|
|
86
87
|
id: z.string().regex(/^[0-9a-f]{64}$/),
|
|
87
88
|
name: z.string(),
|
|
88
89
|
lastActive: z.number().int().nonnegative(),
|
|
90
|
+
size: computerSizeSchema,
|
|
89
91
|
}));
|
|
90
92
|
const vmStartSchema = z.lazy(() => z.strictObject({
|
|
91
93
|
runtimeId: z.string().min(1).max(128),
|
|
@@ -124,7 +126,13 @@ export class OnBoxVmContainerHost {
|
|
|
124
126
|
#placement;
|
|
125
127
|
#env;
|
|
126
128
|
#vmId;
|
|
127
|
-
|
|
129
|
+
#size;
|
|
130
|
+
/**
|
|
131
|
+
* `size` names the Computer's size at each boot; a host built only to read
|
|
132
|
+
* or stop VMs omits it and cannot boot one.
|
|
133
|
+
*/
|
|
134
|
+
constructor(placement, env, vmId, size) {
|
|
135
|
+
this.#size = size;
|
|
128
136
|
this.#placement = placement;
|
|
129
137
|
this.#env = env;
|
|
130
138
|
this.#vmId = z
|
|
@@ -161,10 +169,13 @@ export class OnBoxVmContainerHost {
|
|
|
161
169
|
}
|
|
162
170
|
}
|
|
163
171
|
async #boot(operation, env, enableInternet) {
|
|
172
|
+
if (this.#size === undefined)
|
|
173
|
+
throw new Error("This on-box VM host was built without a Computer size");
|
|
164
174
|
const started = await this.#call(operation, vmStartSchema, {
|
|
165
175
|
env,
|
|
166
176
|
enableInternet,
|
|
167
177
|
sleepAfterMs: vmHostSleepBackstopMs,
|
|
178
|
+
size: this.#size(),
|
|
168
179
|
});
|
|
169
180
|
return { runtimeId: started.runtimeId };
|
|
170
181
|
}
|
|
@@ -20,6 +20,24 @@ export declare class ProcessLogTail {
|
|
|
20
20
|
/** The retained lines, including any unfinished last line. */
|
|
21
21
|
snapshot(): ProcessLogSnapshot;
|
|
22
22
|
}
|
|
23
|
+
/** What one wait found: the process as last read, and whether it was still running at the bound. */
|
|
24
|
+
export type ProcessWaitOutcome = Readonly<{
|
|
25
|
+
process: ComputerProcess;
|
|
26
|
+
timedOut: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Poll one process until it is no longer running or the bound passes. The drain
|
|
30
|
+
* that watches the process records its exit; every tenth poll the caller's
|
|
31
|
+
* `observe` also asks the execution owner, so a lost watcher cannot hold a
|
|
32
|
+
* wait open. The clock and sleep are the caller's, so a fake clock drives it.
|
|
33
|
+
*/
|
|
34
|
+
export declare function waitForProcessExit(options: {
|
|
35
|
+
read: () => ComputerProcess;
|
|
36
|
+
observe: (process: ComputerProcess) => Promise<ComputerProcess>;
|
|
37
|
+
now: () => number;
|
|
38
|
+
sleep: (ms: number) => Promise<void>;
|
|
39
|
+
timeoutMs: number;
|
|
40
|
+
}): Promise<ProcessWaitOutcome>;
|
|
23
41
|
/** Computer-owned replay identities; computerd owns execution and exit observations. */
|
|
24
42
|
export declare class ComputerProcessInventory {
|
|
25
43
|
#private;
|
|
@@ -117,6 +117,25 @@ export class ProcessLogTail {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Poll one process until it is no longer running or the bound passes. The drain
|
|
122
|
+
* that watches the process records its exit; every tenth poll the caller's
|
|
123
|
+
* `observe` also asks the execution owner, so a lost watcher cannot hold a
|
|
124
|
+
* wait open. The clock and sleep are the caller's, so a fake clock drives it.
|
|
125
|
+
*/
|
|
126
|
+
export async function waitForProcessExit(options) {
|
|
127
|
+
const deadline = options.now() + options.timeoutMs;
|
|
128
|
+
for (let poll = 0;; poll += 1) {
|
|
129
|
+
const row = options.read();
|
|
130
|
+
const current = row.state === "running" && poll % 10 === 9
|
|
131
|
+
? await options.observe(row)
|
|
132
|
+
: row;
|
|
133
|
+
const remaining = deadline - options.now();
|
|
134
|
+
if (current.state !== "running" || remaining <= 0)
|
|
135
|
+
return { process: current, timedOut: current.state === "running" };
|
|
136
|
+
await options.sleep(Math.min(500, remaining));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
120
139
|
function clipLine(line) {
|
|
121
140
|
return line.length > maximumProcessLogLineCharacters
|
|
122
141
|
? line.slice(0, maximumProcessLogLineCharacters)
|
|
@@ -19599,11 +19599,21 @@ var appBackendBindingKinds = {
|
|
|
19599
19599
|
requires: ["computer.execute"],
|
|
19600
19600
|
effect: "read"
|
|
19601
19601
|
},
|
|
19602
|
+
gitChanges: {
|
|
19603
|
+
cap: "app.computer.read",
|
|
19604
|
+
requires: ["computer.readFile"],
|
|
19605
|
+
effect: "read"
|
|
19606
|
+
},
|
|
19602
19607
|
write: {
|
|
19603
19608
|
cap: "app.computer.write",
|
|
19604
19609
|
requires: ["computer.writeFile"],
|
|
19605
19610
|
effect: "write"
|
|
19606
19611
|
},
|
|
19612
|
+
mkdir: {
|
|
19613
|
+
cap: "app.computer.write",
|
|
19614
|
+
requires: ["computer.writeFile"],
|
|
19615
|
+
effect: "write"
|
|
19616
|
+
},
|
|
19607
19617
|
move: {
|
|
19608
19618
|
cap: "app.computer.write",
|
|
19609
19619
|
requires: ["computer.writeFile"],
|
|
@@ -22285,6 +22295,7 @@ var symbols = {
|
|
|
22285
22295
|
sendPrompts: (0, import_jsx_runtime4.jsxs)("g", { transform: "translate(32 32) scale(1.08) translate(-32 -32)", children: [(0, import_jsx_runtime4.jsx)("g", { transform: "translate(4 13.2) scale(.412 .436)", children: (0, import_jsx_runtime4.jsx)(SpeechBubble, { fill: coral }) }), (0, import_jsx_runtime4.jsx)("g", { transform: "translate(17.1 28.7) scale(.19)", children: (0, import_jsx_runtime4.jsx)(SpeakingMouth, {}) }), (0, import_jsx_runtime4.jsx)(TaperedRay, { fill: mint, transform: "translate(48.1 26.4) rotate(65) scale(1.7 1.28)" }), (0, import_jsx_runtime4.jsx)(TaperedRay, { fill: mint, transform: "translate(48.4 33.8) rotate(110) scale(1.7 1.28)" })] }),
|
|
22286
22296
|
write: (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [(0, import_jsx_runtime4.jsx)(Pencil, {}), (0, import_jsx_runtime4.jsx)(InkTrail, {})] }),
|
|
22287
22297
|
run: (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [(0, import_jsx_runtime4.jsx)("rect", { style: { fill: blue }, x: "6", y: "9", width: "52", height: "43", rx: "7" }), (0, import_jsx_runtime4.jsx)("path", { style: { stroke: cream }, strokeWidth: "5", strokeLinecap: "round", strokeLinejoin: "round", d: "m17 22 9 8-9 8m17 0h12" })] }),
|
|
22298
|
+
stop: (0, import_jsx_runtime4.jsx)("rect", { style: { fill: coral }, x: "12", y: "12", width: "40", height: "40", rx: "9" }),
|
|
22288
22299
|
connected: (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [(0, import_jsx_runtime4.jsx)("path", { fill: "none", style: { stroke: blue }, strokeWidth: "12", strokeLinecap: "round", d: "M34 37Q43 21 26 20H18Q3 20 6 37q2 10 15 9" }), (0, import_jsx_runtime4.jsx)("path", { fill: "none", style: { stroke: coral }, strokeWidth: "12", strokeLinecap: "round", d: "M29 33Q20 50 38 53h8q16-1 12-17-2-11-14-10" }), (0, import_jsx_runtime4.jsx)("path", { style: { stroke: yellow }, strokeWidth: "4", strokeLinecap: "round", d: "m27 4 2 6m10-5-2 7m12 0-5 4" })] }),
|
|
22289
22300
|
working: (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [(0, import_jsx_runtime4.jsx)("ellipse", { style: { fill: mint }, cx: "23", cy: "14", rx: "13", ry: "8", transform: "rotate(-30 23 14)" }), (0, import_jsx_runtime4.jsx)("ellipse", { style: { fill: yellow }, cx: "48", cy: "36", rx: "13", ry: "8", transform: "rotate(35 48 36)" }), (0, import_jsx_runtime4.jsx)("ellipse", { style: { fill: grape }, cx: "22", cy: "48", rx: "13", ry: "8", transform: "rotate(45 22 48)" }), (0, import_jsx_runtime4.jsx)("path", { fill: "none", style: { stroke: figure }, strokeWidth: "3", strokeLinecap: "round", d: "M42 8q13 2 13 13M43 55q-5 5-12 4M5 39q-5-9 1-17" })] }),
|
|
22290
22301
|
complete: (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [(0, import_jsx_runtime4.jsx)("path", { style: { fill: mint }, d: "M32 6q5-8 10 0 9-3 10 6 9 2 5 11 8 6 0 12 3 9-6 11-1 9-10 6-6 8-12 0-9 3-11-6-9-2-6-11-8-6 0-12-3-9 6-11 1-9 10-6Z" }), (0, import_jsx_runtime4.jsx)("path", { fill: "none", style: { stroke: ink }, strokeWidth: "6", strokeLinecap: "round", strokeLinejoin: "round", d: "m23 29 7 7 13-15" }), (0, import_jsx_runtime4.jsx)("path", { style: { stroke: figure }, strokeWidth: "3", strokeLinecap: "round", d: "m4 8 5 6m48-4 5-5M2 24l6 1" })] }),
|
|
@@ -22494,6 +22505,19 @@ import { join as join6 } from "node:path";
|
|
|
22494
22505
|
// src/build.ts
|
|
22495
22506
|
init_snapshot_program_scripts();
|
|
22496
22507
|
|
|
22508
|
+
// src/build/build-memory.ts
|
|
22509
|
+
import { totalmem } from "node:os";
|
|
22510
|
+
var mebibyte = 1024 * 1024;
|
|
22511
|
+
var preferredHeapMib = 4096;
|
|
22512
|
+
function machineMemoryMib() {
|
|
22513
|
+
const constrained = process.constrainedMemory();
|
|
22514
|
+
const bytes = constrained > 0 && constrained < totalmem() ? constrained : totalmem();
|
|
22515
|
+
return Math.floor(bytes / mebibyte);
|
|
22516
|
+
}
|
|
22517
|
+
function buildHeapMib(memoryMib) {
|
|
22518
|
+
return Math.min(preferredHeapMib, Math.floor(memoryMib * 2 / 3));
|
|
22519
|
+
}
|
|
22520
|
+
|
|
22497
22521
|
// src/build/process-group.ts
|
|
22498
22522
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
22499
22523
|
var CleanupError = class extends Error {
|
|
@@ -35742,13 +35766,12 @@ function runHtmlCommand(args2, cwd, env, command = "pnpm", onOutput) {
|
|
|
35742
35766
|
function snapshotPrograms() {
|
|
35743
35767
|
return Promise.resolve().then(() => (init_snapshot_program_scripts(), snapshot_program_scripts_exports));
|
|
35744
35768
|
}
|
|
35745
|
-
var snapshotBuildHeapMegabytes = 4096;
|
|
35746
35769
|
function snapshotBuildEnvironment(sourceSnapshotPath) {
|
|
35747
35770
|
const env = {
|
|
35748
35771
|
PATH: process.env.PATH ?? "/usr/bin:/bin",
|
|
35749
35772
|
HOME: join5(sourceSnapshotPath, ".publisher-home"),
|
|
35750
35773
|
NODE_ENV: "production",
|
|
35751
|
-
NODE_OPTIONS: `--max-old-space-size=${String(
|
|
35774
|
+
NODE_OPTIONS: `--max-old-space-size=${String(buildHeapMib(machineMemoryMib()))}`,
|
|
35752
35775
|
NODE_EXTRA_CA_CERTS: process.env.NODE_EXTRA_CA_CERTS,
|
|
35753
35776
|
SSL_CERT_FILE: process.env.SSL_CERT_FILE,
|
|
35754
35777
|
npm_config_userconfig: "/dev/null",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/computer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"author": "Levi <levi@technomancy.dev>",
|
|
5
5
|
"description": "Cloudflare Computer host for one durable Fungi Computer",
|
|
6
6
|
"type": "module",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"@fungi.computer/capnweb": "0.12.0-fungi.0",
|
|
61
61
|
"@fungi.computer/cloudflare-computer": "0.2.1-fungi.2",
|
|
62
62
|
"@fungi.computer/cordyceps": "0.4.2",
|
|
63
|
-
"@fungi.computer/knapsack": "0.4.
|
|
63
|
+
"@fungi.computer/knapsack": "0.4.12",
|
|
64
64
|
"@fungi.computer/seam": "0.2.5",
|
|
65
65
|
"@fungi.computer/watchdog": "0.1.3",
|
|
66
|
-
"@fungi.computer/computer-contract": "0.
|
|
66
|
+
"@fungi.computer/computer-contract": "0.4.0",
|
|
67
67
|
"effect": "4.0.2",
|
|
68
68
|
"just-bash": "3.4.2",
|
|
69
69
|
"zod": "4.4.3"
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"test:nightly": "bash ../../tooling/proof-runner/run-proof.sh node test/egress-proof.mjs",
|
|
120
120
|
"test:app-method-execution": "node test/app-method-execution-proof.mjs",
|
|
121
121
|
"test:execution-lifecycle": "node test/execution-lifecycle-proof.mjs",
|
|
122
|
-
"test:unit": "bash ../../tooling/proof-runner/hermetic-host.sh -- sh -c \"node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/egress-policy.test.mjs test/preview.test.mjs test/fleet.test.mjs test/proof-worker.test.mjs test/proof-client.test.mjs test/native-readiness.test.mjs test/workspace-sync.test.mjs test/runtime-observer.test.mjs test/files-patch.test.mjs test/exec-output.test.mjs && node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/seam-signature.test.mjs test/local-backend-replay.test.mjs test/machine-link-reopen-replay.test.mjs test/computer-backends.test.mjs test/terminal-welcome.test.mjs test/on-box-vm.test.mjs && node test/terminal-protocol.test.mjs && node test/container-policy.test.mjs && node test/files-adapter-proof.mjs && node test/operation-record-proof.mjs && node test/process-inventory-proof.mjs\"",
|
|
122
|
+
"test:unit": "bash ../../tooling/proof-runner/hermetic-host.sh -- sh -c \"node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/egress-policy.test.mjs test/preview.test.mjs test/process-wait.test.mjs test/fleet.test.mjs test/proof-worker.test.mjs test/proof-client.test.mjs test/native-readiness.test.mjs test/workspace-sync.test.mjs test/runtime-observer.test.mjs test/files-patch.test.mjs test/exec-output.test.mjs && node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/seam-signature.test.mjs test/local-backend-replay.test.mjs test/machine-link-reopen-replay.test.mjs test/computer-backends.test.mjs test/terminal-welcome.test.mjs test/on-box-vm.test.mjs && node test/terminal-protocol.test.mjs && node test/container-policy.test.mjs && node test/files-adapter-proof.mjs && node test/operation-record-proof.mjs && node test/process-inventory-proof.mjs\"",
|
|
123
123
|
"test:fleet-native": "node test/fleet.native.mjs",
|
|
124
124
|
"assemble:image": "node scripts/assemble-image.mjs"
|
|
125
125
|
}
|