@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
@@ -837,4 +837,90 @@ 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
+ },
891
+ {
892
+ version: 16,
893
+ name: "expected respondents and the roster's rounds",
894
+ up(db) {
895
+ // The people an artifact expects answers from (D121, D168): one row per respondent, keyed by
896
+ // the host's stable key, acting as one viewer of kind `token` (D104) through a personal link.
897
+ // `roster_state` keeps the round and whether it is complete, so a completion is told once.
898
+ // Presence is never stored: no table holds it (D47, CO-04).
899
+ db.exec(`
900
+ CREATE TABLE roster_entry (
901
+ artifact_id TEXT NOT NULL REFERENCES artifact(id),
902
+ ref TEXT NOT NULL CHECK (length(ref) BETWEEN 1 AND 256),
903
+ name TEXT,
904
+ email TEXT,
905
+ viewer_id TEXT NOT NULL REFERENCES viewer(id),
906
+ token_id TEXT REFERENCES token(id),
907
+ position INTEGER NOT NULL,
908
+ added_at TEXT NOT NULL,
909
+ PRIMARY KEY (artifact_id, ref),
910
+ UNIQUE (artifact_id, viewer_id),
911
+ UNIQUE (artifact_id, position)
912
+ );
913
+ CREATE TABLE roster_state (
914
+ artifact_id TEXT PRIMARY KEY REFERENCES artifact(id),
915
+ round INTEGER NOT NULL CHECK (round >= 1),
916
+ round_cursor INTEGER NOT NULL CHECK (round_cursor >= 0),
917
+ round_started_at TEXT NOT NULL,
918
+ complete INTEGER NOT NULL CHECK (complete IN (0, 1))
919
+ );
920
+ CREATE TRIGGER roster_state_round_grows BEFORE UPDATE OF round, round_cursor ON roster_state
921
+ WHEN NEW.round < OLD.round OR NEW.round_cursor < OLD.round_cursor
922
+ BEGIN SELECT RAISE(ABORT, 'a roster round never goes back'); END;
923
+ `);
924
+ },
925
+ },
840
926
  ];
@@ -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,17 +5,30 @@
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,
13
+ rosterAddMethod,
14
+ rosterGetMethod,
15
+ rosterRemoveMethod,
11
16
  stateGetMethod,
12
17
  statePatchMethod,
13
18
  } from "@mostra/protocol";
14
19
  import type { HostedState } from "../actions/index.ts";
15
- import type { MethodHandler } from "../protocol-server/index.ts";
20
+ import { handler, type MethodHandler } from "../protocol-server/index.ts";
16
21
  import type { Link } from "./manager.ts";
17
22
 
18
- const FORWARDED = new Set([stateGetMethod.method, statePatchMethod.method, livePushMethod.method]);
23
+ const FORWARDED = new Set([
24
+ stateGetMethod.method,
25
+ statePatchMethod.method,
26
+ livePushMethod.method,
27
+ // The roster and its personal links are the hosted home's: its viewers answer there (D168).
28
+ rosterAddMethod.method,
29
+ rosterRemoveMethod.method,
30
+ rosterGetMethod.method,
31
+ ]);
19
32
 
20
33
  /** Server code's `state` for an artifact hosted somewhere, else `undefined`. */
21
34
  export function hostedState(link: Link, artifactId: string): HostedState | undefined {
@@ -41,8 +54,8 @@ export function hostedState(link: Link, artifactId: string): HostedState | undef
41
54
  }
42
55
 
43
56
  /**
44
- * Wraps the instance's `state/get`, `state/patch` and `live/push` so that, for a hosted artifact,
45
- * they act on its hosted home: the same params, the artifact named by its ID there.
57
+ * Wraps the instance's `state/get`, `state/patch`, `live/push` and `roster/*` so that, for a hosted
58
+ * artifact, they act on its hosted home: the same params, the artifact named by its ID there.
46
59
  */
47
60
  export function forwardHosted(
48
61
  link: Link,
@@ -63,3 +76,37 @@ export function forwardHosted(
63
76
  };
64
77
  });
65
78
  }
79
+
80
+ /**
81
+ * The owner's `artifact/pause` (D165 item 14): pauses or resumes the artifact here and on every
82
+ * server it is hosted on, each as its owner. A server where the operator paused it answers that
83
+ * only the operator resumes it (`MOSTRA_REMOTE_PAUSED_BY_OPERATOR`); one that can't be reached is
84
+ * `MOSTRA_REMOTE_UNREACHABLE`, and the call can be made again, since a pause is idempotent.
85
+ */
86
+ export function pauseHandler(
87
+ link: Link,
88
+ resolve: (ref: ArtifactRef) => string,
89
+ pause: (
90
+ artifactId: string,
91
+ change: { readonly paused: boolean; readonly by: "owner"; readonly reason?: string },
92
+ ) => ArtifactPauseResult,
93
+ ): MethodHandler {
94
+ return handler(artifactPauseMethod, async (params) => {
95
+ const artifactId = resolve(params.artifact);
96
+ let byOperator = false;
97
+ for (const server of link.hostedServers(artifactId)) {
98
+ const answer = await link.forward(server, artifactPauseMethod, {
99
+ artifact: { artifactId },
100
+ paused: params.paused,
101
+ ...(params.reason !== undefined ? { reason: params.reason } : {}),
102
+ });
103
+ if (answer.by === "operator") byOperator = true;
104
+ }
105
+ const local = pause(artifactId, {
106
+ paused: params.paused,
107
+ by: "owner",
108
+ ...(params.reason !== undefined ? { reason: params.reason } : {}),
109
+ });
110
+ return byOperator ? { paused: true, by: "operator" } : local;
111
+ });
112
+ }
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";