Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ jobs:
rustup toolchain install "$version" --profile minimal --component clippy
rustup override set "$version"
- name: Check translations
run: python3 scripts/check-i18n.py
run: |
python3 scripts/check-i18n.py
python3 scripts/test_i18n_checks.py
- name: Run tests
run: |
set -o pipefail
Expand Down
240 changes: 44 additions & 196 deletions README.md

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# LMM CLI

[English](README.md) · [使用指南](docs/usage.zh-CN.md) · [翻译指南](docs/i18n.md)

LMM(Language Model Mesh,语言模型网络)是独立的 Rust CLI,用于服务商预设查询、本地软件检查、账号模型目录与余额读取,以及范围明确的应用适配器。Cargo 包名为 `lmm-cli`,可执行文件为 `lmm`;构建和依赖锁文件独立于父项目服务。

当前源码是开发预览,包含显式安装的 Pi 1.2.0 SDK 的 Linux 适配器,以及 CC Switch 受管发行包适配器。计划、数据库写入或进程启动成功,均不能证明应用已通过 LMM 路由激活或模型调用可用。详细边界见[使用指南](docs/usage.zh-CN.md)、[受管发行包合同](docs/managed-distributions.md)和[原生接入证据](docs/native-credential-evidence.md)。

## 构建当前源码

```sh
mise install
mise exec -- cargo install --path . --locked
lmm --lang zh-CN --help
```

使用本仓库 `mise.toml` 固定的开发工具链(Rust 1.100.0);Cargo 清单声明的最低版本为 Rust 1.99.1。构建需要本机编译工具。Linux OAuth 另需运行中的 Secret Service,Windows 和 macOS 使用系统凭据库。已发布包可能不同于当前源码;这里尚未提供面向无开发环境用户的独立安装器。

## 选择语言

```sh
lmm --lang en catalog astrbot
lmm catalog astrbot --lang zh-CN
LMM_LANG=zh-CN lmm --help
```

全局 `--lang` 优先于 `LMM_LANG`、`LC_ALL`、`LC_MESSAGES`、`LANG` 中首个非空值。未知环境语言回退英文;不支持的显式参数会被拒绝。帮助和终端文字支持中英文;JSON 的目录用途、提示和已识别错误正文在两种语言下均保持固定英文。命令名、标识符、协议值和数字不变,详见[翻译指南](docs/i18n.md)。

## 当前命令

| 任务 | 入口 | 结果与边界 |
| --- | --- | --- |
| 服务商预设 | `lmm presets [query] --json` | 离线的 56 项预设快照;不配置服务商、不验证连通性 |
| 软件目录 | `lmm catalog [query]` | 项目身份,以及分别列出的安装、接入、维护能力 |
| 本地检查 | `lmm status [software] --json` | 路径线索、CC Switch 受管状态或显式选择的原生设置 |
| 分享诊断 | `lmm doctor [software] --report --json` | 移除本地路径,明确保留未完成的验证项 |
| CLI 账号 | `lmm login`、`models`、`balance`、`logout` | 浏览器 PKCE 和账号只读权限;不授予应用模型调用权限 |
| CC Switch 受管程序 | `lmm install cc-switch --dry-run --json` | 固定官方版本计划;执行时需要精确 `plan_id` |
| CC Switch 原生配置 | `lmm setup cc-switch --help` | 独立应用授权和仅添加的原生数据库事务;激活另行处理 |
| Pi Provider | `lmm setup pi --help` | 显式指定 Node、Pi 1.2.0 SDK、项目和 agent 路径;授权保留在 Pi 内 |

`--json` 禁用 CLI 提示;`--non-interactive` 不等待缺失输入。可能需要系统解锁的凭据操作会在访问凭据前拒绝无人值守模式。`--yes` 不能替代缺失的适配器、必要的计划 ID、应用同意或服务端消费上限。

## 从只读命令开始

```sh
lmm presets deepseek --json
lmm catalog
lmm status astrbot --instance /absolute/path/to/AstrBot --json
lmm doctor astrbot --instance /absolute/path/to/AstrBot --report --json
lmm install cc-switch --dry-run --json
```

