@fungi.computer/computer 0.18.1 → 0.18.3

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.
@@ -0,0 +1,29 @@
1
+ import type { ComputerExecOutput } from "@fungi.computer/computer-contract";
2
+ /**
3
+ * How far one command got. `preparing` is everything before the runtime is
4
+ * asked to start it, so nothing ran; `dispatched` means the runtime may have
5
+ * started it and its result was lost.
6
+ */
7
+ export type CommandStage = "preparing" | "dispatched";
8
+ export type CommandFailure = Readonly<{
9
+ kind: "not_started";
10
+ output: ComputerExecOutput;
11
+ }> | Readonly<{
12
+ kind: "unknown";
13
+ cause: string;
14
+ }>;
15
+ /**
16
+ * Turn a thrown command failure into what the caller is told. A command that
17
+ * never reached dispatch did not run: that is a failed result carrying its
18
+ * cause. A command that may have started has no established outcome, so it
19
+ * stays unknown, but never without its cause; for a hosted command only the
20
+ * error name, since its runtime may echo env or stdin. `secrets` are credential values
21
+ * handed to the command; they never appear in the reported text.
22
+ */
23
+ export declare function describeCommandFailure(input: Readonly<{
24
+ stage: CommandStage;
25
+ cause: unknown;
26
+ secrets: readonly string[];
27
+ /** A host-credentialed command: its runtime errors may echo carriage values. */
28
+ hosted: boolean;
29
+ }>): CommandFailure;
@@ -0,0 +1,46 @@
1
+ /** Longest cause text reported to a caller. */
2
+ const maximumCauseCharacters = 400;
3
+ function causeText(cause) {
4
+ return cause instanceof Error
5
+ ? `${cause.name}: ${cause.message}`
6
+ : `Computer execution rejected with ${String(cause)}`;
7
+ }
8
+ function redact(text, secrets) {
9
+ let result = text;
10
+ for (const secret of secrets)
11
+ if (secret.length >= 8)
12
+ result = result.replaceAll(secret, "[redacted]");
13
+ return result.length > maximumCauseCharacters
14
+ ? `${result.slice(0, maximumCauseCharacters - 1)}…`
15
+ : result;
16
+ }
17
+ /**
18
+ * Turn a thrown command failure into what the caller is told. A command that
19
+ * never reached dispatch did not run: that is a failed result carrying its
20
+ * cause. A command that may have started has no established outcome, so it
21
+ * stays unknown, but never without its cause; for a hosted command only the
22
+ * error name, since its runtime may echo env or stdin. `secrets` are credential values
23
+ * handed to the command; they never appear in the reported text.
24
+ */
25
+ export function describeCommandFailure(input) {
26
+ if (input.hosted && input.stage === "dispatched")
27
+ return {
28
+ kind: "unknown",
29
+ cause: input.cause instanceof Error
30
+ ? `the native runtime failed (${input.cause.name})`
31
+ : "the native runtime failed",
32
+ };
33
+ const cause = redact(causeText(input.cause), input.secrets);
34
+ if (input.stage === "dispatched")
35
+ return { kind: "unknown", cause };
36
+ return {
37
+ kind: "not_started",
38
+ output: {
39
+ status: "failed",
40
+ exitCode: -1,
41
+ stdout: "",
42
+ stderr: `The command did not start: ${cause}`,
43
+ truncated: false,
44
+ },
45
+ };
46
+ }
@@ -3,7 +3,7 @@ import type { Workspace } from "@fungi.computer/cloudflare-computer";
3
3
  export declare function applyWorkspacePatch(workspace: Pick<Workspace, "runtime">, backend: string, input: {
4
4
  patch: string;
5
5
  }): Promise<{
6
- status: "failed" | "completed" | "cancelled";
6
+ status: "completed" | "failed" | "cancelled";
7
7
  exitCode: number;
8
8
  stdout: string;
9
9
  stderr: string;
@@ -13,7 +13,7 @@ export declare function applyWorkspacePatch(workspace: Pick<Workspace, "runtime"
13
13
  totalBytes: number;
14
14
  }[];
15
15
  } | {
16
- status: "failed" | "completed" | "cancelled";
16
+ status: "completed" | "failed" | "cancelled";
17
17
  exitCode: number;
18
18
  stdout: string;
19
19
  stderr: string;
package/dist/index.d.ts CHANGED
@@ -284,7 +284,7 @@ export declare class ComputerDO extends ContainerComputer implements ComputerFil
284
284
  protected applyPatchAfterAcceptance(input: {
285
285
  patch: string;
286
286
  }, accept: () => void): Promise<{
287
- status: "failed" | "completed" | "cancelled";
287
+ status: "completed" | "failed" | "cancelled";
288
288
  exitCode: number;
289
289
  stdout: string;
290
290
  stderr: string;
@@ -294,7 +294,7 @@ export declare class ComputerDO extends ContainerComputer implements ComputerFil
294
294
  totalBytes: number;
295
295
  }[];
296
296
  } | {
297
- status: "failed" | "completed" | "cancelled";
297
+ status: "completed" | "failed" | "cancelled";
298
298
  exitCode: number;
299
299
  stdout: string;
300
300
  stderr: string;
package/dist/index.js CHANGED
@@ -70,6 +70,7 @@ import { PullPendingTracker } from "./pull-pending.js";
70
70
  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, ComputerFileRemoveError, removeInputSchema, removeOutputSchema, readInputSchema, readBytesInputSchema, readOutputSchema, replaceInputSchema, writeInputSchema, writeOutputSchema, processIdInputSchema, processKillOutputSchema, processListOutputSchema, processLogsInputSchema, processLogsOutputSchema, processWaitInputSchema, processWaitOutputSchema, maximumProcessLogLines, processStartInputSchema, processStartToolInputSchema, ComputerProcessNotFoundError, computerServiceDeclarationSchema, serviceLogsInputSchema, serviceNameInputSchema, } from "@fungi.computer/computer-contract";
