# aidc CLI

AIDC Developer 的命令行，也是智能体使用 AIDC 的首选入口：每条命令都能输出 JSON、从不交互（唯一例外是 `aidc login` 在你自己的终端里问账号和密码）、退出码稳定。所有业务逻辑都在 API 里，CLI 只做参数、文件与输出。

## 安装

```bash
curl -fsSL https://www.ai-dc.ai/developer/cli/install.sh | sh
```

需要 Node 18 以上。安装脚本把单文件 CLI 下载到 `~/.aidc/bin/aidc`，并在 PATH 里第一个 `$HOME` 下的可写目录（`~/.local/bin`、`~/bin`…）放一个链接；输出的最后一行 `下一步：… login` 就是这台机器上能用的命令（没有合适的目录时是完整路径 `~/.aidc/bin/aidc`）。也可以直接 `node aidc.mjs …`（下载地址 `https://www.ai-dc.ai/developer/cli/aidc.mjs`）。`aidc video` 与长音频转写需要 ffmpeg。

## 登录

**一律登录（2026-09-29）**：除 `aidc login`、`aidc logout`、`aidc help`、`aidc --version` 外，每条命令都要先登录（没登录退出码 3）——包括只在本机跑的 `app init / check / export / dev`、`ui`、`data profile`、`modeling estimate`、`evolve slots`。**member 起步**：公司成员也能登录，能调用本公司已发布的应用（`aidc app call`）、在本机开发、`aidc whoami` 看自己；部署、发布、数据与管理命令要这家公司的 developer。自带凭证的 `aidc stream pipe`（`AIDC_PUBLISH_KEY`）与 `aidc connect send`（`AIDC_AGENT_KEY`）照旧。

```text
$ aidc login
登录 AIDC Developer（https://www.ai-dc.ai）
还没有账号？在 https://www.ai-dc.ai/login 点「注册」创建（建议用公司邮箱）；开发公司应用还需要公司发给你的 developer 授权码。

账号（用户名或邮箱）：zhang.san@example.com
密码：
已登录：张三（zhang.san）· 示例公司（cell-example）
```

| 命令 | 说明 |
| --- | --- |
| `aidc login` | 在终端里输入 AIDC 账号（用户名或邮箱）和密码（不回显），拿到一把代表你所在公司的开发者 Key |
| `aidc login --user <账号> [-n <cellId>]` | 预先给账号；账号能代表几家公司（AIDC 平台员工）时用 `-n` 指定，不给就在终端里选 |
| `aidc login --with-key < key.txt` | 从 stdin 读开发者 Key（CI） |
| `aidc login --browser [--no-wait]` | 身边没有终端的智能体：打印链接与授权码，人在浏览器里批准；`--no-wait --json` 只打印链接，随后 `aidc login --continue` 完成 |
| `aidc login --continue --no-wait --json` | 浏览器批准只查一次：没批准返回 `{"event":"authorization_pending"}`、退出码 3，批准了完成登录（`--continue` 不带 `--no-wait` 会一直等到批准或过期） |
| `aidc whoami` · `aidc keys` | 身份、Key 列表 |
| `aidc logout [--revoke]` | 删除本机 Key；`--revoke` 同时在服务端吊销 |

- **只在交互终端里问**：`aidc login` 是唯一会停下来问人的命令。stdin 不是终端（智能体、CI、管道）时立即以退出码 2 报错、说明该怎么做，不会挂着等输入。密码只在提示处输入——不收命令行参数、环境变量或 stdin。
- **还没有账号**：在 `https://www.ai-dc.ai/login` 点「注册」。使用 AIDC Developer 至少要是一家公司的 member：公司发给你的授权码（License）在 `https://www.ai-dc.ai/account` 输入；没有时登录会报「这个账号还不属于任何公司」（退出码 4）。部署、发布还要 developer 授权码。
- **密码**：与网页登录是同一个密码、同一套规则——连续输错 5 次锁 15 分钟（终端和网页算在一起），终端里最多连输三次。忘了就在登录页点「忘记密码？」重设；临时密码、邮箱没验证时先去网页登录处理。只用邮箱验证码登录、没设过密码的账号，也在「忘记密码？」里设一个。
- **Key 代表谁**：签给输入密码的这个账号、代表一家公司，按这个人在这家公司的角色（developer 或 member，`aidc whoami` / `aidc keys` 看得到），用量记在这家公司。重复登录会签新的 Key，旧的仍然有效——换机器或不用了 `aidc logout --revoke`。

