@stage-labs/metro 0.1.0-beta.24 → 0.1.0-beta.241

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 (473) hide show
  1. package/dist/api.js +9 -129
  2. package/dist/background.js +123 -0
  3. package/dist/claude-settings.js +40 -0
  4. package/dist/claude.js +197 -0
  5. package/dist/cli.js +59 -111
  6. package/dist/control.js +19 -103
  7. package/dist/hold.js +210 -0
  8. package/dist/local.js +43 -0
  9. package/dist/mcp-config.js +27 -0
  10. package/dist/memory.js +222 -0
  11. package/dist/node-name.js +71 -0
  12. package/dist/onboarding.js +44 -0
  13. package/dist/provider-flags.js +9 -0
  14. package/dist/route.js +58 -0
  15. package/dist/runtime-install.js +96 -0
  16. package/dist/runtime.js +29 -52
  17. package/dist/serve.js +157 -0
  18. package/dist/service.js +304 -0
  19. package/dist/tail.js +10 -11
  20. package/dist/update.js +13 -1
  21. package/dist/voice.js +56 -0
  22. package/package.json +2 -23
  23. package/runtime/marketplace/.claude-plugin/marketplace.json +12 -0
  24. package/runtime/marketplace/plugin/.claude-plugin/plugin.json +17 -0
  25. package/runtime/marketplace/plugin/.mcp.json +1 -0
  26. package/runtime/marketplace/plugin/MEMORY.md +78 -0
  27. package/runtime/marketplace/plugin/METRO.md +26 -0
  28. package/runtime/marketplace/plugin/STAGE.md +75 -0
  29. package/runtime/marketplace/plugin/bin/guard.mjs +75 -0
  30. package/runtime/marketplace/plugin/bin/metro-plugin.mjs +30 -0
  31. package/runtime/marketplace/plugin/bin/policy.mjs +97 -0
  32. package/runtime/marketplace/plugin/bin/session-start.mjs +31 -0
  33. package/runtime/marketplace/plugin/hooks/hooks.json +25 -0
  34. package/runtime/node_modules/@metro-labs/core/package.json +51 -0
  35. package/runtime/node_modules/@metro-labs/core/src/endpoints.ts +7 -0
  36. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/events.ts +11 -7
  37. package/runtime/node_modules/@metro-labs/{mcp/src/db → core/src}/ids.ts +5 -0
  38. package/runtime/node_modules/@metro-labs/core/src/is-record.ts +2 -0
  39. package/runtime/node_modules/@metro-labs/{mcp/src/stations → core/src}/lines.ts +22 -26
  40. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/protocol.ts +7 -4
  41. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/secure-fs.ts +17 -0
  42. package/runtime/node_modules/@metro-labs/core/src/station-names.ts +14 -0
  43. package/runtime/node_modules/@metro-labs/core/src/stations/account-files.ts +41 -0
  44. package/runtime/node_modules/@metro-labs/core/src/stations/account-store.ts +83 -0
  45. package/runtime/node_modules/@metro-labs/{mcp → core}/src/stations/attachments.ts +0 -1
  46. package/runtime/node_modules/@metro-labs/core/src/stations/mail-text.ts +72 -0
  47. package/runtime/node_modules/@metro-labs/core/src/stations/mail-trust.ts +29 -0
  48. package/runtime/node_modules/@metro-labs/core/src/stations/mail.ts +212 -0
  49. package/runtime/node_modules/@metro-labs/core/src/stations/messaging-normalize.ts +16 -0
  50. package/runtime/node_modules/@metro-labs/core/src/stations/oauth.ts +126 -0
  51. package/runtime/node_modules/@metro-labs/core/src/stations/profile.ts +58 -0
  52. package/runtime/node_modules/@metro-labs/core/src/stations/sender-profile.ts +64 -0
  53. package/runtime/node_modules/@metro-labs/{mcp → core}/src/stations/station-runtime.ts +6 -11
  54. package/runtime/node_modules/@metro-labs/core/src/stations/train-boot.ts +42 -0
  55. package/runtime/node_modules/@metro-labs/core/src/stations/train-events.ts +84 -0
  56. package/runtime/node_modules/@metro-labs/{mcp → core}/src/stations/types.ts +19 -1
  57. package/runtime/node_modules/@metro-labs/core/src/tickets.ts +37 -0
  58. package/runtime/node_modules/@metro-labs/core/src/version.ts +2 -0
  59. package/runtime/node_modules/@metro-labs/daemon/package.json +51 -0
  60. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/agent-fs.ts +134 -0
  61. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/crontab.ts +44 -0
  62. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/files-api.ts +12 -0
  63. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/files.ts +89 -0
  64. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/home-fs.ts +113 -0
  65. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/job-env.ts +39 -0
  66. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/provision.ts +80 -0
  67. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedule-detail.ts +99 -0
  68. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedules-api.ts +27 -0
  69. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedules.ts +144 -0
  70. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/unit-files.ts +43 -0
  71. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/user.ts +91 -0
  72. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/view.ts +87 -0
  73. package/runtime/node_modules/@metro-labs/daemon/src/agents/account-attach.ts +19 -0
  74. package/runtime/node_modules/@metro-labs/daemon/src/agents/account-lookups.ts +55 -0
  75. package/runtime/node_modules/@metro-labs/daemon/src/agents/account-routes.ts +76 -0
  76. package/runtime/node_modules/@metro-labs/daemon/src/agents/accounts-api.ts +357 -0
  77. package/runtime/node_modules/@metro-labs/daemon/src/agents/admin.ts +30 -0
  78. package/runtime/node_modules/@metro-labs/daemon/src/agents/allowlist.ts +59 -0
  79. package/runtime/node_modules/@metro-labs/daemon/src/agents/api.ts +131 -0
  80. package/runtime/node_modules/@metro-labs/daemon/src/agents/bundle.ts +132 -0
  81. package/runtime/node_modules/@metro-labs/daemon/src/agents/file-admin.ts +305 -0
  82. package/runtime/node_modules/@metro-labs/daemon/src/agents/files.ts +142 -0
  83. package/runtime/node_modules/@metro-labs/{mcp/src/db/key-map.ts → daemon/src/agents/keys.ts} +1 -11
  84. package/runtime/node_modules/@metro-labs/daemon/src/agents/map.ts +133 -0
  85. package/runtime/node_modules/@metro-labs/daemon/src/agents/policy-route.ts +27 -0
  86. package/runtime/node_modules/@metro-labs/{mcp/src/db/agent-scope.ts → daemon/src/agents/scope.ts} +2 -2
  87. package/runtime/node_modules/@metro-labs/daemon/src/agents/sender-cards.ts +94 -0
  88. package/runtime/node_modules/@metro-labs/daemon/src/agents/senders.ts +38 -0
  89. package/runtime/node_modules/@metro-labs/daemon/src/approvals/api.ts +55 -0
  90. package/runtime/node_modules/@metro-labs/daemon/src/approvals/pending.ts +150 -0
  91. package/runtime/node_modules/@metro-labs/daemon/src/approvals/preview.ts +66 -0
  92. package/runtime/node_modules/@metro-labs/daemon/src/boot/boot.ts +231 -0
  93. package/runtime/node_modules/@metro-labs/daemon/src/boot/connect-hint.ts +36 -0
  94. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/boot}/crash-guard.ts +1 -1
  95. package/runtime/node_modules/@metro-labs/daemon/src/boot/local-owner.ts +21 -0
  96. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/boot}/paths.ts +6 -34
  97. package/runtime/node_modules/@metro-labs/daemon/src/channels/addressed.ts +26 -0
  98. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/inbound.ts +75 -45
  99. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/media-note.ts +11 -7
  100. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/pending.ts +4 -1
  101. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/relay.ts +2 -2
  102. package/runtime/node_modules/@metro-labs/daemon/src/claude/api.ts +380 -0
  103. package/runtime/node_modules/@metro-labs/daemon/src/claude/files.ts +359 -0
  104. package/runtime/node_modules/@metro-labs/daemon/src/claude/login.ts +208 -0
  105. package/runtime/node_modules/@metro-labs/daemon/src/claude/memory-routine.ts +123 -0
  106. package/runtime/node_modules/@metro-labs/daemon/src/claude/memory.ts +32 -0
  107. package/runtime/node_modules/@metro-labs/daemon/src/claude/onboarding.ts +60 -0
  108. package/runtime/node_modules/@metro-labs/daemon/src/claude/plugin-install.ts +149 -0
  109. package/runtime/node_modules/@metro-labs/daemon/src/claude/session-files.ts +75 -0
  110. package/runtime/node_modules/@metro-labs/daemon/src/claude/session.ts +299 -0
  111. package/runtime/node_modules/@metro-labs/daemon/src/claude/settings.ts +109 -0
  112. package/runtime/node_modules/@metro-labs/daemon/src/claude/setup.ts +351 -0
  113. package/runtime/node_modules/@metro-labs/daemon/src/claude/skills.ts +120 -0
  114. package/runtime/node_modules/@metro-labs/daemon/src/claude/usage-probe.ts +127 -0
  115. package/runtime/node_modules/@metro-labs/daemon/src/claude/version.ts +113 -0
  116. package/runtime/node_modules/@metro-labs/{mcp/src/daemon/connector-api.ts → daemon/src/connectors/api.ts} +79 -113
  117. package/runtime/node_modules/@metro-labs/{mcp/src/db/connector-config.ts → daemon/src/connectors/config.ts} +67 -41
  118. package/runtime/node_modules/@metro-labs/daemon/src/connectors/gates.ts +72 -0
  119. package/runtime/node_modules/@metro-labs/daemon/src/connectors/health.ts +18 -0
  120. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/connectors}/oauth-client.ts +14 -17
  121. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/connectors}/oauth-discovery.ts +33 -20
  122. package/runtime/node_modules/@metro-labs/{mcp/src/daemon/connector-oauth-routes.ts → daemon/src/connectors/oauth-routes.ts} +30 -32
  123. package/runtime/node_modules/@metro-labs/{mcp/src/daemon/connector-oauth.ts → daemon/src/connectors/oauth.ts} +61 -22
  124. package/runtime/node_modules/@metro-labs/daemon/src/connectors/plugin-sync.ts +131 -0
  125. package/runtime/node_modules/@metro-labs/daemon/src/connectors/reach.ts +27 -0
  126. package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay-policy.ts +90 -0
  127. package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay.ts +347 -0
  128. package/runtime/node_modules/@metro-labs/daemon/src/connectors/store.ts +385 -0
  129. package/runtime/node_modules/@metro-labs/daemon/src/connectors/tools.ts +81 -0
  130. package/runtime/node_modules/@metro-labs/daemon/src/connectors/transfer-api.ts +116 -0
  131. package/runtime/node_modules/@metro-labs/daemon/src/connectors/transfer-crypto.ts +44 -0
  132. package/runtime/node_modules/@metro-labs/daemon/src/connectors/transfer-store.ts +48 -0
  133. package/runtime/node_modules/@metro-labs/daemon/src/connectors/url.ts +37 -0
  134. package/runtime/node_modules/@metro-labs/daemon/src/connectors/verify.ts +106 -0
  135. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/attach-grant.ts +4 -4
  136. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/attach-owner.ts +3 -3
  137. package/runtime/node_modules/@metro-labs/daemon/src/files/attach-reaper.ts +174 -0
  138. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/attach-serve.ts +12 -13
  139. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/upload-api.ts +10 -27
  140. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/upload-store.ts +4 -4
  141. package/runtime/node_modules/@metro-labs/daemon/src/gateway/bedrock.ts +233 -0
  142. package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-auth.ts +214 -0
  143. package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-device.ts +91 -0
  144. package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-stream.ts +173 -0
  145. package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-translate.ts +209 -0
  146. package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-version.ts +44 -0
  147. package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex.ts +155 -0
  148. package/runtime/node_modules/@metro-labs/daemon/src/gateway/effort.ts +93 -0
  149. package/runtime/node_modules/@metro-labs/daemon/src/gateway/eventstream.ts +123 -0
  150. package/runtime/node_modules/@metro-labs/daemon/src/gateway/forward.ts +237 -0
  151. package/runtime/node_modules/@metro-labs/daemon/src/gateway/frames.ts +118 -0
  152. package/runtime/node_modules/@metro-labs/daemon/src/gateway/gateway.ts +307 -0
  153. package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-auth.ts +160 -0
  154. package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-client.ts +46 -0
  155. package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-setup.ts +150 -0
  156. package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-stream.ts +139 -0
  157. package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-translate.ts +235 -0
  158. package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini.ts +208 -0
  159. package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-api.ts +203 -0
  160. package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-config.ts +285 -0
  161. package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-lists.ts +57 -0
  162. package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-signin.ts +161 -0
  163. package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-store.ts +72 -0
  164. package/runtime/node_modules/@metro-labs/daemon/src/gateway/openrouter.ts +104 -0
  165. package/runtime/node_modules/@metro-labs/daemon/src/gateway/pkce.ts +36 -0
  166. package/runtime/node_modules/@metro-labs/daemon/src/gateway/provider-models.ts +118 -0
  167. package/runtime/node_modules/@metro-labs/daemon/src/gateway/served.ts +18 -0
  168. package/runtime/node_modules/@metro-labs/daemon/src/gateway/subscription.ts +120 -0
  169. package/runtime/node_modules/@metro-labs/daemon/src/gateway/text.ts +35 -0
  170. package/runtime/node_modules/@metro-labs/daemon/src/gateway/tool-search.ts +126 -0
  171. package/runtime/node_modules/@metro-labs/daemon/src/gateway/usage-refresh.ts +102 -0
  172. package/runtime/node_modules/@metro-labs/daemon/src/gateway/usage.ts +348 -0
  173. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/accounts.ts +28 -17
  174. package/runtime/node_modules/@metro-labs/daemon/src/mcp/attachment-schema.ts +91 -0
  175. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/call-tools.ts +81 -38
  176. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/ctx.ts +4 -4
  177. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/event-store.ts +15 -16
  178. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/group-tools.ts +2 -2
  179. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/index.ts +37 -79
  180. package/runtime/node_modules/@metro-labs/daemon/src/mcp/instructions.ts +30 -0
  181. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/member-tools.ts +2 -2
  182. package/runtime/node_modules/@metro-labs/daemon/src/mcp/permission-prompt.ts +92 -0
  183. package/runtime/node_modules/@metro-labs/daemon/src/mcp/permission-relay.ts +88 -0
  184. package/runtime/node_modules/@metro-labs/daemon/src/mcp/policy-gate.ts +82 -0
  185. package/runtime/node_modules/@metro-labs/daemon/src/mcp/policy-snapshot.ts +79 -0
  186. package/runtime/node_modules/@metro-labs/daemon/src/mcp/profile-lookup.ts +60 -0
  187. package/runtime/node_modules/@metro-labs/daemon/src/mcp/profile-tool.ts +96 -0
  188. package/runtime/node_modules/@metro-labs/daemon/src/mcp/read-tool.ts +87 -0
  189. package/runtime/node_modules/@metro-labs/daemon/src/mcp/request-identity.ts +46 -0
  190. package/runtime/node_modules/@metro-labs/daemon/src/mcp/session-slot.ts +75 -0
  191. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/session.ts +61 -57
  192. package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-catalog.ts +93 -0
  193. package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-def.ts +9 -0
  194. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/tool-dispatch.ts +53 -40
  195. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/tool-schemas.ts +97 -114
  196. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/upload-tool.ts +6 -11
  197. package/runtime/node_modules/@metro-labs/daemon/src/metro-user/helper-script.ts +126 -0
  198. package/runtime/node_modules/@metro-labs/daemon/src/metro-user/install.ts +37 -0
  199. package/runtime/node_modules/@metro-labs/daemon/src/metro-user/privilege.ts +48 -0
  200. package/runtime/node_modules/@metro-labs/daemon/src/monitor/api.ts +132 -0
  201. package/runtime/node_modules/@metro-labs/daemon/src/net/tunnel.ts +316 -0
  202. package/runtime/node_modules/@metro-labs/daemon/src/policy/policy.ts +118 -0
  203. package/runtime/node_modules/@metro-labs/daemon/src/routes/bearer.ts +35 -0
  204. package/runtime/node_modules/@metro-labs/daemon/src/routes/body.ts +24 -0
  205. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/routes}/http.ts +65 -52
  206. package/runtime/node_modules/@metro-labs/daemon/src/routes/local-mode.ts +209 -0
  207. package/runtime/node_modules/@metro-labs/daemon/src/routes/session-apis.ts +71 -0
  208. package/runtime/node_modules/@metro-labs/daemon/src/routes/session.ts +29 -0
  209. package/runtime/node_modules/@metro-labs/daemon/src/routes/threema-callback.ts +103 -0
  210. package/runtime/node_modules/@metro-labs/daemon/src/server/cloudwatch.ts +178 -0
  211. package/runtime/node_modules/@metro-labs/daemon/src/server/control.ts +39 -0
  212. package/runtime/node_modules/@metro-labs/daemon/src/server/machine.ts +58 -0
  213. package/runtime/node_modules/@metro-labs/daemon/src/server/owner.ts +26 -0
  214. package/runtime/node_modules/@metro-labs/daemon/src/server/update.ts +90 -0
  215. package/runtime/node_modules/@metro-labs/daemon/src/server.ts +2 -0
  216. package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-browser.ts +102 -0
  217. package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-driver.ts +42 -0
  218. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-inline.ts +29 -1
  219. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-interactive.ts +5 -31
  220. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-resolve.ts +38 -13
  221. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/attach-session.ts +32 -22
  222. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-xmtp.ts +8 -9
  223. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach.ts +69 -3
  224. package/runtime/node_modules/@metro-labs/{mcp/src/db → daemon/src/stations}/materialize.ts +60 -175
  225. package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/registry.ts +20 -2
  226. package/runtime/node_modules/@metro-labs/daemon/src/stations/runtime-deps.ts +82 -0
  227. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/supervisor-io.ts +3 -3
  228. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/supervisor.ts +6 -9
  229. package/runtime/node_modules/@metro-labs/daemon/src/stations/threema-callbacks.ts +32 -0
  230. package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/train-call.ts +1 -1
  231. package/runtime/node_modules/@metro-labs/daemon/src/stations/webhook-endpoints.ts +51 -0
  232. package/runtime/node_modules/@metro-labs/daemon/src/terminal/api.ts +84 -0
  233. package/runtime/node_modules/@metro-labs/daemon/src/terminal/socket.ts +124 -0
  234. package/runtime/node_modules/@metro-labs/daemon/src/terminal/tickets.ts +15 -0
  235. package/runtime/node_modules/@metro-labs/daemon/src/vault/api.ts +45 -0
  236. package/runtime/node_modules/@metro-labs/daemon/src/vault/config.ts +51 -0
  237. package/runtime/node_modules/@metro-labs/daemon/src/vault/firewall.ts +9 -0
  238. package/runtime/node_modules/@metro-labs/daemon/src/vault/index.ts +96 -0
  239. package/runtime/node_modules/@metro-labs/daemon/src/vault/install.ts +56 -0
  240. package/runtime/node_modules/@metro-labs/daemon/src/vault/paths.ts +26 -0
  241. package/runtime/node_modules/@metro-labs/daemon/src/vault/proxy.ts +147 -0
  242. package/runtime/node_modules/@metro-labs/daemon/src/vault/store.ts +129 -0
  243. package/runtime/node_modules/@metro-labs/daemon/src/vault/trust.ts +44 -0
  244. package/runtime/node_modules/@metro-labs/daemon/src/voice/api.ts +14 -0
  245. package/runtime/node_modules/@metro-labs/daemon/src/voice/approvals.ts +43 -0
  246. package/runtime/node_modules/@metro-labs/daemon/src/voice/audio.ts +153 -0
  247. package/runtime/node_modules/@metro-labs/daemon/src/voice/brain.ts +135 -0
  248. package/runtime/node_modules/@metro-labs/daemon/src/voice/call.ts +200 -0
  249. package/runtime/node_modules/@metro-labs/daemon/src/voice/calls.ts +130 -0
  250. package/runtime/node_modules/@metro-labs/daemon/src/voice/peer.ts +84 -0
  251. package/runtime/node_modules/@metro-labs/daemon/src/voice/scribe.ts +103 -0
  252. package/runtime/node_modules/@metro-labs/daemon/src/voice/speakable.ts +54 -0
  253. package/runtime/node_modules/@metro-labs/daemon/src/voice/speech.ts +104 -0
  254. package/runtime/node_modules/@metro-labs/daemon/src/voice/store.ts +116 -0
  255. package/runtime/node_modules/@metro-labs/daemon/src/voice/talk.ts +256 -0
  256. package/runtime/node_modules/@metro-labs/discord-bot/package.json +2 -4
  257. package/runtime/node_modules/@metro-labs/discord-bot/src/accounts.ts +3 -23
  258. package/runtime/node_modules/@metro-labs/discord-bot/src/actions.ts +19 -187
  259. package/runtime/node_modules/@metro-labs/discord-bot/src/attachments.ts +2 -2
  260. package/runtime/node_modules/@metro-labs/discord-bot/src/format.ts +26 -67
  261. package/runtime/node_modules/@metro-labs/discord-bot/src/group-actions.ts +1 -1
  262. package/runtime/node_modules/@metro-labs/discord-bot/src/group.ts +2 -2
  263. package/runtime/node_modules/@metro-labs/discord-bot/src/index.ts +8 -14
  264. package/runtime/node_modules/@metro-labs/discord-bot/src/members.ts +2 -2
  265. package/runtime/node_modules/@metro-labs/discord-bot/src/profile.ts +68 -0
  266. package/runtime/node_modules/@metro-labs/discord-bot/src/send-files.ts +12 -13
  267. package/runtime/node_modules/@metro-labs/discord-bot/src/station.ts +5 -1
  268. package/runtime/node_modules/@metro-labs/gmail/package.json +25 -0
  269. package/runtime/node_modules/@metro-labs/gmail/src/accounts.ts +81 -0
  270. package/runtime/node_modules/@metro-labs/gmail/src/actions.ts +14 -0
  271. package/runtime/node_modules/@metro-labs/gmail/src/api.ts +31 -0
  272. package/runtime/node_modules/@metro-labs/gmail/src/attachments.ts +35 -0
  273. package/runtime/node_modules/@metro-labs/gmail/src/auth.ts +105 -0
  274. package/runtime/node_modules/@metro-labs/gmail/src/config.ts +13 -0
  275. package/runtime/node_modules/@metro-labs/gmail/src/inbound.ts +96 -0
  276. package/runtime/node_modules/@metro-labs/gmail/src/index.ts +12 -0
  277. package/runtime/node_modules/@metro-labs/gmail/src/login.ts +37 -0
  278. package/runtime/node_modules/@metro-labs/gmail/src/message.ts +125 -0
  279. package/runtime/node_modules/@metro-labs/gmail/src/mime.ts +70 -0
  280. package/runtime/node_modules/@metro-labs/gmail/src/outbound.ts +124 -0
  281. package/runtime/node_modules/@metro-labs/gmail/src/query.ts +99 -0
  282. package/runtime/node_modules/@metro-labs/gmail/src/state.ts +24 -0
  283. package/runtime/node_modules/@metro-labs/gmail/src/station.ts +15 -0
  284. package/runtime/node_modules/@metro-labs/gmail/src/trust.ts +42 -0
  285. package/runtime/node_modules/@metro-labs/http/package.json +30 -0
  286. package/runtime/node_modules/@metro-labs/http/src/api-http.ts +135 -0
  287. package/runtime/node_modules/@metro-labs/{mcp/src/daemon/session-api.ts → http/src/mode-api.ts} +13 -9
  288. package/runtime/node_modules/@metro-labs/http/src/return-to.ts +21 -0
  289. package/runtime/node_modules/@metro-labs/http/src/sigv4.ts +90 -0
  290. package/runtime/node_modules/@metro-labs/http/src/workos-token.ts +149 -0
  291. package/runtime/node_modules/@metro-labs/outlook/package.json +25 -0
  292. package/runtime/node_modules/@metro-labs/outlook/src/accounts.ts +78 -0
  293. package/runtime/node_modules/@metro-labs/outlook/src/actions.ts +14 -0
  294. package/runtime/node_modules/@metro-labs/outlook/src/attachments.ts +81 -0
  295. package/runtime/node_modules/@metro-labs/outlook/src/auth.ts +120 -0
  296. package/runtime/node_modules/@metro-labs/outlook/src/browser.ts +42 -0
  297. package/runtime/node_modules/@metro-labs/outlook/src/config.ts +23 -0
  298. package/runtime/node_modules/@metro-labs/outlook/src/format.ts +59 -0
  299. package/runtime/node_modules/@metro-labs/outlook/src/graph.ts +55 -0
  300. package/runtime/node_modules/@metro-labs/outlook/src/inbound.ts +96 -0
  301. package/runtime/node_modules/@metro-labs/outlook/src/index.ts +12 -0
  302. package/runtime/node_modules/@metro-labs/outlook/src/login.ts +129 -0
  303. package/runtime/node_modules/@metro-labs/outlook/src/me.ts +31 -0
  304. package/runtime/node_modules/@metro-labs/outlook/src/outbound.ts +103 -0
  305. package/runtime/node_modules/@metro-labs/outlook/src/query.ts +84 -0
  306. package/runtime/node_modules/@metro-labs/outlook/src/state.ts +28 -0
  307. package/runtime/node_modules/@metro-labs/outlook/src/station.ts +15 -0
  308. package/runtime/node_modules/@metro-labs/outlook/src/trust.ts +41 -0
  309. package/runtime/node_modules/@metro-labs/telegram/package.json +1 -3
  310. package/runtime/node_modules/@metro-labs/telegram/src/accounts.ts +5 -24
  311. package/runtime/node_modules/@metro-labs/telegram/src/actions.ts +8 -6
  312. package/runtime/node_modules/@metro-labs/telegram/src/attachments.ts +1 -1
  313. package/runtime/node_modules/@metro-labs/telegram/src/client.ts +2 -2
  314. package/runtime/node_modules/@metro-labs/telegram/src/format.ts +19 -34
  315. package/runtime/node_modules/@metro-labs/telegram/src/group.ts +3 -3
  316. package/runtime/node_modules/@metro-labs/telegram/src/inbound.ts +13 -34
  317. package/runtime/node_modules/@metro-labs/telegram/src/index.ts +4 -43
  318. package/runtime/node_modules/@metro-labs/telegram/src/media-actions.ts +2 -3
  319. package/runtime/node_modules/@metro-labs/telegram/src/members.ts +1 -1
  320. package/runtime/node_modules/@metro-labs/telegram/src/profile.ts +70 -0
  321. package/runtime/node_modules/@metro-labs/telegram/src/reactions.ts +2 -2
  322. package/runtime/node_modules/@metro-labs/telegram/src/station.ts +4 -1
  323. package/runtime/node_modules/@metro-labs/telegram/src/types.ts +0 -1
  324. package/runtime/node_modules/@metro-labs/telegram-bot/package.json +1 -1
  325. package/runtime/node_modules/@metro-labs/telegram-bot/src/accounts.ts +7 -41
  326. package/runtime/node_modules/@metro-labs/telegram-bot/src/actions.ts +22 -77
  327. package/runtime/node_modules/@metro-labs/telegram-bot/src/attachments.ts +2 -2
  328. package/runtime/node_modules/@metro-labs/telegram-bot/src/format.ts +46 -48
  329. package/runtime/node_modules/@metro-labs/telegram-bot/src/index.ts +15 -15
  330. package/runtime/node_modules/@metro-labs/telegram-bot/src/media-actions.ts +6 -82
  331. package/runtime/node_modules/@metro-labs/telegram-bot/src/members.ts +1 -1
  332. package/runtime/node_modules/@metro-labs/telegram-bot/src/profile.ts +85 -0
  333. package/runtime/node_modules/@metro-labs/telegram-bot/src/station.ts +5 -1
  334. package/runtime/node_modules/@metro-labs/telegram-bot/src/types.ts +20 -12
  335. package/runtime/node_modules/@metro-labs/threema/package.json +26 -0
  336. package/runtime/node_modules/@metro-labs/threema/src/accounts.ts +96 -0
  337. package/runtime/node_modules/@metro-labs/threema/src/actions.ts +124 -0
  338. package/runtime/node_modules/@metro-labs/threema/src/api.ts +152 -0
  339. package/runtime/node_modules/@metro-labs/threema/src/crypto.ts +100 -0
  340. package/runtime/node_modules/@metro-labs/threema/src/files.ts +47 -0
  341. package/runtime/node_modules/@metro-labs/threema/src/format.ts +164 -0
  342. package/runtime/node_modules/@metro-labs/threema/src/groups.ts +96 -0
  343. package/runtime/node_modules/@metro-labs/threema/src/ids.ts +21 -0
  344. package/runtime/node_modules/@metro-labs/threema/src/inbound.ts +87 -0
  345. package/runtime/node_modules/@metro-labs/threema/src/index.ts +24 -0
  346. package/runtime/node_modules/@metro-labs/threema/src/messages.ts +264 -0
  347. package/runtime/node_modules/@metro-labs/threema/src/outbound.ts +160 -0
  348. package/runtime/node_modules/@metro-labs/threema/src/station.ts +13 -0
  349. package/runtime/node_modules/@metro-labs/threema/src/verify.ts +117 -0
  350. package/runtime/node_modules/@metro-labs/webhook/package.json +1 -1
  351. package/runtime/node_modules/@metro-labs/webhook/src/station.ts +5 -8
  352. package/runtime/node_modules/@metro-labs/whatsapp/package.json +2 -5
  353. package/runtime/node_modules/@metro-labs/whatsapp/src/accounts.ts +6 -28
  354. package/runtime/node_modules/@metro-labs/whatsapp/src/ack.ts +1 -1
  355. package/runtime/node_modules/@metro-labs/whatsapp/src/actions.ts +54 -11
  356. package/runtime/node_modules/@metro-labs/whatsapp/src/attachments.ts +2 -2
  357. package/runtime/node_modules/@metro-labs/whatsapp/src/auth-state.ts +1 -1
  358. package/runtime/node_modules/@metro-labs/whatsapp/src/client.ts +86 -4
  359. package/runtime/node_modules/@metro-labs/whatsapp/src/format.ts +7 -58
  360. package/runtime/node_modules/@metro-labs/whatsapp/src/inbound.ts +11 -28
  361. package/runtime/node_modules/@metro-labs/whatsapp/src/index.ts +4 -37
  362. package/runtime/node_modules/@metro-labs/whatsapp/src/keys.ts +1 -1
  363. package/runtime/node_modules/@metro-labs/whatsapp/src/login.ts +1 -1
  364. package/runtime/node_modules/@metro-labs/whatsapp/src/media.ts +1 -1
  365. package/runtime/node_modules/@metro-labs/whatsapp/src/names.ts +75 -0
  366. package/runtime/node_modules/@metro-labs/whatsapp/src/parse.ts +44 -0
  367. package/runtime/node_modules/@metro-labs/whatsapp/src/resolve.ts +52 -0
  368. package/runtime/node_modules/@metro-labs/whatsapp/src/station.ts +16 -1
  369. package/runtime/node_modules/@metro-labs/whatsapp/src/token-store.ts +5 -9
  370. package/runtime/node_modules/@metro-labs/whatsapp/src/types.ts +0 -1
  371. package/runtime/node_modules/@metro-labs/xmtp/package.json +3 -2
  372. package/runtime/node_modules/@metro-labs/xmtp/src/accounts.ts +10 -20
  373. package/runtime/node_modules/@metro-labs/xmtp/src/actions-close.ts +2 -2
  374. package/runtime/node_modules/@metro-labs/xmtp/src/actions-conv.ts +35 -220
  375. package/runtime/node_modules/@metro-labs/xmtp/src/actions-meta.ts +40 -53
  376. package/runtime/node_modules/@metro-labs/xmtp/src/actions.ts +95 -222
  377. package/runtime/node_modules/@metro-labs/xmtp/src/attachments.ts +3 -3
  378. package/runtime/node_modules/@metro-labs/xmtp/src/call-leftovers.ts +48 -0
  379. package/runtime/node_modules/@metro-labs/xmtp/src/codecs.ts +95 -3
  380. package/runtime/node_modules/@metro-labs/xmtp/src/conv-helpers.ts +11 -7
  381. package/runtime/node_modules/@metro-labs/xmtp/src/delete-requests.ts +34 -0
  382. package/runtime/node_modules/@metro-labs/xmtp/src/emit-payloads.ts +37 -25
  383. package/runtime/node_modules/@metro-labs/xmtp/src/emit.ts +8 -18
  384. package/runtime/node_modules/@metro-labs/xmtp/src/frames.ts +178 -0
  385. package/runtime/node_modules/@metro-labs/xmtp/src/group-members.ts +1 -1
  386. package/runtime/node_modules/@metro-labs/xmtp/src/group.ts +2 -2
  387. package/runtime/node_modules/@metro-labs/xmtp/src/identity.ts +30 -16
  388. package/runtime/node_modules/@metro-labs/xmtp/src/index.ts +13 -20
  389. package/runtime/node_modules/@metro-labs/xmtp/src/labels.ts +57 -33
  390. package/runtime/node_modules/@metro-labs/xmtp/src/member-args.ts +1 -1
  391. package/runtime/node_modules/@metro-labs/xmtp/src/names.ts +61 -0
  392. package/runtime/node_modules/@metro-labs/xmtp/src/profile.ts +153 -0
  393. package/runtime/node_modules/@metro-labs/xmtp/src/resolve.ts +44 -0
  394. package/runtime/node_modules/@metro-labs/xmtp/src/sender.ts +112 -0
  395. package/runtime/node_modules/@metro-labs/xmtp/src/smart.ts +72 -0
  396. package/runtime/node_modules/@metro-labs/xmtp/src/station.ts +8 -2
  397. package/runtime/node_modules/@metro-labs/xmtp/src/tools-handlers.ts +22 -58
  398. package/runtime/node_modules/@metro-labs/xmtp/src/tools.ts +55 -48
  399. package/runtime/node_modules/@metro-labs/xmtp/src/transcribe.ts +4 -6
  400. package/runtime/node_modules/@metro-labs/xmtp/src/verify.ts +19 -5
  401. package/runtime/node_modules/@metro-labs/xmtp/src/wire.ts +14 -4
  402. package/runtime/runtime.json +1 -1
  403. package/runtime/server.ts +1 -0
  404. package/runtime/stations.json +40 -0
  405. package/dist/prompt.js +0 -61
  406. package/dist/store.js +0 -70
  407. package/runtime/node_modules/@metro-labs/discord-bot/src/voice-speak.ts +0 -195
  408. package/runtime/node_modules/@metro-labs/discord-bot/src/voice-transcribe.ts +0 -292
  409. package/runtime/node_modules/@metro-labs/discord-bot/src/voice.ts +0 -197
  410. package/runtime/node_modules/@metro-labs/discord-bot/src/wire.ts +0 -5
  411. package/runtime/node_modules/@metro-labs/mcp/package.json +0 -66
  412. package/runtime/node_modules/@metro-labs/mcp/src/channels/dedupe.ts +0 -24
  413. package/runtime/node_modules/@metro-labs/mcp/src/daemon/account-api.ts +0 -311
  414. package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-api.ts +0 -341
  415. package/runtime/node_modules/@metro-labs/mcp/src/daemon/api-http.ts +0 -129
  416. package/runtime/node_modules/@metro-labs/mcp/src/daemon/boot.ts +0 -320
  417. package/runtime/node_modules/@metro-labs/mcp/src/daemon/cli-pair-api.ts +0 -111
  418. package/runtime/node_modules/@metro-labs/mcp/src/daemon/cli-pair.ts +0 -20
  419. package/runtime/node_modules/@metro-labs/mcp/src/daemon/collection-api.ts +0 -202
  420. package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-json.ts +0 -31
  421. package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-tools.ts +0 -100
  422. package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-url.ts +0 -57
  423. package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-verify.ts +0 -333
  424. package/runtime/node_modules/@metro-labs/mcp/src/daemon/google-auth.ts +0 -164
  425. package/runtime/node_modules/@metro-labs/mcp/src/daemon/google-oauth.ts +0 -208
  426. package/runtime/node_modules/@metro-labs/mcp/src/daemon/identity.ts +0 -79
  427. package/runtime/node_modules/@metro-labs/mcp/src/daemon/oauth-pending.ts +0 -65
  428. package/runtime/node_modules/@metro-labs/mcp/src/daemon/pair-codes.ts +0 -58
  429. package/runtime/node_modules/@metro-labs/mcp/src/daemon/project-api.ts +0 -214
  430. package/runtime/node_modules/@metro-labs/mcp/src/daemon/run-api.ts +0 -125
  431. package/runtime/node_modules/@metro-labs/mcp/src/daemon/run-pair.ts +0 -18
  432. package/runtime/node_modules/@metro-labs/mcp/src/daemon/runtime-source.ts +0 -105
  433. package/runtime/node_modules/@metro-labs/mcp/src/daemon/session-apis.ts +0 -41
  434. package/runtime/node_modules/@metro-labs/mcp/src/daemon/session.ts +0 -218
  435. package/runtime/node_modules/@metro-labs/mcp/src/daemon/tunnel.ts +0 -169
  436. package/runtime/node_modules/@metro-labs/mcp/src/db/account-attach.ts +0 -91
  437. package/runtime/node_modules/@metro-labs/mcp/src/db/agent-admin.ts +0 -215
  438. package/runtime/node_modules/@metro-labs/mcp/src/db/agent-map.ts +0 -71
  439. package/runtime/node_modules/@metro-labs/mcp/src/db/client.ts +0 -37
  440. package/runtime/node_modules/@metro-labs/mcp/src/db/connector-collections.ts +0 -218
  441. package/runtime/node_modules/@metro-labs/mcp/src/db/connectors.ts +0 -329
  442. package/runtime/node_modules/@metro-labs/mcp/src/db/projects.ts +0 -300
  443. package/runtime/node_modules/@metro-labs/mcp/src/db/runtime-admin.ts +0 -31
  444. package/runtime/node_modules/@metro-labs/mcp/src/db/runtimes.ts +0 -105
  445. package/runtime/node_modules/@metro-labs/mcp/src/db/schema.ts +0 -131
  446. package/runtime/node_modules/@metro-labs/mcp/src/db/token-carry.ts +0 -45
  447. package/runtime/node_modules/@metro-labs/mcp/src/db/users.ts +0 -57
  448. package/runtime/node_modules/@metro-labs/mcp/src/db/whatsapp-login.ts +0 -18
  449. package/runtime/node_modules/@metro-labs/mcp/src/mcp/channel-owner.ts +0 -29
  450. package/runtime/node_modules/@metro-labs/mcp/src/mcp/frame-scope.ts +0 -21
  451. package/runtime/node_modules/@metro-labs/mcp/src/mcp/permission-relay.ts +0 -66
  452. package/runtime/node_modules/@metro-labs/mcp/src/mcp/request-identity.ts +0 -73
  453. package/runtime/node_modules/@metro-labs/mcp/src/mcp/session-registry.ts +0 -172
  454. package/runtime/node_modules/@metro-labs/mcp/src/mcp/session-route.ts +0 -43
  455. package/runtime/node_modules/@metro-labs/mcp/src/monitor/api.ts +0 -240
  456. package/runtime/node_modules/@metro-labs/mcp/src/server.ts +0 -2
  457. package/runtime/node_modules/@metro-labs/mcp/src/stations/account-store.ts +0 -80
  458. package/runtime/node_modules/@metro-labs/mcp/src/stations/messaging-normalize.ts +0 -88
  459. package/runtime/node_modules/@metro-labs/telegram/src/normalize.ts +0 -22
  460. package/runtime/node_modules/@metro-labs/telegram/src/wire.ts +0 -1
  461. package/runtime/node_modules/@metro-labs/telegram-bot/src/wire.ts +0 -3
  462. package/runtime/node_modules/@metro-labs/whatsapp/src/normalize.ts +0 -22
  463. package/runtime/node_modules/@metro-labs/whatsapp/src/wire.ts +0 -5
  464. package/runtime/node_modules/@metro-labs/xmtp/src/actions-push.ts +0 -87
  465. package/runtime/node_modules/@metro-labs/xmtp/src/emit-core.ts +0 -55
  466. package/runtime/node_modules/@metro-labs/xmtp/src/push.ts +0 -349
  467. /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/log.ts +0 -0
  468. /package/runtime/node_modules/@metro-labs/{mcp/src/mcp → core/src}/str.ts +0 -0
  469. /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/train-error.ts +0 -0
  470. /package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/webhook-note.ts +0 -0
  471. /package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/raw-get-stream.ts +0 -0
  472. /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → http/src}/api-error.ts +0 -0
  473. /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → http/src}/cors.ts +0 -0