71
71
  import { agentWorkspacePath, createWorkspaceFilesPort, readBoundedWorkspaceText, workspaceRoot, workspaceFileExists, listWorkspaceFiles, } from "./files.js";
72
72
  import { computerExecutionResult } from "./execution-result.js";
73
+ import { describeCommandFailure, } from "./command-failure.js";
73
74
  import { ComputerOperationRecord } from "./operation-record.js";
74
75
  import { createComputerExecutionLifecycle } from "./execution-lifecycle.js";
75
76
  import { applyWorkspacePatch } from "./files-patch.js";
@@ -1393,6 +1394,9 @@ export class ComputerDO extends ContainerComputer {
1393
1394
  kind: "exec",
1394
1395
  };
1395
1396
  let completed = false;
1397
+ let stage = "preparing";
1398
+ let opening = false;
1399
+ let secrets = [];
1396
1400
  try {
1397
1401
  const workspace = await this.readyWorkspace();
1398
1402
  hooks =
@@ -1403,7 +1407,10 @@ export class ComputerDO extends ContainerComputer {
1403
1407
  throw new Error("Computer host execution is unavailable");
1404
1408
  this.#executions.begin(invocation, route.id, executionContext);
1405
1409
  // The host's last awaited authority fence follows NEW admission.
1410
+ opening = true;
1406
1411
  const carriage = await hooks.open(invocation, executionContext);
1412
+ opening = false;
1413
+ secrets = Object.values(carriage.env ?? {});
1407
1414
  execution = {
1408
1415
  invocation,
1409
1416
  carriage,
@@ -1416,16 +1423,29 @@ export class ComputerDO extends ContainerComputer {
1416
1423
  },
1417
1424
  };
1418
1425
  }
1426
+ stage = "dispatched";
1419
1427
  const output = await exec(workspace, command, route?.id, signal, execution, resultOptions);
1420
1428
  completed = true;
1421
1429
  operations.settle(requestId, output);
1422
1430
  }
1423
1431
  catch (cause) {
1424
- operations.settleUnknown(requestId, executionContext !== undefined
1425
- ? "Computer hosted execution outcome is unavailable"
1426
- : cause instanceof Error
1427
- ? `${cause.name}: ${cause.message}`
1428
- : "Computer execution rejected without an Error");
1432
+ // A host authority error may carry credential-bearing transport data:
1433
+ // name only what failed there, never its message.
1434
+ const reported = opening && cause instanceof Error
1435
+ ? new Error(`host authority was refused (${cause.name})`)
1436
+ : cause;
1437
+ const failure = describeCommandFailure({
1438
+ stage,
1439
+ cause: reported,
1440
+ secrets,
1441
+ hosted: executionContext !== undefined,
1442
+ });
1443
+ if (failure.kind === "not_started") {
1444
+ operations.settle(requestId, failure.output);
1445
+ }
1446
+ else {
1447
+ operations.settleUnknown(requestId, failure.cause);
1448
+ }
1429
1449
  }
