@fungi.computer/tourtois 0.20.14 → 0.21.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.
@@ -1,20 +1,4 @@
1
1
  import type { AgentAccessOperation, AppPermissionOutcome, AppPermissionRequest, ComputerAccessOperation } from "@fungi.computer/agar";
2
- import type { AppAgentPermission, AppComputerPermission } from "@fungi.computer/nacre/app-directory";
3
- export declare const consentableAgentOperations: (requested: readonly AgentAccessOperation[], declared: readonly string[]) => readonly AgentAccessOperation[];
4
- export declare const consentableComputerOperations: (requested: readonly ComputerAccessOperation[], declared: readonly string[]) => readonly ComputerAccessOperation[];
5
- /** The all-Team-Agents grant that adds `offered` to the current policy. */
6
- export declare function consentedAgentPermission(current: AppAgentPermission, offered: readonly AgentAccessOperation[]): AppAgentPermission | "covered" | "customize";
7
- /**
8
- * The all-Team-Computers grant that adds `offered`. An empty selection is no
9
- * access; a real Computer selection is the owner's choice and never widened.
10
- */
11
- export declare function consentedComputerPermission(current: AppComputerPermission | null, offered: readonly ComputerAccessOperation[]): AppComputerPermission | "covered" | "customize";
12
- /** Every right the request names, in plain words, in a stable order. */
13
- export declare function plainRights(request: {
14
- agents: readonly AgentAccessOperation[];
15
- computers: readonly ComputerAccessOperation[];
16
- others?: AppPermissionRequest | undefined;
17
- }): readonly string[];
18
2
  export type AppAccessRequest = Readonly<{
19
3
  appName: string;
20
4
  agents: readonly AgentAccessOperation[];
@@ -3,8 +3,6 @@ import { Button } from "@fungi.computer/caps/components/button";
3
3
  import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogTitle, } from "@fungi.computer/caps/components/dialog";
4
4
  import { WindowFrame } from "@fungi.computer/caps/components/window";
5
5
  import { useRef, useState } from "react";
