Introducing a new way to review your PRs.

Read the announcement

capsoftware / cap

Open source Loom alternative. Beautiful, shareable screen recordings.

View on GitHub

31 documents · Updated Nov 23, 2026

docs / cli-and-chat-integrations

CLI and chat integrations

The Rust cap CLI and the Discord bot are external surfaces for Cap automation and communication. The CLI lets people, scripts, and AI agents capture, manage, process, and share media. The Discord bot connects a release request in chat to the release workflow and reports its result back to the same conversation.

Surface roles

The two surfaces support different product needs. The CLI is a broad control surface for local capture and Cap cloud work. The Discord bot is a focused release surface for communication and workflow control.

SurfaceMain roleProduct connection
cap CLIRun capture and media workflows from a shell or automation agentUses shared recording, project, export, upload, cloud, and developer-media capabilities
Local MCP serverPresent Cap actions to compatible AI agents through a local protocolRoutes agent requests through the same authenticated Cap API used by the CLI
Discord botStart and track a Cap release from DiscordConnects Discord interactions, GitHub Actions, release notes, and the CrabNebula release page

The CLI is normally installed with Cap Desktop, so the command surface stays aligned with the desktop release. It can also run in a headless environment when the caller provides a suitable credential and server. apps/…/Cargo.toml links the CLI to the shared capture, project, export, automation, camera, media, and agent-protocol packages that support this role.

For the wider capture-client map, see Capture clients and integrations. For other capture surfaces, see Mobile and browser capture clients. For the shared recording foundation, see Recorder SDK and shared core.

Rust CLI

The Rust CLI is a command-line entry point for recording, preparing, publishing, and managing Cap content. It serves people at a terminal and non-interactive callers such as CI jobs and AI agents. Its command surface maps each high-level product action to a focused workflow.

CLI capture and media flow

The CLI turns a local capture target into a Cap project and then into shareable media. A caller checks readiness and discovers inputs first. The CLI then records or takes a screenshot, validates the local project, exports a video or selected edited tracks when needed, and uploads the result.

The main command groups are:

  • targets, record, and screenshot: discover inputs and create local media.
  • project and recordings: inspect, validate, configure, and find local .cap projects.
  • export and export-preview: create video output, separate edited tracks, or a preview frame.
  • upload: send an MP4 or exported project to Cap and return a shareable link.
  • automations: expose rules shared with Cap Desktop.

The normal automation path is targets → record → project validate → export → upload. Detached recording gives a caller a recording ID and lets a later command stop and validate the work. Upload can also export a project first when the caller does not need to inspect the intermediate file. Direct upload accepts MP4 media. Agent credentials use the agent upload flow, while Desktop or legacy credentials use the Desktop-compatible flow; an agent upload always creates a new Cap rather than updating an existing video.

The diagram shows the normal local-to-cloud path.

flowchart LR
    A[Check readiness] --> B[Discover capture targets]
    B --> C[Start recording or screenshot]
    C --> D[Complete local .cap project]
    D --> E[Validate project]
    E --> F[Export video or tracks]
    F --> G[Upload MP4 when needed]
    G --> H[Shareable Cap link]

References: apps/…/main.rs• L195-251 apps/…/export.rs• L42-96 apps/…/export.rs• L429-571 apps/…/export.rs• L690-775 apps/…/upload.rs• L92-223 apps/…/upload.rs• L288-325 apps/…/Cargo.toml• L6-50

CLI recording workers

Detached recording separates the command that starts a capture from the worker that completes it. The command checks the request and returns a recording ID, while the worker keeps session state until a stop request, duration, or capture completion finalizes the project.

The lifecycle is:

  1. Reserve a new project path and start the recording worker.
  2. Return the recording ID, process ID, and project path.
  3. Store progress and stop state so another CLI process can inspect the session.
  4. Finalize and validate the project before reporting a successful stop.

This boundary lets CI or an agent continue a recording after the launching shell exits. An incomplete project or a worker that disappears is reported as an error rather than as a successful recording.

References: apps/…/main.rs• L283-302 apps/…/main.rs• L643-679 apps/…/session.rs• L1-119 apps/…/cli.rs• L1425-1439

