@mostra/runtime 0.10.0 → 0.12.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 (257) hide show
  1. package/dist/bin.js +4178 -310
  2. package/dist/bin.js.map +1 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/{instance-FExcyENK.js → instance-CBUlOmzG.js} +1892 -85
  6. package/dist/instance-CBUlOmzG.js.map +1 -0
  7. package/dist/reference/cli.md +1432 -0
  8. package/dist/reference/diagnostics.json +1579 -0
  9. package/dist/reference/errors/MOSTRA_A11Y_MINOR.md +23 -0
  10. package/dist/reference/errors/MOSTRA_A11Y_SERIOUS.md +23 -0
  11. package/dist/reference/errors/MOSTRA_ACTION_CANCELLED.md +23 -0
  12. package/dist/reference/errors/MOSTRA_ACTION_EVENT_INVALID.md +23 -0
  13. package/dist/reference/errors/MOSTRA_ACTION_EXPORT_INVALID.md +23 -0
  14. package/dist/reference/errors/MOSTRA_ACTION_INTERRUPTED.md +23 -0
  15. package/dist/reference/errors/MOSTRA_ACTION_PAUSED.md +23 -0
  16. package/dist/reference/errors/MOSTRA_ACTION_RUN_NOT_FOUND.md +23 -0
  17. package/dist/reference/errors/MOSTRA_ACTION_THREW.md +23 -0
  18. package/dist/reference/errors/MOSTRA_ACTION_TOO_LARGE.md +23 -0
  19. package/dist/reference/errors/MOSTRA_ACTION_UNKNOWN_FUNCTION.md +23 -0
  20. package/dist/reference/errors/MOSTRA_ACTION_UNSERIALIZABLE.md +23 -0
  21. package/dist/reference/errors/MOSTRA_ARTIFACT_BUNDLE_INVALID.md +23 -0
  22. package/dist/reference/errors/MOSTRA_ARTIFACT_DIR_NOT_EMPTY.md +23 -0
  23. package/dist/reference/errors/MOSTRA_ARTIFACT_ENTRY_AMBIGUOUS.md +23 -0
  24. package/dist/reference/errors/MOSTRA_ARTIFACT_ID_DROPPED.md +23 -0
  25. package/dist/reference/errors/MOSTRA_ARTIFACT_NOT_FOUND.md +23 -0
  26. package/dist/reference/errors/MOSTRA_ARTIFACT_NO_ENTRY.md +23 -0
  27. package/dist/reference/errors/MOSTRA_ARTIFACT_NO_PAGE.md +23 -0
  28. package/dist/reference/errors/MOSTRA_ARTIFACT_PATCH_REJECTED.md +23 -0
  29. package/dist/reference/errors/MOSTRA_ARTIFACT_PATH_INVALID.md +23 -0
  30. package/dist/reference/errors/MOSTRA_ARTIFACT_SOURCE_MISSING.md +23 -0
  31. package/dist/reference/errors/MOSTRA_ARTIFACT_SOURCE_UNREADABLE.md +23 -0
  32. package/dist/reference/errors/MOSTRA_ARTIFACT_TEMPLATE_UNKNOWN.md +23 -0
  33. package/dist/reference/errors/MOSTRA_ARTIFACT_VERSION_COLLECTED.md +23 -0
  34. package/dist/reference/errors/MOSTRA_ARTIFACT_VERSION_NOT_FOUND.md +23 -0
  35. package/dist/reference/errors/MOSTRA_BUILD_CRASHED.md +23 -0
  36. package/dist/reference/errors/MOSTRA_BUILD_FAILED.md +23 -0
  37. package/dist/reference/errors/MOSTRA_BUILD_TIMEOUT.md +23 -0
  38. package/dist/reference/errors/MOSTRA_BUILD_UNRESOLVED.md +23 -0
  39. package/dist/reference/errors/MOSTRA_CLI_CONFIG_UNWRITABLE.md +23 -0
  40. package/dist/reference/errors/MOSTRA_CLI_UNKNOWN_COMMAND.md +23 -0
  41. package/dist/reference/errors/MOSTRA_CLI_USAGE.md +23 -0
  42. package/dist/reference/errors/MOSTRA_CONSOLE_ERROR.md +23 -0
  43. package/dist/reference/errors/MOSTRA_CONSOLE_WARNING.md +23 -0
  44. package/dist/reference/errors/MOSTRA_DEP_INSTALL_FAILED.md +23 -0
  45. package/dist/reference/errors/MOSTRA_DEP_MISSING.md +23 -0
  46. package/dist/reference/errors/MOSTRA_DEP_NOT_FOUND.md +23 -0
  47. package/dist/reference/errors/MOSTRA_DEP_OFFLINE.md +23 -0
  48. package/dist/reference/errors/MOSTRA_DEP_SPEC_INVALID.md +23 -0
  49. package/dist/reference/errors/MOSTRA_DEP_TIMEOUT.md +23 -0
  50. package/dist/reference/errors/MOSTRA_DEP_WARM_CONFLICT.md +23 -0
  51. package/dist/reference/errors/MOSTRA_ENV_BIND_FAILED.md +23 -0
  52. package/dist/reference/errors/MOSTRA_ENV_BROWSER_MISSING.md +23 -0
  53. package/dist/reference/errors/MOSTRA_ENV_BUNDLE_DOWNLOAD_FAILED.md +23 -0
  54. package/dist/reference/errors/MOSTRA_ENV_BUNDLE_INVALID.md +23 -0
  55. package/dist/reference/errors/MOSTRA_ENV_BUNDLE_UNAVAILABLE.md +23 -0
  56. package/dist/reference/errors/MOSTRA_ENV_HELPER_MISSING.md +23 -0
  57. package/dist/reference/errors/MOSTRA_ENV_NODE_UNSUPPORTED.md +23 -0
  58. package/dist/reference/errors/MOSTRA_ENV_PORT_TAKEN.md +23 -0
  59. package/dist/reference/errors/MOSTRA_ENV_RUNTIME_INSTALLING.md +23 -0
  60. package/dist/reference/errors/MOSTRA_ENV_RUNTIME_MISSING.md +23 -0
  61. package/dist/reference/errors/MOSTRA_ENV_SERVICE_FAILED.md +23 -0
  62. package/dist/reference/errors/MOSTRA_ENV_SHELL_MISSING.md +23 -0
  63. package/dist/reference/errors/MOSTRA_ENV_WARM_MISSING.md +23 -0
  64. package/dist/reference/errors/MOSTRA_FIELD_CONFLICT.md +23 -0
  65. package/dist/reference/errors/MOSTRA_FIELD_DUPLICATE_ID.md +23 -0
  66. package/dist/reference/errors/MOSTRA_FIELD_ID_INVALID.md +23 -0
  67. package/dist/reference/errors/MOSTRA_FIELD_ID_UNSTABLE.md +23 -0
  68. package/dist/reference/errors/MOSTRA_FIELD_MUTATION_ID_REUSED.md +23 -0
  69. package/dist/reference/errors/MOSTRA_FIELD_SHARED.md +23 -0
  70. package/dist/reference/errors/MOSTRA_FIELD_TOO_LARGE.md +23 -0
  71. package/dist/reference/errors/MOSTRA_FIELD_UNBOUND.md +23 -0
  72. package/dist/reference/errors/MOSTRA_HOME_DISK_FULL.md +23 -0
  73. package/dist/reference/errors/MOSTRA_HOME_GC_INCOMPLETE.md +23 -0
  74. package/dist/reference/errors/MOSTRA_HOME_GONE.md +23 -0
  75. package/dist/reference/errors/MOSTRA_HOME_INTEGRITY.md +23 -0
  76. package/dist/reference/errors/MOSTRA_HOME_LEDGER_UNREADABLE.md +23 -0
  77. package/dist/reference/errors/MOSTRA_HOME_LOCKED.md +23 -0
  78. package/dist/reference/errors/MOSTRA_HOME_MISMATCH.md +23 -0
  79. package/dist/reference/errors/MOSTRA_HOME_NETWORK_FILESYSTEM.md +23 -0
  80. package/dist/reference/errors/MOSTRA_HOME_NOT_ALWAYS_ON.md +23 -0
  81. package/dist/reference/errors/MOSTRA_HOME_NOT_OWNED.md +23 -0
  82. package/dist/reference/errors/MOSTRA_HOME_SOCKET_TOO_LONG.md +23 -0
  83. package/dist/reference/errors/MOSTRA_HOME_TOO_NEW.md +23 -0
  84. package/dist/reference/errors/MOSTRA_HOST_CONNECTION_CLOSED.md +23 -0
  85. package/dist/reference/errors/MOSTRA_HOST_CURSOR_COMPACTED.md +23 -0
  86. package/dist/reference/errors/MOSTRA_HOST_IDENTITY_UNAVAILABLE.md +23 -0
  87. package/dist/reference/errors/MOSTRA_HOST_INITIALIZE_ORDER.md +23 -0
  88. package/dist/reference/errors/MOSTRA_HOST_INTERNAL_ERROR.md +23 -0
  89. package/dist/reference/errors/MOSTRA_HOST_INVALID_PARAMS.md +23 -0
  90. package/dist/reference/errors/MOSTRA_HOST_MALFORMED.md +23 -0
  91. package/dist/reference/errors/MOSTRA_HOST_MESSAGE_TOO_LARGE.md +23 -0
  92. package/dist/reference/errors/MOSTRA_HOST_METHOD_UNKNOWN.md +23 -0
  93. package/dist/reference/errors/MOSTRA_HOST_NOTIFICATION_UNSUPPORTED.md +23 -0
  94. package/dist/reference/errors/MOSTRA_HOST_PORT_UNSUPPORTED.md +23 -0
  95. package/dist/reference/errors/MOSTRA_HOST_REQUEST_ID_REUSED.md +23 -0
  96. package/dist/reference/errors/MOSTRA_HOST_REVISION_UNSUPPORTED.md +23 -0
  97. package/dist/reference/errors/MOSTRA_HOST_SHUTDOWN_REFUSED.md +23 -0
  98. package/dist/reference/errors/MOSTRA_HOST_SUBSCRIPTION_UNKNOWN.md +23 -0
  99. package/dist/reference/errors/MOSTRA_HOST_TIMEOUT.md +23 -0
  100. package/dist/reference/errors/MOSTRA_HYGIENE_CONTENT_TYPE.md +23 -0
  101. package/dist/reference/errors/MOSTRA_HYGIENE_CSRF_MISSING.md +23 -0
  102. package/dist/reference/errors/MOSTRA_HYGIENE_FRAME_SESSION.md +23 -0
  103. package/dist/reference/errors/MOSTRA_HYGIENE_HEADERS_TOO_LARGE.md +23 -0
  104. package/dist/reference/errors/MOSTRA_HYGIENE_HOST_REFUSED.md +23 -0
  105. package/dist/reference/errors/MOSTRA_HYGIENE_NOT_SERVED.md +23 -0
  106. package/dist/reference/errors/MOSTRA_HYGIENE_ORIGIN_REFUSED.md +23 -0
  107. package/dist/reference/errors/MOSTRA_HYGIENE_RATE_LIMITED.md +23 -0
  108. package/dist/reference/errors/MOSTRA_HYGIENE_REQUEST_MALFORMED.md +23 -0
  109. package/dist/reference/errors/MOSTRA_HYGIENE_SCOPE_DENIED.md +23 -0
  110. package/dist/reference/errors/MOSTRA_HYGIENE_SESSION_CONFLICT.md +23 -0
  111. package/dist/reference/errors/MOSTRA_HYGIENE_SESSION_MISSING.md +23 -0
  112. package/dist/reference/errors/MOSTRA_HYGIENE_TOKEN_INVALID.md +23 -0
  113. package/dist/reference/errors/MOSTRA_HYGIENE_TOKEN_REVOKED.md +23 -0
  114. package/dist/reference/errors/MOSTRA_LIVE_SOURCE_FAILED.md +23 -0
  115. package/dist/reference/errors/MOSTRA_LIVE_TOO_LARGE.md +23 -0
  116. package/dist/reference/errors/MOSTRA_MANIFEST_INVALID.md +23 -0
  117. package/dist/reference/errors/MOSTRA_MANIFEST_NOT_LITERAL.md +23 -0
  118. package/dist/reference/errors/MOSTRA_MANIFEST_UNKNOWN_KEY.md +23 -0
  119. package/dist/reference/errors/MOSTRA_NETWORK_EXTERNAL_FAILED.md +23 -0
  120. package/dist/reference/errors/MOSTRA_NETWORK_REQUEST_FAILED.md +23 -0
  121. package/dist/reference/errors/MOSTRA_PLATFORM_UNSUPPORTED.md +23 -0
  122. package/dist/reference/errors/MOSTRA_PUBLISH_ID_CONFLICT.md +23 -0
  123. package/dist/reference/errors/MOSTRA_PUBLISH_SOURCE_CHANGED.md +23 -0
  124. package/dist/reference/errors/MOSTRA_PUBLISH_VERIFY_FAILED.md +23 -0
  125. package/dist/reference/errors/MOSTRA_REGRESSION_ACTION_REMOVED.md +23 -0
  126. package/dist/reference/errors/MOSTRA_REGRESSION_ARIA.md +23 -0
  127. package/dist/reference/errors/MOSTRA_REGRESSION_FIELD_REMOVED.md +23 -0
  128. package/dist/reference/errors/MOSTRA_REGRESSION_LIVE_REMOVED.md +23 -0
  129. package/dist/reference/errors/MOSTRA_REGRESSION_PAGE_REMOVED.md +23 -0
  130. package/dist/reference/errors/MOSTRA_REGRESSION_PIXELS.md +23 -0
  131. package/dist/reference/errors/MOSTRA_REMOTE_CONFIG_INVALID.md +23 -0
  132. package/dist/reference/errors/MOSTRA_REMOTE_HOME_MOVING.md +23 -0
  133. package/dist/reference/errors/MOSTRA_REMOTE_HOME_SUSPENDED.md +23 -0
  134. package/dist/reference/errors/MOSTRA_REMOTE_LIMIT_REACHED.md +23 -0
  135. package/dist/reference/errors/MOSTRA_REMOTE_LOGIN_FAILED.md +23 -0
  136. package/dist/reference/errors/MOSTRA_REMOTE_NOT_OWNER_INSTANCE.md +23 -0
  137. package/dist/reference/errors/MOSTRA_REMOTE_NO_INSTANCE.md +23 -0
  138. package/dist/reference/errors/MOSTRA_REMOTE_OPERATOR_UNAVAILABLE.md +23 -0
  139. package/dist/reference/errors/MOSTRA_REMOTE_OWNER_OFFLINE.md +23 -0
  140. package/dist/reference/errors/MOSTRA_REMOTE_PAUSED_BY_OPERATOR.md +23 -0
  141. package/dist/reference/errors/MOSTRA_REMOTE_QUEUE_FULL.md +23 -0
  142. package/dist/reference/errors/MOSTRA_REMOTE_RATE_LIMITED.md +23 -0
  143. package/dist/reference/errors/MOSTRA_REMOTE_SIGN_IN_REQUIRED.md +23 -0
  144. package/dist/reference/errors/MOSTRA_REMOTE_UNDER_REVIEW.md +23 -0
  145. package/dist/reference/errors/MOSTRA_REMOTE_UNREACHABLE.md +23 -0
  146. package/dist/reference/errors/MOSTRA_RUNTIME_BLANK.md +23 -0
  147. package/dist/reference/errors/MOSTRA_RUNTIME_NOT_READY.md +23 -0
  148. package/dist/reference/errors/MOSTRA_RUNTIME_PAGE_ERROR.md +23 -0
  149. package/dist/reference/errors/MOSTRA_RUNTIME_WORKER_CRASHED.md +23 -0
  150. package/dist/reference/errors/MOSTRA_RUNTIME_WORKER_PARKED.md +23 -0
  151. package/dist/reference/errors/MOSTRA_SECRET_MISSING.md +23 -0
  152. package/dist/reference/errors/MOSTRA_SHARE_NOT_ENABLED.md +23 -0
  153. package/dist/reference/errors/MOSTRA_SHARE_NOT_FOUND.md +23 -0
  154. package/dist/reference/errors/MOSTRA_SHARE_PORTS_EXHAUSTED.md +23 -0
  155. package/dist/reference/errors/MOSTRA_SHARE_TOOL_MISSING.md +23 -0
  156. package/dist/reference/errors/MOSTRA_SHARE_TOOL_NOT_READY.md +23 -0
  157. package/dist/reference/errors/MOSTRA_SHARE_TTL_INVALID.md +23 -0
  158. package/dist/reference/errors/MOSTRA_SHARE_TUNNEL_FAILED.md +23 -0
  159. package/dist/reference/errors/MOSTRA_SMOKE_BUDGET.md +23 -0
  160. package/dist/reference/errors/MOSTRA_SMOKE_NO_EFFECT.md +23 -0
  161. package/dist/reference/errors/MOSTRA_SUBMIT_ALREADY.md +23 -0
  162. package/dist/reference/errors/MOSTRA_SUBMIT_BLOCKED.md +23 -0
  163. package/dist/reference/errors/MOSTRA_SUBMIT_CHANNEL_DENIED.md +23 -0
  164. package/dist/reference/errors/MOSTRA_SUBMIT_NOT_FOUND.md +23 -0
  165. package/dist/reference/errors/MOSTRA_SUBMIT_PAUSED.md +23 -0
  166. package/dist/reference/errors/MOSTRA_SUBMIT_POLICY_NONE.md +23 -0
  167. package/dist/reference/errors/MOSTRA_SUBMIT_REVISION_MOVED.md +23 -0
  168. package/dist/reference/errors/MOSTRA_SUBMIT_SIGNAL_INVALID.md +23 -0
  169. package/dist/reference/errors/MOSTRA_SUBMIT_VIEW_INVALID.md +23 -0
  170. package/dist/reference/errors/MOSTRA_TARGET_UNAVAILABLE.md +23 -0
  171. package/dist/reference/errors/MOSTRA_TEAM_PRESENCE_RATE_LIMITED.md +23 -0
  172. package/dist/reference/errors/MOSTRA_TEAM_ROSTER_POLICY.md +23 -0
  173. package/dist/reference/errors/MOSTRA_TEAM_ROSTER_TOO_LARGE.md +23 -0
  174. package/dist/reference/errors/MOSTRA_TYPE_ERROR.md +23 -0
  175. package/dist/reference/errors/MOSTRA_TYPE_UNTYPED_PACKAGE.md +23 -0
  176. package/dist/reference/errors/MOSTRA_VERIFY_ACTION_SKIPPED.md +23 -0
  177. package/dist/reference/errors/MOSTRA_VERIFY_BASELINE_MISSING.md +23 -0
  178. package/dist/reference/errors/MOSTRA_VERIFY_CRASHED.md +23 -0
  179. package/dist/reference/errors/MOSTRA_VERIFY_LIVE_FAILED.md +23 -0
  180. package/dist/reference/errors/MOSTRA_VERIFY_NO_BASELINE.md +23 -0
  181. package/dist/reference/errors/MOSTRA_VERIFY_SECRET_MISSING.md +23 -0
  182. package/dist/reference/errors/MOSTRA_VERIFY_SKIP_CONSEQUENCE.md +23 -0
  183. package/dist/reference/errors/MOSTRA_VERIFY_TIMEOUT.md +23 -0
  184. package/dist/reference/self-hosting.md +130 -0
  185. package/dist/reference/telemetry.md +84 -0
  186. package/dist/skill/SKILL.md +124 -0
  187. package/dist/skill/assets/examples/dashboard/index.tsx +161 -0
  188. package/dist/skill/assets/examples/dashboard/live.ts +25 -0
  189. package/dist/skill/assets/examples/dashboard/styles.css +125 -0
  190. package/dist/skill/assets/examples/decision/index.tsx +95 -0
  191. package/dist/skill/assets/examples/decision/styles.css +125 -0
  192. package/dist/skill/assets/examples/inbox/actions.ts +23 -0
  193. package/dist/skill/assets/examples/inbox/index.tsx +109 -0
  194. package/dist/skill/assets/examples/inbox/styles.css +125 -0
  195. package/dist/skill/assets/studio.css +125 -0
  196. package/dist/skill/references/answers.md +219 -0
  197. package/dist/skill/references/design.md +154 -0
  198. package/dist/skill/references/libraries.md +167 -0
  199. package/dist/skill/references/long-lived.md +148 -0
  200. package/dist/skill/references/mcp.md +68 -0
  201. package/dist/skill/references/page.md +131 -0
  202. package/dist/skill/references/server.md +146 -0
  203. package/dist/skill/references/sharing.md +123 -0
  204. package/dist/skill/references/teams.md +78 -0
  205. package/dist/skill/references/verify.md +71 -0
  206. package/package.json +10 -5
  207. package/src/gateway/actions.ts +20 -0
  208. package/src/gateway/browser.ts +128 -1
  209. package/src/gateway/capabilities.ts +8 -0
  210. package/src/gateway/http.ts +12 -1
  211. package/src/gateway/index.ts +210 -6
  212. package/src/gateway/listener.ts +31 -6
  213. package/src/gateway/routes.ts +8 -0
  214. package/src/gateway/team.ts +181 -0
  215. package/src/gc/index.ts +5 -0
  216. package/src/instance/index.ts +22 -2
  217. package/src/interaction/ephemeral.ts +21 -0
  218. package/src/interaction/events.ts +17 -0
  219. package/src/interaction/index.ts +325 -20
  220. package/src/interaction/pause.ts +106 -0
  221. package/src/interaction/roster.ts +585 -0
  222. package/src/interaction/submissions.ts +42 -1
  223. package/src/interaction/team.ts +426 -0
  224. package/src/interaction/viewers.ts +34 -1
  225. package/src/interaction/wait.ts +150 -0
  226. package/src/ledger/index.ts +20 -1
  227. package/src/ledger/migrations.ts +86 -0
  228. package/src/link/author.ts +215 -0
  229. package/src/link/hosted.ts +51 -4
  230. package/src/link/http.ts +6 -1
  231. package/src/link/index.ts +3 -1
  232. package/src/link/manager.ts +169 -35
  233. package/src/protocol-server/client.ts +53 -0
  234. package/src/protocol-server/index.ts +1 -1
  235. package/src/server/api.ts +514 -72
  236. package/src/server/auth.ts +600 -74
  237. package/src/server/authorize.ts +816 -0
  238. package/src/server/clients.ts +235 -0
  239. package/src/server/config.ts +7 -0
  240. package/src/server/data.ts +59 -1
  241. package/src/server/directory.ts +91 -0
  242. package/src/server/feed.ts +277 -0
  243. package/src/server/handle.ts +172 -0
  244. package/src/server/hosted-pages.ts +532 -0
  245. package/src/server/hosted.ts +551 -18
  246. package/src/server/index.ts +353 -61
  247. package/src/server/mcp.ts +330 -0
  248. package/src/server/metering.ts +156 -0
  249. package/src/server/oauth-clients.ts +510 -0
  250. package/src/server/operator.ts +557 -0
  251. package/src/server/providers.ts +284 -0
  252. package/src/server/remove.ts +148 -0
  253. package/src/server/routing.ts +275 -0
  254. package/src/share/index.ts +50 -2
  255. package/src/verify/index.ts +7 -0
  256. package/src/verify/runner.ts +27 -2
  257. package/dist/instance-FExcyENK.js.map +0 -1
