chore: 初始化仓库

This commit is contained in:
Lydanne
2026-02-15 22:02:21 +08:00
commit 08d011d63f
381 changed files with 87202 additions and 0 deletions

185
docs/reference/cli.md Normal file
View File

@@ -0,0 +1,185 @@
# CLI 命令参考
所有 Spaceflow CLI 命令的完整参考。
## 全局选项
| 选项 | 简写 | 说明 |
|------|------|------|
| `--help` | `-h` | 显示帮助信息 |
| `--version` | `-V` | 显示版本号 |
| `--verbose` | `-v` | 详细日志(`-v` 基本日志,`-vv` 详细日志) |
| `--dry-run` | | 试运行,不实际执行 |
| `--ci` | | CI 模式 |
## 内置命令
### `install`
安装 Extension。
```bash
spaceflow install <package> # 安装指定 Extension
spaceflow install # 安装 spaceflow.json 中所有 dependencies
spaceflow install <package> -g # 全局安装
```
### `uninstall`
卸载 Extension。
```bash
spaceflow uninstall <name>
```
### `update`
更新已安装的 Extension。
```bash
spaceflow update # 更新所有
spaceflow update <name> # 更新指定 Extension
```
### `list`
列出已安装的 Extension。
```bash
spaceflow list
```
输出示例:
```text
已安装的 Extension:
review @spaceflow/review [link]
命令: review
publish @spaceflow/publish [link]
命令: publish
```
### `build`
构建 Extension。
```bash
spaceflow build # 构建所有
spaceflow build --watch # 监听模式
spaceflow build <name> # 构建指定 Extension
```
### `dev`
开发模式,监听文件变化并自动重新构建。
```bash
spaceflow dev
spaceflow dev <name>
```
### `create`
创建新的 Extension 模板。
```bash
spaceflow create <name> # 创建命令型 Extension
spaceflow create <name> --skill # 创建技能型 Extension
```
### `commit`
Git 提交辅助,基于 Conventional Commits 规范。
```bash
spaceflow commit
```
### `setup`
同步编辑器配置。
```bash
spaceflow setup # 同步所有已配置编辑器
```
### `schema`
生成 `spaceflow.json` 的 JSON Schema。
```bash
spaceflow schema
```
### `mcp`
启动 MCPModel Context Protocol服务。
```bash
spaceflow mcp
```
### `runx`
运行外部命令,透传参数。
```bash
spaceflow runx <source> -- <args>
# 简写
spaceflow x <source> -- <args>
```
### `clear`
清理缓存和临时文件。
```bash
spaceflow clear
```
## 外部命令
以下命令需要先安装对应的 Extension。
### `review`
AI 代码审查。详见 [review 命令](/guide/commands/review)。
```bash
spaceflow review -p <pr-number> [-l <llm-mode>]
spaceflow review -b <base> --head <head> [-l <llm-mode>]
```
### `publish`
版本发布。详见 [publish 命令](/guide/commands/publish)。
```bash
spaceflow publish [--dry-run]
```
### `ci-scripts`
脚本执行。详见 [ci-scripts 命令](/guide/commands/ci-scripts)。
```bash
spaceflow ci-scripts --script <path>
```
### `ci-shell`
Shell 执行。详见 [ci-shell 命令](/guide/commands/ci-shell)。
```bash
spaceflow ci-shell --command <cmd>
```
### `period-summary`
周期总结。详见 [period-summary 命令](/guide/commands/period-summary)。
```bash
spaceflow period-summary --period <week|month>
```

150
docs/reference/config.md Normal file
View File

