@fungi.computer/oyster 0.11.0 → 0.12.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.
Files changed (52) hide show
  1. package/README.md +70 -10
  2. package/dist/app-builds.d.ts +2 -0
  3. package/dist/app-builds.js +17 -6
  4. package/dist/authorization.d.ts +1 -1
  5. package/dist/build/artifact-writer.d.ts +11 -2
  6. package/dist/build/artifact-writer.js +42 -24
  7. package/dist/build/candidate-cli.mjs +33 -19
  8. package/dist/build/content-objects.d.ts +29 -14
  9. package/dist/build/content-objects.js +57 -19
  10. package/dist/build/local-build.js +7 -1
  11. package/dist/build/submission-contract.d.ts +1 -1
  12. package/dist/build/submission-contract.js +5 -5
  13. package/dist/build-egress.d.ts +8 -7
  14. package/dist/build-egress.js +4 -3
  15. package/dist/build.d.ts +1 -1
  16. package/dist/hello-app-script.d.ts +2 -0
  17. package/dist/hello-app-script.js +1 -0
  18. package/dist/install-release-cli.d.ts +2 -1
  19. package/dist/install-release-cli.js +18 -10
  20. package/dist/installation-client.d.ts +1 -0
  21. package/dist/installation-operations.d.ts +2 -0
  22. package/dist/installation-operations.js +1 -0
  23. package/dist/pack.d.ts +5 -2
  24. package/dist/pack.js +3 -1
  25. package/dist/standalone/agents.d.ts +6 -2
  26. package/dist/standalone/agents.js +21 -4
  27. package/dist/standalone/computer-egress.d.ts +5 -3
  28. package/dist/standalone/computer-egress.js +1 -1
  29. package/dist/standalone/hello-app.d.ts +10 -0
  30. package/dist/standalone/hello-app.js +81 -0
  31. package/dist/standalone/install-apps-cli.d.ts +2 -1
  32. package/dist/standalone/install-apps-cli.js +36 -14
  33. package/dist/standalone/instance.js +2 -2
  34. package/dist/standalone/local-desktop.d.ts +11 -0
  35. package/dist/standalone/local-desktop.js +75 -0
  36. package/dist/standalone/registry.d.ts +2 -0
  37. package/dist/standalone/sign-in-link.d.ts +9 -0
  38. package/dist/standalone/sign-in-link.js +49 -0
  39. package/dist/standalone/try-cli.d.ts +52 -0
  40. package/dist/standalone/try-cli.js +427 -0
  41. package/dist/standalone/worker.js +1 -1
  42. package/dist/webhook-abuse.d.ts +7 -1
  43. package/dist/webhook-abuse.js +8 -2
  44. package/dist/workers.d.ts +7 -2
  45. package/dist/workers.js +1 -1
  46. package/docs/api/authorization.md +56 -11
  47. package/docs/api/build-contract.md +52 -10
  48. package/docs/api/build.md +16 -2
  49. package/docs/api/host.md +1 -0
  50. package/docs/api/pack.md +179 -3
  51. package/docs/site/agent-quickstart.mdx +8 -0
  52. package/package.json +13 -8