凭证读取顺序：环境变量 `AIDC_API_KEY` → `~/.aidc/config.json`（0600）。API 根：`--api` → `AIDC_API_BASE` → 配置文件 → `https://www.ai-dc.ai`。

## 命令一览

```text
aidc ui components [组件]                           # 界面 SDK：组件、类与示例标记（本机，不联网）
aidc ui tokens [--mode light|dark] [--theme aidc|signal] [--css]
aidc ui add [目录] [--dry-run]                      # 给已有应用接上界面 SDK（入口页加 ui.css、清单 sdk 加 ui；幂等）

aidc models
aidc model chat -m <模型> "<提示>" [--system …] [--image 图…] [--json-object] [--stream]
aidc model decide --state "<文本>" --question id=说明 --choice id:选项=判据 …

aidc modeling models                                  # 建模 SDK：Marble 模型、价目、当前策略、上游是否已配置
aidc modeling estimate [-m marble-1.1] [--input text|image|pano|multi-image|video]   # 本机估价，不联网
aidc modeling budget                                  # 本月额度：公司上限 / 已结算 / 进行中预留 / 剩余
aidc modeling generate --text "…" | --image 图 [--image 图 … --reconstruct] [--azimuth 0,90…] | --pano 全景图 | --video 视频
                       [-m marble-1.0-draft] [--name …] [--seed N] [--tag …] [--max-credits N] [--no-recaption]
                       [--regenerate] [--idempotency-key K] [--dry-run] [--no-wait]
aidc modeling list [--status running] [--limit 30] · get <id> · wait <id>
aidc modeling upload <图片或视频>                        # 换签名地址后字节直传 World Labs，打印 mediaId
aidc modeling anchors <id> --file anchors.json [--if-rev N] [--dry-run]
aidc modeling export <id> --ply [--resolution full_res] | --mesh [--variant textured|vertex_colored] [--dry-run]
aidc modeling download <id> [--out 目录] [--quality 100k|500k|full_res] [--with-pano]
aidc modeling import --world-id <id> | --snapshot world.json [--name …] [-m 模型] [--input-kind text --text …]   # AIDC 平台账号
aidc modeling delete <id> [--purge] [--dry-run]

aidc vision inspect <图片…> --task "<检查什么>" [--criteria …] [-m gpt-6-luna]
aidc vision detect <图片…> [--labels 人,叉车] [--prompt …] [--max 50] [-m gpt-6-luna]   # 物体检测
aidc vision camera list | show <名字>                        # 公司的网络摄像机 / NVR（经平台转发的 RTSP）
AIDC_CAMERA_PASSWORD=… aidc vision camera add <名字> --host <外网地址> [--port 554] [--vendor dahua|hikvision|generic] \
    [--path 模板] [--username …] [--channels 1:大门,2:仓库] [--default-stream sub] [--max-viewers 4] [--allow-main-live] [--dry-run]
                                                               # 口令只从 AIDC_CAMERA_PASSWORD 或 --password-stdin 读
aidc vision camera probe <名字> [--channels 1-16] [--main]    # 连上、认证、读编码（不拉流）；口令被拒立即停
aidc vision camera snapshot <名字> [--channel 1] [--sub] [-o a.jpg]   # 截一帧（缺省主码流高清），本机 ffmpeg 转图片
aidc vision camera remove <名字> --yes [--dry-run]
aidc voice transcribe <音频/视频> [--language zh] [-m gpt-transcribe]
aidc voice translate "<文本>" --to ja,en,ar-EG,bn
aidc voice minutes <逐字稿.txt> [--title …]
aidc video frames <视频> --every <秒> [--out 目录] [--max N]
aidc video inspect <视频> --every <秒> --task "<检查什么>" [--transcribe]

# ── Semantic（数据平台）：对象、Action、订阅、数据从哪来、SQL、访问、自动化、日志与用量 ──
# Ontology（照 Palantir REST API v2 / OSDK；读命令都收 --branch <分支>，读分支上的定义）
aidc semantic ontology                                # 全貌：Object Type（主键、链接）、Action Type、Interface
aidc semantic object-types [apiName] · action-types [apiName] · interfaces [apiName] · value-types · shared-properties
aidc semantic objects <类型> [--where '{"stage":"付费","seats":{"$gt":30}}'] [--order-by seats:desc] [--select a,b] [--page-size n] [--page-token t]
aidc semantic object <类型> <主键> [--select a,b] · links <类型> <主键> <链接>
aidc semantic aggregate <类型> --select '{"$count":"unordered","costUsd:sum":"desc"}' [--group-by '{"month":"exact"}'] [--where …] [--interface]
aidc semantic object-set <对象集.json|'{…}'> [--aggregate '{"$select":{…}}']
aidc semantic subscribe <类型> [--where '{…}'] [--properties a,b]   # 实时订阅对象集（OSDK subscribe）：● 进来 / 变了 ✗ 离开，--json 输出 JSON 行
aidc semantic apply <Action> [--param 名=值 …] [--params '{…}'] [--validate-only] [--return-edits]   # 改数据的唯一方式；校验不通过 → 退出码 2
aidc semantic apply-batch <Action> <参数数组.json> [--return-edits]                                 # 最多 20 个，一个事务
aidc semantic edits-history <类型> [--pk 主键] [--previous]
aidc semantic security test <类型> [--user <账号 id>] [--pk 主键,…] [--object '{…}' …] [--policy 策略.json]   # 试安全策略（开发者；不回属性值）
# 建本体：智能体在分支上改、开提案，人在网页上审核合并（设 AIDC_AGENT_ID=<智能体> 时作者记为智能体）
aidc semantic define <文件.json|目录> [--dry-run]     # 定义（有则改）；数据源写在 Object Type 的 datasources 里
aidc semantic types · archive <apiName> · publish [--notes …] · releases · describe [--markdown]
aidc semantic branch list · create <分支> [--description …] · show <分支>
aidc semantic branch modify <分支> <文件|目录> [--archive a,b] [--expected-version N] [--dry-run]
aidc semantic branch validate <分支> · conflicts <分支> · rebase <分支> [--keep a,b] [--take-main c] · discard <分支> [资源…] · lock <分支> [--unlock]
aidc semantic branch propose <分支> --title … --trigger "为什么要改" [--self-test "自测结果"] [--description …]   # 打印审核网页地址
aidc semantic proposals [--status OPEN|MERGED|CLOSED] · proposal <id> · proposal close <id> [--note …]
# 数据从哪来（Data Connection：发布端 → 数据流 → Object Type 定义里的 datasources）；流名可写 <流名> 或 <命名空间>/<流名>
aidc semantic streams create <流名> --title … [--key 主键] --field 名:类型[:显示名] … [--retention N] [--spec 文件.json]
aidc semantic streams list · status <流名> · get <流名> · tail <流名> [--after N] · delete <流名> [--dry-run]
aidc semantic streams key <流名> --label "装在哪" · keys <流名> · revoke <流名> --prefix aidc-pk-…
aidc semantic streams publish <流名> --event '{…}' | --file 事件.json
aidc semantic streams pipe <命名空间>/<流名> -- <适配器命令…>   # 边缘发布端（发布 Key 读 AIDC_PUBLISH_KEY）
               [--heartbeat 30] [--full-every 360] [--stale-after 15]   # 秒 / 分 / 分
aidc semantic datasource list [类型]                  # 每个类型的数据源与同步进度
aidc semantic datasource sync                         # 平台数据源立即同步（= /semantic 的「立即同步」；AIDC 组织还同步 AWS 数据源）
aidc semantic datasource set <类型> --stream <流名> --map 属性=列 … [--mode mirror|upsert] [--dry-run]   # 写进类型定义（智能体作者要走分支）
aidc semantic datasource remove <类型> --stream <流名> [--dry-run] · resync <类型> --stream <流名>
# Semantic 数据库（照 Palantir Ontology SQL：一条 SELECT、≤ 10,000 行、20 秒；表名 = Object Type API name）
aidc semantic sql "SELECT … FROM <Object Type>" [--param 值 …] [--row-limit N] [--explain] [--csv] · sql --file q.sql
aidc semantic database [--sync] · database --rotate      # 表与列、我用的角色；开发者轮换口令拿只读直连串
# 访问：Private / Group / Public / Open to Internet（Ontology、Object Type、数字员工、文件）与账号
aidc semantic filesystem list [--scope public|organization|shared|mine] [--type ontology|objectType|agent|file]
aidc semantic filesystem show <rid> · roles <rid>
aidc semantic filesystem access <rid> --tier private|group|public|internet      # 一步设档位（Owner）
aidc semantic filesystem share <rid> (--user <账号 id> | --group <cell-…|cell-…:developers|cell-…:dept:<部门 ID>> | --everyone | --internet) [--role viewer|editor|owner]
aidc semantic filesystem unshare <rid> (--user … | --group … | --everyone | --internet) --role <角色>
aidc semantic filesystem link <rid> [--days 30]                                  # 邀请链接（Group，只有 Viewer）
aidc semantic admin whoami · admin members list · admin members import <名单.json|.csv> --source <来源名> [--dry-run]   # 本公司成员；导入已有名单
# 数据安全：Markings（强制控制：只有成员能访问，不看角色）；对象 / 属性安全策略写在 Object Type 定义里
aidc semantic admin marking-categories list · show <id> · create --name … [--disjunctive] [--hidden] · rename <id> --name …
aidc semantic admin markings list · show <id> · create --name … --category <类别 id> [--member <主体>,…] · rename <id> --name …
aidc semantic admin markings members <id> · add-members <id> <主体…> · remove-members <id> <主体…>          # 只有 ADMINISTER
aidc semantic admin markings roles <id> · grant <id> ADMINISTER|DECLASSIFY|USE <主体…> · revoke <id> <角色> <主体…>
aidc semantic admin markings mine [--user <账号 id>]                             # 是哪些 Marking 的成员
aidc semantic filesystem markings <rid> · mark <rid> <Marking id…> · unmark <rid> <Marking id…>   # 挂上要 USE、去掉要 DECLASSIFY + USE，都要是 Owner
aidc share <应用> --company | --user <用户名或邮箱> | --public [--role viewer|editor] [--days 30] [--note …]   # 应用的分享
# Data Connection 与 Automate（照 Palantir ConnectivityV2 / Automate：ERP 经客户箱上的 agent 按需同步，只回传变化；automation 替代 cron）
aidc semantic connectivity agents|connections --ontology <cell-…>                   # Data Connection：agent（客户箱）与 Connection（不含凭证）
aidc semantic connectivity agent|connection --ontology <cell-…> --file <定义.json> [--dry-run]
aidc semantic connectivity imports <connectionRid> · import <connectionRid> --file <TableImport.json> [--dry-run]
aidc semantic connectivity execute <connectionRid> <tableImportRid> [--full] [--wait]   # 执行一次（经 SSM 叫醒 agent，只回传变化）
aidc semantic connectivity build <buildRid>
aidc semantic automations list --ontology <cell-…> · upsert --ontology <cell-…> --file <automation.json> [--dry-run]
aidc semantic automations show|run|pause|resume|delete <automationRid>                # 条件 + 效果：替代 cron
aidc share list [应用] · aidc share revoke <分享 id>
# 自动化（Automate：数据变化 / 定时 → Action、模型分析、通知）
aidc semantic automate capabilities [--app slug]      # 能力目录：● 清单 exports 显式导出  ○ 从登记的类型 / Action 自动提取
aidc semantic automate list · get <slug> [--channel test]
aidc semantic automate run <slug> [--input '{…}'] [--param 名=值 …] [--preview] [--channel test] [--no-wait] [--idempotency-key k] [--dry-run]
aidc semantic automate runs <slug> [--limit 20] · status <slug> <运行 id> · watch <slug> <运行 id>
# 日志与用量
aidc semantic observability summary [应用] [--days 7] · events [--app …] [--kind feedback] [--status open] · feedback <id> --status done
aidc semantic usage summary [--app slug] [--month 2026-09] [--budget 美元] [--fx 7.1]   # 今日 / 本月 / 累计、按应用 / Key / 模型 / 天、月底预测、未计价
aidc semantic usage records [--app …] [--month …|--from … --to …] [--model …] [--lane app|developer] [--limit 100] [--all] [--csv]
aidc semantic usage check [--month …] [--app …]       # 对账；对不上退出码 1
aidc semantic usage prices                            # 价目（网页上的价目照样公开）
aidc semantic usage estimate -m <模型> --calls N [--per day|month] [--input N] [--cached N] [--output N] [--seconds N] [--kind video] [--off-peak 0.3] [--budget 美元] | --file 估算.json
# 旧命令照样能用（1.20.0 起都是 Semantic 的一部分）：aidc stream = semantic streams、aidc resources = semantic filesystem、aidc members = semantic admin members、
# aidc workflow = semantic automate、aidc log = semantic observability、aidc billing = semantic usage；aidc semantic act（旧的执行 Action）；
# aidc data query|get|create|update|delete|import|aggregate|watch|bind|bindings|resync|unbind（旧的数据层；直接写对象只给开发者）、aidc data profile|group（本地分析）；
# aidc connect datasets · report <数据集> [--report overview]（Semantic 之前的固定报告）· aidc connect send "<消息>" [--session <id>]（智能体，Agent Key 读 AIDC_AGENT_KEY）

aidc evolve slots [目录]                                # 本机：页面上的槽位（data-evolve）与清单 evolve 声明（不联网）
aidc evolve list <应用> [--status proposed] [--scope app|personal] [--kind overlay|request] · show <应用> <id>
aidc evolve compile <应用> "<一句话>" [--slot chat] [--model gpt-5.4-mini]   # 看一句话会变成什么指令（不保存）
aidc evolve save <应用> --ops 指令.json --title "…" [--scope app|personal] [--dry-run]
aidc evolve adopt|reject|revert|propose <应用> <id> [--note …] [--dry-run]
aidc evolve overlay <应用> [--scope app] [--css] · bake <应用> [--dir 应用目录] [--dry-run]   # 固化：全员改进写进源码，版本 +1
aidc evolve evidence [应用] · suggest [应用] [--file f] [--skill SKILL.md] [--conversation f] [--max 5]   # 证据 / 模型起草提案
aidc evolve proposals [--status open] · propose --spec 提案.json · accept <id> · reject <id> · apply <id> [--version 1.2.0]
# propose / reject 两边都有：带 <应用> <id> 两个参数的是应用里的改进，其余是提案。aidc improve …（1.2–1.20 的自提升）是旧名，子命令不变

aidc app init <slug> [--format plugin|aidc] [--template skills|blank|camera|voice|data|semantic|workflow|modeling] [--title …] [-n <命名空间>]
aidc app export [目录] [-n <命名空间>] [--out plugin.zip] # 标准包；输出到应用目录外
aidc app check [目录]
aidc app dev [目录] [--port 5173]
aidc app deploy [目录] [--notes …] [--dry-run]         # 版本号 = 清单 version，内容变了就要升
aidc app publish <slug|目录> [--version 1.2.0] [--notes …] [--dry-run]
aidc app rollback <slug> --version 1.1.0 [--notes …]
aidc app status <slug> · aidc app history <slug> · aidc app list   # slug 也可写 <命名空间>/<slug>
aidc app registry                                      # 应用登记表：每个应用用了哪些 SDK / 资源
aidc app card [slug|目录]                              # 应用卡片：负责部门、版本、SDK、连了哪些数据、对外能力与依赖
aidc app usage <slug>                                  # 资源用量：本月计算分钟 / 全部上限 / 定时 / 今天的通知与邮件通道
aidc app about <slug|命名空间/slug> [--channel test]   # 应用说明（给智能体读：APIs、Skills 全文、示例说法；同 <应用地址>/about.md）
aidc app apis <slug|命名空间/slug> [--channel test]    # 应用的 APIs：名字、参数、返回、调用口；Skills；用到的 AIDC 能力
aidc app call <slug|命名空间/slug> <API> [--param 名=值 …] [--input '{…}'] [--preview] [--channel test] [--idempotency-key k] [--dry-run]
                                                       # 调应用的一个 API（应用 × 成员角色执行；写入先 --preview）

aidc notify test [--dry-run]                           # 给自己发一封测试邮件，验证工作流 notify 步骤的邮件通道
```

