@mostra/runtime 0.9.0 → 0.11.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 (279) hide show
  1. package/dist/bin.js +6628 -9
  2. package/dist/bin.js.map +1 -1
  3. package/dist/builder/child/main.js +2 -2
  4. package/dist/{child-Chiavhdx.js → child-BmNZ4a70.js} +2 -2
  5. package/dist/{child-Chiavhdx.js.map → child-BmNZ4a70.js.map} +1 -1
  6. package/dist/deps/child/install.js +1 -1
  7. package/dist/{directories-mJ1qlVht.js → directories-BLJjeSPD.js} +5 -5
  8. package/dist/directories-BLJjeSPD.js.map +1 -0
  9. package/dist/{files-FygSJIzK.js → files-DGeWuE4I.js} +2 -2
  10. package/dist/{files-FygSJIzK.js.map → files-DGeWuE4I.js.map} +1 -1
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +2 -2
  14. package/dist/{instance-EnaZPs14.js → instance-DCiUHvgZ.js} +3835 -255
  15. package/dist/instance-DCiUHvgZ.js.map +1 -0
  16. package/dist/reference/cli.md +1322 -0
  17. package/dist/reference/diagnostics.json +1552 -0
  18. package/dist/reference/errors/MOSTRA_A11Y_MINOR.md +23 -0
  19. package/dist/reference/errors/MOSTRA_A11Y_SERIOUS.md +23 -0
  20. package/dist/reference/errors/MOSTRA_ACTION_CANCELLED.md +23 -0
  21. package/dist/reference/errors/MOSTRA_ACTION_EVENT_INVALID.md +23 -0
  22. package/dist/reference/errors/MOSTRA_ACTION_EXPORT_INVALID.md +23 -0
  23. package/dist/reference/errors/MOSTRA_ACTION_INTERRUPTED.md +23 -0
  24. package/dist/reference/errors/MOSTRA_ACTION_PAUSED.md +23 -0
  25. package/dist/reference/errors/MOSTRA_ACTION_RUN_NOT_FOUND.md +23 -0
  26. package/dist/reference/errors/MOSTRA_ACTION_THREW.md +23 -0
  27. package/dist/reference/errors/MOSTRA_ACTION_TOO_LARGE.md +23 -0
  28. package/dist/reference/errors/MOSTRA_ACTION_UNKNOWN_FUNCTION.md +23 -0
  29. package/dist/reference/errors/MOSTRA_ACTION_UNSERIALIZABLE.md +23 -0
  30. package/dist/reference/errors/MOSTRA_ARTIFACT_BUNDLE_INVALID.md +23 -0
  31. package/dist/reference/errors/MOSTRA_ARTIFACT_DIR_NOT_EMPTY.md +23 -0
  32. package/dist/reference/errors/MOSTRA_ARTIFACT_ENTRY_AMBIGUOUS.md +23 -0
  33. package/dist/reference/errors/MOSTRA_ARTIFACT_ID_DROPPED.md +23 -0
  34. package/dist/reference/errors/MOSTRA_ARTIFACT_NOT_FOUND.md +23 -0
  35. package/dist/reference/errors/MOSTRA_ARTIFACT_NO_ENTRY.md +23 -0
  36. package/dist/reference/errors/MOSTRA_ARTIFACT_NO_PAGE.md +23 -0
  37. package/dist/reference/errors/MOSTRA_ARTIFACT_PATCH_REJECTED.md +23 -0
  38. package/dist/reference/errors/MOSTRA_ARTIFACT_PATH_INVALID.md +23 -0
  39. package/dist/reference/errors/MOSTRA_ARTIFACT_SOURCE_MISSING.md +23 -0
  40. package/dist/reference/errors/MOSTRA_ARTIFACT_SOURCE_UNREADABLE.md +23 -0
  41. package/dist/reference/errors/MOSTRA_ARTIFACT_TEMPLATE_UNKNOWN.md +23 -0
  42. package/dist/reference/errors/MOSTRA_ARTIFACT_VERSION_COLLECTED.md +23 -0
  43. package/dist/reference/errors/MOSTRA_ARTIFACT_VERSION_NOT_FOUND.md +23 -0
  44. package/dist/reference/errors/MOSTRA_BUILD_CRASHED.md +23 -0
  45. package/dist/reference/errors/MOSTRA_BUILD_FAILED.md +23 -0
  46. package/dist/reference/errors/MOSTRA_BUILD_TIMEOUT.md +23 -0
  47. package/dist/reference/errors/MOSTRA_BUILD_UNRESOLVED.md +23 -0
  48. package/dist/reference/errors/MOSTRA_CLI_CONFIG_UNWRITABLE.md +23 -0
  49. package/dist/reference/errors/MOSTRA_CLI_UNKNOWN_COMMAND.md +23 -0
  50. package/dist/reference/errors/MOSTRA_CLI_USAGE.md +23 -0
  51. package/dist/reference/errors/MOSTRA_CONSOLE_ERROR.md +23 -0
  52. package/dist/reference/errors/MOSTRA_CONSOLE_WARNING.md +23 -0
  53. package/dist/reference/errors/MOSTRA_DEP_INSTALL_FAILED.md +23 -0
  54. package/dist/reference/errors/MOSTRA_DEP_MISSING.md +23 -0
  55. package/dist/reference/errors/MOSTRA_DEP_NOT_FOUND.md +23 -0
  56. package/dist/reference/errors/MOSTRA_DEP_OFFLINE.md +23 -0
  57. package/dist/reference/errors/MOSTRA_DEP_SPEC_INVALID.md +23 -0
  58. package/dist/reference/errors/MOSTRA_DEP_TIMEOUT.md +23 -0
  59. package/dist/reference/errors/MOSTRA_DEP_WARM_CONFLICT.md +23 -0
  60. package/dist/reference/errors/MOSTRA_ENV_BIND_FAILED.md +23 -0
  61. package/dist/reference/errors/MOSTRA_ENV_BROWSER_MISSING.md +23 -0
  62. package/dist/reference/errors/MOSTRA_ENV_BUNDLE_DOWNLOAD_FAILED.md +23 -0
  63. package/dist/reference/errors/MOSTRA_ENV_BUNDLE_INVALID.md +23 -0
  64. package/dist/reference/errors/MOSTRA_ENV_BUNDLE_UNAVAILABLE.md +23 -0
  65. package/dist/reference/errors/MOSTRA_ENV_HELPER_MISSING.md +23 -0
  66. package/dist/reference/errors/MOSTRA_ENV_NODE_UNSUPPORTED.md +23 -0
  67. package/dist/reference/errors/MOSTRA_ENV_PORT_TAKEN.md +23 -0
  68. package/dist/reference/errors/MOSTRA_ENV_RUNTIME_INSTALLING.md +23 -0
  69. package/dist/reference/errors/MOSTRA_ENV_RUNTIME_MISSING.md +23 -0
  70. package/dist/reference/errors/MOSTRA_ENV_SERVICE_FAILED.md +23 -0
  71. package/dist/reference/errors/MOSTRA_ENV_SHELL_MISSING.md +23 -0
  72. package/dist/reference/errors/MOSTRA_ENV_WARM_MISSING.md +23 -0
  73. package/dist/reference/errors/MOSTRA_FIELD_CONFLICT.md +23 -0
  74. package/dist/reference/errors/MOSTRA_FIELD_DUPLICATE_ID.md +23 -0
  75. package/dist/reference/errors/MOSTRA_FIELD_ID_INVALID.md +23 -0
  76. package/dist/reference/errors/MOSTRA_FIELD_ID_UNSTABLE.md +23 -0
  77. package/dist/reference/errors/MOSTRA_FIELD_MUTATION_ID_REUSED.md +23 -0
  78. package/dist/reference/errors/MOSTRA_FIELD_SHARED.md +23 -0
  79. package/dist/reference/errors/MOSTRA_FIELD_TOO_LARGE.md +23 -0
  80. package/dist/reference/errors/MOSTRA_FIELD_UNBOUND.md +23 -0
  81. package/dist/reference/errors/MOSTRA_HOME_DISK_FULL.md +23 -0
  82. package/dist/reference/errors/MOSTRA_HOME_GC_INCOMPLETE.md +23 -0
  83. package/dist/reference/errors/MOSTRA_HOME_GONE.md +23 -0
  84. package/dist/reference/errors/MOSTRA_HOME_INTEGRITY.md +23 -0
  85. package/dist/reference/errors/MOSTRA_HOME_LEDGER_UNREADABLE.md +23 -0
  86. package/dist/reference/errors/MOSTRA_HOME_LOCKED.md +23 -0
  87. package/dist/reference/errors/MOSTRA_HOME_MISMATCH.md +23 -0
  88. package/dist/reference/errors/MOSTRA_HOME_NETWORK_FILESYSTEM.md +23 -0
  89. package/dist/reference/errors/MOSTRA_HOME_NOT_ALWAYS_ON.md +23 -0
  90. package/dist/reference/errors/MOSTRA_HOME_NOT_OWNED.md +23 -0
  91. package/dist/reference/errors/MOSTRA_HOME_SOCKET_TOO_LONG.md +23 -0
  92. package/dist/reference/errors/MOSTRA_HOME_TOO_NEW.md +23 -0
  93. package/dist/reference/errors/MOSTRA_HOST_CONNECTION_CLOSED.md +23 -0
  94. package/dist/reference/errors/MOSTRA_HOST_CURSOR_COMPACTED.md +23 -0
  95. package/dist/reference/errors/MOSTRA_HOST_IDENTITY_UNAVAILABLE.md +23 -0
  96. package/dist/reference/errors/MOSTRA_HOST_INITIALIZE_ORDER.md +23 -0
  97. package/dist/reference/errors/MOSTRA_HOST_INTERNAL_ERROR.md +23 -0
  98. package/dist/reference/errors/MOSTRA_HOST_INVALID_PARAMS.md +23 -0
  99. package/dist/reference/errors/MOSTRA_HOST_MALFORMED.md +23 -0
  100. package/dist/reference/errors/MOSTRA_HOST_MESSAGE_TOO_LARGE.md +23 -0
  101. package/dist/reference/errors/MOSTRA_HOST_METHOD_UNKNOWN.md +23 -0
  102. package/dist/reference/errors/MOSTRA_HOST_NOTIFICATION_UNSUPPORTED.md +23 -0
  103. package/dist/reference/errors/MOSTRA_HOST_PORT_UNSUPPORTED.md +23 -0
  104. package/dist/reference/errors/MOSTRA_HOST_REQUEST_ID_REUSED.md +23 -0
  105. package/dist/reference/errors/MOSTRA_HOST_REVISION_UNSUPPORTED.md +23 -0
  106. package/dist/reference/errors/MOSTRA_HOST_SHUTDOWN_REFUSED.md +23 -0
  107. package/dist/reference/errors/MOSTRA_HOST_SUBSCRIPTION_UNKNOWN.md +23 -0
  108. package/dist/reference/errors/MOSTRA_HOST_TIMEOUT.md +23 -0
  109. package/dist/reference/errors/MOSTRA_HYGIENE_CONTENT_TYPE.md +23 -0
  110. package/dist/reference/errors/MOSTRA_HYGIENE_CSRF_MISSING.md +23 -0
  111. package/dist/reference/errors/MOSTRA_HYGIENE_FRAME_SESSION.md +23 -0
  112. package/dist/reference/errors/MOSTRA_HYGIENE_HEADERS_TOO_LARGE.md +23 -0
  113. package/dist/reference/errors/MOSTRA_HYGIENE_HOST_REFUSED.md +23 -0
  114. package/dist/reference/errors/MOSTRA_HYGIENE_NOT_SERVED.md +23 -0
  115. package/dist/reference/errors/MOSTRA_HYGIENE_ORIGIN_REFUSED.md +23 -0
  116. package/dist/reference/errors/MOSTRA_HYGIENE_RATE_LIMITED.md +23 -0
  117. package/dist/reference/errors/MOSTRA_HYGIENE_REQUEST_MALFORMED.md +23 -0
  118. package/dist/reference/errors/MOSTRA_HYGIENE_SCOPE_DENIED.md +23 -0
  119. package/dist/reference/errors/MOSTRA_HYGIENE_SESSION_CONFLICT.md +23 -0
  120. package/dist/reference/errors/MOSTRA_HYGIENE_SESSION_MISSING.md +23 -0
  121. package/dist/reference/errors/MOSTRA_HYGIENE_TOKEN_INVALID.md +23 -0
  122. package/dist/reference/errors/MOSTRA_HYGIENE_TOKEN_REVOKED.md +23 -0
  123. package/dist/reference/errors/MOSTRA_LIVE_SOURCE_FAILED.md +23 -0
  124. package/dist/reference/errors/MOSTRA_LIVE_TOO_LARGE.md +23 -0
  125. package/dist/reference/errors/MOSTRA_MANIFEST_INVALID.md +23 -0
  126. package/dist/reference/errors/MOSTRA_MANIFEST_NOT_LITERAL.md +23 -0
  127. package/dist/reference/errors/MOSTRA_MANIFEST_UNKNOWN_KEY.md +23 -0
  128. package/dist/reference/errors/MOSTRA_NETWORK_EXTERNAL_FAILED.md +23 -0
  129. package/dist/reference/errors/MOSTRA_NETWORK_REQUEST_FAILED.md +23 -0
  130. package/dist/reference/errors/MOSTRA_PLATFORM_UNSUPPORTED.md +23 -0
  131. package/dist/reference/errors/MOSTRA_PUBLISH_ID_CONFLICT.md +23 -0
  132. package/dist/reference/errors/MOSTRA_PUBLISH_SOURCE_CHANGED.md +23 -0
  133. package/dist/reference/errors/MOSTRA_PUBLISH_VERIFY_FAILED.md +23 -0
  134. package/dist/reference/errors/MOSTRA_REGRESSION_ACTION_REMOVED.md +23 -0
  135. package/dist/reference/errors/MOSTRA_REGRESSION_ARIA.md +23 -0
  136. package/dist/reference/errors/MOSTRA_REGRESSION_FIELD_REMOVED.md +23 -0
  137. package/dist/reference/errors/MOSTRA_REGRESSION_LIVE_REMOVED.md +23 -0
  138. package/dist/reference/errors/MOSTRA_REGRESSION_PAGE_REMOVED.md +23 -0
  139. package/dist/reference/errors/MOSTRA_REGRESSION_PIXELS.md +23 -0
  140. package/dist/reference/errors/MOSTRA_REMOTE_CONFIG_INVALID.md +23 -0
  141. package/dist/reference/errors/MOSTRA_REMOTE_HOME_MOVING.md +23 -0
  142. package/dist/reference/errors/MOSTRA_REMOTE_HOME_SUSPENDED.md +23 -0
  143. package/dist/reference/errors/MOSTRA_REMOTE_LIMIT_REACHED.md +23 -0
  144. package/dist/reference/errors/MOSTRA_REMOTE_LOGIN_FAILED.md +23 -0
  145. package/dist/reference/errors/MOSTRA_REMOTE_NOT_OWNER_INSTANCE.md +23 -0
  146. package/dist/reference/errors/MOSTRA_REMOTE_NO_INSTANCE.md +23 -0
  147. package/dist/reference/errors/MOSTRA_REMOTE_OPERATOR_UNAVAILABLE.md +23 -0
  148. package/dist/reference/errors/MOSTRA_REMOTE_OWNER_OFFLINE.md +23 -0
  149. package/dist/reference/errors/MOSTRA_REMOTE_PAUSED_BY_OPERATOR.md +23 -0
  150. package/dist/reference/errors/MOSTRA_REMOTE_QUEUE_FULL.md +23 -0
  151. package/dist/reference/errors/MOSTRA_REMOTE_RATE_LIMITED.md +23 -0
  152. package/dist/reference/errors/MOSTRA_REMOTE_SIGN_IN_REQUIRED.md +23 -0
  153. package/dist/reference/errors/MOSTRA_REMOTE_UNDER_REVIEW.md +23 -0
  154. package/dist/reference/errors/MOSTRA_REMOTE_UNREACHABLE.md +23 -0
  155. package/dist/reference/errors/MOSTRA_RUNTIME_BLANK.md +23 -0
  156. package/dist/reference/errors/MOSTRA_RUNTIME_NOT_READY.md +23 -0
  157. package/dist/reference/errors/MOSTRA_RUNTIME_PAGE_ERROR.md +23 -0
  158. package/dist/reference/errors/MOSTRA_RUNTIME_WORKER_CRASHED.md +23 -0
  159. package/dist/reference/errors/MOSTRA_RUNTIME_WORKER_PARKED.md +23 -0
  160. package/dist/reference/errors/MOSTRA_SECRET_MISSING.md +23 -0
  161. package/dist/reference/errors/MOSTRA_SHARE_NOT_ENABLED.md +23 -0
  162. package/dist/reference/errors/MOSTRA_SHARE_NOT_FOUND.md +23 -0
  163. package/dist/reference/errors/MOSTRA_SHARE_PORTS_EXHAUSTED.md +23 -0
  164. package/dist/reference/errors/MOSTRA_SHARE_TOOL_MISSING.md +23 -0
  165. package/dist/reference/errors/MOSTRA_SHARE_TOOL_NOT_READY.md +23 -0
  166. package/dist/reference/errors/MOSTRA_SHARE_TTL_INVALID.md +23 -0
  167. package/dist/reference/errors/MOSTRA_SHARE_TUNNEL_FAILED.md +23 -0
  168. package/dist/reference/errors/MOSTRA_SMOKE_BUDGET.md +23 -0
  169. package/dist/reference/errors/MOSTRA_SMOKE_NO_EFFECT.md +23 -0
  170. package/dist/reference/errors/MOSTRA_SUBMIT_ALREADY.md +23 -0
  171. package/dist/reference/errors/MOSTRA_SUBMIT_BLOCKED.md +23 -0
  172. package/dist/reference/errors/MOSTRA_SUBMIT_CHANNEL_DENIED.md +23 -0
  173. package/dist/reference/errors/MOSTRA_SUBMIT_NOT_FOUND.md +23 -0
  174. package/dist/reference/errors/MOSTRA_SUBMIT_PAUSED.md +23 -0
  175. package/dist/reference/errors/MOSTRA_SUBMIT_POLICY_NONE.md +23 -0
  176. package/dist/reference/errors/MOSTRA_SUBMIT_REVISION_MOVED.md +23 -0
  177. package/dist/reference/errors/MOSTRA_SUBMIT_SIGNAL_INVALID.md +23 -0
  178. package/dist/reference/errors/MOSTRA_SUBMIT_VIEW_INVALID.md +23 -0
  179. package/dist/reference/errors/MOSTRA_TARGET_UNAVAILABLE.md +23 -0
  180. package/dist/reference/errors/MOSTRA_TYPE_ERROR.md +23 -0
  181. package/dist/reference/errors/MOSTRA_TYPE_UNTYPED_PACKAGE.md +23 -0
  182. package/dist/reference/errors/MOSTRA_VERIFY_ACTION_SKIPPED.md +23 -0
  183. package/dist/reference/errors/MOSTRA_VERIFY_BASELINE_MISSING.md +23 -0
  184. package/dist/reference/errors/MOSTRA_VERIFY_CRASHED.md +23 -0
  185. package/dist/reference/errors/MOSTRA_VERIFY_LIVE_FAILED.md +23 -0
  186. package/dist/reference/errors/MOSTRA_VERIFY_NO_BASELINE.md +23 -0
  187. package/dist/reference/errors/MOSTRA_VERIFY_SECRET_MISSING.md +23 -0
  188. package/dist/reference/errors/MOSTRA_VERIFY_SKIP_CONSEQUENCE.md +23 -0
  189. package/dist/reference/errors/MOSTRA_VERIFY_TIMEOUT.md +23 -0
  190. package/dist/reference/self-hosting.md +130 -0
  191. package/dist/reference/telemetry.md +84 -0
  192. package/dist/skill/SKILL.md +122 -0
  193. package/dist/skill/assets/examples/dashboard/index.tsx +161 -0
  194. package/dist/skill/assets/examples/dashboard/live.ts +25 -0
  195. package/dist/skill/assets/examples/dashboard/styles.css +125 -0
  196. package/dist/skill/assets/examples/decision/index.tsx +95 -0
  197. package/dist/skill/assets/examples/decision/styles.css +125 -0
  198. package/dist/skill/assets/examples/inbox/actions.ts +23 -0
  199. package/dist/skill/assets/examples/inbox/index.tsx +109 -0
  200. package/dist/skill/assets/examples/inbox/styles.css +125 -0
  201. package/dist/skill/assets/studio.css +125 -0
  202. package/dist/skill/references/answers.md +217 -0
  203. package/dist/skill/references/design.md +154 -0
  204. package/dist/skill/references/libraries.md +167 -0
  205. package/dist/skill/references/long-lived.md +148 -0
  206. package/dist/skill/references/mcp.md +68 -0
  207. package/dist/skill/references/page.md +131 -0
  208. package/dist/skill/references/server.md +146 -0
  209. package/dist/skill/references/sharing.md +123 -0
  210. package/dist/skill/references/verify.md +71 -0
  211. package/package.json +12 -5
  212. package/src/actions/index.ts +163 -10
  213. package/src/bin.ts +78 -1
  214. package/src/gateway/actions.ts +40 -4
  215. package/src/gateway/browser.ts +162 -95
  216. package/src/gateway/capabilities.ts +23 -6
  217. package/src/gateway/http.ts +12 -1
  218. package/src/gateway/index.ts +282 -20
  219. package/src/gateway/listener.ts +31 -6
  220. package/src/gateway/routes.ts +23 -7
  221. package/src/gc/index.ts +19 -0
  222. package/src/instance/index.ts +60 -2
  223. package/src/interaction/ephemeral.ts +32 -23
  224. package/src/interaction/events.ts +21 -1
  225. package/src/interaction/imports.ts +317 -0
  226. package/src/interaction/index.ts +228 -15
  227. package/src/interaction/outbox.ts +9 -0
  228. package/src/interaction/pause.ts +106 -0
  229. package/src/interaction/results.ts +8 -1
  230. package/src/interaction/runs.ts +52 -2
  231. package/src/interaction/submissions.ts +59 -2
  232. package/src/interaction/tally.ts +129 -0
  233. package/src/interaction/viewers.ts +34 -1
  234. package/src/ledger/index.ts +124 -10
  235. package/src/ledger/migrations.ts +234 -0
  236. package/src/ledger/types.ts +8 -0
  237. package/src/link/author.ts +215 -0
  238. package/src/link/binding.ts +289 -0
  239. package/src/link/hosted.ts +101 -0
  240. package/src/link/http.ts +141 -0
  241. package/src/link/index.ts +10 -0
  242. package/src/link/manager.ts +1489 -0
  243. package/src/link/relay.ts +512 -0
  244. package/src/live/index.ts +112 -2
  245. package/src/platform/filesystems.ts +78 -0
  246. package/src/platform/index.ts +1 -0
  247. package/src/protocol-server/client.ts +53 -0
  248. package/src/protocol-server/index.ts +19 -2
  249. package/src/protocol-server/server.ts +38 -7
  250. package/src/protocol-server/websocket.ts +161 -0
  251. package/src/publish/bundle.ts +398 -0
  252. package/src/publish/manifest.ts +9 -0
  253. package/src/publish/methods.ts +12 -1
  254. package/src/publish/publisher.ts +127 -0
  255. package/src/registry/index.ts +35 -14
  256. package/src/server/api.ts +881 -0
  257. package/src/server/auth.ts +1139 -0
  258. package/src/server/authorize.ts +816 -0
  259. package/src/server/clients.ts +235 -0
  260. package/src/server/config.ts +228 -0
  261. package/src/server/data.ts +427 -0
  262. package/src/server/directory.ts +210 -0
  263. package/src/server/feed.ts +191 -0
  264. package/src/server/handle.ts +172 -0
  265. package/src/server/hosted-pages.ts +532 -0
  266. package/src/server/hosted.ts +1323 -0
  267. package/src/server/index.ts +650 -0
  268. package/src/server/mcp.ts +330 -0
  269. package/src/server/metering.ts +156 -0
  270. package/src/server/oauth-clients.ts +510 -0
  271. package/src/server/operator.ts +498 -0
  272. package/src/server/providers.ts +284 -0
  273. package/src/server/relay.ts +1163 -0
  274. package/src/server/remove.ts +148 -0
  275. package/src/server/routing.ts +275 -0
  276. package/src/share/index.ts +110 -6
  277. package/src/verify/runner.ts +23 -2
  278. package/dist/directories-mJ1qlVht.js.map +0 -1
  279. package/dist/instance-EnaZPs14.js.map +0 -1
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Removing a hosted artifact (`ServerHandle.remove`, DATA_MODEL §7.5): an explicit deletion,
3
+ * never part of another action. Everything of the artifact goes in one transaction of its home's
4
+ * ledger: its own rows (every table with an `artifact_id`) and every row that references them,
5
+ * followed through the schema's foreign keys, so no table needs listing here and a table a later
6
+ * migration adds is covered by construction. The write-once triggers that keep versions, events,
7
+ * submissions and tokens immutable are dropped for the transaction and created again in it, so the
8
+ * only way past them is this one.
9
+ */
10
+ import type { MigrationDb, SqlValue } from "../ledger/index.ts";
11
+
12
+ interface ForeignKey {
13
+ readonly table: string;
14
+ readonly from: string;
15
+ readonly to: string;
16
+ }
17
+
18
+ /** What one removal deleted, table by table. */
19
+ export type Removed = Readonly<Record<string, number>>;
20
+
21
+ /**
22
+ * Deletes an artifact and everything referencing it from a home's ledger, in the caller's write
23
+ * transaction. Answers the rows deleted per table.
24
+ */
25
+ export function purgeArtifact(db: MigrationDb, artifactId: string): Removed {
26
+ const tables = db
27
+ .all<{ name: string }>(
28
+ "SELECT name FROM sqlite_schema WHERE type = 'table' AND name NOT LIKE 'sqlite_%'",
29
+ )
30
+ .map((row) => row.name);
31
+ const columns = new Map<string, Set<string>>();
32
+ const children = new Map<string, ForeignKey[]>();
33
+ for (const table of tables) {
34
+ columns.set(
35
+ table,
36
+ new Set(db.all<{ name: string }>(`PRAGMA table_info("${table}")`).map((row) => row.name)),
37
+ );
38
+ for (const key of db.all<{ table: string; from: string; to: string | null }>(
39
+ `PRAGMA foreign_key_list("${table}")`,
40
+ )) {
41
+ const list = children.get(key.table) ?? [];
42
+ list.push({ table, from: key.from, to: key.to ?? "rowid" });
43
+ children.set(key.table, list);
44
+ }
45
+ }
46
+
47
+ // Which rows of each table go: the artifact's own, then whatever references a doomed row.
48
+ const where = new Map<string, { readonly sql: string; readonly params: SqlValue[] }>();
49
+ for (const table of tables) {
50
+ if (table === "artifact") where.set(table, { sql: "id = ?", params: [artifactId] });
51
+ else if (columns.get(table)?.has("artifact_id")) {
52
+ where.set(table, { sql: "artifact_id = ?", params: [artifactId] });
53
+ }
54
+ }
55
+ // A fixed point over the foreign keys: a table joins once a parent of it is doomed. Bounded,
56
+ // since the schema's references form no long chain.
57
+ let grew = true;
58
+ for (let round = 0; grew && round < 16; round++) {
59
+ grew = false;
60
+ for (const [parent, list] of children) {
61
+ const doomed = where.get(parent);
62
+ if (!doomed) continue;
63
+ for (const key of list) {
64
+ const clause = {
65
+ sql: `"${key.from}" IN (SELECT "${key.to}" FROM "${parent}" WHERE ${doomed.sql})`,
66
+ params: doomed.params,
67
+ };
68
+ const existing = where.get(key.table);
69
+ if (!existing) {
70
+ where.set(key.table, clause);
71
+ grew = true;
72
+ } else if (
73
+ !existing.sql.includes(`"${key.from}" IN (SELECT "${key.to}" FROM "${parent}"`)
74
+ ) {
75
+ where.set(key.table, {
76
+ sql: `(${existing.sql}) OR (${clause.sql})`,
77
+ params: [...existing.params, ...clause.params],
78
+ });
79
+ grew = true;
80
+ }
81
+ }
82
+ }
83
+ }
84
+
85
+ const triggers = db.all<{ name: string; sql: string }>(
86
+ `SELECT name, sql FROM sqlite_schema WHERE type = 'trigger' AND tbl_name IN (${[...where.keys()]
87
+ .map(() => "?")
88
+ .join(", ")})`,
89
+ ...where.keys(),
90
+ );
91
+ for (const trigger of triggers) db.exec(`DROP TRIGGER "${trigger.name}"`);
92
+ db.exec("PRAGMA defer_foreign_keys = ON");
93
+ const removed: Record<string, number> = {};
94
+ // Children first: a row is read through its parent's clause before the parent goes.
95
+ const order = [...where.keys()].sort((a, b) => depth(b) - depth(a));
96
+ function depth(table: string, seen = new Set<string>()): number {
97
+ if (table === "artifact" || seen.has(table)) return 0;
98
+ seen.add(table);
99
+ let deepest = 0;
100
+ for (const [parent, list] of children) {
101
+ if (list.some((key) => key.table === table) && where.has(parent) && parent !== table) {
102
+ deepest = Math.max(deepest, depth(parent, seen) + 1);
103
+ }
104
+ }
105
+ return deepest;
106
+ }
107
+ // The clauses read the parents, so the rows to delete are fixed first, by rowid.
108
+ const doomedRows = new Map<string, number[]>();
109
+ for (const table of order) {
110
+ const clause = where.get(table);
111
+ if (!clause) continue;
112
+ doomedRows.set(
113
+ table,
114
+ db
115
+ // Named apart: SQLite answers a table's own column name for `rowid` when it has an
116
+ // INTEGER PRIMARY KEY (`document.id`, `event.cursor`).
117
+ .all<{ row: number }>(
118
+ `SELECT rowid AS row FROM "${table}" WHERE ${clause.sql}`,
119
+ ...clause.params,
120
+ )
121
+ .map((found) => found.row),
122
+ );
123
+ }
124
+ for (const table of order) {
125
+ const rows = doomedRows.get(table) ?? [];
126
+ let count = 0;
127
+ for (let index = 0; index < rows.length; index += 500) {
128
+ const slice = rows.slice(index, index + 500);
129
+ count += db.run(
130
+ `DELETE FROM "${table}" WHERE rowid IN (${slice.map(() => "?").join(", ")})`,
131
+ ...slice,
132
+ ).changes;
133
+ }
134
+ if (count > 0) removed[table] = count;
135
+ }
136
+ for (const trigger of triggers) db.exec(trigger.sql);
137
+ // Nothing left pointing at what went: a row of another artifact naming a removed one would
138
+ // fail the commit anyway; this names it.
139
+ const dangling = db.all<{ table: string; parent: string }>("PRAGMA foreign_key_check");
140
+ if (dangling.length > 0) {
141
+ throw new Error(
142
+ `Removing ${artifactId} would leave ${dangling.length} rows dangling (${[
143
+ ...new Set(dangling.map((row) => `${row.table} → ${row.parent}`)),
144
+ ].join(", ")}).`,
145
+ );
146
+ }
147
+ return removed;
148
+ }
@@ -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
+ }
@@ -96,6 +96,36 @@ export interface SharesOptions {
96
96
  readonly probeMs?: number;
97
97
  /** How often active shares are checked for an expired or revoked link (tests shorten it). */
98
98
  readonly sweepMs?: number;
99
+ /**
100
+ * Shares to a remote server (`via: "remote"`, D165, INTERFACES §18.2): the owner's link hosts
101
+ * the artifact and mints the link on its hosted home. Absent, `remote` shares are refused.
102
+ */
103
+ readonly remote?: RemoteShares;
104
+ }
105
+
106
+ /** What a `remote` share needs of the owner's link to a server (INTERFACES §18.2). */
107
+ export interface RemoteShares {
108
+ /**
109
+ * Pushes the artifact's latest version to the server (`server`, else the default) and mints a
110
+ * link on its hosted home, keeping the link's secret where only this home can read it.
111
+ */
112
+ mint(input: {
113
+ readonly artifactId: string;
114
+ readonly server?: string | undefined;
115
+ readonly scopes?: ShareStartParams["scopes"];
116
+ readonly ttl?: ShareStartParams["ttl"];
117
+ readonly viewer?: ShareStartParams["viewer"];
118
+ }): Promise<{
119
+ readonly server: string;
120
+ readonly url: string;
121
+ readonly tokenId: string;
122
+ readonly hostname: string;
123
+ readonly expiresAt?: string | undefined;
124
+ }>;
125
+ /** A minted link again, from what this home kept; `undefined` once it can't be. */
126
+ url(server: string, tokenId: string): string | undefined;
127
+ /** Revokes a link on the server's hosted home; fails with `MOSTRA_REMOTE_UNREACHABLE`. */
128
+ revoke(server: string, tokenId: string): Promise<void>;
99
129
  }