显式路径属于运行 CLI 的当前操作系统。CLI 不扫描其他用户、远程系统或容器实例。请求写入之前,先阅读[使用指南](docs/usage.zh-CN.md)中的 Pi 设置检查、CC Switch 回执、OAuth、恢复和退出码说明。

## 开发与验证

```sh
python3 scripts/check-i18n.py
python3 scripts/test_i18n_checks.py
mise exec -- cargo fmt --all -- --check
mise exec -- cargo test --locked
mise exec -- cargo clippy --locked --all-targets --all-features -- -D warnings
```

测试使用隔离 fixture。两项 Linux 凭据迁移检查需要显式启用并提供隔离的 Secret Service;普通测试不能代替各操作系统真实凭据库验收。本地验证不会发布 crate、正式版本或生产部署。

## 范围与来源

[原始需求](docs/requirements.zh-CN.md)继续作为产品目标;[Magpie 对照](docs/magpie-parity.md)基于固定上游版本记录已实现能力与剩余工作。LMM 将行为移植到 Rust,不包装或启动 Magpie,也不依赖 Go 运行时。

项目使用 [AGPL-3.0-only](LICENSE) 许可。内置服务商快照参考 MIT 许可的 Magpie 材料,见 [NOTICE](NOTICE) 和[第三方来源记录](third_party/magpie/NOTICE.md)。静态预设不代表当前账号有权限,也不代表运行时兼容。
70 changes: 70 additions & 0 deletions docs/i18n.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Translations

[English README](../README.md) · [中文 README](../README.zh-CN.md)

## Runtime contract

LMM translates terminal presentation while keeping machine-readable output independent of the selected language. Both catalogs are compiled into the binary using `include_str!`; language selection does not require a network request, a working-directory lookup or another runtime dependency. The implementation is in [src/i18n.rs](../src/i18n.rs), with subprocess coverage in [tests/i18n.rs](../tests/i18n.rs).

| File | Purpose |
| --- | --- |
| `locales/en.json` | Complete English catalog and canonical machine prose |
| `locales/zh-CN.json` | Complete Simplified Chinese catalog |
| `src/i18n.rs` | Locale selection, typed messages and named placeholders |
| `scripts/check-i18n.py` | Catalog values, references and placeholder validation |
| `scripts/test_i18n_checks.py` | Validator regressions using temporary fixtures |

## Select a language

The global `--lang en` or `--lang zh-CN` flag works before or after a subcommand. Selection happens before Clap builds help. An unsupported explicit language is an argument error and does not run the requested command.

Without the flag, the first nonempty value in `LMM_LANG`, `LC_ALL`, `LC_MESSAGES` and `LANG` selects the language. Unknown values, `C` and `POSIX` fall back to English. Supported Simplified Chinese aliases include `zh`, `zh_CN.UTF-8`, `zh-SG` and `zh-Hans`; Traditional Chinese does not yet have a catalog and falls back to English. A value after `--` is positional data and cannot select a language.

The selected locale is immutable for the CLI process, including the OAuth callback thread. An uninitialized library defaults to English. Library callers can use `Locale::ZhCn.text(key)` or `msg(key).render_in(locale, values)` without mutating global state; tests use explicit locales and child-process environments.

## Add or change a message

Use the same semantic key in both catalogs and keep a complete sentence together. For example:

```json
{
"output.target": "{software}: installation {installation}"
}
```

```rust
msg("error.unknown_software")
msg("output.scope").render(&[("time", &checked_at.to_string())])
text("arg.instance")
```

Named placeholders may move within a sentence, but their names and occurrence counts must match. Formatting specifiers, conversions, nested templates and literal braces are not supported. Substitution happens once: inserted values are never parsed as templates. Escape untrusted paths and server text with debug formatting, such as `format!("{value:?}")`, before inserting them into terminal output.

`help.template` belongs to Clap rather than the message renderer. Preserve Clap's named fields. Command descriptions and help headings are translated; Clap's own argument validation details and built-in annotations remain in upstream English.

## Keep JSON and adapter errors stable

