@fungi.computer/oyster 0.38.1 → 0.39.1

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.
@@ -28,6 +28,7 @@ import { type ModelKeyRecord, type ModelKeyRefusal, type ModelKeySealInput } fro
28
28
  import type { CloudflareShiitakeOptions } from "@fungi.computer/shiitake/cloudflare";
29
29
  import { type AgentModelChoice, type AgentModelRefusal } from "./agent-model-choice.js";
30
30
  import * as Schema from "effect/Schema";
31
+ import { type FingerprintSet } from "@fungi.computer/veil/redaction";
31
32
  import { type FrameBindingProps } from "../cloudflare.js";
32
33
  import { type AppAgentScheduleListInput, type AgentSchedulePage, type AgentScheduleTarget, type AgentScheduleControlReceipt } from "../agent-schedules.js";
33
34
  import { type StarterLedgerRow } from "../starter-agent.js";
@@ -316,6 +317,13 @@ export declare abstract class StandaloneAgentBase<Env extends StandaloneAgentEnv
316
317
  * and it must run discordReplyWork or an evicted Discord run never answers.
317
318
  */
318
319
  protected shiitakeOptions(): Promise<CloudflareShiitakeOptions>;
320
+ private vaultRedactor;
321
+ /**
322
+ * Session redaction from this instance's stored credentials. The directory
323
+ * that holds them sends fingerprints only, never a value; an Agent with no
324
+ * directory, or a directory that cannot answer, fails closed.
325
+ */
326
+ protected vaultRedaction(): NonNullable<CloudflareShiitakeOptions["redaction"]>;
319
327
  /** Send an installation-admitted message through fleet Session operations. */
320
328
  sendFromApp(installationId: string, sessionId: string, message: FleetMessage): Promise<{
321
329
  sessionId: string;
@@ -358,6 +366,17 @@ export declare class AgentDirectory extends DurableObject<StandaloneAgentEnv> {
358
366
  }>): Promise<Response | Readonly<{
359
367
  error: ModelKeyRefusal;
360
368
  }>>;
369
+ private redactionSet;
370
+ /**
371
+ * Host-only: fingerprints of every credential this directory stores (model
372
+ * keys, connections and Discord tokens), for Session redaction. The HMAC
373
+ * subkey derives from the instance credential key; no value leaves here.
374
+ */
375
+ redactionFingerprints(): Promise<Readonly<{
376
+ revision: string;
377
+ set: FingerprintSet;
378
+ }>>;
379
+ private fingerprintSet;
361
380
  private mcpOwner;
362
381
  /** Loaded on the first MCP request: the SDK and OpenAPI decoders stay out of startup. */
363
382
  private mcpConnections;
@@ -60,7 +60,16 @@ import { cloudflareAccountReady } from "./cloudflare-account.js";
60
60
  import { cloudflareWorkersAIProvider } from "@earendil-works/pi-ai/providers/cloudflare-workers-ai";
61
61
  import { getSupportedThinkingLevels } from "@earendil-works/pi-ai/models";
62
62
  import { agentModelListSchema } from "@fungi.computer/shiitake/model-list";
63
+ import * as Option from "effect/Option";
64
+ import * as Predicate from "effect/Predicate";
63
65
  import * as Schema from "effect/Schema";
66
+ import { decode as decodeBase64Url } from "effect/encoding/Base64Url";
67
+ import * as Result from "effect/Result";
68
+ // Named imports only: Veil's redaction module is already in the startup graph
69
+ // (its egress paths import it), and naming the two calls lets the bundler drop
70
+ // the maintained pattern rules this Worker never runs. A dynamic import would
71
+ // keep the whole module, rules included, in the evaluated idle state.
72
+ import { createFingerprintRedactor, createFingerprintSet, } from "@fungi.computer/veil/redaction";
64
73
  import { z } from "zod";
65
74
  import {} from "../cloudflare.js";
66
75
  import { AppInstanceError } from "../index.js";
