@botiverse/porthole 0.7.0 → 0.8.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 (153) hide show
  1. package/README.md +9 -2
  2. package/THIRD_PARTY_NOTICES.md +421 -0
  3. package/dist/bridge/bounded-text.d.ts +34 -0
  4. package/dist/bridge/bounded-text.js +188 -0
  5. package/dist/bridge/bridge.d.ts +25 -5
  6. package/dist/bridge/bridge.js +311 -73
  7. package/dist/bridge/json-data.d.ts +28 -0
  8. package/dist/bridge/json-data.js +86 -0
  9. package/dist/bridge/navigation.d.ts +5 -0
  10. package/dist/bridge/navigation.js +7 -0
  11. package/dist/bridge/refusal.js +1 -0
  12. package/dist/bridge/types.d.ts +32 -1
  13. package/dist/check/page-source.js +1 -1
  14. package/dist/check/page.js +2 -0
  15. package/dist/compile/compile.d.ts +6 -0
  16. package/dist/compile/compile.js +3 -1
  17. package/dist/compile/policy.d.ts +38 -2
  18. package/dist/compile/policy.js +122 -7
  19. package/dist/config/capabilities.d.ts +23 -4
  20. package/dist/config/capabilities.js +12 -2
  21. package/dist/config/schema.d.ts +11 -0
  22. package/dist/config/validate.d.ts +8 -2
  23. package/dist/config/validate.js +28 -6
  24. package/dist/config/warnings.d.ts +20 -0
  25. package/dist/config/warnings.js +25 -0
  26. package/dist/conformance/behavior.js +46 -1
  27. package/dist/conformance/cookies.d.ts +15 -0
  28. package/dist/conformance/cookies.js +80 -0
  29. package/dist/conformance/harness/page.d.ts +1 -0
  30. package/dist/conformance/harness/page.js +9 -2
  31. package/dist/conformance/harness-source.js +1 -1
  32. package/dist/conformance/host-kit.js +5 -1
  33. package/dist/conformance/index.d.ts +10 -0
  34. package/dist/conformance/limits.js +38 -1
  35. package/dist/conformance/runtime.js +10 -0
  36. package/dist/conformance/served.d.ts +2 -0
  37. package/dist/conformance/served.js +737 -4
  38. package/dist/files/paths.js +4 -0
  39. package/dist/guide/gates.d.ts +7 -1
  40. package/dist/guide/gates.js +12 -0
  41. package/dist/guide/guide.js +2 -2
  42. package/dist/guide/runtime.js +11 -3
  43. package/dist/host/create-host.js +49 -37
  44. package/dist/host/pages-of-set.d.ts +43 -0
  45. package/dist/host/pages-of-set.js +196 -0
  46. package/dist/host/types.d.ts +8 -1
  47. package/dist/index.d.ts +5 -4
  48. package/dist/index.js +3 -2
  49. package/dist/mcp/adapter.js +11 -15
  50. package/dist/node/index.d.ts +36 -4
  51. package/dist/node/index.js +402 -101
  52. package/dist/presets/presets.d.ts +16 -8
  53. package/dist/presets/presets.js +39 -8
  54. package/dist/protocol/live-data.d.ts +6 -2
  55. package/dist/protocol/live-data.js +20 -1
  56. package/dist/protocol/mcp-apps.d.ts +13 -2
  57. package/dist/protocol/mcp-apps.js +10 -2
  58. package/dist/protocol/message-text.d.ts +8 -0
  59. package/dist/protocol/message-text.js +29 -0
  60. package/dist/protocol/runtime-calls.js +3 -0
  61. package/dist/protocol/shell-adapter.js +16 -22
  62. package/dist/react/context-notice.d.ts +32 -0
  63. package/dist/react/context-notice.js +28 -0
  64. package/dist/react/dialog.js +62 -18
  65. package/dist/react/frame.d.ts +12 -1
  66. package/dist/react/frame.js +79 -2
  67. package/dist/react/index.d.ts +2 -1
  68. package/dist/react/index.js +2 -1
  69. package/dist/runtime/contract.d.ts +9 -1
  70. package/dist/runtime/contract.js +31 -2
  71. package/dist/runtime/db.d.ts +41 -6
  72. package/dist/runtime/db.js +120 -16
  73. package/dist/runtime/declaration.d.ts +15 -1
  74. package/dist/runtime/declaration.js +184 -87
  75. package/dist/runtime/requests.js +27 -11
  76. package/dist/runtime/types.generated.js +1 -1
  77. package/dist/server/files.d.ts +5 -0
  78. package/dist/server/files.js +22 -7
  79. package/dist/server/host.d.ts +18 -1
  80. package/dist/server/host.js +132 -2
  81. package/dist/server/index.d.ts +1 -1
  82. package/dist/server/index.js +1 -1
  83. package/dist/server/peer.d.ts +4 -0
  84. package/dist/server/peer.js +19 -0
  85. package/dist/server/proxy.d.ts +6 -0
  86. package/dist/server/proxy.js +12 -3
  87. package/dist/server/server.js +113 -26
  88. package/dist/server/types.d.ts +6 -3
  89. package/dist/shell/document.d.ts +8 -0
  90. package/dist/shell/document.js +3 -0
  91. package/dist/shell/runtime.js +361 -14
  92. package/docs/ADOPTING.md +119 -14
  93. package/docs/ARCHITECTURE.md +13 -3
  94. package/docs/DECISIONS.md +1455 -8
  95. package/docs/DESIGN.md +79 -25
  96. package/docs/THREAT_MODEL.md +616 -0
  97. package/package.json +14 -3
  98. package/src/bridge/bounded-text.ts +240 -0
  99. package/src/bridge/bridge.ts +373 -84
  100. package/src/bridge/json-data.ts +95 -0
  101. package/src/bridge/navigation.ts +10 -0
  102. package/src/bridge/refusal.ts +1 -0
  103. package/src/bridge/types.ts +30 -1
  104. package/src/check/page.ts +2 -0
  105. package/src/compile/compile.ts +9 -1
  106. package/src/compile/policy.ts +130 -7
  107. package/src/config/capabilities.ts +22 -3
  108. package/src/config/schema.ts +11 -0
  109. package/src/config/validate.ts +43 -5
  110. package/src/config/warnings.ts +42 -0
  111. package/src/conformance/behavior.ts +54 -1
  112. package/src/conformance/cookies.ts +93 -0
  113. package/src/conformance/harness/page.ts +11 -2
  114. package/src/conformance/host-kit.ts +10 -1
  115. package/src/conformance/index.ts +10 -0
  116. package/src/conformance/limits.ts +39 -1
  117. package/src/conformance/runtime.ts +21 -0
  118. package/src/conformance/served.ts +888 -4
  119. package/src/files/paths.ts +4 -0
  120. package/src/guide/gates.ts +13 -1
  121. package/src/guide/guide.ts +3 -3
  122. package/src/guide/runtime.ts +12 -3
  123. package/src/host/create-host.ts +54 -36
  124. package/src/host/pages-of-set.ts +226 -0
  125. package/src/host/types.ts +15 -1
  126. package/src/index.ts +5 -0
  127. package/src/mcp/adapter.ts +16 -20
  128. package/src/node/index.ts +507 -116
  129. package/src/presets/presets.ts +60 -17
  130. package/src/protocol/live-data.ts +31 -3
  131. package/src/protocol/mcp-apps.ts +11 -2
  132. package/src/protocol/message-text.ts +36 -0
  133. package/src/protocol/runtime-calls.ts +3 -0
  134. package/src/protocol/shell-adapter.ts +27 -23
  135. package/src/react/context-notice.tsx +95 -0
  136. package/src/react/dialog.tsx +77 -17
  137. package/src/react/frame.tsx +101 -0
  138. package/src/react/index.ts +8 -1
  139. package/src/runtime/contract.ts +36 -2
  140. package/src/runtime/db.ts +140 -20
  141. package/src/runtime/declaration.ts +227 -89
  142. package/src/runtime/requests.ts +27 -11
  143. package/src/runtime/types.generated.ts +1 -1
  144. package/src/server/files.ts +29 -11
  145. package/src/server/host.ts +158 -3
  146. package/src/server/index.ts +1 -0
  147. package/src/server/peer.ts +21 -0
  148. package/src/server/proxy.ts +13 -3
  149. package/src/server/server.ts +139 -36
  150. package/src/server/types.ts +6 -3
  151. package/src/shell/document.ts +8 -0
  152. package/src/shell/runtime.ts +361 -14
  153. package/types/runtime/v1/context.d.ts +13 -2