@@ -0,0 +1,275 @@
1
+ /**
2
+ * Where a request goes, by its exact `Host` (INTERFACES §18.4, D165 item 7, D167): the API origin;
3
+ * a configured user-content domain's apex, the hosted shell; a route's label under a configured
4
+ * domain, or under a domain an operator supplies, the route's frames; a host an operator supplies
5
+ * (`routing.resolve`), a hosted shell for one home or one route; and anything else, nothing (421).
6
+ *
7
+ * A host an operator supplies is recorded the first time it is served (`operator_host` and
8
+ * `label_issued`, kind `operator`), bound to its home forever: an answer that would move it to
9
+ * another home is refused and logged, so no origin, nor the browser storage it holds, passes to
10
+ * another tenant. The operator is asked again for a recorded host as its answer's cache allows,
11
+ * and a host it no longer answers for gets nothing; when it doesn't answer in time, the recorded
12
+ * binding is served, since views proceed without the operator (D165 item 9).
13
+ */
14
+ import type { RoutingAnswer } from "@mostra/protocol/operator";
15
+ import type { Ledger } from "../ledger/index.ts";
16
+ import type { Log } from "../log.ts";
17
+ import type { Operator } from "./operator.ts";
18
+
19
+ /** The server's own labels: 26 lower-case Crockford base32 characters (§18.4). */
20
+ export const SERVER_LABEL: RegExp = /^[0-9a-hjkmnp-tv-z]{26}$/;
21
+
22
+ /** Where one request goes. */
23
+ export type Destination =
24
+ | { readonly kind: "api" }
25
+ | {
26
+ /** A hosted shell: a configured apex (any home's routes), or an operator's host. */
27
+ readonly kind: "shell";
28
+ readonly host: string;
29
+ readonly frameDomain: string;
30
+ /** The one home an operator's host serves; absent on a configured apex. */
31
+ readonly homeId?: string;
32
+ /** The one route an operator's host serves. */
33
+ readonly routeId?: string;
34
+ }
35
+ | {
36
+ readonly kind: "frame";
37
+ readonly frameDomain: string;
38
+ readonly route: { readonly id: string; readonly homeId: string };
39
+ }
40
+ | { readonly kind: "none" };
41
+
42
+ /** A recorded operator host. */
43
+ interface HostRow {
44
+ readonly host: string;
45
+ readonly home_id: string;
46
+ readonly route_id: string | null;
47
+ readonly frame_domain: string;
48
+ }
49
+
50
+ /** Options for {@link createRouting}. */
51
+ export interface RoutingOptions {
52
+ readonly apiHost: string;
53
+ /** The configured user-content domains (D137). */
54
+ readonly domains: () => readonly string[];
55
+ /** The active one, under which a chosen route's frames sit. */
56
+ readonly active: () => string;
57
+ readonly directory: Ledger;
58
+ readonly operator: Operator;
59
+ readonly log: Log;
60
+ }
61
+
62
+ /** The server's routing. */
63
+ export interface Routing {
64
+ /** Where a request for `host` goes. */
65
+ destination(host: string): Promise<Destination>;
66
+ /**
67
+ * An operator host for one home's links (`routing.linkHost`): resolved and recorded when it is
68
+ * new, and given only when it serves that home (and route); `undefined` otherwise.
69
+ */
70
+ linkHost(homeId: string, routeId: string, host: string): Promise<string | undefined>;
71
+ /** Whether `host` is a shell of this home: a configured apex, or one of its operator hosts. */
72
+ servesShell(homeId: string, host: string): boolean;
73
+ /** The frame domain of a shell host for a route of a home, or `undefined`. */
74
+ frameDomainOf(homeId: string, routeId: string, shellHost: string): string | undefined;
75
+ /** The shell hosts that may frame a route's pages on a frame domain (`frame-ancestors`). */
76
+ ancestorsOf(homeId: string, routeId: string, frameDomain: string): string[];
77
+ }
78
+
79
+ /** Builds the routing over the directory and the operator. */
80
+ export function createRouting(options: RoutingOptions): Routing {
81
+ const { directory, operator, log } = options;
82
+ const configured = (host: string): boolean => options.domains().includes(host);
83
+ const configuredParent = (host: string): string | undefined =>
84
+ options.domains().find((domain) => host.endsWith(`.${domain}`));
85
+
86
+ const recorded = (host: string): HostRow | undefined =>
87
+ directory.read((db) => db.get<HostRow>("SELECT * FROM operator_host WHERE host = ?", host));
88
+
89
+ const routeByLabel = (label: string): { id: string; home_id: string } | undefined =>
90
+ directory.read((db) =>
91
+ db.get<{ id: string; home_id: string }>(
92
+ "SELECT id, home_id FROM artifact_route WHERE label = ? AND removing_json IS NULL",
93
+ label,
94
+ ),
95
+ );
96
+
97
+ /** Whether an operator's answer may bind `host` at all: never the server's own names. */
98
+ const bindable = (host: string): boolean => {
99
+ if (host === options.apiHost || configured(host)) return false;
100
+ const parent = configuredParent(host);
101
+ if (parent !== undefined) {
102
+ const label = host.slice(0, host.length - parent.length - 1);
103
+ // One label under a configured domain, and never one the server could issue itself.
104
+ if (label.includes(".") || SERVER_LABEL.test(label)) return false;
105
+ }
106
+ return true;
107
+ };
108
+
109
+ /** Records an operator's answer for a new host; `undefined` when it can't be bound. */
110
+ const record = (host: string, answer: NonNullable<RoutingAnswer>): HostRow | undefined => {
111
+ if (!bindable(host)) {
112
+ log.warn("routing.answer_refused", { host, why: "reserved" });
113
+ return undefined;
114
+ }
115
+ const at = new Date().toISOString();
116
+ return directory.write((db) => {
117
+ let row: HostRow;
118
+ if ("shell" in answer) {
119
+ if (!db.get("SELECT 1 FROM home WHERE id = ?", answer.shell.home)) return undefined;
120
+ // A frame domain is configured, or one of the operator's own; never the API origin's.
121
+ if (answer.shell.domain === options.apiHost) return undefined;
122
+ row = {
123
+ host,
124
+ home_id: answer.shell.home,
125
+ route_id: null,
126
+ frame_domain: answer.shell.domain,
127
+ };
128
+ } else {
129
+ const found = db.get<{ home_id: string }>(
130
+ "SELECT home_id FROM artifact_route WHERE id = ? AND home_id = ? AND removing_json IS NULL",
131
+ answer.route.routeId,
132
+ answer.route.home,
133
+ );
134
+ if (!found) return undefined;
135
+ row = {
136
+ host,
137
+ home_id: answer.route.home,
138
+ route_id: answer.route.routeId,
139
+ frame_domain: options.active(),
140
+ };
141
+ }
142
+ const issued = db.get<{ home_id: string }>(
143
+ "SELECT home_id FROM label_issued WHERE label = ?",
144
+ host,
145
+ );
146
+ if (issued && issued.home_id !== row.home_id) {
147
+ log.warn("routing.answer_refused", { host, why: "issued-to-another-home" });
148
+ return undefined;
149
+ }
150
+ if (!issued) {
151
+ db.run(
152
+ "INSERT INTO label_issued (label, home_id, route_id, kind, issued_at) VALUES (?, ?, ?, 'operator', ?)",
153
+ host,
154
+ row.home_id,
155
+ row.route_id,
156
+ at,
157
+ );
158
+ }
159
+ db.run(
160
+ "INSERT INTO operator_host (host, home_id, route_id, frame_domain, recorded_at) VALUES (?, ?, ?, ?, ?)",
161
+ row.host,
162
+ row.home_id,
163
+ row.route_id,
164
+ row.frame_domain,
165
+ at,
166
+ );
167
+ log.info("routing.host_recorded", { host, home: row.home_id });
168
+ return row;
169
+ });
170
+ };
171
+
172
+ /** Whether an operator's answer agrees with a recorded host's binding. */
173
+ const agrees = (row: HostRow, answer: NonNullable<RoutingAnswer>): boolean =>
174
+ "shell" in answer
175
+ ? answer.shell.home === row.home_id &&
176
+ row.route_id === null &&
177
+ answer.shell.domain === row.frame_domain
178
+ : answer.route.home === row.home_id && answer.route.routeId === row.route_id;
179
+
180
+ /** The operator's host for `host`, asked and recorded, or `undefined`. */
181
+ const operatorHost = async (host: string): Promise<HostRow | undefined> => {
182
+ const row = recorded(host);
183
+ if (!operator.has.routing) return undefined;
184
+ const answer = await operator.route(host);
185
+ if (answer === "unavailable") return row;
186
+ if (answer === null) return undefined;
187
+ if (row) {
188
+ if (agrees(row, answer)) return row;
189
+ log.warn("routing.answer_refused", { host, why: "moved" });
190
+ return undefined;
191
+ }
192
+ return record(host, answer);
193
+ };
194
+
195
+ const asShell = (row: HostRow): Destination => ({
196
+ kind: "shell",
197
+ host: row.host,
198
+ frameDomain: row.frame_domain,
199
+ homeId: row.home_id,
200
+ ...(row.route_id !== null ? { routeId: row.route_id } : {}),
201
+ });
202
+
203
+ /** A route's frames on `<label>.<domain>`, when the label is the route's and the domain serves it. */
204
+ const frame = (host: string): Destination | undefined => {
205
+ const dot = host.indexOf(".");
206
+ if (dot <= 0) return undefined;
207
+ const label = host.slice(0, dot);
208
+ const domain = host.slice(dot + 1);
209
+ if (!SERVER_LABEL.test(label)) return undefined;
210
+ const route = routeByLabel(label);
211
+ if (!route) return undefined;
212
+ if (configured(domain)) {
213
+ return { kind: "frame", frameDomain: domain, route: { id: route.id, homeId: route.home_id } };
214
+ }
215
+ // An operator's frame domain serves only the routes of the homes it was given for.
216
+ const served = directory.read((db) =>
217
+ db.get(
218
+ "SELECT 1 FROM operator_host WHERE frame_domain = ? AND home_id = ? AND (route_id IS NULL OR route_id = ?)",
219
+ domain,
220
+ route.home_id,
221
+ route.id,
222
+ ),
223
+ );
224
+ return served
225
+ ? { kind: "frame", frameDomain: domain, route: { id: route.id, homeId: route.home_id } }
226
+ : undefined;
227
+ };
228
+
229
+ return {
230
+ async destination(host) {
231
+ if (host === options.apiHost) return { kind: "api" };
232
+ if (configured(host)) return { kind: "shell", host, frameDomain: host };
233
+ const framed = frame(host);
234
+ if (framed) return framed;
235
+ const row = await operatorHost(host);
236
+ return row ? asShell(row) : { kind: "none" };
237
+ },
238
+
239
+ async linkHost(homeId, routeId, host) {
240
+ const row = await operatorHost(host.toLowerCase());
241
+ if (!row || row.home_id !== homeId) return undefined;
242
+ if (row.route_id !== null && row.route_id !== routeId) return undefined;
243
+ return row.host;
244
+ },
245
+
246
+ servesShell(homeId, host) {
247
+ if (configured(host)) return true;
248
+ const row = recorded(host);
249
+ return row !== undefined && row.home_id === homeId;
250
+ },
251
+
252
+ frameDomainOf(homeId, routeId, shellHost) {
253
+ if (configured(shellHost)) return shellHost;
254
+ const row = recorded(shellHost);
255
+ if (!row || row.home_id !== homeId) return undefined;
256
+ if (row.route_id !== null && row.route_id !== routeId) return undefined;
257
+ return row.frame_domain;
258
+ },
259
+
260
+ ancestorsOf(homeId, routeId, frameDomain) {
261
+ const hosts = configured(frameDomain) ? [frameDomain] : [];
262
+ for (const row of directory.read((db) =>
263
+ db.all<{ host: string }>(
264
+ "SELECT host FROM operator_host WHERE frame_domain = ? AND home_id = ? AND (route_id IS NULL OR route_id = ?) ORDER BY host",
265
+ frameDomain,
266
+ homeId,
267
+ routeId,
268
+ ),
269
+ )) {
270
+ hosts.push(row.host);
271
+ }
272
+ return hosts;
273
+ },
274
+ };
275
+ }
@@ -27,6 +27,7 @@ import {
27
27
  durationMs,
28
28
  PUBLIC_SHARE_DEFAULT_TTL,
29
29
  PUBLIC_SHARE_MAX_TTL_MS,
30
+ type RespondentLink,
30
31
  RpcError,
31
32
  type Share,
32
33
  ShareId,
@@ -122,6 +123,17 @@ export interface RemoteShares {
122
123
  readonly hostname: string;
123
124
  readonly expiresAt?: string | undefined;
124
125
  }>;
126
+ /**
127
+ * Names expected respondents on the server's hosted home (`roster/add`, D168), each with a
128
+ * personal link there; idempotent by `ref`, so a retried share returns the same links.
129
+ */
130
+ respondents(input: {
131
+ readonly server: string;
132
+ readonly artifactId: string;
133
+ readonly respondents: NonNullable<ShareStartParams["respondents"]>;
134
+ readonly scopes?: ShareStartParams["scopes"];
135
+ readonly ttl?: ShareStartParams["ttl"];
136
+ }): Promise<readonly RespondentLink[]>;
125
137
  /** A minted link again, from what this home kept; `undefined` once it can't be. */
126
138
  url(server: string, tokenId: string): string | undefined;
127
139
  /** Revokes a link on the server's hosted home; fails with `MOSTRA_REMOTE_UNREACHABLE`. */
@@ -615,13 +627,49 @@ export function createShares(options: SharesOptions): Shares {
615
627
  }),