6
- const directoryOperations = ["agent.list"];
7
- const sessionOperations = ["agent.read", "agent.send", "agent.manage"];
8
6
  const agentOperations = [
9
7
  "agent.list",
10
8
  "agent.manage",
@@ -17,45 +15,6 @@ const computerOperations = [
17
15
  "computer.writeFile",
18
16
  "computer.execute",
19
17
  ];
20
- /** What the trusted host may offer: the request bounded by the declared ceiling. */
21
- function consentableOperations(known, requested, declared) {
22
- return known.filter((operation) => requested.includes(operation) && declared.includes(operation));
23
- }
24
- export const consentableAgentOperations = (requested, declared) => consentableOperations(agentOperations, requested, declared);
25
- export const consentableComputerOperations = (requested, declared) => consentableOperations(computerOperations, requested, declared);
26
- /** The all-Team-Agents grant that adds `offered` to the current policy. */
27
- export function consentedAgentPermission(current, offered) {
28
- if (current.kind === "selected-agents")
29
- return "customize";
30
- const currentOperations = [
31
- ...current.directoryOperations,
32
- ...current.sessionOperations,
33
- ];
34
- if (offered.every((operation) => currentOperations.includes(operation)))
35
- return "covered";
36
- const granted = new Set([...currentOperations, ...offered]);
37
- return {
38
- kind: "all-team-agents",
39
- directoryOperations: directoryOperations.filter((operation) => granted.has(operation)),
40
- sessionOperations: sessionOperations.filter((operation) => granted.has(operation)),
41
- };
42
- }
43
- /**
44
- * The all-Team-Computers grant that adds `offered`. An empty selection is no
45
- * access; a real Computer selection is the owner's choice and never widened.
46
- */
47
- export function consentedComputerPermission(current, offered) {
48
- if (current?.kind === "selected-computers" && current.computers.length > 0)
49
- return "customize";
50
- const currentOperations = current?.kind === "all-team-computers" ? current.operations : [];
51
- if (offered.every((operation) => currentOperations.includes(operation)))
52
- return "covered";
53
- const granted = new Set([...currentOperations, ...offered]);
54
- return {
55
- kind: "all-team-computers",
56
- operations: computerOperations.filter((operation) => granted.has(operation)),
57
- };
58
- }
59
18
  /** Sentence variants following "<App> can" in the consent description. */
60
19
  const rightNames = {
61
20
  "agent.list": "see your Agents",
@@ -79,7 +38,7 @@ const otherRightNames = {
79
38
  "media.share": "share what it makes",
80
39
  };
81
40
  /** Every right the request names, in plain words, in a stable order. */
82
- export function plainRights(request) {
41
+ function plainRights(request) {
83
42
  const others = request.others;
84
43
  const named = [
85
44
  ...(others?.git ?? []),
@@ -46,6 +46,14 @@ export type OysterComputersPort = Readonly<{
46
46
  export type ComputerRunState = "running" | "sleeping" | "starting" | "queued" | "start_failed";
47
47
  /** The durable per-Computer switches an owner manages. */
48
48
  export type ComputerSwitchSetting = "internet-access" | "keep-awake";
49
+ /**
50
+ * The host answered that this Computer has no such switch (a local trial's
51
+ * own machine has no sleep or egress policy). Unlike a failed check, there
52
+ * is nothing to retry, so Settings draws no row for it.
53
+ */
54
+ export declare class SwitchUnavailable extends Error {
55
+ constructor();
56
+ }
49
57
  /** Bind owner-admitted fleet controls to this trusted shell's host origin. */
50
58
  export declare function createOysterComputersPort(origin: URL): OysterComputersPort;
51
59
  /**
@@ -35,6 +35,18 @@ const computerRunStateSchema = z.looseObject({
35
35
  state: z.enum(["running", "sleeping", "starting", "queued", "start_failed"]),
36
36
  });
37
37
  const missingRuntime = z.strictObject({ error: z.literal("no_runtime") });
38
+ const switchUnavailable = z.strictObject({ error: z.literal("unavailable") });
39
+ /**
40
+ * The host answered that this Computer has no such switch (a local trial's
41
+ * own machine has no sleep or egress policy). Unlike a failed check, there
42
+ * is nothing to retry, so Settings draws no row for it.
43
+ */
44
+ export class SwitchUnavailable extends Error {
45
+ constructor() {
46
+ super("This Computer does not have that setting.");
47
+ this.name = "SwitchUnavailable";
48
+ }
49
+ }
38
50
  const computerSwitchSchema = z.strictObject({ enabled: z.boolean() });
39
51
  async function request(url, init) {
40
52
  const response = await fetch(url, {
@@ -47,6 +59,9 @@ async function request(url, init) {
47
59
  if (response.status === 503 &&
48
60
  missingRuntime.safeParse(await response.json()).success)
49
61
  throw new AppError("This Computer has no runtime. Use the workspace Computer supplied by oyster try, or attach a runtime.", { code: "HOST_FAILURE", retryable: false });
62
+ if (response.status === 409 &&
63
+ switchUnavailable.safeParse(await response.clone().json()).success)
64
+ throw new SwitchUnavailable();
50
65
  if (!response.ok)
51
66
  throw new AppError(`Computer request refused (${String(response.status)}).`, {
52
67
  code: response.status === 401 || response.status === 403
@@ -139,6 +154,8 @@ function ComputerSwitch({ setting, description, computer, queryKey, read, write,
139
154
  apply: (_previous, enabled) => enabled,
140
155
  mutationFn: write,
141
156
  }));
157
+ if (current.error instanceof SwitchUnavailable)
158
+ return null;
142
159
  return (_jsx(ComputerSettingRow, { setting: setting, description: description, error: current.isError
143
160
  ? `Could not check ${label} for ${computer.name}.`
144
161
  : update.isError
@@ -1,116 +1,16 @@
1
1
  import * as z from "zod";
2
2
  import { type AppAddress } from "@fungi.computer/nacre/app-directory";
3
- export declare const appPermissionChangesSchema: z.ZodObject<{
4
- computer: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodLazy<z.ZodObject<{
5
- kind: z.ZodLiteral<"selected-computers">;
6
- computers: z.ZodArray<z.ZodObject<{
7
- computerId: z.ZodString;
8
- operations: z.ZodArray<z.ZodEnum<{
9
- readonly "computer.list": "computer.list";
10
- readonly "computer.readFile": "computer.readFile";
11
- readonly "computer.writeFile": "computer.writeFile";
12
- readonly "computer.execute": "computer.execute";
13
- }>>;
14
- }, z.core.$strict>>;
15
- }, z.core.$strict>>, z.ZodLazy<z.ZodObject<{
16
- kind: z.ZodLiteral<"all-team-computers">;
17
- operations: z.ZodArray<z.ZodEnum<{
18
- readonly "computer.list": "computer.list";
19
- readonly "computer.readFile": "computer.readFile";
20
- readonly "computer.writeFile": "computer.writeFile";
21
- readonly "computer.execute": "computer.execute";
22
- }>>;
23
- }, z.core.$strict>>], "kind">>;
24
- agents: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
25
- kind: z.ZodLiteral<"all-team-agents">;
26
- directoryOperations: z.ZodArray<z.ZodEnum<{
27
- readonly "agent.list": "agent.list";
28
- }>>;
29
- sessionOperations: z.ZodArray<z.ZodEnum<{
30
- readonly "agent.read": "agent.read";
31
- readonly "agent.send": "agent.send";
32
- readonly "agent.manage": "agent.manage";
33
- }>>;
34
- }, z.core.$strict>, z.ZodObject<{
35
- kind: z.ZodLiteral<"selected-agents">;
36
- directoryOperations: z.ZodArray<z.ZodEnum<{
37
- readonly "agent.list": "agent.list";
38
- }>>;
39
- agents: z.ZodArray<z.ZodObject<{
40
- agentId: z.ZodString;
41
- sessionOperations: z.ZodArray<z.ZodEnum<{
42
- readonly "agent.read": "agent.read";
43
- readonly "agent.send": "agent.send";
44
- readonly "agent.manage": "agent.manage";
45
- }>>;
46
- }, z.core.$strict>>;
47
- }, z.core.$strict>], "kind">>;
48
- generation: z.ZodOptional<z.ZodObject<{
49
- llm: z.ZodBoolean;
50
- media: z.ZodBoolean;
51
- }, z.core.$strict>>;
52
- marketplace: z.ZodOptional<z.ZodObject<{
53
- browse: z.ZodBoolean;
54
- purchase: z.ZodBoolean;
55
- }, z.core.$strict>>;
56
- }, z.core.$strict>;
57
- export type AppPermissionChanges = z.output<typeof appPermissionChangesSchema>;
58
- export declare const appPermissionReceiptSchema: z.ZodObject<{
59
- authorityVersion: z.ZodNumber;
60
- computerPermission: z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodLazy<z.ZodObject<{
61
- kind: z.ZodLiteral<"selected-computers">;
62
- computers: z.ZodArray<z.ZodObject<{
63
- computerId: z.ZodString;
64
- operations: z.ZodArray<z.ZodEnum<{
65
- readonly "computer.list": "computer.list";
66
- readonly "computer.readFile": "computer.readFile";
67
- readonly "computer.writeFile": "computer.writeFile";
68
- readonly "computer.execute": "computer.execute";
69
- }>>;
70
- }, z.core.$strict>>;
71
- }, z.core.$strict>>, z.ZodLazy<z.ZodObject<{
72
- kind: z.ZodLiteral<"all-team-computers">;
73
- operations: z.ZodArray<z.ZodEnum<{
74
- readonly "computer.list": "computer.list";
75
- readonly "computer.readFile": "computer.readFile";
76
- readonly "computer.writeFile": "computer.writeFile";
77
- readonly "computer.execute": "computer.execute";
78
- }>>;
79
- }, z.core.$strict>>], "kind">>;
80
- agentPermission: z.ZodDiscriminatedUnion<[z.ZodObject<{
81
- kind: z.ZodLiteral<"all-team-agents">;
82
- directoryOperations: z.ZodArray<z.ZodEnum<{
83
- readonly "agent.list": "agent.list";
84
- }>>;
85
- sessionOperations: z.ZodArray<z.ZodEnum<{
86
- readonly "agent.read": "agent.read";
87
- readonly "agent.send": "agent.send";
88
- readonly "agent.manage": "agent.manage";
89
- }>>;
90
- }, z.core.$strict>, z.ZodObject<{
91
- kind: z.ZodLiteral<"selected-agents">;
92
- directoryOperations: z.ZodArray<z.ZodEnum<{
93
- readonly "agent.list": "agent.list";
94
- }>>;
95
- agents: z.ZodArray<z.ZodObject<{
96
- agentId: z.ZodString;
97
- sessionOperations: z.ZodArray<z.ZodEnum<{
98
- readonly "agent.read": "agent.read";
99
- readonly "agent.send": "agent.send";
100
- readonly "agent.manage": "agent.manage";
101
- }>>;
102
- }, z.core.$strict>>;
103
- }, z.core.$strict>], "kind">;
104
- generationPermissions: z.ZodObject<{
105
- llm: z.ZodBoolean;
106
- media: z.ZodBoolean;
107
- }, z.core.$strict>;
108
- marketplacePermissions: z.ZodObject<{
109
- browse: z.ZodBoolean;
110
- purchase: z.ZodBoolean;
111
- }, z.core.$strict>;
112
- }, z.core.$strip>;
113
- export declare function appPermissionsMutationRequest(teamId: string, requestId: string, address: AppAddress, expectedAuthorityVersion: number, permissions: AppPermissionChanges): {
3
+ /**
4
+ * One owner save of an App's grants: the changes Oyster reduced from the
5
+ * owner's edit and the digests the owner read them against. The host rejects
6
+ * a save whose Release artifact or declared operations have since changed.
7
+ */
8
+ export type AppGrantsSave<Change extends object> = Readonly<{
9
+ changes: readonly Change[];
10
+ artifactDigest: string;
11
+ declaredOperationsDigest: string;
12
+ }>;
13
+ export declare function appGrantsMutationRequest<Change extends object>(teamId: string, requestId: string, address: AppAddress, expectedAuthorityVersion: number, save: AppGrantsSave<Change>): {
114
14
  url: string;
115
15
  init: {
116
16
  method: string;
@@ -123,7 +23,7 @@ export declare function appPermissionsMutationRequest(teamId: string, requestId:
123
23
  body: string;
124
24
  };
125
25
  };
126
- export type AppMutationRequest = ReturnType<typeof appPermissionsMutationRequest>;
26
+ export type AppMutationRequest = ReturnType<typeof appGrantsMutationRequest>;
127
27
  export declare const appMutationResponseSchema: z.ZodObject<{
128
28
  kind: z.ZodLiteral<"accepted">;
129
29
  receipt: z.ZodUnknown;
@@ -1,21 +1,6 @@
1
1
  import * as z from "zod";
2
- import { appAuthorityEnforcementSchema, appComputerPermissionSchema, appAgentPermissionSchema, appGenerationPermissionsSchema, appMarketplacePermissionsSchema, } from "@fungi.computer/nacre/app-directory";
3
- export const appPermissionChangesSchema = z
4
- .strictObject({
5
- computer: appComputerPermissionSchema.optional(),
6
- agents: appAgentPermissionSchema.optional(),
7
- generation: appGenerationPermissionsSchema.optional(),
8
- marketplace: appMarketplacePermissionsSchema.optional(),
9
- })
10
- .refine((changes) => Object.values(changes).some((value) => value !== undefined), "At least one permission section must change");
11
- export const appPermissionReceiptSchema = z.object({
12
- authorityVersion: z.number().int().positive(),
13
- computerPermission: appComputerPermissionSchema.nullable(),
14
- agentPermission: appAgentPermissionSchema,
15
- generationPermissions: appGenerationPermissionsSchema,
16
- marketplacePermissions: appMarketplacePermissionsSchema,
17
- });
18
- export function appPermissionsMutationRequest(teamId, requestId, address, expectedAuthorityVersion, permissions) {
2
+ import { appAuthorityEnforcementSchema, } from "@fungi.computer/nacre/app-directory";
3
+ export function appGrantsMutationRequest(teamId, requestId, address, expectedAuthorityVersion, save) {
19
4
  return {
20
5
  url: "/api/teams/" + encodeURIComponent(teamId) + "/apps",
21
6
  init: {
@@ -29,7 +14,12 @@ export function appPermissionsMutationRequest(teamId, requestId, address, expect
29
14
  body: JSON.stringify({
30
15
  target: address,
31
16
  expectedVersion: expectedAuthorityVersion,
32
- command: { kind: "set-permissions", permissions },
17
+ command: {
18
+ kind: "set-grants",
19
+ changes: save.changes,
20
+ artifactDigest: save.artifactDigest,
21
+ declaredOperationsDigest: save.declaredOperationsDigest,
22
+ },
33
23
  }),
34
24
  },
35
25
  };
@@ -77,18 +77,49 @@ export declare function useAppDirectory(teamId: string, directoryReader: () => P
77
77
  readonly methods: readonly string[];
78
78
  }[] | undefined;
79
79
  computer?: "owner-fleet" | {
80
- computerId: string;
81
80
  name: string;
81
+ computerId: string;
82
82
  } | undefined;
83
- computerPermission?: {
84
- kind: "selected-computers";
85
- computers: {
86
- computerId: string;
87
- operations: ("computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute")[];
88
- }[];
89
- } | {
90
- kind: "all-team-computers";
91
- operations: ("computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute")[];
83
+ permission?: {
84
+ authority: {
85
+ authorityVersion: number;
86
+ declaredOperationsDigest: import("@fungi.computer/puffball").Sha256Digest;
87
+ approvedGrants: readonly Readonly<{
88
+ capability: "approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.instructions" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "media.share" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage";
89
+ capabilityApproved: true;
90
+ operations: readonly string[];
91
+ fingerprints: Readonly<Record<string, string>>;
92
+ resources: "tenant-scope" | readonly Readonly<{
93
+ kind: string;
94
+ id: string;
95
+ }>[];
96
+ }>[];
97
+ approval: Readonly<{
98
+ by: {
99
+ kind: "member";
100
+ memberId: string;
101
+ } | {
102
+ kind: "agent";
103
+ agentId: string;
104
+ } | {
105
+ kind: "team-key";
106
+ keyId: string;
107
+ };
108
+ at: number;
109
+ authorityVersion: number;
110
+ }> | null;
111
+ } | null;
112
+ declaredOperations: {
113
+ artifactDigest: import("@fungi.computer/puffball").Sha256Digest;
114
+ digest: import("@fungi.computer/puffball").Sha256Digest;
115
+ capabilities: readonly Readonly<{
116
+ capability: "approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.instructions" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "media.share" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage";
117
+ operations: readonly string[];
118
+ fingerprints: Readonly<Record<string, string>>;
119
+ }>[];
120
+ };
121
+ artifactDigest: import("@fungi.computer/puffball").Sha256Digest;
122
+ canEdit: boolean;
92
123
  } | null | undefined;
93
124
  }[];
94
125
  roles: Record<string, {
@@ -96,8 +127,8 @@ export declare function useAppDirectory(teamId: string, directoryReader: () => P
96
127
  chosen: boolean;
97
128
  }>;
98
129
  computer?: {
99
- computerId: string;
100
130
  name: string;
131
+ computerId: string;
101
132
  } | undefined;
102
133
  computerContext?: "owner-fleet" | undefined;
103
134
  needsUpdate?: {
@@ -191,18 +222,49 @@ export declare function useAppDirectory(teamId: string, directoryReader: () => P
191
222
  readonly methods: readonly string[];
192
223
  }[] | undefined;
193
224
  computer?: "owner-fleet" | {
194
- computerId: string;
195
225
  name: string;
226
+ computerId: string;
196
227
  } | undefined;
197
- computerPermission?: {
198
- kind: "selected-computers";
199
- computers: {
200
- computerId: string;
201
- operations: ("computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute")[];
202
- }[];
203
- } | {
204
- kind: "all-team-computers";
205
- operations: ("computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute")[];
228
+ permission?: {
229
+ authority: {
230
+ authorityVersion: number;
231
+ declaredOperationsDigest: import("@fungi.computer/puffball").Sha256Digest;
232
+ approvedGrants: readonly Readonly<{
233
+ capability: "approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.instructions" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "media.share" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage";
234
+ capabilityApproved: true;
235
+ operations: readonly string[];
236
+ fingerprints: Readonly<Record<string, string>>;
237
+ resources: "tenant-scope" | readonly Readonly<{
238
+ kind: string;
239
+ id: string;
240
+ }>[];
241
+ }>[];
242
+ approval: Readonly<{
243
+ by: {
244
+ kind: "member";
245
+ memberId: string;
246
+ } | {
247
+ kind: "agent";
248
+ agentId: string;
249
+ } | {
250
+ kind: "team-key";
251
+ keyId: string;
252
+ };
253
+ at: number;
254
+ authorityVersion: number;
255
+ }> | null;
256
+ } | null;
257
+ declaredOperations: {
258
+ artifactDigest: import("@fungi.computer/puffball").Sha256Digest;
259
+ digest: import("@fungi.computer/puffball").Sha256Digest;
260
+ capabilities: readonly Readonly<{
261
+ capability: "approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.instructions" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "media.share" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage";
262
+ operations: readonly string[];
263
+ fingerprints: Readonly<Record<string, string>>;
264
+ }>[];
265
+ };
266
+ artifactDigest: import("@fungi.computer/puffball").Sha256Digest;
267
+ canEdit: boolean;
206
268
  } | null | undefined;
207
269
  }[] | undefined;
208
270
  needsUpdate: {
@@ -123,17 +123,14 @@ function computersForApp(app, computers) {
123
123
  return computers;
124
124
  if (context !== undefined)
125
125
  return computers.filter((computer) => computer.computerId === context.computerId);
126
- const permission = app.computerPermission;
127
- if (!permission)
128
- return [];
129
- if (permission.kind === "all-team-computers" &&
130
- permission.operations.length > 0)
126
+ const approved = (app.permission?.authority?.approvedGrants ?? []).filter((grant) => grant.capability.startsWith("computer."));
127
+ if (approved.some((grant) => grant.resources === "tenant-scope"))
131
128
  return computers;
132
- if (permission.kind !== "selected-computers")
133
- return [];
134
- const allowedIds = new Set(permission.computers
135
- .filter((computer) => computer.operations.length > 0)
136
- .map((computer) => computer.computerId));
129
+ const allowedIds = new Set(approved.flatMap((grant) => grant.resources === "tenant-scope"
130
+ ? []
131
+ : grant.resources
132
+ .filter((resource) => resource.kind === "computer")
133
+ .map((resource) => resource.id)));
137
134
  return computers.filter((computer) => allowedIds.has(computer.computerId));
138
135
  }
139
136
  export function launchComputerId(href) {
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useCallback, useLayoutEffect, useMemo } from "react";
2
+ import { useCallback, useLayoutEffect, useMemo, useState, } from "react";
3
3
  import { CommandMenu } from "@fungi.computer/caps/blocks/command-menu";
4
4
  import { Combobox } from "@fungi.computer/caps/components/combobox";
5
5
  import { Dialog, DialogContent, DialogDescription, DialogTitle, } from "@fungi.computer/caps/components/dialog";
@@ -60,6 +60,13 @@ function outcomeMessage(outcome) {
60
60
  export function CommandDialogs({ host, state, focusedWindow, directoryApps, onStatus, finalFocus, container: dialog, renderIcon, }) {
61
61
  const { active, keysOpen, setKeysOpen, commandLineOpen, setCommandLineOpen } = state;
62
62
  const focusedTitle = focusedWindow?.launch.title ?? null;
63
+ // A key typed in the Keys sheet that is not a leader key; the command line
64
+ // opens with it already in the search box. The dialog stays mounted, so the
65
+ // search box is keyed on it to start over with that text. It only lives while
66
+ // the line is open, so a later open starts empty.
67
+ const [typedInKeys, setTypedInKeys] = useState("");
68
+ if (!commandLineOpen && typedInKeys !== "")
69
+ setTypedInKeys("");
63
70
  const keys = useMemo(() => leaderKeys(active), [active]);
64
71
  const groups = useMemo(() => {
65
72
  const shell = keys.filter((row) => row.scope === undefined);
@@ -138,8 +145,21 @@ export function CommandDialogs({ host, state, focusedWindow, directoryApps, onSt
138
145
  const owner = dialog?.ownerDocument ?? document;
139
146
  const onKeyDown = (event) => {
140
147
  const row = keys.find((candidate) => leaderKeyMatches(event, candidate.key));
141
- if (row === undefined)
148
+ if (row === undefined) {
149
+ // Not a leader key: the person is typing a command, so carry on in
150
+ // the command line instead of leaving the sheet to swallow it.
151
+ if (event.key.length !== 1 ||
152
+ event.ctrlKey ||
153
+ event.metaKey ||
154
+ event.altKey)
155
+ return;
156
+ event.preventDefault();
157
+ event.stopPropagation();
158
+ setTypedInKeys(event.key);
159
+ setKeysOpen(false);
160
+ setCommandLineOpen(true);
142
161
  return;
162
+ }
143
163
  event.preventDefault();
144
164
  event.stopPropagation();
145
165
  choose(row);
@@ -148,7 +168,7 @@ export function CommandDialogs({ host, state, focusedWindow, directoryApps, onSt
148
168
  return () => {
149
169
  owner.removeEventListener("keydown", onKeyDown, true);
150
170
  };
151
- }, [choose, dialog, keys, keysOpen]);
171
+ }, [choose, dialog, keys, keysOpen, setCommandLineOpen, setKeysOpen]);
152
172
  return (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: keysOpen, onOpenChange: setKeysOpen, children: _jsxs(DialogContent, { container: dialog, className: "tourtois-command-palette", "data-tourtois-which-key": "", finalFocus: finalFocus, children: [_jsx(DialogTitle, { children: "Keys" }), _jsxs(DialogDescription, { children: ["Press a key, or ", isMac() ? "⌘K" : "Ctrl+K", " again for the command line."] }), groups.map((group) => (_jsxs("section", { "aria-label": group.label, children: [_jsx("p", { children: group.label }), _jsx(CommandMenu, { "aria-label": `${group.label} keys`, items: group.rows.map((row) => ({
153
173
  id: row.commandId,
154
174
  label: row.title,
@@ -169,7 +189,7 @@ export function CommandDialogs({ host, state, focusedWindow, directoryApps, onSt
169
189
  if (command.sourceId === appDirectorySourceId)
170
190
  return "Other apps";
171
191
  return "Workspace";
172
- }, inputProps: { "aria-label": "Search commands" }, items: paletteRows, placeholder: ":", renderItem: (command) => (_jsxs("div", { className: "tourtois-command-palette-item", children: [_jsx("span", { className: "tourtois-command-palette-item-icon", children: (() => {
192
+ }, inputProps: { "aria-label": "Search commands" }, defaultInputValue: typedInKeys, items: paletteRows, placeholder: ":", renderItem: (command) => (_jsxs("div", { className: "tourtois-command-palette-item", children: [_jsx("span", { className: "tourtois-command-palette-item-icon", children: (() => {
173
193
  const entry = paletteEntry(command);
174
194
  if (entry === undefined)
175
195
  return null;
@@ -182,5 +202,5 @@ export function CommandDialogs({ host, state, focusedWindow, directoryApps, onSt
182
202
  return;
183
203
  setCommandLineOpen(false);
184
204
  run(command.command, "palette");
185
- } }), _jsxs("div", { className: "tourtois-command-palette-footer", children: [_jsx("span", { className: "tourtois-command-palette-close-hint", children: "Esc to close" }), _jsxs("span", { className: "tourtois-command-palette-leader-hint", children: [_jsx("kbd", { className: "kbd kbd-sm", children: mac ? "⌘ K" : "Ctrl K" }), _jsx("span", { children: "then" }), _jsx("kbd", { className: "kbd kbd-sm", children: "?" }), _jsx("span", { children: "for all keys" })] })] })] }) })] }));
205
+ } }, typedInKeys), _jsxs("div", { className: "tourtois-command-palette-footer", children: [_jsx("span", { className: "tourtois-command-palette-close-hint", children: "Esc to close" }), _jsxs("span", { className: "tourtois-command-palette-leader-hint", children: [_jsx("kbd", { className: "kbd kbd-sm", children: mac ? "⌘ K" : "Ctrl K" }), _jsx("span", { children: "then" }), _jsx("kbd", { className: "kbd kbd-sm", children: "?" }), _jsx("span", { children: "for all keys" })] })] })] }) })] }));
186
206
  }
@@ -23,8 +23,8 @@ export declare const desktopSnapshotSchema: z.ZodObject<{
23
23
  }, z.core.$strict>;
24
24
  source: z.ZodEnum<{
25
25
  none: "none";
26
- team: "team";
27
26
  member: "member";
27
+ team: "team";
28
28
  }>;
29
29
  memberRevision: z.ZodNullable<z.ZodNumber>;
30
30
  teamRevision: z.ZodNullable<z.ZodNumber>;
@@ -32,8 +32,8 @@ export type DesktopGill = Readonly<{
32
32
  }>;
33
33
  export declare const desktopArrangeSchema: z.ZodObject<{
34
34
  scope: z.ZodEnum<{
35
- team: "team";
36
35
  member: "member";
36
+ team: "team";
37
37
  }>;
38
38
  basedOn: z.ZodNullable<z.ZodNumber>;
39
39
  ops: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
package/dist/layers.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { OverlayRoot } from "@fungi.computer/caps/components/overlay-root";
3
3
  import { MaosaicoLayers, useLayer } from "@fungi.computer/maosaico";
4
- import { createContext, useContext, useMemo } from "react";
4
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, } from "react";
5
5
  function OverlayContainers({ children, subscribeDismiss, }) {
6
6
  const popover = useLayer("popover");
7
7
  const dialog = useLayer("dialog");
@@ -18,8 +18,62 @@ const DismissContext = createContext(() => undefined);
18
18
  export function useDismissOverlays() {
19
19
  return useContext(DismissContext);
20
20
  }
21
+ const windows = '[data-maosaico-layer="windows"]';
22
+ /**
23
+ * Whether focus landing in an App's frame is the person's doing. A click in a
24
+ * frame is invisible to this document except as the pointer resting on the
25
+ * frame (this document sees it enter the frame element, then nothing) or on
26
+ * a window, and Tab leaves a key press behind. An App that focuses itself while it loads has
27
+ * neither, so it must not close a menu the person just opened. The menu keeps
28
+ * the keyboard too: focus goes back to where it was in this document.
29
+ */
30
+ function usePersonDrivenFocus() {
31
+ const overFrame = useRef(false);
32
+ const tabbed = useRef(false);
33
+ const heldFocus = useRef(null);
34
+ useEffect(() => {
35
+ const pointer = (event) => {
36
+ overFrame.current =
37
+ event.target instanceof Element &&
38
+ event.target.closest(`iframe, ${windows}`) !== null;
39
+ tabbed.current = false;
40
+ };
41
+ const key = (event) => {
42
+ tabbed.current = event.key === "Tab";
43
+ };
44
+ const focused = (event) => {
45
+ if (event.target instanceof HTMLElement &&
46
+ event.target.closest(`iframe, ${windows}`) === null)
47
+ heldFocus.current = event.target;
48
+ };
49
+ document.addEventListener("pointerover", pointer, true);
50
+ document.addEventListener("pointerdown", pointer, true);
51
+ document.addEventListener("keydown", key, true);
52
+ document.addEventListener("focusin", focused, true);
53
+ return () => {
54
+ document.removeEventListener("pointerover", pointer, true);
55
+ document.removeEventListener("pointerdown", pointer, true);
56
+ document.removeEventListener("keydown", key, true);
57
+ document.removeEventListener("focusin", focused, true);
58
+ };
59
+ }, []);
60
+ return useCallback(() => {
61
+ const person = overFrame.current || tabbed.current;
62
+ tabbed.current = false;
63
+ if (!person) {
64
+ const held = heldFocus.current;
65
+ const menuOpen = document.querySelector('[data-maosaico-layer="popover"] [data-open]') !== null;
66
+ if (menuOpen && held?.isConnected === true)
67
+ queueMicrotask(() => {
68
+ held.focus({ preventScroll: true });
69
+ });
70
+ }
71
+ return person;
72
+ }, []);
73
+ }
21
74
  /** Tourtois composes Caps portal destinations with Maosaico's ordered roots. */
22
75
  export function TourtoisLayers({ children }) {
76
+ const personDriven = usePersonDrivenFocus();
23
77
  const dismissal = useMemo(() => {
24
78
  const listeners = new Set();
25
79
  return {
@@ -35,5 +89,9 @@ export function TourtoisLayers({ children }) {
35
89
  },
36
90
  };
37
91
  }, []);
38
- return (_jsx(MaosaicoLayers, { onDismiss: dismissal.dismiss, children: _jsx(DismissContext.Provider, { value: dismissal.dismiss, children: _jsx(OverlayContainers, { subscribeDismiss: dismissal.subscribe, children: children }) }) }));
92
+ const onDismiss = useCallback(() => {
93
+ if (personDriven())
94
+ dismissal.dismiss();
95
+ }, [personDriven, dismissal]);
96
+ return (_jsx(MaosaicoLayers, { onDismiss: onDismiss, children: _jsx(DismissContext.Provider, { value: dismissal.dismiss, children: _jsx(OverlayContainers, { subscribeDismiss: dismissal.subscribe, children: children }) }) }));
39
97
  }
@@ -72,10 +72,10 @@ export type AppAccessDialog = Readonly<{
72
72
  export type PlatformControlsData = SettingsSectionPorts & Readonly<{
73
73
  directory(): Promise<WorkbenchDirectory>;
74
74
  /**
75
- * Override the owner consent flow below. Omit it to use the built-in
76
- * one-click dialog, bounded by the target App's own declared
77
- * capabilities; the owner's click in this trusted shell is the only grant
78
- * a host without a separate per-App ceiling needs.
75
+ * The host's owner consent flow: it decides what the App may be offered
76
+ * from the owner's stored approvals, asks through `dialog` and saves the
77
+ * grant itself. A dialog answer grants nothing on its own, so a host
78
+ * without this flow declines every request.
79
79
  */
80
80
  requestAppAccess?(target: Parameters<WorkbenchHostControls["requestAppAccess"]>[0], input: AppPermissionRequest, dialog: AppAccessDialog): Promise<AppPermissionOutcome>;
81
81
  }>;
@@ -4,11 +4,10 @@ import { Button } from "@fungi.computer/caps/components/button";
4
4
  import { toast } from "@fungi.computer/caps/components/toaster";
5
5
  import { OverlayRoot, } from "@fungi.computer/caps/components/overlay-root";
6
6
  import { desktopGillAdditionSchema, desktopGillSelectionSchema, } from "@fungi.computer/nacre/workbench";
7
- import { addressKey } from "@fungi.computer/nacre/app-directory";
8
7
  import { tourtoisQueryKeys } from "./queries.js";
9
8
  import { useQuery } from "@tanstack/react-query";
10
9
  import { lazy, Suspense, useEffect, useState, useSyncExternalStore, } from "react";
11
- import { AppAccessConsent, consentableAgentOperations, consentableComputerOperations, } from "./AppAccessConsent.js";
10
+ import { AppAccessConsent } from "./AppAccessConsent.js";
12
11
  import { RouterProvider, useRouterState } from "@tanstack/react-router";
13
12
  import { createSettingsRouter, navigateSettings, settingsLocationSchema, } from "./settings-routes.js";
14
13
  export { parseSettingsLocation } from "./settings-routes.js";
@@ -261,7 +260,6 @@ export function PlatformControlsView({ teamId, controls, data, }) {
261
260
  return "customize";
262
261
  },
263
262
  };
264
- const requestAppAccess = data.requestAppAccess;
265
263
  const refreshAfterGrant = async (outcome) => {
266
264
  const settled = await outcome;
267
265
  // The admitted App re-reads its grants and context without a reload.
@@ -269,34 +267,8 @@ export function PlatformControlsView({ teamId, controls, data, }) {
269
267
  controls.changed();
270
268
  return settled;
271
269
  };
272
- const ask = requestAppAccess === undefined
273
- ? async (target, input) => {
274
- const current = await data.directory();
275
- const app = current.apps.find((candidate) => candidate.surfaceId === target.surfaceId);
276
- const openSettings = () => dialog.customize({
277
- category: "apps",
278
- appKey: app ? addressKey(app.address) : null,
279
- section: "desktop",
280
- });
281
- if (app === undefined)
282
- return openSettings();
283
- const agents = consentableAgentOperations(input.agents ?? [], app.declaredCapabilities);
284
- const computers = consentableComputerOperations(input.computers ?? [], app.declaredCapabilities);
285
- if (agents.length === 0 && computers.length === 0)
286
- return openSettings();
287
- const outcome = await dialog.ask({
288
- appName: target.title,
289
- agents,
290
- computers,
291
- // This trusted shell only renders for the signed-in owner;
292
- // their Allow click here is the whole grant, since this host
293
- // keeps no further per-App ceiling to persist.
294
- allow: () => Promise.resolve(true),
295
- });
296
- return outcome === "customize" ? openSettings() : outcome;
297
- }
298
- : (target, input) => requestAppAccess(target, input, dialog);
299
- const attached = controls.attach((target, input) => refreshAfterGrant(ask(target, input)));
270
+ const attached = controls.attach((target, input) => refreshAfterGrant(data.requestAppAccess?.(target, input, dialog) ??
271
+ Promise.resolve("declined")));
300
272
  return attached;
301
273
  }, [controls, data]);
302
274
  const settings = (_jsxs(_Fragment, { children: [_jsx(RouterProvider, { router: controls.router }), _jsx(AppAccessConsent, { request: consent }), _jsx(DeferredSystemSettings, { location: location, sections: controls.sections, onNavigate: (next) => {
@@ -17,8 +17,8 @@ export type TeamIdentity = z.output<typeof teamIdentitySchema>["team"];
17
17
  export type TeamComputerPage = z.output<typeof workbenchComputerDirectorySchema>;
18
18
  /** The complete inventory offered to the shell's Computer picker. */
19
19
  export declare function readWorkbenchComputers(workbench: Pick<TourtoisShell, "computers">, signal: AbortSignal): Promise<{
20
- computerId: string;
21
20
  name: string;
21
+ computerId: string;
22
22
  }[]>;
23
23
  /**
24
24
  * The trusted shell's view of its host: Team/Computer/App directory reads,
@@ -5,7 +5,7 @@ import type { createAppWindowManager, AppLaunchDescriptor } from "./app-windows.
5
5
  export declare function useDirectoryCommands({ host, directory, manager, launchFor, onFocus, onError, }: {
6
6
  host: TourtoisAppSurfaceHost | null;
7
7
  directory: readonly AppDirectoryApp[];
8
- manager: ReturnType<typeof createAppWindowManager>;
8
+ manager: Pick<ReturnType<typeof createAppWindowManager>, "open">;
9
9
  launchFor: (app: AppDirectoryApp) => AppLaunchDescriptor | null;
10
10
  onFocus: (windowId: string) => void;
11
11
  onError: (message: string) => void;
@@ -37,6 +37,10 @@ export function useDirectoryCommands({ host, directory, manager, launchFor, onFo
37
37
  try {
38
38
  await context.manager.open(launch);
39
39
  context.onFocus(launch.windowId);
40
+ // The window is the focus now, but only a focused App's commands are
41
+ // active, and a cold App has not reported frame focus yet. Name it
42
+ // here rather than wait for a report that may never come.
43
+ host.focus?.(surfaceId);
40
44
  const key = appSurfaceCommandKey({ surfaceId, commandId });
41
45
  const registered = () => host
42
46
  .active()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/tourtois",
3
- "version": "0.20.14",
3
+ "version": "0.21.0",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Tourtois: the trusted desktop shell for Oyster and Fungi, with host-supplied Settings sections",
6
6
  "type": "module",
@@ -65,10 +65,6 @@
65
65
  "./app-icon": {
66
66
  "types": "./dist/app-icon.d.ts",
67
67
  "import": "./dist/app-icon.js"
68
- },
69
- "./app-access-consent": {
70
- "types": "./dist/AppAccessConsent.d.ts",
71
- "import": "./dist/AppAccessConsent.js"
72
68
  }
73
69
  },
74
70
  "files": [
@@ -77,15 +73,15 @@
77
73
  "LICENSE"
78
74
  ],
79
75
  "dependencies": {
80
- "@fungi.computer/agar": "0.18.0",
76
+ "@fungi.computer/agar": "0.18.2",
81
77
  "@fungi.computer/cairn": "0.1.0",
82
- "@fungi.computer/caps": "0.11.7",
78
+ "@fungi.computer/caps": "0.12.0",
83
79
  "@fungi.computer/ear-tag": "0.1.0",
84
80
  "@fungi.computer/gills": "0.3.0",
85
81
  "@fungi.computer/maosaico": "0.1.2",
86
- "@fungi.computer/parakeet": "0.12.0",
87
- "@fungi.computer/puffball": "0.9.0",
88
- "@fungi.computer/shiitake": "0.18.2",
82
+ "@fungi.computer/parakeet": "0.12.2",
83
+ "@fungi.computer/puffball": "0.9.1",
84
+ "@fungi.computer/shiitake": "0.19.0",
89
85
  "@fungi.computer/sigils": "0.3.2",
90
86
  "@fungi.computer/sprite": "0.2.2",
91
87
  "@fungi.computer/sprite-zdog": "0.3.2",
@@ -100,16 +96,16 @@
100
96
  "lucide-react": "0.460.0",
101
97
  "react-dom": "18.3.1",
102
98
  "zod": "4.4.3",
103
- "@fungi.computer/nacre": "0.6.6"
99
+ "@fungi.computer/nacre": "0.7.0"
104
100
  },
105
101
  "peerDependencies": {
106
102
  "react": "^18.3.1 || ^19.2.0"
107
103
  },
108
104
  "devDependencies": {
109
- "@fungi.computer/oyster": "0.32.0",
105
+ "@fungi.computer/oyster": "0.34.0",
110
106
  "@cloudflare/workers-types": "5.20260828.1",
111
- "@fungi.computer/forage": "0.3.9",
112
- "@fungi.computer/mycelium": "0.4.0",
107
+ "@fungi.computer/forage": "0.3.10",
108
+ "@fungi.computer/mycelium": "0.4.1",
113
109
  "@ladle/react": "5.1.1",
114
110
  "@types/react": "18.3.3",
115
111
  "@vitejs/plugin-react": "6.1.1",