@@ -0,0 +1,52 @@
1
+ import { Cli } from "@fungi.computer/lantern";
2
+ import { type SignInLink } from "./sign-in-link.js";
3
+ export declare const tryUsage = "Usage: oyster try [directory] [--port 8787] [--no-open] [--verbose] [--package <npm spec>]";
4
+ /**
5
+ * Streaming logs and a redrawing spinner cannot share a terminal, so
6
+ * --verbose prints plain lines instead of spinners.
7
+ */
8
+ export declare function createTryCli(args: readonly string[]): Cli;
9
+ /** Show a failed `oyster try` as an error with its next step. */
10
+ export declare function reportTryFailure(cause: unknown, ui: Cli): void;
11
+ /** The injectable effects of `oyster try`; tests replace them. */
12
+ export type TryEffects = Readonly<{
13
+ /** Install the scaffolded project's dependencies. */
14
+ installDependencies: (directory: string, manager: Manager, verbose: boolean) => Promise<void>;
15
+ /** Start Oyster and resolve once it answers; `stop` ends it. */
16
+ startServer: (input: {
17
+ directory: string;
18
+ port: number;
19
+ key: string;
20
+ verbose: boolean;
21
+ }) => Promise<{
22
+ stop: () => Promise<void>;
23
+ exited: Promise<number | null>;
24
+ }>;
25
+ /** Install the Hello App on the running Oyster. */
26
+ installHello: (input: {
27
+ directory: string;
28
+ url: string;
29
+ key: string;
30
+ }) => Promise<number>;
31
+ /** Build and install the Tourtois desktop unless it is already there. */
32
+ installDesktop: (input: {
33
+ directory: string;
34
+ url: string;
35
+ key: string;
36
+ }) => Promise<void>;
37
+ /** A one-time page that signs the owner in without the key in a URL. */
38
+ signInLink: (input: {
39
+ oysterUrl: string;
40
+ key: string;
41
+ }) => Promise<SignInLink>;
42
+ /** Open the browser. */
43
+ open: (url: string) => void;
44
+ /** Resolve when the user asks to stop. */
45
+ interrupted: () => Promise<void>;
46
+ /** Check that the port is free. */
47
+ portFree: (port: number) => Promise<boolean>;
48
+ }>;
49
+ export type Manager = "npm" | "pnpm";
50
+ /** pnpm when it ran this command (`pnpm dlx`), otherwise npm. */
51
+ export declare function detectManager(userAgent: string | undefined): "pnpm" | "npm";
52
+ export declare function tryOyster(args: readonly string[], effects?: TryEffects, ui?: Cli): Promise<void>;
@@ -0,0 +1,427 @@
1
+ // `oyster try`: one command from nothing to a running local Oyster with a
2
+ // Hello App. It scaffolds a small project (the standalone worker and wrangler
3
+ // config this package ships, plus a package.json), installs it with the
4
+ // caller's package manager, runs `wrangler dev` locally, installs the Hello
5
+ // App and opens the browser. Running it again in the same directory restarts
6
+ // the server without scaffolding again.
7
+ //
8
+ // npx @fungi.computer/oyster try [directory] [--port 8787] [--no-open] [--verbose]
9
+ //
10
+ // Output goes through Lantern, the shared Fungi terminal kit: a wordmark, one
11
+ // spinner per real step, a success box and a next step for every failure. It
12
+ // is quiet by default; install and server output go to files under .oyster/
13
+ // and --verbose streams them instead. Piped output or CI gets plain lines.
14
+ import { spawn, spawnSync } from "node:child_process";
15
+ import { randomBytes } from "node:crypto";
16
+ import { createWriteStream } from "node:fs";
17
+ import { copyFile, mkdir, readdir, readFile, stat, writeFile, } from "node:fs/promises";
18
+ import { createServer } from "node:net";
19
+ import { basename, delimiter, join, resolve } from "node:path";
20
+ import process from "node:process";
21
+ import { parseArgs } from "node:util";
22
+ import { Cli } from "@fungi.computer/lantern";
23
+ import * as z from "zod";
24
+ import { installHelloApp } from "./hello-app.js";
25
+ import { installLocalDesktop, isInstalled } from "./local-desktop.js";
26
+ import { startSignInLink } from "./sign-in-link.js";
27
+ export const tryUsage = "Usage: oyster try [directory] [--port 8787] [--no-open] [--verbose] [--package <npm spec>]";
28
+ const tryHelp = `${tryUsage}
29
+
30
+ Creates ./my-oyster (or <directory>) with a local Oyster, installs it, starts it
31
+ on http://127.0.0.1:<port> and installs a Hello App from <directory>/hello-app,
32
+ a git repository you can edit. Commit an edit and run this again, from inside
33
+ that directory or by naming it, to restart and reinstall without scaffolding.
34
+ Press Ctrl-C to stop.
35
+
36
+ Options:
37
+ --port <number> port to listen on (default 8787)
38
+ --no-open do not open the browser
39
+ --verbose stream install and server output instead of saving it
40
+ under .oyster/
41
+ --package <spec> install Oyster from this npm spec instead of the version
42
+ that is running (a tarball path, for example)
43
+ -h, --help show this help
44
+ `;
45
+ // The local workspace builder (src/build/local-build.ts) refuses any other pnpm.
46
+ const localBuildPnpmVersion = "11.24.0";
47
+ const requiredNodeMajor = 24;
48
+ const ownerKeyFile = ".oyster-owner";
49
+ const logFile = join(".oyster", "wrangler.log");
50
+ const installLogFile = join(".oyster", "install.log");
51
+ const command = "npx @fungi.computer/oyster try";
52
+ /** A failure that knows the exact next step; the command shows both. */
53
+ class TryError extends Error {
54
+ title;
55
+ next;
56
+ constructor(title, next) {
57
+ super(`${title} ${next}`);
58
+ this.name = "TryError";
59
+ this.title = title;
60
+ this.next = next;
61
+ }
62
+ }
63
+ /**
64
+ * Streaming logs and a redrawing spinner cannot share a terminal, so
65
+ * --verbose prints plain lines instead of spinners.
66
+ */
67
+ export function createTryCli(args) {
68
+ return args.includes("--verbose")
69
+ ? new Cli({ brand: "fungi", interactive: false })
70
+ : new Cli({ brand: "fungi" });
71
+ }
72
+ /** The deepest Error in a `cause` chain, where the real failure lives. */
73
+ function innermostError(cause) {
74
+ let current = cause instanceof Error ? cause : new Error(String(cause));
75
+ for (let depth = 0; depth < 10; depth += 1) {
76
+ if (!(current.cause instanceof Error))
77
+ break;
78
+ current = current.cause;
79
+ }
80
+ return current;
81
+ }
82
+ const networkErrorCodes = new Set([
83
+ "ENOTFOUND",
84
+ "EAI_AGAIN",
85
+ "ECONNREFUSED",
86
+ "ECONNRESET",
87
+ "ETIMEDOUT",
88
+ "ENETUNREACH",
89
+ ]);
90
+ function isNetworkFailure(error) {
91
+ return "code" in error && networkErrorCodes.has(error.code);
92
+ }
93
+ /** Show a failed `oyster try` as an error with its next step. */
94
+ export function reportTryFailure(cause, ui) {
95
+ if (cause instanceof TryError)
96
+ ui.problem(cause.title, cause.next);
97
+ else
98
+ ui.problem(cause instanceof Error ? cause.message : String(cause), `Run \`${command} --help\` for the options, or add --verbose to see the full output.`);
99
+ }
100
+ const ownManifestSchema = z.object({
101
+ version: z.string(),
102
+ dependencies: z.record(z.string(), z.string()).default({}),
103
+ peerDependencies: z.record(z.string(), z.string()).default({}),
104
+ });
105
+ /** pnpm when it ran this command (`pnpm dlx`), otherwise npm. */
106
+ export function detectManager(userAgent) {
107
+ return userAgent?.startsWith("pnpm/") === true ? "pnpm" : "npm";
108
+ }
109
+ async function ownManifest() {
110
+ return ownManifestSchema.parse(JSON.parse(await readFile(join(import.meta.dirname, "../../package.json"), "utf8")));
111
+ }
112
+ function projectManifest(own, spec) {
113
+ const dependencies = {
114
+ "@fungi.computer/oyster": spec ?? own.version,
115
+ "@fungi.computer/computer": own.dependencies["@fungi.computer/computer"] ?? "latest",
116
+ react: "^19.2.0",
117
+ "react-dom": "^19.2.0",
118
+ // Building the desktop here needs this exact pnpm, whatever the caller uses.
119
+ pnpm: localBuildPnpmVersion,
120
+ wrangler: own.peerDependencies.wrangler ?? "^4.127.1",
121
+ };
122
+ return (JSON.stringify({
123
+ name: "my-oyster",
124
+ private: true,
125
+ type: "module",
126
+ // npm 11.19 and newer skip dependency install scripts unless approved.
127
+ allowScripts: {
128
+ "@google/genai": false,
129
+ "@mongodb-js/zstd": false,
130
+ esbuild: true,
131
+ exifreader: false,
132
+ "node-liblzma": false,
133
+ protobufjs: false,
134
+ workerd: true,
135
+ },
136
+ scripts: { start: "npx @fungi.computer/oyster try" },
137
+ dependencies,
138
+ }, null, 2) + "\n");
139
+ }
140
+ // pnpm 11 refuses dependency build scripts it was not told about.
141
+ const pnpmWorkspace = `allowBuilds:
142
+ "@google/genai": false
143
+ "@mongodb-js/zstd": false
144
+ esbuild: true
145
+ exifreader: false
146
+ node-liblzma: false
147
+ protobufjs: false
148
+ workerd: true
149
+ `;
150
+ async function exists(path) {
151
+ return stat(path).then(() => true, () => false);
152
+ }
153
+ async function scaffold(directory, own, spec, manager) {
154
+ await mkdir(directory, { recursive: true });
155
+ const examples = join(import.meta.dirname, "../../examples/standalone");
156
+ for (const name of ["worker.ts", "wrangler.jsonc"])
157
+ await copyFile(join(examples, name), join(directory, name));
158
+ await writeFile(join(directory, "package.json"), projectManifest(own, spec));
159
+ if (manager === "pnpm")
160
+ await writeFile(join(directory, "pnpm-workspace.yaml"), pnpmWorkspace);
161
+ await writeFile(join(directory, ".gitignore"), ".oyster/\n.wrangler/\nnode_modules/\n.oyster-owner\n");
162
+ }
163
+ /** Write a child's output to a log file, and also to stderr when verbose. */
164
+ function captureOutput(child, log, verbose) {
165
+ for (const stream of [child.stdout, child.stderr]) {
166
+ stream?.pipe(log, { end: false });
167
+ if (verbose)
168
+ stream?.pipe(process.stderr, { end: false });
169
+ }
170
+ }
171
+ async function runInstall(directory, manager, verbose) {
172
+ await mkdir(join(directory, ".oyster"), { recursive: true });
173
+ const log = createWriteStream(join(directory, installLogFile));
174
+ try {
175
+ await new Promise((done, fail) => {
176
+ const child = spawn(manager, ["install"], {
177
+ cwd: directory,
178
+ stdio: ["ignore", "pipe", "pipe"],
179
+ shell: process.platform === "win32",
180
+ });
181
+ captureOutput(child, log, verbose);
182
+ child.on("error", (cause) => {
183
+ fail(new Error(`Could not run ${manager} install: ${cause.message}`));
184
+ });
185
+ child.on("close", (code) => {
186
+ if (code === 0)
187
+ done();
188
+ else
189
+ fail(new Error(`${manager} install failed (exit ${String(code)}).`));
190
+ });
191
+ });
192
+ }
193
+ finally {
194
+ log.end();
195
+ }
196
+ }
197
+ function portFree(port) {
198
+ return new Promise((done) => {
199
+ const server = createServer();
200
+ server.once("error", () => {
201
+ done(false);
202
+ });
203
+ server.listen(port, "127.0.0.1", () => {
204
+ server.close(() => {
205
+ done(true);
206
+ });
207
+ });
208
+ });
209
+ }
210
+ async function waitUntilReady(url, child, timeoutMs) {
211
+ const deadline = Date.now() + timeoutMs;
212
+ while (Date.now() < deadline) {
213
+ if (child.exitCode !== null)
214
+ return false;
215
+ const answered = await fetch(`${url}/login`, {
216
+ signal: AbortSignal.timeout(2_000),
217
+ }).then((response) => response.status < 500, () => false);
218
+ if (answered)
219
+ return true;
220
+ await new Promise((wake) => setTimeout(wake, 500));
221
+ }
222
+ return false;
223
+ }
224
+ async function tail(path) {
225
+ try {
226
+ const text = await readFile(path, "utf8");
227
+ return text.trim().split("\n").slice(-15).join("\n");
228
+ }
229
+ catch {
230
+ return "(no log was written)";
231
+ }
232
+ }
233
+ function startWrangler(input) {
234
+ return (async () => {
235
+ const wrangler = join(input.directory, "node_modules", "wrangler", "bin", "wrangler.js");
236
+ if (!(await exists(wrangler)))
237
+ throw new TryError(`wrangler is not installed in ${input.directory}.`, `Run \`npm install\` there, then run \`${command}\` again.`);
238
+ await mkdir(join(input.directory, ".oyster"), { recursive: true });
239
+ const log = join(input.directory, logFile);
240
+ const logStream = createWriteStream(log);
241
+ const url = `http://127.0.0.1:${String(input.port)}`;
242
+ const child = spawn(process.execPath, [
243
+ wrangler,
244
+ "dev",
245
+ "--local",
246
+ "--enable-containers=false",
247
+ "--ip",
248
+ "127.0.0.1",
249
+ "--port",
250
+ String(input.port),
251
+ "--local-upstream",
252
+ "oyster.test",
253
+ "--upstream-protocol",
254
+ "https",
255
+ "--var",
256
+ `OYSTER_OWNER_KEY:${input.key}`,
257
+ "--var",
258
+ "OYSTER_ORIGIN:https://oyster.test",
259
+ ], {
260
+ cwd: input.directory,
261
+ stdio: ["ignore", "pipe", "pipe"],
262
+ env: { ...process.env, WRANGLER_SEND_METRICS: "false" },
263
+ });
264
+ captureOutput(child, logStream, input.verbose);
265
+ const exited = new Promise((done) => {
266
+ child.on("close", (code) => {
267
+ logStream.end();
268
+ done(code);
269
+ });
270
+ });
271
+ const stop = async () => {
272
+ if (child.exitCode === null)
273
+ child.kill("SIGTERM");
274
+ const forced = setTimeout(() => {
275
+ child.kill("SIGKILL");
276
+ }, 10_000);
277
+ await exited;
278
+ clearTimeout(forced);
279
+ };
280
+ if (!(await waitUntilReady(url, child, 120_000))) {
281
+ await stop();
282
+ throw new TryError("Oyster did not start.", `Read ${log}, or run \`${command} --verbose\` to watch it start. The last lines:\n${await tail(log)}`);
283
+ }
284
+ return { stop, exited };
285
+ })();
286
+ }
287
+ function openBrowser(url) {
288
+ const [command, args] = process.platform === "darwin"
289
+ ? ["open", [url]]
290
+ : process.platform === "win32"
291
+ ? ["cmd", ["/c", "start", "", url]]
292
+ : ["xdg-open", [url]];
293
+ const child = spawn(command, args, { stdio: "ignore", detached: true });
294
+ child.on("error", () => undefined);
295
+ child.unref();
296
+ }
297
+ function untilInterrupted() {
298
+ return new Promise((done) => {
299
+ const once = () => {
300
+ process.off("SIGINT", once);
301
+ process.off("SIGTERM", once);
302
+ done();
303
+ };
304
+ process.on("SIGINT", once);
305
+ process.on("SIGTERM", once);
306
+ });
307
+ }
308
+ const realEffects = {
309
+ installDependencies: runInstall,
310
+ startServer: startWrangler,
311
+ installHello: installHelloApp,
312
+ installDesktop: async ({ directory, ...input }) => {
313
+ process.env.PATH = `${join(directory, "node_modules", ".bin")}${delimiter}${process.env.PATH ?? ""}`;
314
+ if (!(await isInstalled({ ...input, installationId: "tourtois" })))
315
+ await installLocalDesktop(input);
316
+ },
317
+ signInLink: startSignInLink,
318
+ open: openBrowser,
319
+ interrupted: untilInterrupted,
320
+ portFree,
321
+ };
322
+ export async function tryOyster(args, effects = realEffects, ui = createTryCli(args)) {
323
+ const { values, positionals } = parseArgs({
324
+ args: [...args],
325
+ allowPositionals: true,
326
+ strict: true,
327
+ options: {
328
+ port: { type: "string" },
329
+ "no-open": { type: "boolean" },
330
+ verbose: { type: "boolean" },
331
+ package: { type: "string" },
332
+ help: { type: "boolean", short: "h" },
333
+ },
334
+ });
335
+ const verbose = values.verbose === true;
336
+ if (values.help === true) {
337
+ process.stdout.write(tryHelp);
338
+ return;
339
+ }
340
+ if (positionals.length > 1)
341
+ throw new Error(tryUsage);
342
+ ui.welcome("Oyster: your own Apps, running on this machine");
343
+ const major = Number(process.versions.node.split(".")[0]);
344
+ if (major < requiredNodeMajor)
345
+ throw new TryError(`Oyster needs Node ${String(requiredNodeMajor)} or newer; this is Node ${process.versions.node}.`, `Install a current Node from https://nodejs.org, then run \`${command}\` again.`);
346
+ if (!gitAvailable())
347
+ throw new TryError("Oyster builds the Hello App from a git commit, so it needs Git.", `Install Git from https://git-scm.com, then run \`${command}\` again.`);
348
+ const port = Number(values.port ?? "8787");
349
+ if (!Number.isInteger(port) || port < 1 || port > 65_535)
350
+ throw new TryError("--port must be a number from 1 to 65535.", `For example: \`${command} --port 8788\`.`);
351
+ const directory = resolve(positionals[0] ??
352
+ ((await exists(join(process.cwd(), ownerKeyFile))) ? "." : "my-oyster"));
353
+ const keyPath = join(directory, ownerKeyFile);
354
+ const fresh = !(await exists(keyPath));
355
+ if (fresh) {
356
+ const occupied = (await exists(directory))
357
+ ? (await readdir(directory)).length > 0
358
+ : false;
359
+ if (occupied)
360
+ throw new TryError(`${directory} already has files and is not an Oyster made by \`oyster try\`.`, `Choose a new directory: \`${command} <directory>\`.`);
361
+ }
362
+ if (!(await effects.portFree(port)))
363
+ throw new TryError(`Port ${String(port)} on 127.0.0.1 is already in use.`, `Stop whatever is using it, or choose another port: \`${command} --port ${String(port + 1)}\`.`);
364
+ let key;
365
+ if (fresh) {
366
+ const manager = detectManager(process.env.npm_config_user_agent);
367
+ const own = await ownManifest();
368
+ await ui.task(`Creating ${basename(directory)}`, () => scaffold(directory, own, values.package, manager));
369
+ await ui
370
+ .task(`Installing dependencies with ${manager} (a minute or two)`, () => effects.installDependencies(directory, manager, verbose))
371
+ .catch((cause) => {
372
+ throw new TryError(cause instanceof Error ? cause.message : String(cause), `Read ${join(directory, installLogFile)} (or add --verbose), delete ${directory}, and run \`${command}\` again.`);
373
+ });
374
+ key = Array.from(randomBytes(24), (byte) => byte.toString(16).padStart(2, "0")).join("");
375
+ await writeFile(keyPath, key + "\n", { mode: 0o600 });
376
+ }
377
+ else {
378
+ key = (await readFile(keyPath, "utf8")).trim();
379
+ ui.info(`Restarting the Oyster in ${directory}`);
380
+ }
381
+ const url = `http://127.0.0.1:${String(port)}`;
382
+ const server = await ui.task("Starting Oyster", () => effects.startServer({ directory, port, key, verbose }));
383
+ let closeLink = () => undefined;
384
+ try {
385
+ await ui.task("Installing the Hello App", () => effects.installHello({ directory, url, key }));
386
+ await ui
387
+ .task(fresh
388
+ ? "Building Tourtois (about 2 min the first time)"
389
+ : "Checking Tourtois", () => effects.installDesktop({ directory, url, key }))
390
+ .catch((cause) => {
391
+ ui.warn(`Tourtois, the desktop, could not be built (${innermostError(cause).message}). Continuing with the Hello App.`, isNetworkFailure(innermostError(cause))
392
+ ? `Connect to the internet and run \`${command}\` again from ${directory} to try the desktop again.`
393
+ : `Run \`${command} --verbose\` from ${directory} and report this.`);
394
+ });
395
+ const link = await ui.task("Opening your desktop", async () => {
396
+ const made = await effects.signInLink({ oysterUrl: url, key });
397
+ closeLink = made.close;
398
+ if (values["no-open"] !== true && process.stdout.isTTY)
399
+ effects.open(made.url);
400
+ return made;
401
+ });
402
+ ui.note("Oyster is running", [
403
+ `Open (works once): ${link.url}`,
404
+ `Oyster: ${url}`,
405
+ `Owner key saved in: ${keyPath}`,
406
+ `Hello App source: ${join(directory, "hello-app")}`,
407
+ `Sign in later by pasting that key at ${url}/login.`,
408
+ "Press Ctrl-C to stop.",
409
+ ]);
410
+ const outcome = await Promise.race([
411
+ effects.interrupted().then(() => "interrupted"),
412
+ server.exited.then(() => "exited"),
413
+ ]);
414
+ if (outcome === "exited")
415
+ throw new TryError("Oyster stopped unexpectedly.", `Read ${join(directory, logFile)}, then run \`${command}\` again.`);
416
+ }
417
+ finally {
418
+ closeLink();
419
+ ui.step("Stopping Oyster");
420
+ await server.stop();
421
+ }
422
+ ui.outro("Stopped. Run the same command again to start it again.");
423
+ }
424
+ /** Whether `git` is available; Hello App packing reads its commit. */
425
+ function gitAvailable() {
426
+ return spawnSync("git", ["--version"], { stdio: "ignore" }).status === 0;
427
+ }
@@ -151,7 +151,7 @@ export class OysterComputerEgress extends WorkerEntrypoint {
151
151
  admitObject: (jobId, grant) => registry.admitBuildObject(jobId, computerObjectId, grant),
152
152
  // The bytes stream from the Computer to R2, which checks the digest;
153
153
  // the registry only admits the upload and later reads the facts.
154
- storeObject: (object, body, mediaType) => putContentObject(this.env.RELEASES, object,
154
+ storeObject: (object, body, mediaType, owner) => putContentObject(this.env.RELEASES, owner, object,
155
155
  // R2 takes a stream of known length; the stated length is exact.
156
156
  body?.pipeThrough(new FixedLengthStream(object.byteLength)) ?? null, mediaType),
157
157
  submitCandidate: (jobId, manifest, grant, credentialId) => registry.submitBuildCandidate(jobId, manifest, grant, credentialId),
@@ -18,7 +18,13 @@ export declare function workflowWebhookAbuse(options: {
18
18
  hostConcurrency: number;
19
19
  bindingConcurrency: number;
20
20
  };
21
- /** Per-instance streaming bound; durable run concurrency belongs to Braid. */
21
+ /**
22
+ * Per-instance streaming bound; durable run concurrency belongs to Braid.
23
+ * The rate key carries the tenant: a multi-tenant host (the Hub) serves
24
+ * every Team on one origin, and this lease is spent before any signature
25
+ * check, so a shared key would let one tenant's unauthenticated traffic
26
+ * refuse every other tenant's deliveries.
27
+ */
22
28
  hostLease(): Promise<null | (() => void)>;
23
29
  bindingAdmission(bindingId: string): Promise<boolean>;
24
30
  };
@@ -21,12 +21,18 @@ export function workflowWebhookAbuse(options) {
21
21
  let active = 0;
22
22
  return {
23
23
  concurrency,
24
- /** Per-instance streaming bound; durable run concurrency belongs to Braid. */
24
+ /**
25
+ * Per-instance streaming bound; durable run concurrency belongs to Braid.
26
+ * The rate key carries the tenant: a multi-tenant host (the Hub) serves
27
+ * every Team on one origin, and this lease is spent before any signature
28
+ * check, so a shared key would let one tenant's unauthenticated traffic
29
+ * refuse every other tenant's deliveries.
30
+ */
25
31
  async hostLease() {
26
32
  if (active >= concurrency.hostConcurrency)
27
33
  return null;
28
34
  const { success } = await options.hostRate.limit({
29
- key: rateKey(["workflow-webhooks", scope.host, "host"]),
35
+ key: rateKey([...prefix, "host"]),
30
36
  });
31
37
  // Native admission awaits I/O; simultaneous successful replies still
32
38
  // cannot overbook the local streaming ceiling.
package/dist/workers.d.ts CHANGED
@@ -260,8 +260,13 @@ export type OysterBindingContext<Env> = Readonly<{
260
260
  */
261
261
  export type OysterBindingRow<Env> = Readonly<{
262
262
  methods: Readonly<Record<string, FrameBindingMethod<OysterBindingResult>>>;
263
- /** Serve one decoded packet; the Instance has already admitted its frame and grant. */
264
- dispatch(context: OysterBindingContext<Env>, frame: InvocationFrame<OysterInvocationHost>, props: FrameBindingProps, method: string, args: readonly unknown[]): Promise<OysterBindingResult>;
263
+ /**
264
+ * Serve one decoded packet; the Instance has already admitted its frame and
265
+ * grant. `admitted` is the installation that packet's one Registry read
266
+ * re-admitted: its approved grants are the resource ceiling a row applies
267
+ * to results no single `requestedResource` selects.
268
+ */
269
+ dispatch(context: OysterBindingContext<Env>, frame: InvocationFrame<OysterInvocationHost>, props: FrameBindingProps, method: string, args: readonly unknown[], admitted: Installation): Promise<OysterBindingResult>;
265
270
  }>;
266
271
  /**
267
272
  * The bindings an Instance serves, keyed by the closed App binding vocabulary;
package/dist/workers.js CHANGED
@@ -807,7 +807,7 @@ export class OysterInstance extends DurableObject {
807
807
  if (!required.every((operation) => selected.includes(operation)))
808
808
  throw new AppInstanceError("binding_not_granted");
809
809
  }
810
- const result = await row.dispatch(this.#bindingContext, frame, props, method, args);
810
+ const result = await row.dispatch(this.#bindingContext, frame, props, method, args, current);
811
811
  if (this.frames.active(props.frameId) !== frame)
812
812
  throw new AppInstanceError("revoked");
813
813
  assertBackgroundBinding(frame, props.binding);