@fungi.computer/oyster 0.14.1 → 0.16.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 (61) hide show
  1. package/README.md +178 -1552
  2. package/dist/agents.d.ts +8 -0
  3. package/dist/agents.js +6 -0
  4. package/dist/app-builds.d.ts +5 -6
  5. package/dist/app-builds.js +3 -10
  6. package/dist/apps/permissions.js +8 -1
  7. package/dist/auth.d.ts +2 -0
  8. package/dist/auth.js +9 -8
  9. package/dist/boot-host-script.js +1 -1
  10. package/dist/build/candidate-cli.mjs +4 -0
  11. package/dist/catalog-frame.d.ts +0 -1
  12. package/dist/computer.d.ts +5 -0
  13. package/dist/computer.js +1 -0
  14. package/dist/embed-metafiles.js +2 -2
  15. package/dist/embed-scripts.js +3 -3
  16. package/dist/hello-app-script.js +1 -1
  17. package/dist/host-page-assets.js +1 -1
  18. package/dist/host-page.d.ts +5 -1
  19. package/dist/host-page.js +23 -23
  20. package/dist/host.js +6 -1
  21. package/dist/page/app-access.js +23 -1
  22. package/dist/page/app-permissions.js +165 -50
  23. package/dist/page/app-rights.d.ts +8 -0
  24. package/dist/page/app-rights.js +13 -0
  25. package/dist/page/computer-handles.d.ts +15 -0
  26. package/dist/page/computer-handles.js +4 -1
  27. package/dist/page/mount.d.ts +5 -0
  28. package/dist/page/mount.js +4 -0
  29. package/dist/page-script.js +3 -3
  30. package/dist/standalone/agents.js +10 -0
  31. package/dist/standalone/app-set.d.ts +9 -0
  32. package/dist/standalone/app-set.js +43 -0
  33. package/dist/standalone/app-source.js +16 -1
  34. package/dist/standalone/builds.d.ts +2 -2
  35. package/dist/standalone/builds.js +4 -0
  36. package/dist/standalone/cloudflare-account.d.ts +10 -0
  37. package/dist/standalone/cloudflare-account.js +17 -0
  38. package/dist/standalone/computer.d.ts +8 -3
  39. package/dist/standalone/computer.js +26 -3
  40. package/dist/standalone/install-apps-cli.js +1 -1
  41. package/dist/standalone/local-desktop.d.ts +19 -2
  42. package/dist/standalone/local-desktop.js +38 -15
  43. package/dist/standalone/media.d.ts +2 -0
  44. package/dist/standalone/media.js +17 -1
  45. package/dist/standalone/registry.d.ts +4 -1
  46. package/dist/standalone/registry.js +6 -0
  47. package/dist/standalone/sign-in-link.d.ts +1 -1
  48. package/dist/standalone/sign-in-link.js +9 -18
  49. package/dist/standalone/try-cli.d.ts +7 -0
  50. package/dist/standalone/try-cli.js +88 -8
  51. package/dist/starter-agent.d.ts +59 -0
  52. package/dist/starter-agent.js +85 -0
  53. package/docs/api/README.md +744 -88
  54. package/docs/api/agents.md +6 -0
  55. package/docs/api/auth.md +10 -0
  56. package/docs/api/computer.md +4 -0
  57. package/docs/api/page/mount.md +2 -0
  58. package/docs/api/workers-git.md +14 -9
  59. package/docs/api/workers.md +8 -3
  60. package/docs/site/agent-quickstart.mdx +1 -1
  61. package/package.json +34 -50
@@ -1,6 +1,6 @@
1
1
  import { type AppPermissionsViewData } from "./apps/permissions.js";
2
2
  /** Human-facing states only. API refusals keep their original wire format. */
