Skip to content

Latest commit

 

History

History
958 lines (779 loc) · 43.5 KB

README.md

File metadata and controls

958 lines (779 loc) · 43.5 KB

Comma Systems

The backend of Comma is one Elixir/Mix umbrella with one release, mix release comma. The release holds several subsystems. Each subsystem is a set of OTP apps under apps/.

Subsystem COMMA_SUBSYSTEMS name What
Salix salix The distributed, multi-tenant multi-agent runtime with optional remote VM environments
Comma product comma_product Comma product backend and API. It drives Salix through the Comma.Salix.* boundary
BridgeForTeams bridge_for_teams Teams backend and dashboard. It shares the Salix runtime
Alert Router alert_router Comma notification router

Comma's @subsystems map in apps/comma/lib/comma.ex lists the apps of each subsystem.

Selecting subsystems per node

A pod runs only the subsystems in COMMA_SUBSYSTEMS (comma-separated). When it is unset, the pod runs all subsystems:

COMMA_SUBSYSTEMS=salix bin/comma start
COMMA_SUBSYSTEMS=comma_product,salix bin/comma start
COMMA_SUBSYSTEMS=bridge_for_teams,salix bin/comma start

An unknown subsystem name stops startup. The selection applies only to the release. mix run and mix test start all umbrella apps.


Salix

Salix uses BEAM/OTP for process orchestration, object storage for aggregate state and content, and PostgreSQL for queried control and coordination data. See the storage boundary, the agent runtime, and the Salix TLA+ specs. Production deployment is in DEPLOYMENT.md.

Production Salix requires object storage with conditional writes, PostgreSQL through salix.database.url, and Redis through REDIS_URL or COMMA_REDIS_URL. Production startup fails when the database or Redis configuration is missing. PostgreSQL migrations and control-data cutover readiness must complete before Salix serves. See DEPLOYMENT.md for storage conditionals (including storage.atomic_operations for GCS) and config/runtime.exs for startup requirements.

Getting started

The team setup needs only Docker Desktop or OrbStack. The Dev Container image pins Elixir, OTP, Node, pnpm, native build tools, and service dependencies. From the repository root:

make dev-backend

This starts MinIO, Postgres, ClickHouse, Redis, Mailpit, and the deterministic LLM. It compiles the source-mounted backend, runs local migrations, and seeds the developer account and Group. It returns when the Salix and Comma APIs are healthy. Build output and service data stay in Docker volumes, so a restart compiles only changed source.

Lifecycle commands:

make dev-container-status
make dev-container-shell
make dev-container-restart  # recompile changed backend source, then wait for health
make dev-systems-logs
make dev-systems-down       # stop containers and keep every volume
make dev-container-rebuild  # only when the Dev Container Dockerfile or toolchain changes

Run Web and Electron from the host with host-installed client dependencies:

pnpm --dir clients install # first host setup only
make dev                  # container backend + host Web on :5174
make dev-electron         # container backend + native Electron

When the backend is ready, these checks must succeed:

curl http://127.0.0.1:4000/health   # Salix API
curl http://127.0.0.1:4200/health   # Comma product API
nc -vz 127.0.0.1 4400               # transfer server

The development-only bootstrap runs the Comma schema cutover on an empty local database. It requires MIX_ENV=dev, COMMA_ENVIRONMENT=local, the local database name, and empty product tables. It fails closed for populated or remote data. Release containers use the one-shot comma-migrate service.

Service Local address
Salix API/dashboard http://127.0.0.1:4000
Comma product API http://127.0.0.1:4200
Salix transfer 127.0.0.1:4400
Mailpit inbox / SMTP http://127.0.0.1:8025 / 127.0.0.1:1025
MinIO API / console http://127.0.0.1:19000 / http://127.0.0.1:19001
Postgres 127.0.0.1:15432
ClickHouse HTTP http://127.0.0.1:18123

Run isolated Salix-only sandboxes in parallel

For Salix work without the Comma product, each worktree can run its own Compose project. Only Salix HTTP and transfer are published to the host:

make salix-dev-up
make salix-dev-info

The worktree path sets the project suffix and the two host ports. The command refuses to start if a host port belongs to another service. To override the label or ports:

SALIX_DEV_ID=router-memory \
SALIX_DEV_HTTP_PORT=25001 \
SALIX_DEV_TRANSFER_PORT=45001 \
make salix-dev-up

Repeat explicit port overrides for each lifecycle command. There is no source watcher. After a Salix code change, rebuild:

make salix-dev-rebuild
make salix-dev-logs
make salix-dev-status  # addresses plus container health
make salix-dev-psql    # psql inside this worktree's private Postgres
make salix-dev-shell   # shell inside the running Salix release container
make salix-dev-down    # stop containers, keep data
make salix-dev-reset   # delete only this worktree's containers and volumes

