Skip to content

Commit 9ff3427

Browse files
qdrivenclaude
andcommitted
docs: rewrite usage docs as cheatsheets, add analysis report (Refs: #10)
Usage docs: - Add git.md, magic.md, script.md, docs-cmd.md (new) - Rewrite agent.md, task.md, usage.md as cheatsheet format - Remove create.md, sync.md, update.md, gitcode.md (merged into git.md) New content: - docs/quick-start/getting-started.md - docs/analysis/project-analysis.md (architecture, evaluation, improvements) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c9b4037 commit 9ff3427

File tree

15 files changed

+761
-993
lines changed

15 files changed

+761
-993
lines changed

.github-task-workflow.active-issue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8
1+
10

docs/analysis/project-analysis.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Spark CLI 项目分析报告
2+
3+
## 项目概述
4+
5+
Spark CLI 是一个 Go 语言编写的命令行工具,定位为日常开发自动化和 AI Skill 集成的 CLI 后端。
6+
7+
**核心理念:** 确定性任务通过 CLI 自动化执行,节省 LLM token 成本;同时为 AI Agent 提供 CLI 调用接口。
8+
9+
## 技术栈
10+
11+
| 层面 | 技术选型 |
12+
|------|---------|
13+
| 语言 | Go 1.25 |
14+
| CLI 框架 | Cobra |
15+
| 配置管理 | Viper |
16+
| 终端 UI | PTerm + Bubble Tea |
17+
| 测试框架 | Ginkgo / Gomega |
18+
| 文档生成 | docmd |
19+
20+
## 功能模块
21+
22+
| 模块 | 命令 | 功能 |
23+
|------|------|------|
24+
| Git 管理 | `spark git` | 多仓库更新、Mono-repo 创建、子模块同步、Gitcode 远程、组织克隆 |
25+
| Agent 配置 | `spark agent` | 多种 AI Agent(Claude Code、Codex、Kimi、GLM)的配置管理和 Profile 切换 |
26+
| 任务管理 | `spark task` | 任务创建、分发、同步、AI 实现 |
27+
| 系统工具 | `spark magic` | DNS 刷新、pip/go/node 镜像源切换 |
28+
| 脚本管理 | `spark script` | 自定义脚本发现与执行 |
29+
| 文档管理 | `spark docs` | 文档结构初始化、docmd 站点配置 |
30+
31+
## 架构设计
32+
33+
```
34+
main.go → cmd.Execute()
35+
36+
├── cmd/ # Cobra 命令定义层
37+
│ ├── git/ # Git 操作命令组
38+
│ ├── magic/ # 系统工具命令组
39+
│ ├── script/ # 脚本管理命令组
40+
│ ├── docs/ # 文档管理命令组
41+
│ ├── agent.go # Agent 命令
42+
│ ├── agent_profile.go # Profile 子命令
43+
│ └── task.go # 任务命令
44+
45+
└── internal/ # 业务逻辑层
46+
├── agent/ # Agent 配置管理
47+
├── config/ # 配置加载与迁移
48+
├── git/ # Git 核心操作
49+
├── github/ # GitHub API 交互
50+
├── mono/ # Mono-repo 管理
51+
├── script/ # 脚本发现与执行
52+
├── task/ # 任务工作流
53+
└── tui/ # 终端 UI 组件
54+
```
55+
56+
**设计特点:**
57+
- cmd/ 只负责参数解析和调用 internal/ 的逻辑
58+
- internal/ 包之间低耦合,各司其职
59+
- 支持 `--tui` 标志在 CLI 和交互模式间切换
60+
61+
## 优点
62+
63+
### 1. 清晰的架构分层
64+
cmd/ 和 internal/ 的职责划分明确,命令层只做参数解析和 UI 呈现,业务逻辑完全在 internal/ 中。
65+
66+
### 2. 良好的外部库选型
67+
Cobra + Viper + PTerm 是 Go CLI 开发的成熟组合,降低了开发和维护成本。
68+
69+
### 3. AI Agent 统一抽象
70+
将多种 AI Agent(Claude Code、Codex、Kimi、GLM)的配置管理统一到一套接口下,通过 Profile 模板实现跨项目切换。
71+
72+
### 4. 实用导向
73+
每个功能都源于真实的工作需求(多仓库管理、镜像切换、DNS 刷新),不是为了技术而技术。
74+
75+
### 5. 配置迁移支持
76+
自动将旧配置 `.monolize.yaml` 迁移到 `.spark.yaml`,体现了对用户的尊重。
77+
78+
## 需要改进的方面
79+
80+
### 1. 测试覆盖不足
81+
- `internal/agent/``internal/mono/` 完全没有测试
82+
- cmd/ 层缺少集成测试
83+
- 现有测试质量不错(使用 Ginkgo BDD 风格),但覆盖面需要扩展
84+
85+
### 2. 外部命令依赖过重
86+
大量使用 `exec.Command` 调用 `git``gh``kimi``npm` 等外部命令,缺少抽象层。这导致:
87+
- 难以在不安装这些工具的环境中运行
88+
- 单元测试需要 mock 整个环境
89+
- 错误信息不够精确
90+
91+
### 3. 错误处理不一致
92+
- 部分函数返回错误链 (`fmt.Errorf("...: %w", err)`),部分直接返回
93+
- 缺少统一的错误类型和用户友好的错误提示
94+
- 某些路径缺少上下文信息
95+
96+
### 4. 代码重复
97+
- `cmd/magic/` 下 pip.go、go.go、node.go 的代码结构高度相似(list/use/current),可以提取为通用模板
98+
- 多处文件拷贝逻辑重复出现
99+
- `exec.Command` 的调用模式重复
100+
101+
### 5. 配置验证缺失
102+
- 没有对配置值进行验证
103+
- 缺少配置文件的 schema 定义
104+
- 环境变量覆盖支持不足
105+
106+
## 改进建议
107+
108+
| 优先级 | 改进项 | 预期收益 |
109+
|--------|--------|---------|
110+
|| 补充 internal/agent/ 和 internal/mono/ 的测试 | 提高代码可靠性 |
111+
|| 提取外部命令执行抽象层 | 可测试性 + 可维护性 |
112+
|| 统一 magic 命令的 mirror 切换模式 | 减少 60% 重复代码 |
113+
|| 添加配置验证 | 减少用户配置错误 |
114+
|| 添加集成测试 | 端到端验证 |
115+
|| 添加 contribution guide | 降低贡献门槛 |
116+
117+
## 总结
118+
119+
Spark CLI 是一个实用的开发工具,架构清晰、功能覆盖合理。核心优势在于将多种日常开发操作(Git 管理、镜像切换、AI Agent 配置)统一到一个 CLI 中,并通过 Profile 系统和 TUI 模式提供了良好的用户体验。主要改进方向是扩展测试覆盖、减少代码重复、统一外部命令调用模式。
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# 快速开始
2+
3+
## 安装
4+
5+
```bash
6+
git clone https://github.com/variableway/spark-cli.git
7+
cd spark-cli
8+
make build
9+
```
10+
11+
`make build` 编译二进制文件并安装到 `~/.local/bin/spark`。确保该路径在 `$PATH` 中。
12+
13+
## 配置
14+
15+
创建 `~/.spark.yaml`
16+
17+
```yaml
18+
repo-path:
19+
- ~/workspace
20+
git:
21+
username: your-name
22+
email: your@email.com
23+
github_owner: your-username
24+
```
25+
26+
## 常用命令
27+
28+
### Git 仓库管理
29+
30+
```bash
31+
spark git update -p ~/workspace # 更新所有仓库
32+
spark git create -n my-mono -o ./output # 创建 Mono-repo
33+
spark git clone-org variableway -o ./repos # 克隆组织仓库
34+
```
35+
36+
### 镜像源切换
37+
38+
```bash
39+
spark magic pip use tsinghua # Python → 清华源
40+
spark magic go use goproxy # Go → goproxy.cn
41+
spark magic node use taobao # Node → 淘宝源
42+
```
43+
44+
### AI Agent 配置
45+
46+
```bash
47+
spark agent list # 查看支持的 Agent
48+
spark agent view claude-code # 查看 Claude Code 配置
49+
spark agent profile add my-profile -t glm # 创建 Profile
50+
spark agent use my-profile # 应用到当前项目
51+
```
52+
53+
### 任务管理
54+
55+
```bash
56+
spark task init # 初始化任务目录
57+
spark task create my-feature # 创建特性文件
58+
spark task dispatch my-feature # 分发到工作目录
59+
spark task sync my-feature # 同步回任务目录
60+
```
61+
62+
### 文档管理
63+
64+
```bash
65+
spark docs init # 创建文档结构
66+
spark docs site # 初始化 docmd 站点
67+
docmd dev # 本地预览文档
68+
```
69+
70+
## 下一步
71+
72+
- [完整使用指南](../usage/usage.md)
73+
- [Git 管理](../usage/git.md)
74+
- [AI Agent 配置](../usage/agent.md)
75+
- [项目分析报告](../analysis/project-analysis.md)

0 commit comments

Comments
 (0)