CLI cloud management

The CLI also acts as a shell client for an authenticated Cap account. It reads and manages Caps, observes processing, starts confirmed processing, handles transcripts, imports Loom videos, downloads media, and applies sharing or placement changes.

The same surface extends to account and product administration. It covers organizations, members, invites, billing handoffs, custom domains, folders, spaces, storage integrations, notifications, analytics, and long-running operations. Reads and waits observe existing state. Mutations that can change shared data, spend money, or alter access require explicit confirmation.

AreaMain capability
Caps and processingList, inspect, wait for, process, import, download, and update Cap content.
Transcripts and feedbackRead or replace transcripts. Add comments, replies, and reactions.
Sharing and accessSet visibility, manage passwords, unlock protected Caps, and share with organizations or spaces.
Organization and libraryManage organizations, folders, spaces, members, invites, viewer settings, and recording placement.
Account and product administrationManage account settings, notifications, analytics, billing, storage, and developer apps.
OperationsDuplicate or delete Caps and observe asynchronous work through jobs get or jobs wait.

The cloud client gives these commands one request contract. It sends authenticated requests to the configured Cap server, retries retryable failures, preserves one idempotency key across a mutation retry, and reports typed errors with codes, hints, retry state, and request IDs when available.

References: apps/…/caps.rs• L19-49 apps/…/caps.rs• L664-807 apps/…/agent_client.rs• L664-807 apps/…/account.rs• L104-184 apps/…/organizations.rs• L565-779 apps/…/library.rs• L484-729 apps/…/notifications.rs• L77-144 apps/…/analytics.rs• L24-47 apps/…/jobs.rs• L52-139

CLI developer media

The developers commands expose Cap Infra as a product surface for applications. A developer app holds its media, transcripts, allowed domains, API keys, usage, and prepaid credits. The CLI lets an operator manage that app and use it as a video or speech service.

The command surface now covers the full app lifecycle as well as media work:

  • App state: list, inspect, create, update, and delete developer apps.
  • Access and billing: manage embed domains, rotate keys, inspect usage, buy credits, and control automatic top-up.
  • Video: upload, list, inspect, wait for readiness, and delete stored videos.
  • Speech: create transcripts from a local file or public URL, list, inspect, wait, read text, and delete transcripts.

Video and transcript jobs follow the same asynchronous pattern. The CLI creates the resource, transfers the local file when needed, starts processing, and can wait until the resource is ready or has failed. It keeps signed storage targets inside the CLI and returns product status and links rather than exposing those targets to agents.

ResourceProduct role
Developer videoAccept a local MP4, process it for playback, and expose playback, share, and embed links.
Developer transcriptAccept a local audio or video file or a public URL, then return text and optional timed segments.
Developer appManage domains, credentials, usage, billing credits, auto top-up, and transactions.

Uploads and transcription have different product effects. Stored video uses the app's storage credits over time. Transcription uses prepaid credits based on audio length. The CLI therefore requires confirmation before either paid workflow and supports dry-run previews for destructive app, video, transcript, domain, and key actions.

References: apps/…/developers.rs• L15-72 apps/…/developers.rs• L625-715 apps/…/developers.rs• L716-841 apps/…/developers.rs• L842-1035 apps/…/developer_media.rs• L189-250 apps/…/developer_media.rs• L387-475 apps/…/developer_media.rs• L688-741

CLI agent interface

The CLI is designed for machine control as well as human use. A global --json flag selects machine-readable output, while command-level --format json remains available. Standard output carries the result and standard error carries logs and human-readable errors. Recording and export use newline-delimited JSON so a caller can observe progress while work continues.

The cap guide --json command is the discovery point for agents. It publishes the output rules, environment inputs, exit codes, command groups, streaming event types, and schema version. Callers should branch on structured fields such as error, valid, ok, and captureReady instead of parsing human text. Export keeps its established PascalCase event tags and snake_case fields so desktop consumers can use the same stream.

The diagram shows how a shell, CI job, or agent receives results.