@@ -5,7 +5,7 @@ import { entryTests } from "./entry.js";
5
5
  import HARNESS from "./harness-source.js";
6
6
  export { conformancePage } from "./page.js";
7
7
  import { leakTests } from "./probes.js";
8
- import { servedTests } from "./served.js";
8
+ import { servedTests, TAB_CASES, } from "./served.js";
9
9
  const CANARY = "https://porthole-canary.example";
10
10
  /** A page on no one's origin that frames what a case asks (routed by the test, like the canary). */
11
11
  const FOREIGN = "http://porthole-foreign.example";
@@ -112,6 +112,7 @@ export function hostConformance(options) {
112
112
  return request;
113
113
  },
114
114
  calls: () => invoke(page, "calls", id),
115
+ shown: () => invoke(page, "shown", id),
115
116
  errors: () => invoke(page, "errors", id),
116
117
  events: () => invoke(page, "events", id),
117
118
  destroy: () => invoke(page, "destroy", id),
@@ -282,6 +283,7 @@ const URL_CASES = [
282
283
  "served.url.ticket",
283
284
  "served.url.tab",
284
285
  "served.url.framed",
286
+ "served.url.siblings",
285
287
  ];
286
288
  const PROXY_CASES = ["served.proxy.view", "served.proxy.parent-only", "served.proxy.egress"];