616
628
  );
617
629
  }
630
+ if (params.respondents !== undefined && params.respondents.length > 0) {
631
+ // Expected respondents are named on a hosted share (D168): their links are the hosted
632
+ // home's. Over a tunnel each viewer is already their own (a tailnet person, a link's own
633
+ // viewer), and `mostra roster add` names respondents with local personal links.
634
+ if (params.via !== "remote") {
635
+ throw new RpcError(
636
+ createDiagnostic("MOSTRA_HOST_INVALID_PARAMS", {
637
+ message:
638
+ "Expected respondents are named on a share to a remote server (via remote); for local links use roster/add.",
639
+ }),
640
+ -32602,
641
+ );
642
+ }
643
+ if (params.viewer !== undefined) {
644
+ throw new RpcError(
645
+ createDiagnostic("MOSTRA_HOST_INVALID_PARAMS", {
646
+ message:
647
+ "A share names either one viewer for its link or expected respondents, each with a link of their own: not both.",
648
+ }),
649
+ -32602,
650
+ );
651
+ }
652
+ }
653
+ const withRespondents = async (share: ShareStartResult): Promise<ShareStartResult> => {
654
+ const respondents = params.respondents;
655
+ if (respondents === undefined || respondents.length === 0 || !options.remote) return share;
656
+ const plan = JSON.parse((row(share.shareId) as ShareRow).plan_json) as Plan;
657
+ const links = await options.remote.respondents({
658
+ server: plan.server as string,
659
+ artifactId: detail.id,
660
+ respondents,
661
+ scopes: params.scopes,
662
+ ttl: params.ttl,
663
+ });
664
+ return { ...share, respondents: [...links] };
665
+ };
618
666
  const key = requestKey("share/start", params);