flowchart LR
    Caller[Shell, CI, or agent] -->|command plus --json| CLI[cap CLI]
    CLI -->|local work or API request| Work[Capture, media, or Cap work]
    Work -->|JSON or NDJSON| Stdout[stdout result]
    CLI -->|logs and error detail| Stderr[stderr]
    Caller -->|cap guide --json| Contract[Capability and schema manifest]

References: apps/…/main.rs• L120-171 apps/…/main.rs• L757-975 apps/…/export.rs• L307-335 apps/…/export.rs• L429-453 apps/…/guide.rs• L5-21 apps/…/guide.rs• L95-155 apps/…/cli.rs• L924-945

CLI authentication and agent setup

The CLI supports local Desktop credentials, API keys, and agent credentials. Browser login uses a short-lived approval flow with a protected callback, then stores a scoped CLI credential. The creator, admin, and full login profiles provide increasing access scopes. Headless callers can use CAP_AGENT_TOKEN, an agent token in CAP_API_KEY, or a stored agent credential. Stored credentials use the OS credential store first and a permission-restricted file only when the caller explicitly allows that fallback.

Agent credential lookup gives explicit agent environment credentials priority. It then checks the stored CLI login before falling back to the legacy CAP_API_KEY or Cap Desktop login. A stored login is not used with a different CAP_SERVER_URL, and remote agent servers require HTTPS; HTTP is allowed only for loopback development servers. Commands report credential source and verification status without printing secrets.

cap auth status distinguishes a credential that is present from one that the server has verified. cap auth logout revokes a revocable CLI credential and removes stored agent credentials. It does not revoke a legacy CAP_API_KEY or change the Cap Desktop login. The local MCP server gives compatible AI agents a second interface to the same cloud actions. It uses a stdio protocol, keeps stdout for protocol messages, and requires confirmation for mutating tools.

The MCP server exposes both Cap management and developer media tools. Read tools can inspect Caps, account and organization state, libraries, notifications, analytics, developer apps, videos, transcripts, and credit transactions. Mutating tools use explicit confirmed input. Long work supports progress, cancellation, and a later wait call when the resource already exists. Large Cap context fields move to cap:// resources so an agent can request transcript, comments, or reactions without inflating the main response.

The agents setup flow installs the Cap skill, the local MCP entry, or both for one selected agent. The skill directs future Cap tasks to the CLI or MCP first and treats cap guide --json as the authoritative contract.

References: apps/…/agent_auth.rs• L16-50 apps/…/agent_auth.rs• L245-350 apps/…/agent_auth.rs• L353-427 apps/…/credentials.rs• L77-175 apps/…/credentials.rs• L409-510 apps/…/credentials.rs• L633-832 apps/…/mcp.rs• L826-1035 apps/…/mcp.rs• L1098-1175 apps/…/mcp.rs• L2473-2946 apps/…/mcp.rs• L4047-4147 apps/…/SKILL.md• L10-32 apps/…/SKILL.md• L58-61 apps/…/SKILL.md• L100-112 apps/…/cli.rs• L1498-1583

CLI automation integration

Cap Desktop remains the local owner of desktop settings and the visual workflow. The CLI reads the same automation rules and runs them for screenshots, completed recordings, and completed uploads, so capture made outside the UI can trigger the same product actions.

The CLI host supports file saving, export, upload, file opening, file-manager reveal, commands, webhooks, presets, and local cleanup. Desktop-only actions such as clipboard access, notifications, OCR, and opening the editor remain unavailable. Recording conditions can use the measured duration of the finished studio media, while upload actions require an exported video unless an existing share link is already present.

Cleanup actions depend on a verified remote upload result. The CLI does not provide that remote verification, so it keeps local media rather than treating an unconfirmed upload as safe to delete.

References: apps/…/automation.rs• L1-20 apps/…/automation.rs• L50-65 apps/…/automation.rs• L181-229 apps/…/automation.rs• L343-392 apps/…/automation.rs• L519-623 apps/…/main.rs• L248-249 apps/…/upload.rs• L165-182 apps/…/SKILL.md• L114-127

CLI media verification