287
289
  const DOMAIN_CASES = [
@@ -292,6 +294,8 @@ const DOMAIN_CASES = [
292
294
  "served.domain.address",
293
295
  "served.domain.storage-scope",
294
296
  "served.domain.ticket-once",
297
+ "served.domain.self-navigation",
298
+ ...TAB_CASES,
295
299
  "served.domain.frame-ancestors",
296
300
  "served.domain.egress",
297
301
  ];
@@ -48,6 +48,11 @@ export interface LaunchSpec {
48
48
  };
49
49
  /** Whether the host has a `confirm` function (default true): without one, gated calls are refused. */
50
50
  readonly confirms?: boolean;
51
+ /**
52
+ * Whether the host has a `show` function (default true, P100): without one, `show`-gated calls
53
+ * (a model context update, by default) are refused.
54
+ */
55
+ readonly shows?: boolean;
51
56
  }
52
57
  export interface RecordedCall {
53
58
  readonly capability: CapabilityName;
@@ -78,6 +83,11 @@ export interface LaunchedDisplay {
78
83
  }): Promise<ConfirmRequest>;
79
84
  /** The calls that reached the host's handlers, in order. */
80
85
  calls(): Promise<readonly RecordedCall[]>;
86
+ /**
87
+ * What the host showed the person for `show`-gated calls (P100: each model context update), in
88
+ * order. A host whose harness doesn't say has `12.model-context` reported inapplicable.
89
+ */
90
+ shown?(): Promise<readonly ConfirmRequest[]>;
81
91
  /** The errors the display reported. */
82
92
  errors(): Promise<readonly string[]>;
83
93
  /** Every event the display emitted, in order. */
@@ -118,6 +118,43 @@ export const LIMIT_PROBES = [
118
118
  expect(await quiet.errors()).toEqual([]);
119
119
  },
120
120
  },