619
667
  if (key !== undefined) {
620
668
  const replay = ledger.read((db) => recordedResult<{ shareId: string }>(db, key));
621
669
  const found = replay ? row(replay.shareId) : undefined;
622
- if (found) return withUrl(toShare(found));
670
+ if (found) return withRespondents(withUrl(toShare(found)));
623
671
  }
624
- if (params.via === "remote") return startRemote(params, detail, key);
672
+ if (params.via === "remote") return withRespondents(await startRemote(params, detail, key));
625
673
  const ttlMs = lifetime(params.via, params.ttl);
626
674
  const shareId = ShareId.create();
627
675
  const { shell, artifact, plan, hostname } = await setUp(
@@ -492,6 +492,13 @@ export function createVerifier(options: VerifierOptions): Verifier {
492
492
  return { timedOut: true } as RenderResult;
493
493
  throw error;
494
494
  });
495
+ // A render the browser's own connection failure spoiled was rendered again (#132): said
496
+ // in the log, never in the verdict, since it says nothing of the artifact.
497
+ if (result.renderedAgain !== undefined)
498
+ options.log.info("verify.rendered_again", {
499
+ name,
500
+ why: options.redactor.redact(result.renderedAgain),
501
+ });
495
502
  // Every ARIA snapshot verify keeps is written through the redactor, the baseline's too