`Message` serializes its English text regardless of display locale. JSON keys, descriptions, purposes, notes, blockers, recognized error text, command names, IDs, protocol values, currencies, numbers and timestamps do not change when only `--lang` changes. Catalog and provider search can match both bundled languages without changing returned identifiers. Original vendor metadata is preserved rather than translated.

Existing native adapter APIs return strings or typed errors that are also used in JSON previews. They use `english(key)` to retain a canonical value. At the terminal boundary, `message_from_english` recognizes only exact catalog values and recovers a typed message; `localize` translates that recognized value. Unknown external text stays literal. Do not perform broad string replacement or interpret an adapter's text as a template.

Recognized CLI and OAuth errors include a stable `error_code`; unclassified adapter strings have no recognized code. Consumers should inspect structured outcomes and known codes instead of matching human prose. The hidden `credential` command is a raw-token pipe and rejects JSON or terminal token output in either language; it is not a general-purpose account display command.

A missing localized entry falls back to English and then to its visible key. This avoids a runtime failure but does not make an incomplete catalog acceptable: repository validation requires matching nonempty catalogs and rejects missing or unused message references.

## Verify a change

Run these commands from the repository root:

```sh
python3 scripts/check-i18n.py
python3 scripts/test_i18n_checks.py
mise exec -- cargo fmt --all -- --check
mise exec -- cargo test --locked
mise exec -- cargo clippy --locked --all-targets --all-features -- -D warnings
mise exec -- cargo package --list --locked
```

The Python checker rejects duplicate and malformed keys, empty or non-string values, disallowed control characters, CJK text in the English catalog or Rust sources, mismatched placeholders, and missing or unused references. It recognizes `msg`, `text`, `english` and the typed enum message mappings. Its fixture tests do not compile Rust; the Cargo tests verify locale precedence, help, errors, JSON equality, native adapter refusal paths and escaped untrusted paths.

The source package must include both catalogs, both READMEs and the translation guide. To add another language, extend `Locale`, its aliases, its embedded catalog mapping and `Locale::ALL`, then add subprocess tests and update documentation in the same change. No command, adapter permission or credential-store behavior should change as a side effect of translation work.
4 changes: 3 additions & 1 deletion docs/managed-distributions.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ lmm status cc-switch --instance /absolute/path/to/.cc-switch --json

显式实例检查使用只读 SQLite 事务,要求 schema 24 和已核验的 `providers` 主键与列。仅查询 ID、应用类型、名称及数据库选择标志;不读取 `settings_config`、`meta` 或凭据内容。`selected_in_database` 不能证明本机 Codex/Claude 配置已经激活,也不能证明经过本地代理。

`setup`、`sync` 和 `disconnect` 的完整应用接入仍需要独立应用授权与原生配置激活合同。现有 CLI 登录只拥有 `catalog:read balance:read`,不得把该 token 写进 CC Switch 的供应商配置。不得只修改 `is_current` 就声称完成激活,因为上游激活还写本机应用配置。这些尚未具备的流程继续返回明确阻塞,不返回空成功。
应用配置使用独立于发行包管理的授权与事务路径。当前 `setup --add-only` 和 `sync` 通过显式实例的原生 SQLite 事务添加或更新 LMM,保留原模型选择;`restore --configuration --change` 按回执恢复受管理字段并拒绝后续编辑冲突。代码入口见 [applications_cli.rs](../src/applications_cli.rs) 与 [bindings.rs](../src/cc_switch/bindings.rs)。现有 CLI 登录只拥有 `catalog:read balance:read`,不会把该 token 写进供应商配置;独立应用授权仍需服务端对应合同与用户同意。

完整激活和删除继续受原生应用状态限制。不能只修改 `is_current` 就声称完成激活,也不能只凭 SQLite 中未选中的标记删除可能被 live、代理或 Stack 引用的项目。这些操作需要 CC Switch 原生管理入口或独立审阅的上游集成,详见[原生接入证据](native-credential-evidence.md)。受管发行包成功、供应商记录存在和真实模型调用成功仍是不同结果。

隔离测试使用合成发行包字节、临时目录和真实 SQLite;不下载或执行官方 AppImage,不访问真实账号或支付渠道。真实 Linux 图形环境运行、官方文件端到端下载与模型调用仍需独立验收。
Loading