121
+ {
122
+ id: "14.error-shapes",
123
+ item: 14,
124
+ title: "what content logs as an error reaches the host as bounded text in any shape structured clone carries: a cycle, a BigInt, a shared graph (S05)",
125
+ async run(context) {
126
+ // A graph of 20 objects each holding the next twice: 2^20 leaves written as a tree.
127
+ const logs = `<script>
128
+ (() => {
129
+ const say = (data) => parent.postMessage({ jsonrpc: "2.0", method: "notifications/message", params: { level: "error", data } }, "*");
130
+ const cycle = { name: "porthole-cycle" };
131
+ cycle.self = cycle;
132
+ let graph = "leaf";
133
+ for (let i = 0; i < 20; i += 1) graph = { a: graph, b: graph };
134
+ say(cycle);
135
+ say({ big: 5n });
136
+ say(graph);
137
+ say("porthole-after");
138
+ })();
139
+ </script>`;
140
+ const page = `<!doctype html><html><head><title>View</title></head><body><p>x</p>${logs}</body></html>`;
141
+ for (const display of [
142
+ await context.launch({ config: inline(), content: `<p>x</p>${logs}` }),
143
+ await context.launch({ config: presets.mcpApp(), content: "", document: page }),
144
+ ]) {
145
+ await expect
146
+ .poll(async () => (await display.errors()).includes("porthole-after"))
147
+ .toBe(true);
148
+ const errors = await display.errors();
149
+ expect(errors).toContain('{"name":"porthole-cycle","self":"[Circular]"}');
150
+ expect(errors).toContain('{"big":"5n"}');
151
+ const graph = errors.find((each) => each.startsWith('{"a":{"a":'));
152
+ expect(graph, "the shared graph, reported").toBeDefined();
153
+ expect(graph).toContain('"b":"[Repeated]"');
154
+ expect(graph?.length).toBeLessThanOrEqual(2_000);
155
+ }
156
+ },
157
+ },
121
158
  {
122
159
  id: "14.silent",
123
160
  item: 14,
@@ -523,7 +560,7 @@ export const LIMIT_PROBES = [
523
560
  export const LIMIT_CHECKS = {
524
561
  layout: ["11.size", "14.fill"],
525
562
  theme: ["11.theme-flip", "11.document-theme", "14.theme-never"],
526
- errors: ["14.errors"],
563
+ errors: ["14.errors", "14.error-shapes"],
527
564
  silent: ["14.silent"],
528
565
  network: ["1.connect", "2.resources"],
529
566
  "inline-assets": ["14.inline-assets"],
@@ -44,6 +44,7 @@ export function defineRuntimeConformance(options) {
44
44
  // Gates the person answers are the app's UI: a yes here, so the services are what's tested.
45
45
  confirm: () => Promise.resolve(true),
46
46
  consent: () => true,
47
+ show: () => { },
47
48
  userActivation: () => true,
48
49
  onEvent: () => { },
49
50
  });
@@ -208,6 +209,15 @@ export function defineRuntimeConformance(options) {
208
209
  expect(!view.ok, "a view-only person writes nothing, even past the bridge");
209
210
  ok(await as(handlers, viewers.admin)("db", { op: "set", path: "config/main", data: {} }), "an admin writes it");
210
211
  });
212
+ // P093: a store that folds case keeps `Config/main` where `config/main` is.
213
+ add("db: a rule holds for its collection in any case, at the bridge and in the app", async (handlers) => {
214
+ for (const path of ["Config/main", "CONFIG/main"]) {
215
+ expect(codeOf(await as(handlers, viewers.interact)("db", { op: "set", path, data: {} })) ===
216
+ "forbidden", `the rule for config holds at the bridge for ${path}`);
217
+ const past = await direct(handlers, "db", { op: "set", path, data: {} }, viewers.interact);
218
+ expect(!past.ok, `the app's handler holds the rule for config for ${path} itself`);
219
+ }
220
+ });
211
221
  }
212
222
  if (config.capabilities.artifact !== undefined) {
213
223
  add("artifact: get answers the current version; a publish from it makes the next", async (handlers) => {
@@ -72,6 +72,8 @@ export interface ServedSuiteOptions {
72
72
  /** Case ids to skip, each with the reason (shown in the report). */
73
73
  readonly skip?: Readonly<Record<string, string>>;
74
74
  }
75
+ /** The cases of a served page on a tab of its own (P099), one per wall. */
76
+ export declare const TAB_CASES: readonly string[];
75
77
  /** Registers every served-mode case as a test. */
76
78
  /**
77
79
  * Registers every served-mode case as a test. A host that wants to select them by its own spec