Generated configuration is in the ignored .local/salix-dev/ directory. An optional compose.override.yml in the generated project directory applies to all lifecycle commands. Keep private environment files there.

Inspect the complete Salix system prompt

Dump a complete prompt through the production composer. This does not start Salix or read storage:

cd systems
mix salix.prompt.dump
mix salix.prompt.dump --role worker --runtime script --no-skill
mix salix.prompt.dump --agent-prompt "Additional diagnostic instructions"

In an OTP release:

bin/comma eval 'SalixAgent.Release.dump_system_prompt()'

Local seed data

The Dev Container seeds before it becomes healthy. make dev-systems-seed is an idempotent rerun. It creates or reuses comma-local@example.com, its default Workspace, the Salix Group Router and Worker, a local credit grant, and the user Chat. It prints the Workspace ID and an API session token for local tools.

make dev-electron stores that Session in the ignored .local/comma-dev-session.json and signs the unpackaged client in. Web, and Electron started with pnpm --dir clients dev:electron, use the real passwordless login. Request a code for that email and read it in Mailpit.

To issue one more credit grant, advance the generation. Repeating a generation issues nothing:

COMMA_LOCAL_CREDIT_GRANT_GENERATION=2 make dev-systems-seed

The seed command mutates users, sessions, workspaces, billing grants, and Chat data. It rejects a non-loopback COMMA_LOCAL_API_BASE_URL. Only an intentional remote-data operation may set COMMA_LOCAL_DEV_SEED_ALLOW_NON_LOOPBACK=I_UNDERSTAND_THIS_MUTATES_REMOTE_DATA. Never set it for local development.

Local builds compile the recommendation mock with COMMA_LOCAL_RECOMMENDATION_MOCK=true. It starts disabled. Toggle it in Settings > Debug. Production builds omit the mock. Connections created while the mock is on must be reconnected to a real provider.

Validate passwordless authentication locally

The default suite is local and deterministic. It needs no Google project or account. Start the backend and Web, then run the smoke in a third terminal:

make dev-backend
pnpm --dir clients dev:web
pnpm --dir clients smoke:auth:local

With the same backend running, the Electron smoke tests the renderer, preload, Main, and local API path. The test is opt-in:

pnpm --dir clients smoke:auth:electron:local

A real Google sign-in is an optional manual canary. Use one Web OAuth Client ID per environment:

Runtime Google Cloud boundary OAuth client Authorized JavaScript origins
Local Web Development/testing project Web: Dev http://127.0.0.1:5174
Staging Web Development/testing project, or dedicated staging Web: Staging https://app-staging.comma.surf
Production Production/publishing project Web: Prod https://app.comma.surf

Production must be in a separate Google project from development and testing. Never add localhost or staging origins to the production OAuth client. Origins are exact scheme + host + port values. The GIS callback flow needs no redirect URI or client secret.

The local stack uses 127.0.0.1 for Web and API so the SameSite=Lax cookie is same-site. Do not mix localhost and 127.0.0.1 in one login flow.

To run the Web canary, add the Google account as a test user while the development project is in Testing:

COMMA_GOOGLE_WEB_CLIENT_ID="YOUR_DEV_WEB_CLIENT_ID" make dev

Electron needs a separate Desktop app client for non-production and for production:

COMMA_GOOGLE_ELECTRON_CLIENT_ID="YOUR_DEV_DESKTOP_CLIENT_ID" \
COMMA_GOOGLE_ELECTRON_CLIENT_SECRET="YOUR_DEV_DESKTOP_CLIENT_SECRET" \
make dev-electron

The Comma backend exchanges the Desktop authorization code. The Desktop client secret stays in server configuration and is never bundled into Electron. Restart the backend after you change the client ID or secret. See Google's GIS Web client setup and production OAuth policy.

Local LLM

The default local LLM is deterministic. It needs no provider key:

  • Send an ordinary Chat message. The reply contains LOCAL_CHAT_OK.
  • Send LOCAL_CREATE_TASK. A Task card appears, opens by its public Comma conversation ID, and reaches completed with LOCAL_TASK_DONE.

Use a real LLM locally

Keep real-provider credentials in the ignored .local/ directory. Do not put an API key in systems/config/compose-dev.json, a tracked Compose file, or a Salix Template record. The Template references an environment variable through api_key_env.

Create the two private files from the repository root:

mkdir -p .local
cp systems/config/compose-dev.json .local/compose-dev-real-llm.json
chmod 600 .local/compose-dev-real-llm.json

In .local/compose-dev-real-llm.json, replace only llm.default_template. For an OpenAI-compatible Responses endpoint:

{
  "template_id": "comma-local-dev",
  "name": "Comma Local Dev Real LLM",
  "model": "YOUR_MODEL",
  "provider": "openai",
  "max_tokens": 2048,
  "context_tokens": 200000,
  "provider_config": {
    "protocol": "responses",
    "base_url": "YOUR_APPROVED_PROVIDER_BASE_URL",
    "api_key_env": "COMMA_REAL_LLM_API_KEY"
  }
}