496
503
  // (D138 item 1, Opus review finding 8); the runner only reads it.
497
504
  if (result.aria) {
@@ -100,6 +100,14 @@ export function runnerEnvironment(env: Environment, browsers?: string): Environm
100
100
  if (browsers !== undefined) out["PLAYWRIGHT_BROWSERS_PATH"] = browsers;
101
101
  const idle = env["MOSTRA_TEST_VERIFY_IDLE_MS"];
102
102
  if (idle) out["MOSTRA_TEST_VERIFY_IDLE_MS"] = idle;
103
+ for (const name of [
104
+ "MOSTRA_TEST_VERIFY_LOSE_BROWSER",
105
+ "MOSTRA_TEST_VERIFY_FAIL_ONCE",
106
+ "MOSTRA_TEST_VERIFY_COLLIDE_ONCE",
107
+ ]) {
108
+ const value = env[name];
109
+ if (value) out[name] = value;
110
+ }
103
111
  return out;
104
112
  }
105
113
 
@@ -187,12 +195,28 @@ export function createRunnerClient(options: {
187
195
  }),
188
196
  );
189
197
  }
198
+ let failure = "";
190
199
  if (outcome.kind === "error" && outcome.error instanceof RpcError) {
191
200
  // The runner answered with a diagnostic of its own (no browser, say): it stands. A closed
192
- // channel or an internal error means the runner itself failed, reported as a crash.
201
+ // channel (the runner died) or an internal error means the runner itself failed.
193
202
  const code = outcome.error.diagnostic.code;
194
203
  if (code !== "MOSTRA_HOST_INTERNAL_ERROR" && !code.startsWith("MOSTRA_HOST_CONNECTION"))
195
204
  throw outcome.error;
205
+ if (code === "MOSTRA_HOST_INTERNAL_ERROR") {
206
+ // Alive but failed in itself: it never answers again. It is stopped, and the request runs
207
+ // once more on a fresh runner, so one broken runner can't fail every later verify (#106's
208
+ // sighting); the page is judged by that try. A runner that died is reported as a crash
209
+ // below, as before, since the page may have killed it.
210
+ failure = outcome.error.diagnostic.message;
211
+ options.log.warn("verify.runner_failed", { method, error: failure.slice(0, 500) });
212
+ if (child) {
213
+ const failed = child;
214
+ child = undefined;
215
+ const stopped = await failed.catch(() => undefined);
216
+ if (stopped) recycled.add(stopped);
217
+ await stopped?.stop(2000);
218
+ }
219
+ }
196
220
  }
197
221
  // Another run's recovery stopped the runner under this request: it isn't this page's fault,
198
222
  // so the request runs once more on a fresh runner (Opus review finding 5). The retry keeps the
@@ -209,9 +233,10 @@ export function createRunnerClient(options: {
209
233
  new Promise<undefined>((done) => setTimeout(() => done(undefined), 1000)),
210
234
  ]);
211
235
  const tail = exit?.stderrTail.slice(-10).join("\n") ?? "";
236
+ const said = failure ? `\nThe runner said: ${failure.slice(0, 1000)}` : "";
212
237
  throw new RpcError(
213
238
  createDiagnostic("MOSTRA_VERIFY_CRASHED", {
214
- message: `The verify runner stopped before it answered${exit ? ` (${exit.signal ?? `code ${exit.code}`})` : ""}.${tail ? `\n${tail}` : ""}`,
239
+ message: `The verify runner stopped before it answered${exit ? ` (${exit.signal ?? `code ${exit.code}`})` : ""}.${tail ? `\n${tail}` : ""}${said}`,
215
240
  }),
216
241
  );
217
242
  };