The CLI includes checks that protect the boundary between capture, editor playback, and exported media. cap selftest playback can use an existing project or create a synthetic project through the real recording path, then compare the source recording with editor playback and export without capture hardware.

The selftest reports a structured verdict. A pass means that playback and export preserve the source audio and video relationship within the product's timing limits. A failed playback measurement or export is a product failure, while a source recording that cannot be measured is inconclusive.

References: apps/…/playback.rs• L1-14 apps/…/playback.rs• L79-124 apps/…/playback.rs• L135-255 apps/…/playback.rs• L288-380

CLI test contract

The CLI tests protect the contracts that external callers depend on. They run the binary as a caller would and check command discovery, JSON shape, output separation, validation, authentication reporting, MCP traffic, cancellation, cloud operations, export behavior, upload credential selection, and detached-session behavior.

The tests also protect the handoffs between local capture, project validation, export, upload, cloud waits, developer media, and automation. Their main value is not coverage of each command. It is proof that a caller can discover a command, provide safe input, observe progress, and distinguish success from an incomplete or failed operation.

Authentication tests now cover agent status verification, source reporting, secure server rules, login defaults, and secret-free output. Upload tests keep agent credentials on the agent upload path and legacy or Desktop credentials on the compatible upload path. These checks make credential and upload changes visible at the external boundary.

References: apps/…/cli.rs• L46-179 apps/…/cli.rs• L181-343 apps/…/cli.rs• L601-713 apps/…/cli.rs• L924-1079 apps/…/cli.rs• L1156-1423 apps/…/cli.rs• L1488-1583 apps/…/credentials.rs• L834-1064 apps/…/upload.rs• L553-678 apps/…/developer_media.rs• L744-957 apps/…/mcp.rs• L4149-4220 apps/…/playback.rs• L216-255

Discord release integration

The Discord bot is a small HTTP worker that turns a signed Discord interaction into a release workflow request. Its current product role is release coordination rather than general Cap media control. The supported slash command is release, and the bot posts status and completion links in the original Discord channel.

The release path connects four systems. Discord supplies the interaction and the user-facing message. The bot dispatches the publish.yml GitHub workflow. The workflow calls the reusable desktop-release workflow. Later callbacks let the bot update the message with release notes, the CrabNebula release, and the GitHub Actions run.

The worker supports local development and deployment through Wrangler. Its route checks run with Vitest in the same Cloudflare worker test environment.

The diagram shows the release conversation from the initial Discord action to the final links.

sequenceDiagram
    participant U as Discord user
    participant D as Discord
    participant B as Discord bot worker
    participant G as GitHub Actions
    participant R as Release systems
    U->>D: Run release command
    D->>B: Signed interaction
    B->>B: Save interaction state
    B->>G: Dispatch publish workflow
    B-->>D: Release workflow started
    G->>B: Authenticated release-ready callback
    B-->>D: Update message with release links
    G->>R: Build desktop release
    G->>B: Authenticated release-done callback
    B-->>D: Post completion links and mention user

Discord request verification

The bot accepts Discord interaction requests only after checking the Ed25519 signature over the request timestamp and JSON body. It answers Discord pings and routes slash commands after verification. This protects the release trigger from unsigned callers.

The workflow callback is a separate protected path. It accepts a bearer token issued to the Cap GitHub Actions workflow. It verifies the issuer, audience, repository, and workflow claims before it can change a Discord message.

References: apps/…/index.ts• L61-75 apps/…/index.ts• L77-139 apps/…/index.ts• L141-224

Discord release state

The bot stores the original interaction by ID before it starts the workflow. A callback uses that state to find the channel, user, and Discord response token. This gives the asynchronous workflow a durable link back to the conversation that started it.

The first response tells the user to wait. The release-ready update adds the version and release-note action. The release-done message mentions the initiating user and links to the release notes, the CrabNebula release, and the workflow run.

References: apps/…/index.ts• L167-215 apps/…/index.ts• L283-359 .github/…/publish.yml• L8-44

Verification surfaces

The CLI tests protect the external command contract. The playback selftest protects the media boundary between source recording, editor playback, and export. The Discord worker tests check the route behavior for direct worker calls and the Cloudflare worker path.

