@stage-labs/metro 0.1.0-beta.26 → 0.1.0-beta.261
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.
- package/dist/agent.js +128 -0
- package/dist/api.js +9 -129
- package/dist/background.js +141 -0
- package/dist/claude-settings.js +40 -0
- package/dist/claude.js +201 -0
- package/dist/cli.js +67 -117
- package/dist/control.js +19 -103
- package/dist/hold.js +210 -0
- package/dist/local.js +43 -0
- package/dist/mcp-config.js +27 -0
- package/dist/memory.js +222 -0
- package/dist/node-name.js +71 -0
- package/dist/onboarding.js +44 -0
- package/dist/provider-flags.js +9 -0
- package/dist/root-release-io.js +161 -0
- package/dist/root-release.js +74 -0
- package/dist/route.js +66 -0
- package/dist/runtime-install.js +97 -0
- package/dist/runtime.js +29 -52
- package/dist/serve.js +157 -0
- package/dist/service.js +328 -0
- package/dist/tail.js +10 -11
- package/dist/update.js +13 -1
- package/dist/voice.js +56 -0
- package/package.json +3 -24
- package/runtime/marketplace/.claude-plugin/marketplace.json +12 -0
- package/runtime/marketplace/plugin/.claude-plugin/plugin.json +17 -0
- package/runtime/marketplace/plugin/.mcp.json +1 -0
- package/runtime/marketplace/plugin/MEMORY.md +78 -0
- package/runtime/marketplace/plugin/METRO.md +26 -0
- package/runtime/marketplace/plugin/STAGE.md +95 -0
- package/runtime/marketplace/plugin/bin/guard.mjs +75 -0
- package/runtime/marketplace/plugin/bin/metro-plugin.mjs +30 -0
- package/runtime/marketplace/plugin/bin/policy.mjs +97 -0
- package/runtime/marketplace/plugin/bin/session-start.mjs +31 -0
- package/runtime/marketplace/plugin/hooks/hooks.json +25 -0
- package/runtime/node_modules/@metro-labs/core/package.json +52 -0
- package/runtime/node_modules/@metro-labs/core/src/endpoints.ts +7 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/events.ts +11 -7
- package/runtime/node_modules/@metro-labs/{mcp/src/db → core/src}/ids.ts +10 -1
- package/runtime/node_modules/@metro-labs/core/src/is-record.ts +2 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/stations → core/src}/lines.ts +22 -26
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/protocol.ts +7 -4
- package/runtime/node_modules/@metro-labs/core/src/runner-activity.ts +103 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/secure-fs.ts +17 -0
- package/runtime/node_modules/@metro-labs/core/src/station-names.ts +14 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/account-files.ts +41 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/account-store.ts +83 -0
- package/runtime/node_modules/@metro-labs/{mcp → core}/src/stations/attachments.ts +0 -1
- package/runtime/node_modules/@metro-labs/core/src/stations/mail-text.ts +72 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/mail-trust.ts +29 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/mail.ts +212 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/messaging-normalize.ts +16 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/oauth.ts +126 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/profile.ts +58 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/sender-profile.ts +64 -0
- package/runtime/node_modules/@metro-labs/{mcp → core}/src/stations/station-runtime.ts +6 -11
- package/runtime/node_modules/@metro-labs/core/src/stations/train-boot.ts +42 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/train-events.ts +84 -0
- package/runtime/node_modules/@metro-labs/{mcp → core}/src/stations/types.ts +19 -1
- package/runtime/node_modules/@metro-labs/core/src/tickets.ts +37 -0
- package/runtime/node_modules/@metro-labs/core/src/version.ts +2 -0
- package/runtime/node_modules/@metro-labs/daemon/package.json +51 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/agent-fs.ts +246 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/crontab.ts +44 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/files-api.ts +12 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/files.ts +89 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/home-fs.ts +113 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/job-env.ts +39 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/metro-home.ts +42 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/provision.ts +81 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedule-detail.ts +93 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedules-api.ts +27 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedules.ts +144 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/unit-files.ts +43 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/user.ts +91 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/view.ts +93 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/account-attach.ts +19 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/account-lookups.ts +55 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/account-routes.ts +76 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/accounts-api.ts +357 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/admin.ts +30 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/allowlist.ts +59 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/api.ts +131 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/bundle.ts +132 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/file-admin.ts +305 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/files.ts +142 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/db/key-map.ts → daemon/src/agents/keys.ts} +1 -11
- package/runtime/node_modules/@metro-labs/daemon/src/agents/map.ts +133 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/policy-route.ts +27 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/db/agent-scope.ts → daemon/src/agents/scope.ts} +2 -2
- package/runtime/node_modules/@metro-labs/daemon/src/agents/sender-cards.ts +94 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/senders.ts +38 -0
- package/runtime/node_modules/@metro-labs/daemon/src/approvals/api.ts +55 -0
- package/runtime/node_modules/@metro-labs/daemon/src/approvals/pending.ts +150 -0
- package/runtime/node_modules/@metro-labs/daemon/src/approvals/preview.ts +66 -0
- package/runtime/node_modules/@metro-labs/daemon/src/boot/boot.ts +238 -0
- package/runtime/node_modules/@metro-labs/daemon/src/boot/connect-hint.ts +36 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/boot}/crash-guard.ts +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/boot/local-owner.ts +21 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/boot}/paths.ts +8 -36
- package/runtime/node_modules/@metro-labs/daemon/src/channels/addressed.ts +26 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/inbound.ts +75 -45
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/media-note.ts +11 -7
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/pending.ts +4 -1
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/relay.ts +2 -2
- package/runtime/node_modules/@metro-labs/daemon/src/claude/api.ts +285 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/files.ts +359 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/login.ts +242 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/memory-routine.ts +123 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/memory.ts +32 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/onboarding.ts +60 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/plugin-install.ts +149 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/runner-activity.ts +17 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/runner-process.ts +50 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/runner.ts +45 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/session-continuity.ts +48 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/session-files.ts +75 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/session.ts +358 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/settings.ts +109 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/setup-api.ts +161 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/setup-state.ts +18 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/setup.ts +343 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/skills.ts +120 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/usage-probe.ts +128 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/version.ts +113 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon/connector-api.ts → daemon/src/connectors/api.ts} +79 -114
- package/runtime/node_modules/@metro-labs/{mcp/src/db/connector-config.ts → daemon/src/connectors/config.ts} +67 -41
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/gates.ts +72 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/health.ts +18 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/connectors}/oauth-client.ts +14 -17
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/connectors}/oauth-discovery.ts +33 -20
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon/connector-oauth-routes.ts → daemon/src/connectors/oauth-routes.ts} +30 -32
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon/connector-oauth.ts → daemon/src/connectors/oauth.ts} +60 -21
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/plugin-sync.ts +131 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/reach.ts +27 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay-policy.ts +90 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/connectors}/relay.ts +80 -35
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/store.ts +385 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/tools.ts +81 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/transfer-api.ts +116 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/transfer-crypto.ts +44 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/transfer-store.ts +48 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/url.ts +37 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/verify.ts +106 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/attach-grant.ts +4 -4
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/attach-owner.ts +3 -3
- package/runtime/node_modules/@metro-labs/daemon/src/files/attach-reaper.ts +174 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/attach-serve.ts +11 -17
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/upload-api.ts +10 -27
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/upload-store.ts +4 -4
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/bedrock.ts +233 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/claude-logins.ts +168 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-auth.ts +219 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-device.ts +119 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-stream.ts +179 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-translate.ts +209 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-version.ts +44 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex.ts +143 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/effort.ts +103 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/eventstream.ts +123 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/fallback.ts +147 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/forward.ts +285 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/frames.ts +118 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gateway.ts +396 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-auth.ts +160 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-client.ts +46 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-setup.ts +150 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-stream.ts +139 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-translate.ts +236 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini.ts +208 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-api.ts +256 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-config.ts +353 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-lists.ts +57 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-signin.ts +157 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-store.ts +83 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/openrouter-login.ts +192 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/openrouter-signin.ts +64 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/openrouter.ts +104 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/pkce.ts +36 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/provider-models.ts +117 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/served.ts +18 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/subscription.ts +120 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/text.ts +35 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/tool-search.ts +126 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/usage-refresh.ts +115 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/usage.ts +343 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/accounts.ts +38 -18
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/attachment-schema.ts +91 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/call-tools.ts +86 -38
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/ctx.ts +4 -4
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/event-store.ts +15 -16
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/group-tools.ts +2 -2
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/index.ts +49 -77
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/instructions.ts +30 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/member-tools.ts +2 -2
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/permission-prompt.ts +92 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/permission-relay.ts +88 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/policy-gate.ts +82 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/policy-snapshot.ts +79 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/profile-lookup.ts +60 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/profile-tool.ts +96 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/read-tool.ts +87 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/request-identity.ts +48 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/session-slot.ts +75 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/session.ts +61 -57
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-catalog.ts +93 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-def.ts +9 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/tool-dispatch.ts +53 -40
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/tool-schemas.ts +115 -114
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/upload-tool.ts +6 -11
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/helper-script.ts +183 -0
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/imds.ts +16 -0
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/install.ts +78 -0
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/privilege.ts +50 -0
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/root-follow.ts +16 -0
- package/runtime/node_modules/@metro-labs/daemon/src/monitor/api.ts +132 -0
- package/runtime/node_modules/@metro-labs/daemon/src/net/tunnel.ts +316 -0
- package/runtime/node_modules/@metro-labs/daemon/src/policy/policy.ts +118 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/bearer.ts +38 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/body.ts +24 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/routes}/http.ts +64 -53
- package/runtime/node_modules/@metro-labs/daemon/src/routes/local-mode.ts +210 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/session-apis.ts +71 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/session.ts +29 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/threema-callback.ts +103 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server/cloudwatch.ts +178 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server/control.ts +39 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server/machine.ts +58 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server/owner.ts +26 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server/update.ts +90 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server.ts +2 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-browser.ts +102 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-driver.ts +42 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-inline.ts +29 -1
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-interactive.ts +5 -31
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-resolve.ts +84 -13
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/attach-session.ts +32 -22
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-xmtp.ts +8 -9
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach.ts +69 -3
- package/runtime/node_modules/@metro-labs/{mcp/src/db → daemon/src/stations}/materialize.ts +60 -175
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/registry.ts +20 -2
- package/runtime/node_modules/@metro-labs/daemon/src/stations/runtime-deps.ts +82 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/supervisor-io.ts +3 -3
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/supervisor.ts +6 -9
- package/runtime/node_modules/@metro-labs/daemon/src/stations/threema-callbacks.ts +32 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/train-call.ts +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/stations/webhook-endpoints.ts +51 -0
- package/runtime/node_modules/@metro-labs/daemon/src/terminal/api.ts +84 -0
- package/runtime/node_modules/@metro-labs/daemon/src/terminal/socket.ts +124 -0
- package/runtime/node_modules/@metro-labs/daemon/src/terminal/tickets.ts +15 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/api.ts +45 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/config.ts +51 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/firewall.ts +9 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/index.ts +96 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/install.ts +56 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/paths.ts +26 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/proxy.ts +147 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/store.ts +129 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/trust.ts +44 -0
- package/runtime/node_modules/@metro-labs/daemon/src/voice/api.ts +14 -0
- package/runtime/node_modules/@metro-labs/daemon/src/voice/approvals.ts +38 -0
- package/runtime/node_modules/@metro-labs/daemon/src/voice/audio.ts +153 -0
- package/runtime/node_modules/@metro-labs/daemon/src/voice/brain.ts +135 -0
- package/runtime/node_modules/@metro-labs/daemon/src/voice/call.ts +200 -0
- package/runtime/node_modules/@metro-labs/daemon/src/voice/calls.ts +130 -0
- package/runtime/node_modules/@metro-labs/daemon/src/voice/peer.ts +84 -0
- package/runtime/node_modules/@metro-labs/daemon/src/voice/scribe.ts +103 -0
- package/runtime/node_modules/@metro-labs/daemon/src/voice/speakable.ts +54 -0
- package/runtime/node_modules/@metro-labs/daemon/src/voice/speech.ts +104 -0
- package/runtime/node_modules/@metro-labs/daemon/src/voice/store.ts +116 -0
- package/runtime/node_modules/@metro-labs/daemon/src/voice/talk.ts +256 -0
- package/runtime/node_modules/@metro-labs/discord-bot/package.json +3 -5
- package/runtime/node_modules/@metro-labs/discord-bot/src/accounts.ts +3 -23
- package/runtime/node_modules/@metro-labs/discord-bot/src/actions.ts +19 -187
- package/runtime/node_modules/@metro-labs/discord-bot/src/attachments.ts +2 -2
- package/runtime/node_modules/@metro-labs/discord-bot/src/format.ts +26 -67
- package/runtime/node_modules/@metro-labs/discord-bot/src/group-actions.ts +1 -1
- package/runtime/node_modules/@metro-labs/discord-bot/src/group.ts +2 -2
- package/runtime/node_modules/@metro-labs/discord-bot/src/index.ts +8 -14
- package/runtime/node_modules/@metro-labs/discord-bot/src/members.ts +2 -2
- package/runtime/node_modules/@metro-labs/discord-bot/src/profile.ts +68 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/send-files.ts +12 -13
- package/runtime/node_modules/@metro-labs/discord-bot/src/station.ts +5 -1
- package/runtime/node_modules/@metro-labs/gmail/package.json +25 -0
- package/runtime/node_modules/@metro-labs/gmail/src/accounts.ts +81 -0
- package/runtime/node_modules/@metro-labs/gmail/src/actions.ts +14 -0
- package/runtime/node_modules/@metro-labs/gmail/src/api.ts +31 -0
- package/runtime/node_modules/@metro-labs/gmail/src/attachments.ts +35 -0
- package/runtime/node_modules/@metro-labs/gmail/src/auth.ts +105 -0
- package/runtime/node_modules/@metro-labs/gmail/src/config.ts +13 -0
- package/runtime/node_modules/@metro-labs/gmail/src/inbound.ts +96 -0
- package/runtime/node_modules/@metro-labs/gmail/src/index.ts +12 -0
- package/runtime/node_modules/@metro-labs/gmail/src/login.ts +37 -0
- package/runtime/node_modules/@metro-labs/gmail/src/message.ts +125 -0
- package/runtime/node_modules/@metro-labs/gmail/src/mime.ts +70 -0
- package/runtime/node_modules/@metro-labs/gmail/src/outbound.ts +124 -0
- package/runtime/node_modules/@metro-labs/gmail/src/query.ts +99 -0
- package/runtime/node_modules/@metro-labs/gmail/src/state.ts +24 -0
- package/runtime/node_modules/@metro-labs/gmail/src/station.ts +15 -0
- package/runtime/node_modules/@metro-labs/gmail/src/trust.ts +42 -0
- package/runtime/node_modules/@metro-labs/http/package.json +30 -0
- package/runtime/node_modules/@metro-labs/http/src/api-http.ts +141 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon/session-api.ts → http/src/mode-api.ts} +13 -9
- package/runtime/node_modules/@metro-labs/http/src/return-to.ts +25 -0
- package/runtime/node_modules/@metro-labs/http/src/sigv4.ts +90 -0
- package/runtime/node_modules/@metro-labs/http/src/workos-token.ts +149 -0
- package/runtime/node_modules/@metro-labs/outlook/package.json +25 -0
- package/runtime/node_modules/@metro-labs/outlook/src/accounts.ts +78 -0
- package/runtime/node_modules/@metro-labs/outlook/src/actions.ts +14 -0
- package/runtime/node_modules/@metro-labs/outlook/src/attachments.ts +81 -0
- package/runtime/node_modules/@metro-labs/outlook/src/auth.ts +120 -0
- package/runtime/node_modules/@metro-labs/outlook/src/browser.ts +42 -0
- package/runtime/node_modules/@metro-labs/outlook/src/config.ts +23 -0
- package/runtime/node_modules/@metro-labs/outlook/src/format.ts +59 -0
- package/runtime/node_modules/@metro-labs/outlook/src/graph.ts +55 -0
- package/runtime/node_modules/@metro-labs/outlook/src/inbound.ts +96 -0
- package/runtime/node_modules/@metro-labs/outlook/src/index.ts +12 -0
- package/runtime/node_modules/@metro-labs/outlook/src/login.ts +129 -0
- package/runtime/node_modules/@metro-labs/outlook/src/me.ts +31 -0
- package/runtime/node_modules/@metro-labs/outlook/src/outbound.ts +103 -0
- package/runtime/node_modules/@metro-labs/outlook/src/query.ts +84 -0
- package/runtime/node_modules/@metro-labs/outlook/src/state.ts +28 -0
- package/runtime/node_modules/@metro-labs/outlook/src/station.ts +15 -0
- package/runtime/node_modules/@metro-labs/outlook/src/trust.ts +41 -0
- package/runtime/node_modules/@metro-labs/telegram/package.json +2 -4
- package/runtime/node_modules/@metro-labs/telegram/src/accounts.ts +5 -24
- package/runtime/node_modules/@metro-labs/telegram/src/actions.ts +8 -6
- package/runtime/node_modules/@metro-labs/telegram/src/attachments.ts +1 -1
- package/runtime/node_modules/@metro-labs/telegram/src/client.ts +4 -4
- package/runtime/node_modules/@metro-labs/telegram/src/format.ts +19 -34
- package/runtime/node_modules/@metro-labs/telegram/src/group.ts +3 -3
- package/runtime/node_modules/@metro-labs/telegram/src/inbound.ts +13 -34
- package/runtime/node_modules/@metro-labs/telegram/src/index.ts +4 -43
- package/runtime/node_modules/@metro-labs/telegram/src/media-actions.ts +2 -3
- package/runtime/node_modules/@metro-labs/telegram/src/members.ts +1 -1
- package/runtime/node_modules/@metro-labs/telegram/src/profile.ts +70 -0
- package/runtime/node_modules/@metro-labs/telegram/src/reactions.ts +2 -2
- package/runtime/node_modules/@metro-labs/telegram/src/station.ts +4 -1
- package/runtime/node_modules/@metro-labs/telegram/src/types.ts +0 -1
- package/runtime/node_modules/@metro-labs/telegram-bot/package.json +2 -2
- package/runtime/node_modules/@metro-labs/telegram-bot/src/accounts.ts +7 -41
- package/runtime/node_modules/@metro-labs/telegram-bot/src/actions.ts +22 -77
- package/runtime/node_modules/@metro-labs/telegram-bot/src/attachments.ts +2 -2
- package/runtime/node_modules/@metro-labs/telegram-bot/src/format.ts +46 -48
- package/runtime/node_modules/@metro-labs/telegram-bot/src/index.ts +15 -15
- package/runtime/node_modules/@metro-labs/telegram-bot/src/media-actions.ts +6 -82
- package/runtime/node_modules/@metro-labs/telegram-bot/src/members.ts +1 -1
- package/runtime/node_modules/@metro-labs/telegram-bot/src/profile.ts +85 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/station.ts +5 -1
- package/runtime/node_modules/@metro-labs/telegram-bot/src/types.ts +20 -12
- package/runtime/node_modules/@metro-labs/threema/package.json +26 -0
- package/runtime/node_modules/@metro-labs/threema/src/accounts.ts +96 -0
- package/runtime/node_modules/@metro-labs/threema/src/actions.ts +124 -0
- package/runtime/node_modules/@metro-labs/threema/src/api.ts +152 -0
- package/runtime/node_modules/@metro-labs/threema/src/crypto.ts +100 -0
- package/runtime/node_modules/@metro-labs/threema/src/files.ts +47 -0
- package/runtime/node_modules/@metro-labs/threema/src/format.ts +164 -0
- package/runtime/node_modules/@metro-labs/threema/src/groups.ts +96 -0
- package/runtime/node_modules/@metro-labs/threema/src/ids.ts +21 -0
- package/runtime/node_modules/@metro-labs/threema/src/inbound.ts +87 -0
- package/runtime/node_modules/@metro-labs/threema/src/index.ts +24 -0
- package/runtime/node_modules/@metro-labs/threema/src/messages.ts +264 -0
- package/runtime/node_modules/@metro-labs/threema/src/outbound.ts +160 -0
- package/runtime/node_modules/@metro-labs/threema/src/station.ts +13 -0
- package/runtime/node_modules/@metro-labs/threema/src/verify.ts +117 -0
- package/runtime/node_modules/@metro-labs/webhook/package.json +2 -2
- package/runtime/node_modules/@metro-labs/webhook/src/station.ts +5 -8
- package/runtime/node_modules/@metro-labs/whatsapp/package.json +3 -6
- package/runtime/node_modules/@metro-labs/whatsapp/src/accounts.ts +6 -28
- package/runtime/node_modules/@metro-labs/whatsapp/src/ack.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/actions.ts +54 -11
- package/runtime/node_modules/@metro-labs/whatsapp/src/attachments.ts +2 -2
- package/runtime/node_modules/@metro-labs/whatsapp/src/auth-state.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/client.ts +86 -4
- package/runtime/node_modules/@metro-labs/whatsapp/src/format.ts +7 -58
- package/runtime/node_modules/@metro-labs/whatsapp/src/inbound.ts +11 -28
- package/runtime/node_modules/@metro-labs/whatsapp/src/index.ts +4 -37
- package/runtime/node_modules/@metro-labs/whatsapp/src/keys.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/login.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/media.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/names.ts +75 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/parse.ts +44 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/resolve.ts +52 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/station.ts +16 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/token-store.ts +5 -9
- package/runtime/node_modules/@metro-labs/whatsapp/src/types.ts +0 -1
- package/runtime/node_modules/@metro-labs/xmtp/package.json +4 -3
- package/runtime/node_modules/@metro-labs/xmtp/src/accounts.ts +10 -20
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-close.ts +2 -2
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-conv.ts +39 -223
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-meta.ts +47 -53
- package/runtime/node_modules/@metro-labs/xmtp/src/actions.ts +112 -223
- package/runtime/node_modules/@metro-labs/xmtp/src/attachments.ts +3 -3
- package/runtime/node_modules/@metro-labs/xmtp/src/call-leftovers.ts +48 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/codecs.ts +113 -3
- package/runtime/node_modules/@metro-labs/xmtp/src/conv-helpers.ts +35 -20
- package/runtime/node_modules/@metro-labs/xmtp/src/delete-requests.ts +34 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/emit-payloads.ts +37 -25
- package/runtime/node_modules/@metro-labs/xmtp/src/emit.ts +8 -18
- package/runtime/node_modules/@metro-labs/xmtp/src/frames.ts +178 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/group-members.ts +1 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/group.ts +2 -2
- package/runtime/node_modules/@metro-labs/xmtp/src/identity.ts +30 -16
- package/runtime/node_modules/@metro-labs/xmtp/src/index.ts +18 -70
- package/runtime/node_modules/@metro-labs/xmtp/src/labels.ts +102 -50
- package/runtime/node_modules/@metro-labs/xmtp/src/member-args.ts +1 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/names.ts +61 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/network.ts +110 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/profile.ts +160 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/resolve.ts +44 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/sender.ts +112 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/smart.ts +79 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/station.ts +8 -2
- package/runtime/node_modules/@metro-labs/xmtp/src/stream.ts +66 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/tools-handlers.ts +22 -58
- package/runtime/node_modules/@metro-labs/xmtp/src/tools.ts +72 -49
- package/runtime/node_modules/@metro-labs/xmtp/src/transcribe.ts +4 -6
- package/runtime/node_modules/@metro-labs/xmtp/src/verify.ts +19 -5
- package/runtime/node_modules/@metro-labs/xmtp/src/wallet.ts +28 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/wire.ts +14 -4
- package/runtime/runtime.json +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/package.json +52 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/endpoints.ts +7 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/events.ts +121 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/ids.ts +28 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/is-record.ts +2 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/lines.ts +78 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/log.ts +42 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/protocol.ts +227 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/runner-activity.ts +103 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/secure-fs.ts +74 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/station-names.ts +14 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/account-files.ts +41 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/account-store.ts +83 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/attachments.ts +195 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/mail-text.ts +72 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/mail-trust.ts +29 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/mail.ts +212 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/messaging-normalize.ts +16 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/oauth.ts +126 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/profile.ts +58 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/sender-profile.ts +64 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/station-runtime.ts +59 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/train-boot.ts +42 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/train-events.ts +84 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/types.ts +125 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/str.ts +5 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/tickets.ts +37 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/train-error.ts +53 -0
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/version.ts +2 -0
- package/runtime/sdk-runner/runner.json +10 -0
- package/runtime/sdk-runner/src/activity-tasks.ts +142 -0
- package/runtime/sdk-runner/src/activity.ts +293 -0
- package/runtime/sdk-runner/src/app.ts +77 -0
- package/runtime/sdk-runner/src/approvals.ts +28 -0
- package/runtime/sdk-runner/src/channel-text.ts +26 -0
- package/runtime/sdk-runner/src/config.ts +50 -0
- package/runtime/sdk-runner/src/inbox.ts +94 -0
- package/runtime/sdk-runner/src/link.ts +130 -0
- package/runtime/sdk-runner/src/main.ts +44 -0
- package/runtime/sdk-runner/src/rules.ts +11 -0
- package/runtime/sdk-runner/src/runner.ts +251 -0
- package/runtime/sdk-runner/src/session-store.ts +71 -0
- package/runtime/sdk-runner/src/session-watch.ts +111 -0
- package/runtime/sdk-runner/src/singleton.ts +15 -0
- package/runtime/sdk-runner/src/speech.ts +79 -0
- package/runtime/sdk-runner/src/tool-proxy.ts +40 -0
- package/runtime/server.ts +1 -0
- package/runtime/stations.json +40 -0
- package/dist/plugin.js +0 -82
- package/dist/prompt.js +0 -61
- package/dist/store.js +0 -70
- package/runtime/node_modules/@metro-labs/discord-bot/src/voice-speak.ts +0 -195
- package/runtime/node_modules/@metro-labs/discord-bot/src/voice-transcribe.ts +0 -292
- package/runtime/node_modules/@metro-labs/discord-bot/src/voice.ts +0 -197
- package/runtime/node_modules/@metro-labs/discord-bot/src/wire.ts +0 -5
- package/runtime/node_modules/@metro-labs/mcp/package.json +0 -66
- package/runtime/node_modules/@metro-labs/mcp/src/channels/dedupe.ts +0 -24
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/account-api.ts +0 -311
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-api.ts +0 -341
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/api-http.ts +0 -129
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/boot.ts +0 -321
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/cli-pair-api.ts +0 -118
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/cli-pair.ts +0 -20
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/collection-api.ts +0 -202
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-json.ts +0 -21
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-tools.ts +0 -100
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-url.ts +0 -57
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-verify.ts +0 -333
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/google-auth.ts +0 -164
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/google-oauth.ts +0 -208
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/identity.ts +0 -79
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/oauth-pending.ts +0 -65
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/pair-codes.ts +0 -58
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/project-api.ts +0 -214
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/run-api.ts +0 -125
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/run-pair.ts +0 -18
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/runtime-source.ts +0 -105
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/session-apis.ts +0 -43
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/session.ts +0 -218
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/tunnel.ts +0 -169
- package/runtime/node_modules/@metro-labs/mcp/src/db/account-attach.ts +0 -91
- package/runtime/node_modules/@metro-labs/mcp/src/db/agent-admin.ts +0 -215
- package/runtime/node_modules/@metro-labs/mcp/src/db/agent-map.ts +0 -71
- package/runtime/node_modules/@metro-labs/mcp/src/db/client.ts +0 -37
- package/runtime/node_modules/@metro-labs/mcp/src/db/connector-collections.ts +0 -218
- package/runtime/node_modules/@metro-labs/mcp/src/db/connector-relay.ts +0 -126
- package/runtime/node_modules/@metro-labs/mcp/src/db/connectors.ts +0 -308
- package/runtime/node_modules/@metro-labs/mcp/src/db/projects.ts +0 -300
- package/runtime/node_modules/@metro-labs/mcp/src/db/runtime-admin.ts +0 -31
- package/runtime/node_modules/@metro-labs/mcp/src/db/runtimes.ts +0 -105
- package/runtime/node_modules/@metro-labs/mcp/src/db/schema.ts +0 -131
- package/runtime/node_modules/@metro-labs/mcp/src/db/token-carry.ts +0 -45
- package/runtime/node_modules/@metro-labs/mcp/src/db/users.ts +0 -57
- package/runtime/node_modules/@metro-labs/mcp/src/db/whatsapp-login.ts +0 -18
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/channel-owner.ts +0 -29
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/frame-scope.ts +0 -21
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/permission-relay.ts +0 -66
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/request-identity.ts +0 -73
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/session-registry.ts +0 -172
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/session-route.ts +0 -43
- package/runtime/node_modules/@metro-labs/mcp/src/monitor/api.ts +0 -240
- package/runtime/node_modules/@metro-labs/mcp/src/server.ts +0 -2
- package/runtime/node_modules/@metro-labs/mcp/src/stations/account-store.ts +0 -80
- package/runtime/node_modules/@metro-labs/mcp/src/stations/messaging-normalize.ts +0 -88
- package/runtime/node_modules/@metro-labs/telegram/src/normalize.ts +0 -22
- package/runtime/node_modules/@metro-labs/telegram/src/wire.ts +0 -1
- package/runtime/node_modules/@metro-labs/telegram-bot/src/wire.ts +0 -3
- package/runtime/node_modules/@metro-labs/whatsapp/src/normalize.ts +0 -22
- package/runtime/node_modules/@metro-labs/whatsapp/src/wire.ts +0 -5
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-push.ts +0 -87
- package/runtime/node_modules/@metro-labs/xmtp/src/emit-core.ts +0 -55
- package/runtime/node_modules/@metro-labs/xmtp/src/push.ts +0 -349
- /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/log.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp/src/mcp → core/src}/str.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/train-error.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/webhook-note.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/raw-get-stream.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → http/src}/api-error.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → http/src}/cors.ts +0 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import { ApiError } from '@metro-labs/http/api-error';
|
|
3
|
+
import type { RunnerActivity } from '@metro-labs/core/runner-activity';
|
|
4
|
+
import { readAgentActivity } from './runner-activity.js';
|
|
5
|
+
import { sdkAlive, stopSdkRunner } from './runner-process.js';
|
|
6
|
+
import { continueArgs, sdkPending } from './session-continuity.js';
|
|
7
|
+
import { syncAgentView } from '../agent-user/view.js';
|
|
8
|
+
import { homedir } from 'node:os';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
import { errMsg, log } from '@metro-labs/core/log';
|
|
11
|
+
import { isRecord } from '@metro-labs/core/is-record';
|
|
12
|
+
import { readJson, writeJson } from '@metro-labs/core/secure-fs';
|
|
13
|
+
import { METRO_VERSION } from '@metro-labs/core/version';
|
|
14
|
+
import { agentsDir, listAgentFiles } from '../agents/files.js';
|
|
15
|
+
import { notReady, readModelConfig, routedConnection } from '../gateway/model-config.js';
|
|
16
|
+
import { claudeDir } from './files.js';
|
|
17
|
+
import { harnessRunner, isHarnessRunner, sdkAllowed, SDK_NEEDS_KEY, type HarnessRunner } from './runner.js';
|
|
18
|
+
import { claudeAccount, claudeInstalled } from './login.js';
|
|
19
|
+
import { trustFolder } from './onboarding.js';
|
|
20
|
+
import { inSessionScope } from './memory.js';
|
|
21
|
+
import { runningAsRoot } from '../metro-user/privilege.js';
|
|
22
|
+
import { agentExtraEnv, agentUser, agentUserExpected, agentViewDir, asAgent, claudeHome } from '../agent-user/user.js';
|
|
23
|
+
|
|
24
|
+
function sessionEnv(): Record<string, string> {
|
|
25
|
+
const user = agentUser();
|
|
26
|
+
if (user === null) return {};
|
|
27
|
+
const port = process.env.METRO_WEBHOOK_PORT?.trim() ?? '';
|
|
28
|
+
return { ...agentExtraEnv(), METRO_AGENTS_DIR: agentViewDir(user), ...(port === '' ? {} : { METRO_WEBHOOK_PORT: port }) };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const SESSION_NAME = 'metro';
|
|
32
|
+
const STATE_FILE = 'claude-session.json';
|
|
33
|
+
const WARNING = 'WARNING: Loading development channels';
|
|
34
|
+
const CONFIRM_POLL_MS = 500;
|
|
35
|
+
const CONFIRM_WAIT_MS = 60_000;
|
|
36
|
+
const WATCH_MS = 15_000;
|
|
37
|
+
const STRIKE_WINDOW_MS = 60_000;
|
|
38
|
+
const MAX_STRIKES = 5;
|
|
39
|
+
const PAUSE_MS = 30 * 60_000;
|
|
40
|
+
|
|
41
|
+
export interface SessionDeps {
|
|
42
|
+
tmux?: string;
|
|
43
|
+
metro?: string[];
|
|
44
|
+
runner?: string[];
|
|
45
|
+
home?: string;
|
|
46
|
+
agents?: string;
|
|
47
|
+
signedIn?: () => boolean;
|
|
48
|
+
now?: () => number;
|
|
49
|
+
version?: string;
|
|
50
|
+
prepare?: (runner: HarnessRunner) => Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface SessionStatus {
|
|
54
|
+
name: string;
|
|
55
|
+
running: boolean;
|
|
56
|
+
runner?: HarnessRunner;
|
|
57
|
+
activity?: RunnerActivity | null;
|
|
58
|
+
autostart: boolean;
|
|
59
|
+
blocked: string | null;
|
|
60
|
+
lastStartedAt: string | null;
|
|
61
|
+
lastError: string | null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface Memory {
|
|
65
|
+
lastStartedAt: number | null;
|
|
66
|
+
lastError: string | null;
|
|
67
|
+
strikes: number;
|
|
68
|
+
pausedUntil: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const memory: Memory = { lastStartedAt: null, lastError: null, strikes: 0, pausedUntil: 0 };
|
|
72
|
+
|
|
73
|
+
const statePath = (agents: string): string => join(agents, STATE_FILE);
|
|
74
|
+
|
|
75
|
+
function readState(agents: string): Record<string, unknown> {
|
|
76
|
+
const raw = readJson<unknown>(statePath(agents), null);
|
|
77
|
+
return isRecord(raw) ? raw : {};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const writeState = (agents: string, patch: Record<string, unknown>): void => {
|
|
81
|
+
writeJson(statePath(agents), { ...readState(agents), ...patch });
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const autostartEnabled = (agents = agentsDir()): boolean => readState(agents).autostart !== false;
|
|
85
|
+
|
|
86
|
+
export function setAutostart(enabled: boolean, agents = agentsDir()): void {
|
|
87
|
+
writeState(agents, { autostart: enabled });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function startedVersion(agents = agentsDir()): string | null {
|
|
91
|
+
const version = readState(agents).version;
|
|
92
|
+
return typeof version === 'string' ? version : null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function tmuxOk(tmux: string, args: string[]): boolean {
|
|
96
|
+
const run = spawnSync(...asAgent(tmux, args), { stdio: 'ignore' });
|
|
97
|
+
return run.error === undefined && run.status === 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export const sessionRunning = (tmux = 'tmux'): boolean => tmuxOk(tmux, ['has-session', '-t', SESSION_NAME]);
|
|
101
|
+
|
|
102
|
+
export const tmuxServerUp = (tmux = 'tmux'): boolean => tmuxOk(tmux, ['list-sessions']);
|
|
103
|
+
|
|
104
|
+
export function metroCli(args: string[], fixed?: string[]): string[] {
|
|
105
|
+
const bin = process.env.METRO_CLI_BIN?.trim() ?? '';
|
|
106
|
+
const runtime = agentUser() === null ? process.execPath : 'node';
|
|
107
|
+
const base = fixed ?? (bin === '' ? ['metro', ...args] : [runtime, bin, ...args]);
|
|
108
|
+
const env = Object.entries(sessionEnv()).map(([k, v]) => `${k}=${v}`);
|
|
109
|
+
return env.length === 0 || fixed !== undefined ? base : ['env', ...env, ...base];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const sessionHome = (deps: SessionDeps): string => deps.home ?? claudeHome() ?? homedir();
|
|
113
|
+
|
|
114
|
+
export function sessionRunner(deps: SessionDeps = {}): HarnessRunner {
|
|
115
|
+
const agents = deps.agents ?? agentsDir();
|
|
116
|
+
const runner = readState(agents).runner;
|
|
117
|
+
return isHarnessRunner(runner) ? runner : harnessRunner(agents);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function assertSessionStopped(deps: SessionDeps = {}): void {
|
|
121
|
+
if (sessionLive(deps)) throw new ApiError('The session is running. Let it finish its work, stop it, then change its runner, permissions or prompt and start it again.', 409);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function assertSdkDrained(deps: SessionDeps = {}): void {
|
|
125
|
+
if (sdkPending(sessionHome(deps)) !== 0)
|
|
126
|
+
throw new ApiError('The Agent SDK still has chat messages it has not answered, or its saved state cannot be read. Start it so it answers them (fix the Model page first if it cannot start), stop it, then switch runners.', 409);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
let changing = false;
|
|
130
|
+
|
|
131
|
+
export async function withSessionChange<T>(run: () => Promise<T>): Promise<T> {
|
|
132
|
+
if (changing) throw new ApiError('A session change is already being prepared. Try again when it finishes.', 409);
|
|
133
|
+
changing = true;
|
|
134
|
+
try {
|
|
135
|
+
return await run();
|
|
136
|
+
} finally {
|
|
137
|
+
changing = false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export async function prepareSessionRunner(runner: HarnessRunner, deps: SessionDeps = {}): Promise<void> {
|
|
142
|
+
if (deps.prepare !== undefined) return deps.prepare(runner);
|
|
143
|
+
const [bin = 'metro', ...args] = metroCli(['agent', '--prepare', runner]);
|
|
144
|
+
await new Promise<void>((resolve, reject) => {
|
|
145
|
+
const child = spawn(...asAgent(bin, args), { stdio: ['ignore', 'ignore', 'pipe'], timeout: 16 * 60_000 });
|
|
146
|
+
let error = '';
|
|
147
|
+
child.stderr.on('data', (chunk: Buffer) => { error = (error + chunk.toString()).slice(-2000); });
|
|
148
|
+
child.on('error', (err) => { reject(new ApiError(`Runner preparation failed: ${errMsg(err)}`, 503)); });
|
|
149
|
+
child.on('close', (code) => {
|
|
150
|
+
if (code === 0) resolve();
|
|
151
|
+
else reject(new ApiError(`Runner preparation failed. The runner choice was not changed. ${error.trim()}`, 503));
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function metroCommand(deps: SessionDeps, home: string): string[] {
|
|
157
|
+
if (harnessRunner(deps.agents ?? agentsDir()) === 'sdk') return metroCli(['agent'], deps.runner);
|
|
158
|
+
return [...metroCli(['claude'], deps.metro), ...continueArgs(home, claudeDir(), deps.agents)];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function credentialReady(deps: SessionDeps): string | null {
|
|
162
|
+
const signedIn = deps.signedIn ?? (() => claudeAccount().signedIn);
|
|
163
|
+
if (signedIn()) return null;
|
|
164
|
+
try {
|
|
165
|
+
const cfg = readModelConfig(deps.agents ?? agentsDir());
|
|
166
|
+
const conn = routedConnection(cfg);
|
|
167
|
+
if (conn !== null && notReady(cfg) === null && (conn.provider !== 'anthropic' || conn.apiKey !== '')) return null;
|
|
168
|
+
} catch (err) {
|
|
169
|
+
return `the Model page is not readable (${errMsg(err)})`;
|
|
170
|
+
}
|
|
171
|
+
return 'Claude Code is not signed in and the Model page routes nowhere yet';
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const agentUserMissing = (deps: SessionDeps): boolean =>
|
|
175
|
+
deps.metro === undefined && agentUserExpected() && agentUser() === null;
|
|
176
|
+
|
|
177
|
+
const ROOT_REFUSED = 'Metro runs as root; reinstall it as the metro user';
|
|
178
|
+
|
|
179
|
+
export function sessionBlocked(deps: SessionDeps = {}): string | null {
|
|
180
|
+
if (runningAsRoot()) return ROOT_REFUSED;
|
|
181
|
+
const agents = deps.agents ?? agentsDir();
|
|
182
|
+
if (harnessRunner(agents) === 'sdk' && !sdkAllowed(agents)) return SDK_NEEDS_KEY;
|
|
183
|
+
if (listAgentFiles(agents).length === 0) return 'no agent on this machine yet';
|
|
184
|
+
return launchBlocked(deps);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function launchBlocked(deps: SessionDeps): string | null {
|
|
188
|
+
if (agentUserMissing(deps))
|
|
189
|
+
return 'Claude Code runs as the user agent here, and that user is not ready yet; see the log';
|
|
190
|
+
if (deps.metro === undefined && !claudeInstalled()) return 'Claude Code is not installed on this machine';
|
|
191
|
+
if (!tmuxOk(deps.tmux ?? 'tmux', ['-V'])) return 'tmux is not installed on this machine';
|
|
192
|
+
return credentialReady(deps);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function capturePane(tmux: string): string {
|
|
196
|
+
const run = spawnSync(...asAgent(tmux, ['capture-pane', '-p', '-t', SESSION_NAME]), { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
|
|
197
|
+
return run.error === undefined && run.status === 0 ? run.stdout : '';
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function noteLaunchLines(pane: string, seen: Set<string>): void {
|
|
201
|
+
for (const line of pane.split('\n').map((l) => l.trim()))
|
|
202
|
+
if (line.startsWith('metro claude:') && !seen.has(line)) {
|
|
203
|
+
seen.add(line);
|
|
204
|
+
log.info({ line }, 'claude-session: metro claude said');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function confirmChannels(tmux: string, until: number): void {
|
|
209
|
+
const seen = new Set<string>();
|
|
210
|
+
let confirmed = false;
|
|
211
|
+
const tick = (): void => {
|
|
212
|
+
const pane = capturePane(tmux);
|
|
213
|
+
noteLaunchLines(pane, seen);
|
|
214
|
+
if (!confirmed && pane.includes(WARNING) && pane.includes('server:metro')) {
|
|
215
|
+
spawnSync(...asAgent(tmux, ['send-keys', '-t', SESSION_NAME, 'Enter']), { stdio: 'ignore' });
|
|
216
|
+
log.info('claude-session: confirmed the development channels dialog for server:metro');
|
|
217
|
+
confirmed = true;
|
|
218
|
+
}
|
|
219
|
+
if (Date.now() < until && sessionRunning(tmux)) setTimeout(tick, CONFIRM_POLL_MS).unref();
|
|
220
|
+
};
|
|
221
|
+
setTimeout(tick, CONFIRM_POLL_MS).unref();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function recordStart(deps: SessionDeps, tmux: string, now: number, run: { error?: Error; status: number | null; stderr: string }): void {
|
|
225
|
+
memory.lastStartedAt = now;
|
|
226
|
+
if (run.error !== undefined || run.status !== 0) {
|
|
227
|
+
memory.lastError = run.error === undefined ? `tmux new-session exited ${String(run.status)}: ${run.stderr.trim()}` : errMsg(run.error);
|
|
228
|
+
log.warn({ err: memory.lastError }, 'claude-session: tmux could not start');
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
memory.lastError = null;
|
|
232
|
+
const agents = deps.agents ?? agentsDir();
|
|
233
|
+
writeState(agents, { version: deps.version ?? METRO_VERSION, runner: harnessRunner(agents) });
|
|
234
|
+
confirmChannels(tmux, now + CONFIRM_WAIT_MS);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function tmuxLaunch(deps: SessionDeps, tmux: string, args: string[]): [string, string[]] {
|
|
238
|
+
const launch = asAgent(tmux, args);
|
|
239
|
+
return deps.tmux === undefined && !tmuxServerUp(tmux) ? inSessionScope(launch) : launch;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function startSession(deps: SessionDeps = {}): SessionStatus {
|
|
243
|
+
if (changing) throw new ApiError('A runner change is being prepared. Start the session after it finishes.', 409);
|
|
244
|
+
const status = sessionStatus(deps);
|
|
245
|
+
if (status.running) return status;
|
|
246
|
+
if (status.blocked !== null) throw new ApiError(`Cannot start the session: ${status.blocked}`, 409);
|
|
247
|
+
syncAgentView(undefined, deps.agents);
|
|
248
|
+
const tmux = deps.tmux ?? 'tmux';
|
|
249
|
+
const home = sessionHome(deps);
|
|
250
|
+
const now = (deps.now ?? Date.now)();
|
|
251
|
+
const trusted = trustFolder(home);
|
|
252
|
+
const [command = 'metro', ...args] = metroCommand(deps, home);
|
|
253
|
+
const tmuxArgs = ['new-session', '-d', '-s', SESSION_NAME, '-c', home, '-x', '200', '-y', '50', command, ...args];
|
|
254
|
+
const launch = tmuxLaunch(deps, tmux, tmuxArgs);
|
|
255
|
+
const run = spawnSync(...launch, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], cwd: '/' });
|
|
256
|
+
recordStart(deps, tmux, now, run);
|
|
257
|
+
if (memory.lastError === null) log.info({ home, trusted, command: [command, ...args].join(' ') }, 'claude-session: started Claude Code in tmux');
|
|
258
|
+
return sessionStatus(deps);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export function stopSession(deps: SessionDeps = {}): SessionStatus {
|
|
262
|
+
spawnSync(...asAgent(deps.tmux ?? 'tmux', ['kill-session', '-t', SESSION_NAME]), { stdio: 'ignore' });
|
|
263
|
+
stopSdkRunner(sessionHome(deps));
|
|
264
|
+
return sessionStatus(deps);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export const sessionLive = (deps: SessionDeps = {}): boolean =>
|
|
268
|
+
sessionRunning(deps.tmux ?? 'tmux') || sdkAlive(readAgentActivity(sessionHome(deps)));
|
|
269
|
+
|
|
270
|
+
export function sessionStatus(deps: SessionDeps = {}): SessionStatus {
|
|
271
|
+
const activity = readAgentActivity(sessionHome(deps));
|
|
272
|
+
const sdk = sdkAlive(activity);
|
|
273
|
+
return {
|
|
274
|
+
name: SESSION_NAME,
|
|
275
|
+
running: sessionRunning(deps.tmux ?? 'tmux') || sdk,
|
|
276
|
+
runner: sdk ? 'sdk' : sessionRunner(deps),
|
|
277
|
+
activity,
|
|
278
|
+
autostart: autostartEnabled(deps.agents ?? agentsDir()),
|
|
279
|
+
blocked: sessionBlocked(deps),
|
|
280
|
+
lastStartedAt: memory.lastStartedAt === null ? null : new Date(memory.lastStartedAt).toISOString(),
|
|
281
|
+
lastError: memory.lastError,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function strike(now: number): boolean {
|
|
286
|
+
if (memory.lastStartedAt !== null && now - memory.lastStartedAt < STRIKE_WINDOW_MS) memory.strikes += 1;
|
|
287
|
+
else memory.strikes = 1;
|
|
288
|
+
if (memory.strikes < MAX_STRIKES) return false;
|
|
289
|
+
memory.pausedUntil = now + PAUSE_MS;
|
|
290
|
+
memory.strikes = 0;
|
|
291
|
+
log.warn({ pauseMinutes: PAUSE_MS / 60_000 }, 'claude-session: Claude Code keeps exiting right after starting; not restarting it for a while');
|
|
292
|
+
return true;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export type Ensured = 'started' | 'restarted' | 'running' | 'blocked' | 'off' | 'paused';
|
|
296
|
+
|
|
297
|
+
function holdsBack(deps: SessionDeps, now: number): Ensured | null {
|
|
298
|
+
if (now < memory.pausedUntil) return 'paused';
|
|
299
|
+
if (sessionBlocked(deps) !== null) return 'blocked';
|
|
300
|
+
return strike(now) ? 'paused' : null;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
interface Resolved {
|
|
304
|
+
now: number;
|
|
305
|
+
agents: string;
|
|
306
|
+
version: string;
|
|
307
|
+
tmux: string;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const resolved = (deps: SessionDeps): Resolved => ({
|
|
311
|
+
now: (deps.now ?? Date.now)(),
|
|
312
|
+
agents: deps.agents ?? agentsDir(),
|
|
313
|
+
version: deps.version ?? METRO_VERSION,
|
|
314
|
+
tmux: deps.tmux ?? 'tmux',
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
function situation(r: Resolved): 'running' | 'stale' | 'absent' {
|
|
318
|
+
if (!sessionRunning(r.tmux)) return 'absent';
|
|
319
|
+
return startedVersion(r.agents) === r.version ? 'running' : 'stale';
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export function ensureSession(deps: SessionDeps = {}): Ensured {
|
|
323
|
+
const r = resolved(deps);
|
|
324
|
+
if (!autostartEnabled(r.agents)) return 'off';
|
|
325
|
+
if (changing) return 'blocked';
|
|
326
|
+
const found = situation(r);
|
|
327
|
+
if (found === 'running' || (found === 'absent' && sessionLive(deps))) return 'running';
|
|
328
|
+
const held = holdsBack(deps, r.now);
|
|
329
|
+
if (held !== null) return held;
|
|
330
|
+
if (found === 'stale') {
|
|
331
|
+
log.info({ was: startedVersion(r.agents), now: r.version }, 'claude-session: restarting the session an older metro started, so the new plugin and flags load');
|
|
332
|
+
stopSession(deps);
|
|
333
|
+
}
|
|
334
|
+
startSession(deps);
|
|
335
|
+
return found === 'stale' ? 'restarted' : 'started';
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
let watcher: ReturnType<typeof setInterval> | null = null;
|
|
339
|
+
|
|
340
|
+
export function watchSession(deps: SessionDeps = {}, everyMs = WATCH_MS): void {
|
|
341
|
+
if (watcher !== null) return;
|
|
342
|
+
const tick = (): void => {
|
|
343
|
+
try {
|
|
344
|
+
const outcome = ensureSession(deps);
|
|
345
|
+
if (outcome === 'started' || outcome === 'restarted') log.info({ outcome }, 'claude-session: Claude Code is up');
|
|
346
|
+
} catch (err) {
|
|
347
|
+
log.warn({ err: errMsg(err) }, 'claude-session: check failed');
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
watcher = setInterval(tick, everyMs);
|
|
351
|
+
watcher.unref();
|
|
352
|
+
setTimeout(tick, 1_000).unref();
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export function unwatchSession(): void {
|
|
356
|
+
if (watcher !== null) clearInterval(watcher);
|
|
357
|
+
watcher = null;
|
|
358
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { existsSync, readFileSync, realpathSync, statSync } from '../agent-user/agent-fs.js';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { ApiError } from '@metro-labs/http/api-error';
|
|
4
|
+
import { claudeDir, listClaudeProjects } from './files.js';
|
|
5
|
+
import { isRecord } from '@metro-labs/core/is-record';
|
|
6
|
+
import { errMsg } from '@metro-labs/core/log';
|
|
7
|
+
import { writeHomeText } from '../agent-user/home-fs.js';
|
|
8
|
+
|
|
9
|
+
export const SETTINGS_MAX = 256 * 1024;
|
|
10
|
+
const USER_ID = 'user';
|
|
11
|
+
const LOCAL_SUFFIX = '.local';
|
|
12
|
+
|
|
13
|
+
type SettingsScope = 'user' | 'project' | 'local';
|
|
14
|
+
|
|
15
|
+
export interface ClaudeSettingsFile {
|
|
16
|
+
id: string;
|
|
17
|
+
scope: SettingsScope;
|
|
18
|
+
label: string;
|
|
19
|
+
path: string;
|
|
20
|
+
exists: boolean;
|
|
21
|
+
editable: boolean;
|
|
22
|
+
text: string;
|
|
23
|
+
modifiedAt: string | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const missing = (id: string, scope: SettingsScope, label: string, path: string): ClaudeSettingsFile => ({
|
|
27
|
+
id,
|
|
28
|
+
scope,
|
|
29
|
+
label,
|
|
30
|
+
path,
|
|
31
|
+
exists: false,
|
|
32
|
+
editable: true,
|
|
33
|
+
text: '',
|
|
34
|
+
modifiedAt: null,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
function entryOf(id: string, scope: SettingsScope, label: string, path: string): ClaudeSettingsFile {
|
|
38
|
+
if (!existsSync(path)) return missing(id, scope, label, path);
|
|
39
|
+
const stat = statSync(path);
|
|
40
|
+
const editable = stat.size <= SETTINGS_MAX;
|
|
41
|
+
return {
|
|
42
|
+
id,
|
|
43
|
+
scope,
|
|
44
|
+
label,
|
|
45
|
+
path,
|
|
46
|
+
exists: true,
|
|
47
|
+
editable,
|
|
48
|
+
text: editable ? readFileSync(path, 'utf8') : '',
|
|
49
|
+
modifiedAt: stat.mtime.toISOString(),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const PROJECT_FILES: [string, SettingsScope, string][] = [
|
|
54
|
+
['', 'project', 'settings.json'],
|
|
55
|
+
[LOCAL_SUFFIX, 'local', 'settings.local.json'],
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
function projectEntries(dir: string): ClaudeSettingsFile[] {
|
|
59
|
+
const out: ClaudeSettingsFile[] = [];
|
|
60
|
+
for (const project of listClaudeProjects(dir)) {
|
|
61
|
+
const cwd = project.cwd;
|
|
62
|
+
if (cwd === null) continue;
|
|
63
|
+
for (const [suffix, scope, name] of PROJECT_FILES) {
|
|
64
|
+
const path = join(cwd, '.claude', name);
|
|
65
|
+
if (existsSync(path)) out.push(entryOf(`${project.id}${suffix}`, scope, cwd, path));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const sameFile = (a: string, b: string): boolean => {
|
|
72
|
+
try {
|
|
73
|
+
return realpathSync(a) === realpathSync(b);
|
|
74
|
+
} catch {
|
|
75
|
+
return a === b;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export function listClaudeSettings(dir = claudeDir()): ClaudeSettingsFile[] {
|
|
80
|
+
const user = entryOf(USER_ID, 'user', 'This machine', join(dir, 'settings.json'));
|
|
81
|
+
return [user, ...projectEntries(dir).filter((p) => !sameFile(p.path, user.path))];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function assertSettingsJson(text: string): void {
|
|
85
|
+
if (text.length > SETTINGS_MAX) throw new ApiError('that is more text than a settings file may hold', 413);
|
|
86
|
+
let parsed: unknown;
|
|
87
|
+
try {
|
|
88
|
+
parsed = JSON.parse(text);
|
|
89
|
+
} catch (err) {
|
|
90
|
+
throw new ApiError(`that is not valid JSON: ${errMsg(err)}`, 400);
|
|
91
|
+
}
|
|
92
|
+
if (!isRecord(parsed)) throw new ApiError('Claude Code settings must be a JSON object', 400);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function writeClaudeSettings(
|
|
96
|
+
id: string,
|
|
97
|
+
text: string,
|
|
98
|
+
seenAt: string | null | undefined,
|
|
99
|
+
dir = claudeDir(),
|
|
100
|
+
): ClaudeSettingsFile {
|
|
101
|
+
const target = listClaudeSettings(dir).find((file) => file.id === id);
|
|
102
|
+
if (target === undefined) throw new ApiError('no such settings file', 404);
|
|
103
|
+
if (!target.editable) throw new ApiError('that settings file is too large to edit here', 409);
|
|
104
|
+
assertSettingsJson(text);
|
|
105
|
+
if (seenAt !== undefined && seenAt !== target.modifiedAt)
|
|
106
|
+
throw new ApiError('that file changed on disk since you opened it; reload it before saving', 409);
|
|
107
|
+
writeHomeText(target.path, text, existsSync(target.path) ? statSync(target.path).mode & 0o777 : 0o644);
|
|
108
|
+
return entryOf(target.id, target.scope, target.label, target.path);
|
|
109
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
import { log } from '@metro-labs/core/log';
|
|
3
|
+
import { isRecord } from '@metro-labs/core/is-record';
|
|
4
|
+
import { ApiError } from '@metro-labs/http/api-error';
|
|
5
|
+
import { readJsonBody, type ApiSession } from '@metro-labs/http/api-http';
|
|
6
|
+
import {
|
|
7
|
+
claudeSetupStatus,
|
|
8
|
+
ensureClaudeSetup,
|
|
9
|
+
isPermissionMode,
|
|
10
|
+
liveEvents,
|
|
11
|
+
permissionMode,
|
|
12
|
+
setLiveEvents,
|
|
13
|
+
setMemoryRoutine,
|
|
14
|
+
setPermissionMode,
|
|
15
|
+
setPrivacy,
|
|
16
|
+
setSystemPrompt,
|
|
17
|
+
systemPrompt,
|
|
18
|
+
SYSTEM_PROMPT_MAX,
|
|
19
|
+
type PermissionMode,
|
|
20
|
+
type SetupDeps,
|
|
21
|
+
} from './setup.js';
|
|
22
|
+
import { harnessRunner, isHarnessRunner, sdkAllowed, sdkOnLogin, SDK_NEEDS_KEY, setHarnessRunner, setSdkOnLogin, type HarnessRunner } from './runner.js';
|
|
23
|
+
import { assertSdkDrained, assertSessionStopped, prepareSessionRunner, setAutostart, withSessionChange, type SessionDeps } from './session.js';
|
|
24
|
+
import { tryMemoryJob } from './memory-routine.js';
|
|
25
|
+
|
|
26
|
+
const SETUP_BODY_MAX = SYSTEM_PROMPT_MAX * 2;
|
|
27
|
+
const OPERATOR_ONLY = 'only the Metro operator can allow the Agent SDK on a Claude login';
|
|
28
|
+
|
|
29
|
+
export interface SetupApiDeps {
|
|
30
|
+
session?: SessionDeps;
|
|
31
|
+
setup?: SetupDeps;
|
|
32
|
+
liveEvents?: (on: boolean) => void;
|
|
33
|
+
memoryJob?: (on: boolean) => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface SetupChange {
|
|
37
|
+
privacy?: boolean;
|
|
38
|
+
permissionMode?: PermissionMode;
|
|
39
|
+
runner?: HarnessRunner;
|
|
40
|
+
sdkOnLogin?: boolean;
|
|
41
|
+
systemPrompt?: string;
|
|
42
|
+
liveEvents?: boolean;
|
|
43
|
+
memoryRoutine?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function promptChange(raw: unknown): string | undefined {
|
|
47
|
+
if (raw === undefined) return undefined;
|
|
48
|
+
if (typeof raw !== 'string') throw new ApiError('systemPrompt must be text', 400);
|
|
49
|
+
if (Buffer.byteLength(raw) > SYSTEM_PROMPT_MAX) throw new ApiError(`systemPrompt must be under ${String(SYSTEM_PROMPT_MAX / 1024)} KiB`, 400);
|
|
50
|
+
return raw;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function flagChange(raw: unknown, name: string): boolean | undefined {
|
|
54
|
+
if (raw === undefined) return undefined;
|
|
55
|
+
if (typeof raw !== 'boolean') throw new ApiError(`${name} must be true or false`, 400);
|
|
56
|
+
return raw;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function modeChange(raw: unknown): PermissionMode | undefined {
|
|
60
|
+
if (raw === undefined) return undefined;
|
|
61
|
+
if (!isPermissionMode(raw)) throw new ApiError('permissionMode must be auto or bypass', 400);
|
|
62
|
+
return raw;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function runnerChange(raw: unknown): HarnessRunner | undefined {
|
|
66
|
+
if (raw === undefined) return undefined;
|
|
67
|
+
if (!isHarnessRunner(raw)) throw new ApiError('runner must be cli or sdk', 400);
|
|
68
|
+
return raw;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function setupChange(body: unknown): SetupChange {
|
|
72
|
+
if (!isRecord(body)) throw new ApiError('a body is required', 400);
|
|
73
|
+
const change: SetupChange = {
|
|
74
|
+
privacy: flagChange(body.privacy, 'privacy'),
|
|
75
|
+
permissionMode: modeChange(body.permissionMode),
|
|
76
|
+
runner: runnerChange(body.runner),
|
|
77
|
+
sdkOnLogin: flagChange(body.sdkOnLogin, 'sdkOnLogin'),
|
|
78
|
+
systemPrompt: promptChange(body.systemPrompt),
|
|
79
|
+
liveEvents: flagChange(body.liveEvents, 'liveEvents'),
|
|
80
|
+
memoryRoutine: flagChange(body.memoryRoutine, 'memoryRoutine'),
|
|
81
|
+
};
|
|
82
|
+
const given = Object.fromEntries(Object.entries(change).filter(([, value]) => value !== undefined)) as SetupChange;
|
|
83
|
+
if (Object.keys(given).length === 0) throw new ApiError('nothing to change', 400);
|
|
84
|
+
return given;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function checkRunnerChange(change: SetupChange, session: ApiSession, agents: string | undefined): void {
|
|
88
|
+
if (change.sdkOnLogin !== undefined && session.operator !== true) throw new ApiError(OPERATOR_ONLY, 403);
|
|
89
|
+
if (change.runner === 'sdk' && !sdkAllowed(agents, undefined, change.sdkOnLogin ?? sdkOnLogin(agents))) throw new ApiError(SDK_NEEDS_KEY, 403);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function nextRunner(change: SetupChange, agents: string | undefined): HarnessRunner {
|
|
93
|
+
const runner = change.runner ?? harnessRunner(agents);
|
|
94
|
+
return runner === 'sdk' && change.sdkOnLogin === false && !sdkAllowed(agents, undefined, false) ? 'cli' : runner;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function changesSession(change: SetupChange, agents: string | undefined): boolean {
|
|
98
|
+
return nextRunner(change, agents) !== harnessRunner(agents)
|
|
99
|
+
|| (change.permissionMode !== undefined && change.permissionMode !== permissionMode(agents))
|
|
100
|
+
|| (change.systemPrompt !== undefined && change.systemPrompt.trim() !== systemPrompt(agents));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function saveSessionSettings(change: SetupChange, runner: HarnessRunner, agents: string | undefined): void {
|
|
104
|
+
if (change.sdkOnLogin !== undefined && change.sdkOnLogin !== sdkOnLogin(agents)) {
|
|
105
|
+
setSdkOnLogin(change.sdkOnLogin, agents);
|
|
106
|
+
log.info({ on: change.sdkOnLogin }, 'claude-setup: the operator changed whether the Agent SDK may run on this box’s Claude login');
|
|
107
|
+
}
|
|
108
|
+
if (runner !== harnessRunner(agents)) {
|
|
109
|
+
setAutostart(false, agents);
|
|
110
|
+
setHarnessRunner(runner, agents);
|
|
111
|
+
}
|
|
112
|
+
if (change.permissionMode !== undefined) setPermissionMode(change.permissionMode, agents);
|
|
113
|
+
if (change.systemPrompt !== undefined) setSystemPrompt(change.systemPrompt, agents);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function checkStoppedChange(change: SetupChange, deps: SetupApiDeps): HarnessRunner {
|
|
117
|
+
const agents = deps.setup?.agents;
|
|
118
|
+
const session = { ...deps.session, agents: deps.session?.agents ?? agents };
|
|
119
|
+
const runner = nextRunner(change, agents);
|
|
120
|
+
if (changesSession(change, agents)) assertSessionStopped(session);
|
|
121
|
+
if (runner !== harnessRunner(agents) && harnessRunner(agents) === 'sdk') assertSdkDrained(session);
|
|
122
|
+
return runner;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function applyLiveEvents(on: boolean, deps: SetupApiDeps): void {
|
|
126
|
+
const agents = deps.setup?.agents;
|
|
127
|
+
if (on !== liveEvents(agents)) setLiveEvents(on, agents);
|
|
128
|
+
deps.liveEvents?.(on);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function applyMemoryRoutine(on: boolean, deps: SetupApiDeps): void {
|
|
132
|
+
setMemoryRoutine(on, deps.setup?.agents);
|
|
133
|
+
(deps.memoryJob ?? tryMemoryJob)(on);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function applySetupChange(change: SetupChange, session: ApiSession, deps: SetupApiDeps, req: IncomingMessage): Promise<void> {
|
|
137
|
+
const setup = deps.setup ?? {};
|
|
138
|
+
checkRunnerChange(change, session, setup.agents);
|
|
139
|
+
const runner = checkStoppedChange(change, deps);
|
|
140
|
+
if (runner !== harnessRunner(setup.agents)) {
|
|
141
|
+
await prepareSessionRunner(runner, deps.session);
|
|
142
|
+
checkRunnerChange(change, session, setup.agents);
|
|
143
|
+
if (checkStoppedChange(change, deps) !== runner) throw new ApiError('The model setup changed during preparation. Choose the runner again.', 409);
|
|
144
|
+
}
|
|
145
|
+
if (req.socket.destroyed) throw new ApiError('The request disconnected during preparation. The runner choice was not changed.', 409);
|
|
146
|
+
if (change.privacy !== undefined) setPrivacy(change.privacy, setup.agents);
|
|
147
|
+
if (change.liveEvents !== undefined) applyLiveEvents(change.liveEvents, deps);
|
|
148
|
+
if (change.memoryRoutine !== undefined) applyMemoryRoutine(change.memoryRoutine, deps);
|
|
149
|
+
saveSessionSettings(change, runner, setup.agents);
|
|
150
|
+
ensureClaudeSetup(setup);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export async function setupAnswer(req: IncomingMessage, deps: SetupApiDeps, session: ApiSession): Promise<unknown> {
|
|
154
|
+
const setup = deps.setup ?? {};
|
|
155
|
+
const method = req.method ?? 'GET';
|
|
156
|
+
if (method === 'GET') return claudeSetupStatus(setup);
|
|
157
|
+
if (method !== 'POST') throw new ApiError('method not allowed', 405);
|
|
158
|
+
const change = setupChange(await readJsonBody(req, SETUP_BODY_MAX));
|
|
159
|
+
await withSessionChange(() => applySetupChange(change, session, deps, req));
|
|
160
|
+
return claudeSetupStatus(setup);
|
|
161
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { mkdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { isRecord } from '@metro-labs/core/is-record';
|
|
4
|
+
import { readJson, writeJson } from '@metro-labs/core/secure-fs';
|
|
5
|
+
|
|
6
|
+
const STATE_FILE = 'claude-setup.json';
|
|
7
|
+
|
|
8
|
+
const statePath = (agents: string): string => join(agents, STATE_FILE);
|
|
9
|
+
|
|
10
|
+
export function readSetupState(agents: string): Record<string, unknown> {
|
|
11
|
+
const raw = readJson<unknown>(statePath(agents), null);
|
|
12
|
+
return isRecord(raw) ? raw : {};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function writeSetupState(agents: string, patch: Record<string, unknown>): void {
|
|
16
|
+
mkdirSync(agents, { recursive: true });
|
|
17
|
+
writeJson(statePath(agents), { ...readSetupState(agents), ...patch });
|
|
18
|
+
}
|