@fungi.computer/oyster 0.56.1 → 0.57.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.
Files changed (50) hide show
  1. package/dist/agent-computer-source.js +4 -1
  2. package/dist/auth.d.ts +12 -4
  3. package/dist/auth.js +85 -24
  4. package/dist/boot-capability-route.js +5 -1
  5. package/dist/boot-gate.d.ts +5 -0
  6. package/dist/boot-gate.js +12 -2
  7. package/dist/boot-host-script.js +1 -1
  8. package/dist/boot-mount.d.ts +7 -1
  9. package/dist/boot-mount.js +11 -5
  10. package/dist/computer-api.d.ts +2 -0
  11. package/dist/embed-metafiles.js +2 -2
  12. package/dist/embed-scripts.js +1 -1
  13. package/dist/hello-app-script.js +1 -1
  14. package/dist/host-page-assets.js +1 -1
  15. package/dist/host-page-lazy.d.ts +2 -0
  16. package/dist/host-page-lazy.js +8 -0
  17. package/dist/host-page.d.ts +19 -1
  18. package/dist/host-page.js +61 -11
  19. package/dist/host.d.ts +2 -0
  20. package/dist/host.js +4 -1
  21. package/dist/owner-sessions.d.ts +25 -0
  22. package/dist/owner-sessions.js +50 -0
  23. package/dist/page/boot-host.js +20 -2
  24. package/dist/page-script.js +1 -1
  25. package/dist/platform-skills.generated.d.ts +1 -1
  26. package/dist/platform-skills.generated.js +1 -1
  27. package/dist/standalone/agent-computers.js +1 -1
  28. package/dist/standalone/agents.js +1 -0
  29. package/dist/standalone/builds.js +5 -0
  30. package/dist/standalone/candidate-preview.d.ts +25 -0
  31. package/dist/standalone/candidate-preview.js +265 -0
  32. package/dist/standalone/computer-api.js +4 -1
  33. package/dist/standalone/computer-fleet.js +3 -1
  34. package/dist/standalone/tenancy.d.ts +1 -1
  35. package/dist/standalone/tenancy.js +9 -1
  36. package/dist/standalone/worker.js +12 -2
  37. package/dist/starter-agent.js +5 -2
  38. package/dist/tenancy/owner-key.d.ts +4 -1
  39. package/dist/tenancy/owner-key.js +27 -2
  40. package/dist/upgrade/old-worker-http.js +2 -6
  41. package/dist/workers-git.js +10 -2
  42. package/dist/workers.d.ts +11 -0
  43. package/dist/workers.js +33 -1
  44. package/docs/api/README.md +5 -3
  45. package/docs/api/auth.md +96 -8
  46. package/docs/api/computer-api.md +9 -6
  47. package/docs/api/host.md +1 -0
  48. package/docs/api/tenancy/owner-key.md +1 -0
  49. package/docs/api/workers.md +81 -0
  50. package/package.json +17 -17
@@ -28,7 +28,10 @@ function capturedConnections(options, captured) {
28
28
  attachmentId: attachment.attachmentId,
29
29
  name: attachment.name,
30
30
  namespace: ["computers"],
31
- files: { port: ports.files },
31
+ files: {
32
+ port: ports.files,
33
+ pathInstructions: 'Start with files.list({path: "."}) to discover the working folder. Use relative file paths from that listing, such as "AGENTS.md"; a leading slash names the filesystem root, not the working folder. Read an instructions file only when listed.',
34
+ },
32
35
  computer: ports.computer,
33
36
  };
34
37
  });
package/dist/auth.d.ts CHANGED
@@ -1,15 +1,23 @@
1
1
  import type { OysterAuth } from "./host.js";
2
2
  import type { OysterKeyStore } from "./keys.js";
3
+ import { type OwnerSessions } from "./owner-sessions.js";
4
+ export { ownerSessionLifetimeMs, ownerSessionStore, type OwnerSessions, type OwnerSessionSql, } from "./owner-sessions.js";
3
5
  /** Cookie emitted by ownerKeyAuth, for composing credential-specific adapters. */
4
6
  export declare const ownerKeyCookieName = "oyster_session";
5
7
  /** Marks a browser that has signed in here before; it carries no authority. */
6
8
  export declare const returningCookieName = "oyster_returning";
7
9
  /**
8
- * Single-owner sign-in: a bearer token, a Git Basic-auth password, or a session
9
- * cookie holding the owner key's digest. The key is never stored in the browser.
10
+ * Whether `request` carries the owner key itself, as a Bearer token or a Git
11
+ * Basic-auth password. `absent` means it carries neither.
10
12
  */
