@botiverse/porthole 0.15.3 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/dist/annotate/types.d.ts +15 -1
  3. package/dist/annotate/validate.js +19 -1
  4. package/dist/bridge/bridge.d.ts +1 -8
  5. package/dist/bridge/bridge.js +0 -7
  6. package/dist/bridge/types.d.ts +1 -1
  7. package/dist/check/page-source.js +1 -1
  8. package/dist/check/page.js +1 -1
  9. package/dist/compile/policy.d.ts +0 -7
  10. package/dist/compile/policy.js +1 -10
  11. package/dist/config/capabilities.d.ts +8 -14
  12. package/dist/config/capabilities.js +4 -5
  13. package/dist/config/schema.d.ts +2 -13
  14. package/dist/config/validate.js +0 -24
  15. package/dist/conformance/behavior.js +26 -37
  16. package/dist/conformance/clipboard.js +47 -1
  17. package/dist/conformance/harness-source.js +1 -1
  18. package/dist/displays/displays.js +1 -3
  19. package/dist/guide/limits.js +1 -1
  20. package/dist/guide/runtime.js +1 -1
  21. package/dist/host/create-host.d.ts +1 -1
  22. package/dist/host/create-host.js +8 -52
  23. package/dist/host/door.d.ts +1 -1
  24. package/dist/host/locate.d.ts +1 -1
  25. package/dist/host/locate.js +2 -2
  26. package/dist/host/outcome.d.ts +5 -12
  27. package/dist/host/outcome.js +8 -16
  28. package/dist/host/types.d.ts +6 -22
  29. package/dist/index.d.ts +2 -4
  30. package/dist/index.js +2 -4
  31. package/dist/isolation/served.d.ts +4 -14
  32. package/dist/isolation/served.js +7 -28
  33. package/dist/isolation/types.d.ts +2 -25
  34. package/dist/isolation/types.js +0 -23
  35. package/dist/platform/focus-field.d.ts +11 -0
  36. package/dist/platform/focus-field.js +18 -0
  37. package/dist/platform/types.d.ts +7 -23
  38. package/dist/platform/web.js +8 -106
  39. package/dist/presets/presets.d.ts +0 -2
  40. package/dist/presets/presets.js +0 -1
  41. package/dist/react/frame.d.ts +0 -8
  42. package/dist/react/frame.js +0 -4
  43. package/dist/runtime/contract.d.ts +2 -2
  44. package/dist/runtime/contract.js +2 -2
  45. package/dist/runtime/types.generated.js +6 -6
  46. package/dist/server/files.js +7 -23
  47. package/dist/server/host.d.ts +1 -1
  48. package/dist/server/index.d.ts +1 -1
  49. package/dist/server/index.js +4 -6
  50. package/dist/server/naming.js +1 -1
  51. package/dist/server/server.js +28 -166
  52. package/dist/server/types.d.ts +7 -7
  53. package/dist/shell/annotate.d.ts +3 -0
  54. package/dist/shell/annotate.js +15 -5
  55. package/dist/shell/plan.d.ts +0 -5
  56. package/dist/shell/plan.js +2 -4
  57. package/dist/shell/runtime.js +1 -268
  58. package/docs/ADOPTING.md +398 -1081
  59. package/docs/DECISIONS.md +172 -10
  60. package/docs/DESIGN.md +1114 -1388
  61. package/docs/PRINCIPLES.md +85 -1
  62. package/docs/THREAT_MODEL.md +658 -1127
  63. package/package.json +1 -1
  64. package/src/annotate/types.ts +12 -1
  65. package/src/annotate/validate.ts +23 -1
  66. package/src/bridge/bridge.ts +1 -17
  67. package/src/bridge/types.ts +1 -1
  68. package/src/check/page.ts +1 -1
  69. package/src/compile/policy.ts +1 -11
  70. package/src/config/capabilities.ts +8 -14
  71. package/src/config/schema.ts +2 -13
  72. package/src/config/validate.ts +0 -28
  73. package/src/conformance/behavior.ts +50 -52
  74. package/src/conformance/clipboard.ts +56 -1
  75. package/src/displays/displays.ts +1 -3
  76. package/src/guide/limits.ts +1 -1
  77. package/src/guide/runtime.ts +1 -1
  78. package/src/host/create-host.ts +8 -53
  79. package/src/host/door.ts +1 -1
  80. package/src/host/locate.ts +2 -2
  81. package/src/host/outcome.ts +8 -21
  82. package/src/host/types.ts +6 -20
  83. package/src/index.ts +2 -4
  84. package/src/isolation/served.ts +6 -34
  85. package/src/isolation/types.ts +2 -31
  86. package/src/platform/focus-field.ts +18 -0
  87. package/src/platform/types.ts +7 -22
  88. package/src/platform/web.ts +8 -129
  89. package/src/presets/presets.ts +0 -3
  90. package/src/react/frame.tsx +0 -10
  91. package/src/runtime/contract.ts +4 -4
  92. package/src/runtime/types.generated.ts +6 -6
  93. package/src/server/files.ts +4 -19
  94. package/src/server/host.ts +1 -1
  95. package/src/server/index.ts +4 -16
  96. package/src/server/naming.ts +1 -1
  97. package/src/server/server.ts +29 -189
  98. package/src/server/types.ts +7 -7
  99. package/src/shell/annotate.ts +15 -5
  100. package/src/shell/plan.ts +2 -9
  101. package/src/shell/runtime.ts +1 -268
  102. package/types/runtime/v1/artifact.d.ts +2 -3
  103. package/types/runtime/v1/assets.d.ts +1 -1
  104. package/types/runtime/v1/chat.d.ts +2 -2
  105. package/types/runtime/v1/comments.d.ts +1 -1
  106. package/types/runtime/v1/downloads.d.ts +2 -2
  107. package/types/runtime/v1/links.d.ts +2 -2
  108. package/dist/platform/focus-guard.d.ts +0 -288
  109. package/dist/platform/focus-guard.js +0 -838
  110. package/dist/server/nested.d.ts +0 -66
  111. package/dist/server/nested.js +0 -121
  112. package/dist/shell/frame.d.ts +0 -28
  113. package/dist/shell/frame.js +0 -407
  114. package/docs/ARCHITECTURE.md +0 -359
  115. package/docs/OBJECTIVES.md +0 -116
  116. package/src/platform/focus-guard.ts +0 -1114
  117. package/src/server/nested.ts +0 -157
  118. package/src/shell/frame.ts +0 -444