@@ -1449,6 +1458,30 @@ export class StandaloneAgentBase extends ShiitakeDO {
1449
1458
  this.archiveControl().work,
1450
1459
  this.discordReplyWork(),
1451
1460
  ],
1461
+ redaction: this.vaultRedaction(),
1462
+ };
1463
+ }
1464
+ vaultRedactor;
1465
+ /**
1466
+ * Session redaction from this instance's stored credentials. The directory
1467
+ * that holds them sends fingerprints only, never a value; an Agent with no
1468
+ * directory, or a directory that cannot answer, fails closed.
1469
+ */
1470
+ vaultRedaction() {
1471
+ return {
1472
+ load: async () => {
1473
+ const pin = await this.policyDirectory();
1474
+ if (pin === null)
1475
+ throw new Error("Agent directory is unavailable");
1476
+ const answer = await this.env.AGENT_DIRECTORY.getByName(pin.directoryName).redactionFingerprints();
1477
+ if (this.vaultRedactor?.revision !== answer.revision) {
1478
+ this.vaultRedactor = {
1479
+ revision: answer.revision,
1480
+ redactor: createFingerprintRedactor(answer.set),
1481
+ };
1482
+ }
1483
+ return this.vaultRedactor.redactor;
1484
+ },
1452
1485
  };
1453
1486
  }
1454
1487
  /** Send an installation-admitted message through fleet Session operations. */
@@ -1589,6 +1622,44 @@ export class AgentDirectory extends DurableObject {
1589
1622
  throw error;
1590
1623
  }
1591
1624
  }
1625
+ redactionSet;
1626
+ /**
1627
+ * Host-only: fingerprints of every credential this directory stores (model
1628
+ * keys, connections and Discord tokens), for Session redaction. The HMAC
1629
+ * subkey derives from the instance credential key; no value leaves here.
1630
+ */
1631
+ async redactionFingerprints() {
1632
+ const storage = credentialStorage(this.ctx.storage);
1633
+ const rows = [...(await storage.list("credential:")).values()];
1634
+ // Each seal draws a fresh IV, so any stored change is a new revision.
1635
+ const revision = rows
1636
+ .map((row) => `${row.credentialId}:${row.sealed}`)
1637
+ .sort()
1638
+ .join("\n");
1639
+ const cached = this.redactionSet;
1640
+ if (cached?.revision === revision)
1641
+ return cached;
1642
+ // A set that fails to build is never cached: the next read retries.
1643
+ const fresh = { revision, set: await this.fingerprintSet(rows) };
1644
+ this.redactionSet = fresh;
1645
+ return fresh;
1646
+ }
1647
+ async fingerprintSet(rows) {
1648
+ const store = createInstanceCredentialStore(this.credentialOptions());
1649
+ const values = new Set();
1650
+ for (const row of rows)
1651
+ await store.withSecret(row.credentialId, (secret) => {
1652
+ for (const value of secretStrings(secret))
1653
+ values.add(value);
1654
+ });
1655
+ // With no stored values there is nothing to find; any key will do. A
1656
+ // malformed key refuses in createFingerprintSet, so redaction fails closed.
1657
+ const key = this.env.OYSTER_CREDENTIAL_KEY;
1658
+ const ownerKey = key === undefined
1659
+ ? crypto.getRandomValues(new Uint8Array(32))
1660
+ : Result.getOrElse(decodeBase64Url(key), () => new Uint8Array(0));
1661
+ return createFingerprintSet(ownerKey, [...values]);
1662
+ }
1592
1663
  mcpOwner;
1593
1664
  /** Loaded on the first MCP request: the SDK and OpenAPI decoders stay out of startup. */