`aidc app check` / `aidc app deploy` 发现成本问题时在 stderr 打 ⚠️ 告警（`--json` 时在 `warnings` 字段），不拦部署：工作流定时 ≤ 1 小时一次、`limits` 高于缺省、代码里 `setInterval` 拉数据。见[发布 SDK · 资源上限](publish.md#资源上限与成本告警)。

Semantic（含数据流、访问、自动化、日志、用量）、分享、自进化、建模命令的命名空间缺省 = 当前登录的公司（`-n cell-…` 可以指定；AIDC 平台账号可以 `-n public`）。`aidc modeling generate` 缺省等世界生成完成（约 5 分钟，进度打在 stderr），本地文件先直传 World Labs（`--dry-run` 不上传、不花钱）；生成失败退出码 8，额度 / 单次上限不够退出码 7。`aidc semantic automate run` 缺省等运行结束并逐步打印进度（stderr），运行失败退出码 1。

流名可以写 `<流名>`（命名空间取当前登录的公司）或 `<命名空间>/<流名>`。`aidc semantic streams pipe` 常驻运行（systemd 服务，不是定时器），适配器协议见 [数据流与数据源](connect.md)。

通用参数：`--json`（stdout 不是终端时默认开启）、`--dry-run`、`--api <根地址>`、`-n/--namespace`。

## 输出与退出码

- JSON 模式下，成功输出命令的数据对象；失败输出 `{ ok: false, error: { code, message, status, details, requestId } }`。进度提示一律在 stderr。
- `aidc login --json`：成功输出 `{"event":"logged_in","username":…,"cellId":…,"companyName":…,"keyPrefix":…}`（提示仍在 stderr）；`--browser` 时先逐行输出 `{"event":"authorize","url":…,"userCode":…}`。

| 退出码 | 含义 |
| --- | --- |
| 0 | 成功 |
| 1 | 一般错误 |
| 2 | 参数错误 / 校验不通过 |
| 3 | 未登录或凭证无效 |
| 4 | 无权限 |
| 5 | 不存在 |
| 6 | 冲突（例如发布未测过的版本、内容变了没升版本号） |
| 7 | 限流或额度用完 |
| 8 | 上游或网络故障 |

## 外部程序

`aidc video` 与长音频转写通过 ffmpeg 抽帧、转码、分段（`AIDC_FFMPEG` / `AIDC_FFPROBE` 可指定路径）。没装时命令报错并给出安装方式，不会退化成不完整的实现。