@@ -1,94 +1,8 @@
1
1
  import { DOOR_SANDBOX_TOKENS } from "../compile/policy.ts";
2
2
  import type { ColorScheme } from "../config/schema.ts";
3
- import {
4
- SHELL_BEAT_METHOD,
5
- SHELL_FOCUS_METHOD,
6
- SHELL_LOOK_METHOD,
7
- SHELL_METHOD_PREFIX,
8
- SHELL_STATE_METHOD,
9
- } from "../isolation/types.ts";
10
3
  import { postMessageTransport } from "../transport/post-message.ts";
11
- import { focusGuard, type FocusGuard, type FocusTake } from "./focus-guard.ts";
12
- import type { Transport } from "../transport/types.ts";
13
4
  import type { DoorSurface, PlatformHost, Surface, SurfaceSpec } from "./types.ts";
14
5
 
15
- /** A shell's own message (P111), by its namespace. */
16
- const isShellWord = (data: unknown): data is { method: string; params?: unknown } =>
17
- data !== null &&
18
- typeof data === "object" &&
19
- typeof (data as { method?: unknown }).method === "string" &&
20
- (data as { method: string }).method.startsWith(SHELL_METHOD_PREFIX);
21
-
22
- /**
23
- * A nested page's transport (P111): the shell's state, checked, to the focus guard; the rest of
24
- * the shell's namespace dropped; everything else as it came.
25
- */
26
- function shellWords(opened: Transport, frame: HTMLIFrameElement, guard: FocusGuard): Transport {
27
- const listeners = new Set<(message: unknown) => void>();
28
- opened.listen((message) => {
29
- if (!isShellWord(message)) {
30
- for (const listener of listeners) {
31
- listener(message);
32
- }
33
- return;
34
- }
35
- const params = message.params;
36
- if (params === null || typeof params !== "object") {
37
- return;
38
- }
39
- const { supported, ago, focused, gap, asked, pressed, presses } = params as Record<
40
- string,
41
- unknown
42
- >;
43
- const span = (value: unknown) =>
44
- typeof value === "number" && Number.isFinite(value) && value >= 0;
45
- if (message.method === SHELL_BEAT_METHOD) {
46
- if (span(gap)) {
47
- guard.beat(frame);
48
- }
49
- return;
50
- }
51
- if (
52
- message.method !== SHELL_STATE_METHOD ||
53
- typeof supported !== "boolean" ||
54
- typeof focused !== "boolean" ||
55
- !(ago === null || span(ago)) ||
56
- !span(gap) ||
57
- !(asked === undefined || (Number.isSafeInteger(asked) && (asked as number) >= 0)) ||
58
- // The page's presses (P148): absent from a shell older than them, or both there.
59
- !(
60
- (pressed === undefined && presses === undefined) ||
61
- ((pressed === null || span(pressed)) &&
62
- Number.isSafeInteger(presses) &&
63
- (presses as number) >= 0)
64
- )
65
- ) {
66
- return;
67
- }
68
- guard.shell(frame, {
69
- supported,
70
- ago: ago as number | null,
71
- focused,
72
- gap: gap as number,
73
- ...(asked === undefined ? {} : { asked: asked as number }),
74
- ...(presses === undefined
75
- ? {}
76
- : { pressed: pressed as number | null, presses: presses as number }),
77
- });
78
- });
79
- return {
80
- send: (message) => opened.send(message),
81
- listen(listener) {
82
- listeners.add(listener);
83
- return () => listeners.delete(listener);
84
- },
85
- close() {
86
- listeners.clear();
87
- opened.close();
88
- },
89
- };
90
- }
91
-
92
6
  /**
93
7
  * The web platform: an `<iframe>` whose policy attributes are set before its document is given,
94
8
  * talking over `postMessage`. Its first load is the document it was given; any later load is the
@@ -141,37 +55,10 @@ export const webPlatform: PlatformHost = {
141
55
  container.append(frame);
142
56
 
143
57
  const view = container.ownerDocument.defaultView ?? window;
144
- // The focus guard (P109): a move of the keyboard into this frame from one of the page's text
145
- // fields that the person didn't make is undone.
146
- const guard = focusGuard(view);
147
- const taken = new Set<(take: FocusTake) => void>();
148
- const nested = spec.nested === true && spec.source.kind === "url";
149
58
  // A frame is heard from its own window and its located origin alone: never the host's own
150
59
  // origin (P125 removed P068's in-frame pages and the channel that heard them), so no page of
151
60
  // the host's own can speak for a frame either.
152
- const opened = postMessageTransport(() => frame.contentWindow, origin, view);
153
- const unguard = guard.add(
154
- frame,
155
- (take) => {
156
- for (const listener of taken) {
157
- listener(take);
158
- }
159
- },
160
- {
161
- nested,
162
- // A nested page's shell is asked to look as the guard hears a move into its frame (P120).
163
- ...(nested
164
- ? {
165
- ask: (n: number) =>
166
- opened.send({ jsonrpc: "2.0", method: SHELL_LOOK_METHOD, params: { n } }),
167
- }
168
- : {}),
169
- },
170
- );
171
- // A nested page's shell (P111): its own words go to the guard, by the frame's window and the
172
- // content origin (the transport's checks); the page's pass on. The shell drops any page
173
- // message in its namespace, so there none is the page's.
174
- const transport = nested ? shellWords(opened, frame, guard) : opened;
61
+ const transport = postMessageTransport(() => frame.contentWindow, origin, view);
175
62
  return {
176
63
  transport,
177
64
  element: frame,
@@ -199,20 +86,15 @@ export const webPlatform: PlatformHost = {
199
86
  ).userActivation;
200
87
  return activation === undefined ? undefined : activation.isActive;
201
88
  },
89
+ // Where the keyboard is, as the frame's own tree says it (its document's, or the shadow
90
+ // root's it is in): no more than that. A frame may take the focus by itself (0.16.0
91
+ // removed the guard that took it back, P149), so this is no word on who put it there.
202
92
  focused() {
203
- return guard.focused(frame) || (nested && guard.gesture(frame));
204
- },
205
- onFocusTaken(listener) {
206
- taken.add(listener);
207
- return () => taken.delete(listener);
93
+ const root = frame.getRootNode() as Partial<DocumentOrShadowRoot>;
94
+ return root.activeElement === frame;
208
95
  },
209
96
  focus() {
210
- guard.focus(frame);
211
- // A nested page (P136): the move stops at its shell on every engine, one way or another,
212
- // and only the shell can pass it on. Only a move that landed: the shell asks no more of it.
213
- if (nested && view.document.activeElement === frame) {
214
- opened.send({ jsonrpc: "2.0", method: SHELL_FOCUS_METHOD });
215
- }
97
+ frame.focus();
216
98
  },
217
99
  onLoad(listener) {
218
100
  loaded.add(listener);
@@ -225,8 +107,6 @@ export const webPlatform: PlatformHost = {
225
107
  destroy() {
226
108
  navigated.clear();
227
109
  loaded.clear();
228
- taken.clear();
229
- unguard();
230
110
  transport.close();
231
111
  frame.remove();
232
112
  },
@@ -236,8 +116,7 @@ export const webPlatform: PlatformHost = {
236
116
  * A served display's door (P125): hidden (no size, `visibility: hidden`, which still runs its
237
117
  * script and fires its load on all three engines), out of focus and of the accessibility tree,
238
118
  * sandboxed with scripts alone, no `allow`, no name. Nothing but its frame status is heard from
239
- * it, from its window and the opaque origin alone; the focus guard, the bridge and annotations
240
- * never see it.
119
+ * it, from its window and the opaque origin alone; the bridge and annotations never see it.
241
120
  */