1594
1665
  async mcpConnections() {
@@ -2470,6 +2541,32 @@ export class AgentDirectory extends DurableObject {
2470
2541
  }
2471
2542
  /** Where an authorization server returns the owner after a sign-in. */
2472
2543
  const mcpCallbackUrl = (origin) => new URL("/api/connections/callback", origin).href;
2544
+ const decodeJsonSecret = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Json));
2545
+ /** Every string leaf of one parsed JSON value. */
2546
+ function jsonStrings(value, into) {
2547
+ if (value === null || Predicate.isNumber(value) || Predicate.isBoolean(value))
2548
+ return;
2549
+ if (Predicate.isString(value)) {
2550
+ into.push(value);
2551
+ return;
2552
+ }
2553
+ // An array's values are its items; an object's are its fields.
2554
+ for (const item of Object.values(value))
2555
+ jsonStrings(item, into);
2556
+ }
2557
+ /**
2558
+ * The strings one sealed secret can print: the secret itself and, for a JSON
2559
+ * bundle (an OAuth token set, a Cloudflare key), each string inside it. Over-
2560
+ * matching a non-secret field only masks it. Vault never stores a value
2561
+ * under eight code units, so shorter strings are not values to find.
2562
+ */
2563
+ function secretStrings(secret) {
2564
+ const strings = [secret];
2565
+ const parsed = decodeJsonSecret(secret);
2566
+ if (Option.isSome(parsed))
2567
+ jsonStrings(parsed.value, strings);
2568
+ return strings.filter((value) => value.length >= 8);
2569
+ }
2473
2570
  /** The directory's Durable Object storage as the credential store's key-value port. */
