@fungi.computer/computer 0.8.3 → 0.8.5

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/Dockerfile CHANGED
@@ -60,10 +60,10 @@ COPY --from=terminal /opt/fungi/node_modules /opt/fungi/node_modules
60
60
  COPY container/runtime-privileges.mjs /opt/fungi/
61
61
  COPY --from=terminal /opt/fungi/runtime-privileges.node /opt/fungi/
62
62
  COPY container/package.json container/computer-init.mjs container/computer-start.sh container/resource-bounds.mjs container/terminal-server.mjs container/terminal-runtime.mjs container/terminal-protocol.mjs /opt/fungi/
63
- COPY container/terminal-assets/bashrc container/terminal-assets/git-prompt.sh /opt/fungi/terminal-assets/
63
+ COPY container/terminal-assets/bashrc container/terminal-assets/git-prompt.sh container/terminal-assets/global-tools.sh /opt/fungi/terminal-assets/
64
64
  RUN chmod -R a+rX /opt/fungi \
65
65
  && printf '\n. /opt/fungi/terminal-assets/bashrc\n' >> /etc/bash.bashrc \
66
- && printf '. /opt/fungi/terminal-assets/bashrc\n' > /etc/profile.d/fungi-terminal.sh
66
+ && printf '. /opt/fungi/terminal-assets/global-tools.sh\n. /opt/fungi/terminal-assets/bashrc\n' > /etc/profile.d/fungi-terminal.sh
67
67
 
68
68
  # No customer process can invoke a setuid/setgid helper, including fusermount.
69
69
  # FUSE is mounted while init is root, before either runtime listener opens.
@@ -21,4 +21,13 @@ chown "$uid:$uid" /workspace
21
21
  ulimit -Su "$pids_max"
22
22
  ulimit -Hu "$pids_max"
23
23
  export HOME=/workspace
24
+ # The image's npm and pnpm prefixes are root-owned. Global installs go into
25
+ # user-owned folders in the persistent home; npm and pnpm create them on first
26
+ # use as this UID. Every Computer process (computerd exec, terminal) inherits
27
+ # this environment. terminal-assets/global-tools.sh (sourced from
28
+ # /etc/profile.d) restores the PATH entries for login shells, because Debian's
29
+ # /etc/profile resets PATH.
30
+ export NPM_CONFIG_PREFIX="$HOME/.npm-global"
31
+ export PNPM_HOME="$HOME/.local/share/pnpm"
32
+ export PATH="$NPM_CONFIG_PREFIX/bin:$PNPM_HOME/bin:$PATH"
24
33
  exec node /opt/fungi/computer-init.mjs
@@ -33,3 +33,7 @@ proof checks real cells at wide and narrow widths, connection ordering, retries
33
33
  and theme replay. Computerd command execution is separate and receives no
34
34
  welcome bytes. Local image proof checks the prompt and absence of art/hints on
35
35
  an interactive PTY, plus quiet non-interactive startup.