3
- export type HostPageState = "permissions" | "root" | "empty" | "login" | "login-invalid" | "key-help" | "signing-in" | "link-expired" | "not-found" | "server-error" | "access-denied" | "desktop-missing";
3
+ export type HostPageState = "permissions" | "root" | "empty" | "login" | "login-invalid" | "key-help" | "signing-in" | "not-found" | "server-error" | "access-denied" | "desktop-missing";
4
4
  export type HostPageOptions = Readonly<{
5
5
  state: HostPageState;
6
6
  title?: string;
@@ -15,6 +15,10 @@ export type HostPageOptions = Readonly<{
15
15
  accessHref?: string;
16
16
  }>[];
17
17
  reset?: boolean;
18
+ /** Login only: this browser has signed in to this Oyster before. */
19
+ returning?: boolean;
20
+ /** Login only: the visitor arrived through a one-time link that was already used. */
21
+ usedLink?: boolean;
18
22
  /** Only the single-use helper passes a key, in a POST field, never a URL. */
19
23
  signIn?: Readonly<{
20
24
  action: string;
package/dist/host-page.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { createElement as h } from "react";
2
2
  import { renderToStaticMarkup } from "react-dom/server";
3
3
  import { TradingCard } from "@fungi.computer/caps/components/trading-card";
4
+ import { Alert } from "@fungi.computer/caps/components/alert";
5
+ import { Status } from "@fungi.computer/caps/components/status";
4
6
  import { Button } from "@fungi.computer/caps/components/button";
5
7
  import { Input } from "@fungi.computer/caps/components/input";
6
8
  import { Card, CardHeader, CardTitle, CardContent, } from "@fungi.computer/caps/components/card";
@@ -25,7 +27,7 @@ const copy = {
25
27
  "Your Oyster is running. Install an App to give it something to open.",
26
28
  ],
27
29
  login: [
28
- "Welcome back.",
30
+ "Welcome.",
29
31
  "Your Oyster · sign in",
30
32
  "Use the owner key saved with this Oyster. It stays private; it never belongs in a shared link.",
31
33
  ],
@@ -44,14 +46,9 @@ const copy = {
44
46
  "One-time sign-in",
45
47
  "This private link signs you in on this computer. It works once. Continue to your Oyster below if it does not open automatically.",
46
48
  ],
47
- "link-expired": [
48
- "This link has had its turn.",
49
- "One-time link · expired or already used",
50
- "Start your local Oyster again with the same project directory to get a fresh link, or sign in with your saved owner key.",
51
- ],
52
49
  "not-found": [
53
50
  "Nothing growing here.",
54
- "404 · page not found",
51
+ "404",
55
52
  "This address doesn’t point to an available page. Your desktop is a good place to start again.",
56
53
  ],
57
54
  "server-error": [
@@ -113,12 +110,6 @@ const abilities = {
113
110
  "Continue below if it does not.",
114
111
  "Use your saved key if needed.",
115
112
  ],
116
- "link-expired": [
117
- "Get back into Oyster",
118
- "Sign in with your saved key.",
119
- "Or restart the same local trial.",
120
- "Open the fresh link once.",
121
- ],
122
113
  "not-found": [
123
114
  "Find an available page",
124
115
  "Return to your Oyster.",
@@ -191,6 +182,12 @@ function pageContent(options, url) {
191
182
  if (state === "login" || state === "login-invalid") {
192
183
  content.push(h("form", { method: "post", action: url("/login"), className: "form-stack" }, state === "login-invalid"
193
184
  ? h("p", { className: "error-copy", role: "alert" }, "The key wasn’t accepted. Please check it and try again.")
185
+ : null, state === "login" && options.usedLink === true
186
+ ? h(Alert, { tone: "warning", role: "status" }, h("div", { className: "notice" }, h(Status, {
187
+ glyph: "dot",
188
+ tone: "warning",
189
+ "aria-hidden": true,
190
+ }), h("span", null, "This link was already used. Paste the key from ", h("code", null, ".oyster-owner"), " in your Oyster project.")))
194
191
  : null, h("label", { htmlFor: "owner-key" }, "Owner key"), h(Input, {
195
192
  id: "owner-key",
196
193
  name: "key",
@@ -199,7 +196,9 @@ function pageContent(options, url) {
199
196
  autoComplete: "current-password",
200
197
  placeholder: "Paste your owner key",
201
198
  "aria-invalid": state === "login-invalid" ? true : undefined,
202
- }), h("p", { className: "helper" }, "For a local trial: .oyster-owner in your Oyster project."), h("div", { className: "actions" }, h(Button, { type: "submit" }, state === "login" ? "Sign in" : "Try again"), link("Find my key", url("/login/key-help"), true))));
199
+ }), options.usedLink === true
200
+ ? null
201
+ : h("p", { className: "helper field-hint" }, "For a local trial: ", h("code", null, ".oyster-owner"), " in your Oyster project."), h("div", { className: "actions" }, h(Button, { type: "submit" }, state === "login" ? "Sign in" : "Try again"), link("Find my key", url("/login/key-help"), true))));
203
202
  }
204
203
  else if (state === "signing-in" && signIn) {
205
204
  content.push(h("form", { method: "post", action: signIn.action, "data-auto-sign-in": true }, h("input", { type: "hidden", name: "key", value: signIn.key }), h("div", { className: "actions" }, h(Button, { type: "submit" }, "Continue to Oyster"), link("Having trouble?", url("/login/key-help"), true))));
@@ -208,9 +207,6 @@ function pageContent(options, url) {
208
207
  content.push(h("p", { className: "detail" }, "If the original key is gone, follow the owner recovery instructions. Oyster cannot reveal or reconstruct it. No key reset happens from this page."));
209
208
  actions.push(link("Back to sign-in", url("/login")), link("Read recovery steps", `${docs}/guides/run-your-own-oyster`, true));
210
209
  }
211
- else if (state === "link-expired") {
212
- actions.push(link("Sign in with my key", url("/login")), link("Read restart steps", `${docs}/oyster-quickstart`, true));
213
- }
214
210
  else if (state === "root" ||
215
211
  state === "empty" ||
216
212
  state === "desktop-missing") {
@@ -242,7 +238,6 @@ function illustration(state, assetUrl) {
242
238
  "login-invalid",
243
239
  "key-help",
244
240
  "signing-in",
245
- "link-expired",
246
241
  "access-denied",
247
242
  ].includes(state);
248
243
  const art = keyArt
@@ -254,12 +249,12 @@ function illustration(state, assetUrl) {
254
249
  name: keyArt
255
250
  ? "A little help"
256
251
  : art === "offline"
257
- ? "We’ll reconnect"
252
+ ? "Page not found"
258
253
  : "Room to grow",
259
254
  stage: "OYSTER",
260
255
  stat: "✦",
261
256
  finish: "holo",
262
- style: { aspectRatio: "5 / 7" },
257
+ style: { aspectRatio: "auto" },
263
258
  art: h("div", {
264
259
  className: "ink-art",
265
260
  "data-ink": assetUrl(`${art}.json`),
@@ -274,7 +269,7 @@ function illustration(state, assetUrl) {
274
269
  src: assetUrl(`${art}-dark.avif`),
275
270
  alt: "",
276
271
  })), h("div", { className: "ink-live" })),
277
- typeLine: eyebrow,
272
+ typeLine: state === "not-found" ? "Off the map" : eyebrow,
278
273
  move: {
279
274
  name: ability,
280
275
  children: h("ol", { className: "ability-steps" }, ...steps.map((step) => h("li", { key: step }, step))),
@@ -286,7 +281,10 @@ function illustration(state, assetUrl) {
286
281
  /** One server-rendered Caps composition, usable without styles, art or JS. */
287
282
  export async function hostPage(options) {
288
283
  const { state, title = "Oyster" } = options;
289
- const [heading, eyebrow, description] = copy[state];
284
+ const [baseHeading, eyebrow, description] = copy[state];
285
+ const heading = state === "login" && options.returning === true
286
+ ? "Welcome back."
287
+ : baseHeading;
290
288
  const url = (path) => options.oysterUrl ? new URL(path, options.oysterUrl).href : path;
291
289
  // A failed decorative module must still leave the form and recovery readable.
292
290
  let assets;
@@ -315,7 +313,9 @@ export async function hostPage(options) {
315
313
  ? h("div", { className: "actions" }, ...actions)
316
314
  : null, h("p", { className: "helper" }, state === "login" || state === "login-invalid"
317
315
  ? "Your key is sent only to this Oyster."
318
- : h("a", { href: `${docs}/agents/index.md` }, "Hand your LLM the setup guide →")))), h("footer", { className: "page-footer" }, h("span", null, "Oyster · A home for your Apps")), assetUrl("host-page.js")
316
+ : state === "not-found"
317
+ ? null
318
+ : h("a", { href: `${docs}/agents/index.md` }, "Hand your LLM the setup guide →")))), h("footer", { className: "page-footer" }, h("span", null, "Oyster · A home for your Apps")), assetUrl("host-page.js")
319
319
  ? h("script", { type: "module", src: assetUrl("host-page.js") })
320
320
  : null, options.permissions
321
321
  ? h("script", {
package/dist/host.js CHANGED
@@ -28,6 +28,8 @@ export { capabilityDescriptorSchema, capabilityMethodKindSchema, capabilityMetho
28
28
  import { selectionOf, } from "./index.js";
29
29
  import { parseRelease, readCachedVerified, sha256, } from "./release.js";
30
30
  import { createGitDoor } from "./git.js";
31
+ import { getCookie } from "hono/cookie";
32
+ import { returningCookieName } from "./auth.js";
31
33
  import { buildGitPassPrefix, presentedGitKey } from "./git-auth.js";
32
34
  import { workflowGitPassPrefix } from "@fungi.computer/braid/runtime";
33
35
  import { loadPageAssets, PageAssetsLoadError, } from "./page-assets.js";
@@ -372,7 +374,10 @@ export function oysterRouteTable(host) {
372
374
  });
373
375
  };
374
376
  table.get("/_oyster/host-assets/*", publicRoute("content-addressed host illustrations and layout"), (context) => hostPageAsset(new URL(context.req.url).pathname));
375
- table.get("/login", publicRoute("the sign-in form"), () => page("login"));
377
+ table.get("/login", publicRoute("the sign-in form"), (context) => page("login", {
378
+ returning: getCookie(context, returningCookieName) === "1",
379
+ usedLink: context.req.query("link") === "used",
380
+ }));
376
381
  table.get("/login/key-help", publicRoute("owner key recovery instructions, without a reset"), () => page("key-help"));
377
382
  table.post("/login", door("the host's own sign-in checks the posted key"), (context) => host.auth.login === undefined
378
383
  ? refusal(404, "Sign-in is not available")
@@ -1,4 +1,23 @@
1
1
  import { grantRequestFor, appPermissionPageSchema, } from "../apps/permissions.js";
2
+ /** The families beyond Agents and Computers, which the sheet lists in words. */
3
+ function otherFamilies(input) {
4
+ return {
5
+ git: input.git ?? [],
6
+ workflows: input.workflows ?? [],
7
+ events: input.events ?? [],
8
+ generation: input.generation ?? [],
9
+ };
10
+ }
11
+ function asksForAnything(input) {
12
+ return [
13
+ input.agents,
14
+ input.computers,
15
+ input.git,
16
+ input.workflows,
17
+ input.events,
18
+ input.generation,
19
+ ].some((list) => list !== undefined && list.length > 0);
20
+ }
2
21
  /**
3
22
  * Keep standalone consent in the Oyster host: the picked shell draws the
4
23
  * prompt, while Oyster bounds the request and commits through its owner CAS.
@@ -10,7 +29,8 @@ export function createShellAppAccess(directory) {
10
29
  const app = current.apps.find((row) => row.surfaceId === surfaceId);
11
30
  const installationId = app?.installationId ?? null;
12
31
  const customize = () => dialog.customize(installationId);
13
- if (installationId === null)
32
+ // An empty request is the App asking to open its permissions.
33
+ if (installationId === null || !asksForAnything(input))
14
34
  return customize();
15
35
  const path = `/api/installations/${encodeURIComponent(installationId)}/grants`;
16
36
  const response = await fetch(path, {
@@ -38,6 +58,7 @@ export function createShellAppAccess(directory) {
38
58
  appName: view.appName,
39
59
  agents: input.agents ?? [],
40
60
  computers: input.computers ?? [],
61
+ others: otherFamilies(input),
41
62
  refusal: {
42
63
  code: decision.code,
43
64
  message: "Allow for this window is unavailable on this Oyster. No access was changed. Use Customize to review Computer permissions explicitly.",
@@ -52,6 +73,7 @@ export function createShellAppAccess(directory) {
52
73
  appName: view.appName,
53
74
  agents: input.agents ?? [],
54
75
  computers: input.computers ?? [],
76
+ others: otherFamilies(input),
55
77
  allow: async () => {
56
78
  const saved = await fetch(path, {
57
79
  method: "PUT",
@@ -1,16 +1,146 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useCallback, useEffect, useId, useRef, useState } from "react";
3
+ import { Disclosure } from "@fungi.computer/caps/components/disclosure";
4
+ import { Alert } from "@fungi.computer/caps/components/alert";
3
5
  import { Button } from "@fungi.computer/caps/components/button";
4
6
  import { Card, CardContent } from "@fungi.computer/caps/components/card";
5
- import { Checkbox } from "@fungi.computer/caps/components/checkbox";
6
7
  import { DataList, DataRow } from "@fungi.computer/caps/components/data-list";
7
8
  import { Form, FormFooter } from "@fungi.computer/caps/components/field";
8
- import { IconCheckbox } from "@fungi.computer/caps/components/icon-checkbox";
9
+ import { Switch } from "@fungi.computer/caps/components/switch";
10
+ import { LoadingState } from "@fungi.computer/caps/blocks/loading-state";
11
+ import { PermissionGrid, } from "@fungi.computer/caps/blocks/permission-grid";
9
12
  import { Status } from "@fungi.computer/caps/components/status";
10
- import { Display, ScreenCell, ScreenCells, } from "@fungi.computer/caps/components/surface";
11
13
  import { Sigil } from "@fungi.computer/sigils";
12
14
  import { permissionCatalog } from "../apps/catalog.js";
13
15
  import { draftOf, editPermissions, permissionScreen, planGrantChange, rebaseDraft, } from "../apps/permissions.js";
16
+ const groupLabels = {
17
+ computers: "Computers",
18
+ agents: "Agents",
19
+ generation: "Generation",
20
+ bazaar: "Bazaar",
21
+ data: "Data",
22
+ workflows: "Workflows",
23
+ git: "Git",
24
+ channels: "Channels",
25
+ apps: "Apps",
26
+ shell: "Shell",
27
+ other: "Other",
28
+ };
29
+ const gridHeadings = {
30
+ capability: "Permission",
31
+ state: "State",
32
+ scope: "Applies to",
33
+ control: "Change",
34
+ };
35
+ /** "publishDraft" and "publish_draft" read as "Publish draft". */
36
+ function methodLabel(operation) {
37
+ const words = operation
38
+ .replace(/([a-z0-9])([A-Z])/gu, "$1 $2")
39
+ .replace(/[._-]+/gu, " ")
40
+ .trim()
41
+ .toLowerCase();
42
+ return words.charAt(0).toUpperCase() + words.slice(1);
43
+ }
44
+ /** One grid row per grant: a label, its state in words and a labelled switch. */
45
+ function grantRow(context, input) {
46
+ return {
47
+ id: input.id,
48
+ mark: _jsx(Sigil, { name: input.sigil }),
49
+ label: input.label,
50
+ state: input.on ? "allowed" : "denied",
51
+ group: input.chip,
52
+ stateLabel: input.stateLabel ?? (input.on ? "On" : "Off"),
53
+ scope: input.scopeName,
54
+ control: (_jsx(Switch, { id: input.pending ? `grant-${input.id}` : undefined, "aria-label": `${input.scopeName}: ${input.label}`, "aria-describedby": context.describedBy(input.capability), checked: input.on, disabled: context.disabled || input.locked, onCheckedChange: input.onChange })),
55
+ };
56
+ }
57
+ /** The rows for one resource (or "all") of a scoped group. */
58
+ function resourceRows(context, group, resource) {
59
+ const key = resource.resource === "all"
60
+ ? "all"
61
+ : `${resource.resource.kind}:${resource.resource.id}`;
62
+ return resource.cells.flatMap((cell) => {
63
+ const column = group.columns.find((item) => item.capability === cell.capability);
64
+ if (column === undefined)
65
+ return [];
66
+ const id = `${key}:${cell.capability}`;
67
+ return [
68
+ grantRow(context, {
69
+ id,
70
+ capability: cell.capability,
71
+ sigil: column.sigil,
72
+ label: column.label,
73
+ chip: groupLabels[group.id],
74
+ scopeName: resource.label,
75
+ stateLabel: cell.state === "via-all" ? "On for all" : undefined,
76
+ pending: column.pending && cell.state === "off",
77
+ on: cell.state !== "off",
78
+ locked: cell.state === "via-all",
79
+ onChange: (on) => {
80
+ context.edit(resource.resource === "all"
81
+ ? { kind: "all", capability: cell.capability, on }
82
+ : {
83
+ kind: "resource",
84
+ capability: cell.capability,
85
+ resource: resource.resource,
86
+ on,
87
+ });
88
+ },
89
+ }),
90
+ ];
91
+ });
92
+ }
93
+ /** Switches and App-call operations, which apply to the App rather than a resource. */
94
+ function appRows(context, group) {
95
+ return [
96
+ ...group.switches.map((column) => {
97
+ const locked = permissionCatalog[column.capability].consent === "affordance";
98
+ return grantRow(context, {
99
+ id: column.capability,
100
+ capability: column.capability,
101
+ sigil: column.sigil,
102
+ label: column.label,
103
+ chip: groupLabels[group.id],
104
+ scopeName: "This App",
105
+ stateLabel: locked ? "Always on" : undefined,
106
+ pending: column.pending && !column.on,
107
+ on: column.on,
108
+ locked,
109
+ onChange: (on) => {
110
+ context.edit({ kind: "switch", capability: column.capability, on });
111
+ },
112
+ });
113
+ }),
114
+ ...group.operations.map((operation) => grantRow(context, {
115
+ id: `${operation.capability}:${operation.operation}`,
116
+ capability: operation.capability,
117
+ sigil: permissionCatalog["apps.call"].sigil,
118
+ label: methodLabel(operation.operation),
119
+ chip: groupLabels[group.id],
120
+ scopeName: "Other Apps",
121
+ pending: false,
122
+ on: operation.on,
123
+ locked: false,
124
+ onChange: (on) => {
125
+ context.edit({
126
+ kind: "operation",
127
+ capability: operation.capability,
128
+ operation: operation.operation,
129
+ on,
130
+ });
131
+ },
132
+ })),
133
+ ];
134
+ }
135
+ /** Every row of a group: its resources' grants, then the App's own switches. */
136
+ function groupRows(context, group) {
137
+ return [
138
+ ...group.rows
139
+ .filter((resource) => resource.cells.some((cell) => cell.state !== "via-all"))
140
+ .flatMap((resource) => resourceRows(context, group, resource)),
141
+ ...appRows(context, group),
142
+ ];
143
+ }
14
144
  /** One editor; each App owns its draft and pending-request lifetime on reuse. */
15
145
  export function AppPermissionsView(props) {
16
146
  return _jsx(PermissionEditor, { ...props }, props.appKey);
@@ -23,10 +153,13 @@ function PermissionEditor({ port, appKey, onAccepted, onStateChange, }) {
23
153
  const [retired, setRetired] = useState(false);
24
154
  const [refreshNeeded, setRefreshNeeded] = useState(false);
25
155
  const [message, setMessage] = useState(null);
156
+ const [saved, setSaved] = useState(false);
26
157
  const [loadError, setLoadError] = useState(false);
27
158
  const [reload, setReload] = useState(0);
159
+ const [otherOpen, setOtherOpen] = useState(false);
160
+ const asked = useRef(null);
161
+ const describeId = useId();
28
162
  const mounted = useRef(true);
29
- const legendId = useId();
30
163
  const retire = useCallback(() => {
31
164
  setRetired(true);
32
165
  setUncertain(false);
@@ -71,7 +204,8 @@ function PermissionEditor({ port, appKey, onAccepted, onStateChange, }) {
71
204
  if (!mounted.current)
72
205
  return;
73
206
  setRefreshNeeded(false);
74
- setMessage("Permissions saved.");
207
+ setSaved(true);
208
+ setMessage("Permissions saved");
75
209
  }
76
210
  catch (cause) {
77
211
  console.error("App permissions surrounding-screen refresh failed", cause);
@@ -97,6 +231,7 @@ function PermissionEditor({ port, appKey, onAccepted, onStateChange, }) {
97
231
  return;
98
232
  setSaving(true);
99
233
  setRefreshNeeded(false);
234
+ setSaved(false);
100
235
  setMessage(null);
101
236
  try {
102
237
  if (!uncertain) {
@@ -166,7 +301,7 @@ function PermissionEditor({ port, appKey, onAccepted, onStateChange, }) {
166
301
  setReload((value) => value + 1);
167
302
  }, children: "Retry permissions" })] }));
168
303
  if (view === null)
169
- return _jsx("p", { role: "status", children: retired ? message : "Loading permissions…" });
304
+ return retired ? (_jsx("p", { role: "status", children: message })) : (_jsx(LoadingState, { message: "Loading permissions\u2026" }));
170
305
  const authority = {
171
306
  ...view.permissions.authority,
172
307
  approvedGrants: [...draft].flatMap(([capability, grant]) => grant === null
@@ -194,12 +329,25 @@ function PermissionEditor({ port, appKey, onAccepted, onStateChange, }) {
194
329
  const shellChanged = changes.some((change) => change.capability === "team.workbenchHost");
195
330
  const groups = screen.groups.filter((group) => group.id !== "shell");
196
331
  const pending = baseline.pending.filter((capability) => capability !== "team.workbenchHost");
197
- return (_jsxs(Form, { style: { maxWidth: "46rem" }, onSubmit: (event) => {
332
+ const context = {
333
+ disabled,
334
+ describedBy: (capability) => `${describeId}-${capability}`,
335
+ edit,
336
+ };
337
+ const rowsOf = (items) => items.flatMap((group) => groupRows(context, group));
338
+ const needsOk = (group) => [...group.columns, ...group.switches].some((column) => pending.some((item) => item === column.capability));
339
+ // The split is fixed on first sight, so rows never move under the cursor.
340
+ asked.current ??= new Set(groups.filter(needsOk).map((group) => group.id));
341
+ const askedIds = asked.current;
342
+ const first = rowsOf(askedIds.size > 0 ? groups.filter((g) => askedIds.has(g.id)) : groups);
343
+ const later = askedIds.size > 0 ? rowsOf(groups.filter((g) => !askedIds.has(g.id))) : [];
344
+ const showFooter = (groups.length > 0 && !shellChanged) || uncertain || refreshNeeded;
345
+ return (_jsxs(Form, { style: { maxWidth: "var(--container-2xl)", marginInline: "auto" }, onSubmit: (event) => {
198
346
  event.preventDefault();
199
347
  void save();
200
- }, children: [!screen.canEdit && _jsx("p", { children: "Only an owner can change these permissions." }), pending.length > 0 && (_jsxs("p", { children: ["Needs approval:", " ", pending
201
- .map((capability) => permissionCatalog[capability].label)
202
- .join(", ")] })), shell !== undefined && (_jsx(ShellPermissionRow, { column: shell, changed: shellChanged, otherChanges: changes.length > 1, disabled: disabled, onToggle: () => {
348
+ }, children: [!screen.canEdit && _jsx("p", { children: "Only an owner can change these permissions." }), pending.length > 0 && (_jsx(Alert, { tone: "warning", title: `${String(pending.length)} ${pending.length === 1 ? "permission needs" : "permissions need"} your OK`, action: _jsx(Button, { type: "button", size: "xs", variant: "outline", onClick: () => {
349
+ document.querySelector('[id^="grant-"]')?.focus();
350
+ }, children: "Review" }), children: "Turn on what you want this App to do, then save." })), shell !== undefined && (_jsx(ShellPermissionRow, { column: shell, changed: shellChanged, otherChanges: changes.length > 1, disabled: disabled, onToggle: () => {
203
351
  edit({
204
352
  kind: "switch",
205
353
  capability: "team.workbenchHost",
@@ -208,49 +356,16 @@ function PermissionEditor({ port, appKey, onAccepted, onStateChange, }) {
208
356
  }, onCancel: () => {
209
357
  setDraft((current) => new Map(current).set("team.workbenchHost", draftOf(view.permissions.authority).get("team.workbenchHost") ??
210
358
  null));
211
- } })), groups.length > 0 && (_jsx(Display, { size: "sm", "aria-label": `${view.appName} permissions`, children: _jsx(ScreenCells, { appearance: "compact", children: groups.map((group) => (_jsxs("section", { "aria-label": `${group.id} permissions`, children: [_jsx("h3", { children: group.id }), group.rows.map((row) => (_jsx(ScreenCell, { appearance: "compact", icon: _jsx(Sigil, { name: group.scope === "computer" ? "computer" : "listAgents" }), legend: row.label, children: row.cells.map((cell) => {
212
- const column = group.columns.find((item) => item.capability === cell.capability);
213
- if (column === undefined)
214
- return null;
215
- return (_jsx(IconCheckbox, { appearance: "compact", icon: _jsx(Sigil, { name: column.sigil }), caption: column.caption, label: `${row.label}: ${column.label}`, "aria-describedby": `${legendId}-${cell.capability}`, checked: cell.state !== "off", disabled: disabled || cell.state === "via-all", onChange: (event) => {
216
- edit(row.resource === "all"
217
- ? {
218
- kind: "all",
219
- capability: cell.capability,
220
- on: event.target.checked,
221
- }
222
- : {
223
- kind: "resource",
224
- capability: cell.capability,
225
- resource: row.resource,
226
- on: event.target.checked,
227
- });
228
- } }, cell.capability));
229
- }) }, row.resource === "all"
230
- ? "all"
231
- : `${row.resource.kind}:${row.resource.id}`))), group.switches.map((column) => (_jsx(ScreenCell, { appearance: "compact", legend: column.label, children: _jsx(IconCheckbox, { appearance: "compact", icon: _jsx(Sigil, { name: column.sigil }), caption: column.caption, label: column.label, "aria-describedby": `${legendId}-${column.capability}`, checked: column.on, disabled: disabled ||
232
- permissionCatalog[column.capability].consent ===
233
- "affordance", onChange: (event) => {
234
- edit({
235
- kind: "switch",
236
- capability: column.capability,
237
- on: event.target.checked,
238
- });
239
- } }) }, column.capability))), group.operations.map((operation) => (_jsxs("label", { children: [_jsx(Checkbox, { checked: operation.on, disabled: disabled, onChange: (event) => {
240
- edit({
241
- kind: "operation",
242
- capability: operation.capability,
243
- operation: operation.operation,
244
- on: event.target.checked,
245
- });
246
- } }), operation.operation] }, operation.operation))), _jsx("dl", { children: [...group.columns, ...group.switches].map((column) => (_jsxs("div", { id: `${legendId}-${column.capability}`, children: [_jsx("dt", { children: column.label }), _jsxs("dd", { children: [column.description, column.warning !== null && _jsx("p", { children: column.warning })] })] }, column.capability))) })] }, group.id))) }) })), screen.groups.length === 0 && _jsx("p", { children: "This App requests no permissions." }), message !== null && (_jsx("p", { role: "status", "aria-live": "polite", children: message })), ((groups.length > 0 && !shellChanged) || uncertain || refreshNeeded) && (_jsxs(FormFooter, { divider: false, children: [refreshNeeded && (_jsx(Button, { type: "button", size: "xs", variant: "outline", disabled: saving, onClick: () => void retryRefresh(), children: "Retry screen refresh" })), _jsx(Button, { type: "submit", size: "xs", variant: "outline", disabled: saving ||
247
- retired ||
248
- !screen.canEdit ||
249
- (!uncertain && changes.length === 0), children: saving
359
+ } })), first.length > 0 && (_jsx(PermissionGrid, { caption: later.length > 0
360
+ ? `${view.appName} asks for`
361
+ : `${view.appName} permissions`, headings: gridHeadings, rows: first })), later.length > 0 && (_jsx(Disclosure, { open: otherOpen, onOpenChange: setOtherOpen, summary: `Other permissions · ${String(later.length)}`, children: _jsx(PermissionGrid, { caption: "Already decided", headings: gridHeadings, rows: later }) })), _jsx("div", { className: "sr-only", children: groups
362
+ .flatMap((group) => [...group.columns, ...group.switches])
363
+ .map((column) => (_jsxs("p", { id: `${describeId}-${column.capability}`, children: [column.description, column.warning === null ? "" : ` ${column.warning}`] }, column.capability))) }), screen.groups.length === 0 && _jsx("p", { children: "This App requests no permissions." }), message !== null && !showFooter && (_jsx("p", { role: "status", "aria-live": "polite", children: message })), showFooter && (_jsxs(FormFooter, { divider: false, children: [message !== null &&
364
+ (saved && !uncertain && !refreshNeeded ? (_jsx(Status, { role: "status", size: "compact", glyph: "dot", tone: "success", label: message })) : (_jsx("span", { role: "status", children: message }))), refreshNeeded && (_jsx(Button, { type: "button", size: "xs", variant: "outline", disabled: saving, onClick: () => void retryRefresh(), children: "Retry screen refresh" })), (changes.length > 0 || saving || uncertain) && (_jsx(Button, { type: "submit", variant: "primary", disabled: saving || retired || !screen.canEdit, children: saving
250
365
  ? "Saving…"
251
366
  : uncertain
252
367
  ? "Review current permissions"
253
- : "Save permissions" })] }))] }));
368
+ : "Save permissions" }))] }))] }));
254
369
  }
255
370
  /** Shell is a single approval, not a resource/verb matrix. Confirmation still
256
371
  * submits the editor's whole draft through its one atomic save. */
@@ -0,0 +1,8 @@
1
+ import { type AppPermissions } from "@fungi.computer/agar";
2
+ import { type AppPermissionsViewData } from "../apps/permissions.js";
3
+ /**
4
+ * Which of an App's declared rights its owner's grants cover. Reads the same
5
+ * facts the permission page shows, so the two never disagree. A right the App
6
+ * does not declare is left out.
7
+ */
8
+ export declare function appRightStates(page: Pick<AppPermissionsViewData, "permissions">): AppPermissions;
@@ -0,0 +1,13 @@
1
+ import { APP_RIGHTS } from "@fungi.computer/agar";
2
+ import { pendingCapabilities, } from "../apps/permissions.js";
3
+ /**
4
+ * Which of an App's declared rights its owner's grants cover. Reads the same
5
+ * facts the permission page shows, so the two never disagree. A right the App
6
+ * does not declare is left out.
7
+ */
8
+ export function appRightStates(page) {
9
+ const { authority, declaredOperations } = page.permissions;
10
+ const declared = declaredOperations.capabilities.map(({ capability }) => capability);
11
+ const missing = new Set(pendingCapabilities(authority, { capabilities: declared }, declaredOperations));
12
+ return Object.fromEntries(APP_RIGHTS.filter((right) => declared.some((name) => name === right)).map((right) => [right, missing.has(right) ? "missing" : "granted"]));
13
+ }
@@ -76,4 +76,19 @@ export declare class ComputerProcessesHandle extends RpcTarget implements Handle
76
76
  };
77
77
  readonly signalled: boolean;
78
78
  }>;
79
+ logs(id: string, lines?: number): Promise<{
80
+ readonly process: {
81
+ readonly port: number | null;
82
+ readonly id: string;
83
+ readonly command: string;
84
+ readonly cwd: string | null;
85
+ readonly startedAt: number;
86
+ readonly state: "running" | "uncertain" | "exited";
87
+ readonly exitCode: number | null;
88
+ readonly sync: "unknown" | "pending" | "synced";
89
+ readonly endedAt: number | null;
90
+ };
91
+ readonly lines: readonly string[];
92
+ readonly truncated: boolean;
93
+ }>;
79
94
  }
@@ -1,6 +1,6 @@
1
1
  import { RpcTarget } from "@fungi.computer/capnweb";
2
2
  import * as Schema from "effect/Schema";
3
- import { computerPortExposureSchema, computerPortRemovalSchema, computerPortsResultSchema, computerProcessKillSchema, computerProcessSchema, computerProcessesSchema, } from "@fungi.computer/agar/computer";
3
+ import { computerPortExposureSchema, computerPortRemovalSchema, computerPortsResultSchema, computerProcessKillSchema, computerProcessLogsSchema, computerProcessSchema, computerProcessesSchema, } from "@fungi.computer/agar/computer";
4
4
  /**
5
5
  * Agar's `computer.ports` handle over the host's wire. The App passes a bare
6
6
  * port; Hub's routes and the Computer owner take `{ port }` as the body, so
@@ -41,4 +41,7 @@ export class ComputerProcessesHandle extends RpcTarget {
41
41
  async kill(id) {
42
42
  return Schema.decodeUnknownSync(computerProcessKillSchema)(await this.#call("kill", { id }));
43
43
  }
44
+ async logs(id, lines) {
45
+ return Schema.decodeUnknownSync(computerProcessLogsSchema)(await this.#call("logs", lines === undefined ? { id } : { id, lines }));
46
+ }
44
47
  }
@@ -3,6 +3,7 @@ import { OysterAgentBrowserHost } from "./agent-browser.js";
3
3
  export type { OysterAgentBrowserHost } from "./agent-browser.js";
4
4
  import type { WhistleRuntime } from "@fungi.computer/whistle";
5
5
  import * as Schema from "effect/Schema";
6
+ import { type AppPermissions, type AppSetup } from "@fungi.computer/agar";
6
7
  import { type AppHost, type AppHostLaunch, type AppHostHandlers } from "@fungi.computer/agar/host";
7
8
  import type { WhistleJsonValue } from "@fungi.computer/whistle";
8
9
  /** Current server-admitted configuration for one installed App page. */
@@ -157,6 +158,10 @@ export type OysterAppConnectionOptions = Readonly<{
157
158
  appOpen?: OysterAppOpenRouting;
158
159
  openRequest?: AppHostLaunch["context"]["value"]["openRequest"];
159
160
  surfaceId?: string;
161
+ /** Host setup facts the App sees from its first message; absent on hosts with none. */
162
+ setup?: AppSetup | undefined;
163
+ /** Which declared rights this App holds, when the host can read its grants. */
164
+ permissions?: AppPermissions | undefined;
160
165
  reservedChords: readonly import("@fungi.computer/agar/host").AppHostReservedChord[];
161
166
  theme: string;
162
167
  }>;
@@ -343,6 +343,10 @@ async function openOysterApp(options, appWindow, opening, navigate) {
343
343
  focus: { editing: false, surface: null },
344
344
  openRequest: options.openRequest ?? null,
345
345
  visibility: "visible",
346
+ ...(options.setup !== undefined && { setup: options.setup }),
347
+ ...(options.permissions !== undefined && {
348
+ permissions: options.permissions,
349
+ }),
346
350
  },
347
351
  },
348
352
  lifecycle: { version: 1, value: "connected" },