2474
2571
  const credentialStorage = (storage) => ({
2475
2572
  get: (key) => storage.get(key),
@@ -67,6 +67,11 @@ export function channelSessionDoor(open, deliverGrants, conversations) {
67
67
  error.cause === "closed" &&
68
68
  error.requestId === requestId
69
69
  ? "closed_request"
70
- : null,
70
+ : error instanceof ShiitakeError &&
71
+ error.boundary === "contract" &&
72
+ (error.cause === "secret_in_prompt" ||
73
+ error.cause === "unavailable")
74
+ ? "intake_refused"
75
+ : null,
71
76
  };
72
77
  }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Whether this Linux session is known to have no Secret Service: no session
3
+ * bus, or a bus that neither runs nor can activate `org.freedesktop.secrets`.
4
+ * The keyring binding reports an absent and a broken service alike as
5
+ * GenericFailure, so ask the bus for its typed name lists instead of reading
6
+ * error text. A present but locked or failing service is not absent; its
7
+ * errors stay fatal so private custody never silently downgrades to a file.
8
+ */
9
+ export declare function secretServiceAbsent(): Promise<boolean>;
@@ -0,0 +1,77 @@
1
+ import { once } from "node:events";
2
+ import { access } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import process from "node:process";
5
+ import { Message, sessionBus } from "@jellybrick/dbus-next";
6
+ import * as z from "zod";
7
+ const secretServiceName = "org.freedesktop.secrets";
8
+ const missingBus = z.object({ code: z.enum(["ENOENT", "ECONNREFUSED"]) });
9
+ /** No address, X11 display or XDG bus socket: no session bus can be reached. */
10
+ async function noSessionBusAddress() {
11
+ if (process.env.DBUS_SESSION_BUS_ADDRESS || process.env.DISPLAY)
12
+ return false;
13
+ const runtime = process.env.XDG_RUNTIME_DIR;
14
+ if (!runtime)
15
+ return true;
16
+ try {
17
+ await access(join(runtime, "bus"));
18
+ return false;
19
+ }
20
+ catch (cause) {
21
+ if (missingBus.safeParse(cause).success)
22
+ return true;
23
+ throw cause;
24
+ }
25
+ }
26
+ /**
27
+ * Whether this Linux session is known to have no Secret Service: no session
28
+ * bus, or a bus that neither runs nor can activate `org.freedesktop.secrets`.
29
+ * The keyring binding reports an absent and a broken service alike as
30
+ * GenericFailure, so ask the bus for its typed name lists instead of reading
31
+ * error text. A present but locked or failing service is not absent; its
32
+ * errors stay fatal so private custody never silently downgrades to a file.
33
+ */
34
+ export async function secretServiceAbsent() {
35
+ if (await noSessionBusAddress())
36
+ return true;
37
+ let bus;
38
+ try {
39
+ bus = sessionBus();
40
+ const connected = bus;
41
+ const names = async (member) => {
42
+ const reply = await Promise.race([
43
+ connected.call(new Message({
44
+ destination: "org.freedesktop.DBus",
45
+ path: "/org/freedesktop/DBus",
46
+ interface: "org.freedesktop.DBus",
47
+ member,
48
+ })),
49
+ once(connected, "error", { signal: AbortSignal.timeout(3_000) }),
50
+ ]);
51
+ if (Array.isArray(reply)) {
52
+ const error = reply[0];
53
+ if (error instanceof Error)
54
+ throw error;
55
+ throw new Error("Cannot connect to the Secret Service session bus");
56
+ }
57
+ if (reply === null)
58
+ throw new Error("Cannot inspect the Secret Service session bus");
59
+ return z.array(z.string()).parse(reply.body[0]);
60
+ };
61
+ const [active, activatable] = await Promise.all([
62
+ names("ListNames"),
63
+ names("ListActivatableNames"),
64
+ ]);
65
+ return (!active.includes(secretServiceName) &&
66
+ !activatable.includes(secretServiceName));
67
+ }
68
+ catch (cause) {
69
+ // A stale address or socket path refuses the connection: no bus is running.
70
+ if (missingBus.safeParse(cause).success)
71
+ return true;
72
+ throw cause;
73
+ }
74
+ finally {
75
+ bus?.disconnect();
76
+ }
77
+ }
@@ -13,6 +13,7 @@
13
13
  // and --verbose streams them instead. Piped output or CI gets plain lines.
14
14
  import { spawn } from "node:child_process";
15
15
  import { startTrialComputer } from "./trial-computer.js";
16
+ import { secretServiceAbsent } from "./secret-service.js";
16
17
  import { createTrialOwner, prepareTrialPrivateState } from "./try-custody.js";
17
18
  import { randomBytes } from "node:crypto";
18
19
  import { encode as encodeBase64Url } from "effect/encoding/Base64Url";
@@ -22,7 +23,7 @@ import { runGit } from "../build/local-build.js";
22
23
  import { CleanupError, stopProcessGroup, awaitCleanup, } from "../build/process-group.js";
23
24
  import { InstallationObservationError } from "../installation-client.js";
24
25
  import { createWriteStream } from "node:fs";
25
- import { access, chmod, mkdir, mkdtemp, rename, readdir, rm, readFile, realpath, stat, writeFile, } from "node:fs/promises";
26
+ import { chmod, mkdir, mkdtemp, rename, readdir, rm, readFile, realpath, stat, writeFile, } from "node:fs/promises";
26
27
  import { createServer } from "node:net";
27
28
  import { createCredentialSealer, } from "@fungi.computer/veil/credential-store";
28
29
  import { basename, dirname, delimiter, join, resolve } from "node:path";
@@ -92,12 +93,15 @@ async function timedTask(ui, label, work) {
92
93
  throw cause;
93
94
  }
94
95
  }