1430
1450
  finally {
1431
1451
  if (hooks !== undefined && executionContext !== undefined) {
@@ -1,3 +1,4 @@
1
+ import { z } from "zod";
1
2
  import { computerOperationResultSchema, computerRequestIdSchema, execOutputSchema, } from "@fungi.computer/computer-contract";
2
3
  /** Terminal status records are retained for 7 days. */
3
4
  export const operationRetentionMs = 7 * 24 * 60 * 60 * 1_000;
@@ -30,6 +31,9 @@ export class ComputerRequestInvalidError extends Error {
30
31
  this.name = "ComputerRequestInvalidError";
31
32
  }
32
33
  }
34
+ /** Why an unknown outcome is unknown; stored where a known outcome's output is. */
35
+ const unknownDetailSchema = z.strictObject({ cause: z.string() });
36
+ const reopenedCause = "The Computer restarted while this command was running, so its result was not recorded; it may still have run, so check before running it again.";
33
37
  /** The embedded UUIDv7 millisecond time; the ID is already Zod-validated. */
34
38
  function requestIdTime(requestId) {
35
39
  return Number.parseInt(requestId.replaceAll("-", "").slice(0, 12), 16);
@@ -49,7 +53,7 @@ export class ComputerOperationRecord {
49
53
  sql.exec("CREATE TABLE IF NOT EXISTS computer_operations (request_id TEXT PRIMARY KEY, input_hash TEXT NOT NULL, status TEXT NOT NULL CHECK (status IN ('accepted', 'running', 'succeeded', 'failed', 'unknown')), created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL, output_expires_at INTEGER NOT NULL, output_json TEXT) STRICT");
50
54
  // Reopening never reinterprets unfinished work as permission to rerun it.
51
55
  storage.transactionSync(() => {
52
- sql.exec("UPDATE computer_operations SET status = 'unknown', updated_at = ? WHERE status IN ('accepted', 'running')", now());
56
+ sql.exec("UPDATE computer_operations SET status = 'unknown', updated_at = ?, output_json = ? WHERE status IN ('accepted', 'running')", now(), JSON.stringify({ cause: reopenedCause }));
53
57
  });
54
58
  }
55
59
  #admissionTime(requestIdInput) {
@@ -99,7 +103,7 @@ export class ComputerOperationRecord {
99
103
  */
100
104
  settleUnknown(requestId, cause) {
101
105
  console.error("Computer operation outcome unknown", { requestId, cause });
102
- this.#storage.sql.exec("UPDATE computer_operations SET status = 'unknown', updated_at = ?, output_json = NULL WHERE request_id = ?", this.#now(), requestId);
106
+ this.#storage.sql.exec("UPDATE computer_operations SET status = 'unknown', updated_at = ?, output_json = ? WHERE request_id = ?", this.#now(), JSON.stringify({ cause }), requestId);
103
107
  }
104
108
  /** Durable status lookup; an unseen ID older than the window is expired. */
105
109
  status(requestIdInput, accept) {
@@ -116,6 +120,13 @@ export class ComputerOperationRecord {
116
120
  .toArray()[0];
117
121
  }
118
122
  #result(requestId, row, now) {
123
+ if (row?.status === "unknown") {
124
+ const cause = row.output_json !== null && row.output_expires_at > now
125
+ ? unknownDetailSchema.parse(JSON.parse(row.output_json)).cause
126
+ : undefined;
127
+ const unknown = { requestId, status: "unknown", output: null };
128
+ return computerOperationResultSchema.parse(cause === undefined ? unknown : { ...unknown, cause });
129
+ }
119
130
  if (row !== undefined) {
120
131
  return computerOperationResultSchema.parse({
121
132
  requestId,
@@ -20898,6 +20898,8 @@ var method = Struct({
20898
20898
  output: projection,
20899
20899
  pending: optional2(Literal2(true)),
20900
20900
  hidden: optional2(Literal2(true)),
20901
+ label: optional2(String4.check(isMinLength(1), isMaxLength(48), isPattern2(/^[^\p{Cc}\p{Cf}\p{Zl}\p{Zp}.!?]+$/u))),
20902
+ precheck: optional2(String4.check(isMinLength(1), isMaxLength(128))),
20901
20903
  present: optional2(Struct({
20902
20904
  verb: String4.check(isMinLength(1), isMaxLength(32))
20903
20905
  })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/computer",
3
- "version": "0.18.1",
3
+ "version": "0.18.3",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Cloudflare Computer host for one durable Fungi Computer",
6
6
  "type": "module",
@@ -72,10 +72,10 @@
72
72
  "@fungi.computer/capnweb": "0.12.0-fungi.0",
73
73
  "@fungi.computer/cloudflare-computer": "0.2.1-fungi.3",
74
74
  "@fungi.computer/cordyceps": "0.4.3",
75
- "@fungi.computer/knapsack": "0.4.25",
75
+ "@fungi.computer/knapsack": "0.4.26",
76
76
  "@fungi.computer/seam": "0.2.7",
77
77
  "@fungi.computer/watchdog": "0.1.5",
78
- "@fungi.computer/computer-contract": "0.6.1",
78
+ "@fungi.computer/computer-contract": "0.6.3",
79
79
  "effect": "4.0.2",
80
80
  "just-bash": "3.4.2",
81
81
  "zod": "4.4.3",
@@ -137,7 +137,7 @@
137
137
  "test:ssh-container": "node test/ssh-container-proof.mjs",
138
138
  "test:preview-failure:browser": "node test/preview-failure.browser.mjs",
139
139
  "test:execution-lifecycle": "node test/execution-lifecycle-proof.mjs",
140
- "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/port-failure.test.mjs test/port-access.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 test/tools-install.test.mjs test/services.test.mjs test/services-apply.test.mjs test/services-tools.test.mjs test/services-render.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\"",
140
+ "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/port-failure.test.mjs test/port-access.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 test/command-failure.test.mjs test/tools-install.test.mjs test/services.test.mjs test/services-apply.test.mjs test/services-tools.test.mjs test/services-render.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\"",
141
141
  "test:services": "node test/services-proof.mjs && node test/services-wake-proof.mjs",
142
142
  "test:fleet-native": "node test/fleet.native.mjs",
143
143
  "assemble:image": "node scripts/assemble-image.mjs"