@fungi.computer/computer 0.4.1 → 0.5.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.
@@ -1,7 +1,11 @@
1
+ /** The one idle window: a Computer sleeps this long after its last activity. */
1
2
  export declare const computerContainerSleepAfterMs: number;
3
+ /** A kept-awake container's platform backstop: the 24 hour runtime ceiling. */
4
+ export declare const computerKeepAwakeTimeoutMs: number;
2
5
  export declare function hostedComputerContainersPaused(hostedComputers: string | undefined): boolean;
3
6
  export declare class ComputerContainersPausedError extends Error {
4
7
  constructor();
5
8
  }
6
9
  export declare function assertComputerContainersEnabled(hostedComputers: string | undefined): void;
7
- export declare function configureComputerContainer(container: Pick<Container, "setInactivityTimeout"> | undefined): Promise<void>;
10
+ /** The platform inactivity timeout is a backstop; ComputerDO owns idle sleep. */
11
+ export declare function configureComputerContainer(container: Pick<Container, "setInactivityTimeout"> | undefined, keepAwake: boolean): Promise<void>;
@@ -1,5 +1,8 @@
1
1
  import { z } from "zod";
2
+ /** The one idle window: a Computer sleeps this long after its last activity. */
2
3
  export const computerContainerSleepAfterMs = 15 * 60 * 1_000;
4
+ /** A kept-awake container's platform backstop: the 24 hour runtime ceiling. */
5
+ export const computerKeepAwakeTimeoutMs = 24 * 60 * 60 * 1_000;
3
6
  const hostedComputersSchema = z
4
7
  .enum(["enabled", "paused"])
5
8
  .default("enabled")
@@ -17,8 +20,9 @@ export function assertComputerContainersEnabled(hostedComputers) {
17
20
  if (hostedComputerContainersPaused(hostedComputers))
18
21
  throw new ComputerContainersPausedError();
19
22
  }
