@aid-framework/cli

中文文档
0.1.98发布于 2026/11/03Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 1万

The aid command: scaffold a project, validate its spec, generate its code, and run its eval gate.

原始使用文档
文档目录15 节
  1. Install
  2. Quick start
  3. Serving it
  4. Commands
  5. Exit codes
  6. --json
  7. The spec path
  8. Targets
  9. aid gen : planning, then reconciling
  10. When a generated file has been edited by hand
  11. aid eval : gating behaviour, not bytes
  12. What the CLI is not
  13. API
  14. Related packages
  15. License

@aid-framework/cli

The aid command: scaffold, validate, compile, index and evaluate an AI application from a single declarative spec file.

You write app/app.spec.yaml. aid checks it, compiles it into a runnable service, and gates its behaviour. Nothing in the generated tree is hand-written, and nothing you write is ever overwritten.

Install

npm install --save-dev @aid-framework/cli

Requires Node.js 24 or newer. Or run it without installing:

npx @aid-framework/cli --help

Quick start

npx aid init my-app
cd my-app
npx aid validate
npx aid gen

Three commands, and the generated app exists:

my-app/
  README.md
  app/
    app.spec.yaml
    business/         ← yours: prompts, tool handlers, domain logic
    generated/        ← the compiler's: never hand-edit
    aid.manifest.json ← provenance and per-file hashes

Serving it

The generator owns the routes; the application decides what to mount and how to run it. That entry point is yours, and it is a few lines — app/main.py:

from fastapi import FastAPI

from app.generated.routes.answer_ticket import answer_ticket_router

app = FastAPI(title="my-app", version="0.1.0")
app.include_router(answer_ticket_router)

Install the runtime and the server, then run it:

pip install aid-runtime-python "fastapi>=0.115,<1" "uvicorn>=0.30,<1"
uvicorn app.main:app --reload

aid gen never writes main.py or a pyproject.toml: mounting and packaging are application decisions, and a generator that guessed them would overwrite your choice on the next run.

The starter spec declares no pipelines, so a fresh init generates the structure but no routes. Add a pipeline to app/app.spec.yaml and regenerate, and one router module appears per HTTP-served pipeline.

Commands

CommandWhat it does
aid init [dir]Scaffold a project: a starter spec and a README
aid validate [spec]Parse the spec, build the IR, run every build-time gate
aid gen [spec]Compile the spec and reconcile the tree with it
aid ingest [spec]Index a retriever corpus into the store the spec declares
aid eval [spec]Run the eval gate, or record the baseline it measures against
aid doctor [spec]Diagnose the tree against the spec: drift, provenance and version mismatches, missing and outdated generated files. Reports; writes nothing

Every command accepts --help for its own options and --json for machine-readable output.

Exit codes

The exit code is the contract, because it is what CI reads:

CodeMeaning
0The project is as asked
1The spec, a gate, the target, or the working tree said no
2The invocation was wrong, or the CLI failed internally

1 and 2 are deliberately distinct. A red build caused by a spec problem is fixed in the spec; a red build caused by 2 is fixed in the invocation or is a bug. Collapsing them sends people to the wrong file.

--json

Every command answers --json with exactly one JSON document on stdout. Human-readable text and progress go to stderr, so aid validate --json | jq works without filtering.

npx aid validate --json | jq -r '.diagnostics[] | select(.severity=="error") | .code'

The spec path

Given no argument, a command reads app/app.spec.yaml — the path aid init creates and the path the generators compile into. Pass a path to override it:

npx aid validate path/to/other.spec.yaml

Targets

A spec declares the targets it is for, and aid gen emits one target at a time:

project:
  name: my-app
  targets:
    - py-fastapi
    - ts-vercel
npx aid gen                        # the first declared target
npx aid gen --target ts-vercel     # any other declared target

--target selects among the targets the spec declares; it cannot invent one. Naming a target the spec does not declare fails with target-unsupported and lists what is declared. That is stricter on purpose — a spec is the statement of intent, and silently generating a stack it did not ask for would make the spec a lie.

TargetEmitsRuntime
py-fastapiFastAPI service, Pydantic modelsaid-runtime-python
ts-vercelNext.js / Vercel functions, zod models@aid-framework/runtime

aid gen: planning, then reconciling

gen never writes blindly. It plans the full file set from the IR, compares that plan against the tree, and only then reconciles.

TierOwnerOn regeneration
app/generated/the compileroverwritten — never hand-edit
app/business/youcreated once if missing, then never touched

Preview without writing anything:

npx aid gen --dry-run
py-fastapi: dry run, 16 created, 0 updated, 0 unchanged, 0 kept
created:
  app/business/prompts/__init__.py
  app/generated/deps.py
  app/generated/requests.py
  app/generated/schemas.py
  ...

The counts are created / updated / unchanged / kept, so a no-op regeneration says so instead of looking like progress.

When a generated file has been edited by hand

gen records a SHA-256 for every file it writes in aid.manifest.json. If a generated/ file on disk no longer matches its recorded hash, a human edited it, and gen refuses to overwrite it. It writes the new content beside it as <path>.aid-rej and reports the conflict with both hashes.

The choice is yours to make explicitly:

npx aid gen --force     # discard the hand edit and overwrite

or move the file into business/ and point the business seam at it. Either way the edit is not lost silently, which is the failure mode that matters: a generator that overwrites unconditionally destroys the only signal it has that a human disagreed with it.

aid eval: gating behaviour, not bytes

A generated service varies between runs — the model is not deterministic, and pretending otherwise produces tests that are either always red or measuring nothing. aid eval therefore samples and compares distributions:

npx aid eval --record     # record a baseline from the current behaviour
npx aid eval              # gate the current behaviour against it

What the CLI is not

It is not a runtime. It reads the spec, compiles it, and reports; the generated app imports the runtime package for its target and runs without the CLI installed. @aid-framework/cli is a devDependency for exactly that reason.

API

The CLI is also importable, so a build tool can drive it without a subprocess:

import { main, runCli } from '@aid-framework/cli';

process.exitCode = await runCli(process.argv.slice(2));
ExportPurpose
runCli(argv)Run a command and return its exit code
mainThe command dispatcher
EXIT_OK, EXIT_REJECTED, EXIT_USAGEThe exit-code constants (0, 1, 2)

License

Apache-2.0. Code generated by AID Framework is not subject to this license.

版本与发布记录

@aid-framework/cli 共发布 52 个版本,首次发布于 2026/10/31;过去 12 个月发布了 52 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.98latest2026/11/032 天前
0.1.972026/11/032 天前
0.1.962026/11/033 天前
0.1.952026/11/033 天前
0.1.942026/11/033 天前
0.1.932026/11/033 天前

关于 @aid-framework/cli 的常见问题

@aid-framework/cli 是什么?

The aid command: scaffold a project, validate its spec, generate its code, and run its eval gate.

如何安装 @aid-framework/cli?

在项目目录运行 npm install @aid-framework/cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 aid,可以用 npx aid 直接运行。

@aid-framework/cli 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aid-framework/cli 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aid-framework/cli 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aid-framework/cli 可以商用吗?

@aid-framework/cli 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aid-framework/cli 的下载量有多少?

根据 npm 官方下载统计,@aid-framework/cli 在 2026/10/06 – 2026/11/04 这 30 天内被下载 10,375 次,日均约 346 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aid-framework/cli 还在维护吗?

最新版本 0.1.98 发布于 2026/11/03(2 天前);至今共发布 52 个版本,其中过去 12 个月发布了 52 个;首次发布于 2026/10/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。