Put the credential in .local/comma-real-llm.env and restrict it:

COMMA_REAL_LLM_API_KEY=YOUR_LOCAL_PROVIDER_KEY
chmod 600 .local/comma-real-llm.env
make dev-real-llm
# or: make dev-electron-real-llm

systems/docker-compose.devcontainer.real-llm.yml only mounts those ignored files. It holds no credentials.

The local data volume keeps the journaled Template. If the checkout was seeded with the mock, the mounted JSON does not replace the existing comma-local-dev Template. Reset the local volumes before you switch providers:

docker compose \
  -f systems/docker-compose.dev.yml \
  -f systems/docker-compose.devcontainer.yml \
  down -v
make dev-real-llm

This deletes only local Compose data. If replies still contain LOCAL_CHAT_OK, the mock Template is still in the volume. If the provider returns 401, check that api_key_env matches the variable name in .local/comma-real-llm.env. Do not print the rendered Compose configuration, because it expands env_file secrets.

Client processes and local data

make dev and make dev-electron run the client in the foreground. Ctrl-C stops the client and leaves the backend running. Web uses port 5174 and Electron Forge uses 5173. When the backend already runs, use pnpm --dir clients dev:web and pnpm --dir clients dev:electron.

With several worktrees open, quit other Comma Dev Electron processes before an Electron smoke. macOS can keep an older build under the same name and app-data location.

To reset all local data and rerun every migration:

docker compose \
  -f systems/docker-compose.dev.yml \
  -f systems/docker-compose.devcontainer.yml \
  down -v
make dev-systems-up

The default Compose scope is salix,comma_product. This stack does not fake the BridgeForTeams dashboard or real external providers. For BFT Dashboard work, see Bridge For Teams. For the Agent configuration handoff after migrations, see Local model switching.

Host-native setup

Install the libsodium, Opus, and libsrtp2 headers, pkg-config, and a Rust toolchain (brew install libsodium opus srtp pkg-config rustup, or apt-get install libsodium-dev libopus-dev libsrtp2-dev pkg-config with rustup).

# MinIO on :19000 with buckets salix-dev + salix-test
minio server /tmp/minio --address :19000 &
aws --endpoint-url http://127.0.0.1:19000 s3 mb s3://salix-dev
aws --endpoint-url http://127.0.0.1:19000 s3 mb s3://salix-test

mix deps.get
mix test                       # full suite (fake backend + real MinIO)
mix run --no-halt              # API on :4000, transfer on :4400

Salix loads runtime config from /etc/salix/config.json or systems/config.json. Keep a local systems/config.json private (0600) and untracked. Use config/config.example.json for committed examples. Set SALIX_CONFIG_PATH=/absolute/path/to/config.json to use another config file.

The platform VM configuration is ctl/vm/default_config.json, managed from the Salix dashboard or /v1/admin/vm/default-config. When it is absent, Salix uses the top-level vm section of the config JSON. Comma workspaces use the platform configuration. A BridgeForTeams tenant with its own VM config keeps it, unless an operator sets vm.config_source to "platform". A tenant with no VM config uses the platform configuration. Sprites is retired.

Call the API:

curl -X POST localhost:4000/v1/comma/admin/users \
  -H 'authorization: Bearer test-token' \
  -H 'content-type: application/json' \
  -d '{"email":"demo@example.com"}'

This uses the deployment bearer. Human admins use Comma Admin Web. Its commands require a server-derived Admin actor, a reason, target-bound confirmation, idempotency, and durable redacted audit evidence.

New Comma Workspaces default to vm.enabled: true. Explicit vm.enabled: false is kept. In Comma Admin, Users → Workspace & billing → Cloud VM sets the value for a ready Workspace. A change requires an audited reason and target-bound confirmation, and queues the Workspace convergence job. Configuration sync is not VM readiness. Salix removes the shared VM only when no other agent or runtime installation intent needs it.

Real rounds need provider configuration in the agent's Template (protocol, model, base_url, and api_key or api_key_env). There is no cluster-wide fallback key. Without a key, the round fails at the provider and settles with an LLM-error message.

Verbose JSONL logging

The log is disabled by default. Enable it with --log-file <path>, or with log.file in config.json for a release:

mix run --no-halt -- --log-file salix.jsonl

Each agent step becomes one JSON object per line. Credential-looking fields are redacted. The logger is CommaLog (app comma_log), shared by all subsystems.

Salix emergency agent recovery

SalixAgent.force_recover/2 is a break-glass IEx API for an internal-runtime agent that is stuck in a running or queued state. Run it from a trusted shell on a prod Salix/Comma release node:

