specline 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 zhouyushun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,161 @@
1
+ # Specline
2
+
3
+ 面向 Cursor IDE 的 **Spec 驱动 AI 编码流水线**,内置确定性质量门禁。
4
+
5
+ 一句话需求 → 自动走完 编写规格 → 编码 → 审查 → 测试 → 归档 全流程:
6
+
7
+ ```
8
+ /specline-pipeline "实现用户登录功能"
9
+ ```
10
+
11
+ ## 它能做什么
12
+
13
+ ```
14
+ 自然语言需求 → Spec → 审核 → 编码 → 审查 → 测试 → 归档
15
+ ↑ ↑ ↑ ↑ ↑ ↑
16
+ spec- spec- 前后端 code- 单元/ ✓ 完成
17
+ creator reviewer 并行 reviewer 集成/
18
+ E2E
19
+ ```
20
+
21
+ 每个阶段都经过 **确定性门禁校验** —— 用 `grep`、`jq`、编译器退出码、测试退出码判断通过与否。**质量判断零 LLM 参与**。
22
+
23
+ ## 核心特性
24
+
25
+ - **需求驱动**:自然语言 → 结构化规格文档(Requirements + Scenarios + WHEN/THEN)
26
+ - **并行编码**:自动按前端/后端拆分任务,同批次并发派发 Coding Agent
27
+ - **确定性门禁**:每个阶段用 Shell 脚本的退出码判定是否通过,不做模糊判断
28
+ - **黑盒测试**:测试 Agent 只看 Spec 文档,不能读取任何实现源码
29
+ - **断点续跑**:随时中断,下次从最后一个可信门禁自动恢复(tasks.md 的 `[x]`/`[ ]` 标记进度)
30
+ - **人机协作**:3 个人工检查点——Spec 确认、Review 可选复核、归档确认
31
+ - **安全 Hook**:自动拦截危险 Shell 命令(如 `rm -rf`、`curl|bash`)+ 代码变更后自动格式化
32
+ - **零外部依赖**:不依赖 OpenSpec CLI,全部功能自包含
33
+
34
+ ## 快速开始
35
+
36
+ ```bash
37
+ # 全局安装
38
+ npm install -g specline
39
+
40
+ # 在项目中初始化
41
+ cd my-project
42
+ specline init
43
+
44
+ # 或者用 npx(无需安装)
45
+ npx specline init
46
+ ```
47
+
48
+ 初始化后项目会获得完整的流水线基础设施:
49
+
50
+ ```
51
+ my-project/
52
+ ├── .cursor/
53
+ │ ├── agents/ ← 7 个 Specline Agent 定义
54
+ │ ├── commands/ ← 2 个 Slash 命令入口
55
+ │ ├── skills/ ← 5 个 Skill 指令
56
+ │ ├── hooks/ ← 4 个 Gate/Hook 脚本
57
+ │ └── hooks.json ← Cursor Hook 配置
58
+ ├── specline/ ← 运行时目录
59
+ │ ├── config.yaml
60
+ │ ├── changes/ ← 变更目录
61
+ │ │ └── archive/ ← 归档目录
62
+ │ └── specs/ ← 主规格目录
63
+ └── .specline-config.yaml
64
+ ```
65
+
66
+ 然后在 Cursor 中输入:
67
+
68
+ ```
69
+ /specline-pipeline "添加 JWT 用户认证"
70
+ ```
71
+
72
+ 开始编码前先探索思路:
73
+
74
+ ```
75
+ /specline-explore
76
+ ```
77
+
78
+ ## 流水线阶段
79
+
80
+ ```
81
+ PHASE 1: SPEC(规格)
82
+ specline-spec-creator 生成 4 个规划文件
83
+ ├── proposal.md — 需求提案(What/Why/Scope)
84
+ ├── specs/*/spec.md — 功能规格(Requirements/Scenarios/WHEN-THEN)
85
+ ├── design.md — 技术设计(架构/数据流/决策)
86
+ └── tasks.md — 任务清单(Type/Depends/Covers/Files + [ ] 进度标记)
87
+ → specline-spec-reviewer 审核
88
+ → Gate: grep + jq 格式校验
89
+ → 🟡 人工确认 Spec 和任务规划
90
+
91
+ PHASE 2: CODING(编码)
92
+ 解析 tasks.md → 按依赖 DAG 分层 → 同批次前后端 Agent 并发
93
+ 每完成一个任务,[ ] 自动标记为 [x]
94
+ → Gate: 编译检查(tsc --noEmit / python -m compileall)
95
+
96
+ PHASE 3: REVIEW(审查)
97
+ specline-code-reviewer 审查代码质量、安全性、可维护性
98
+ → Gate: Lint 检查 + code-review.json error 计数
99
+
100
+ PHASE 4: TEST(测试)
101
+ 单元测试 → 集成测试 → E2E 测试(黑盒,只看 Spec)
102
+ → 失败自动分析:测试写错了 / 代码写错了 / Spec 模糊
103
+ → 自动重试最多 2 次
104
+
105
+ PHASE 5: ARCHIVE(归档)
106
+ → 🟡 人工确认归档
107
+ → delta specs 合并到主规格目录
108
+ → 按日期归档到 specline/changes/archive/
109
+ ✅ 完成
110
+ ```
111
+
112
+ ## 架构
113
+
114
+ ```
115
+ /specline-pipeline ← 你输入这个
116
+
117
+
118
+ specline-pipeline SKILL ← 编排层(读状态、派发 Agent、调 Gate)
119
+
120
+ ┌───┼──────────────────┬──────────────────────┐
121
+ ▼ ▼ ▼ ▼
122
+ 7 个子 Agent specline-pipeline- Cursor Hooks
123
+ (创造性工作) gate.sh (安全网)
124
+ (确定性门禁)
125
+ ```
126
+
127
+ ## 子 Agent 列表
128
+
129
+ | Agent | 职责 |
130
+ |-------|------|
131
+ | `specline-spec-creator` | 根据自然语言需求,基于内联模板直接生成 proposal/design/tasks/spec 四个文件 |
132
+ | `specline-spec-reviewer` | 审核规格的完整性、一致性和覆盖度 |
133
+ | `specline-frontend-dev` | UI 组件、页面、样式、交互逻辑(单个任务级别) |
134
+ | `specline-backend-dev` | API 端点、数据模型、业务逻辑(单个任务级别) |
135
+ | `specline-code-reviewer` | 代码质量、安全性、可维护性审查 |
136
+ | `specline-test-writer` | 黑盒测试编写——只能看 Spec,不能读源码 |
137
+ | `specline-test-runner` | 执行测试并分类失败原因(测试问题/代码问题/Spec 模糊) |
138
+
139
+ ## 确定性门禁
140
+
141
+ 每个门禁都是 Shell 脚本,`exit 0` = 通过,`exit 1` = 失败:
142
+
143
+ | 门禁 | 检查内容 |
144
+ |------|---------|
145
+ | Spec | `grep` 检查 Purpose/Requirements/Scenarios 章节完整性、WHEN/THEN 配对 |
146
+ | Build | `tsc --noEmit` / `python -m compileall` 编译检查 |
147
+ | Lint | `ruff` / `eslint` 退出码 + code-review.json 中 error 数量 |
148
+ | Test | 测试框架退出码 + 覆盖率阈值 |
149
+ | Archive | 归档目录结构 + 必要文件完整性 |
150
+
151
+ ## 环境要求
152
+
153
+ - **Cursor IDE**(支持 hooks 和 skills)
154
+ - **jq**(Gate 脚本 JSON 处理)
155
+ - macOS 预装
156
+ - Linux: `apt install jq`
157
+ - Windows: `choco install jq`
158
+
159
+ ## License
160
+
161
+ MIT
package/cli.mjs ADDED
@@ -0,0 +1,169 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { existsSync, mkdirSync, readdirSync, copyFileSync, writeFileSync } from 'fs';
4
+ import { join, dirname, resolve } from 'path';
5
+ import { fileURLToPath } from 'url';
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ const TEMPLATES_DIR = join(__dirname, 'templates');
9
+ const VERSION = '1.0.0';
10
+
11
+ function log(msg) {
12
+ console.log(msg);
13
+ }
14
+
15
+ function warn(msg) {
16
+ console.log(`\x1b[33m⚠️ ${msg}\x1b[0m`);
17
+ }
18
+
19
+ function success(msg) {
20
+ console.log(`\x1b[32m✅ ${msg}\x1b[0m`);
21
+ }
22
+
23
+ function error(msg) {
24
+ console.error(`\x1b[31m❌ ${msg}\x1b[0m`);
25
+ }
26
+
27
+ function copyDirRecursive(src, dest) {
28
+ if (!existsSync(dest)) {
29
+ mkdirSync(dest, { recursive: true });
30
+ }
31
+ const entries = readdirSync(src, { withFileTypes: true });
32
+ for (const entry of entries) {
33
+ const srcPath = join(src, entry.name);
34
+ const destPath = join(dest, entry.name);
35
+ if (entry.isDirectory()) {
36
+ copyDirRecursive(srcPath, destPath);
37
+ } else {
38
+ copyFileSync(srcPath, destPath);
39
+ }
40
+ }
41
+ }
42
+
43
+ function cmd_init(targetPath) {
44
+ const cwd = process.cwd();
45
+ const target = resolve(cwd, targetPath || '.');
46
+
47
+ if (!existsSync(target)) {
48
+ error(`目标路径不存在: ${target}`);
49
+ process.exit(1);
50
+ }
51
+
52
+ const configFile = join(target, '.specline-config.yaml');
53
+ const forceMode = process.argv.includes('--force') || process.argv.includes('-f');
54
+
55
+ if (existsSync(configFile) && !forceMode) {
56
+ warn('Specline 已在此项目中初始化。使用 --force 强制覆盖。');
57
+ process.exit(0);
58
+ }
59
+
60
+ // 检测 hooks.json 冲突
61
+ const hooksJsonDest = join(target, '.cursor', 'hooks.json');
62
+ if (existsSync(hooksJsonDest)) {
63
+ const backupPath = hooksJsonDest + '.bak';
64
+ copyFileSync(hooksJsonDest, backupPath);
65
+ warn('已备份原有 hooks.json → .cursor/hooks.json.bak');
66
+ }
67
+
68
+ // 创建目录结构
69
+ const dirs = [
70
+ '.cursor/agents',
71
+ '.cursor/commands',
72
+ '.cursor/skills',
73
+ '.cursor/hooks',
74
+ 'specline/changes/archive',
75
+ 'specline/specs',
76
+ ];
77
+
78
+ for (const dir of dirs) {
79
+ const fullDir = join(target, dir);
80
+ if (!existsSync(fullDir)) {
81
+ mkdirSync(fullDir, { recursive: true });
82
+ }
83
+ }
84
+
85
+ // 从 templates/ 复制文件
86
+ if (!existsSync(TEMPLATES_DIR)) {
87
+ error(`templates/ 目录不存在: ${TEMPLATES_DIR}`);
88
+ process.exit(1);
89
+ }
90
+
91
+ copyDirRecursive(TEMPLATES_DIR, target);
92
+
93
+ // 统计各类文件数量
94
+ function countFiles(dir) {
95
+ let count = 0;
96
+ if (!existsSync(dir)) return 0;
97
+ try {
98
+ const entries = readdirSync(dir, { withFileTypes: true, recursive: true });
99
+ for (const entry of entries) {
100
+ if (entry.isFile()) count++;
101
+ }
102
+ } catch (_) {}
103
+ return count;
104
+ }
105
+
106
+ const agentsCount = countFiles(join(target, '.cursor', 'agents'));
107
+ const commandsCount = countFiles(join(target, '.cursor', 'commands'));
108
+ const skillsCount = countFiles(join(target, '.cursor', 'skills'));
109
+ const hooksCount = countFiles(join(target, '.cursor', 'hooks'));
110
+
111
+ // 写入初始化配置
112
+ const initConfig = `# Specline 项目配置
113
+ version: "${VERSION}"
114
+ initialized_at: "${new Date().toISOString()}"
115
+ `;
116
+ writeFileSync(configFile, initConfig, 'utf-8');
117
+
118
+ success('Specline 初始化完成');
119
+ log(`📁 文件: ${commandsCount} commands, ${skillsCount} skills, ${agentsCount} agents, ${hooksCount} hooks`);
120
+ log('');
121
+ log('🚀 试试在 Cursor 中输入:');
122
+ log(' /specline-pipeline "你的第一个需求"');
123
+ log(' /specline-explore');
124
+
125
+ process.exit(0);
126
+ }
127
+
128
+ function cmd_version() {
129
+ log(`specline v${VERSION}`);
130
+ process.exit(0);
131
+ }
132
+
133
+ function cmd_help() {
134
+ log(`specline v${VERSION} — Spec-driven AI coding pipeline for Cursor IDE
135
+
136
+ 用法:
137
+ specline init [path] 在指定路径初始化流水线基础设施
138
+ specline init --force 强制覆盖已有配置
139
+ specline --version, -v 显示版本号
140
+ specline --help, -h 显示此帮助信息
141
+
142
+ 示例:
143
+ specline init 在当前目录初始化
144
+ specline init ./my-project 在指定目录初始化
145
+ npx specline init 无需全局安装即可使用
146
+ `);
147
+ process.exit(0);
148
+ }
149
+
150
+ // 入口
151
+ const [,, command, ...args] = process.argv;
152
+
153
+ switch (command) {
154
+ case 'init': {
155
+ // 过滤出 --force/-f 之外的真实路径参数
156
+ const pathArg = args.filter(a => a !== '--force' && a !== '-f')[0];
157
+ cmd_init(pathArg);
158
+ break;
159
+ }
160
+ case '--version':
161
+ case '-v':
162
+ cmd_version();
163
+ break;
164
+ case '--help':
165
+ case '-h':
166
+ default:
167
+ cmd_help();
168
+ break;
169
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "specline",
3
+ "version": "1.0.0",
4
+ "description": "Spec-driven AI coding pipeline with deterministic quality gates for Cursor IDE",
5
+ "bin": {
6
+ "specline": "./cli.mjs"
7
+ },
8
+ "files": [
9
+ "cli.mjs",
10
+ "templates/"
11
+ ],
12
+ "keywords": [
13
+ "cursor",
14
+ "specline",
15
+ "spec-driven",
16
+ "ai-coding",
17
+ "pipeline",
18
+ "agent-orchestration",
19
+ "deterministic-gates",
20
+ "dev-pipeline"
21
+ ],
22
+ "license": "MIT",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/RayChou1221/specline"
26
+ },
27
+ "engines": {
28
+ "node": ">=20.0.0"
29
+ }
30
+ }
@@ -0,0 +1,47 @@
1
+ ---
2
+ name: specline-backend-dev
3
+ description: 根据 Spec 编写后端代码(API 端点、数据模型、业务逻辑、CLI 命令)。只操作后端相关文件。支持 task-aware 模式——接收单个任务,只修改该任务涉及的文件。
4
+ ---
5
+
6
+ 你是后端开发专家。你通过 `/dev-pipeline` 编排系统接收**单个编码任务**。
7
+
8
+ ## 任务上下文
9
+
10
+ 你在流水线的 Coding 阶段被调用。每次调用时,主 Agent 会传递以下上下文:
11
+
12
+ 1. **当前任务**:从 `tasks.md` 中提取的单一任务描述(Type: backend 的任务)
13
+ 2. **Spec 文档**:`specline/changes/<change-name>/specs/<capability>/spec.md`
14
+ 3. **Design 文档**:`specline/changes/<change-name>/design.md`
15
+ 4. **全部任务列表**:`specline/changes/<change-name>/tasks.md`(了解其他任务的范围)
16
+
17
+ ## 工作方式
18
+
19
+ 1. 理解当前任务的范围和边界——只实现本任务描述的 API/模型/逻辑功能
20
+ 2. 阅读 Spec 中与当前任务相关的后端需求
21
+ 3. 确认 design.md 中的技术决策(架构模式、数据流、错误处理策略等)
22
+ 4. 编写代码,遵循项目现有代码风格和架构模式
23
+ 5. 完成后输出变更文件列表
24
+ 6. **完成后必须将 `specline/changes/<change-name>/tasks.md` 中本任务标题的 `[ ]` 改为 `[x]`**(方便流水线断点续跑)
25
+
26
+ ## 约束
27
+
28
+ - 只操作本任务涉及的后端文件(.py 后端代码、数据模型、API 路由、CLI 命令等)
29
+ - 不修改前端 UI 组件和样式
30
+ - 不修改其他任务负责的文件
31
+ - 与其他任务约定的接口(API 端点、数据模型字段等)必须严格遵守
32
+ - 保持与现有代码风格一致
33
+ - 确保错误处理和日志记录完整
34
+
35
+ ## 产出报告
36
+
37
+ 完成后输出 JSON 到 `.cursor/tmp/task-<task-id>-result.json`:
38
+
39
+ ```json
40
+ {
41
+ "task_id": "<task-id>",
42
+ "type": "backend",
43
+ "status": "completed",
44
+ "files_changed": ["server/models.py", "server/routes/api.py"],
45
+ "summary": "实现了 Agent 数据模型和 API 端点"
46
+ }
47
+ ```
@@ -0,0 +1,51 @@
1
+ ---
2
+ name: specline-code-reviewer
3
+ description: 审查代码变更的质量、安全性和最佳实践。产出结构化的 code-review.json,区分 error(必须修复)和 warning(建议改进)。利用 tasks.md 的 Covers 追溯链定位问题。
4
+ ---
5
+
6
+ 你是代码审查专家。审查最近的代码变更,产出结构化审查结果。
7
+
8
+ ## 审查维度
9
+
10
+ 1. **正确性**:逻辑是否正确,边界条件是否处理
11
+ 2. **安全性**:是否有注入风险、密钥泄露、权限漏洞
12
+ 3. **性能**:是否有明显性能问题(N+1 查询、未释放资源等)
13
+ 4. **可维护性**:命名是否清晰、是否有重复代码、模块划分是否合理
14
+ 5. **错误处理**:异常是否被妥善捕获和处理
15
+ 6. **测试友好**:代码是否易于测试
16
+
17
+ ## 工作方式
18
+
19
+ 1. 查看 git diff 获取变更文件列表
20
+ 2. 对照 `specline/changes/<change-name>/tasks.md` 中的 `Covers` 追溯链,知道每个文件属于哪个任务、覆盖哪个 Requirement
21
+ 3. 逐一审查变更代码
22
+ 4. 每个发现标记 severity:`error`(必须修复)或 `warning`(建议改进)
23
+ 5. 每个发现标注 `covers`:对应的 Requirement 名称(从 tasks.md 的 Covers 中获取)
24
+ 6. 每个发现标注 `task_id`:对应的任务编号
25
+
26
+ ## 输出格式
27
+
28
+ 产出 `code-review.json`:
29
+
30
+ ```json
31
+ {
32
+ "findings": [
33
+ {
34
+ "severity": "error",
35
+ "file": "agent/daemon.py",
36
+ "line": 45,
37
+ "task_id": "3",
38
+ "covers": "Requirement: 守护进程管理",
39
+ "message": "未处理 WebSocket 连接超时异常,可能导致守护进程崩溃"
40
+ },
41
+ {
42
+ "severity": "warning",
43
+ "file": "server/models.py",
44
+ "line": 12,
45
+ "task_id": "1",
46
+ "covers": "Requirement: 数据模型",
47
+ "message": "建议为 Agent 表添加索引以优化按状态查询的性能"
48
+ }
49
+ ]
50
+ }
51
+ ```
@@ -0,0 +1,47 @@
1
+ ---
2
+ name: specline-frontend-dev
3
+ description: 根据 Spec 编写前端代码(UI 组件、页面、样式、交互逻辑)。加载 frontend-design skill 确保设计质量。只操作前端相关文件。支持 task-aware 模式——接收单个任务,只修改该任务涉及的文件。
4
+ ---
5
+
6
+ 你是前端开发专家。你通过 `/dev-pipeline` 编排系统接收**单个编码任务**。
7
+
8
+ ## 任务上下文
9
+
10
+ 你在流水线的 Coding 阶段被调用。每次调用时,主 Agent 会传递以下上下文:
11
+
12
+ 1. **当前任务**:从 `tasks.md` 中提取的单一任务描述(Type: frontend 的任务)
13
+ 2. **Spec 文档**:`specline/changes/<change-name>/specs/<capability>/spec.md`
14
+ 3. **Design 文档**:`specline/changes/<change-name>/design.md`
15
+ 4. **全部任务列表**:`specline/changes/<change-name>/tasks.md`(了解其他任务的范围)
16
+
17
+ ## 工作方式
18
+
19
+ 1. 理解当前任务的范围和边界——只实现本任务描述的 UI/样式/交互功能
20
+ 2. 阅读 Spec 中与当前任务相关的前端需求
21
+ 3. 确认 design.md 中的技术决策(组件库、样式方案、路由设计等)
22
+ 4. 编写代码,优先加载 `frontend-design` skill 确保设计质量
23
+ 5. 完成后输出变更文件列表
24
+ 6. **完成后必须将 `specline/changes/<change-name>/tasks.md` 中本任务标题的 `[ ]` 改为 `[x]`**(方便流水线断点续跑)
25
+
26
+ ## 约束
27
+
28
+ - 只操作本任务涉及的前端文件(.tsx, .jsx, .css, .html, 组件文件等)
29
+ - 不修改后端 API、数据模型、业务逻辑
30
+ - 不修改其他任务负责的文件
31
+ - 与其他任务约定的接口(API 格式、Props 类型等)必须严格遵守
32
+ - 保持代码风格一致
33
+ - 确保组件可用的默认状态(无数据时不崩溃)
34
+
35
+ ## 产出报告
36
+
37
+ 完成后输出 JSON 到 `.cursor/tmp/task-<task-id>-result.json`:
38
+
39
+ ```json
40
+ {
41
+ "task_id": "<task-id>",
42
+ "type": "frontend",
43
+ "status": "completed",
44
+ "files_changed": ["src/components/Header.tsx", "src/styles/main.css"],
45
+ "summary": "实现了 Dashboard 页面和 Header 组件"
46
+ }
47
+ ```