36
+
37
+ `global-tools.sh` restores the user-owned npm and pnpm global folders on PATH
38
+ for login shells (Debian's `/etc/profile` resets PATH); `computer-start.sh` sets
39
+ `NPM_CONFIG_PREFIX` and `PNPM_HOME` for every Computer process.
@@ -0,0 +1,10 @@
1
+ # Debian's /etc/profile resets PATH for login shells, dropping the user-owned
2
+ # global tool folders computer-start.sh put on every Computer process's PATH.
3
+ # Restore them (idempotently) so `npm install -g` and `pnpm add -g` binaries
4
+ # resolve in login shells too, interactive or not.
5
+ [ -n "${NPM_CONFIG_PREFIX:-}" ] || return 0
6
+ case ":$PATH:" in
7
+ *":$NPM_CONFIG_PREFIX/bin:"*) ;;
8
+ *) PATH="$NPM_CONFIG_PREFIX/bin:${PNPM_HOME:+$PNPM_HOME/bin:}$PATH" ;;
9
+ esac
10
+ export PATH
@@ -0,0 +1,9 @@
1
+ import type { WatchdogSqliteOwner } from "@fungi.computer/watchdog";
2
+ /** Record the name a name-addressed wake carries. */
3
+ export declare function recordComputerName(sql: WatchdogSqliteOwner["sql"], name: string): void;
4
+ /**
5
+ * The wake's own name, else the recorded one. Read-only: it never recreates
6
+ * the record after an erasure. Undefined only when no name-addressed wake has
7
+ * reached this Computer.
8
+ */
9
+ export declare function computerName(sql: WatchdogSqliteOwner["sql"], wokenAs: string | undefined): string | undefined;
@@ -0,0 +1,38 @@
1
+ import { z } from "zod";
2
+ /*
3
+ * A Computer's durable name, recorded by each name-addressed wake.
4
+ *
5
+ * `ctx.id.name` belongs to the wake that constructed the live instance, not to
6
+ * the object. The doors that address a Computer by object id (the container's
7
+ * WorkspaceProxy reconnect and egress, the service proxy, VM ingress) and
8
+ * alarms wake it with no name, and every later name-addressed call reaches
9
+ * that same nameless instance. A redeploy restarts the object while its
10
+ * container reconnects, so a nameless instance reads the name from storage.
11
+ */
12
+ /** Record the name a name-addressed wake carries. */
13
+ export function recordComputerName(sql, name) {
14
+ sql.exec("CREATE TABLE IF NOT EXISTS computer_name (singleton INTEGER PRIMARY KEY CHECK (singleton=1), name TEXT NOT NULL) STRICT");
15
+ sql.exec("INSERT INTO computer_name (singleton,name) VALUES (1,?) ON CONFLICT (singleton) DO NOTHING", name);
16
+ // An object id is derived from its name, so a second name is corruption.
17
+ if (storedComputerName(sql) !== name)
18
+ throw new Error("Computer storage records a different name");
19
+ }
20
+ /**
21
+ * The wake's own name, else the recorded one. Read-only: it never recreates
22
+ * the record after an erasure. Undefined only when no name-addressed wake has
23
+ * reached this Computer.
24
+ */
25
+ export function computerName(sql, wokenAs) {
26
+ return wokenAs ?? storedComputerName(sql);
27
+ }
28
+ function storedComputerName(sql) {
29
+ const recorded = sql
30
+ .exec("SELECT 1 FROM sqlite_master WHERE type='table' AND name='computer_name'")
31
+ .toArray().length > 0;
32
+ if (!recorded)
33
+ return undefined;
34
+ const row = sql
35
+ .exec("SELECT name FROM computer_name WHERE singleton=1")
36
+ .toArray()[0];
37
+ return row === undefined ? undefined : z.string().parse(row.name);
38
+ }
package/dist/index.d.ts CHANGED
@@ -78,6 +78,12 @@ declare class ContainerComputer extends ContainerComputerBase {
78
78
  /** Parked dial-ins from attached machines; survives Workspace rebuilds. */
79
79
  readonly localConnections: LocalBackendConnections;
80
80
  constructor(ctx: DurableObjectState, env: ComputerEnv);
81
+ /**
82
+ * This Computer's name, from storage: an instance first woken by object id
83
+ * has no `ctx.id.name` for its whole life. Undefined only when no
84
+ * name-addressed wake has reached this Computer yet.
85
+ */
86
+ protected computerName(): string | undefined;
81
87
  getWorkspaceContainer(): import("@fungi.computer/cloudflare-computer/backends/container").WorkspaceContainerAPI;
82
88
  /**
83
89
  * This Computer's attached backends, in attach order. The standalone
@@ -302,6 +308,7 @@ export declare class ComputerDO extends ContainerComputer implements ComputerFil
302
308
  protected replaceFileIfUnchangedAfterAcceptance(input: ComputerFileReplacement, accept: () => void): Promise<ComputerFileReplacementResult>;
303
309
  }
304
310
  export { WorkspaceProxy, WorkspaceServiceProxy };
311
+ export { computerName } from "./computer-name.js";
305
312
  export { OnBoxVmContainerHost, OnBoxVmTimeoutError, onBoxVmPlacement, onBoxVmIngress, type OnBoxVmEnv, type OnBoxVmOperation, type OnBoxVmState, } from "./on-box-vm.js";
306
313
  export { computerContainerSleepAfterMs } from "./container-policy.js";
307
314
  export * from "./computer-backends.js";
package/dist/index.js CHANGED
@@ -53,6 +53,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
53
53
  import { boundExecStream } from "./exec-output.js";
54
54
  export { createLocalBackendReplayStore } from "./local-backend-replay.js";
55
55
  import { computerInternetAccess } from "./internet-access.js";
56
+ import { computerName, recordComputerName } from "./computer-name.js";
56
57
  import { getWorkspace, SQLiteWorkspaceProvider, Workspace, WorkspaceProxy, WorkspaceServiceProxy, } from "@fungi.computer/cloudflare-computer";
57
58
  import { WorkerShellBackend, } from "@fungi.computer/cloudflare-computer/backends/worker-shell";
58
59
  import jqCommands from "@fungi.computer/cloudflare-computer/shell/jq";
@@ -235,11 +236,21 @@ class ContainerComputer extends ContainerComputerBase {
235
236
  #pullPending = new PullPendingTracker();
236
237
  constructor(ctx, env) {
237
238
  super(ctx, env);
239
+ if (ctx.id.name !== undefined)
240
+ recordComputerName(ctx.storage.sql, ctx.id.name);
238
241
  if (ctx.container === undefined ||
239
242
  hostedComputerContainersPaused(env.HOSTED_COMPUTERS))
240
243
  return;
241
244
  ctx.waitUntil(configureComputerContainer(ctx.container, computerKeepAwake(ctx.storage.sql)));
242
245
  }
246
+ /**
247
+ * This Computer's name, from storage: an instance first woken by object id
248
+ * has no `ctx.id.name` for its whole life. Undefined only when no
249
+ * name-addressed wake has reached this Computer yet.
250
+ */
251
+ computerName() {
252
+ return computerName(this.state.storage.sql, this.state.id.name);
253
+ }
243
254
  getWorkspaceContainer() {
244
255
  assertComputerContainersEnabled(this.bindings.HOSTED_COMPUTERS);
245
256
  return super.getWorkspaceContainer();
@@ -280,7 +291,7 @@ class ContainerComputer extends ContainerComputerBase {
280
291
  const backend = this.attachedBackends().find((candidate) => candidate.kind === "local" &&
281
292
  attachedBackendId(candidate) === backendId);
282
293
  if (backend === undefined ||
283
- computerName !== this.state.id.name ||
294
+ computerName !== this.computerName() ||
284
295
  !(await verifyLocalBackendDial(request, computerName, backend, this.state.storage)))
285
296
  return new Response(null, { status: 404 });
286
297
  // A verified plain request lets the machine tell attached from detached.
@@ -1535,7 +1546,7 @@ export class ComputerDO extends ContainerComputer {
1535
1546
  /** Host-owned display labels only; never credentials or provider URLs. */
1536
1547
  terminalDisplayEnvironment() {
1537
1548
  return Promise.resolve({
1538
- FUNGI_COMPUTER_NAME: this.state.id.name ?? "Computer",
1549
+ FUNGI_COMPUTER_NAME: this.computerName() ?? "Computer",
1539
1550
  });
1540
1551
  }
1541
1552
  /** Atomically replace one bounded file only when its raw contents still match. */
@@ -1567,6 +1578,7 @@ export class ComputerDO extends ContainerComputer {
1567
1578
  // Runtime backends reach the authoritative Workspace through these loopback
1568
1579
  // entrypoints. The consuming Worker must re-export both from its main module.
1569
1580
  export { WorkspaceProxy, WorkspaceServiceProxy };
1581
+ export { computerName } from "./computer-name.js";
1570
1582
  export { OnBoxVmContainerHost, OnBoxVmTimeoutError, onBoxVmPlacement, onBoxVmIngress, } from "./on-box-vm.js";
1571
1583
  export { computerContainerSleepAfterMs } from "./container-policy.js";
1572
1584
  export * from "./computer-backends.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/computer",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Cloudflare Computer host for one durable Fungi Computer",
6
6
  "type": "module",