SalixAgent.force_recover("agent_...",
  session_id: "...",
  timeout: 5_000
)

It stops the live runtime and session processes, repairs the durable internal session state, appends an operator recovery message, and wakes the session on the owning node. It does not archive, cancel, or delete the agent.

Omit session_id: to recover every internal session of the agent that has pending work. To clear the stuck state without a wake, pass wake: false. The session goes back to idle, and pending durable work stays for normal activation.

The result is {:ok, %{"agent_id" => ..., "wake_requested" => ..., "sessions" => [...]}}. Each session entry has its "status", its event count, and its wake result, or an "error".

The API supports only Salix-managed internal runtime agents. Recover an external runtime agent through its own control plane.

BridgeForTeams system-admin shell operations

Run privileged bootstrap and recovery operations from an Elixir shell on a trusted release node, or from a trusted MIX_ENV=prod maintenance shell with the same database configuration. The secret is returned once. Do not persist it outside the operator handoff.

To create a one-time organization invite code:

{:ok, %{code: code}} =
  BridgeForTeams.OrgCreationInvites.create_invite_code(
    org_name: "Acme Co",
    org_slug: "acme-co",
    note: "initial owner for acme-co"
  )

Give the code to the owner. They redeem it in the dashboard signup flow to create the organization and their owner account. The name and slug are bound to the code. Codes are stored only as hashes and cannot be reused.

For staging smoke tests, use the manual GitHub Actions workflow Comma Staging Bootstrap Invite from the trusted main ref. It needs no local GKE credentials. Inputs are org_name, org_slug, note, and ttl_seconds. Download the one-day comma-staging-bootstrap-invite-* artifact and open its signup_url in the staging dashboard. Treat the artifact as a short-lived secret.

To recover an account when organization SSO is misconfigured:

{:ok, %{url: url}} =
  BridgeForTeams.AccountRecovery.create_recovery_link(
    "owner@example.com",
    base_url: "https://teams.example.com",
    note: "temporary SSO recovery"
  )

Send the url to the account owner through a trusted channel. The link signs that account in once at /auth/recovery. Links are stored only as hashes, require an active user, and cannot be reused.

BridgeForTeams CLI

The product CLI is a standalone Go binary in systems/cli/bft. It needs no Elixir or Erlang. In a source checkout:

go build -o /tmp/bft ./cli/bft/cmd/bft
/tmp/bft --help
/tmp/bft commands --json
go test -C cli/bft ./...
cli/bft/scripts/build-release.sh

The BFT CLI Release workflow publishes releases to ${CLOUDFLARE_R2_PUBLIC_BASE_URL}/bft-cli. The dashboard installer reads :bft_cli_artifact_base_url and :bft_cli_release_id.

Test exit codes with the built binary. go run turns a non-zero exit such as 64 into 1.

Output modes:

  • Human mode prints guided setup steps and copyable URLs.
  • Agent mode prints stable JSON. Non-TTY stdout defaults to JSON. In a TTY, pass --json or --output json. Pass --output text to force text. Use --limit, --filter, and --fields to bound the output.
  • Exit codes: 0 success, 2 onboarding step needs manual action, 64 usage or context error, 66 not found, 69 runtime unavailable, 70 unexpected backend error.

Pass credentials by environment variable reference (for example --app-secret-env BFT_FEISHU_APP_SECRET), not as literal arguments. The CLI redacts secret fields and secret-bearing URL query parameters in its output.

Telegram bot

A BotFather bot connects to one Agent Swarm. The behavior is in the moduledocs of SalixIM.Provider.Telegram and SalixIM.ProviderRuntime.

Setup:

  1. Create a bot with @BotFather. Keep privacy mode on and do not make the bot a group admin: Salix has no mention filter for Telegram, so every message the bot receives starts a Router turn.
  2. Connect it on the Swarm Connections page, or with bft telegram connect. Salix checks the token with getMe and polls getUpdates, so there is no callback address. Salix calls https://api.telegram.org.
  3. Add the bot to a group. The group shows up on the page and in bft telegram status. Allow it there, or with bft telegram chats.
  4. Turn off /setjoingroups in BotFather once the bot is in its groups.

Operator notes:

  • A connect made through CFT serves only its allowed_chat_ids. Other chats never reach the Router and the agent cannot send to them. A group outside the list is noted for an admin; a stranger's private chat leaves nothing.
  • A private chat's id is the person's id: bft telegram chats --chat <id> allows one. The page lists only groups and channels the bot was added to.
  • A connect created through the tenant API without allowed_chat_ids serves every chat.
  • One bot serves one connect. Two would take each other's updates.
  • OAuth links, native question buttons, the typing indicator, /status-style commands, Task cards and topics exist only for Comma-managed Telegram chats.

QQ bot

