amagi
中文 README: README.zh-CN.md
Rust SDK, CLI, and Web API service skeleton for multi-platform social web adapters.
Overview
- Build local CLI workflows with
amagi run - Start a JSON Web API service with
amagi serve - Generate API docs with
cargo doc --no-deps --open - Publish generated docs to
docs.rsafter releasing the crate - Full CLI command and parameter reference:
docs/reference/cli-reference.md - Chinese CLI reference:
docs/reference/cli-reference.zh-CN.md - SDK usage reference:
docs/reference/sdk-reference.md - Chinese SDK reference:
docs/reference/sdk-reference.zh-CN.md - Web API reference:
docs/reference/web-api-reference.md - Chinese Web API reference:
docs/reference/web-api-reference.zh-CN.md - API catalog reference:
docs/reference/api-catalog-reference.md - Chinese API catalog reference:
docs/reference/api-catalog-reference.zh-CN.md - Installation guide:
docs/installation/README.md - Chinese installation guide:
docs/installation/README.zh-CN.md
Quick Start
Verified Twitter CLI Interfaces
The Twitter/X CLI reference now marks tested usable interfaces directly, and also calls out interfaces with known behavior caveats:
Environment
The binary startup path loads layered dotenv configuration automatically, and
SDK consumers can also build config from dotenv files through ClientOptions::from_env() or
AmagiClient::from_env().
Default dotenv lookup order:
- user-level config file
- current working directory
.env
Process environment variables still override both dotenv layers.
User-level dotenv path:
- Linux/macOS:
~/.config/amagi/.env - Windows:
%APPDATA%\\amagi\\.env
Set AMAGI_USER_ENV_FILE to override this user-level dotenv path explicitly.
Example .env:
AMAGI_DOUYIN_COOKIE=
AMAGI_BILIBILI_COOKIE=
AMAGI_KUAISHOU_COOKIE=token=...
AMAGI_TWITTER_COOKIE=
AMAGI_XIAOHONGSHU_COOKIE=
AMAGI_TIMEOUT_MS=10000
AMAGI_MAX_RETRIES=3
AMAGI_LOG_FORMAT=text
AMAGI_LOG=info
AMAGI_OUTPUT=text
AMAGI_OUTPUT_FILE=
AMAGI_OUTPUT_PRETTY=false
AMAGI_OUTPUT_APPEND=false
AMAGI_OUTPUT_CREATE_DIRS=false
AMAGI_HOST=127.0.0.1
AMAGI_PORT=4567
You can also keep a template in .env.example.
The CLI and Web runtime both read platform cookies from process environment variables:
PowerShell:
$env:AMAGI_DOUYIN_COOKIE = "..."
$env:AMAGI_BILIBILI_COOKIE = "..."
$env:AMAGI_KUAISHOU_COOKIE = "..."
$env:AMAGI_TWITTER_COOKIE = "..."
$env:AMAGI_XIAOHONGSHU_COOKIE = "..."
Shared runtime variables:
AMAGI_USER_ENV_FILEAMAGI_TIMEOUT_MSAMAGI_MAX_RETRIESAMAGI_OUTPUTAMAGI_OUTPUT_FILEAMAGI_OUTPUT_PRETTYAMAGI_OUTPUT_APPENDAMAGI_OUTPUT_CREATE_DIRSAMAGI_LOG_FORMATAMAGI_LOGAMAGI_HOSTAMAGI_PORT
Example:
AMAGI_DOUYIN_COOKIE="sid_guard=..."
AMAGI_DOUYIN_COOKIE="sid_guard=..."
AMAGI_KUAISHOU_COOKIE="token=..."
AMAGI_KUAISHOU_COOKIE="token=..."
AMAGI_TWITTER_COOKIE="auth_token=...; ct0=...; twid=..."
AMAGI_TWITTER_COOKIE="auth_token=...; ct0=...; twid=..."
AMAGI_TWITTER_COOKIE="auth_token=...; ct0=...; twid=..."
AMAGI_OUTPUT=json AMAGI_OUTPUT_FILE=tmp/emoji.json AMAGI_OUTPUT_PRETTY=true
AMAGI_OUTPUT=json AMAGI_OUTPUT_FILE=tmp/events.json AMAGI_OUTPUT_APPEND=true AMAGI_KUAISHOU_COOKIE="token=..."
CLI Output
The CLI can write either human-readable text or machine-readable JSON to stdout or a file.
--output text|json: choose text or JSON output--output-file,-o: write CLI-facing output to a file instead of stdout--pretty: pretty-print JSON payloads--append: append to an existing output file--create-parent-dirs: create missing parent directories for the output path
Examples:
Feature Selection
Choose only the surface you need in Cargo.toml:
# API catalog only
= { = "0.1.0", = false, = ["catalog"] }
# Rust SDK only
= { = "0.1.0", = false, = ["client"] }
# CLI runtime only
= { = "0.1.0", = false, = ["cli"] }
# Web API service only
= { = "0.1.0", = false, = ["server"] }
Feature notes:
catalog: only exports the static catalog and route metadata.client: exportscatalog, client types, events, errors, and Rust-native platform fetchers.cli: enables the command parser and local runtime without forcing the server surface.server: enables the Axum-based HTTP server surface without forcing the CLI parser.
Project Layout
src/catalog/: shared catalog and route metadatasrc/client/: client configuration and request defaultssrc/events/: typed event bus and payload modelssrc/platforms/: Rust-native platform fetchers and shared upstream transportsrc/server/: HTTP server entrypoint and handlerssrc/cli/,src/output/,src/app/: CLI, output, and runtime orchestrationsrc/config/,src/error/,src/telemetry/,src/env/: shared runtime supportdocs/reference/,docs/installation/: reference docs and installation guidesscripts/: local installation scripts for Linux shells and PowerShellsrc/lib.rs: public exports and crate-level entrypointssrc/main.rs: binary bootstrap
Rustdoc Example
Documentation Conventions
- Use
///for public API documentation comments - Use
//!for crate-level and module-level documentation - Start each public item with a one-line summary sentence ending in a period
- Prefer intra-doc links for related types, modules, and helper functions
- Prefer
# Examples,# Errors, and# Panicssections when they describe observable behavior - Document the public contract rather than repeating implementation details
- Use
#[doc(alias = "...")]for useful alternate English search terms
Suggested Style
/// Build the socket address used by the HTTP server.
///
/// # Examples
///
/// ```rust
/// use amagi::config::ServeConfig;
///
/// let serve = ServeConfig {
/// host: "127.0.0.1".into(),
/// port: 4567,
/// };
///
/// assert_eq!(serve.bind_addr(), "127.0.0.1:4567");
/// ```