The most important external contracts are stable machine output and safe action boundaries. Consumers should use the guide and JSON fields instead of parsing human text. They should treat a missing terminal event, a failed verdict, or a non-zero exit as a failed operation.

References: apps/…/cli.rs• L46-188 apps/…/cli.rs• L466-719 apps/…/cli.rs• L808-945 apps/…/cli.rs• L1488-1583 apps/…/playback.rs• L216-255 apps/…/mcp.rs• L4149-4220 apps/…/index.spec.ts• L15-30 apps/…/guide.rs• L95-155

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the CLI command tree, cap guide --json, the installed skill, and integration tests aligned. Agents use the guide as the discoverable contract.
  • Preserve the stdout and stderr split. JSON and NDJSON consumers must not receive logs on stdout. MCP stdout must remain protocol-only.
  • Keep foreground and detached recording paths aligned when changing duration checks, session state, lifecycle events, or finalization rules.
  • Keep export, project validation, and upload aligned. A valid GIF or MOV export is not a valid cap upload input; upload accepts MP4 media. Keep track export separate from video upload because it produces a folder of files.
  • Keep agent and legacy upload selection aligned with credential resolution. Agent uploads create new Caps and do not support --video-id; Desktop or legacy uploads retain the existing-video path.
  • Keep cloud client error fields, retry rules, idempotency behavior, access-grant headers, and confirmation headers aligned with the Cap API.
  • Keep jobs wait and command-level wait options aligned with asynchronous operation states and timeout bounds.
  • Keep developer CLI commands, MCP developer tools, developer-media resource states, upload limits, billing notes, and MCP cancellation hints aligned.
  • Keep secure-input boundaries aligned. Passwords, S3 credentials, local image files, and newly issued developer credentials must not enter MCP schemas or logs.
  • Keep organization, library, notification, analytics, and account command payloads aligned with their server contracts and confirmation rules.
  • Keep login scopes, callback state checks, token exchange, credential storage, status verification, and logout revocation aligned. Do not make logout claim to revoke legacy or Desktop credentials.
  • Keep agent credential precedence and server matching aligned. A stored login must not be sent to a different CAP_SERVER_URL, and remote agent credentials must remain HTTPS-only.
  • Keep automation trigger context aligned with the shared Desktop rule model. In particular, preserve measured recording duration, share-link state, supported CLI actions, and the unsupported UI-only actions.
  • Keep automation cleanup aligned with verified upload results. The CLI must not delete local media when the remote result is unconfirmed.
  • Keep the playback selftest's raw, playback, export, and verdict fields aligned when editor timing or export timing changes.
  • When changing the Discord release payload, update the GitHub workflow input and both asynchronous callback paths. The interaction ID is the link between them.
  • When changing workflow authentication, keep the GitHub OIDC audience, repository checks, callback claims, and worker route in agreement.
  • When changing Discord message links, preserve the release-note, CrabNebula, and workflow-run destinations used by the release conversation.

Important failure modes