A QQ open platform bot connects to one Agent Swarm. The behavior is in the moduledocs of SalixIM.QQInbound, SalixIM.Provider.QQ, SalixIM.Provider.QQ.Groups, SalixIM.Provider.QQ.Menu, and SalixIM.QQMessageRecord.

Setup:

  1. Create a bot in the QQ open platform. Copy its AppID and AppSecret.
  2. Connect it on the Swarm Connections page, or with bft qq connect. Salix checks the credentials with QQ.
  3. In the QQ bot console, choose Webhook delivery and save the callback address <public base URL>/v1/im/qq/events?app_id=<AppID>. Subscribe to the private chat, group, interaction, and group member events. QQ accepts only HTTPS on port 80, 443, 8080, or 8443.
  4. If the console has an IP allowlist, add the deployment's egress addresses. Salix calls https://api.bot.qq.com.

Operator notes:

  • Salix verifies each callback with the Ed25519 key that QQ derives from the AppSecret.
  • A group takes proactive messages only after a group admin turns on "机器人主动在群聊内发言" for the bot.
  • The group record has every message only when a group admin sets "机器人可获取的群聊消息范围" to "获取群内全部消息". Private chats are not recorded.
  • A bare group mention uses the context QQ attached; without it, Salix reads up to 10 earlier recorded messages of that group (1.5-second budget, at most 32 concurrent reads per node). The Router asks for clarification when no clear request is found.
  • A Task created from a human QQ request posts a Markdown status card to that chat, and a new one on each state change (QQ cannot edit messages). Cards use QQ's reply allowance; later group cards need proactive-message permission.
  • A command panel made in the QQ bot console replaces the Swarm's menu. Delete it in the console to show the menu. A Swarm admin edits shortcuts on the Swarm Connections page or with bft qq menu.
  • qq.list_members and qq.get_member work only for bots on QQ's allowlist. Other bots get error 11253. Ask the QQ open platform to add the bot.

The record uses the Postgres outbox qq_mirror_outbox and the ClickHouse table qq_messages. It is on wherever ClickHouse is configured. qq_mirror.enabled: false in the Salix config turns it off.

WeCom bot

A WeCom (企业微信) AI bot in API mode connects to one Agent Swarm through its long connection. The behavior is in the moduledocs of SalixIM.WeComSocket, SalixIM.WeComSocketRuntime, SalixIM.WeComInbound, SalixIM.WeComFiles, and SalixIM.Provider.WeCom.

Setup:

  1. In the WeCom admin console, open 工作台 → 智能机器人 and create a bot. Choose API mode and the long connection (使用长连接). Copy the Bot ID and the Secret. A super admin of the organization should create the bot. Then each userid is the person's organization account. Otherwise it is an ID that WeCom makes.
  2. Set the bot's 可见范围 to the people who will use it. The bot joins only internal groups, not groups with external contacts.
  3. Connect it on the Swarm Connections page, or with bft wecom connect. Salix checks the credentials by subscribing once on wss://openws.work.weixin.qq.com.

Operator notes:

  • WeCom keeps one long connection per bot. A new subscription takes the bot from the old one. Do not run the bot anywhere else, the console's 调试 too. The socket takes the bot back after 5 seconds, then waits longer each time it is taken again within 15 minutes, up to 10 minutes.
  • One node in the cluster holds each socket, under the lease ctl/im/wecom-socket/<connect_id>. A send from another node reaches it through the :pg scope SalixIM.WeComPG.
  • The socket opens outbound to openws.work.weixin.qq.com:443. Attachments download from *.myqcloud.com. No inbound address or IP allowlist is needed.
  • A group sends the bot only text and mixed messages that mention it. Images, voice, files, and videos come only from private chats.
  • WeCom takes at most 30 messages a minute and 1000 an hour per chat. A send to a chat that never wrote to the bot fails.

Data abilities (SalixMCP.HostedServices, plugins wecom-msg, wecom-mail, wecom-doc, wecom-todo, wecom-schedule, wecom-meeting, wecom-disk, wecom-contact):

  1. In the bot's 可使用权限, grant an ability. 查看使用方式 shows its address, https://qyapi.weixin.qq.com/mcp/v2/bot/<ability>?apikey=…. Each ability has its own key.
  2. On the Swarm Plugins page, enable the ability's plugin and paste the key or that ability's whole address (another address is refused). Salix runs one read-only tool with it. WeCom answers a bad key with errcode 850001 inside a successful result.

Rules:

  • The data is that of the bot's creator (多人使用 shares the creator's permissions). Like any connected account, it serves the whole Agent Swarm: everyone who can reach the Swarm on any channel can use it, and the Swarm's history is shared. Connect the abilities only to a Swarm whose people may read that data.
  • Write tools (send mail, share documents, send messages) reach people outside the Swarm. Plugins turn whole abilities on and off: turning off mail removes reading and sending mail together; one write tool cannot be turned off alone.
  • Grants expire after seven days (the console shows the date). A call with an expired, revoked or replaced key fails as credential_invalid (SalixMCP.Gateway), and the agent tells the person to have the ability granted again. Grant it again and paste the new key.