242
121
  createDoor(container: HTMLElement, spec: { readonly url: string }): DoorSurface {
243
122
  // oxlint-disable-next-line react/iframe-missing-sandbox -- set from the door's list, next
@@ -56,8 +56,6 @@ export interface PresetOptions {
56
56
  * be offered the runtime's own (`user`, `comments`, `artifact`, `assets`, `db`).
57
57
  */
58
58
  readonly runtime?: RuntimeVersion;
59
- /** Domain isolation, artifact pages: the page in an opaque child of Porthole's shell (P111). */
60
- readonly nested?: true;
61
59
  /**
62
60
  * `own` (P128): an `<iframe>` of one of the page's own files (a relative `src`) or a `srcdoc`
63
61
  * one loads and runs, in a realm of its own that the shell's hardening doesn't reach
@@ -249,7 +247,6 @@ function build(
249
247
  ...(options.storage === undefined ? {} : { storage: options.storage }),
250
248
  ...(options.errors === undefined ? {} : { errors: options.errors }),
251
249
  ...(options.runtime === undefined ? {} : { runtime: options.runtime }),
252
- ...(options.nested === undefined ? {} : { nested: options.nested }),
253
250
  ...(options.nestedFrames === undefined ? {} : { nestedFrames: options.nestedFrames }),
254
251
  });
255
252
  }
@@ -656,12 +656,6 @@ export interface PortholeFrameProps {
656
656
  readonly onRefused?: (capability: CapabilityName, refusal: Refusal) => void;
657
657
  /** Too many declines: the display stops asking until it runs again. */
658
658
  readonly onMuted?: () => void;
659
- /**
660
- * The content moved the keyboard into its frame from one of the page's text fields without the
661
- * person, and focus went back (P109); `typing`: the person was typing on the page. A display
662
- * that keeps doing it is stopped (`onContentError` says so).
663
- */
664
- readonly onFocusTaken?: (taken: { readonly typing: boolean }) => void;
665
659
  /**
666
660
  * How the frame's first document went: loaded, blocked (and why), or a timeout. A host shows its
667
661
  * own fallback (a url-mode app "Open in a new tab") on anything but loaded.
@@ -1067,9 +1061,6 @@ function Mount({
1067
1061
  case "muted":
1068
1062
  frame.onMuted?.();
1069
1063
  return;
1070
- case "focusTaken":
1071
- frame.onFocusTaken?.(detail as DisplayEvents["focusTaken"]);
1072
- return;
1073
1064
  case "outcome":
1074
1065
  frame.onOutcome?.(detail as DisplayEvents["outcome"]);
1075
1066
  return;
@@ -1205,7 +1196,6 @@ function Mount({
1205
1196
  "navigationBlocked",
1206
1197
  "refused",
1207
1198
  "muted",
1208
- "focusTaken",
1209
1199
  "outcome",
1210
1200
  "annotation",
1211
1201
  "findRequested",
@@ -51,8 +51,8 @@ export interface RuntimeMethod {
51
51
  readonly watch?: true;
52
52
  /**
53
53
  * Gates of its own, over its host function's (after the review, P088): what changes the
54
- * artifact for everyone needs the person's click and their yes. A host's config may replace
55
- * them (`CapabilityConfig.methodGates`).
54
+ * artifact for everyone needs the person's yes. A host's config may replace them
55
+ * (`CapabilityConfig.methodGates`).
56
56
  */
57
57
  readonly gates?: readonly Gate[];
58
58
  }
@@ -82,8 +82,8 @@ const method = (
82
82
  ...(extra.gates === undefined ? {} : { gates: extra.gates }),
83
83
  });
84
84
 
85
- /** What changes the artifact for everyone: the person's click, then their yes. */
86
- const CHANGES: readonly Gate[] = ["user-activation", "confirm"];
85
+ /** What changes the artifact for everyone: the person's yes, to its whole effect (no proof of a click since 0.16.0, P149). */
86
+ const CHANGES: readonly Gate[] = ["confirm"];
87
87
 
88
88
  /** Contract 1's capabilities, by the name a page passes to `use`. */
