@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
@@ -271,8 +271,6 @@ export const SHELL_RUNTIME = String.raw `(() => {
271
271
  // takes the next load for that page, not for content that left). Anything else stays stopped:
272
272
  // another path of the origin, a file that isn't a page, another origin.
273
273
  let navigating = (_url) => {};
274
- // A nested page's files' address renewed by its shell (P111), which the shell's message gives.
275
- let adoptFiles = (_base) => false;
276
274
  let filesBase = plan.files && typeof plan.files.base === "string" ? plan.files.base : null;
277
275
  // Every address the page's files had (P083: a sealed one is renewed): what reports say as "./".
278
276
  const filesBases = filesBase === null ? [] : [filesBase];
@@ -926,14 +924,9 @@ export const SHELL_RUNTIME = String.raw `(() => {
926
924
  const noRewrite = function () {
927
925
  throw new Error("document.open and document.write aren't available here: build the page with DOM methods");
928
926
  };
929
- const unfixedBeforeRewrite = unfixed.length;
930
927
  for (const name of ["open", "write", "writeln"]) {
931
928
  lock(Document.prototype, name, noRewrite);
932
929
  }
933
- // Whether all three are fixed in place. The press port rests on it (P148): document.open() takes
934
- // every listener off the window, the runtime's among them, and a document opened and closed
935
- // again loads again, so content that could call it would hear a port before the runtime did.
936
- const rewriteFixed = unfixed.length === unfixedBeforeRewrite;
937
930
 
938
931
  // Some engines act on a hint the moment its element is connected or changed (WebKit opens a
939
932
  // preconnect then, outside the CSP), before the observer's microtask. So every way to connect a
@@ -1397,254 +1390,6 @@ export const SHELL_RUNTIME = String.raw `(() => {
1397
1390
  ]);
1398
1391
  }
1399
1392
 
1400
- // A nested page's real presses, told to its shell (P148). The shell sees a press in the page only
1401
- // as its own activation turning on, and a press within 5 s of the last gesture turns nothing on
1402
- // (P111): to the host that reads as a button that does nothing. So the runtime, which runs before
1403
- // any content and hears the browser's own events first, tells the shell each one, over a
1404
- // MessagePort the shell sends at each load of the page's frame. What keeps that the runtime's
1405
- // word and never the content's:
1406
- // - the port: taken here, by the first listener there is (on window, capturing), from the first
1407
- // message that is the browser's own (isTrusted), from the parent read now, that names the
1408
- // method and carries exactly one port. The event goes no further. Every other event of that
1409
- // name is stopped too, so content never hears one, and one that fails a check doesn't use up
1410
- // the one port. The port is in this closure alone: no content holds it or can post on it. No
1411
- // second port is taken: the shell's next one (it sends one at every load of the frame, and
1412
- // WebKit fires a load for a navigation within the document) is answered on the first, that
1413
- // this document is still here;
1414
- // - the press: only the browser's own events (isTrusted), read through the platform's getters
1415
- // kept now. A mouse on its way down; a finger or a pen on its way up (one that scrolls ends in
1416
- // pointercancel: HTML's own rule for what activates); Enter or Space, not held down, on a
1417
- // native control that isn't editable (a link takes Enter alone), by its tag and type, never
1418
- // its role, which is the content's word; a click on such a control (an assistive technology's
1419
- // activation is a click alone), but not the click a form gives its submit button when Enter is
1420
- // pressed in another of its fields, which is typing, nor any click while a key is down;
1421
- // - what is told: nothing but that there was one. No place, no target, no time.
1422
- // After a press is told, what the page's calls say to its host (send, below) waits for the
1423
- // shell's word that it has the press (it tells the host before it answers), so a call made in
1424
- // the press's own handler never arrives ahead of it; a shell that doesn't answer in 250 ms
1425
- // holds nothing back.
1426
- // None of it is installed unless all of it can be (a built-in missing, or document.open, write
1427
- // or writeln not fixed in place above): the page then tells no press, and the host has the
1428
- // shell's activation alone, as before.
1429
- let pressHeld = null;
1430
- const pressParent = window.parent;
1431
- if (plan.press === true && !hostless && pressParent !== window && rewriteFixed) {
1432
- const messageProto = typeof MessageEvent === "function" ? MessageEvent.prototype : null;
1433
- const messageSourceOf = getterOf(messageProto, "source");
1434
- const messageDataOf = getterOf(messageProto, "data");
1435
- const messagePortsOf = getterOf(messageProto, "ports");
1436
- const stopNow = Event.prototype.stopImmediatePropagation;
1437
- const portProto = typeof MessagePort === "function" ? MessagePort.prototype : null;
1438
- const portPost = portProto === null ? null : portProto.postMessage;
1439
- const portStart = portProto === null ? null : portProto.start;
1440
- const eventTargetOf = getterOf(Event.prototype, "target");
1441
- const pointerTypeOf = getterOf(typeof PointerEvent === "function" ? PointerEvent.prototype : null, "pointerType");
1442
- const keyProto = typeof KeyboardEvent === "function" ? KeyboardEvent.prototype : null;
1443
- const keyOf = getterOf(keyProto, "key");
1444
- const repeatOf = getterOf(keyProto, "repeat");
1445
- const editableOf = getterOf(HTMLElement.prototype, "isContentEditable");
1446
- const designModeOf = getterOf(Document.prototype, "designMode");
1447
- const activeOf = getterOf(Document.prototype, "activeElement");
1448
- const controlTypeOf = getterOf(HTMLInputElement.prototype, "type");
1449
- // Each control's form through its own getter: a field tied to a form by its form attribute is
1450
- // not inside that form's element.
1451
- const formGetters = bare(null);
1452
- formGetters.button = getterOf(HTMLButtonElement.prototype, "form");
1453
- formGetters.input = getterOf(HTMLInputElement.prototype, "form");
1454
- formGetters.select = getterOf(HTMLSelectElement.prototype, "form");
1455
- formGetters.textarea = getterOf(HTMLTextAreaElement.prototype, "form");
1456
- const pressLater = setTimeout;
1457
- const pressNoLater = clearTimeout;
1458
- const pressListen = EventTarget.prototype.addEventListener;
1459
- const all =
1460
- messageSourceOf !== null && messageDataOf !== null && messagePortsOf !== null &&
1461
- typeof stopNow === "function" && typeof portPost === "function" && typeof portStart === "function" &&
1462
- eventTargetOf !== null && pointerTypeOf !== null && keyOf !== null && repeatOf !== null &&
1463
- editableOf !== null && designModeOf !== null && activeOf !== null && controlTypeOf !== null &&
1464
- formGetters.button !== null && formGetters.input !== null && formGetters.select !== null && formGetters.textarea !== null &&
1465
- localNameOf !== null && namespaceOf !== null && nodeTypeOf !== null;
1466
- if (all) {
1467
- let port = null;
1468
- // How many presses the shell hasn't answered yet, and the timer that stops waiting for it.
1469
- let unanswered = 0;
1470
- let giveUp = 0;
1471
- const release = () => {
1472
- unanswered = 0;
1473
- callOf(pressNoLater, window, [giveUp]);
1474
- const held = pressHeld;
1475
- pressHeld = null;
1476
- if (held !== null) {
1477
- for (let i = 0; i < held.length; i += 1) {
1478
- post(held[i]);
1479
- }
1480
- }
1481
- };
1482
- const tellPress = () => {
1483
- if (port === null) {
1484
- return;
1485
- }
1486
- try {
1487
- callOf(portPost, port, [0]);
1488
- } catch (_) {
1489
- return;
1490
- }
1491
- unanswered += 1;
1492
- if (pressHeld === null) {
1493
- pressHeld = [];
1494
- }
1495
- callOf(pressNoLater, window, [giveUp]);
1496
- giveUp = callOf(pressLater, window, [release, 250]);
1497
- };
1498
- callOf(pressListen, window, [
1499
- "message",
1500
- (event) => {
1501
- let named = false;
1502
- try {
1503
- const data = callOf(messageDataOf, event, []);
1504
- named = data !== null && typeof data === "object" && data.method === "porthole/shell/press-port";
1505
- } catch (_) {}
1506
- if (!named) {
1507
- return;
1508
- }
1509
- callOf(stopNow, event, []);
1510
- if (event.isTrusted !== true) {
1511
- return;
1512
- }
1513
- try {
1514
- const ports = callOf(messagePortsOf, event, []);
1515
- if (callOf(messageSourceOf, event, []) !== pressParent || ports === null || ports.length !== 1) {
1516
- return;
1517
- }
1518
- // Only the first is ever taken. A later one is the shell's for a load that left this
1519
- // document where it was (WebKit's, for a navigation within it, P142): told, on the
1520
- // port held, that this document is still here, so the shell goes on hearing that one.
1521
- if (port !== null) {
1522
- callOf(portPost, port, [1]);
1523
- return;
1524
- }
1525
- const taken = ports[0];
1526
- // The shell's answer to a press: it has it, and has told the host.
1527
- callOf(pressListen, taken, [
1528
- "message",
1529
- () => {
1530
- unanswered -= 1;
1531
- if (unanswered <= 0) {
1532
- release();
1533
- }
1534
- },
1535
- ]);
1536
- callOf(portStart, taken, []);
1537
- port = taken;
1538
- } catch (_) {}
1539
- },
1540
- true,
1541
- ]);
1542
- // A native control a key or a click presses: "both" (Enter and Space), "enter" (a link), or
1543
- // "" for anything else, an editable one included. By the kept getters: the tag and the type,
1544
- // never an attribute the content writes to say what it is.
1545
- const controlOf = (node) => {
1546
- if (typeOf(node) !== 1 || callOf(namespaceOf, node, []) !== XHTML) {
1547
- return "";
1548
- }
1549
- const name = callOf(localNameOf, node, []);
1550
- let kind = "";
1551
- if (name === "button" || name === "summary") {
1552
- kind = "both";
1553
- } else if (name === "input") {
1554
- const type = callOf(controlTypeOf, node, []);
1555
- kind = type === "button" || type === "submit" || type === "reset" ? "both" : "";
1556
- } else if (name === "a") {
1557
- kind = callOf(hasAttributeIn, node, ["href"]) === true ? "enter" : "";
1558
- }
1559
- return kind !== "" && callOf(editableOf, node, []) !== true ? kind : "";
1560
- };
1561
- const formOf = (node) => {
1562
- if (typeOf(node) !== 1 || callOf(namespaceOf, node, []) !== XHTML) {
1563
- return null;
1564
- }
1565
- const getter = formGetters[callOf(localNameOf, node, [])];
1566
- return typeof getter === "function" ? callOf(getter, node, []) : null;
1567
- };
1568
- // The browser's own event: nothing a page dispatches is a press.
1569
- const real = (event) => event.isTrusted === true;
1570
- // Whether a key is down: from the browser's own keydown to its keyup, or the next press of
1571
- // a pointer. No click in that time is a press. The key's own press was judged as it went
1572
- // down, where it went down: content that moves the focus to its button inside the keydown
1573
- // of an Enter typed in a text field gets that button a click of the browser's own, and a
1574
- // held key's repeats give a button one each. An assistive technology's click comes with no
1575
- // key down.
1576
- let keyDown = false;
1577
- const pointed = (down) => (event) => {
1578
- if (!real(event)) {
1579
- return;
1580
- }
1581
- keyDown = false;
1582
- try {
1583
- if ((callOf(pointerTypeOf, event, []) === "mouse") === down) {
1584
- tellPress();
1585
- }
1586
- } catch (_) {}
1587
- };
1588
- callOf(pressListen, window, ["pointerdown", pointed(true), true]);
1589
- callOf(pressListen, window, ["pointerup", pointed(false), true]);
1590
- callOf(pressListen, window, [
1591
- "keyup",
1592
- (event) => {
1593
- if (real(event)) {
1594
- keyDown = false;
1595
- }
1596
- },
1597
- true,
1598
- ]);
1599
- callOf(pressListen, window, [
1600
- "keydown",
1601
- (event) => {
1602
- if (!real(event)) {
1603
- return;
1604
- }
1605
- keyDown = true;
1606
- try {
1607
- // A key held down goes on being the key it was when it went down, wherever the focus
1608
- // has moved since: its repeats are no press.
1609
- const key = callOf(keyOf, event, []);
1610
- if ((key !== "Enter" && key !== " ") || callOf(repeatOf, event, []) === true || callOf(designModeOf, document, []) === "on") {
1611
- return;
1612
- }
1613
- const kind = controlOf(callOf(eventTargetOf, event, []));
1614
- if (kind === "both" || (kind === "enter" && key === "Enter")) {
1615
- tellPress();
1616
- }
1617
- } catch (_) {}
1618
- },
1619
- true,
1620
- ]);
1621
- callOf(pressListen, window, [
1622
- "click",
1623
- (event) => {
1624
- if (!real(event)) {
1625
- return;
1626
- }
1627
- try {
1628
- const target = callOf(eventTargetOf, event, []);
1629
- if (keyDown || controlOf(target) === "") {
1630
- return;
1631
- }
1632
- // A form's own click on its submit button, for Enter in another of its fields.
1633
- const active = callOf(activeOf, document, []);
1634
- if (active !== null && active !== target) {
1635
- const form = formOf(target);
1636
- if (form !== null && form === formOf(active)) {
1637
- return;
1638
- }
1639
- }
1640
- tellPress();
1641
- } catch (_) {}
1642
- },
1643
- true,
1644
- ]);
1645
- }
1646
- }
1647
-
1648
1393
  // The clipboard is the host's to write (P051): content can neither write nor read it. A copy
1649
1394
  // the person makes (their keys, their menu) copies their selection as the browser makes it: no
1650
1395
  // copy or cut listener of the content's runs, so none can swap what goes on the clipboard.
@@ -1863,14 +1608,8 @@ export const SHELL_RUNTIME = String.raw `(() => {
1863
1608
  window.parent.postMessage(Object.assign({ jsonrpc: "2.0" }, message), "*");
1864
1609
  }
1865
1610
  };
1866
- // After a press was told to the shell (P148), what the shell's protocol says next (a call, an
1867
- // answer) waits for the shell to have the press: posted by the release above, through post.
1868
1611
  const send = (message) => {
1869
1612
  if (plan.protocol === "shell") {
1870
- if (pressHeld !== null) {
1871
- pressHeld[pressHeld.length] = message;
1872
- return;
1873
- }
1874
1613
  post(message);
1875
1614
  }
1876
1615
  };
@@ -1911,7 +1650,7 @@ export const SHELL_RUNTIME = String.raw `(() => {
1911
1650
  // modules keep the address they loaded from; the server serves their own loads till the session
1912
1651
  // ends.
1913
1652
  const replace = History.prototype.replaceState;
1914
- // The files' origin, read from the address itself: a nested page's own origin is opaque (P111).
1653
+ // The files' origin, read from the address itself.
1915
1654
  const filesOrigin = filesBase === null ? null : new NativeURL(filesBase).origin;
1916
1655
  // A renewed sealed address (P083): one segment under the same origin's sealed prefix, checked
1917
1656
  // through the platform's own functions (content may have replaced a prototype's, and the base
@@ -1931,7 +1670,6 @@ export const SHELL_RUNTIME = String.raw `(() => {
1931
1670
  filesBases.push(base);
1932
1671
  return true;
1933
1672
  };
1934
- adoptFiles = adopt;
1935
1673
  if (filesBase !== null && typeof plan.files.expires === "number") {
1936
1674
  const nativeFetch = window.fetch.bind(window);
1937
1675
  const renewIn = (expires) => Math.max(30000, expires - Date.now() - 300000);
@@ -2501,11 +2239,6 @@ export const SHELL_RUNTIME = String.raw `(() => {
2501
2239
  case "ui/notifications/tool-input":
2502
2240
  void render(params.arguments);
2503
2241
  break;
2504
- case "porthole/files-renewed":
2505
- // From the page's parent only (the listener's check): a nested page's shell renewed its
2506
- // files' sealed address, which this page can't (its loads aren't its origin's own, P111).
2507
- adoptFiles(params.base);
2508
- break;
2509
2242
  case "ui/notifications/host-context-changed":
2510
2243
  applyTheme(params);
2511
2244
  break;