Lark bot

A custom app of the Lark open platform (open.larksuite.com) connects to one Agent Swarm. A Lark connect holds its own credentials and does not use the organization's Feishu app. The behavior is in the moduledocs of SalixIM.LarkInbound, SalixIM.Provider.Lark, SalixIM.Provider.Lark.Docs, SalixIM.Provider.Lark.Minutes, SalixIM.LarkMessageRecord, and SalixIM.Provider.Lark.Manual.

Setup:

  1. Create a custom app in the Lark Developer Console and add the Bot capability. Copy the App ID, the App Secret, and the Verification Token or the Encrypt Key from Events & Callbacks.
  2. Connect it on the Swarm Connections page, or with bft lark connect.
  3. In Events & Callbacks, choose "Send events to developer's server" and save the request URL <public base URL>/v1/im/lark/events?app_id=<App ID>. Subscribe to im.message.receive_v1, im.message.recalled_v1 and im.chat.member.bot.added_v1 (the bot introduces itself in a new group). Under Callbacks, use the same URL and subscribe to card.action.trigger. Without it, confirmation and question card buttons do nothing.
  4. Import the scopes. Use Copy JSON in the Lark section of the Swarm Connections page, or bft lark scopes --output text (BridgeForTeams.LarkScopes). In Permissions & Scopes, use the batch import. Without im:message.group_msg, the bot gets only messages that mention it.
  5. For a chat with members of another organization, turn on External Sharing in the app's version details and allow the bot in external groups. Lark still refuses the app history reads there with error 230027, so the bot reads what Lark delivered to it from the record.
  6. Create a version of the app and publish it. Scopes and events take effect with the published version.
  7. Run the checks: Run checks on the connect's row, or bft lark checks --org <org> --project <project> (--connect-id for one of several apps). mix bridge_for_teams.run_checks --surface lark_bot prints the same result. The gates are in SalixIM.LarkChecks. bot.first_message and bot.manual are always needs_manual.

Made by a scan (no Developer Console):

  1. On the Swarm Connections page, choose Scan to connect, or in Comma add the Lark plugin. Salix begins Lark's one-click app creation (SalixIM.Provider.Lark.Registration, an OAuth device flow): the page shows a QR code of the link.
  2. The person scans it with Lark (or opens the link in Lark) and confirms. Lark makes and publishes a custom app with the bot, its scopes and its events in that person's tenant, and returns the App ID and App Secret.
  3. Salix connects the app with "events" => "socket". Such an app has no request URL: its events come through the long connection Salix opens (SalixIM.LarkSocket, one per connect in the cluster under a lease held by SalixIM.LarkSocketRuntime). The runtime finds socket connects through their own index (ctl/im_socket_connects/), not by reading every connect. A connect made from Comma has an owner_open_id: only that person's messages reach the Router.
  4. An event the Router could not take is answered with code 500, as the Lark SDKs do, so Lark sends it again. At most 16 events are handled at a time per connect; up to 256 more wait in order, and one past that is answered with code 500.
  5. Lark keeps no events for a long connection that is down. Each time the socket opens, Salix reads back the history of the connect's chats since it was lost (the last ten minutes for a socket that just started), and receipts keep a message from reaching the Router twice (SalixIM.LarkSocket.CatchUp). A message the Router could not take is tried again after 15 s, 1 min and 5 min. The chats read back are those that had a message for the bot and the groups the bot is in; a private chat whose first message comes while the socket is down is not.
  6. An app made by a scan has nobody in the Developer Console. When Lark refuses it for a missing scope (error 99991672, or 230027 need scope), the connect records the scope and the dashboard and Comma name it. The history backfill sets such a chat aside until the next listing. Scan to update on the connect's row (in Comma, Reconnect) begins the same scan with the app's App ID (clientID): the person confirms the scopes the app gets, and the connect keeps the same app.

The registration always begins on Feishu's accounts service and the person confirms on open.larksuite.com/page/cli, as Lark's own CLI does: Lark's /page/launcher makes the app but never answers the poll. The device code is a credential; the dashboard and Comma give it to the browser only encrypted.

The Feishu plugin (飞书, listed under 中国服务 in Comma) and the Feishu section of the dashboard's Swarm Connections page use the same scan, confirmed on open.feishu.cn/page/cli (SalixIM.ProviderConnects.finish_feishu_registration):

  • The Feishu connect owns the app's App Secret, as a Lark connect does, so a Workspace or swarm can connect several scanned apps beside its tenant Feishu app (ProviderAppStore, which an app given by hand uses). The connect has "events" => "socket", and in Comma owner_only. An account whose tenant is Lark is refused.
  • The same long connection and catch-up run against open.feishu.cn. Its events go to SalixIM.ProviderHTTP.handle_feishu_socket_event/2, which takes messages and card presses from the owner only.
  • Removing the plugin retires the connect. The app stays in the member's Feishu tenant.