11
- export declare function ownerKeyAuth(ownerKey: string, ownerId?: string): OysterAuth;
13
+ export declare function ownerKeyCredential(ownerKey: string, request: Request): Promise<"owner" | "refused" | "absent">;
14
+ /**
15
+ * Single-owner sign-in: a bearer token, a Git Basic-auth password, or a
16
+ * browser session. A session is a random id in the cookie; `sessions` keeps
17
+ * its digest, owner and expiry, and logging out revokes it.
18
+ */
19
+ export declare function ownerKeyAuth(ownerKey: string, ownerId: string, sessions: OwnerSessions): OysterAuth;
12
20
  /** How stale a key's last-used time may be: calls inside this window do not re-stamp it. */
13
21
  export declare const lastUsedGranularityMs: number;
14
22
  /** The owner key, or a named key admitted as its canonical Team-key actor. */
15
- export declare function ownerOrKeyAuth(ownerKey: string, ownerId: string, keys: () => Pick<OysterKeyStore, "verify" | "touch">): OysterAuth;
23
+ export declare function ownerOrKeyAuth(ownerKey: string, ownerId: string, sessions: OwnerSessions, keys: () => Pick<OysterKeyStore, "verify" | "touch">): OysterAuth;
package/dist/auth.js CHANGED
@@ -3,7 +3,10 @@ import * as Schema from "effect/Schema";
3
3
  import { parse } from "hono/utils/cookie";
4
4
  import { presentedGitKey } from "./git-auth.js";
5
5
  import { sha256 } from "./release.js";
6
+ import { sameOriginRequest } from "./request-origin.js";
6
7
  import { isLoopbackHttp } from "./tenancy/registry-record.js";
8
+ import { ownerSessionLifetimeMs, } from "./owner-sessions.js";
9
+ export { ownerSessionLifetimeMs, ownerSessionStore, } from "./owner-sessions.js";
7
10
  /** Cookie emitted by ownerKeyAuth, for composing credential-specific adapters. */
8
11
  export const ownerKeyCookieName = "oyster_session";
9
12
  /** Marks a browser that has signed in here before; it carries no authority. */
@@ -21,13 +24,57 @@ async function constantTimeEqual(a, b) {
21
24
  return difference === 0;
22
25
  }
23
26
  /**
24
- * Single-owner sign-in: a bearer token, a Git Basic-auth password, or a session
25
- * cookie holding the owner key's digest. The key is never stored in the browser.
27
+ * Whether `request` carries the owner key itself, as a Bearer token or a Git
28
+ * Basic-auth password. `absent` means it carries neither.
26
29
  */