95
- /** A failure that knows the exact next step; the command shows both. */
96
+ /**
97
+ * A failure that knows the exact next step; the command shows both, and the
98
+ * underlying reason when one caused it.
99
+ */
96
100
  class TryError extends Error {
97
101
  title;
98
102
  next;
99
- constructor(title, next) {
100
- super(`${title} ${next}`);
103
+ constructor(title, next, options) {
104
+ super(`${title} ${next}`, options);
101
105
  this.name = "TryError";
102
106
  this.title = title;
103
107
  this.next = next;
@@ -129,6 +133,16 @@ function innermostError(cause) {
129
133
  }
130
134
  return current;
131
135
  }
136
+ /**
137
+ * The innermost cause's message. A JSON syntax error quotes its input, which
138
+ * can be a saved keyring, so it is named instead of shown.
139
+ */
140
+ function failureReason(cause) {
141
+ const innermost = innermostError(cause);
142
+ return innermost instanceof SyntaxError
143
+ ? "a saved file is not valid JSON"
144
+ : innermost.message;
145
+ }
132
146
  const networkErrorCodes = new Set([
133
147
  "ENOTFOUND",
134
148
  "EAI_AGAIN",
@@ -143,7 +157,9 @@ function isNetworkFailure(error) {
143
157
  /** Show a failed `oyster try` as an error with its next step. */
144
158
  export function reportTryFailure(cause, ui) {
145
159
  if (cause instanceof TryError)
146
- ui.problem(cause.title, cause.next);
160
+ ui.problem(cause.cause === undefined
161
+ ? cause.title
162
+ : `${cause.title} Reason: ${failureReason(cause.cause)}`, cause.next);
147
163
  else
148
164
  ui.problem(cause instanceof Error ? cause.message : String(cause), `Run \`${command} --help\` for the options, or add --verbose to see the full output.`);
149
165
  }
@@ -419,26 +435,12 @@ const trialKeyringSchema = z.strictObject({
419
435
  keys: z.record(z.string(), z.string()),
420
436
  });
421
437
  const warnedCredentialFiles = new Set();
422
- /** A known-absent session bus permits a file; a locked/broken keychain does not. */
423
- async function headlessKeychain() {
424
- if (process.platform !== "linux" ||
425
- process.env.DBUS_SESSION_BUS_ADDRESS ||
426
- process.env.DISPLAY)
427
- return false;
428
- if (process.env.XDG_RUNTIME_DIR === undefined)
429
- return true;
430
- try {
431
- await access(join(process.env.XDG_RUNTIME_DIR, "bus"));
432
- return false;
433
- }
434
- catch (cause) {
435
- if (z.object({ code: z.literal("ENOENT") }).safeParse(cause).success)
436
- return true;
437
- throw cause;
438
- }
439
- }
440
- /** The host's keychain, never the library's nonpersistent keyutils fallback. */
441
- const osKeychain = async (account) => (await headlessKeychain())
438
+ /**
439
+ * The host's keychain, never the library's nonpersistent keyutils fallback.
440
+ * A Linux session known to have no Secret Service permits a file; a locked or
441
+ * broken keychain does not.
442
+ */
443
+ const osKeychain = async (account) => process.platform === "linux" && (await secretServiceAbsent())
442
444
  ? undefined
443
445
  : new (await import("@napi-rs/keyring")).AsyncEntry("fungi-oyster-credentials", account, { linux: { store: "secret-service" } });
444
446
  /** Convert native dotenv input once, after private custody has retained the key. */
@@ -561,7 +563,14 @@ export async function prepareTryModelKeyCustody(directory, keychain = osKeychain
561
563
  await chmod(path, 0o600);
562
564
  if (!warnedCredentialFiles.has(path)) {
563
565
  warnedCredentialFiles.add(path);
564
- process.stderr.write(`oyster: OS keychain unavailable (Linux Secret Service); wrapping keys stored/read in 0600 file ${JSON.stringify(path)}.\n`);
566
+ process.stderr.write([
567
+ "",
568
+ "oyster: WARNING: Linux Secret Service is not available on this machine.",
569
+ `oyster: This Oyster's model-key wrapping key is stored UNENCRYPTED in the 0600 file ${JSON.stringify(path)}.`,
570
+ "oyster: Anyone who can read that file as you can decrypt the model keys this Oyster saves.",
571
+ "oyster: To keep it in the OS keychain instead, install and start a Secret Service provider (for example gnome-keyring, or KeePassXC with Secret Service integration enabled) in your login session, then restart the Oyster.",
572
+ "",
573
+ ].join("\n"));
565
574
  }
566
575
  }
567
576
  else {
@@ -582,8 +591,8 @@ export async function prepareTryModelKeyCustody(directory, keychain = osKeychain
582
591
  await removeTrialCredentialBindings(directory);
583
592
  return keyring;
584
593
  }
585
- catch {
586
- throw new TryError("This Oyster could not prepare private model-key storage.", "Check the OS keychain and private credential-keyring.json, then restart the Oyster. Existing keys were not replaced.");
594
+ catch (cause) {
595
+ throw new TryError("This Oyster could not prepare private model-key storage.", "Check the OS keychain and private credential-keyring.json, then restart the Oyster. Existing keys were not replaced.", { cause });
587
596
  }
588
597
  }
589
598
  function startWrangler(input, keychain) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/oyster",
3
- "version": "0.38.1",
3
+ "version": "0.39.1",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Oyster by Fungi: open-source Apps for people and AI agents. Try with one command or run on your own Cloudflare account.",
6
6
  "homepage": "https://docs.fungi.computer/oyster",
@@ -360,35 +360,36 @@
360
360
  "@earendil-works/pi-ai": "1.5.2",
361
361
  "@fungi.computer/agar": "0.22.1",
362
362
  "@fungi.computer/bird-dog": "0.3.7",
363
- "@fungi.computer/braid": "0.5.3",
363
+ "@fungi.computer/braid": "0.5.4",
364
364
  "@fungi.computer/burrow": "0.2.1",
365
365
  "@fungi.computer/cairn": "0.1.0",
366
366
  "@fungi.computer/capnweb": "0.12.0-fungi.0",
367
367
  "@fungi.computer/caps": "0.12.1",
368
368
  "@fungi.computer/carrier": "0.2.5",
369
- "@fungi.computer/computer": "0.14.6",
370
- "@fungi.computer/computer-contract": "0.5.6",
369
+ "@fungi.computer/computer": "0.14.8",
370
+ "@fungi.computer/computer-contract": "0.5.7",
371
371
  "@fungi.computer/darkroom": "0.11.7",
372
372
  "@fungi.computer/ear-tag": "0.1.0",
373
373
  "@fungi.computer/forage": "0.3.13",
374
374
  "@fungi.computer/gills": "0.4.0",
375
- "@fungi.computer/knapsack": "0.4.19",
375
+ "@fungi.computer/knapsack": "0.4.20",
376
376
  "@fungi.computer/lantern": "0.4.2",
377
- "@fungi.computer/mycelium": "0.4.6",
377
+ "@fungi.computer/mycelium": "0.4.7",
378
378
  "@fungi.computer/nacre": "0.8.2",
379
- "@fungi.computer/parakeet": "0.13.3",
379
+ "@fungi.computer/parakeet": "0.14.0",
380
380
  "@fungi.computer/puffball": "0.12.0",
381
381
  "@fungi.computer/seam": "0.2.6",
382
- "@fungi.computer/shiitake": "0.20.4",
383
- "@fungi.computer/shiitake-extensions": "0.11.9",
382
+ "@fungi.computer/shiitake": "0.21.0",
383
+ "@fungi.computer/shiitake-extensions": "0.11.10",
384
384
  "@fungi.computer/sigils": "0.3.2",
385
385
  "@fungi.computer/sprite": "0.2.2",
386
386
  "@fungi.computer/sprite-zdog": "0.3.2",
387
- "@fungi.computer/veil": "0.8.0",
387
+ "@fungi.computer/veil": "0.8.1",
388
388
  "@fungi.computer/watchdog": "0.1.4",
389
389
  "@fungi.computer/whistle": "0.3.0",
390
- "@fungi.computer/workflows-wire": "0.5.3",
391
- "@fungi.computer/zookeeper": "0.0.41",
390
+ "@fungi.computer/workflows-wire": "0.5.4",
391
+ "@fungi.computer/zookeeper": "0.0.42",
392
+ "@jellybrick/dbus-next": "0.11.4",
392
393
  "@modelcontextprotocol/server": "2.0.0",
393
394
  "@msgpack/msgpack": "3.1.3",
394
395
  "@napi-rs/keyring": "2.1.2",