@@ -1,3 +1,6 @@
1
+ import type { ToolDef } from './tool-def.js';
2
+ import { attachmentItem, CREATE_UPLOAD_TOOL } from './attachment-schema.js';
3
+
1
4
  const lineProp = {
2
5
  type: 'string',
3
6
  description:
@@ -8,98 +11,10 @@ const msgIdProp = {
8
11
  description: 'The target message_id.',
9
12
  } as const;
10
13
 
11
- const attachmentItem = {
12
- type: 'object',
13
- description:
14
- 'A file to attach. Provide EXACTLY ONE source; naming two is an error and so is naming ' +
15
- 'none. Which one to use: `upload` for any real file on your own machine, including a ' +
16
- 'confidential one (call `create_upload` first, push the bytes over HTTP, then name the ' +
17
- 'id here); `data` ONLY for a tiny file, a few KB at most, because the base64 has to be ' +
18
- 'written out verbatim in this tool call and long base64 gets corrupted in the writing; ' +
19
- '`url` when the file is ALREADY published somewhere the daemon can fetch it; `path` ONLY ' +
20
- 'for a file that is already sitting on the daemon host, which is almost never your ' +
21
- 'machine.',
22
- properties: {
23
- upload: {
24
- type: 'string',
25
- description:
26
- 'The `upload_id` of a file already pushed to metro over HTTP (`create_upload` mints ' +
27
- 'the slot and the one-line command; the bytes never pass through this conversation). ' +
28
- 'THIS IS THE ROUTE FOR ANYTHING REAL: it takes files up to 64 MiB, works for a file on ' +
29
- 'your own machine, and publishes nothing. The upload belongs to your agent, expires ' +
30
- '30 minutes after it is created, and no other agent can name it.',
31
- },
32
- data: {
33
- type: 'string',
34
- description:
35
- 'Base64-encoded file bytes, inline in this call. ONLY FOR TINY FILES. The hard cap is ' +
36
- '8 MiB decoded, but the real ceiling is far lower and is not enforced by the daemon: ' +
37
- 'this base64 has to be emitted verbatim as part of the tool call, and past roughly ' +
38
- '10 KB (~13 KB of base64) it comes out corrupted, so the file arrives silently ' +
39
- 'damaged or fails to decode. Use `upload` instead for anything bigger. A ' +
40
- '`data:<mime>;base64,` prefix is accepted and supplies the mime when `mime` is ' +
41
- 'omitted. Stations impose their own, lower limits (xmtp refuses non-image files over ' +
42
- '~190 KiB).',
43
- },
44
- url: {
45
- type: 'string',
46
- description:
47
- 'http(s) URL fetched BY THE DAEMON, so it must already be publicly reachable from the ' +
48
- 'daemon host. Right when the file is already published; never for anything ' +
49
- 'confidential, because it has to be public for this to work at all. Use `upload` for ' +
50
- 'a confidential file.',
51
- },
52
- path: {
53
- type: 'string',
54
- description:
55
- 'Absolute path resolved ON THE DAEMON HOST, which is a different machine from yours. ' +
56
- 'A path on your own disk does NOT resolve here and is refused, however local it ' +
57
- 'looks. Use `upload` for a file on your machine.',
58
- },
59
- mime: {
60
- type: 'string',
61
- description: 'MIME type (guessed from the name/extension if omitted).',
62
- },
63
- name: {
64
- type: 'string',
65
- description:
66
- 'Filename to present (defaults to the basename, or to the name given at upload time).',
67
- },
68
- },
69
- } as const;
70
-
71
- const CREATE_UPLOAD_TOOL = {
72
- name: 'create_upload',
73
- description:
74
- 'Reserve a slot to push a file to metro over HTTP so you can attach it with `send`. Use ' +
75
- 'this for any file that actually matters: it is the only attachment route that carries a ' +
76
- 'file from YOUR machine without publishing it and without the bytes passing through this ' +
77
- 'conversation. Args: name? (the filename to present), mime?. Returns `upload_id`, a ' +
78
- 'single-use `upload_url` and a ready-to-run `curl` line. ONE STEP NEEDS A SHELL: run that ' +
79
- 'command (or any HTTP client) to push the bytes; there is no way to move a local file to ' +
80
- 'the daemon over MCP alone, because anything in an MCP call has to be written out by the ' +
81
- 'model first. If you have no shell, hand the single command to a subagent that does and ' +
82
- 'keep the `upload_id` -- the slot belongs to this metro agent, not to whoever runs the ' +
83
- 'command. Then: send({line, attachments:[{upload:"<upload_id>"}]}). Up to 64 MiB, expires ' +
84
- '30 minutes after it is created, and no other agent can reference it.',
85
- inputSchema: {
86
- type: 'object',
87
- properties: {
88
- name: {
89
- type: 'string',
90
- description: 'Filename to present to the recipient (e.g. `report.pdf`).',
91
- },
92
- mime: {
93
- type: 'string',
94
- description: 'MIME type (guessed from the name/extension if omitted).',
95
- },
96
- },
97
- },
98
- };
99
-
100
- export const COMMON_TOOLS = [
14
+ export const COMMON_TOOLS: ToolDef[] = [
101
15
  {
102
16
  name: 'reply',
17
+ group: 'write',
103
18
  description:
104
19
  'Reply to a specific message in a Metro conversation (text quotes the target). Args: ' +
105
20
  "line, message_id, text. The station is derived from the line. Returns the daemon's " +
@@ -116,15 +31,19 @@ export const COMMON_TOOLS = [
116
31
  },
117
32
  {
118
33
  name: 'send',
34
+ group: 'write',
119
35
  description:
120
36
  'Send a message (and/or media) to a Metro conversation. Args: line, text?, reply_to?, ' +
121
- 'attachments?. The station is derived from the line. Each attachment names EXACTLY ONE ' +
37
+ 'subject?, attachments?, frame?. The station is derived from the line. Outlook and Gmail: send to ' +
38
+ 'metro://<outlook|gmail>/<account>/<email address> to start a new email (subject defaults to the ' +
39
+ 'first line of text); the result names the new thread line. Each attachment names EXACTLY ONE ' +
122
40
  'source, and the choice matters: `upload` (an `upload_id` from `create_upload`, the ' +
123
41
  'route for any real file on your own machine, confidential or not, up to 64 MiB); ' +
124
42
  '`data` (base64 inline -- TINY FILES ONLY, a few KB, because the base64 has to be ' +
125
43
  'written out verbatim in the call and longer than that it corrupts); `url` (the daemon ' +
126
44
  'fetches it, so the file must already be public); `path` (resolved on the DAEMON host, ' +
127
- 'which is not your machine). At least one of text/attachments is required. ' +
45
+ 'which is not your machine). Stage (XMTP) only: `frame` posts an interactive view. At least one ' +
46
+ 'of text/attachments/frame is required. ' +
128
47
  'The success line names each attachment the station actually delivered; a station that ' +
129
48
  'cannot carry a file errors instead of reporting success.',
130
49
  inputSchema: {
@@ -139,17 +58,53 @@ export const COMMON_TOOLS = [
139
58
  type: 'string',
140
59
  description: 'Optional message_id to quote/reply to.',
141
60
  },
61
+ subject: {
62
+ type: 'string',
63
+ description: 'Outlook and Gmail only: the subject of a new email.',
64
+ },
142
65
  attachments: {
143
66
  type: 'array',
144
67
  description: 'Optional files to attach.',
145
68
  items: attachmentItem,
146
69
  },
70
+ frame: {
71
+ type: 'object',
72
+ description:
73
+ 'Stage (XMTP) only: a frame, a small interactive view that Stage shows as a card (title and ' +
74
+ 'description) and opens full screen. `widget` is OpenAI ChatKit widget JSON (a Card, ListView ' +
75
+ 'or Basic root, 64K characters at most); a missing `title` or `description` is taken from the ' +
76
+ 'widget. Or give `screens` instead of `widget` for several screens in one frame. A tap comes back ' +
77
+ 'to you as a reply to the frame: "Frame action: <type> <payload ' +
78
+ "JSON>\". It is sent after the text, and the message_id returned is the frame's. The stage " +
79
+ 'skill lists the widget nodes, with an example.',
80
+ properties: {
81
+ widget: {
82
+ type: 'object',
83
+ description:
84
+ 'ChatKit widget JSON, e.g. {"type":"Card","children":[{"type":"Title","value":"Deploy?"},' +
85
+ '{"type":"Button","label":"Ship it","onClickAction":{"type":"deploy","payload":{"env":"prod"}}}]}.',
86
+ additionalProperties: true,
87
+ },
88
+ screens: {
89
+ type: 'object',
90
+ description:
91
+ 'Instead of `widget`: up to 50 screens by id, each a widget or {"title", "widget"}, 64K ' +
92
+ 'characters in all. An action {"type":"frame.open","payload":{"screen":"<id>"}} opens a ' +
93
+ 'screen and {"type":"frame.back"} goes back, in Stage, with no message to you.',
94
+ additionalProperties: true,
95
+ },
96
+ start: { type: 'string', description: 'Required with `screens`: the id of the first screen.' },
97
+ title: { type: 'string', description: 'Card title in the chat (200 characters at most).' },
98
+ description: { type: 'string', description: 'Card description in the chat (1000 characters at most).' },
99
+ },
100
+ },
147
101
  },
148
102
  required: ['line'],
149
103
  },
150
104
  },
151
105
  {
152
106
  name: 'react',
107
+ group: 'write',
153
108
  description:
154
109
  'Add an emoji reaction to a message. Args: line, message_id, emoji. The station is derived from the line.',
155
110
  inputSchema: {
@@ -162,8 +117,22 @@ export const COMMON_TOOLS = [
162
117
  required: ['line', 'message_id', 'emoji'],
163
118
  },
164
119
  },
120
+ {
121
+ name: 'typing',
122
+ group: 'write',
123
+ description:
124
+ 'Show "typing…" once in a chat while you prepare an answer. The network clears it by itself after its own time (about 5 s on the Telegram bot, 10 s on Discord, 25 s on WhatsApp) or when you send. Call it again to show it again. Args: line.',
125
+ inputSchema: {
126
+ type: 'object',
127
+ properties: {
128
+ line: lineProp,
129
+ },
130
+ required: ['line'],
131
+ },
132
+ },
165
133
  {
166
134
  name: 'unreact',
135
+ group: 'write',
167
136
  description:
168
137
  'Remove an emoji reaction from a message. Args: line, message_id, emoji. The station is derived from the line.',
169
138
  inputSchema: {
@@ -181,6 +150,7 @@ export const COMMON_TOOLS = [
181
150
  },
182
151
  {
183
152
  name: 'edit',
153
+ group: 'write',
184
154
  description:
185
155
  'Edit the text of a message you sent. Args: line, message_id, text. The station is ' +
186
156
  "derived from the line. Returns the daemon's reason if the station does not support edits.",
@@ -196,6 +166,8 @@ export const COMMON_TOOLS = [
196
166
  },
197
167
  {
198
168
  name: 'delete',
169
+ group: 'write',
170
+ destructive: true,
199
171
  description:
200
172
  'Delete a message you sent. Args: line, message_id. The station is derived from the line. ' +
201
173
  "Returns the daemon's reason if the station does not support deletes.",
@@ -207,14 +179,28 @@ export const COMMON_TOOLS = [
207
179
  },
208
180
  {
209
181
  name: 'read',
182
+ group: 'read',
210
183
  description:
211
- 'Read recent message history for a conversation. Args: line, limit?, before?, since?. The ' +
212
- 'station is derived from the line. Returns the raw history JSON (shapes differ per ' +
213
- "station), or the daemon's reason if the station does not support reads.",
184
+ 'Read message history. Args: line?, account?, limit?, before?, since?, until?, query?, ' +
185
+ 'from?, unread_only?, message_id?. Give a line to read one conversation, or an account ' +
186
+ '(from list_accounts) instead of a line to read across that whole account, where the ' +
187
+ 'station allows it. `message_id` returns that one message in full, with its files saved ' +
188
+ 'like inbound media (url and local_path). Each station applies the filters it supports; ' +
189
+ 'the answer lists any it did not apply in `ignored`, so check it. Returns the raw JSON ' +
190
+ "(shapes differ per station), or the daemon's reason if the station does not support " +
191
+ 'reads. Outlook: `query` is a Microsoft search over all mail (with `from` folded into it; ' +
192
+ 'line, since, until and unread_only then narrow what the search found), and without ' +
193
+ '`query` every filter is applied by Outlook itself, newest first. Gmail: `query` uses ' +
194
+ 'Gmail search syntax (from:, subject:, has:attachment, newer_than:7d...), and the other ' +
195
+ 'filters are added to it.',
214
196
  inputSchema: {
215
197
  type: 'object',
216
198
  properties: {
217
199
  line: lineProp,
200
+ account: {
201
+ type: 'string',
202
+ description: 'An account id from list_accounts, to read the whole account when you give no line.',
203
+ },
218
204
  limit: { type: 'number', description: 'Max messages to return.' },
219
205
  before: {
220
206
  type: 'string',
@@ -224,12 +210,20 @@ export const COMMON_TOOLS = [
224
210
  type: 'string',
225
211
  description: 'Return messages since this timestamp.',
226
212
  },
213
+ until: {
214
+ type: 'string',
215
+ description: 'Return messages before this timestamp.',
216
+ },
217
+ query: { type: 'string', description: 'Free text to search for.' },
218
+ from: { type: 'string', description: 'Only messages from this sender (an id or an address).' },
219
+ unread_only: { type: 'boolean', description: 'Only messages not read yet.' },
220
+ message_id: { type: 'string', description: 'Return this one message in full.' },
227
221
  },
228
- required: ['line'],
229
222
  },
230
223
  },
231
224
  {
232
225
  name: 'list_members',
226
+ group: 'read',
233
227
  description:
234
228
  'List the members of a Metro group/channel in a station-agnostic shape. Args: line, ' +
235
229
  'limit?. The station is derived from the line. Returns {line, station, memberCount, ' +
@@ -253,6 +247,7 @@ export const COMMON_TOOLS = [
253
247
  },
254
248
  {
255
249
  name: 'create_group',
250
+ group: 'write',
256
251
  description:
257
252
  'Create a new group/channel on a station and add members, in a station-agnostic shape. ' +
258
253
  'Args: station (required, xmtp|telegram|discord-bot|telegram-bot), name (required), members? ' +
@@ -292,6 +287,7 @@ export const COMMON_TOOLS = [
292
287
  },
293
288
  {
294
289
  name: 'add_members',
290
+ group: 'write',
295
291
  description:
296
292
  'Add members to an existing Metro group, in a station-agnostic shape. Args: line ' +
297
293
  '(required), members? (string[]; station-specific identifiers). xmtp also accepts ' +
@@ -324,6 +320,8 @@ export const COMMON_TOOLS = [
324
320
  },
325
321
  {
326
322
  name: 'remove_members',
323
+ group: 'write',
324
+ destructive: true,
327
325
  description:
328
326
  'Remove members from an existing Metro group, in a station-agnostic shape. Args: line ' +
329
327
  '(required), members? (string[]). xmtp also accepts addresses?/inboxIds? for backward ' +
@@ -354,6 +352,7 @@ export const COMMON_TOOLS = [
354
352
  },
355
353
  {
356
354
  name: 'export_invite',
355
+ group: 'write',
357
356
  description:
358
357
  'Get a join/invite link for a Metro group, for platforms where direct-add is not always ' +
359
358
  'permitted. Args: line (required). The station is derived from the line. Returns {op, ' +
@@ -368,8 +367,9 @@ export const COMMON_TOOLS = [
368
367
  CREATE_UPLOAD_TOOL,
369
368
  ];
370
369
 
371
- export const LIST_ACCOUNTS_TOOL = {
370
+ export const LIST_ACCOUNTS_TOOL: ToolDef = {
372
371
  name: 'list_accounts',
372
+ group: 'read',
373
373
  description:
374
374
  'List the configured messaging accounts across all stations (PUBLIC identity only: ' +
375
375
  'addresses, bot ids/usernames). No args. Never returns tokens, private keys, or the ' +
@@ -378,20 +378,3 @@ export const LIST_ACCOUNTS_TOOL = {
378
378
  'verb need not be discovered by trial and error.',
379
379
  inputSchema: { type: 'object', properties: {} },
380
380
  };
381
-
382
- export const MCP_INSTRUCTIONS =
383
- 'Messages from Metro chat arrive as <channel source="metro" line="..." from="..." ' +
384
- 'station="..." message_id="...">. To respond, use the messaging tools, always passing the ' +
385
- '`line` attribute verbatim (the station is derived from it): `send` (text and/or media via ' +
386
- '`attachments`, optional `reply_to`), `reply` (quote a `message_id` with `text`), `react`/' +
387
- '`unreact` (emoji on a `message_id`), `edit`/`delete` (a `message_id`), and `read` (recent ' +
388
- "history). Station support varies - the tool returns the daemon's reason if a verb is " +
389
- 'unsupported on that line. An inbound attachment is surfaced as a note carrying the ' +
390
- "sender's own text alongside a `Public URL` - fetch that url to read the file; the note's " +
391
- '`local_path` resolves on the DAEMON host, not on yours, so the Read tool works on it only ' +
392
- 'for an agent running there. To send a file OUT, call `create_upload`, ' +
393
- 'run the one curl line it hands back (that step needs a shell; the bytes go from your disk ' +
394
- 'straight to metro and never through this conversation), then `send` with ' +
395
- 'attachments:[{upload:"<upload_id>"}]. Inline `data` is for tiny files only, `url` only for ' +
396
- 'an already-public file, and `path` is read on the DAEMON host, not yours. Tool-approval ' +
397
- 'prompts are relayed to the same chat - answer "yes <id>"/"no <id>".';
@@ -1,34 +1,29 @@
1
- import { publicBaseOrDefault } from '../daemon/attach-serve.js';
1
+ import { publicBaseOrDefault } from '../files/attach-serve.js';
2
2
  import { safeFileName } from '../stations/attach-inline.js';
3
- import { guessMime } from '../stations/attachments.js';
3
+ import { guessMime } from '@metro-labs/core/stations/attachments';
4
4
  import {
5
5
  createUploadSlot,
6
6
  issueUploadTicket,
7
7
  MAX_UPLOAD_BYTES,
8
8
  removeUpload,
9
9
  UPLOAD_TTL_MS,
10
- } from '../daemon/upload-store.js';
11
- import type { ToolResult } from '../stations/types.js';
10
+ } from '../files/upload-store.js';
11
+ import type { ToolResult } from '@metro-labs/core/stations/types';
12
12
  import { errResult, okJson } from './ctx.js';
13
13
  import { allowedAgents, currentIdentity } from './request-identity.js';
14
- import { str } from './str.js';
14
+ import { str } from '@metro-labs/core/str';
15
15
 
16
16
  const ttlMinutes = (): number => Math.round(UPLOAD_TTL_MS / 60_000);
17
17
 
18
18
  const NO_AGENT =
19
19
  'create_upload needs an agent credential; this session is not scoped to one agent';
20
20
 
21
- const manyAgents = (n: number): string =>
22
- `create_upload is scoped to one agent, but this session covers ${String(n)}` +
23
- ' (a multi-agent sign-in); use `POST /api/uploads?agent=<id>` directly instead';
24
-
25
21
  type OwnerAgent = { agentId: string } | { error: string };
26
22
 
27
23
  function ownerAgent(): OwnerAgent {
28
24
  const allowed = allowedAgents(currentIdentity());
29
25
  const [only] = [...allowed];
30
- if (allowed.size === 1 && only !== undefined) return { agentId: only };
31
- return { error: allowed.size === 0 ? NO_AGENT : manyAgents(allowed.size) };
26
+ return allowed.size === 1 && only !== undefined ? { agentId: only } : { error: NO_AGENT };
32
27
  }
33
28
 
34
29
  export function dispatchCreateUpload(
@@ -0,0 +1,126 @@
1
+ export const HELPER_PATH = '/usr/local/lib/metro/root-helper';
2
+ const HELPER_VERSION = 1;
3
+ export const SUDOERS_PATH = '/etc/sudoers.d/metro';
4
+ export const METRO_USER = 'metro';
5
+ const METRO_HOME = '/var/lib/metro';
6
+
7
+ export const sudoersText = (agent: string): string =>
8
+ [
9
+ `${METRO_USER} ALL=(${agent}) NOPASSWD: ALL`,
10
+ `${METRO_USER} ALL=(root) NOPASSWD: ${HELPER_PATH} *`,
11
+ `Defaults:${METRO_USER} !requiretty`,
12
+ '',
13
+ ].join('\n');
14
+
15
+ const lines = (...parts: string[]): string => parts.join('\n');
16
+
17
+ const CHECKS = lines(
18
+ 'AGENT=agent',
19
+ 'UNITS=/etc/systemd/system',
20
+ 'die() { echo "root-helper: $*" >&2; exit 2; }',
21
+ 'agent_uid() { id -u "$AGENT" 2>/dev/null || die "no agent user"; }',
22
+ 'service_ok() {',
23
+ ' printf %s "$1" | grep -Eq "^[A-Za-z0-9@_.-]+\\.service$" || die "bad service name"',
24
+ ' case "$1" in metro*) die "not a metro unit";; esac',
25
+ ' frag=$(systemctl show "$1" -p FragmentPath --value)',
26
+ ' case "$frag" in "$UNITS"/*) ;; *) die "not a unit under $UNITS";; esac',
27
+ ' systemctl show "$1" -p TriggeredBy --value | grep -q "\\.timer" || die "not started by a timer"',
28
+ '}',
29
+ 'dropin_ok() {',
30
+ ' case "$1" in 10-metro-agent.conf|11-metro-vault.conf) ;; *) die "bad drop-in name";; esac',
31
+ ' home=$(getent passwd "$AGENT" | cut -d: -f6)',
32
+ ' saw_user=0',
33
+ ' while IFS= read -r line; do',
34
+ ' case "$line" in',
35
+ ' "[Service]"|"") ;;',
36
+ ' "User=$AGENT") saw_user=1 ;;',
37
+ ' Group=*) printf %s "${line#Group=}" | grep -Eq "^[0-9]+$" || die "bad group" ;;',
38
+ ' "WorkingDirectory=$home"|"WorkingDirectory=$home"/*) ;;',
39
+ ' Environment=*) ;;',
40
+ ' "EnvironmentFile=-$home/.metro/vault.env") ;;',
41
+ ' "ExecStart=") ;;',
42
+ ' ExecStart=[+!@]*) die "privileged ExecStart refused" ;;',
43
+ ' ExecStart=*) ;;',
44
+ ' *) die "line not allowed: $line" ;;',
45
+ ' esac',
46
+ ' done < "$2"',
47
+ ' if [ "$1" = 10-metro-agent.conf ] && [ "$saw_user" != 1 ]; then die "the drop-in must set User=$AGENT"; fi',
48
+ '}',
49
+ );
50
+
51
+ const FIREWALL = lines(
52
+ 'firewall_on() {',
53
+ ' uid=$(agent_uid)',
54
+ ' for t in iptables ip6tables; do',
55
+ ' $t -w -N METRO_AGENT 2>/dev/null || true',
56
+ ' $t -w -F METRO_AGENT',
57
+ ' $t -w -A METRO_AGENT -o lo -j ACCEPT',
58
+ ' $t -w -A METRO_AGENT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT',
59
+ ' $t -w -A METRO_AGENT -p udp --dport 53 -j ACCEPT',
60
+ ' $t -w -A METRO_AGENT -p tcp --dport 53 -j ACCEPT',
61
+ ' $t -w -A METRO_AGENT -p tcp -j REJECT --reject-with tcp-reset',
62
+ ' $t -w -A METRO_AGENT -j REJECT',
63
+ ' $t -w -C OUTPUT -m owner --uid-owner "$uid" -j METRO_AGENT 2>/dev/null || $t -w -I OUTPUT -m owner --uid-owner "$uid" -j METRO_AGENT',
64
+ ' done',
65
+ '}',
66
+ 'firewall_off() {',
67
+ ' uid=$(agent_uid)',
68
+ ' for t in iptables ip6tables; do',
69
+ ' while $t -w -C OUTPUT -m owner --uid-owner "$uid" -j METRO_AGENT 2>/dev/null; do $t -w -D OUTPUT -m owner --uid-owner "$uid" -j METRO_AGENT; done',
70
+ ' $t -w -F METRO_AGENT 2>/dev/null || true',
71
+ ' $t -w -X METRO_AGENT 2>/dev/null || true',
72
+ ' done',
73
+ '}',
74
+ );
75
+
76
+ const ACTIONS = lines(
77
+ 'action="${1:-}"; [ "$#" -gt 0 ] && shift',
78
+ 'case "$action" in',
79
+ ` version) echo ${String(HELPER_VERSION)} ;;`,
80
+ ' ensure-agent)',
81
+ ' getent passwd "$AGENT" >/dev/null || useradd --create-home --shell /bin/bash "$AGENT"',
82
+ ' chmod 700 "$(getent passwd "$AGENT" | cut -d: -f6)" ;;',
83
+ ' as-agent-scope)',
84
+ ' [ "$#" -ge 3 ] || die "usage: as-agent-scope <max> <high> <command...>"',
85
+ ' printf %s "$1$2" | grep -Eq "^[0-9]+$" || die "bad memory limits"',
86
+ ' max="$1"; high="$2"; shift 2',
87
+ ' uid=$(agent_uid); gid=$(id -g "$AGENT")',
88
+ ' exec systemd-run --scope --quiet --collect --unit="metro-claude-$(date +%s%N)" -p MemoryMax="$max" -p MemoryHigh="$high" -p OOMPolicy=continue -- setpriv --reuid="$uid" --regid="$gid" --init-groups -- "$@" ;;',
89
+ ' dropin-write)',
90
+ ' service_ok "$1"; tmp=$(mktemp); trap \'rm -f "$tmp"\' EXIT; cat > "$tmp"; dropin_ok "$2" "$tmp"',
91
+ ' mkdir -p "$UNITS/$1.d"; install -m 644 "$tmp" "$UNITS/$1.d/$2" ;;',
92
+ ' dropin-remove)',
93
+ ' service_ok "$1"; case "$2" in 10-metro-agent.conf|11-metro-vault.conf) ;; *) die "bad drop-in name";; esac',
94
+ ' rm -f "$UNITS/$1.d/$2" ;;',
95
+ ' daemon-reload) systemctl daemon-reload ;;',
96
+ ' start-job)',
97
+ ' service_ok "$1"; [ "$(systemctl show "$1" -p User --value)" = "$AGENT" ] || die "that job does not run as $AGENT"',
98
+ ' systemctl start --no-block "$1" ;;',
99
+ ' root-crontab) crontab -l -u root 2>/dev/null || true ;;',
100
+ ' root-crontab-drop)',
101
+ ' printf %s "$1" | grep -Eq "^[0-9a-f]{16}$" || die "bad line id"',
102
+ ` backups="${METRO_HOME}/.metro/agents"`,
103
+ ' cur=$(mktemp); crontab -l -u root > "$cur" 2>/dev/null || true',
104
+ ' kept=$(mktemp); found=0',
105
+ ' while IFS= read -r line; do',
106
+ ' id=$(printf %s "$line" | sed "s/^[[:space:]]*//;s/[[:space:]]*$//" | tr -d "\\n" | sha256sum | cut -c1-16)',
107
+ ' if [ "$id" = "$1" ] && [ "$found" = 0 ]; then found=1; elif [ -n "$line" ]; then printf "%s\\n" "$line" >> "$kept"; fi',
108
+ ' done < "$cur"',
109
+ ' [ "$found" = 1 ] || die "that cron line is gone"',
110
+ ' install -m 600 "$cur" "$backups/crontab-root.$(date +%Y-%m-%dT%H-%M-%S).bak"',
111
+ ' crontab -u root "$kept"; rm -f "$cur" "$kept" ;;',
112
+ ' firewall-on) firewall_on ;;',
113
+ ' firewall-off) firewall_off ;;',
114
+ ' trust-ca)',
115
+ ` src="${METRO_HOME}/.metro/agents/vault/ca/ca.crt"`,
116
+ ' head -n1 "$src" | grep -q "BEGIN CERTIFICATE" || die "not a certificate"',
117
+ ' if grep -q "PRIVATE KEY" "$src"; then die "a key is not a certificate"; fi',
118
+ ' install -m 644 "$src" /usr/local/share/ca-certificates/metro-vault.crt && update-ca-certificates >/dev/null ;;',
119
+ ' untrust-ca) rm -f /usr/local/share/ca-certificates/metro-vault.crt; update-ca-certificates --fresh >/dev/null ;;',
120
+ ' install-nss-tools) DEBIAN_FRONTEND=noninteractive apt-get install -y -q libnss3-tools >/dev/null ;;',
121
+ ' *) die "unknown action: $action" ;;',
122
+ 'esac',
123
+ );
124
+
125
+ export const helperScript = (): string =>
126
+ ['#!/bin/sh', 'set -eu', 'export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', CHECKS, FIREWALL, ACTIONS, ''].join('\n');
@@ -0,0 +1,37 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { dirname, join } from 'node:path';
5
+ import { HELPER_PATH, helperScript, SUDOERS_PATH, sudoersText } from './helper-script.js';
6
+ import { AGENT_NAME } from '../agent-user/user.js';
7
+
8
+ interface InstallPaths {
9
+ helper: string;
10
+ sudoers: string;
11
+ }
12
+
13
+ function checked(file: string, args: string[]): void {
14
+ const run = spawnSync(file, args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
15
+ if (run.error !== undefined) throw run.error;
16
+ if (run.status !== 0) throw new Error(`${file} ${args.join(' ')}: ${`${run.stdout}${run.stderr}`.trim() || `exit ${String(run.status)}`}`);
17
+ }
18
+
19
+ export function installRootHelper(paths: InstallPaths = { helper: HELPER_PATH, sudoers: SUDOERS_PATH }): void {
20
+ mkdirSync(dirname(paths.helper), { recursive: true, mode: 0o755 });
21
+ writeFileSync(paths.helper, helperScript(), { mode: 0o755 });
22
+ chmodSync(paths.helper, 0o755);
23
+ const work = mkdtempSync(join(tmpdir(), 'metro-sudoers-'));
24
+ try {
25
+ const draft = join(work, 'metro');
26
+ writeFileSync(draft, sudoersText(AGENT_NAME), { mode: 0o440 });
27
+ checked('visudo', ['-cf', draft]);
28
+ checked('install', ['-m', '440', draft, paths.sudoers]);
29
+ } finally {
30
+ rmSync(work, { recursive: true, force: true });
31
+ }
32
+ }
33
+
34
+ if (import.meta.main) {
35
+ installRootHelper();
36
+ process.stdout.write(`metro: wrote ${HELPER_PATH} and ${SUDOERS_PATH}\n`);
37
+ }
@@ -0,0 +1,48 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { HELPER_PATH, METRO_USER } from './helper-script.js';
3
+
4
+ export interface PrivilegeHost {
5
+ platform: string;
6
+ uid: number | undefined;
7
+ user: string;
8
+ }
9
+
10
+ let metroUid: number | null | undefined;
11
+
12
+ function uidOfMetro(): number | null {
13
+ if (metroUid !== undefined) return metroUid;
14
+ const run = spawnSync('getent', ['passwd', METRO_USER], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
15
+ const uid = Number(run.status === 0 ? run.stdout.split(':')[2] : NaN);
16
+ metroUid = Number.isInteger(uid) && uid > 0 ? uid : null;
17
+ return metroUid;
18
+ }
19
+
20
+ const realHost = (): PrivilegeHost => {
21
+ const uid = process.getuid?.();
22
+ const linux = process.platform === 'linux';
23
+ return { platform: process.platform, uid, user: linux && uid !== 0 && uid !== undefined && uid === uidOfMetro() ? METRO_USER : '' };
24
+ };
25
+
26
+ export const runningAsRoot = (host: PrivilegeHost = realHost()): boolean => host.platform === 'linux' && host.uid === 0;
27
+
28
+ export const runningAsMetro = (host: PrivilegeHost = realHost()): boolean =>
29
+ host.platform === 'linux' && host.uid !== 0 && host.user === METRO_USER;
30
+
31
+ export interface HelperResult {
32
+ status: number | null;
33
+ stdout: string;
34
+ stderr: string;
35
+ }
36
+
37
+ export function rootHelper(args: string[], input?: string): HelperResult {
38
+ const run = spawnSync('sudo', ['-n', HELPER_PATH, ...args], { encoding: 'utf8', input, stdio: ['pipe', 'pipe', 'pipe'], timeout: 180_000 });
39
+ return { status: run.error === undefined ? run.status : null, stdout: run.stdout ?? '', stderr: run.stderr ?? run.error?.message ?? '' };
40
+ }
41
+
42
+ export function mustHelper(args: string[], input?: string): string {
43
+ const run = rootHelper(args, input);
44
+ if (run.status !== 0) throw new Error(run.stderr.trim() || `root-helper ${args[0] ?? ''} failed`);
45
+ return run.stdout;
46
+ }
47
+
48
+ export const helperArgv = (args: string[]): [string, string[]] => ['sudo', ['-n', HELPER_PATH, ...args]];