27
- export function ownerKeyAuth(ownerKey, ownerId = "owner") {
30
+ export async function ownerKeyCredential(ownerKey, request) {
31
+ const authorization = request.headers.get("Authorization");
32
+ if (authorization?.startsWith("Bearer ") === true)
33
+ return (await constantTimeEqual(authorization.slice(7), ownerKey))
34
+ ? "owner"
35
+ : "refused";
36
+ if (authorization?.startsWith("Basic ") === true) {
37
+ const presented = presentedGitKey(request);
38
+ return presented.kind === "key" &&
39
+ (await constantTimeEqual(presented.value, ownerKey))
40
+ ? "owner"
41
+ : "refused";
42
+ }
43
+ return "absent";
44
+ }
45
+ /** The session id a browser presents, or null without one. */
46
+ function presentedSession(request) {
47
+ const value = parse(request.headers.get("Cookie") ?? "", ownerKeyCookieName)[ownerKeyCookieName];
48
+ return value === undefined || value === "" ? null : value;
49
+ }
50
+ /**
51
+ * What the server stores for a session id: an HMAC of it keyed by the owner
52
+ * key, never the id itself. Rotating the owner key ends every session.
53
+ */
54
+ async function sessionDigest(ownerKey, id) {
55
+ const encoder = new TextEncoder();
56
+ const key = await crypto.subtle.importKey("raw", encoder.encode(ownerKey), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
57
+ const mac = new Uint8Array(await crypto.subtle.sign("HMAC", key, encoder.encode(id)));
58
+ return `hmac-sha256:${Array.from(mac, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
59
+ }
60
+ /** A new random session id: 32 bytes, base64url. */
61
+ function newSessionId() {
62
+ const bytes = crypto.getRandomValues(new Uint8Array(32));
63
+ return btoa(String.fromCharCode(...bytes))
64
+ .replaceAll("+", "-")
65
+ .replaceAll("/", "_")
66
+ .replace(/=+$/u, "");
67
+ }
68
+ /** Secure everywhere except loopback HTTP, where Safari would drop it and the traffic never leaves this machine. */
69
+ const cookieFlags = (request) => `Path=/; HttpOnly;${isLoopbackHttp(new URL(request.url)) ? "" : " Secure;"} SameSite=Strict`;
70
+ /**
71
+ * Single-owner sign-in: a bearer token, a Git Basic-auth password, or a
72
+ * browser session. A session is a random id in the cookie; `sessions` keeps
73
+ * its digest, owner and expiry, and logging out revokes it.
74
+ */
75
+ export function ownerKeyAuth(ownerKey, ownerId, sessions) {
28
76
  if (ownerKey.length < 24)
29
77
  throw new Error("OYSTER_OWNER_KEY must be at least 24 characters");
30
- const sessionValue = sha256(new TextEncoder().encode(`oyster:${ownerKey}`));
31
78
  const owner = {
32
79
  kind: "admitted",
33
80
  principal: { actor: { kind: "member", memberId: ownerId }, role: "owner" },
@@ -37,21 +84,14 @@ export function ownerKeyAuth(ownerKey, ownerId = "owner") {
37
84
  ? owner.principal
38
85
  : null),
39
86
  async authenticate(request) {
40
- const authorization = request.headers.get("Authorization");
41
- if (authorization?.startsWith("Bearer ") === true)
42
- return (await constantTimeEqual(authorization.slice(7), ownerKey))
43
- ? owner
44
- : { kind: "refused", status: 401 };
45
- if (authorization?.startsWith("Basic ") === true) {
46
- const presented = presentedGitKey(request);
47
- return presented.kind === "key" &&
48
- (await constantTimeEqual(presented.value, ownerKey))
87
+ const credential = await ownerKeyCredential(ownerKey, request);
88
+ if (credential !== "absent")
89
+ return credential === "owner"
49
90
  ? owner
50
91
  : { kind: "refused", status: 401 };
51
- }
52
- const cookie = parse(request.headers.get("Cookie") ?? "", ownerKeyCookieName)[ownerKeyCookieName];
53
- if (cookie !== undefined &&
54
- (await constantTimeEqual(cookie, await sessionValue)))
92
+ const session = presentedSession(request);
93
+ if (session !== null &&
94
+ (await sessions.owner(await sessionDigest(ownerKey, session), Date.now())) === ownerId)
55
95
  return owner;
56
96
  return { kind: "refused", status: 401 };
57
97
  },
@@ -70,21 +110,40 @@ export function ownerKeyAuth(ownerKey, ownerId = "owner") {
70
110
  if (Option.isNone(form) ||
71
111
  !(await constantTimeEqual(form.value.key, ownerKey)))
72
112
  return new Response("Wrong key", { status: 401 });
73
- // Secure everywhere except loopback HTTP, where Safari would drop it and
74
- // the traffic never leaves this machine.
75
- const secure = isLoopbackHttp(new URL(request.url)) ? "" : " Secure;";
113
+ const session = newSessionId();
114
+ await sessions.open(ownerId, await sessionDigest(ownerKey, session), Date.now());
115
+ const flags = cookieFlags(request);
76
116
  const headers = new Headers({ Location: "/" });
77
- headers.append("Set-Cookie", `${ownerKeyCookieName}=${await sessionValue}; Path=/; HttpOnly;${secure} SameSite=Strict; Max-Age=2592000`);
78
- headers.append("Set-Cookie", `${returningCookieName}=1; Path=/; HttpOnly;${secure} SameSite=Strict; Max-Age=31536000`);
117
+ headers.append("Set-Cookie", `${ownerKeyCookieName}=${session}; ${flags}; Max-Age=${String(ownerSessionLifetimeMs / 1000)}`);
118
+ headers.append("Set-Cookie", `${returningCookieName}=1; ${flags}; Max-Age=31536000`);
79
119
  return new Response(null, { status: 303, headers });
80
120
  },
121
+ async logout(request) {
122
+ // A cross-site form must not be able to sign the owner out.
123
+ if (!sameOriginRequest(request))
124
+ return new Response("Same origin required", {
125
+ status: 403,
126
+ headers: { "Cache-Control": "no-store" },
127
+ });
128
+ const session = presentedSession(request);
129
+ if (session !== null)
130
+ await sessions.revoke(await sessionDigest(ownerKey, session));
131
+ return new Response(null, {
132
+ status: 303,
133
+ headers: {
134
+ Location: "/login",
135
+ "Set-Cookie": `${ownerKeyCookieName}=; ${cookieFlags(request)}; Max-Age=0`,
136
+ "Cache-Control": "no-store",
137
+ },
138
+ });
139
+ },
81
140
  };
82
141
  }
83
142
  /** How stale a key's last-used time may be: calls inside this window do not re-stamp it. */
84
143
  export const lastUsedGranularityMs = 5 * 60 * 1000;
85
144
  /** The owner key, or a named key admitted as its canonical Team-key actor. */
86
- export function ownerOrKeyAuth(ownerKey, ownerId, keys) {
87
- const owner = ownerKeyAuth(ownerKey, ownerId);
145
+ export function ownerOrKeyAuth(ownerKey, ownerId, sessions, keys) {
146
+ const owner = ownerKeyAuth(ownerKey, ownerId, sessions);
88
147
  // When this isolate last tried to stamp each key. A key's "Last used" is
89
148
  // accurate to `lastUsedGranularityMs`, so a burst of calls costs one write.
90
149
  const lastStamp = new Map();
@@ -134,5 +193,7 @@ export function ownerOrKeyAuth(ownerKey, ownerId, keys) {
134
193
  },
135
194
  login: (request) => owner.login?.(request) ??
136
195
  Promise.resolve(new Response("Sign-in is not available", { status: 404 })),
196
+ logout: (request) => owner.logout?.(request) ??
197
+ Promise.resolve(new Response("Sign-out is not available", { status: 404 })),
137
198
  };
138
199
  }
@@ -80,7 +80,11 @@ export async function serveBootCapability(request, options) {
80
80
  const parentPath = `${root.pathname}index.html`;
81
81
  const bridgePath = `${root.pathname}bridge.js`;
82
82
  if (url.pathname === parentPath) {
83
- return new Response(bootParentDocument(checkedLease.identity, entry), {
83
+ return new Response(await bootParentDocument(checkedLease.identity, entry, {
84
+ bridge: "./bridge.js",
85
+ sandbox: "allow-scripts",
86
+ notice: null,
87
+ }), {
84
88
  status: 200,
85
89
  headers: {
86
90
  ...parentSecurityHeaders(candidateBase.href),
@@ -109,6 +109,11 @@ export declare const bootUiSchema: z.ZodObject<{
109
109
  export type BootUi = z.output<typeof bootUiSchema>;
110
110
  /** Captures the same no-grant UI representation as a private candidate preview. */
111
111
  export declare function readBootUi(store: ArtifactStore, release: Release): Promise<BootUi | null>;
112
+ /** The same verified UI plus its declared name, without widening the boot lease. */
113
+ export declare function readPreviewUi(store: ArtifactStore, release: Release): Promise<Readonly<{
114
+ ui: BootUi | null;
115
+ appName: string;
116
+ }>>;
112
117
  export declare const bootCheckResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
113
118
  kind: z.ZodLiteral<"passed">;
114
119
  }, z.core.$strict>, z.ZodObject<{
package/dist/boot-gate.js CHANGED
@@ -147,14 +147,24 @@ export const bootUiSchema = z.strictObject({
147
147
  });
148
148
  /** Captures the same no-grant UI representation as a private candidate preview. */
149
149
  export async function readBootUi(store, release) {
150
+ return (await readPreviewUi(store, release)).ui;
151
+ }
152
+ /** The same verified UI plus its declared name, without widening the boot lease. */
153
+ export async function readPreviewUi(store, release) {
150
154
  const verified = await verifyRelease(store, release, defaultAssetPolicy, false);
151
- if (verified.ui === null)
152
- return null;
155
+ return {
156
+ ui: verifiedBootUi(verified, release),
157
+ appName: verified.declaration?.displayName ?? "App",
158
+ };
159
+ }
160
+ function verifiedBootUi(verified, release) {
153
161
  const identity = {
154
162
  appId: release.appId,
155
163
  releaseId: release.releaseId,
156
164
  surfaceId: "host-boot",
157
165
  };
166
+ if (verified.ui === null)
167
+ return null;
158
168
  if (verified.ui.kind === "html") {
159
169
  return {
160
170
  identity,