@mostra/runtime 0.10.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 (245) hide show
  1. package/dist/bin.js +4058 -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-DCiUHvgZ.js} +682 -47
  6. package/dist/instance-DCiUHvgZ.js.map +1 -0
  7. package/dist/reference/cli.md +1322 -0
  8. package/dist/reference/diagnostics.json +1552 -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_TYPE_ERROR.md +23 -0
  172. package/dist/reference/errors/MOSTRA_TYPE_UNTYPED_PACKAGE.md +23 -0
  173. package/dist/reference/errors/MOSTRA_VERIFY_ACTION_SKIPPED.md +23 -0
  174. package/dist/reference/errors/MOSTRA_VERIFY_BASELINE_MISSING.md +23 -0
  175. package/dist/reference/errors/MOSTRA_VERIFY_CRASHED.md +23 -0
  176. package/dist/reference/errors/MOSTRA_VERIFY_LIVE_FAILED.md +23 -0
  177. package/dist/reference/errors/MOSTRA_VERIFY_NO_BASELINE.md +23 -0
  178. package/dist/reference/errors/MOSTRA_VERIFY_SECRET_MISSING.md +23 -0
  179. package/dist/reference/errors/MOSTRA_VERIFY_SKIP_CONSEQUENCE.md +23 -0
  180. package/dist/reference/errors/MOSTRA_VERIFY_TIMEOUT.md +23 -0
  181. package/dist/reference/self-hosting.md +130 -0
  182. package/dist/reference/telemetry.md +84 -0
  183. package/dist/skill/SKILL.md +122 -0
  184. package/dist/skill/assets/examples/dashboard/index.tsx +161 -0
  185. package/dist/skill/assets/examples/dashboard/live.ts +25 -0
  186. package/dist/skill/assets/examples/dashboard/styles.css +125 -0
  187. package/dist/skill/assets/examples/decision/index.tsx +95 -0
  188. package/dist/skill/assets/examples/decision/styles.css +125 -0
  189. package/dist/skill/assets/examples/inbox/actions.ts +23 -0
  190. package/dist/skill/assets/examples/inbox/index.tsx +109 -0
  191. package/dist/skill/assets/examples/inbox/styles.css +125 -0
  192. package/dist/skill/assets/studio.css +125 -0
  193. package/dist/skill/references/answers.md +217 -0
  194. package/dist/skill/references/design.md +154 -0
  195. package/dist/skill/references/libraries.md +167 -0
  196. package/dist/skill/references/long-lived.md +148 -0
  197. package/dist/skill/references/mcp.md +68 -0
  198. package/dist/skill/references/page.md +131 -0
  199. package/dist/skill/references/server.md +146 -0
  200. package/dist/skill/references/sharing.md +123 -0
  201. package/dist/skill/references/verify.md +71 -0
  202. package/package.json +10 -5
  203. package/src/gateway/actions.ts +20 -0
  204. package/src/gateway/browser.ts +44 -0
  205. package/src/gateway/capabilities.ts +8 -0
  206. package/src/gateway/http.ts +12 -1
  207. package/src/gateway/index.ts +170 -5
  208. package/src/gateway/listener.ts +31 -6
  209. package/src/gateway/routes.ts +8 -0
  210. package/src/gc/index.ts +5 -0
  211. package/src/instance/index.ts +20 -1
  212. package/src/interaction/index.ts +60 -0
  213. package/src/interaction/pause.ts +106 -0
  214. package/src/interaction/submissions.ts +42 -1
  215. package/src/interaction/viewers.ts +34 -1
  216. package/src/ledger/index.ts +20 -1
  217. package/src/ledger/migrations.ts +51 -0
  218. package/src/link/author.ts +215 -0
  219. package/src/link/hosted.ts +37 -1
  220. package/src/link/http.ts +6 -1
  221. package/src/link/index.ts +3 -1
  222. package/src/link/manager.ts +138 -34
  223. package/src/protocol-server/client.ts +53 -0
  224. package/src/protocol-server/index.ts +1 -1
  225. package/src/server/api.ts +514 -72
  226. package/src/server/auth.ts +600 -74
  227. package/src/server/authorize.ts +816 -0
  228. package/src/server/clients.ts +235 -0
  229. package/src/server/config.ts +7 -0
  230. package/src/server/data.ts +59 -1
  231. package/src/server/directory.ts +69 -0
  232. package/src/server/feed.ts +191 -0
  233. package/src/server/handle.ts +172 -0
  234. package/src/server/hosted-pages.ts +532 -0
  235. package/src/server/hosted.ts +519 -18
  236. package/src/server/index.ts +343 -61
  237. package/src/server/mcp.ts +330 -0
  238. package/src/server/metering.ts +156 -0
  239. package/src/server/oauth-clients.ts +510 -0
  240. package/src/server/operator.ts +498 -0
  241. package/src/server/providers.ts +284 -0
  242. package/src/server/remove.ts +148 -0
  243. package/src/server/routing.ts +275 -0
  244. package/src/verify/runner.ts +23 -2
  245. package/dist/instance-FExcyENK.js.map +0 -1