TriggerConsequenceGuard
A non-interactive caller starts a foreground recording without a durationThe process can stop at input end and produce an unusable captureUse --duration or the detached start/stop lifecycle
A caller treats a queued response as completed workIt can publish or report media before processing finishesUse the matching wait command and inspect the terminal state
A mutating CLI or MCP action lacks explicit confirmationShared content, paid processing, billing, or account data can change without approvalRequire --yes or confirmed=true; use dry-run where available
A cloud mutation is retried with a new idempotency keyOne user action can create duplicate server changesReuse one idempotency key across retries
A protected Cap request lacks its access grantThe request cannot read the protected CapStore the short-lived grant and send it in the access-grant header
A stored CLI login is used with a different CAP_SERVER_URLThe credential can be sent to the wrong Cap server or the request can failRefuse the mismatch and use a credential issued for the selected server
An agent credential targets a remote HTTP serverThe CLI exposes the credential over an insecure connectionRequire HTTPS; allow HTTP only for loopback development
The OS credential store is unavailable after browser loginThe token cannot be stored safely and the login must not appear successfulRequire --allow-file-credential before using the permission-restricted fallback
A caller runs cap auth logout with a legacy key or Desktop loginThe caller can assume a credential was revoked when it was only left unchangedReport that logout handles stored agent credentials, not legacy or Desktop credentials
A developer upload or transcript uses an invalid or over-size sourceThe resource can fail before processing startsValidate file type, audio presence, size, and wait bounds before submission
A transcript has status queued or processingText is not ready even though the resource existsWait for complete; treat error as a failed resource
An export emits no terminal JSON eventAn agent can mistake a stopped stream for successEmit a final Error event and return a non-zero exit
A caller uses export settings that do not match the requested containerThe command rejects the request or produces a result that another command cannot consumeKeep container-specific settings together and use MP4 for cap upload
A caller passes --video-id with an agent credentialThe command cannot update the requested existing video through the agent upload APIUse Desktop or legacy credentials for --video-id, or upload a new Cap with the agent path
MCP writes logs or banners to stdoutThe client cannot parse the protocol streamReserve stdout for MCP messages and send diagnostics elsewhere
MCP work is cancelled after a developer upload creates a resourceThe agent can lose the resource ID or repeat the uploadReturn the created ID and status with a resume or cleanup hint
A CLI automation rule requires an unavailable UI actionThe rule action is skipped or fails instead of completing the Desktop behaviorUse only actions supported by the CLI host or keep the rule in Desktop
A CLI automation cleanup rule follows an unverified uploadLocal media remains instead of being deletedRequire a verified remote result; the CLI currently cannot provide one
A playback selftest cannot measure the source recordingThe result is inconclusive rather than evidence of a passing sync checkProvide a valid project or let the selftest generate its fixture and inspect the verdict
Playback or export changes sync beyond its allowed rangeThe selftest returns a failure even when capture itself is validTreat raw, playback, and export measurements as one product boundary
A Discord request has an invalid signatureAn untrusted caller can trigger a releaseReject the request before command handling
A workflow callback has invalid claims or no stored interaction IDRelease status can update the wrong or no Discord messageVerify callback claims and require stored interaction state

Key files

FileWhy to read it
apps/…/Cargo.tomlShows the shared capture, media, automation, and agent capabilities connected to the CLI.
apps/…/main.rsDefines the top-level command surface and common JSON, error, runtime, and worker behavior.
apps/…/guide.rsDefines the machine-readable capability and output contract used by agents.
apps/…/agent_auth.rsDefines browser login, scoped agent profiles, token revocation, and auth-facing results.
apps/…/credentials.rsDefines how Desktop, environment, stored agent credentials, server checks, and auth status connect the CLI to a Cap server.
apps/…/export.rsShows how local projects become exported video or edited track media and how progress and completion reach callers.
apps/…/upload.rsConnects MP4 output to shareable Cap links and selects the agent or Desktop-compatible upload path.
apps/…/agent_client.rsDefines the common authenticated cloud request, retry, error, and idempotency contract.
apps/…/caps.rsDefines the authenticated Cap content, processing, sharing, access, and operation surface.
apps/…/developers.rsDefines the developer-app, video, transcript, credit, domain, and credential workflows.
apps/…/developer_media.rsDefines the shared developer video and transcript lifecycle and wait behavior.
apps/…/mcp.rsDefines the local AI-agent protocol, tool safety, cancellation, resources, and secure-input boundaries.
apps/…/organizations.rsDefines organization membership, billing, domains, and external storage actions.
apps/…/library.rsDefines folders, spaces, public collection pages, and space membership actions.
apps/…/automation.rsConnects the shared Desktop automation rules to CLI capture, media, upload, and local actions.
apps/…/playback.rsDefines the headless end-to-end playback and export sync check used without capture hardware.
apps/…/cli.rsShows the external CLI, auth, upload, and MCP contracts protected by integration tests.
apps/…/SKILL.mdDefines how an AI agent should route Cap work through the CLI or local MCP.
apps/…/index.tsDefines Discord request handling, release dispatch, callback validation, and release messages.
apps/…/index.spec.tsShows the current worker route checks.
.github/…/publish.ymlDefines the release workflow entry point and the interaction ID handoff from Discord.