Security and data notes:

  • Salix accepts a callback when its signature or decryption proves the Encrypt Key, or its token equals the Verification Token. A connect made by a scan takes no callback; its long connection is opened with the App Secret.
  • Documents and Minutes are read as the bot. The bot opens a document only when it is shared with a chat that includes the bot, shared with the app, or open by link inside the tenant.
  • A document link must be on a larksuite.com host. Feishu links go to a Feishu connect.
  • People sign in with their Lark account on the swarm's Connections page (Accounts), or from a chat through the link the bot posts. Each sign-in is a Group OAuth Binding of provider lark (SalixStore.OAuth.Adapters.Lark); the organization's OAuth app for Lark is the bot's Lark app with the redirect URL /v1/oauth/lark/callback and the user scopes of the batch import. A person sees what they took part in or may open; the app sees what was shared with it.
  • The bot finds content without a link. lark.search_docs (Lark's search/v2/doc_wiki/search), lark.list_drive_files and lark.search_meetings run as the app and then as every signed-in account, and lark.get_meeting / lark.get_note try them in that order, unless account names one (app for the app alone). lark.list_wiki_spaces, lark.list_wiki_nodes and lark.list_minutes run as the app unless account names a person. The bot reads what it finds with the same account.
  • Documents, spreadsheets and Base are read as the app first. When the app is denied, the bot reads as the signed-in account of the person who asked, asks that person to sign in when they have no account, and offers an access request as them when their account is denied too. Content writes (update_doc, insert_doc_media, the comment writes) take account the same way, after that person agrees. The error of a denied call names the next step. Other operations refuse account. The same applies to the feishu.* operations. A unified note has no transcript document: lark.get_note with include_transcript reads its transcript page by page from /vc/v1/notes/:id/unified_note_transcript, which Lark gives only to a person.
  • The bot cannot read an external chat (Lark error 230027). lark.get_chat_history, lark.get_thread_replies and lark.get_message with account read a group as a signed-in member (user scope im:message.group_msg:get_as_user). The sign-in also asks for im:message.send_as_user, so a sandbox command run with it (comma exec --credential lark/<alias>=...) sends as that person. With docs:permission.member:apply it asks the owner of a document, spreadsheet or Base for access as that person (lark.request_doc_access, feishu.request_doc_access). The default sign-in does not ask for the scopes that read spreadsheets and Base (sheets:spreadsheet:readonly, bitable:app:readonly) or edit documents and their comments (docx:document, docx:document:write_only, docs:document.comment:create, docs:document.comment:write_only, docs:document.media:upload). The batch import offers them as user scopes, and a sign-in asks for them only when a person needs them (on_demand_scopes/0 of the OAuth adapters), so an app without them still lets people sign in. An oauth.request_authorization that names only these scopes asks for them on top of the default sign-in; the platform keeps what a person granted before. Any other list of scopes replaces the defaults. The sign-in does not ask for private chat scopes.
  • A Worker holds the document and Minutes operations of a Lark connect and every read operation (chat history, threads, search, chats, members, directory). The Router holds all of them.
  • A finished Lark meeting reaches the Router as context. A turn from that message calls no Lark operation (SalixIM.Provider.Lark.MeetingActivationAuthorization).
  • A person invites the bot from a running Lark or Feishu video meeting (SalixMeet.LarkBot). The app needs vc:meeting.bot.join:write, vc:meeting.message:write, the data scope "meeting owner within the app's availability", and the events vc.bot.meeting_invited_v1 and vc.bot.meeting_ended_v1. The bot joins with bots/join and reads transcript and chat from bots/events. A person can ask the bot something by voice or in the meeting chat. The meeting copilot writes the answer as text with bots/message. An app without the scope stays silent in the meeting. Status and the summary go to the inviter's private chat with the bot, and each invitation is its own Meeting, so the bot can be in several meetings at once.
  • The message record uses the outbox lark_mirror_outbox, the ClickHouse table lark_messages, and the switch lark_mirror.enabled. A recall removes the message from search. The record does not import history from before the connect.

Not connected for Lark: run checks for meetings and calendar, and the meeting preparation and history pages of the Dashboard.

Lark plugin and hosted MCP

The system plugin lark (Salix.Control.Plugins) holds the Swarm's Lark connect (lark-im) and im_api.lark.*. It adds the Lark hosted MCP server https://mcp.larksuite.com/mcp (target remote:lark, tools mcp.lark.*). It is on by default in BridgeForTeams. Comma installs it by a scan (above).

  • The MCP connection lark-native uses native MCP OAuth (Salix.Control.RemoteMCPOAuth). A Swarm admin selects Connect on the plugin page and signs in to Lark. The token is that person's Lark user token. It is kept on the Swarm's MCP binding, and every Agent of the Swarm uses it. The bot credentials are not used.
  • Salix requests the same read scopes as for Feishu, plus offline_access.

Sign-in with Lark

An organization can sign members in to the Dashboard with Lark (BridgeForTeams.Auth.Lark), as SSO provider lark. It is separate from the provider feishu and from any Swarm's Lark connect. An organization has one SSO connection, so Lark replaces Feishu or generic OIDC.

  1. Create or select a custom app in the Lark Developer Console. BFT stores its credentials for sign-in only.
  2. Open Settings → Single sign-on, select Lark, and enter the App ID and App Secret. The secret is write-only. A blank secret keeps the stored one while the provider stays Lark.
  3. Copy the Redirect URI from the page (<public base URL>/auth/callback). In Security Settings of the Lark app, add it to the redirect URLs.
  4. Select Run checks, or run bft sso checks --org <org>.
  5. Sign in with a test account in a new browser session at /login?o=<slug>.

Rules:

  • Sign-in needs no scope. Lark returns the email only with contact:user.email:readonly. Enter extra scopes on the Single sign-on page. The Lark app must have them.
  • The login key of a member is the Lark union_id, or else the open_id, in one organization. The user_id is never the key.
  • A Lark identity never matches a Feishu identity or an email. After a switch to Lark, members sign in as new members with the first-sign-in role.
  • A change to or from Lark keeps no scope, tenant binding, or first-sign-in policy of the previous provider, and it needs the new secret.
  • Tenant binding. Threat: a Lark app that more than one tenant can use lets a person of another company sign in and become a member. Authority: the tenant_key in the Lark user info, read with the server's token. The expected value is provider_config["tenant_key"] of the SSO connection. An operator sets it with BridgeForTeams.Orgs.upsert_sso_connection/3. The Dashboard does not write it. Owner: BridgeForTeams.Auth compares the two at each sign-in. Result: on a mismatch the person gets no session, identity, or membership, and Operations records sso.login.failed with lark_tenant_mismatch. A connection without the key has no tenant check. Feishu has the same check with feishu_tenant_mismatch.

Bridge ToB local acceptance

Before live Feishu acceptance, configure the Feishu app and connect. See Feishu.

For a setup-to-first-message smoke, start the local Systems app and the public callback tunnel, then run:

systems/scripts/bridge_tob_acceptance_harness.sh --print-env-template
systems/scripts/bridge_tob_acceptance_harness.sh

The harness reads repo-local .env and 0600 local secret files. It checks readiness, performs Feishu URL verification, posts a synthetic inbound event, and reports the result.

The live smoke checks bot-visible chats and a signed callback preflight. It is read-only by default. BRIDGE_TOB_LIVE_FEISHU_SEND=true sends one real redacted message:

cd systems
mix run --no-start scripts/bridge_tob_feishu_live_smoke.exs
BRIDGE_TOB_LIVE_FEISHU_SEND=true mix run --no-start scripts/bridge_tob_feishu_live_smoke.exs

A first-message pass requires a real Feishu user message and the assistant reply in the same group. Select the group by name or redacted ID prefix:

BRIDGE_TOB_LIVE_FEISHU_TARGET_CHAT_NAME="your smoke group name" \
BRIDGE_TOB_LIVE_FEISHU_TARGET_CHAT_ID_PREFIX=oc_redacted \
BRIDGE_TOB_LIVE_FEISHU_BASE_MESSAGE_COUNT=26 \
BRIDGE_TOB_LIVE_FEISHU_MARKER_PREFIX=bridge-tob-live-real-xxxx \
  mix run --no-start scripts/bridge_tob_feishu_live_smoke.exs

To create a dedicated smoke group in Feishu (an external side effect, off by default):

BRIDGE_TOB_LIVE_FEISHU_CREATE_DEDICATED_GROUP=true \
  mix run --no-start scripts/bridge_tob_feishu_live_smoke.exs

Test matrix

Command What
mix test the full suite
mix test --include multinode cross-node tests on two real BEAM nodes (epmd -daemon first)
mix test --include clickhouse analytics sink against a live ClickHouse at 127.0.0.1:8123
SALIX_E2E_LLM_API_KEY=... mix test apps/salix_agent/test/live_llm*_e2e_test.exs --include live_llm --only live_llm real-provider checks. SALIX_LIVE_LLM_S3_BACKEND=aws uses local MinIO

CI is in .github/workflows/systems-ci.yml.

Production

mix release comma builds the release. Dockerfile builds the deployable image. Configuration comes from the environment through config/runtime.exs. See DEPLOYMENT.md.

Platform telemetry

Follow the systems_observability guide and Observability.