@@ -323,6 +323,35 @@ export interface SubmitOutcome {
323
323
  * `MOSTRA_SUBMIT_POLICY_NONE`, `MOSTRA_SUBMIT_ALREADY` (a {@link SubmitConflict}) under `once`,
324
324
  * `MOSTRA_SUBMIT_REVISION_MOVED` when the draft changed since the viewer saw it.
325
325
  */
326
+ /**
327
+ * Whether a submit would be judged afresh: not a repeat of one already recorded (which answers that
328
+ * submission), not refused by the view or a pause before anything is recorded. Only such a submit
329
+ * is admitted by the server's rates and the operator's limits (Fable review of WP-30, 8).
330
+ */
331
+ export function wouldRecord(
332
+ db: LedgerDb,
333
+ input: Pick<SubmitInput, "artifactId" | "viewerId" | "tokenId" | "viewId" | "expectedRevision">,
334
+ ): boolean {
335
+ try {
336
+ const view = viewFor(db, input.viewId, input.artifactId, input.viewerId, input.tokenId);
337
+ const draft = documentFor(db, input.artifactId, input.viewerId, false);
338
+ if (
339
+ draft !== undefined &&
340
+ db.get(
341
+ "SELECT 1 FROM submission WHERE view_id = ? AND draft_document_id = ? AND draft_revision = ?",
342
+ view.id,
343
+ draft.id,
344
+ input.expectedRevision,
345
+ )
346
+ ) {
347
+ return false;
348
+ }
349
+ return !db.get("SELECT 1 FROM artifact_pause WHERE artifact_id = ?", input.artifactId);
350
+ } catch {
351
+ return false;
352
+ }
353
+ }
354
+
326
355
  export function submit(db: LedgerDb, input: SubmitInput): SubmitOutcome {
327
356
  // 1. The view, and through it the exact version the viewer saw, and the channels it accepts.
328
357
  const view = viewFor(db, input.viewId, input.artifactId, input.viewerId, input.tokenId);
@@ -339,7 +368,19 @@ export function submit(db: LedgerDb, input: SubmitInput): SubmitOutcome {
339
368
  if (repeat)
340
369
  return { submission: { ...submissionSummary(db, repeat), duplicate: true }, created: false };
341
370
 
342
- // 2. The policy in force.
371
+ // 2. The policy in force, and whether the artifact takes answers now: a paused one takes none
372
+ // until resumed, whoever paused it, and the draft stays as it was (D165 item 14).
373
+ const paused = db.get<{ by: string }>(
374
+ "SELECT by FROM artifact_pause WHERE artifact_id = ? ORDER BY by = 'operator' DESC LIMIT 1",
375
+ input.artifactId,
376
+ );
377
+ if (paused) {
378
+ throw new RpcError(
379
+ createDiagnostic("MOSTRA_SUBMIT_PAUSED", {
380
+ message: `This page is paused${paused.by === "operator" ? " by its server's operator" : ""}: it takes no answers until it is resumed, and the draft is kept.`,
381
+ }),
382
+ );
383
+ }
343
384
  const artifact = db.get<{ policy_json: string | null; latest_version_id: string | null }>(
344
385
  "SELECT policy_json, latest_version_id FROM artifact WHERE id = ?",
345
386
  input.artifactId,
@@ -57,6 +57,9 @@ function viewerOf(row: ViewerRow): Viewer {
57
57
  ...(row.kind === "token" || row.kind === "host" || row.kind === "tailnet"
58
58
  ? { ref: row.external_ref }
59
59
  : {}),
60
+ // A hosted account's name is its identity provider's; an anonymous viewer's, their own.
61
+ ...(row.kind === "account" ? { verified: true } : {}),
62
+ ...(row.kind === "anonymous" ? { verified: false } : {}),
60
63
  };
61
64
  }
62
65
 
@@ -110,7 +113,37 @@ export function viewerForLink(db: LedgerDb, tokenId: string, name: string): stri
110
113
  return viewerByRef(db, "token", { ref: `link:${tokenId}`, name });
111
114
  }
112
115
 
113
- function viewerByRef(db: LedgerDb, kind: "token" | "host" | "tailnet", spec: ViewerSpec): string {
116
+ /**
117
+ * A signed-in person on a hosted link minted without a viewer (D165 item 8): one viewer of kind
118
+ * `account` per account, named as its identity provider verified it.
119
+ */
120
+ export function viewerForAccount(db: LedgerDb, accountId: string, name?: string): string {
121
+ return viewerByRef(db, "account", { ref: accountId, ...(name !== undefined ? { name } : {}) });
122
+ }
123
+
124
+ /**
125
+ * A person who isn't signed in on a hosted link minted without a viewer (D165 item 8): one viewer
126
+ * of kind `anonymous` per browser and route, by the route's derived key
127
+ * (`HMAC-SHA-256(browser secret, routeId)`), never the shell's raw secret. A name they choose is
128
+ * set apart, unverified ({@link nameAnonymous}).
129
+ */
130
+ export function viewerForAnonymous(db: LedgerDb, key: string): string {
131
+ return viewerByRef(db, "anonymous", { ref: key });
132
+ }
133
+
134
+ /** Sets the self-chosen, unverified name of an anonymous viewer; any other viewer is left alone. */
135
+ export function nameAnonymous(db: LedgerDb, viewerId: string, name: string | null): boolean {
136
+ return (
137
+ db.run("UPDATE viewer SET name = ? WHERE id = ? AND kind = 'anonymous'", name, viewerId)
138
+ .changes > 0
139
+ );
140
+ }
141
+
142
+ function viewerByRef(
143
+ db: LedgerDb,
144
+ kind: "token" | "host" | "tailnet" | "account" | "anonymous",
145
+ spec: ViewerSpec,
146
+ ): string {
114
147
  const found = db.get<ViewerRow>(
115
148
  "SELECT * FROM viewer WHERE kind = ? AND external_ref = ?",
116
149
  kind,
@@ -29,7 +29,7 @@ export {
29
29
  recordResult,
30
30
  requestKey,
31
31
  } from "./requests.ts";
32
- export type { LedgerDb } from "./types.ts";
32
+ export type { LedgerDb, MigrationDb, SqlValue } from "./types.ts";
33
33
 
34
34
  /** The ledger's file name inside `<home>/store`. */
35
35
  export const LEDGER_FILE = "ledger.sqlite";
@@ -81,6 +81,13 @@ export interface Ledger {
81
81
  * `MOSTRA_HOME_DISK_FULL`; a removed ledger throws `MOSTRA_HOME_GONE`. Nothing partial commits.
82
82
  */
83
83
  write<T>(fn: (db: LedgerDb) => T): T;
84
+ /**
85
+ * Runs `fn` in one write transaction that may also drop and create triggers: the one path past
86
+ * the write-once triggers, for a remote server operator's explicit removal of an artifact
87
+ * (`ServerHandle.remove`, DATA_MODEL §7.5), which recreates every trigger it dropped before it
88
+ * commits. Nothing else calls it.
89
+ */
90
+ removal<T>(fn: (db: MigrationDb) => T): T;
84
91
  /** Runs `fn` in one read transaction, so it sees a single consistent state. */
85
92
  read<T>(fn: (db: LedgerDb) => T): T;
86
93
  /**
@@ -444,6 +451,18 @@ function wrap(
444
451
  }
445
452
  return result;
446
453
  },
454
+ removal<T>(fn: (db: MigrationDb) => T): T {
455
+ assertInPlace();
456
+ const result = guarded(() => db.transaction(() => fn(target)).immediate());
457
+ for (const listener of listeners) {
458
+ try {
459
+ listener();
460
+ } catch {
461
+ // A listener's failure is its own; the commit stands.
462
+ }
463
+ }
464
+ return result;
465
+ },
447
466
  onCommit(listener) {
448
467
  listeners.add(listener);
449
468
  return () => listeners.delete(listener);
@@ -837,4 +837,55 @@ export const MIGRATIONS: readonly Migration[] = [
837
837
  `);
838
838
  },
839
839
  },
840
+ {
841
+ version: 14,
842
+ name: "pause, quarantine and the operator's cursor",
843
+ up(db) {
844
+ // D165 items 9 and 14 (DATA_MODEL §7.2). A paused artifact keeps a row while paused, and an
845
+ // operator's pause is removed only by the operator; a quarantine names a route's artifact, or
846
+ // one version of it, in this home only. The operator's cursor is how far this home's events
847
+ // were turned into the operator's outbound events (at least once, stable IDs; WP-30).
848
+ db.exec(`
849
+ CREATE TABLE artifact_pause (
850
+ artifact_id TEXT PRIMARY KEY REFERENCES artifact(id),
851
+ by TEXT NOT NULL CHECK (by IN ('owner', 'operator')),
852
+ reason TEXT,
853
+ paused_at TEXT NOT NULL
854
+ );
855
+ CREATE TABLE quarantine (
856
+ artifact_id TEXT NOT NULL REFERENCES artifact(id),
857
+ version_id TEXT NOT NULL DEFAULT '',
858
+ reason TEXT NOT NULL,
859
+ at TEXT NOT NULL,
860
+ PRIMARY KEY (artifact_id, version_id)
861
+ );
862
+ CREATE TABLE operator_cursor (
863
+ id INTEGER PRIMARY KEY CHECK (id = 1),
864
+ cursor INTEGER NOT NULL CHECK (cursor >= 0)
865
+ );
866
+ `);
867
+ },
868
+ },
869
+ {
870
+ version: 15,
871
+ name: "an owner's pause and an operator's, apart",
872
+ up(db) {
873
+ // An owner's pause and an operator's are kept apart, one row each, so neither one's resume
874
+ // lifts the other's (Fable review of WP-30, 7): the artifact takes answers again only once
875
+ // no pause is left.
876
+ db.exec(`
877
+ CREATE TABLE artifact_pause_by (
878
+ artifact_id TEXT NOT NULL REFERENCES artifact(id),
879
+ by TEXT NOT NULL CHECK (by IN ('owner', 'operator')),
880
+ reason TEXT,
881
+ paused_at TEXT NOT NULL,
882
+ PRIMARY KEY (artifact_id, by)
883
+ );
884
+ INSERT INTO artifact_pause_by (artifact_id, by, reason, paused_at)
885
+ SELECT artifact_id, by, reason, paused_at FROM artifact_pause;
886
+ DROP TABLE artifact_pause;
887
+ ALTER TABLE artifact_pause_by RENAME TO artifact_pause;
888
+ `);
889
+ },
890
+ },
840
891
  ];
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Authoring from a chat host, on the owner instance (INTERFACES §18.8, D165 item 5): the remote MCP
3
+ * server relays `artifact/create`, `verify` and `publish`, and the workspace's files, to the
4
+ * account's default owner instance as `port/relay.author`, and this module runs each here, on this
5
+ * home's own protocol server, in an in-process session as any host would (invariant 11).
6
+ *
7
+ * The relay is a way in from outside this machine, so every directory it names stays inside this
8
+ * home's MCP workspace (`MOSTRA_MCP_WORKSPACE`, default `~/mostra-artifacts`, as `mostra mcp`'s):
9
+ * a relative one resolves there, an absolute one must already be there, and anything else is
10
+ * `MOSTRA_ARTIFACT_PATH_INVALID`. A screenshot is read only from verify's own cache. A publish also
11
+ * hosts the version on the server that asked and answers its hosted link.
12
+ */
13
+ import { realpathSync } from "node:fs";
14
+ import { readFile } from "node:fs/promises";
15
+ import { isAbsolute, join, relative, resolve } from "node:path";
16
+ import { defaultWorkspaceRoot, localWorkspace } from "@mostra/mcp";
17
+ import {
18
+ artifactCreateMethod,
19
+ artifactGetMethod,
20
+ artifactPublishMethod,
21
+ artifactVerifyMethod,
22
+ createDiagnostic,
23
+ portRelayAuthorMethod,
24
+ RpcError,
25
+ shareStartMethod,
26
+ } from "@mostra/protocol";
27
+ import type { Environment, Log } from "../log.ts";
28
+ import { attachInProcess, type ProtocolServer } from "../protocol-server/index.ts";
29
+
30
+ /** What the owner's authoring needs. */
31
+ export interface OwnerAuthorOptions {
32
+ readonly home: string;
33
+ readonly env: Environment;
34
+ readonly log: Log;
35
+ readonly runtimeVersion: string;
36
+ /** This home's protocol server, once it exists. */
37
+ readonly protocol: () => ProtocolServer | undefined;
38
+ /** The servers an artifact is hosted on now. */
39
+ readonly hostedOn: (artifactId: string) => readonly string[];
40
+ }
41
+
42
+ /** Answers `port/relay.author` from the server `server`. */
43
+ export type OwnerAuthor = (server: string, params: unknown) => Promise<unknown>;
44
+
45
+ /** The eight bytes every PNG file starts with. */
46
+ const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
47
+
48
+ function outside(message: string): RpcError {
49
+ return new RpcError(createDiagnostic("MOSTRA_ARTIFACT_PATH_INVALID", { message }));
50
+ }
51
+
52
+ /** Whether `inner` is `outer` or inside it. */
53
+ function within(outer: string, inner: string): boolean {
54
+ const between = relative(outer, inner);
55
+ return between === "" || (!between.startsWith("..") && !isAbsolute(between));
56
+ }
57
+
58
+ /** Creates the owner's answer to relayed authoring. */
59
+ export function createOwnerAuthor(options: OwnerAuthorOptions): OwnerAuthor {
60
+ const configured = options.env["MOSTRA_MCP_WORKSPACE"];
61
+ const root = resolve(
62
+ configured !== undefined && configured !== "" ? configured : defaultWorkspaceRoot(),
63
+ );
64
+ const workspace = localWorkspace(root);
65
+ const verifyCache = join(options.home, "cache", "verify");
66
+
67
+ /** A directory the relay names, inside the workspace or refused. */
68
+ const dirOf = (dir: unknown): string => {
69
+ if (typeof dir !== "string" || dir === "") throw outside("Name an artifact's directory.");
70
+ const absolute = isAbsolute(dir) ? resolve(dir) : workspace.resolveDir(dir);
71
+ let real = absolute;
72
+ try {
73
+ real = realpathSync.native(absolute);
74
+ } catch {
75
+ // A directory not made yet is judged by its name.
76
+ }
77
+ let base = root;
78
+ try {
79
+ base = realpathSync.native(root);
80
+ } catch {
81
+ // The workspace not made yet: no real path to compare against beyond its name.
82
+ }
83
+ if (!within(root, absolute) || !within(base, real)) {
84
+ throw outside(
85
+ `A chat host's authoring stays inside this machine's Mostra workspace (${root}); ${dir} is outside it.`,
86
+ );
87
+ }
88
+ return absolute;
89
+ };
90
+
91
+ /** One call on this home's protocol server, in a session of its own. */
92
+ const local = async <P, R>(
93
+ method: { readonly method: string } & Parameters<
94
+ Awaited<ReturnType<typeof attachInProcess>>["client"]["peer"]["call"]
95
+ >[0],
96
+ params: P,
97
+ ): Promise<R> => {
98
+ const protocol = options.protocol();
99
+ if (protocol === undefined) {
100
+ throw new RpcError(
101
+ createDiagnostic("MOSTRA_REMOTE_NO_INSTANCE", {
102
+ message: "This Mostra instance is still starting; try again in a moment.",
103
+ }),
104
+ );
105
+ }
106
+ const { client } = await attachInProcess(protocol, {
107
+ name: "mostra-remote-author",
108
+ version: options.runtimeVersion,
109
+ });
110
+ try {
111
+ return (await client.peer.call(method, params as never)) as R;
112
+ } finally {
113
+ client.close();
114
+ }
115
+ };
116
+
117
+ return async (server, raw) => {
118
+ const { method, params } = portRelayAuthorMethod.params.parse(raw);
119
+ const given = (params ?? {}) as Record<string, unknown>;
120
+ options.log.info("link.author", { server, method });
121
+ switch (method) {
122
+ case "workspace/root":
123
+ return root;
124
+ case "workspace/allocate":
125
+ return workspace.allocateDir(
126
+ typeof given["title"] === "string" ? given["title"] : undefined,
127
+ );
128
+ case "workspace/read": {
129
+ const content = await workspace.read(dirOf(given["dir"]), String(given["path"] ?? ""));
130
+ return content === undefined ? {} : { content: Buffer.from(content).toString("base64") };
131
+ }
132
+ case "workspace/apply": {
133
+ const write = Array.isArray(given["write"]) ? given["write"] : [];
134
+ const deletes = Array.isArray(given["delete"]) ? given["delete"] : [];
135
+ return workspace.apply(dirOf(given["dir"]), {
136
+ write: write.map((file) => {
137
+ const entry = file as { path?: unknown; content?: unknown };
138
+ return {
139
+ path: String(entry.path ?? ""),
140
+ content: Buffer.from(String(entry.content ?? ""), "base64"),
141
+ };
142
+ }),
143
+ delete: deletes.map(String),
144
+ });
145
+ }
146
+ case "verify/screenshot": {
147
+ const path = resolve(String(given["path"] ?? ""));
148
+ let real = path;
149
+ try {
150
+ real = realpathSync.native(path);
151
+ } catch {
152
+ return {};
153
+ }
154
+ // Only verify's own screenshots: a `.png` inside its cache, by name and by where the name
155
+ // really leads, whose bytes are a PNG; nothing else of the cache (a run's scratch ledger,
156
+ // its keys, a cached verdict) crosses the relay (Fable review of WP-30, 10).
157
+ if (
158
+ !path.toLowerCase().endsWith(".png") ||
159
+ !within(verifyCache, path) ||
160
+ !within(realpathSync.native(verifyCache), real)
161
+ ) {
162
+ return {};
163
+ }
164
+ try {
165
+ const bytes = await readFile(real);
166
+ return bytes.subarray(0, PNG_SIGNATURE.length).equals(PNG_SIGNATURE)
167
+ ? { png: bytes.toString("base64") }
168
+ : {};
169
+ } catch {
170
+ return {};
171
+ }
172
+ }
173
+ case "artifact/create":
174
+ return local(artifactCreateMethod, { ...given, dir: dirOf(given["dir"]) });
175
+ case "artifact/get": {
176
+ // The relay asks which artifact a directory is; it learns that and its title, never this
177
+ // home's own links (their secrets open its local pages) or anything else of the artifact.
178
+ const artifact = given["artifact"] as { path?: unknown; artifactId?: unknown } | undefined;
179
+ const detail = await local<object, { id: string; title: string }>(artifactGetMethod, {
180
+ artifact:
181
+ artifact?.path !== undefined
182
+ ? { path: dirOf(artifact.path) }
183
+ : { artifactId: String(artifact?.artifactId ?? "") },
184
+ });
185
+ return { id: detail.id, title: detail.title };
186
+ }
187
+ case "artifact/verify": {
188
+ const source = given["source"] as { path?: unknown } | undefined;
189
+ return local(artifactVerifyMethod, { ...given, source: { path: dirOf(source?.path) } });
190
+ }
191
+ case "artifact/publish": {
192
+ const source = given["source"] as { path?: unknown } | undefined;
193
+ const receipt = await local<object, { artifactId: string; url?: string; tokenId?: string }>(
194
+ artifactPublishMethod,
195
+ { ...given, source: { path: dirOf(source?.path) } },
196
+ );
197
+ // A publish from a chat host also hosts the version on the server it came through
198
+ // (D165 item 5): a first share there pushes it; once hosted, every publish is pushed.
199
+ if (!options.hostedOn(receipt.artifactId).includes(server)) {
200
+ await local(shareStartMethod, {
201
+ artifact: { artifactId: receipt.artifactId },
202
+ via: "remote",
203
+ server,
204
+ });
205
+ }
206
+ // The receipt crosses the relay without this home's default link: its secret opens the
207
+ // local page, and the server answers its own hosted link instead.
208
+ const { url: _local, tokenId: _token, ...crossing } = receipt;
209
+ return crossing;
210
+ }
211
+ default:
212
+ throw outside(`The relay serves no authoring method ${method as string}.`);
213
+ }
214
+ };
215
+ }
@@ -5,14 +5,16 @@
5
5
  * can't be reached, and are never applied here alone.
6
6
  */
7
7
  import {
8
+ type ArtifactPauseResult,
8
9
  type ArtifactRef,
10
+ artifactPauseMethod,
9
11
  livePushMethod,
10
12
  MutationId,
11
13
  stateGetMethod,
12
14
  statePatchMethod,
13
15
  } from "@mostra/protocol";
14
16
  import type { HostedState } from "../actions/index.ts";
15
- import type { MethodHandler } from "../protocol-server/index.ts";
17
+ import { handler, type MethodHandler } from "../protocol-server/index.ts";
16
18
  import type { Link } from "./manager.ts";
17
19
 
18
20
  const FORWARDED = new Set([stateGetMethod.method, statePatchMethod.method, livePushMethod.method]);
@@ -63,3 +65,37 @@ export function forwardHosted(
63
65
  };
64
66
  });
65
67
  }
68
+
69
+ /**
70
+ * The owner's `artifact/pause` (D165 item 14): pauses or resumes the artifact here and on every
71
+ * server it is hosted on, each as its owner. A server where the operator paused it answers that
72
+ * only the operator resumes it (`MOSTRA_REMOTE_PAUSED_BY_OPERATOR`); one that can't be reached is
73
+ * `MOSTRA_REMOTE_UNREACHABLE`, and the call can be made again, since a pause is idempotent.
74
+ */
75
+ export function pauseHandler(
76
+ link: Link,
77
+ resolve: (ref: ArtifactRef) => string,
78
+ pause: (
79
+ artifactId: string,
80
+ change: { readonly paused: boolean; readonly by: "owner"; readonly reason?: string },
81
+ ) => ArtifactPauseResult,
82
+ ): MethodHandler {
83
+ return handler(artifactPauseMethod, async (params) => {
84
+ const artifactId = resolve(params.artifact);
85
+ let byOperator = false;
86
+ for (const server of link.hostedServers(artifactId)) {
87
+ const answer = await link.forward(server, artifactPauseMethod, {
88
+ artifact: { artifactId },
89
+ paused: params.paused,
90
+ ...(params.reason !== undefined ? { reason: params.reason } : {}),
91
+ });
92
+ if (answer.by === "operator") byOperator = true;
93
+ }
94
+ const local = pause(artifactId, {
95
+ paused: params.paused,
96
+ by: "owner",
97
+ ...(params.reason !== undefined ? { reason: params.reason } : {}),
98
+ });
99
+ return byOperator ? { paused: true, by: "operator" } : local;
100
+ });
101
+ }
package/src/link/http.ts CHANGED
@@ -116,10 +116,15 @@ export async function postForm(
116
116
  path: string,
117
117
  fields: Record<string, string>,
118
118
  connectTo?: RemoteAddress,
119
+ bearer?: string,
119
120
  ): Promise<{ status: number; json: Record<string, unknown> }> {
120
121
  const answer = await remoteRequest(server, path, {
121
122
  method: "POST",
122
- headers: { "content-type": "application/x-www-form-urlencoded", accept: "application/json" },
123
+ headers: {
124
+ "content-type": "application/x-www-form-urlencoded",
125
+ accept: "application/json",
126
+ ...(bearer !== undefined ? { authorization: `Bearer ${bearer}` } : {}),
127
+ },
123
128
  body: new URLSearchParams(fields).toString(),
124
129
  ...(connectTo ? { connectTo } : {}),
125
130
  });
package/src/link/index.ts CHANGED
@@ -3,6 +3,8 @@
3
3
  * binding, sign-in, the sync cursor and the relay. One public entry, as every runtime module
4
4
  * (REPO_STANDARDS §3).
5
5
  */
6
+
7
+ export { createOwnerAuthor } from "./author.ts";
6
8
  export { type Binding, ownerInitialize, startBinding } from "./binding.ts";
7
- export { forwardHosted, hostedState } from "./hosted.ts";
9
+ export { forwardHosted, hostedState, pauseHandler } from "./hosted.ts";
8
10
  export { createLink, type Link } from "./manager.ts";