89
89
  export const RUNTIME_CAPABILITIES = {
@@ -3,16 +3,16 @@
3
3
  // contract every capability shares).
4
4
  export const RUNTIME_TYPES: Readonly<Record<string, Readonly<Record<string, string>>>> = {
5
5
  "1": {
6
- "artifact": "// Porthole capability runtime, contract 1: artifact (this artifact itself). Declare it: { artifact: {} }.\n// Use it when the page is the record: a checklist, a plan, a document someone edits in place.\n\ninterface PortholeArtifactFile {\n readonly path: string;\n readonly size: number;\n readonly sha256: string;\n}\n\ninterface PortholeArtifactVersion {\n /** The version's id: what a publish names as its base. */\n readonly version: string;\n readonly number?: number;\n /** The page it opens at (\"index.html\"). */\n readonly entry: string;\n readonly files: readonly PortholeArtifactFile[];\n}\n\ninterface PortholeArtifactPublish {\n /** The version you read and changed (from get()). If it moved, publish rejects with conflict. */\n readonly base: string;\n /**\n * A patch on base's files, by path: text, bytes (a Blob, an ArrayBuffer, a typed array), or\n * null to remove one; files not named are kept. A page sends its whole document, as it should\n * be served. At most 255 files.\n */\n readonly files: Readonly<Record<string, string | Blob | ArrayBuffer | ArrayBufferView | null>>;\n readonly entry?: string;\n /** At most 60 characters. */\n readonly label?: string;\n /** At most 500 characters. */\n readonly note?: string;\n}\n\ninterface PortholeArtifact {\n /** The current version and its files (fetch a file by its relative path). Level: view. */\n get(): Promise<PortholeArtifactVersion>;\n /**\n * Publishes a new version of this artifact, from a click; the app asks the person first. The\n * page can't change what it declares. On conflict: get() again, merge, publish again. Level:\n * admin.\n */\n publish(\n change: PortholeArtifactPublish,\n ): Promise<{ readonly version: string; readonly number?: number }>;\n}\n\ninterface PortholeCapabilities {\n artifact: PortholeArtifact;\n}\n",
7
- "assets": "// Porthole capability runtime, contract 1: assets (the artifact's asset library). Declare it: { assets: {} }.\n// Assets live outside every version, at \"/_blob/<id>\" on the page's own origin: keep that url (or\n// the id) in your data, and show it with assets.url(id). Images, media and fonts load; scripts and\n// stylesheets only where the app lets only admins upload, and only those an admin added. Not for\n// files that version with the page: publish those with it.\n\ninterface PortholeAsset {\n /** 32 hex characters. */\n readonly id: string;\n /** \"/_blob/<id>\": use it as given. */\n readonly url: string;\n readonly name: string;\n /** Porthole's type for the name's extension. */\n readonly type: string;\n readonly size: number;\n}\n\ninterface PortholeAssets {\n /** The library, people's uploads through the page included. Level: view. */\n list(): Promise<readonly PortholeAsset[]>;\n /**\n * Adds a file (a File from an <input type=\"file\">, a Blob, bytes) under its name (a File's own,\n * or options.name): an image, media, a font, a PDF, text or data, never HTML; a script or a\n * stylesheet only where uploads are the admins'. The app may ask the person first. Level: admin,\n * unless the app lets people who interact upload.\n */\n upload(\n file: Blob | ArrayBuffer | ArrayBufferView,\n options?: { readonly name?: string },\n ): Promise<PortholeAsset>;\n /**\n * The address that loads an asset in this page now: put it in src or href when you show it.\n * Store the id (or \"/_blob/<id>\"), never this: it carries this page's access. A \"/_blob/<id>\"\n * written in the page loads too, except in some browsers' frames (Safari's); this always does.\n */\n url(id: string): string;\n /** Removes one, from a click; the app asks the person first. Level: admin. */\n delete(id: string): Promise<boolean>;\n}\n\ninterface PortholeCapabilities {\n assets: PortholeAssets;\n}\n",
8
- "chat": "// Porthole capability runtime, contract 1: chat. Declare it: { chat: {} }.\n\ninterface PortholeChat {\n /**\n * Sends text to the agent as the person's message (\"explain this point\"). Call it from a click.\n * Resolves true if it was sent. Level: interact.\n */\n send(text: string): Promise<boolean>;\n}\n\ninterface PortholeCapabilities {\n chat: PortholeChat;\n}\n",
6
+ "artifact": "// Porthole capability runtime, contract 1: artifact (this artifact itself). Declare it: { artifact: {} }.\n// Use it when the page is the record: a checklist, a plan, a document someone edits in place.\n\ninterface PortholeArtifactFile {\n readonly path: string;\n readonly size: number;\n readonly sha256: string;\n}\n\ninterface PortholeArtifactVersion {\n /** The version's id: what a publish names as its base. */\n readonly version: string;\n readonly number?: number;\n /** The page it opens at (\"index.html\"). */\n readonly entry: string;\n readonly files: readonly PortholeArtifactFile[];\n}\n\ninterface PortholeArtifactPublish {\n /** The version you read and changed (from get()). If it moved, publish rejects with conflict. */\n readonly base: string;\n /**\n * A patch on base's files, by path: text, bytes (a Blob, an ArrayBuffer, a typed array), or\n * null to remove one; files not named are kept. A page sends its whole document, as it should\n * be served. At most 255 files.\n */\n readonly files: Readonly<Record<string, string | Blob | ArrayBuffer | ArrayBufferView | null>>;\n readonly entry?: string;\n /** At most 60 characters. */\n readonly label?: string;\n /** At most 500 characters. */\n readonly note?: string;\n}\n\ninterface PortholeArtifact {\n /** The current version and its files (fetch a file by its relative path). Level: view. */\n get(): Promise<PortholeArtifactVersion>;\n /**\n * Publishes a new version of this artifact; the app asks the person first. The page can't\n * change what it declares. On conflict: get() again, merge, publish again. Level: admin.\n */\n publish(\n change: PortholeArtifactPublish,\n ): Promise<{ readonly version: string; readonly number?: number }>;\n}\n\ninterface PortholeCapabilities {\n artifact: PortholeArtifact;\n}\n",
7
+ "assets": "// Porthole capability runtime, contract 1: assets (the artifact's asset library). Declare it: { assets: {} }.\n// Assets live outside every version, at \"/_blob/<id>\" on the page's own origin: keep that url (or\n// the id) in your data, and show it with assets.url(id). Images, media and fonts load; scripts and\n// stylesheets only where the app lets only admins upload, and only those an admin added. Not for\n// files that version with the page: publish those with it.\n\ninterface PortholeAsset {\n /** 32 hex characters. */\n readonly id: string;\n /** \"/_blob/<id>\": use it as given. */\n readonly url: string;\n readonly name: string;\n /** Porthole's type for the name's extension. */\n readonly type: string;\n readonly size: number;\n}\n\ninterface PortholeAssets {\n /** The library, people's uploads through the page included. Level: view. */\n list(): Promise<readonly PortholeAsset[]>;\n /**\n * Adds a file (a File from an <input type=\"file\">, a Blob, bytes) under its name (a File's own,\n * or options.name): an image, media, a font, a PDF, text or data, never HTML; a script or a\n * stylesheet only where uploads are the admins'. The app may ask the person first. Level: admin,\n * unless the app lets people who interact upload.\n */\n upload(\n file: Blob | ArrayBuffer | ArrayBufferView,\n options?: { readonly name?: string },\n ): Promise<PortholeAsset>;\n /**\n * The address that loads an asset in this page now: put it in src or href when you show it.\n * Store the id (or \"/_blob/<id>\"), never this: it carries this page's access. A \"/_blob/<id>\"\n * written in the page loads too, except in some browsers' frames (Safari's); this always does.\n */\n url(id: string): string;\n /** Removes one; the app asks the person first. Level: admin. */\n delete(id: string): Promise<boolean>;\n}\n\ninterface PortholeCapabilities {\n assets: PortholeAssets;\n}\n",
8
+ "chat": "// Porthole capability runtime, contract 1: chat. Declare it: { chat: {} }.\n\ninterface PortholeChat {\n /**\n * Sends text to the agent as the person's message (\"explain this point\"); the app asks them\n * first. Resolves true if it was sent. Level: interact.\n */\n send(text: string): Promise<boolean>;\n}\n\ninterface PortholeCapabilities {\n chat: PortholeChat;\n}\n",
9
9
  "clipboard": "// Porthole capability runtime, contract 1: clipboard. Built in: never declare it.\n\ninterface PortholeClipboard {\n /**\n * Copies text to the person's clipboard (at most 20,000 characters); the app shows them what\n * was copied. Nothing else in the page can write the clipboard. Call it from a click.\n * Resolves true if it was copied. Level: view.\n */\n copy(text: string): Promise<boolean>;\n}\n\ninterface PortholeCapabilities {\n clipboard: PortholeClipboard;\n}\n",
10
- "comments": "// Porthole capability runtime, contract 1: comments. Built in: never declare it.\n\n/** Where a comment goes, in the page's own words. */\ninterface PortholeCommentAnchor {\n /** A stable name the page chose: \"slide-3\", \"refs/a.md#L12\" (at most 256 characters). */\n readonly name: string;\n /** What the app shows for it (at most 200; what a person can't see is taken out). */\n readonly label?: string;\n /** The text the comment is about (at most 2,000; what a person can't see is taken out). */\n readonly quote?: string;\n}\n\n/** How the composer opens. */\ninterface PortholeCommentOptions {\n /**\n * Text the composer starts with (at most 2,000 characters): a draft the person edits, posts\n * or discards in the app. It is never posted without them. Visible text only: new lines and\n * tabs are fine (at most 32 blanks in a row, two blank lines in a row), and so are U+200C and\n * U+200D between two letters or marks (Persian, the Indic scripts); a draft with zero-width\n * characters, a joiner anywhere else (an emoji joined with U+200D too; ❤️ is fine), bidi or tag\n * characters, or a line or paragraph separator (U+2028, U+2029) is refused.\n */\n readonly draft?: string;\n}\n\ninterface PortholeComments {\n /**\n * Opens the app's comment composer at the anchor (a name alone is { name }), starting with\n * `options.draft` if given. The person writes and posts it in the app. Resolves true if the\n * composer opened, false if it didn't (the app may refuse while the person is writing).\n * Write-only: a page never reads comments. Call it from a click in the page. Level: view.\n */\n open(anchor: PortholeCommentAnchor | string, options?: PortholeCommentOptions): Promise<boolean>;\n}\n\ninterface PortholeCapabilities {\n comments: PortholeComments;\n}\n",
10
+ "comments": "// Porthole capability runtime, contract 1: comments. Built in: never declare it.\n\n/** Where a comment goes, in the page's own words. */\ninterface PortholeCommentAnchor {\n /** A stable name the page chose: \"slide-3\", \"refs/a.md#L12\" (at most 256 characters). */\n readonly name: string;\n /** What the app shows for it (at most 200; what a person can't see is taken out). */\n readonly label?: string;\n /** The text the comment is about (at most 2,000; what a person can't see is taken out). */\n readonly quote?: string;\n}\n\n/** How the composer opens. */\ninterface PortholeCommentOptions {\n /**\n * Text the composer starts with (at most 2,000 characters): a draft the person edits, posts\n * or discards in the app. It is never posted without them. Visible text only: new lines and\n * tabs are fine (at most 32 blanks in a row, two blank lines in a row), and so are U+200C and\n * U+200D between two letters or marks (Persian, the Indic scripts); a draft with zero-width\n * characters, a joiner anywhere else (an emoji joined with U+200D too; ❤️ is fine), bidi or tag\n * characters, or a line or paragraph separator (U+2028, U+2029) is refused.\n */\n readonly draft?: string;\n}\n\ninterface PortholeComments {\n /**\n * Opens the app's comment composer at the anchor (a name alone is { name }), starting with\n * `options.draft` if given. The person writes and posts it in the app. Resolves true if the\n * composer opened, false if it didn't (the app may refuse while the person is writing).\n * Write-only: a page never reads comments. Level: view.\n */\n open(anchor: PortholeCommentAnchor | string, options?: PortholeCommentOptions): Promise<boolean>;\n}\n\ninterface PortholeCapabilities {\n comments: PortholeComments;\n}\n",
11
11
  "context": "// Porthole capability runtime, contract 1: context. Declare it: { context: {} }.\n\ninterface PortholeContextUpdate {\n /**\n * MCP text blocks only: [{ type: \"text\", text: \"…\" }]. Visible characters only, here and in\n * structuredContent: no zero-width or bidi controls, variation selectors, tag or private-use\n * characters, or controls other than new lines and tabs (refused), but the selectors and\n * joiners inside real emoji (☀️, 👨‍👩‍👧, 1️⃣), and a joiner or non-joiner between two letters of\n * a script it shapes (Arabic, Persian, the Indic scripts, Myanmar…).\n */\n readonly content?: readonly unknown[];\n /** Plain JSON. With the text, at most 20,000 characters. */\n readonly structuredContent?: Record<string, unknown>;\n}\n\ninterface PortholeContext {\n /**\n * Tells the agent, at its next turns, what the page says the person is looking at (replaces the\n * last). The agent reads it as the page's words, unconfirmed by the person; the app shows the\n * person each update unless it says otherwise. Level: interact.\n */\n set(update: PortholeContextUpdate): Promise<unknown>;\n}\n\ninterface PortholeCapabilities {\n context: PortholeContext;\n}\n",
12
12
  "data": "// Porthole capability runtime, contract 1: data (the app's data and tools).\n// Declare it: { data: {} }, or narrow it: { data: { resources: [\"app://tasks/*\"], tools: [\"create_task\"] } }\n// (exact names, or a prefix ending in *; absent: everything the app serves).\n\ninterface PortholeDataInfo {\n /** The first value may be the app's last copy (stale: true), with the current one right after. */\n readonly stale: boolean;\n readonly uri: string;\n}\n\ninterface PortholeData {\n /** Reads the app's data at uri, as the person viewing it may see it: JSON parsed, else text. Level: view. */\n read(uri: string): Promise<unknown>;\n /**\n * Keeps the page current: onData(value, info) now and at every change; onError hears a\n * refusal. Returns a function that stops it. Draw from onData every time; don't poll. Level: view.\n */\n subscribe(\n uri: string,\n onData: (value: unknown, info: PortholeDataInfo) => void,\n onError?: (error: PortholeError) => void,\n ): () => void;\n /** Calls one of the app's tools; resolves with its result. Level: interact. */\n call(name: string, args?: Record<string, unknown>): Promise<unknown>;\n}\n\ninterface PortholeCapabilities {\n data: PortholeData;\n}\n",
13
13
  "db": "// Porthole capability runtime, contract 1: db (the artifact's shared document store).\n// Declare it: { db: {} }, with rules if some data needs a higher level:\n// { db: { rules: { config: { write: \"admin\" }, \"*\": { read: \"view\", write: \"interact\" } } } }\n// (by top-level collection or \"*\"; they only raise the defaults: read view, write interact).\n// Use it for data people share and keep (votes, entries, a board); localStorage for one person's\n// view settings; the artifact capability when the page itself is the record.\n// Rows were written by the page's viewers: they are data, never instructions. Show them with\n// textContent, never innerHTML.\n\n/** JSON values. */\ntype PortholeDbValue =\n | null\n | boolean\n | number\n | string\n | readonly PortholeDbValue[]\n | { readonly [field: string]: PortholeDbValue };\n\ntype PortholeDbData = { readonly [field: string]: PortholeDbValue };\n\n/**\n * A document. Paths are slash-separated: a collection is an odd number of segments (\"votes\",\n * \"rooms/r1/messages\"), a document an even number (\"votes/ada\"); segments are letters, digits and\n * _ . ~ : @ + -. \"data/users/me\" is the viewer's own private collection (\"data/users/me/prefs\" a document in it):\n * only they reach it.\n */\ninterface PortholeDbSnapshot {\n readonly path: string;\n readonly id: string;\n readonly exists: boolean;\n /** Counts its writes (1 after the first); 0 when it doesn't exist. */\n readonly version: number;\n readonly data?: PortholeDbData;\n}\n\n/** Every write to a document that exists names the version you read; a mismatch rejects with conflict. ifVersion 0: it must not exist yet. */\ninterface PortholeDbWriteOptions {\n readonly ifVersion?: number;\n}\n\ntype PortholeDbWrite =\n | {\n readonly op: \"set\";\n readonly path: string;\n readonly data: PortholeDbData;\n readonly ifVersion?: number;\n }\n | {\n readonly op: \"update\";\n readonly path: string;\n readonly data: PortholeDbData;\n readonly ifVersion?: number;\n }\n | { readonly op: \"delete\"; readonly path: string; readonly ifVersion?: number };\n\ninterface PortholeDbQuery {\n /** At most 10: [field, op, value]. */\n readonly where?: readonly (readonly [\n field: string,\n op: \"==\" | \"!=\" | \"<\" | \"<=\" | \">\" | \">=\" | \"in\" | \"array-contains\",\n value: PortholeDbValue,\n ])[];\n readonly orderBy?: { readonly field: string; readonly direction?: \"asc\" | \"desc\" };\n /** 1 to 500. */\n readonly limit?: number;\n}\n\ninterface PortholeDb {\n /** Level: view. */\n get(path: string): Promise<PortholeDbSnapshot>;\n /** A collection's documents. Level: view. */\n query(\n collection: string,\n query?: PortholeDbQuery,\n ): Promise<{ readonly docs: readonly PortholeDbSnapshot[] }>;\n /** Writes a whole document (at most 1 MiB of JSON). Level: interact. */\n set(\n path: string,\n data: PortholeDbData,\n options?: PortholeDbWriteOptions,\n ): Promise<{ readonly version: number }>;\n /** Merges fields over a document's. Level: interact. */\n update(\n path: string,\n data: PortholeDbData,\n options?: PortholeDbWriteOptions,\n ): Promise<{ readonly version: number }>;\n /** Level: interact. */\n delete(path: string, options?: PortholeDbWriteOptions): Promise<null>;\n /**\n * Up to 50 writes to different documents, all or none. Each write's new version (null for a\n * delete). Each write at its own level.\n */\n batch(\n writes: readonly PortholeDbWrite[],\n ): Promise<{ readonly versions: readonly (number | null)[] }>;\n /**\n * Follows a document (a snapshot) or a collection ({ docs }) now and at every change. Returns a\n * function that stops it. Draw from onData; don't poll. Level: view.\n */\n onSnapshot(\n path: string,\n onData: (state: PortholeDbSnapshot | { readonly docs: readonly PortholeDbSnapshot[] }) => void,\n onError?: (error: PortholeError) => void,\n ): () => void;\n}\n\ninterface PortholeCapabilities {\n db: PortholeDb;\n}\n",
14
- "downloads": "// Porthole capability runtime, contract 1: downloads. Built in: never declare it.\n\n/** A file to hand the person: its name, and its text or bytes. */\ninterface PortholeDownload {\n /** A file name, no slashes: \"report.csv\". Its extension gives its type unless `type` says. */\n readonly name: string;\n readonly type?: string;\n readonly text?: string;\n readonly data?: Blob | ArrayBuffer | ArrayBufferView;\n}\n\ninterface PortholeDownloads {\n /**\n * Hands the person a file to save (<a download> and script-driven saves don't work here).\n * Call it from a click. Resolves true if the download started. Level: view.\n */\n save(file: PortholeDownload): Promise<boolean>;\n}\n\ninterface PortholeCapabilities {\n downloads: PortholeDownloads;\n}\n",
15
- "links": "// Porthole capability runtime, contract 1: links. Built in: never declare it.\n\ninterface PortholeLinks {\n /**\n * Opens an http(s) link outside the page (a click on an <a href> does the same). Call it from\n * a click. Resolves true if it opened. Level: view.\n */\n open(url: string): Promise<boolean>;\n}\n\ninterface PortholeCapabilities {\n links: PortholeLinks;\n}\n",
14
+ "downloads": "// Porthole capability runtime, contract 1: downloads. Built in: never declare it.\n\n/** A file to hand the person: its name, and its text or bytes. */\ninterface PortholeDownload {\n /** A file name, no slashes: \"report.csv\". Its extension gives its type unless `type` says. */\n readonly name: string;\n readonly type?: string;\n readonly text?: string;\n readonly data?: Blob | ArrayBuffer | ArrayBufferView;\n}\n\ninterface PortholeDownloads {\n /**\n * Hands the person a file to save (<a download> and script-driven saves don't work here);\n * the app asks them first. Resolves true if the download started. Level: view.\n */\n save(file: PortholeDownload): Promise<boolean>;\n}\n\ninterface PortholeCapabilities {\n downloads: PortholeDownloads;\n}\n",
15
+ "links": "// Porthole capability runtime, contract 1: links. Built in: never declare it.\n\ninterface PortholeLinks {\n /**\n * Opens an http(s) link outside the page (a click on an <a href> does the same); the app asks\n * the person first. Resolves true if it opened. Level: view.\n */\n open(url: string): Promise<boolean>;\n}\n\ninterface PortholeCapabilities {\n links: PortholeLinks;\n}\n",
16
16
  "porthole": "// Porthole capability runtime, contract 1: the call contract (how a page reaches any capability).\n\n/**\n * Why a call was refused: branch on it; show `message` (a sentence for the person) where the\n * result would be. Never retry in a loop.\n * - consent_required: the person hasn't allowed it yet.\n * - denied: the person said no.\n * - rate_limited: too many calls this minute.\n * - not_allowed: not available here (some places show the page without it).\n * - failed: the app tried and couldn't.\n * - forbidden: this person may see the page but not do this (their level).\n * - conflict: what you change moved since you read it: read it again, then write.\n * - too_large: past a limit.\n */\ntype PortholeErrorCode =\n | \"consent_required\"\n | \"denied\"\n | \"rate_limited\"\n | \"not_allowed\"\n | \"failed\"\n | \"forbidden\"\n | \"conflict\"\n | \"too_large\";\n\n/** What every capability method rejects with. */\ninterface PortholeError extends Error {\n readonly code: PortholeErrorCode;\n}\n\n/** Each capability's namespace, by the name `use` takes (each capability's own file adds its own). */\ninterface PortholeCapabilities {}\n\ninterface PortholeRuntime {\n /**\n * The capability's namespace, frozen; or null when it isn't there for this page: the app\n * doesn't offer it, the page didn't declare it, or no app is showing the page (a tab, a\n * preview). The reasons are indistinguishable: draw the page without it. `use` never rejects;\n * permission problems come when you call a method (a rejected promise, `PortholeError`).\n */\n use<N extends keyof PortholeCapabilities>(name: N): Promise<PortholeCapabilities[N] | null>;\n}\n\n/** The page's one global. Nothing else is added to `window`. */\ndeclare const porthole: PortholeRuntime;\n",
17
17
  "user": "// Porthole capability runtime, contract 1: user. Declare it: { user: {} }.\n\n/** Who is viewing, as the app says. */\ninterface PortholeUserInfo {\n /** The app's id for this person (whose data \"data/users/me\" is), or null if it gives none. */\n readonly id: string | null;\n readonly name: string | null;\n /** What they may do here: view < interact < admin < owner. */\n readonly level: \"view\" | \"interact\" | \"admin\" | \"owner\";\n}\n\ninterface PortholeUser {\n /** Level: view. */\n get(): Promise<PortholeUserInfo>;\n}\n\ninterface PortholeCapabilities {\n user: PortholeUser;\n}\n",
18
18
  },
@@ -12,7 +12,6 @@ import { DEFAULT_ENTRY, lookupFile, requestFilePath, type FileLookup } from "../
12
12
  import { fileTypeOf } from "../files/types.ts";
13
13
  import { isCodeAsset } from "../runtime/requests.ts";
14
14
  import { sha256, utf8 } from "./crypto.ts";
15
- import { NESTED_FILE_HEADERS, nestedFileCsp } from "./nested.ts";
16
15
  import type { FileBody, StoredAsset, StoredFiles } from "./types.ts";
17
16
 
18
17
  /**
@@ -260,8 +259,6 @@ export async function serveFile(serving: FileServing): Promise<Response> {
260
259
  return nothing(serving, 404, method);
261
260
  }
262
261
  const { type, role } = fileTypeOf(found.path);
263
- // A nested page (P111): in its shell's child, an opaque origin.
264
- const nested = serving.compiled.config.nested === true;
265
262
  // In a frame, the version's files are at a sealed address (P083), which their own loads of the
266
263
  // artifact's assets carry as their `Referer` (P091): to this origin only, never another.
267
264
  const referrer =
@@ -283,13 +280,8 @@ export async function serveFile(serving: FileServing): Promise<Response> {
283
280
  // A page and a script (a worker's policy is its script's) get the page's CSP, a page with its
284
281
  // frame's sandbox, on a tab of its own too (P099); anything else runs nothing when opened on
285
282
  // its own.
286
- // A nested page's files are on its shell's origin (P111, after the review): every one carries a
287
- // sandbox, so none opened as a document on its own (a tab, "open image in new tab") runs on that
288
- // origin. Pages run their scripts, opaque; anything else runs nothing (a file's is inert already,
289
- // a script's gets one too).
290
- const csp = nested
291
- ? nestedFileCsp(role, directives)
292
- : role === "file"
283
+ const csp =
284
+ role === "file"
293
285
  ? INERT_FILE_CSP
294
286
  : role === "page"
295
287
  ? servedDocumentCsp(serving.compiled.config, directives)
@@ -309,8 +301,7 @@ export async function serveFile(serving: FileServing): Promise<Response> {
309
301
  if (role === "page") {
310
302
  // Every page of the set in the shell (P081): its hardening, its host functions, its theme.
311
303
  const html = serving.compiled.shellDocument({
312
- // A nested page hears its shell, on its own origin, never the host (P111).
313
- origins: nested ? [serving.origin] : serving.hostOrigins,
304
+ origins: serving.hostOrigins,
314
305
  document: await textOf(body),
315
306
  cspMeta: false,
316
307
  ...(referrer === "same-origin" ? { referrer } : {}),
@@ -350,14 +341,8 @@ export async function serveFile(serving: FileServing): Promise<Response> {
350
341
  serving.pinned ? `private, max-age=${YEAR}, immutable` : "private, no-cache",
351
342
  );
352
343
  // Only this origin's own pages load it: no other content origin (a sibling, same-site without
353
- // the public suffix list) can embed it with the viewer's cookie. A nested page's origin is
354
- // opaque, and its files carry their access in their path, never a cookie (P111).
344
+ // the public suffix list) can embed it with the viewer's cookie.
355
345
  headers.set("cross-origin-resource-policy", "same-origin");
356
- if (nested) {
357
- for (const [name, value] of Object.entries(NESTED_FILE_HEADERS)) {
358
- headers.set(name, value);
359
- }
360
- }
361
346
  headers.set("accept-ranges", "bytes");
362
347
  if (role === "file" && type === "application/octet-stream") {
363
348
  headers.set("content-disposition", "attachment");
@@ -113,7 +113,7 @@ export interface ContentHostOptions<V> {
113
113
  /**
114
114
  * Origins of an outer page that frame the app itself (P141): each may be an ancestor of every frame
115
115
  * the app shows, above an app origin's page, so it is in every `frame-ancestors` Porthole sends
116
- * (content, nested pages, doors, status and entry pages, the authorize route's pages) after
116
+ * (content, doors, status and entry pages, the authorize route's pages) after
117
117
  * `appOrigins`, and nowhere else. Never an origin a frame hears or tells, never an app origin for
118
118
  * redirect entry or the handoff; the app's own page must still be the frame's parent. Exact https
119
119
  * origins (`http://` on loopback), none an app origin, none the content domain's site. The app's
@@ -70,27 +70,15 @@ export {
70
70
  type D1StatementLike,
71
71
  } from "./tickets.ts";
72
72
  export { DOOR_PATH, FRAME_STATUS_METHOD } from "../isolation/types.ts";
73
- // A served display's door (P125): `/server` serves it for a shell, a page that isn't nested and the
73
+ // A served display's door (P125): `/server` serves it for a shell, a page and the
74
74
  // sandbox proxy; a content Worker of a host's own answers the same at `DOOR_PATH<key>`, after
75
75
  // taking the door's own ticket (`TicketRecord.door`) and running the checks its content's address
76
76
  // runs (docs/ADOPTING.md, "The door"). A host that signs its own tickets answers it with
77
77
  // `PortholeServer.doorAnswer` once it has admitted the request itself (P126).
78
78
  export { doorResponse, doorStatusResponse, type DoorOptions } from "./pages.ts";
79
- // A nested page (P111): Porthole's shell at the framed address, the page and its files below the
80
- // sealed prefix, all on the shell's own label (P114, `nestedLabelOf`). `/server` serves them for a
81
- // config with `nested`; a content Worker of its own answers the same (docs/ADOPTING.md, "Nested
82
- // pages").
83
- export {
84
- isNestedLabel,
85
- NESTED_FILE_HEADERS,
86
- NESTED_FILES_PREFIX,
87
- nestedAncestors,
88
- nestedFileCsp,
89
- nestedLabelOf,
90
- nestedShellCsp,
91
- nestedShellResponse,
92
- PORTHOLE_LABEL_PREFIX,
93
- } from "./nested.ts";
79
+ // Labels that start so are Porthole's own (its health label; until 0.16.0 a nested page's shell's,
80
+ // P114): no host's naming makes one.
81
+ export { PORTHOLE_LABEL_PREFIX } from "../isolation/served.ts";
94
82
  export { isHostLabel, prefixedName, type Naming } from "./naming.ts";
95
83
  // The page an app serves in conformance test mode (P071).
96
84
  export { conformancePage } from "../conformance/page.ts";
@@ -42,7 +42,7 @@ export function prefixedName(prefix: string): Naming & {
42
42
  "A name prefix is a lowercase letter, then letters or digits, then '-' (a-)",
43
43
  );
44
44
  }
45
- // Porthole's own labels (a nested page's shell's, P114) are never a scope's.
45
+ // Porthole's own labels are never a scope's.
46
46
  if (prefix === "porthole-") {
47
47
  throw new TypeError("The name prefix porthole- is Porthole's own: choose another (a-)");
48
48
  }