@@ -0,0 +1,150 @@
# 配置参考
`spaceflow.json` 完整配置项参考。
## 配置文件位置
按优先级从低到高排列,后者覆盖前者:
| 优先级 | 路径 | 说明 |
| --------- | ----------------------------- | ------------ |
| 1最低 | `~/.spaceflow/spaceflow.json` | 全局配置 |
| 2 | `~/.spaceflowrc` | 全局 RC 文件 |
| 3 | `.spaceflow/spaceflow.json` | 项目配置 |
| 4最高 | `.spaceflowrc` | 项目 RC 文件 |
## 完整配置示例
```json
{
"$schema": "./.spaceflow/config-schema.json",
"lang": "zh-CN",
"support": ["claudeCode", "windsurf", "cursor"],
"review": {
"references": ["./references", "https://github.com/org/review-spec"],
"includes": ["*/**/*.ts", "!*/**/*.spec.*", "!*/**/*.config.*"],
"generateDescription": true,
"autoUpdatePrTitle": true,
"lineComments": true,
"verifyFixes": true,
"analyzeDeletions": false,
"deletionAnalysisMode": "open-code",
"concurrency": 10,
"retries": 3,
"retryDelay": 1000
},
"publish": {
"monorepo": { "enabled": true, "propagateDeps": true },
"changelog": {
"preset": {
"type": [
{ "type": "feat", "section": "新特性" },
{ "type": "fix", "section": "修复BUG" },
{ "type": "perf", "section": "性能优化" },
{ "type": "refactor", "section": "代码重构" },
{ "type": "docs", "section": "文档更新" },
{ "type": "style", "section": "代码格式" },
{ "type": "test", "section": "测试用例" },
{ "type": "chore", "section": "其他修改" }
]
}
},
"npm": {
"publish": true,
"packageManager": "pnpm",
"tag": "latest",
"ignoreVersion": true,
"versionArgs": ["--workspaces false"]
},
"git": {
"pushWhitelistUsernames": ["github-actions[bot]"]
}
},
"dependencies": {
"@spaceflow/review": "link:./commands/review",
"@spaceflow/publish": "link:./commands/publish",
"@spaceflow/ci-shell": "link:./commands/ci-shell",
"@spaceflow/ci-scripts": "link:./commands/ci-scripts"
}
}
```
## 顶层字段
### `$schema`
- **类型**`string`
- **说明**JSON Schema 路径,用于编辑器自动补全
- **示例**`"./.spaceflow/config-schema.json"`
### `lang`
- **类型**`string`
- **默认值**`"zh-CN"`
- **说明**:界面语言。支持 `zh-CN``en`
### `support`
- **类型**`string[]`
- **默认值**`["claudeCode"]`
- **说明**:需要关联的 AI 编辑器列表
- **可选值**`"claudeCode"` | `"windsurf"` | `"cursor"` | `"opencode"`
### `dependencies`
- **类型**`Record<string, string>`
- **说明**:已安装的外部 Extension 注册表,由 `spaceflow install` 自动管理
## review 配置
| 字段 | 类型 | 默认值 | 说明 |
| ---------------------- | ---------- | ------------- | -------------------------------------- |
| `references` | `string[]` | `[]` | 审查规范来源(本地目录或远程仓库 URL |
| `includes` | `string[]` | `["*/**/*"]` | 审查文件匹配模式glob |
| `generateDescription` | `boolean` | `false` | 自动生成 PR 描述 |
| `autoUpdatePrTitle` | `boolean` | `false` | 自动更新 PR 标题 |
| `lineComments` | `boolean` | `true` | 生成行内评论 |
| `verifyFixes` | `boolean` | `false` | 验证修复建议 |
| `analyzeDeletions` | `boolean` | `false` | 分析删除代码影响 |
| `deletionAnalysisMode` | `string` | `"open-code"` | 删除分析模式 |
| `concurrency` | `number` | `10` | 并发审查文件数 |
| `retries` | `number` | `3` | 失败重试次数 |
| `retryDelay` | `number` | `1000` | 重试间隔(毫秒) |
### `references` 支持的格式
| 格式 | 示例 |
| ----------- | ---------------------------------------------------- |
| 本地目录 | `"./references"` |
| GitHub 仓库 | `"https://github.com/org/review-spec"` |
| GitHub 目录 | `"https://github.com/org/repo/tree/main/references"` |
| Gitea 仓库 | `"https://git.example.com/org/review-spec"` |
| SSH | `"git+ssh://git@github.com/org/repo.git"` |
## publish 配置
### `publish.monorepo`
| 字段 | 类型 | 默认值 | 说明 |
| --------------- | --------- | ------- | ------------------ |
| `enabled` | `boolean` | `false` | 启用 Monorepo 模式 |
| `propagateDeps` | `boolean` | `false` | 传播依赖版本更新 |
### `publish.changelog`
变更日志配置,基于 [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog)。
### `publish.npm`
| 字段 | 类型 | 默认值 | 说明 |
| ---------------- | --------- | ---------- | -------------- |
| `publish` | `boolean` | `true` | 是否发布到 npm |
| `packageManager` | `string` | `"pnpm"` | 包管理器 |
| `tag` | `string` | `"latest"` | npm tag |
| `ignoreVersion` | `boolean` | `false` | 忽略版本检查 |
### `publish.git`
| 字段 | 类型 | 说明 |
| ------------------------ | ---------- | ---------------------- |
| `pushWhitelistUsernames` | `string[]` | 允许推送的用户名白名单 |

View File

@@ -0,0 +1,94 @@
# 环境变量
Spaceflow 使用的所有环境变量参考。
## 通用
| 变量 | 说明 | 默认值 |
|------|------|--------|
| `SPACEFLOW_LANG` | 界面语言 | `zh-CN` |
| `CI` | 是否在 CI 环境中运行 | — |
## Git Provider
| 变量 | 说明 | 默认值 |
|------|------|--------|
| `GIT_PROVIDER_TYPE` | Git 平台类型(`github` / `gitea` | 自动检测 |
| `GITHUB_TOKEN` | GitHub API Token | — |
| `GITHUB_SERVER_URL` | GitHub Server URL | `https://github.com` |
| `GITEA_TOKEN` | Gitea API Token向后兼容 | — |
| `GITEA_SERVER_URL` | Gitea Server URL | — |
::: tip 自动检测逻辑
- 提供 `GITHUB_TOKEN` → 识别为 `github`
- 提供 `GITEA_TOKEN` → 识别为 `gitea`
- 都未提供 → 默认 `github`
- 可通过 `GIT_PROVIDER_TYPE` 显式覆盖
:::
## LLM 配置
### OpenAI
| 变量 | 说明 | 默认值 |
|------|------|--------|
| `OPENAI_API_KEY` | OpenAI API Key | — |
| `OPENAI_BASE_URL` | OpenAI API Base URL | `https://api.openai.com/v1` |
| `OPENAI_MODEL` | 模型名称 | `gpt-4o` |
### Claude
| 变量 | 说明 | 默认值 |
|------|------|--------|
| `ANTHROPIC_API_KEY` | Anthropic API Key | — |
### Claude Code
| 变量 | 说明 | 默认值 |
|------|------|--------|
| `CLAUDE_CODE_BASE_URL` | Claude Code Agent Base URL | — |
| `CLAUDE_CODE_AUTH_TOKEN` | Claude Code Auth Token | — |
| `CLAUDE_CODE_MODEL` | 模型名称 | `ark-code-latest` |
### OpenCode
| 变量 | 说明 | 默认值 |
|------|------|--------|
| `OPENCODE_API_KEY` | OpenCode API Key | — |
## 飞书
| 变量 | 说明 | 默认值 |
|------|------|--------|
| `FEISHU_APP_ID` | 飞书应用 App ID | — |
| `FEISHU_APP_SECRET` | 飞书应用 App Secret | — |
## GitHub Actions
在 GitHub Actions 中使用时,以下变量会自动注入:
| 变量 | 说明 |
|------|------|
| `GITHUB_TOKEN` | GitHub 自动注入的 Token |
| `GITHUB_SERVER_URL` | GitHub Server URL |
| `GITHUB_REPOSITORY` | 仓库全名(`owner/repo` |
| `GITHUB_EVENT_NAME` | 事件类型 |
| `GITHUB_REF` | 触发分支/标签 |
## 使用示例
### 本地开发
```bash
export GITHUB_TOKEN=ghp_xxxxxxxxxxxx
export OPENAI_API_KEY=sk-xxxxxxxxxxxx
spaceflow review -p 123
```
### CI 环境
```yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
```

View File

@@ -0,0 +1,215 @@
# Review Spec 规范
Review Spec 是 Spaceflow 中用于定义代码审查规则的 Markdown 格式文档。AI 审查系统会读取这些规范,并据此对代码进行自动化审查。
## 文件命名规则
规范文件名必须遵循以下格式:
```text
<扩展名>.<类型>.md
```
| 部分 | 说明 | 示例 |
|------|------|------|
| 扩展名 | 适用的文件扩展名,多个用 `&` 连接 | `js&ts`, `vue`, `tsx` |
| 类型 | 规范类型,可多级,用 `.` 分隔 | `nest`, `test-code`, `file-name` |
| 后缀 | 必须是 `.md` | `.md` |
示例:
```text
js&ts.nest.md # JS/TS NestJS 项目规范
js&ts.file-name.md # JS/TS 文件命名规范
js&ts.test-code.md # JS/TS 测试代码规范
vue.base.md # Vue 基础规范
```
## 文件结构
### 文件级配置
位于文件开头,使用 blockquote 语法:
```markdown
> - includes `*.controller.ts` `*.service.ts`
> - severity `warn`
> - override `[JsTs.FileName]`
```
### 规则定义
使用二级标题定义规则:
````markdown
## 规则标题 `[规则ID]`
规则描述...
### Good
```typescript
// 推荐代码示例
```
### Bad
```typescript
// 不推荐代码示例
```
````
## 文件级配置项
### `includes`
指定规范适用的文件路径模式glob
```markdown
> - includes `**/*.controller.ts` `**/*.service.ts`
```
- 支持 `*`(任意字符)和 `**`(任意层级)
- 多个模式用空格分隔,包裹在反引号中
### `severity`
指定规则的默认严重程度。
```markdown
> - severity `warn`
```
| 值 | 含义 | 显示 | 阻止合并 |
|----|------|------|----------|
| `error` | 错误 | 🔴 红色 | 通常阻止 |
| `warn` | 警告 | 🟡 黄色 | 通常不阻止 |
| `off` | 关闭 | 不显示 | 否 |
### `override`
排除其他规范文件中的规则,支持前缀匹配。
```markdown
> - override `[JsTs.FileName]`
```
排除所有以 `JsTs.FileName` 开头的规则(包括 `JsTs.FileName.UpperCamel` 等子规则)。
## 规则级配置
可以在规则内容中使用 blockquote 覆盖文件级配置:
```markdown
## 服务规范 `[JsTs.Nest.Service]`
服务文件包含业务逻辑...
> - severity `warn`
```
## 规则 ID 命名
规则 ID 支持多级命名,使用 `.` 分隔:
```markdown
## 主规则 `[JsTs.Nest]`
## 控制器规范 `[JsTs.Nest.Controller]`
## 服务规范 `[JsTs.Nest.Service]`
```
## 远程规范仓库
支持从 Git 仓库加载规范文件:
```json
{
"review": {
"references": [
"./references",
"https://github.com/your-org/review-spec"
]
}
}
```
### 支持的 URL 格式
| 格式 | 示例 |
|------|------|
| GitHub 仓库 | `https://github.com/org/repo` |
| GitHub 目录 | `https://github.com/org/repo/tree/main/references` |
| Gitea 仓库 | `https://git.example.com/org/repo` |
| Gitea 目录 | `https://git.example.com/org/repo/src/branch/main/references` |
| SSH | `git@host:owner/repo.git` |
| SSH完整 | `git+ssh://git@host/owner/repo.git` |
远程规范会缓存到 `~/.spaceflow/review-spec-cache/`TTL 为 5 分钟CI 环境中每次拉取最新)。
## 完整示例
````markdown
# NestJS 项目规范 `[JsTs.Nest]`
> - includes `*.controller.ts` `*.service.ts` `*.module.ts`
> - severity `error`
> - override `[JsTs.FileName]`
## 控制器规范 `[JsTs.Nest.Controller]`
控制器文件不能包含业务逻辑,只能调用 service 方法。
### Good
```typescript
@Controller("user")
export class UserController {
constructor(private readonly userService: UserService) {}
@Get()
async getUser(@Param("id") id: string) {
return this.userService.findById(id);
}
}
```
### Bad
```typescript
@Controller("user")
export class UserController {
@Get()
async getUser(@Param("id") id: string) {
const user = await db.query("SELECT * FROM users WHERE id = ?", [id]);
return user;
}
}
```
## 服务规范 `[JsTs.Nest.Service]`
服务文件包含业务逻辑,必须通过 model 访问数据库。
> - severity `warn`
### Good
```typescript
@Injectable()
export class UserService {
constructor(private readonly userModel: UserModel) {}
async getUser(id: string) {
return this.userModel.findById(id);
}
}
```
````
## 最佳实践
- **规则 ID 命名** — 使用有意义的层级结构,如 `语言.类型.规则名`
- **代码示例** — 提供清晰的 Good/Bad 示例
- **严重程度** — 合理设置 severity避免过多 error 阻塞开发
- **文件组织** — 按功能或类型组织规则文件,避免单个文件过大
- **includes 精确** — 使用精确的文件路径匹配,避免误匹配