100
130
 
101
131
  /** The shares of one instance. */
@@ -136,6 +166,8 @@ interface PlannedFace {
136
166
 
137
167
  interface Plan {
138
168
  readonly faces: readonly PlannedFace[];
169
+ /** A `remote` share's server: it has no faces of its own (its pages are the server's). */
170
+ readonly server?: string;
139
171
  }
140
172
 
141
173
  /** A running tunnel and the shares that use it. */
@@ -172,9 +204,16 @@ export function createShares(options: SharesOptions): Shares {
172
204
  ledger.read((db) => db.get<ShareRow>("SELECT * FROM share WHERE id = ?", shareId));
173
205
 
174
206
  const toShare = (found: ShareRow): Share => {
175
- // A share follows its link through rotations (`view/rotate`): its token now.
176
- const tokenId = capabilities.current(found.token_id);
177
- const url = found.stopped_at === null ? gateway.reveal(tokenId) : undefined;
207
+ const server = (JSON.parse(found.plan_json) as Plan).server;
208
+ // A share follows its link through rotations (`view/rotate`): its token now. A remote share's
209
+ // link is its hosted home's.
210
+ const tokenId = server === undefined ? capabilities.current(found.token_id) : found.token_id;
211
+ const url =
212
+ found.stopped_at !== null
213
+ ? undefined
214
+ : server === undefined
215
+ ? gateway.reveal(tokenId)
216
+ : options.remote?.url(server, tokenId);
178
217
  const artifactKey = (JSON.parse(found.plan_json) as Plan).faces.find(
179
218
  (face) => face.listener === "artifact",
180
219
  )?.key;
@@ -520,6 +559,53 @@ export function createShares(options: SharesOptions): Shares {
520
559
  }
521
560
  };
522
561
 
562
+ /** A share to a remote server: hosted there, its link minted there (INTERFACES §18.2). */
563
+ const startRemote = async (
564
+ params: ShareStartParams,
565
+ detail: { readonly id: string },
566
+ key: ReturnType<typeof requestKey>,
567
+ ): Promise<ShareStartResult> => {
568
+ const remote = options.remote;
569
+ if (!remote) {
570
+ throw new RpcError(
571
+ createDiagnostic("MOSTRA_HOST_INVALID_PARAMS", {
572
+ message: "This instance shares to no remote server.",
573
+ }),
574
+ -32602,
575
+ );
576
+ }
577
+ const minted = await remote.mint({
578
+ artifactId: detail.id,
579
+ server: params.server,
580
+ scopes: params.scopes,
581
+ ttl: params.ttl,
582
+ viewer: params.viewer,
583
+ });
584
+ const shareId = ShareId.create();
585
+ const startedAt = options.now();
586
+ ledger.write((db) => {
587
+ db.run(
588
+ "INSERT INTO share (id, artifact_id, via, hostname, token_id, mode, plan_json, started_at, expires_at, stopped_at, stop_reason) VALUES (?, ?, 'remote', ?, ?, 'worker', ?, ?, ?, NULL, NULL)",
589
+ shareId,
590
+ detail.id,
591
+ minted.hostname,
592
+ minted.tokenId,
593
+ JSON.stringify({ faces: [], server: minted.server } satisfies Plan),
594
+ iso(startedAt),
595
+ minted.expiresAt ?? null,
596
+ );
597
+ appendEvent(db, {
598
+ artifactId: detail.id,
599
+ type: "share.started",
600
+ payload: { shareId, via: "remote", hostname: minted.hostname, server: minted.server },
601
+ });
602
+ if (key !== undefined) recordResult(db, key, { shareId });
603
+ });
604
+ schedule(shareId, minted.expiresAt);
605
+ log.info("share.started", { shareId, artifactId: detail.id, via: "remote" });
606
+ return { ...toShare(row(shareId) as ShareRow), url: minted.url };
607
+ };
608
+
523
609
  const start = async (params: ShareStartParams): Promise<ShareStartResult> => {
524
610
  const detail = options.artifacts.get(params.artifact);
525
611
  if (!detail.latestVersion && detail.versions.length === 0) {
@@ -535,6 +621,7 @@ export function createShares(options: SharesOptions): Shares {
535
621
  const found = replay ? row(replay.shareId) : undefined;
536
622
  if (found) return withUrl(toShare(found));
537
623
  }
624
+ if (params.via === "remote") return startRemote(params, detail, key);
538
625
  const ttlMs = lifetime(params.via, params.ttl);
539
626
  const shareId = ShareId.create();
540
627
  const { shell, artifact, plan, hostname } = await setUp(
@@ -616,6 +703,12 @@ export function createShares(options: SharesOptions): Shares {
616
703
  const stop = async (shareId: string, reason: string): Promise<Share | undefined> => {
617
704
  const found = row(shareId);
618
705
  if (!found || found.stopped_at !== null) return undefined;
706
+ const server = (JSON.parse(found.plan_json) as Plan).server;
707
+ // A remote share's link lives on its hosted home: revoked there first, so a share listed as
708
+ // stopped never leaves a live link behind (`MOSTRA_REMOTE_UNREACHABLE` keeps it active).
709
+ if (server !== undefined && reason !== "expired" && reason !== "revoked") {
710
+ await options.remote?.revoke(server, found.token_id);
711
+ }
619
712
  const at = options.now();
620
713
  ledger.write((db: LedgerDb) => {
621
714
  db.run(
@@ -624,7 +717,7 @@ export function createShares(options: SharesOptions): Shares {
624
717
  reason,
625
718
  shareId,
626
719
  );
627
- if (reason !== "expired" && reason !== "revoked") {
720
+ if (server === undefined && reason !== "expired" && reason !== "revoked") {
628
721
  capabilities.revoke(capabilities.current(found.token_id), db);
629
722
  }
630
723
  appendEvent(db, {
@@ -645,9 +738,14 @@ export function createShares(options: SharesOptions): Shares {
645
738
  /** Ends shares whose link expired or was revoked since (`view/revoke` of a share's link). */
646
739
  const sweep = async (): Promise<void> => {
647
740
  for (const found of activeRows()) {
741
+ const expired = found.expires_at !== null && Date.parse(found.expires_at) <= options.now();
742
+ // A remote share's link is its hosted home's: only its lifetime is known here.
743
+ if (found.via === "remote") {
744
+ if (expired) await serial(() => stop(found.id, "expired"));
745
+ continue;
746
+ }
648
747
  const grant = capabilities.grant(capabilities.current(found.token_id));
649
748
  if (grant?.live) continue;
650
- const expired = found.expires_at !== null && Date.parse(found.expires_at) <= options.now();
651
749
  await serial(() => stop(found.id, expired ? "expired" : "revoked"));
652
750
  }
653
751
  };
@@ -764,8 +862,14 @@ export function createShares(options: SharesOptions): Shares {
764
862
  async recover() {
765
863
  const pending: Promise<void>[] = [];
766
864
  for (const found of activeRows()) {
767
- const grant = capabilities.grant(capabilities.current(found.token_id));
768
865
  const expired = found.expires_at !== null && Date.parse(found.expires_at) <= options.now();
866
+ // A remote share needs nothing set up again: its pages are the server's.
867
+ if (found.via === "remote") {
868
+ if (expired) await serial(() => stop(found.id, "expired"));
869
+ else schedule(found.id, found.expires_at ?? undefined);
870
+ continue;
871
+ }
872
+ const grant = capabilities.grant(capabilities.current(found.token_id));
769
873
  if (expired || !grant?.live) {
770
874
  await serial(() => stop(found.id, expired ? "expired" : "revoked"));
771
875
  } else if (found.via === "cloudflare") {
@@ -100,6 +100,10 @@ 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 ["MOSTRA_TEST_VERIFY_LOSE_BROWSER", "MOSTRA_TEST_VERIFY_FAIL_ONCE"]) {
104
+ const value = env[name];
105
+ if (value) out[name] = value;
106
+ }
103
107
  return out;
104
108
  }
105
109
 
@@ -187,12 +191,28 @@ export function createRunnerClient(options: {
187
191
  }),
188
192
  );
189
193
  }
194
+ let failure = "";
190
195
  if (outcome.kind === "error" && outcome.error instanceof RpcError) {
191
196
  // 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.
197
+ // channel (the runner died) or an internal error means the runner itself failed.
193
198
  const code = outcome.error.diagnostic.code;
194
199
  if (code !== "MOSTRA_HOST_INTERNAL_ERROR" && !code.startsWith("MOSTRA_HOST_CONNECTION"))
195
200
  throw outcome.error;
201
+ if (code === "MOSTRA_HOST_INTERNAL_ERROR") {
202
+ // Alive but failed in itself: it never answers again. It is stopped, and the request runs
203
+ // once more on a fresh runner, so one broken runner can't fail every later verify (#106's
204
+ // sighting); the page is judged by that try. A runner that died is reported as a crash
205
+ // below, as before, since the page may have killed it.
206
+ failure = outcome.error.diagnostic.message;
207
+ options.log.warn("verify.runner_failed", { method, error: failure.slice(0, 500) });
208
+ if (child) {
209
+ const failed = child;
210
+ child = undefined;
211
+ const stopped = await failed.catch(() => undefined);
212
+ if (stopped) recycled.add(stopped);
213
+ await stopped?.stop(2000);
214
+ }
215
+ }
196
216
  }
197
217
  // Another run's recovery stopped the runner under this request: it isn't this page's fault,
198
218
  // so the request runs once more on a fresh runner (Opus review finding 5). The retry keeps the
@@ -209,9 +229,10 @@ export function createRunnerClient(options: {
209
229
  new Promise<undefined>((done) => setTimeout(() => done(undefined), 1000)),
210
230
  ]);
211
231
  const tail = exit?.stderrTail.slice(-10).join("\n") ?? "";
232
+ const said = failure ? `\nThe runner said: ${failure.slice(0, 1000)}` : "";
212
233
  throw new RpcError(
213
234
  createDiagnostic("MOSTRA_VERIFY_CRASHED", {
214
- message: `The verify runner stopped before it answered${exit ? ` (${exit.signal ?? `code ${exit.code}`})` : ""}.${tail ? `\n${tail}` : ""}`,
235
+ message: `The verify runner stopped before it answered${exit ? ` (${exit.signal ?? `code ${exit.code}`})` : ""}.${tail ? `\n${tail}` : ""}${said}`,
215
236
  }),
216
237
  );
217
238
  };