20
- export async function configureComputerContainer(container) {
23
+ /** The platform inactivity timeout is a backstop; ComputerDO owns idle sleep. */
24
+ export async function configureComputerContainer(container, keepAwake) {
21
25
  if (container === undefined)
22
26
  throw new Error("Computer Durable Object is not container-enabled");
23
- await container.setInactivityTimeout(computerContainerSleepAfterMs);
27
+ await container.setInactivityTimeout(keepAwake ? computerKeepAwakeTimeoutMs : computerContainerSleepAfterMs);
24
28
  }
@@ -3,6 +3,7 @@ export { checkComputerGrant, type ComputerAdmission } from "./admission.js";
3
3
  export { createFleetBacking } from "./backing.js";
4
4
  export { computerActionSchema, computerProvenanceSchema, computerGrantSchema, computerStateSchema, computerFactSchema, ComputerBackingError, type ComputerAction, type ComputerProvenance, type ComputerGrant, type ComputerRuntimeState, type ComputerFact, type ComputerBackendsProjection, type ComputerBackingChange, type LocalBackendAttachInput, type LocalBackendDetachInput, } from "./wire.js";
5
5
  export { ComputerRuntimeUsage } from "./runtime-usage.js";
6
+ export { computerKeepAwake } from "./keep-awake.js";
6
7
  export { computerUsageIntervalSchema, type ComputerUsageInterval, } from "./wire.js";
7
8
  export { createFleetInventory } from "./inventory.js";
8
9
  export { ComputerInventoryError, computerCreateRequestSchema, computerPageSchema, type ComputerCreateRequest, type ComputerPage, type FleetActor, type FleetComputer, } from "./inventory-wire.js";
@@ -3,6 +3,7 @@ export { checkComputerGrant } from "./admission.js";
3
3
  export { createFleetBacking } from "./backing.js";
4
4
  export { computerActionSchema, computerProvenanceSchema, computerGrantSchema, computerStateSchema, computerFactSchema, ComputerBackingError, } from "./wire.js";
5
5
  export { ComputerRuntimeUsage } from "./runtime-usage.js";
6
+ export { computerKeepAwake } from "./keep-awake.js";
6
7
  export { computerUsageIntervalSchema, } from "./wire.js";
7
8
  export { createFleetInventory } from "./inventory.js";
8
9
  export { ComputerInventoryError, computerCreateRequestSchema, computerPageSchema, } from "./inventory-wire.js";
@@ -0,0 +1,4 @@
1
+ import type { WatchdogSqliteOwner } from "@fungi.computer/watchdog";
2
+ /** This Computer's durable Keep awake opt-in. Absence means off: an idle
3
+ * Computer sleeps, and only an intentional opt-in keeps it up and metered. */
4
+ export declare function computerKeepAwake(sql: WatchdogSqliteOwner["sql"], enabled?: boolean): boolean;
@@ -0,0 +1,14 @@
1
+ import { z } from "zod";
2
+ /** This Computer's durable Keep awake opt-in. Absence means off: an idle
3
+ * Computer sleeps, and only an intentional opt-in keeps it up and metered. */
4
+ export function computerKeepAwake(sql, enabled) {
5
+ sql.exec("CREATE TABLE IF NOT EXISTS computer_keep_awake (singleton INTEGER PRIMARY KEY CHECK (singleton=1), enabled INTEGER NOT NULL CHECK (enabled IN (0,1))) STRICT");
6
+ if (enabled !== undefined)
7
+ sql.exec("INSERT INTO computer_keep_awake (singleton,enabled) VALUES (1,?) ON CONFLICT (singleton) DO UPDATE SET enabled=excluded.enabled", enabled ? 1 : 0);
8
+ const row = sql
9
+ .exec("SELECT enabled FROM computer_keep_awake WHERE singleton=1")
10
+ .toArray()[0];
11
+ return row === undefined
12
+ ? false
13
+ : z.union([z.literal(0), z.literal(1)]).parse(row.enabled) === 1;
14
+ }
@@ -88,7 +88,16 @@ export declare class FleetLifecycle {
88
88
  syncRecycledWorkspace(backing: HostedBacking): Promise<void>;
89
89
  private finishVmRecycle;
90
90
  private recycleQuietVms;
91
+ /** Whether this Computer is metered without fresh activity: a dispatch is
92
+ * in flight, or its owner opted into Keep awake. */
93
+ private get awake();
94
+ /** Metering never runs past the last activity of a Computer that is not awake. */
95
+ private billedThrough;
96
+ /** Whether an idle runtime has passed its sleep window. */
97
+ private sleepDue;
91
98
  private observeRuntime;
99
+ /** Whether the runtime still runs, and when it stopped if it does not. */
100
+ private readRuntime;
92
101
  awaitRecycle(): Promise<void>;
93
102
  /** Reconcile durable observations before the host delivers usage facts. */
94
103
  observe(): Promise<HostedBacking[]>;
@@ -4,6 +4,7 @@ import { attachedBackendId, } from "../computer-backends.js";
4
4
  import { z } from "zod";
5
5
  import { ComputerRuntimeUsage } from "./runtime-usage.js";
6
6
  import { checkComputerGrant } from "./admission.js";
7
+ import { computerKeepAwake } from "./keep-awake.js";
7
8
  const vmRecycleAfterMs = 23 * 60 * 60 * 1_000;
8
9
  const vmRecycleQuietMs = 30_000;
9
10
  const runtimeWatchSchema = z.lazy(() => z.coerce.number().int().min(1_000).max(3_600_000).catch(60_000));
@@ -132,15 +133,13 @@ export class FleetLifecycle {
132
133
  throw new FleetGrantRefused();
133
134
  this.#hostedOperations++;
134
135
  try {
135
- if (backing.kind === "platform-container")
136
- this.usage.touchActivity(backing, Date.now());
136
+ this.usage.touchActivity(backing, Date.now());
137
137
  return await run();
138
138
  }
139
139
  finally {
140
140
  this.#hostedOperations--;
141
141
  this.#lastHostedActivity = Date.now();
142
- if (backing.kind === "platform-container")
143
- this.usage.touchActivity(backing, this.#lastHostedActivity);
142
+ this.usage.touchActivity(backing, this.#lastHostedActivity);
144
143
  if (backing.kind === "on-box-vm") {
145
144
  if (!this.usage.hasOpen(backing))
146
145
  this.#facts.push({ kind: "reservation.release" });
@@ -166,8 +165,7 @@ export class FleetLifecycle {
166
165
  return;
167
166
  lastRecordedAt = now;
168
167
  this.#lastHostedActivity = now;
169
- if (backing.kind === "platform-container")
170
- this.usage.touchActivity(backing, now);
168
+ this.usage.touchActivity(backing, now);
171
169
  };
172
170
  if (socket !== null) {
173
171
  const pair = new WebSocketPair();
@@ -267,7 +265,7 @@ export class FleetLifecycle {
267
265
  if (!(current.running && current.runtimeId === row.runtimeId)) {
268
266
  this.usage.observe(row.runtimeId, {
269
267
  running: false,
270
- endedAt: row.requestedAt,
268
+ at: this.billedThrough(row.runtimeId, row.requestedAt),
271
269
  });
272
270
  if (current.running && current.runtimeId !== null)
273
271
  this.containerRuntimeStarted({
@@ -330,32 +328,50 @@ export class FleetLifecycle {
330
328
  }
331
329
  }
332
330
  }
331
+ /** Whether this Computer is metered without fresh activity: a dispatch is
332
+ * in flight, or its owner opted into Keep awake. */
333
+ get awake() {
334
+ return (this.#hostedOperations > 0 || computerKeepAwake(this.ports.storage.sql));
335
+ }
336
+ /** Metering never runs past the last activity of a Computer that is not awake. */
337
+ billedThrough(runtimeId, at) {
338
+ if (this.awake)
339
+ return at;
340
+ return Math.min(at, this.usage.lastActivity(runtimeId, at) ?? at);
341
+ }
342
+ /** Whether an idle runtime has passed its sleep window. */
343
+ sleepDue(runtimeId, now) {
344
+ if (this.awake)
345
+ return false;
346
+ const last = this.usage.lastActivity(runtimeId, now);
347
+ return last !== null && now >= last + computerContainerSleepAfterMs;
348
+ }
333
349
  async observeRuntime(runtimeId, backing, newest) {
334
350
  const now = Date.now();
335
- if (backing.kind === "platform-container") {
336
- const container = this.ports.backend.state.container;
337
- if (newest && container?.running === true) {
338
- const deadline = this.usage.idleDeadline(runtimeId, computerContainerSleepAfterMs, now);
339
- if (deadline !== null &&
340
- this.#hostedOperations === 0 &&
341
- now >= deadline) {
342
- try {
343
- await container.destroy(new Error("Computer idle timeout"));
344
- }
345
- catch (cause) {
346
- this.diagnostic("computer_idle_stop_failed", "idle_stop", cause);
347
- return { running: true, endedAt: now };
348
- }
349
- return { running: false, endedAt: deadline };
350
- }
351
- return { running: true, endedAt: now };
351
+ const { running, exitedAt } = await this.readRuntime(runtimeId, backing, newest, now);
352
+ if (running && this.sleepDue(runtimeId, now)) {
353
+ try {
354
+ await this.destroyRuntime(backing, "Computer idle timeout");
355
+ }
356
+ catch (cause) {
357
+ this.diagnostic("computer_idle_stop_failed", "idle_stop", cause);
358
+ return { running: true, at: this.billedThrough(runtimeId, now) };
352
359
  }
353
- return { running: false, endedAt: now };
360
+ return { running: false, at: this.billedThrough(runtimeId, now) };
354
361
  }
362
+ return { running, at: this.billedThrough(runtimeId, exitedAt) };
363
+ }
364
+ /** Whether the runtime still runs, and when it stopped if it does not. */
365
+ async readRuntime(runtimeId, backing, newest, now) {
366
+ if (backing.kind === "platform-container")
367
+ return {
368
+ running: newest && this.ports.backend.state.container?.running === true,
369
+ exitedAt: now,
370
+ };
355
371
  const state = await this.ports.backend.onBoxVmHost(backing.hostId).state();
356
372
  return {
357
373
  running: state.running && state.runtimeId === runtimeId,
358
- endedAt: state.exit?.exitedAt ?? now,
374
+ exitedAt: Math.min(now, state.exit?.exitedAt ?? now),
359
375
  };
360
376
  }
361
377
  async awaitRecycle() {
@@ -429,12 +445,12 @@ export class FleetLifecycle {
429
445
  await this.ports.backend.state.container.destroy(new Error(reason));
430
446
  return this.observeOpenRuntimes();
431
447
  }
432
- async destroyRuntime(backing) {
448
+ async destroyRuntime(backing, reason = "Computer usage delivery unavailable") {
433
449
  if (backing.kind === "on-box-vm") {
434
450
  await this.ports.backend.onBoxVmHost(backing.hostId).destroy();
435
451
  return;
436
452
  }
437
453
  if (this.ports.backend.state.container !== undefined)
438
- await this.ports.backend.state.container.destroy(new Error("Computer usage delivery unavailable"));
454
+ await this.ports.backend.state.container.destroy(new Error(reason));
439
455
  }
440
456
  }
@@ -4,9 +4,9 @@ import type { ComputerFact, ComputerProvenance, ComputerUsageInterval } from "./
4
4
  /**
5
5
  * Computer-local interval ledger; the host owns usage settlement.
6
6
  *
7
- * A running runtime's checkpoint advances at most once per `checkpointMs`.
8
- * Repeated reads inside one checkpoint expose the same interval so the host
9
- * can deliver it idempotently.
7
+ * A running runtime's checkpoint advances at most once per `checkpointMs`, and
8
+ * only as far as its owner says it is billed through. Repeated reads inside one
9
+ * checkpoint expose the same interval so the host can deliver it idempotently.
10
10
  */
11
11
  export declare class ComputerRuntimeUsage {
12
12
  private readonly sql;
@@ -15,7 +15,8 @@ export declare class ComputerRuntimeUsage {
15
15
  ensure(): void;
16
16
  started(start: ContainerRuntimeStart): void;
17
17
  touchActivity(backing: HostedBacking, at: number): void;
18
- idleDeadline(runtimeId: string, idleMs: number, now: number): number | null;
18
+ /** The last recorded activity of an open runtime; a missing record starts now. */
19
+ lastActivity(runtimeId: string, now: number): number | null;
19
20
  hasOpen(backing: HostedBacking): boolean;
20
21
  hasAnyOpen(): boolean;
21
22
  open(): {
@@ -37,9 +38,13 @@ export declare class ComputerRuntimeUsage {
37
38
  requestRecycle(runtimeId: string, backing: HostedBacking, requestedAt: number): void;
38
39
  finishRecycle(runtimeId: string): void;
39
40
  oldestVmStart(): number | null;
41
+ /**
42
+ * Record a runtime observation. `at` is the end of an ended runtime, or the
43
+ * billed-through time of a running one; checkpoints never move backward.
44
+ */
40
45
  observe(runtimeId: string, observed: {
41
46
  running: boolean;
42
- endedAt: number;
47
+ at: number;
43
48
  }): void;
44
49
  pending(): ComputerUsageInterval[];
45
50
  /** Read delivery facts without changing the retained checkpoint or acknowledgment. */
@@ -3,9 +3,9 @@ import { hostedBackingSchema, } from "../computer-backends.js";
3
3
  /**
4
4
  * Computer-local interval ledger; the host owns usage settlement.
5
5
  *
6
- * A running runtime's checkpoint advances at most once per `checkpointMs`.
7
- * Repeated reads inside one checkpoint expose the same interval so the host
8
- * can deliver it idempotently.
6
+ * A running runtime's checkpoint advances at most once per `checkpointMs`, and
7
+ * only as far as its owner says it is billed through. Repeated reads inside one
8
+ * checkpoint expose the same interval so the host can deliver it idempotently.
9
9
  */
10
10
  export class ComputerRuntimeUsage {
11
11
  sql;
@@ -29,7 +29,8 @@ export class ComputerRuntimeUsage {
29
29
  this.sql.exec("UPDATE hub_computer_runtime_activity SET last_activity_at=MAX(last_activity_at, ?) WHERE runtime_id IN (SELECT runtime_id FROM hub_computer_runtime_usage WHERE backing=? AND ended=0)", at, encodedBacking);
30
30
  this.sql.exec("INSERT OR IGNORE INTO hub_computer_runtime_activity (runtime_id, last_activity_at) SELECT runtime_id, ? FROM hub_computer_runtime_usage WHERE backing=? AND ended=0", at, encodedBacking);
31
31
  }
32
- idleDeadline(runtimeId, idleMs, now) {
32
+ /** The last recorded activity of an open runtime; a missing record starts now. */
33
+ lastActivity(runtimeId, now) {
33
34
  this.ensure();
34
35
  this.sql.exec("INSERT OR IGNORE INTO hub_computer_runtime_activity (runtime_id, last_activity_at) SELECT runtime_id, ? FROM hub_computer_runtime_usage WHERE runtime_id=? AND ended=0", now, runtimeId);
35
36
  const row = this.sql
@@ -37,7 +38,7 @@ export class ComputerRuntimeUsage {
37
38
  .toArray()[0];
38
39
  return row === undefined
39
40
  ? null
40
- : z.number().int().nonnegative().parse(row.last_activity_at) + idleMs;
41
+ : z.number().int().nonnegative().parse(row.last_activity_at);
41
42
  }
42
43
  hasOpen(backing) {
43
44
  this.ensure();
@@ -102,13 +103,16 @@ export class ComputerRuntimeUsage {
102
103
  .exec("SELECT MIN(started_at) AS started_at FROM hub_computer_runtime_usage WHERE ended=0 AND json_extract(backing,'$.kind')='on-box-vm'")
103
104
  .toArray()[0]?.started_at ?? null);
104
105
  }
106
+ /**
107
+ * Record a runtime observation. `at` is the end of an ended runtime, or the
108
+ * billed-through time of a running one; checkpoints never move backward.
109
+ */
105
110
  observe(runtimeId, observed) {
106
111
  if (!observed.running) {
107
- this.sql.exec("UPDATE hub_computer_runtime_usage SET observed_at = MAX(observed_at, ?), ended = 1 WHERE runtime_id = ?", observed.endedAt, runtimeId);
112
+ this.sql.exec("UPDATE hub_computer_runtime_usage SET observed_at = MAX(observed_at, ?), ended = 1 WHERE runtime_id = ?", observed.at, runtimeId);
108
113
  return;
109
114
  }
110
- const now = Date.now();
111
- this.sql.exec("UPDATE hub_computer_runtime_usage SET observed_at = ? WHERE runtime_id = ? AND ended = 0 AND observed_at <= ?", now, runtimeId, now - this.checkpointMs);
115
+ this.sql.exec("UPDATE hub_computer_runtime_usage SET observed_at = ? WHERE runtime_id = ? AND ended = 0 AND observed_at < ? AND observed_at <= ?", observed.at, runtimeId, observed.at, Date.now() - this.checkpointMs);
112
116
  }
113
117
  pending() {
114
118
  return this.sql
@@ -75,6 +75,7 @@ export declare const computerStateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
75
75
  running: "running";
76
76
  sleeping: "sleeping";
77
77
  starting: "starting";
78
+ start_failed: "start_failed";
78
79
  }>;
79
80
  }, z.core.$strict>, z.ZodObject<{
80
81
  state: z.ZodLiteral<"queued">;
@@ -197,6 +198,7 @@ export declare const computerFactSchema: z.ZodLazy<z.ZodDiscriminatedUnion<[z.Zo
197
198
  running: "running";
198
199
  sleeping: "sleeping";
199
200
  starting: "starting";
201
+ start_failed: "start_failed";
200
202
  }>;
201
203
  }, z.core.$strict>, z.ZodObject<{
202
204
  state: z.ZodLiteral<"queued">;
@@ -32,7 +32,10 @@ export const computerGrantSchema = z.strictObject({
32
32
  });
33
33
  /** State visible without knowing which application hosts the Computer. */
34
34
  export const computerStateSchema = z.discriminatedUnion("state", [
35
- z.strictObject({ state: z.enum(["running", "sleeping", "starting"]) }),
35
+ // start_failed: a queued start ended without running; start again.
36
+ z.strictObject({
37
+ state: z.enum(["running", "sleeping", "starting", "start_failed"]),
38
+ }),
36
39
  z.strictObject({
37
40
  state: z.literal("queued"),
38
41
  position: z.number().int().positive(),
package/dist/index.d.ts CHANGED
@@ -140,6 +140,11 @@ export declare class ComputerDO extends ContainerComputer implements ComputerFil
140
140
  constructor(ctx: DurableObjectState, env: ComputerEnv);
141
141
  /** Host-admitted settings write; egress reads the current durable value. */
142
142
  internetAccess(enabled?: boolean): boolean;
143
+ /**
144
+ * Host-admitted Keep awake write. The fleet's idle policy and metering read
145
+ * the durable value; a container's platform backstop follows it.
146
+ */
147
+ keepAwake(enabled?: boolean): Promise<boolean>;
143
148
  /** Ordinary Computers have no credential host; resource hosts override it. */
144
149
  protected executionHooks(): ComputerExecutionHostHooks | undefined;
145
150
  /**
package/dist/index.js CHANGED
@@ -74,8 +74,9 @@ import { ComputerOperationRecord } from "./operation-record.js";
74
74
  import { createComputerExecutionLifecycle } from "./execution-lifecycle.js";
75
75
  import { applyWorkspacePatch } from "./files-patch.js";
76
76
  import { ComputerProcessInventory, drainProcessExit, failedObservation, observeProcess, } from "./process-inventory.js";
77
- import { assertComputerContainersEnabled, computerContainerSleepAfterMs, ComputerContainersPausedError, configureComputerContainer, hostedComputerContainersPaused, } from "./container-policy.js";
77
+ import { assertComputerContainersEnabled, ComputerContainersPausedError, configureComputerContainer, hostedComputerContainersPaused, } from "./container-policy.js";
78
78
  import { OnBoxVmContainerHost, onBoxVmPlacement, } from "./on-box-vm.js";
79
+ import { computerKeepAwake } from "./fleet/keep-awake.js";
79
80
  import { attachedBackendId, describeAttachedBackend, routeComputerBackend, } from "./computer-backends.js";
80
81
  import { MeteredContainerHost } from "./metered-container-host.js";
81
82
  import { LocalBackendConnections, LocalWorkspaceBackend, localBackendDialPath, verifyLocalBackendDial, } from "./local-backend.js";
@@ -237,7 +238,7 @@ class ContainerComputer extends ContainerComputerBase {
237
238
  if (ctx.container === undefined ||
238
239
  hostedComputerContainersPaused(env.HOSTED_COMPUTERS))
239
240
  return;
240
- ctx.waitUntil(configureComputerContainer(ctx.container));
241
+ ctx.waitUntil(configureComputerContainer(ctx.container, computerKeepAwake(ctx.storage.sql)));
241
242
  }
242
243
  getWorkspaceContainer() {
243
244
  assertComputerContainersEnabled(this.bindings.HOSTED_COMPUTERS);
@@ -352,7 +353,7 @@ class ContainerComputer extends ContainerComputerBase {
352
353
  }
353
354
  /** Let the consuming owner admit boots while preserving the runtime host seam. */
354
355
  createOnBoxVmHost(placement) {
355
- return new OnBoxVmContainerHost(placement, this.bindings, this.state.id.toString(), computerContainerSleepAfterMs);
356
+ return new OnBoxVmContainerHost(placement, this.bindings, this.state.id.toString());
356
357
  }
357
358
  /** Whether a hosted backend's runtime is running now. */
358
359
  async containerRunning(backing) {
@@ -490,6 +491,18 @@ export class ComputerDO extends ContainerComputer {
490
491
  internetAccess(enabled) {
491
492
  return computerInternetAccess(this.state.storage.sql, enabled);
492
493
  }
494
+ /**
495
+ * Host-admitted Keep awake write. The fleet's idle policy and metering read
496
+ * the durable value; a container's platform backstop follows it.
497
+ */
498
+ async keepAwake(enabled) {
499
+ const kept = computerKeepAwake(this.state.storage.sql, enabled);
500
+ if (enabled !== undefined &&
501
+ this.state.container !== undefined &&
502
+ !hostedComputerContainersPaused(this.bindings.HOSTED_COMPUTERS))
503
+ await configureComputerContainer(this.state.container, kept);
504
+ return kept;
505
+ }
493
506
  #binaryFileTail = Promise.resolve(undefined);
494
507
  #operationRecord;
495
508
  #processRecord;
@@ -74,7 +74,7 @@ export declare class OnBoxVmTimeoutError extends OnBoxVmTimeoutError_base<{
74
74
  /** One Durable Object's view of its microVM through the host service. */
75
75
  export declare class OnBoxVmContainerHost implements IWorkspaceContainerAPI {
76
76
  #private;
77
- constructor(placement: OnBoxVmPlacement, env: OnBoxVmEnv, vmId: string, sleepAfterMs: number);
77
+ constructor(placement: OnBoxVmPlacement, env: OnBoxVmEnv, vmId: string);
78
78
  /** Signed host-wide inventory; includes VMs outside this Hub's directory. */
79
79
  inventory(): Promise<OnBoxVmInventory>;
80
80
  start(env: Record<string, string>, enableInternet: boolean): Promise<{
package/dist/on-box-vm.js CHANGED
@@ -90,6 +90,11 @@ const vmInventorySchema = z.array(vmStateSchema.extend({
90
90
  const vmStartSchema = z.lazy(() => z.strictObject({
91
91
  runtimeId: z.string().min(1).max(128),
92
92
  }));
93
+ /**
94
+ * vmd's own traffic timer is only a backstop at its maximum: ComputerDO owns
95
+ * idle sleep, so a kept-awake VM is not stopped by the host while it is quiet.
96
+ */
97
+ const vmHostSleepBackstopMs = 24 * 60 * 60 * 1_000;
93
98
  /** A bounded control-plane wait, not the VM's execution or allocation lifetime. */
94
99
  const vmControlTimeoutMs = 60_000;
95
100
  /** The host's outcome is unknown after a timeout; this is not evidence of offline. */
@@ -119,15 +124,13 @@ export class OnBoxVmContainerHost {
119
124
  #placement;
120
125
  #env;
121
126
  #vmId;
122
- #sleepAfterMs;
123
- constructor(placement, env, vmId, sleepAfterMs) {
127
+ constructor(placement, env, vmId) {
124
128
  this.#placement = placement;
125
129
  this.#env = env;
126
130
  this.#vmId = z
127
131
  .string()
128
132
  .regex(/^[0-9a-f]{64}$/)
129
133
  .parse(vmId);
130
- this.#sleepAfterMs = sleepAfterMs;
131
134
  }
132
135
  async #call(operation, schema, body) {
133
136
  let path = `/vms/${this.#vmId}`;
@@ -161,7 +164,7 @@ export class OnBoxVmContainerHost {
161
164
  const started = await this.#call(operation, vmStartSchema, {
162
165
  env,
163
166
  enableInternet,
164
- sleepAfterMs: this.#sleepAfterMs,
167
+ sleepAfterMs: vmHostSleepBackstopMs,
165
168
  });
166
169
  return { runtimeId: started.runtimeId };
167
170
  }
@@ -19718,6 +19718,7 @@ var appCapabilityIds = [
19718
19718
  "computer.execute",
19719
19719
  "llm.generation",
19720
19720
  "media.generation",
19721
+ "media.share",
19721
19722
  "games:servers",
19722
19723
  "git.repository",
19723
19724
  "apps.open",
@@ -22397,6 +22398,8 @@ var symbols = {
22397
22398
  sell: (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [(0, import_jsx_runtime4.jsx)("path", { fill: yellow, d: "M6.4 41.2V48.4C6.4 51.4 13.2 54 21.8 54S37.2 51.4 37.2 48.4V41.2C37.2 37.8 30.4 35 21.8 35S6.4 37.8 6.4 41.2Z" }), (0, import_jsx_runtime4.jsx)("ellipse", { fill: cream, cx: "21.9", cy: "40.8", rx: "13.2", ry: "3.6" }), (0, import_jsx_runtime4.jsxs)("g", { transform: "rotate(-3 22.5 30) translate(0.5 0)", children: [(0, import_jsx_runtime4.jsx)("path", { fill: yellow, d: "M7.5 26V34C7.5 37.3 14.2 40 22.5 40S37.5 37.3 37.5 34V26C37.5 22.7 30.8 20 22.5 20S7.5 22.7 7.5 26Z" }), (0, import_jsx_runtime4.jsx)("ellipse", { fill: cream, cx: "23.7", cy: "26.55", rx: "13.05", ry: "4.4" })] }), (0, import_jsx_runtime4.jsxs)("g", { transform: "translate(46.3 40.3) rotate(-25)", children: [(0, import_jsx_runtime4.jsx)("path", { fill: coral, d: "M-8.5-10Q-8.5-12-7-13L-1.5-16.3Q0-17.2 1.5-16.3L7-13Q8.5-12 8.5-10V9Q8.5 12 5.5 12H-5.5Q-8.5 12-8.5 9Z" }), (0, import_jsx_runtime4.jsx)("circle", { fill: cream, cx: "0", cy: "-10.7", r: "2.2" })] }), (0, import_jsx_runtime4.jsx)(TaperedRay, { fill: yellow, transform: "translate(38.2 18.6) scale(1.1 .86)" }), (0, import_jsx_runtime4.jsx)(TaperedRay, { fill: yellow, transform: "translate(42.8 21.2) rotate(45) scale(1.1 .85)" })] }),
22398
22399
  // Schedules and recurring runs: a calendar page with a clock.
22399
22400
  schedule: (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [(0, import_jsx_runtime4.jsx)("rect", { fill: cream, x: "6", y: "11", width: "47.6", height: "44", rx: "6" }), (0, import_jsx_runtime4.jsx)("path", { fill: coral, d: "M12 11H47.6Q53.6 11 53.6 17V21.5H6V17Q6 11 12 11Z" }), (0, import_jsx_runtime4.jsxs)("g", { fill: cream, children: [(0, import_jsx_runtime4.jsx)("circle", { cx: "16.1", cy: "16.15", r: "3.4" }), (0, import_jsx_runtime4.jsx)("circle", { cx: "43.4", cy: "16.15", r: "3.4" })] }), (0, import_jsx_runtime4.jsxs)("g", { fill: blue, children: [(0, import_jsx_runtime4.jsx)("rect", { x: "13.6", y: "6", width: "5", height: "11.2", rx: "2.5" }), (0, import_jsx_runtime4.jsx)("rect", { x: "40.9", y: "6", width: "5", height: "11.2", rx: "2.5" })] }), (0, import_jsx_runtime4.jsxs)("g", { fill: mint, children: [(0, import_jsx_runtime4.jsx)("rect", { x: "11.1", y: "25.1", width: "6.9", height: "6.6", rx: "1.8" }), (0, import_jsx_runtime4.jsx)("rect", { x: "20.7", y: "25.1", width: "6.9", height: "6.6", rx: "1.8" }), (0, import_jsx_runtime4.jsx)("rect", { x: "30.4", y: "25.1", width: "6.9", height: "6.6", rx: "1.8" }), (0, import_jsx_runtime4.jsx)("rect", { x: "20.7", y: "33.9", width: "6.9", height: "6.6", rx: "1.8" }), (0, import_jsx_runtime4.jsx)("rect", { x: "30.4", y: "33.9", width: "6.9", height: "6.6", rx: "1.8" }), (0, import_jsx_runtime4.jsx)("rect", { x: "11.1", y: "42.7", width: "6.9", height: "6.6", rx: "1.8" }), (0, import_jsx_runtime4.jsx)("rect", { x: "30.4", y: "42.7", width: "6.9", height: "6.6", rx: "1.8" })] }), (0, import_jsx_runtime4.jsxs)("g", { fill: grape, children: [(0, import_jsx_runtime4.jsx)("rect", { x: "40.4", y: "25.1", width: "6.9", height: "6.6", rx: "1.8" }), (0, import_jsx_runtime4.jsx)("rect", { x: "11.1", y: "33.9", width: "6.9", height: "6.6", rx: "1.8" }), (0, import_jsx_runtime4.jsx)("rect", { x: "20.7", y: "42.7", width: "6.9", height: "6.6", rx: "1.8" })] }), (0, import_jsx_runtime4.jsx)("circle", { fill: yellow, cx: "45.5", cy: "45.6", r: "12.2" }), (0, import_jsx_runtime4.jsx)("path", { fill: "none", stroke: ink, strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round", d: "M45.1 39.3V46.2L51.3 49.8" }), (0, import_jsx_runtime4.jsx)("circle", { fill: ink, cx: "45.1", cy: "46.2", r: "2.5" })] }),
22401
+ // Loop: one prompt inside a returning circular arrow.
22402
+ loop: (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [(0, import_jsx_runtime4.jsx)("path", { style: { stroke: coral }, strokeWidth: "6", strokeLinecap: "round", d: "M47.5 14.5C43 11 37.5 9 32 9 19.5 9 9 19.5 9 32S19.5 55 32 55 55 44.5 55 32" }), (0, import_jsx_runtime4.jsx)("path", { style: { fill: coral }, d: "M53.5 21.5Q54.5 20 55 22L58 33Q58.5 35 56.5 34.5L48.5 32.5Q47 32 48 30.5Z" }), (0, import_jsx_runtime4.jsx)("g", { transform: "translate(18 21) scale(.28)", children: (0, import_jsx_runtime4.jsx)(SpeechBubble, { fill: blue }) }), (0, import_jsx_runtime4.jsxs)("g", { style: { fill: cream }, children: [(0, import_jsx_runtime4.jsx)("rect", { x: "25", y: "27.5", width: "14", height: "3", rx: "1.5" }), (0, import_jsx_runtime4.jsx)("rect", { x: "25", y: "33.5", width: "9", height: "3", rx: "1.5" })] })] }),
22400
22403
  // Fungi: Shiitake, the brand mushroom, winking.
22401
22404
  fungi: (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [(0, import_jsx_runtime4.jsx)("ellipse", { fill: cream, cx: "33.5", cy: "43.6", rx: "18.6", ry: "14.4", transform: "rotate(-6 33.5 43.6)" }), (0, import_jsx_runtime4.jsx)("path", { fill: coral, d: "M29.5 6.5C22 7.5 16 11 11 18.5 4 29 4.6 39.6 13.5 42.2 24 45 44 40.5 54 34.6 57.6 32.6 58.6 29.2 57.5 25 56.5 20 53 16 48.5 13 43.5 8 37 5.5 29.5 6.5Z" }), (0, import_jsx_runtime4.jsxs)("g", { fill: cream, children: [(0, import_jsx_runtime4.jsx)("ellipse", { cx: "29", cy: "15.7", rx: "8.7", ry: "6.3", transform: "rotate(-15.5 29 15.7)" }), (0, import_jsx_runtime4.jsx)("ellipse", { cx: "50.8", cy: "20.1", rx: "6.5", ry: "3.5", transform: "rotate(51.6 50.8 20.1)" }), (0, import_jsx_runtime4.jsx)("ellipse", { cx: "13", cy: "26.8", rx: "4.2", ry: "3.3", transform: "rotate(-54.5 13 26.8)" })] }), (0, import_jsx_runtime4.jsxs)("g", { fill: ink, transform: "translate(26.6 46.6) scale(1.1) translate(-33.7 -38.5)", children: [(0, import_jsx_runtime4.jsx)("rect", { x: "31.85", y: "35.9", width: "3.75", height: "5.25", rx: "1.85" }), (0, import_jsx_runtime4.jsx)("path", { d: "M 47.4 34.3 C 46 35 44.6 35.8 43.5 36.7 42.9 37.2 43.2 38.3 44 38.4 45.2 38.6 46.5 38.6 47.7 38.4 48.4 38.3 48.3 37.3 47.6 37.3 46.6 37.4 45.7 37.4 45 37.3 45.9 36.7 46.9 36.1 48 35.6 48.7 35.3 48.2 34 47.4 34.3 Z" }), (0, import_jsx_runtime4.jsx)("path", { d: "M 37.4 41.1 C 38.6 44.3 42.6 44.3 43.6 40.5 43.7 40 43.1 39.8 42.9 40.3 41.9 42.8 39.1 42.9 38.3 40.7 38.1 40.2 37.3 40.5 37.4 41.1 Z" })] })] })
22402
22405
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/computer",
3
- "version": "0.4.1",
3
+ "version": "0.5.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",
61
61
  "@fungi.computer/cloudflare-computer": "0.2.1-fungi.2",
62
62
  "@fungi.computer/cordyceps": "0.4.0",
63
- "@fungi.computer/knapsack": "0.4.2",
63
+ "@fungi.computer/knapsack": "0.4.4",
64
64
  "@fungi.computer/seam": "0.2.0",
65
65
  "@fungi.computer/watchdog": "0.1.0",
66
- "@fungi.computer/computer-contract": "0.0.7",
66
+ "@fungi.computer/computer-contract": "0.0.9",
67
67
  "effect": "4.0.2",
68
68
  "just-bash": "3.4.2",
69
69
  "zod": "4.4.3"
@@ -118,9 +118,8 @@
118
118
  "test:nightly": "bash ../../tooling/proof-runner/run-proof.sh node test/egress-proof.mjs",
119
119
  "test:app-method-execution": "node test/app-method-execution-proof.mjs",
120
120
  "test:execution-lifecycle": "node test/execution-lifecycle-proof.mjs",
121
- "test:unit": "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/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",
121
+ "test:unit": "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
122
  "test:fleet-native": "node test/fleet.native.mjs",
123
- "test:light-shell:native": "node --import tsx test/light-shell.native.mjs --state",
124
123
  "assemble:image": "node scripts/assemble-image.mjs"
125
124
  }
126
125
  }