trek-ai-cli
| Install | |
|---|---|
npm install trek-ai-cli |
|
| Latest Version: | 0.1.35 |
| Vue: | 3 |
| License: | MIT |
| Last Updated: | Sep 21, 2026 |
| Links: | npm |
trek-ai-cli
40+ 个 ai-agent 子命令 + MCP stdio server,适用于任何 Vue 组件库项目。装上之后
在项目根目录跑 npx ai-agent init 生成 ai.config.ts,所有命令都从
这个文件读宿主布局。
Node ≥ 22 · MIT · 安装即得
ai-agent二进制
Install
pnpm add -D trek-ai-cli
(trek-ai-cli 是个 dev tool,不应该装成 production 依赖。)
装完会有一个 ai-agent bin 在 node_modules/.bin/,或者直接 npx ai-agent ...。
一行快速开始
# 1. 初始化(在项目根目录生成 ai.config.ts)
npx ai-agent init
# 2. 编辑 ai.config.ts,告诉 CLI 项目布局(component 根、docs 根、测试命令等)
# 3. 装 pre-commit / pre-push hooks(可选)
npx ai-agent hook install
# 4. 跑一条命令试试
npx ai-agent check docs-render
ai.config.ts 配置契约
ai-agent init 生成的文件长这样(通用 Vue 组件库,字段按你的项目改):
import { defineConfig } from 'trek-ai-cli'
export default defineConfig({
// 1. 项目标识(模板里 {{project.name}} 用)
name: 'my-component-lib',
// displayName: 'My Component Lib', // 可选,展示名(默认=name)
// 2. 项目根(默认 = 配置文件所在目录)
// root: '/abs/path/to/repo',
// 3. 项目形态
profile: {
kind: 'vue3-component-lib',
componentRoot: 'packages/components',
componentsIndex: 'packages/my-lib/component.ts',
docRoot: 'docs/en-US/component',
exampleRoot: 'docs/examples',
sidebarConfig: 'docs/.vitepress/i18n/pages/component.json',
i18nPath: 'packages/locale/lang', // 可选
packagePrefix: '@my-scope/components', // 可选,组件导入前缀
// componentNamePattern: 'fancy-{name}', // 可选,默认 kebab-case
// namespaceHook: 'useNamespace', // 可选
} as const,
// 4. shell 命令注册表
commands: {
test: 'pnpm exec vitest',
e2e: 'playwright test --project=chromium --headed --workers=1',
lint: 'pnpm exec eslint .',
typecheck: 'pnpm exec tsc -p tsconfig.json --noEmit',
docsBuild: 'pnpm run -C docs build',
docsDev: 'pnpm run -C docs dev',
},
// 5. LLM 配置(可选,默认读 env)
// llm: { provider: 'openai', model: 'gpt-4o-mini' },
})
defineConfig是个 identity function —— 只是为了让你在ai.config.ts里有 IntelliSense,值原样透传。不要改成 CJS:
ai.config.ts会被 CLI 用tsx当 ESM 加载, 写module.exports会被解析失败。
子命令(按场景分组)
完整列表跑
npx ai-agent --help。
🚀 起步(不需要 ai.config.ts)
| 命令 | 说明 |
|---|---|
ai-agent init |
在当前目录生成 ai.config.ts |
ai-agent --help / -h |
打印帮助 |
ai-agent --version / -v |
打印版本 |
🪝 Git hooks
| 命令 | 说明 |
|---|---|
ai-agent hook install |
装 pre-commit + pre-push |
ai-agent hook uninstall |
卸 hooks |
ai-agent hook list |
列出已装的 hook |
ai-agent hook run pre-commit [...] |
内部用(被 .git/hooks/pre-commit 调) |
ai-agent hook run pre-push [...] |
内部用 |
🧭 MCP server
| 命令 | 说明 |
|---|---|
ai-agent mcp |
启动 MCP stdio server(给 AI agent 暴露 26 个 tool) |
📚 Rules(给 AI agent 写规则)
| 命令 | 说明 |
|---|---|
ai-agent rules sync |
把 templates 渲染到 .claude/agents/、.cursor/rules/ 等;同时渲染根级 AI 指南(AGENTS.md、AI_AGENT_*.md)到宿主仓库根 |
ai-agent rules sync --only=claude,cursor |
只渲指定 client(指南始终会渲染) |
ai-agent rules list |
列出每个 client 都有哪些模板 |
🏗 项目命令(跑宿主 build/test/docs 等)
把 ai.config.ts 里 commands 注册的宿主命令暴露成 ai-agent 子命令,
统一从 ai-agent 入口执行。commands 持有完整实现(宿主高频脚本已迁到此,package.json 不再重复定义):
| 命令 | 说明 |
|---|---|
ai-agent build |
完整项目构建(CLI 内置 trek-ai-build 工具链,经 jiti 跑 buildfile) |
ai-agent test |
单元测试(vitest) |
ai-agent e2e / test:e2e |
Playwright E2E |
ai-agent typecheck |
全套 typecheck(聚合 typecheck:*) |
ai-agent lint |
ESLint |
ai-agent docs:build |
文档构建 |
ai-agent docs:dev |
文档 dev server |
ai-agent dev |
Playground dev server |
ai-agent clean |
清理构建产物 |
ai-agent run <task> [-- args...] |
执行任意已注册 task;-- 后参数透传 |
ai-agent test:coverage / publish:npmjs / typecheck:web … |
任意命令键(test:/typecheck:/publish:/docs:/pack: 前缀等)都可在 commands 注册并联调 |
解析顺序:先查 ai.config.ts#commands 的精确键(含 test:coverage/publish:npmjs 等带冒号任意键,可含 shell 语法如 &&/正则,经 shell 执行),再查别名归一化,最后回落读宿主 package.json#scripts(pnpm run <script>)。ai-agent 直接持有/spawn 命令,不回环、透传退出码。
🛠 Env 检查
| 命令 | 说明 |
|---|---|
ai-agent env check |
探测 Python / 写盘权限 / bin 路径 |
ai-agent env install |
装 agent-reach、graphify 等子工具 |
🔍 知识库 & 检索(需要 ai.config.ts)
| 命令 | 说明 |
|---|---|
ai-agent build-knowledge |
从 docs / examples / components 构建知识库 |
ai-agent build-embeddings |
单独跑 embedding 步骤 |
ai-agent download-model |
预下载 ONNX 嵌入模型 |
ai-agent search <query> |
语义检索(打印 top-K 命中) |
ai-agent ask <question> |
检索 + LLM 生成答案(流式) |
ai-agent graph |
导出组件依赖图 |
📦 组件增删改(per-component)
| 命令 | 说明 |
|---|---|
ai-agent import-component <name> --from=<path> |
导入一个外部组件 |
ai-agent remove-component <name> |
反向移除(清代码 + sidebar + docs) |
ai-agent generate-docs <name> |
重新生成组件的 .md 文档 |
ai-agent generate-test <name> |
重新生成 vitest 单测 |
ai-agent generate-examples <name> |
重新生成 examples |
ai-agent generate-e2e <name> |
重新生成 Playwright e2e |
ai-agent generate-icon <name> |
让 LLM 生成 SVG icon 并接入 |
ai-agent register-sidebar <name> |
把组件加到 sidebar.json |
ai-agent sync-component-api |
同步组件 API 表(写到 docs) |
ai-agent audit-component <name> |
LLM 审计该组件代码 + 文档 |
ai-agent score-spec <name> |
按 spec 给组件打分 |
ai-agent score-spec --all |
扫所有组件 |
ai-agent generate-spec-all |
一键给所有组件生成 spec 草稿 |
✅ 质量门(check 4 件套)
| 命令 | 说明 |
|---|---|
ai-agent check registrations |
检查组件是否在 component.ts 注册 |
ai-agent check e2e |
跑 e2e 套件 |
ai-agent check docs-render |
检查 docs 是否能渲染 |
ai-agent check docs-render --check-reverse |
反向检查(中文/英文 sidebar 与 docs 互查) |
ai-agent check docs-render --check-reverse --fix |
自动修复不一致 |
ai-agent check docs-render --check-reverse --dry-run |
只看不改 |
ai-agent check coverage |
单测覆盖率 |
ai-agent check e2e-cmd |
跑 e2e 命令的 dry-run 验证 |
🤖 Agent 编排(高阶)
| 命令 | 说明 |
|---|---|
ai-agent go prompt "<requirement>" |
给一个需求,让 agent 自主 plan + execute |
ai-agent go verify --name=<comp> |
验证某个组件是否满足 spec |
ai-agent go orchestrate "<req>" |
多步编排(plan → exec → verify) |
ai-agent fix <kind> |
自动修某类问题(配合 check 输出) |
ai-agent auto-maintain |
周期维护(docs 同步、sidebar 重排、lesson 清理) |
ai-agent start |
启动后台 worker(轮询 + 自动修) |
ai-agent play |
交互式 playground(手动跑 LLM + tool) |
ai-agent reach |
触发 agent-reach 子工具(可达性分析) |
ai-agent publish-package <name> |
走包发布流程(本地直发) |
💾 缓存 & 指标
| 命令 | 说明 |
|---|---|
ai-agent cache status |
查 cache 大小 / 命中数 |
ai-agent cache clear |
清 cache |
ai-agent cache warm |
预热 |
ai-agent metrics |
打印本机累积的运行指标 |
ai-agent metrics clear |
清指标 |
公共参数(大多数 check / generate 都支持)
| Flag | 说明 |
|---|---|
--project-root=<path> |
显式指定宿主项目根(默认 = 当前目录) |
--json |
输出 JSON 而不是人类可读文本 |
--dry-run |
试跑但不改任何文件 |
--fix |
自动修复(check 命令) |
--strict |
任何 issue 都让 exit code = 1 |
程序化调用(trek-ai-cli 作为库)
trek-ai-cli 也导出几个函数,方便你在自己的 bin / IDE 插件里复用:
import {
loadConfig,
findConfigPath,
loadConfigFromPath,
toRulesContext,
defineConfig,
STARTER_CONFIG,
type AIConfig,
type ProjectProfile,
type ComponentLibProfile,
type AppProfile,
type CommandRegistry,
} from 'trek-ai-cli'
// 1. 找 + 加载 ai.config.ts(从 cwd 往上找)
const cfg = await loadConfig()
// 2. 加载指定路径
const cfg2 = await loadConfigFromPath('/abs/path/to/ai.config.ts')
// 3. 找而不加载
const p = await findConfigPath() // '/abs/.../ai.config.ts' or null
// 4. 渲染给 trek-ai-rules 用
const ctx = toRulesContext(cfg)
// → RulesContext(见 trek-ai-rules README)
// 5. 拿到 init 命令的 starter 配置(可以基于它再定制)
const starter: AIConfig = STARTER_CONFIG
类型化你的 ai.config.ts
import { defineConfig, type AIConfig } from 'trek-ai-cli'
export default defineConfig<AIConfig>({
// 完整 IntelliSense
})
内嵌 MCP server
ai-agent mcp 启动一个 stdio JSON-RPC server,暴露 26 个 tool。
任何支持 MCP 的客户端(Claude Desktop / Cursor / Cline / 自研 agent)
都能接上。tool 列表见 packages/cli/src/mcp/handlers/
(每个 *.ts 一个 tool 实现)。
// .mcp.json(MCP client 配置)
{
"mcpServers": {
"my-lib-agent": {
"command": "npx",
"args": ["ai-agent", "mcp"]
}
}
}
AI-augmented advisor(LLM 修复建议)
ai-agent check * 输出里如果有 issue,会带 llmHint 字段 —— 这是
CLI 调 trek-ai-core 的 LLMClient 给每条 issue 生成的 2-3 句
上下文相关的修复建议。带(rule + 上下文)的缓存,重复调用免费。
LLM 没配(LLM_DISABLED=1 或没设 OPENAI_API_KEY / DEEPSEEK_API_KEY)
时,advisor 还是返回静态字段(summary / rationale / fixCommand /
referencePath),只是没有 llmHint。
License
MIT.
Version History
| Version | Released | License |
|---|---|---|
| 0.1.35 | MIT | |
| 0.1.34 | MIT | |
| 0.1.32 | MIT | |
| 0.1.31 | MIT | |
| 0.1.30 | MIT | |
| 0.1.29 | MIT | |
| 0.1.28 | MIT | |
| 0.1.27 | MIT | |
| 0.1.26 | MIT | |
| 0.1.25 | MIT | |
| 0.1.22 | MIT | |
| 0.1.21 | MIT | |
| 0.1.20 | MIT | |
| 0.1.19 | MIT | |
| 0.1.18 | MIT | |
| 0.1.17 | MIT | |
| 0.1.16 | MIT | |
| 0.1.14 | MIT | |
| 0.1.13 | MIT | |
| 0.1.12 | MIT | |
| 0.1.11 | MIT | |
| 0.1.10 | MIT | |
| 0.1.9 | MIT | |
| 0.1.8 | MIT | |
| 0.1.7 | MIT | |
| 0.1.6 | MIT | |
| 0.1.5 | MIT | |
| 0.1.4 | MIT | |
| 0.1.3 | MIT | |
| 0.1.2 | MIT |
Showing the latest 30 of 32. See every release on npm